DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
DigitalSetFromMap.ih
1 
30 
31 #include <cstdlib>
33 #include "DGtal/kernel/sets/DigitalSetFromMap.h"
35 // IMPLEMENTATION of inline methods.
37 
39 // ----------------------- Standard services ------------------------------
40 
41 // ------------------------------------------------------------------------
42 template <typename TMapImage>
43 inline
45 {
46 }
47 
48 // ------------------------------------------------------------------------
49 template <typename TMapImage>
50 inline
53  const typename Image::Value& aDefaultValue )
54  : myImgPtr( &aImage ), myFun( Functor() ), myDefault( aDefaultValue )
55 {
56 }
57 // ------------------------------------------------------------------------
58 template <typename TMapImage>
59 inline
62  : myImgPtr( other.myImgPtr ), myFun( other.myFun ), myDefault (other.myDefault)
63 {
64 }
65 
66 // ------------------------------------------------------------------------
67 template <typename TMapImage>
68 inline
72 {
73  if (this != &other)
74  {
75  myImgPtr = other.myImgPtr;
76  myFun = other.myFun;
77  myDefault = other.myDefault;
78  }
79  return *this;
80 }
81 
82 // ------------------------------------------------------------------------
83 template <typename TMapImage>
84 inline
87 {
88  return myImgPtr->domain();
89 }
90 
91 
92 
94 // Interface - public :
95 
96 
97 // ------------------------------------------------------------------------
98 template <typename TMapImage>
99 inline
102 {
103  return myImgPtr->size();
104 }
105 
106 // ------------------------------------------------------------------------
107 template <typename TMapImage>
108 inline
109 bool
111 {
112  return myImgPtr->empty();
113 }
114 
115 
116 // ------------------------------------------------------------------------
117 template <typename TMapImage>
118 inline
119 void
121 {
122  ASSERT( this->domain().isInside( p ) );
123  myImgPtr->insert( Pair( p, myDefault ) );
124 }
125 
126 
127 // ------------------------------------------------------------------------
128 template <typename TMapImage>
129 template <typename PointInputIterator>
130 void
131 DGtal::DigitalSetFromMap<TMapImage>::insert( PointInputIterator first, PointInputIterator last )
132 {
133  for (PointInputIterator it = first; it != last; ++it)
134  this->insert( *it );
135 }
136 
137 
138 // ------------------------------------------------------------------------
139 template <typename TMapImage>
140 inline
141 void
143 {
144  ASSERT( this->domain().isInside( p ) );
145  myImgPtr->insert( Pair( p, myDefault ) );
146 }
147 
148 // ------------------------------------------------------------------------
149 template <typename TMapImage>
150 template <typename PointInputIterator>
151 inline
152 void
154 ( PointInputIterator first, PointInputIterator last )
155 {
156  for (PointInputIterator it = first; it != last; ++it)
157  this->insert( *it );
158 }
159 
160 // ------------------------------------------------------------------------
161 template <typename TMapImage>
164 {
165  return myImgPtr->erase( p );
166 }
167 
168 // ------------------------------------------------------------------------
169 template <typename TMapImage>
170 inline
171 void
173 {
174  myImgPtr->erase( it.base() );
175 }
176 
177 // ------------------------------------------------------------------------
178 template <typename TMapImage>
179 inline
180 void
182 {
183  myImgPtr->clear();
184 }
185 
186 // ------------------------------------------------------------------------
187 template <typename TMapImage>
188 inline
191 {
192  return ConstIterator( myImgPtr->find( p ), myFun );
193 }
194 
195 // ------------------------------------------------------------------------
196 template <typename TMapImage>
197 inline
200 {
201  return Iterator( myImgPtr->find( p ), myFun );
202 }
203 
204 // ------------------------------------------------------------------------
205 template <typename TMapImage>
206 inline
209 {
210  return ConstIterator( myImgPtr->begin(), myFun );
211 }
212 
213 // ------------------------------------------------------------------------
214 template <typename TMapImage>
215 inline
218 {
219  return ConstIterator( myImgPtr->end(), myFun );
220 }
221 
222 // ------------------------------------------------------------------------
223 template <typename TMapImage>
224 inline
227 {
228  return Iterator( myImgPtr->begin(), myFun );
229 }
230 
231 // ------------------------------------------------------------------------
232 template <typename TMapImage>
233 inline
236 {
237  return Iterator( myImgPtr->end(), myFun );
238 }
239 
240 // ------------------------------------------------------------------------
241 template <typename TMapImage>
242 template <typename TDigitalSet>
243 inline
246 ::operator+=( const TDigitalSet & aSet )
247 {
248  if ( this != &aSet )
249  {
250  Iterator itDst = this->end();
251  for ( typename TDigitalSet::ConstIterator itSrc = aSet.begin();
252  itSrc != aSet.end();
253  ++itSrc )
254  {
255  itDst = Iterator( myImgPtr->insert( itDst.base(), Pair(*itSrc, myDefault) ),
256  myFun );
257  }
258  }
259  return *this;
260 }
261 
262 
264 // ----------------------- Other Set services -----------------------------
265 
266 // ------------------------------------------------------------------------
267 template <typename TMapImage>
268 template <typename TOutputIterator>
269 inline
270 void
272 (TOutputIterator& ito) const
273 {
274  Domain d = this->domain();
275  typename Domain::ConstIterator itPoint = d.begin();
276  typename Domain::ConstIterator itEnd = d.end();
277  while ( itPoint != itEnd ) {
278  if ( this->find( *itPoint ) == end() ) {
279  *ito++ = *itPoint;
280  }
281  ++itPoint;
282  }
283 }
284 
285 // ------------------------------------------------------------------------
286 template <typename TMapImage>
287 template <typename TDigitalSet>
288 inline
289 void
291 ( const TDigitalSet& otherSet )
292 {
293  this->clear();
294  Domain d = this->domain();
295  typename Domain::ConstIterator itPoint = d.begin();
296  typename Domain::ConstIterator itEnd = d.end();
297  while ( itPoint != itEnd ) {
298  if ( otherSet.find( *itPoint ) == otherSet.end() ) {
299  this->insert( *itPoint );
300  }
301  ++itPoint;
302  }
303 }
304 
305 // ------------------------------------------------------------------------
306 template <typename TMapImage>
307 inline
308 void
310 ( Point & lower, Point & upper ) const
311 {
312  Domain d = this->domain();
313  lower = d.upperBound();
314  upper = d.lowerBound();
315  ConstIterator it = this->begin();
316  ConstIterator itEnd = this->end();
317  while ( it != itEnd ) {
318  lower = lower.inf( *it );
319  upper = upper.sup( *it );
320  ++it;
321  }
322 }
323 
325 // Interface - public :
326 
327 template <typename TMapImage>
328 inline
329 void
331 {
332  out << "[DigitalSetFromMap]" << " size=" << size();
333 }
334 
335 template <typename TMapImage>
336 inline
337 bool
339 {
340  return ( (myImgPtr) && (myImgPtr->isValid()) );
341 }
342 
343 
344 // --------------- CDrawableWithBoard2D realization -------------------------
345 
346 template<typename TMapImage>
347 inline
348 std::string
350 {
351  return "DigitalSetFromMap";
352 }
353 
355 // Implementation of inline function //
356 
357 template <typename TMapImage>
358 inline
359 std::ostream &
360 DGtal::operator<< ( std::ostream & out, const DGtal::DigitalSetFromMap<TMapImage> & object )
361 {
362  object.selfDisplay( out );
363  return out;
364 }
365 
366 // //
368 
369