32 #include "DGtal/base/Common.h" 33 #include "DGtal/helpers/StdDefs.h" 34 #include "DGtal/images/ImageContainerBySTLVector.h" 35 #include "DGtal/io/writers/GenericWriter.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;
77 namespace po = boost::program_options;
80 int main(
int argc,
char** argv )
82 typedef ImageContainerBySTLVector < Z3i::Domain, unsigned char > Image3D;
85 po::options_description general_opt(
"Allowed options are: ");
86 general_opt.add_options()
87 (
"help,h",
"display this message")
88 (
"input,i", po::value<std::string>(),
"Sequence of 3d Discrete points (.sdp) " )
89 (
"output,o", po::value<std::string>(),
"Vol file (.vol, .longvol, .pgm3d) " )
90 (
"foregroundVal,f", po::value<int>()->default_value(128),
"value which will represent the foreground object in the resulting image (default 128)")
91 (
"invertY",
"Invert the Y axis (image flip in the y direction)")
92 (
"backgroundVal,b", po::value<int>()->default_value(0),
"value which will represent the background outside the object in the resulting image (default 0)")
93 (
"domain,d", po::value<std::vector <int> >()->multitoken(),
"The domain of the resulting image xmin ymin zmin xmax ymax zmax ");
98 po::store(po::parse_command_line(argc, argv, general_opt), vm);
99 }
catch(
const std::exception& ex){
101 trace.info()<<
"Error checking program options: "<< ex.what()<< endl;
104 if( !parseOK || vm.count(
"help"))
106 std::cout <<
"Convert digital set of points into a volumic file.\n";
107 std::cout <<
"Usage: " << argv[0] <<
" [input] [output]\n" 108 << general_opt <<
"\n";
109 std::cout <<
"Example:\n" 110 <<
"sdp2vol -i volumePoints.sdp -o volume.vol -d 0 0 0 10 10 10 \n";
113 if(! vm.count(
"input") ||! vm.count(
"output") || !vm.count(
"domain") )
115 trace.error() <<
" Input/ output filename and domain are needed to be defined" << endl;
119 std::vector<int> domainCoords= vm[
"domain"].as<std::vector <int> >();
120 Z3i::Point ptLower(domainCoords[0],domainCoords[1], domainCoords[2]);
121 Z3i::Point ptUpper(domainCoords[3],domainCoords[4], domainCoords[5]);
122 Image3D::Domain imageDomain(ptLower, ptUpper);
124 string inputSDP = vm[
"input"].as<std::string>();
125 string outputFilename = vm[
"output"].as<std::string>();
126 int foregroundVal = vm[
"foregroundVal"].as<
int>();
127 int backgroundVal = vm[
"backgroundVal"].as<
int>();
130 vector<unsigned int> vPos;
134 trace.info() <<
"Reading input SDP file: " << inputSDP ;
135 std::vector<Z3i::Point> vectPoints= PointListReader<Z3i::Point>::getPointsFromFile(inputSDP, vPos);
136 trace.info() <<
" [done] " << std::endl ;
138 Image3D imageResult(imageDomain);
139 for(Image3D::Domain::ConstIterator iter = imageResult.domain().begin(); iter!= imageResult.domain().end();
141 imageResult.setValue(*iter, backgroundVal);
144 for(
unsigned int i=0; i<vectPoints.size(); i++){
145 if(vm.count(
"invertY")){
146 vectPoints[i][1]=ptUpper[1]-vectPoints[i][1];
148 if(imageResult.domain().isInside(vectPoints[i])){
149 imageResult.setValue(vectPoints[i], foregroundVal);
151 trace.warning() <<
"point " << vectPoints[i] <<
" outside the domain (ignored in the resulting volumic image)" << std::endl;
154 trace.info()<<
"Exporting resulting volumic image ... ";
155 GenericWriter<Image3D>::exportFile(outputFilename, imageResult);
156 trace.info() <<
" [done]"<<std::endl;