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 | Static Private Member Functions
DGtal::HueShadeColorMap< PValue, DefaultCycles > Class Template Reference

#include <HueShadeColorMap.h>

Public Types

typedef PValue Value

Public Member Functions

 HueShadeColorMap (const PValue &min, const PValue &max, const unsigned int cycles=DefaultCycles)
Color operator() (const PValue &value) const
 ~HueShadeColorMap ()
 HueShadeColorMap (const HueShadeColorMap &other)
HueShadeColorMapoperator= (const HueShadeColorMap &other)
void selfDisplay (std::ostream &out) const
bool isValid () const
const PValue & min () const
const PValue & max () const
void setCycles (int cycles)

Static Public Member Functions

static Color getColor (const unsigned int cycles, const PValue &min, const PValue &max, const PValue &value)

Protected Member Functions

 HueShadeColorMap ()

Protected Attributes

PValue myMin
PValue myMax
unsigned int myCycles

Static Private Member Functions

static void HSVtoRGB (double &r, double &g, double &b, double h, const double s, const double v)

Detailed Description

template<typename PValue, int DefaultCycles = 1>
class DGtal::HueShadeColorMap< PValue, DefaultCycles >

Aim: This class template may be used to (linearly) convert scalar values in a given range into a color in a cyclic hue shade colormap, maybe aka rainbow color map. This color map is suitable, for example, to colorize distance functions. By default, only one hue cycle is used.

Description of template class 'HueShadeColorMap'

The HueShadeColorMap can be used either as a functor object (the value range is given at the object's construction) 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 "DGtal/io/Color.h"
#include "HueShadeColorMap.h"
// ...
{
HueShadeColorMap<float> hueShade(0.0f,1.0f);
HueShadeColorMap<float,10> hueShadeBis(0.0f,1.0f); // Ten cycles.
HueShadeColorMap<float> hueShadeTer(0.0f,1.0f,10); // Idem.
Color red = hueShade(1.0f);
Color lightBlue1 = hueShade(0.5f);
// Or, equivalently:
Color lightBlue2 = HueShadeColorMap<float>::getColor(0.0f,1.0f,0.5f);
}
Template Parameters:
PValueThe type of the range values.
DefaultCyclesThe default number of cycles (used as a default parameter by the constructor).

Definition at line 101 of file HueShadeColorMap.h.


Member Typedef Documentation

template<typename PValue, int DefaultCycles = 1>
typedef PValue DGtal::HueShadeColorMap< PValue, DefaultCycles >::Value

Definition at line 106 of file HueShadeColorMap.h.


Constructor & Destructor Documentation

template<typename Value , int DefaultCycles>
DGtal::HueShadeColorMap< Value, DefaultCycles >::HueShadeColorMap ( const PValue &  min,
const PValue &  max,
const unsigned int  cycles = DefaultCycles 
)
inline

Constructor.

Parameters:
minThe lower bound of the value range.
maxThe upper bound of the value range.
cyclesThe number of cycles in the colormap.

Definition at line 45 of file HueShadeColorMap.ih.

: myMin( amin ), myMax( amax ), myCycles( cycles )
{ }
template<typename Value , int DefaultCycles>
DGtal::HueShadeColorMap< Value, DefaultCycles >::~HueShadeColorMap ( )
inline

Destructor.

Definition at line 62 of file HueShadeColorMap.ih.

{
}
template<typename Value , int DefaultCycles>
DGtal::HueShadeColorMap< Value, DefaultCycles >::HueShadeColorMap ( const HueShadeColorMap< PValue, DefaultCycles > &  other)
inline

Copy constructor.

Parameters:
otherthe object to clone.

Definition at line 55 of file HueShadeColorMap.ih.

: myMin( other.myMin ), myMax( other.myMax ), myCycles( other.myCycles )
{
}
template<typename PValue, int DefaultCycles = 1>
DGtal::HueShadeColorMap< PValue, DefaultCycles >::HueShadeColorMap ( )
protected

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


Member Function Documentation

template<typename Value , int DefaultCycles>
Color DGtal::HueShadeColorMap< Value, DefaultCycles >::getColor ( const unsigned int  cycles,
const PValue &  min,
const PValue &  max,
const PValue &  value 
)
inlinestatic

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

Parameters:
cyclesThe number of (rainbow) cycles.
minThe lower bound of the value range.
maxThe upper bound of the value range.
valueA value within the value range.
Returns:
A color whose hue linearly depends on the position of [value] within the range [min]..[max].

Definition at line 148 of file HueShadeColorMap.ih.

{
const double scale = ( value - min ) / static_cast<double>( max - min );
const double hue = 360 * ( scale * cycles - floor(scale * cycles));
double red, green, blue;
HueShadeColorMap<Value,DefaultCycles>::HSVtoRGB( red, green, blue, hue, 0.9, 1.0 );
return Color( static_cast<int>( red * 255),
static_cast<int>( green * 255),
static_cast<int>( blue * 255) );
}
template<typename Value , int DefaultCycles>
void DGtal::HueShadeColorMap< Value, DefaultCycles >::HSVtoRGB ( double &  r,
double &  g,
double &  b,
double  h,
const double  s,
const double  v 
)
inlinestaticprivate

Converts a color from the HSV (Hue,Saturation,Value) space to the RGB space.

Parameters:
rThe red component (out).
gThe green component (out).
bThe blue component (out).
hThe hue of the color in [0..360)
sThe saturation of the color in [0..1].
vThe value of the color in [0..1].

Definition at line 186 of file HueShadeColorMap.ih.

{
int i;
double f, p, q, t;
if( s == 0 ) { // achromatic (gray)
r = g = b = v;
return;
}
i = static_cast<int>( floor( h / 60 ) );
f = ( h / 60 ) - i; // factorial part of h
p = v * ( 1.0 - s );
q = v * ( 1.0 - s * f );
t = v * ( 1.0 - s * ( 1.0 - f ) );
switch( i ) {
case 0:
r = v; g = t; b = p;
break;
case 1:
r = q; g = v; b = p;
break;
case 2:
r = p; g = v; b = t;
break;
case 3:
r = p; g = q; b = v;
break;
case 4:
r = t; g = p; b = v;
break;
default: // case 5:
r = v; g = p; b = q;
break;
}
}
template<typename Value , int DefaultCycles>
bool DGtal::HueShadeColorMap< Value, DefaultCycles >::isValid ( ) const
inline

Checks the validity/consistency of the object.

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

Definition at line 139 of file HueShadeColorMap.ih.

{
return true;
}
template<typename Value , int DefaultCycles>
const Value & DGtal::HueShadeColorMap< Value, DefaultCycles >::max ( ) const
inline

Returns the upper bound of the value range.

Returns:
The upper bound of the value range.

Definition at line 93 of file HueShadeColorMap.ih.

{
return myMax;
}
template<typename Value , int DefaultCycles>
const Value & DGtal::HueShadeColorMap< Value, DefaultCycles >::min ( ) const
inline

Returns the lower bound of the value range.

Returns:
The lower bound of the value range.

Definition at line 85 of file HueShadeColorMap.ih.

{
return myMin;
}
template<typename Value , int DefaultCycles>
Color DGtal::HueShadeColorMap< Value, DefaultCycles >::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 hue linearly depends on the position of [value] within the current range.

Definition at line 111 of file HueShadeColorMap.ih.

{
return getColor( myCycles, myMin, myMax, value );
}
template<typename PValue, int DefaultCycles = 1>
HueShadeColorMap< Value, DefaultCycles > & HueShadeColorMap::operator= ( const HueShadeColorMap< PValue, DefaultCycles > &  other)

Assignment.

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

Definition at line 69 of file HueShadeColorMap.ih.

References DGtal::HueShadeColorMap< PValue, DefaultCycles >::myCycles, DGtal::HueShadeColorMap< PValue, DefaultCycles >::myMax, and DGtal::HueShadeColorMap< PValue, DefaultCycles >::myMin.

{
if ( &other != this ) {
myMin = other.myMin;
myMax = other.myMax;
myCycles = other.myCycles;
}
return *this;
}
template<typename Value , int DefaultCycles>
void DGtal::HueShadeColorMap< Value, DefaultCycles >::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 123 of file HueShadeColorMap.ih.

{
out << "[HueShadeColorMap "
<< " min=" << myMin
<< " max=" << myMax
<< " cycles=" << myCycles
<< " ]";
}
template<typename Value , int DefaultCycles>
void DGtal::HueShadeColorMap< Value, DefaultCycles >::setCycles ( int  cycles)
inline

Sets the number of cycles of hue shade.

Parameters:
cyclesNumber of cycles.

Definition at line 101 of file HueShadeColorMap.ih.

{
myCycles = cycles;
}

Field Documentation

template<typename PValue, int DefaultCycles = 1>
unsigned int DGtal::HueShadeColorMap< PValue, DefaultCycles >::myCycles
protected

The number of cycles in the color map.

Definition at line 215 of file HueShadeColorMap.h.

Referenced by DGtal::HueShadeColorMap< PValue, DefaultCycles >::operator=().

template<typename PValue, int DefaultCycles = 1>
PValue DGtal::HueShadeColorMap< PValue, DefaultCycles >::myMax
protected

The lower bound of the value range.

Definition at line 214 of file HueShadeColorMap.h.

Referenced by DGtal::HueShadeColorMap< PValue, DefaultCycles >::operator=().

template<typename PValue, int DefaultCycles = 1>
PValue DGtal::HueShadeColorMap< PValue, DefaultCycles >::myMin
protected

The lower bound of the value range.

Definition at line 213 of file HueShadeColorMap.h.

Referenced by DGtal::HueShadeColorMap< PValue, DefaultCycles >::operator=().


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