DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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 
137  GradientColorMap( const PValue & min,
138  const PValue & max,
139  const ColorGradientPreset preset
140  = static_cast<ColorGradientPreset>( PDefaultPreset ),
141  const Color firstColor
142  =
143  ( PDefaultFirstColor == -1 ) ? Color::None :
144  Color( DGTAL_RED_COMPONENT( PDefaultFirstColor ),
145  DGTAL_GREEN_COMPONENT( PDefaultFirstColor ),
146  DGTAL_BLUE_COMPONENT( PDefaultFirstColor ) ),
147  const Color lastColor
148  =
149  ( PDefaultFirstColor == -1 ) ? Color::None :
150  Color( DGTAL_RED_COMPONENT( PDefaultLastColor ),
151  DGTAL_GREEN_COMPONENT( PDefaultLastColor ),
152  DGTAL_BLUE_COMPONENT( PDefaultLastColor ) )
153  );
154 
162  Color operator()( const PValue & value ) const;
163 
168 
173  GradientColorMap ( const GradientColorMap & other );
174 
180  GradientColorMap & operator= ( const GradientColorMap & other );
181 
182  // ----------------------- Interface --------------------------------------
183  public:
184 
189  void clearColors();
190 
196  void addColor( const Color & color );
197 
202  void selfDisplay ( std::ostream & out ) const;
203 
208  bool isValid() const;
209 
215  const PValue & min() const;
216 
222  const PValue & max() const;
223 
224  // ----------------------- Static methods ---------------------------------
225 
236  static Color getColor( const std::vector<Color> & colors,
237  const PValue & min,
238  const PValue & max,
239  const PValue & value );
240 
241  // ------------------------- Protected Datas ------------------------------
242  private:
243 
244  // ------------------------- Private Datas --------------------------------
245  private:
246 
247  // ------------------------- Hidden services ------------------------------
248  protected:
249 
250  PValue myMin;
251  PValue myMax;
252  std::vector<Color> myColors;
259 
260  // ------------------------- Internals ------------------------------------
261  private:
262 
263 
264  }; // end of class GradientColorMap
265 
272  template <typename PValue,
273  int PDefaultPreset,
274  int PDefaultFirstColor,
275  int PDefaultLastColor >
276  std::ostream&
277  operator<< ( std::ostream & out, const GradientColorMap<PValue,PDefaultPreset,PDefaultFirstColor,PDefaultLastColor> & object );
278 
279 } // namespace DGtal
280 
281 
283 // Includes inline functions.
284 #include "DGtal/io/colormaps/GradientColorMap.ih"
285 
286 // //
288 
289 #endif // !defined GradientColorMap_h
290 
291 #undef GradientColorMap_RECURSES
292 #endif // else defined(GradientColorMap_RECURSES)