RangeData Manual

About

The RangeData stores data on ranges and on the current value within these ranges. It is typically used with the LodObject. The RangeData class is defined in the customgui_range.h header file. The ID is CUSTOMDATATYPE_RANGE.

Access

RangeData data is typically accessed from a LodObject. See LodObject Manual.

// This example reads the range data from the given LOD object.
GeData rangeData;
if (!lodObject->GetParameter(LOD_BAR, rangeData, DESCFLAGS_GET::NONE))
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
CustomDataType* const customData = rangeData.GetCustomDataType(CUSTOMDATATYPE_RANGE);
RangeData* const rangeCustomData = static_cast<RangeData*>(customData);
if (rangeCustomData == nullptr)
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
const Float currentValue = rangeCustomData->GetCurrentValue();
ApplicationOutput("Value: " + String::FloatToString(currentValue));

Allocation/Deallocation

RangeData objects are created with the usual tools, see Entity Creation and Destruction Manual (Classic).

A RangeData object must be initialized:

// This example configures the given LOD object and defines the
// number of manual groups using the RangeData data.
// create custom data
AutoAlloc<RangeData> rangeCustomData;
if (rangeCustomData == nullptr)
return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION);
// configure LodObject
// configure range data
if (!rangeCustomData->Init(10))
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
// store to LodObject
GeData rangeGeData;
rangeGeData.SetCustomDataType(CUSTOMDATATYPE_RANGE, rangeCustomData);
lodObject->SetParameter(LOD_BAR, rangeGeData, DESCFLAGS_SET::NONE);

Value

A RangeData stores a value between 0.0 and 1.0:

// This example sets the current, user defined value of the range slider.
// get range data
GeData rangeData;
lodObject->GetParameter(LOD_BAR, rangeData, DESCFLAGS_GET::NONE);
CustomDataType* const customData = rangeData.GetCustomDataType(CUSTOMDATATYPE_RANGE);
RangeData* const rangeCustomData = static_cast<RangeData*>(customData);
if (rangeCustomData == nullptr)
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
// User LOD Value
// set value
rangeCustomData->SetCurrentValue(0.5);
lodObject->SetParameter(LOD_BAR, rangeData, DESCFLAGS_SET::NONE);

Knots

Multiple knots can be added to a RangeData object. These knots define the borders of the ranges.

// This example clears the given RangeData and
// adds two new knots.
// clear
rangeCustomData->Reset();
// add knots
rangeCustomData->AddValue(0.33);
rangeCustomData->AddValue(0.66);
// set selection
rangeCustomData->SetSelectedKnot(0);

A single knot can be selected:

// This example deletes the currently selected knot.
const Int knotIndex = rangeCustomData->GetSelectedKnot();
rangeCustomData->DeleteKnot(knotIndex);

Ranges

Value ranges are defined as the space confined by knots:

// This example sets the color of the range containing the current value.
// get current range
const Float currentValue = rangeCustomData->GetCurrentValue();
const Int currentRange = rangeCustomData->GetRangeIndex(currentValue);
// set color
const Vector color { 1.0, 0.0, 0.0 };
rangeCustomData->SetRangeColor(currentRange, color);

Color Modes

The ranges between knots can be colored in different ways:

// This example assigns a new color to each range.
// set mode
rangeCustomData->SetRandomColorMode(false);
rangeCustomData->SetColorMode(true);
// get number of ranges
const Int rangeCount = rangeCustomData->GetRangesCount();
const Float colorStep = 1.0 / Float(rangeCount);
// set color of each range
for (Int i = 0; i < rangeCount; ++i)
{
const Vector hsv { Float(i) * colorStep, 1.0, 1.0 };
const Vector rgb = HSVToRGB(hsv);
rangeCustomData->SetRangeColor(i, rgb);
}

RangePair

The dimensions of a range are stored with a RangePair object:

The RangePair class includes:

// This example sets the current value to the center
// of the current range.
// get current value and range
const Float currentValue = rangeCustomData->GetCurrentValue();
const Int currentRange = rangeCustomData->GetRangeIndex(currentValue);
// get range center
const RangePair rData = rangeCustomData->GetRange(currentRange);
const Float centerValue = rData.GetCenter();
// set value
rangeCustomData->SetCurrentValue(centerValue);

Further Reading

String::FloatToString
static String FloatToString(Float32 v, Int32 vvk=-1, Int32 nnk=-3)
Definition: c4d_string.h:526
LOD_MODE_MANUAL_GROUPS
@ LOD_MODE_MANUAL_GROUPS
Definition: olod.h:25
RangeData::GetCurrentValue
Float GetCurrentValue() const
Int
maxon::Int Int
Definition: ge_sys_math.h:49
GeData::SetCustomDataType
void SetCustomDataType(Int32 datatype, const CustomDataType &v)
Definition: c4d_gedata.h:636
RangeData
Definition: customgui_range.h:141
LOD_CRITERIA
@ LOD_CRITERIA
Definition: olod.h:7
RangeData::AddValue
Bool AddValue(Float value)
Float
maxon::Float Float
Definition: ge_sys_math.h:51
MAXON_SOURCE_LOCATION
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:66
HSVToRGB
Vector HSVToRGB(const Vector &col)
LOD_BAR
@ LOD_BAR
Definition: olod.h:8
DESCFLAGS_SET::NONE
@ NONE
None.
RangeData::SetSelectedKnot
void SetSelectedKnot(Int knotIndex)
RangeData::GetSelectedKnot
Int GetSelectedKnot() const
RangeData::SetCurrentValue
void SetCurrentValue(Float value)
RangeData::SetColorMode
void SetColorMode(Bool perRange)
RangePair::GetCenter
Float GetCenter() const
Definition: customgui_range.h:127
C4DAtom::SetParameter
Bool SetParameter(const DescID &id, const GeData &t_data, DESCFLAGS_SET flags)
maxon::Vec3< maxon::Float64, 1 >
RangeData::Init
Bool Init(Int rangeNumber)
CUSTOMDATATYPE_RANGE
static const Int32 CUSTOMDATATYPE_RANGE
RangeData ID.
Definition: customgui_range.h:19
RangeData::SetRandomColorMode
void SetRandomColorMode(Bool random)
RangeData::GetRangeIndex
Int GetRangeIndex(Float value) const
GeData
Definition: c4d_gedata.h:77
LOD_CRITERIA_MANUAL_SLIDER
@ LOD_CRITERIA_MANUAL_SLIDER
Definition: olod.h:29
RangePair
Definition: customgui_range.h:80
ApplicationOutput
#define ApplicationOutput(formatString,...)
Definition: debugdiagnostics.h:209
RangeData::DeleteKnot
void DeleteKnot(Int knotIndex)
CustomDataType
Base class for custom data types.
Definition: c4d_customdatatype.h:46
LOD_MODE
@ LOD_MODE
Definition: olod.h:6
AutoAlloc
Definition: ge_autoptr.h:32
RangeData::SetRangeColor
void SetRangeColor(Int index, const Vector &color)
DESCFLAGS_GET::NONE
@ NONE
None.
GeData::GetCustomDataType
CustomDataType * GetCustomDataType(Int32 datatype) const
Definition: c4d_gedata.h:485
LOD_CRITERIA_SCREEN_H
@ LOD_CRITERIA_SCREEN_H
Definition: olod.h:30
RangeData::Reset
void Reset(Bool invalidateObject=false)
RangeData::GetRange
RangePair GetRange(Int index) const
C4DAtom::GetParameter
Bool GetParameter(const DescID &id, GeData &t_data, DESCFLAGS_GET flags)
RangeData::GetRangesCount
Int GetRangesCount() const