EMODnet Quantized Mesh Generator for Cesium
tin_creation_simplification_point_set.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_CREATION_SIMPLIFICATION_POINT_SET_H
22 #define EMODNET_QMGC_TIN_CREATION_SIMPLIFICATION_POINT_SET_H
23 
24 #include "tin_creator.h"
25 #include "tin_creation_cgal_types.h"
26 #include "cgal/Projection_traits_3_extended.h"
27 #include "cgal/point_set_features_simplification_cost.h"
28 #include "tin_creation_utils.h"
29 
30 namespace TinCreation {
31 
46 {
47  // --- Typedefs ---
49  typedef PS::Vertex_base_2<ProjTraitsXY> VbXY;
50  typedef CGAL::Constrained_triangulation_face_base_2<ProjTraitsXY> FbXY;
51  typedef CGAL::Triangulation_data_structure_2<VbXY, FbXY> TDSXY;
52  typedef CGAL::Constrained_Delaunay_triangulation_2<ProjTraitsXY,
53  TDSXY, CGAL::Exact_predicates_tag> CDTXY;
56 
57 public:
64  TinCreationSimplificationPointSet(double borderSimplificationMaxDistance,
65  double borderSimplificationMaxLengthPercent,
66  unsigned int minFeaturePolylineSize)
67  : m_minFeaturePolylineSize(minFeaturePolylineSize)
68  {
69  m_borderSimpMaxDistPerZoom = std::vector<FT>{borderSimplificationMaxDistance};
70  m_borderSimpMaxLengthPercentPerZoom = std::vector<FT>{borderSimplificationMaxLengthPercent};
71 // setParamsForZoom(0);
72  }
73 
80  TinCreationSimplificationPointSet(const std::vector<double>& borderSimplificationMaxDistance,
81  const std::vector<double>& borderSimplificationMaxLengthPercent,
82  unsigned int minFeaturePolylineSize)
83  : m_borderSimpMaxDistPerZoom(borderSimplificationMaxDistance)
84  , m_borderSimpMaxLengthPercentPerZoom(borderSimplificationMaxLengthPercent)
85  {
86 // setParamsForZoom(0);
87  }
88 
89  Polyhedron create(const std::vector<Point_3>& dataPts,
90  const bool &constrainEasternVertices,
91  const bool &constrainWesternVertices,
92  const bool &constrainNorthernVertices,
93  const bool &constrainSouthernVertices) ;
94 
100  // While the process of preserving border/feature edges is implemented in this base class, the methods using point
101  // set simplification differ on the way they simplify the point set
102  // Thus, this is the only method that needs to be implemented in the child classes
103  virtual std::vector<Point_3> simplify(const std::vector<Point_3>& pts) = 0;
104 
105  void setParamsForZoom(const unsigned int& zoom) {
106  m_borderSimpMaxDist = standardHandlingOfThresholdPerZoom(m_borderSimpMaxDistPerZoom, zoom);
107 
108  m_borderSimpMaxLengthPercent = standardHandlingOfThresholdPerZoom(m_borderSimpMaxLengthPercentPerZoom, zoom);
109  m_borderSimpMaxLengthPercent /= 100.0; // Note that the m_borderSimpMaxLengthPercent is a percentage, so we divide it by 100 to have it between 0..1, as expected by the CGAL::Polyline_simplification_2::simplify function
110 
111  // Set further parameters that are exclusive of each point set simplification strategy using setParamsForZoomConcreteStrategy(zoom); in derived classes
113  }
114 
119  virtual void setParamsForZoomConcreteStrategy(const unsigned int& zoom) = 0;
120 
121 private:
122  double m_borderSimpMaxDist;
123  double m_borderSimpMaxScaledSqDist;
124  double m_borderSimpMaxLengthPercent; // We do not scale this length, as it is relative to the XY plane
125  std::vector<double> m_borderSimpMaxDistPerZoom;
126  std::vector<double> m_borderSimpMaxLengthPercentPerZoom;
127  unsigned int m_minFeaturePolylineSize;
128  CTXY m_cdt;
129 
131  void imposeConstraintsAndSimplifyPolylines(Polyhedron& surface,
132  const bool &constrainEasternVertices,
133  const bool &constrainWesternVertices,
134  const bool &constrainNorthernVertices,
135  const bool &constrainSouthernVertices) ;
136 
139  void getAllNonBorderVertices(const Polyhedron& poly, PointCloud& nonBorderPts) const ;
140 };
141 
142 } // End namespace TinCreation
143 
144 #endif //EMODNET_QMGC_TIN_CREATION_SIMPLIFICATION_POINT_SET_H
T standardHandlingOfThresholdPerZoom(const std::vector< T > &thresholdsPerZoom, const unsigned int &zoom, const bool &downScale=true)
Definition: tin_creation_utils.h:43
This namespace contains all the types/classes/functions required to create a TIN out of a regularly g...
TinCreationSimplificationPointSet(double borderSimplificationMaxDistance, double borderSimplificationMaxLengthPercent, unsigned int minFeaturePolylineSize)
Definition: tin_creation_simplification_point_set.h:64
void setParamsForZoom(const unsigned int &zoom)
Adapts the parameters of the algorithm for the desired zoom level.
Definition: tin_creation_simplification_point_set.h:105
virtual void setParamsForZoomConcreteStrategy(const unsigned int &zoom)=0
TinCreationSimplificationPointSet(const std::vector< double > &borderSimplificationMaxDistance, const std::vector< double > &borderSimplificationMaxLengthPercent, unsigned int minFeaturePolylineSize)
Definition: tin_creation_simplification_point_set.h:80
Polyhedron create(const std::vector< Point_3 > &dataPts, const bool &constrainEasternVertices, const bool &constrainWesternVertices, const bool &constrainNorthernVertices, const bool &constrainSouthernVertices)
Create a TIN from a set of points.
Definition: tin_creation_simplification_point_set.cpp:33
Polyline simplification cost function used by point set simplification methods.
Definition: point_set_features_simplification_cost.h:43
Creates a TIN using a point set simplification algorithm.
Definition: tin_creation_simplification_point_set.h:45
Defines the interphase of a TIN creation algorithm.
Definition: tin_creator.h:37
Definition: Projection_traits_3_extended.h:145
virtual std::vector< Point_3 > simplify(const std::vector< Point_3 > &pts)=0