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 TickedColorMap.ih
19 * @author David Coeurjolly (\c david.coeurjolly@liris.cnrs.fr )
20 * Laboratoire d'InfoRmatique en Image et Systemes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
24 * Implementation of inline methods defined in TickedColorMap.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, typename CMAP>
44DGtal::TickedColorMap<Value,CMAP>::TickedColorMap
48 : myMin( amin ), myMax( amax ), myTickColor( color )
50 ASSERT_MSG(myMin < myMax, "Max should be strictly greather than Min in a colormap.");
51 myColorMap = new ColorMap(myMin,myMax);
54template <typename Value, typename CMAP>
56DGtal::TickedColorMap<Value,CMAP>::TickedColorMap
57( const ColorMap& other,
59 : myMin( other.min() ), myMax( other.max() ), myTickColor( color )
61 ASSERT_MSG(myMin < myMax, "Max should be strictly greather than Min in a colormap.");
62 myColorMap = new ColorMap( other );
66template <typename Value, typename CMAP>
68DGtal::TickedColorMap<Value,CMAP>::TickedColorMap
69( const TickedColorMap<Value,CMAP> & other )
70 : myMin( other.myMin ), myMax( other.myMax ), myTickColor( other.myTickColor )
72 ASSERT_MSG(myMin < myMax, "Max should be strictly greather than Min in a colormap.");
75template <typename Value, typename CMAP>
77DGtal::TickedColorMap<Value,CMAP>::~TickedColorMap()
82template <typename Value, typename CMAP>
83DGtal::TickedColorMap<Value,CMAP> &
84DGtal::TickedColorMap<Value,CMAP>::operator=
85( const TickedColorMap<Value,CMAP> & other )
87 if ( &other != this ) {
90 ASSERT_MSG(myMin < myMax, "Max should be strictly greather than Min in a colormap.");
91 myTickColor = other.myTickColor;
92 myTicks = other.myTicks;
97///////////////////////////////////////////////////////////////////////////////
98// Interface - public :
100template<typename Value, typename CMAP>
103DGtal::TickedColorMap<Value,CMAP>::min() const
108template<typename Value, typename CMAP>
111DGtal::TickedColorMap<Value,CMAP>::max() const
116template<typename Value, typename CMAP>
119DGtal::TickedColorMap<Value,CMAP>::operator()( const Value & value ) const
121 //If there's no ticks, just return the color.
122 if (myTicks.size()==0)
123 return myColorMap->operator()(value);
125 typename std::vector< std::pair<Value,Value> >::const_iterator up;
127 //Test the upper bound
128 up = std::upper_bound(myTicks.begin(), myTicks.end(), std::make_pair(value,value));
129 if (up == myTicks.end())
131 if (std::abs(value - myTicks[myTicks.size() -1].first) < myTicks[myTicks.size() -1].second)
134 return myColorMap->operator()(value);
137 if (std::abs(value - up->first) < up->second)
140 //We test the lower bound
141 if ((up != myTicks.begin()) &&
142 (std::abs(value - (up-1)->first) < (up-1)->second))
145 return myColorMap->operator()(value);
149 * Writes/Displays the object on an output stream.
150 * @param out the output stream where the object is written.
152template <typename Value, typename CMAP>
155DGtal::TickedColorMap<Value,CMAP>::selfDisplay ( std::ostream & out ) const
157 out << "[TickedColorMap "
160 << " tickColor= "<< myTickColor
161 << " number of ticks = "<< myTicks.size()
165template<typename Value, typename CMAP>
167void DGtal::TickedColorMap<Value,CMAP>::addTick(const Value tick,
168 const Value thickness)
170 ASSERT( tick >= myMin );
171 ASSERT( tick <= myMax );
173 myTicks.push_back(std::make_pair(tick,thickness));
176template<typename Value, typename CMAP>
178void DGtal::TickedColorMap<Value,CMAP>::addRegularTicks(const unsigned int nbTicks,
179 const Value thickness)
181 const Value width=myMax-myMin;
182 for(unsigned int i=0; i < nbTicks; ++i)
183 myTicks.push_back(std::make_pair(myMin + static_cast<Value>((double)i*width/(double)nbTicks),
188template<typename Value, typename CMAP>
190void DGtal::TickedColorMap<Value,CMAP>::finalize()
192 std::sort(myTicks.begin(), myTicks.end());
197 * Checks the validity/consistency of the object.
198 * @return 'true' if the object is valid, 'false' otherwise.
200template <typename Value, typename CMAP>
203DGtal::TickedColorMap<Value,CMAP>::isValid() const
209///////////////////////////////////////////////////////////////////////////////
210// Implementation of inline functions //
212template <typename Value, typename CMAP>
215DGtal::operator<< ( std::ostream & out,
216 const TickedColorMap<Value,CMAP> & object )
218 object.selfDisplay( out );
223///////////////////////////////////////////////////////////////////////////////