From: dbp Date: Thu, 14 May 2015 09:14:40 +0000 (+0300) Subject: 0026220: Visualization - In Graphic3d_Structure use single NCollection_IndexedMap... X-Git-Tag: V7_0_0_beta~549 X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=commitdiff_plain;h=602d1eadf19a7d107800bc71f59a0f94f80e2d1b 0026220: Visualization - In Graphic3d_Structure use single NCollection_IndexedMap instead of NCollection_DataMap and NCollection_Sequence --- diff --git a/src/Graphic3d/Graphic3d_IndexedMapOfAddress.hxx b/src/Graphic3d/Graphic3d_IndexedMapOfAddress.hxx index 9296b68b4b..80be9de5fc 100644 --- a/src/Graphic3d/Graphic3d_IndexedMapOfAddress.hxx +++ b/src/Graphic3d/Graphic3d_IndexedMapOfAddress.hxx @@ -16,8 +16,8 @@ #ifndef _Graphic3d_IndexedMapOfAddress #define _Graphic3d_IndexedMapOfAddress -#include +#include -typedef NCollection_DataMap Graphic3d_IndexedMapOfAddress; +typedef NCollection_IndexedMap Graphic3d_IndexedMapOfAddress; #endif // _Graphic3d_IndexedMapOfAddress diff --git a/src/Graphic3d/Graphic3d_Structure.cdl b/src/Graphic3d/Graphic3d_Structure.cdl index 1710ac2e79..e6af767af9 100644 --- a/src/Graphic3d/Graphic3d_Structure.cdl +++ b/src/Graphic3d/Graphic3d_Structure.cdl @@ -1003,17 +1003,11 @@ fields -- the associated low-level structure myCStructure : CStructure from Graphic3d; - -- the structures to which the structure is attached - myAncestors : SequenceOfAddress from TColStd; + -- the set of structures to which the structure is attached + myAncestors : IndexedMapOfAddress from Graphic3d; - -- the structures attached to the structure - myDescendants : SequenceOfAddress from TColStd; - - -- the map of structures to which the structure is attached - myAncestorMap : IndexedMapOfAddress from Graphic3d; - - -- the map of structures attached to the structure - myDescendantMap : IndexedMapOfAddress from Graphic3d; + -- the set of structures attached to the structure + myDescendants : IndexedMapOfAddress from Graphic3d; -- the highlight method of the structure myHighlightColor : Color from Quantity; diff --git a/src/Graphic3d/Graphic3d_Structure.cxx b/src/Graphic3d/Graphic3d_Structure.cxx index db64f66463..befdb95f36 100644 --- a/src/Graphic3d/Graphic3d_Structure.cxx +++ b/src/Graphic3d/Graphic3d_Structure.cxx @@ -164,16 +164,14 @@ void Graphic3d_Structure::Remove() // of ancestors of this structure and in the list of ancestors // of descendants of the same structure. - const Standard_Integer aNbDesc = myDescendants.Length(); - for (Standard_Integer aStructIter = 1; aStructIter <= aNbDesc; ++aStructIter) + for (Standard_Integer aStructIdx = 1, aNbDesc = myDescendants.Size(); aStructIdx <= aNbDesc; ++aStructIdx) { - ((Graphic3d_Structure *)(myDescendants.ChangeValue (aStructIter)))->Remove (APtr, Graphic3d_TOC_ANCESTOR); + ((Graphic3d_Structure *)myDescendants.FindKey (aStructIdx))->Remove (APtr, Graphic3d_TOC_ANCESTOR); } - const Standard_Integer aNbAnces = myAncestors.Length(); - for (Standard_Integer aStructIter = 1; aStructIter <= aNbAnces; ++aStructIter) + for (Standard_Integer aStructIdx = 1, aNbAnces = myAncestors.Size(); aStructIdx <= aNbAnces; ++aStructIdx) { - ((Graphic3d_Structure *)(myAncestors.ChangeValue (aStructIter)))->Remove (APtr, Graphic3d_TOC_DESCENDANT); + ((Graphic3d_Structure *)myAncestors.FindKey (aStructIdx))->Remove (APtr, Graphic3d_TOC_DESCENDANT); } // Destruction of me in the graphic library @@ -479,10 +477,9 @@ Standard_Boolean Graphic3d_Structure::ContainsFacet() const } // stop at the first descendant containing at least one facet - const Standard_Integer aNbDesc = myDescendants.Length(); - for (Standard_Integer aStructIter = 1; aStructIter <= aNbDesc; ++aStructIter) + for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next()) { - if (((const Graphic3d_Structure *)(myDescendants.Value (aStructIter)))->ContainsFacet()) + if (((const Graphic3d_Structure *)anIter.Value())->ContainsFacet()) { return Standard_True; } @@ -514,10 +511,9 @@ Standard_Boolean Graphic3d_Structure::IsEmpty() const } // stop at the first non-empty descendant - const Standard_Integer aNbDesc = myDescendants.Length(); - for (Standard_Integer aDescIter = 1; aDescIter <= aNbDesc; ++aDescIter) + for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next()) { - if (!((const Graphic3d_Structure* )(myDescendants.Value (aDescIter)))->IsEmpty()) + if (!((const Graphic3d_Structure* )anIter.Value())->IsEmpty()) { return Standard_False; } @@ -1274,10 +1270,9 @@ Standard_Boolean Graphic3d_Structure::AcceptConnection (const Handle(Graphic3d_S //============================================================================= void Graphic3d_Structure::Ancestors (Graphic3d_MapOfStructure& theSet) const { - const Standard_Integer aNbAnces = myAncestors.Length (); - for (Standard_Integer anIter = 1; anIter <= aNbAnces; ++anIter) + for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myAncestors); anIter.More(); anIter.Next()) { - theSet.Add ((Graphic3d_Structure* )(myAncestors.Value (anIter))); + theSet.Add ((Graphic3d_Structure* )anIter.Value()); } } @@ -1305,95 +1300,66 @@ Standard_Address Graphic3d_Structure::Owner() const //============================================================================= void Graphic3d_Structure::Descendants (Graphic3d_MapOfStructure& theSet) const { - const Standard_Integer aNbDesc = myDescendants.Length (); - for (Standard_Integer anIter = 1; anIter <= aNbDesc; ++anIter) + for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next()) { - theSet.Add ((Graphic3d_Structure* )(myDescendants.Value (anIter))); + theSet.Add ((Graphic3d_Structure* )anIter.Value()); } } //============================================================================= -//function : AppendDescendant +//function : AppendAncestor //purpose : //============================================================================= -Standard_Boolean Graphic3d_Structure::AppendDescendant (const Standard_Address theDescendant) +Standard_Boolean Graphic3d_Structure::AppendAncestor (const Standard_Address theAncestor) { - if (myDescendantMap.IsBound (theDescendant)) - { - return Standard_False; // already connected - } - - myDescendantMap.Bind (theDescendant, myDescendants.Length() + 1); - myDescendants.Append (theDescendant); + const Standard_Integer aSize = myAncestors.Size(); - return Standard_True; + return myAncestors.Add (theAncestor) > aSize; // new object } //============================================================================= -//function : RemoveDescendant +//function : AppendDescendant //purpose : //============================================================================= -Standard_Boolean Graphic3d_Structure::RemoveDescendant (const Standard_Address theDescendant) +Standard_Boolean Graphic3d_Structure::AppendDescendant (const Standard_Address theDescendant) { - Standard_Integer aStructIdx; - if (!myDescendantMap.Find (theDescendant, aStructIdx)) - { - return Standard_False; - } - - myDescendantMap.UnBind (theDescendant); - - if (aStructIdx != myDescendants.Length()) - { - myDescendants.Exchange (aStructIdx, myDescendants.Length()); - myDescendantMap.Bind (myDescendants (aStructIdx), aStructIdx); - } + const Standard_Integer aSize = myDescendants.Size(); - myDescendants.Remove (myDescendants.Length()); - - return Standard_True; + return myDescendants.Add (theDescendant) > aSize; // new object } //============================================================================= -//function : AppendAncestor +//function : RemoveAncestor //purpose : //============================================================================= -Standard_Boolean Graphic3d_Structure::AppendAncestor (const Standard_Address theAncestor) +Standard_Boolean Graphic3d_Structure::RemoveAncestor (const Standard_Address theAncestor) { - if (myAncestorMap.IsBound (theAncestor)) + const Standard_Integer anIndex = myAncestors.FindIndex (theAncestor); + + if (anIndex != 0) { - return Standard_False; // already connected + myAncestors.Swap (anIndex, myAncestors.Size()); + myAncestors.RemoveLast(); } - myAncestorMap.Bind (theAncestor, myAncestors.Length() + 1); - myAncestors.Append (theAncestor); - - return Standard_True; + return anIndex != 0; // object was found } //============================================================================= -//function : RemoveAncestor +//function : RemoveDescendant //purpose : //============================================================================= -Standard_Boolean Graphic3d_Structure::RemoveAncestor (const Standard_Address theAncestor) +Standard_Boolean Graphic3d_Structure::RemoveDescendant (const Standard_Address theDescendant) { - Standard_Integer aStructIdx; - if (!myAncestorMap.Find (theAncestor, aStructIdx)) - { - return Standard_False; - } - - myAncestorMap.UnBind (theAncestor); + const Standard_Integer anIndex = myDescendants.FindIndex (theDescendant); - if (aStructIdx != myAncestors.Length()) + if (anIndex != 0) { - myAncestors.Exchange (aStructIdx, myAncestors.Length()); - myAncestorMap.Bind (myAncestors (aStructIdx), aStructIdx); + myDescendants.Swap (anIndex, myDescendants.Size()); + myDescendants.RemoveLast(); } - myAncestors.Remove (myAncestors.Length()); - - return Standard_True; + return anIndex != 0; // object was found } //============================================================================= @@ -1491,27 +1457,25 @@ void Graphic3d_Structure::DisconnectAll (const Graphic3d_TypeOfConnection theTyp { case Graphic3d_TOC_DESCENDANT: { - const Standard_Integer aLength = myDescendants.Length(); - for (Standard_Integer anIter = 1; anIter <= aLength; ++anIter) + for (Standard_Integer anIdx = 1, aLength = myDescendants.Size(); anIdx <= aLength; ++anIdx) { // Value (1) instead of Value (i) as myDescendants // is modified by : // Graphic3d_Structure::Disconnect (AStructure) // that takes AStructure from myDescendants - ((Graphic3d_Structure* )(myDescendants.Value (1)))->Disconnect (this); + ((Graphic3d_Structure* )(myDescendants.FindKey (1)))->Disconnect (this); } break; } case Graphic3d_TOC_ANCESTOR: { - const Standard_Integer aLength = myAncestors.Length(); - for (Standard_Integer anIter = 1; anIter <= aLength; ++anIter) + for (Standard_Integer anIdx = 1, aLength = myAncestors.Size(); anIdx <= aLength; ++anIdx) { // Value (1) instead of Value (i) as myAncestors // is modified by : // Graphic3d_Structure::Disconnect (AStructure) // that takes AStructure from myAncestors - ((Graphic3d_Structure* )(myAncestors.Value (1)))->Disconnect (this); + ((Graphic3d_Structure* )(myAncestors.FindKey (1)))->Disconnect (this); } break; } @@ -1543,8 +1507,8 @@ void Graphic3d_Structure::SetTransform (const TColStd_Array2OfReal& theMat TColStd_Array2OfReal aMatrix44 (0, 3, 0, 3); // Assign the new transformation in an array [0..3][0..3] - // Avoid problemes if the user has defined matrice [1..4][1..4] - // or [3..6][-1..2] !! + // Avoid problems if the user has defined matrix [1..4][1..4] + // or [3..6][-1..2] !! Standard_Integer lr = theMatrix.LowerRow(); Standard_Integer ur = theMatrix.UpperRow(); Standard_Integer lc = theMatrix.LowerCol(); @@ -1851,9 +1815,9 @@ void Graphic3d_Structure::addTransformed (Graphic3d_BndBox4d& theBox, Graphic3d_BndBox4d aCombinedBox, aBox; getBox (aCombinedBox, theToIgnoreInfiniteFlag); - for (Standard_Integer aStructIt = 1; aStructIt <= myDescendants.Length(); ++aStructIt) + for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next()) { - const Graphic3d_Structure* aStruct = (const Graphic3d_Structure* )myDescendants.Value (aStructIt); + const Graphic3d_Structure* aStruct = (const Graphic3d_Structure* )anIter.Value(); aStruct->getBox (aBox, theToIgnoreInfiniteFlag); aCombinedBox.Combine (aBox); }