DGtal  1.5.beta
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/Viewer3D.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." );
69  Image image = VolReader<Image>::importVol(inputFilename);
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;
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
128  MeshHelpers::digitalSurface2DualPolygonalSurface
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  QApplication application(argc,argv);
138  Viewer3D<> viewer;
139  viewer.show();
140  viewer.setLineColor(Color(150,0,0,254));
141  viewer << viewmesh;
142  viewer << Viewer3D<>::updateDisplay;
143  application.exec();
144 
145 }
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
virtual void setLineColor(DGtal::Color aColor)
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
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
std::set< SCell > SurfelSet
Preferred type for defining a set of surfels (always signed cells).
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
Aim: This class is defined to represent a surface mesh through a set of vertices and faces....
Definition: Mesh.h:92
Aim: Represents a polygon mesh, i.e. a 2-dimensional combinatorial surface whose faces are (topologic...
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as connected surfels....
Definition: SetOfSurfels.h:74
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:79
std::ostream & error()
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
MyDigitalSurface::SurfelSet SurfelSet
Trace trace
Definition: Common.h:153
Aim: A trivial embedder for digital points, which corresponds to the canonic injection of Zn into Rn.
Aim: Define utilities to convert a digital set into an image.
Definition: SetFromImage.h:64
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:90
ImageContainerBySTLVector< Domain, Value > Image
PointVector< 3, double > RealPoint
void usage(int, char **argv)

References DGtal::Trace::beginBlock(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::domain(), DGtal::Trace::endBlock(), DGtal::Trace::error(), DGtal::Trace::info(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), DGtal::Display3D< Space, KSpace >::setLineColor(), DGtal::Viewer3D< TSpace, TKSpace >::show(), DGtal::DigitalSurface< TDigitalSurfaceContainer >::size(), 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 }

Referenced by main().