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 GrayscaleColorMap.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 GrayscaleColorMap.h
26 * This file is part of the DGtal library.
30 //////////////////////////////////////////////////////////////////////////////
32 //////////////////////////////////////////////////////////////////////////////
34 ///////////////////////////////////////////////////////////////////////////////
35 // IMPLEMENTATION of inline methods.
36 ///////////////////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////////////////
39 // ----------------------- Standard services ------------------------------
41 template <typename Value>
43 DGtal::GrayscaleColorMap<Value>::GrayscaleColorMap( const Value & aMin,
45 : myMin( aMin ), myMax( aMax )
47 ASSERT_MSG(myMin < myMax, "Max should be strictly greather than Min in a colormap.");
50 template <typename Value>
52 DGtal::GrayscaleColorMap<Value>::GrayscaleColorMap
53 ( const GrayscaleColorMap<Value> & other )
54 : myMin( other.myMin ), myMax( other.myMax )
56 ASSERT_MSG(myMin < myMax, "Max should be strictly greather than Min in a colormap.");
59 template <typename Value>
61 DGtal::GrayscaleColorMap<Value>::~GrayscaleColorMap()
65 template <typename Value>
66 DGtal::GrayscaleColorMap<Value> &
67 DGtal::GrayscaleColorMap<Value>::operator=
68 ( const GrayscaleColorMap<Value> & other )
70 if ( &other != this ) {
73 ASSERT_MSG(myMin < myMax, "Max should be strictly greather than Min in a colormap.");
78 ///////////////////////////////////////////////////////////////////////////////
79 // Interface - public :
82 template<typename Value>
85 DGtal::GrayscaleColorMap<Value>::min() const
90 template<typename Value>
93 DGtal::GrayscaleColorMap<Value>::max() const
98 template<typename Value>
101 DGtal::GrayscaleColorMap<Value>::operator()( const Value & value ) const
103 return GrayscaleColorMap<Value>::getColor( myMin, myMax, value );
107 * Writes/Displays the object on an output stream.
108 * @param out the output stream where the object is written.
110 template <typename Value>
113 DGtal::GrayscaleColorMap<Value>::selfDisplay ( std::ostream & out ) const
115 out << "[GrayscaleColorMap "
122 * Checks the validity/consistency of the object.
123 * @return 'true' if the object is valid, 'false' otherwise.
125 template <typename Value>
128 DGtal::GrayscaleColorMap<Value>::isValid() const
134 template <typename Value>
137 DGtal::GrayscaleColorMap<Value>::getColor( const Value & min,
139 const Value & value )
141 ASSERT_MSG(min < max, "Max should be strictly greather than Min in a colormap.");
142 double range = static_cast<double>( max - min );
143 double scale = static_cast<double>( value - min );
144 unsigned char gray = static_cast<unsigned char>( 255.0 * ( scale / range ) );
145 return Color( gray );
148 ///////////////////////////////////////////////////////////////////////////////
149 // Implementation of inline functions //
151 template <typename Value>
154 DGtal::operator<< ( std::ostream & out,
155 const GrayscaleColorMap<Value> & object )
157 object.selfDisplay( out );
162 ///////////////////////////////////////////////////////////////////////////////