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 DigitalSetBySTLSet.ih
19 * @author Jacques-Olivier Lachaud (\c jacques-olivier.lachaud@univ-savoie.fr )
20 * Laboratory of Mathematics (CNRS, UMR 5807), University of Savoie, France
22 * @author Sebastien Fourey (\c Sebastien.Fourey@greyc.ensicaen.fr )
23 * Groupe de Recherche en Informatique, Image, Automatique et
24 * Instrumentation de Caen - GREYC (CNRS, UMR 6072), ENSICAEN, France
28 * Implementation of inline methods defined in DigitalSetBySTLSet.h
30 * This file is part of the DGtal library.
34 //////////////////////////////////////////////////////////////////////////////
36 //////////////////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////////////////
39 // IMPLEMENTATION of inline methods.
40 ///////////////////////////////////////////////////////////////////////////////
42 ///////////////////////////////////////////////////////////////////////////////
43 // ----------------------- Standard services ------------------------------
48 template <typename Domain, typename Compare>
50 DGtal::DigitalSetBySTLSet<Domain, Compare>::~DigitalSetBySTLSet()
56 * Creates the empty set in the domain [d].
58 * @param d any counted pointer on domain.
60 template <typename Domain, typename Compare>
62 DGtal::DigitalSetBySTLSet<Domain, Compare>::DigitalSetBySTLSet
63 ( Clone<Domain> d, const Compare & c )
64 : myDomain( d ), mySet( c )
70 * @param other the object to clone.
72 template <typename Domain, typename Compare>
74 DGtal::DigitalSetBySTLSet<Domain, Compare>::DigitalSetBySTLSet( const DigitalSetBySTLSet<Domain, Compare> & other )
75 : myDomain( other.myDomain ), mySet( other.mySet )
81 * @param other the object to copy.
82 * @return a reference on 'this'.
84 template <typename Domain, typename Compare>
86 DGtal::DigitalSetBySTLSet<Domain, Compare> &
87 DGtal::DigitalSetBySTLSet<Domain, Compare>::operator= ( const DigitalSetBySTLSet<Domain, Compare> & other )
89 ASSERT( ( domain().lowerBound() <= other.domain().lowerBound() )
90 && ( domain().upperBound() >= other.domain().upperBound() )
91 && "This domain should include the domain of the other set in case of assignment." );
98 * @return the embedding domain.
100 template <typename Domain, typename Compare>
103 DGtal::DigitalSetBySTLSet<Domain, Compare>::domain() const
108 template <typename Domain, typename Compare>
110 DGtal::CowPtr<Domain>
111 DGtal::DigitalSetBySTLSet<Domain, Compare>::domainPointer() const
118 ///////////////////////////////////////////////////////////////////////////////
119 // Interface - public :
123 * @return the number of elements in the set.
125 template <typename Domain, typename Compare>
127 typename DGtal::DigitalSetBySTLSet<Domain, Compare>::Size
128 DGtal::DigitalSetBySTLSet<Domain, Compare>::size() const
130 return (unsigned int)mySet.size();
134 * @return 'true' iff the set is empty (no element).
136 template <typename Domain, typename Compare>
139 DGtal::DigitalSetBySTLSet<Domain, Compare>::empty() const
141 return mySet.empty();
146 * Adds point [p] to this set.
148 * @param p any digital point.
149 * @pre p should belong to the associated domain.
151 template <typename Domain, typename Compare>
154 DGtal::DigitalSetBySTLSet<Domain, Compare>::insert( const Point & p )
156 // ASSERT( domain().isInside( p ) );
162 * Adds the collection of points specified by the two iterators to
165 * @param first the start point in the collection of Point.
166 * @param last the last point in the collection of Point.
167 * @pre all points should belong to the associated domain.
169 template <typename Domain, typename Compare>
170 template <typename PointInputIterator>
172 DGtal::DigitalSetBySTLSet<Domain, Compare>::insert( PointInputIterator first, PointInputIterator last )
174 mySet.insert( first, last );
179 * Adds point [p] to this set if the point is not already in the
182 * @param p any digital point.
184 * @pre p should belong to the associated domain.
185 * @pre p should not belong to this.
187 template <typename Domain, typename Compare>
190 DGtal::DigitalSetBySTLSet<Domain, Compare>::insertNew( const Point & p )
192 // ASSERT( domain().isInside( p ) );
197 * Adds the collection of points specified by the two iterators to
200 * @param first the start point in the collection of Point.
201 * @param last the last point in the collection of Point.
203 * @pre all points should belong to the associated domain.
204 * @pre each point should not belong to this.
206 template <typename Domain, typename Compare>
207 template <typename PointInputIterator>
210 DGtal::DigitalSetBySTLSet<Domain, Compare>::insertNew
211 ( PointInputIterator first, PointInputIterator last )
213 mySet.insert( first, last );
217 * Removes point [p] from the set.
219 * @param p the point to remove.
220 * @return the number of removed elements (0 or 1).
222 template <typename Domain, typename Compare>
223 typename DGtal::DigitalSetBySTLSet<Domain, Compare>::Size
224 DGtal::DigitalSetBySTLSet<Domain, Compare>::erase( const Point & p )
226 return (unsigned int)mySet.erase( p );
230 * Removes the point pointed by [it] from the set.
232 * @param it an iterator on this set.
233 * Note: generally faster than giving just the point.
235 template <typename Domain, typename Compare>
238 DGtal::DigitalSetBySTLSet<Domain, Compare>::erase( Iterator it )
245 * @post this set is empty.
247 template <typename Domain, typename Compare>
250 DGtal::DigitalSetBySTLSet<Domain, Compare>::clear()
256 * @param p any digital point.
257 * @return a const iterator pointing on [p] if found, otherwise end().
259 template <typename Domain, typename Compare>
261 typename DGtal::DigitalSetBySTLSet<Domain, Compare>::ConstIterator
262 DGtal::DigitalSetBySTLSet<Domain, Compare>::find( const Point & p ) const
264 return mySet.find( p );
268 * @param p any digital point.
269 * @return an iterator pointing on [p] if found, otherwise end().
271 template <typename Domain, typename Compare>
273 typename DGtal::DigitalSetBySTLSet<Domain, Compare>::Iterator
274 DGtal::DigitalSetBySTLSet<Domain, Compare>::find( const Point & p )
276 return mySet.find( p );
280 * @return a const iterator on the first element in this set.
282 template <typename Domain, typename Compare>
284 typename DGtal::DigitalSetBySTLSet<Domain, Compare>::ConstIterator
285 DGtal::DigitalSetBySTLSet<Domain, Compare>::begin() const
287 return mySet.begin();
291 * @return a const iterator on the element after the last in this set.
293 template <typename Domain, typename Compare>
295 typename DGtal::DigitalSetBySTLSet<Domain, Compare>::ConstIterator
296 DGtal::DigitalSetBySTLSet<Domain, Compare>::end() const
302 * @return an iterator on the first element in this set.
304 template <typename Domain, typename Compare>
306 typename DGtal::DigitalSetBySTLSet<Domain, Compare>::Iterator
307 DGtal::DigitalSetBySTLSet<Domain, Compare>::begin()
309 return mySet.begin();
313 * @return a iterator on the element after the last in this set.
315 template <typename Domain, typename Compare>
317 typename DGtal::DigitalSetBySTLSet<Domain, Compare>::Iterator
318 DGtal::DigitalSetBySTLSet<Domain, Compare>::end()
323 template <typename Domain, typename Compare>
325 const typename DGtal::DigitalSetBySTLSet<Domain, Compare>::Container &
326 DGtal::DigitalSetBySTLSet<Domain, Compare>::container() const
331 template <typename Domain, typename Compare>
333 typename DGtal::DigitalSetBySTLSet<Domain, Compare>::Container &
334 DGtal::DigitalSetBySTLSet<Domain, Compare>::container()
341 * @param aSet any other set.
343 template <typename Domain, typename Compare>
345 DGtal::DigitalSetBySTLSet<Domain, Compare> &
346 DGtal::DigitalSetBySTLSet<Domain, Compare>::operator+=( const DigitalSetBySTLSet<Domain, Compare> & aSet )
350 Iterator it_dst = end();
351 for ( ConstIterator it_src = aSet.begin();
352 it_src != aSet.end();
355 // Use hint it_dst to go faster.
356 it_dst = mySet.insert( it_dst, *it_src );
362 //-----------------------------------------------------------------------------
363 template <typename Domain, typename Compare>
366 DGtal::DigitalSetBySTLSet<Domain, Compare>
367 ::operator()( const Point & p ) const
369 return find( p ) != end();
372 ///////////////////////////////////////////////////////////////////////////////
373 // ----------------------- Other Set services -----------------------------
376 template <typename Domain, typename Compare>
377 template <typename TOutputIterator>
380 DGtal::DigitalSetBySTLSet<Domain, Compare>::computeComplement(TOutputIterator& ito) const
382 typename Domain::ConstIterator itPoint = domain().begin();
383 typename Domain::ConstIterator itEnd = domain().end();
384 while ( itPoint != itEnd ) {
385 if ( find( *itPoint ) == end() ) {
393 * Builds the complement in the domain of the set [other_set] in
396 * @param other_set defines the set whose complement is assigned to 'this'.
398 template <typename Domain, typename Compare>
401 DGtal::DigitalSetBySTLSet<Domain, Compare>::assignFromComplement
402 ( const DigitalSetBySTLSet<Domain, Compare> & other_set )
405 typename Domain::ConstIterator itPoint = domain().begin();
406 typename Domain::ConstIterator itEnd = domain().end();
407 while ( itPoint != itEnd ) {
408 if ( other_set.find( *itPoint ) == other_set.end() ) {
416 * Computes the bounding box of this set.
418 * @param lower the first point of the bounding box (lowest in all
420 * @param upper the last point of the bounding box (highest in all
423 template <typename Domain, typename Compare>
426 DGtal::DigitalSetBySTLSet<Domain, Compare>::computeBoundingBox
427 ( Point & lower, Point & upper ) const
429 lower = domain().upperBound();
430 upper = domain().lowerBound();
431 ConstIterator it = begin();
432 ConstIterator itEnd = end();
433 while ( it != itEnd ) {
434 lower = lower.inf( *it );
435 upper = upper.sup( *it );
440 ///////////////////////////////////////////////////////////////////////////////
441 // Interface - public :
444 * Writes/Displays the object on an output stream.
445 * @param out the output stream where the object is written.
447 template <typename Domain, typename Compare>
450 DGtal::DigitalSetBySTLSet<Domain, Compare>::selfDisplay ( std::ostream & out ) const
452 out << "[DigitalSetBySTLSet]" << " size=" << size();
456 * Checks the validity/consistency of the object.
457 * @return 'true' if the object is valid, 'false' otherwise.
459 template <typename Domain, typename Compare>
462 DGtal::DigitalSetBySTLSet<Domain, Compare>::isValid() const
468 // --------------- CDrawableWithBoard2D realization -------------------------
471 * Default drawing style object.
472 * @return the dyn. alloc. default style for this object.
476 * @return the style name used for drawing this object.
478 template<typename Domain, typename Compare>
481 DGtal::DigitalSetBySTLSet<Domain, Compare>::className() const
483 return "DigitalSetBySTLSet";
486 ///////////////////////////////////////////////////////////////////////////////
487 // Implementation of inline function //
489 template <typename Domain, typename Compare>
492 DGtal::operator<< ( std::ostream & out, const DGtal::DigitalSetBySTLSet<Domain, Compare> & object )
494 object.selfDisplay( out );
499 ///////////////////////////////////////////////////////////////////////////////