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::GrayscaleColorMap< PValue > Class Template Reference

#include <GrayscaleColorMap.h>

Public Types

typedef PValue Value

Public Member Functions

 GrayscaleColorMap (const PValue &min, const PValue &max)
Color operator() (const PValue &value) const
 ~GrayscaleColorMap ()
 GrayscaleColorMap (const GrayscaleColorMap &other)
GrayscaleColorMapoperator= (const GrayscaleColorMap &other)
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 PValue &min, const PValue &max, const PValue &value)

Protected Member Functions

 GrayscaleColorMap ()

Protected Attributes

PValue myMin
PValue myMax

Detailed Description

template<typename PValue>
class DGtal::GrayscaleColorMap< PValue >

Aim: This class template may be used to (linearly) convert scalar values in a given range into gray levels.

Description of template class 'GrayscaleColorMap'

The GrayscaleColorMap 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 "GrayscaleColorMap.h"
// ...
{
GrayscaleColorMap<float> grayShade(0.0f,1.0f);
Color white = grayShade(1.0f);
Color gray1 = grayShade(0.5f);
// Or, equivalently:
Color gray2 = GrayscaleColorMap<float>::getColor(0.0f,1.0f,0.5f);
}
Template Parameters:
PValueThe type of the range values.

Definition at line 93 of file GrayscaleColorMap.h.


Member Typedef Documentation

template<typename PValue>
typedef PValue DGtal::GrayscaleColorMap< PValue >::Value

Definition at line 98 of file GrayscaleColorMap.h.


Constructor & Destructor Documentation

template<typename Value >
DGtal::GrayscaleColorMap< Value >::GrayscaleColorMap ( const PValue &  min,
const PValue &  max 
)
inline

Constructor.

Parameters:
minThe lower bound of the value range.
maxThe upper bound of the value range.

Definition at line 43 of file GrayscaleColorMap.ih.

: myMin( aMin ), myMax( aMax )
{ }
template<typename Value >
DGtal::GrayscaleColorMap< Value >::~GrayscaleColorMap ( )
inline

Destructor.

Definition at line 58 of file GrayscaleColorMap.ih.

{
}
template<typename Value >
DGtal::GrayscaleColorMap< Value >::GrayscaleColorMap ( const GrayscaleColorMap< PValue > &  other)
inline

Copy constructor.

Parameters:
otherthe object to clone.

Definition at line 51 of file GrayscaleColorMap.ih.

: myMin( other.myMin ), myMax( other.myMax )
{
}
template<typename PValue>
DGtal::GrayscaleColorMap< PValue >::GrayscaleColorMap ( )
protected

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


Member Function Documentation

template<typename Value >
Color DGtal::GrayscaleColorMap< Value >::getColor ( const PValue &  min,
const PValue &  max,
const PValue &  value 
)
inlinestatic

Computes the gray level associated with a value in a given range.

Parameters:
minThe lower bound of the value range.
maxThe upper bound of the value range.
valueA value within the value range.
Returns:
A gray level (as a Color) which linearly depends on the position of [value] within the range [min]..[max].

Definition at line 133 of file GrayscaleColorMap.ih.

Referenced by DGtal::GrayscaleColorMap< PValue >::operator()().

{
double range = static_cast<double>( max - min );
double scale = static_cast<double>( value - min );
unsigned char gray = static_cast<unsigned char>( 255.0 * ( scale / range ) );
return Color( gray );
}
template<typename Value >
bool DGtal::GrayscaleColorMap< Value >::isValid ( ) const
inline

Checks the validity/consistency of the object.

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

Definition at line 124 of file GrayscaleColorMap.ih.

{
return true;
}
template<typename Value >
const Value & DGtal::GrayscaleColorMap< Value >::max ( ) const
inline

Returns the upper bound of the value range.

Returns:
The upper bound of the value range.

Definition at line 89 of file GrayscaleColorMap.ih.

{
return myMax;
}
template<typename Value >
const Value & DGtal::GrayscaleColorMap< Value >::min ( ) const
inline

Returns the lower bound of the value range.

Returns:
The lower bound of the value range.

Definition at line 81 of file GrayscaleColorMap.ih.

{
return myMin;
}
template<typename Value >
Color DGtal::GrayscaleColorMap< Value >::operator() ( const PValue &  value) const
inline

Computes the gray level associated with a value in a given range.

Parameters:
valueA value within the value range.
Returns:
A gray level (as a Color) which linearly depends on the position of [value] within the current range.

Definition at line 97 of file GrayscaleColorMap.ih.

References DGtal::GrayscaleColorMap< PValue >::getColor().

template<typename PValue>
GrayscaleColorMap< Value > & GrayscaleColorMap::operator= ( const GrayscaleColorMap< PValue > &  other)

Assignment.

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

Definition at line 65 of file GrayscaleColorMap.ih.

References DGtal::GrayscaleColorMap< PValue >::myMax, and DGtal::GrayscaleColorMap< PValue >::myMin.

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

{
out << "[GrayscaleColorMap "
<< " min=" << myMin
<< " max=" << myMax
<< " ]";
}

Field Documentation

template<typename PValue>
PValue DGtal::GrayscaleColorMap< PValue >::myMax
protected

The lower bound of the value range.

Definition at line 195 of file GrayscaleColorMap.h.

Referenced by DGtal::GrayscaleColorMap< PValue >::operator=().

template<typename PValue>
PValue DGtal::GrayscaleColorMap< PValue >::myMin
protected

The lower bound of the value range.

Definition at line 194 of file GrayscaleColorMap.h.

Referenced by DGtal::GrayscaleColorMap< PValue >::operator=().


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