DGtal  1.3.beta
topology/volMarchingCubes.cpp

Marching-cube like surface extracted using the combinatorial manifold structure of digital surfaces.

See also
Application to export surface in OFF format
* # Commands
* $ ./examples/topology/volMarchingCubes  ../examples/samples/Al.100.vol 0 1 0 
* 
Marching-cube surface of Al.100.vol file.
#include <iostream>
#include <queue>
#include "DGtal/base/Common.h"
#include "DGtal/kernel/CanonicEmbedder.h"
#include "DGtal/io/readers/VolReader.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/images/imagesSetsUtils/SetFromImage.h"
#include "DGtal/images/ImageLinearCellEmbedder.h"
#include "DGtal/shapes/Shapes.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/topology/helpers/Surfaces.h"
#include "DGtal/topology/DigitalSurface.h"
#include "DGtal/topology/SetOfSurfels.h"
using namespace std;
using namespace DGtal;
using namespace Z3i;
void usage( int, char** argv )
{
std::cerr << "Usage: " << argv[ 0 ] << " <fileName.vol> <minT> <maxT> <Adj>" << 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;
std::cerr << "\t - 0: interior adjacency, 1: exterior adjacency." << std::endl;
}
int main( int argc, char** argv )
{
if ( argc < 5 )
{
usage( argc, argv );
return 1;
}
std::string inputFilename = argv[ 1 ];
unsigned int minThreshold = atoi( argv[ 2 ] );
unsigned int maxThreshold = atoi( argv[ 3 ] );
bool intAdjacency = atoi( argv[ 4 ] ) == 0;
trace.beginBlock( "Reading vol file into an image." );
Image image = VolReader<Image>::importVol(inputFilename);
DigitalSet set3d (image.domain());
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( intAdjacency ); // interior in all directions.
trace.beginBlock( "Extracting boundary by scanning the space. " );
typedef SetOfSurfels< KSpace, SurfelSet > MySetOfSurfels;
MySetOfSurfels theSetOfSurfels( ks, surfAdj );
Surfaces<KSpace>::sMakeBoundary( theSetOfSurfels.surfelSet(),
ks, set3d,
image.domain().lowerBound(),
image.domain().upperBound() );
MyDigitalSurface digSurf( theSetOfSurfels );
trace.info() << "Digital surface has " << digSurf.size() << " surfels."
<< std::endl;
trace.beginBlock( "Making OFF surface <marching-cube.off>. " );
typedef CanonicEmbedder< Space > MyEmbedder;
typedef
CellEmbedder cellEmbedder;
MyEmbedder trivialEmbedder;
// The +0.5 is to avoid isosurface going exactly through a voxel
// center, especially for binary volumes.
cellEmbedder.init( ks, image, trivialEmbedder,
( (double) minThreshold ) + 0.5 );
ofstream out( "marching-cube.off" );
if ( out.good() )
digSurf.exportEmbeddedSurfaceAs3DOFF( out, cellEmbedder );
out.close();
return 0;
}
DGtal::Surfaces
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:78
DGtal::SetFromImage
Aim: Define utilities to convert a digital set into an image.
Definition: SetFromImage.h:63
DGtal::Trace::endBlock
double endBlock()
DGtal::KhalimskySpaceND::SurfelSet
std::set< SCell > SurfelSet
Preferred type for defining a set of surfels (always signed cells).
Definition: KhalimskySpaceND.h:450
DGtal::ImageContainerBySTLVector
Definition: ImageContainerBySTLVector.h:126
DGtal::DigitalSurface
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
Definition: DigitalSurface.h:139
DGtal::SurfelAdjacency< KSpace::dimension >
DGtal::Trace::error
std::ostream & error()
DGtal::KhalimskySpaceND::init
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
DGtal::trace
Trace trace
Definition: Common.h:154
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Trace::info
std::ostream & info()
DGtal::ImageLinearCellEmbedder::init
void init(ConstAlias< KSpace > K, ConstAlias< Image > f, ConstAlias< Embedder > e, double iso_value)
DGtal::Z2i::DigitalSet
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
Definition: StdDefs.h:100
Image
ImageContainerBySTLVector< Domain, Value > Image
Definition: testSimpleRandomAccessRangeFromPoint.cpp:45
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::CanonicEmbedder
Aim: A trivial embedder for digital points, which corresponds to the canonic injection of Zn into Rn.
Definition: CanonicEmbedder.h:64
main
int main(int argc, char **argv)
Definition: testArithmeticDSS-benchmark.cpp:147
DGtal::Image
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
usage
void usage(int, char **argv)
Definition: approximation.cpp:64
DGtal::VolReader
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:89
DGtal::SetOfSurfels
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as connected surfels....
Definition: SetOfSurfels.h:73
DGtal::ImageLinearCellEmbedder
Aim: a cellular embedder for images. (default constructible, copy constructible, assignable)....
Definition: ImageLinearCellEmbedder.h:69
MyDigitalSurface
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
Definition: greedy-plane-segmentation-ex2.cpp:92
SurfelSet
MyDigitalSurface::SurfelSet SurfelSet
Definition: greedy-plane-segmentation-ex2.cpp:95
DGtal::KhalimskySpaceND
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Definition: KhalimskySpaceND.h:64