DGtal  0.9.3beta
volToOFF.cpp
1 
30 #include <iostream>
33 #include "DGtal/base/Common.h"
34 #include "DGtal/io/readers/VolReader.h"
35 #include "DGtal/helpers/StdDefs.h"
36 #include "DGtal/topology/helpers/Surfaces.h"
37 #include "DGtal/topology/DigitalSurface.h"
38 #include "DGtal/topology/SetOfSurfels.h"
39 #include "DGtal/images/ImageSelector.h"
40 #include "DGtal/images/imagesSetsUtils/SetFromImage.h"
42 
44 
45 using namespace std;
46 using namespace DGtal;
47 using namespace Z3i;
48 
50 
51 
52 void usage( int, char** argv )
53 {
54  std::cerr << "Usage: " << argv[ 0 ] << " <fileName.vol> <minT> <maxT> <int=0|ext=1>" << std::endl;
55  std::cerr << "\t - displays the boundary of the shape stored in vol file <fileName.vol> as an OFF geomview surface file. It is a kind of marching-cube surface, defined by duality with respect to the digital surface." << std::endl;
56  std::cerr << "\t - voxel v belongs to the shape iff its value I(v) follows minT <= I(v) <= maxT." << std::endl;
57  std::cerr << "\t - 0: interior adjacency, 1: exterior adjacency." << std::endl;
58 }
59 
60 int main( int argc, char** argv )
61 {
62  if ( argc < 5 )
63  {
64  usage( argc, argv );
65  return 1;
66  }
67  std::string inputFilename = argv[ 1 ];
68  unsigned int minThreshold = atoi( argv[ 2 ] );
69  unsigned int maxThreshold = atoi( argv[ 3 ] );
70  bool intAdjacency = atoi( argv[ 4 ] ) == 0;
71 
73  trace.beginBlock( "Reading vol file into an image." );
75  Image image = VolReader<Image>::importVol(inputFilename);
76  DigitalSet set3d (image.domain());
77  SetFromImage<DigitalSet>::append<Image>(set3d, image,
78  minThreshold, maxThreshold);
79  trace.endBlock();
81 
83  // Construct the Khalimsky space from the image domain
84  KSpace K;
85  bool space_ok = K.init( image.domain().lowerBound(),
86  image.domain().upperBound(), true );
87  if (!space_ok)
88  {
89  trace.error() << "Error in the Khamisky space construction."<<std::endl;
90  return 2;
91  }
93 
95  typedef SurfelAdjacency<KSpace::dimension> MySurfelAdjacency;
96  MySurfelAdjacency surfAdj( intAdjacency ); // interior in all directions.
98 
100  trace.beginBlock( "Extracting boundary by scanning the space. " );
101  typedef KSpace::SurfelSet SurfelSet;
102  typedef SetOfSurfels< KSpace, SurfelSet > MySetOfSurfels;
104 
105  MySetOfSurfels theSetOfSurfels( K, surfAdj );
106  Surfaces<KSpace>::sMakeBoundary( theSetOfSurfels.surfelSet(),
107  K, set3d,
108  image.domain().lowerBound(),
109  image.domain().upperBound() );
110  MyDigitalSurface digSurf( theSetOfSurfels );
111  trace.info() << "Digital surface has " << digSurf.size() << " surfels."
112  << std::endl;
113  trace.endBlock();
115 
117  trace.beginBlock( "Making OFF surface <marching-cube.off>. " );
118  ofstream out( "marching-cube.off" );
119  if ( out.good() )
120  digSurf.exportSurfaceAs3DOFF( out );
121  out.close();
122  trace.endBlock();
124 
125  return 0;
126 }
void beginBlock(const std::string &keyword="")
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
Definition: StdDefs.h:100
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
Trace trace
Definition: Common.h:137
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:78
KhalimskySpaceND< 2, Integer > KSpace
Definition: StdDefs.h:77
STL namespace.
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:88
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: Define utilities to convert a digital set into an image.
Definition: SetFromImage.h:63
std::ostream & info()
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as connected surfels...
Definition: SetOfSurfels.h:73
const Domain & domain() const
Definition: Image.h:192
std::ostream & error()