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 )
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(),
"customizes the domain of the resulting image xmin ymin zmin xmax ymax zmax (computed automatically by default) ");
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") )
115 trace.
error() <<
" Input/ output filename and domain are needed to be defined" << endl;
121 string inputSDP = vm[
"input"].as<std::string>();
122 string outputFilename = vm[
"output"].as<std::string>();
123 int foregroundVal = vm[
"foregroundVal"].as<
int>();
124 int backgroundVal = vm[
"backgroundVal"].as<
int>();
127 vector<unsigned int> vPos;
131 trace.
info() <<
"Reading input SDP file: " << inputSDP ;
133 trace.
info() <<
" [done] " << std::endl ;
141 explicit BBCompPoints(
unsigned int d): myDim(d){};
145 if(!vm.count(
"domain"))
147 unsigned int marge = 1;
148 for(
unsigned int i=0; i< 4; i++)
150 BBCompPoints cmp_points(i);
151 ptUpper[i] = (*(std::max_element(vectPoints.begin(), vectPoints.end(), cmp_points)))[i]+marge;
152 ptLower[i] = (*(std::min_element(vectPoints.begin(), vectPoints.end(), cmp_points)))[i]-marge;
157 std::vector<int> domainCoords= vm[
"domain"].as<std::vector <int> >();
158 ptLower =
Z3i::Point(domainCoords[3],domainCoords[4], domainCoords[5]);
159 ptUpper =
Z3i::Point(domainCoords[0],domainCoords[1], domainCoords[2]);
163 trace.
info() <<
"domain: "<<imageDomain<<std::endl;
164 Image3D imageResult(imageDomain);
166 iter!= imageResult.domain().end();
169 imageResult.setValue(*iter, backgroundVal);
172 for(
unsigned int i=0; i<vectPoints.size(); i++)
174 if(vm.count(
"invertY"))
176 vectPoints[i][1]=ptUpper[1]-vectPoints[i][1];
178 if(imageResult.domain().isInside(vectPoints[i]))
180 imageResult.setValue(vectPoints[i], foregroundVal);
184 trace.
warning() <<
"point " << vectPoints[i] <<
" outside the domain (ignored in the resulting volumic image)" << std::endl;
187 trace.
info()<<
"Exporting resulting volumic image ... ";
Trace trace(traceWriterTerm)
std::vector< Value >::const_iterator ConstIterator