DGtal 1.3.0
Loading...
Searching...
No Matches
HueShadeColorMap.ih
1/**
2 * This program is free software: you can redistribute it and/or modify
3 * it under the terms of the GNU Lesser General Public License as
4 * published by the Free Software Foundation, either version 3 of the
5 * License, or (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *
15 **/
16
17/**
18 * @file HueShadeColorMap.ih
19 * @author Sebastien Fourey (\c Sebastien.Fourey@greyc.ensicaen.fr )
20 * Groupe de Recherche en Informatique, Image, Automatique et Instrumentation de Caen - GREYC (CNRS, UMR 6072), ENSICAEN, France
21 *
22 * @date 2010/07/19
23 *
24 * Implementation of inline methods defined in HueShadeColorMap.h
25 *
26 * This file is part of the DGtal library.
27 */
28
29
30//////////////////////////////////////////////////////////////////////////////
31#include <cstdlib>
32//////////////////////////////////////////////////////////////////////////////
33
34///////////////////////////////////////////////////////////////////////////////
35// IMPLEMENTATION of inline methods.
36///////////////////////////////////////////////////////////////////////////////
37
38///////////////////////////////////////////////////////////////////////////////
39// ----------------------- Standard services ------------------------------
40
41
42template <typename Value, int DefaultCycles>
43inline
44DGtal::HueShadeColorMap<Value,DefaultCycles>::HueShadeColorMap
45( const Value & amin,
46 const Value & amax,
47 const unsigned int cycles )
48 : myMin( amin ), myMax( amax ), myCycles( cycles )
49{
50 ASSERT_MSG(myMin < myMax, "Max should be strictly greather than Min in a colormap.");
51}
52
53
54template <typename Value, int DefaultCycles>
55inline
56DGtal::HueShadeColorMap<Value,DefaultCycles>::HueShadeColorMap
57( const HueShadeColorMap<Value,DefaultCycles> & other )
58 : myMin( other.myMin ), myMax( other.myMax ), myCycles( other.myCycles )
59{
60 ASSERT_MSG(myMin < myMax, "Max should be strictly greather than Min in a colormap.");
61}
62
63template <typename Value, int DefaultCycles>
64inline
65DGtal::HueShadeColorMap<Value,DefaultCycles>::~HueShadeColorMap()
66{
67}
68
69template <typename Value, int DefaultCycles>
70DGtal::HueShadeColorMap<Value,DefaultCycles> &
71DGtal::HueShadeColorMap<Value,DefaultCycles>::operator=
72( const HueShadeColorMap<Value,DefaultCycles> & other )
73{
74 if ( &other != this ) {
75 myMin = other.myMin;
76 myMax = other.myMax;
77 ASSERT_MSG(myMin < myMax, "Max should be strictly greather than Min in a colormap.");
78 myCycles = other.myCycles;
79 }
80 return *this;
81}
82
83///////////////////////////////////////////////////////////////////////////////
84// Interface - public :
85
86template<typename Value, int DefaultCycles>
87inline
88const Value &
89DGtal::HueShadeColorMap<Value,DefaultCycles>::min() const
90{
91 return myMin;
92}
93
94template<typename Value, int DefaultCycles>
95inline
96const Value &
97DGtal::HueShadeColorMap<Value,DefaultCycles>::max() const
98{
99 return myMax;
100}
101
102template<typename Value, int DefaultCycles>
103inline
104void
105DGtal::HueShadeColorMap<Value,DefaultCycles>::setCycles( int cycles )
106{
107 myCycles = cycles;
108}
109
110
111template<typename Value, int DefaultCycles>
112inline
113DGtal::Color
114DGtal::HueShadeColorMap<Value,DefaultCycles>::operator()
115 ( const Value & value ) const
116{
117 return getColor( myCycles, myMin, myMax, value );
118}
119
120/**
121 * Writes/Displays the object on an output stream.
122 * @param out the output stream where the object is written.
123 */
124template <typename Value, int DefaultCycles>
125inline
126void
127DGtal::HueShadeColorMap<Value,DefaultCycles>::selfDisplay ( std::ostream & out ) const
128{
129 out << "[HueShadeColorMap "
130 << " min=" << myMin
131 << " max=" << myMax
132 << " cycles=" << myCycles
133 << " ]";
134}
135
136/**
137 * Checks the validity/consistency of the object.
138 * @return 'true' if the object is valid, 'false' otherwise.
139 */
140template <typename Value, int DefaultCycles>
141inline
142bool
143DGtal::HueShadeColorMap<Value,DefaultCycles>::isValid() const
144{
145 return true;
146}
147
148template <typename Value, int DefaultCycles>
149inline
150DGtal::Color
151DGtal::HueShadeColorMap<Value,DefaultCycles>::getColor
152( const unsigned int cycles,
153 const Value & min,
154 const Value & max,
155 const Value & value )
156{
157 ASSERT_MSG(min < max, "Max should be strictly greather than Min in a colormap.");
158 const double scale = ( value - min ) / static_cast<double>( max - min );
159 const double hue = 360 * ( scale * cycles - floor(scale * cycles));
160 double red, green, blue;
161 DGtal::Color::HSVtoRGB( red, green, blue, hue, 0.9, 1.0 );
162 return Color( static_cast<unsigned char>( red * 255),
163 static_cast<unsigned char>( green * 255),
164 static_cast<unsigned char>( blue * 255) );
165}
166
167///////////////////////////////////////////////////////////////////////////////
168// Implementation of inline functions //
169
170template <typename Value, int DefaultCycles>
171inline
172std::ostream&
173DGtal::operator<< ( std::ostream & out,
174 const HueShadeColorMap<Value,DefaultCycles> & object )
175{
176 object.selfDisplay( out );
177 return out;
178}
179
180// //
181///////////////////////////////////////////////////////////////////////////////
182
183
184///////////////////////////////////////////////////////////////////////////////
185// Interface - private :
186
187
188