DGtal  1.5.beta
SimpleDistanceColorMap.h
1 
17 #pragma once
18 
31 #if defined(SimpleDistanceColorMap_RECURSES)
32 #error Recursive header files inclusion detected in SimpleDistanceColorMap.h
33 #else // defined(SimpleDistanceColorMap_RECURSES)
35 #define SimpleDistanceColorMap_RECURSES
36 
37 #if !defined SimpleDistanceColorMap_h
39 #define SimpleDistanceColorMap_h
40 
42 // Inclusions
43 #include <iostream>
44 #include "DGtal/base/Common.h"
45 #include "DGtal/kernel/NumberTraits.h"
46 #include "DGtal/io/Color.h"
48 
49 namespace DGtal
50 {
51 
53  // class SimpleDistanceColorMap
63  template <typename TValue>
65  {
66  // ----------------------- Standard services ------------------------------
67  public:
68 
70  typedef TValue Value;
71 
78 
86 
87 
96  const Value & amax,
97  const bool withTick=true):
98  myMin(amin), myMax(amax), myTick(withTick)
99  {}
100 
101 
102 
109  Color operator()( const Value & aValue ) const
110  {
113  const double d = 1. - val;
114  double r = (1. - d*d) * .8;
115  double g = (1. - (2. * (d - .5)) * (2. * (d - .5))) * .7;
116  double b = (1. - (1. - d) * (1. - d));
117 
118  // lines
119  if (myTick)
120  {
121  double h = val;
122  h = h * 30.;
123  h = h - floor( h );
124  h = (1. / (1. + exp(-100.*(h - .55)))) + (1. / (1. + exp(-100.*(-h + .45))));
125  h = 1. - h;
126  r = h + (1. -h)*r;
127  g = h + (1. - h)*g;
128  b = h + (1. - h)*b;
129  }
130 
131  return Color(static_cast<unsigned char>(r*255),
132  static_cast<unsigned char>(g*255),
133  static_cast<unsigned char>(b*255));
134  }
135 
136 
137 
138  // ----------------------- Interface --------------------------------------
139  public:
140 
145  void selfDisplay ( std::ostream & out ) const;
146 
151  bool isValid() const { return true;}
152 
158  const Value & min() const
159  {
160  return myMin;
161  }
162 
168  const Value & max() const
169  {
170  return myMax;
171  }
172 
173  // ------------------------- Protected Datas ------------------------------
174  protected:
175 
178 
181 
183  bool myTick;
184 
185  // ------------------------- Hidden services ------------------------------
186  protected:
187 
193 
194 
195  }; // end of class SimpleDistanceColorMap
196 } // namespace DGtal
197 
198 
199 // //
201 
202 #endif // !defined SimpleDistanceColorMap
203 
204 #undef SimpleDistanceColorMap_RECURSES
205 #endif // else defined(SimpleDistanceColorMap_RECURSES)
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
Aim: simple blue to red colormap for distance information for instance.
void selfDisplay(std::ostream &out) const
SimpleDistanceColorMap(const Value &amin, const Value &amax, const bool withTick=true)
SimpleDistanceColorMap(const SimpleDistanceColorMap &other)
SimpleDistanceColorMap & operator=(const SimpleDistanceColorMap &anOther)
Color operator()(const Value &aValue) const
bool myTick
Boolean to activate/desactivate ticks.
DGtal is the top-level namespace which contains all DGtal functions and types.
static double castToDouble(const std::decay< T >::type &aT)
Cast method to double (for I/O or board export uses only).
Definition: NumberTraits.h:164
Aim: The traits class for all models of Cinteger.
Definition: NumberTraits.h:564