0032552: Modeling Algorithms - BRepExtrema_DistShapeShape algorithm consumes too...
authorasuraven <asuraven@opencascade.com>
Thu, 2 Sep 2021 10:59:04 +0000 (13:59 +0300)
committersmoskvin <smoskvin@opencascade.com>
Fri, 17 Sep 2021 17:07:40 +0000 (20:07 +0300)
Used a new BRepExtrema_DistShapeShape::DistanceVertVert() function to replace DistanceMapMap() to calculate vertex/vertex distance

src/BRepExtrema/BRepExtrema_DistShapeShape.cxx
src/BRepExtrema/BRepExtrema_DistShapeShape.hxx

index be13543..dcd92f2 100644 (file)
@@ -147,7 +147,6 @@ Standard_Boolean BRepExtrema_DistShapeShape::DistanceMapMap (const TopTools_Inde
       }
     }
   }
-
   std::stable_sort(aPairList.begin(), aPairList.end(), BRepExtrema_CheckPair_Comparator);
   Message_ProgressRange aDistRange(aTwinScope.Next(0.7));
   Message_ProgressScope aDistScope(aDistRange, NULL, aPairList.Size());
@@ -205,6 +204,64 @@ Standard_Boolean BRepExtrema_DistShapeShape::DistanceMapMap (const TopTools_Inde
   return Standard_True;
 }
 
+//=======================================================================
+//function : DistanceVertVert
+//purpose  : 
+//=======================================================================
+
+Standard_Boolean BRepExtrema_DistShapeShape::DistanceVertVert(const TopTools_IndexedMapOfShape& theMap1,
+                                                              const TopTools_IndexedMapOfShape& theMap2,
+                                                              const Message_ProgressRange& theRange)
+{
+  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())
+    {
+      return Standard_False;
+    }
+    const TopoDS_Vertex& aVertex1 = TopoDS::Vertex(theMap1.FindKey(anIdx1));
+    const gp_Pnt aPoint1 = BRep_Tool::Pnt(aVertex1);
+    for (Standard_Integer anIdx2 = 1; anIdx2 <= aCount2; ++anIdx2)
+    {
+      const TopoDS_Vertex& aVertex2 = TopoDS::Vertex(theMap2.FindKey(anIdx2));
+      const gp_Pnt aPoint2 = BRep_Tool::Pnt(aVertex2);
+
+      const Standard_Real aDist = aPoint1.Distance(aPoint2);
+      if (aDist < myDistRef - myEps)
+      {
+        mySolutionsShape1.Clear();
+        mySolutionsShape2.Clear();
+
+        const BRepExtrema_SolutionElem Sol1(aDist, aPoint1, BRepExtrema_IsVertex, aVertex1);
+        const BRepExtrema_SolutionElem Sol2(aDist, aPoint2, BRepExtrema_IsVertex, aVertex2);
+        mySolutionsShape1.Append(Sol1);
+        mySolutionsShape2.Append(Sol2);
+
+        myDistRef = aDist;
+      }
+      else if (fabs(aDist - myDistRef) < myEps)
+      {
+        const BRepExtrema_SolutionElem Sol1(aDist, aPoint1, BRepExtrema_IsVertex, aVertex1);
+        const BRepExtrema_SolutionElem Sol2(aDist, aPoint2, BRepExtrema_IsVertex, aVertex2);
+        mySolutionsShape1.Append(Sol1);
+        mySolutionsShape2.Append(Sol2);
+
+        if (myDistRef > aDist)
+        {
+          myDistRef = aDist;
+        }
+      }
+    }
+  }
+  return Standard_True;
+}
+
 //=======================================================================
 //function : BRepExtrema_DistShapeShape
 //purpose  : 
@@ -408,7 +465,7 @@ Standard_Boolean BRepExtrema_DistShapeShape::Perform(const Message_ProgressRange
     else
       myDistRef= 1.e30; //szv:!!!
 
-    if(!DistanceMapMap (myMapV1, myMapV2, myBV1, myBV2, aRootScope.Next()))
+    if(!DistanceVertVert(myMapV1, myMapV2, aRootScope.Next()))
     {
       return Standard_False;
     }
index 797a4e9..8b3450e 100644 (file)
@@ -154,6 +154,11 @@ private:
                                   const Bnd_SeqOfBox&               LBox2,
                                   const Message_ProgressRange&      theRange);
 
+  //! computes the minimum distance between two maps of vertices <br>
+  Standard_Boolean DistanceVertVert(const TopTools_IndexedMapOfShape& theMap1,
+                                    const TopTools_IndexedMapOfShape& theMap2,
+                                    const Message_ProgressRange& theRange);
+
   Standard_Boolean SolidTreatment(const TopoDS_Shape& theShape,
                                   const TopTools_IndexedMapOfShape& theMap,
                                   const Message_ProgressRange& theRange);