ACF $AcfVersion:0$
Public Types | Public Member Functions | List of all members
icmm::TColorGradient< GradientFunction > Class Template Reference

Simple implementation of color gradient based on interpolation between start and end colors. More...

#include <TColorGradient.h>

Inheritance diagram for icmm::TColorGradient< GradientFunction >:
icmm::IColorTransformation imath::TIMathFunction< icmm::CVarColor, icmm::CVarColor > istd::IPolymorphic

Public Types

typedef IColorTransformation::ResultType GradientColor
 
- Public Types inherited from imath::TIMathFunction< icmm::CVarColor, icmm::CVarColor >
typedef icmm::CVarColor ArgumentType
 
typedef icmm::CVarColor ResultType
 

Public Member Functions

 TColorGradient (const GradientColor &startColor, const GradientColor &endColor)
 
virtual bool GetValueAt (const ArgumentType &argument, ResultType &result) const override
 
virtual ResultType GetValueAt (const ArgumentType &argument) const override
 
- Public Member Functions inherited from imath::TIMathFunction< icmm::CVarColor, icmm::CVarColor >
virtual bool GetValueAt (const icmm::CVarColor &argument, icmm::CVarColor &result) const=0
 Get function value for specified argument value.
 
virtual icmm::CVarColor GetValueAt (const icmm::CVarColor &argument) const=0
 Get function value for specified argument value.
 
- Public Member Functions inherited from istd::IPolymorphic
virtual ~IPolymorphic ()
 

Detailed Description

template<class GradientFunction>
class icmm::TColorGradient< GradientFunction >

Simple implementation of color gradient based on interpolation between start and end colors.

Purpose

TColorGradient provides smooth color transitions between two colors using linear or custom interpolation functions. It implements IColorTransformation, allowing it to generate intermediate colors based on a parameter value (typically 0 to 1).

Design

The gradient is parameterized by:

Usage Examples

// Example 1: Simple linear gradient from red to blue
red.SetElement(0, 1.0); // R
red.SetElement(1, 0.0); // G
red.SetElement(2, 0.0); // B
blue.SetElement(0, 0.0); // R
blue.SetElement(1, 0.0); // G
blue.SetElement(2, 1.0); // B
icmm::CLinearColorGradient gradient(red, blue);
// Get color at 50% (purple)
icmm::CVarColor param(1);
param.SetElement(0, 0.5);
icmm::CVarColor midColor;
gradient.GetValueAt(param, midColor);
// midColor = {0.5, 0.0, 0.5} - purple
// Example 2: Creating a color ramp
QList<icmm::CVarColor> CreateColorRamp(
const icmm::CVarColor& start,
const icmm::CVarColor& end,
int steps)
{
icmm::CLinearColorGradient gradient(start, end);
QList<icmm::CVarColor> ramp;
for (int i = 0; i < steps; ++i) {
double t = static_cast<double>(i) / (steps - 1);
icmm::CVarColor param(1);
param.SetElement(0, t);
icmm::CVarColor color = gradient.GetValueAt(param);
ramp.append(color);
}
return ramp;
}
// Usage
icmm::CVarColor white(3, 1.0);
icmm::CVarColor black(3, 0.0);
QList<icmm::CVarColor> grayscaleRamp = CreateColorRamp(black, white, 10);
// Example 3: Temperature gradient (blue to red)
icmm::CVarColor CreateTemperatureGradient()
{
// Cold (blue)
icmm::CVarColor cold(3);
cold.SetElement(0, 0.0);
cold.SetElement(1, 0.0);
cold.SetElement(2, 1.0);
// Hot (red)
hot.SetElement(0, 1.0);
hot.SetElement(1, 0.0);
hot.SetElement(2, 0.0);
return icmm::CLinearColorGradient(cold, hot);
}
// Example 4: Using gradient for visualization
void VisualizeData(const QVector<double>& data,
const icmm::CLinearColorGradient& gradient)
{
// Find data range
double minVal = *std::min_element(data.begin(), data.end());
double maxVal = *std::max_element(data.begin(), data.end());
double range = maxVal - minVal;
for (double value : data) {
// Normalize to [0, 1]
double t = (value - minVal) / range;
icmm::CVarColor param(1);
param.SetElement(0, t);
// Get color for this value
icmm::CVarColor color = gradient.GetValueAt(param);
// Render with this color
DrawPoint(color);
}
}
// Example 5: Custom gradient function
class SmoothStepGradientFunction
{
public:
static double GetValue(double x)
{
// Smooth step interpolation (ease in/out)
return x * x * (3.0 - 2.0 * x);
}
};
// Create gradient with smooth step function
CSmoothStepGradient;
icmm::CVarColor start(3, 0.0);
icmm::CVarColor end(3, 1.0);
CSmoothStepGradient smoothGradient(start, end);
// Example 6: Heatmap colors
icmm::CLinearColorGradient CreateHeatmapGradient()
{
// Black (cold)
icmm::CVarColor black(3);
black.SetElement(0, 0.0);
black.SetElement(1, 0.0);
black.SetElement(2, 0.0);
// Yellow (hot)
icmm::CVarColor yellow(3);
yellow.SetElement(0, 1.0);
yellow.SetElement(1, 1.0);
yellow.SetElement(2, 0.0);
return icmm::CLinearColorGradient(black, yellow);
}
Generic color implementation with variable number of color components.
Definition CVarColor.h:176
Simple implementation of color gradient based on interpolation between start and end colors.
TColorGradient< LinearGradientFunction > CLinearColorGradient

Gradient Functions

The template parameter GradientFunction controls interpolation:

LinearGradientFunction** (default):

Applications

Best Practices

Note
Parameter values outside [0, 1] are automatically clamped to valid range.
See also
icmm::IColorTransformation, icmm::TComposedColorGradient, icmm::CVarColor, icmm::CLinearColorGradient

Definition at line 202 of file TColorGradient.h.

Member Typedef Documentation

◆ GradientColor

template<class GradientFunction >
typedef IColorTransformation::ResultType icmm::TColorGradient< GradientFunction >::GradientColor

Definition at line 205 of file TColorGradient.h.

Constructor & Destructor Documentation

◆ TColorGradient()

template<class GradientFunction >
icmm::TColorGradient< GradientFunction >::TColorGradient ( const GradientColor startColor,
const GradientColor endColor 
)

Definition at line 220 of file TColorGradient.h.

Member Function Documentation

◆ GetValueAt() [1/2]

template<class GradientFunction >
TColorGradient< GradientFunction >::ResultType icmm::TColorGradient< GradientFunction >::GetValueAt ( const ArgumentType argument) const
overridevirtual

Definition at line 258 of file TColorGradient.h.

◆ GetValueAt() [2/2]

template<class GradientFunction >
bool icmm::TColorGradient< GradientFunction >::GetValueAt ( const ArgumentType argument,
ResultType result 
) const
overridevirtual

Definition at line 230 of file TColorGradient.h.

References istd::TRange< ValueType >::GetClipped().


The documentation for this class was generated from the following file: