DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
GrayscaleColorMap.ih
1 
30 
31 #include <cstdlib>
33 
35 // IMPLEMENTATION of inline methods.
37 
39 // ----------------------- Standard services ------------------------------
40 
41 template <typename Value>
42 inline
44  const Value & aMax )
45  : myMin( aMin ), myMax( aMax )
46 { }
47 
48 template <typename Value>
49 inline
51 ( const GrayscaleColorMap<Value> & other )
52  : myMin( other.myMin ), myMax( other.myMax )
53 {
54 }
55 
56 template <typename Value>
57 inline
59 {
60 }
61 
62 template <typename Value>
65 ( const GrayscaleColorMap<Value> & other )
66 {
67  if ( &other != this ) {
68  myMin = other.myMin;
69  myMax = other.myMax;
70  }
71  return *this;
72 }
73 
75 // Interface - public :
76 
77 
78 template<typename Value>
79 inline
80 const Value &
82 {
83  return myMin;
84 }
85 
86 template<typename Value>
87 inline
88 const Value &
90 {
91  return myMax;
92 }
93 
94 template<typename Value>
95 inline
96 Color
98 {
99  return GrayscaleColorMap<Value>::getColor( myMin, myMax, value );
100 }
101 
106 template <typename Value>
107 inline
108 void
110 {
111  out << "[GrayscaleColorMap "
112  << " min=" << myMin
113  << " max=" << myMax
114  << " ]";
115 }
116 
121 template <typename Value>
122 inline
123 bool
125 {
126  return true;
127 }
128 
129 
130 template <typename Value>
131 inline
132 Color
134  const Value & max,
135  const Value & value )
136 {
137  double range = static_cast<double>( max - min );
138  double scale = static_cast<double>( value - min );
139  unsigned char gray = static_cast<unsigned char>( 255.0 * ( scale / range ) );
140  return Color( gray );
141 }
142 
144 // Implementation of inline functions //
145 
146 template <typename Value>
147 inline
148 std::ostream&
149 DGtal::operator<< ( std::ostream & out,
150  const GrayscaleColorMap<Value> & object )
151 {
152  object.selfDisplay( out );
153  return out;
154 }
155 
156 // //
158 
159