File failed to load: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/config/TeX-MML-AM_CHTML/MathJax.js
DGtal 2.0.0
viewPolygonalMarchingCubes.cpp File Reference
#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/PolygonalSurface.h"
#include "DGtal/shapes/MeshHelpers.h"
#include "DGtal/io/viewers/PolyscopeViewer.h"
Include dependency graph for viewPolygonalMarchingCubes.cpp:

Go to the source code of this file.

Functions

void usage (int, char **argv)
int main (int argc, char **argv)

Detailed Description

Author
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
Date
2012/02/06

An example file named viewPolygonalMarchingCubes to display an isosurface from a vol file.

This file is part of the DGtal library.

Definition in file viewPolygonalMarchingCubes.cpp.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

[viewPolygonalMarchingCubes-readVol]

[viewPolygonalMarchingCubes-readVol]

[viewPolygonalMarchingCubes-KSpace]

[viewPolygonalMarchingCubes-KSpace]

[viewPolygonalMarchingCubes-SurfelAdjacency]

[viewPolygonalMarchingCubes-SurfelAdjacency]

[viewPolygonalMarchingCubes-ExtractingSurface]

[viewPolygonalMarchingCubes-ExtractingSurface]

[viewPolygonalMarchingCubes-makingMesh]

[viewPolygonalMarchingCubes-makingMesh]

Definition at line 53 of file viewPolygonalMarchingCubes.cpp.

54{
55 if ( argc < 5 )
56 {
57 usage( argc, argv );
58 return 1;
59 }
60 std::string inputFilename = argv[ 1 ];
61 unsigned int minThreshold = atoi( argv[ 2 ] );
62 unsigned int maxThreshold = atoi( argv[ 3 ] );
63 bool intAdjacency = atoi( argv[ 4 ] ) == 0;
64
66
68 trace.beginBlock( "Reading vol file into an image." );
70 DigitalSet set3d (image.domain());
72 minThreshold, maxThreshold);
73 trace.endBlock();
75
76
78 trace.beginBlock( "Construct the Khalimsky space from the image domain." );
79 KSpace ks;
80 bool space_ok = ks.init( image.domain().lowerBound(),
81 image.domain().upperBound(), true );
82 if (!space_ok)
83 {
84 trace.error() << "Error in the Khamisky space construction."<<std::endl;
85 return 2;
86 }
87 trace.endBlock();
89
91 typedef SurfelAdjacency<KSpace::dimension> MySurfelAdjacency;
92 MySurfelAdjacency surfAdj( intAdjacency ); // interior in all directions.
94
96 trace.beginBlock( "Extracting boundary by scanning the space. " );
98 typedef SetOfSurfels< KSpace, SurfelSet > MySetOfSurfels;
100 MySetOfSurfels theSetOfSurfels( ks, surfAdj );
101 Surfaces<KSpace>::sMakeBoundary( theSetOfSurfels.surfelSet(),
102 ks, set3d,
103 image.domain().lowerBound(),
104 image.domain().upperBound() );
105 MyDigitalSurface digSurf( theSetOfSurfels );
106 trace.info() << "Digital surface has " << digSurf.size() << " surfels."
107 << std::endl;
108 trace.endBlock();
110
112 trace.beginBlock( "Making triangulated surface. " );
113 typedef CanonicEmbedder< Space > TrivialEmbedder;
115 typedef CellEmbedder::Value RealPoint;
116 typedef PolygonalSurface< RealPoint > PolygonMesh;
117 typedef Mesh< RealPoint > ViewMesh;
118 typedef std::map< MyDigitalSurface::Vertex, PolygonMesh::Index > VertexMap;
119 PolygonMesh polymesh;
120 ViewMesh viewmesh;
121 TrivialEmbedder trivialEmbedder;
122 CellEmbedder cellEmbedder;
123 // The +0.5 is to avoid isosurface going exactly through a voxel
124 // center, especially for binary volumes.
125 cellEmbedder.init( ks, image, trivialEmbedder,
126 ( (double) minThreshold ) + 0.5 );
127 VertexMap vmap; // stores the map Vertex -> Index
129 ( digSurf, cellEmbedder, polymesh, vmap );
130 trace.info() << "Polygonal surface is " << polymesh << std::endl;
131 MeshHelpers::polygonalSurface2Mesh( polymesh, viewmesh );
132 trace.info() << "Mesh has " << viewmesh.nbVertex()
133 << " vertices and " << viewmesh.nbFaces() << " faces." << std::endl;
134 trace.endBlock();
136
137 PolyscopeViewer<> viewer;
138 viewer.drawColor(Color(150,0,0,254));
139 viewer << viewmesh;
140 viewer.show();
141
142}
Structure representing an RGB triple with alpha component.
Definition Color.h:77
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)....
Aim: implements association bewteen points lying in a digital domain and values.
Definition Image.h:70
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
static void polygonalSurface2Mesh(const PolygonalSurface< Point > &polysurf, Mesh< Point > &mesh)
static void digitalSurface2DualPolygonalSurface(const DigitalSurface< DigitalSurfaceContainer > &dsurf, const CellEmbedder &cembedder, PolygonalSurface< typename CellEmbedder::Value > &polysurf, VertexMap &vertexmap)
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
KhalimskySpaceND< 3, Integer > KSpace
Definition StdDefs.h:146
Space::RealPoint RealPoint
Definition StdDefs.h:170
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
Definition StdDefs.h:173
Trace trace
ImageContainerBySTLVector< Domain, Value > Type
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())
Image image(domain)

References DGtal::SetFromImage< TSet >::append(), DGtal::MeshHelpers::digitalSurface2DualPolygonalSurface(), DGtal::Display3D< Space, KSpace >::drawColor(), image(), DGtal::VolReader< TImageContainer, TFunctor >::importVol(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), DGtal::MeshHelpers::polygonalSurface2Mesh(), DGtal::PolyscopeViewer< Space, KSpace >::show(), DGtal::DigitalSurface< TDigitalSurfaceContainer >::size(), DGtal::Surfaces< TKSpace >::sMakeBoundary(), DGtal::trace, and usage().

◆ usage()

void usage ( int ,
char ** argv )

Definition at line 43 of file viewPolygonalMarchingCubes.cpp.

44{
45 std::cerr << "Usage: " << argv[ 0 ] << " <fileName.vol> <minT> <maxT> <Adj>" << std::endl;
46 std::cerr << "\t - displays the boundary of the shape stored in vol file <fileName.vol>" << std::endl;
47 std::cerr << "\t as a Marching-Cube triangulated surface (more precisely a dual" << std::endl;
48 std::cerr << "\t surface to the digital boundary)." << std::endl;
49 std::cerr << "\t - voxel v belongs to the shape iff its value I(v) follows minT <= I(v) <= maxT." << std::endl;
50 std::cerr << "\t - 0: interior adjacency, 1: exterior adjacency (rules used to connect surface elements unambiguously)." << std::endl;
51}