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.
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.
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/>.
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
24 * Implementation of inline methods defined in HueShadeColorMap.h
26 * This file is part of the DGtal library.
30//////////////////////////////////////////////////////////////////////////////
32//////////////////////////////////////////////////////////////////////////////
34///////////////////////////////////////////////////////////////////////////////
35// IMPLEMENTATION of inline methods.
36///////////////////////////////////////////////////////////////////////////////
38///////////////////////////////////////////////////////////////////////////////
39// ----------------------- Standard services ------------------------------
42template <typename Value, int DefaultCycles>
44DGtal::HueShadeColorMap<Value,DefaultCycles>::HueShadeColorMap
47 const unsigned int cycles )
48 : myMin( amin ), myMax( amax ), myCycles( cycles )
50 ASSERT_MSG(myMin < myMax, "Max should be strictly greather than Min in a colormap.");
54template <typename Value, int DefaultCycles>
56DGtal::HueShadeColorMap<Value,DefaultCycles>::HueShadeColorMap
57( const HueShadeColorMap<Value,DefaultCycles> & other )
58 : myMin( other.myMin ), myMax( other.myMax ), myCycles( other.myCycles )
60 ASSERT_MSG(myMin < myMax, "Max should be strictly greather than Min in a colormap.");
63template <typename Value, int DefaultCycles>
65DGtal::HueShadeColorMap<Value,DefaultCycles>::~HueShadeColorMap()
69template <typename Value, int DefaultCycles>
70DGtal::HueShadeColorMap<Value,DefaultCycles> &
71DGtal::HueShadeColorMap<Value,DefaultCycles>::operator=
72( const HueShadeColorMap<Value,DefaultCycles> & other )
74 if ( &other != this ) {
77 ASSERT_MSG(myMin < myMax, "Max should be strictly greather than Min in a colormap.");
78 myCycles = other.myCycles;
83///////////////////////////////////////////////////////////////////////////////
84// Interface - public :
86template<typename Value, int DefaultCycles>
89DGtal::HueShadeColorMap<Value,DefaultCycles>::min() const
94template<typename Value, int DefaultCycles>
97DGtal::HueShadeColorMap<Value,DefaultCycles>::max() const
102template<typename Value, int DefaultCycles>
105DGtal::HueShadeColorMap<Value,DefaultCycles>::setCycles( int cycles )
111template<typename Value, int DefaultCycles>
114DGtal::HueShadeColorMap<Value,DefaultCycles>::operator()
115 ( const Value & value ) const
117 return getColor( myCycles, myMin, myMax, value );
121 * Writes/Displays the object on an output stream.
122 * @param out the output stream where the object is written.
124template <typename Value, int DefaultCycles>
127DGtal::HueShadeColorMap<Value,DefaultCycles>::selfDisplay ( std::ostream & out ) const
129 out << "[HueShadeColorMap "
132 << " cycles=" << myCycles
137 * Checks the validity/consistency of the object.
138 * @return 'true' if the object is valid, 'false' otherwise.
140template <typename Value, int DefaultCycles>
143DGtal::HueShadeColorMap<Value,DefaultCycles>::isValid() const
148template <typename Value, int DefaultCycles>
151DGtal::HueShadeColorMap<Value,DefaultCycles>::getColor
152( const unsigned int cycles,
155 const Value & value )
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) );
167///////////////////////////////////////////////////////////////////////////////
168// Implementation of inline functions //
170template <typename Value, int DefaultCycles>
173DGtal::operator<< ( std::ostream & out,
174 const HueShadeColorMap<Value,DefaultCycles> & object )
176 object.selfDisplay( out );
181///////////////////////////////////////////////////////////////////////////////
184///////////////////////////////////////////////////////////////////////////////
185// Interface - private :