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 ColorBrightnessColorMap.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 ColorBrightnessColorMap.h
26 * This file is part of the DGtal library.
30 //////////////////////////////////////////////////////////////////////////////
32 //////////////////////////////////////////////////////////////////////////////
34 ///////////////////////////////////////////////////////////////////////////////
35 // IMPLEMENTATION of inline methods.
36 ///////////////////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////////////////
39 // ----------------------- Standard services ------------------------------
42 template <typename PValue, int PDefaultColor>
44 DGtal::ColorBrightnessColorMap<PValue,PDefaultColor>::ColorBrightnessColorMap
45 ( const PValue & minV, const PValue & maxV, const Color color )
46 : myMin( minV ), myMax( maxV ), myColor( color )
48 ASSERT_MSG(myMin < myMax, "Max should be strictly greather than Min in a colormap.");
52 template <typename PValue, int PDefaultColor>
54 DGtal::ColorBrightnessColorMap<PValue,PDefaultColor>::ColorBrightnessColorMap
55 ( const ColorBrightnessColorMap<PValue,PDefaultColor> & other )
56 : myMin( other.myMin ), myMax( other.myMax ), myColor( other.myColor )
58 ASSERT_MSG(myMin < myMax, "Max should be strictly greather than Min in a colormap.");
61 template <typename PValue, int PDefaultColor>
63 DGtal::ColorBrightnessColorMap<PValue,PDefaultColor>::~ColorBrightnessColorMap()
67 template <typename PValue, int PDefaultColor>
68 DGtal::ColorBrightnessColorMap<PValue,PDefaultColor> &
69 DGtal::ColorBrightnessColorMap<PValue,PDefaultColor>::operator=
70 ( const ColorBrightnessColorMap<PValue,PDefaultColor> & other )
72 if ( &other != this ) {
75 myColor = other.myColor;
76 ASSERT_MSG(myMin < myMax, "Max should be strictly greather than Min in a colormap.");
81 ///////////////////////////////////////////////////////////////////////////////
82 // Interface - public :
84 template<typename PValue, int PDefaultColor>
87 DGtal::ColorBrightnessColorMap<PValue,PDefaultColor>::min() const
92 template<typename PValue, int PDefaultColor>
95 DGtal::ColorBrightnessColorMap<PValue,PDefaultColor>::max() const
100 template<typename PValue, int PDefaultColor>
103 DGtal::ColorBrightnessColorMap<PValue,PDefaultColor>::operator()( const PValue & value ) const
105 return ColorBrightnessColorMap<PValue,PDefaultColor>::getColor( myColor, myMin, myMax, value );
109 * Writes/Displays the object on an output stream.
110 * @param out the output stream where the object is written.
112 template <typename PValue, int PDefaultColor>
115 DGtal::ColorBrightnessColorMap<PValue,PDefaultColor>::selfDisplay ( std::ostream & out ) const
117 out << "[ColorBrightnessColorMap "
121 << myColor.red() << ","
122 << myColor.green() << ","
123 << myColor.blue() << ") "
128 * Checks the validity/consistency of the object.
129 * @return 'true' if the object is valid, 'false' otherwise.
131 template <typename PValue, int PDefaultColor>
134 DGtal::ColorBrightnessColorMap<PValue,PDefaultColor>::isValid() const
139 template <typename PValue, int PDefaultColor>
142 DGtal::ColorBrightnessColorMap<PValue,PDefaultColor>::getColor( const Color color,
145 const PValue & value )
147 ASSERT_MSG(min < max, "Max should be strictly greather than Min in a colormap.");
149 DGtal::Color::RGBtoHSV( h, s, v,
153 const double range = static_cast<double>( max - min );
154 const double scale = static_cast<double>( value - min ) / range;
155 double red, green, blue;
156 DGtal::Color::HSVtoRGB( red, green, blue, h, s, v * scale );
157 return DGtal::Color( static_cast<unsigned char>( red * 255),
158 static_cast<unsigned char>( green * 255),
159 static_cast<unsigned char>( blue * 255) );
162 ///////////////////////////////////////////////////////////////////////////////
163 // Implementation of inline functions //
165 template <typename PValue, int PDefaultColor>
168 DGtal::operator<< ( std::ostream & out,
169 const ColorBrightnessColorMap<PValue,PDefaultColor> & object )
171 object.selfDisplay( out );
176 ///////////////////////////////////////////////////////////////////////////////
179 ///////////////////////////////////////////////////////////////////////////////
180 // Interface - private :