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"
86template<
typename TImage2D,
typename TPo
int3D >
87struct Image3DPredicatFrom2DImage{
88 typedef TPoint3D Point3D;
89 typedef HyperRectDomain<Z3i::Space> Domain;
90 typedef typename TImage2D::Value Value;
94 Image3DPredicatFrom2DImage(DGtal::ConstAlias<TImage2D> anImage,
double aScale,
95 unsigned int maxHeight,
96 unsigned int fg,
unsigned int bg
97 ):myImageRef(anImage),
99 myMaxHeight(maxHeight),
103 unsigned int operator()(
const Point3D &aPoint)
const {
104 functors::Projector<SpaceND<2, typename TImage2D::Integer> > projXY;
105 return (*myImageRef)(projXY(aPoint))*myScale >= aPoint[2] ? myFG: myBG ;
109 Domain domain()
const {
110 return Domain(Z3i::Point(0,0,0), Z3i::Point(myImageRef->domain().upperBound()[0],
111 myImageRef->domain().upperBound()[1],
114 CountedConstPtrOrConstPtr<TImage2D> myImageRef;
116 unsigned int myMaxHeight;
123int main(
int argc,
char** argv )
125 typedef ImageContainerBySTLVector < Z2i::Domain, unsigned char> Image2D;
129 std::string inputFileName;
130 std::string outputFileName {
"result.vol"};
132 unsigned int foregroundValue = {128};
133 unsigned int backgroundValue = {0};
135 unsigned int maxZ {255};
138 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");
139 app.add_option(
"-i,--input,1", inputFileName,
"input heightfield file (2D image).")
140 ->check(CLI::ExistingFile)
142 app.add_option(
"-o,--output,2", outputFileName,
"output volumetric file.");
143 app.add_option(
"-s,--scale", scale,
"set the scale factor on height values (default 1.0)");
144 app.add_option(
"-z,--volZ", maxZ,
"set the Z max value of domain.");
145 app.add_option(
"-f,--foregroundValue", foregroundValue,
"specify the foreground value of the resulting voxel.");
146 app.add_option(
"-b,--backgroundValue", backgroundValue,
"specify the background value of the resulting volumetric file.");
148 app.get_formatter()->column_width(40);
149 CLI11_PARSE(app, argc, argv);
153 trace.info() <<
"Reading input file " << inputFileName ;
154 Image2D inputImage = DGtal::GenericReader<Image2D>::import(inputFileName);
156 trace.info() <<
" [done] " << std::endl ;
159 typedef Image3DPredicatFrom2DImage<Image2D, Z3i::Point> HeightMapVol;
160 Image3DPredicatFrom2DImage<Image2D, Z3i::Point> image3Dpredicate(inputImage, scale, maxZ, foregroundValue, backgroundValue);
161 trace.info() <<
"Processing image to output file " << outputFileName ;
163 VolWriter<HeightMapVol>::exportVol(outputFileName, image3Dpredicate);
164 trace.info() <<
" [done] " << std::endl ;