32 #include "DGtal/base/Common.h"
33 #include "DGtal/helpers/StdDefs.h"
34 #include "DGtal/images/ImageContainerBySTLVector.h"
35 #include "DGtal/io/writers/VolWriter.h"
36 #include "DGtal/io/readers/GenericReader.h"
37 #include "DGtal/images/ConstImageAdapter.h"
38 #include "DGtal/kernel/BasicPointFunctors.h"
41 #include <boost/program_options/options_description.hpp>
42 #include <boost/program_options/parsers.hpp>
43 #include <boost/program_options/variables_map.hpp>
46 using namespace DGtal;
50 namespace po = boost::program_options;
87 template<
typename TImage2D,
typename TPo
int3D >
88 struct Image3DPredicatFrom2DImage{
89 typedef TPoint3D Point3D;
91 typedef typename TImage2D::Value Value;
96 unsigned int maxHeight,
97 unsigned int fg,
unsigned int bg
98 ):myImageRef(anImage),
100 myMaxHeight(maxHeight),
104 unsigned int operator()(
const Point3D &aPoint)
const {
106 return (*myImageRef)(projXY(aPoint))*myScale >= aPoint[2] ? myFG: myBG ;
110 Domain domain()
const {
112 myImageRef->domain().upperBound()[1],
117 unsigned int myMaxHeight;
124 int main(
int argc,
char** argv )
130 po::options_description general_opt(
"Allowed options are: ");
131 general_opt.add_options()
132 (
"help,h",
"display this message")
133 (
"input,i", po::value<std::string>(),
"heightfield file." )
134 (
"output,o", po::value<std::string>(),
"volumetric file ")
135 (
"scale,s", po::value<double>()->default_value(1.0),
"set the scale factor on height values. (default 1.0)")
136 (
"volZ,z", po::value<unsigned int>()->default_value(255),
"set the Z max value of domain.")
137 (
"foregroundValue,f", po::value<unsigned int>()->default_value(128),
"specify the foreground value of the resulting voxel." )
138 (
"backgroundValue,b", po::value<unsigned int>()->default_value(0),
"specify the background value of the resulting volumetric file.");
141 po::variables_map vm;
143 po::store(po::parse_command_line(argc, argv, general_opt), vm);
144 }
catch(
const std::exception& ex){
146 trace.
info()<<
"Error checking program options: "<< ex.what()<< endl;
149 if( !parseOK || vm.count(
"help")||argc<=1)
151 std::cout <<
"Usage: " << argv[0] <<
" [input] [output]\n"
152 <<
"Convert a 2D heightfield image into a volumetric file. "
153 << general_opt <<
"\n";
154 std::cout <<
"Example:\n"
155 <<
"heightfield2vol -i ${DGtal}/examples/samples/church.pgm -o volResu.vol -s 0.3 -z 50 \n";
159 if(! vm.count(
"input") ||! vm.count(
"output"))
161 trace.
error() <<
" Input and output filename are needed to be defined" << endl;
165 string inputFilename = vm[
"input"].as<std::string>();
166 string outputFilename = vm[
"output"].as<std::string>();
168 trace.
info() <<
"Reading input file " << inputFilename ;
170 double scale = vm[
"scale"].as<
double>();
171 unsigned int maxZ = vm[
"volZ"].as<
unsigned int>();
172 trace.
info() <<
" [done] " << std::endl ;
174 unsigned int foregroundValue = vm[
"foregroundValue"].as<
unsigned int>();
175 unsigned int backgroundValue = vm[
"backgroundValue"].as<
unsigned int>();
177 typedef Image3DPredicatFrom2DImage<Image2D, Z3i::Point> HeightMapVol;
178 Image3DPredicatFrom2DImage<Image2D, Z3i::Point> image3Dpredicate(inputImage, scale, maxZ, foregroundValue, backgroundValue);
179 trace.
info() <<
"Processing image to output file " << outputFilename ;
183 trace.
info() <<
" [done] " << std::endl ;
static TContainer import(const std::string &filename, std::vector< unsigned int > dimSpace=std::vector< unsigned int >())
Trace trace(traceWriterTerm)
typename Self::Domain Domain