Code_TYMPAN  4.4.0
Industrial site acoustic simulation
cgal_tools.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 
25 #ifndef TYMPAN__CGAL_TOOLS_HPP__INCLUDED
26 #define TYMPAN__CGAL_TOOLS_HPP__INCLUDED
27 
28 #include <boost/array.hpp>
29 #include <boost/foreach.hpp>
30 #include <boost/range.hpp>
31 #include <boost/range/iterator_range.hpp>
32 // #include <boost/range/functions.hpp>
33 // #include <boost/range/adaptors.hpp>
34 // #include <boost/range/adaptor/transformed.hpp>
35 // using boost::adaptors::transformed;
36 
37 // TODO This header complexity will have to be masked as an implementation detail
38 #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
39 #include <CGAL/Triangulation_face_base_with_info_2.h>
40 #include <CGAL/Triangulation_vertex_base_with_info_2.h>
41 #include <CGAL/Constrained_Delaunay_triangulation_2.h>
42 #include <CGAL/Constrained_triangulation_plus_2.h>
43 #include <CGAL/Polygon_2.h>
44 #include <CGAL/Polygon_2_algorithms.h>
45 #include <CGAL/centroid.h>
46 #include <CGAL/box_intersection_d.h>
47 #include <CGAL/intersections.h>
48 
51 
52 namespace tympan
53 {
54 
55 // From CGAL manuel Section 37.8
56 // http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Triangulation_2/Chapter_main.html#Section_37.8
57 typedef CGAL::Exact_predicates_inexact_constructions_kernel CGAL_K;
58 typedef CGAL_K CGAL_Gt; /* Geometric Traits */
59 typedef CGAL::Point_2<CGAL_Gt> CGAL_Point2;
60 typedef CGAL::Point_3<CGAL_Gt> CGAL_Point3;
61 typedef CGAL::Vector_2<CGAL_Gt> CGAL_Vector2;
62 typedef CGAL::Vector_3<CGAL_Gt> CGAL_Vector3;
63 typedef CGAL::Polygon_2<CGAL_Gt> CGAL_Polygon;
64 typedef CGAL::Plane_3<CGAL_Gt> CGAL_Plane;
65 typedef CGAL::Triangle_3<CGAL_Gt> CGAL_Triangle;
66 typedef std::deque<CGAL_Triangle> CGAL_Triangles;
67 typedef CGAL::Box_intersection_d::Box_with_handle_d<double, 3, CGAL_Triangles::iterator> CGAL_TBox;
68 typedef CGAL::Aff_transformation_3<CGAL_Gt> CGAL_Transform3;
69 
71 inline OPoint3D from_cgal(const CGAL_Point3& cp)
72 {
73  return OPoint3D(cp.x(), cp.y(), cp.z());
74 }
76 inline CGAL_Point3 to_cgal(const OPoint3D& op)
77 {
78  return CGAL_Point3(op._x, op._y, op._z);
79 }
81 inline OVector3D from_cgal(const CGAL_Vector3& cp)
82 {
83  return OVector3D(cp.x(), cp.y(), cp.z());
84 }
86 inline CGAL_Vector3 to_cgal(const OVector3D& op)
87 {
88  return CGAL_Vector3(op._x, op._y, op._z);
89 }
91 CGAL_Plane to_cgal(const OPlan& oplan);
92 
108 std::deque<CGAL_Point3> build_box(float w, float h, CGAL_Point3 pta, CGAL_Point3 ptb);
109 
122 std::deque<size_t> intersected_triangles(CGAL_Triangles& triangle_soup,
123  std::deque<CGAL_Point3> query_triangle, float l, float w, float h);
124 
129 
134 {
135 
136 public:
137  struct VertexInfo
138  {
140  VertexInfo(int i_ = -1) : i(i_) {}
141  int i;
142  };
143 
144  struct FaceInfo
145  {
146  };
147 
148  /* Please refer to the following example in CGAL doc for meaning of those typedef
149  * http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Triangulation_2/Chapter_main.html#Subsection_37.8.2
150  */
151  typedef CGAL::Triangulation_vertex_base_with_info_2<VertexInfo, CGAL_Gt> Vbb;
152  typedef CGAL::Triangulation_face_base_with_info_2<FaceInfo, CGAL_Gt> Fbb;
153  typedef CGAL::Constrained_triangulation_face_base_2<CGAL_Gt, Fbb> Fb;
154  typedef CGAL::Triangulation_data_structure_2<Vbb, Fb> TDS;
155  typedef CGAL::Exact_predicates_tag Itag;
156  typedef CGAL::Constrained_Delaunay_triangulation_2<CGAL_Gt, TDS, Itag> CDT;
157  // typedef CGAL::Constrained_triangulation_plus_2<CDT> CDTplus;
158  typedef CDT::Vertex_handle Vertex_handle;
159  typedef CDT::Face_handle Face_handle;
160  typedef CDT::Triangle Triangle;
161  typedef std::deque<CDT::Vertex_handle> Vertex_handles_container;
162 
163 public:
164  typedef boost::array<unsigned, 3> Tri_indices;
166  PolygonTriangulator(const CGAL_Polygon& poly_);
168  virtual ~PolygonTriangulator();
170  const CDT& triangulation() const
171  {
172  return cdt;
173  }
175  const Vertex_handle& vertex_handle(unsigned i) const;
178  {
179  return poly_vh;
180  }
181 
189  void exportTriangles(std::deque<CDT::Triangle>& triangles) const;
190 
199  void exportTrianglesIndices(std::deque<Tri_indices>& triangles) const;
200 
201 protected:
206 
207 }; // PolygonTriangulator
208 
209 } // namespace tympan
210 
211 namespace tympan // Templates and inline implementations
212 {
213 
214 } // namespace tympan
215 
216 #endif // TYMPAN__CGAL_TOOLS_HPP__INCLUDED
All base classes related to 3D manipulation.
double _y
y coordinate of OCoord3D
Definition: 3d.h:283
double _z
z coordinate of OCoord3D
Definition: 3d.h:284
double _x
x coordinate of OCoord3D
Definition: 3d.h:282
Plan defined by its equation : ax+by+cz+d=0.
Definition: plan.h:31
The 3D point class.
Definition: 3d.h:487
The 3D vector class.
Definition: 3d.h:298
This class provides triangulating simple polygons without holes.
Definition: cgal_tools.h:134
PolygonTriangulator(const CGAL_Polygon &poly_)
Constructor from a CGAL_Polygon.
Definition: cgal_tools.cpp:134
CGAL::Triangulation_vertex_base_with_info_2< VertexInfo, CGAL_Gt > Vbb
Definition: cgal_tools.h:151
const CDT & triangulation() const
Return CDT object.
Definition: cgal_tools.h:170
const Vertex_handle & vertex_handle(unsigned i) const
Return the ith vertex handle.
Definition: cgal_tools.cpp:156
const Vertex_handles_container & vertex_handles() const
Return the polygon vertex handles.
Definition: cgal_tools.h:177
virtual ~PolygonTriangulator()
Destructor.
Definition: cgal_tools.cpp:154
CGAL::Triangulation_face_base_with_info_2< FaceInfo, CGAL_Gt > Fbb
Definition: cgal_tools.h:152
std::deque< CDT::Vertex_handle > Vertex_handles_container
Definition: cgal_tools.h:161
const CGAL_Polygon & poly
Reference to the CGAL_Polygon to triangulate.
Definition: cgal_tools.h:203
CGAL::Constrained_triangulation_face_base_2< CGAL_Gt, Fbb > Fb
Definition: cgal_tools.h:153
CGAL::Triangulation_data_structure_2< Vbb, Fb > TDS
Definition: cgal_tools.h:154
CDT::Face_handle Face_handle
Definition: cgal_tools.h:159
CGAL::Constrained_Delaunay_triangulation_2< CGAL_Gt, TDS, Itag > CDT
Definition: cgal_tools.h:156
CDT::Vertex_handle Vertex_handle
Definition: cgal_tools.h:158
boost::array< unsigned, 3 > Tri_indices
Definition: cgal_tools.h:164
CGAL::Exact_predicates_tag Itag
Definition: cgal_tools.h:155
void exportTrianglesIndices(std::deque< Tri_indices > &triangles) const
Exports the triangles inside the polygon.
Definition: cgal_tools.cpp:183
void exportTriangles(std::deque< CDT::Triangle > &triangles) const
Exports the triangles inside the polygon.
Definition: cgal_tools.cpp:163
Vertex_handles_container poly_vh
Polygon vertex handles.
Definition: cgal_tools.h:202
CGAL_Vector3 normalize(CGAL_Vector3 v)
normalize vector v
Definition: cgal_tools.cpp:41
CGAL::Exact_predicates_inexact_constructions_kernel CGAL_K
Definition: cgal_tools.h:57
CGAL::Triangle_3< CGAL_Gt > CGAL_Triangle
Definition: cgal_tools.h:65
CGAL_Plane to_cgal(const OPlan &oplan)
Convert a OPlan to CGAL_Plane.
Definition: cgal_tools.cpp:34
CGAL::Vector_2< CGAL_Gt > CGAL_Vector2
Definition: cgal_tools.h:61
CGAL::Point_3< CGAL_Gt > CGAL_Point3
Definition: cgal_tools.h:60
CGAL::Vector_3< CGAL_Gt > CGAL_Vector3
Definition: cgal_tools.h:62
OPoint3D from_cgal(const CGAL_Point3 &cp)
Convert a CGAL_Point3 to OPoint3D.
Definition: cgal_tools.h:71
CGAL::Point_2< CGAL_Gt > CGAL_Point2
Definition: cgal_tools.h:59
CGAL_K CGAL_Gt
Definition: cgal_tools.h:58
CGAL::Box_intersection_d::Box_with_handle_d< double, 3, CGAL_Triangles::iterator > CGAL_TBox
Definition: cgal_tools.h:67
std::deque< CGAL_Triangle > CGAL_Triangles
Definition: cgal_tools.h:66
std::deque< CGAL_Point3 > build_box(float w, float h, CGAL_Point3 pta, CGAL_Point3 ptb)
return 4 points defining a 3D parallelepiped
Definition: cgal_tools.cpp:46
CGAL::Aff_transformation_3< CGAL_Gt > CGAL_Transform3
Definition: cgal_tools.h:68
CGAL::Plane_3< CGAL_Gt > CGAL_Plane
Definition: cgal_tools.h:64
CGAL::Polygon_2< CGAL_Gt > CGAL_Polygon
Definition: cgal_tools.h:63
std::deque< size_t > intersected_triangles(CGAL_Triangles &triangle_soup, std::deque< CGAL_Point3 > query_box, float length, float width, float height)
Find the triangles from triangle_soup that are intersected by the 3D box including the points of quer...
Definition: cgal_tools.cpp:83
int i
This is the index of the vertice within the initial polygon.
Definition: cgal_tools.h:141
VertexInfo(int i_=-1)
Constructor.
Definition: cgal_tools.h:140