From cf8e963aff8d573e14984a130ac34f52dd848f33 Mon Sep 17 00:00:00 2001 From: bugmaster <> Date: Wed, 17 Aug 2011 08:30:24 +0000 Subject: [PATCH] 0022653: Bad performance of Open CASCADE libraries that are used by Partition Algorithm Devekoped by : PKV --- src/IntTools/IntTools_Context.cxx | 69 +++++++++--------- src/IntTools/IntTools_Tools.cxx | 69 ++++++++++++------ src/TCollection/TCollection_DataMap.cdl | 13 +++- src/TCollection/TCollection_DataMap.gxx | 68 ++++++++++++------ .../TCollection_IndexedDataMap.cdl | 15 +++- .../TCollection_IndexedDataMap.gxx | 72 ++++++++++++------- 6 files changed, 201 insertions(+), 105 deletions(-) diff --git a/src/IntTools/IntTools_Context.cxx b/src/IntTools/IntTools_Context.cxx index 75c0fa694a..710c60a1a9 100755 --- a/src/IntTools/IntTools_Context.cxx +++ b/src/IntTools/IntTools_Context.cxx @@ -108,8 +108,9 @@ { Standard_Address anAdr; IntTools_FClass2d* pFClass2d; - - if (!myFClass2dMap.Contains(aF)) { + // + anAdr=myFClass2dMap.FindFromKey1(aF); + if (!anAdr) { Standard_Real aTolF; TopoDS_Face aFF=aF; aFF.Orientation(TopAbs_FORWARD); @@ -122,8 +123,8 @@ } else { - anAdr=myFClass2dMap.FindFromKey(aF); - pFClass2d=(IntTools_FClass2d*)anAdr; + Standard_Address *pAdr=(Standard_Address *)anAdr; + pFClass2d=(IntTools_FClass2d*)*pAdr; } return *pFClass2d; @@ -136,8 +137,9 @@ { Standard_Address anAdr; GeomAPI_ProjectPointOnSurf* pProjPS; - - if (!myProjPSMap.Contains(aF)) { + // + anAdr=myProjPSMap.FindFromKey1(aF); + if (!anAdr) { Standard_Real Umin, Usup, Vmin, Vsup, anEpsT=1.e-12 ; BRepAdaptor_Surface aBAS; // @@ -157,8 +159,8 @@ } else { - anAdr=myProjPSMap.FindFromKey(aF); - pProjPS=(GeomAPI_ProjectPointOnSurf*)anAdr; + Standard_Address *pAdr=(Standard_Address *)anAdr; + pProjPS=(GeomAPI_ProjectPointOnSurf*)*pAdr; } return *pProjPS; } @@ -170,8 +172,9 @@ { Standard_Address anAdr; GeomAPI_ProjectPointOnCurve* pProjPC; - - if (!myProjPCMap.Contains(aE)) { + // + anAdr=myProjPCMap.FindFromKey1(aE); + if (!anAdr) { Standard_Real f, l; // Handle(Geom_Curve)aC3D=BRep_Tool::Curve (aE, f, l); @@ -182,10 +185,9 @@ anAdr=(Standard_Address)pProjPC; myProjPCMap.Add(aE, anAdr); } - else { - anAdr=myProjPCMap.FindFromKey(aE); - pProjPC=(GeomAPI_ProjectPointOnCurve*)anAdr; + Standard_Address *pAdr=(Standard_Address *)anAdr; + pProjPC=(GeomAPI_ProjectPointOnCurve*)*pAdr; } return *pProjPC; } @@ -198,8 +200,9 @@ { Standard_Address anAdr; GeomAPI_ProjectPointOnCurve* pProjPT; - - if (!myProjPTMap.Contains(aC3D)) { + // + anAdr=myProjPTMap.FindFromKey1(aC3D); + if (!anAdr) { Standard_Real f, l; f=aC3D->FirstParameter(); l=aC3D->LastParameter(); @@ -212,8 +215,8 @@ } else { - anAdr=myProjPTMap.FindFromKey(aC3D); - pProjPT=(GeomAPI_ProjectPointOnCurve*)anAdr; + Standard_Address *pAdr=(Standard_Address *)anAdr; + pProjPT=(GeomAPI_ProjectPointOnCurve*)*pAdr; } return *pProjPT; } @@ -225,8 +228,9 @@ { Standard_Address anAdr; IntTools_SurfaceRangeLocalizeData* pSData; - - if (!myProjSDataMap.Contains(aF)) { + // + anAdr=myProjSDataMap.FindFromKey1(aF); + if (!anAdr) { // pSData=new IntTools_SurfaceRangeLocalizeData(3, 3, @@ -238,8 +242,8 @@ } else { - anAdr=myProjSDataMap.FindFromKey(aF); - pSData=(IntTools_SurfaceRangeLocalizeData*)anAdr; + Standard_Address *pAdr=(Standard_Address *)anAdr; + pSData=(IntTools_SurfaceRangeLocalizeData*)*pAdr; } return *pSData; @@ -252,24 +256,21 @@ { Standard_Address anAdr; BRepClass3d_SolidClassifier* pSC; - - if (!mySClassMap.Contains(aSolid)) { + // + anAdr=mySClassMap.FindFromKey1(aSolid); + if (!anAdr) { // pSC=new BRepClass3d_SolidClassifier(aSolid); // anAdr=(Standard_Address)pSC; mySClassMap.Add(aSolid, anAdr); } - else { - anAdr=mySClassMap.FindFromKey(aSolid); - pSC =(BRepClass3d_SolidClassifier*)anAdr; + Standard_Address *pAdr=(Standard_Address *)anAdr; + pSC =(BRepClass3d_SolidClassifier*)*pAdr; } return *pSC; } - - -//modified by NIZNHY-PKV Tue Feb 2 08:33:16 2010f //======================================================================= //function : ComputeVE //purpose : @@ -302,9 +303,12 @@ if (BRep_Tool::Degenerated(aE2)) { return -1; } - if (!BRep_Tool::IsGeometric(aE2)) { - return -2; - } + // + //modified by NIZNHY-PKV Wed Jul 13 08:30:08 2011f + //if (!BRep_Tool::IsGeometric(aE2)) { + // return -2; + //} + //modified by NIZNHY-PKV Wed Jul 13 08:30:13 2011t // Standard_Real aTolV1, aTolE2, aTolSum, aTolVx; Standard_Integer aNbProj; @@ -337,7 +341,6 @@ // return 0; } -//modified by NIZNHY-PKV Tue Feb 2 08:33:21 2010t //======================================================================= //function : ComputeVS //purpose : diff --git a/src/IntTools/IntTools_Tools.cxx b/src/IntTools/IntTools_Tools.cxx index ea9bec1f49..d416fc9e12 100755 --- a/src/IntTools/IntTools_Tools.cxx +++ b/src/IntTools/IntTools_Tools.cxx @@ -83,25 +83,34 @@ static //======================================================================= Standard_Boolean IntTools_Tools::IsClosed (const Handle(Geom_Curve)& aC3D) { - - Standard_Real aF, aL, aDist; + Standard_Boolean bRet; + Standard_Real aF, aL, aDist, aPC; gp_Pnt aP1, aP2; - + Handle (Geom_BoundedCurve) aGBC= Handle (Geom_BoundedCurve)::DownCast(aC3D); if (aGBC.IsNull()) { return Standard_False; } - + aF=aC3D->FirstParameter(); aL=aC3D-> LastParameter(); aC3D->D0(aF, aP1); aC3D->D0(aL, aP2); - aDist=aP1.Distance(aP2); - //return (aDist < 1.e-12); - return (aDist < Precision::Confusion()); + + // + //modified by NIZNHY-PKV Mon Jul 04 11:58:23 2011f + aPC=Precision::Confusion(); + aPC=aPC*aPC; + aDist=aP1.SquareDistance(aP2); + bRet=aDistFirstParameter(); aL=aC3D->LastParameter(); aMid=0.5*(aF+aL); - //modified by NIZNHY-PKV Thu Feb 5 08:26:58 2009 f GeomAdaptor_Curve aGAC(aC3D); GeomAbs_CurveType aCT=aGAC.GetType(); if (aCT==GeomAbs_BSplineCurve || @@ -226,7 +234,6 @@ static //aMid=0.5*aMid; aMid=IntTools_Tools::IntermediatePoint(aF, aL); } - //modified by NIZNHY-PKV Thu Feb 5 08:27:00 2009 t // Handle(Geom_Curve) aC3DNewF, aC3DNewL; aC3DNewF =new Geom_TrimmedCurve (aC3D, aF, aMid); @@ -278,20 +285,26 @@ static const Standard_Real aTolPV, const TopoDS_Vertex& aV) { + Standard_Boolean bRet; Standard_Real aTolV, aD, dTol; gp_Pnt aPv; aTolV=BRep_Tool::Tolerance(aV); // - //modified by NIZNHY-PKV Thu Jan 18 17:44:46 2007f - //aTolV=aTolV+aTolPV; dTol=Precision::Confusion(); aTolV=aTolV+aTolPV+dTol; - //modified by NIZNHY-PKV Thu Jan 18 17:44:49 2007t // aPv=BRep_Tool::Pnt(aV); - aD=aPv.Distance(aP); - return (aD<=aTolV); + // + //modified by NIZNHY-PKV Mon Jul 04 12:00:37 2011f + aD=aPv.SquareDistance(aP); + aTolV=aTolV*aTolV; + bRet=(aD<=aTolV); + return bRet; + // + //aD=aPv.Distance(aP); + //return (aD<=aTolV); + //modified by NIZNHY-PKV Mon Jul 04 12:00:40 2011t } @@ -390,11 +403,14 @@ static aTolV1=BRep_Tool::Tolerance(aV1); aTolV2=BRep_Tool::Tolerance(aV2); aTolSum=aTolV1+aTolV2; - + aP1=BRep_Tool::Pnt(aV1); aP2=BRep_Tool::Pnt(aV2); - - d=aP1.Distance(aP2); + //modified by NIZNHY-PKV Mon Jul 04 11:55:52 2011f + aTolSum=aTolSum*aTolSum; + d=aP1.SquareDistance(aP2); + //d=aP1.Distance(aP2); + //modified by NIZNHY-PKV Mon Jul 04 11:55:53 2011t if (dD0(m2, aP2); aSumTol=aTol1+aTol2; - - if (aP1.Distance(aP2) < aSumTol) { - return Standard_True; - } - return Standard_False; + //modified by NIZNHY-PKV Mon Jul 04 12:02:20 2011f + aSumTol=aSumTol*aSumTol; + aD2=aP1.SquareDistance(aP2); + bRet=aD2 + -- or NULL if K is not in the map. + ChangeFind1(me:out; K : TheKey) + returns Address from Standard; + ---Purpose: Returns the address of Item of the key + -- or NULL if K is not in the map. +--modified by NIZNHY-PKV Tue Jul 05 09:57:14 2011t + end DataMap; diff --git a/src/TCollection/TCollection_DataMap.gxx b/src/TCollection/TCollection_DataMap.gxx index 52ed51eac8..a8adf9b838 100755 --- a/src/TCollection/TCollection_DataMap.gxx +++ b/src/TCollection/TCollection_DataMap.gxx @@ -137,56 +137,53 @@ Standard_Boolean TCollection_DataMap::Bind(const TheKey& K, const TheItem& I) return Standard_True; } + //======================================================================= -//function : Contains +//function : Remove //purpose : //======================================================================= -Standard_Boolean TCollection_DataMap::IsBound(const TheKey& K) const +Standard_Boolean TCollection_DataMap::UnBind(const TheKey& K) { if (IsEmpty()) return Standard_False; TCollection_DataMapNode** data = (TCollection_DataMapNode**) myData1; - TCollection_DataMapNode* p = data[Hasher::HashCode(K,NbBuckets())]; + Standard_Integer k = Hasher::HashCode(K,NbBuckets()); + TCollection_DataMapNode* p = data[k]; + TCollection_DataMapNode* q = NULL; while (p) { if (Hasher::IsEqual(p->Key(),K)) { + Decrement(); + if (q) q->Next() = p->Next(); + else data[k] = (TCollection_DataMapNode*) p->Next(); + delete p; return Standard_True; - } + } + q = p; p = (TCollection_DataMapNode*) p->Next(); } return Standard_False; } - //======================================================================= -//function : Remove +//function : IsBound //purpose : //======================================================================= - -Standard_Boolean TCollection_DataMap::UnBind(const TheKey& K) +Standard_Boolean TCollection_DataMap::IsBound(const TheKey& K) const { if (IsEmpty()) return Standard_False; TCollection_DataMapNode** data = (TCollection_DataMapNode**) myData1; - Standard_Integer k = Hasher::HashCode(K,NbBuckets()); - TCollection_DataMapNode* p = data[k]; - TCollection_DataMapNode* q = NULL; + TCollection_DataMapNode* p = data[Hasher::HashCode(K,NbBuckets())]; while (p) { if (Hasher::IsEqual(p->Key(),K)) { - Decrement(); - if (q) q->Next() = p->Next(); - else data[k] = (TCollection_DataMapNode*) p->Next(); - delete p; return Standard_True; - } - q = p; + } p = (TCollection_DataMapNode*) p->Next(); } return Standard_False; } - //======================================================================= //function : Find //purpose : //======================================================================= - const TheItem& TCollection_DataMap::Find(const TheKey& K) const { Standard_NoSuchObject_Raise_if(IsEmpty(),"TCollection_DataMap::Find"); @@ -201,12 +198,10 @@ const TheItem& TCollection_DataMap::Find(const TheKey& K) const Standard_NoSuchObject::Raise("TCollection_DataMap::Find"); return p->Value(); } - //======================================================================= //function : ChangeFind //purpose : //======================================================================= - TheItem& TCollection_DataMap::ChangeFind(const TheKey& K) { Standard_NoSuchObject_Raise_if(IsEmpty(),"TCollection_DataMap::ChangeFind"); @@ -221,7 +216,36 @@ TheItem& TCollection_DataMap::ChangeFind(const TheKey& K) Standard_NoSuchObject::Raise("TCollection_DataMap::ChangeFind"); return p->Value(); } - +//modified by NIZNHY-PKV Tue Jul 05 09:54:14 2011f +//======================================================================= +//function : Find1 +//purpose : +//======================================================================= +Standard_Address TCollection_DataMap::Find1(const TheKey& K) const +{ + TCollection_DataMap *pMap=(TCollection_DataMap *)this; + return pMap->ChangeFind1(K); +} +//======================================================================= +//function : ChangeFind1 +//purpose : +//======================================================================= +Standard_Address TCollection_DataMap::ChangeFind1(const TheKey& K) +{ + if (IsEmpty()) { + return NULL; + } + TCollection_DataMapNode** data = (TCollection_DataMapNode**) myData1; + TCollection_DataMapNode* p = data[Hasher::HashCode(K,NbBuckets())]; + while (p) { + if (Hasher::IsEqual(p->Key(),K)) { + return (Standard_Address)&p->Value(); + } + p = (TCollection_DataMapNode*) p->Next(); + } + return NULL; +} +//modified by NIZNHY-PKV Tue Jul 05 09:54:18 2011t diff --git a/src/TCollection/TCollection_IndexedDataMap.cdl b/src/TCollection/TCollection_IndexedDataMap.cdl index 4cb0b32eff..dd4118c112 100755 --- a/src/TCollection/TCollection_IndexedDataMap.cdl +++ b/src/TCollection/TCollection_IndexedDataMap.cdl @@ -203,6 +203,17 @@ is -- Trigger: Raises NoSuchObject if K is not in the map. raises NoSuchObject from Standard ---C++: return & - is static; - + is static; + +--modified by NIZNHY-PKV Tue Jul 05 08:38:26 2011f + FindFromKey1(me; K : TheKey) + returns Address from Standard; + ---Purpose: Returns the address of Item of the key + -- or NULL if K is not in the map. + ChangeFromKey1(me:out; K : TheKey) + returns Address from Standard; + ---Purpose: Returns the address of Item of the key + -- or NULL if K is not in the map. +--modified by NIZNHY-PKV Tue Jul 05 08:38:26 2011t + end IndexedDataMap; diff --git a/src/TCollection/TCollection_IndexedDataMap.gxx b/src/TCollection/TCollection_IndexedDataMap.gxx index fe0242af86..ebcb7b52fa 100755 --- a/src/TCollection/TCollection_IndexedDataMap.gxx +++ b/src/TCollection/TCollection_IndexedDataMap.gxx @@ -242,24 +242,6 @@ void TCollection_IndexedDataMap::RemoveLast() delete p; } -//======================================================================= -//function : Contains -//purpose : -//======================================================================= - -Standard_Boolean TCollection_IndexedDataMap::Contains(const TheKey& K1) const -{ - if (IsEmpty()) return Standard_False; - TCollection_IndexedDataMapNode** data1 = (TCollection_IndexedDataMapNode**)myData1; - Standard_Integer k1 = Hasher::HashCode(K1,NbBuckets()); - TCollection_IndexedDataMapNode *p1; - p1 = data1[k1]; - while (p1) { - if (Hasher::IsEqual(p1->Key1(),K1)) return Standard_True; - p1 = (TCollection_IndexedDataMapNode*) p1->Next(); - } - return Standard_False; -} //======================================================================= //function : FindKey @@ -340,12 +322,27 @@ Standard_Integer TCollection_IndexedDataMap::FindIndex(const TheKey& K1) const } return 0; } - +//======================================================================= +//function : Contains +//purpose : +//======================================================================= +Standard_Boolean TCollection_IndexedDataMap::Contains(const TheKey& K1) const +{ + if (IsEmpty()) return Standard_False; + TCollection_IndexedDataMapNode** data1 = (TCollection_IndexedDataMapNode**)myData1; + Standard_Integer k1 = Hasher::HashCode(K1,NbBuckets()); + TCollection_IndexedDataMapNode *p1; + p1 = data1[k1]; + while (p1) { + if (Hasher::IsEqual(p1->Key1(),K1)) return Standard_True; + p1 = (TCollection_IndexedDataMapNode*) p1->Next(); + } + return Standard_False; +} //======================================================================= //function : FindFromKey //purpose : //======================================================================= - const TheItem& TCollection_IndexedDataMap::FindFromKey(const TheKey& K1) const { Standard_OutOfRange_Raise_if(IsEmpty(),"TCollection_IndexedDataMap::FindFromKey"); @@ -360,12 +357,10 @@ const TheItem& TCollection_IndexedDataMap::FindFromKey(const TheKey& K1) const Standard_OutOfRange::Raise("TCollection_IndexedDataMap::FindFromKey"); return p1->Value(); } - //======================================================================= //function : ChangeFromKey //purpose : //======================================================================= - TheItem& TCollection_IndexedDataMap::ChangeFromKey(const TheKey& K1) { Standard_OutOfRange_Raise_if(IsEmpty(),"TCollection_IndexedDataMap::ChangeFromKey"); @@ -380,8 +375,37 @@ TheItem& TCollection_IndexedDataMap::ChangeFromKey(const TheKey& K1) Standard_OutOfRange::Raise("TCollection_IndexedDataMap::ChangeFromKey"); return p1->Value(); } - - +//modified by NIZNHY-PKV Tue Jul 05 08:37:03 2011f +//======================================================================= +//function : FindFromKey1 +//purpose : +//======================================================================= +Standard_Address TCollection_IndexedDataMap::FindFromKey1(const TheKey& K1) const +{ + TCollection_IndexedDataMap *pMap=(TCollection_IndexedDataMap *)this; + return pMap->ChangeFromKey1(K1); +} +//======================================================================= +//function : ChangeFromKey1 +//purpose : +//======================================================================= +Standard_Address TCollection_IndexedDataMap::ChangeFromKey1(const TheKey& K1) +{ + if (IsEmpty()) { + return NULL; + } + TCollection_IndexedDataMapNode** data1 = (TCollection_IndexedDataMapNode**)myData1; + Standard_Integer k1 = Hasher::HashCode(K1,NbBuckets()); + TCollection_IndexedDataMapNode *p1; + p1 = data1[k1]; + while (p1) { + if (Hasher::IsEqual(p1->Key1(),K1)) { + return (Standard_Address)&p1->Value(); + } + p1 = (TCollection_IndexedDataMapNode*) p1->Next(); + } + return NULL; +} // @@SDM: begin -- 2.20.1