31 #include "DGtal/base/Common.h"
32 #include "DGtal/helpers/StdDefs.h"
33 #include "DGtal/images/ImageContainerBySTLVector.h"
34 #include "DGtal/io/writers/VolWriter.h"
35 #include "DGtal/io/readers/GenericReader.h"
36 #include "DGtal/images/ConstImageAdapter.h"
37 #include "DGtal/kernel/BasicPointFunctors.h"
43 using namespace DGtal;
84 template<
typename TImage2D,
typename TPo
int3D >
85 struct Image3DPredicatFrom2DImage{
86 typedef TPoint3D Point3D;
88 typedef typename TImage2D::Value Value;
93 unsigned int maxHeight,
94 unsigned int fg,
unsigned int bg
95 ):myImageRef(anImage),
97 myMaxHeight(maxHeight),
101 unsigned int operator()(
const Point3D &aPoint)
const {
103 return (*myImageRef)(projXY(aPoint))*myScale >= aPoint[2] ? myFG: myBG ;
109 myImageRef->domain().upperBound()[1],
114 unsigned int myMaxHeight;
121 int main(
int argc,
char** argv )
127 std::string inputFileName;
128 std::string outputFileName {
"result.vol"};
130 unsigned int foregroundValue = {128};
131 unsigned int backgroundValue = {0};
133 unsigned int maxZ {255};
136 app.description(
"Convert a 2D heightfield image into a volumetric file.\n Example: \n heightfield2vol ${DGtal}/examples/samples/church.pgm volResu.vol -s 0.3 -z 50 \n");
137 app.add_option(
"-i,--input,1", inputFileName,
"input heightfield file (2D image).")
138 ->check(CLI::ExistingFile)
140 app.add_option(
"-o,--output,2", outputFileName,
"output volumetric file.",
true);
141 app.add_option(
"-s,--scale", scale,
"set the scale factor on height values (default 1.0)");
142 app.add_option(
"-z,--volZ", maxZ,
"set the Z max value of domain.");
143 app.add_option(
"-f,--foregroundValue", foregroundValue,
"specify the foreground value of the resulting voxel.");
144 app.add_option(
"-b,--backgroundValue", backgroundValue,
"specify the background value of the resulting volumetric file.");
146 app.get_formatter()->column_width(40);
147 CLI11_PARSE(app, argc, argv);
151 trace.
info() <<
"Reading input file " << inputFileName ;
154 trace.
info() <<
" [done] " << std::endl ;
157 typedef Image3DPredicatFrom2DImage<Image2D, Z3i::Point> HeightMapVol;
158 Image3DPredicatFrom2DImage<Image2D, Z3i::Point> image3Dpredicate(inputImage, scale, maxZ, foregroundValue, backgroundValue);
159 trace.
info() <<
"Processing image to output file " << outputFileName ;
162 trace.
info() <<
" [done] " << std::endl ;
int main(int argc, char **argv)
typename Self::Domain Domain
Trace trace(traceWriterTerm)
static TContainer import(const std::string &filename, std::vector< unsigned int > dimSpace=std::vector< unsigned int >())