DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
topology/volTrackBoundary.cpp

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.

See also:
Constructing digital surfaces by tracking

On the lobser.vol volume, volTrackBoundary.cpp extracts 148364 surfels in 351ms.

# Commands
$ ./examples/topology/volTrackBoundary ../examples/samples/lobster.vol 50 255
volTrackBoundary-lobster.png
Digital surface that is the boundary of a (6,18)-connected component in image lobster.vol, extracted by tracking from an initial surfel in 351ms.
#include <iostream>
#include <queue>
#include <QImageReader>
#include <QtGui/qapplication.h>
#include "DGtal/kernel/sets/SetPredicate.h"
#include "DGtal/io/readers/VolReader.h"
#include "DGtal/io/viewers/Viewer3D.h"
#include "DGtal/io/DrawWithDisplay3DModifier.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"
using namespace std;
using namespace DGtal;
using namespace Z3i;
void usage( int /*argc*/, 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 )
{
usage( argc, argv );
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." );
Image image = VolReader<Image>::importVol(inputFilename);
DigitalSet set3d (image.domain());
SetPredicate<DigitalSet> set3dPredicate( set3d );
SetFromImage<DigitalSet>::append<Image>(set3d, image,
minThreshold, maxThreshold);
trace.beginBlock( "Construct the Khalimsky space from the image domain." );
KSpace ks;
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;
}
typedef SurfelAdjacency<KSpace::dimension> MySurfelAdjacency;
MySurfelAdjacency surfAdj( true ); // interior in all directions.
trace.beginBlock( "Extracting boundary by tracking from an initial bel." );
KSpace::SCellSet boundary;
SCell bel = Surfaces<KSpace>::findABel( ks, set3dPredicate, 100000 );
surfAdj,
set3dPredicate, bel );
trace.beginBlock( "Displaying surface in Viewer3D." );
QApplication application(argc,argv);
Viewer3D viewer;
viewer.show();
viewer << CustomColors3D(Color(250, 0, 0 ), 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;
viewer << Viewer3D::updateDisplay;
trace.info() << "nb surfels = " << nbSurfels << std::endl;
return application.exec();
}