GemaCoreLib
The GeMA Core library
Loading...
Searching...
No Matches
gmBVHAcceleration.h
Go to the documentation of this file.
1
13#ifndef _GEMA_BVHACCELERATION_H_
14#define _GEMA_BVHACCELERATION_H_
15
16// BVH includes
17#include <bvh.h>
18#include <vec.h>
19#include <ray.h>
20#include <node.h>
21#include <default_builder.h>
22#include <thread_pool.h>
23#include <stack.h>
24#include <tri.h>
25#include <seg.h>
27
28
29#include <vector>
30#include <gmValueAccessor.h>
31#include <gmSurfaceCellIntersection.h>
33
34class GmDiscontinuity;
35
37 double point[3];
38 double normal[3];
39 bool isExtension;
40 bool zeroSign;
41};
42
43
45{
46public:
47 //BVH aliases for double and 3D geometry
48 using Scalar = double;
49 using Vec3 = bvh::Vec<Scalar, 3>;
50 using BBox = bvh::BBox<Scalar, 3>;
51 using Tri = bvh::Tri<Scalar, 3>;
52 using Node = bvh::Node<Scalar, 3>;
53 using Bvh = bvh::Bvh<Node>;
54 using Ray = bvh::Ray<Scalar, 3>;
55 using PrecomputedTri = bvh::PrecomputedTri<Scalar>;
56
58
59private:
60
61 Bvh bvh;
62 int validTriIdEnd;
63 std::vector<PrecomputedTri> preTri;
64
65public:
66 /*
67 * Constructor for BVH acceleration structure
68 *
69 * triCoords - [x1, y1, z1, .., xn, yn, zn]
70 * triIndex - [ t1_v1, t1_v2, t1_v3, ..., tm_v1, tm_v2, tm_v3]
71 * numPoints - N
72 * numTriangles - M
73 * numValidTriangles - K <= M
74 * threadPool - default (inefficient)
75 */
76 GmBVHAcceleration(const double* triCoords, const int* triIndex, int numPoints, int numTriangles, int numValidTriangles, bvh::ThreadPool threadPool = bvh::ThreadPool());
77
78 /*
79 * Return true if the the segment given by 'start' and 'end'
80 * intersects any of the triangles and stores the intersection
81 * point at 'intersection' and if start, end sign test is zero.
82 */
83 std::tuple<size_t, size_t, bool, bool, bool> segIntersection(const double* start, const double* end, RayIntersection& ri, double repelTol = 0, double repelDistance = 0, double eps = 1e-5);
84
85
86 /*
87 * Used for globally consistency intersection when the sign test
88 * of a node is near zero.
89 *
90 * The solutio is to get all edges with that node and compute
91 * their sign once and consistently.
92 *
93 */
94 void zeroIntersection(const int zeroId, const size_t triId, const QVector<int>& nodeIds, const GmValueAccessor* coordAc, QVector<std::tuple<RayIntersection, int, bool>>& outIntersect, double repelTol = 0, double repelDistance = 0, double eps = 1e-5);
95
96private:
97
98 void computeLinePoint(Vec3 p0, Vec3 dir, double t, double* out);
99};
100
101
103public:
104 /*
105 * Checks if point src is visible from dst, in other words, if a
106 * the line connecting src-dst does not cross any discontinuity.
107 * The 'eps' parameter is used for testing how near any of the
108 * points is from the discontinuity. Anything lower than 'eps'
109 * is considered to lie on the discontinuity, and hence, is
110 * always visible for points in both sides.
111 *
112 */
113 virtual bool isVisibleInclusive(const double* src, const double* dst, double eps = 5e-3) const = 0;
114
115 /*
116 * Checks if point src is visible from dst, in other words, if a
117 * the line connecting src-dst does not cross any discontinuity.
118 * The 'eps' parameter is used for testing how near any of the
119 * points is from the discontinuity. Anything lower than 'eps'
120 * is considered to lie on the discontinuity, and hence, is
121 * always NOT visible for points in both sides.
122 *
123 * IMPORTANT:
124 * Test for 'near' is done only at the 'dst'. Correctly setting
125 * the source (reference) and destine point is a must.
126 */
127 virtual bool isVisibleExclusive(const double* src, const double* dst, double eps = 5e-3) const = 0;
128 virtual ~GmBVHVisibility() {}
129};
130
132{
133public:
134 //BVH aliases for double and 3D geometry
135 using Scalar = double;
136 using Vec3 = bvh::Vec<Scalar, 3>;
137 using BBox = bvh::BBox<Scalar, 3>;
138 using Tri = bvh::Tri<Scalar, 3>;
139 using Node = bvh::Node<Scalar, 3>;
140 using Bvh = bvh::Bvh<Node>;
141 using Ray = bvh::Ray<Scalar, 3>;
142 using PrecomputedTri = bvh::PrecomputedTri<Scalar>;
143
145
146private:
147
148 Bvh bvh;
149 std::vector<PrecomputedTri> preTri;
150
151public:
152 GmBVHVisibility3D(const QMap<int, Gm3DSurfaceCellIntersection>& cellMap, const QVector<GmVector3>& points, bvh::ThreadPool threadPool = bvh::ThreadPool());
153 GmBVHVisibility3D(const QVector<GmDiscontinuity*>& data, bvh::ThreadPool threadPool = bvh::ThreadPool());
154
155
156 bool isVisibleInclusive(const double* src, const double* dst, double eps) const final {
157 return isVisible<true>(src, dst, eps);
158 }
159
160 bool isVisibleExclusive(const double* src, const double* dst, double eps) const final {
161 return isVisible<false>(src, dst, eps);
162 }
163
164private:
165 template<bool inclusive>
166 bool isVisible(const double* src, const double* dst, double eps) const;
167};
168
169
171{
172public:
173 //BVH aliases for double and 2D geometry
174 using Scalar = double;
175 using Vec2 = bvh::Vec<Scalar, 2>;
176 using BBox = bvh::BBox<Scalar, 2>;
177 using Seg = bvh::Seg<Scalar, 2>;
178 using Node = bvh::Node<Scalar,2>;
179 using Bvh = bvh::Bvh<Node>;
180 using Ray = bvh::Ray<Scalar, 2>;
181 using PrecomputedSeg = bvh::PrecomputedSeg<Scalar>;
182
184
185private:
186
187 Bvh bvh;
188 std::vector<PrecomputedSeg> preSeg;
189
190public:
191 //Using the same def as GmDiscontinuitySet::SegmentCell2DIntersectionList
192 //to avoid the need of including GmDiscontinuitySet
194 GmBVHVisibility2D(const QMap<int, Gm2DSegmentCellIntersection>& cellMap, bvh::ThreadPool threadPool = bvh::ThreadPool());
195 GmBVHVisibility2D(const QVector<GmDiscontinuity*>& data, bvh::ThreadPool threadPool = bvh::ThreadPool());
196
197 bool isVisibleInclusive(const double* src, const double* dst, double eps) const final {
198 return isVisible<true>(src, dst, eps);
199 }
200
201 bool isVisibleExclusive(const double* src, const double* dst, double eps) const final {
202 return isVisible<false>(src, dst, eps);
203 }
204
205private:
206 template<bool inclusive>
207 bool isVisible(const double* src, const double* dst, double eps) const;
208};
209#endif
Definition gmBVHAcceleration.h:45
Definition gmBVHAcceleration.h:171
Definition gmBVHAcceleration.h:132
Definition gmBVHAcceleration.h:102
The geometric representation for a single discontinuity from the Discontinuity set....
Definition gmDiscontinuity.h:38
Interface class for accessing and setting values from an "indexable" collection of values.
Definition gmValueAccessor.h:60
Declaration of the GmSegmentCellIntersection class & friends.
Declaration of the GmValueAccessor interface and GmValueAccessorBase class.
Definition gmBVHAcceleration.h:36