1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + This file is part of enGrid. +
5 // + Copyright 2008-2014 enGits GmbH +
7 // + enGrid is free software: you can redistribute it and/or modify +
8 // + it under the terms of the GNU General Public License as published by +
9 // + the Free Software Foundation, either version 3 of the License, or +
10 // + (at your option) any later version. +
12 // + enGrid is distributed in the hope that it will be useful, +
13 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
14 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
15 // + GNU General Public License for more details. +
17 // + You should have received a copy of the GNU General Public License +
18 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22 #ifndef CGALTRICADINTERFACE_H
23 #define CGALTRICADINTERFACE_H
25 #include <CGAL/Simple_cartesian.h>
26 #include <CGAL/AABB_tree.h>
27 #include <CGAL/AABB_traits.h>
28 #include <CGAL/AABB_triangle_primitive.h>
29 #include <CGAL/AABB_segment_primitive.h>
32 #include "cadinterface.h"
34 class CgalTriCadInterface
: public CadInterface
39 typedef CGAL::Simple_cartesian
<double> K
;
43 typedef K::Line_3 Line
;
44 typedef K::Point_3 Point
;
45 typedef K::Segment_3 Segment
;
46 typedef K::Triangle_3 Triangle
;
48 typedef QVector
<Triangle
>::iterator TriangleIterator
;
49 typedef CGAL::AABB_triangle_primitive
<K
,TriangleIterator
> TrianglePrimitive
;
50 typedef CGAL::AABB_traits
<K
, TrianglePrimitive
> TriangleTraits
;
51 typedef CGAL::AABB_tree
<TriangleTraits
> TriangleTree
;
52 typedef TriangleTree::Point_and_primitive_id TrianglePointAndPrimitiveId
;
54 typedef QVector
<Segment
>::iterator SegmentIterator
;
55 typedef CGAL::AABB_segment_primitive
<K
, SegmentIterator
> SegmentPrimitive
;
56 typedef CGAL::AABB_traits
<K
, SegmentPrimitive
> SegmentTraits
;
57 typedef CGAL::AABB_tree
<SegmentTraits
> SegmentTree
;
59 //typedef boost::optional<TriangleTree::Intersection_and_primitive_id<Ray>::Type> Intersection;
60 typedef TriangleTree::Intersection_and_primitive_id
<Ray
>::Type Intersection
;
62 private: // attributes
64 QVector
<Triangle
> m_Triangles
;
65 TriangleTree m_TriangleTree
;
66 QVector
<Segment
> m_Segments
;
67 SegmentTree m_SegmentTree
;
68 vtkUnstructuredGrid
*m_BGrid
;
69 MeshPartition m_BPart
;
70 QVector
<vtkIdType
> m_Tri2Grid
;
71 QVector
<double> m_Radius
; ///< Surface radius for mesh resolution.
76 void computeSurfaceCurvature();
77 Ray
createRay(vec3_t x1
, vec3_t v
);
82 CgalTriCadInterface(vtkUnstructuredGrid
*grid
);
83 virtual HitType
shootRay(vec3_t x
, vec3_t v
, vec3_t
&x_hit
, vec3_t
&n_hit
, double &r
);
84 virtual vec3_t
snap(vec3_t x
, bool correct_curvature
= false);
85 virtual vec3_t
snapWithNormal(vec3_t x
, vec3_t n
, bool correct_curvature
= false);
86 virtual vec3_t
snapNode(vtkIdType id_node
, vec3_t x
, bool correct_curvature
);
87 virtual vec3_t
snapToEdge(vec3_t x
);
88 virtual vec3_t
snapToCorner(vec3_t x
);
89 virtual void computeIntersections(vec3_t x
, vec3_t v
, QVector
<QPair
<vec3_t
, vtkIdType
> > &intersections
);
93 #endif // CGALTRICADINTERFACE_H