DGtal 1.3.0
Loading...
Searching...
No Matches
GrayscaleColorMap.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 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
21 *
22 * @date 2010/07/19
23 *
24 * Implementation of inline methods defined in GrayscaleColorMap.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
41template <typename Value>
42inline
43DGtal::GrayscaleColorMap<Value>::GrayscaleColorMap( const Value & aMin,
44 const Value & aMax )
45 : myMin( aMin ), myMax( aMax )
46{
47 ASSERT_MSG(myMin < myMax, "Max should be strictly greather than Min in a colormap.");
48}
49
50template <typename Value>
51inline
52DGtal::GrayscaleColorMap<Value>::GrayscaleColorMap
53( const GrayscaleColorMap<Value> & other )
54 : myMin( other.myMin ), myMax( other.myMax )
55{
56 ASSERT_MSG(myMin < myMax, "Max should be strictly greather than Min in a colormap.");
57}
58
59template <typename Value>
60inline
61DGtal::GrayscaleColorMap<Value>::~GrayscaleColorMap()
62{
63}
64
65template <typename Value>
66DGtal::GrayscaleColorMap<Value> &
67DGtal::GrayscaleColorMap<Value>::operator=
68( const GrayscaleColorMap<Value> & other )
69{
70 if ( &other != this ) {
71 myMin = other.myMin;
72 myMax = other.myMax;
73 ASSERT_MSG(myMin < myMax, "Max should be strictly greather than Min in a colormap.");
74 }
75 return *this;
76}
77
78///////////////////////////////////////////////////////////////////////////////
79// Interface - public :
80
81
82template<typename Value>
83inline
84const Value &
85DGtal::GrayscaleColorMap<Value>::min() const
86{
87 return myMin;
88}
89
90template<typename Value>
91inline
92const Value &
93DGtal::GrayscaleColorMap<Value>::max() const
94{
95 return myMax;
96}
97
98template<typename Value>
99inline
100DGtal::Color
101DGtal::GrayscaleColorMap<Value>::operator()( const Value & value ) const
102{
103 return GrayscaleColorMap<Value>::getColor( myMin, myMax, value );
104}
105
106/**
107 * Writes/Displays the object on an output stream.
108 * @param out the output stream where the object is written.
109 */
110template <typename Value>
111inline
112void
113DGtal::GrayscaleColorMap<Value>::selfDisplay ( std::ostream & out ) const
114{
115 out << "[GrayscaleColorMap "
116 << " min=" << myMin
117 << " max=" << myMax
118 << " ]";
119}
120
121/**
122 * Checks the validity/consistency of the object.
123 * @return 'true' if the object is valid, 'false' otherwise.
124 */
125template <typename Value>
126inline
127bool
128DGtal::GrayscaleColorMap<Value>::isValid() const
129{
130 return true;
131}
132
133
134template <typename Value>
135inline
136DGtal::Color
137DGtal::GrayscaleColorMap<Value>::getColor( const Value & min,
138 const Value & max,
139 const Value & value )
140{
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 );
146}
147
148///////////////////////////////////////////////////////////////////////////////
149// Implementation of inline functions //
150
151template <typename Value>
152inline
153std::ostream&
154DGtal::operator<< ( std::ostream & out,
155 const GrayscaleColorMap<Value> & object )
156{
157 object.selfDisplay( out );
158 return out;
159}
160
161// //
162///////////////////////////////////////////////////////////////////////////////
163
164