DGtal  0.9.3beta
GradientColorMap.h
1 
17 #pragma once
18 
31 #if defined(GradientColorMap_RECURSES)
32 #error Recursive header files inclusion detected in GradientColorMap.h
33 #else // defined(GradientColorMap_RECURSES)
34 
35 #define GradientColorMap_RECURSES
36 
37 #if !defined GradientColorMap_h
38 
39 #define GradientColorMap_h
40 
42 // Inclusions
43 #include <iostream>
44 #include "DGtal/base/Common.h"
45 #include "Board/Board.h"
46 #include "DGtal/io/Color.h"
48 
49 #ifndef DGTAL_RGB2INT
50 #define DGTAL_RGB2INT(R,G,B) (((R)<<16)|((G)<<8)|(B))
51 #define DGTAL_RED_COMPONENT(I) (((I)>>16)&0xFF)
52 #define DGTAL_GREEN_COMPONENT(I) (((I)>>8)&0xFF)
53 #define DGTAL_BLUE_COMPONENT(I) ((I)&0xFF)
54 #endif
55 
56 namespace DGtal
57 {
58 
59  // ----------------------- Related enumerations -----------------------------
70 
72  // template class GradientColorMap
114  template <typename PValue,
115  int PDefaultPreset = CMAP_CUSTOM,
116  int PDefaultFirstColor = -1,
117  int PDefaultLastColor = -1 >
119  {
120 
121  public:
122 
123  typedef PValue Value;
124 
125  // ----------------------- Standard services ------------------------------
126  public:
127 
138  GradientColorMap( const PValue & min,
139  const PValue & max,
140  const ColorGradientPreset preset
141  = static_cast<ColorGradientPreset>( PDefaultPreset ),
142  const Color firstColor
143  =
144  ( PDefaultFirstColor == -1 ) ? Color::None :
145  Color( DGTAL_RED_COMPONENT( PDefaultFirstColor ),
146  DGTAL_GREEN_COMPONENT( PDefaultFirstColor ),
147  DGTAL_BLUE_COMPONENT( PDefaultFirstColor ) ),
148  const Color lastColor
149  =
150  ( PDefaultFirstColor == -1 ) ? Color::None :
151  Color( DGTAL_RED_COMPONENT( PDefaultLastColor ),
152  DGTAL_GREEN_COMPONENT( PDefaultLastColor ),
153  DGTAL_BLUE_COMPONENT( PDefaultLastColor ) )
154  );
155 
163  Color operator()( const PValue & value ) const;
164 
169 
174  GradientColorMap ( const GradientColorMap & other );
175 
181  GradientColorMap & operator= ( const GradientColorMap & other );
182 
183  // ----------------------- Interface --------------------------------------
184  public:
185 
190  void clearColors();
191 
197  void addColor( const Color & color );
198 
203  void selfDisplay ( std::ostream & out ) const;
204 
209  bool isValid() const;
210 
216  const PValue & min() const;
217 
223  const PValue & max() const;
224 
225  // ----------------------- Static methods ---------------------------------
226 
238  static Color getColor( const std::vector<Color> & colors,
239  const PValue & min,
240  const PValue & max,
241  const PValue & value );
242 
243  // ------------------------- Protected Datas ------------------------------
244  private:
245 
246  // ------------------------- Private Datas --------------------------------
247  private:
248 
249  // ------------------------- Hidden services ------------------------------
250  protected:
251 
252  PValue myMin;
253  PValue myMax;
254  std::vector<Color> myColors;
261 
262  // ------------------------- Internals ------------------------------------
263  private:
264 
265 
266  }; // end of class GradientColorMap
267 
274  template <typename PValue,
275  int PDefaultPreset,
276  int PDefaultFirstColor,
277  int PDefaultLastColor >
278  std::ostream&
279  operator<< ( std::ostream & out, const GradientColorMap<PValue,PDefaultPreset,PDefaultFirstColor,PDefaultLastColor> & object );
280 
281 } // namespace DGtal
282 
283 
285 // Includes inline functions.
286 #include "DGtal/io/colormaps/GradientColorMap.ih"
287 
288 // //
290 
291 #endif // !defined GradientColorMap_h
292 
293 #undef GradientColorMap_RECURSES
294 #endif // else defined(GradientColorMap_RECURSES)
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
static Color getColor(const std::vector< Color > &colors, const PValue &min, const PValue &max, const PValue &value)
std::vector< Color > myColors
const PValue & max() const
Color operator()(const PValue &value) const
void addColor(const Color &color)
void selfDisplay(std::ostream &out) const
const PValue & min() const
static const Color None
Definition: Color.h:387
DGtal is the top-level namespace which contains all DGtal functions and types.
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
GradientColorMap & operator=(const GradientColorMap &other)