DGtal  1.3.beta
QuantifiedColorMap.h
1 
17 #pragma once
18 
31 #if defined(QuantifiedColorMap_RECURSES)
32 #error Recursive header files inclusion detected in QuantifiedColorMap.h
33 #else // defined(QuantifiedColorMap_RECURSES)
34 
35 #define QuantifiedColorMap_RECURSES
36 
37 #if !defined QuantifiedColorMap_h
38 
39 #define QuantifiedColorMap_h
40 
42 // Inclusions
43 #include <iostream>
44 #include <sstream>
45 #include <string>
46 #include "DGtal/base/Common.h"
47 #include "DGtal/base/Clone.h"
48 #include "DGtal/io/Color.h"
49 #include "DGtal/io/colormaps/CColorMap.h"
50 
51 namespace DGtal
52 {
53 
55  // template class QuantifiedColorMap
65  template < typename TColorMap >
67  {
69  using ColorMap = TColorMap;
71  using Value = typename ColorMap::Value;
72 
73  //---------------------------------------------------------------------------
74  public:
75 
79  QuantifiedColorMap( Clone< ColorMap > colormap, int nb = 50 )
80  : myColorMap( colormap ), myNbColors( nb )
81  {}
82 
88  Color operator()( const Value & value ) const
89  {
90  const Value rel = ( value - myColorMap.min() )
91  / ( myColorMap.max() - myColorMap.min() );
92  const Value qrel = round( myNbColors * rel ) / myNbColors;
93  const Value outv = qrel * ( myColorMap.max() - myColorMap.min() )
94  + myColorMap.min();
95  return myColorMap( outv );
96  }
97 
98  //---------------------------------------------------------------------------
99  public:
104 
105  };
106 
111  template < typename TColorMap >
113  makeQuantifiedColorMap( TColorMap colormap, int nb = 50 )
114  {
115  return QuantifiedColorMap< TColorMap >( colormap, nb );
116  }
117 
118 } // namespace DGtal
119 
121 // Includes inline functions.
122 // //
124 
125 #endif // !defined QuantifiedColorMap_h
126 
127 #undef QuantifiedColorMap_RECURSES
128 #endif // else defined(QuantifiedColorMap_RECURSES)
DGtal::QuantifiedColorMap::Value
typename ColorMap::Value Value
Definition: QuantifiedColorMap.h:71
DGtal::Clone
Aim: This class encapsulates its parameter class to indicate that the given parameter is required to ...
Definition: Clone.h:266
DGtal::QuantifiedColorMap::operator()
Color operator()(const Value &value) const
Definition: QuantifiedColorMap.h:88
DGtal::QuantifiedColorMap::myColorMap
ColorMap myColorMap
the colormap that is quantified
Definition: QuantifiedColorMap.h:101
DGtal::Color
Structure representing an RGB triple with alpha component.
Definition: Color.h:67
DGtal::QuantifiedColorMap::myNbColors
int myNbColors
the maximum number of colors
Definition: QuantifiedColorMap.h:103
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::QuantifiedColorMap::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CColorMap< TColorMap >))
DGtal::concepts::CColorMap
Aim: Defines the concept describing a color map. A color map converts a value within a given range in...
Definition: CColorMap.h:93
DGtal::QuantifiedColorMap::QuantifiedColorMap
QuantifiedColorMap(Clone< ColorMap > colormap, int nb=50)
Definition: QuantifiedColorMap.h:79
DGtal::QuantifiedColorMap::ColorMap
TColorMap ColorMap
Definition: QuantifiedColorMap.h:69
DGtal::QuantifiedColorMap
Aim: A modifier class that quantifies any colormap into a given number of colors. It is particularly ...
Definition: QuantifiedColorMap.h:66
DGtal::makeQuantifiedColorMap
QuantifiedColorMap< TColorMap > makeQuantifiedColorMap(TColorMap colormap, int nb=50)
Definition: QuantifiedColorMap.h:113
Value
double Value
Definition: testSimpleRandomAccessRangeFromPoint.cpp:38