32 #include "DGtal/base/Common.h" 33 #include "DGtal/helpers/StdDefs.h" 34 #include "DGtal/images/ImageContainerBySTLVector.h" 35 #include "DGtal/io/readers/VolReader.h" 37 #include <boost/program_options/options_description.hpp> 38 #include <boost/program_options/parsers.hpp> 39 #include <boost/program_options/variables_map.hpp> 42 using namespace DGtal;
46 namespace po = boost::program_options;
82 int main(
int argc,
char** argv )
84 typedef ImageContainerBySTLVector < Z3i::Domain, unsigned char > Image3D;
87 po::options_description general_opt(
"Allowed options are: ");
88 general_opt.add_options()
89 (
"help,h",
"display this message")
90 (
"input,i", po::value<std::string>(),
"volumetric file (.vol) " )
91 (
"output,o", po::value<std::string>(),
"sequence of discrete point file (.sdp) " )
92 (
"exportImageValues,e",
"option to export also the image value of the voxel in a fourth field.")
93 (
"thresholdMin,m", po::value<int>()->default_value(128),
"min threshold (default 128)" )
94 (
"thresholdMax,M", po::value<int>()->default_value(255),
"max threshold (default 255)" );
100 po::store(po::parse_command_line(argc, argv, general_opt), vm);
101 }
catch(
const std::exception& ex){
103 trace.info()<<
"Error checking program options: "<< ex.what()<< endl;
106 if( !parseOK || vm.count(
"help")||argc<=1)
108 std::cout <<
"Usage: " << argv[0] <<
" [input] [output]\n" 109 <<
"Convert volumetric file into a digital set of points from a given threshold." 110 << general_opt <<
"\n";
111 std::cout <<
"Example:\n" 112 <<
"vol2sdp -i ${DGtal}/examples/samples/lobster.vol -o volumeList.sdp \n";
116 if(! vm.count(
"input") ||! vm.count(
"output"))
118 trace.error() <<
" Input and output filename are needed to be defined" << endl;
123 string inputFilename = vm[
"input"].as<std::string>();
124 string outputFilename = vm[
"output"].as<std::string>();
126 trace.info() <<
"Reading input file " << inputFilename ;
127 Image3D inputImage = DGtal::VolReader<Image3D>::importVol(inputFilename);
128 trace.info() <<
" [done] " << std::endl ;
129 std::ofstream outStream;
130 outStream.open(outputFilename.c_str());
131 int minTh = vm[
"thresholdMin"].as<
int>();
132 int maxTh = vm[
"thresholdMax"].as<
int>();
134 trace.info() <<
"Processing image to output file " << outputFilename ;
136 outStream <<
"# sdp file generate by vol2sdp with source vol:" << inputFilename <<
" and threshold min: " << minTh <<
" max:" << maxTh << std::endl;
137 outStream <<
"# format: x y z ";
138 if(vm.count(
"exportImageValues")){
139 outStream <<
" image_value";
141 outStream << std::endl;
144 for(Image3D::Domain::ConstIterator it=inputImage.domain().begin(); it != inputImage.domain().end(); ++it){
145 if(inputImage(*it) >= minTh && inputImage(*it) <= maxTh ){
146 outStream << (*it)[0] <<
" " << (*it)[1] <<
" " << (*it)[2];
147 if(vm.count(
"exportImageValues")){
148 outStream <<
" " << (
unsigned int) inputImage(*it);
151 outStream << std::endl;
156 trace.info() <<
" [done] " << std::endl ;