Murl::Math::SplineBase< DataType > Class Template Referenceabstract

A template base class for spline interpolations. More...

#include "murl_math_spline_base.h"

Inheritance diagram for Murl::Math::SplineBase< DataType >:

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 KeyGetKey (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< KeymKeys
 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

template<class DataType >
enum Murl::Math::SplineBase::WrapMode

Enumeration of the wrap modes.

Enumerator
WRAP_NONE 

No wrapping.

WRAP_CLAMP_TO_EDGE 

Clamp if time lies outside of the defined curve.

WRAP_REPEAT 

Repeat infinitely in either direction.

WRAP_REPEAT_MIRRORED 

Repeat infinitely in either direction, flipping each time.

◆ CurveType

template<class DataType >
enum Murl::Math::SplineBase::CurveType

Enumeration of the curve type.

Enumerator
CURVE_DEFAULT 

Use p[0]/p[n-1] to calculate the control points for first/last point.

CURVE_CLOSED 

Closed curve, use p[n-2]/p[1] to calculate the control points for first/last point.

Constructor & Destructor Documentation

◆ SplineBase() [1/2]

template<class DataType >
Murl::Math::SplineBase< DataType >::SplineBase ( )
inline

The default constructor.

The default wrap mode is CLAMP_TO_EDGE. The default curve type is CURVE_DEFAULT.

◆ SplineBase() [2/2]

template<class DataType >
Murl::Math::SplineBase< DataType >::SplineBase ( WrapMode  wrapMode,
CurveType  curveType 
)
inline

Constructor taking the wrap mode and the curve type.

Parameters
wrapModeThe wrapMode.
curveTypeThe curveType.

Member Function Documentation

◆ SetCurveType()

template<class DataType >
void Murl::Math::SplineBase< DataType >::SetCurveType ( CurveType  curveType)
inline

Set the current curve type.

Parameters
curveTypeThe curve type to set.

References Murl::Math::SplineBase< DataType >::mCurveType.

◆ GetCurveType()

template<class DataType >
CurveType Murl::Math::SplineBase< DataType >::GetCurveType ( ) const
inline

Get the current curve type.

Returns
The current curve type.

References Murl::Math::SplineBase< DataType >::mCurveType.

◆ SetWrapMode()

template<class DataType >
void Murl::Math::SplineBase< DataType >::SetWrapMode ( WrapMode  wrapMode)
inline

Set the current wrap mode.

Parameters
wrapModeThe wrap mode to set.

References Murl::Math::SplineBase< DataType >::mWrapMode.

◆ GetWrapMode()

template<class DataType >
WrapMode Murl::Math::SplineBase< DataType >::GetWrapMode ( ) const
inline

Get the current wrap mode.

Returns
The current wrap mode.

References Murl::Math::SplineBase< DataType >::mWrapMode.

◆ AddKey() [1/2]

template<class DataType >
SInt32 Murl::Math::SplineBase< DataType >::AddKey ( const Key key)
inline

Add a new interpolation key.

The key is inserted into the sorted key array according to the time value.

Parameters
keyThe 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]

template<class DataType >
SInt32 Murl::Math::SplineBase< DataType >::AddKey ( Real  time,
const DataType &  value 
)
inline

Add a new interpolation key.

The key is inserted into the sorted key array according to the time value.

Parameters
timeThe time for the key in seconds.
valueThe value for the key.
Returns
The index of the key.

References Murl::Math::SplineBase< DataType >::AddKey().

◆ RemoveKey()

template<class DataType >
Bool Murl::Math::SplineBase< DataType >::RemoveKey ( SInt32  index)
inline

Remove a key at a specified index.

Parameters
indexThe zero-based index.
Returns
true if successful, false if the index is invalid.

References Murl::Math::SplineBase< DataType >::mKeys.

◆ SetKeyValue()

template<class DataType >
Bool Murl::Math::SplineBase< DataType >::SetKeyValue ( SInt32  index,
const DataType &  value 
)
inline

Set a key's value for a specified index.

Parameters
indexThe zero-based index.
valueThe value to set.
Returns
true if successful, false if the index is invalid.

References Murl::Math::SplineBase< DataType >::mKeys.

◆ SetKey() [1/2]

template<class DataType >
SInt32 Murl::Math::SplineBase< DataType >::SetKey ( SInt32  index,
const Key key 
)
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
indexThe zero-based index.
keyThe 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]

template<class DataType >
SInt32 Murl::Math::SplineBase< DataType >::SetKey ( SInt32  index,
Real  time,
const DataType &  value 
)
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
indexThe zero-based index.
timeThe time for the key in seconds.
valueThe value to set.
Returns
The new index of the key, -1 if the index is invalid.

References Murl::Math::SplineBase< DataType >::SetKey().

◆ CopyKeys()

template<class DataType >
void Murl::Math::SplineBase< DataType >::CopyKeys ( const SplineBase< DataType > &  source)
inline

Copy the keys from a spline object.

Overwrites this object's keys with the source keys.

Parameters
sourceThe source spline object.

References Murl::Math::SplineBase< DataType >::mKeys.

◆ GetKeyIndex()

template<class DataType >
SInt32 Murl::Math::SplineBase< DataType >::GetKeyIndex ( Real  time) const
inline

Get the nearest key index for a specified time.

Parameters
timeThe time in seconds.
Returns
The index of the key.

References Murl::Math::SplineBase< DataType >::FindIndex(), and Murl::Math::SplineBase< DataType >::mKeys.

◆ GetNumberOfKeys()

template<class DataType >
SInt32 Murl::Math::SplineBase< DataType >::GetNumberOfKeys ( ) const
inline

Get the number of keys.

Returns
The number of keys.

References Murl::Math::SplineBase< DataType >::mKeys.

◆ GetKey()

template<class DataType >
const Key& Murl::Math::SplineBase< DataType >::GetKey ( SInt32  index) const
inline

Get a key for a specified index.

Parameters
indexThe zero-based index in range [0 .. GetNumberOfKeys()-1].
Returns
The key at the specified index.

References Murl::Math::SplineBase< DataType >::mKeys.

◆ Interpolate()

◆ UpdateControlPoints()

template<class DataType >
Bool Murl::Math::SplineBase< DataType >::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()

template<class DataType >
void Murl::Math::SplineBase< DataType >::SetControlPointsValid ( Bool  areValid)
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
areValidThe control points valid state.

◆ CalculateControlPoints()

template<class DataType >
virtual Bool Murl::Math::SplineBase< DataType >::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()

template<class DataType >
virtual void Murl::Math::SplineBase< DataType >::InterpolateCurrentValue ( Double  time,
SInt32  timeIndex 
)
protectedpure virtual

Override point to update the current value for a specified time.

Parameters
timeThe time to interpolate.
timeIndexThe index to the nearest key which is greater or equal the time.

Referenced by Murl::Math::SplineBase< DataType >::Interpolate().

◆ GetPrevKey()

template<class DataType >
Key Murl::Math::SplineBase< DataType >::GetPrevKey ( SInt32  index) const
inlineprotected

◆ GetNextKey()

template<class DataType >
Key Murl::Math::SplineBase< DataType >::GetNextKey ( SInt32  index) const
inlineprotected

◆ FindIndex()

template<class DataType >
SInt32 Murl::Math::SplineBase< DataType >::FindIndex ( Real  time) const
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
timeThe 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


Copyright © 2011-2024 Spraylight GmbH.