Open Search
    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(ConstDescID(DescLevel(LOD_BAR)), rangeData, DESCFLAGS_GET::NONE))
    return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
    const RangeData* const rangeCustomData = rangeData.GetCustomDataType<RangeData>();
    if (rangeCustomData == nullptr)
    return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
    const Float currentValue = rangeCustomData->GetCurrentValue();
    ApplicationOutput("Value: " + String::FloatToString(currentValue));
    Definition: c4d_gedata.h:83
    const DATATYPE * GetCustomDataType() const
    Definition: c4d_gedata.h:542
    Definition: customgui_range.h:146
    Float GetCurrentValue() const
    static String FloatToString(Float32 v, Int32 vvk=-1, Int32 nnk=-3)
    Definition: c4d_string.h:529
    maxon::Float Float
    Definition: ge_sys_math.h:66
    #define MAXON_SOURCE_LOCATION
    Definition: memoryallocationbase.h:67
    #define ApplicationOutput(formatString,...)
    Definition: debugdiagnostics.h:210
    #define ConstDescID(...)
    Definition: lib_description.h:594
    @ LOD_BAR
    Definition: olod.h:8
    Represents a level within a DescID.
    Definition: lib_description.h:298

    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<RangeData>(rangeCustomData);
    lodObject->SetParameter(ConstDescID(DescLevel(LOD_BAR)), rangeGeData, DESCFLAGS_SET::NONE);
    Definition: ge_autoptr.h:37
    void SetCustomDataType(const DATATYPE &v)
    Definition: c4d_gedata.h:747
    @ LOD_MODE
    Definition: olod.h:6
    @ LOD_CRITERIA
    Definition: olod.h:7
    @ LOD_CRITERIA_SCREEN_H
    Definition: olod.h:30
    @ LOD_MODE_MANUAL_GROUPS
    Definition: olod.h:25

    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(ConstDescID(DescLevel(LOD_BAR)), rangeData, DESCFLAGS_GET::NONE);
    RangeData* const rangeCustomData = rangeData.GetCustomDataTypeWritable<RangeData>();
    if (rangeCustomData == nullptr)
    return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
    // User LOD Value
    // set value
    rangeCustomData->SetCurrentValue(0.5);
    lodObject->SetParameter(ConstDescID(DescLevel(LOD_BAR)), rangeData, DESCFLAGS_SET::NONE);
    DATATYPE * GetCustomDataTypeWritable()
    Definition: c4d_gedata.h:547
    void SetCurrentValue(Float value)
    @ LOD_CRITERIA_MANUAL_SLIDER
    Definition: olod.h:29

    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);
    void SetSelectedKnot(Int knotIndex)
    void Reset(Bool invalidateObject=false)
    Bool AddValue(Float value)

    A single knot can be selected:

    // This example deletes the currently selected knot.
    const Int knotIndex = rangeCustomData->GetSelectedKnot();
    rangeCustomData->DeleteKnot(knotIndex);
    Int GetSelectedKnot() const
    void DeleteKnot(Int knotIndex)
    maxon::Int Int
    Definition: ge_sys_math.h:64

    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);
    void SetRangeColor(Int index, const Vector &color)
    Int GetRangeIndex(Float value) const

    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);
    }
    Py_ssize_t i
    Definition: abstract.h:645
    Vector HSVToRGB(const Vector &col)
    void SetRandomColorMode(Bool random)
    Int GetRangesCount() const
    void SetColorMode(Bool perRange)

    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);
    RangePair GetRange(Int index) const
    Definition: customgui_range.h:85
    Float GetCenter() const
    Definition: customgui_range.h:131

    Further Reading