EMODnet Quantized Mesh Generator for Cesium
tin_creator.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_TIN_CREATOR_H
22 #define EMODNET_QMGC_TIN_CREATOR_H
23 
24 #include <memory>
25 #include "tin_creation_cgal_types.h"
26 #include "base/misc_utils.h"
27 
28 // Note: this set of classes implement a Strategy Pattern
29 namespace TinCreation {
30 
38 public:
41  : m_scaleZ(1.0)
42  , m_minX(-1.0), m_minY(-1.0), m_minZ(-1.0), m_maxX(-1.0), m_maxY(-1.0), m_maxZ(-1.0)
43  , m_boundsSet(false) {}
44 
58  virtual Polyhedron create(const std::vector<Point_3> &dataPts,
59  const bool &constrainEasternVertices,
60  const bool &constrainWesternVertices,
61  const bool &constrainNorthernVertices,
62  const bool &constrainSouthernVertices) = 0;
63 
71  virtual void setParamsForZoom(const unsigned int& zoom) = 0;
72 
77  void setScaleZ(const double& scale) { m_scaleZ = scale; }
78 
80  double getScaleZ() { return m_scaleZ; }
81 
91  void setBounds(const double& minX, const double& minY, const double& minZ,
92  const double& maxX, const double& maxY, const double& maxZ ) {
93  m_minX = minX; m_minY = minY; m_minZ = minZ;
94  m_maxX = maxX; m_maxY = maxY; m_maxZ = maxZ;
95  m_boundsSet = true;
96  }
97 
99  double getMinX() const { return m_minX; }
101  double getMinY() const { return m_minY; }
103  double getMinZ() const { return m_minZ; }
105  double getMaxX() const { return m_maxX; }
107  double getMaxY() const { return m_maxY; }
109  double getMaxZ() const { return m_maxZ; }
110 
111  bool hasOriginalBoundingBox() const { return m_boundsSet; }
112 
114  // This conversion is used by some point set simplification methods requiring metric coordinates
115  std::vector<Point_3> convertUVHToECEF(const std::vector<Point_3>& pts) const;
116 
118  // This conversion is used by some point set simplification methods requiring metric coordinates
119  std::vector<Point_3> convertECEFToUVH(const std::vector<Point_3>& pts) const;
120 
122  // This conversion is used by some point set simplification methods requiring metric coordinates
123  Point_3 convertUVHToECEF(const Point_3& p) const;
124 
126  // This conversion is used by some point set simplification methods requiring metric coordinates
127  Point_3 convertECEFToUVH(const Point_3& p) const;
128 
129 private:
130  double m_scaleZ;
131  double m_minX, m_minY, m_minZ, m_maxX, m_maxY, m_maxZ;
132  bool m_boundsSet;
133 };
134 
143 class TinCreator {
144 public:
145  // --- Methods ---
147  TinCreator() { m_creator = nullptr; }
148 
153  void setCreator(std::shared_ptr<TinCreationStrategy> creator) { m_creator = creator; }
154 
168  Polyhedron create(const std::vector<Point_3> &dataPts,
169  const bool &constrainEasternVertices = false,
170  const bool &constrainWesternVertices = false,
171  const bool &constrainNorthernVertices = false,
172  const bool &constrainSouthernVertices = false) {
173  return m_creator->create(dataPts,
174  constrainEasternVertices,
175  constrainWesternVertices,
176  constrainNorthernVertices,
177  constrainSouthernVertices);
178  }
179 
187  void setParamsForZoom(const unsigned int& zoom) {
188  m_creator->setParamsForZoom(zoom);
189  }
190 
195  void setScaleZ(const double& scale) { m_creator->setScaleZ(scale); }
196 
206  void setBounds(const double& minX, const double& minY, const double& minZ,
207  const double& maxX, const double& maxY, const double& maxZ) {
208  m_creator->setBounds(minX, minY, minZ, maxX, maxY, maxZ);
209  double scaleZ = remap( 1.0, 0.0, maxZ-minZ, 0.0, 1.0 );
210  setScaleZ(scaleZ);
211  }
212 
213 private:
214  // --- Attributes ---
215  std::shared_ptr<TinCreationStrategy> m_creator;
216 };
217 
218 } // End namespace tin_creation
219 
220 #endif //EMODNET_QMGC_TIN_CREATOR_H
double getMinZ() const
Get the minimum Z coordinate.
Definition: tin_creator.h:103
double getScaleZ()
Get the scale in Z.
Definition: tin_creator.h:80
void setBounds(const double &minX, const double &minY, const double &minZ, const double &maxX, const double &maxY, const double &maxZ)
Definition: tin_creator.h:206
This namespace contains all the types/classes/functions required to create a TIN out of a regularly g...
double getMaxX() const
Get the maximum X coordinate.
Definition: tin_creator.h:105
void setCreator(std::shared_ptr< TinCreationStrategy > creator)
Sets the actual TIN creator algorithm.
Definition: tin_creator.h:153
TinCreationStrategy()
Constructor.
Definition: tin_creator.h:40
TinCreator()
Constructor.
Definition: tin_creator.h:147
double getMinY() const
Get the minimum Y coordinate.
Definition: tin_creator.h:101
double getMinX() const
Get the minimum X coordinate.
Definition: tin_creator.h:99
void setScaleZ(const double &scale)
Definition: tin_creator.h:195
double getMaxZ() const
Get the maximum Z coordinate.
Definition: tin_creator.h:109
Main class used to create a TIN from an input set of points.
Definition: tin_creator.h:143
void setScaleZ(const double &scale)
Definition: tin_creator.h:77
void setBounds(const double &minX, const double &minY, const double &minZ, const double &maxX, const double &maxY, const double &maxZ)
Definition: tin_creator.h:91
void setParamsForZoom(const unsigned int &zoom)
Adapts the parameters of the algorithm for the desired zoom level.
Definition: tin_creator.h:187
std::vector< Point_3 > convertUVHToECEF(const std::vector< Point_3 > &pts) const
Convert points to ECEF assuming that they are on a UVH format, and given the limits of the tile...
Definition: tin_creator.cpp:28
std::vector< Point_3 > convertECEFToUVH(const std::vector< Point_3 > &pts) const
Convert points from local UVH to ECEF given the limits of the tile.
Definition: tin_creator.cpp:47
virtual Polyhedron create(const std::vector< Point_3 > &dataPts, const bool &constrainEasternVertices, const bool &constrainWesternVertices, const bool &constrainNorthernVertices, const bool &constrainSouthernVertices)=0
Create a TIN from a set of points.
virtual void setParamsForZoom(const unsigned int &zoom)=0
Adapts the parameters of the algorithm for the desired zoom level.
Polyhedron create(const std::vector< Point_3 > &dataPts, const bool &constrainEasternVertices=false, const bool &constrainWesternVertices=false, const bool &constrainNorthernVertices=false, const bool &constrainSouthernVertices=false)
Create a TIN from a set of points.
Definition: tin_creator.h:168
double getMaxY() const
Get the maximum Y coordinate.
Definition: tin_creator.h:107
Defines the interphase of a TIN creation algorithm.
Definition: tin_creator.h:37