Code_TYMPAN  4.4.0
Industrial site acoustic simulation
cgal_tools.h
Go to the documentation of this file.
1 
10 #ifndef TYMPAN__CGAL_TOOLS_HPP__INCLUDED
11 #define TYMPAN__CGAL_TOOLS_HPP__INCLUDED
12 
13 #include <boost/array.hpp>
14 #include <boost/foreach.hpp>
15 #include <boost/range.hpp>
16 #include <boost/range/iterator_range.hpp>
17 // #include <boost/range/functions.hpp>
18 // #include <boost/range/adaptors.hpp>
19 // #include <boost/range/adaptor/transformed.hpp>
20 // using boost::adaptors::transformed;
21 
22 // TODO This header complexity will have to be masked as an implementation detail
23 #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
24 #include <CGAL/Triangulation_face_base_with_info_2.h>
25 #include <CGAL/Triangulation_vertex_base_with_info_2.h>
26 #include <CGAL/Constrained_Delaunay_triangulation_2.h>
27 #include <CGAL/Constrained_triangulation_plus_2.h>
28 #include <CGAL/Polygon_2.h>
29 #include <CGAL/Polygon_2_algorithms.h>
30 #include <CGAL/centroid.h>
31 #include <CGAL/box_intersection_d.h>
32 #include <CGAL/intersections.h>
33 
36 
37 namespace tympan
38 {
39 
40 // From CGAL manuel Section 37.8
41 // http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Triangulation_2/Chapter_main.html#Section_37.8
42 typedef CGAL::Exact_predicates_inexact_constructions_kernel CGAL_K;
43 typedef CGAL_K CGAL_Gt; /* Geometric Traits */
44 typedef CGAL::Point_2<CGAL_Gt> CGAL_Point2;
45 typedef CGAL::Point_3<CGAL_Gt> CGAL_Point3;
46 typedef CGAL::Vector_2<CGAL_Gt> CGAL_Vector2;
47 typedef CGAL::Vector_3<CGAL_Gt> CGAL_Vector3;
48 typedef CGAL::Polygon_2<CGAL_Gt> CGAL_Polygon;
49 typedef CGAL::Plane_3<CGAL_Gt> CGAL_Plane;
50 typedef CGAL::Triangle_3<CGAL_Gt> CGAL_Triangle;
51 typedef std::deque<CGAL_Triangle> CGAL_Triangles;
52 typedef CGAL::Box_intersection_d::Box_with_handle_d<double, 3, CGAL_Triangles::iterator> CGAL_TBox;
53 typedef CGAL::Aff_transformation_3<CGAL_Gt> CGAL_Transform3;
54 
56 inline OPoint3D from_cgal(const CGAL_Point3& cp)
57 {
58  return OPoint3D(cp.x(), cp.y(), cp.z());
59 }
61 inline CGAL_Point3 to_cgal(const OPoint3D& op)
62 {
63  return CGAL_Point3(op._x, op._y, op._z);
64 }
66 inline OVector3D from_cgal(const CGAL_Vector3& cp)
67 {
68  return OVector3D(cp.x(), cp.y(), cp.z());
69 }
71 inline CGAL_Vector3 to_cgal(const OVector3D& op)
72 {
73  return CGAL_Vector3(op._x, op._y, op._z);
74 }
76 CGAL_Plane to_cgal(const OPlan& oplan);
77 
93 std::deque<CGAL_Point3> build_box(float w, float h, CGAL_Point3 pta, CGAL_Point3 ptb);
94 
107 std::deque<size_t> intersected_triangles(CGAL_Triangles& triangle_soup,
108  std::deque<CGAL_Point3> query_triangle, float l, float w, float h);
109 
114 
119 {
120 
121 public:
122  struct VertexInfo
123  {
125  VertexInfo(int i_ = -1) : i(i_) {}
126  int i;
127  };
128 
129  struct FaceInfo
130  {
131  };
132 
133  /* Please refer to the following example in CGAL doc for meaning of those typedef
134  * http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Triangulation_2/Chapter_main.html#Subsection_37.8.2
135  */
136  typedef CGAL::Triangulation_vertex_base_with_info_2<VertexInfo, CGAL_Gt> Vbb;
137  typedef CGAL::Triangulation_face_base_with_info_2<FaceInfo, CGAL_Gt> Fbb;
138  typedef CGAL::Constrained_triangulation_face_base_2<CGAL_Gt, Fbb> Fb;
139  typedef CGAL::Triangulation_data_structure_2<Vbb, Fb> TDS;
140  typedef CGAL::Exact_predicates_tag Itag;
141  typedef CGAL::Constrained_Delaunay_triangulation_2<CGAL_Gt, TDS, Itag> CDT;
142  // typedef CGAL::Constrained_triangulation_plus_2<CDT> CDTplus;
143  typedef CDT::Vertex_handle Vertex_handle;
144  typedef CDT::Face_handle Face_handle;
145  typedef CDT::Triangle Triangle;
146  typedef std::deque<CDT::Vertex_handle> Vertex_handles_container;
147 
148 public:
149  typedef boost::array<unsigned, 3> Tri_indices;
151  PolygonTriangulator(const CGAL_Polygon& poly_);
153  virtual ~PolygonTriangulator();
155  const CDT& triangulation() const
156  {
157  return cdt;
158  }
160  const Vertex_handle& vertex_handle(unsigned i) const;
163  {
164  return poly_vh;
165  }
166 
174  void exportTriangles(std::deque<CDT::Triangle>& triangles) const;
175 
184  void exportTrianglesIndices(std::deque<Tri_indices>& triangles) const;
185 
186 protected:
191 
192 }; // PolygonTriangulator
193 
194 } // namespace tympan
195 
196 namespace tympan // Templates and inline implementations
197 {
198 
199 } // namespace tympan
200 
201 #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:119
PolygonTriangulator(const CGAL_Polygon &poly_)
Constructor from a CGAL_Polygon.
Definition: cgal_tools.cpp:119
CGAL::Triangulation_vertex_base_with_info_2< VertexInfo, CGAL_Gt > Vbb
Definition: cgal_tools.h:136
const CDT & triangulation() const
Return CDT object.
Definition: cgal_tools.h:155
const Vertex_handle & vertex_handle(unsigned i) const
Return the ith vertex handle.
Definition: cgal_tools.cpp:141
const Vertex_handles_container & vertex_handles() const
Return the polygon vertex handles.
Definition: cgal_tools.h:162
virtual ~PolygonTriangulator()
Destructor.
Definition: cgal_tools.cpp:139
CGAL::Triangulation_face_base_with_info_2< FaceInfo, CGAL_Gt > Fbb
Definition: cgal_tools.h:137
std::deque< CDT::Vertex_handle > Vertex_handles_container
Definition: cgal_tools.h:146
const CGAL_Polygon & poly
Reference to the CGAL_Polygon to triangulate.
Definition: cgal_tools.h:188
CGAL::Constrained_triangulation_face_base_2< CGAL_Gt, Fbb > Fb
Definition: cgal_tools.h:138
CGAL::Triangulation_data_structure_2< Vbb, Fb > TDS
Definition: cgal_tools.h:139
CDT::Face_handle Face_handle
Definition: cgal_tools.h:144
CGAL::Constrained_Delaunay_triangulation_2< CGAL_Gt, TDS, Itag > CDT
Definition: cgal_tools.h:141
CDT::Vertex_handle Vertex_handle
Definition: cgal_tools.h:143
boost::array< unsigned, 3 > Tri_indices
Definition: cgal_tools.h:149
CGAL::Exact_predicates_tag Itag
Definition: cgal_tools.h:140
void exportTrianglesIndices(std::deque< Tri_indices > &triangles) const
Exports the triangles inside the polygon.
Definition: cgal_tools.cpp:168
void exportTriangles(std::deque< CDT::Triangle > &triangles) const
Exports the triangles inside the polygon.
Definition: cgal_tools.cpp:148
Vertex_handles_container poly_vh
Polygon vertex handles.
Definition: cgal_tools.h:187
CGAL_Vector3 normalize(CGAL_Vector3 v)
normalize vector v
Definition: cgal_tools.cpp:26
CGAL::Exact_predicates_inexact_constructions_kernel CGAL_K
Definition: cgal_tools.h:42
CGAL::Triangle_3< CGAL_Gt > CGAL_Triangle
Definition: cgal_tools.h:50
CGAL_Plane to_cgal(const OPlan &oplan)
Convert a OPlan to CGAL_Plane.
Definition: cgal_tools.cpp:19
CGAL::Vector_2< CGAL_Gt > CGAL_Vector2
Definition: cgal_tools.h:46
CGAL::Point_3< CGAL_Gt > CGAL_Point3
Definition: cgal_tools.h:45
CGAL::Vector_3< CGAL_Gt > CGAL_Vector3
Definition: cgal_tools.h:47
OPoint3D from_cgal(const CGAL_Point3 &cp)
Convert a CGAL_Point3 to OPoint3D.
Definition: cgal_tools.h:56
CGAL::Point_2< CGAL_Gt > CGAL_Point2
Definition: cgal_tools.h:44
CGAL_K CGAL_Gt
Definition: cgal_tools.h:43
CGAL::Box_intersection_d::Box_with_handle_d< double, 3, CGAL_Triangles::iterator > CGAL_TBox
Definition: cgal_tools.h:52
std::deque< CGAL_Triangle > CGAL_Triangles
Definition: cgal_tools.h:51
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:31
CGAL::Aff_transformation_3< CGAL_Gt > CGAL_Transform3
Definition: cgal_tools.h:53
CGAL::Plane_3< CGAL_Gt > CGAL_Plane
Definition: cgal_tools.h:49
CGAL::Polygon_2< CGAL_Gt > CGAL_Polygon
Definition: cgal_tools.h:48
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:68
int i
This is the index of the vertice within the initial polygon.
Definition: cgal_tools.h:126
VertexInfo(int i_=-1)
Constructor.
Definition: cgal_tools.h:125