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...
 
typedef DataType ValueType
 The template parameter value type. More...
 
typedef SplineKey< DataType > Key
 Type definition of the animation key data type. More...
 

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. More...
 
CurveType mCurveType
 The current curve type. More...
 
WrapMode mWrapMode
 The current wrap mode. More...
 
DataType mCurrentValue
 The current interpolated value. More...
 

Detailed Description

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

A template base class for spline interpolations.

Member Typedef Documentation

◆ ValueType

template<class DataType>
typedef DataType Murl::Math::SplineBase< DataType >::ValueType

The template parameter value type.

◆ Key

template<class DataType>
typedef SplineKey<DataType> Murl::Math::SplineBase< DataType >::Key

Type definition of the animation key data type.

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.

◆ GetCurveType()

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

Get the current curve type.

Returns
The current curve type.

◆ SetWrapMode()

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

Set the current wrap mode.

Parameters
wrapModeThe wrap mode to set.

◆ GetWrapMode()

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

Get the current wrap mode.

Returns
The current wrap mode.

◆ 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::SplineKey< DataType >::mTime.

◆ 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.

◆ 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.

◆ 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.

◆ 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::SplineKey< DataType >::mTime.

◆ 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.

◆ 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::SplineKey< DataType >::mTime.

◆ GetNumberOfKeys()

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

Get the number of keys.

Returns
The number of keys.

◆ 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.

◆ Interpolate()

template<class DataType>
virtual const DataType& Murl::Math::SplineBase< DataType >::Interpolate ( Double  time)
inlinevirtual

Get the interpolated value at a specific time.

Parameters
timeThe time for the interpolation value in seconds.
Returns
The the interpolated value.

References Murl::Math::Clamp(), Murl::Math::Fmod(), and Murl::Math::SplineKey< DataType >::mTime.

◆ 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.

◆ 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.

◆ 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.

◆ GetPrevKey()

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

Get the previous key for a specified index depending on the curve type and the wrap mode.

Parameters
indexThe index.
Returns
The previous key.

References Murl::Math::SplineKey< DataType >::mTime, and Murl::Math::SplineKey< DataType >::mValue.

Referenced by Murl::Math::SplineHermite< DataType >::CalculateControlPoint(), and Murl::Math::SplineBezier< DataType >::CalculateControlPoint().

◆ GetNextKey()

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

Get the next key for a specified index depending on the curve type and the wrap mode.

Parameters
indexThe index.
Returns
The previous key.

References Murl::Math::SplineKey< DataType >::mTime, and Murl::Math::SplineKey< DataType >::mValue.

Referenced by Murl::Math::SplineHermite< DataType >::CalculateControlPoint(), and Murl::Math::SplineBezier< DataType >::CalculateControlPoint().

◆ 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::SplineKey< DataType >::mTime.

Member Data Documentation

◆ mKeys

template<class DataType>
Array<Key> Murl::Math::SplineBase< DataType >::mKeys
protected

◆ mCurveType

template<class DataType>
CurveType Murl::Math::SplineBase< DataType >::mCurveType
protected

The current curve type.

◆ mWrapMode

template<class DataType>
WrapMode Murl::Math::SplineBase< DataType >::mWrapMode
protected

The current wrap mode.

◆ mCurrentValue

template<class DataType>
DataType Murl::Math::SplineBase< DataType >::mCurrentValue
protected

The documentation for this class was generated from the following file:
  • murl_math_spline_base.h


Copyright © 2011-2018 Spraylight GmbH.