Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYIGNLevelCurvesParser.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012-2024> <EDF-DTG> <FRANCE>
3  * This file is part of Code_TYMPAN (R).
4  * Code_TYMPAN (R) is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * Code_TYMPAN (R) is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License along
13  * with Code_TYMPAN (R). If not, see <https://www.gnu.org/licenses/>.
14  */
15 
16 // TYIGNLevelCurvesParser.h
17 #ifndef TYIGNLEVELCURVESPARSER_H
18 #define TYIGNLEVELCURVESPARSER_H
19 
20 #include <QObject>
21 #include <QtXml>
22 #include <iostream>
23 #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
24 #include <CGAL/Polygon_2.h>
25 #include <CGAL/Constrained_Delaunay_triangulation_2.h>
26 #include <CGAL/Constrained_triangulation_plus_2.h>
27 #include <CGAL/Polyline_simplification_2/simplify.h>
28 #include <CGAL/Polyline_simplification_2/Squared_distance_cost.h>
29 #include <CGAL/Unique_hash_map.h>
30 
31 namespace PS = CGAL::Polyline_simplification_2;
32 typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
33 typedef PS::Vertex_base_2<K> Vb;
34 typedef CGAL::Constrained_triangulation_face_base_2<K> Fb;
35 typedef CGAL::Triangulation_data_structure_2<Vb, Fb> TDS;
36 typedef CGAL::Constrained_Delaunay_triangulation_2<K, TDS, CGAL::Exact_predicates_tag> CDT;
37 typedef CGAL::Constrained_triangulation_plus_2<CDT> CT;
38 typedef CT::Point Point;
40 
42 {
43 public:
44  std::size_t id;
45 
46  ConstraintIdWrapper(const Constraint_id& constraint_id)
47  {
48  static const size_t shift = (size_t)log2(1 + sizeof(Constraint_id));
49  id = (std::size_t)(constraint_id.second) >> shift;
50  }
51 
52  bool operator==(const ConstraintIdWrapper& other) const
53  {
54  return id == other.id;
55  }
56 };
57 
58 // Custom hash function for ConstraintIdWrapper
59 namespace std
60 {
61 template <> struct hash<ConstraintIdWrapper>
62 {
63  std::size_t operator()(const ConstraintIdWrapper& wrapper) const
64  {
65  return std::hash<std::size_t>()(wrapper.id);
66  }
67 };
68 } // namespace std
69 
73 typedef PS::Stop_below_count_ratio_threshold Stop;
74 typedef PS::Scaled_squared_distance_cost Cost;
76 
82 class TYIGNLevelCurvesParser : public QObject
83 {
84  Q_OBJECT
85 public:
87  {
88  QString id;
89  double altitude;
90 
91  // Default constructor
92  AltimetryInfo() : id(""), altitude(0.0) {}
93 
94  // Constructor
95  AltimetryInfo(const QString& idVal, double altitudeVal) : id(idVal), altitude(altitudeVal) {}
96  };
97 
98  explicit TYIGNLevelCurvesParser(QObject* parent = nullptr);
99 
105  bool isXmlLoaded() const
106  {
107  return m_isXmlLoaded;
108  }
109 
116  {
118  }
119 
125  QDomDocument getXmlDocument() const
126  {
127  return m_xmlDocument;
128  }
129 
135  const CT& getCT() const
136  {
137  return m_ct;
138  }
139 
146  std::unordered_map<ConstraintIdWrapper, AltimetryInfo>& getConstraintToAltimetryInfoMap()
147  {
149  }
150 
151  /*
152  * @brief Reset parser
153  */
154  void reset();
155 
156  bool loadXmlFile(const QString& filePath);
157  void parseXmlData(const OCoord3D& SIGCoords, const OBox& selectedZone, double scaleFactor);
158 
159  /*
160  * @brief Build an XML document from text
161  *
162  * @param text The text used to instantiate XML document
163  *
164  * @return bool <code>true</code> if succeeds;
165  * <code>false</code> if not.
166  */
167  bool buildXmlDocument(const QString& text); // New method to build XML document from text
168 
175  bool buildCTFromXMLFile(const OCoord3D& SIGCoords);
176 
177  /*
178  * @brief Build a polyline from an IGN level curve
179  * The polyligne is added as a new constraint to the constrained triangulation class member m_ct
180  *
181  * @param courbe The IGN courbe element in xml file
182  *
183  * @param SIGCoords The coordinates of the origin of the zone in Tympan coordinate system
184  *
185  * @return bool <code>true</code> if succeeds;
186  * <code>false</code> if not.
187  */
188  bool buildPolylineFromCourbe(const QDomElement& courbe, const OCoord3D& SIGCoords);
189 
190  /*
191  * @brief Simplify polyines defined as constraints in the constrained triangulation class member m_ct
192  *
193  * @return size_t The number of removed vertices
194  */
195  size_t simplifyPolylines();
196 
208  bool createLevelCurvesFromCT(const OCoord3D& SIGCoords, const OBox& selectedZone, double scaleFactor);
209 
210  static TYPoint convertLatLonToWebMercator(double latitude, double longitude);
211 
212  /*
213  * @brief Get the point of given index in the points list in Tympan coordinate system
214  *
215  * @param points The list of the coordinates of the points returned by IGN WFS service for level curves.
216  * These coordinates are in EPSG::4326 with latitude longitude for each point. All coordinates are
217  * separated by space
218  *
219  * @param index The index of the point times 2, as there are 2 coordinates by point
220  *
221  * @param SIGCoords The coordinates of the origin of the zone in Tympan coordinate system
222  *
223  * @param altitude The altitude of the level curve
224  *
225  * @return bool <code>true</code> if succeeds;
226  * <code>false</code> if not.
227  */
228  static TYPoint getPoint(const QStringList& points, int index, const OCoord3D& SIGCoords, double altitude);
229 
230  static Point getCGALPoint(const QStringList& points, int index, const OCoord3D& SIGCoords,
231  double altitude);
232 
233 signals:
235 
236 public slots:
237 
238 private:
239  QDomDocument m_xmlDocument;
242 
244  // Map to keep association between constraints and AltimetryInfo objects
245  std::unordered_map<ConstraintIdWrapper, AltimetryInfo> m_constraintToAltimetryInfoMap;
246 };
247 
248 #endif // TYIGNLEVELCURVESPARSER_H
CGAL::Constrained_triangulation_face_base_2< K > Fb
CT::Vertices_in_constraint_iterator Vertices_in_constraint_iterator
PS::Stop_below_count_ratio_threshold Stop
CGAL::Constrained_triangulation_plus_2< CDT > CT
CGAL::Triangulation_data_structure_2< Vb, Fb > TDS
CT::Constraint_iterator Constraint_iterator
CGAL::Exact_predicates_inexact_constructions_kernel K
CGAL::Constrained_Delaunay_triangulation_2< K, TDS, CGAL::Exact_predicates_tag > CDT
CT::Point Point
PS::Scaled_squared_distance_cost Cost
PS::Vertex_base_2< K > Vb
CT::Constraint_id Constraint_id
CT::Points_in_constraint_iterator Points_in_constraint_iterator
bool operator==(const ConstraintIdWrapper &other) const
ConstraintIdWrapper(const Constraint_id &constraint_id)
The box class.
Definition: 3d.h:1346
The 3D coordinate class.
Definition: 3d.h:226
Holds the business logic of parsing the response of level curve IGN web service, in order to send sig...
std::unordered_map< ConstraintIdWrapper, AltimetryInfo > & getConstraintToAltimetryInfoMap()
Getter for the constraint to AltimetryInfo map.
bool isXmlLoaded() const
Getter for the isXmlLoaded flag.
TYIGNLevelCurvesParser(QObject *parent=nullptr)
std::unordered_map< ConstraintIdWrapper, AltimetryInfo > m_constraintToAltimetryInfoMap
void courbeNiveauCreated(LPTYCourbeNiveau courbeNiveau)
static Point getCGALPoint(const QStringList &points, int index, const OCoord3D &SIGCoords, double altitude)
bool createLevelCurvesFromCT(const OCoord3D &SIGCoords, const OBox &selectedZone, double scaleFactor)
Create level curves from CGAL constrained triangulation.
QDomDocument getXmlDocument() const
Getter for the xmlDocument.
bool buildXmlDocument(const QString &text)
bool buildCTFromXMLFile(const OCoord3D &SIGCoords)
Build constrained triangulation from IGN XML file containing level curves.
bool buildPolylineFromCourbe(const QDomElement &courbe, const OCoord3D &SIGCoords)
static TYPoint getPoint(const QStringList &points, int index, const OCoord3D &SIGCoords, double altitude)
void parseXmlData(const OCoord3D &SIGCoords, const OBox &selectedZone, double scaleFactor)
bool loadXmlFile(const QString &filePath)
const CT & getCT() const
Getter for the CT member.
bool hasRetrievedLevelCurves() const
Getter for the hasRetrievedLevelCurves flag.
static TYPoint convertLatLonToWebMercator(double latitude, double longitude)
AltimetryInfo(const QString &idVal, double altitudeVal)
std::size_t operator()(const ConstraintIdWrapper &wrapper) const