In many circumstances, it is better to use the presented graph structure of digital surfaces. For instance it may be used to find the surface just by searching it by adjacencies. This process is called tracking. This is done for you by static method Surfaces::trackBoundary.
#include <iostream>
#include <queue>
#include "DGtal/base/Common.h"
#include "DGtal/io/viewers/PolyscopeViewer.h"
#include "DGtal/io/readers/VolReader.h"
#include "DGtal/io/Color.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/images/imagesSetsUtils/SetFromImage.h"
#include "DGtal/shapes/Shapes.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/topology/helpers/Surfaces.h"
void usage(
int ,
char** argv )
{
std::cerr << "Usage: " << argv[ 0 ] << " <fileName.vol> <minT> <maxT>" << std::endl;
std::cerr << "\t - displays the boundary of the shape stored in vol file <fileName.vol>." << std::endl;
std::cerr << "\t - voxel v belongs to the shape iff its value I(v) follows minT <= I(v) <= maxT." << std::endl;
}
int main(
int argc,
char** argv )
{
if ( argc < 4 )
{
return 1;
}
std::string inputFilename = argv[ 1 ];
unsigned int minThreshold = atoi( argv[ 2 ] );
unsigned int maxThreshold = atoi( argv[ 3 ] );
trace.beginBlock(
"Reading vol file into an image." );
typedef ImageSelector < Domain, int>::Type
Image;
minThreshold, maxThreshold);
trace.beginBlock(
"Construct the Khalimsky space from the image domain." );
bool space_ok = ks.init(
image.domain().lowerBound(),
image.domain().upperBound(),
true );
if (!space_ok)
{
trace.error() <<
"Error in the Khamisky space construction."<<std::endl;
return 2;
}
MySurfelAdjacency surfAdj( true );
trace.beginBlock(
"Extracting boundary by tracking from an initial bel." );
KSpace::SCellSet boundary;
surfAdj,
set3d, bel );
trace.beginBlock(
"Displaying surface in PolyscopeViewer." );
PolyscopeViewer<> viewer( ks );
viewer <<
Color( 128, 128, 128 );
unsigned long nbSurfels = 0;
for ( KSpace::SCellSet::const_iterator it = boundary.begin(),
it_end = boundary.end(); it != it_end; ++it, ++nbSurfels )
viewer << *it;
trace.info() <<
"nb surfels = " << nbSurfels << std::endl;
viewer.show();
return 0;
}
Structure representing an RGB triple with alpha component.
static void trackBoundary(SCellSet &surface, const KSpace &K, const SurfelAdjacency< KSpace::dimension > &surfel_adj, const PointPredicate &pp, const SCell &start_surfel)
static SCell findABel(const KSpace &K, const PointPredicate &pp, unsigned int nbtries=1000)
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
Z3i this namespace gathers the standard of types for 3D imagery.
DGtal is the top-level namespace which contains all DGtal functions and types.
static void append(Set &aSet, const ForegroundPredicate &isForeground, typename Image::Domain::ConstIterator itBegin, typename Image::Domain::ConstIterator itEnd)
static ImageContainer importVol(const std::string &filename, const Functor &aFunctor=Functor())
ImageContainerBySTLVector< Domain, Value > Image
Z2i::DigitalSet DigitalSet