DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor > Class Template Reference

#include <GradientColorMap.h>

Inheritance diagram for DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >:
Inheritance graph
[legend]
Collaboration diagram for DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >:
Collaboration graph
[legend]

Public Types

typedef PValue Value

Public Member Functions

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

Static Public Member Functions

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

Protected Member Functions

 GradientColorMap ()

Protected Attributes

PValue myMin
PValue myMax
std::vector< ColormyColors

Detailed Description

template<typename PValue, int PDefaultPreset = CMAP_CUSTOM, int PDefaultFirstColor = -1, int PDefaultLastColor = -1>
class DGtal::GradientColorMap< PValue, 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 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 "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:
ValueThe type of the range values.
PDefaultPresetThe default gradient preset (e.g. CMAP_GRAYSCALE, CMAP_HOT, or CMAP_CUSTOM
PDefaultFirstColorIf DefaultPreset is CMAP_CUSTOM, this is the starting color of the gradient.
PDefaultLastColorIf DefaultPreset is CMAP_CUSTOM, this is the ending color of the gradient.
Examples:
io/boards/dgtalBoard2D-4-colormaps.cpp, topology/3dKSSurfaceExtraction.cpp, topology/ctopo-2-3d.cpp, and topology/ctopo-2.cpp.

Definition at line 118 of file GradientColorMap.h.


Member Typedef Documentation

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

Definition at line 123 of file GradientColorMap.h.


Constructor & Destructor Documentation

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

Constructor.

Parameters:
minThe lower bound of the value range.
maxThe upper bound of the value range.
presetA preset identifier.
firstColorThe "left" color of the gradient if preset is CMAP_CUSTOM.
lastColorThe "right" color of the gradient if preset is CMAP_CUSTOM.

Definition at line 47 of file GradientColorMap.ih.

References DGtal::CMAP_AUTUMN, DGtal::CMAP_COOL, DGtal::CMAP_COPPER, DGtal::CMAP_CUSTOM, DGtal::CMAP_GRAYSCALE, DGtal::CMAP_HOT, DGtal::CMAP_JET, DGtal::CMAP_SPRING, DGtal::CMAP_SUMMER, and DGtal::CMAP_WINTER.

: myMin( minV ), myMax( maxV )
{
switch ( preset ) {
myColors.push_back( Color::Black );
myColors.push_back( Color::White );
break;
myColors.push_back( Color( 255, 0, 255 ));
myColors.push_back( Color( 255, 255, 0 ));
break;
myColors.push_back( Color( 0, 132, 100 ));
myColors.push_back( Color( 255, 255, 100 ));
break;
myColors.push_back( Color( 255, 0, 0 ));
myColors.push_back( Color( 255, 255, 0));
break;
myColors.push_back( Color( 0, 0, 255 ));
myColors.push_back( Color( 0, 255, 132 ));
break;
case CMAP_COOL:
myColors.push_back( Color( 0, 255, 255 ));
myColors.push_back( Color( 255, 0, 255 ));
break;
myColors.push_back( Color( 0, 0, 0 ));
myColors.push_back( Color( 255, 198, 123 ));
break;
case CMAP_HOT:
myColors.push_back( Color::Black );
myColors.push_back( Color::Red );
myColors.push_back( Color( 255, 140, 0 ) );
myColors.push_back( Color::Yellow );
myColors.push_back( Color::White );
break;
case CMAP_JET:
myColors.push_back( Color::Blue );
myColors.push_back( Color::Cyan );
myColors.push_back( Color::Yellow );
myColors.push_back( Color( 255, 140, 0 ) );
myColors.push_back( Color::Red );
myColors.push_back( Color( 132, 0, 0 ) );
break;
if ( firstColor != Color::None
&& lastColor != Color::None ) {
myColors.push_back( firstColor );
myColors.push_back( lastColor );
}
break;
}
}
template<typename PValue , int PDefaultPreset, int PDefaultFirstColor, int PDefaultLastColor>
DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::~GradientColorMap ( )
inline

Destructor.

Definition at line 124 of file GradientColorMap.ih.

{
}
template<typename PValue, int PDefaultPreset, int PDefaultFirstColor, int PDefaultLastColor>
DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::GradientColorMap ( const GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor > &  other)
inline

Copy constructor.

Parameters:
otherthe object to clone.

Definition at line 114 of file GradientColorMap.ih.

: myMin( other.myMin ), myMax( other.myMax ), myColors( other.myColors )
{
}
template<typename PValue, int PDefaultPreset = CMAP_CUSTOM, int PDefaultFirstColor = -1, int PDefaultLastColor = -1>
DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::GradientColorMap ( )
protected

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


Member Function Documentation

template<typename PValue , int PDefaultPreset, int PDefaultFirstColor, int PDefaultLastColor>
void DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::addColor ( const Color color)
inline

Adds a color to the list of color steps.

Parameters:
colorA color.
Examples:
topology/3dKSSurfaceExtraction.cpp, topology/ctopo-2-3d.cpp, and topology/ctopo-2.cpp.

Definition at line 155 of file GradientColorMap.ih.

Referenced by DGtal::RandomColorMap::RandomColorMap().

{
myColors.push_back( color );
}
template<typename PValue , int PDefaultPreset, int PDefaultFirstColor, int PDefaultLastColor>
void DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::clearColors ( )
inline

Clears the list of colors.

Definition at line 166 of file GradientColorMap.ih.

{
myColors.clear();
}
template<typename PValue, int PDefaultPreset, int PDefaultFirstColor, int PDefaultLastColor>
Color DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::getColor ( const std::vector< Color > &  colors,
const PValue &  min,
const PValue &  max,
const PValue &  value 
)
inlinestatic

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

Parameters:
colorsThe gradients boundary colors.
minThe lower bound of the value range.
maxThe upper bound of the value range.
valueA value within the value range.
Returns:
A color whose color linearly depends on the position of [value] within the range [min]..[max].

Definition at line 257 of file GradientColorMap.ih.

References DGtal::Color::blue(), DGtal::Color::green(), and DGtal::Color::red().

{
if ( colors.size() < 2 )
return Color::None;
double scale = static_cast<double>( value - min ) / (max - min);
const int intervals = (const int)colors.size() - 1;
int upper_index = static_cast<int>( ceil( intervals * scale ) );
if ( !upper_index ) // Special case when value == min.
upper_index = 1;
const Color & firstColor = colors[ upper_index - 1 ];
const Color & lastColor = colors[ upper_index ];
scale = ( scale * intervals ) - (upper_index - 1);
const unsigned char red = static_cast<unsigned char>( firstColor.red() +
scale * ( lastColor.red() -
firstColor.red() ));
const unsigned char green = static_cast<unsigned char>( firstColor.green() +
scale * ( lastColor.green() -
firstColor.green() ));
const unsigned char blue = static_cast<unsigned char>( firstColor.blue() +
scale * ( lastColor.blue() -
firstColor.blue() ));
return Color( red, green, blue );
}
template<typename PValue , int PDefaultPreset, int PDefaultFirstColor, int PDefaultLastColor>
bool DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::isValid ( ) const
inline

Checks the validity/consistency of the object.

Returns:
'true' if the object is valid, 'false' otherwise.

Definition at line 245 of file GradientColorMap.ih.

{
return true;
}
template<typename PValue , int PDefaultPreset, int PDefaultFirstColor, int PDefaultLastColor>
const PValue & DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::max ( ) const
inline

Returns the upper bound of the value range.

Returns:
The upper bound of the value range.

Definition at line 188 of file GradientColorMap.ih.

{
return myMax;
}
template<typename PValue , int PDefaultPreset, int PDefaultFirstColor, int PDefaultLastColor>
const PValue & DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::min ( ) const
inline

Returns the lower bound of the value range.

Returns:
The lower bound of the value range.

Definition at line 177 of file GradientColorMap.ih.

{
return myMin;
}
template<typename PValue, int PDefaultPreset, int PDefaultFirstColor, int PDefaultLastColor>
Color DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::operator() ( const PValue &  value) const
inline

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

Parameters:
valueA value within the value range.
Returns:
A color whose brightness linearly depends on the position of [value] within the current range.

Definition at line 200 of file GradientColorMap.ih.

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

Assignment.

Parameters:
otherthe object to copy.
Returns:
a reference on 'this'.

Definition at line 134 of file GradientColorMap.ih.

References DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::myColors, DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::myMax, and DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::myMin.

{
if ( &other != this ) {
myMin = other.myMin;
myMax = other.myMax;
myColors = other.myColors;
}
return *this;
}
template<typename PValue , int PDefaultPreset, int PDefaultFirstColor, int PDefaultLastColor>
void DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::selfDisplay ( std::ostream &  out) const
inline

Writes/Displays the object on an output stream.

Parameters:
outthe output stream where the object is written.

Definition at line 219 of file GradientColorMap.ih.

{
out << "[GradientColorMap "
<< " min=" << myMin
<< " max=" << myMax;
std::vector<Color>::iterator it = myColors.begin();
while ( it != myColors.end() ) {
out << " RGB("
<< it->red() << ","
<< it->green() << ","
<< it->blue() << ") ";
++it;
}
out << " ]";
}

Field Documentation

template<typename PValue, int PDefaultPreset = CMAP_CUSTOM, int PDefaultFirstColor = -1, int PDefaultLastColor = -1>
std::vector<Color> DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::myColors
protected
template<typename PValue, int PDefaultPreset = CMAP_CUSTOM, int PDefaultFirstColor = -1, int PDefaultLastColor = -1>
PValue DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::myMax
protected

The lower bound of the value range.

Definition at line 251 of file GradientColorMap.h.

Referenced by DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::operator=().

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

The lower bound of the value range.

Definition at line 250 of file GradientColorMap.h.

Referenced by DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::operator=().


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