DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
RandomColorMap.ih
1 
29 
30 // IMPLEMENTATION of inline methods.
32 
34 #include <cstdlib>
36 
37 
38 
40 // Implementation of inline methods //
41 
42 
43 
44 
45 
46 inline
47 DGtal::RandomColorMap::RandomColorMap(const unsigned int &aFirstIndex, const unsigned int & aLastIndex,
48  const Color &aFirstColor, const Color &aLastColor)
49 {
50  myMin = aFirstIndex;
51  myMax = aLastIndex;
52  myGradientMap = new GradientColorMap<unsigned int> (aFirstIndex, aLastIndex);
53  myGradientMap->addColor(aFirstColor);
54  myGradientMap->addColor(aLastColor);
56 }
57 
58 
59 
60 inline
61 void
63  for(unsigned int i=myMin; i<=myMax; i++){
64  myColorIndex.push_back(myMax+1);
65  myFreeColorIndex.push_back(i);
66  }
67  unsigned int i=0;
68  while(myFreeColorIndex.size()!=0){
69  unsigned int pos = rand()%myFreeColorIndex.size();
70  myColorIndex[i]=myFreeColorIndex.at(pos);
71  myFreeColorIndex.erase(myFreeColorIndex.begin()+pos);
72  i++;
73  }
74 
75 }
76 
77 inline
79 {
80  delete myGradientMap;
81 }
82 
83 
84 
85 inline
86 void
88 {
89  myGradientMap->addColor(aColor);
90  associateRandomIndexColor();
91 }
92 
93 inline
94 void
95 DGtal::RandomColorMap::selfDisplay ( std::ostream & out ) const
96 {
97  out << "[RandomColorMap]";
98 }
99 
100 
101 inline
102 bool
104 {
105  return true;
106 }
107 
108 
109 inline
112 {
113 if ( &anOther != this ) {
114  myMin = anOther.myMin;
115  myMax = anOther.myMax;
116  myColorIndex = anOther.myColorIndex;
117  myFreeColorIndex= anOther.myFreeColorIndex;
118  myGradientMap = new GradientColorMap<unsigned int> (myMin, myMax);
119  }
120  return *this;
121 }
122 
123 inline
124 Color
125 DGtal::RandomColorMap::operator()( const unsigned int & aValue ) const
126 {
127  return (*myGradientMap)(myColorIndex.at(aValue));
128 }
129 
130 
131 inline
132 const unsigned int &
134 {
135  return myMin;
136 }
137 
138 inline
139 const unsigned int &
141 {
142  return myMax;
143 }
144 
145 
147 // Implementation of inline functions and external operators //
148 
155 inline
156 std::ostream&
157 DGtal::operator<< ( std::ostream & out,
158  const RandomColorMap & object )
159 {
160  object.selfDisplay ( out );
161  return out;
162 }
163 
164 // //
166 
167