Open Search
    SortedGradientKnots< T_Float, T_Int > Class Template Reference

    #include <gradientmath.h>

    Detailed Description

    template<typename T_Float, typename T_Int>
    class maxon::SortedGradientKnots< T_Float, T_Int >

    This class organizes a collection of gradient knots. Knots can be added in arbitrary order and are sorted as a finalization step. To avoid re-ordering data associated with the knots, e.g. colors, we maintain the original indices for data lookup.

    Template Parameters
    T_FloatThe type of real-valued position, recommended are Float, Float32 and Float64.
    T_IntThe type of index, recommended are Int, Int32 and Int64. We recommend to match the bitdepth of index and position.

    Public Types

    using FloatType = T_Float
     
    using IntType = T_Int
     
    using IndexedKnotType = IndexedGradientKnot< FloatType, IntType >
     

    Public Member Functions

    void Reset ()
     
    Result< void > ReserveMemory (IntType numKnots)
     
    Result< void > InsertKnot (FloatType position)
     
    const IndexedKnotTypeGetSampleKnot (FloatType samplePosition) const
     
    const IndexedKnotTypeGetLeft (const IndexedKnotType &knot) const
     
    const IndexedKnotTypeGetRight (const IndexedKnotType &knot) const
     
    const IndexedKnotTypeGetKnot (IntType knotIndex) const
     
    IntType GetCount () const
     
    Bool IsEmpty () const
     
    Result< void > Sort ()
     

    Private Attributes

    BaseArray< IndexedKnotType_knots
     
    BaseArray< T_Int > _inversePermutation
     

    Member Typedef Documentation

    ◆ FloatType

    using FloatType = T_Float

    ◆ IntType

    using IntType = T_Int

    ◆ IndexedKnotType

    Member Function Documentation

    ◆ Reset()

    void Reset ( )

    Removes all knots.

    ◆ ReserveMemory()

    Result<void> ReserveMemory ( IntType  numKnots)

    Allocates the memory required for knot storage. If the amount of knots is known beforehand we recommend to pre-allocate memory to avoid any memory allocations during knot insertion.

    Parameters
    [in]numKnotsThe number of knots to reserve memory for.
    Returns
    OK on success.

    ◆ InsertKnot()

    Result<void> InsertKnot ( FloatType  position)

    Inserts a knot at the provided position. The index of the knot is implicit.ertion.

    Parameters
    [in]positionThe position of the knot.
    Returns
    OK on success.

    ◆ GetSampleKnot()

    const IndexedKnotType& GetSampleKnot ( FloatType  samplePosition) const

    Return the knot left to the requested position if there is one. If there is none, the knot right next to the requested position is returned. Please note that this function is unsafe for empty gradients.

    Parameters
    [in]samplePositionThe requested position.
    Returns
    The requested knot.

    ◆ GetLeft()

    const IndexedKnotType& GetLeft ( const IndexedKnotType knot) const

    Return the knot left to a knot if there is one. If not, the knot itself is returned. Please note that this function is unsafe for empty gradients.

    Parameters
    [in]knotThe knot to query.
    Returns
    The requested neighboring knot.

    ◆ GetRight()

    const IndexedKnotType& GetRight ( const IndexedKnotType knot) const

    Return the knot right to a knot if there is one. If not, the knot itself is returned. Please note that this function is unsafe for empty gradients.

    Parameters
    [in]knotThe knot to query.
    Returns
    The requested neighboring knot.

    ◆ GetKnot()

    const IndexedKnotType& GetKnot ( IntType  knotIndex) const

    Returns the knot at a specific index.

    Parameters
    [in]knotIndexThe index of the knot to retrieve.
    Returns
    The requested knot.

    ◆ GetCount()

    IntType GetCount ( ) const

    Returns the number of knots contained.

    Returns
    The number of knots.

    ◆ IsEmpty()

    Bool IsEmpty ( ) const

    Checks whether the knot series is empty.

    Returns
    True if there are no knots.

    ◆ Sort()

    Result<void> Sort ( )

    Sorts the knots in ascending order. The original ordering from knot insertion is preserved as an inverse permutation for later data lookup with the original indices.

    Returns
    OK on success.

    Member Data Documentation

    ◆ _knots

    BaseArray<IndexedKnotType> _knots
    private

    ◆ _inversePermutation

    BaseArray<T_Int> _inversePermutation
    private