DGtal  1.5.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)
35 #define QuantifiedColorMap_RECURSES
36 
37 #if !defined QuantifiedColorMap_h
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)
Aim: This class encapsulates its parameter class to indicate that the given parameter is required to ...
Definition: Clone.h:267
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
DGtal is the top-level namespace which contains all DGtal functions and types.
QuantifiedColorMap< TColorMap > makeQuantifiedColorMap(TColorMap colormap, int nb=50)
Aim: A modifier class that quantifies any colormap into a given number of colors. It is particularly ...
Color operator()(const Value &value) const
BOOST_CONCEPT_ASSERT((concepts::CColorMap< TColorMap >))
QuantifiedColorMap(Clone< ColorMap > colormap, int nb=50)
ColorMap myColorMap
the colormap that is quantified
typename ColorMap::Value Value
int myNbColors
the maximum number of colors
Aim: Defines the concept describing a color map. A color map converts a value within a given range in...
Definition: CColorMap.h:94