Marching-cube like surface extracted using the combinatorial manifold structure of digital surfaces and the intermediate representation TriangulatedSurface.
#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"
#include "DGtal/shapes/Mesh.h"
#include "DGtal/shapes/TriangulatedSurface.h"
#include "DGtal/shapes/MeshHelpers.h"
#include "DGtal/io/viewers/PolyscopeViewer.h"
void usage(
int,
char** argv )
{
std::cerr << "Usage: " << argv[ 0 ] << " <fileName.vol> <minT> [<maxT>=255] [<Adj>=0]" << std::endl;
std::cerr << "\t - displays the boundary of the shape stored in vol file <fileName.vol>" << std::endl;
std::cerr << "\t as a Marching-Cube triangulated surface (more precisely a dual" << std::endl;
std::cerr << "\t surface to the digital boundary)." << 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 - minT is the iso-surface level." << std::endl;
std::cerr << "\t - maxT should be equal to the maximum possible value in the image." << std::endl;
std::cerr << "\t - 0: interior adjacency, 1: exterior adjacency (rules used to connect surface elements unambiguously)." << std::endl;
}
int main(
int argc,
char** argv )
{
if ( argc < 5 )
{
return 1;
}
std::string inputFilename = argv[ 1 ];
unsigned int minThreshold = atoi( argv[ 2 ] );
unsigned int maxThreshold = argc > 3 ? atoi( argv[ 3 ] ) : 255;
bool intAdjacency = argc > 4 ? (atoi( argv[ 4 ] ) == 0) : true;
typedef ImageSelector < Domain, int>::Type
Image;
trace.beginBlock(
"Reading vol file into an 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( intAdjacency );
trace.beginBlock(
"Extracting boundary by scanning the space. " );
MySetOfSurfels theSetOfSurfels( ks, surfAdj );
ks, set3d,
image.domain().lowerBound(),
image.domain().upperBound() );
trace.info() <<
"Digital surface has " << digSurf.size() <<
" surfels."
<< std::endl;
trace.beginBlock(
"Making triangulated surface. " );
typedef std::map< MyDigitalSurface::Vertex, TriMesh::Index > VertexMap;
ViewMesh viewmesh;
TrivialEmbedder trivialEmbedder;
CellEmbedder cellEmbedder;
cellEmbedder.init( ks,
image, trivialEmbedder,
( (double) minThreshold ) + 0.5 );
VertexMap vmap;
( digSurf, cellEmbedder, trimesh, vmap );
trace.info() <<
"Triangulated surface is " << trimesh << std::endl;
trace.info() <<
"Mesh has " << viewmesh.nbVertex()
<< " vertices and " << viewmesh.nbFaces() << " faces." << std::endl;
PolyscopeViewer<> viewer;
viewer << viewmesh;
}
Structure representing an RGB triple with alpha component.
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
void drawColor(const DGtal::Color &color)
Aim: a cellular embedder for images. (default constructible, copy constructible, assignable)....
static void digitalSurface2DualTriangulatedSurface(const DigitalSurface< DigitalSurfaceContainer > &dsurf, const CellEmbedder &cembedder, TriangulatedSurface< typename CellEmbedder::Value > &trisurf, VertexMap &vertexmap)
static void triangulatedSurface2Mesh(const TriangulatedSurface< Point > &trisurf, Mesh< Point > &mesh)
void show() override
Starts the event loop and display of elements.
static void sMakeBoundary(SCellSet &aBoundary, const KSpace &aKSpace, const PointPredicate &pp, const Point &aLowerBound, const Point &aUpperBound)
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
MyDigitalSurface::SurfelSet SurfelSet
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
TriangulatedSurface< RealPoint > TriMesh
PointVector< 3, double > RealPoint
Z2i::DigitalSet DigitalSet