DGtal  0.9.3
Functions
volMarchingCubes.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 dependency graph for volMarchingCubes.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 volMarchingCubes.

This file is part of the DGtal library.

Definition in file volMarchingCubes.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

[volMarchingCubes-readVol]

[volMarchingCubes-readVol]

[volMarchingCubes-KSpace]

[volMarchingCubes-KSpace]

[volMarchingCubes-SurfelAdjacency]

[volMarchingCubes-SurfelAdjacency]

[volMarchingCubes-ExtractingSurface]

[volMarchingCubes-ExtractingSurface]

[volMarchingCubes-makingOFF]

[volMarchingCubes-makingOFF]

Definition at line 66 of file volMarchingCubes.cpp.

References DGtal::Trace::beginBlock(), DGtal::Image< TImageContainer >::domain(), DGtal::Trace::endBlock(), DGtal::Trace::error(), image(), DGtal::Trace::info(), DGtal::ImageLinearCellEmbedder< TKSpace, TImage, TEmbedder >::init(), DGtal::trace, and usage().

67 {
68  if ( argc < 5 )
69  {
70  usage( argc, argv );
71  return 1;
72  }
73  std::string inputFilename = argv[ 1 ];
74  unsigned int minThreshold = atoi( argv[ 2 ] );
75  unsigned int maxThreshold = atoi( argv[ 3 ] );
76  bool intAdjacency = atoi( argv[ 4 ] ) == 0;
77 
79  trace.beginBlock( "Reading vol file into an image." );
81  Image image = VolReader<Image>::importVol(inputFilename);
82  DigitalSet set3d (image.domain());
84  minThreshold, maxThreshold);
85  trace.endBlock();
87 
88 
90  trace.beginBlock( "Construct the Khalimsky space from the image domain." );
91  KSpace ks;
92  bool space_ok = ks.init( image.domain().lowerBound(),
93  image.domain().upperBound(), true );
94  if (!space_ok)
95  {
96  trace.error() << "Error in the Khamisky space construction."<<std::endl;
97  return 2;
98  }
99  trace.endBlock();
101 
103  typedef SurfelAdjacency<KSpace::dimension> MySurfelAdjacency;
104  MySurfelAdjacency surfAdj( intAdjacency ); // interior in all directions.
106 
108  trace.beginBlock( "Extracting boundary by scanning the space. " );
110  typedef SetOfSurfels< KSpace, SurfelSet > MySetOfSurfels;
112  MySetOfSurfels theSetOfSurfels( ks, surfAdj );
113  Surfaces<KSpace>::sMakeBoundary( theSetOfSurfels.surfelSet(),
114  ks, set3d,
115  image.domain().lowerBound(),
116  image.domain().upperBound() );
117  MyDigitalSurface digSurf( theSetOfSurfels );
118  trace.info() << "Digital surface has " << digSurf.size() << " surfels."
119  << std::endl;
120  trace.endBlock();
122 
124  trace.beginBlock( "Making OFF surface <marching-cube.off>. " );
125  typedef CanonicEmbedder< Space > MyEmbedder;
126  typedef
128  CellEmbedder cellEmbedder;
129  MyEmbedder trivialEmbedder;
130  // The +0.5 is to avoid isosurface going exactly through a voxel
131  // center, especially for binary volumes.
132  cellEmbedder.init( ks, image, trivialEmbedder,
133  ( (double) minThreshold ) + 0.5 );
134  ofstream out( "marching-cube.off" );
135  if ( out.good() )
136  digSurf.exportEmbeddedSurfaceAs3DOFF( out, cellEmbedder );
137  out.close();
138  trace.endBlock();
140  return 0;
141 }
void beginBlock(const std::string &keyword="")
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
Definition: StdDefs.h:100
MyDigitalSurface::SurfelSet SurfelSet
Trace trace
Definition: Common.h:137
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:78
void usage(int, char **argv)
KhalimskySpaceND< 2, Integer > KSpace
Definition: StdDefs.h:77
double endBlock()
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:89
Aim: Define utilities to convert a digital set into an image.
Definition: SetFromImage.h:63
Aim: A trivial embedder for digital points, which corresponds to the canonic injection of Zn into Rn...
std::ostream & info()
ImageContainerBySTLVector< Domain, Value > Image
const Domain & domain() const
Definition: Image.h:192
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as connected surfels...
Definition: SetOfSurfels.h:73
void init(ConstAlias< KSpace > K, ConstAlias< Image > f, ConstAlias< Embedder > e, double iso_value)
std::ostream & error()
Aim: a cellular embedder for images. (default constructible, copy constructible, assignable). Model of CCellEmbedder.
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
Image image(domain)

◆ usage()

void usage ( int  ,
char **  argv 
)

Definition at line 57 of file volMarchingCubes.cpp.

Referenced by main().

58 {
59  std::cerr << "Usage: " << argv[ 0 ] << " <fileName.vol> <minT> <maxT> <Adj>" << std::endl;
60  std::cerr << "\t - displays the boundary of the shape stored in vol file <fileName.vol>." << std::endl;
61  std::cerr << "\t - voxel v belongs to the shape iff its value I(v) follows minT <= I(v) <= maxT." << std::endl;
62  std::cerr << "\t - 0: interior adjacency, 1: exterior adjacency." << std::endl;
63 
64 }