DGtal  1.2.0
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)
35 #define GradientColorMap_RECURSES
36 
37 #if !defined GradientColorMap_h
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 -----------------------------
71 
73  // template class GradientColorMap
115  template <typename PValue,
116  int PDefaultPreset = CMAP_CUSTOM,
117  int PDefaultFirstColor = -1,
118  int PDefaultLastColor = -1 >
120  {
121 
122  public:
123 
124  typedef PValue Value;
125 
126  // ----------------------- Standard services ------------------------------
127  public:
128 
139  GradientColorMap( const PValue & min,
140  const PValue & max,
141  const ColorGradientPreset preset
142  = static_cast<ColorGradientPreset>( PDefaultPreset ),
143  const Color firstColor
144  =
145  ( PDefaultFirstColor == -1 ) ? Color::None :
146  Color( DGTAL_RED_COMPONENT( PDefaultFirstColor ),
147  DGTAL_GREEN_COMPONENT( PDefaultFirstColor ),
148  DGTAL_BLUE_COMPONENT( PDefaultFirstColor ) ),
149  const Color lastColor
150  =
151  ( PDefaultFirstColor == -1 ) ? Color::None :
152  Color( DGTAL_RED_COMPONENT( PDefaultLastColor ),
153  DGTAL_GREEN_COMPONENT( PDefaultLastColor ),
154  DGTAL_BLUE_COMPONENT( PDefaultLastColor ) )
155  );
156 
164  Color operator()( const PValue & value ) const;
165 
170 
176 
183 
184  // ----------------------- Interface --------------------------------------
185  public:
186 
191  void clearColors();
192 
198  void addColor( const Color & color );
199 
204  void selfDisplay ( std::ostream & out ) const;
205 
210  bool isValid() const;
211 
217  const PValue & min() const;
218 
224  const PValue & max() const;
225 
226  // ----------------------- Static methods ---------------------------------
227 
239  static Color getColor( const std::vector<Color> & colors,
240  const PValue & min,
241  const PValue & max,
242  PValue value );
243 
244  // ------------------------- Protected Datas ------------------------------
245  private:
246 
247  // ------------------------- Private Datas --------------------------------
248  private:
249 
250  // ------------------------- Hidden services ------------------------------
251  protected:
252 
253  PValue myMin;
254  PValue myMax;
255  std::vector<Color> myColors;
262 
263  // ------------------------- Internals ------------------------------------
264  private:
265 
266 
267  }; // end of class GradientColorMap
268 
275  template <typename PValue,
276  int PDefaultPreset,
277  int PDefaultFirstColor,
278  int PDefaultLastColor >
279  std::ostream&
281 
282 } // namespace DGtal
283 
284 
286 // Includes inline functions.
287 #include "DGtal/io/colormaps/GradientColorMap.ih"
288 
289 // //
291 
292 #endif // !defined GradientColorMap_h
293 
294 #undef GradientColorMap_RECURSES
295 #endif // else defined(GradientColorMap_RECURSES)
Structure representing an RGB triple with alpha component.
Definition: Color.h:67
static const Color None
Definition: Color.h:388
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
std::vector< Color > myColors
void addColor(const Color &color)
GradientColorMap(const GradientColorMap &other)
const PValue & max() const
void selfDisplay(std::ostream &out) const
const PValue & min() const
Color operator()(const PValue &value) const
GradientColorMap(const PValue &min, const PValue &max, const ColorGradientPreset preset=static_cast< ColorGradientPreset >(PDefaultPreset), const Color firstColor=(PDefaultFirstColor==-1) ? Color::None :Color(DGTAL_RED_COMPONENT(PDefaultFirstColor), DGTAL_GREEN_COMPONENT(PDefaultFirstColor), DGTAL_BLUE_COMPONENT(PDefaultFirstColor)), const Color lastColor=(PDefaultFirstColor==-1) ? Color::None :Color(DGTAL_RED_COMPONENT(PDefaultLastColor), DGTAL_GREEN_COMPONENT(PDefaultLastColor), DGTAL_BLUE_COMPONENT(PDefaultLastColor)))
static Color getColor(const std::vector< Color > &colors, const PValue &min, const PValue &max, PValue value)
GradientColorMap & operator=(const GradientColorMap &other)
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
@ CMAP_GRAYSCALE