8#ifndef META_OCEAN_MATH_MATH_UTILITIES_H
9#define META_OCEAN_MATH_MATH_UTILITIES_H
37 template <
typename TTransformation,
typename TObject>
38 static inline void transform(
const TTransformation& transformation,
const std::vector<TObject>& objects, std::vector<TObject>& results,
Worker* worker =
nullptr,
const unsigned int minimalObjectsPerThread = 1000u);
64 template <
typename TTransformation,
typename TObject>
65 static inline void transformSubset(
const TTransformation* transformation,
const TObject* objects, TObject* results,
const unsigned int firstObject,
const unsigned int numberObjects);
68template <
typename TTransformation,
typename TObject>
69inline void MathUtilities::transform(
const TTransformation& transformation,
const std::vector<TObject>& objects, std::vector<TObject>& results,
Worker* worker,
const unsigned int minimalObjectsPerThread)
71 ocean_assert(minimalObjectsPerThread >= 1u);
72 results.resize(objects.size());
76 worker->
executeFunction(
Worker::Function::createStatic(
transformSubset<TTransformation, TObject>, &transformation, objects.data(), results.data(), 0u, 0u), 0u, (
unsigned int)objects.size(), 3u, 4u, minimalObjectsPerThread);
86 ocean_assert(0.0f <= value && value <= 1.0f);
87 ocean_assert(decomposedValues !=
nullptr);
89 const float value1 = value * 255.0f;
90 const float value2 = value * 255.0f * 255.0f;
91 const float value3 = value * 255.0f * 255.0f * 255.0f;
93 const int int0 = int(value1);
94 const int int1 = int((value1 -
float(
int(value1))) * 255.0f);
95 const int int2 = int((value2 -
float(
int(value2))) * 255.0f);
96 const int int3 = int((value3 -
float(
int(value3))) * 255.0f);
98 ocean_assert(int0 >= 0 && int0 <= 255);
99 ocean_assert(int1 >= 0 && int1 <= 255);
100 ocean_assert(int2 >= 0 && int2 <= 255);
101 ocean_assert(int3 >= 0 && int3 <= 255);
103 decomposedValues[0] = uint8_t(int0);
104 decomposedValues[1] = uint8_t(int1);
105 decomposedValues[2] = uint8_t(int2);
106 decomposedValues[3] = uint8_t(int3);
111 ocean_assert(decomposedValues !=
nullptr);
113 return float(decomposedValues[0]) / 255.0f
114 + float(decomposedValues[1]) / (255.0f * 255.0f)
115 +
float(decomposedValues[2]) / (255.0f * 255.0f * 255.0f)
116 +
float(decomposedValues[3]) / (255.0f * 255.0f * 255.0f * 255.0f);
122 ocean_assert(transformation !=
nullptr && objects !=
nullptr && results !=
nullptr);
130 ocean_assert(transformation !=
nullptr && objects !=
nullptr && results !=
nullptr);
138 ocean_assert(transformation !=
nullptr && objects !=
nullptr && results !=
nullptr);
143template <
typename TTransformation,
typename TObject>
144inline void MathUtilities::transformSubset(
const TTransformation* transformation,
const TObject* objects, TObject* results,
const unsigned int firstObject,
const unsigned int numberObjects)
146 ocean_assert(transformation !=
nullptr && objects !=
nullptr && results !=
nullptr);
148 for (
unsigned int n = firstObject; n < firstObject + numberObjects; ++n)
150 results[n] = *transformation * objects[n];
static Caller< void > createStatic(typename StaticFunctionPointerMaker< void, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass >::Type function)
This class implements utility functions for the math library.
Definition MathUtilities.h:26
static void transformSubset(const TTransformation *transformation, const TObject *objects, TObject *results, const unsigned int firstObject, const unsigned int numberObjects)
Transforms a subset of several objects (e.g., 3D vector or 4D vectors) by a transformation object (e....
Definition MathUtilities.h:144
static void transform(const TTransformation &transformation, const std::vector< TObject > &objects, std::vector< TObject > &results, Worker *worker=nullptr, const unsigned int minimalObjectsPerThread=1000u)
Transforms several objects (e.g., 3D vector or 4D vectors) by a transformation object (e....
Definition MathUtilities.h:69
static void encodeFloatToUint8(const float value, uint8_t *decomposedValues)
Encodes a float value to four uint8 values.
Definition MathUtilities.h:84
static float decodeFloatFromUint8(const uint8_t *decomposedValues)
Decodes four uint8 values into a float value.
Definition MathUtilities.h:109
bool multiply(const VectorT2< float > &vector, VectorT2< float > &result) const
static void multiply(const SquareMatrixT4< double > &matrix, const VectorT4< double > *vectors, VectorT4< double > *results, const size_t number)
This class implements a worker able to distribute function calls over different threads.
Definition Worker.h:33
bool executeFunction(const Function &function, const unsigned int first, const unsigned int size, const unsigned int firstIndex=(unsigned int)(-1), const unsigned int sizeIndex=(unsigned int)(-1), const unsigned int minimalIterations=1u, const unsigned int threadIndex=(unsigned int)(-1))
Executes a callback function separable by two function parameters.
VectorT3< float > VectorF3
Definition of a 3D vector with float values.
Definition Vector3.h:43
VectorT4< double > VectorD4
Definition of a 4D vector with double values.
Definition Vector4.h:36
SquareMatrixT4< float > SquareMatrixF4
Instantiation of the SquareMatrixT4 template class using a double precision float data type.
Definition SquareMatrix4.h:53
SquareMatrixT4< double > SquareMatrixD4
Instantiation of the SquareMatrixT4 template class using a double precision float data type.
Definition SquareMatrix4.h:46
SquareMatrixT3< float > SquareMatrixF3
Instantiation of the SquareMatrixT3 template class using a single precision float data type.
Definition SquareMatrix3.h:57
VectorT4< float > VectorF4
Definition of a 4D vector with float values.
Definition Vector4.h:43
The namespace covering the entire Ocean framework.
Definition Accessor.h:15