29 #include "DGtal/base/Common.h" 30 #include "DGtal/helpers/StdDefs.h" 31 #include "DGtal/io/readers/GenericReader.h" 32 #include "DGtal/io/boards/Board3D.h" 33 #include "DGtal/io/DrawWithDisplay3DModifier.h" 34 #include "DGtal/io/readers/PointListReader.h" 36 #include "DGtal/images/ImageSelector.h" 38 #include <boost/program_options/options_description.hpp> 39 #include <boost/program_options/parsers.hpp> 40 #include <boost/program_options/variables_map.hpp> 43 using namespace DGtal;
70 namespace po = boost::program_options;
73 int main(
int argc,
char** argv )
76 po::options_description general_opt(
"Allowed options are: ");
77 general_opt.add_options()
78 (
"help,h",
"display this message")
79 (
"input,i", po::value<std::string>(),
"vol file (.vol) , pgm3d (.p3d or .pgm3d, pgm (with 3 dims)) file or sdp (sequence of discrete points)" )
80 (
"output,o", po::value<std::string>(),
"Output OBJ filename" )
81 (
"thresholdMin,m", po::value<int>()->default_value(0),
"threshold min to define binary shape" )
82 (
"thresholdMax,M", po::value<int>()->default_value(255),
"threshold max to define binary shape" );
88 po::store(po::parse_command_line(argc, argv, general_opt), vm);
89 }
catch(
const std::exception& ex)
92 trace.info()<<
"Error checking program options: "<< ex.what()<< endl;
95 if( !parseOK || vm.count(
"help")||argc<=1)
97 std::cout <<
"Usage: " << argv[0] <<
" [input-file]\n" 98 <<
"Convert a volume file into OBJ format\n" 99 << general_opt <<
"\n";
103 if(! vm.count(
"input"))
105 trace.error() <<
" The input filename was defined" << endl;
108 if(! vm.count(
"output"))
110 trace.error() <<
" The output filename was defined" << endl;
114 string inputFilename = vm[
"input"].as<std::string>();
115 string outputFilename = vm[
"output"].as<std::string>();
116 int thresholdMin = vm[
"thresholdMin"].as<
int>();
117 int thresholdMax = vm[
"thresholdMax"].as<
int>();
121 typedef ImageSelector<Domain, unsigned char>::Type Image;
122 string extension = inputFilename.substr(inputFilename.find_last_of(
".") + 1);
123 if(extension!=
"vol" && extension !=
"p3d" && extension !=
"pgm3D" &&
124 extension !=
"pgm3d" && extension !=
"sdp" && extension !=
"pgm")
126 trace.info() <<
"File extension not recognized: "<< extension << std::endl;
130 if(extension==
"vol" || extension==
"pgm3d" || extension==
"pgm3D")
132 Image image = GenericReader<Image>::import (inputFilename );
133 trace.info() <<
"Image loaded: "<<image<< std::endl;
134 Domain domain = image.domain();
135 for(Domain::ConstIterator it = domain.begin(), itend=domain.end(); it!=itend; ++it){
136 unsigned char val= image( (*it) );
137 if(val<=thresholdMax && val >=thresholdMin){
145 vector<Z3i::Point> vectVoxels = PointListReader<Z3i::Point>::getPointsFromFile(inputFilename);
146 for(
unsigned int i=0;i< vectVoxels.size(); i++){
147 board << vectVoxels.at(i);
152 board.saveOBJ(outputFilename);