From: asuraven Date: Thu, 26 Aug 2021 15:41:05 +0000 (+0300) Subject: 0032539: Optimize vertex dist X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=eca67a3669d46b8cc81d8c7d381e92920c27ea4c;p=occt-copy.git 0032539: Optimize vertex dist --- diff --git a/src/BRepExtrema/BRepExtrema_DistShapeShape.cxx b/src/BRepExtrema/BRepExtrema_DistShapeShape.cxx index aec844ff08..3d30c83c27 100644 --- a/src/BRepExtrema/BRepExtrema_DistShapeShape.cxx +++ b/src/BRepExtrema/BRepExtrema_DistShapeShape.cxx @@ -58,13 +58,13 @@ namespace } static void BoxCalculation(const TopTools_IndexedMapOfShape& Map, - Bnd_SeqOfBox& SBox) + std::vector& 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* theLBox1, + const std::vector* 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* myLBox1; + const std::vector* 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& theLBox1, + const std::vector& 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* theLBox1, + const std::vector* theLBox2, const Message_ProgressRange theRange, Standard_Boolean* theIsBreak, Standard_Boolean* theIsDone, @@ -445,8 +445,8 @@ struct DistanceTask const NCollection_Array1* myArray; const TopTools_IndexedMapOfShape* myMap1; const TopTools_IndexedMapOfShape* myMap2; - const Bnd_SeqOfBox* myLBox1; - const Bnd_SeqOfBox* myLBox2; + const std::vector* myLBox1; + const std::vector* 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& theLBox1, + const std::vector& theLBox2, const Message_ProgressRange& theRange) { NCollection_Vector 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); diff --git a/src/BRepExtrema/BRepExtrema_DistShapeShape.hxx b/src/BRepExtrema/BRepExtrema_DistShapeShape.hxx index 340f564b48..1c3ef06bb9 100644 --- a/src/BRepExtrema/BRepExtrema_DistShapeShape.hxx +++ b/src/BRepExtrema/BRepExtrema_DistShapeShape.hxx @@ -29,6 +29,8 @@ #include #include +#include + //! This class provides tools to compute minimum distance
//! between two Shapes (Compound,CompSolid, Solid, Shell, Face, Wire, Edge, Vertex).
class BRepExtrema_DistShapeShape @@ -154,15 +156,15 @@ private: //! computes the minimum distance between two maps of shapes (Face,Edge,Vertex)
Standard_EXPORT void DistanceMapMap(const TopTools_IndexedMapOfShape& Map1, const TopTools_IndexedMapOfShape& Map2, - const Bnd_SeqOfBox& LBox1, - const Bnd_SeqOfBox& LBox2, + const std::vector& LBox1, + const std::vector& 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& theLBox1, + const std::vector& 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 myBV1; + std::vector myBV2; + std::vector myBE1; + std::vector myBE2; + std::vector myBF1; + std::vector myBF2; Standard_Boolean myIsBreak; mutable Handle(Standard_HMutex) myMutex;