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::DigitalSetFromMap< TMapImage > Class Template Reference

#include <DigitalSetFromMap.h>

Collaboration diagram for DGtal::DigitalSetFromMap< TMapImage >:
Collaboration graph
[legend]

Public Types

typedef TMapImage Image
typedef std::pair< const
typename Image::Point,
typename Image::Value
Pair
typedef DigitalSetFromMap< ImageSelf
typedef Image::Domain Domain
typedef Domain::Point Point
typedef Domain::Size Size
typedef Pair1st< PointFunctor
typedef ConstIteratorAdapter
< typename
Image::ConstIterator, Functor,
Point
ConstIterator
typedef ConstIteratorAdapter
< typename Image::Iterator,
Functor, Point
Iterator

Public Member Functions

 ~DigitalSetFromMap ()
 DigitalSetFromMap (Image &aImage, const typename Image::Value &aDefaultValue=0)
 DigitalSetFromMap (const DigitalSetFromMap &other)
DigitalSetFromMapoperator= (const DigitalSetFromMap &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 ()
template<typename TDigitalSet >
Selfoperator+= (const TDigitalSet &aSet)
template<typename TOutputIterator >
void computeComplement (TOutputIterator &ito) const
template<typename TDigitalSet >
void assignFromComplement (const TDigitalSet &otherSet)
void computeBoundingBox (Point &lower, Point &upper) const
void selfDisplay (std::ostream &out) const
bool isValid () const
std::string className () const

Protected Member Functions

 DigitalSetFromMap ()

Protected Attributes

ImagemyImgPtr
Functor myFun
Image::Value myDefault

Detailed Description

template<typename TMapImage>
class DGtal::DigitalSetFromMap< TMapImage >

Aim: An adapter for viewing an associative image container like ImageContainerBySTLMap as a simple digital set. This class is merely based on an aliasing pointer on the image, which must exists elsewhere.

Description of template class 'DigitalSetFromMap'

Model of CDigitalSet.

Template Parameters:
TMapImagetype of associative image container

Definition at line 73 of file DigitalSetFromMap.h.


Member Typedef Documentation

template<typename TMapImage>
typedef ConstIteratorAdapter<typename Image::ConstIterator, Functor, Point> DGtal::DigitalSetFromMap< TMapImage >::ConstIterator

Definition at line 88 of file DigitalSetFromMap.h.

template<typename TMapImage>
typedef Image::Domain DGtal::DigitalSetFromMap< TMapImage >::Domain

Definition at line 83 of file DigitalSetFromMap.h.

template<typename TMapImage>
typedef Pair1st<Point> DGtal::DigitalSetFromMap< TMapImage >::Functor

Definition at line 87 of file DigitalSetFromMap.h.

template<typename TMapImage>
typedef TMapImage DGtal::DigitalSetFromMap< TMapImage >::Image

Definition at line 77 of file DigitalSetFromMap.h.

template<typename TMapImage>
typedef ConstIteratorAdapter<typename Image::Iterator, Functor, Point> DGtal::DigitalSetFromMap< TMapImage >::Iterator

Definition at line 89 of file DigitalSetFromMap.h.

template<typename TMapImage>
typedef std::pair<const typename Image::Point, typename Image::Value> DGtal::DigitalSetFromMap< TMapImage >::Pair

Definition at line 79 of file DigitalSetFromMap.h.

template<typename TMapImage>
typedef Domain::Point DGtal::DigitalSetFromMap< TMapImage >::Point

Definition at line 84 of file DigitalSetFromMap.h.

template<typename TMapImage>
typedef DigitalSetFromMap<Image> DGtal::DigitalSetFromMap< TMapImage >::Self

Definition at line 80 of file DigitalSetFromMap.h.

template<typename TMapImage>
typedef Domain::Size DGtal::DigitalSetFromMap< TMapImage >::Size

Definition at line 85 of file DigitalSetFromMap.h.


Constructor & Destructor Documentation

template<typename TMapImage >
DGtal::DigitalSetFromMap< TMapImage >::~DigitalSetFromMap ( )
inline

Destructor.

Definition at line 44 of file DigitalSetFromMap.ih.

{
}
template<typename TMapImage >
DGtal::DigitalSetFromMap< TMapImage >::DigitalSetFromMap ( Image aImage,
const typename Image::Value aDefaultValue = 0 
)
inline

Constructor. Link the adapter to an existing image.

Parameters:
aImageany associative image container.
aDefaultValuevalue assigned to new points in the underlying image (0 by default).

Definition at line 52 of file DigitalSetFromMap.ih.

: myImgPtr( &aImage ), myFun( Functor() ), myDefault( aDefaultValue )
{
}
template<typename TMapImage >
DGtal::DigitalSetFromMap< TMapImage >::DigitalSetFromMap ( const DigitalSetFromMap< TMapImage > &  other)
inline

Copy constructor.

Parameters:
otherthe object to clone.

Definition at line 61 of file DigitalSetFromMap.ih.

: myImgPtr( other.myImgPtr ), myFun( other.myFun ), myDefault (other.myDefault)
{
}
template<typename TMapImage>
DGtal::DigitalSetFromMap< TMapImage >::DigitalSetFromMap ( )
protected

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


Member Function Documentation

template<typename TMapImage >
template<typename TDigitalSet >
void DGtal::DigitalSetFromMap< TMapImage >::assignFromComplement ( const TDigitalSet &  otherSet)
inline

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

Parameters:
otherSetdefines the set whose complement is assigned to 'this'.
Template Parameters:
TDigitalSeta model of digital set.

Definition at line 291 of file DigitalSetFromMap.ih.

{
this->clear();
Domain d = this->domain();
typename Domain::ConstIterator itPoint = d.begin();
typename Domain::ConstIterator itEnd = d.end();
while ( itPoint != itEnd ) {
if ( otherSet.find( *itPoint ) == otherSet.end() ) {
this->insert( *itPoint );
}
++itPoint;
}
}
template<typename TMapImage >
DGtal::DigitalSetFromMap< TMapImage >::ConstIterator DGtal::DigitalSetFromMap< TMapImage >::begin ( ) const
inline
Returns:
a const iterator on the first element in this set.

Definition at line 208 of file DigitalSetFromMap.ih.

{
return ConstIterator( myImgPtr->begin(), myFun );
}
template<typename TMapImage >
DGtal::DigitalSetFromMap< TMapImage >::Iterator DGtal::DigitalSetFromMap< TMapImage >::begin ( )
inline
Returns:
an iterator on the first element in this set.

Definition at line 226 of file DigitalSetFromMap.ih.

{
return Iterator( myImgPtr->begin(), myFun );
}
template<typename TMapImage >
std::string DGtal::DigitalSetFromMap< TMapImage >::className ( ) const
inline
Returns:
the style name used for drawing this object.

Definition at line 349 of file DigitalSetFromMap.ih.

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

Clears the set.

Postcondition:
this set is empty.

Definition at line 181 of file DigitalSetFromMap.ih.

References DGtal::DigitalSetFromMap< TMapImage >::clear().

Referenced by DGtal::DigitalSetFromMap< TMapImage >::clear().

{
myImgPtr->clear();
}
template<typename TMapImage >
void DGtal::DigitalSetFromMap< TMapImage >::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 310 of file DigitalSetFromMap.ih.

{
Domain d = this->domain();
lower = d.upperBound();
upper = d.lowerBound();
ConstIterator it = this->begin();
ConstIterator itEnd = this->end();
while ( it != itEnd ) {
lower = lower.inf( *it );
upper = upper.sup( *it );
++it;
}
}
template<typename TMapImage >
template<typename TOutputIterator >
void DGtal::DigitalSetFromMap< TMapImage >::computeComplement ( TOutputIterator &  ito) const
inline

Fill a given set through the output iterator ito with the complement of this set in the domain.

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

Definition at line 272 of file DigitalSetFromMap.ih.

{
Domain d = this->domain();
typename Domain::ConstIterator itPoint = d.begin();
typename Domain::ConstIterator itEnd = d.end();
while ( itPoint != itEnd ) {
if ( this->find( *itPoint ) == end() ) {
*ito++ = *itPoint;
}
++itPoint;
}
}
template<typename TMapImage >
const DGtal::DigitalSetFromMap< TMapImage >::Domain & DGtal::DigitalSetFromMap< TMapImage >::domain ( ) const
inline
Returns:
the embedding domain.

Definition at line 86 of file DigitalSetFromMap.ih.

References DGtal::DigitalSetFromMap< TMapImage >::domain().

Referenced by DGtal::DigitalSetFromMap< TMapImage >::domain().

{
return myImgPtr->domain();
}
template<typename TMapImage >
bool DGtal::DigitalSetFromMap< TMapImage >::empty ( ) const
inline
Returns:
'true' iff the set is empty (no element).

Definition at line 110 of file DigitalSetFromMap.ih.

References DGtal::DigitalSetFromMap< TMapImage >::empty().

Referenced by DGtal::DigitalSetFromMap< TMapImage >::empty().

{
return myImgPtr->empty();
}
template<typename TMapImage >
DGtal::DigitalSetFromMap< TMapImage >::ConstIterator DGtal::DigitalSetFromMap< TMapImage >::end ( ) const
inline
Returns:
a const iterator on the element after the last in this set.

Definition at line 217 of file DigitalSetFromMap.ih.

{
return ConstIterator( myImgPtr->end(), myFun );
}
template<typename TMapImage >
DGtal::DigitalSetFromMap< TMapImage >::Iterator DGtal::DigitalSetFromMap< TMapImage >::end ( )
inline
Returns:
a iterator on the element after the last in this set.

Definition at line 235 of file DigitalSetFromMap.ih.

{
return Iterator( myImgPtr->end(), myFun );
}
template<typename TMapImage >
DGtal::DigitalSetFromMap< TMapImage >::Size DGtal::DigitalSetFromMap< TMapImage >::erase ( const Point p)

Removes point [p] from the set.

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

Definition at line 163 of file DigitalSetFromMap.ih.

References DGtal::DigitalSetFromMap< TMapImage >::erase().

Referenced by DGtal::DigitalSetFromMap< TMapImage >::erase().

{
return myImgPtr->erase( p );
}
template<typename TMapImage >
void DGtal::DigitalSetFromMap< TMapImage >::erase ( Iterator  it)
inline

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

Parameters:
itan iterator on this set. Note: generally faster than giving just the point.

Definition at line 172 of file DigitalSetFromMap.ih.

References DGtal::DigitalSetFromMap< TMapImage >::erase().

{
myImgPtr->erase( it.base() );
}
template<typename TMapImage>
void DGtal::DigitalSetFromMap< TMapImage >::erase ( Iterator  first,
Iterator  last 
)

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.
template<typename TMapImage >
DGtal::DigitalSetFromMap< TMapImage >::ConstIterator DGtal::DigitalSetFromMap< TMapImage >::find ( const Point p) const
inline
Parameters:
pany digital point.
Returns:
a constant iterator pointing on [p] if found, otherwise end().

Definition at line 190 of file DigitalSetFromMap.ih.

{
return ConstIterator( myImgPtr->find( p ), myFun );
}
template<typename TMapImage >
DGtal::DigitalSetFromMap< TMapImage >::Iterator DGtal::DigitalSetFromMap< TMapImage >::find ( const Point p)
inline
Parameters:
pany digital point.
Returns:
an iterator pointing on [p] if found, otherwise end().

Definition at line 199 of file DigitalSetFromMap.ih.

{
return Iterator( myImgPtr->find( p ), myFun );
}
template<typename TMapImage >
void DGtal::DigitalSetFromMap< TMapImage >::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 120 of file DigitalSetFromMap.ih.

{
ASSERT( this->domain().isInside( p ) );
myImgPtr->insert( Pair( p, myDefault ) );
}
template<typename TMapImage >
template<typename PointInputIterator >
void DGtal::DigitalSetFromMap< TMapImage >::insert ( PointInputIterator  first,
PointInputIterator  last 
)

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 131 of file DigitalSetFromMap.ih.

{
for (PointInputIterator it = first; it != last; ++it)
this->insert( *it );
}
template<typename TMapImage >
void DGtal::DigitalSetFromMap< TMapImage >::insertNew ( const Point p)
inline

Adds point [p] to this set if the point is not already in the set.

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

Definition at line 142 of file DigitalSetFromMap.ih.

{
ASSERT( this->domain().isInside( p ) );
myImgPtr->insert( Pair( p, myDefault ) );
}
template<typename TMapImage >
template<typename PointInputIterator >
void DGtal::DigitalSetFromMap< TMapImage >::insertNew ( 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.
each point should not belong to this.

Definition at line 154 of file DigitalSetFromMap.ih.

{
for (PointInputIterator it = first; it != last; ++it)
this->insert( *it );
}
template<typename TMapImage >
bool DGtal::DigitalSetFromMap< TMapImage >::isValid ( ) const
inline

Checks the validity/consistency of the object.

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

Definition at line 338 of file DigitalSetFromMap.ih.

{
return ( (myImgPtr) && (myImgPtr->isValid()) );
}
template<typename TMapImage >
template<typename TDigitalSet >
DGtal::DigitalSetFromMap< TMapImage > & DGtal::DigitalSetFromMap< TMapImage >::operator+= ( const TDigitalSet &  aSet)
inline

set union to left.

Parameters:
aSetany other set.
Template Parameters:
TDigitalSeta model of digital set.

Definition at line 246 of file DigitalSetFromMap.ih.

{
if ( this != &aSet )
{
Iterator itDst = this->end();
for ( typename TDigitalSet::ConstIterator itSrc = aSet.begin();
itSrc != aSet.end();
++itSrc )
{
itDst = Iterator( myImgPtr->insert( itDst.base(), Pair(*itSrc, myDefault) ),
myFun );
}
}
return *this;
}
template<typename TMapImage >
DGtal::DigitalSetFromMap< TMapImage > & DGtal::DigitalSetFromMap< TMapImage >::operator= ( const DigitalSetFromMap< TMapImage > &  other)
inline

Assignment.

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

Definition at line 71 of file DigitalSetFromMap.ih.

References DGtal::DigitalSetFromMap< TMapImage >::myDefault, DGtal::DigitalSetFromMap< TMapImage >::myFun, and DGtal::DigitalSetFromMap< TMapImage >::myImgPtr.

{
if (this != &other)
{
myImgPtr = other.myImgPtr;
myFun = other.myFun;
myDefault = other.myDefault;
}
return *this;
}
template<typename TMapImage >
void DGtal::DigitalSetFromMap< TMapImage >::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 330 of file DigitalSetFromMap.ih.

Referenced by DGtal::operator<<().

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

Definition at line 101 of file DigitalSetFromMap.ih.

References DGtal::DigitalSetFromMap< TMapImage >::size().

Referenced by DGtal::DigitalSetFromMap< TMapImage >::size().

{
return myImgPtr->size();
}

Field Documentation

template<typename TMapImage>
Image::Value DGtal::DigitalSetFromMap< TMapImage >::myDefault
protected

Default value for point insertion

Definition at line 107 of file DigitalSetFromMap.h.

Referenced by DGtal::DigitalSetFromMap< TMapImage >::operator=().

template<typename TMapImage>
Functor DGtal::DigitalSetFromMap< TMapImage >::myFun
protected

Functor transforming pairs point-value into points

Definition at line 102 of file DigitalSetFromMap.h.

Referenced by DGtal::DigitalSetFromMap< TMapImage >::operator=().

template<typename TMapImage>
Image* DGtal::DigitalSetFromMap< TMapImage >::myImgPtr
protected

Aliasing pointer on the image

Definition at line 97 of file DigitalSetFromMap.h.

Referenced by DGtal::DigitalSetFromMap< TMapImage >::operator=().


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