]> OCCT Git - occt-copy.git/commitdiff
0032539: Optimize vert/vert dist + throw to break
authorasuraven <andrey.suravenkov@opencascade.com>
Wed, 25 Aug 2021 09:23:13 +0000 (12:23 +0300)
committerasuraven <andrey.suravenkov@opencascade.com>
Mon, 30 Aug 2021 13:00:35 +0000 (16:00 +0300)
src/BRepExtrema/BRepExtrema_DistShapeShape.cxx
src/BRepExtrema/BRepExtrema_DistShapeShape.hxx

index 13245e7c9c776cc05ca714f611ac60827cfbcfcd..1e808bc5917441bc05cf7872df9aea3ec58a47b4 100644 (file)
@@ -111,6 +111,76 @@ namespace
 //purpose  : 
 //=======================================================================
 
+void BRepExtrema_DistShapeShape::DistanceVertVert(const TopTools_IndexedMapOfShape& theMap1,
+                                                  const TopTools_IndexedMapOfShape& theMap2,
+                                                  const Bnd_SeqOfBox& theLBox1,
+                                                  const Bnd_SeqOfBox& theLBox2,
+                                                  const Message_ProgressRange& theRange)
+{
+  NCollection_Vector<BRepExtrema_CheckPair> aPairList;
+  const Standard_Integer aCount1 = theMap1.Extent();
+  const Standard_Integer aCount2 = theMap2.Extent();
+
+  Message_ProgressScope aScope(theRange, NULL, aCount1);
+
+  for (Standard_Integer anIdx1 = 1; anIdx1 <= aCount1; ++anIdx1)
+  {
+    aScope.Next();
+    if (!aScope.More())
+    {
+      throw StdFail_NotDone();
+    }
+    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())
+      {
+        continue;
+      }
+      const TopoDS_Shape& aShape1 = theMap1.FindKey(anIdx1);
+      const TopoDS_Shape& aShape2 = theMap2.FindKey(anIdx1);
+
+      BRepExtrema_DistanceSS aDistTool(aShape1, aShape2, aBox1, aBox2, myDistRef, myEps);
+      if (aDistTool.IsDone())
+      {
+        if (aDistTool.DistValue() < myDistRef - myEps)
+        {
+          mySolutionsShape1.Clear();
+          mySolutionsShape2.Clear();
+
+          BRepExtrema_SeqOfSolution aSeq1 = aDistTool.Seq1Value();
+          BRepExtrema_SeqOfSolution aSeq2 = aDistTool.Seq2Value();
+
+          mySolutionsShape1.Append(aSeq1);
+          mySolutionsShape2.Append(aSeq2);
+
+          myDistRef = aDistTool.DistValue();
+        }
+        else if (fabs(aDistTool.DistValue() - myDistRef) < myEps)
+        {
+          BRepExtrema_SeqOfSolution aSeq1 = aDistTool.Seq1Value();
+          BRepExtrema_SeqOfSolution aSeq2 = aDistTool.Seq2Value();
+
+          mySolutionsShape1.Append(aSeq1);
+          mySolutionsShape2.Append(aSeq2);
+
+          if (myDistRef > aDistTool.DistValue())
+          {
+            myDistRef = aDistTool.DistValue();
+          }
+        }
+      }
+    }
+  }
+}
+
+//=======================================================================
+//function : DistanceMapMap
+//purpose  : 
+//=======================================================================
+
 void BRepExtrema_DistShapeShape::DistanceMapMap (const TopTools_IndexedMapOfShape& theMap1,
                                                  const TopTools_IndexedMapOfShape& theMap2,
                                                  const Bnd_SeqOfBox&               theLBox1,
@@ -306,13 +376,13 @@ void BRepExtrema_DistShapeShape::LoadS2 (const TopoDS_Shape& Shape2)
 //purpose  : 
 //=======================================================================
 void BRepExtrema_DistShapeShape::SolidTreatmentOne(const TopoDS_Shape& theShape,
-                                                   const TopTools_IndexedMapOfShape& theMap,
-                                                   const Message_ProgressRange& theRange
+                                                   const TopTools_IndexedMapOfShape& theVertexMap,
+                                                   const Message_ProgressRange& theRange)
 {
   BRepClass3d_SolidClassifier aClassifier(theShape);
   const Standard_Real aTolerance = 0.001;
-  Message_ProgressScope aScope(theRange, NULL, theMap.Extent());
-  for (Standard_Integer i = 1; i < theMap.Extent(); ++i)
+  Message_ProgressScope aScope(theRange, NULL, theVertexMap.Extent());
+  for (Standard_Integer i = 1; i < theVertexMap.Extent(); ++i)
   {
     Message_ProgressRange aRange = aScope.Next();
     if (!aScope.More())
@@ -429,9 +499,9 @@ struct TreatmentFunctor
 //function : SolidTreatmentMulty
 //purpose  : 
 //=======================================================================
-Standard_Boolean BRepExtrema_DistShapeShape::SolidTreatmentMulty(const TopoDS_Shape& theShape,
-                                                                 const TopTools_IndexedMapOfShape& theVertexMap,
-                                                                 const Message_ProgressRange& theRange)
+void BRepExtrema_DistShapeShape::SolidTreatmentMulty(const TopoDS_Shape& theShape,
+                                                     const TopTools_IndexedMapOfShape& theVertexMap,
+                                                     const Message_ProgressRange& theRange)
 {
   const Standard_Integer aMapSize = theVertexMap.Extent();
   const Standard_Integer aMinTaskSize = 3;
@@ -475,7 +545,7 @@ Standard_Boolean BRepExtrema_DistShapeShape::SolidTreatmentMulty(const TopoDS_Sh
 
   if (myIsBreak)
   {
-    return Standard_False;
+    throw StdFail_NotDone();
   }
 
   if (myInnerSol)
@@ -488,25 +558,23 @@ Standard_Boolean BRepExtrema_DistShapeShape::SolidTreatmentMulty(const TopoDS_Sh
     mySolutionsShape1.Append(aTaskArray[anI].mySolutionsShape);
     mySolutionsShape2.Append(aTaskArray[anI].mySolutionsShape);
   }
-
-  return Standard_True;
 }
 //=======================================================================
 //function : SolidTreatment
 //purpose  : 
 //=======================================================================
-Standard_Boolean BRepExtrema_DistShapeShape::SolidTreatment(const TopoDS_Shape& theShape,
-                                                            const TopTools_IndexedMapOfShape& theVertexMap,
-                                                            const Message_ProgressRange& theRange,
-                                                            const Standard_Boolean theIsMultiThread)
+void BRepExtrema_DistShapeShape::SolidTreatment(const TopoDS_Shape& theShape,
+                                                const TopTools_IndexedMapOfShape& theVertexMap,
+                                                const Message_ProgressRange& theRange,
+                                                const Standard_Boolean theIsMultiThread)
 {
   if (theIsMultiThread)
   {
-    return SolidTreatmentMulty(theShape, theVertexMap, theRange);
+    SolidTreatmentMulty(theShape, theVertexMap, theRange);
   }
   else
   {
-    return SolidTreatmentOne(theShape, theVertexMap, theRange);
+    SolidTreatmentOne(theShape, theVertexMap, theRange);
   }
 }
 
@@ -542,12 +610,12 @@ Standard_Boolean BRepExtrema_DistShapeShape::Perform(const Message_ProgressRange
   {
     if (anIsSolid1)
     {
-      SolidTreatment(myShape1, myMapV2, aRootScope.Next(), theIsMultiThread));
+      SolidTreatment(myShape1, myMapV2, aRootScope.Next(), theIsMultiThread);
     }
 
-    if (anIsSolid2 && (!myInnerSol))
+  if (anIsSolid2 && (!myInnerSol))
   {
-      SolidTreatment(myShape2, myMapV1, aRootScope.Next(), theIsMultiThread));
+      SolidTreatment(myShape2, myMapV1, aRootScope.Next(), theIsMultiThread);
     }
 
   if (!myInnerSol)
@@ -587,14 +655,14 @@ Standard_Boolean BRepExtrema_DistShapeShape::Perform(const Message_ProgressRange
     else
       myDistRef= 1.e30; //szv:!!!
 
-      DistanceMapMap (myMapV1, myMapV2, myBV1, myBV2, aRootScope.Next());
-      DistanceMapMap (myMapV1, myMapE2, myBV1, myBE2, aRootScope.Next());
-      DistanceMapMap (myMapE1, myMapV2, myBE1, myBV2, aRootScope.Next());
-      DistanceMapMap (myMapV1, myMapF2, myBV1, myBF2, aRootScope.Next());
-      DistanceMapMap (myMapF1, myMapV2, myBF1, myBV2, aRootScope.Next());
-      DistanceMapMap (myMapE1, myMapE2, myBE1, myBE2, aRootScope.Next());
-      DistanceMapMap (myMapE1, myMapF2, myBE1, myBF2, aRootScope.Next());
-      DistanceMapMap (myMapF1, myMapE2, myBF1, myBE2, aRootScope.Next());
+    DistanceVertVert(myMapV1, myMapV2, myBV1, myBV2, aRootScope.Next());
+    DistanceMapMap (myMapV1, myMapE2, myBV1, myBE2, aRootScope.Next());
+    DistanceMapMap (myMapE1, myMapV2, myBE1, myBV2, aRootScope.Next());
+    DistanceMapMap (myMapV1, myMapF2, myBV1, myBF2, aRootScope.Next());
+    DistanceMapMap (myMapF1, myMapV2, myBF1, myBV2, aRootScope.Next());
+    DistanceMapMap (myMapE1, myMapE2, myBE1, myBE2, aRootScope.Next());
+    DistanceMapMap (myMapE1, myMapF2, myBE1, myBF2, aRootScope.Next());
+    DistanceMapMap (myMapF1, myMapE2, myBF1, myBE2, aRootScope.Next());
 
     if (fabs (myDistRef) > myEps)
     {
index 4337b4e934fe7e0c8b41e1bae8f9cac8c2b55394..ab1feae1a98801e6b04c6950b6960550c771e533 100644 (file)
@@ -157,18 +157,24 @@ private:
                                       const Bnd_SeqOfBox&               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);
+
   void SolidTreatment(const TopoDS_Shape& theShape,
                       const TopTools_IndexedMapOfShape& theMap,
                       const Message_ProgressRange& theRange,
                       const Standard_Boolean theIsMultiThread);
 
-  Standard_Boolean SolidTreatmentOne(const TopoDS_Shape& theShape,
-                                     const TopTools_IndexedMapOfShape& theVertexMap,
-                                     const Message_ProgressRange& theRange);
+  void SolidTreatmentOne(const TopoDS_Shape& theShape,
+                         const TopTools_IndexedMapOfShape& theVertexMap,
+                         const Message_ProgressRange& theRange);
 
-  Standard_Boolean SolidTreatmentMulty(const TopoDS_Shape& theShape,
-                                       const TopTools_IndexedMapOfShape& theVertexMap,
-                                       const Message_ProgressRange& theRange);
+  void SolidTreatmentMulty(const TopoDS_Shape& theShape,
+                           const TopTools_IndexedMapOfShape& theVertexMap,
+                           const Message_ProgressRange& theRange);
 private:
 
   Standard_Real myDistRef;