SplineData Class Reference

#include <customgui_splinecontrol.h>

Inheritance diagram for SplineData:

Detailed Description

Spline data type (CUSTOMDATATYPE_SPLINE) for SplineCustomGui.

Note
Has to be created with Alloc() and destroyed with Free(). Use AutoAlloc to automate the allocation and destruction based on scope.

Private Member Functions

 SplineData ()
 
 ~SplineData ()
 

Alloc/Free

static SplineDataAlloc ()
 
static void Free (SplineData *&pData)
 

Knot

Int32 GetKnotCount () const
 
CustomSplineKnotGetKnot (Int32 l)
 
const CustomSplineKnotGetKnot (Int32 l) const
 
Bool SetKnot (Int32 l, const CustomSplineKnot &knot)
 
Int32 InsertKnot (Float x, Float y, Int32 lFlags=0)
 
Bool DeleteKnot (Int32 a)
 
void SortKnots (Int32 &lActiveKnot)
 
Int32 GetSelectCount () const
 

Point

Vector GetPoint (Float r) const
 
void DeleteAllPoints ()
 

Make Spline

Bool MakePointBuffer (Int32 lPoints=-1)
 
Bool MakeLinearSplineLinear (Int32 lPoints=-1)
 
Bool MakeLinearSplineBezier (Int32 lPoints=-1)
 
Bool MakeSquareSpline (Int32 lPoints=-1)
 
Bool MakeCubicSpline (Int32 lPoints=-1)
 
Bool MakeRootSpline (Int32 lPoints=-1)
 
Bool MakeInversSpline (Int32 lPoints=-1)
 
Bool MakeSinSpline (Int32 lPoints=-1)
 
Bool MakeAbsCosSpline (Int32 lPoints=-1)
 
Bool MakeUserSpline (const maxon::String &str, Int32 lPoints=-1)
 

Spline Knots Manipulation

void SelectAll ()
 
void Flip ()
 
void Mirror ()
 
void Minimum ()
 
void Maximum ()
 

Set Type/Zero

Bool SetType (Int32 id, Bool bAll=false)
 
Bool SetZero (Bool bY, Bool bAll=false)
 

Range

Bool GetRange (Float *xmin, Float *xmax, Float *xsteps, Float *ymin, Float *ymax, Float *ysteps) const
 
void SetRange (Float xmin, Float xmax, Float xsteps, Float ymin, Float ymax, Float ysteps)
 
void AdaptRange (Float xmin, Float xmax, Float xsteps, Float ymin, Float ymax, Float ysteps)
 

Tension

Float GetTension () const
 
void SetTension (Float tension)
 

User Callback

SplineDataCallback GetUserCallback (void *&pData) const
 
void SetUserCallback (SplineDataCallback fn, void *pData)
 

Miscellaneous

Bool CopyTo (SplineData *pDest)
 
Bool InitDefaultFlag (Int32 flag)
 

Constructor & Destructor Documentation

◆ SplineData()

SplineData ( )
private

◆ ~SplineData()

~SplineData ( )
private

Member Function Documentation

◆ Alloc()

static SplineData* Alloc ( )
static

Allocates a spline data. Destroy the allocated spline data with Free(). Use AutoAlloc to automate the allocation and destruction based on scope.

Returns
The allocated spline data, or nullptr if the allocation failed.

◆ Free()

static void Free ( SplineData *&  pData)
static

Destructs spline data allocated with Alloc(). Use AutoAlloc to automate the allocation and destruction based on scope.

Parameters
[in,out]pDataThe spline data to destruct. If the pointer is nullptr nothing happens. The pointer is assigned nullptr afterwards.

◆ GetKnotCount()

Int32 GetKnotCount ( ) const

Gets the number of knots .

Returns
The knot count.

◆ GetKnot() [1/2]

CustomSplineKnot* GetKnot ( Int32  l)

Gets the spline knot at position l.

Parameters
[in]lThe position index. 0 <= l < GetKnotCount()
Returns
The spline knot.

◆ GetKnot() [2/2]

const CustomSplineKnot* GetKnot ( Int32  l) const

◆ SetKnot()

Bool SetKnot ( Int32  l,
const CustomSplineKnot knot 
)

Sets the spline knot at position l.

Parameters
[in]lThe knot index. 0 <= l < GetKnotCount()
[in]knotThe spline knot.
Returns
true if the spline knot was successfully set, otherwise false.

◆ InsertKnot()

Int32 InsertKnot ( Float  x,
Float  y,
Int32  lFlags = 0 
)

Inserts a knot.

Parameters
[in]xThe X coordinate.
[in]yThe Y coordinate.
[in]lFlagsThe knot flags: FLAG_KNOT
Returns
The index of the inserted knot.

◆ DeleteKnot()

Bool DeleteKnot ( Int32  a)

Deletes a knot.

Parameters
[in]aThe index of the knot to delete. 0 <= a < GetKnotCount()
Returns
true if the knot was deleted successfully, otherwise false.

◆ SortKnots()

void SortKnots ( Int32 lActiveKnot)

Sorts the knots.

Parameters
[out]lActiveKnotAssigned the new index of the active knot.

◆ GetSelectCount()

Int32 GetSelectCount ( ) const

Gets the number of selected knots.

Returns
The selected knot count.

◆ GetPoint()

Vector GetPoint ( Float  r) const

Gets a point from its X coordinate.

Parameters
[in]rThe X coordinate.
Returns
The retrieved point.

◆ DeleteAllPoints()

void DeleteAllPoints ( )

Deletes all points.

◆ MakePointBuffer()

Bool MakePointBuffer ( Int32  lPoints = -1)

Makes an uninitialized spline with lPoints points.

Parameters
[in]lPointsThe number of points, or -1 to get the default value.
Returns
true if successful, otherwise false.

◆ MakeLinearSplineLinear()

Bool MakeLinearSplineLinear ( Int32  lPoints = -1)

Makes a linear spline with lPoints points. The spline knots' is linear.

Parameters
[in]lPointsThe number of points, or -1 to get the default value.
Returns
true if successful, otherwise false.

◆ MakeLinearSplineBezier()

Bool MakeLinearSplineBezier ( Int32  lPoints = -1)

Makes a linear spline with lPoints points. The spline knots' interpolation is Bezier.

Parameters
[in]lPointsThe number of points, or -1 to get the default value.
Returns
true if successful, otherwise false.

◆ MakeSquareSpline()

Bool MakeSquareSpline ( Int32  lPoints = -1)

Makes a square spline with lPoints points.

Parameters
[in]lPointsThe number of points, or -1 to get the default value.
Returns
true if successful, otherwise false.

◆ MakeCubicSpline()

Bool MakeCubicSpline ( Int32  lPoints = -1)

Makes a cubic spline with lPoints points.

Parameters
[in]lPointsThe number of points, or -1 to get the default value.
Returns
true if successful, otherwise false.

◆ MakeRootSpline()

Bool MakeRootSpline ( Int32  lPoints = -1)

Makes a root spline with lPoints points.

Parameters
[in]lPointsThe number of points, or -1 to get the default value.
Returns
true if successful, otherwise false.

◆ MakeInversSpline()

Bool MakeInversSpline ( Int32  lPoints = -1)

Makes an inverse spline with lPoints points.

Parameters
[in]lPointsThe number of points, or -1 to get the default value.
Returns
true if successful, otherwise false.

◆ MakeSinSpline()

Bool MakeSinSpline ( Int32  lPoints = -1)

Makes a sinus spline with lPoints points.

Parameters
[in]lPointsThe number of points, or -1 to get the default value.
Returns
true if successful, otherwise false.

◆ MakeAbsCosSpline()

Bool MakeAbsCosSpline ( Int32  lPoints = -1)

Makes an absolute cosine spline with lPoints points.

Parameters
[in]lPointsThe number of points, or -1 to get the default value.
Returns
true if successful, otherwise false.

◆ MakeUserSpline()

Bool MakeUserSpline ( const maxon::String str,
Int32  lPoints = -1 
)

Makes a user spline from str with lPoints number of points.

Parameters
[in]strThe user spline string. Any valid formula can be used.
[in]lPointsThe number of points, or -1 to get the default value.
Returns
true if successful, otherwise false.

◆ SelectAll()

void SelectAll ( )

Selects all points.

◆ Flip()

void Flip ( )

Flips the spline.

◆ Mirror()

void Mirror ( )

Mirrors the spline.

◆ Minimum()

void Minimum ( )

Makes all Y coordinates greater than or equal to 0.

◆ Maximum()

void Maximum ( )

Makes all Y coordinates less than or equal to 1.

◆ SetType()

Bool SetType ( Int32  id,
Bool  bAll = false 
)

Sets the interpolation type of the selected knots.

Parameters
[in]idThe interpolation type: SPLINE_TYPE
[in]bAllPass true to set all knots, false to set selected knots only.
Returns
true if successful, otherwise false.

◆ SetZero()

Bool SetZero ( Bool  bY,
Bool  bAll = false 
)

Sets the tangents of the selected knots to zero.

Parameters
[in]bYPass true to set the tangents' Y coordinate to zero, false to set the X coordinate.
[in]bAllPass true to set all tangents, false to set the tangents of selected knots only.
Returns
true if successful, otherwise false.

◆ GetRange()

Bool GetRange ( Float xmin,
Float xmax,
Float xsteps,
Float ymin,
Float ymax,
Float ysteps 
) const

Gets the range of the spline.

Warning
Only valid if the spline is shown in the spline GUI.
Parameters
[out]xminAssigned the minimum X value.
[out]xmaxAssigned the maximum X value.
[out]xstepsAssigned the X steps value.
[out]yminAssigned the minimum Y value.
[out]ymaxAssigned the maximum Y value.
[out]ystepsAssigned the Y steps value.
Returns
true if successful, otherwise false.

◆ SetRange()

void SetRange ( Float  xmin,
Float  xmax,
Float  xsteps,
Float  ymin,
Float  ymax,
Float  ysteps 
)

Sets the range of the spline.

Warning
Only valid if the spline is shown in the spline GUI.
Parameters
[in]xminThe minimum X value.
[in]xmaxThe maximum X value.
[in]xstepsThe X steps value.
[in]yminThe minimum Y value.
[in]ymaxThe maximum Y value.
[in]ystepsThe Y steps value.

◆ AdaptRange()

void AdaptRange ( Float  xmin,
Float  xmax,
Float  xsteps,
Float  ymin,
Float  ymax,
Float  ysteps 
)

Adapts the internal [0, 1] range of the old spline GUI to the range set by [xmin, xmax, ymin, ymax].

Warning
Only valid if the spline is shown in the spline GUI.
Parameters
[in]xminThe minimum X value.
[in]xmaxThe maximum X value.
[in]xstepsThe X steps value.
[in]yminThe minimum Y value.
[in]ymaxThe maximum Y value.
[in]ystepsThe Y steps value.

◆ GetTension()

Float GetTension ( ) const

Gets the tension value.

Returns
The tension value.

◆ SetTension()

void SetTension ( Float  tension)

Sets the tension value. Effective range goes from 0.0 (no tension - softer splines) to 1.0 (full tension - harder splines)

Parameters
[in]tensionThe new tension value.

◆ GetUserCallback()

SplineDataCallback GetUserCallback ( void *&  pData) const

Gets the user callback function pointer.

Parameters
[out]pDataAssigned the user data of the callback.
Returns
The user callback.

◆ SetUserCallback()

void SetUserCallback ( SplineDataCallback  fn,
void *  pData 
)

Sets the callback function to be called for events on the instance.

The callback must be setup each time a SplineData parameter is being initialized or gets a new instance assigned. See example below for details.

// The callback function which does clamp the SplineData.
//
// This callback is being invoked after a SplineData parameter has been modified to which this
// callback has been attached. It is being used in this case to clamp the tangents of the
// SplineData vertices, so that they cannot lie outside of the half-unit interval [0, 1]. The
// effect will be that the tangent handles will "snap back" when a user has set a handle to a value
// which does exceed that interval.
// Being demonstrated is a naive approach to such clamping, for more sensible results the tangent
// points would have to be projected onto that [0, 1] interval box instead of just being clamped
// to it.
//
// @param[in] cid The callback message id.
// @param[out] data The callback data. This will be pData when set up manually, otherwise it will
// be filled in by Cinema 4D.
static bool SplineDataCallBack(Int32 cid, const void* data)
{
// There are other callback types, in this case only SPLINE_CALLBACK_CORE_MESSAGE is being used.
{
// Cast the callback data into a SplineDataCallbackCoreMessage and extract the attached
// SplineData.
if (data == nullptr)
return true;
const SplineDataCallbackCoreMessage* coreMessageData = static_cast<const SplineDataCallbackCoreMessage*>(data);
SplineCustomGui* splineCustomGui = coreMessageData->pGUI;
if (splineCustomGui == nullptr)
return true;
SplineData* splineData = splineCustomGui->GetSplineData();
if (splineData == nullptr)
return true;
// Iterate over all vertices of the SplineData
for (int i = 0; i < splineData->GetKnotCount(); i++)
{
CustomSplineKnot* knot = splineData->GetKnot(i);
// Tangents live in a vector space relative to their vertex, so the tangent vertices are being
// converted to the global spline space first, and then clamped to that [0, 1] interval.
Vector globalLeftTangent = (knot->vPos + knot->vTangentLeft).Clamp01();
Vector globalRightTangent = (knot->vPos + knot->vTangentRight).Clamp01();
// Then the tangents are being converted back to their local vertex space and written back.
knot->vTangentLeft = globalLeftTangent - knot->vPos;
knot->vTangentRight = globalRightTangent - knot->vPos;
}
}
return true;
}
// Initializes some NodeData which does host a SplineData parameter that should be monitored by a
// callback function.
//
// The callback must be attached to all new SplineData instances which should be monitored. Common
// places to do this are NodeData::Init, NodeData::SetDParameter, etc., i.e., places where
// SplineData instances are being created or assigned to a parameter.
Bool SomeNode::Init(GeListNode* node)
{
if (node == nullptr || !SUPER::Init(node))
return false;
BaseContainer* bc = ((BaseList2D*)node)->GetDataInstance();
// Create a SplineData instance and set the callback function.
SplineData* splineData = static_cast<SplineData*>(geData.GetCustomDataType(CUSTOMDATATYPE_SPLINE));
// The second argument, pData, could also be defined manually, but in most cases it is not
// necessary to do this.
splineData->SetUserCallback(SplineDataCallBack, nullptr);
// And populate the the SplineData with a initialization value.
if (splineData)
splineData->MakeLinearSplineBezier(2);
bc->SetData(ID_SPLINEDATA, geData);
return true;
}
// Bind the callback when the SplineData parameter instance of SomeNode is being overwritten.
//
// Note that the SUPER typedef is only available after invoking the INSTANCEOF macro in the
// declaration of the NodeData for which it is being invoked, here SomeNode.
Bool SomeNode::SetDParameter(GeListNode* node, const DescID& id, const GeData& t_data,
DESCFLAGS_SET& flags)
{
if (id[0].id == ID_SPLINEDATA)
{
SplineData* splineData = static_cast<SplineData*>(t_data.GetCustomDataType(CUSTOMDATATYPE_SPLINE));
splineData->SetUserCallback(SplineDataCallBack, nullptr);
}
return SUPER::SetDParameter(node, id, t_data, flags);
}
@ DEFAULTVALUE
Dummy value for the default value GeData constructor.
Definition: c4d_gedata.h:65
Definition: c4d_basecontainer.h:47
GeData * SetData(Int32 id, const GeData &n)
Definition: c4d_basecontainer.h:255
Definition: c4d_baselist.h:2188
Definition: lib_description.h:331
Definition: c4d_gedata.h:83
CustomDataType * GetCustomDataType(Int32 datatype) const
Definition: c4d_gedata.h:507
Represents a C4DAtom that resides in a 4D list.
Definition: c4d_baselist.h:1811
Definition: customgui_splinecontrol.h:631
SplineData * GetSplineData(void)
Definition: customgui_splinecontrol.h:268
Int32 GetKnotCount() const
Bool MakeLinearSplineBezier(Int32 lPoints=-1)
void SetUserCallback(SplineDataCallback fn, void *pData)
Sets the callback function to be called for events on the instance.
CustomSplineKnot * GetKnot(Int32 l)
#define CUSTOMDATATYPE_SPLINE
Spline data type ID.
Definition: customgui_splinecontrol.h:23
maxon::Bool Bool
Definition: ge_sys_math.h:55
maxon::Int32 Int32
Definition: ge_sys_math.h:60
DESCFLAGS_SET
Definition: ge_prepass.h:3180
#define SPLINE_CALLBACK_CORE_MESSAGE
Called when core messages are sent. The corresponding data is SplineDataCallbackCoreMessage.
Definition: customgui_splinecontrol.h:45
Float32 Clamp01(Float32 a)
Clip a floating point number against the lower limit 0 and the upper limit 1. The result will be retu...
Definition: apibasemath.h:127
Represents a knot in a spline.
Definition: customgui_splinecontrol.h:209
Vector vPos
Knot position.
Definition: customgui_splinecontrol.h:219
Vector vTangentRight
Right tangent.
Definition: customgui_splinecontrol.h:225
Vector vTangentLeft
Left tangent.
Definition: customgui_splinecontrol.h:224
Callback struct for the SPLINE_CALLBACK_CORE_MESSAGE call.
Definition: customgui_splinecontrol.h:93
SplineCustomGui * pGUI
Custom GUI of the spline data.
Definition: customgui_splinecontrol.h:95
Parameters
[in]fnThe pointer to the callback function.
[in]pDataThe callback data. In most cases it is best, to pass in nullptr and let Cinema 4D fill in the data on callbacks.

◆ CopyTo()

Bool CopyTo ( SplineData pDest)

Copies this spline dat values into the destination spline data pDest.

Parameters
[in]pDestThe destination spline data. The caller owns the pointed spline data.
Returns
true if this spline data was successfully copied to pDest, otherwise false.

◆ InitDefaultFlag()

Bool InitDefaultFlag ( Int32  flag)

Initializes the knot flag for selected knots.

Parameters
[in]flagA combination of these flags: FLAG_KNOT
Returns
true if successful, otherwise false.