DGtalTools  0.9.4
ofs2off.cpp
1 
29 #include <iostream>
31 #include "DGtal/base/Common.h"
32 
33 #include "DGtal/io/readers/MeshReader.h"
34 #include "DGtal/io/writers/MeshWriter.h"
35 #include "DGtal/io/Display3D.h"
36 #include "DGtal/shapes/Mesh.h"
37 
38 #include <boost/program_options/options_description.hpp>
39 #include <boost/program_options/parsers.hpp>
40 #include <boost/program_options/variables_map.hpp>
41 
42 using namespace std;
43 using namespace DGtal;
44 
69 namespace po = boost::program_options;
71 
72 int main( int argc, char** argv )
73 {
74  // parse command line ----------------------------------------------
75  po::options_description general_opt("Allowed options are: ");
76  general_opt.add_options()
77  ("help,h", "display this message")
78  ("input,i", po::value<std::string>(), "ofs file (.ofs) " )
79  ("output,o", po::value<std::string>(), "ofs file (.off) " );
80 
81 
82  bool parseOK=true;
83  po::variables_map vm;
84  try{
85  po::store(po::parse_command_line(argc, argv, general_opt), vm);
86  }catch(const std::exception& ex){
87  parseOK=false;
88  trace.info()<< "Error checking program options: "<< ex.what()<< endl;
89  }
90  po::notify(vm);
91  if( !parseOK || vm.count("help")||argc<=1)
92  {
93  std::cout << "Usage: " << argv[0] << " [input] [output]\n"
94  << "Convert OFS file into OFF mesh format"
95  << general_opt << "\n";
96  return 0;
97  }
98 
99  if(! vm.count("input")||! vm.count("output"))
100  {
101  trace.error() << " Input and output filename are needed to be defined" << endl;
102  return 0;
103  }
104 
105 
106  string inputFilename = vm["input"].as<std::string>();
107  string outputFilename = vm["output"].as<std::string>();
108 
109  // We store the colors
110  Mesh<Display3D<>::BallD3D> anImportedMesh(true);
111  bool import = anImportedMesh << inputFilename;
112  bool exported = anImportedMesh >> outputFilename;
113  if(!import || !exported){
114  trace.info() << "Conversion failed: " << (exported? "Reading OFS failed. ": "Export OFF failed. ") << std::endl;
115  return 0;
116  }
117 
118 
119 
120  trace.info() << "[done]. "<< std::endl;
121 
122  return 0;
123 
124 }
STL namespace.
Trace trace(traceWriterTerm)
std::ostream & info()
std::ostream & error()