DGtal  1.3.beta
volToOFF.cpp
Go to the documentation of this file.
1 
53 #include <iostream>
56 #include "DGtal/base/Common.h"
57 #include "DGtal/io/readers/VolReader.h"
58 #include "DGtal/helpers/StdDefs.h"
59 #include "DGtal/topology/helpers/Surfaces.h"
60 #include "DGtal/topology/DigitalSurface.h"
61 #include "DGtal/topology/SetOfSurfels.h"
62 #include "DGtal/images/ImageSelector.h"
63 #include "DGtal/images/imagesSetsUtils/SetFromImage.h"
65 
67 
68 using namespace std;
69 using namespace DGtal;
70 using namespace Z3i;
71 
73 
74 
75 void usage( int, char** argv )
76 {
77  std::cerr << "Usage: " << argv[ 0 ] << " <fileName.vol> <minT> <maxT> <int=0|ext=1>" << std::endl;
78  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;
79  std::cerr << "\t - voxel v belongs to the shape iff its value I(v) follows minT <= I(v) <= maxT." << std::endl;
80  std::cerr << "\t - 0: interior adjacency, 1: exterior adjacency." << std::endl;
81 }
82 
83 int main( int argc, char** argv )
84 {
85  if ( argc < 5 )
86  {
87  usage( argc, argv );
88  return 1;
89  }
90  std::string inputFilename = argv[ 1 ];
91  unsigned int minThreshold = atoi( argv[ 2 ] );
92  unsigned int maxThreshold = atoi( argv[ 3 ] );
93  bool intAdjacency = atoi( argv[ 4 ] ) == 0;
94 
96  trace.beginBlock( "Reading vol file into an image." );
98  Image image = VolReader<Image>::importVol(inputFilename);
99  DigitalSet set3d (image.domain());
101  minThreshold, maxThreshold);
102  trace.endBlock();
104 
106  // Construct the Khalimsky space from the image domain
107  KSpace K;
108  bool space_ok = K.init( image.domain().lowerBound(),
109  image.domain().upperBound(), true );
110  if (!space_ok)
111  {
112  trace.error() << "Error in the Khamisky space construction."<<std::endl;
113  return 2;
114  }
116 
118  typedef SurfelAdjacency<KSpace::dimension> MySurfelAdjacency;
119  MySurfelAdjacency surfAdj( intAdjacency ); // interior in all directions.
121 
123  trace.beginBlock( "Extracting boundary by scanning the space. " );
125  typedef SetOfSurfels< KSpace, SurfelSet > MySetOfSurfels;
127 
128  MySetOfSurfels theSetOfSurfels( K, surfAdj );
129  Surfaces<KSpace>::sMakeBoundary( theSetOfSurfels.surfelSet(),
130  K, set3d,
131  image.domain().lowerBound(),
132  image.domain().upperBound() );
133  MyDigitalSurface digSurf( theSetOfSurfels );
134  trace.info() << "Digital surface has " << digSurf.size() << " surfels."
135  << std::endl;
136  trace.endBlock();
138 
140  trace.beginBlock( "Making OFF surface <marching-cube.off>. " );
141  ofstream out( "marching-cube.off" );
142  if ( out.good() )
143  digSurf.exportSurfaceAs3DOFF( out );
144  out.close();
145  trace.endBlock();
147 
148  return 0;
149 }
DGtal::Surfaces
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:78
DGtal::SetFromImage
Aim: Define utilities to convert a digital set into an image.
Definition: SetFromImage.h:63
DGtal::Trace::endBlock
double endBlock()
DGtal::KhalimskySpaceND::SurfelSet
std::set< SCell > SurfelSet
Preferred type for defining a set of surfels (always signed cells).
Definition: KhalimskySpaceND.h:450
DGtal::ImageContainerBySTLVector
Definition: ImageContainerBySTLVector.h:126
DGtal::DigitalSurface
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
Definition: DigitalSurface.h:139
DGtal::SurfelAdjacency< KSpace::dimension >
DGtal::Trace::error
std::ostream & error()
DGtal::KhalimskySpaceND::init
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
DGtal::DigitalSurface::size
Size size() const
DGtal::trace
Trace trace
Definition: Common.h:154
K
KSpace K
Definition: testCubicalComplex.cpp:62
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::DigitalSurface::exportSurfaceAs3DOFF
void exportSurfaceAs3DOFF(std::ostream &out) const
DGtal::Trace::info
std::ostream & info()
main
int main(int argc, char **argv)
Definition: volToOFF.cpp:83
Image
ImageContainerBySTLVector< Domain, Value > Image
Definition: testSimpleRandomAccessRangeFromPoint.cpp:45
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::Image
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
DGtal::VolReader
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:89
DGtal::SetOfSurfels
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as connected surfels....
Definition: SetOfSurfels.h:73
DGtal::DigitalSetByAssociativeContainer::domain
const Domain & domain() const
usage
void usage(int, char **argv)
Definition: volToOFF.cpp:75
MyDigitalSurface
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
Definition: greedy-plane-segmentation-ex2.cpp:92
SurfelSet
MyDigitalSurface::SurfelSet SurfelSet
Definition: greedy-plane-segmentation-ex2.cpp:95
DGtal::DigitalSetByAssociativeContainer
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Definition: DigitalSetByAssociativeContainer.h:89
DGtal::KhalimskySpaceND
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Definition: KhalimskySpaceND.h:64