DGtal 1.4.0
Loading...
Searching...
No Matches
DGtal::GradientColorMap< PValue, 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 <DGtal/io/colormaps/GradientColorMap.h>

Inheritance diagram for DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >:
[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, 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.
}
static const Color Red
Definition Color.h:416
static const Color White
Definition Color.h:415
static const Color Blue
Definition Color.h:419
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Template Parameters
PValueThe 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
geometry/meshes/curvature-comparator-ii-cnc-3d.cpp, geometry/meshes/curvature-measures-icnc-3d.cpp, geometry/meshes/curvature-measures-icnc-XY-3d.cpp, geometry/meshes/curvature-measures-nc-3d.cpp, geometry/meshes/curvature-measures-nc-XY-3d.cpp, geometry/meshes/digpoly-curvature-measures-cnc-3d.cpp, geometry/meshes/digpoly-curvature-measures-cnc-XY-3d.cpp, geometry/meshes/obj-curvature-measures-icnc-3d.cpp, geometry/meshes/obj-curvature-measures-icnc-XY-3d.cpp, geometry/meshes/vol-curvature-measures-icnc-3d.cpp, geometry/meshes/vol-curvature-measures-icnc-XY-3d.cpp, geometry/surfaces/dvcm-2d-curvature.cpp, geometry/surfaces/dvcm-3d.cpp, geometry/volumes/distance/distancetransform3D.cpp, geometry/volumes/distance/exampleFMM3D.cpp, geometry/volumes/dvcm-2d.cpp, graph/graphTraversal.cpp, io/boards/dgtalBoard2D-4-colormaps.cpp, shapes/exampleSurfaceMesh.cpp, topology/3dKSSurfaceExtraction.cpp, topology/ctopo-2-3d.cpp, topology/ctopo-2.cpp, topology/digitalSurfaceSlice.cpp, tutorial-examples/freemanChainFromImage.cpp, and tutorial-examples/volDTGranulo.cpp.

Definition at line 119 of file GradientColorMap.h.

Member Typedef Documentation

◆ Value

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 124 of file GradientColorMap.h.

Constructor & Destructor Documentation

◆ GradientColorMap() [1/3]

template<typename PValue , int PDefaultPreset = CMAP_CUSTOM, int PDefaultFirstColor = -1, int PDefaultLastColor = -1>
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)) )

Constructor.

Precondition
min and max values must be different.
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.

◆ ~GradientColorMap()

template<typename PValue , int PDefaultPreset = CMAP_CUSTOM, int PDefaultFirstColor = -1, int PDefaultLastColor = -1>
DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::~GradientColorMap ( )

Destructor.

◆ GradientColorMap() [2/3]

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

Copy constructor.

Parameters
otherthe object to clone.

◆ GradientColorMap() [3/3]

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

◆ addColor()

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

◆ clearColors()

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

Clears the list of colors.

Referenced by main().

◆ getColor()

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

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

Precondition
min and max values must be different.
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].

◆ isValid()

template<typename PValue , int PDefaultPreset = CMAP_CUSTOM, int PDefaultFirstColor = -1, int PDefaultLastColor = -1>
bool DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::isValid ( ) const

Checks the validity/consistency of the object.

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

◆ max()

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

Returns the upper bound of the value range.

Returns
The upper bound of the value range.

◆ min()

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

Returns the lower bound of the value range.

Returns
The lower bound of the value range.

◆ operator()()

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

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.

◆ operator=()

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

Assignment.

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

◆ selfDisplay()

template<typename PValue , int PDefaultPreset = CMAP_CUSTOM, int PDefaultFirstColor = -1, int PDefaultLastColor = -1>
void DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::selfDisplay ( std::ostream & out) const

Writes/Displays the object on an output stream.

Parameters
outthe output stream where the object is written.

Field Documentation

◆ myColors

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

The gradients boundary colors.

Definition at line 255 of file GradientColorMap.h.

◆ myMax

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 254 of file GradientColorMap.h.

◆ myMin

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 253 of file GradientColorMap.h.


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