Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes

DGtal::GradientColorMap< PValueType, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor > Class Template Reference

Aim: This class template may be used to (linearly) convert scalar values in a given range into a color in a gradient defined by two or more colors. More...

#include <GradientColorMap.h>

Public Types

typedef PValueType ValueType

Public Member Functions

 GradientColorMap (const PValueType &min, const PValueType &max, const ColorGradientPreset preset=static_cast< ColorGradientPreset >(PDefaultPreset), const LibBoard::Color firstColor=(PDefaultFirstColor==-1)?LibBoard::Color::None:LibBoard::Color(DGTAL_RED_COMPONENT(PDefaultFirstColor), DGTAL_GREEN_COMPONENT(PDefaultFirstColor), DGTAL_BLUE_COMPONENT(PDefaultFirstColor)), const LibBoard::Color lastColor=(PDefaultFirstColor==-1)?LibBoard::Color::None:LibBoard::Color(DGTAL_RED_COMPONENT(PDefaultLastColor), DGTAL_GREEN_COMPONENT(PDefaultLastColor), DGTAL_BLUE_COMPONENT(PDefaultLastColor)))
LibBoard::Color operator() (const PValueType &value) const
 ~GradientColorMap ()
 GradientColorMap (const GradientColorMap &other)
GradientColorMapoperator= (const GradientColorMap &other)
void clearColors ()
void addColor (const LibBoard::Color &color)
void selfDisplay (std::ostream &out) const
bool isValid () const
const PValueType & min () const
const PValueType & max () const

Static Public Member Functions

static LibBoard::Color getColor (const std::vector< LibBoard::Color > &colors, const PValueType &min, const PValueType &max, const PValueType &value)

Protected Member Functions

 GradientColorMap ()

Protected Attributes

PValueType myMin
PValueType myMax
std::vector< LibBoard::ColormyColors

Detailed Description

template<typename PValueType, int PDefaultPreset = CMAP_CUSTOM, int PDefaultFirstColor = -1, int PDefaultLastColor = -1>
class DGtal::GradientColorMap< PValueType, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >

Aim: This class template may be used to (linearly) convert scalar values in a given range into a color in a gradient defined by two or more colors.

Description of template class 'GradientColorMap'

The GradientColorMap can be used either as a functor object (the value range is given at the object's construction, together with the reference color) which converts a value into a LibBoard::Color structure, or it can be used through a static method taking both the range and the value as parameters.

The code below shows a possible use of this class.

 #include "Board/Color.h"
 #include "GradientColorMap.h"
 // ...
 {
   Board b;

   GradientColorMap<float> gradient( 0.0, 1000.0, Color::White, Color::Red );
   b.setPenColor( gradient( 230.0 ) ); // Somewhere between white and red.

   GradientColorMap<int> grad3( 0, 500 );
   grad3.addColor( Color::Blue );
   grad3.addColor( Color::White );
   grad3.addColor( Color::Red );
   
   b.setPenColor( grad3( 100 ) ); // Between Blue and white.
   b.setPenColor( grad3( 300 ) ); // Between white and red.
 }
Template Parameters:
ValueType The type of the range values.
PDefaultPreset The default gradient preset (e.g. CMAP_GRAYSCALE, CMAP_HOT, or CMAP_CUSTOM
PDefaultFirstColor If DefaultPreset is CMAP_CUSTOM, this is the starting color of the gradient.
PDefaultLastColor If DefaultPreset is CMAP_CUSTOM, this is the ending color of the gradient.
Examples:

dgtalboard-4-colormaps.cpp.


Member Typedef Documentation

template<typename PValueType, int PDefaultPreset = CMAP_CUSTOM, int PDefaultFirstColor = -1, int PDefaultLastColor = -1>
typedef PValueType DGtal::GradientColorMap< PValueType, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::ValueType

Constructor & Destructor Documentation

template<typename PValueType, int PDefaultPreset = CMAP_CUSTOM, int PDefaultFirstColor = -1, int PDefaultLastColor = -1>
DGtal::GradientColorMap< PValueType, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::GradientColorMap ( const PValueType &  min,
const PValueType &  max,
const ColorGradientPreset  preset = static_cast< ColorGradientPreset >(PDefaultPreset),
const LibBoard::Color  firstColor = (PDefaultFirstColor==-1)?LibBoard::Color::None:LibBoard::Color(DGTAL_RED_COMPONENT(PDefaultFirstColor), DGTAL_GREEN_COMPONENT(PDefaultFirstColor), DGTAL_BLUE_COMPONENT(PDefaultFirstColor)),
const LibBoard::Color  lastColor = (PDefaultFirstColor==-1)?LibBoard::Color::None:LibBoard::Color(DGTAL_RED_COMPONENT(PDefaultLastColor), DGTAL_GREEN_COMPONENT(PDefaultLastColor), DGTAL_BLUE_COMPONENT(PDefaultLastColor)) 
)

Constructor.

Parameters:
min The lower bound of the value range.
max The upper bound of the value range.
preset A preset identifier.
firstColor The "left" color of the gradient if preset is CMAP_CUSTOM.
lastColor The "right" color of the gradient if preset is CMAP_CUSTOM.
template<typename PValueType, int PDefaultPreset = CMAP_CUSTOM, int PDefaultFirstColor = -1, int PDefaultLastColor = -1>
DGtal::GradientColorMap< PValueType, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::~GradientColorMap (  ) 

Destructor.

template<typename PValueType, int PDefaultPreset = CMAP_CUSTOM, int PDefaultFirstColor = -1, int PDefaultLastColor = -1>
DGtal::GradientColorMap< PValueType, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::GradientColorMap ( const GradientColorMap< PValueType, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor > &  other  ) 

Copy constructor.

Parameters:
other the object to clone.
template<typename PValueType, int PDefaultPreset = CMAP_CUSTOM, int PDefaultFirstColor = -1, int PDefaultLastColor = -1>
DGtal::GradientColorMap< PValueType, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::GradientColorMap (  )  [protected]

Constructor. Forbidden by default (protected to avoid g++ warnings).


Member Function Documentation

template<typename PValueType, int PDefaultPreset = CMAP_CUSTOM, int PDefaultFirstColor = -1, int PDefaultLastColor = -1>
void DGtal::GradientColorMap< PValueType, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::addColor ( const LibBoard::Color color  ) 

Adds a color to the list of color steps.

Parameters:
color A color.

Referenced by main(), and testSimplePoints2D().

template<typename PValueType, int PDefaultPreset = CMAP_CUSTOM, int PDefaultFirstColor = -1, int PDefaultLastColor = -1>
void DGtal::GradientColorMap< PValueType, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::clearColors (  ) 

Clears the list of colors.

Referenced by main().

template<typename PValueType, int PDefaultPreset = CMAP_CUSTOM, int PDefaultFirstColor = -1, int PDefaultLastColor = -1>
static LibBoard::Color DGtal::GradientColorMap< PValueType, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::getColor ( const std::vector< LibBoard::Color > &  colors,
const PValueType &  min,
const PValueType &  max,
const PValueType &  value 
) [static]

Computes the color associated with a value in a given range.

Parameters:
colors The gradients boundary colors.
min The lower bound of the value range.
max The upper bound of the value range.
value A value within the value range.
Returns:
A color whose color linearly depends on the position of [value] within the range [min]..[max].
template<typename PValueType, int PDefaultPreset = CMAP_CUSTOM, int PDefaultFirstColor = -1, int PDefaultLastColor = -1>
bool DGtal::GradientColorMap< PValueType, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::isValid (  )  const

Checks the validity/consistency of the object.

Returns:
'true' if the object is valid, 'false' otherwise.
template<typename PValueType, int PDefaultPreset = CMAP_CUSTOM, int PDefaultFirstColor = -1, int PDefaultLastColor = -1>
const PValueType& DGtal::GradientColorMap< PValueType, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::max (  )  const

Returns the upper bound of the value range.

Returns:
The upper bound of the value range.
template<typename PValueType, int PDefaultPreset = CMAP_CUSTOM, int PDefaultFirstColor = -1, int PDefaultLastColor = -1>
const PValueType& DGtal::GradientColorMap< PValueType, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::min (  )  const

Returns the lower bound of the value range.

Returns:
The lower bound of the value range.
template<typename PValueType, int PDefaultPreset = CMAP_CUSTOM, int PDefaultFirstColor = -1, int PDefaultLastColor = -1>
LibBoard::Color DGtal::GradientColorMap< PValueType, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::operator() ( const PValueType &  value  )  const

Computes the color associated with a value in a given range.

Parameters:
value A value within the value range.
Returns:
A color whose brightness linearly depends on the position of [value] within the current range.
template<typename PValueType, int PDefaultPreset = CMAP_CUSTOM, int PDefaultFirstColor = -1, int PDefaultLastColor = -1>
GradientColorMap& DGtal::GradientColorMap< PValueType, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::operator= ( const GradientColorMap< PValueType, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor > &  other  ) 

Assignment.

Parameters:
other the object to copy.
Returns:
a reference on 'this'.
template<typename PValueType, int PDefaultPreset = CMAP_CUSTOM, int PDefaultFirstColor = -1, int PDefaultLastColor = -1>
void DGtal::GradientColorMap< PValueType, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::selfDisplay ( std::ostream &  out  )  const

Writes/Displays the object on an output stream.

Parameters:
out the output stream where the object is written.

Field Documentation

template<typename PValueType, int PDefaultPreset = CMAP_CUSTOM, int PDefaultFirstColor = -1, int PDefaultLastColor = -1>
std::vector<LibBoard::Color> DGtal::GradientColorMap< PValueType, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::myColors [protected]

The gradients boundary colors.

template<typename PValueType, int PDefaultPreset = CMAP_CUSTOM, int PDefaultFirstColor = -1, int PDefaultLastColor = -1>
PValueType DGtal::GradientColorMap< PValueType, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::myMax [protected]

The lower bound of the value range.

template<typename PValueType, int PDefaultPreset = CMAP_CUSTOM, int PDefaultFirstColor = -1, int PDefaultLastColor = -1>
PValueType DGtal::GradientColorMap< PValueType, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::myMin [protected]

The lower bound of the value range.


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