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);
68 template <
typename TTransformation,
typename TObject>
69 inline 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);
80 transformSubset<TTransformation, TObject>(&transformation, objects.data(), results.data(), 0u, (
unsigned int)objects.size());
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);
120 inline void MathUtilities::transformSubset<SquareMatrixF3, VectorF3>(
const SquareMatrixF3* transformation,
const VectorF3* objects,
VectorF3* results,
const unsigned int firstObject,
const unsigned int numberObjects)
122 ocean_assert(transformation !=
nullptr && objects !=
nullptr && results !=
nullptr);
128 inline void MathUtilities::transformSubset<SquareMatrixD4, VectorD4>(
const SquareMatrixD4* transformation,
const VectorD4* objects,
VectorD4* results,
const unsigned int firstObject,
const unsigned int numberObjects)
130 ocean_assert(transformation !=
nullptr && objects !=
nullptr && results !=
nullptr);
136 inline void MathUtilities::transformSubset<SquareMatrixF4, VectorF4>(
const SquareMatrixF4* transformation,
const VectorF4* objects,
VectorF4* results,
const unsigned int firstObject,
const unsigned int numberObjects)
138 ocean_assert(transformation !=
nullptr && objects !=
nullptr && results !=
nullptr);
143 template <
typename TTransformation,
typename TObject>
144 inline 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)
Creates a new caller container for a static function with no function parameter.
Definition: Caller.h:2876
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
This class implements a 3x3 square matrix.
Definition: SquareMatrix3.h:88
bool multiply(const VectorT2< T > &vector, VectorT2< T > &result) const
Multiplies a 2D vector with this matrix (from the right).
Definition: SquareMatrix3.h:1708
This class implements a 4x4 square matrix.
Definition: SquareMatrix4.h:85
static void multiply(const SquareMatrixT4< T > &matrix, const VectorT4< T > *vectors, VectorT4< T > *results, const size_t number)
Multiplies several 4D vectors with a given matrix.
Definition: SquareMatrix4.h:2561
This class implements a vector with three elements.
Definition: Vector3.h:97
This class implements a vector with four elements.
Definition: Vector4.h:97
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.
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15