This file is indexed.

/usr/include/oce/SelectMgr_Frustum.lxx is in liboce-visualization-dev 0.18.2-2build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
// Created on: 2015-03-16
// Created by: Varvara POSKONINA
// Copyright (c) 2005-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.

#include <NCollection_Vector.hxx>
#include <Poly_Array1OfTriangle.hxx>
#include <Standard_Assert.hxx>

// =======================================================================
// function : isSeparated
// purpose  : Checks if AABB and frustum are separated along the given axis.
// =======================================================================
template <int N>
Standard_Boolean SelectMgr_Frustum<N>::isSeparated (const SelectMgr_Vec3& theBoxMin,
                                                    const SelectMgr_Vec3& theBoxMax,
                                                    const gp_XYZ&         theDirect,
                                                    Standard_Boolean*     theInside) const
{
  const Standard_Real aMinB =
    theDirect.X() * (theDirect.X() < 0.0 ? theBoxMax.x() : theBoxMin.x()) +
    theDirect.Y() * (theDirect.Y() < 0.0 ? theBoxMax.y() : theBoxMin.y()) +
    theDirect.Z() * (theDirect.Z() < 0.0 ? theBoxMax.z() : theBoxMin.z());

  const Standard_Real aMaxB =
    theDirect.X() * (theDirect.X() < 0.0 ? theBoxMin.x() : theBoxMax.x()) +
    theDirect.Y() * (theDirect.Y() < 0.0 ? theBoxMin.y() : theBoxMax.y()) +
    theDirect.Z() * (theDirect.Z() < 0.0 ? theBoxMin.z() : theBoxMax.z());

  Standard_ASSERT_RAISE (aMaxB >= aMinB, "Error! Failed to project box");

  // frustum projection
  Standard_Real aMinF =  DBL_MAX;
  Standard_Real aMaxF = -DBL_MAX;

  for (Standard_Integer aVertIdx = 0; aVertIdx < N * 2; ++aVertIdx)
  {
    const Standard_Real aProj = myVertices[aVertIdx].XYZ().Dot (theDirect);

    aMinF = Min (aMinF, aProj);
    aMaxF = Max (aMaxF, aProj);

    if (aMinF <= aMaxB && aMaxF >= aMinB)
    {
      if (theInside == NULL || !(*theInside)) // only overlap test
      {
        return Standard_False;
      }
    }
  }

  if (aMinF > aMaxB || aMaxF < aMinB)
  {
    return Standard_True; // fully separated
  }
  else if (theInside != NULL) // to check for inclusion?
  {
    *theInside &= aMinB >= aMinF && aMaxB <= aMaxF;
  }

  return Standard_False;
}

// =======================================================================
// function : isSeparated
// purpose  : Checks if triangle and frustum are separated along the
//            given axis
// =======================================================================
template <int N>
Standard_Boolean SelectMgr_Frustum<N>::isSeparated (const gp_Pnt& thePnt1,
                                                    const gp_Pnt& thePnt2,
                                                    const gp_Pnt& thePnt3,
                                                    const gp_XYZ& theAxis) const
{
  // frustum projection
  Standard_Real aMinF = RealLast();
  Standard_Real aMaxF = RealFirst();

  // triangle projection
  Standard_Real aMinTr = RealLast();
  Standard_Real aMaxTr = RealFirst();

  Standard_Real aTriangleProj;

  aTriangleProj = theAxis.Dot (thePnt1.XYZ());
  aMinTr = Min (aMinTr, aTriangleProj);
  aMaxTr = Max (aMaxTr, aTriangleProj);

  aTriangleProj = theAxis.Dot (thePnt2.XYZ());
  aMinTr = Min (aMinTr, aTriangleProj);
  aMaxTr = Max (aMaxTr, aTriangleProj);

  aTriangleProj = theAxis.Dot (thePnt3.XYZ());
  aMinTr = Min (aMinTr, aTriangleProj);
  aMaxTr = Max (aMaxTr, aTriangleProj);

  for (Standard_Integer aVertIter = 0; aVertIter < N * 2; ++aVertIter)
  {
    const Standard_Real aProj = myVertices[aVertIter].XYZ().Dot (theAxis);

    aMinF = Min (aMinF, aProj);
    aMaxF = Max (aMaxF, aProj);

    if (aMinF <= aMaxTr && aMaxF >= aMinTr)
    {
      return Standard_False;
    }
  }

  return aMinF > aMaxTr || aMaxF < aMinTr;
}

// =======================================================================
// function : hasOverlap
// purpose  : Returns true if selecting volume is overlapped by
//            axis-aligned bounding box with minimum corner at point
//            theMinPnt and maximum at point theMaxPnt
// =======================================================================
template <int N>
Standard_Boolean SelectMgr_Frustum<N>::hasOverlap (const SelectMgr_Vec3& theMinPnt,
                                                   const SelectMgr_Vec3& theMaxPnt,
                                                   Standard_Boolean*     theInside)
{
  for (Standard_Integer anAxis = 0; anAxis < 3; ++anAxis)
  {
    if (theMinPnt[anAxis] > myMaxOrthoVertsProjections[anAxis]
     || theMaxPnt[anAxis] < myMinOrthoVertsProjections[anAxis])
    {
      return Standard_False; // fully separated
    }
    else if (theInside != NULL) // to check for inclusion?
    {
      *theInside &= theMinPnt[anAxis] >= myMinOrthoVertsProjections[anAxis]
                 && theMaxPnt[anAxis] <= myMaxOrthoVertsProjections[anAxis];
    }
  }

  const Standard_Integer anIncFactor = (myIsOrthographic && N == 4) ? 2 : 1;

  for (Standard_Integer aPlaneIdx = 0; aPlaneIdx < N + 1; aPlaneIdx += anIncFactor)
  {
    const gp_XYZ& aPlane = myPlanes[aPlaneIdx].XYZ();

    const Standard_Real aBoxProjMin =
      aPlane.X() * (aPlane.X() < 0.f ? theMaxPnt.x() : theMinPnt.x()) +
      aPlane.Y() * (aPlane.Y() < 0.f ? theMaxPnt.y() : theMinPnt.y()) +
      aPlane.Z() * (aPlane.Z() < 0.f ? theMaxPnt.z() : theMinPnt.z());

    const Standard_Real aBoxProjMax =
      aPlane.X() * (aPlane.X() < 0.f ? theMinPnt.x() : theMaxPnt.x()) +
      aPlane.Y() * (aPlane.Y() < 0.f ? theMinPnt.y() : theMaxPnt.y()) +
      aPlane.Z() * (aPlane.Z() < 0.f ? theMinPnt.z() : theMaxPnt.z());

    Standard_ASSERT_RAISE (aBoxProjMax >= aBoxProjMin, "Error! Failed to project box");

    if (aBoxProjMin > myMaxVertsProjections[aPlaneIdx]
     || aBoxProjMax < myMinVertsProjections[aPlaneIdx])
    {
      return Standard_False; // fully separated
    }
    else if (theInside != NULL) // to check for inclusion?
    {
      *theInside &= aBoxProjMin >= myMinVertsProjections[aPlaneIdx]
                 && aBoxProjMax <= myMaxVertsProjections[aPlaneIdx];
    }
  }

  for (Standard_Integer aDim = 0; aDim < 3; ++aDim)
  {
    // the following code performs a speedup of cross-product
    // of vector with 1.0 at the position aDim and myEdgeDirs[aVolDir]
    const Standard_Integer aNext = (aDim + 1) % 3;
    const Standard_Integer aNextNext = (aDim + 2) % 3;
    for (Standard_Integer aVolDir = 0, aDirectionsNb = myIsOrthographic ? 4 : 6; aVolDir < aDirectionsNb; ++aVolDir)
    {
      gp_XYZ aDirection (DBL_MAX, DBL_MAX, DBL_MAX);
      aDirection.ChangeData()[aDim]      = 0;
      aDirection.ChangeData()[aNext]     = -myEdgeDirs[aVolDir].XYZ().GetData()[aNextNext];
      aDirection.ChangeData()[aNextNext] = myEdgeDirs[aVolDir].XYZ().GetData()[aNext];

      if (isSeparated (theMinPnt, theMaxPnt, aDirection, theInside))
      {
        return Standard_False;
      }
    }
  }

  return Standard_True;
}

// =======================================================================
// function : hasOverlap
// purpose  : SAT intersection test between defined volume and given point
// =======================================================================
template <int N>
Standard_Boolean SelectMgr_Frustum<N>::hasOverlap (const gp_Pnt& thePnt)
{
  const Standard_Integer anIncFactor = (myIsOrthographic && N == 4) ? 2 : 1;

  for (Standard_Integer aPlaneIdx = 0; aPlaneIdx < N + 1; aPlaneIdx += anIncFactor)
  {
    const Standard_Real aPointProj = myPlanes[aPlaneIdx].XYZ().Dot (thePnt.XYZ());

    if (aPointProj > myMaxVertsProjections[aPlaneIdx]
     || aPointProj < myMinVertsProjections[aPlaneIdx])
    {
      return Standard_False;
    }
  }

  return Standard_True;
}

// =======================================================================
// function : hasOverlap
// purpose  : SAT intersection test between defined volume and given segment
// =======================================================================
template <int N>
Standard_Boolean SelectMgr_Frustum<N>::hasOverlap (const gp_Pnt& theStartPnt,
                                                   const gp_Pnt& theEndPnt)
{
  const gp_XYZ& aDir = theEndPnt.XYZ() - theStartPnt.XYZ();
  if (aDir.Modulus() < Precision::Confusion())
    return Standard_True;

  const Standard_Integer anIncFactor = (myIsOrthographic && N == 4) ? 2 : 1;
  for (Standard_Integer aPlaneIdx = 0; aPlaneIdx < N + 1; aPlaneIdx += anIncFactor)
  {
    Standard_Real aMinSegm = RealLast(), aMaxSegm = RealFirst();
    Standard_Real aMinF    = RealLast(), aMaxF    = RealFirst();

    Standard_Real aProj1 = myPlanes[aPlaneIdx].XYZ().Dot (theStartPnt.XYZ());
    Standard_Real aProj2 = myPlanes[aPlaneIdx].XYZ().Dot (theEndPnt.XYZ());
    aMinSegm = Min (aProj1, aProj2);
    aMaxSegm = Max (aProj1, aProj2);

    aMaxF = myMaxVertsProjections[aPlaneIdx];
    aMinF = myMinVertsProjections[aPlaneIdx];

    if (aMinSegm > aMaxF
      || aMaxSegm < aMinF)
    {
      return Standard_False;
    }
  }

  Standard_Real aMin1 = DBL_MAX, aMax1 = -DBL_MAX;
  Standard_Real aMin2 = DBL_MAX, aMax2 = -DBL_MAX;
  for (Standard_Integer aVertIdx = 0; aVertIdx < N * 2; ++aVertIdx)
  {
    Standard_Real aProjection = aDir.Dot (myVertices[aVertIdx].XYZ());
    aMax2 = Max (aMax2, aProjection);
    aMin2 = Min (aMin2, aProjection);
  }
  Standard_Real aProj1 = aDir.Dot (theStartPnt.XYZ());
  Standard_Real aProj2 = aDir.Dot (theEndPnt.XYZ());
  aMin1 = Min (aProj1, aProj2);
  aMax1 = Max (aProj1, aProj2);
  if (aMin1 > aMax2
    || aMax1 < aMin2)
  {
    return Standard_False;
  }

  Standard_Integer aDirectionsNb = myIsOrthographic ? 4 : 6;
  for (Standard_Integer aEdgeDirIdx = 0; aEdgeDirIdx < aDirectionsNb; ++aEdgeDirIdx)
  {
    Standard_Real aMinSegm = DBL_MAX, aMaxSegm = -DBL_MAX;
    Standard_Real aMinF    = DBL_MAX, aMaxF    = -DBL_MAX;

    const gp_XYZ aTestDir = aDir.Crossed (myEdgeDirs[aEdgeDirIdx].XYZ());

    Standard_Real Proj1 = aTestDir.Dot (theStartPnt.XYZ());
    Standard_Real Proj2 = aTestDir.Dot (theEndPnt.XYZ());
    aMinSegm = Min (Proj1, Proj2);
    aMaxSegm = Max (Proj1, Proj2);

    for (Standard_Integer aVertIdx = 0; aVertIdx < N * 2; ++aVertIdx)
    {
      Standard_Real aProjection = aTestDir.Dot (myVertices[aVertIdx].XYZ());
      aMaxF = Max (aMaxF, aProjection);
      aMinF = Min (aMinF, aProjection);
    }

    if (aMinSegm > aMaxF
      || aMaxSegm < aMinF)
    {
      return Standard_False;
    }
  }

  return Standard_True;
}

// =======================================================================
// function : hasOverlap
// purpose  : SAT intersection test between frustum given and planar convex
//            polygon represented as ordered point set
// =======================================================================
template <int N>
Standard_Boolean SelectMgr_Frustum<N>::hasOverlap (const Handle(TColgp_HArray1OfPnt)& theArrayOfPnts,
                                                   gp_Vec& theNormal)
{
  Standard_Integer aStartIdx = theArrayOfPnts->Lower();
  Standard_Integer anEndIdx = theArrayOfPnts->Upper();

  const gp_XYZ& aPnt1 = theArrayOfPnts->Value (aStartIdx).XYZ();
  const gp_XYZ& aPnt2 = theArrayOfPnts->Value (aStartIdx + 1).XYZ();
  const gp_XYZ& aPnt3 = theArrayOfPnts->Value (aStartIdx + 2).XYZ();
  const gp_XYZ aVec1 = aPnt1 - aPnt2;
  const gp_XYZ aVec2 = aPnt3 - aPnt2;
  theNormal = aVec2.Crossed (aVec1);
  const gp_XYZ& aNormal = theNormal.XYZ();
  Standard_Real aPolygProjection = aNormal.Dot (aPnt1);

  Standard_Real aMax = RealFirst();
  Standard_Real aMin = RealLast();
  for (Standard_Integer aVertIdx = 0; aVertIdx < N * 2; ++aVertIdx)
  {
    Standard_Real aProjection = aNormal.Dot (myVertices[aVertIdx].XYZ());
    aMax = Max (aMax, aProjection);
    aMin = Min (aMin, aProjection);
  }
  if (aPolygProjection > aMax
    || aPolygProjection < aMin)
  {
    return Standard_False;
  }

  const Standard_Integer anIncFactor = (myIsOrthographic && N == 4) ? 2 : 1;
  for (Standard_Integer aPlaneIdx = 0; aPlaneIdx <  N + 1; aPlaneIdx += anIncFactor)
  {
    Standard_Real aMaxF = RealFirst();
    Standard_Real aMinF = RealLast();
    Standard_Real aMaxPolyg = RealFirst();
    Standard_Real aMinPolyg = RealLast();
    const gp_XYZ& aPlane = myPlanes[aPlaneIdx].XYZ();
    for (Standard_Integer aPntIter = aStartIdx; aPntIter <= anEndIdx; ++aPntIter)
    {
      Standard_Real aProjection = aPlane.Dot (theArrayOfPnts->Value (aPntIter).XYZ());
      aMaxPolyg = Max (aMaxPolyg, aProjection);
      aMinPolyg = Min (aMinPolyg, aProjection);
    }
    aMaxF = myMaxVertsProjections[aPlaneIdx];
    aMinF = myMinVertsProjections[aPlaneIdx];
    if (aMinPolyg > aMaxF
      || aMaxPolyg < aMinF)
    {
      return Standard_False;
    }
  }

  Standard_Integer aDirectionsNb = myIsOrthographic ? 4 : 6;
  for (Standard_Integer aPntsIter = 0, aLastIdx = anEndIdx - aStartIdx, aLen = theArrayOfPnts->Length(); aPntsIter <= aLastIdx; ++aPntsIter)
  {
    const gp_XYZ aSegmDir = theArrayOfPnts->Value ((aPntsIter + 1) % aLen + aStartIdx).XYZ()
      - theArrayOfPnts->Value (aPntsIter + aStartIdx).XYZ();
    for (Standard_Integer aVolDir = 0; aVolDir < aDirectionsNb; ++aVolDir)
    {
      Standard_Real aMaxPolyg = RealFirst();
      Standard_Real aMinPolyg = RealLast();
      Standard_Real aMaxF = RealFirst();
      Standard_Real aMinF = RealLast();
      const gp_XYZ aTestDir = aSegmDir.Crossed (myEdgeDirs[aVolDir].XYZ());

      for (Standard_Integer aPntIter = aStartIdx; aPntIter <= anEndIdx; ++aPntIter)
      {
        Standard_Real aProjection = aTestDir.Dot (theArrayOfPnts->Value (aPntIter).XYZ());
        aMaxPolyg = Max (aMaxPolyg, aProjection);
        aMinPolyg = Min (aMinPolyg, aProjection);
      }

      for (Standard_Integer aVertIdx = 0; aVertIdx < N * 2; ++aVertIdx)
      {
        Standard_Real aProjection = aTestDir.Dot (myVertices[aVertIdx].XYZ());
        aMaxF = Max (aMaxF, aProjection);
        aMinF = Min (aMinF, aProjection);
      }

      if (aMinPolyg > aMaxF
        || aMaxPolyg < aMinF)
      {
        return Standard_False;
      }
    }
  }

  return Standard_True;
}

// =======================================================================
// function : hasOverlap
// purpose  : SAT intersection test between defined volume and given triangle
// =======================================================================
template <int N>
Standard_Boolean SelectMgr_Frustum<N>::hasOverlap (const gp_Pnt& thePnt1,
                                                   const gp_Pnt& thePnt2,
                                                   const gp_Pnt& thePnt3,
                                                   gp_Vec& theNormal)
{
  const gp_XYZ aTrEdges[3] = { thePnt2.XYZ() - thePnt1.XYZ(),
                               thePnt3.XYZ() - thePnt2.XYZ(),
                               thePnt1.XYZ() - thePnt3.XYZ() };

  const Standard_Integer anIncFactor = (myIsOrthographic && N == 4) ? 2 : 1;
  for (Standard_Integer aPlaneIdx = 0; aPlaneIdx < N + 1; aPlaneIdx += anIncFactor)
  {
    const gp_XYZ& aPlane = myPlanes[aPlaneIdx].XYZ();
    Standard_Real aTriangleProj;

    aTriangleProj = aPlane.Dot (thePnt1.XYZ());
    Standard_Real aTriangleProjMin = aTriangleProj;
    Standard_Real aTriangleProjMax = aTriangleProj;

    aTriangleProj = aPlane.Dot (thePnt2.XYZ());
    aTriangleProjMin = Min (aTriangleProjMin, aTriangleProj);
    aTriangleProjMax = Max (aTriangleProjMax, aTriangleProj);

    aTriangleProj = aPlane.Dot (thePnt3.XYZ());
    aTriangleProjMin = Min (aTriangleProjMin, aTriangleProj);
    aTriangleProjMax = Max (aTriangleProjMax, aTriangleProj);

    Standard_Real aFrustumProjMax = myMaxVertsProjections[aPlaneIdx];
    Standard_Real aFrustumProjMin = myMinVertsProjections[aPlaneIdx];
    if (aTriangleProjMin > aFrustumProjMax
      || aTriangleProjMax < aFrustumProjMin)
    {
      return Standard_False;
    }
  }

  theNormal = aTrEdges[2].Crossed (aTrEdges[0]);
  if (isSeparated (thePnt1, thePnt2, thePnt3, theNormal.XYZ()))
  {
    return Standard_False;
  }

  Standard_Integer aDirectionsNb = myIsOrthographic ? 4 : 6;
  for (Standard_Integer aTriangleEdgeIdx = 0; aTriangleEdgeIdx < 3; ++aTriangleEdgeIdx)
  {
    for (Standard_Integer aVolDir = 0; aVolDir < aDirectionsNb; ++aVolDir)
    {
      const gp_XYZ& aTestDirection =  myEdgeDirs[aVolDir].XYZ().Crossed (aTrEdges[aTriangleEdgeIdx]);

      if (isSeparated (thePnt1, thePnt2, thePnt3, aTestDirection))
      {
        return Standard_False;
      }
    }
  }

  return Standard_True;
}