DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes
DGtal::DigitalSetBySTLVector< TDomain > Class Template Reference

#include <DigitalSetBySTLVector.h>

Collaboration diagram for DGtal::DigitalSetBySTLVector< TDomain >:
Collaboration graph
[legend]

Public Types

typedef TDomain Domain
typedef DigitalSetBySTLVector
< Domain
Self
typedef Domain::Space Space
typedef Domain::Point Point
typedef Domain::Size Size
typedef std::vector< Point >
::iterator 
Iterator
typedef std::vector< Point >
::const_iterator 
ConstIterator

Public Member Functions

 ~DigitalSetBySTLVector ()
 DigitalSetBySTLVector (const Domain &d)
 DigitalSetBySTLVector (const DigitalSetBySTLVector &other)
DigitalSetBySTLVectoroperator= (const DigitalSetBySTLVector &other)
const Domaindomain () const
Size size () const
bool empty () const
void insert (const Point &p)
template<typename PointInputIterator >
void insert (PointInputIterator first, PointInputIterator last)
void insertNew (const Point &p)
template<typename PointInputIterator >
void insertNew (PointInputIterator first, PointInputIterator last)
Size erase (const Point &p)
void erase (Iterator it)
void erase (Iterator first, Iterator last)
void clear ()
ConstIterator find (const Point &p) const
Iterator find (const Point &p)
ConstIterator begin () const
ConstIterator end () const
Iterator begin ()
Iterator end ()
DigitalSetBySTLVector< Domain > & operator+= (const DigitalSetBySTLVector< Domain > &aSet)
template<typename TOutputIterator >
void computeComplement (TOutputIterator &ito) const
void assignFromComplement (const DigitalSetBySTLVector< Domain > &other_set)
void computeBoundingBox (Point &lower, Point &upper) const
void selfDisplay (std::ostream &out) const
bool isValid () const
std::string className () const

Protected Member Functions

 DigitalSetBySTLVector ()

Protected Attributes

const DomainmyDomain
std::vector< PointmyVector

Detailed Description

template<typename TDomain>
class DGtal::DigitalSetBySTLVector< TDomain >

Aim: Realizes the concept CDigitalSet by using the STL container std::vector.

Description of template class 'DigitalSetBySTLVector'

It thus describes a modifiable set of points within the given domain [Domain].

Template Parameters:
Domaina realization of the concept CDomain.
See also:
CDigitalSet,CDomain

Definition at line 70 of file DigitalSetBySTLVector.h.


Member Typedef Documentation

template<typename TDomain>
typedef std::vector<Point>::const_iterator DGtal::DigitalSetBySTLVector< TDomain >::ConstIterator

Definition at line 79 of file DigitalSetBySTLVector.h.

template<typename TDomain>
typedef TDomain DGtal::DigitalSetBySTLVector< TDomain >::Domain

Definition at line 73 of file DigitalSetBySTLVector.h.

template<typename TDomain>
typedef std::vector<Point>::iterator DGtal::DigitalSetBySTLVector< TDomain >::Iterator

Definition at line 78 of file DigitalSetBySTLVector.h.

template<typename TDomain>
typedef Domain::Point DGtal::DigitalSetBySTLVector< TDomain >::Point

Definition at line 76 of file DigitalSetBySTLVector.h.

template<typename TDomain>
typedef DigitalSetBySTLVector<Domain> DGtal::DigitalSetBySTLVector< TDomain >::Self

Definition at line 74 of file DigitalSetBySTLVector.h.

template<typename TDomain>
typedef Domain::Size DGtal::DigitalSetBySTLVector< TDomain >::Size

Definition at line 77 of file DigitalSetBySTLVector.h.

template<typename TDomain>
typedef Domain::Space DGtal::DigitalSetBySTLVector< TDomain >::Space

Definition at line 75 of file DigitalSetBySTLVector.h.


Constructor & Destructor Documentation

template<typename Domain >
DGtal::DigitalSetBySTLVector< Domain >::~DigitalSetBySTLVector ( )
inline

Destructor.

Definition at line 47 of file DigitalSetBySTLVector.ih.

{
}
template<typename Domain >
DGtal::DigitalSetBySTLVector< Domain >::DigitalSetBySTLVector ( const Domain d)
inline

Constructor. Creates the empty set in the domain [d].

Parameters:
dany domain.

Definition at line 60 of file DigitalSetBySTLVector.ih.

: myDomain( d ), myVector()
{
}
template<typename Domain >
DGtal::DigitalSetBySTLVector< Domain >::DigitalSetBySTLVector ( const DigitalSetBySTLVector< TDomain > &  other)
inline

Copy constructor.

Parameters:
otherthe object to clone.

Definition at line 72 of file DigitalSetBySTLVector.ih.

: myDomain( other.myDomain ), myVector( other.myVector )
{
}
template<typename TDomain>
DGtal::DigitalSetBySTLVector< TDomain >::DigitalSetBySTLVector ( )
protected

Default Constructor. Forbidden since a Domain is necessary for defining a set.


Member Function Documentation

template<typename Domain >
void DGtal::DigitalSetBySTLVector< Domain >::assignFromComplement ( const DigitalSetBySTLVector< Domain > &  other_set)
inline

Builds the complement in the domain of the set [other_set] in this.

Parameters:
other_setdefines the set whose complement is assigned to 'this'.

Definition at line 419 of file DigitalSetBySTLVector.ih.

References DGtal::DigitalSetBySTLVector< TDomain >::begin(), and DGtal::DigitalSetBySTLVector< TDomain >::end().

{
clear();
typename Domain::ConstIterator itPoint = myDomain.begin();
typename Domain::ConstIterator itEnd = myDomain.end();
while ( itPoint != itEnd ) {
if ( std::find( other_set.begin(),
other_set.end(),
*itPoint ) == other_set.end() ) {
insert( *itPoint );
}
++itPoint;
}
}
template<typename Domain >
DGtal::DigitalSetBySTLVector< Domain >::ConstIterator DGtal::DigitalSetBySTLVector< Domain >::begin ( ) const
inline
template<typename Domain >
DGtal::DigitalSetBySTLVector< Domain >::Iterator DGtal::DigitalSetBySTLVector< Domain >::begin ( )
inline
Returns:
an iterator on the first element in this set.

Definition at line 346 of file DigitalSetBySTLVector.ih.

{
return myVector.begin();
}
template<typename Domain >
std::string DGtal::DigitalSetBySTLVector< Domain >::className ( ) const
inline

Default drawing style object.

Returns:
the dyn. alloc. default style for this object.
the style name used for drawing this object.
the style name used for drawing this object.

Definition at line 503 of file DigitalSetBySTLVector.ih.

Referenced by DGtal::Display3DFactory::draw().

{
return "DigitalSetBySTLVector";
}
template<typename Domain >
void DGtal::DigitalSetBySTLVector< Domain >::clear ( )
inline

Clears the set.

Postcondition:
this set is empty.

Definition at line 281 of file DigitalSetBySTLVector.ih.

{
myVector.clear();
}
template<typename Domain >
void DGtal::DigitalSetBySTLVector< Domain >::computeBoundingBox ( Point lower,
Point upper 
) const
inline

Computes the bounding box of this set.

Parameters:
lowerthe first point of the bounding box (lowest in all directions).
upperthe last point of the bounding box (highest in all directions).

Definition at line 446 of file DigitalSetBySTLVector.ih.

{
if ( begin() != end() )
{
ConstIterator it = begin();
ConstIterator it_end = end();
upper = lower = *it;
for ( ; it != it_end; ++it )
if ( it->isLower( lower ) ) lower = *it;
else if ( it->isUpper( upper ) ) upper = *it;
}
else
{
lower = myDomain.upperBound();
upper = myDomain.lowerBound();
}
}
template<typename Domain >
template<typename TOutputIterator >
void DGtal::DigitalSetBySTLVector< Domain >::computeComplement ( TOutputIterator &  ito) const
inline

Computes the complement in the domain of this set

Parameters:
itoan output iterator
Template Parameters:
TOutputIteratora model of output iterator

Definition at line 397 of file DigitalSetBySTLVector.ih.

{
typename Domain::ConstIterator itPoint = myDomain.begin();
typename Domain::ConstIterator itEnd = myDomain.end();
while ( itPoint != itEnd ) {
if ( std::find( begin(), end(), *itPoint ) == end() ) {
*ito++ = *itPoint;
}
++itPoint;
}
}
template<typename Domain >
const Domain & DGtal::DigitalSetBySTLVector< Domain >::domain ( ) const
inline
Returns:
the embedding domain.

Definition at line 102 of file DigitalSetBySTLVector.ih.

{
return myDomain;
}
template<typename Domain >
bool DGtal::DigitalSetBySTLVector< Domain >::empty ( ) const
inline
Returns:
'true' iff the set is empty (no element).

Definition at line 127 of file DigitalSetBySTLVector.ih.

{
return myVector.empty();
}
template<typename Domain >
DGtal::DigitalSetBySTLVector< Domain >::ConstIterator DGtal::DigitalSetBySTLVector< Domain >::end ( ) const
inline
template<typename Domain >
DGtal::DigitalSetBySTLVector< Domain >::Iterator DGtal::DigitalSetBySTLVector< Domain >::end ( )
inline
Returns:
a iterator on the element after the last in this set.

Definition at line 358 of file DigitalSetBySTLVector.ih.

{
return myVector.end();
}
template<typename Domain >
DGtal::DigitalSetBySTLVector< Domain >::Size DGtal::DigitalSetBySTLVector< Domain >::erase ( const Point p)
inline

Removes point [p] from the set.

Parameters:
pthe point to remove.
Returns:
the number of removed elements (0 or 1).

Definition at line 224 of file DigitalSetBySTLVector.ih.

{
Iterator it = find( p );
if ( it != end() )
{
erase( it );
return 1;
}
return 0;
}
template<typename Domain >
void DGtal::DigitalSetBySTLVector< Domain >::erase ( Iterator  it)
inline

Removes the point pointed by [it] from the set.

Parameters:
itan iterator on this set.
Precondition:
it should point on a valid element ( it != end() ). Note: generally faster than giving just the point.

Definition at line 245 of file DigitalSetBySTLVector.ih.

{
*it = myVector.back();
myVector.pop_back();
}
template<typename Domain >
void DGtal::DigitalSetBySTLVector< Domain >::erase ( Iterator  first,
Iterator  last 
)
inline

Removes the collection of points specified by the two iterators from this set.

Parameters:
firstthe start point in this set.
lastthe last point in this set.

Definition at line 261 of file DigitalSetBySTLVector.ih.

{
while ( ( last != end() )
&& ( first != last ) )
{
*first++ = myVector.back();
myVector.pop_back();
}
if ( first != last )
while ( first != end() )
myVector.pop_back();
}
template<typename Domain >
DGtal::DigitalSetBySTLVector< Domain >::ConstIterator DGtal::DigitalSetBySTLVector< Domain >::find ( const Point p) const
inline
Parameters:
pany digital point.
Returns:
a const iterator pointing on [p] if found, otherwise end().

Definition at line 293 of file DigitalSetBySTLVector.ih.

{
const ConstIterator it_end = end();
for ( ConstIterator it = begin(); it != it_end; ++it )
if ( p == *it ) return it;
return it_end;
}
template<typename Domain >
DGtal::DigitalSetBySTLVector< Domain >::Iterator DGtal::DigitalSetBySTLVector< Domain >::find ( const Point p)
inline
Parameters:
pany digital point.
Returns:
an iterator pointing on [p] if found, otherwise end().

Definition at line 308 of file DigitalSetBySTLVector.ih.

{
const Iterator it_end = end();
for ( Iterator it = begin(); it != it_end; ++it )
if ( p == *it ) return it;
return it_end;
}
template<typename Domain >
void DGtal::DigitalSetBySTLVector< Domain >::insert ( const Point p)
inline

Adds point [p] to this set.

Parameters:
pany digital point.
Precondition:
p should belong to the associated domain.

Definition at line 141 of file DigitalSetBySTLVector.ih.

{
// ASSERT( myDomain.isInside( p ) );
Iterator it = find( p );
if ( it == end() )
myVector.push_back( p );
}
template<typename Domain >
template<typename PointInputIterator >
void DGtal::DigitalSetBySTLVector< Domain >::insert ( PointInputIterator  first,
PointInputIterator  last 
)
inline

Adds the collection of points specified by the two iterators to this set.

Parameters:
firstthe start point in the collection of Point.
lastthe last point in the collection of Point.
Precondition:
all points should belong to the associated domain.

Definition at line 162 of file DigitalSetBySTLVector.ih.

{
for ( ; first != last; ++first )
insert( *first );
}
template<typename Domain >
void DGtal::DigitalSetBySTLVector< Domain >::insertNew ( const Point p)
inline

Adds point [p] to this set if the point is not already in the set. There is no defined behavior if the point is already in the set (for instance, may be present twice).

Parameters:
pany digital point.
Precondition:
p should belong to the associated domain.
p should not belong to this.

Definition at line 181 of file DigitalSetBySTLVector.ih.

{
// ASSERT( myDomain.isInside( p ) );
ASSERT_ALL_PRE( find( p ) == end() );
myVector.push_back( p );
}
template<typename Domain >
template<typename PointInputIterator >
void DGtal::DigitalSetBySTLVector< Domain >::insertNew ( PointInputIterator  first,
PointInputIterator  last 
)
inline

Adds the collection of points specified by the two iterators to this set. The collection should contain distinct points. Each of these points should also not belong already to the set. set. There is no defined behavior if the preceding requisites are not satisfied (for instance, points may be present several times in the set).

Parameters:
firstthe start point in the collection of Point.
lastthe last point in the collection of Point.
Precondition:
all points should belong to the associated domain.
each point should not belong to this.

Definition at line 207 of file DigitalSetBySTLVector.ih.

{
while ( first != last )
myVector.push_back( *first++ );
// std::copy( first, last, myVector.end() );
}
template<typename Domain >
bool DGtal::DigitalSetBySTLVector< Domain >::isValid ( ) const
inline

Checks the validity/consistency of the object.

Returns:
'true' if the object is valid, 'false' otherwise.

Definition at line 487 of file DigitalSetBySTLVector.ih.

{
return true;
}
template<typename Domain >
DGtal::DigitalSetBySTLVector< Domain > & DGtal::DigitalSetBySTLVector< Domain >::operator+= ( const DigitalSetBySTLVector< Domain > &  aSet)
inline

set union to left.

Parameters:
aSetany other set.

Definition at line 371 of file DigitalSetBySTLVector.ih.

References DGtal::DigitalSetBySTLVector< TDomain >::myVector.

{
if ( this != &aSet )
{
std::vector<Point> other( aSet.myVector );
std::stable_sort( other.begin(), other.end() );
std::stable_sort( begin(), end() );
std::vector<Point> new_vector;
new_vector.reserve( size() + other.size() );
std::set_union( begin(), end(), other.begin(), other.end(),
std::back_insert_iterator< std::vector<Point> >
( new_vector ) );
myVector.swap( new_vector );
}
return *this;
}
template<typename Domain >
DGtal::DigitalSetBySTLVector< Domain > & DGtal::DigitalSetBySTLVector< Domain >::operator= ( const DigitalSetBySTLVector< TDomain > &  other)
inline

Assignment.

Parameters:
otherthe object to copy.
Returns:
a reference on 'this'.

Definition at line 86 of file DigitalSetBySTLVector.ih.

References DGtal::DigitalSetBySTLVector< TDomain >::myDomain, and DGtal::DigitalSetBySTLVector< TDomain >::myVector.

{
ASSERT( ( myDomain.lowerBound() <= other.myDomain.lowerBound() )
&& ( myDomain.upperBound() >= other.myDomain.upperBound() )
&& "This domain should include the domain of the other set in case of assignment." );
myVector = other.myVector;
return *this;
}
template<typename Domain >
void DGtal::DigitalSetBySTLVector< Domain >::selfDisplay ( std::ostream &  out) const
inline

Writes/Displays the object on an output stream.

Parameters:
outthe output stream where the object is written.

Definition at line 475 of file DigitalSetBySTLVector.ih.

{
out << "[DigitalSetBySTLVector]" << " size=" << size();
}
template<typename Domain >
DGtal::DigitalSetBySTLVector< Domain >::Size DGtal::DigitalSetBySTLVector< Domain >::size ( ) const
inline
Returns:
the number of elements in the set.

Definition at line 116 of file DigitalSetBySTLVector.ih.

{
return (unsigned int)myVector.size();
}

Field Documentation

template<typename TDomain>
const Domain& DGtal::DigitalSetBySTLVector< TDomain >::myDomain
protected

The associated domain.

Definition at line 298 of file DigitalSetBySTLVector.h.

Referenced by DGtal::DigitalSetBySTLVector< TDomain >::operator=().

template<typename TDomain>
std::vector<Point> DGtal::DigitalSetBySTLVector< TDomain >::myVector
protected

The container storing the points of the set.

Definition at line 303 of file DigitalSetBySTLVector.h.

Referenced by DGtal::DigitalSetBySTLVector< TDomain >::operator+=(), and DGtal::DigitalSetBySTLVector< TDomain >::operator=().


The documentation for this class was generated from the following files: