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 TFactor>
153 template <
typename T,
typename TKey>
154 static T
lagrange2(
const TKey& x0,
const T& y0,
const TKey& x1,
const T& y1,
const TKey& x);
169 template <
typename T,
typename TKey>
170 static T
lagrange3(
const TKey& x0,
const T& y0,
const TKey& x1,
const T& y1,
const TKey& x2,
const T& y2,
const TKey& x);
180template <
typename TKey,
typename TValue,
typename TFactor>
233 inline size_t size()
const;
269 inline bool hasValue(
const TKey& key)
const;
278 inline TValue&
value(
const TKey& key);
285 inline bool remove(
const TKey& key);
294 inline bool insert(
const TKey& key,
const TValue&
value,
const bool forceOverwrite =
false);
303 inline bool insert(
const TKey& key, TValue&&
value,
const bool forceOverwrite =
false);
310 inline TValue
linear(
const TKey& key)
const;
381template <
typename TFactor>
386 return v0 * (TFactor(1) - t) + v1 * t;
395 return float(v0 * (1.0 - t)) + float(v1 * t);
399template <
typename TFactor>
411 v0.
decompose(translation0, rotation0, scale0, shear0);
412 v1.
decompose(translation1, rotation1, scale1, shear1);
414 return HomogenousMatrixT4<float>(linear(translation0, translation1, t), linear(rotation0, rotation1, t), linear(scale0, scale1, t), linear(shear0, shear1, t));
418template <
typename TFactor>
430 v0.
decompose(translation0, rotation0, scale0, shear0);
431 v1.
decompose(translation1, rotation1, scale1, shear1);
433 return HomogenousMatrixT4<double>(linear(translation0, translation1, t), linear(rotation0, rotation1, t), linear(scale0, scale1, t), linear(shear0, shear1, t));
437template <
typename TFactor>
442 return std::make_pair(linear(v0.first, v1.first, t), linear(v0.second, v1.second, t));
446template <
typename TFactor>
451 return std::make_pair(linear(v0.first, v1.first, t), linear(v0.second, v1.second, t));
455template <
typename TFactor>
460 return std::make_pair(linear(v0.first, v1.first, t), linear(v0.second, v1.second, t));
464template <
typename TFactor>
469 return std::make_pair(linear(v0.first, v1.first, t), linear(v0.second, v1.second, t));
473template <
typename TFactor>
482template <
typename TFactor>
488 return v0.
slerp(v1,
float(t));
492template <
typename TFactor>
498 return v0.
slerp(v1,
double(t));
502template <
typename TFactor>
512template <
typename TFactor>
521template <
typename T,
typename TFactor>
524 ocean_assert(t >= TFactor(0) && t <= TFactor(1));
538template <
typename T,
typename TFactor>
544template <
typename T,
typename TFactor>
545inline 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)
547 ocean_assert(valid00 || valid01 || valid10 || valid11);
549 ocean_assert(valid00 == 1 || valid00 == 0);
550 ocean_assert(valid01 == 1 || valid01 == 0);
551 ocean_assert(valid10 == 1 || valid10 == 0);
552 ocean_assert(valid11 == 1 || valid11 == 0);
554 const unsigned int state = (
unsigned int)(valid00) | ((
unsigned int)(valid01) << 8) | ((
unsigned int)(valid10) << 16) | ((
unsigned int)(valid11) << 24);
561 return bilinear(v00, v01, v10, v11, tx, ty);
586 return linear(v10, v11, tx);
591 return linear(v00, v10, ty);
596 return linear(v00, v01, tx);
601 return linear(v01, v11, ty);
607 return linear(v10, v01,
VectorT2<TFactor>(tx, TFactor(1) - ty).length() * TFactor(0.70710678118654752440084436210485));
639 ocean_assert(
false &&
"Invalid interpolation statement!");
643template <
typename T,
typename TFactor>
648 return (v0 * TFactor(-0.5) + v1 * TFactor(1.5) - v2 * TFactor(1.5) + v3 * TFactor(0.5)) * t * t * t
649 + (v0 - v1 * TFactor(2.5) + v2 * TFactor(2) - v3 * TFactor(0.5)) * t * t
650 + (v0 * TFactor(-0.5) + v2 * TFactor(0.5)) * t
654template <
typename T,
typename TFactor>
674 return interpolated_R_v1 * v1;
677template <
typename T,
typename TKey>
682 return (y0 * (x1 - x) + y1 * (x - x0)) * (TKey(1) / (x1 - x0));
685template <
typename T,
typename TKey>
690 return y0 * ((x - x1) * (x - x2)) * (TKey(1) / ((x0 - x1) * (x0 - x2)))
691 + y1 * ((x - x0) * (x - x2)) * (TKey(1) / ((x1 - x0) * (x1 - x2)))
692 + y2 * ((x - x0) * (x - x1)) * (TKey(1) / ((x2 - x0) * (x2 - x1)));
695template <
typename TKey,
typename TValue,
typename TFactor>
701template <
typename TKey,
typename TValue,
typename TFactor>
703 valueMap_(interpolationMap.valueMap_)
708template <
typename TKey,
typename TValue,
typename TFactor>
710 valueMap_(std::move(interpolationMap.valueMap_))
715template <
typename TKey,
typename TValue,
typename TFactor>
722template <
typename TKey,
typename TValue,
typename TFactor>
724 valueMap_(std::move(valueMap))
729template <
typename TKey,
typename TValue,
typename TFactor>
732 return valueMap_.size();
735template <
typename TKey,
typename TValue,
typename TFactor>
738 return valueMap_.empty();
741template <
typename TKey,
typename TValue,
typename TFactor>
747template <
typename TKey,
typename TValue,
typename TFactor>
753template <
typename TKey,
typename TValue,
typename TFactor>
756 valueMap_ = interpolationMap;
759template <
typename TKey,
typename TValue,
typename TFactor>
762 valueMap_ = std::move(interpolationMap);
765template <
typename TKey,
typename TValue,
typename TFactor>
768 return valueMap_.find(key) != valueMap_.end();
771template <
typename TKey,
typename TValue,
typename TFactor>
774 return valueMap_[key];
777template <
typename TKey,
typename TValue,
typename TFactor>
780 return valueMap_.erase(key) != 0;
783template <
typename TKey,
typename TValue,
typename TFactor>
788 valueMap_[key] = value;
792 if (valueMap_.find(key) != valueMap_.end())
797 valueMap_[key] = value;
802template <
typename TKey,
typename TValue,
typename TFactor>
807 valueMap_[key] = std::move(value);
811 if (valueMap_.find(key) != valueMap_.end())
816 valueMap_[key] = std::move(value);
821template <
typename TKey,
typename TValue,
typename TFactor>
824 return linear(valueMap_, key);
827template <
typename TKey,
typename TValue,
typename TFactor>
830 return linear(valueMap_, key, interpolationFunction);
833template <
typename TKey,
typename TValue,
typename TFactor>
836 if (valueMap.empty())
841 const typename ValueMap::const_iterator iHigher = valueMap.lower_bound(key);
844 if (iHigher == valueMap.end())
846 ocean_assert(valueMap.rbegin() != valueMap.rend());
847 return valueMap.rbegin()->second;
851 if (iHigher == valueMap.begin())
853 return iHigher->second;
858 typename ValueMap::const_iterator iLower(iHigher);
861 TFactor width = TFactor(iHigher->first - iLower->first);
863 ocean_assert(width > 0);
864 ocean_assert(key > iLower->first);
866 TFactor interpolationFactor = TFactor(key - iLower->first) / width;
867 ocean_assert(interpolationFactor >= TFactor(0) && interpolationFactor <= TFactor(1));
872template <
typename TKey,
typename TValue,
typename TFactor>
875 ocean_assert(interpolationFunction);
877 if (valueMap.empty() || !interpolationFunction)
882 const typename ValueMap::const_iterator iHigher = valueMap.lower_bound(key);
885 if (iHigher == valueMap.end())
887 ocean_assert(valueMap.rbegin() != valueMap.rend());
888 return valueMap.rbegin()->second;
892 if (iHigher == valueMap.begin())
894 return iHigher->second;
899 typename ValueMap::const_iterator iLower(iHigher);
902 TFactor width = TFactor(iHigher->first - iLower->first);
904 ocean_assert(width > 0);
905 ocean_assert(key > iLower->first);
907 TFactor interpolationFactor = TFactor(key - iLower->first) / width;
908 ocean_assert(interpolationFactor >= TFactor(0) && interpolationFactor <= TFactor(1));
910 return interpolationFunction(iLower->second, iHigher->second, interpolationFactor);
913template <
typename TKey,
typename TValue,
typename TFactor>
920template <
typename TKey,
typename TValue,
typename TFactor>
925 valueMap_ = std::move(
object.valueMap_);
931template <
typename TKey,
typename TValue,
typename TFactor>
934 return valueMap_ ==
object.valueMap_;
937template <
typename TKey,
typename TValue,
typename TFactor>
940 return !(*
this == object);
943template <
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:382
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:644
static T linear(const T &v0, const T &v1, const TFactor &t)
Performs a linear interpolation between two values.
Definition Interpolation.h:522
static VectorT3< T > spherical(const VectorT3< T > &v0, const VectorT3< T > &v1, const TFactor &t)
Performs a spherical linear interpolation (SLERP) between two unit vectors.
Definition Interpolation.h:655
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:539
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:678
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:686
This class implements an interpolation map allowing to determine an interpolated value between severa...
Definition Interpolation.h:182
void clear()
Clears all elements (pairs of keys and values) of this interpolation map object.
Definition Interpolation.h:742
TValue & value(const TKey &key)
Returns the value of this interpolation map object defined by a corresponding key.
Definition Interpolation.h:772
bool operator==(const InterpolationMap< TKey, TValue, TFactor > &object) const
Returns whether two interpolation objects are equal.
Definition Interpolation.h:932
TValue(*)(const TValue &, const TValue &, const TFactor &) LinearInterpolationFunction
Definition of a function pointer for a function providing a linear interpolation.
Definition Interpolation.h:196
const ValueMap & interpolationMap() const
Returns the entire internal interpolation map.
Definition Interpolation.h:748
bool isEmpty() const
Returns whether this interpolation map object is empty.
Definition Interpolation.h:736
InterpolationMap()
Default constructor.
Definition Interpolation.h:696
void setInterpolationMap(const ValueMap &interpolationMap)
Sets or changes the entire internal interpolation map.
Definition Interpolation.h:754
InterpolationMap< TKey, TValue, TFactor > & operator=(const InterpolationMap< TKey, TValue, TFactor > &object)
Assign operator.
Definition Interpolation.h:914
bool hasValue(const TKey &key) const
Returns whether this interpolation map object holds a value for a specified key.
Definition Interpolation.h:766
std::map< TKey, TValue > ValueMap
Definition of a map mapping keys to values.
Definition Interpolation.h:188
bool remove(const TKey &key)
Removes an elements (pair of key and value) from this interpolation map object.
Definition Interpolation.h:778
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:784
TValue linear(const TKey &key) const
Returns the linear interpolation of the stored values for a given key.
Definition Interpolation.h:822
bool operator!=(const InterpolationMap< TKey, TValue, TFactor > &object) const
Returns whether two interpolation objects are not equal.
Definition Interpolation.h:938
size_t size() const
Returns the number of elements (pairs of keys and values) of this interpolation map.
Definition Interpolation.h:730
ValueMap valueMap_
Map mapping keys to values.
Definition Interpolation.h:377
TValue & operator[](const TKey &key)
Returns the value of this interpolation map object defined by a corresponding key.
Definition Interpolation.h:944
This class provides basic numeric functionalities.
Definition Numeric.h:57
static constexpr bool isInsideRange(const T lower, const T value, const T upper, const T epsilon=NumericT< T >::eps())
Returns whether a value lies between a given range up to a provided epsilon border.
Definition Numeric.h:2881
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:882
QuaternionT< T > slerp(const QuaternionT< T > &quaternion, T factor) const
Spherical linear interpolation between two quaternions.
Definition Quaternion.h:848
This class implements a axis-angle rotation using floating point values.
Definition Rotation.h:73
static RotationT< T > left_R_right(const VectorT3< T > &left, const VectorT3< T > &right)
Returns a rotation object based on two given unit vectors.
Definition Rotation.h:705
VectorT3< T > axis() const
Returns the axis of the rotation.
Definition Rotation.h:643
T angle() const
Returns the angle of the rotation.
Definition Rotation.h:649
bool isValid() const
Returns whether this rotation has valid parameters.
Definition Rotation.h:547
This class implements a vector with two elements.
Definition Vector2.h:96
This class implements a vector with three elements.
Definition Vector3.h:97
bool isUnit(const T eps=NumericT< T >::eps()) const
Returns whether this vector is a unit vector (whether the vector has the length 1).
Definition Vector3.h:873
PoseT< Scalar > Pose
Definition of the Pose object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION flag either with sing...
Definition Pose.h:31
The namespace covering the entire Ocean framework.
Definition Accessor.h:15