DGtalTools  1.3.beta
Functions
3dHeightMapViewer.cpp File Reference
#include <iostream>
#include <climits>
#include "DGtal/base/Common.h"
#include "DGtal/base/BasicFunctors.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/io/readers/GenericReader.h"
#include "DGtal/io/viewers/Viewer3D.h"
#include <DGtal/io/colormaps/GradientColorMap.h>
#include <DGtal/io/colormaps/GrayscaleColorMap.h>
#include <DGtal/images/ImageContainerBySTLVector.h>
#include "DGtal/io/Color.h"
#include <DGtal/base/ConstAlias.h>
#include <DGtal/kernel/BasicPointFunctors.h>
#include <DGtal/topology/helpers/Surfaces.h>
#include "CLI11.hpp"
Include dependency graph for 3dHeightMapViewer.cpp:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Bertrand Kerautret (kerau.nosp@m.tre@.nosp@m.loria.nosp@m..fr ) LORIA (CNRS, UMR 7503), University of Nancy, France
Date
2014/06/2014

An example file named qglViewer.

This file is part of the DGtal library.

Definition in file 3dHeightMapViewer.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 206 of file 3dHeightMapViewer.cpp.

References DGtal::Trace::info(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), DGtal::KhalimskySpaceND< dim, TInteger >::sCoords(), DGtal::KhalimskySpaceND< dim, TInteger >::sDirectIncident(), and DGtal::trace.

207 {
208 
209  // parse command line using CLI ----------------------------------------------
210  CLI::App app;
211  std::string inputFileName;
212  double scale {1.0};
213  bool colorMap {false};
214  std::string colorTextureImage;
215  app.description("Displays 2D image as heightmap by using QGLviewer.\n Exemple of use: visualisation/3dHeightMapViewer ${DGtal}/examples/samples/church.pgm -s 0.2");
216 
217  app.add_option("-i,--input,1", inputFileName, "2d input image representing the height map (given as grayscape image cast into 8 bits)." )
218  ->required()
219  ->check(CLI::ExistingFile);
220  app.add_option("--scale,-s",scale, "set the scale of the maximal level. (default 1.0)");
221  app.add_flag("--colorMap,-c", colorMap, "define the heightmap color with a pre-defined colormap (GradientColorMap)");
222  app.add_option("--colorTextureImage,-t", colorTextureImage, "define the heightmap color from a given color image (32 bits image).");
223 
224 
225 
226  app.get_formatter()->column_width(40);
227  CLI11_PARSE(app, argc, argv);
228  // END parse command line using CLI ----------------------------------------------
229 
230 
233 
234  Image2DG image = GenericReader<Image2DG>::import( inputFileName );
235  Image2DCol imageTexture(image.domain());
236  int maxHeight = (int)(std::numeric_limits<Image2DG::Value>::max()*scale);
237  trace.info()<< "Max height from scale:" << maxHeight << std::endl;
238 
239  if(colorTextureImage != ""){
240  imageTexture = GenericReader<Image2DCol>::import( colorTextureImage );
241  }
242 
243  QApplication application(argc,argv);
244  Z2i::RealPoint plow (image.domain().lowerBound()[0]-0.5,
245  image.domain().lowerBound()[1]-0.5);
246 
247  Z2i::RealPoint pup (image.domain().upperBound()[0]+0.5,
248  image.domain().upperBound()[1]+0.5);
249 
250  Viewer3DImageSpec<> viewer(plow, pup) ;
251  viewer.setWindowTitle("Height Map Viewer");
252  viewer.show();
253 
254 
255  KSpace K;
256  K.init(Z3i::Point(0,0,0),Z3i::Point(image.domain().upperBound()[0], image.domain().upperBound()[1], maxHeight+1), true);
257  std::set<KSpace::SCell> boundVect;
258  Image3DPredicatFrom2DImage<Image2DG, Z3i::Point> image3Dpredicate(image, scale);
259  trace.info() << "Constructing boundary... ";
260  Surfaces<KSpace>::sMakeBoundary (boundVect, K, image3Dpredicate, Z3i::Point(0,0,0),
261  Z3i::Point(image.domain().upperBound()[0], image.domain().upperBound()[1], maxHeight+1));
262  trace.info() << "[done]"<< std::endl;
263 
264  viewer << SetMode3D((*(boundVect.begin())).className(), "Basic" );
265  GradientColorMap<Image2DG::Value,CMAP_JET> gradientShade( 0, std::numeric_limits<Image2DG::Value>::max());
266  GrayscaleColorMap<Image2DG::Value> grayShade(0, std::numeric_limits<Image2DG::Value>::max());
267 
268 
269  for(std::set<KSpace::SCell>::const_iterator it = boundVect.begin();
270  it!= boundVect.end(); it++){
271  Z3i::Point pt = K.sCoords(K.sDirectIncident( *it, 2 ));
273  Image2DG::Value val = image(proj(pt));
274  if(colorMap){
275  viewer.setFillColor(gradientShade(val));
276  }else if (colorTextureImage != "") {
277  viewer.setFillColor(Color(imageTexture(proj(pt))));
278  }else{
279  viewer.setFillColor(grayShade(val));
280  }
281  viewer << *it;
282  }
283 
284  viewer << Viewer3D<>::updateDisplay;
285  return application.exec();
286 }
SCell sDirectIncident(const SCell &p, Dimension k) const
bool init(const Point &lower, const Point &upper, bool isClosed)
Point sCoords(const SCell &c) const
Trace trace(traceWriterTerm)
std::ostream & info()