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

#include <Surfaces.h>

Public Types

typedef TKSpace KSpace
typedef KSpace::Integer Integer
typedef KSpace::Point Point
typedef KSpace::Cell Cell
typedef KSpace::SCell SCell
typedef KSpace::DirIterator DirIterator

Public Member Functions

 ~Surfaces ()
void selfDisplay (std::ostream &out) const
bool isValid () const

Static Public Member Functions

template<typename PointPredicate >
static SCell findABel (const KSpace &K, const PointPredicate &pp, unsigned int nbtries=1000) throw (DGtal::InputException)
template<typename PointPredicate >
static SCell findABel (const KSpace &K, const PointPredicate &pp, Point x1, Point x2)
template<typename SCellSet , typename PointPredicate >
static void trackBoundary (SCellSet &surface, const KSpace &K, const SurfelAdjacency< KSpace::dimension > &surfel_adj, const PointPredicate &pp, const SCell &start_surfel)
template<typename SCellSet , typename PointPredicate >
static void trackClosedBoundary (SCellSet &surface, const KSpace &K, const SurfelAdjacency< KSpace::dimension > &surfel_adj, const PointPredicate &pp, const SCell &start_surfel)
template<typename SCellSet , typename SurfelPredicate >
static void trackSurface (SCellSet &surface, const KSpace &K, const SurfelAdjacency< KSpace::dimension > &surfel_adj, const SurfelPredicate &pp, const SCell &start_surfel)
template<typename SCellSet , typename SurfelPredicate >
static void trackClosedSurface (SCellSet &surface, const KSpace &K, const SurfelAdjacency< KSpace::dimension > &surfel_adj, const SurfelPredicate &pp, const SCell &start_surfel)
template<typename PointPredicate >
static void track2DBoundary (std::vector< SCell > &aSCellContour2D, const KSpace &K, const SurfelAdjacency< KSpace::dimension > &surfel_adj, const PointPredicate &pp, const SCell &start_surfel)
template<typename PointPredicate >
static void track2DSliceBoundary (std::vector< SCell > &aSCellContour2D, const KSpace &K, const Dimension &trackDir, const SurfelAdjacency< KSpace::dimension > &surfel_adj, const PointPredicate &pp, const SCell &start_surfel)
template<typename SurfelPredicate >
static void track2DSurface (std::vector< SCell > &aSCellContour, const KSpace &K, const SurfelAdjacency< KSpace::dimension > &surfel_adj, const SurfelPredicate &sp, const SCell &start_surfel)
template<typename SurfelPredicate >
static void track2DSliceSurface (std::vector< SCell > &aSCellContour, const KSpace &K, const Dimension &trackDir, const SurfelAdjacency< KSpace::dimension > &surfel_adj, const SurfelPredicate &sp, const SCell &start_surfel)
template<typename PointPredicate >
static void track2DBoundaryPoints (std::vector< Point > &aVectorOfPoints, const KSpace &K, const SurfelAdjacency< KSpace::dimension > &surfel_adj, const PointPredicate &pp, const SCell &start_surfel)
template<typename PointPredicate >
static void extractAllPointContours4C (std::vector< std::vector< Point > > &aVectPointContour2D, const KSpace &aKSpace, const PointPredicate &pp, const SurfelAdjacency< 2 > &aSAdj)
template<typename PointPredicate >
static void extractAll2DSCellContours (std::vector< std::vector< SCell > > &aVectSCellContour2D, const KSpace &aKSpace, const SurfelAdjacency< KSpace::dimension > &aSurfelAdj, const PointPredicate &pp)
template<typename PointPredicate >
static void extractAllConnectedSCell (std::vector< std::vector< SCell > > &aVectConnectedSCell, const KSpace &aKSpace, const SurfelAdjacency< KSpace::dimension > &aSurfelAdj, const PointPredicate &pp, bool forceOrientCellExterior=false)
template<typename PointPredicate >
static void orientSCellExterior (std::vector< SCell > &aVectOfSCell, const KSpace &aKSpace, const PointPredicate &pp)
template<typename CellSet , typename PointPredicate >
static void uMakeBoundary (CellSet &aBoundary, const KSpace &aKSpace, const PointPredicate &pp, const Point &aLowerBound, const Point &aUpperBound)
template<typename SCellSet , typename PointPredicate >
static void sMakeBoundary (SCellSet &aBoundary, const KSpace &aKSpace, const PointPredicate &pp, const Point &aLowerBound, const Point &aUpperBound)
template<typename OutputIterator , typename PointPredicate >
static void uWriteBoundary (OutputIterator &out_it, const KSpace &aKSpace, const PointPredicate &pp, const Point &aLowerBound, const Point &aUpperBound)
template<typename OutputIterator , typename PointPredicate >
static void sWriteBoundary (OutputIterator &out_it, const KSpace &aKSpace, const PointPredicate &pp, const Point &aLowerBound, const Point &aUpperBound)

Protected Member Functions

 Surfaces ()

Private Member Functions

 Surfaces (const Surfaces &other)
Surfacesoperator= (const Surfaces &other)

Detailed Description

template<typename TKSpace>
class DGtal::Surfaces< TKSpace >

Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).

Description of template class 'Surfaces'

Template Parameters:
TKSpacethe type of cellular grid space (e.g. a KhalimskySpaceND).

Note that many methods requires a surfel adjacency so as to know how connected surfels are linked (first by the interior or first by the exterior). Secondly, many methods are parameterized by a PointPredicate which describes the shape as a characteristic function. This is to be more generic than a simple DigitalSet. With this approach, shapes can be defined implicitly.

Essentially a backport from ImaGene.

Examples:
topology/3dKSSurfaceExtraction.cpp, topology/ctopo-2-3d.cpp, topology/ctopo-2.cpp, topology/volScanBoundary.cpp, topology/volToOFF.cpp, and topology/volTrackBoundary.cpp.

Definition at line 78 of file Surfaces.h.


Member Typedef Documentation

template<typename TKSpace>
typedef KSpace::Cell DGtal::Surfaces< TKSpace >::Cell

Definition at line 85 of file Surfaces.h.

template<typename TKSpace>
typedef KSpace::DirIterator DGtal::Surfaces< TKSpace >::DirIterator

Definition at line 87 of file Surfaces.h.

template<typename TKSpace>
typedef KSpace::Integer DGtal::Surfaces< TKSpace >::Integer

Definition at line 83 of file Surfaces.h.

template<typename TKSpace>
typedef TKSpace DGtal::Surfaces< TKSpace >::KSpace

Definition at line 82 of file Surfaces.h.

template<typename TKSpace>
typedef KSpace::Point DGtal::Surfaces< TKSpace >::Point

Definition at line 84 of file Surfaces.h.

template<typename TKSpace>
typedef KSpace::SCell DGtal::Surfaces< TKSpace >::SCell

Definition at line 86 of file Surfaces.h.


Constructor & Destructor Documentation

template<typename TKSpace >
DGtal::Surfaces< TKSpace >::~Surfaces ( )
inline

Destructor.

Definition at line 56 of file Surfaces.ih.

{
}
template<typename TKSpace>
DGtal::Surfaces< TKSpace >::Surfaces ( )
protected

Constructor. Forbidden by default (protected to avoid g++ warnings).

template<typename TKSpace>
DGtal::Surfaces< TKSpace >::Surfaces ( const Surfaces< TKSpace > &  other)
private

Copy constructor.

Parameters:
otherthe object to clone. Forbidden by default.

Member Function Documentation

template<typename TKSpace >
template<typename PointPredicate >
void DGtal::Surfaces< TKSpace >::extractAll2DSCellContours ( std::vector< std::vector< SCell > > &  aVectSCellContour2D,
const KSpace aKSpace,
const SurfelAdjacency< KSpace::dimension > &  aSurfelAdj,
const PointPredicate &  pp 
)
static

Extract all contours as a vector containing the set of contours composed of SCell. Each contour is represented by a vector of signed surfels whose elements represents a boundary component of a digital shape defined by the predicate [pp]. The algorithms tracks surfels along the boundary of the shape.

Template Parameters:
PointPredicatea model of CPointPredicate describing the inside of a digital shape, meaning a functor taking a Point and returning 'true' whenever the point belongs to the shape.
Parameters:
aSCellContour2D(modified) a vector of contour represented by a vector of cells (which are all surfels), containing the ordered list of the boundary component of [spelset].
aKSpaceany space.
aSurfelAdjthe surfel adjacency chosen for the tracking.
ppan instance of a model of CPointPredicate, for instance a SetPredicate for a digital set representing a shape.

Definition at line 649 of file Surfaces.ih.

{
std::set<SCell> bdry;
sMakeBoundary( bdry, aKSpace, pp,
aKSpace.lowerBound(), aKSpace.upperBound() );
aVectSCellContour2D.clear();
while( ! bdry.empty() )
{
std::vector<SCell> aContour;
SCell aCell = *(bdry.begin());
track2DBoundary( aContour, aKSpace, aSurfelAdj, pp, aCell );
aVectSCellContour2D.push_back( aContour );
// removing cells from boundary;
for( unsigned int i = 0; i < aContour.size(); i++ )
{
SCell sc = aContour.at(i);
bdry.erase(sc);
}
}
}
template<typename TKSpace >
template<typename PointPredicate >
void DGtal::Surfaces< TKSpace >::extractAllConnectedSCell ( std::vector< std::vector< SCell > > &  aVectConnectedSCell,
const KSpace aKSpace,
const SurfelAdjacency< KSpace::dimension > &  aSurfelAdj,
const PointPredicate &  pp,
bool  forceOrientCellExterior = false 
)
static

Extract all surfel elements associated to each connected components of the given DigitalSet. The connected surfel set are given as result in a vector containing all components. The orientation of the resulting SCell indicates the exterior orientation according the positive axis.

Template Parameters:
PointPredicatea model of CPointPredicate describing the inside of a digital shape, meaning a functor taking a Point and returning 'true' whenever the point belongs to the shape.
Parameters:
aVectConnectedSCell(modified) a vector containing for each connected components a vector of the sequence of connected SCells.
aKSpaceany space.
aSurfelAdjthe surfel adjacency chosen for the tracking.
ppan instance of a model of CPointPredicate, for instance a SetPredicate for a digital set representing a shape.
forceOrientCellExteriorif 'true', used to change the default cell orientation in order to get the direction of shape exterior (default =false). This is used only for displaying cells with Viewer3D. This mechanism should evolve shortly.

Definition at line 701 of file Surfaces.ih.

{
set<SCell> bdry;
sMakeBoundary( bdry, aKSpace, pp,
aKSpace.lowerBound(), aKSpace.upperBound() );
aVectConnectedSCell.clear();
while(!bdry.empty()){
set<SCell> aConnectedSCellSet;
SCell aCell = *(bdry.begin());
trackBoundary(aConnectedSCellSet, aKSpace, aSurfelAdj, pp, aCell );
//transform into vector<SCell>
vector<SCell> vCS;
for(typename set<SCell>::iterator it = aConnectedSCellSet.begin(); it!= aConnectedSCellSet.end(); ++it){
vCS.push_back(*it);
// removing cells from boundary;
bdry.erase(*it);
}
if(forceOrientCellExterior){
orientSCellExterior(vCS, aKSpace, pp);
}
aVectConnectedSCell.push_back(vCS);
}
}
template<typename TKSpace >
template<typename PointPredicate >
void DGtal::Surfaces< TKSpace >::extractAllPointContours4C ( std::vector< std::vector< Point > > &  aVectPointContour2D,
const KSpace aKSpace,
const PointPredicate &  pp,
const SurfelAdjacency< 2 > &  aSAdj 
)
static

Function that extracts all the boundaries of a 2D shape (specified by a predicate on point) in a 2D KSpace. The boundaries are returned as a vector of vector of points.

Extract all 4-connected contours as a vector containing the sequence of contour Points. Each contour is represented by a vector of points defined by the sequence of pointels extracted from the boundary surfels. Calls extractAll2DSCellContours.

Template Parameters:
PointPredicatea model of CPointPredicate describing the inside of a digital shape, meaning a functor taking a Point and returning 'true' whenever the point belongs to the shape.
Parameters:
aVectPointContour2D(modified) a vector of contour represented by a vector of cells (which are all surfels), containing the ordered list of the boundary component of [pp].
aKSpaceany space.
ppan instance of a model of CPointPredicate, for instance a SetPredicate for a digital set representing a shape.
aSAdjthe surfel adjacency chosen for the tracking.

Definition at line 738 of file Surfaces.ih.

{
aVectPointContour2D.clear();
std::vector< std::vector<SCell> > vectContoursBdrySCell;
extractAll2DSCellContours( vectContoursBdrySCell,
aKSpace, aSAdj, pp );
for(unsigned int i=0; i< vectContoursBdrySCell.size(); i++){
std::vector< Point > aContour;
for(unsigned int j=0; j< vectContoursBdrySCell.at(i).size(); j++){
SCell sc = vectContoursBdrySCell.at(i).at(j);
float x = (float)
float y = (float)
bool xodd = ( sc.myCoordinates[ 0 ] & 1 );
bool yodd = ( sc.myCoordinates[ 1 ] & 1 );
double x0 = !xodd ? x - 0.5 : (!aKSpace.sSign(sc)? x - 0.5: x + 0.5) ;
double y0 = !yodd ? y - 0.5 : (!aKSpace.sSign(sc)? y - 0.5: y + 0.5);
double x1 = !xodd ? x - 0.5 : (aKSpace.sSign(sc)? x - 0.5: x + 0.5) ;
double y1 = !yodd ? y - 0.5 : (aKSpace.sSign(sc)? y - 0.5: y + 0.5);
Point ptA((const int)(x0+0.5), (const int)(y0-0.5));
Point ptB((const int)(x1+0.5), (const int)(y1-0.5)) ;
aContour.push_back(ptA);
if(sc== vectContoursBdrySCell.at(i).at(vectContoursBdrySCell.at(i).size()-1)){
aContour.push_back(ptB);
}
}
aVectPointContour2D.push_back(aContour);
}
}
template<typename TKSpace >
template<typename PointPredicate >
DGtal::Surfaces< TKSpace >::SCell DGtal::Surfaces< TKSpace >::findABel ( const KSpace K,
const PointPredicate &  pp,
unsigned int  nbtries = 1000 
) throw (DGtal::InputException)
static

Find a bel in some digital set by random tries then dichotomy.

Template Parameters:
PointPredicatea model of CPointPredicate describing the inside of a digital shape, meaning a functor taking a Point and returning 'true' whenever the point belongs to the shape.
Parameters:
Kany cellular grid space.
ppan instance of a model of CPointPredicate, for instance a SetPredicate for a digital set representing a shape, which should be at least partially included in the bounds of space [K].
nbriesthe maximum number of random tries (default 1000).
Returns:
a signed surfel separating a digital point in [dset] from a face adjacent digital point outside [dset] or throws an InputException if none was found after [nbtries] iterations.

Definition at line 65 of file Surfaces.ih.

{
BOOST_CONCEPT_ASSERT(( CPointPredicate<PointPredicate> ));
Point sizes = K.upperBound() - K.lowerBound();
Point x1 = K.lowerBound();
Point x2;
// (1) Find two candidates in the space.
bool val_v1 = pp( x1 ); // dset.find( x1 ) != dset.end();
bool found = false;
for ( unsigned int j = 0; j < nbtries; ++j )
{
for ( Dimension i = 0; i < K.dimension; ++i )
{
r = rand();
x2[ i ] = ( r % sizes[ i ] ) + K.min( i );
}
bool val_v2 = pp( x2 ); // dset.find( x2 ) != dset.end();
if ( val_v2 != val_v1 )
{
found = true;
break;
}
}
if ( ! found ) throw dgtalerror;
return findABel( K, pp, x1, x2 );
}
template<typename TKSpace >
template<typename PointPredicate >
DGtal::Surfaces< TKSpace >::SCell DGtal::Surfaces< TKSpace >::findABel ( const KSpace K,
const PointPredicate &  pp,
Point  x1,
Point  x2 
)
static

Find a bel in some digital set given two hints (one point inside, one point outside).

Template Parameters:
PointPredicatea model of CPointPredicate describing the inside of a digital shape, meaning a functor taking a Point and returning 'true' whenever the point belongs to the shape.
Parameters:
Kany cellular grid space.
ppan instance of a model of CPointPredicate, for instance a SetPredicate for a digital set representing a shape, which should be at least partially included in the bounds of space [K].
x1a point within the bounds of K and such that pp( x1 ) != pp( x2 ).
x2a point within the bounds of K and such that pp( x1 ) != pp( x2 ).
Returns:
a signed surfel separating a digital point in [dset] from a face adjacent digital point outside [dset] or throws an InputException if none was found after [nbtries] iterations.

Definition at line 102 of file Surfaces.ih.

{
BOOST_CONCEPT_ASSERT(( CPointPredicate<PointPredicate> ));
// (1) Checks the two candidates in the space.
bool val_v1 = pp( x1 ); // dset.find( x1 ) != dset.end();
ASSERT( val_v1 != pp( x2 ) );
// (2) Find two candidates on the same axis.
Dimension d = 0;
bool alreadyOnSameAxis = true;
for ( Dimension i = 0; i < K.dimension; ++i )
{
if ( x1[ i ] != x2[ i ] )
{
for ( Dimension j = i + 1; j < K.dimension; ++j )
{
if ( x1[ j ] != x2[ j ] )
{
alreadyOnSameAxis = false;
Integer c = x2[ j ];
x2[ j ] = x1[ j ];
bool val_v2 = pp( x2 ); // dset.find( x2 ) != dset.end();
if ( val_v2 != val_v1 )
{ // v2 is updated.
d = i;
}
else
{ // v1 is updated.
x1 = x2;
x2[ j ] = c;
d = j;
}
} // if ( x1[ j ] != x2[ j ] )
} // for ( Dimension j = i + 1; j < K.dimension; ++j )
if ( alreadyOnSameAxis )
d = i;
} // if ( x1[ i ] != x2[ i ] )
} // for ( Dimension i = 0; i < K.dimension; ++i )
// (3) Check result.
for ( Dimension i = 0; i < K.dimension; ++i )
{
if ( ( i == d ) && ( x1[ i ] == x2[ i ] ) )
std::cerr << "[DGtal::Surfaces::findABel] Error 1a along "
<< i << std::endl;
if ( ( i != d ) && ( x1[ i ] != x2[ i ] ) )
std::cerr << "[DGtal::Surfaces::findABel] Error 1b along "
<< i << std::endl;
}
// (4) Dichotomy
Point xmid = x1;
while ( true )
{
xmid[ d ] = ( x1[ d ] + x2[ d ] ) / 2;
if ( ( xmid[ d ] == x1[ d ] ) || ( xmid[ d ] == x2[ d ] ) )
break;
bool val_mid = pp( xmid ); // dset.find( xmid ) != dset.end();
if ( val_mid != val_v1 )
x2[ d ] = xmid[ d ];
else
x1[ d ] = xmid[ d ];
}
// (5) Check result.
for ( Dimension i = 0; i < K.dimension; ++i )
{
// std::cerr << "i=" << i << " x1=" << x1[ i ] << " x2=" << x2[ i ]
// << std::endl;
if ( ( i == d ) && ( x1[ i ] != x2[ i ] - 1 ) )
std::cerr << "[DGtal::Surfaces::findABel] Error 2a along "
<< i << std::endl;
if ( ( i != d ) && ( x1[ i ] != x2[ i ] ) )
std::cerr << "[DGtal::Surfaces::findABel] Error 2a along "
<< i << std::endl;
}
// (6) Computes bel.
if ( val_v1 )
return K.sIncident( K.sSpel( x1, K.POS ), d, true );
else
return K.sIncident( K.sSpel( x1, K.NEG ), d, true );
}
template<typename TKSpace >
bool DGtal::Surfaces< TKSpace >::isValid ( ) const
inline

Checks the validity/consistency of the object.

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

Definition at line 1017 of file Surfaces.ih.

{
return true;
}
template<typename TKSpace>
Surfaces& DGtal::Surfaces< TKSpace >::operator= ( const Surfaces< TKSpace > &  other)
private

Assignment.

Parameters:
otherthe object to copy.
Returns:
a reference on 'this'. Forbidden by default.
template<typename TKSpace >
template<typename PointPredicate >
void DGtal::Surfaces< TKSpace >::orientSCellExterior ( std::vector< SCell > &  aVectOfSCell,
const KSpace aKSpace,
const PointPredicate &  pp 
)
static

Orient the SCell positively in the direction of the exterior of the DigitalSet aShape. It simply check if the direct incident Cell in the first upper dimension (obtain with sDirectIncident) belongs to the DigitalSet or not.

This method is used to change the default cell orientation in order to get the direction of shape exterior (default =false). This is used only for displaying cells with Viewer3D. This mechanism should evolve shortly.

Template Parameters:
PointPredicatea model of CPointPredicate describing the inside of a digital shape, meaning a functor taking a Point and returning 'true' whenever the point belongs to the shape.
Parameters:
aVectOfSCell(modified) a vector containing the SCell to be oriented positively in the direction of the exterior.
aKSpaceany space.
ppan instance of a model of CPointPredicate, for instance a SetPredicate for a digital set representing a shape.

Definition at line 679 of file Surfaces.ih.

{
for( typename vector<SCell>::iterator it = aVectOfSCell.begin();
it!=aVectOfSCell.end(); it++){
SCell incidUpperDim = aKSpace.sDirectIncident(*it, aKSpace.sOrthDir(*it));
if( pp( aKSpace.sCoords(incidUpperDim) )){
aKSpace.sSetSign (*it, !aKSpace.sDirect(*it, aKSpace.sOrthDir(*it)) );
}else{
aKSpace.sSetSign (*it, aKSpace.sDirect(*it, !aKSpace.sOrthDir(*it)) );
}
}
}
template<typename TKSpace >
void DGtal::Surfaces< TKSpace >::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 1005 of file Surfaces.ih.

{
out << "[Surfaces]";
}
template<typename TKSpace >
template<typename SCellSet , typename PointPredicate >
void DGtal::Surfaces< TKSpace >::sMakeBoundary ( SCellSet &  aBoundary,
const KSpace aKSpace,
const PointPredicate &  pp,
const Point aLowerBound,
const Point aUpperBound 
)
static

Creates a set of signed surfels whose elements represents all the boundary components of a digital shape described by the predicate [pp].

Template Parameters:
SCellSeta model of a set of SCell (e.g., std::set<SCell>).
PointPredicatea model of CPointPredicate describing the inside of a digital shape, meaning a functor taking a Point and returning 'true' whenever the point belongs to the shape.
Parameters:
aBoundary(modified) a set of cells (which are all surfels), the boundary component of [aSpelSet].
aKSpaceany space.
aSurfelAdjthe surfel adjacency chosen for the tracking.
ppan instance of a model of CPointPredicate, for instance a SetPredicate for a digital set representing a shape.
aLowerBoundand
aUpperBoundpoints giving the bounds of the extracted boundary.

Definition at line 859 of file Surfaces.ih.

{
unsigned int k;
bool in_here, in_further;
for ( k = 0; k < aKSpace.dimension; ++k )
{
Cell dir_low_uid = aKSpace.uSpel( aLowerBound );
Cell dir_up_uid = aKSpace.uGetDecr( aKSpace.uSpel( aUpperBound ), k);
Cell p = dir_low_uid;
do
{
in_here = pp( aKSpace.uCoords(p) );
in_further = pp( aKSpace.uCoords(aKSpace.uGetIncr( p, k )) );
if ( in_here != in_further ) // boundary element
{ // add it to the set.
aBoundary.insert( aKSpace.sIncident( aKSpace.signs( p, in_here ),
k, true ));
}
}
while ( aKSpace.uNext( p, dir_low_uid, dir_up_uid ) );
}
}
template<typename TKSpace >
template<typename OutputIterator , typename PointPredicate >
void DGtal::Surfaces< TKSpace >::sWriteBoundary ( OutputIterator &  out_it,
const KSpace aKSpace,
const PointPredicate &  pp,
const Point aLowerBound,
const Point aUpperBound 
)
static

Writes on the output iterator out_it the signed surfels whose elements represents all the boundary elements of a digital shape described by the predicate [pp].

Template Parameters:
OutputIteratorany output iterator (like std::back_insert_iterator< std::vector<SCell> >).
PointPredicatea model of CPointPredicate describing the inside of a digital shape, meaning a functor taking a Point and returning 'true' whenever the point belongs to the shape.
Parameters:
out_itany output iterator for writing the signed cells.
aKSpaceany space.
aSurfelAdjthe surfel adjacency chosen for the tracking.
ppan instance of a model of CPointPredicate, for instance a SetPredicate for a digital set representing a shape.
aLowerBoundand
aUpperBoundpoints giving the bounds of the extracted boundary.

Definition at line 925 of file Surfaces.ih.

References DGtal::false.

{
// bool in_here, in_further;
bool in_here, in_before;
typedef typename KSpace::Space Space;
std::vector< Dimension > axes( aKSpace.dimension );
for ( k = 0; k < aKSpace.dimension; ++k )
axes[ k ] = k;
// We look for surfels in every direction.
for ( k = 0; k < aKSpace.dimension; ++k )
{
// When looking for surfels, the visiting must follow the k-th
// axis first so as to reuse the predicate "pp( p )".
std::swap( axes[ 0 ], axes[ k ] );
Point low = aLowerBound; ++low[ k ];
Point up = aUpperBound;
Domain domain( low, up );
Integer x = low[ k ];
typename Domain::ConstSubRange range = domain.subRange( axes );
for ( typename Domain::ConstSubRange::ConstIterator
it = range.begin(), it_end = range.end();
it != it_end; ++it )
{
const Point & p = *it;
if ( p[ k ] == x)
{
in_here = pp( p );
Point p2( p ); --p2[ k ];
in_before = pp( p2 );
}
else
{
in_before = in_here;
in_here = pp( p );
}
if ( in_here != in_before ) // boundary element
{ // writes it into the output iterator.
*out_it++ = aKSpace.sIncident( aKSpace.sSpel( p, in_here ),
k, false );
}
}
}
// for ( k = 0; k < aKSpace.dimension; ++k )
// {
// Cell dir_low_uid = aKSpace.uSpel( aLowerBound );
// Cell dir_up_uid = aKSpace.uGetDecr( aKSpace.uSpel( aUpperBound ), k);
// Cell p = dir_low_uid;
// do
// {
// in_here = pp( aKSpace.uCoords(p) );
// in_further = pp( aKSpace.uCoords(aKSpace.uGetIncr( p, k )) );
// if ( in_here != in_further ) // boundary element
// { // writes it into the output iterator.
// *out_it++ = aKSpace.sIncident( aKSpace.signs( p, in_here ),
// k, true );
// }
// }
// while ( aKSpace.uNext( p, dir_low_uid, dir_up_uid ) );
// }
}
template<typename TKSpace >
template<typename PointPredicate >
void DGtal::Surfaces< TKSpace >::track2DBoundary ( std::vector< SCell > &  aSCellContour2D,
const KSpace K,
const SurfelAdjacency< KSpace::dimension > &  surfel_adj,
const PointPredicate &  pp,
const SCell start_surfel 
)
static

Function that extracts the boundary of a 2D shape (specified by a predicate on point) in a 2D KSpace. The boundary is returned as a vector of surfels. The surfels are guaranteed to be in the direct orientation ordering.

Creates a vector of signed surfels whose elements represents a 2D boundary component of a digital shape described by a PointPredicate. The algorithm tracks surfels along the boundary of the shape by starting from the given [start_surfel]. It only tracks the boundary of a 2D shape.

Template Parameters:
PointPredicatea model of CPointPredicate describing the inside of a digital shape, meaning a functor taking a Point and returning 'true' whenever the point belongs to the shape.
Parameters:
aSCellContour2D(modified) a vector of cells (which are all surfels), containing the ordered list of the boundary component of [spelset] which touches [start_surfel].
Kany space of dimension 2.
surfel_adjthe surfel adjacency chosen for the tracking.
ppan instance of a model of CPointPredicate, for instance a SetPredicate for a digital set representing a shape, which should be at least partially included in the bounds of space [K].
start_surfela signed surfel which should be between an element of [shape] and an element not in [shape].

Definition at line 345 of file Surfaces.ih.

References DGtal::SurfelNeighborhood< TKSpace >::getAdjacentOnPointPredicate(), DGtal::SurfelNeighborhood< TKSpace >::init(), and DGtal::SurfelNeighborhood< TKSpace >::setSurfel().

{
BOOST_CONCEPT_ASSERT(( CPointPredicate<PointPredicate> ));
ASSERT( K.dimension == 2 );
SCell b= start_surfel; // current surfel
SCell bn; // neighboring surfel
ASSERT( K.sIsSurfel( start_surfel ) );
// std::set<SCell> setSurface;
// setSurface.insert(start_surfel);
aSCellContour2D.clear(); // boundary being extracted.
aSCellContour2D.push_back(start_surfel);
SN.init( &K, &surfel_adj, start_surfel );
SN.setSurfel( b );
// search along indirect orientation.
bool hasPrevNeighbor = true;
while ( hasPrevNeighbor )
{
hasPrevNeighbor=false;
Dimension track_dir = *(K.sDirs( b ));
SN.setSurfel( b );
if ( SN.getAdjacentOnPointPredicate( bn, pp, track_dir,
! K.sDirect( b, track_dir ) ) )
{
if ( bn != start_surfel )
// if ( setSurface.find( bn ) == setSurface.end() )
{
hasPrevNeighbor=true;
aSCellContour2D.push_back( bn );
// setSurface.insert(bn);
}
}
b = bn;
}
// since the contour is not necessary closed we search in the other direction.
reverse(aSCellContour2D.begin(), aSCellContour2D.end());
if ( b != start_surfel )
{ // the contour is necessarily open.
b = start_surfel;
bool hasNextNeighbor = true;
while ( hasNextNeighbor )
{
hasNextNeighbor=false;
Dimension track_dir = *(K.sDirs( b ));
SN.setSurfel( b );
if ( SN.getAdjacentOnPointPredicate( bn, pp, track_dir,
K.sDirect( b, track_dir ) ) )
{
// if ( setSurface.find( bn ) == setSurface.end() )
// {
aSCellContour2D.push_back( bn );
hasNextNeighbor=true;
// setSurface.insert(bn);
// }
}
b=bn;
}
}
}
template<typename TKSpace >
template<typename PointPredicate >
void DGtal::Surfaces< TKSpace >::track2DBoundaryPoints ( std::vector< Point > &  aVectorOfPoints,
const KSpace K,
const SurfelAdjacency< KSpace::dimension > &  surfel_adj,
const PointPredicate &  pp,
const SCell start_surfel 
)
inlinestatic

Function that extracts the boundary of a 2D shape (specified by a predicate on point) in a 2D KSpace. The boundary is returned as a vector of points.

This method uses random tries to find a first linel separating an interior pixel from an exterior one. It then follows direct orientations to extract the 4-connected set of points.

Parameters:
aVectorOfPoints(returns) the sequence of points of the boundary component of the digitized shape containing [start_surfel].
Kany space of dimension 2.
surfel_adjthe surfel adjacency chosen for the tracking.
ppan instance of a model of CPointPredicate, for instance a SetPredicate for a digital set representing a shape, which should be at least partially included in the bounds of space [K].
start_surfela signed surfel which should be between an element of [shape] and an element not in [shape].

Definition at line 618 of file Surfaces.ih.

{
aVectorOfPoints.clear();
// Getting the consecutive surfels of the 2D boundary
std::vector<SCell> vectBdrySCell;
K, surfel_adj, pp, start_surfel );
typedef typename std::vector<SCell>::const_iterator SCellConstIterator;
for ( SCellConstIterator it = vectBdrySCell.begin(),
it_end = vectBdrySCell.end();
it != it_end; ++it )
{
Dimension track = *( K.sDirs( *it ) );
SCell pointel = K.sIndirectIncident( *it, track );
aVectorOfPoints.push_back( K.sCoords( pointel ) );
}
}
template<typename TKSpace >
template<typename PointPredicate >
void DGtal::Surfaces< TKSpace >::track2DSliceBoundary ( std::vector< SCell > &  aSCellContour2D,
const KSpace K,
const Dimension trackDir,
const SurfelAdjacency< KSpace::dimension > &  surfel_adj,
const PointPredicate &  pp,
const SCell start_surfel 
)
static

Function that extracts a 2D slice of the boundary of a nD shape (specified by a predicate on point) in a nD KSpace. The boundary is returned as a vector of surfels. The surfels are guaranteed to be in the direct orientation ordering.

Creates a vector of signed surfels whose elements represents a 2D boundary component of a digital shape described by a PointPredicate. The algorithms tracks surfels along the boundary of the shape by starting from the given [start_surfel], along the direction specified by [trackDir]. More precisely, it is the boundary of the slice of the shape along directions [trackDir] and the orthogonal direction of [start_surfel].

Template Parameters:
PointPredicatea model of CPointPredicate describing the inside of a digital shape, meaning a functor taking a Point and returning 'true' whenever the point belongs to the shape.
Parameters:
aSCellContour2D(modified) a vector of cells (which are all surfels), containing the ordered list of the boundary component of [spelset] which touches [start_surfel].
Kany space (dimension is arbitrary).
trackDirthe initial track direction at [start_surfel], should be different from the orthogonal direction of [start_surfel].
surfel_adjthe surfel adjacency chosen for the tracking.
ppan instance of a model of CPointPredicate, for instance a SetPredicate for a digital set representing a shape, which should be at least partially included in the bounds of space [K].
start_surfela signed surfel which should be between an element of [shape] and an element not in [shape].

Definition at line 417 of file Surfaces.ih.

References DGtal::SurfelNeighborhood< TKSpace >::getAdjacentOnPointPredicate(), DGtal::SurfelNeighborhood< TKSpace >::init(), and DGtal::SurfelNeighborhood< TKSpace >::setSurfel().

{
BOOST_CONCEPT_ASSERT(( CPointPredicate<PointPredicate> ));
SCell b= start_surfel; // current surfel
SCell bn; // neighboring surfel
ASSERT( K.sIsSurfel( start_surfel ) );
// std::set<SCell> setSurface;
// setSurface.insert(start_surfel);
aSCellContour2D.clear(); // boundary being extracted.
aSCellContour2D.push_back(start_surfel);
SN.init( &K, &surfel_adj, start_surfel );
SN.setSurfel( b );
Dimension orthDir = K.sOrthDir( start_surfel );
bool hasPrevNeighbor = true;
while ( hasPrevNeighbor )
{
hasPrevNeighbor=false;
// search a tracking direction compatible with track/orth direction
Dimension track_dir = K.sOrthDir( b ) == orthDir ? trackDir : orthDir;
SN.setSurfel( b );
if ( SN.getAdjacentOnPointPredicate( bn, pp, track_dir,
!K.sDirect( b, track_dir ) ) )
{
if ( bn != start_surfel )
// if ( setSurface.find( bn ) == setSurface.end() )
{
hasPrevNeighbor=true;
aSCellContour2D.push_back( bn );
// setSurface.insert(bn);
}
}
b = bn;
}
// since the contour is not necessary closed we search in the other direction.
reverse(aSCellContour2D.begin(), aSCellContour2D.end());
if ( b != start_surfel )
{ // the contour is necessarily open.
b = start_surfel;
bool hasNextNeighbor = true;
while ( hasNextNeighbor )
{
hasNextNeighbor=false;
// search a tracking direction compatible with constant direction
Dimension track_dir = K.sOrthDir( b ) == orthDir ? trackDir : orthDir;
SN.setSurfel( b );
if ( SN.getAdjacentOnPointPredicate( bn, pp, track_dir,
K.sDirect( b, track_dir ) ) )
{
// if ( setSurface.find( bn ) == setSurface.end() )
// {
aSCellContour2D.push_back( bn );
// setSurface.insert(bn);
hasNextNeighbor=true;
// }
}
b=bn;
}
}
}
template<typename TKSpace >
template<typename SurfelPredicate >
void DGtal::Surfaces< TKSpace >::track2DSliceSurface ( std::vector< SCell > &  aSCellContour,
const KSpace K,
const Dimension trackDir,
const SurfelAdjacency< KSpace::dimension > &  surfel_adj,
const SurfelPredicate &  sp,
const SCell start_surfel 
)
inlinestatic

Function that extracts a 2D slice of a n-1 digital surface (specified by a predicate on surfel) in a nD KSpace. The boundary is returned as a vector of surfels. The surfels (of dimension n-1) are guaranteed to be in the direct orientation ordering.

Creates a vector of signed surfels whose elements represents a component of a slice of digital surface described by a SurfelPredicate. The algorithm tracks surfels along the surface by starting from the given start_surfel and by moving along the directions trackDir and the orthogonal direction to start_surfel. All surfels are returned so as to follow the direct orientation. If the surface is open, the first surfel is at one extremity (the indirect extremity) while the last surfel is at the other extremity. Otherwise, the first surfel is start_surfel.

Template Parameters:
SurfelPredicatea model of CSurfelPredicate, meaning a functor taking a Surfel (SCell) and returning 'true' whenever the surfel belongs to the digital surface. Models include FrontierPredicate and BoundaryPredicate.
Parameters:
aSCellContour(modified) a vector of cells (which are all surfels), containing the ordered list of surfels that forms the connected component of the digital surface slice containing surfel start_surfel and the direction trackDir.
Kany space (dimension is arbitrary).
trackDirthe initial track direction at [start_surfel], should be different from the orthogonal direction of [start_surfel].
surfel_adjthe surfel adjacency chosen for the tracking.
span instance of a model of CSurfelPredicate, for instance a FrontierPredicate or a BoundaryPredicate.
start_surfela signed surfel such that sp(start_surfel) is true.

Definition at line 552 of file Surfaces.ih.

References DGtal::SurfelNeighborhood< TKSpace >::getAdjacentOnSurfelPredicate(), DGtal::SurfelNeighborhood< TKSpace >::init(), and DGtal::SurfelNeighborhood< TKSpace >::setSurfel().

{
BOOST_CONCEPT_ASSERT(( CSurfelPredicate<SurfelPredicate> ));
SCell b= start_surfel; // current surfel
SCell bn; // neighboring surfel
ASSERT( K.sIsSurfel( start_surfel ) );
aSCellContour.clear(); // boundary being extracted.
aSCellContour.push_back(start_surfel);
SN.init( &K, &surfel_adj, start_surfel );
SN.setSurfel( b );
Dimension orthDir = K.sOrthDir( start_surfel );
bool hasPrevNeighbor = true;
while ( hasPrevNeighbor )
{
hasPrevNeighbor=false;
// search a tracking direction compatible with track/orth direction
Dimension track_dir = K.sOrthDir( b ) == orthDir ? trackDir : orthDir;
SN.setSurfel( b );
if ( SN.getAdjacentOnSurfelPredicate( bn, sp, track_dir,
!K.sDirect( b, track_dir ) ) )
{
if ( bn != start_surfel )
{
hasPrevNeighbor=true;
aSCellContour.push_back( bn );
}
}
b = bn;
}
// since the contour is not necessary closed we search in the other direction.
reverse( aSCellContour.begin(), aSCellContour.end() );
if ( b != start_surfel )
{ // the contour is necessarily open.
b = start_surfel;
bool hasNextNeighbor = true;
while ( hasNextNeighbor )
{
hasNextNeighbor=false;
// search a tracking direction compatible with constant direction
Dimension track_dir = K.sOrthDir( b ) == orthDir ? trackDir : orthDir;
SN.setSurfel( b );
if ( SN.getAdjacentOnSurfelPredicate( bn, sp, track_dir,
K.sDirect( b, track_dir ) ) )
{
aSCellContour.push_back( bn );
hasNextNeighbor=true;
}
b=bn;
}
}
}
template<typename TKSpace >
template<typename SurfelPredicate >
void DGtal::Surfaces< TKSpace >::track2DSurface ( std::vector< SCell > &  aSCellContour,
const KSpace K,
const SurfelAdjacency< KSpace::dimension > &  surfel_adj,
const SurfelPredicate &  sp,
const SCell start_surfel 
)
inlinestatic

Function that extracts a 1d-contour (specified by a predicate on surfel) in a 2D KSpace. The boundary is returned as a vector of surfels. The surfels are guaranteed to be in the direct orientation ordering.

Creates a vector of signed surfels whose elements represents a component of a digital surface described by a SurfelPredicate. The algorithm tracks surfels along the surface by starting from the given start_surfel. All surfels are returned so as to follow the direct orientation. If the surface is open, the first surfel is at one extremity (the indirect extremity) while the last surfel is at the other extremity. Otherwise, the first surfel is start_surfel.

Template Parameters:
SurfelPredicatea model of CSurfelPredicate, meaning a functor taking a Surfel (SCell) and returning 'true' whenever the surfel belongs to the digital surface. Models include FrontierPredicate and BoundaryPredicate.
Parameters:
aSCellContour(modified) a vector of cells (which are all surfels), containing the ordered list of surfels that forms the connected component containing surfel [start_surfel].
Kany space of dimension 2.
surfel_adjthe surfel adjacency chosen for the tracking.
span instance of a model of CSurfelPredicate, for instance a FrontierPredicate or a BoundaryPredicate.
start_surfela signed surfel such that sp(start_surfel) is true.

Definition at line 489 of file Surfaces.ih.

References DGtal::SurfelNeighborhood< TKSpace >::getAdjacentOnSurfelPredicate(), DGtal::SurfelNeighborhood< TKSpace >::init(), and DGtal::SurfelNeighborhood< TKSpace >::setSurfel().

{
BOOST_CONCEPT_ASSERT(( CSurfelPredicate<SurfelPredicate> ));
ASSERT( KSpace::dimension == 2 );
SCell b= start_surfel; // current surfel
SCell bn; // neighboring surfel
ASSERT( K.sIsSurfel( start_surfel ) );
aSCellContour.clear(); // boundary being extracted.
aSCellContour.push_back(start_surfel);
SN.init( &K, &surfel_adj, start_surfel );
SN.setSurfel( b );
// search along indirect orientation.
bool hasPrevNeighbor = true;
while ( hasPrevNeighbor )
{
hasPrevNeighbor=false;
Dimension track_dir = *(K.sDirs( b ));
SN.setSurfel( b );
if ( SN.getAdjacentOnSurfelPredicate( bn, sp, track_dir,
! K.sDirect( b, track_dir ) ) )
{
if ( bn != start_surfel )
{
hasPrevNeighbor=true;
aSCellContour.push_back( bn );
}
}
b = bn;
}
// since the contour is not necessary closed we search in the other direction.
reverse( aSCellContour.begin(), aSCellContour.end() );
if ( b != start_surfel )
{ // the contour is necessarily open.
b = start_surfel;
bool hasNextNeighbor = true;
while ( hasNextNeighbor )
{
hasNextNeighbor=false;
Dimension track_dir = *(K.sDirs( b ));
SN.setSurfel( b );
if ( SN.getAdjacentOnSurfelPredicate( bn, sp, track_dir,
K.sDirect( b, track_dir ) ) )
{
aSCellContour.push_back( bn );
hasNextNeighbor=true;
}
b=bn;
}
}
}
template<typename TKSpace >
template<typename SCellSet , typename PointPredicate >
void DGtal::Surfaces< TKSpace >::trackBoundary ( SCellSet &  surface,
const KSpace K,
const SurfelAdjacency< KSpace::dimension > &  surfel_adj,
const PointPredicate &  pp,
const SCell start_surfel 
)
static

Function that extracts the boundary of a nD digital shape (specified by a predicate on point), closed or open, in a nD KSpace. The boundary is returned as a set of surfels.

Creates a set of signed surfels whose elements represents a boundary component of a digital shape described by a PointPredicate. The algorithms tracks surfels along the boundary of the shape.

Template Parameters:
SCellSeta model of a set of SCell (e.g., std::set<SCell>).
PointPredicatea model of CPointPredicate describing the inside of a digital shape, meaning a functor taking a Point and returning 'true' whenever the point belongs to the shape.
Parameters:
surface(modified) a set of cells (which are all surfels), the boundary component of [spelset] which touches [start_surfel].
Kany space.
surfel_adjthe surfel adjacency chosen for the tracking.
ppan instance of a model of CPointPredicate, for instance a SetPredicate for a digital set representing a shape, which should be at least partially included in the bounds of space [K].
start_surfela signed surfel which should be between an element of [shape] and an element not in [shape].

Definition at line 191 of file Surfaces.ih.

References DGtal::SurfelNeighborhood< TKSpace >::getAdjacentOnPointPredicate(), DGtal::SurfelNeighborhood< TKSpace >::init(), and DGtal::SurfelNeighborhood< TKSpace >::setSurfel().

{
BOOST_CONCEPT_ASSERT(( CPointPredicate<PointPredicate> ));
SCell b; // current surfel
SCell bn; // neighboring surfel
ASSERT( K.sIsSurfel( start_surfel ) );
surface.clear(); // boundary being extracted.
SN.init( &K, &surfel_adj, start_surfel );
std::queue<SCell> qbels;
qbels.push( start_surfel );
surface.insert( start_surfel );
// For all pending bels
while ( ! qbels.empty() )
{
b = qbels.front();
qbels.pop();
SN.setSurfel( b );
for ( DirIterator q = K.sDirs( b ); q != 0; ++q )
{
Dimension track_dir = *q;
// ----- 1st pass with positive orientation ------
if ( SN.getAdjacentOnPointPredicate( bn, pp, track_dir, true ) )
{
if ( surface.find( bn ) == surface.end() )
{
surface.insert( bn );
qbels.push( bn );
}
}
// ----- 2nd pass with negative orientation ------
if ( SN.getAdjacentOnPointPredicate( bn, pp, track_dir, false ) )
{
if ( surface.find( bn ) == surface.end() )
{
surface.insert( bn );
qbels.push( bn );
}
}
} // for ( DirIterator q = K.sDirs( b ); q != 0; ++q )
} // while ( ! qbels.empty() )
}
template<typename TKSpace >
template<typename SCellSet , typename PointPredicate >
void DGtal::Surfaces< TKSpace >::trackClosedBoundary ( SCellSet &  surface,
const KSpace K,
const SurfelAdjacency< KSpace::dimension > &  surfel_adj,
const PointPredicate &  pp,
const SCell start_surfel 
)
static

Function that extracts the closed boundary of a nD digital shape (specified by a predicate on point), in a nD KSpace. The boundary is returned as a set of surfels.

Creates a set of signed surfels whose elements represents a boundary component of a digital shape described by a PointPredicate. The algorithms tracks surfels along the boundary of the shape. It follows only direct orientations, so that it is faster than trackBoundary but requires the object to be fully inside the space. Follows the idea of Artzy, Frieder and Herman algorithm [Artzy:1981-cgip], but in nD.

Template Parameters:
SCellSeta model of a set of SCell (e.g., std::set<SCell>).
PointPredicatea model of CPointPredicate describing the inside of a digital shape, meaning a functor taking a Point and returning 'true' whenever the point belongs to the shape.
Parameters:
surface(modified) a set of cells (which are all surfels), the boundary component of [spelset] which touches [start_surfel].
Kany space.
surfel_adjthe surfel adjacency chosen for the tracking.
ppan instance of a model of CPointPredicate, for instance a SetPredicate for a digital set representing a shape, which should be at least partially included in the bounds of space [K].
start_surfela signed surfel which should be between an element of [shape] and an element not in [shape].

Definition at line 782 of file Surfaces.ih.

References DGtal::SurfelNeighborhood< TKSpace >::getAdjacentOnPointPredicate(), DGtal::SurfelNeighborhood< TKSpace >::init(), and DGtal::SurfelNeighborhood< TKSpace >::setSurfel().

{
SCell b; // current surfel
SCell bn; // neighboring surfel
ASSERT( K.sIsSurfel( start_surfel ) );
surface.clear(); // boundary being extracted.
SN.init( &K, &surfel_adj, start_surfel );
std::queue<SCell> qbels;
qbels.push( start_surfel );
surface.insert( start_surfel );
// For all pending bels
while ( ! qbels.empty() )
{
b = qbels.front();
qbels.pop();
SN.setSurfel( b );
for ( DirIterator q = K.sDirs( b ); q != 0; ++q )
{
Dimension track_dir = *q;
// ----- One pass, look for direct orientation ------
if ( SN.getAdjacentOnPointPredicate( bn, pp, track_dir,
K.sDirect( b, track_dir ) ) )
{
if ( surface.find( bn ) == surface.end() )
{
surface.insert( bn );
qbels.push( bn );
}
}
} // for ( DirIterator q = K.sDirs( b ); q != 0; ++q )
} // while ( ! qbels.empty() )
}
template<typename TKSpace >
template<typename SCellSet , typename SurfelPredicate >
void DGtal::Surfaces< TKSpace >::trackClosedSurface ( SCellSet &  surface,
const KSpace K,
const SurfelAdjacency< KSpace::dimension > &  surfel_adj,
const SurfelPredicate &  pp,
const SCell start_surfel 
)
static

Function that extracts a closed n-1 digital surface (specified by a predicate on surfel) in a nD KSpace. The surface is returned as a set of surfels.

Creates a set of signed surfels whose elements represents a boundary component of a digital surface described by a SurfelPredicate. The algorithms tracks surfels along the surface. This is an optimized version of trackSurface, which is valid only when the tracked surface is closed.

Template Parameters:
SCellSeta model of a set of SCell (e.g., std::set<SCell>).
SurfelPredicatea model of CSurfelPredicate describing whether a surfel belongs or not to the surface.
Parameters:
surface(modified) a set of cells (which are all surfels), the boundary component of [spelset] which touches [start_surfel].
Kany space.
surfel_adjthe surfel adjacency chosen for the tracking.
span instance of a model of CSurfelPredicate.
start_surfela signed surfel which should be part of the surface, ie. 'sp(start_surfel)==true'.

Definition at line 298 of file Surfaces.ih.

References DGtal::SurfelNeighborhood< TKSpace >::getAdjacentOnSurfelPredicate(), DGtal::SurfelNeighborhood< TKSpace >::init(), and DGtal::SurfelNeighborhood< TKSpace >::setSurfel().

{
BOOST_CONCEPT_ASSERT(( CSurfelPredicate<SurfelPredicate> ));
SCell b; // current surfel
SCell bn; // neighboring surfel
ASSERT( K.sIsSurfel( start_surfel ) );
surface.clear(); // boundary being extracted.
SN.init( &K, &surfel_adj, start_surfel );
std::queue<SCell> qbels;
qbels.push( start_surfel );
surface.insert( start_surfel );
// For all pending bels
while ( ! qbels.empty() )
{
b = qbels.front();
qbels.pop();
SN.setSurfel( b );
for ( DirIterator q = K.sDirs( b ); q != 0; ++q )
{
Dimension track_dir = *q;
// ----- direct orientation ------
if ( SN.getAdjacentOnSurfelPredicate( bn, sp, track_dir,
K.sDirect( b, track_dir ) ) )
{
if ( surface.find( bn ) == surface.end() )
{
surface.insert( bn );
qbels.push( bn );
}
}
} // for ( DirIterator q = K.sDirs( b ); q != 0; ++q )
} // while ( ! qbels.empty() )
}
template<typename TKSpace >
template<typename SCellSet , typename SurfelPredicate >
void DGtal::Surfaces< TKSpace >::trackSurface ( SCellSet &  surface,
const KSpace K,
const SurfelAdjacency< KSpace::dimension > &  surfel_adj,
const SurfelPredicate &  pp,
const SCell start_surfel 
)
static

Function that extracts a n-1 digital surface (specified by a predicate on surfel), closed or open, in a nD KSpace. The surface is returned as a set of surfels.

Creates a set of signed surfels whose elements represents a boundary component of a digital surface described by a SurfelPredicate. The algorithms tracks surfels along the surface.

Template Parameters:
SCellSeta model of a set of SCell (e.g., std::set<SCell>).
SurfelPredicatea model of CSurfelPredicate describing whether a surfel belongs or not to the surface.
Parameters:
surface(modified) a set of cells (which are all surfels), the boundary component of [spelset] which touches [start_surfel].
Kany space.
surfel_adjthe surfel adjacency chosen for the tracking.
span instance of a model of CSurfelPredicate.
start_surfela signed surfel which should be part of the surface, ie. 'sp(start_surfel)==true'.

Definition at line 244 of file Surfaces.ih.

References DGtal::SurfelNeighborhood< TKSpace >::getAdjacentOnSurfelPredicate(), DGtal::SurfelNeighborhood< TKSpace >::init(), and DGtal::SurfelNeighborhood< TKSpace >::setSurfel().

{
BOOST_CONCEPT_ASSERT(( CSurfelPredicate<SurfelPredicate> ));
SCell b; // current surfel
SCell bn; // neighboring surfel
ASSERT( K.sIsSurfel( start_surfel ) );
surface.clear(); // boundary being extracted.
SN.init( &K, &surfel_adj, start_surfel );
std::queue<SCell> qbels;
qbels.push( start_surfel );
surface.insert( start_surfel );
// For all pending bels
while ( ! qbels.empty() )
{
b = qbels.front();
qbels.pop();
SN.setSurfel( b );
for ( DirIterator q = K.sDirs( b ); q != 0; ++q )
{
Dimension track_dir = *q;
// ----- 1st pass with positive orientation ------
if ( SN.getAdjacentOnSurfelPredicate( bn, sp, track_dir, true ) )
{
if ( surface.find( bn ) == surface.end() )
{
surface.insert( bn );
qbels.push( bn );
}
}
// ----- 2nd pass with negative orientation ------
if ( SN.getAdjacentOnSurfelPredicate( bn, sp, track_dir, false ) )
{
if ( surface.find( bn ) == surface.end() )
{
surface.insert( bn );
qbels.push( bn );
}
}
} // for ( DirIterator q = K.sDirs( b ); q != 0; ++q )
} // while ( ! qbels.empty() )
}
template<typename TKSpace >
template<typename CellSet , typename PointPredicate >
void DGtal::Surfaces< TKSpace >::uMakeBoundary ( CellSet &  aBoundary,
const KSpace aKSpace,
const PointPredicate &  pp,
const Point aLowerBound,
const Point aUpperBound 
)
static

Creates a set of unsigned surfels whose elements represents all the boundary components of a digital shape described by the predicate [pp].

Template Parameters:
CellSeta model of a set of Cell (e.g., std::set<Cell>).
PointPredicatea model of CPointPredicate describing the inside of a digital shape, meaning a functor taking a Point and returning 'true' whenever the point belongs to the shape.
Parameters:
aBoundary(modified) a set of cells (which are all surfels), the boundary component of [aSpelSet].
aKSpaceany space.
aSurfelAdjthe surfel adjacency chosen for the tracking.
ppan instance of a model of CPointPredicate, for instance a SetPredicate for a digital set representing a shape.
aLowerBoundand
aUpperBoundpoints giving the bounds of the extracted boundary.

Definition at line 826 of file Surfaces.ih.

{
unsigned int k;
bool in_here, in_further;
for ( k = 0; k < aKSpace.dimension; ++k )
{
Cell dir_low_uid = aKSpace.uSpel( aLowerBound );
Cell dir_up_uid = aKSpace.uGetDecr( aKSpace.uSpel( aUpperBound ), k);
Cell p = dir_low_uid;
do
{
in_here = pp( aKSpace.uCoords(p) );
in_further = pp( aKSpace.uCoords(aKSpace.uGetIncr( p, k )) );
if ( in_here != in_further ) // boundary element
{ // add it to the set.
aBoundary.insert( aKSpace.uIncident( p, k, true ));
}
}
while ( aKSpace.uNext( p, dir_low_uid, dir_up_uid ) );
}
}
template<typename TKSpace >
template<typename OutputIterator , typename PointPredicate >
void DGtal::Surfaces< TKSpace >::uWriteBoundary ( OutputIterator &  out_it,
const KSpace aKSpace,
const PointPredicate &  pp,
const Point aLowerBound,
const Point aUpperBound 
)
static

Writes on the output iterator out_it the unsigned surfels whose elements represents all the boundary elements of a digital shape described by the predicate [pp].

Template Parameters:
OutputIteratorany output iterator (like std::back_insert_iterator< std::vector<Cell> >).
PointPredicatea model of CPointPredicate describing the inside of a digital shape, meaning a functor taking a Point and returning 'true' whenever the point belongs to the shape.
Parameters:
out_itany output iterator for writing the cells.
aKSpaceany space.
aSurfelAdjthe surfel adjacency chosen for the tracking.
ppan instance of a model of CPointPredicate, for instance a SetPredicate for a digital set representing a shape.
aLowerBoundand
aUpperBoundpoints giving the bounds of the extracted boundary.

Definition at line 893 of file Surfaces.ih.

{
unsigned int k;
bool in_here, in_further;
for ( k = 0; k < aKSpace.dimension; ++k )
{
Cell dir_low_uid = aKSpace.uSpel( aLowerBound );
Cell dir_up_uid = aKSpace.uGetDecr( aKSpace.uSpel( aUpperBound ), k);
Cell p = dir_low_uid;
do
{
in_here = pp( aKSpace.uCoords(p) );
in_further = pp( aKSpace.uCoords(aKSpace.uGetIncr( p, k )) );
if ( in_here != in_further ) // boundary element
{ // writes it into the output iterator.
*out_it++ = aKSpace.uIncident( p, k, true );
}
}
while ( aKSpace.uNext( p, dir_low_uid, dir_up_uid ) );
}
}

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