DGtal  1.0.beta
Public Types | Public Member Functions | Private Member Functions | Private Attributes
DGtal::GridCurve< TKSpace > Class Template Reference

#include <DGtal/geometry/curves/GridCurve.h>

Collaboration diagram for DGtal::GridCurve< TKSpace >:
[legend]

Public Types

typedef TKSpace KSpace
 
typedef KSpace::Point Point
 
typedef KSpace::Point Vector
 
typedef KSpace::SCell SCell
 
typedef std::vector< SCellStorage
 
typedef Storage::const_iterator const_iterator
 
typedef Storage::const_iterator ConstIterator
 
typedef Storage::const_reverse_iterator const_reverse_iterator
 
typedef Storage::const_reverse_iterator ConstReverseIterator
 
typedef ConstRangeAdapter< typename Storage::const_iterator, functors::Identity, SCellSCellsRange
 
typedef ConstRangeAdapter< typename Storage::const_iterator, functors::SCellToPoint< KSpace >, PointPointsRange
 
typedef ConstRangeAdapter< typename Storage::const_iterator, CanonicSCellEmbedder< KSpace >, typename KSpace::Space::RealPointMidPointsRange
 
typedef ConstRangeAdapter< typename Storage::const_iterator, functors::SCellToArrow< KSpace >, std::pair< Point, Vector > > ArrowsRange
 
typedef ConstRangeAdapter< typename Storage::const_iterator, functors::SCellToInnerPoint< KSpace >, PointInnerPointsRange
 
typedef ConstRangeAdapter< typename Storage::const_iterator, functors::SCellToOuterPoint< KSpace >, PointOuterPointsRange
 
typedef ConstRangeAdapter< typename Storage::const_iterator, functors::SCellToIncidentPoints< KSpace >, std::pair< Point, Point > > IncidentPointsRange
 
typedef ConstRangeAdapter< typename Storage::const_iterator, functors::SCellToCode< KSpace >, char > CodesRange
 

Public Member Functions

 BOOST_CONCEPT_ASSERT ((concepts::CCellularGridSpaceND< KSpace >))
 
 ~GridCurve ()
 
 GridCurve (ConstAlias< KSpace > aKSpace)
 
 GridCurve ()
 
 GridCurve (const GridCurve &other)
 
GridCurveoperator= (const GridCurve &other)
 
std::string className () const
 
void selfDisplay (std::ostream &out) const
 
bool isValid () const
 
bool initFromVectorStream (std::istream &in)
 
void writeVectorToStream (std::ostream &out)
 
bool initFromVector (const std::vector< Point > &aVectorOfPoints)
 
bool initFromPointsVector (const std::vector< Point > &aVectorOfPoints)
 
template<typename TIterator >
bool initFromPointsRange (const TIterator &itb, const TIterator &ite)
 
bool initFromSCellsVector (const std::vector< SCell > &aVectorOfSCells)
 
template<typename TIterator >
bool initFromSCellsRange (const TIterator &itb, const TIterator &ite)
 
bool isClosed () const
 
bool isOpen () const
 
ConstIterator begin () const
 
ConstIterator end () const
 
ConstReverseIterator rbegin () const
 
ConstReverseIterator rend () const
 
SCell back () const
 
void push_back (const SCell &aSCell)
 
void pushBack (const SCell &aSCell)
 
Storage::size_type size () const
 
SCellsRange getSCellsRange () const
 
PointsRange getPointsRange () const
 
MidPointsRange getMidPointsRange () const
 
ArrowsRange getArrowsRange () const
 
InnerPointsRange getInnerPointsRange () const
 
OuterPointsRange getOuterPointsRange () const
 
IncidentPointsRange getIncidentPointsRange () const
 
GridCurve::CodesRange getCodesRange () const
 

Private Member Functions

SCell PointVectorTo1SCell (const Point &aPoint, const Vector &aVector)
 
bool isInside (const SCell &aSCell) const
 

Private Attributes

const KSpacemyKPtr
 
bool myFlagIsOwned
 
Storage mySCells
 

Detailed Description

template<typename TKSpace = KhalimskySpaceND<2>>
class DGtal::GridCurve< TKSpace >

Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d-scells), d being either equal to 1 or (n-1).

For instance, the topological boundary of a simply connected digital set is a closed sequence of 1-scells in 2d.

Template Parameters
TKSpaceKhalimsky space, a model of CCellularGridSpaceND

Using the namespace Z2i, defined in StdDefs.h, you can instanciate a grid curve as follows:

//default construction
Curve c1;
//from a Khalimsky space
K2 ks; ks.init( lowerBound, upperBound, true );
Curve c2( ks );

This object provides several IO services. For instance, you can read a grid curve from a data file, which contains the (digital) coordinates of the 0-cells (pointels) in nd:

fstream inputStream;
inputStream.open (square.c_str(), ios::in);
c1.initFromVectorStream(inputStream);
inputStream.close();

Note that if the first and last 0-scells of the file have the same coordinates (i) or if only one of their coordinates differ by 1 (ii), then the grid curve is considered as closed, ie. scells directly incident to the last signed cell and indirectly incident to the first signed cell are the same.

You can also build a grid curve from the contour of a digital set as follows:

vector<SCell> contour; //contour
SurfelAdjacency<K2::dimension> sAdj( true ); //adjacency
//tracking and init grid curve
SCell s = Surfaces<KSpace>::findABel( ks, set, 1000 );
Surfaces<KSpace>::track2DBoundary( contour, ks, sAdj, set, s );
c2.initFromSCellsVector( contour );

To save a grid curve in a data file, GridCurve provides the special method writeVectorToStream():

ofstream outputStream("myGridCurve.dat");
if (outputStream.is_open())
c2.writeVectorToStream(outputStream);
outputStream.close();

The stream mechanism is used to display the true content of the grid curve:

trace.info() << c1 << std::endl;

In 2d, the grid curve can be drawn in a vector graphics file as follows:

Board2D aBoard;
aBoard.setUnit(Board2D::UCentimeter);
aBoard << c2;
aBoard.saveEPS( "myGridCurve.eps", Board2D::BoundingBox, 5000 );

See Board2D: a stream mechanism for displaying 2D digital objects to learn more about the 2d drawing mechanism used in DGtal.

Moreover, this object provides several ranges as nested types:

You can get an access to these eight ranges through the following methods:

Each range can be displayed in the standard output or can be drawn (except CodesRange) in a vector graphics file as shown in the following snippet:

Curve::IncidentPointsRange r = c1.getIncidentPointsRange();
trace.info() << r << endl;
aBoard << SetMode(aDomain.className(), "Grid") << aDomain;
aBoard << r;
aBoard.saveEPS( "MyIncidentPointsRange.eps", Board2D::BoundingBox, 5000 );

Moreover, each range has the following inner types:

And each range provides these (circular)iterator services:

You can use these services to iterate over the elements of a given range as follows:

trace.info() << "\t iterate over the range" << endl;
Range::ConstIterator it = r.begin();
Range::ConstIterator itEnd = r.end();
for ( ; it != itEnd; ++it)
{
trace.info() << *it;
}
trace.info() << endl;
trace.info() << "\t iterate over the range in the reverse way" << endl;
Range::ConstReverseIterator rit = r.rbegin();
Range::ConstReverseIterator ritEnd = r.rend();
for ( ; rit != ritEnd; ++rit)
{
trace.info() << *rit;
}
trace.info() << endl;
trace.info() << "\t iterate over the range in a circular way" << endl;
//set the starting element wherever you want...
for (unsigned i = 0; i < 20; ++i) ++c;
//... and circulate
do
{
trace.info() << *c;
c++;
} while (c!=cend);
trace.info() << endl;
See also
exampleGridCurve2d.cpp testGridCurve.cpp
Examples:
geometry/curves/estimation/exampleCurvature.cpp, geometry/curves/exampleGridCurve3d-2.cpp, geometry/curves/exampleGridCurve3d.cpp, geometry/surfaces/dvcm-2d-curvature.cpp, and geometry/tools/exampleAlphaShape.cpp.

Definition at line 172 of file GridCurve.h.

Member Typedef Documentation

template<typename TKSpace = KhalimskySpaceND<2>>
typedef ConstRangeAdapter< typename Storage::const_iterator, functors::SCellToArrow<KSpace>, std::pair<Point,Vector> > DGtal::GridCurve< TKSpace >::ArrowsRange

Definition at line 445 of file GridCurve.h.

template<typename TKSpace = KhalimskySpaceND<2>>
typedef ConstRangeAdapter< typename Storage::const_iterator, functors::SCellToCode<KSpace>, char > DGtal::GridCurve< TKSpace >::CodesRange

Definition at line 491 of file GridCurve.h.

template<typename TKSpace = KhalimskySpaceND<2>>
typedef Storage::const_iterator DGtal::GridCurve< TKSpace >::const_iterator

Definition at line 313 of file GridCurve.h.

template<typename TKSpace = KhalimskySpaceND<2>>
typedef Storage::const_reverse_iterator DGtal::GridCurve< TKSpace >::const_reverse_iterator

Definition at line 315 of file GridCurve.h.

template<typename TKSpace = KhalimskySpaceND<2>>
typedef Storage::const_iterator DGtal::GridCurve< TKSpace >::ConstIterator

Definition at line 314 of file GridCurve.h.

template<typename TKSpace = KhalimskySpaceND<2>>
typedef Storage::const_reverse_iterator DGtal::GridCurve< TKSpace >::ConstReverseIterator

Definition at line 316 of file GridCurve.h.

template<typename TKSpace = KhalimskySpaceND<2>>
typedef ConstRangeAdapter< typename Storage::const_iterator, functors::SCellToIncidentPoints<KSpace>, std::pair<Point, Point> > DGtal::GridCurve< TKSpace >::IncidentPointsRange

Definition at line 481 of file GridCurve.h.

template<typename TKSpace = KhalimskySpaceND<2>>
typedef ConstRangeAdapter< typename Storage::const_iterator, functors::SCellToInnerPoint<KSpace>, Point > DGtal::GridCurve< TKSpace >::InnerPointsRange

Definition at line 457 of file GridCurve.h.

template<typename TKSpace = KhalimskySpaceND<2>>
typedef TKSpace DGtal::GridCurve< TKSpace >::KSpace

Definition at line 176 of file GridCurve.h.

template<typename TKSpace = KhalimskySpaceND<2>>
typedef ConstRangeAdapter< typename Storage::const_iterator, CanonicSCellEmbedder<KSpace>, typename KSpace::Space::RealPoint > DGtal::GridCurve< TKSpace >::MidPointsRange

Definition at line 433 of file GridCurve.h.

template<typename TKSpace = KhalimskySpaceND<2>>
typedef ConstRangeAdapter< typename Storage::const_iterator, functors::SCellToOuterPoint<KSpace>, Point > DGtal::GridCurve< TKSpace >::OuterPointsRange

Definition at line 469 of file GridCurve.h.

template<typename TKSpace = KhalimskySpaceND<2>>
typedef KSpace::Point DGtal::GridCurve< TKSpace >::Point

Definition at line 179 of file GridCurve.h.

template<typename TKSpace = KhalimskySpaceND<2>>
typedef ConstRangeAdapter< typename Storage::const_iterator, functors::SCellToPoint<KSpace>, Point > DGtal::GridCurve< TKSpace >::PointsRange

Definition at line 421 of file GridCurve.h.

template<typename TKSpace = KhalimskySpaceND<2>>
typedef KSpace::SCell DGtal::GridCurve< TKSpace >::SCell

Definition at line 182 of file GridCurve.h.

template<typename TKSpace = KhalimskySpaceND<2>>
typedef ConstRangeAdapter< typename Storage::const_iterator, functors::Identity, SCell > DGtal::GridCurve< TKSpace >::SCellsRange

Definition at line 410 of file GridCurve.h.

template<typename TKSpace = KhalimskySpaceND<2>>
typedef std::vector<SCell> DGtal::GridCurve< TKSpace >::Storage

Definition at line 183 of file GridCurve.h.

template<typename TKSpace = KhalimskySpaceND<2>>
typedef KSpace::Point DGtal::GridCurve< TKSpace >::Vector

Definition at line 180 of file GridCurve.h.

Constructor & Destructor Documentation

template<typename TKSpace = KhalimskySpaceND<2>>
DGtal::GridCurve< TKSpace >::~GridCurve ( )

Destructor.

template<typename TKSpace = KhalimskySpaceND<2>>
DGtal::GridCurve< TKSpace >::GridCurve ( ConstAlias< KSpace aKSpace)

Constructor.

Parameters
aKSpacethe Khalimsky space where the grid curve lies.
template<typename TKSpace = KhalimskySpaceND<2>>
DGtal::GridCurve< TKSpace >::GridCurve ( )

Default Constructor. (the underlying Khalimsky space is default constructed).

template<typename TKSpace = KhalimskySpaceND<2>>
DGtal::GridCurve< TKSpace >::GridCurve ( const GridCurve< TKSpace > &  other)

Copy constructor.

Parameters
otherthe object to clone.

Member Function Documentation

template<typename TKSpace = KhalimskySpaceND<2>>
SCell DGtal::GridCurve< TKSpace >::back ( ) const
Returns
last scell
template<typename TKSpace = KhalimskySpaceND<2>>
ConstIterator DGtal::GridCurve< TKSpace >::begin ( ) const
Returns
begin iterator on scells
template<typename TKSpace = KhalimskySpaceND<2>>
DGtal::GridCurve< TKSpace >::BOOST_CONCEPT_ASSERT ( (concepts::CCellularGridSpaceND< KSpace >)  )
template<typename TKSpace = KhalimskySpaceND<2>>
std::string DGtal::GridCurve< TKSpace >::className ( ) const
Returns
the style name used for drawing this object.
template<typename TKSpace = KhalimskySpaceND<2>>
ConstIterator DGtal::GridCurve< TKSpace >::end ( ) const
Returns
end iterator on scells
template<typename TKSpace = KhalimskySpaceND<2>>
ArrowsRange DGtal::GridCurve< TKSpace >::getArrowsRange ( ) const
inline
Returns
an instance of ArrowsRange

Definition at line 450 of file GridCurve.h.

450  {
451  return ArrowsRange(mySCells.begin(), mySCells.end(), new functors::SCellToArrow<KSpace>(*myKPtr) );
452  }
ConstRangeAdapter< typename Storage::const_iterator, functors::SCellToArrow< KSpace >, std::pair< Point, Vector > > ArrowsRange
Definition: GridCurve.h:445
Storage mySCells
Definition: GridCurve.h:377
template<typename TKSpace = KhalimskySpaceND<2>>
GridCurve::CodesRange DGtal::GridCurve< TKSpace >::getCodesRange ( ) const
inline
Returns
an instance of CodesRange

Definition at line 496 of file GridCurve.h.

496  {
497  return CodesRange( mySCells.begin(), mySCells.end(), new functors::SCellToCode<KSpace>(*myKPtr) );
498  }
Storage mySCells
Definition: GridCurve.h:377
ConstRangeAdapter< typename Storage::const_iterator, functors::SCellToCode< KSpace >, char > CodesRange
Definition: GridCurve.h:491
template<typename TKSpace = KhalimskySpaceND<2>>
IncidentPointsRange DGtal::GridCurve< TKSpace >::getIncidentPointsRange ( ) const
inline
Returns
an instance of IncidentPointsRange

Definition at line 486 of file GridCurve.h.

486  {
487  return IncidentPointsRange(mySCells.begin(), mySCells.end(), new functors::SCellToIncidentPoints<KSpace>(*myKPtr) );
488  }
ConstRangeAdapter< typename Storage::const_iterator, functors::SCellToIncidentPoints< KSpace >, std::pair< Point, Point > > IncidentPointsRange
Definition: GridCurve.h:481
Storage mySCells
Definition: GridCurve.h:377
template<typename TKSpace = KhalimskySpaceND<2>>
InnerPointsRange DGtal::GridCurve< TKSpace >::getInnerPointsRange ( ) const
inline
Returns
an instance of ArrowsRange
Examples:
geometry/tools/exampleAlphaShape.cpp.

Definition at line 462 of file GridCurve.h.

462  {
463  return InnerPointsRange(mySCells.begin(), mySCells.end(), new functors::SCellToInnerPoint<KSpace>(*myKPtr) );
464  }
ConstRangeAdapter< typename Storage::const_iterator, functors::SCellToInnerPoint< KSpace >, Point > InnerPointsRange
Definition: GridCurve.h:457
Storage mySCells
Definition: GridCurve.h:377
template<typename TKSpace = KhalimskySpaceND<2>>
MidPointsRange DGtal::GridCurve< TKSpace >::getMidPointsRange ( ) const
inline
Returns
an instance of MidPointsRange

Definition at line 438 of file GridCurve.h.

438  {
439  return MidPointsRange(mySCells.begin(), mySCells.end(), new CanonicSCellEmbedder<KSpace>(*myKPtr) );
440  }
ConstRangeAdapter< typename Storage::const_iterator, CanonicSCellEmbedder< KSpace >, typename KSpace::Space::RealPoint > MidPointsRange
Definition: GridCurve.h:433
Storage mySCells
Definition: GridCurve.h:377
template<typename TKSpace = KhalimskySpaceND<2>>
OuterPointsRange DGtal::GridCurve< TKSpace >::getOuterPointsRange ( ) const
inline
Returns
an instance of OuterPointsRange

Definition at line 474 of file GridCurve.h.

474  {
475  return OuterPointsRange(mySCells.begin(), mySCells.end(), new functors::SCellToOuterPoint<KSpace>(*myKPtr) );
476  }
ConstRangeAdapter< typename Storage::const_iterator, functors::SCellToOuterPoint< KSpace >, Point > OuterPointsRange
Definition: GridCurve.h:469
Storage mySCells
Definition: GridCurve.h:377
template<typename TKSpace = KhalimskySpaceND<2>>
PointsRange DGtal::GridCurve< TKSpace >::getPointsRange ( ) const
inline
Returns
an instance of PointsRange

Definition at line 426 of file GridCurve.h.

426  {
427  return PointsRange(mySCells.begin(), mySCells.end(), new functors::SCellToPoint<KSpace>(*myKPtr) );
428  }
ConstRangeAdapter< typename Storage::const_iterator, functors::SCellToPoint< KSpace >, Point > PointsRange
Definition: GridCurve.h:421
Storage mySCells
Definition: GridCurve.h:377
template<typename TKSpace = KhalimskySpaceND<2>>
SCellsRange DGtal::GridCurve< TKSpace >::getSCellsRange ( ) const
inline
Returns
an instance of SCellsRange

Definition at line 415 of file GridCurve.h.

415  {
416  return SCellsRange(mySCells.begin(), mySCells.end(), new functors::Identity() );
417  }
ConstRangeAdapter< typename Storage::const_iterator, functors::Identity, SCell > SCellsRange
Definition: GridCurve.h:410
Storage mySCells
Definition: GridCurve.h:377
template<typename TKSpace = KhalimskySpaceND<2>>
template<typename TIterator >
bool DGtal::GridCurve< TKSpace >::initFromPointsRange ( const TIterator &  itb,
const TIterator &  ite 
)

Init from a range of points.

Parameters
itbbegin iterator
iteend iterator
template<typename TKSpace = KhalimskySpaceND<2>>
bool DGtal::GridCurve< TKSpace >::initFromPointsVector ( const std::vector< Point > &  aVectorOfPoints)

Init from a STL vector of points.

Parameters
aVectorOfPointsthe vector containing a sequence of grid points (digital coordinates).
See also
initFromPointsRange
template<typename TKSpace = KhalimskySpaceND<2>>
template<typename TIterator >
bool DGtal::GridCurve< TKSpace >::initFromSCellsRange ( const TIterator &  itb,
const TIterator &  ite 
)

Init from a range of signed cells.

Parameters
itbbegin iterator
iteend iterator
template<typename TKSpace = KhalimskySpaceND<2>>
bool DGtal::GridCurve< TKSpace >::initFromSCellsVector ( const std::vector< SCell > &  aVectorOfSCells)

Init from a STL vector of signed cells.

Parameters
aVectorOfSCellsthe vector containing the sequence of signed cells.
See also
initFromSCellsRange
template<typename TKSpace = KhalimskySpaceND<2>>
bool DGtal::GridCurve< TKSpace >::initFromVector ( const std::vector< Point > &  aVectorOfPoints)

Deprecated name, use initFromPointsVector instead Init.

Parameters
aVectorOfPointsthe vector containing a sequence of grid points (digital coordinates).
See also
initFromPointsRange
template<typename TKSpace = KhalimskySpaceND<2>>
bool DGtal::GridCurve< TKSpace >::initFromVectorStream ( std::istream &  in)

Init.

Parameters
inany input stream,
template<typename TKSpace = KhalimskySpaceND<2>>
bool DGtal::GridCurve< TKSpace >::isClosed ( ) const

Checks whether the grid curve is open or closed. Signed cells directly incident to the last scell and indirectly incident to the first scell should be the same in case of a closed grid curve.

Returns
'true' if grid curve is closed, 'false' otherwise
template<typename TKSpace = KhalimskySpaceND<2>>
bool DGtal::GridCurve< TKSpace >::isInside ( const SCell aSCell) const
private
Parameters
aSCellany signed cell
Returns
'true' if aSCell is within the underlying Khalimsky space and 'false' otherwise
template<typename TKSpace = KhalimskySpaceND<2>>
bool DGtal::GridCurve< TKSpace >::isOpen ( ) const
Returns
'true' if the grid curve is not closed, 'false' otherwise
See also
isClosed
template<typename TKSpace = KhalimskySpaceND<2>>
bool DGtal::GridCurve< TKSpace >::isValid ( ) const

Checks the validity/consistency of the object.

Returns
'true' if the object is valid, 'false' otherwise.
template<typename TKSpace = KhalimskySpaceND<2>>
GridCurve& DGtal::GridCurve< TKSpace >::operator= ( const GridCurve< TKSpace > &  other)

Assignment.

Parameters
otherthe object to copy.
Returns
a reference on 'this'.
template<typename TKSpace = KhalimskySpaceND<2>>
SCell DGtal::GridCurve< TKSpace >::PointVectorTo1SCell ( const Point aPoint,
const Vector aVector 
)
private
Parameters
aPointany point
aVectorany vector of L1 norm equal to 1
Returns
the signed 1-cell associated to a pair point - shift vector (both in digital coordinates)
template<typename TKSpace = KhalimskySpaceND<2>>
void DGtal::GridCurve< TKSpace >::push_back ( const SCell aSCell)

Back insertion of aSCell

Parameters
aSCellany signed cell
See also
pushBack NB: this alias is kept for STL compliance
template<typename TKSpace = KhalimskySpaceND<2>>
void DGtal::GridCurve< TKSpace >::pushBack ( const SCell aSCell)

Back insertion of aSCell

Parameters
aSCellany signed cell
Examples:
geometry/tools/exampleAlphaShape.cpp.
template<typename TKSpace = KhalimskySpaceND<2>>
ConstReverseIterator DGtal::GridCurve< TKSpace >::rbegin ( ) const
Returns
reverse begin iterator on scells
template<typename TKSpace = KhalimskySpaceND<2>>
ConstReverseIterator DGtal::GridCurve< TKSpace >::rend ( ) const
Returns
reverse end iterator on scells
template<typename TKSpace = KhalimskySpaceND<2>>
void DGtal::GridCurve< TKSpace >::selfDisplay ( std::ostream &  out) const

Writes/Displays the object on an output stream.

Parameters
outthe output stream where the object is written.
template<typename TKSpace = KhalimskySpaceND<2>>
Storage::size_type DGtal::GridCurve< TKSpace >::size ( ) const
Returns
number of scells
template<typename TKSpace = KhalimskySpaceND<2>>
void DGtal::GridCurve< TKSpace >::writeVectorToStream ( std::ostream &  out)

Outputs the grid curve to the stream out.

Parameters
outany output stream,

Field Documentation

template<typename TKSpace = KhalimskySpaceND<2>>
bool DGtal::GridCurve< TKSpace >::myFlagIsOwned
private

bool equal to 'true' if this owns the Khalimsky space but 'false' otherwise

Definition at line 372 of file GridCurve.h.

template<typename TKSpace = KhalimskySpaceND<2>>
const KSpace* DGtal::GridCurve< TKSpace >::myKPtr
private

Pointer on a Khalimsky space

Definition at line 367 of file GridCurve.h.

template<typename TKSpace = KhalimskySpaceND<2>>
Storage DGtal::GridCurve< TKSpace >::mySCells
private

list of signed cells

Definition at line 377 of file GridCurve.h.


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