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 RandomColorMap.ih
19 * @author Bertrand Kerautret (\c kerautre@loria.fr )
20 * LORIA (CNRS, UMR 7503), University of Nancy, France
24 * Implementation of inline methods defined in RandomColorMap.h
26 * This file is part of the DGtal library.
29 ///////////////////////////////////////////////////////////////////////////////
30 // IMPLEMENTATION of inline methods.
31 ///////////////////////////////////////////////////////////////////////////////
33 //////////////////////////////////////////////////////////////////////////////
35 //////////////////////////////////////////////////////////////////////////////
39 ///////////////////////////////////////////////////////////////////////////////
40 // Implementation of inline methods //
47 DGtal::RandomColorMap::RandomColorMap(const unsigned int &aFirstIndex, const unsigned int & aLastIndex,
48 const Color &aFirstColor, const Color &aLastColor)
52 ASSERT_MSG(myMin < myMax, "Max should be strictly greather than Min in a colormap.");
53 myGradientMap = new GradientColorMap<unsigned int> (aFirstIndex, aLastIndex);
54 myGradientMap->addColor(aFirstColor);
55 myGradientMap->addColor(aLastColor);
56 associateRandomIndexColor();
63 DGtal::RandomColorMap::associateRandomIndexColor(){
64 for(unsigned int i=myMin; i<=myMax; i++){
65 myColorIndex.push_back(myMax+1);
66 myFreeColorIndex.push_back(i);
69 while(myFreeColorIndex.size()!=0){
70 unsigned int pos = rand()%myFreeColorIndex.size();
71 myColorIndex[i]=myFreeColorIndex.at(pos);
72 myFreeColorIndex.erase(myFreeColorIndex.begin()+pos);
79 DGtal::RandomColorMap::~RandomColorMap()
88 DGtal::RandomColorMap::addColor( const Color &aColor)
90 myGradientMap->addColor(aColor);
91 associateRandomIndexColor();
96 DGtal::RandomColorMap::selfDisplay ( std::ostream & out ) const
98 out << "[RandomColorMap]";
104 DGtal::RandomColorMap::isValid() const
111 DGtal::RandomColorMap &
112 DGtal::RandomColorMap::operator=(const DGtal::RandomColorMap & anOther)
114 if ( &anOther != this ) {
115 myMin = anOther.myMin;
116 myMax = anOther.myMax;
117 ASSERT_MSG(myMin < myMax, "Max should be strictly greather than Min in a colormap.");
118 myColorIndex = anOther.myColorIndex;
119 myFreeColorIndex= anOther.myFreeColorIndex;
120 myGradientMap = new GradientColorMap<unsigned int> (myMin, myMax);
127 DGtal::RandomColorMap::operator()( const unsigned int & aValue ) const
129 return (*myGradientMap)(myColorIndex.at(aValue));
135 DGtal::RandomColorMap::min() const
142 DGtal::RandomColorMap::max() const
148 ///////////////////////////////////////////////////////////////////////////////
149 // Implementation of inline functions and external operators //
152 * Overloads 'operator<<' for displaying objects of class 'RandomColorMap'.
153 * @param out the output stream where the object is written.
154 * @param object the object of class 'RandomColorMap' to write.
155 * @return the output stream after the writing.
159 DGtal::operator<< ( std::ostream & out,
160 const RandomColorMap & object )
162 object.selfDisplay ( out );
167 ///////////////////////////////////////////////////////////////////////////////