DGtal  0.9.3
Functions
volToOFF.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/io/readers/VolReader.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/topology/helpers/Surfaces.h"
#include "DGtal/topology/DigitalSurface.h"
#include "DGtal/topology/SetOfSurfels.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/images/imagesSetsUtils/SetFromImage.h"
Include dependency graph for volToOFF.cpp:

Go to the source code of this file.

Functions

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

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

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

A simple marching cube algorithm for vol files based on digital surfaces.

This file is part of the DGtal library.

Definition in file volToOFF.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

[volToOff-readVol]

[volToOff-readVol]

[volToOff-KSpace]

[volToOff-KSpace]

[volToOff-SurfelAdjacency]

[volToOff-SurfelAdjacency]

[volToOff-ExtractingSurface]

[volToOff-ExtractingSurface]

[volToOff-makingOFF]

[volToOff-makingOFF]

Definition at line 83 of file volToOFF.cpp.

References DGtal::Trace::beginBlock(), DGtal::Image< TImageContainer >::domain(), DGtal::Trace::endBlock(), DGtal::Trace::error(), image(), DGtal::Trace::info(), K, DGtal::trace, and usage().

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 }
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
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
void usage(int, char **argv)
Definition: volToOFF.cpp:75
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
KSpace K
std::ostream & error()
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
Image image(domain)

◆ usage()

void usage ( int  ,
char **  argv 
)

Definition at line 75 of file volToOFF.cpp.

Referenced by main().

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 }