33#include "DGtal/base/Common.h"
34#include "DGtal/base/BasicFunctors.h"
35#include "DGtal/helpers/StdDefs.h"
36#include "DGtal/io/readers/GenericReader.h"
37#include "DGtal/io/viewers/PolyscopeViewer.h"
38#include <DGtal/images/ImageContainerBySTLVector.h>
40#include "DGtal/io/Color.h"
42#include <DGtal/base/ConstAlias.h>
43#include <DGtal/kernel/BasicPointFunctors.h>
44#include <DGtal/topology/helpers/Surfaces.h>
45#include <DGtal/io/colormaps/GradientColorMap.h>
46#include <DGtal/io/colormaps/GrayscaleColorMap.h>
99template<
typename TImage2D,
typename TPo
int3D >
100struct Image3DPredicatFrom2DImage{
101 typedef TPoint3D Point3D;
105 Image3DPredicatFrom2DImage(DGtal::ConstAlias<TImage2D> anImage,
double aScale):myImageRef(anImage),
109 bool operator()(
const Point3D &aPoint)
const {
110 functors::Projector<SpaceND<2, typename TImage2D::Integer> > projXY;
111 return (*myImageRef)(projXY(aPoint))*myScale >= aPoint[2];
113 CountedConstPtrOrConstPtr<TImage2D> myImageRef;
124int main(
int argc,
char** argv )
129 std::string inputFileName;
131 bool colorMap {
false};
132 std::string colorTextureImage;
133 app.description(
"Displays 2D image as heightmap by using QGLviewer.\n Exemple of use: visualisation/3dHeightMapViewer ${DGtal}/examples/samples/church.pgm -s 0.2");
135 app.add_option(
"-i,--input,1", inputFileName,
"2d input image representing the height map (given as grayscape image cast into 8 bits)." )
137 ->check(CLI::ExistingFile);
138 app.add_option(
"--scale,-s",scale,
"set the scale of the maximal level. (default 1.0)");
139 app.add_flag(
"--colorMap,-c", colorMap,
"define the heightmap color with a pre-defined colormap (GradientColorMap)");
140 app.add_option(
"--colorTextureImage,-t", colorTextureImage,
"define the heightmap color from a given color image (32 bits image).");
144 app.get_formatter()->column_width(40);
145 CLI11_PARSE(app, argc, argv);
149 typedef DGtal::ImageContainerBySTLVector<Z2i::Domain, unsigned char> Image2DG ;
150 typedef DGtal::ImageContainerBySTLVector<Z2i::Domain, unsigned int> Image2DCol ;
152 Image2DG image = GenericReader<Image2DG>::import( inputFileName );
153 Image2DCol imageTexture(image.domain());
154 int maxHeight = (int)(std::numeric_limits<Image2DG::Value>::max()*scale);
155 trace.info()<<
"Max height from scale:" << maxHeight << std::endl;
157 if(colorTextureImage !=
""){
158 imageTexture = GenericReader<Image2DCol>::import( colorTextureImage );
161 Z2i::RealPoint plow (image.domain().lowerBound()[0]-0.5,
162 image.domain().lowerBound()[1]-0.5);
164 Z2i::RealPoint pup (image.domain().upperBound()[0]+0.5,
165 image.domain().upperBound()[1]+0.5);
167 PolyscopeViewer viewer;
171 K.init(Z3i::Point(0,0,0),Z3i::Point(image.domain().upperBound()[0], image.domain().upperBound()[1], maxHeight+1),
true);
172 std::set<KSpace::SCell> boundVect;
173 Image3DPredicatFrom2DImage<Image2DG, Z3i::Point> image3Dpredicate(image, scale);
174 trace.info() <<
"Constructing boundary... ";
175 Surfaces<KSpace>::sMakeBoundary (boundVect, K, image3Dpredicate, Z3i::Point(0,0,0),
176 Z3i::Point(image.domain().upperBound()[0], image.domain().upperBound()[1], maxHeight+1));
177 trace.info() <<
"[done]"<< std::endl;
179 viewer.drawAsSimplified();
180 GradientColorMap<Image2DG::Value,CMAP_JET> gradientShade( 0, std::numeric_limits<Image2DG::Value>::max());
181 GrayscaleColorMap<Image2DG::Value> grayShade(0, std::numeric_limits<Image2DG::Value>::max());
184 for(std::set<KSpace::SCell>::const_iterator it = boundVect.begin();
185 it!= boundVect.end(); it++){
186 Z3i::Point pt = K.sCoords(K.sDirectIncident( *it, 2 ));
187 functors::Projector<SpaceND<2,int> > proj;
188 Image2DG::Value val = image(proj(pt));
190 if(!colorMap && colorTextureImage !=
""){
191 viewer << WithQuantity(*it,
"color", Color(imageTexture(proj(pt))));
193 viewer << WithQuantity(*it,
"value", val);