From: asuraven Date: Wed, 25 Aug 2021 09:23:13 +0000 (+0300) Subject: 0032539: Optimize vert/vert dist + throw to break X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=659af8b159c753321e5bcca41e3b23b79b9dda30;p=occt-copy.git 0032539: Optimize vert/vert dist + throw to break --- diff --git a/src/BRepExtrema/BRepExtrema_DistShapeShape.cxx b/src/BRepExtrema/BRepExtrema_DistShapeShape.cxx index 13245e7c9c..1e808bc591 100644 --- a/src/BRepExtrema/BRepExtrema_DistShapeShape.cxx +++ b/src/BRepExtrema/BRepExtrema_DistShapeShape.cxx @@ -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 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) { diff --git a/src/BRepExtrema/BRepExtrema_DistShapeShape.hxx b/src/BRepExtrema/BRepExtrema_DistShapeShape.hxx index 4337b4e934..ab1feae1a9 100644 --- a/src/BRepExtrema/BRepExtrema_DistShapeShape.hxx +++ b/src/BRepExtrema/BRepExtrema_DistShapeShape.hxx @@ -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;