EMODnet Quantized Mesh Generator for Cesium
All Classes Namespaces Files Functions Variables Pages
quantized_mesh_tiler.h
1 // Copyright (c) 2018 Coronis Computing S.L. (Spain)
2 // All rights reserved.
3 //
4 // This file is part of EMODnet Quantized Mesh Generator for Cesium.
5 //
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program. If not, see <https://www.gnu.org/licenses/>.
18 //
19 // Author: Ricard Campos (ricardcd@gmail.com)
20 
21 #ifndef EMODNET_QMGC_QUANTIZED_MESH_TILER_H
22 #define EMODNET_QMGC_QUANTIZED_MESH_TILER_H
23 
24 #include "quantized_mesh.h"
25 #include "quantized_mesh_tile.h"
26 #include "tin_creation/tin_creation_cgal_types.h"
27 #include <ctb.hpp>
28 #include <boost/filesystem.hpp>
29 #include "ellipsoid.h"
30 #include "tin_creation/tin_creator.h"
31 #include <mutex>
32 #include "borders_data.h"
33 
34 namespace fs = boost::filesystem ;
35 
36 
41 class QuantizedMeshTiler : public ctb::TerrainTiler
42 {
43  // --- Private Typedefs ---
44  typedef TinCreation::Point_3 Point_3;
45  typedef TinCreation::Vector_3 Vector_3;
46  typedef TinCreation::Point_2 Point_2;
47  typedef TinCreation::Polyhedron Polyhedron;
48 
49 public:
50  // --- Options struct ---
51  struct QMTOptions {
52  bool IsBathymetry = false ;
54  int HeighMapSamplingSteps = 256 ;
55  float ClippingHighValue = std::numeric_limits<float>::infinity() ;
56  float ClippingLowValue = -std::numeric_limits<float>::infinity() ;
59  };
60 
61  // --- Methods ---
62 
67  QuantizedMeshTiler(GDALDataset *dataset,
68  const ctb::Grid &grid,
69  const ctb::TilerOptions &tilerOptions,
70  const QMTOptions& options,
71  const TinCreation::TinCreator& tinCreator )
72  : TerrainTiler(dataset, grid, tilerOptions)
73  , m_options(options)
74  , m_tinCreator(tinCreator)
75  {checkOptions();}
76 
81  : TerrainTiler(tiler.poDataset, tiler.mGrid, tiler.options)
82  , m_options(tiler.m_options)
83  , m_tinCreator(tiler.m_tinCreator)
84  {}
85 
102  QuantizedMeshTile createTile(const ctb::TileCoordinate &coord, BordersData& bd) ;
103 
108  QMTOptions getOptions() { return m_options; }
109 
114  void setTinCreatorParamsForZoom(const unsigned int& zoom) { m_tinCreator.setParamsForZoom(zoom); }
115 
126  std::vector<Point_3> getUVHPointsFromRaster(const ctb::TileCoordinate &coord,
127  BordersData& bd,
128  float& minHeight, float& maxHeight,
129  ctb::CRSBounds& tileBounds) const ;
130 
131 private:
132  // --- Attributes ---
133  QMTOptions m_options;
134  TinCreation::TinCreator m_tinCreator;
135  mutable std::mutex m_mutex; // Mark mutex as mutable because it doesn't represent the object's real state
136  // Note that we don't need the mutex if we create multiple instances of tilers, as done in qm_tiler right now. We leave it here in case it is needed for other implementations
137 
138  // --- Private Functions ---
142  void checkOptions() {
143  if ( m_options.HeighMapSamplingSteps < 0 ) {
144  std::cerr << "[WARNING] QuantizedMeshTiler::options HeighMapSamplingSteps < 0, defaulting to 256" << std::endl;
145  m_options.HeighMapSamplingSteps = 256 ;
146  }
147  if ( m_options.HeighMapSamplingSteps > 256 ) {
148  std::cerr << "[WARNING] QuantizedMeshTiler::options HeighMapSamplingSteps > 256 (maximum), defaulting to 256" << std::endl;
149  m_options.HeighMapSamplingSteps = 256 ;
150  }
151  }
152 
160  float clip(const float& n, const float& lower, const float& upper) const {
161  return std::max(lower, std::min(n, upper));
162  }
163 
164  // --- The following private functions split the processing required to generate the tiles for better readability ---
165 
166 
167 
177  void computeQuantizedMeshHeader(QuantizedMeshTile& qmTile,
178  const Polyhedron& surface,
179  const float& minHeight, float& maxHeight,
180  const ctb::CRSBounds& tileBounds) const ;
181 
182 
196  void computeQuantizedMeshGeometry(QuantizedMeshTile& qmTile,
197  Polyhedron& surface,
198  const float& minHeight, const float& maxHeight,
199  std::vector<Point_3> &tileEastVertices,
200  std::vector<Point_3> &tileWestVertices,
201  std::vector<Point_3> &tileNorthVertices,
202  std::vector<Point_3> &tileSouthVertices ) const ;
203 };
204 
205 #endif //EMODNET_QMGC_QUANTIZED_MESH_TILER_H
QMTOptions getOptions()
Get the creation options for this tiler (QMTOptions structure)
Definition: quantized_mesh_tiler.h:108
float ClippingLowValue
Minimum value allowed on the raster, clip values if smaller.
Definition: quantized_mesh_tiler.h:56
QuantizedMeshTile createTile(const ctb::TileCoordinate &coord, BordersData &bd)
Create the quantized mesh tile.
Definition: quantized_mesh_tiler.cpp:34
Structure storing the data for the borders of a tile. This includes the 4 east-west-north-south borde...
Definition: borders_data.h:30
QuantizedMeshTiler(GDALDataset *dataset, const ctb::Grid &grid, const ctb::TilerOptions &tilerOptions, const QMTOptions &options, const TinCreation::TinCreator &tinCreator)
Constructor: instantiates a tiler with all required arguments.
Definition: quantized_mesh_tiler.h:67
bool IsBathymetry
Flag indicating wether the values on the raster must be considered as elevations (false) or depths (t...
Definition: quantized_mesh_tiler.h:52
Main class used to create a TIN from an input set of points.
Definition: tin_creator.h:143
Describes an ellipsoid.
Definition: ellipsoid.h:32
Definition: quantized_mesh_tiler.h:51
QuantizedMeshTiler(const QuantizedMeshTiler &tiler)
A copy constructor that does not try to copy the mutex (needed because mutex are non-copyable) ...
Definition: quantized_mesh_tiler.h:80
Tiler of a terrain generating quantized-mesh tiles.
Definition: quantized_mesh_tiler.h:41
The WGS84 ellipsoid.
Definition: ellipsoid.h:86
float ClippingHighValue
Maximum value allowed on the raster, clip values if larger.
Definition: quantized_mesh_tiler.h:55
std::vector< Point_3 > getUVHPointsFromRaster(const ctb::TileCoordinate &coord, BordersData &bd, float &minHeight, float &maxHeight, ctb::CRSBounds &tileBounds) const
Get the heightmap values from the GDAL raster in normalized coordinates.
Definition: quantized_mesh_tiler.cpp:66
Encapsulates a Tile in Quantized Mesh format *.
Definition: quantized_mesh_tile.h:33
void setTinCreatorParamsForZoom(const unsigned int &zoom)
Definition: quantized_mesh_tiler.h:114
Ellipsoid RefEllipsoid
The reference ellipsoid of the tile (needed to compute horizon occlusion point)
Definition: quantized_mesh_tiler.h:53
float AboveSeaLevelScaleFactor
Scale factor to apply to the readings above sea level (ignored if < 0)
Definition: quantized_mesh_tiler.h:57
float BelowSeaLevelScaleFactor
Scale factor to apply to the readings below sea level (ignored if < 0)
Definition: quantized_mesh_tiler.h:58
int HeighMapSamplingSteps
Sampling steps. Maximum = 256!
Definition: quantized_mesh_tiler.h:54