0026121: Visualization - revise implementation of point sets used in Select3D_Sensiti...
authorvpa <vpa@opencascade.com>
Thu, 30 Apr 2015 15:08:55 +0000 (18:08 +0300)
committerbugmaster <bugmaster@opencascade.com>
Wed, 6 May 2015 14:02:54 +0000 (17:02 +0300)
Code duplication was eliminated by removing constructors with handle input arrays

src/Select3D/Select3D_BoundarySensitivePointSet.cxx
src/Select3D/Select3D_BoundarySensitivePointSet.hxx
src/Select3D/Select3D_InteriorSensitivePointSet.cxx
src/Select3D/Select3D_InteriorSensitivePointSet.hxx
src/Select3D/Select3D_SensitiveFace.cxx

index 7a34c12..8a5b6a2 100644 (file)
@@ -26,16 +26,6 @@ Select3D_BoundarySensitivePointSet::Select3D_BoundarySensitivePointSet (const Ha
 {}
 
 //=======================================================================
-// function : Select3D_BoundarySensitivePointSet
-// purpose  : Creates new instance of Select3D_SensitivePoly with BVH tree
-//            required and initializes it with the given array of points
-//=======================================================================
-Select3D_BoundarySensitivePointSet::Select3D_BoundarySensitivePointSet (const Handle(SelectBasics_EntityOwner)& OwnerId,
-                                                                        const Handle(TColgp_HArray1OfPnt)& ThePoints)
-  : Select3D_SensitivePoly (OwnerId, ThePoints, Standard_True)
-{}
-
-//=======================================================================
 // function : Matches
 // purpose  : Checks whether the point set overlaps current selecting
 //            volume
index f04c613..1218811 100644 (file)
@@ -36,11 +36,6 @@ public:
   Standard_EXPORT Select3D_BoundarySensitivePointSet (const Handle(SelectBasics_EntityOwner)& OwnerId,
                                                       const TColgp_Array1OfPnt& ThePoints);
 
-  //! Creates new instance of Select3D_SensitivePoly with BVH tree
-  //! required and initializes it with the given array of points
-  Standard_EXPORT Select3D_BoundarySensitivePointSet (const Handle(SelectBasics_EntityOwner)& OwnerId,
-                                                      const Handle(TColgp_HArray1OfPnt)& ThePoints);
-
   //! Checks whether the point set overlaps current selecting volume
   Standard_EXPORT virtual Standard_Boolean Matches (SelectBasics_SelectingVolumeManager& theMgr,
                                                     SelectBasics_PickResult& thePickResult) Standard_OVERRIDE;
index e24af87..cc2c7f8 100644 (file)
@@ -84,146 +84,55 @@ Select3D_InteriorSensitivePointSet::Select3D_InteriorSensitivePointSet (const Ha
   : Select3D_SensitiveSet (theOwnerId)
 {
   Select3D_Plane aPlane;
-  Standard_Integer aStartIdx = 1, anEndIdx = 0;
   Standard_Integer aLowerIdx = thePoints.Lower();
   Standard_Integer anUpperIdx = thePoints.Upper();
-  Select3D_BndBox3d aBndBox;
-  gp_XYZ aPntSum (0.0, 0.0, 0.0);
-  if (thePoints.Length() > 3)
-  {
-    for (Standard_Integer aPntIter = aLowerIdx; aPntIter <= anUpperIdx; ++aPntIter)
-    {
-      gp_Pnt aPnt1, aPnt2;
-      const gp_Pnt& aPnt3 = thePoints.Value (aPntIter);
-      aBndBox.Add (SelectMgr_Vec3 (aPnt3.X(), aPnt3.Y(), aPnt3.Z()));
-      aPntSum += aPnt3.XYZ();
-      if (aPntIter - aLowerIdx >= 2)
-      {
-        aPnt1 = thePoints.Value (aPntIter - 2);
-        aPnt2 = thePoints.Value (aPntIter - 1);
-      }
-      if (aPntIter - aStartIdx == 2 && !aPlane.IsValid())
-      {
-        aPlane.MakePlane (aPnt1, aPnt2, aPnt3);
-        aStartIdx = aPntIter - 2;
-        anEndIdx = aPntIter;
-      }
-      else if (aPlane.IsValid())
-      {
-        const gp_XYZ& aVec1 = aPnt1.XYZ() - aPnt2.XYZ();
-        const gp_XYZ& aVec2 = aPnt3.XYZ() - aPnt2.XYZ();
-        Standard_Real anAngle = aVec1.Dot (aVec2);
-        if (!aPlane.Contains (thePoints.Value (aPntIter)) || anAngle > Precision::Confusion())
-        {
-          // subtract 1 due to indexation from zero in sub-polygons
-          Standard_Integer anUpperBound = aPntIter - aStartIdx - 1;
-          Handle (TColgp_HArray1OfPnt) aPointsArray = new TColgp_HArray1OfPnt (0, anUpperBound);
-          for (Standard_Integer aIdx = aStartIdx; aIdx <= aStartIdx + anUpperBound; ++aIdx)
-          {
-            aPointsArray->SetValue (aIdx - aStartIdx, thePoints.Value (aIdx));
-          }
-          Handle(Select3D_SensitivePoly) aPlanarPolyg = new Select3D_SensitivePoly (theOwnerId,
-                                                                                    aPointsArray,
-                                                                                    Standard_False);
-          myPlanarPolygons.Append (aPlanarPolyg);
-          aStartIdx = aPntIter;
-          anEndIdx = aPntIter;
-          aPlane.Invalidate();
-        }
-        else
-        {
-          if (anEndIdx == anUpperIdx)
-          {
-            Handle (TColgp_HArray1OfPnt) aPointsArray = new TColgp_HArray1OfPnt (0, anEndIdx - aStartIdx);
-            for (Standard_Integer aIdx = aStartIdx; aIdx <= anEndIdx; ++aIdx)
-            {
-              aPointsArray->SetValue (aIdx - aStartIdx, thePoints.Value (aIdx));
-            }
-            Handle(Select3D_SensitivePoly) aPlanarPolyg = new Select3D_SensitivePoly (theOwnerId,
-                                                                                      aPointsArray,
-                                                                                      Standard_False);
-            myPlanarPolygons.Append (aPlanarPolyg);
-          }
-          anEndIdx++;
-        }
-      }
-    }
-  }
-  else
-  {
-    Handle (TColgp_HArray1OfPnt) aPointsArray = new TColgp_HArray1OfPnt (0, 2);
-    const gp_Pnt& aPnt1 = thePoints.Value (aLowerIdx);
-    const gp_Pnt& aPnt2 = thePoints.Value (aLowerIdx + 1);
-    const gp_Pnt& aPnt3 = thePoints.Value (aLowerIdx + 2);
-    aPointsArray->SetValue (0, aPnt1);
-    aPointsArray->SetValue (1, aPnt2);
-    aPointsArray->SetValue (2, aPnt3);
-    aBndBox.Add (SelectMgr_Vec3 (aPnt1.X(), aPnt1.Y(), aPnt1.Z()));
-    aBndBox.Add (SelectMgr_Vec3 (aPnt2.X(), aPnt2.Y(), aPnt2.Z()));
-    aBndBox.Add (SelectMgr_Vec3 (aPnt3.X(), aPnt3.Y(), aPnt3.Z()));
-    aPntSum += aPnt1.XYZ() + aPnt2.XYZ() + aPnt3.XYZ();
-    Handle(Select3D_SensitivePoly) aPlanarPolyg = new Select3D_SensitivePoly (theOwnerId,
-                                                                              aPointsArray,
-                                                                              Standard_False);
-    myPlanarPolygons.Append (aPlanarPolyg);
-  }
-
-  myPolygonsIdxs = new TColStd_HArray1OfInteger (0, myPlanarPolygons.Length() - 1);
-  for (Standard_Integer aIdx = 0; aIdx < myPlanarPolygons.Length(); ++aIdx)
-  {
-    myPolygonsIdxs->SetValue (aIdx, aIdx);
-  }
-
-  myCOG = aPntSum / thePoints.Length();
-  myBndBox = aBndBox;
-}
-
-// =======================================================================
-// function : Select3D_InteriorSensitivePointSet
-// purpose  : Splits the given point set thePoints onto planar convex
-//            polygons
-// =======================================================================
-Select3D_InteriorSensitivePointSet::Select3D_InteriorSensitivePointSet (const Handle(SelectBasics_EntityOwner)& theOwnerId,
-                                                                        const Handle(TColgp_HArray1OfPnt)& thePoints)
-  : Select3D_SensitiveSet (theOwnerId)
-{
-  Select3D_Plane aPlane;
-  Standard_Integer aLowerIdx = thePoints->Lower();
-  Standard_Integer anUpperIdx = thePoints->Upper();
   Standard_Integer aStartIdx = aLowerIdx, anEndIdx = 0;
   Select3D_BndBox3d aBndBox;
   gp_XYZ aPntSum (0.0, 0.0, 0.0);
   for (Standard_Integer aPntIter = aLowerIdx; aPntIter <= anUpperIdx; ++aPntIter)
   {
     gp_Pnt aPnt1, aPnt2;
-    const gp_Pnt& aPnt3 = thePoints->Value (aPntIter);
+    const gp_Pnt& aPnt3 = thePoints.Value (aPntIter);
     aPntSum += aPnt3.XYZ();
     SelectMgr_Vec3 aCurrPnt (aPnt3.X(), aPnt3.Y(), aPnt3.Z());
     aBndBox.Add (aCurrPnt);
     if (aPntIter - aLowerIdx >= 2)
     {
-      aPnt1 = thePoints->Value (aPntIter - 2);
-      aPnt2 = thePoints->Value (aPntIter - 1);
+      aPnt1 = thePoints.Value (aPntIter - 2);
+      aPnt2 = thePoints.Value (aPntIter - 1);
     }
     if (aPntIter - aStartIdx == 2 && !aPlane.IsValid())
     {
       aPlane.MakePlane (aPnt1, aPnt2, aPnt3);
       aStartIdx = aPntIter - 2;
       anEndIdx = aPntIter;
+
+      if (anEndIdx == anUpperIdx)
+      {
+        Handle (TColgp_HArray1OfPnt) aPointsArray = new TColgp_HArray1OfPnt (0, anEndIdx - aStartIdx);
+        for (Standard_Integer aIdx = aStartIdx; aIdx <= anEndIdx; ++aIdx)
+        {
+          aPointsArray->SetValue (aIdx - aStartIdx, thePoints.Value(aIdx));
+        }
+        Handle(Select3D_SensitivePoly) aPlanarPolyg = new Select3D_SensitivePoly (theOwnerId,
+                                                                                 aPointsArray,
+                                                                                 Standard_False);
+        myPlanarPolygons.Append (aPlanarPolyg);
+      }
     }
     else if (aPlane.IsValid())
     {
       const gp_XYZ& aVec1 = aPnt1.XYZ() - aPnt2.XYZ();
       const gp_XYZ& aVec2 = aPnt3.XYZ() - aPnt2.XYZ();
       Standard_Real anAngle = aVec1.Dot (aVec2);
-      if (!aPlane.Contains (thePoints->Value (aPntIter)) || anAngle > Precision::Confusion())
+      if (!aPlane.Contains (thePoints.Value (aPntIter)) || anAngle > Precision::Confusion())
       {
         // subtract 1 due to indexation from zero in sub-polygons
         Standard_Integer anUpperBound = aPntIter - aStartIdx - 1;
         Handle (TColgp_HArray1OfPnt) aPointsArray = new TColgp_HArray1OfPnt (0, anUpperBound);
         for (Standard_Integer aIdx = aStartIdx; aIdx <= aStartIdx + anUpperBound; ++aIdx)
         {
-          aPointsArray->SetValue (aIdx - aStartIdx, thePoints->Value (aIdx));
+          aPointsArray->SetValue (aIdx - aStartIdx, thePoints.Value (aIdx));
         }
         Handle(Select3D_SensitivePoly) aPlanarPolyg = new Select3D_SensitivePoly (theOwnerId,
                                                                                   aPointsArray,
@@ -241,7 +150,7 @@ Select3D_InteriorSensitivePointSet::Select3D_InteriorSensitivePointSet (const Ha
           Handle (TColgp_HArray1OfPnt) aPointsArray = new TColgp_HArray1OfPnt (0, anEndIdx - aStartIdx);
           for (Standard_Integer aIdx = aStartIdx; aIdx <= anEndIdx; ++aIdx)
           {
-            aPointsArray->SetValue (aIdx - aStartIdx, thePoints->Value (aIdx));
+            aPointsArray->SetValue (aIdx - aStartIdx, thePoints.Value (aIdx));
           }
           Handle(Select3D_SensitivePoly) aPlanarPolyg = new Select3D_SensitivePoly (theOwnerId,
                                                                                     aPointsArray,
@@ -252,14 +161,14 @@ Select3D_InteriorSensitivePointSet::Select3D_InteriorSensitivePointSet (const Ha
     }
   }
 
+  myCOG = aPntSum / thePoints.Length();
+  myBndBox = aBndBox;
+
   myPolygonsIdxs = new TColStd_HArray1OfInteger (0, myPlanarPolygons.Length() - 1);
   for (Standard_Integer aIdx = 0; aIdx < myPlanarPolygons.Length(); ++aIdx)
   {
     myPolygonsIdxs->SetValue (aIdx, aIdx);
   }
-
-  myCOG = aPntSum / thePoints->Length();
-  myBndBox = aBndBox;
 }
 
 // =======================================================================
index 2e1dab0..22df166 100644 (file)
@@ -45,10 +45,6 @@ public:
   Standard_EXPORT Select3D_InteriorSensitivePointSet (const Handle(SelectBasics_EntityOwner)& theOwnerId,
                                                       const TColgp_Array1OfPnt& thePoints);
 
-  //! Splits the given point set thePoints onto planar convex polygons
-  Standard_EXPORT Select3D_InteriorSensitivePointSet (const Handle(SelectBasics_EntityOwner)& theOwnerId,
-                                                      const Handle(TColgp_HArray1OfPnt)& thePoints);
-
   //! Checks whether the point set overlaps current selecting volume
   Standard_EXPORT virtual Standard_Boolean Matches (SelectBasics_SelectingVolumeManager& theMgr,
                                                     SelectBasics_PickResult& thePickResult) Standard_OVERRIDE;
index 5fdd578..630f6d1 100644 (file)
@@ -57,11 +57,11 @@ Select3D_SensitiveFace::Select3D_SensitiveFace (const Handle(SelectBasics_Entity
 {
   if (mySensType == Select3D_TOS_INTERIOR)
   {
-    myFacePoints = new Select3D_InteriorSensitivePointSet (theOwnerId, thePoints);
+    myFacePoints = new Select3D_InteriorSensitivePointSet (theOwnerId, thePoints->Array1());
   }
   else
   {
-    myFacePoints = new Select3D_BoundarySensitivePointSet (theOwnerId, thePoints);
+    myFacePoints = new Select3D_BoundarySensitivePointSet (theOwnerId, thePoints->Array1());
   }
 }