]> OCCT Git - occt-copy.git/commitdiff
0032539: Optimize vertex dist
authorasuraven <andrey.suravenkov@opencascade.com>
Thu, 26 Aug 2021 15:41:05 +0000 (18:41 +0300)
committerasuraven <andrey.suravenkov@opencascade.com>
Mon, 30 Aug 2021 13:00:58 +0000 (16:00 +0300)
src/BRepExtrema/BRepExtrema_DistShapeShape.cxx
src/BRepExtrema/BRepExtrema_DistShapeShape.hxx

index aec844ff0817621d240182fcbaedaf6230e7f6f2..3d30c83c270cebc826c98a8cf859174be63964ad 100644 (file)
@@ -58,13 +58,13 @@ namespace
   }
 
   static void BoxCalculation(const TopTools_IndexedMapOfShape& Map,
-                             Bnd_SeqOfBox&                     SBox)
+                             std::vector<Bnd_Box>&             SBox)
   {
     for (Standard_Integer i = 1; i <= Map.Extent(); i++)
     {
       Bnd_Box box;
       BRepBndLib::Add(Map(i), box);
-      SBox.Append(box);
+      SBox.push_back(box);
     }
   }
 
@@ -117,8 +117,8 @@ struct VertexTask
              BRepExtrema_SeqOfSolution* theSolutionsShape2,
              const TopTools_IndexedMapOfShape* theMap1,
              const TopTools_IndexedMapOfShape* theMap2,
-             const Bnd_SeqOfBox* theLBox1,
-             const Bnd_SeqOfBox* theLBox2,
+             const std::vector<Bnd_Box>* theLBox1,
+             const std::vector<Bnd_Box>* theLBox2,
              const Message_ProgressRange theRange,
              Standard_Boolean* theIsBreak,
              Standard_Real* theDistRef,
@@ -180,8 +180,8 @@ struct VertexTask
   BRepExtrema_SeqOfSolution* mySolutionsShape2;
   const TopTools_IndexedMapOfShape* myMap1;
   const TopTools_IndexedMapOfShape* myMap2;
-  const Bnd_SeqOfBox* myLBox1;
-  const Bnd_SeqOfBox* myLBox2;
+  const std::vector<Bnd_Box>* myLBox1;
+  const std::vector<Bnd_Box>* myLBox2;
   Message_ProgressRange myRange;
   Standard_Boolean* myIsBreak;
   Standard_Real* myDistRef;
@@ -202,6 +202,12 @@ struct VertexFunctor
 
     Message_ProgressScope aScope(theTask.myRange, NULL, aCount1);
 
+    Standard_Real aDistRef(0);
+    {
+      Standard_Mutex::Sentry aLock(theTask.myMutex.get());
+      aDistRef = *theTask.myDistRef;
+    }
+
     for (Standard_Integer anIdx1 = theTask.myFirtsIndex; anIdx1 <= theTask.myLastIndex; ++anIdx1)
     {
       if (!aScope.More())
@@ -216,21 +222,15 @@ struct VertexFunctor
 
       for (Standard_Integer anIdx2 = 1; anIdx2 <= aCount2; ++anIdx2)
       {
-        const Bnd_Box& aBox1 = theTask.myLBox1->Value(anIdx1);
-        const Bnd_Box& aBox2 = theTask.myLBox2->Value(anIdx2);
-        if (aBox1.IsVoid()
-            || aBox2.IsVoid())
+        const Bnd_Box& aBox1 = theTask.myLBox1->at(anIdx1-1);
+        const Bnd_Box& aBox2 = theTask.myLBox2->at(anIdx2-1);
+        if (aBox1.IsVoid() || aBox2.IsVoid())
         {
           continue;
         }
         const TopoDS_Shape& aShape1 = theTask.myMap1->FindKey(anIdx1);
         const TopoDS_Shape& aShape2 = theTask.myMap2->FindKey(anIdx2);
 
-        Standard_Real aDistRef(0);
-        {
-          Standard_Mutex::Sentry aLock(theTask.myMutex.get());
-          aDistRef = *theTask.myDistRef;
-        }
         BRepExtrema_DistanceSS aDistTool(aShape1, aShape2, aBox1, aBox2, aDistRef, theTask.myEps);
         if (aDistTool.IsDone())
         {
@@ -261,6 +261,7 @@ struct VertexFunctor
               *theTask.myDistRef = aDistTool.DistValue();
             }
           }
+          aDistRef = *theTask.myDistRef;
         }
       }
     }
@@ -273,8 +274,8 @@ struct VertexFunctor
 
 void BRepExtrema_DistShapeShape::DistanceVertVert(const TopTools_IndexedMapOfShape& theMap1,
                                                   const TopTools_IndexedMapOfShape& theMap2,
-                                                  const Bnd_SeqOfBox& theLBox1,
-                                                  const Bnd_SeqOfBox& theLBox2,
+                                                  const std::vector<Bnd_Box>& theLBox1,
+                                                  const std::vector<Bnd_Box>& theLBox2,
                                                   const Message_ProgressRange& theRange)
 {
   const Standard_Integer aCount1 = theMap1.Extent();
@@ -293,10 +294,9 @@ void BRepExtrema_DistShapeShape::DistanceVertVert(const TopTools_IndexedMapOfSha
       }
       for (Standard_Integer anIdx2 = 1; anIdx2 <= aCount2; ++anIdx2)
       {
-        const Bnd_Box& aBox1 = theLBox1.Value(anIdx1);
-        const Bnd_Box& aBox2 = theLBox2.Value(anIdx2);
-        if (aBox1.IsVoid()
-            || aBox2.IsVoid())
+        const Bnd_Box& aBox1 = theLBox1[anIdx1];
+        const Bnd_Box& aBox2 = theLBox2[anIdx2];
+        if (aBox1.IsVoid() || aBox2.IsVoid())
         {
           continue;
         }
@@ -382,8 +382,8 @@ struct DistanceTask
                BRepExtrema_SeqOfSolution* theSolutionsShape2,
                const TopTools_IndexedMapOfShape* theMap1,
                const TopTools_IndexedMapOfShape* theMap2,
-               const Bnd_SeqOfBox* theLBox1,
-               const Bnd_SeqOfBox* theLBox2,
+               const std::vector<Bnd_Box>* theLBox1,
+               const std::vector<Bnd_Box>* theLBox2,
                const Message_ProgressRange theRange,
                Standard_Boolean* theIsBreak,
                Standard_Boolean* theIsDone,
@@ -445,8 +445,8 @@ struct DistanceTask
   const NCollection_Array1<BRepExtrema_CheckPair>* myArray;
   const TopTools_IndexedMapOfShape* myMap1;
   const TopTools_IndexedMapOfShape* myMap2;
-  const Bnd_SeqOfBox* myLBox1;
-  const Bnd_SeqOfBox* myLBox2;
+  const std::vector<Bnd_Box>* myLBox1;
+  const std::vector<Bnd_Box>* myLBox2;
   Message_ProgressRange myRange;
   Standard_Boolean* myIsBreak;
   Standard_Boolean* myIsDone;
@@ -487,8 +487,8 @@ struct DistanceFunctor
         }
       }
 
-      const Bnd_Box& aBox1 = theTask.myLBox1->Value(aPair.Index1);
-      const Bnd_Box& aBox2 = theTask.myLBox2->Value(aPair.Index2);
+      const Bnd_Box& aBox1 = theTask.myLBox1->at(aPair.Index1-1);
+      const Bnd_Box& aBox2 = theTask.myLBox2->at(aPair.Index2-1);
 
       const TopoDS_Shape& aShape1 = theTask.myMap1->FindKey(aPair.Index1);
       const TopoDS_Shape& aShape2 = theTask.myMap2->FindKey(aPair.Index2);
@@ -535,8 +535,8 @@ struct DistanceFunctor
 
 void BRepExtrema_DistShapeShape::DistanceMapMap (const TopTools_IndexedMapOfShape& theMap1,
                                                  const TopTools_IndexedMapOfShape& theMap2,
-                                                 const Bnd_SeqOfBox&               theLBox1,
-                                                 const Bnd_SeqOfBox&               theLBox2,
+                                                 const std::vector<Bnd_Box>&       theLBox1,
+                                                 const std::vector<Bnd_Box>&       theLBox2,
                                                  const Message_ProgressRange&      theRange)
 {
   NCollection_Vector<BRepExtrema_CheckPair> aPairList;
@@ -556,10 +556,9 @@ void BRepExtrema_DistShapeShape::DistanceMapMap (const TopTools_IndexedMapOfShap
     }
     for (Standard_Integer anIdx2 = 1; anIdx2 <= aCount2; ++anIdx2)
     {
-      const Bnd_Box& aBox1 = theLBox1.Value (anIdx1);
-      const Bnd_Box& aBox2 = theLBox2.Value (anIdx2);
-      if (aBox1.IsVoid()
-       || aBox2.IsVoid())
+      const Bnd_Box& aBox1 = theLBox1[anIdx1-1];
+      const Bnd_Box& aBox2 = theLBox2[anIdx2-1];
+      if (aBox1.IsVoid() || aBox2.IsVoid())
       {
         continue;
       }
@@ -591,8 +590,8 @@ void BRepExtrema_DistShapeShape::DistanceMapMap (const TopTools_IndexedMapOfShap
         break; // early search termination
       }
 
-      const Bnd_Box& aBox1 = theLBox1.Value(aPair.Index1);
-      const Bnd_Box& aBox2 = theLBox2.Value(aPair.Index2);
+      const Bnd_Box& aBox1 = theLBox1[aPair.Index1-1];
+      const Bnd_Box& aBox2 = theLBox2[aPair.Index2-1];
 
       const TopoDS_Shape& aShape1 = theMap1(aPair.Index1);
       const TopoDS_Shape& aShape2 = theMap2(aPair.Index2);
@@ -1033,9 +1032,9 @@ Standard_Boolean BRepExtrema_DistShapeShape::Perform(const Message_ProgressRange
     {
       if (!myIsInitS1) // rebuild cached data for 1st shape
       {
-        myBV1.Clear();
-        myBE1.Clear();
-        myBF1.Clear();
+        myBV1.clear();
+        myBE1.clear();
+        myBF1.clear();
 
         BoxCalculation (myMapV1, myBV1);
         BoxCalculation (myMapE1, myBE1);
@@ -1046,9 +1045,9 @@ Standard_Boolean BRepExtrema_DistShapeShape::Perform(const Message_ProgressRange
 
       if (!myIsInitS2) // rebuild cached data for 2nd shape
       {
-        myBV2.Clear();
-        myBE2.Clear();
-        myBF2.Clear();
+        myBV2.clear();
+        myBE2.clear();
+        myBF2.clear();
 
         BoxCalculation (myMapV2, myBV2);
         BoxCalculation (myMapE2, myBE2);
index 340f564b48f0ed7cfdc627ac182a89f7795d06d6..1c3ef06bb9a12dc3a2cdd940942c331e5914faba 100644 (file)
@@ -29,6 +29,8 @@
 #include <Standard_Mutex.hxx>
 #include <TopTools_IndexedMapOfShape.hxx>
 
+#include <vector>
+
 //! This class  provides tools to compute minimum distance <br>
 //! between two Shapes (Compound,CompSolid, Solid, Shell, Face, Wire, Edge, Vertex). <br>
 class BRepExtrema_DistShapeShape
@@ -154,15 +156,15 @@ private:
   //! computes the minimum distance between two maps of shapes (Face,Edge,Vertex) <br>
   Standard_EXPORT void DistanceMapMap(const TopTools_IndexedMapOfShape& Map1,
                                       const TopTools_IndexedMapOfShape& Map2,
-                                      const Bnd_SeqOfBox&               LBox1,
-                                      const Bnd_SeqOfBox&               LBox2,
+                                      const std::vector<Bnd_Box>&       LBox1,
+                                      const std::vector<Bnd_Box>&       LBox2,
                                       const Message_ProgressRange&      theRange);
 
   void DistanceVertVert(const TopTools_IndexedMapOfShape& theMap1,
                         const TopTools_IndexedMapOfShape& theMap2,
-                        const Bnd_SeqOfBox& theLBox1,
-                        const Bnd_SeqOfBox& theLBox2,
-                        const Message_ProgressRange& theRange);
+                        const std::vector<Bnd_Box>&       theLBox1,
+                        const std::vector<Bnd_Box>&       theLBox2,
+                        const Message_ProgressRange&      theRange);
 
   void SolidTreatment(const TopoDS_Shape& theShape,
                       const TopTools_IndexedMapOfShape& theMap,
@@ -199,12 +201,12 @@ private:
   Standard_Boolean myIsInitS2;
   Extrema_ExtFlag myFlag;
   Extrema_ExtAlgo myAlgo;
-  Bnd_SeqOfBox myBV1;
-  Bnd_SeqOfBox myBV2;
-  Bnd_SeqOfBox myBE1;
-  Bnd_SeqOfBox myBE2;
-  Bnd_SeqOfBox myBF1;
-  Bnd_SeqOfBox myBF2;
+  std::vector<Bnd_Box> myBV1;
+  std::vector<Bnd_Box> myBV2;
+  std::vector<Bnd_Box> myBE1;
+  std::vector<Bnd_Box> myBE2;
+  std::vector<Bnd_Box> myBF1;
+  std::vector<Bnd_Box> myBF2;
 
   Standard_Boolean myIsBreak;
   mutable Handle(Standard_HMutex) myMutex;