f751596e |
1 | // Created on: 2015-03-16 |
2 | // Created by: Varvara POSKONINA |
3 | // Copyright (c) 2005-2014 OPEN CASCADE SAS |
4 | // |
5 | // This file is part of Open CASCADE Technology software library. |
6 | // |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
12 | // |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
15 | |
16 | #include <NCollection_Vector.hxx> |
17 | #include <Poly_Array1OfTriangle.hxx> |
2157d6ac |
18 | #include <Standard_Assert.hxx> |
f751596e |
19 | |
f751596e |
20 | // ======================================================================= |
21 | // function : isSeparated |
22 | // purpose : Checks if AABB and frustum are separated along the given axis. |
23 | // ======================================================================= |
24 | template <int N> |
25 | Standard_Boolean SelectMgr_Frustum<N>::isSeparated (const SelectMgr_Vec3& theBoxMin, |
26 | const SelectMgr_Vec3& theBoxMax, |
3bf9a45f |
27 | const gp_XYZ& theDirect, |
2157d6ac |
28 | Standard_Boolean* theInside) const |
f751596e |
29 | { |
2157d6ac |
30 | const Standard_Real aMinB = |
3bf9a45f |
31 | theDirect.X() * (theDirect.X() < 0.0 ? theBoxMax.x() : theBoxMin.x()) + |
32 | theDirect.Y() * (theDirect.Y() < 0.0 ? theBoxMax.y() : theBoxMin.y()) + |
33 | theDirect.Z() * (theDirect.Z() < 0.0 ? theBoxMax.z() : theBoxMin.z()); |
f751596e |
34 | |
2157d6ac |
35 | const Standard_Real aMaxB = |
3bf9a45f |
36 | theDirect.X() * (theDirect.X() < 0.0 ? theBoxMin.x() : theBoxMax.x()) + |
37 | theDirect.Y() * (theDirect.Y() < 0.0 ? theBoxMin.y() : theBoxMax.y()) + |
38 | theDirect.Z() * (theDirect.Z() < 0.0 ? theBoxMin.z() : theBoxMax.z()); |
f751596e |
39 | |
2157d6ac |
40 | Standard_ASSERT_RAISE (aMaxB >= aMinB, "Error! Failed to project box"); |
f751596e |
41 | |
2157d6ac |
42 | // frustum projection |
43 | Standard_Real aMinF = DBL_MAX; |
44 | Standard_Real aMaxF = -DBL_MAX; |
f751596e |
45 | |
46 | for (Standard_Integer aVertIdx = 0; aVertIdx < N * 2; ++aVertIdx) |
47 | { |
3bf9a45f |
48 | const Standard_Real aProj = myVertices[aVertIdx].XYZ().Dot (theDirect); |
f751596e |
49 | |
50 | aMinF = Min (aMinF, aProj); |
51 | aMaxF = Max (aMaxF, aProj); |
52 | |
53 | if (aMinF <= aMaxB && aMaxF >= aMinB) |
54 | { |
2157d6ac |
55 | if (theInside == NULL || !(*theInside)) // only overlap test |
56 | { |
57 | return Standard_False; |
58 | } |
f751596e |
59 | } |
60 | } |
61 | |
2157d6ac |
62 | if (aMinF > aMaxB || aMaxF < aMinB) |
63 | { |
64 | return Standard_True; // fully separated |
65 | } |
66 | else if (theInside != NULL) // to check for inclusion? |
67 | { |
68 | *theInside &= aMinB >= aMinF && aMaxB <= aMaxF; |
69 | } |
70 | |
71 | return Standard_False; |
f751596e |
72 | } |
73 | |
74 | // ======================================================================= |
75 | // function : isSeparated |
76 | // purpose : Checks if triangle and frustum are separated along the |
77 | // given axis |
78 | // ======================================================================= |
79 | template <int N> |
80 | Standard_Boolean SelectMgr_Frustum<N>::isSeparated (const gp_Pnt& thePnt1, |
81 | const gp_Pnt& thePnt2, |
82 | const gp_Pnt& thePnt3, |
3bf9a45f |
83 | const gp_XYZ& theAxis) const |
f751596e |
84 | { |
85 | // frustum projection |
86 | Standard_Real aMinF = RealLast(); |
87 | Standard_Real aMaxF = RealFirst(); |
88 | |
89 | // triangle projection |
90 | Standard_Real aMinTr = RealLast(); |
91 | Standard_Real aMaxTr = RealFirst(); |
92 | |
93 | Standard_Real aTriangleProj; |
94 | |
3bf9a45f |
95 | aTriangleProj = theAxis.Dot (thePnt1.XYZ()); |
f751596e |
96 | aMinTr = Min (aMinTr, aTriangleProj); |
97 | aMaxTr = Max (aMaxTr, aTriangleProj); |
98 | |
3bf9a45f |
99 | aTriangleProj = theAxis.Dot (thePnt2.XYZ()); |
f751596e |
100 | aMinTr = Min (aMinTr, aTriangleProj); |
101 | aMaxTr = Max (aMaxTr, aTriangleProj); |
102 | |
3bf9a45f |
103 | aTriangleProj = theAxis.Dot (thePnt3.XYZ()); |
f751596e |
104 | aMinTr = Min (aMinTr, aTriangleProj); |
105 | aMaxTr = Max (aMaxTr, aTriangleProj); |
106 | |
107 | for (Standard_Integer aVertIter = 0; aVertIter < N * 2; ++aVertIter) |
108 | { |
3bf9a45f |
109 | const Standard_Real aProj = myVertices[aVertIter].XYZ().Dot (theAxis); |
f751596e |
110 | |
111 | aMinF = Min (aMinF, aProj); |
112 | aMaxF = Max (aMaxF, aProj); |
113 | |
114 | if (aMinF <= aMaxTr && aMaxF >= aMinTr) |
115 | { |
116 | return Standard_False; |
117 | } |
118 | } |
119 | |
120 | return aMinF > aMaxTr || aMaxF < aMinTr; |
121 | } |
122 | |
123 | // ======================================================================= |
124 | // function : hasOverlap |
125 | // purpose : Returns true if selecting volume is overlapped by |
126 | // axis-aligned bounding box with minimum corner at point |
127 | // theMinPnt and maximum at point theMaxPnt |
128 | // ======================================================================= |
129 | template <int N> |
7ab15952 |
130 | Standard_Boolean SelectMgr_Frustum<N>::hasOverlap (const SelectMgr_Vec3& theMinPnt, |
2157d6ac |
131 | const SelectMgr_Vec3& theMaxPnt, |
4a056d20 |
132 | Standard_Boolean* theInside) const |
f751596e |
133 | { |
2157d6ac |
134 | for (Standard_Integer anAxis = 0; anAxis < 3; ++anAxis) |
f751596e |
135 | { |
2157d6ac |
136 | if (theMinPnt[anAxis] > myMaxOrthoVertsProjections[anAxis] |
137 | || theMaxPnt[anAxis] < myMinOrthoVertsProjections[anAxis]) |
138 | { |
139 | return Standard_False; // fully separated |
140 | } |
141 | else if (theInside != NULL) // to check for inclusion? |
142 | { |
143 | *theInside &= theMinPnt[anAxis] >= myMinOrthoVertsProjections[anAxis] |
144 | && theMaxPnt[anAxis] <= myMaxOrthoVertsProjections[anAxis]; |
145 | } |
f751596e |
146 | } |
147 | |
148 | const Standard_Integer anIncFactor = (myIsOrthographic && N == 4) ? 2 : 1; |
2157d6ac |
149 | |
f751596e |
150 | for (Standard_Integer aPlaneIdx = 0; aPlaneIdx < N + 1; aPlaneIdx += anIncFactor) |
151 | { |
3bf9a45f |
152 | const gp_XYZ& aPlane = myPlanes[aPlaneIdx].XYZ(); |
f751596e |
153 | |
2157d6ac |
154 | const Standard_Real aBoxProjMin = |
3bf9a45f |
155 | aPlane.X() * (aPlane.X() < 0.f ? theMaxPnt.x() : theMinPnt.x()) + |
156 | aPlane.Y() * (aPlane.Y() < 0.f ? theMaxPnt.y() : theMinPnt.y()) + |
157 | aPlane.Z() * (aPlane.Z() < 0.f ? theMaxPnt.z() : theMinPnt.z()); |
f751596e |
158 | |
2157d6ac |
159 | const Standard_Real aBoxProjMax = |
3bf9a45f |
160 | aPlane.X() * (aPlane.X() < 0.f ? theMinPnt.x() : theMaxPnt.x()) + |
161 | aPlane.Y() * (aPlane.Y() < 0.f ? theMinPnt.y() : theMaxPnt.y()) + |
162 | aPlane.Z() * (aPlane.Z() < 0.f ? theMinPnt.z() : theMaxPnt.z()); |
f751596e |
163 | |
2157d6ac |
164 | Standard_ASSERT_RAISE (aBoxProjMax >= aBoxProjMin, "Error! Failed to project box"); |
f751596e |
165 | |
2157d6ac |
166 | if (aBoxProjMin > myMaxVertsProjections[aPlaneIdx] |
167 | || aBoxProjMax < myMinVertsProjections[aPlaneIdx]) |
f751596e |
168 | { |
2157d6ac |
169 | return Standard_False; // fully separated |
170 | } |
171 | else if (theInside != NULL) // to check for inclusion? |
172 | { |
173 | *theInside &= aBoxProjMin >= myMinVertsProjections[aPlaneIdx] |
174 | && aBoxProjMax <= myMaxVertsProjections[aPlaneIdx]; |
f751596e |
175 | } |
176 | } |
177 | |
f751596e |
178 | for (Standard_Integer aDim = 0; aDim < 3; ++aDim) |
179 | { |
3bf9a45f |
180 | // the following code performs a speedup of cross-product |
181 | // of vector with 1.0 at the position aDim and myEdgeDirs[aVolDir] |
182 | const Standard_Integer aNext = (aDim + 1) % 3; |
183 | const Standard_Integer aNextNext = (aDim + 2) % 3; |
2157d6ac |
184 | for (Standard_Integer aVolDir = 0, aDirectionsNb = myIsOrthographic ? 4 : 6; aVolDir < aDirectionsNb; ++aVolDir) |
f751596e |
185 | { |
3bf9a45f |
186 | gp_XYZ aDirection (DBL_MAX, DBL_MAX, DBL_MAX); |
187 | aDirection.ChangeData()[aDim] = 0; |
188 | aDirection.ChangeData()[aNext] = -myEdgeDirs[aVolDir].XYZ().GetData()[aNextNext]; |
189 | aDirection.ChangeData()[aNextNext] = myEdgeDirs[aVolDir].XYZ().GetData()[aNext]; |
f751596e |
190 | |
2157d6ac |
191 | if (isSeparated (theMinPnt, theMaxPnt, aDirection, theInside)) |
f751596e |
192 | { |
193 | return Standard_False; |
194 | } |
195 | } |
196 | } |
197 | |
198 | return Standard_True; |
199 | } |
200 | |
201 | // ======================================================================= |
202 | // function : hasOverlap |
203 | // purpose : SAT intersection test between defined volume and given point |
204 | // ======================================================================= |
205 | template <int N> |
4a056d20 |
206 | Standard_Boolean SelectMgr_Frustum<N>::hasOverlap (const gp_Pnt& thePnt) const |
f751596e |
207 | { |
f751596e |
208 | const Standard_Integer anIncFactor = (myIsOrthographic && N == 4) ? 2 : 1; |
2157d6ac |
209 | |
f751596e |
210 | for (Standard_Integer aPlaneIdx = 0; aPlaneIdx < N + 1; aPlaneIdx += anIncFactor) |
211 | { |
3bf9a45f |
212 | const Standard_Real aPointProj = myPlanes[aPlaneIdx].XYZ().Dot (thePnt.XYZ()); |
f751596e |
213 | |
2157d6ac |
214 | if (aPointProj > myMaxVertsProjections[aPlaneIdx] |
215 | || aPointProj < myMinVertsProjections[aPlaneIdx]) |
f751596e |
216 | { |
217 | return Standard_False; |
218 | } |
219 | } |
220 | |
221 | return Standard_True; |
222 | } |
223 | |
224 | // ======================================================================= |
225 | // function : hasOverlap |
226 | // purpose : SAT intersection test between defined volume and given segment |
227 | // ======================================================================= |
228 | template <int N> |
7ab15952 |
229 | Standard_Boolean SelectMgr_Frustum<N>::hasOverlap (const gp_Pnt& theStartPnt, |
4a056d20 |
230 | const gp_Pnt& theEndPnt) const |
f751596e |
231 | { |
3bf9a45f |
232 | const gp_XYZ& aDir = theEndPnt.XYZ() - theStartPnt.XYZ(); |
233 | if (aDir.Modulus() < Precision::Confusion()) |
f751596e |
234 | return Standard_True; |
235 | |
236 | const Standard_Integer anIncFactor = (myIsOrthographic && N == 4) ? 2 : 1; |
237 | for (Standard_Integer aPlaneIdx = 0; aPlaneIdx < N + 1; aPlaneIdx += anIncFactor) |
238 | { |
239 | Standard_Real aMinSegm = RealLast(), aMaxSegm = RealFirst(); |
240 | Standard_Real aMinF = RealLast(), aMaxF = RealFirst(); |
f751596e |
241 | |
3bf9a45f |
242 | Standard_Real aProj1 = myPlanes[aPlaneIdx].XYZ().Dot (theStartPnt.XYZ()); |
243 | Standard_Real aProj2 = myPlanes[aPlaneIdx].XYZ().Dot (theEndPnt.XYZ()); |
f751596e |
244 | aMinSegm = Min (aProj1, aProj2); |
245 | aMaxSegm = Max (aProj1, aProj2); |
246 | |
247 | aMaxF = myMaxVertsProjections[aPlaneIdx]; |
248 | aMinF = myMinVertsProjections[aPlaneIdx]; |
249 | |
250 | if (aMinSegm > aMaxF |
251 | || aMaxSegm < aMinF) |
252 | { |
253 | return Standard_False; |
254 | } |
255 | } |
256 | |
257 | Standard_Real aMin1 = DBL_MAX, aMax1 = -DBL_MAX; |
258 | Standard_Real aMin2 = DBL_MAX, aMax2 = -DBL_MAX; |
259 | for (Standard_Integer aVertIdx = 0; aVertIdx < N * 2; ++aVertIdx) |
260 | { |
3bf9a45f |
261 | Standard_Real aProjection = aDir.Dot (myVertices[aVertIdx].XYZ()); |
f751596e |
262 | aMax2 = Max (aMax2, aProjection); |
263 | aMin2 = Min (aMin2, aProjection); |
264 | } |
3bf9a45f |
265 | Standard_Real aProj1 = aDir.Dot (theStartPnt.XYZ()); |
266 | Standard_Real aProj2 = aDir.Dot (theEndPnt.XYZ()); |
f751596e |
267 | aMin1 = Min (aProj1, aProj2); |
268 | aMax1 = Max (aProj1, aProj2); |
269 | if (aMin1 > aMax2 |
270 | || aMax1 < aMin2) |
271 | { |
272 | return Standard_False; |
273 | } |
274 | |
275 | Standard_Integer aDirectionsNb = myIsOrthographic ? 4 : 6; |
276 | for (Standard_Integer aEdgeDirIdx = 0; aEdgeDirIdx < aDirectionsNb; ++aEdgeDirIdx) |
277 | { |
278 | Standard_Real aMinSegm = DBL_MAX, aMaxSegm = -DBL_MAX; |
279 | Standard_Real aMinF = DBL_MAX, aMaxF = -DBL_MAX; |
280 | |
3bf9a45f |
281 | const gp_XYZ aTestDir = aDir.Crossed (myEdgeDirs[aEdgeDirIdx].XYZ()); |
f751596e |
282 | |
3bf9a45f |
283 | Standard_Real Proj1 = aTestDir.Dot (theStartPnt.XYZ()); |
284 | Standard_Real Proj2 = aTestDir.Dot (theEndPnt.XYZ()); |
f751596e |
285 | aMinSegm = Min (Proj1, Proj2); |
286 | aMaxSegm = Max (Proj1, Proj2); |
287 | |
288 | for (Standard_Integer aVertIdx = 0; aVertIdx < N * 2; ++aVertIdx) |
289 | { |
3bf9a45f |
290 | Standard_Real aProjection = aTestDir.Dot (myVertices[aVertIdx].XYZ()); |
f751596e |
291 | aMaxF = Max (aMaxF, aProjection); |
292 | aMinF = Min (aMinF, aProjection); |
293 | } |
294 | |
295 | if (aMinSegm > aMaxF |
296 | || aMaxSegm < aMinF) |
297 | { |
298 | return Standard_False; |
299 | } |
300 | } |
301 | |
302 | return Standard_True; |
303 | } |
304 | |
305 | // ======================================================================= |
306 | // function : hasOverlap |
307 | // purpose : SAT intersection test between frustum given and planar convex |
308 | // polygon represented as ordered point set |
309 | // ======================================================================= |
310 | template <int N> |
114b7bf1 |
311 | Standard_Boolean SelectMgr_Frustum<N>::hasOverlap (const TColgp_Array1OfPnt& theArrayOfPnts, |
4a056d20 |
312 | gp_Vec& theNormal) const |
f751596e |
313 | { |
114b7bf1 |
314 | Standard_Integer aStartIdx = theArrayOfPnts.Lower(); |
315 | Standard_Integer anEndIdx = theArrayOfPnts.Upper(); |
f751596e |
316 | |
114b7bf1 |
317 | const gp_XYZ& aPnt1 = theArrayOfPnts.Value (aStartIdx).XYZ(); |
318 | const gp_XYZ& aPnt2 = theArrayOfPnts.Value (aStartIdx + 1).XYZ(); |
319 | const gp_XYZ& aPnt3 = theArrayOfPnts.Value (aStartIdx + 2).XYZ(); |
3bf9a45f |
320 | const gp_XYZ aVec1 = aPnt1 - aPnt2; |
321 | const gp_XYZ aVec2 = aPnt3 - aPnt2; |
322 | theNormal = aVec2.Crossed (aVec1); |
323 | const gp_XYZ& aNormal = theNormal.XYZ(); |
324 | Standard_Real aPolygProjection = aNormal.Dot (aPnt1); |
f751596e |
325 | |
326 | Standard_Real aMax = RealFirst(); |
327 | Standard_Real aMin = RealLast(); |
328 | for (Standard_Integer aVertIdx = 0; aVertIdx < N * 2; ++aVertIdx) |
329 | { |
3bf9a45f |
330 | Standard_Real aProjection = aNormal.Dot (myVertices[aVertIdx].XYZ()); |
f751596e |
331 | aMax = Max (aMax, aProjection); |
332 | aMin = Min (aMin, aProjection); |
333 | } |
334 | if (aPolygProjection > aMax |
335 | || aPolygProjection < aMin) |
336 | { |
337 | return Standard_False; |
338 | } |
339 | |
3bf9a45f |
340 | const Standard_Integer anIncFactor = (myIsOrthographic && N == 4) ? 2 : 1; |
341 | for (Standard_Integer aPlaneIdx = 0; aPlaneIdx < N + 1; aPlaneIdx += anIncFactor) |
f751596e |
342 | { |
343 | Standard_Real aMaxF = RealFirst(); |
344 | Standard_Real aMinF = RealLast(); |
345 | Standard_Real aMaxPolyg = RealFirst(); |
346 | Standard_Real aMinPolyg = RealLast(); |
3bf9a45f |
347 | const gp_XYZ& aPlane = myPlanes[aPlaneIdx].XYZ(); |
f751596e |
348 | for (Standard_Integer aPntIter = aStartIdx; aPntIter <= anEndIdx; ++aPntIter) |
349 | { |
114b7bf1 |
350 | Standard_Real aProjection = aPlane.Dot (theArrayOfPnts.Value (aPntIter).XYZ()); |
f751596e |
351 | aMaxPolyg = Max (aMaxPolyg, aProjection); |
352 | aMinPolyg = Min (aMinPolyg, aProjection); |
353 | } |
354 | aMaxF = myMaxVertsProjections[aPlaneIdx]; |
355 | aMinF = myMinVertsProjections[aPlaneIdx]; |
356 | if (aMinPolyg > aMaxF |
357 | || aMaxPolyg < aMinF) |
358 | { |
359 | return Standard_False; |
360 | } |
361 | } |
362 | |
363 | Standard_Integer aDirectionsNb = myIsOrthographic ? 4 : 6; |
114b7bf1 |
364 | for (Standard_Integer aPntsIter = 0, aLastIdx = anEndIdx - aStartIdx, aLen = theArrayOfPnts.Length(); aPntsIter <= aLastIdx; ++aPntsIter) |
f751596e |
365 | { |
114b7bf1 |
366 | const gp_XYZ aSegmDir = theArrayOfPnts.Value ((aPntsIter + 1) % aLen + aStartIdx).XYZ() |
367 | - theArrayOfPnts.Value (aPntsIter + aStartIdx).XYZ(); |
f751596e |
368 | for (Standard_Integer aVolDir = 0; aVolDir < aDirectionsNb; ++aVolDir) |
369 | { |
370 | Standard_Real aMaxPolyg = RealFirst(); |
371 | Standard_Real aMinPolyg = RealLast(); |
372 | Standard_Real aMaxF = RealFirst(); |
373 | Standard_Real aMinF = RealLast(); |
3bf9a45f |
374 | const gp_XYZ aTestDir = aSegmDir.Crossed (myEdgeDirs[aVolDir].XYZ()); |
f751596e |
375 | |
376 | for (Standard_Integer aPntIter = aStartIdx; aPntIter <= anEndIdx; ++aPntIter) |
377 | { |
114b7bf1 |
378 | Standard_Real aProjection = aTestDir.Dot (theArrayOfPnts.Value (aPntIter).XYZ()); |
f751596e |
379 | aMaxPolyg = Max (aMaxPolyg, aProjection); |
380 | aMinPolyg = Min (aMinPolyg, aProjection); |
381 | } |
382 | |
383 | for (Standard_Integer aVertIdx = 0; aVertIdx < N * 2; ++aVertIdx) |
384 | { |
3bf9a45f |
385 | Standard_Real aProjection = aTestDir.Dot (myVertices[aVertIdx].XYZ()); |
f751596e |
386 | aMaxF = Max (aMaxF, aProjection); |
387 | aMinF = Min (aMinF, aProjection); |
388 | } |
389 | |
390 | if (aMinPolyg > aMaxF |
391 | || aMaxPolyg < aMinF) |
392 | { |
393 | return Standard_False; |
394 | } |
395 | } |
396 | } |
397 | |
398 | return Standard_True; |
399 | } |
400 | |
401 | // ======================================================================= |
402 | // function : hasOverlap |
403 | // purpose : SAT intersection test between defined volume and given triangle |
404 | // ======================================================================= |
405 | template <int N> |
7ab15952 |
406 | Standard_Boolean SelectMgr_Frustum<N>::hasOverlap (const gp_Pnt& thePnt1, |
407 | const gp_Pnt& thePnt2, |
408 | const gp_Pnt& thePnt3, |
4a056d20 |
409 | gp_Vec& theNormal) const |
f751596e |
410 | { |
3bf9a45f |
411 | const gp_XYZ aTrEdges[3] = { thePnt2.XYZ() - thePnt1.XYZ(), |
412 | thePnt3.XYZ() - thePnt2.XYZ(), |
413 | thePnt1.XYZ() - thePnt3.XYZ() }; |
f751596e |
414 | |
415 | const Standard_Integer anIncFactor = (myIsOrthographic && N == 4) ? 2 : 1; |
416 | for (Standard_Integer aPlaneIdx = 0; aPlaneIdx < N + 1; aPlaneIdx += anIncFactor) |
417 | { |
3bf9a45f |
418 | const gp_XYZ& aPlane = myPlanes[aPlaneIdx].XYZ(); |
f751596e |
419 | Standard_Real aTriangleProj; |
420 | |
3bf9a45f |
421 | aTriangleProj = aPlane.Dot (thePnt1.XYZ()); |
f751596e |
422 | Standard_Real aTriangleProjMin = aTriangleProj; |
423 | Standard_Real aTriangleProjMax = aTriangleProj; |
424 | |
3bf9a45f |
425 | aTriangleProj = aPlane.Dot (thePnt2.XYZ()); |
f751596e |
426 | aTriangleProjMin = Min (aTriangleProjMin, aTriangleProj); |
427 | aTriangleProjMax = Max (aTriangleProjMax, aTriangleProj); |
428 | |
3bf9a45f |
429 | aTriangleProj = aPlane.Dot (thePnt3.XYZ()); |
f751596e |
430 | aTriangleProjMin = Min (aTriangleProjMin, aTriangleProj); |
431 | aTriangleProjMax = Max (aTriangleProjMax, aTriangleProj); |
432 | |
433 | Standard_Real aFrustumProjMax = myMaxVertsProjections[aPlaneIdx]; |
434 | Standard_Real aFrustumProjMin = myMinVertsProjections[aPlaneIdx]; |
435 | if (aTriangleProjMin > aFrustumProjMax |
436 | || aTriangleProjMax < aFrustumProjMin) |
437 | { |
438 | return Standard_False; |
439 | } |
440 | } |
441 | |
3bf9a45f |
442 | theNormal = aTrEdges[2].Crossed (aTrEdges[0]); |
443 | if (isSeparated (thePnt1, thePnt2, thePnt3, theNormal.XYZ())) |
f751596e |
444 | { |
445 | return Standard_False; |
446 | } |
447 | |
448 | Standard_Integer aDirectionsNb = myIsOrthographic ? 4 : 6; |
449 | for (Standard_Integer aTriangleEdgeIdx = 0; aTriangleEdgeIdx < 3; ++aTriangleEdgeIdx) |
450 | { |
451 | for (Standard_Integer aVolDir = 0; aVolDir < aDirectionsNb; ++aVolDir) |
452 | { |
3bf9a45f |
453 | const gp_XYZ& aTestDirection = myEdgeDirs[aVolDir].XYZ().Crossed (aTrEdges[aTriangleEdgeIdx]); |
f751596e |
454 | |
455 | if (isSeparated (thePnt1, thePnt2, thePnt3, aTestDirection)) |
456 | { |
457 | return Standard_False; |
458 | } |
459 | } |
460 | } |
461 | |
462 | return Standard_True; |
463 | } |
a5162275 |
464 | |
465 | //======================================================================= |
466 | //function : DumpJson |
467 | //purpose : |
468 | //======================================================================= |
469 | template <int N> |
470 | void SelectMgr_Frustum<N>::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const |
471 | { |
472 | OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream) |
473 | |
474 | const Standard_Integer anIncFactor = (myIsOrthographic && N == 4) ? 2 : 1; |
475 | for (Standard_Integer aPlaneIdx = 0; aPlaneIdx < N + 1; aPlaneIdx += anIncFactor) |
476 | { |
477 | const gp_Vec& aPlane = myPlanes[aPlaneIdx]; |
478 | OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &aPlane) |
479 | |
480 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myMaxVertsProjections[aPlaneIdx]) |
481 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myMinVertsProjections[aPlaneIdx]) |
482 | } |
483 | |
484 | for (Standard_Integer aVertIdx = 0; aVertIdx < N * 2; ++aVertIdx) |
485 | { |
486 | const gp_Pnt& aVertex = myVertices[aVertIdx]; |
487 | OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &aVertex) |
488 | } |
489 | |
490 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myPixelTolerance) |
491 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsOrthographic) |
492 | OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myBuilder) |
493 | OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myCamera) |
494 | |
495 | for (Standard_Integer anIndex = 0; anIndex < 3; anIndex++) |
496 | { |
497 | Standard_Real aMaxOrthoVertsProjections = myMaxOrthoVertsProjections[anIndex]; |
498 | Standard_Real aMinOrthoVertsProjections = myMinOrthoVertsProjections[anIndex]; |
499 | |
500 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, aMaxOrthoVertsProjections) |
501 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, aMinOrthoVertsProjections) |
502 | } |
503 | |
504 | for (Standard_Integer anIndex = 0; anIndex < 6; anIndex++) |
505 | { |
506 | const gp_Vec& anEdgeDir = myEdgeDirs[anIndex]; |
507 | OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &anEdgeDir) |
508 | } |
509 | } |