DGtalTools 2.0.0
Loading...
Searching...
No Matches
3dHeightMapViewer.cpp
1
30#include <iostream>
31#include <climits>
32
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>
39
40#include "DGtal/io/Color.h"
41
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>
47
48using namespace std;
49using namespace DGtal;
50using namespace Z3i;
51
52#include "CLI11.hpp"
53
54
55
98// Defining a Helper to get the 3D point functor from an 2DImage
99template<typename TImage2D, typename TPoint3D >
100struct Image3DPredicatFrom2DImage{
101 typedef TPoint3D Point3D;
105 Image3DPredicatFrom2DImage(DGtal::ConstAlias<TImage2D> anImage, double aScale):myImageRef(anImage),
106 myScale(aScale){
107 }
108 inline
109 bool operator()(const Point3D &aPoint) const {
110 functors::Projector<SpaceND<2, typename TImage2D::Integer> > projXY;
111 return (*myImageRef)(projXY(aPoint))*myScale >= aPoint[2];
112 }
113 CountedConstPtrOrConstPtr<TImage2D> myImageRef;
114 double myScale;
115};
116
117
118
119
120
121
122
123
124int main( int argc, char** argv )
125{
126
127 // parse command line using CLI ----------------------------------------------
128 CLI::App app;
129 std::string inputFileName;
130 double scale {1.0};
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");
134
135 app.add_option("-i,--input,1", inputFileName, "2d input image representing the height map (given as grayscape image cast into 8 bits)." )
136 ->required()
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).");
141
142
143
144 app.get_formatter()->column_width(40);
145 CLI11_PARSE(app, argc, argv);
146 // END parse command line using CLI ----------------------------------------------
147
148
149 typedef DGtal::ImageContainerBySTLVector<Z2i::Domain, unsigned char> Image2DG ;
150 typedef DGtal::ImageContainerBySTLVector<Z2i::Domain, unsigned int> Image2DCol ;
151
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;
156
157 if(colorTextureImage != ""){
158 imageTexture = GenericReader<Image2DCol>::import( colorTextureImage );
159 }
160
161 Z2i::RealPoint plow (image.domain().lowerBound()[0]-0.5,
162 image.domain().lowerBound()[1]-0.5);
163
164 Z2i::RealPoint pup (image.domain().upperBound()[0]+0.5,
165 image.domain().upperBound()[1]+0.5);
166
167 PolyscopeViewer viewer;
168
169
170 KSpace K;
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;
178
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());
182
183
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));
189
190 if(!colorMap && colorTextureImage != ""){
191 viewer << WithQuantity(*it, "color", Color(imageTexture(proj(pt))));
192 } else {
193 viewer << WithQuantity(*it, "value", val);
194 }
195 viewer << *it;
196 }
197
198 viewer.show();
199 return 0;
200}
Definition ATu0v1.h:57