A template base class for spline interpolations. More...
#include "murl_math_spline_base.h"
Public Types | |
enum | WrapMode { WRAP_NONE , WRAP_CLAMP_TO_EDGE , WRAP_REPEAT , WRAP_REPEAT_MIRRORED } |
Enumeration of the wrap modes. More... | |
enum | CurveType { CURVE_DEFAULT , CURVE_CLOSED } |
Enumeration of the curve type. More... | |
using | ValueType = DataType |
The template parameter value type. | |
using | Key = SplineKey< DataType > |
Type definition of the animation key data type. | |
Public Member Functions | |
SplineBase () | |
The default constructor. More... | |
SplineBase (WrapMode wrapMode, CurveType curveType) | |
Constructor taking the wrap mode and the curve type. More... | |
virtual | ~SplineBase () |
The destructor. | |
void | SetCurveType (CurveType curveType) |
Set the current curve type. More... | |
CurveType | GetCurveType () const |
Get the current curve type. More... | |
void | SetWrapMode (WrapMode wrapMode) |
Set the current wrap mode. More... | |
WrapMode | GetWrapMode () const |
Get the current wrap mode. More... | |
SInt32 | AddKey (const Key &key) |
Add a new interpolation key. More... | |
SInt32 | AddKey (Real time, const DataType &value) |
Add a new interpolation key. More... | |
Bool | RemoveKey (SInt32 index) |
Remove a key at a specified index. More... | |
Bool | SetKeyValue (SInt32 index, const DataType &value) |
Set a key's value for a specified index. More... | |
SInt32 | SetKey (SInt32 index, const Key &key) |
Set a key for a specified index. More... | |
SInt32 | SetKey (SInt32 index, Real time, const DataType &value) |
Set a key for a specified index. More... | |
void | CopyKeys (const SplineBase< DataType > &source) |
Copy the keys from a spline object. More... | |
SInt32 | GetKeyIndex (Real time) const |
Get the nearest key index for a specified time. More... | |
SInt32 | GetNumberOfKeys () const |
Get the number of keys. More... | |
const Key & | GetKey (SInt32 index) const |
Get a key for a specified index. More... | |
void | EmptyKeys () |
Empty the keys, but keep the underlying storage. | |
void | ClearKeys () |
Clear the keys and remove the underlying storage. | |
virtual const DataType & | Interpolate (Double time) |
Get the interpolated value at a specific time. More... | |
Bool | UpdateControlPoints () |
Update the control points immediately. More... | |
void | SetControlPointsValid (Bool areValid) |
Set the control points valid state. More... | |
Protected Member Functions | |
virtual Bool | CalculateControlPoints ()=0 |
Override point for updating control points if the keys or the wrap mode or the curve type changed. More... | |
virtual void | InterpolateCurrentValue (Double time, SInt32 timeIndex)=0 |
Override point to update the current value for a specified time. More... | |
Key | GetPrevKey (SInt32 index) const |
Get the previous key for a specified index depending on the curve type and the wrap mode. More... | |
Key | GetNextKey (SInt32 index) const |
Get the next key for a specified index depending on the curve type and the wrap mode. More... | |
SInt32 | FindIndex (Real time) const |
Find the index using binary search O(log n). More... | |
Protected Attributes | |
Array< Key > | mKeys |
The key array stores all given keys sorted according to the time value. | |
CurveType | mCurveType |
The current curve type. | |
WrapMode | mWrapMode |
The current wrap mode. | |
DataType | mCurrentValue |
The current interpolated value. | |
Detailed Description
template<class DataType>
class Murl::Math::SplineBase< DataType >
A template base class for spline interpolations.
Member Enumeration Documentation
◆ WrapMode
enum Murl::Math::SplineBase::WrapMode |
◆ CurveType
enum Murl::Math::SplineBase::CurveType |
Constructor & Destructor Documentation
◆ SplineBase() [1/2]
|
inline |
The default constructor.
The default wrap mode is CLAMP_TO_EDGE. The default curve type is CURVE_DEFAULT.
◆ SplineBase() [2/2]
|
inline |
Constructor taking the wrap mode and the curve type.
- Parameters
-
wrapMode The wrapMode. curveType The curveType.
Member Function Documentation
◆ SetCurveType()
|
inline |
Set the current curve type.
- Parameters
-
curveType The curve type to set.
References Murl::Math::SplineBase< DataType >::mCurveType.
◆ GetCurveType()
|
inline |
Get the current curve type.
- Returns
- The current curve type.
References Murl::Math::SplineBase< DataType >::mCurveType.
◆ SetWrapMode()
|
inline |
Set the current wrap mode.
- Parameters
-
wrapMode The wrap mode to set.
References Murl::Math::SplineBase< DataType >::mWrapMode.
◆ GetWrapMode()
|
inline |
Get the current wrap mode.
- Returns
- The current wrap mode.
References Murl::Math::SplineBase< DataType >::mWrapMode.
◆ AddKey() [1/2]
|
inline |
Add a new interpolation key.
The key is inserted into the sorted key array according to the time value.
- Parameters
-
key The key to copy and add.
- Returns
- The index of the key.
References Murl::Math::SplineBase< DataType >::FindIndex(), Murl::Math::SplineBase< DataType >::mKeys, and Murl::Math::SplineKey< DataType >::mTime.
Referenced by Murl::Math::SplineBase< DataType >::AddKey().
◆ AddKey() [2/2]
|
inline |
Add a new interpolation key.
The key is inserted into the sorted key array according to the time value.
- Parameters
-
time The time for the key in seconds. value The value for the key.
- Returns
- The index of the key.
References Murl::Math::SplineBase< DataType >::AddKey().
◆ RemoveKey()
|
inline |
Remove a key at a specified index.
- Parameters
-
index The zero-based index.
- Returns
- true if successful, false if the index is invalid.
References Murl::Math::SplineBase< DataType >::mKeys.
◆ SetKeyValue()
|
inline |
Set a key's value for a specified index.
- Parameters
-
index The zero-based index. value The value to set.
- Returns
- true if successful, false if the index is invalid.
References Murl::Math::SplineBase< DataType >::mKeys.
◆ SetKey() [1/2]
|
inline |
Set a key for a specified index.
The key is set into the sorted key array according to the key's time value, therefore the key's index may change which is returned.
- Parameters
-
index The zero-based index. key The key to copy and set.
- Returns
- The new index of the key, -1 if the index is invalid.
References Murl::Math::SplineBase< DataType >::FindIndex(), Murl::Math::SplineBase< DataType >::mKeys, and Murl::Math::SplineKey< DataType >::mTime.
Referenced by Murl::Math::SplineBase< DataType >::SetKey().
◆ SetKey() [2/2]
|
inline |
Set a key for a specified index.
The key is set into the sorted key array according to the time value, therefore the key's index may change which is returned.
- Parameters
-
index The zero-based index. time The time for the key in seconds. value The value to set.
- Returns
- The new index of the key, -1 if the index is invalid.
References Murl::Math::SplineBase< DataType >::SetKey().
◆ CopyKeys()
|
inline |
Copy the keys from a spline object.
Overwrites this object's keys with the source keys.
- Parameters
-
source The source spline object.
References Murl::Math::SplineBase< DataType >::mKeys.
◆ GetKeyIndex()
|
inline |
Get the nearest key index for a specified time.
- Parameters
-
time The time in seconds.
- Returns
- The index of the key.
References Murl::Math::SplineBase< DataType >::FindIndex(), and Murl::Math::SplineBase< DataType >::mKeys.
◆ GetNumberOfKeys()
|
inline |
Get the number of keys.
- Returns
- The number of keys.
References Murl::Math::SplineBase< DataType >::mKeys.
◆ GetKey()
|
inline |
Get a key for a specified index.
- Parameters
-
index The zero-based index in range [0 .. GetNumberOfKeys()-1].
- Returns
- The key at the specified index.
References Murl::Math::SplineBase< DataType >::mKeys.
◆ Interpolate()
|
inlinevirtual |
Get the interpolated value at a specific time.
- Parameters
-
time The time for the interpolation value in seconds.
- Returns
- The the interpolated value.
References Murl::Math::Clamp(), Murl::Math::SplineBase< DataType >::FindIndex(), Murl::Math::Fmod(), Murl::Math::SplineBase< DataType >::InterpolateCurrentValue(), Murl::Math::SplineBase< DataType >::mCurrentValue, Murl::Math::SplineBase< DataType >::mKeys, Murl::Math::SplineBase< DataType >::mWrapMode, Murl::Math::SplineBase< DataType >::UpdateControlPoints(), Murl::Math::SplineBase< DataType >::WRAP_CLAMP_TO_EDGE, Murl::Math::SplineBase< DataType >::WRAP_REPEAT, and Murl::Math::SplineBase< DataType >::WRAP_REPEAT_MIRRORED.
◆ UpdateControlPoints()
|
inline |
Update the control points immediately.
The countrol points are updated automatically during Interpolate() if necessary, this method is used to update the control points before calling Interpolate().
- Returns
- true if the control points are valid.
References Murl::Math::SplineBase< DataType >::CalculateControlPoints().
Referenced by Murl::Math::SplineBase< DataType >::Interpolate().
◆ SetControlPointsValid()
|
inline |
Set the control points valid state.
Every modification of the key's time or value invalidates the control points. This method is used to suppress automatic updating of the control points, if manually modification of the control points is required.
- Parameters
-
areValid The control points valid state.
◆ CalculateControlPoints()
|
protectedpure virtual |
Override point for updating control points if the keys or the wrap mode or the curve type changed.
- Returns
- true if the control points are updated successful.
Referenced by Murl::Math::SplineBase< DataType >::UpdateControlPoints().
◆ InterpolateCurrentValue()
|
protectedpure virtual |
Override point to update the current value for a specified time.
- Parameters
-
time The time to interpolate. timeIndex The index to the nearest key which is greater or equal the time.
Referenced by Murl::Math::SplineBase< DataType >::Interpolate().
◆ GetPrevKey()
|
inlineprotected |
Get the previous key for a specified index depending on the curve type and the wrap mode.
- Parameters
-
index The index.
- Returns
- The previous key.
References Murl::Math::SplineBase< DataType >::CURVE_CLOSED, Murl::Math::SplineBase< DataType >::mCurveType, Murl::Math::SplineBase< DataType >::mKeys, Murl::Math::SplineBase< DataType >::mWrapMode, and Murl::Math::SplineBase< DataType >::WRAP_REPEAT_MIRRORED.
Referenced by Murl::Math::SplineBezier< DataType >::CalculateControlPoint(), and Murl::Math::SplineHermite< DataType >::CalculateControlPoint().
◆ GetNextKey()
|
inlineprotected |
Get the next key for a specified index depending on the curve type and the wrap mode.
- Parameters
-
index The index.
- Returns
- The previous key.
References Murl::Math::SplineBase< DataType >::CURVE_CLOSED, Murl::Math::SplineBase< DataType >::mCurveType, Murl::Math::SplineBase< DataType >::mKeys, Murl::Math::SplineBase< DataType >::mWrapMode, and Murl::Math::SplineBase< DataType >::WRAP_REPEAT_MIRRORED.
Referenced by Murl::Math::SplineBezier< DataType >::CalculateControlPoint(), and Murl::Math::SplineHermite< DataType >::CalculateControlPoint().
◆ FindIndex()
|
inlineprotected |
Find the index using binary search O(log n).
Returns the index of the nearest key that is greater or equal to the given time.
- Parameters
-
time The time to search for.
- Returns
- The index of the nearest key in the range [0, mKeys.GetCount()].
References Murl::Math::SplineBase< DataType >::mKeys.
Referenced by Murl::Math::SplineBase< DataType >::AddKey(), Murl::Math::SplineBase< DataType >::GetKeyIndex(), Murl::Math::SplineBase< DataType >::Interpolate(), and Murl::Math::SplineBase< DataType >::SetKey().
The documentation for this class was generated from the following file:
- murl_math_spline_base.h