8 #ifndef META_OCEAN_MATH_INTERPOLATION_H
9 #define META_OCEAN_MATH_INTERPOLATION_H
49 template <
typename TFactor>
50 static inline T
interpolate(
const T& v0,
const T& v1,
const TFactor& t);
64 template <
typename T,
typename TFactor>
65 static inline T
linear(
const T& v0,
const T& v1,
const TFactor& t);
84 template <
typename T,
typename TFactor>
85 static inline T
bilinear(
const T& v00,
const T& v01,
const T& v10,
const T& v11,
const TFactor& tx,
const TFactor& ty);
111 template <
typename T,
typename TFactor>
112 static inline T
bilinear(
const T& v00,
const T& v01,
const T& v10,
const T& v11,
const bool valid00,
const bool valid01,
const bool valid10,
const bool valid11,
const TFactor& tx,
const TFactor& ty);
125 template <
typename T,
typename TFactor>
126 static inline T
cubic(
const T& v0,
const T& v1,
const T& v2,
const T& v3,
const TFactor& t);
139 template <
typename T,
typename TKey>
140 static T
lagrange2(
const TKey& x0,
const T& y0,
const TKey& x1,
const T& y1,
const TKey& x);
155 template <
typename T,
typename TKey>
156 static T
lagrange3(
const TKey& x0,
const T& y0,
const TKey& x1,
const T& y1,
const TKey& x2,
const T& y2,
const TKey& x);
166 template <
typename TKey,
typename TValue,
typename TFactor>
219 inline size_t size()
const;
255 inline bool hasValue(
const TKey& key)
const;
264 inline TValue&
value(
const TKey& key);
271 inline bool remove(
const TKey& key);
280 inline bool insert(
const TKey& key,
const TValue&
value,
const bool forceOverwrite =
false);
289 inline bool insert(
const TKey& key, TValue&&
value,
const bool forceOverwrite =
false);
296 inline TValue
linear(
const TKey& key)
const;
366 template <
typename T>
367 template <
typename TFactor>
372 return v0 * (TFactor(1) - t) + v1 * t;
381 return float(v0 * (1.0 - t)) + float(v1 * t);
385 template <
typename TFactor>
397 v0.
decompose(translation0, rotation0, scale0, shear0);
398 v1.
decompose(translation1, rotation1, scale1, shear1);
400 return HomogenousMatrixT4<float>(linear(translation0, translation1, t), linear(rotation0, rotation1, t), linear(scale0, scale1, t), linear(shear0, shear1, t));
404 template <
typename TFactor>
416 v0.
decompose(translation0, rotation0, scale0, shear0);
417 v1.
decompose(translation1, rotation1, scale1, shear1);
419 return HomogenousMatrixT4<double>(linear(translation0, translation1, t), linear(rotation0, rotation1, t), linear(scale0, scale1, t), linear(shear0, shear1, t));
423 template <
typename TFactor>
428 return std::make_pair(linear(v0.first, v1.first, t), linear(v0.second, v1.second, t));
432 template <
typename TFactor>
437 return std::make_pair(linear(v0.first, v1.first, t), linear(v0.second, v1.second, t));
441 template <
typename TFactor>
446 return std::make_pair(linear(v0.first, v1.first, t), linear(v0.second, v1.second, t));
450 template <
typename TFactor>
455 return std::make_pair(linear(v0.first, v1.first, t), linear(v0.second, v1.second, t));
459 template <
typename TFactor>
468 template <
typename TFactor>
474 return v0.
slerp(v1,
float(t));
478 template <
typename TFactor>
484 return v0.
slerp(v1,
double(t));
488 template <
typename TFactor>
498 template <
typename TFactor>
507 template <
typename T,
typename TFactor>
510 ocean_assert(t >= TFactor(0) && t <= TFactor(1));
524 template <
typename T,
typename TFactor>
525 inline T
Interpolation::bilinear(
const T& v00,
const T& v01,
const T& v10,
const T& v11,
const TFactor& tx,
const TFactor& ty)
530 template <
typename T,
typename TFactor>
531 inline T
Interpolation::bilinear(
const T& v00,
const T& v01,
const T& v10,
const T& v11,
const bool valid00,
const bool valid01,
const bool valid10,
const bool valid11,
const TFactor& tx,
const TFactor& ty)
533 ocean_assert(valid00 || valid01 || valid10 || valid11);
535 ocean_assert(valid00 == 1 || valid00 == 0);
536 ocean_assert(valid01 == 1 || valid01 == 0);
537 ocean_assert(valid10 == 1 || valid10 == 0);
538 ocean_assert(valid11 == 1 || valid11 == 0);
540 const unsigned int state = (
unsigned int)(valid00) | ((
unsigned int)(valid01) << 8) | ((
unsigned int)(valid10) << 16) | ((
unsigned int)(valid11) << 24);
547 return bilinear(v00, v01, v10, v11, tx, ty);
572 return linear(v10, v11, tx);
577 return linear(v00, v10, ty);
582 return linear(v00, v01, tx);
587 return linear(v01, v11, ty);
593 return linear(v10, v01,
Vector2(tx, 1 - ty).length() *
Scalar(0.70710678118654752440084436210485));
599 return linear(v00, v11,
Vector2(tx, ty).length() *
Scalar(0.70710678118654752440084436210485));
622 ocean_assert(
false &&
"Invalid interpolation statement!");
626 template <
typename T,
typename TFactor>
631 return (v0 * TFactor(-0.5) + v1 * TFactor(1.5) - v2 * TFactor(1.5) + v3 * TFactor(0.5)) * t * t * t
632 + (v0 - v1 * TFactor(2.5) + v2 * TFactor(2) - v3 * TFactor(0.5)) * t * t
633 + (v0 * TFactor(-0.5) + v2 * TFactor(0.5)) * t
637 template <
typename T,
typename TKey>
642 return (y0 * (x1 - x) + y1 * (x - x0)) * (TKey(1) / (x1 - x0));
645 template <
typename T,
typename TKey>
650 return y0 * ((x - x1) * (x - x2)) * (TKey(1) / ((x0 - x1) * (x0 - x2)))
651 + y1 * ((x - x0) * (x - x2)) * (TKey(1) / ((x1 - x0) * (x1 - x2)))
652 + y2 * ((x - x0) * (x - x1)) * (TKey(1) / ((x2 - x0) * (x2 - x1)));
655 template <
typename TKey,
typename TValue,
typename TFactor>
661 template <
typename TKey,
typename TValue,
typename TFactor>
663 interpolationValueMap(interpolationMap.interpolationValueMap)
668 template <
typename TKey,
typename TValue,
typename TFactor>
670 interpolationValueMap(std::move(interpolationMap.interpolationValueMap))
675 template <
typename TKey,
typename TValue,
typename TFactor>
677 interpolationValueMap(valueMap)
682 template <
typename TKey,
typename TValue,
typename TFactor>
684 interpolationValueMap(std::move(valueMap))
689 template <
typename TKey,
typename TValue,
typename TFactor>
692 return interpolationValueMap.size();
695 template <
typename TKey,
typename TValue,
typename TFactor>
698 return interpolationValueMap.empty();
701 template <
typename TKey,
typename TValue,
typename TFactor>
704 interpolationValueMap.clear();
707 template <
typename TKey,
typename TValue,
typename TFactor>
710 return interpolationValueMap;
713 template <
typename TKey,
typename TValue,
typename TFactor>
716 interpolationValueMap = interpolationMap;
719 template <
typename TKey,
typename TValue,
typename TFactor>
722 interpolationValueMap = std::move(interpolationMap);
725 template <
typename TKey,
typename TValue,
typename TFactor>
728 return interpolationValueMap.find(key) != interpolationValueMap.end();
731 template <
typename TKey,
typename TValue,
typename TFactor>
734 return interpolationValueMap[key];
737 template <
typename TKey,
typename TValue,
typename TFactor>
740 return interpolationValueMap.erase(key) != 0;
743 template <
typename TKey,
typename TValue,
typename TFactor>
748 interpolationValueMap[key] = value;
752 if (interpolationValueMap.find(key) != interpolationValueMap.end())
757 interpolationValueMap[key] = value;
762 template <
typename TKey,
typename TValue,
typename TFactor>
767 interpolationValueMap[key] = std::move(value);
771 if (interpolationValueMap.find(key) != interpolationValueMap.end())
776 interpolationValueMap[key] = std::move(value);
781 template <
typename TKey,
typename TValue,
typename TFactor>
784 return linear(interpolationValueMap, key);
787 template <
typename TKey,
typename TValue,
typename TFactor>
790 return linear(interpolationValueMap, key, interpolationFunction);
793 template <
typename TKey,
typename TValue,
typename TFactor>
796 if (valueMap.empty())
801 const typename ValueMap::const_iterator iHigher = valueMap.lower_bound(key);
804 if (iHigher == valueMap.end())
806 ocean_assert(valueMap.rbegin() != valueMap.rend());
807 return valueMap.rbegin()->second;
811 if (iHigher == valueMap.begin())
813 return iHigher->second;
818 typename ValueMap::const_iterator iLower(iHigher);
821 TFactor width = TFactor(iHigher->first - iLower->first);
823 ocean_assert(width > 0);
824 ocean_assert(key > iLower->first);
826 TFactor interpolationFactor = TFactor(key - iLower->first) / width;
827 ocean_assert(interpolationFactor >= TFactor(0) && interpolationFactor <= TFactor(1));
832 template <
typename TKey,
typename TValue,
typename TFactor>
835 ocean_assert(interpolationFunction);
837 if (valueMap.empty() || !interpolationFunction)
842 const typename ValueMap::const_iterator iHigher = valueMap.lower_bound(key);
845 if (iHigher == valueMap.end())
847 ocean_assert(valueMap.rbegin() != valueMap.rend());
848 return valueMap.rbegin()->second;
852 if (iHigher == valueMap.begin())
854 return iHigher->second;
859 typename ValueMap::const_iterator iLower(iHigher);
862 TFactor width = TFactor(iHigher->first - iLower->first);
864 ocean_assert(width > 0);
865 ocean_assert(key > iLower->first);
867 TFactor interpolationFactor = TFactor(key - iLower->first) / width;
868 ocean_assert(interpolationFactor >= TFactor(0) && interpolationFactor <= TFactor(1));
870 return interpolationFunction(iLower->second, iHigher->second, interpolationFactor);
873 template <
typename TKey,
typename TValue,
typename TFactor>
876 interpolationValueMap =
object.interpolationValueMap;
880 template <
typename TKey,
typename TValue,
typename TFactor>
885 interpolationValueMap = std::move(
object.interpolationValueMap);
891 template <
typename TKey,
typename TValue,
typename TFactor>
894 return interpolationValueMap ==
object.interpolationValueMap;
897 template <
typename TKey,
typename TValue,
typename TFactor>
900 return !(*
this == object);
903 template <
typename TKey,
typename TValue,
typename TFactor>
This class implements a 4x4 homogeneous transformation matrix using floating point values with the pr...
Definition: HomogenousMatrix4.h:110
bool isValid() const
Returns whether this matrix is a valid homogeneous transformation.
Definition: HomogenousMatrix4.h:1806
bool decompose(VectorT3< T > &translation, QuaternionT< T > &rotation, VectorT3< T > &scale, VectorT3< T > &shear) const
Decomposes the transformation matrix into translation, rotation, scale and shear parameters.
Definition: HomogenousMatrix4.h:1407
This class implements a helper linear interpolation helper class allowing to overload the interpolati...
Definition: Interpolation.h:38
static T interpolate(const T &v0, const T &v1, const TFactor &t)
Performs a linear interpolation between two values.
Definition: Interpolation.h:368
This class implements data interpolation functions.
Definition: Interpolation.h:29
static T cubic(const T &v0, const T &v1, const T &v2, const T &v3, const TFactor &t)
Performs a cubic (Catmull-Rom) interpolation between mainly two values while two further supporting p...
Definition: Interpolation.h:627
static T linear(const T &v0, const T &v1, const TFactor &t)
Performs a linear interpolation between two values.
Definition: Interpolation.h:508
static T bilinear(const T &v00, const T &v01, const T &v10, const T &v11, const TFactor &tx, const TFactor &ty)
Performs a bi-linear interpolation between four values within a 2x2 neighborhood.
Definition: Interpolation.h:525
static T lagrange2(const TKey &x0, const T &y0, const TKey &x1, const T &y1, const TKey &x)
Performs a Lagrange interpolation for a polynomial with degree 2.
Definition: Interpolation.h:638
static T lagrange3(const TKey &x0, const T &y0, const TKey &x1, const T &y1, const TKey &x2, const T &y2, const TKey &x)
Performs a Lagrange interpolation for a polynomial with degree 3.
Definition: Interpolation.h:646
This class implements an interpolation map allowing to determine an interplated value between several...
Definition: Interpolation.h:168
void clear()
Clears all elements (pairs of keys and values) of this interpolation map object.
Definition: Interpolation.h:702
std::map< TKey, TValue > ValueMap
Definition of a map mapping keys to values.
Definition: Interpolation.h:174
TValue & value(const TKey &key)
Returns the value of this interpolation map object defined by a corresponding key.
Definition: Interpolation.h:732
bool operator==(const InterpolationMap< TKey, TValue, TFactor > &object) const
Returns whether two interpolation objects are equal.
Definition: Interpolation.h:892
const ValueMap & interpolationMap() const
Returns the entire internal interpolation map.
Definition: Interpolation.h:708
bool isEmpty() const
Returns whether this interpolation map object is empty.
Definition: Interpolation.h:696
InterpolationMap()
Default constructor.
Definition: Interpolation.h:656
void setInterpolationMap(const ValueMap &interpolationMap)
Sets or changes the entire internal interpolation map.
Definition: Interpolation.h:714
InterpolationMap< TKey, TValue, TFactor > & operator=(const InterpolationMap< TKey, TValue, TFactor > &object)
Assign operator.
Definition: Interpolation.h:874
bool hasValue(const TKey &key) const
Returns whether this interpolation map object holds a value for a specified key.
Definition: Interpolation.h:726
ValueMap interpolationValueMap
Map mapping keys to values.
Definition: Interpolation.h:363
TValue(* LinearInterpolationFunction)(const TValue &, const TValue &, const TFactor &)
Definition of a function pointer for a function providing a linear interpolation.
Definition: Interpolation.h:182
bool remove(const TKey &key)
Removes an elements (pair of key and value) from this interpolation map object.
Definition: Interpolation.h:738
bool insert(const TKey &key, const TValue &value, const bool forceOverwrite=false)
Inserts a new pair of key and value to this map object.
Definition: Interpolation.h:744
TValue linear(const TKey &key) const
Returns the linear interpolation of the stored values for a given key.
Definition: Interpolation.h:782
bool operator!=(const InterpolationMap< TKey, TValue, TFactor > &object) const
Returns whether two interpolation objects are not equal.
Definition: Interpolation.h:898
size_t size() const
Returns the number of elements (pairs of keys and values) of this interpolation map.
Definition: Interpolation.h:690
TValue & operator[](const TKey &key)
Returns the value of this interpolation map object defined by a corresponding key.
Definition: Interpolation.h:904
This class provides basic numeric functionalities.
Definition: Numeric.h:57
VectorT3< T > translation() const
Returns the translation of this pose.
Definition: Pose.h:422
QuaternionT< T > orientation() const
Returns the orientation of this pose.
This class implements a unit quaternion rotation.
Definition: Quaternion.h:100
bool isValid() const
Returns whether this quaternion is a valid unit quaternion.
Definition: Quaternion.h:899
QuaternionT< T > slerp(const QuaternionT< T > &quaternion, T factor) const
Spherical linear interpolation between two quaternions.
Definition: Quaternion.h:865
This class implements a axis-angle rotation using floating point values.
Definition: Rotation.h:79
bool isValid() const
Returns whether this rotation has valid parameters.
Definition: Rotation.h:665
This class implements a vector with three elements.
Definition: Vector3.h:97
float Scalar
Definition of a scalar type.
Definition: Math.h:128
PoseT< Scalar > Pose
Definition of the Pose object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION flag either with sing...
Definition: Pose.h:31
VectorT2< Scalar > Vector2
Definition of a 2D vector.
Definition: Vector2.h:21
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15