1 // Created on: 2016-02-20
2 // Created by: Kirill Gavrilov
3 // Copyright (c) 2016 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <Select3D_SensitivePrimitiveArray.hxx>
18 #include <NCollection_AlignedAllocator.hxx>
20 IMPLEMENT_STANDARD_RTTIEXT(Select3D_SensitivePrimitiveArray, Select3D_SensitiveSet)
25 //! Auxiliary converter.
26 static inline gp_Pnt vecToPnt (const Graphic3d_Vec3& theVec)
28 return gp_Pnt (theVec.x(), theVec.y(), theVec.z());
31 //! Auxiliary converter.
32 static inline gp_Pnt vecToPnt (const Graphic3d_Vec2& theVec)
34 return gp_Pnt (theVec.x(), theVec.y(), 0.0);
38 //! Auxiliary function to find shared node between two triangles.
39 static inline bool hasSharedNode (const Standard_Integer* theTri1,
40 const Standard_Integer* theTri2)
42 return theTri1[0] == theTri2[0]
43 || theTri1[1] == theTri2[0]
44 || theTri1[2] == theTri2[0]
45 || theTri1[0] == theTri2[1]
46 || theTri1[1] == theTri2[1]
47 || theTri1[2] == theTri2[1]
48 || theTri1[0] == theTri2[2]
49 || theTri1[1] == theTri2[2]
50 || theTri1[2] == theTri2[2];
53 //! Fill in the triangle nodes indices.
54 static inline void getTriIndices (const Handle(Graphic3d_IndexBuffer)& theIndices,
55 const Standard_Integer theIndexOffset,
56 Standard_Integer* theNodes)
58 if (!theIndices.IsNull())
60 theNodes[0] = theIndices->Index (theIndexOffset + 0);
61 theNodes[1] = theIndices->Index (theIndexOffset + 1);
62 theNodes[2] = theIndices->Index (theIndexOffset + 2);
66 theNodes[0] = theIndexOffset + 0;
67 theNodes[1] = theIndexOffset + 1;
68 theNodes[2] = theIndexOffset + 2;
74 // =======================================================================
75 // function : Select3D_SensitivePrimitiveArray
77 // =======================================================================
78 Select3D_SensitivePrimitiveArray::Select3D_SensitivePrimitiveArray (const Handle(SelectBasics_EntityOwner)& theOwnerId)
79 : Select3D_SensitiveSet (theOwnerId),
80 myPrimType (Graphic3d_TOPA_UNDEFINED),
83 myPosOffset (Standard_Size(-1)),
85 myPatchDistance (ShortRealLast()),
87 myBvhIndices (new NCollection_AlignedAllocator(16)),
88 myMinDepthElem (RealLast()),
89 myMinDepthNode (RealLast()),
90 myMinDepthEdge (RealLast()),
93 myDetectedEdgeNode1 (-1),
94 myDetectedEdgeNode2 (-1),
95 myToDetectElem (true),
96 myToDetectNode (false),
97 myToDetectEdge (false)
102 // =======================================================================
103 // function : InitTriangulation
105 // =======================================================================
106 bool Select3D_SensitivePrimitiveArray::InitTriangulation (const Handle(Graphic3d_Buffer)& theVerts,
107 const Handle(Graphic3d_IndexBuffer)& theIndices,
108 const TopLoc_Location& theInitLoc,
109 const Standard_Integer theIndexLower,
110 const Standard_Integer theIndexUpper,
111 const bool theToEvalMinMax)
114 myPrimType = Graphic3d_TOPA_TRIANGLES;
120 myPosOffset = Standard_Size(-1);
121 myBvhIndices.release();
123 myInitLocation = theInitLoc;
124 if (theVerts.IsNull()
125 || theVerts->NbElements == 0)
130 for (Standard_Integer anAttribIter = 0; anAttribIter < theVerts->NbAttributes; ++anAttribIter)
132 const Graphic3d_Attribute& anAttrib = theVerts->Attribute (anAttribIter);
133 if (anAttrib.Id == Graphic3d_TOA_POS)
135 if (anAttrib.DataType == Graphic3d_TOD_VEC3
136 || anAttrib.DataType == Graphic3d_TOD_VEC4)
140 else if (anAttrib.DataType != Graphic3d_TOD_VEC2)
145 myPosOffset = theVerts->AttributeOffset (anAttribIter);
149 if (myPosOffset == Standard_Size(-1))
154 if (!theIndices.IsNull())
156 if (theIndexLower < 0
157 || theIndexUpper >= theIndices->NbElements
158 || theIndices->NbElements == 0)
165 if (theIndexLower < 0
166 || theIndexUpper >= theVerts->NbElements)
172 Standard_Integer aTriFrom = theIndexLower / 3;
173 Standard_Integer aNbTris = (theIndexUpper - theIndexLower + 1) / 3;
178 if (!myBvhIndices.Init (aNbTris, myPatchSizeMax > 1))
184 myIndices = theIndices;
185 myIndexLower = theIndexLower;
186 myIndexUpper = theIndexUpper;
187 myInvInitLocation = myInitLocation.Transformation().Inverted();
189 Graphic3d_Vec3 aCenter (0.0f, 0.0f, 0.0f);
190 Standard_Integer aTriNodes1[3] = { -1, -1, -1 };
191 Standard_Integer aTriNodes2[3] = { -1, -1, -1 };
192 Standard_Integer* aTriNodesPrev = aTriNodes1;
193 Standard_Integer* aTriNodes = aTriNodes2;
194 Standard_Integer aPatchFrom = 0;
195 Standard_Integer aPatchSize = 0;
196 if (myBvhIndices.HasPatches())
198 myBvhIndices.NbElements = 0;
200 for (Standard_Integer aTriIter = 0; aTriIter < aNbTris; ++aTriIter)
202 const Standard_Integer anIndexOffset = (aTriFrom + aTriIter) * 3;
203 getTriIndices (myIndices, anIndexOffset, aTriNodes);
206 const Graphic3d_Vec3& aNode1 = getPosVec3 (aTriNodes[0]);
207 const Graphic3d_Vec3& aNode2 = getPosVec3 (aTriNodes[1]);
208 const Graphic3d_Vec3& aNode3 = getPosVec3 (aTriNodes[2]);
209 aCenter += (aNode1 + aNode2 + aNode3) / 3.0;
213 const Graphic3d_Vec2& aNode1 = getPosVec2 (aTriNodes[0]);
214 const Graphic3d_Vec2& aNode2 = getPosVec2 (aTriNodes[1]);
215 const Graphic3d_Vec2& aNode3 = getPosVec2 (aTriNodes[2]);
216 aCenter.xy() += (aNode1 + aNode2 + aNode3) / 3.0;
218 if (myBvhIndices.HasPatches())
220 std::swap (aTriNodes, aTriNodesPrev);
221 if (aPatchSize < myPatchSizeMax
222 && hasSharedNode (aTriNodes, aTriNodesPrev))
229 myBvhIndices.SetIndex (myBvhIndices.NbElements++, aTriFrom + aPatchFrom, aPatchSize);
230 aPatchFrom = aTriIter;
236 myBvhIndices.SetIndex (aTriIter, aTriFrom + aTriIter);
241 myBvhIndices.SetIndex (myBvhIndices.NbElements++, aTriFrom + aPatchFrom, aPatchSize);
243 aCenter /= float(aNbTris);
245 myCDG3D = vecToPnt (aCenter);
248 computeBoundingBox();
253 // =======================================================================
254 // function : InitPoints
256 // =======================================================================
257 bool Select3D_SensitivePrimitiveArray::InitPoints (const Handle(Graphic3d_Buffer)& theVerts,
258 const Handle(Graphic3d_IndexBuffer)& theIndices,
259 const TopLoc_Location& theInitLoc,
260 const Standard_Integer theIndexLower,
261 const Standard_Integer theIndexUpper,
262 const bool theToEvalMinMax)
265 myPrimType = Graphic3d_TOPA_POINTS;
271 myPosOffset = Standard_Size(-1);
272 myBvhIndices.release();
274 myInitLocation = theInitLoc;
275 if (theVerts.IsNull()
276 || theVerts->NbElements == 0)
281 for (Standard_Integer anAttribIter = 0; anAttribIter < theVerts->NbAttributes; ++anAttribIter)
283 const Graphic3d_Attribute& anAttrib = theVerts->Attribute (anAttribIter);
284 if (anAttrib.Id == Graphic3d_TOA_POS)
286 if (anAttrib.DataType == Graphic3d_TOD_VEC3
287 || anAttrib.DataType == Graphic3d_TOD_VEC4)
291 else if (anAttrib.DataType != Graphic3d_TOD_VEC2)
296 myPosOffset = theVerts->AttributeOffset (anAttribIter);
300 if (myPosOffset == Standard_Size(-1))
305 if (!theIndices.IsNull())
307 if (theIndexLower < 0
308 || theIndexUpper >= theIndices->NbElements
309 || theIndices->NbElements == 0)
316 if (theIndexLower < 0
317 || theIndexUpper >= theVerts->NbElements)
323 Standard_Integer aNbPoints = theIndexUpper - theIndexLower + 1;
328 if (!myBvhIndices.Init (aNbPoints, myPatchSizeMax > 1))
334 myIndices = theIndices;
335 myIndexLower = theIndexLower;
336 myIndexUpper = theIndexUpper;
337 myInvInitLocation = myInitLocation.Transformation().Inverted();
339 Graphic3d_Vec3 aCenter (0.0f, 0.0f, 0.0f);
340 Standard_Integer aPatchFrom = 0;
341 Standard_Integer aPatchSize = 0;
342 if (myBvhIndices.HasPatches())
344 myBvhIndices.NbElements = 0;
346 const float aPatchSize2 = myPatchDistance < ShortRealLast()
347 ? myPatchDistance * myPatchDistance
349 const Graphic3d_Vec3* aPnt3dPrev = NULL;
350 const Graphic3d_Vec3* aPnt3d = NULL;
351 const Graphic3d_Vec2* aPnt2dPrev = NULL;
352 const Graphic3d_Vec2* aPnt2d = NULL;
353 for (Standard_Integer aPointIter = 0; aPointIter < aNbPoints; ++aPointIter)
355 const Standard_Integer anIndexOffset = (theIndexLower + aPointIter);
356 const Standard_Integer aPointIndex = !myIndices.IsNull()
357 ? myIndices->Index (anIndexOffset)
361 aPnt3d = &getPosVec3 (aPointIndex);
366 aPnt2d = &getPosVec2 (aPointIndex);
367 aCenter.xy() += *aPnt2d;
370 if (myBvhIndices.HasPatches())
374 std::swap (aPnt3d, aPnt3dPrev);
375 if (aPatchSize < myPatchSizeMax
377 && (*aPnt3dPrev - *aPnt3d).SquareModulus() < aPatchSize2)
385 std::swap (aPnt2d, aPnt2dPrev);
386 if (aPatchSize < myPatchSizeMax
388 && (*aPnt2dPrev - *aPnt2d).SquareModulus() < aPatchSize2)
395 myBvhIndices.SetIndex (myBvhIndices.NbElements++, theIndexLower + aPatchFrom,
396 aPatchSize != 0 ? aPatchSize : 1);
397 aPatchFrom = aPointIter;
402 myBvhIndices.SetIndex (aPointIter, theIndexLower + aPointIter);
407 myBvhIndices.SetIndex (myBvhIndices.NbElements++, theIndexLower + aPatchFrom, aPatchSize);
409 aCenter /= float(aNbPoints);
411 myCDG3D = vecToPnt (aCenter);
414 computeBoundingBox();
419 // =======================================================================
420 // function : GetConnected
422 // =======================================================================
423 Handle(Select3D_SensitiveEntity) Select3D_SensitivePrimitiveArray::GetConnected()
425 Handle(Select3D_SensitivePrimitiveArray) aNewEntity = new Select3D_SensitivePrimitiveArray (myOwnerId);
428 case Graphic3d_TOPA_POINTS:
430 aNewEntity->InitPoints (myVerts, myIndices, myInitLocation, myIndexLower, myIndexUpper);
433 case Graphic3d_TOPA_TRIANGLES:
435 aNewEntity->InitTriangulation (myVerts, myIndices, myInitLocation, myIndexLower, myIndexUpper);
443 // =======================================================================
446 // =======================================================================
447 Standard_Integer Select3D_SensitivePrimitiveArray::Size() const
449 return myBvhIndices.NbElements;
452 // =======================================================================
455 // =======================================================================
456 Select3D_BndBox3d Select3D_SensitivePrimitiveArray::Box (const Standard_Integer theIdx) const
458 const Standard_Integer anElemIdx = myBvhIndices.Index (theIdx);
459 const Standard_Integer aPatchSize = myBvhIndices.PatchSize (theIdx);
460 Select3D_BndBox3d aBox;
463 case Graphic3d_TOPA_POINTS:
465 for (Standard_Integer anElemIter = 0; anElemIter < aPatchSize; ++anElemIter)
467 const Standard_Integer anIndexOffset = (anElemIdx + anElemIter);
468 const Standard_Integer aPointIndex = !myIndices.IsNull()
469 ? myIndices->Index (anIndexOffset)
473 const Graphic3d_Vec3& aPoint = getPosVec3 (aPointIndex);
474 aBox.Add (SelectMgr_Vec3 (aPoint.x(), aPoint.y(), aPoint.z()));
478 const Graphic3d_Vec2& aPoint = getPosVec2 (aPointIndex);
479 aBox.Add (SelectMgr_Vec3 (aPoint.x(), aPoint.y(), 0.0));
484 case Graphic3d_TOPA_TRIANGLES:
486 Standard_Integer aTriNodes[3];
489 for (Standard_Integer anElemIter = 0; anElemIter < aPatchSize; ++anElemIter)
491 const Standard_Integer anIndexOffset = (anElemIdx + anElemIter) * 3;
492 getTriIndices (myIndices, anIndexOffset, aTriNodes);
493 const Graphic3d_Vec3& aNode1 = getPosVec3 (aTriNodes[0]);
494 const Graphic3d_Vec3& aNode2 = getPosVec3 (aTriNodes[1]);
495 const Graphic3d_Vec3& aNode3 = getPosVec3 (aTriNodes[2]);
496 Graphic3d_Vec3 aMinPnt = (aNode1.cwiseMin (aNode2)).cwiseMin (aNode3);
497 Graphic3d_Vec3 aMaxPnt = (aNode1.cwiseMax (aNode2)).cwiseMax (aNode3);
498 aBox.Add (SelectMgr_Vec3 (aMinPnt.x(), aMinPnt.y(), aMinPnt.z()));
499 aBox.Add (SelectMgr_Vec3 (aMaxPnt.x(), aMaxPnt.y(), aMaxPnt.z()));
504 for (Standard_Integer anElemIter = 0; anElemIter < aPatchSize; ++anElemIter)
506 const Standard_Integer anIndexOffset = (anElemIdx + anElemIter) * 3;
507 getTriIndices (myIndices, anIndexOffset, aTriNodes);
508 const Graphic3d_Vec2& aNode1 = getPosVec2 (aTriNodes[0]);
509 const Graphic3d_Vec2& aNode2 = getPosVec2 (aTriNodes[1]);
510 const Graphic3d_Vec2& aNode3 = getPosVec2 (aTriNodes[2]);
511 Graphic3d_Vec2 aMinPnt = (aNode1.cwiseMin (aNode2)).cwiseMin (aNode3);
512 Graphic3d_Vec2 aMaxPnt = (aNode1.cwiseMax (aNode2)).cwiseMax (aNode3);
513 aBox.Add (SelectMgr_Vec3 (aMinPnt.x(), aMinPnt.y(), 0.0));
514 aBox.Add (SelectMgr_Vec3 (aMaxPnt.x(), aMaxPnt.y(), 0.0));
527 // =======================================================================
530 // =======================================================================
531 Standard_Real Select3D_SensitivePrimitiveArray::Center (const Standard_Integer theIdx,
532 const Standard_Integer theAxis) const
534 const Select3D_BndBox3d& aBox = Box (theIdx);
535 SelectMgr_Vec3 aCenter = (aBox.CornerMin() + aBox.CornerMax()) * 0.5;
536 return theAxis == 0 ? aCenter.x() : (theAxis == 1 ? aCenter.y() : aCenter.z());
539 // =======================================================================
542 // =======================================================================
543 void Select3D_SensitivePrimitiveArray::Swap (const Standard_Integer theIdx1,
544 const Standard_Integer theIdx2)
546 Standard_Integer anElemIdx1 = myBvhIndices.Index (theIdx1);
547 Standard_Integer anElemIdx2 = myBvhIndices.Index (theIdx2);
548 if (myBvhIndices.HasPatches())
550 Standard_Integer aPatchSize1 = myBvhIndices.PatchSize (theIdx1);
551 Standard_Integer aPatchSize2 = myBvhIndices.PatchSize (theIdx2);
552 myBvhIndices.SetIndex (theIdx1, anElemIdx2, aPatchSize2);
553 myBvhIndices.SetIndex (theIdx2, anElemIdx1, aPatchSize1);
557 myBvhIndices.SetIndex (theIdx1, anElemIdx2);
558 myBvhIndices.SetIndex (theIdx2, anElemIdx1);
562 // =======================================================================
563 // function : BoundingBox
565 // =======================================================================
566 Select3D_BndBox3d Select3D_SensitivePrimitiveArray::BoundingBox()
568 if (!myBndBox.IsValid())
570 computeBoundingBox();
572 return applyTransformation();
575 // =======================================================================
576 // function : computeBoundingBox
578 // =======================================================================
579 void Select3D_SensitivePrimitiveArray::computeBoundingBox()
582 if (myVerts.IsNull())
587 const Standard_Integer aNbVerts = myVerts->NbElements;
590 for (Standard_Integer aVertIter = 0; aVertIter < aNbVerts; ++aVertIter)
592 const Graphic3d_Vec3& aVert = getPosVec3 (aVertIter);
593 myBndBox.Add (SelectMgr_Vec3 (aVert.x(), aVert.y(), aVert.z()));
598 for (Standard_Integer aVertIter = 0; aVertIter < aNbVerts; ++aVertIter)
600 const Graphic3d_Vec2& aVert = getPosVec2 (aVertIter);
601 myBndBox.Add (SelectMgr_Vec3 (aVert.x(), aVert.y(), 0.0));
606 // =======================================================================
607 // function : applyTransformation
609 // =======================================================================
610 Select3D_BndBox3d Select3D_SensitivePrimitiveArray::applyTransformation()
612 if (!HasInitLocation())
617 Select3D_BndBox3d aBndBox;
618 for (Standard_Integer aX = 0; aX <=1; ++aX)
620 for (Standard_Integer aY = 0; aY <=1; ++aY)
622 for (Standard_Integer aZ = 0; aZ <= 1; ++aZ)
624 gp_Pnt aVertex = gp_Pnt (aX == 0 ? myBndBox.CornerMin().x() : myBndBox.CornerMax().x(),
625 aY == 0 ? myBndBox.CornerMin().y() : myBndBox.CornerMax().y(),
626 aZ == 0 ? myBndBox.CornerMin().z() : myBndBox.CornerMax().z());
627 aVertex.Transform (myInitLocation.Transformation());
628 aBndBox.Add (Select3D_Vec3 (aVertex.X(), aVertex.Y(), aVertex.Z()));
635 // =======================================================================
636 // function : Matches
638 // =======================================================================
639 Standard_Boolean Select3D_SensitivePrimitiveArray::Matches (SelectBasics_SelectingVolumeManager& theMgr,
640 SelectBasics_PickResult& thePickResult)
642 myMinDepthElem = RealLast();
643 myMinDepthNode = RealLast();
644 myMinDepthEdge = RealLast();
647 myDetectedEdgeNode1 = -1;
648 myDetectedEdgeNode2 = -1;
649 return Select3D_SensitiveSet::Matches (theMgr, thePickResult);
652 // =======================================================================
653 // function : overlapsElement
655 // =======================================================================
656 Standard_Boolean Select3D_SensitivePrimitiveArray::overlapsElement (SelectBasics_SelectingVolumeManager& theMgr,
657 Standard_Integer theElemIdx,
658 Standard_Real& theMatchDepth)
660 const Standard_Integer anElemIdx = myBvhIndices.Index (theElemIdx);
661 const Standard_Integer aPatchSize = myBvhIndices.PatchSize (theElemIdx);
662 Select3D_BndBox3d aBox;
663 Standard_Boolean aResult = Standard_False;
664 Standard_Real aMinDepth = RealLast();
667 case Graphic3d_TOPA_POINTS:
669 for (Standard_Integer anElemIter = 0; anElemIter < aPatchSize; ++anElemIter)
671 const Standard_Integer anIndexOffset = (anElemIdx + anElemIter);
672 const Standard_Integer aPointIndex = !myIndices.IsNull()
673 ? myIndices->Index (anIndexOffset)
678 aPoint = vecToPnt (getPosVec3 (aPointIndex));
682 aPoint = vecToPnt (getPosVec2 (aPointIndex));
685 Standard_Real aCurrentDepth = RealLast();
689 if (theMgr.Overlaps (aPoint, aCurrentDepth))
691 if (aCurrentDepth <= myMinDepthNode)
693 myDetectedElem = myDetectedNode = aPointIndex;
694 myMinDepthElem = myMinDepthNode = aCurrentDepth;
696 aResult = Standard_True;
699 aMinDepth = Min (aMinDepth, aCurrentDepth);
703 case Graphic3d_TOPA_TRIANGLES:
705 Graphic3d_Vec3i aTriNodes;
706 for (Standard_Integer anElemIter = 0; anElemIter < aPatchSize; ++anElemIter)
708 const Standard_Integer anIndexOffset = (anElemIdx + anElemIter) * 3;
709 getTriIndices (myIndices, anIndexOffset, aTriNodes);
713 aPnts[0] = vecToPnt (getPosVec3 (aTriNodes[0]));
714 aPnts[1] = vecToPnt (getPosVec3 (aTriNodes[1]));
715 aPnts[2] = vecToPnt (getPosVec3 (aTriNodes[2]));
719 aPnts[0] = vecToPnt (getPosVec2 (aTriNodes[0]));
720 aPnts[1] = vecToPnt (getPosVec2 (aTriNodes[1]));
721 aPnts[2] = vecToPnt (getPosVec2 (aTriNodes[2]));
724 Standard_Real aCurrentDepth = RealLast();
727 if (theMgr.Overlaps (aPnts[0], aPnts[1], aPnts[2], Select3D_TOS_INTERIOR, aCurrentDepth))
729 if (aCurrentDepth <= myMinDepthElem)
731 myDetectedElem = anElemIdx + anElemIter;
732 myMinDepthElem = aCurrentDepth;
734 aResult = Standard_True;
739 for (int aNodeIter = 0; aNodeIter < 3; ++aNodeIter)
741 if (theMgr.Overlaps (aPnts[aNodeIter], aCurrentDepth))
743 if (aCurrentDepth <= myMinDepthNode)
745 myDetectedNode = aTriNodes[aNodeIter];
746 myMinDepthNode = aCurrentDepth;
748 aResult = Standard_True;
754 for (int aNodeIter = 0; aNodeIter < 3; ++aNodeIter)
756 int aNode1 = aNodeIter == 0 ? 2 : (aNodeIter - 1);
757 int aNode2 = aNodeIter;
758 if (theMgr.Overlaps (aPnts[aNode1], aPnts[aNode2], aCurrentDepth))
760 if (aCurrentDepth <= myMinDepthEdge)
762 myDetectedEdgeNode1 = aTriNodes[aNode1];
763 myDetectedEdgeNode2 = aTriNodes[aNode2];
764 myMinDepthEdge = aCurrentDepth;
766 aResult = Standard_True;
770 aMinDepth = Min (aMinDepth, aCurrentDepth);
776 return Standard_False;
780 theMatchDepth = aMinDepth;
784 // =======================================================================
785 // function : distanceToCOG
787 // =======================================================================
788 Standard_Real Select3D_SensitivePrimitiveArray::distanceToCOG (SelectBasics_SelectingVolumeManager& theMgr)
790 return theMgr.DistToGeometryCenter (myCDG3D);
793 // =======================================================================
794 // function : elementIsInside
796 // =======================================================================
797 Standard_Boolean Select3D_SensitivePrimitiveArray::elementIsInside (SelectBasics_SelectingVolumeManager& theMgr,
798 const Standard_Integer theElemIdx)
800 const Standard_Integer anElemIdx = myBvhIndices.Index (theElemIdx);
801 const Standard_Integer aPatchSize = myBvhIndices.PatchSize (theElemIdx);
804 case Graphic3d_TOPA_POINTS:
806 for (Standard_Integer anElemIter = 0; anElemIter < aPatchSize; ++anElemIter)
808 const Standard_Integer anIndexOffset = (anElemIdx + anElemIter);
809 const Standard_Integer aPointIndex = !myIndices.IsNull()
810 ? myIndices->Index (anIndexOffset)
815 aPoint = vecToPnt (getPosVec3 (aPointIndex));
819 aPoint = vecToPnt (getPosVec2 (aPointIndex));
821 if (!theMgr.Overlaps (aPoint))
823 return Standard_False;
826 return Standard_True;
828 case Graphic3d_TOPA_TRIANGLES:
830 Graphic3d_Vec3i aTriNodes;
831 for (Standard_Integer anElemIter = 0; anElemIter < aPatchSize; ++anElemIter)
833 const Standard_Integer anIndexOffset = (anElemIdx + anElemIter) * 3;
834 getTriIndices (myIndices, anIndexOffset, aTriNodes);
838 aPnts[0] = vecToPnt (getPosVec3 (aTriNodes[0]));
839 aPnts[1] = vecToPnt (getPosVec3 (aTriNodes[1]));
840 aPnts[2] = vecToPnt (getPosVec3 (aTriNodes[2]));
844 aPnts[0] = vecToPnt (getPosVec2 (aTriNodes[0]));
845 aPnts[1] = vecToPnt (getPosVec2 (aTriNodes[1]));
846 aPnts[2] = vecToPnt (getPosVec2 (aTriNodes[2]));
849 if (!theMgr.Overlaps (aPnts[0])
850 || !theMgr.Overlaps (aPnts[1])
851 || !theMgr.Overlaps (aPnts[2]))
853 return Standard_False;
856 return Standard_True;
860 return Standard_False;