From a3ee66b0371b361bf97d6261c61a35995b4595bb Mon Sep 17 00:00:00 2001 From: eap Date: Tue, 22 Jul 2014 16:40:10 +0400 Subject: [PATCH] 52457: Addition of hypotheses is 8 time longer than meshing. --- src/DriverMED/DriverMED_Family.cxx | 9 +- src/DriverMED/DriverMED_Family.h | 2 +- src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx | 18 +- src/DriverMED/DriverMED_W_SMESHDS_Mesh.h | 2 +- src/SMESH/SMESH_Algo.cxx | 49 ++-- src/SMESH/SMESH_Algo.hxx | 14 +- src/SMESH/SMESH_Gen.cxx | 33 ++- src/SMESH/SMESH_HypoFilter.cxx | 26 +- src/SMESH/SMESH_HypoFilter.hxx | 12 +- src/SMESH/SMESH_Mesh.cxx | 239 +++++++--------- src/SMESH/SMESH_Mesh.hxx | 24 +- src/SMESH/SMESH_MeshEditor.cxx | 10 +- src/SMESHDS/SMESHDS_Mesh.cxx | 256 +++++++----------- src/SMESHDS/SMESHDS_Mesh.hxx | 28 +- src/SMESHDS/SMESHDS_TSubMeshHolder.hxx | 143 ++++++++++ src/SMESH_I/SMESH_Gen_i.cxx | 52 +--- src/StdMeshers/StdMeshers_ProjectionUtils.cxx | 2 +- .../StdMeshers_RadialQuadrangle_1D2D.cxx | 6 +- src/StdMeshers/StdMeshers_Regular_1D.cxx | 9 +- 19 files changed, 487 insertions(+), 447 deletions(-) create mode 100644 src/SMESHDS/SMESHDS_TSubMeshHolder.hxx diff --git a/src/DriverMED/DriverMED_Family.cxx b/src/DriverMED/DriverMED_Family.cxx index 42f2f6aa3..2f9aceb46 100644 --- a/src/DriverMED/DriverMED_Family.cxx +++ b/src/DriverMED/DriverMED_Family.cxx @@ -145,7 +145,7 @@ DriverMED_Family //============================================================================= DriverMED_FamilyPtrList DriverMED_Family -::MakeFamilies(const SMESHDS_SubMeshPtrMap& theSubMeshes, +::MakeFamilies(SMESHDS_SubMeshIteratorPtr theSubMeshes, const SMESHDS_GroupBasePtrList& theGroups, const bool doGroupOfNodes, const bool doGroupOfEdges, @@ -170,11 +170,10 @@ DriverMED_Family int aElemFamId = FIRST_ELEM_FAMILY; // Process sub-meshes - SMESHDS_SubMeshPtrMap::const_iterator aSMIter = theSubMeshes.begin(); - for (; aSMIter != theSubMeshes.end(); aSMIter++) + while ( theSubMeshes->more() ) { - const int anId = aSMIter->first; - SMESHDS_SubMesh* aSubMesh = aSMIter->second; + SMESHDS_SubMesh* aSubMesh = const_cast< SMESHDS_SubMesh* >( theSubMeshes->next() ); + const int anId = aSubMesh->GetID(); if ( aSubMesh->IsComplexSubmesh() ) continue; // submesh containing other submeshs DriverMED_FamilyPtrList aSMFams = SplitByType(aSubMesh,anId); diff --git a/src/DriverMED/DriverMED_Family.h b/src/DriverMED/DriverMED_Family.h index d774603da..5a1c4d66c 100644 --- a/src/DriverMED/DriverMED_Family.h +++ b/src/DriverMED/DriverMED_Family.h @@ -69,7 +69,7 @@ class MESHDRIVERMED_EXPORT DriverMED_Family */ static DriverMED_FamilyPtrList - MakeFamilies (const SMESHDS_SubMeshPtrMap& theSubMeshes, + MakeFamilies (SMESHDS_SubMeshIteratorPtr theSubMeshes, const SMESHDS_GroupBasePtrList& theGroups, const bool doGroupOfNodes, const bool doGroupOfEdges, diff --git a/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx b/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx index 47fa68b5d..aec74adc9 100644 --- a/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx +++ b/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx @@ -101,7 +101,7 @@ void DriverMED_W_SMESHDS_Mesh::AddAllSubMeshes() void DriverMED_W_SMESHDS_Mesh::AddSubMesh(SMESHDS_SubMesh* theSubMesh, int theID) { - mySubMeshes[theID] = theSubMesh; + mySubMeshes.push_back( theSubMesh ); } void DriverMED_W_SMESHDS_Mesh::AddGroupOfNodes() @@ -292,6 +292,20 @@ namespace // return elem_famNum->second; return aDefaultFamilyId; } + + //================================================================================ + /*! + * \brief Returns iterator on sub-meshes + */ + //================================================================================ + + SMESHDS_SubMeshIteratorPtr getIterator( std::vector& mySubMeshes ) + { + return SMESHDS_SubMeshIteratorPtr + ( new SMDS_SetIterator + < const SMESHDS_SubMesh*, std::vector< SMESHDS_SubMesh* >::iterator >( mySubMeshes.begin(), + mySubMeshes.end() )); + } } Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() @@ -435,7 +449,7 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() myDoGroupOfBalls && nbBalls); } else { aFamilies = DriverMED_Family::MakeFamilies - (mySubMeshes, myGroups, + (getIterator( mySubMeshes ), myGroups, myDoGroupOfNodes && nbNodes, myDoGroupOfEdges && nbEdges, myDoGroupOfFaces && nbFaces, diff --git a/src/DriverMED/DriverMED_W_SMESHDS_Mesh.h b/src/DriverMED/DriverMED_W_SMESHDS_Mesh.h index d817c3f27..4342d5dd2 100644 --- a/src/DriverMED/DriverMED_W_SMESHDS_Mesh.h +++ b/src/DriverMED/DriverMED_W_SMESHDS_Mesh.h @@ -79,7 +79,7 @@ class MESHDRIVERMED_EXPORT DriverMED_W_SMESHDS_Mesh: public Driver_SMESHDS_Mesh MED::EVersion myMedVersion; std::list myGroups; bool myAllSubMeshes; - std::map mySubMeshes; + std::vector mySubMeshes; bool myDoGroupOfNodes; bool myDoGroupOfEdges; bool myDoGroupOfFaces; diff --git a/src/SMESH/SMESH_Algo.cxx b/src/SMESH/SMESH_Algo.cxx index 0f41460d5..732c3e64a 100644 --- a/src/SMESH/SMESH_Algo.cxx +++ b/src/SMESH/SMESH_Algo.cxx @@ -178,6 +178,7 @@ const SMESH_Algo::Features& SMESH_Algo::GetFeatures( const std::string& algoType SMESH_Algo::SMESH_Algo (int hypId, int studyId, SMESH_Gen * gen) : SMESH_Hypothesis(hypId, studyId, gen) { + _compatibleAllHypFilter = _compatibleNoAuxHypFilter = NULL; _onlyUnaryInput = _requireDiscreteBoundary = _requireShape = true; _quadraticMesh = _supportSubmeshes = false; _error = COMPERR_OK; @@ -193,6 +194,8 @@ SMESH_Algo::SMESH_Algo (int hypId, int studyId, SMESH_Gen * gen) SMESH_Algo::~SMESH_Algo() { + delete _compatibleNoAuxHypFilter; + // delete _compatibleAllHypFilter; -- _compatibleNoAuxHypFilter does it!!! } //============================================================================= @@ -263,10 +266,9 @@ SMESH_Algo::GetUsedHypothesis(SMESH_Mesh & aMesh, { SMESH_Algo* me = const_cast< SMESH_Algo* >( this ); me->_usedHypList.clear(); - SMESH_HypoFilter filter; - if ( InitCompatibleHypoFilter( filter, ignoreAuxiliary )) + if ( const SMESH_HypoFilter* filter = GetCompatibleHypoFilter( ignoreAuxiliary )) { - aMesh.GetHypotheses( aShape, filter, me->_usedHypList, true ); + aMesh.GetHypotheses( aShape, *filter, me->_usedHypList, true ); if ( ignoreAuxiliary && _usedHypList.size() > 1 ) me->_usedHypList.clear(); //only one compatible hypothesis allowed } @@ -288,9 +290,8 @@ SMESH_Algo::GetAppliedHypothesis(SMESH_Mesh & aMesh, { SMESH_Algo* me = const_cast< SMESH_Algo* >( this ); me->_appliedHypList.clear(); - SMESH_HypoFilter filter; - if ( InitCompatibleHypoFilter( filter, ignoreAuxiliary )) - aMesh.GetHypotheses( aShape, filter, me->_appliedHypList, false ); + if ( const SMESH_HypoFilter* filter = GetCompatibleHypoFilter( ignoreAuxiliary )) + aMesh.GetHypotheses( aShape, *filter, me->_appliedHypList, false ); return _appliedHypList; } @@ -457,27 +458,35 @@ bool SMESH_Algo::GetSortedNodesOnEdge(const SMESHDS_Mesh* theM //================================================================================ /*! - * \brief Make filter recognize only compatible hypotheses - * \param theFilter - the filter to initialize - * \param ignoreAuxiliary - make filter ignore compatible auxiliary hypotheses + * \brief Returns the filter recognizing only compatible hypotheses + * \param ignoreAuxiliary - make filter ignore auxiliary hypotheses + * \retval SMESH_HypoFilter* - the filter that can be NULL */ //================================================================================ -bool SMESH_Algo::InitCompatibleHypoFilter( SMESH_HypoFilter & theFilter, - const bool ignoreAuxiliary) const +const SMESH_HypoFilter* +SMESH_Algo::GetCompatibleHypoFilter(const bool ignoreAuxiliary) const { if ( !_compatibleHypothesis.empty() ) { - theFilter.Init( theFilter.HasName( _compatibleHypothesis[0] )); - for ( int i = 1; i < _compatibleHypothesis.size(); ++i ) - theFilter.Or( theFilter.HasName( _compatibleHypothesis[ i ] )); - - if ( ignoreAuxiliary ) - theFilter.AndNot( theFilter.IsAuxiliary() ); - - return true; + if ( !_compatibleAllHypFilter ) + { + SMESH_HypoFilter* filter = new SMESH_HypoFilter(); + filter->Init( filter->HasName( _compatibleHypothesis[0] )); + for ( int i = 1; i < _compatibleHypothesis.size(); ++i ) + filter->Or( filter->HasName( _compatibleHypothesis[ i ] )); + + SMESH_HypoFilter* filterNoAux = new SMESH_HypoFilter( filter ); + filterNoAux->AndNot( filterNoAux->IsAuxiliary() ); + + // _compatibleNoAuxHypFilter will detele _compatibleAllHypFilter!!! + SMESH_Algo* me = const_cast< SMESH_Algo* >( this ); + me->_compatibleAllHypFilter = filter; + me->_compatibleNoAuxHypFilter = filterNoAux; + } + return ignoreAuxiliary ? _compatibleNoAuxHypFilter : _compatibleAllHypFilter; } - return false; + return 0; } //================================================================================ diff --git a/src/SMESH/SMESH_Algo.hxx b/src/SMESH/SMESH_Algo.hxx index 8aeaf7bb6..348c34df0 100644 --- a/src/SMESH/SMESH_Algo.hxx +++ b/src/SMESH/SMESH_Algo.hxx @@ -218,13 +218,12 @@ class SMESH_EXPORT SMESH_Algo : public SMESH_Hypothesis const TopoDS_Shape & aShape, const bool ignoreAuxiliary=true) const; /*! - * \brief Make the filter recognize only compatible hypotheses - * \param theFilter - the filter to initialize - * \param ignoreAuxiliary - make filter ignore compatible auxiliary hypotheses - * \retval bool - true if the algo has compatible hypotheses + * \brief Returns the filter recognizing only compatible hypotheses + * \param ignoreAuxiliary - make filter ignore compatible auxiliary hypotheses + * \retval SMESH_HypoFilter* - the filter that can be NULL */ - bool InitCompatibleHypoFilter( SMESH_HypoFilter & theFilter, - const bool ignoreAuxiliary) const; + const SMESH_HypoFilter* GetCompatibleHypoFilter(const bool ignoreAuxiliary) const; + /*! * \brief Just return false as the algorithm does not hold parameters values */ @@ -408,9 +407,12 @@ public: protected: + const SMESH_HypoFilter * _compatibleAllHypFilter; + const SMESH_HypoFilter * _compatibleNoAuxHypFilter; std::vector _compatibleHypothesis; std::list _appliedHypList; std::list _usedHypList; + // Algo features influencing which Compute() and how is called: // in what turn and with what input shape. diff --git a/src/SMESH/SMESH_Gen.cxx b/src/SMESH/SMESH_Gen.cxx index c8ba34bc3..3acff6796 100644 --- a/src/SMESH/SMESH_Gen.cxx +++ b/src/SMESH/SMESH_Gen.cxx @@ -288,24 +288,24 @@ bool SMESH_Gen::Compute(SMESH_Mesh & aMesh, // Apply all-dimensional algorithms supporing sub-meshes // ====================================================== + std::vector< SMESH_subMesh* > smVec; for ( aShapeDim = 0; aShapeDim < 4; ++aShapeDim ) { // ------------------------------------------------ // sort list of sub-meshes according to mesh order // ------------------------------------------------ - aMesh.SortByMeshOrder( smWithAlgoSupportingSubmeshes[ aShapeDim ] ); + smVec.assign( smWithAlgoSupportingSubmeshes[ aShapeDim ].begin(), + smWithAlgoSupportingSubmeshes[ aShapeDim ].end() ); + aMesh.SortByMeshOrder( smVec ); // ------------------------------------------------------------ // compute sub-meshes with local uni-dimensional algos under // sub-meshes with all-dimensional algos // ------------------------------------------------------------ - list< SMESH_subMesh* >::iterator subIt, subEnd; - subIt = smWithAlgoSupportingSubmeshes[ aShapeDim ].begin(); - subEnd = smWithAlgoSupportingSubmeshes[ aShapeDim ].end(); // start from lower shapes - for ( ; subIt != subEnd; ++subIt ) + for ( size_t i = 0; i < smVec.size(); ++i ) { - sm = *subIt; + sm = smVec[i]; // get a shape the algo is assigned to if ( !GetAlgo( aMesh, sm->GetSubShape(), & algoShape )) @@ -343,10 +343,9 @@ bool SMESH_Gen::Compute(SMESH_Mesh & aMesh, // -------------------------------- // apply the all-dimensional algos // -------------------------------- - subIt = smWithAlgoSupportingSubmeshes[ aShapeDim ].begin(); - for ( ; subIt != subEnd; ++subIt ) + for ( size_t i = 0; i < smVec.size(); ++i ) { - sm = *subIt; + sm = smVec[i]; if ( sm->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE) { const TopAbs_ShapeEnum shapeType = sm->GetSubShape().ShapeType(); @@ -494,18 +493,18 @@ bool SMESH_Gen::Evaluate(SMESH_Mesh & aMesh, // ------------------------------------------------------------ // sort list of meshes according to mesh order // ------------------------------------------------------------ - aMesh.SortByMeshOrder( smWithAlgoSupportingSubmeshes ); + std::vector< SMESH_subMesh* > smVec( smWithAlgoSupportingSubmeshes.begin(), + smWithAlgoSupportingSubmeshes.end() ); + aMesh.SortByMeshOrder( smVec ); // ------------------------------------------------------------ // compute sub-meshes under shapes with algos that DO NOT require // Discreteized boundaries and DO support sub-meshes // ------------------------------------------------------------ - list< SMESH_subMesh* >::iterator subIt, subEnd; - subIt = smWithAlgoSupportingSubmeshes.begin(); - subEnd = smWithAlgoSupportingSubmeshes.end(); // start from lower shapes - for ( ; subIt != subEnd; ++subIt ) { - sm = *subIt; + for ( size_t i = 0; i < smVec.size(); ++i ) + { + sm = smVec[i]; // get a shape the algo is assigned to TopoDS_Shape algoShape; @@ -538,9 +537,9 @@ bool SMESH_Gen::Evaluate(SMESH_Mesh & aMesh, // ---------------------------------------------------------- // apply the algos that do not require Discreteized boundaries // ---------------------------------------------------------- - for ( subIt = smWithAlgoSupportingSubmeshes.begin(); subIt != subEnd; ++subIt ) + for ( size_t i = 0; i < smVec.size(); ++i ) { - sm = *subIt; + sm = smVec[i]; sm->Evaluate(aResMap); if ( aShapesId ) aShapesId->insert( sm->GetId() ); diff --git a/src/SMESH/SMESH_HypoFilter.cxx b/src/SMESH/SMESH_HypoFilter.cxx index e19fd11a6..e5d167064 100644 --- a/src/SMESH/SMESH_HypoFilter.cxx +++ b/src/SMESH/SMESH_HypoFilter.cxx @@ -185,6 +185,7 @@ bool SMESH_HypoFilter::IsMoreLocalThanPredicate::IsOk(const SMESH_Hypothesis* aH //======================================================================= SMESH_HypoFilter::SMESH_HypoFilter() + : myNbPredicates(0) { } @@ -194,6 +195,7 @@ SMESH_HypoFilter::SMESH_HypoFilter() //======================================================================= SMESH_HypoFilter::SMESH_HypoFilter( SMESH_HypoPredicate* aPredicate, bool notNegate ) + : myNbPredicates(0) { add( notNegate ? AND : AND_NOT, aPredicate ); } @@ -352,15 +354,14 @@ SMESH_HypoPredicate* SMESH_HypoFilter::HasType(const int theHypType) bool SMESH_HypoFilter::IsOk (const SMESH_Hypothesis* aHyp, const TopoDS_Shape& aShape) const { - if ( myPredicates.empty() ) + if ( IsEmpty() ) return true; - bool ok = ( myPredicates.front()->_logical_op <= AND_NOT ); - list::const_iterator pred = myPredicates.begin(); - for ( ; pred != myPredicates.end(); ++pred ) + bool ok = ( myPredicates[0]->_logical_op <= AND_NOT ); + for ( int i = 0; i < myNbPredicates; ++i ) { - bool ok2 = (*pred)->IsOk( aHyp, aShape ); - switch ( (*pred)->_logical_op ) { + bool ok2 = myPredicates[i]->IsOk( aHyp, aShape ); + switch ( myPredicates[i]->_logical_op ) { case AND: ok = ok && ok2; break; case AND_NOT: ok = ok && !ok2; break; case OR: ok = ok || ok2; break; @@ -378,10 +379,11 @@ bool SMESH_HypoFilter::IsOk (const SMESH_Hypothesis* aHyp, SMESH_HypoFilter & SMESH_HypoFilter::Init ( SMESH_HypoPredicate* aPredicate, bool notNegate ) { - list::const_iterator pred = myPredicates.begin(); - for ( ; pred != myPredicates.end(); ++pred ) + SMESH_HypoPredicate** pred = &myPredicates[0]; + SMESH_HypoPredicate** end = &myPredicates[myNbPredicates]; + for ( ; pred != end; ++pred ) delete *pred; - myPredicates.clear(); + myNbPredicates = 0; add( notNegate ? AND : AND_NOT, aPredicate ); return *this; @@ -395,7 +397,11 @@ SMESH_HypoFilter & SMESH_HypoFilter::Init ( SMESH_HypoPredicate* aPredicate, bo SMESH_HypoFilter::~SMESH_HypoFilter() { - Init(0); + SMESH_HypoPredicate** pred = &myPredicates[0]; + SMESH_HypoPredicate** end = &myPredicates[myNbPredicates]; + for ( ; pred != end; ++pred ) + delete *pred; + myNbPredicates = 0; } diff --git a/src/SMESH/SMESH_HypoFilter.hxx b/src/SMESH/SMESH_HypoFilter.hxx index 6ac97e62d..7a9c47d77 100644 --- a/src/SMESH/SMESH_HypoFilter.hxx +++ b/src/SMESH/SMESH_HypoFilter.hxx @@ -59,7 +59,7 @@ class SMESH_EXPORT SMESH_HypoFilter: public SMESH_HypoPredicate // Create and add predicates. // Added predicates will be destroyed by filter when it dies SMESH_HypoFilter(); - SMESH_HypoFilter( SMESH_HypoPredicate* aPredicate, bool notNegate = true ); + explicit SMESH_HypoFilter( SMESH_HypoPredicate* aPredicate, bool notNegate = true ); // notNegate==false means !aPredicate->IsOk() SMESH_HypoFilter & Init ( SMESH_HypoPredicate* aPredicate, bool notNegate = true ); SMESH_HypoFilter & And ( SMESH_HypoPredicate* aPredicate ); @@ -80,7 +80,7 @@ class SMESH_EXPORT SMESH_HypoFilter: public SMESH_HypoPredicate static SMESH_HypoPredicate* HasDim(const int theDim); static SMESH_HypoPredicate* HasType(const int theHypType); - bool IsEmpty() const { return myPredicates.empty(); } + bool IsEmpty() const { return myNbPredicates == 0; } /*! * \brief check aHyp or/and aShape it is assigned to @@ -90,7 +90,7 @@ class SMESH_EXPORT SMESH_HypoFilter: public SMESH_HypoPredicate /*! * \brief return true if contains no predicates */ - bool IsAny() const { return myPredicates.empty(); } + bool IsAny() const { return myNbPredicates > 0; } ~SMESH_HypoFilter(); @@ -98,7 +98,9 @@ class SMESH_EXPORT SMESH_HypoFilter: public SMESH_HypoPredicate protected: // fields - std::list myPredicates; + //std::list myPredicates; + SMESH_HypoPredicate* myPredicates[100]; + int myNbPredicates; // private methods @@ -111,7 +113,7 @@ class SMESH_EXPORT SMESH_HypoFilter: public SMESH_HypoPredicate { if ( pred ) { pred->_logical_op = bool_op; - myPredicates.push_back( pred ); + myPredicates[ myNbPredicates++ ] = pred; } } diff --git a/src/SMESH/SMESH_Mesh.cxx b/src/SMESH/SMESH_Mesh.cxx index 6d4db5d83..a7c20a0c5 100644 --- a/src/SMESH/SMESH_Mesh.cxx +++ b/src/SMESH/SMESH_Mesh.cxx @@ -26,17 +26,18 @@ // #include "SMESH_Mesh.hxx" #include "SMESH_MesherHelper.hxx" -#include "SMESH_subMesh.hxx" +#include "SMDS_MeshVolume.hxx" +#include "SMDS_SetIterator.hxx" +#include "SMESHDS_Document.hxx" +#include "SMESHDS_Group.hxx" +#include "SMESHDS_GroupOnGeom.hxx" +#include "SMESHDS_Script.hxx" +#include "SMESHDS_TSubMeshHolder.hxx" #include "SMESH_Gen.hxx" -#include "SMESH_Hypothesis.hxx" #include "SMESH_Group.hxx" #include "SMESH_HypoFilter.hxx" -#include "SMESHDS_Group.hxx" -#include "SMESHDS_Script.hxx" -#include "SMESHDS_GroupOnGeom.hxx" -#include "SMESHDS_Document.hxx" -#include "SMDS_MeshVolume.hxx" -#include "SMDS_SetIterator.hxx" +#include "SMESH_Hypothesis.hxx" +#include "SMESH_subMesh.hxx" #include "utilities.h" @@ -91,6 +92,10 @@ static int MYDEBUG = 0; typedef SMESH_HypoFilter THypType; +class SMESH_Mesh::SubMeshHolder : public SMESHDS_TSubMeshHolder< SMESH_subMesh > +{ +}; + //============================================================================= /*! * @@ -116,6 +121,7 @@ SMESH_Mesh::SMESH_Mesh(int theLocalId, _shapeDiagonal = 0.0; _callUp = NULL; _myMeshDS->ShapeToMesh( PseudoShape() ); + _subMeshHolder = new SubMeshHolder; } //================================================================================ @@ -138,6 +144,7 @@ SMESH_Mesh::SMESH_Mesh(): _shapeDiagonal( 0.0 ), _callUp( 0 ) { + _subMeshHolder = new SubMeshHolder; } namespace @@ -185,13 +192,7 @@ SMESH_Mesh::~SMESH_Mesh() _mapGroup.clear(); // delete sub-meshes - map ::iterator sm = _mapSubMesh.begin(); - for ( ; sm != _mapSubMesh.end(); ++sm ) - { - delete sm->second; - sm->second = 0; - } - _mapSubMesh.clear(); + delete _subMeshHolder; if ( _callUp) delete _callUp; _callUp = 0; @@ -248,10 +249,7 @@ void SMESH_Mesh::ShapeToMesh(const TopoDS_Shape & aShape) { // removal of a shape to mesh, delete objects referring to sub-shapes: // - sub-meshes - map ::iterator i_sm = _mapSubMesh.begin(); - for ( ; i_sm != _mapSubMesh.end(); ++i_sm ) - delete i_sm->second; - _mapSubMesh.clear(); + _subMeshHolder->DeleteAll(); // - groups on geometry map ::iterator i_gr = _mapGroup.begin(); while ( i_gr != _mapGroup.end() ) { @@ -756,7 +754,6 @@ const list& SMESH_Mesh::GetHypothesisList(const TopoDS_Shape & aSubShape) const throw(SALOME_Exception) { - Unexpect aCatch(SalomeException); return _myMeshDS->GetHypothesis(aSubShape); } @@ -790,9 +787,9 @@ const SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const TopoDS_Shape & aSubS if ( andAncestors ) { // user sorted submeshes of ancestors, according to stored submesh priority - const list smList = getAncestorsSubMeshes( aSubShape ); - list::const_iterator smIt = smList.begin(); - for ( ; smIt != smList.end(); smIt++ ) + getAncestorsSubMeshes( aSubShape, _ancestorSubMeshes ); + vector::const_iterator smIt = _ancestorSubMeshes.begin(); + for ( ; smIt != _ancestorSubMeshes.end(); smIt++ ) { const TopoDS_Shape& curSh = (*smIt)->GetSubShape(); const list& hypList = _myMeshDS->GetHypothesis(curSh); @@ -863,18 +860,18 @@ int SMESH_Mesh::GetHypotheses(const TopoDS_Shape & aSubShape, TopTools_MapOfShape map; // user sorted submeshes of ancestors, according to stored submesh priority - const list smList = getAncestorsSubMeshes( aSubShape ); - list::const_iterator smIt = smList.begin(); - for ( ; smIt != smList.end(); smIt++ ) + getAncestorsSubMeshes( aSubShape, _ancestorSubMeshes ); + vector::const_iterator smIt = _ancestorSubMeshes.begin(); + for ( ; smIt != _ancestorSubMeshes.end(); smIt++ ) { const TopoDS_Shape& curSh = (*smIt)->GetSubShape(); - if ( !map.Add( curSh )) + if ( !map.Add( curSh )) continue; const list& hypList = _myMeshDS->GetHypothesis(curSh); for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ ) - if (aFilter.IsOk( cSMESH_Hyp( *hyp ), curSh ) && + if (( aFilter.IsOk( cSMESH_Hyp( *hyp ), curSh )) && ( cSMESH_Hyp(*hyp)->IsAuxiliary() || !mainHypFound ) && - hypTypes.insert( (*hyp)->GetName() ).second ) + ( hypTypes.insert( (*hyp)->GetName() ).second )) { aHypList.push_back( *hyp ); nbHyps++; @@ -937,8 +934,6 @@ void SMESH_Mesh::ClearLog() throw(SALOME_Exception) SMESH_subMesh *SMESH_Mesh::GetSubMesh(const TopoDS_Shape & aSubShape) throw(SALOME_Exception) { - Unexpect aCatch(SalomeException); - SMESH_subMesh *aSubMesh; int index = _myMeshDS->ShapeToIndex(aSubShape); // for submeshes on GEOM Group @@ -955,15 +950,11 @@ SMESH_subMesh *SMESH_Mesh::GetSubMesh(const TopoDS_Shape & aSubShape) // if ( !index ) // return NULL; // neither sub-shape nor a group - map ::iterator i_sm = _mapSubMesh.find(index); - if ( i_sm != _mapSubMesh.end()) - { - aSubMesh = i_sm->second; - } - else + SMESH_subMesh* aSubMesh = _subMeshHolder->Get( index ); + if ( !aSubMesh ) { aSubMesh = new SMESH_subMesh(index, this, _myMeshDS, aSubShape); - _mapSubMesh[index] = aSubMesh; + _subMeshHolder->Add( index, aSubMesh ); } return aSubMesh; } @@ -978,17 +969,10 @@ SMESH_subMesh *SMESH_Mesh::GetSubMesh(const TopoDS_Shape & aSubShape) SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const TopoDS_Shape & aSubShape) const throw(SALOME_Exception) { - Unexpect aCatch(SalomeException); - SMESH_subMesh *aSubMesh = NULL; - int index = _myMeshDS->ShapeToIndex(aSubShape); - - map ::const_iterator i_sm = _mapSubMesh.find(index); - if ( i_sm != _mapSubMesh.end()) - aSubMesh = i_sm->second; - - return aSubMesh; + return GetSubMeshContaining( index ); } + //============================================================================= /*! * Get the SMESH_subMesh object implementation. Dont create it, return null @@ -999,13 +983,11 @@ SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const TopoDS_Shape & aSubShape) SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const int aShapeID) const throw(SALOME_Exception) { - Unexpect aCatch(SalomeException); - - map ::const_iterator i_sm = _mapSubMesh.find(aShapeID); - if (i_sm == _mapSubMesh.end()) - return NULL; - return i_sm->second; + SMESH_subMesh *aSubMesh = _subMeshHolder->Get( aShapeID ); + + return aSubMesh; } + //================================================================================ /*! * \brief Return submeshes of groups containing the given sub-shape @@ -1016,7 +998,6 @@ list SMESH_Mesh::GetGroupSubMeshesContaining(const TopoDS_Shape & aSubShape) const throw(SALOME_Exception) { - Unexpect aCatch(SalomeException); list found; SMESH_subMesh * subMesh = GetSubMeshContaining(aSubShape); @@ -1024,13 +1005,14 @@ SMESH_Mesh::GetGroupSubMeshesContaining(const TopoDS_Shape & aSubShape) const return found; // submeshes of groups have max IDs, so search from the map end - map::const_reverse_iterator i_sm; - for ( i_sm = _mapSubMesh.rbegin(); i_sm != _mapSubMesh.rend(); ++i_sm) { - SMESHDS_SubMesh * ds = i_sm->second->GetSubMeshDS(); +SMESH_subMeshIteratorPtr smIt( _subMeshHolder->GetIterator( /*reverse=*/true ) ); + while ( smIt->more() ) { + SMESH_subMesh* sm = smIt->next(); + SMESHDS_SubMesh * ds = sm->GetSubMeshDS(); if ( ds && ds->IsComplexSubmesh() ) { - if ( SMESH_MesherHelper::IsSubShape( aSubShape, i_sm->second->GetSubShape() )) + if ( SMESH_MesherHelper::IsSubShape( aSubShape, sm->GetSubShape() )) { - found.push_back( i_sm->second ); + found.push_back( sm ); //break; } } else { @@ -1040,7 +1022,7 @@ SMESH_Mesh::GetGroupSubMeshesContaining(const TopoDS_Shape & aSubShape) const if ( found.empty() ) // maybe the main shape is a COMPOUND (issue 0021530) { - if ( SMESH_subMesh * mainSM = GetSubMeshContaining(1)) + if ( SMESH_subMesh * mainSM = GetSubMeshContaining(1) ) if ( mainSM->GetSubShape().ShapeType() == TopAbs_COMPOUND ) { TopoDS_Iterator it( mainSM->GetSubShape() ); @@ -1077,17 +1059,15 @@ bool SMESH_Mesh::IsUsedHypothesis(SMESHDS_Hypothesis * anHyp, if (algo) { // look trough hypotheses used by algo - SMESH_HypoFilter hypoKind; - if ( algo->InitCompatibleHypoFilter( hypoKind, !hyp->IsAuxiliary() )) { + const SMESH_HypoFilter* hypoKind; + if (( hypoKind = algo->GetCompatibleHypoFilter( !hyp->IsAuxiliary() ))) { list usedHyps; - if ( GetHypotheses( aSubShape, hypoKind, usedHyps, true )) + if ( GetHypotheses( aSubShape, *hypoKind, usedHyps, true )) return ( find( usedHyps.begin(), usedHyps.end(), anHyp ) != usedHyps.end() ); } } - // look through all assigned hypotheses - //SMESH_HypoFilter filter( SMESH_HypoFilter::Is( hyp )); - return false; //GetHypothesis( aSubShape, filter, true ); + return false; } //============================================================================= @@ -1096,22 +1076,20 @@ bool SMESH_Mesh::IsUsedHypothesis(SMESHDS_Hypothesis * anHyp, */ //============================================================================= -const list < SMESH_subMesh * >& -SMESH_Mesh::GetSubMeshUsingHypothesis(SMESHDS_Hypothesis * anHyp) - throw(SALOME_Exception) -{ - Unexpect aCatch(SalomeException); - if(MYDEBUG) MESSAGE("SMESH_Mesh::GetSubMeshUsingHypothesis"); - map < int, SMESH_subMesh * >::iterator itsm; - _subMeshesUsingHypothesisList.clear(); - for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++) - { - SMESH_subMesh *aSubMesh = (*itsm).second; - if ( IsUsedHypothesis ( anHyp, aSubMesh )) - _subMeshesUsingHypothesisList.push_back(aSubMesh); - } - return _subMeshesUsingHypothesisList; -} +// const list < SMESH_subMesh * >& +// SMESH_Mesh::GetSubMeshUsingHypothesis(SMESHDS_Hypothesis * anHyp) +// throw(SALOME_Exception) +// { +// _subMeshesUsingHypothesisList.clear(); +// SMESH_subMeshIteratorPtr smIt( _subMeshHolder->GetIterator() ); +// while ( smIt->more() ) +// { +// SMESH_subMesh* aSubMesh = smIt->next(); +// if ( IsUsedHypothesis ( anHyp, aSubMesh )) +// _subMeshesUsingHypothesisList.push_back( aSubMesh ); +// } +// return _subMeshesUsingHypothesisList; +// } //======================================================================= //function : NotifySubMeshesHypothesisModification @@ -1128,45 +1106,39 @@ void SMESH_Mesh::NotifySubMeshesHypothesisModification(const SMESH_Hypothesis* h if (_callUp) _callUp->HypothesisModified(); - const SMESH_Algo *foundAlgo = 0; - SMESH_HypoFilter algoKind, compatibleHypoKind; + SMESH_Algo *algo; + const SMESH_HypoFilter* compatibleHypoKind; list usedHyps; - - map < int, SMESH_subMesh * >::iterator itsm; - for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++) + SMESH_subMeshIteratorPtr smIt( _subMeshHolder->GetIterator() ); + while ( smIt->more() ) { - SMESH_subMesh *aSubMesh = (*itsm).second; - if ( aSubMesh->IsApplicableHypotesis( hyp )) + SMESH_subMesh* aSubMesh = smIt->next(); + + // if aSubMesh meshing depends on hyp, + // we call aSubMesh->AlgoStateEngine( MODIF_HYP, hyp ) that causes either + // 1) clearing of already computed aSubMesh or + // 2) changing algo_state from MISSING_HYP to HYP_OK when parameters of hyp becomes valid, + // other possible changes are not interesting. (IPAL0052457 - assigning hyp performance pb) + if ( aSubMesh->GetComputeState() != SMESH_subMesh::COMPUTE_OK && + aSubMesh->GetComputeState() != SMESH_subMesh::FAILED_TO_COMPUTE && + aSubMesh->GetAlgoState() != SMESH_subMesh::MISSING_HYP ) + continue; + + const TopoDS_Shape & aSubShape = aSubMesh->GetSubShape(); + + if (( aSubMesh->IsApplicableHypotesis( hyp )) && + ( algo = aSubMesh->GetAlgo() ) && + ( compatibleHypoKind = algo->GetCompatibleHypoFilter( !hyp->IsAuxiliary() )) && + ( compatibleHypoKind->IsOk( hyp, aSubShape ))) { - const TopoDS_Shape & aSubShape = aSubMesh->GetSubShape(); - - if ( !foundAlgo ) // init filter for algo search - algoKind.Init( THypType::IsAlgo() ).And( THypType::IsApplicableTo( aSubShape )); - - const SMESH_Algo *algo = static_cast - ( GetHypothesis( aSubShape, algoKind, true )); - - if ( algo ) + // check if hyp is used by algo + usedHyps.clear(); + if ( GetHypotheses( aSubShape, *compatibleHypoKind, usedHyps, true ) && + find( usedHyps.begin(), usedHyps.end(), hyp ) != usedHyps.end() ) { - bool sameAlgo = ( algo == foundAlgo ); - if ( !sameAlgo && foundAlgo ) - sameAlgo = ( strcmp( algo->GetName(), foundAlgo->GetName() ) == 0); - - if ( !sameAlgo ) { // init filter for used hypos search - if ( !algo->InitCompatibleHypoFilter( compatibleHypoKind, !hyp->IsAuxiliary() )) - continue; // algo does not use any hypothesis - foundAlgo = algo; - } - - // check if hyp is used by algo - usedHyps.clear(); - if ( GetHypotheses( aSubShape, compatibleHypoKind, usedHyps, true ) && - find( usedHyps.begin(), usedHyps.end(), hyp ) != usedHyps.end() ) - { - aSubMesh->AlgoStateEngine(SMESH_subMesh::MODIF_HYP, - const_cast< SMESH_Hypothesis*>( hyp )); - } + aSubMesh->AlgoStateEngine(SMESH_subMesh::MODIF_HYP, + const_cast< SMESH_Hypothesis*>( hyp )); } } } @@ -1221,21 +1193,23 @@ bool SMESH_Mesh::HasModificationsToDiscard() const // return true if the next Compute() will be partial and // existing but changed elements may prevent successful re-compute bool hasComputed = false, hasNotComputed = false; - map ::const_iterator i_sm = _mapSubMesh.begin(); - for ( ; i_sm != _mapSubMesh.end() ; ++i_sm ) - switch ( i_sm->second->GetSubShape().ShapeType() ) +SMESH_subMeshIteratorPtr smIt( _subMeshHolder->GetIterator() ); + while ( smIt->more() ) + { + const SMESH_subMesh* aSubMesh = smIt->next(); + switch ( aSubMesh->GetSubShape().ShapeType() ) { case TopAbs_EDGE: case TopAbs_FACE: case TopAbs_SOLID: - if ( i_sm->second->IsMeshComputed() ) + if ( aSubMesh->IsMeshComputed() ) hasComputed = true; else hasNotComputed = true; if ( hasComputed && hasNotComputed) return true; } - + } if ( NbNodes() < 1 ) const_cast(this)->_isModified = false; @@ -2147,7 +2121,6 @@ const TListOfListOfInt& SMESH_Mesh::GetMeshOrder() const void SMESH_Mesh::fillAncestorsMap(const TopoDS_Shape& theShape) { - int desType, ancType; if ( !theShape.IsSame( GetShapeToMesh()) && theShape.ShapeType() == TopAbs_COMPOUND ) { @@ -2193,16 +2166,16 @@ void SMESH_Mesh::fillAncestorsMap(const TopoDS_Shape& theShape) */ //============================================================================= -bool SMESH_Mesh::SortByMeshOrder(list& theListToSort) const + bool SMESH_Mesh::SortByMeshOrder(std::vector& theListToSort) const { if ( !_mySubMeshOrder.size() || theListToSort.size() < 2) return true; bool res = false; - list onlyOrderedList; + vector onlyOrderedList; // collect all ordered submeshes in one list as pointers // and get their positions within theListToSort - typedef list::iterator TPosInList; + typedef vector::iterator TPosInList; map< int, TPosInList > sortedPos; TPosInList smBeg = theListToSort.begin(), smEnd = theListToSort.end(); TListOfListOfInt::const_iterator listIdsIt = _mySubMeshOrder.begin(); @@ -2244,8 +2217,8 @@ bool SMESH_Mesh::SortByMeshOrder(list& theListToSort) const return res; res = true; - list::iterator onlyBIt = onlyOrderedList.begin(); - list::iterator onlyEIt = onlyOrderedList.end(); + vector::iterator onlyBIt = onlyOrderedList.begin(); + vector::iterator onlyEIt = onlyOrderedList.end(); // iterate on ordered submeshes and insert them in detected positions map< int, TPosInList >::iterator i_pos = sortedPos.begin(); @@ -2287,17 +2260,15 @@ bool SMESH_Mesh::IsOrderOK( const SMESH_subMesh* smBefore, */ //============================================================================= -list -SMESH_Mesh::getAncestorsSubMeshes (const TopoDS_Shape& theSubShape) const +void SMESH_Mesh::getAncestorsSubMeshes (const TopoDS_Shape& theSubShape, + std::vector< SMESH_subMesh* >& theSubMeshes) const { - list listOfSubMesh; + theSubMeshes.clear(); TopTools_ListIteratorOfListOfShape it( GetAncestors( theSubShape )); for (; it.More(); it.Next() ) if ( SMESH_subMesh* sm = GetSubMeshContaining( it.Value() )) - listOfSubMesh.push_back(sm); + theSubMeshes.push_back(sm); // sort submeshes according to stored mesh order - SortByMeshOrder( listOfSubMesh ); - - return listOfSubMesh; + SortByMeshOrder( theSubMeshes ); } diff --git a/src/SMESH/SMESH_Mesh.hxx b/src/SMESH/SMESH_Mesh.hxx index 19818878e..84086a3ea 100644 --- a/src/SMESH/SMESH_Mesh.hxx +++ b/src/SMESH/SMESH_Mesh.hxx @@ -182,8 +182,8 @@ public: */ void NotifySubMeshesHypothesisModification(const SMESH_Hypothesis* theChangedHyp); - const std::list < SMESH_subMesh * >& - GetSubMeshUsingHypothesis(SMESHDS_Hypothesis * anHyp) throw(SALOME_Exception); + // const std::list < SMESH_subMesh * >& + // GetSubMeshUsingHypothesis(SMESHDS_Hypothesis * anHyp) throw(SALOME_Exception); /*! * \brief Return True if anHyp is used to mesh aSubShape */ @@ -322,7 +322,7 @@ public: const TListOfListOfInt& GetMeshOrder() const; // sort submeshes according to stored mesh order - bool SortByMeshOrder(std::list& theListToSort) const; + bool SortByMeshOrder(std::vector& theListToSort) const; // return true if given order of sub-meshes is OK bool IsOrderOK( const SMESH_subMesh* smBefore, @@ -333,8 +333,8 @@ public: private: void fillAncestorsMap(const TopoDS_Shape& theShape); - std::list getAncestorsSubMeshes - (const TopoDS_Shape& theSubShape) const; + void getAncestorsSubMeshes(const TopoDS_Shape& theSubShape, + std::vector< SMESH_subMesh* >& theSubMeshes) const; protected: int _id; // id given by creator (unique within the creator instance) @@ -342,12 +342,14 @@ protected: int _groupId; // id generator for group objects int _nbSubShapes; // initial nb of subshapes in the shape to mesh bool _isShapeToMesh;// set to true when a shape is given (only once) - std::list _subMeshesUsingHypothesisList; + //std::list _subMeshesUsingHypothesisList; SMESHDS_Document * _myDocument; SMESHDS_Mesh * _myMeshDS; SMESH_Gen * _gen; - std::map _mapSubMesh; - std::map _mapGroup; + std::map _mapGroup; + + class SubMeshHolder; + SubMeshHolder* _subMeshHolder; bool _isAutoColor; bool _isModified; //!< modified since last total re-compute, issue 0020693 @@ -356,11 +358,13 @@ protected: TopTools_IndexedDataMapOfShapeListOfShape _mapAncestors; + mutable std::vector _ancestorSubMeshes; // to speed up GetHypothes[ei]s() + TListOfListOfInt _mySubMeshOrder; // Struct calling methods at CORBA API implementation level, used to - // 1) make an upper level be consistent with a lower one when group removal - // is invoked by hyp modification (issue 0020918) + // 1) make an upper level (SMESH_I) be consistent with a lower one (SMESH) + // when group removal is invoked by hyp modification (issue 0020918) // 2) to forget not loaded mesh data at hyp modification TCallUp* _callUp; diff --git a/src/SMESH/SMESH_MeshEditor.cxx b/src/SMESH/SMESH_MeshEditor.cxx index 1cf9b4fc0..6bdd80cac 100644 --- a/src/SMESH/SMESH_MeshEditor.cxx +++ b/src/SMESH/SMESH_MeshEditor.cxx @@ -518,14 +518,12 @@ int SMESH_MeshEditor::FindShape (const SMDS_MeshElement * theElem) } else { - const map& id2sm = GetMeshDS()->SubMeshes(); - map::const_iterator id_sm = id2sm.begin(); - for ( ; id_sm != id2sm.end(); ++id_sm ) - if ( id_sm->second->Contains( theElem )) - return id_sm->first; + SMESHDS_SubMeshIteratorPtr smIt = GetMeshDS()->SubMeshes(); + while ( const SMESHDS_SubMesh* sm = smIt->next() ) + if ( sm->Contains( theElem )) + return sm->GetID(); } - //MESSAGE ("::FindShape() - SHAPE NOT FOUND") return 0; } diff --git a/src/SMESHDS/SMESHDS_Mesh.cxx b/src/SMESHDS/SMESHDS_Mesh.cxx index 6766fbda7..ff1da64b0 100644 --- a/src/SMESHDS/SMESHDS_Mesh.cxx +++ b/src/SMESHDS/SMESHDS_Mesh.cxx @@ -27,14 +27,15 @@ // #include "SMESHDS_Mesh.hxx" -#include "SMESHDS_Group.hxx" -#include "SMDS_VertexPosition.hxx" +#include "SMDS_Downward.hxx" #include "SMDS_EdgePosition.hxx" #include "SMDS_FacePosition.hxx" #include "SMDS_SpacePosition.hxx" -#include "SMDS_Downward.hxx" +#include "SMDS_VertexPosition.hxx" +#include "SMESHDS_Group.hxx" #include "SMESHDS_GroupOnGeom.hxx" #include "SMESHDS_Script.hxx" +#include "SMESHDS_TSubMeshHolder.hxx" #include #include @@ -51,17 +52,20 @@ using namespace std; +class SMESHDS_Mesh::SubMeshHolder : public SMESHDS_TSubMeshHolder< const SMESHDS_SubMesh > +{ +}; + //======================================================================= //function : Create //purpose : //======================================================================= SMESHDS_Mesh::SMESHDS_Mesh(int theMeshID, bool theIsEmbeddedMode): myMeshID(theMeshID), - myIsEmbeddedMode(theIsEmbeddedMode), - myCurSubID(-1) + mySubMeshHolder( new SubMeshHolder ), + myIsEmbeddedMode(theIsEmbeddedMode) { myScript = new SMESHDS_Script(theIsEmbeddedMode); - myCurSubMesh = 0; SetPersistentId(theMeshID); } @@ -107,19 +111,17 @@ void SMESHDS_Mesh::ShapeToMesh(const TopoDS_Shape & S) // - hypotheses myShapeToHypothesis.Clear(); // - shape indices in SMDS_Position of nodes - map::iterator i_sub = myShapeIndexToSubMesh.begin(); - for ( ; i_sub != myShapeIndexToSubMesh.end(); i_sub++ ) { - if ( !i_sub->second->IsComplexSubmesh() ) { - SMDS_NodeIteratorPtr nIt = i_sub->second->GetNodes(); + SMESHDS_SubMeshIteratorPtr smIt = SubMeshes(); + while ( SMESHDS_SubMesh* sm = const_cast< SMESHDS_SubMesh* >( smIt->next() )) { + if ( !sm->IsComplexSubmesh() ) { + SMDS_NodeIteratorPtr nIt = sm->GetNodes(); while ( nIt->more() ) - i_sub->second->RemoveNode(nIt->next(), false); + sm->RemoveNode(nIt->next(), false); } } // - sub-meshes - TShapeIndexToSubMesh::iterator i_sm = myShapeIndexToSubMesh.begin(); - for ( ; i_sm != myShapeIndexToSubMesh.end(); ++i_sm ) - delete i_sm->second; - myShapeIndexToSubMesh.clear(); + mySubMeshHolder->DeleteAll(); + myIndexToShape.Clear(); // - groups on geometry set::iterator gr = myGroups.begin(); @@ -145,12 +147,12 @@ void SMESHDS_Mesh::ShapeToMesh(const TopoDS_Shape & S) bool SMESHDS_Mesh::AddHypothesis(const TopoDS_Shape & SS, const SMESHDS_Hypothesis * H) { - if (!myShapeToHypothesis.IsBound(SS.Oriented(TopAbs_FORWARD))) { + if (!myShapeToHypothesis.IsBound(SS/*.Oriented(TopAbs_FORWARD)*/)) { list aList; - myShapeToHypothesis.Bind(SS.Oriented(TopAbs_FORWARD), aList); + myShapeToHypothesis.Bind(SS/*.Oriented(TopAbs_FORWARD)*/, aList); } list& alist = - myShapeToHypothesis(SS.Oriented(TopAbs_FORWARD)); // ignore orientation of SS + myShapeToHypothesis(SS/*.Oriented(TopAbs_FORWARD)*/); // ignore orientation of SS //Check if the Hypothesis is still present list::iterator ith = find(alist.begin(),alist.end(), H ); @@ -169,9 +171,9 @@ bool SMESHDS_Mesh::AddHypothesis(const TopoDS_Shape & SS, bool SMESHDS_Mesh::RemoveHypothesis(const TopoDS_Shape & S, const SMESHDS_Hypothesis * H) { - if( myShapeToHypothesis.IsBound( S.Oriented(TopAbs_FORWARD) ) ) + if( myShapeToHypothesis.IsBound( S/*.Oriented(TopAbs_FORWARD)*/ ) ) { - list& alist=myShapeToHypothesis.ChangeFind( S.Oriented(TopAbs_FORWARD) ); + list& alist=myShapeToHypothesis.ChangeFind( S/*.Oriented(TopAbs_FORWARD)*/ ); list::iterator ith=find(alist.begin(),alist.end(), H ); if (ith != alist.end()) { @@ -790,7 +792,7 @@ SMDS_MeshVolume* SMESHDS_Mesh::AddPolyhedralVolume //purpose : //======================================================================= -static void removeFromContainers (map& theSubMeshes, +static void removeFromContainers (SMESHDS_Mesh* theMesh, set& theGroups, list& theElems, const bool isNode) @@ -821,18 +823,17 @@ static void removeFromContainers (map& theSubMeshes, // Rm from sub-meshes // Element should belong to only one sub-mesh - if ( !theSubMeshes.empty() ) + if ( theMesh->SubMeshes()->more() ) { - SMESHDS_Mesh* mesh = theSubMeshes.begin()->second->GetParent(); list::iterator elIt = theElems.begin(); if ( isNode ) { for ( ; elIt != theElems.end(); ++elIt ) - if ( SMESHDS_SubMesh* sm = mesh->MeshElements( (*elIt)->getshapeId() )) + if ( SMESHDS_SubMesh* sm = theMesh->MeshElements( (*elIt)->getshapeId() )) sm->RemoveNode( static_cast (*elIt), deleted ); } else { for ( ; elIt != theElems.end(); ++elIt ) - if ( SMESHDS_SubMesh* sm = mesh->MeshElements( (*elIt)->getshapeId() )) + if ( SMESHDS_SubMesh* sm = theMesh->MeshElements( (*elIt)->getshapeId() )) sm->RemoveElement( *elIt, deleted ); } } @@ -840,36 +841,34 @@ static void removeFromContainers (map& theSubMeshes, //======================================================================= //function : RemoveNode -//purpose : +//purpose : //======================================================================= void SMESHDS_Mesh::RemoveNode(const SMDS_MeshNode * n) { if ( n->NbInverseElements() == 0 && !(hasConstructionEdges() || hasConstructionFaces())) { - SMESHDS_SubMesh* subMesh=0; - map::iterator SubIt = - myShapeIndexToSubMesh.find( n->getshapeId() ); - if ( SubIt != myShapeIndexToSubMesh.end() ) - subMesh = SubIt->second; - else - SubIt = myShapeIndexToSubMesh.begin(); - for ( ; !subMesh && SubIt != myShapeIndexToSubMesh.end(); SubIt++ ) - if (!SubIt->second->IsComplexSubmesh() && SubIt->second->Contains( n )) - subMesh = SubIt->second; - + SMESHDS_SubMesh* subMesh = MeshElements( n->getshapeId() ); + SMESHDS_SubMeshIteratorPtr subIt; + if ( !subMesh ) + subIt = SubMeshes(); + for ( ; !subMesh && subIt->more(); ) { + subMesh = const_cast< SMESHDS_SubMesh* >( subIt->next() ); + if ( subMesh->IsComplexSubmesh() || !subMesh->Contains( n )) + subMesh = 0; + } RemoveFreeNode( n, subMesh, true); return; } - + myScript->RemoveNode(n->GetID()); - + list removedElems; list removedNodes; SMDS_Mesh::RemoveElement( n, removedElems, removedNodes, true ); - removeFromContainers( myShapeIndexToSubMesh, myGroups, removedElems, false ); - removeFromContainers( myShapeIndexToSubMesh, myGroups, removedNodes, true ); + removeFromContainers( this, myGroups, removedElems, false ); + removeFromContainers( this, myGroups, removedNodes, true ); } //======================================================================= @@ -917,11 +916,8 @@ void SMESHDS_Mesh::RemoveElement(const SMDS_MeshElement * elt) { SMESHDS_SubMesh* subMesh=0; if ( elt->getshapeId() > 0 ) - { - map::iterator SubIt = myShapeIndexToSubMesh.find( elt->getshapeId() ); - if ( SubIt != myShapeIndexToSubMesh.end() ) - subMesh = SubIt->second; - } + subMesh = MeshElements( elt->getshapeId() ); + RemoveFreeElement( elt, subMesh, true); return; } @@ -933,7 +929,7 @@ void SMESHDS_Mesh::RemoveElement(const SMDS_MeshElement * elt) SMDS_Mesh::RemoveElement(elt, removedElems, removedNodes, false); - removeFromContainers( myShapeIndexToSubMesh, myGroups, removedElems, false ); + removeFromContainers( this, myGroups, removedElems, false ); } //======================================================================= @@ -987,9 +983,9 @@ void SMESHDS_Mesh::ClearMesh() SMDS_Mesh::Clear(); // clear submeshes - map::iterator sub, subEnd = myShapeIndexToSubMesh.end(); - for ( sub = myShapeIndexToSubMesh.begin(); sub != subEnd; ++sub ) - sub->second->Clear(); + SMESHDS_SubMeshIteratorPtr smIt = SubMeshes(); + while ( SMESHDS_SubMesh* sm = const_cast< SMESHDS_SubMesh* >( smIt->next() )) + sm->Clear(); // clear groups TGroups::iterator group, groupEnd = myGroups.end(); @@ -1011,8 +1007,6 @@ void SMESHDS_Mesh::ClearMesh() * \brief return submesh by shape * \param shape - the sub-shape * \retval SMESHDS_SubMesh* - the found submesh - * - * search of submeshes is optimized */ //================================================================================ @@ -1021,35 +1015,7 @@ SMESHDS_SubMesh* SMESHDS_Mesh::getSubmesh( const TopoDS_Shape & shape ) if ( shape.IsNull() ) return 0; - if ( !myCurSubShape.IsNull() && shape.IsSame( myCurSubShape )) - return myCurSubMesh; - - getSubmesh( ShapeToIndex( shape )); - myCurSubShape = shape; - return myCurSubMesh; -} - -//================================================================================ -/*! - * \brief return submesh by sub-shape index - * \param Index - the sub-shape index - * \retval SMESHDS_SubMesh* - the found submesh - * search of submeshes is optimized - */ -//================================================================================ - -SMESHDS_SubMesh* SMESHDS_Mesh::getSubmesh( const int Index ) -{ - //Update or build submesh - if ( Index != myCurSubID ) { - map::iterator it = myShapeIndexToSubMesh.find( Index ); - if ( it == myShapeIndexToSubMesh.end() ) - it = myShapeIndexToSubMesh.insert( make_pair(Index, new SMESHDS_SubMesh(this, Index) )).first; - myCurSubMesh = it->second; - myCurSubID = Index; - myCurSubShape.Nullify(); // myCurSubShape no more corresponds to submesh - } - return myCurSubMesh; + return NewSubMesh( ShapeToIndex( shape )); } //================================================================================ @@ -1142,12 +1108,9 @@ void SMESHDS_Mesh::SetNodeOnVertex(const SMDS_MeshNode * aNode, void SMESHDS_Mesh::UnSetNodeOnShape(const SMDS_MeshNode* aNode) { int shapeId = aNode->getshapeId(); - if (shapeId >= 0) - { - map::iterator it = myShapeIndexToSubMesh.find(shapeId); - if (it != myShapeIndexToSubMesh.end()) - it->second->RemoveNode(aNode, /*deleted=*/false); - } + if (shapeId > 0) + if ( SMESHDS_SubMesh* sm = MeshElements( shapeId )) + sm->RemoveNode(aNode, /*deleted=*/false); } //======================================================================= @@ -1167,16 +1130,13 @@ void SMESHDS_Mesh::SetMeshElementOnShape(const SMDS_MeshElement * anElement, void SMESHDS_Mesh::UnSetMeshElementOnShape(const SMDS_MeshElement * elem, const TopoDS_Shape & S) { - int Index = myIndexToShape.FindIndex(S); - - map::iterator it = myShapeIndexToSubMesh.find( Index ); - if ( it != myShapeIndexToSubMesh.end() ) - { - if (elem->GetType() == SMDSAbs_Node) - it->second->RemoveNode(static_cast (elem), /*deleted=*/false); - else - it->second->RemoveElement(elem, /*deleted=*/false); - } + if ( SMESHDS_SubMesh* sm = MeshElements( S )) + { + if (elem->GetType() == SMDSAbs_Node) + sm->RemoveNode(static_cast (elem), /*deleted=*/false); + else + sm->RemoveElement(elem, /*deleted=*/false); + } } //======================================================================= @@ -1185,7 +1145,7 @@ void SMESHDS_Mesh::UnSetMeshElementOnShape(const SMDS_MeshElement * elem, //======================================================================= TopoDS_Shape SMESHDS_Mesh::ShapeToMesh() const { - return myShape; + return myShape; } //======================================================================= @@ -1213,11 +1173,7 @@ bool SMESHDS_Mesh::IsGroupOfSubShapes (const TopoDS_Shape& theShape) const SMESHDS_SubMesh * SMESHDS_Mesh::MeshElements(const TopoDS_Shape & S) const { int Index = ShapeToIndex(S); - TShapeIndexToSubMesh::const_iterator anIter = myShapeIndexToSubMesh.find(Index); - if (anIter != myShapeIndexToSubMesh.end()) - return anIter->second; - else - return NULL; + return (SMESHDS_SubMesh *) ( Index ? mySubMeshHolder->Get( Index ) : 0 ); } /////////////////////////////////////////////////////////////////////////////// @@ -1225,11 +1181,7 @@ SMESHDS_SubMesh * SMESHDS_Mesh::MeshElements(const TopoDS_Shape & S) const /////////////////////////////////////////////////////////////////////////////// SMESHDS_SubMesh * SMESHDS_Mesh::MeshElements(const int Index) const { - TShapeIndexToSubMesh::const_iterator anIter = myShapeIndexToSubMesh.find(Index); - if (anIter != myShapeIndexToSubMesh.end()) - return anIter->second; - else - return NULL; + return const_cast< SMESHDS_SubMesh* >( mySubMeshHolder->Get( Index )); } //======================================================================= @@ -1239,13 +1191,23 @@ SMESHDS_SubMesh * SMESHDS_Mesh::MeshElements(const int Index) const list SMESHDS_Mesh::SubMeshIndices() const { list anIndices; - std::map::const_iterator anIter = myShapeIndexToSubMesh.begin(); - for (; anIter != myShapeIndexToSubMesh.end(); anIter++) { - anIndices.push_back((*anIter).first); - } + SMESHDS_SubMeshIteratorPtr smIt = SubMeshes(); + while ( const SMESHDS_SubMesh* sm = smIt->next() ) + anIndices.push_back( sm->GetID() ); + return anIndices; } +//======================================================================= +//function : SubMeshes +//purpose : +//======================================================================= + +SMESHDS_SubMeshIteratorPtr SMESHDS_Mesh::SubMeshes() const +{ + return SMESHDS_SubMeshIteratorPtr( mySubMeshHolder->GetIterator() ); +} + //======================================================================= //function : GetHypothesis //purpose : @@ -1254,8 +1216,8 @@ list SMESHDS_Mesh::SubMeshIndices() const const list& SMESHDS_Mesh::GetHypothesis(const TopoDS_Shape & S) const { - if ( myShapeToHypothesis.IsBound( S.Oriented(TopAbs_FORWARD) ) ) // ignore orientation of S - return myShapeToHypothesis.Find( S.Oriented(TopAbs_FORWARD) ); + if ( myShapeToHypothesis.IsBound( S/*.Oriented(TopAbs_FORWARD)*/ ) ) // ignore orientation of S + return myShapeToHypothesis.Find( S/*.Oriented(TopAbs_FORWARD)*/ ); static list empty; return empty; @@ -1300,9 +1262,8 @@ void SMESHDS_Mesh::ClearScript() //======================================================================= bool SMESHDS_Mesh::HasMeshElements(const TopoDS_Shape & S) const { - if (myShape.IsNull()) MESSAGE("myShape is NULL"); - int Index = myIndexToShape.FindIndex(S); - return myShapeIndexToSubMesh.find(Index)!=myShapeIndexToSubMesh.end(); + int Index = myIndexToShape.FindIndex(S); + return mySubMeshHolder->Get( Index ); } //======================================================================= @@ -1311,7 +1272,7 @@ bool SMESHDS_Mesh::HasMeshElements(const TopoDS_Shape & S) const //======================================================================= bool SMESHDS_Mesh::HasHypothesis(const TopoDS_Shape & S) { - return myShapeToHypothesis.IsBound(S.Oriented(TopAbs_FORWARD)); + return myShapeToHypothesis.IsBound(S/*.Oriented(TopAbs_FORWARD)*/); } //======================================================================= @@ -1320,15 +1281,12 @@ bool SMESHDS_Mesh::HasHypothesis(const TopoDS_Shape & S) //======================================================================= SMESHDS_SubMesh * SMESHDS_Mesh::NewSubMesh(int Index) { - SMESHDS_SubMesh* SM = 0; - TShapeIndexToSubMesh::iterator anIter = myShapeIndexToSubMesh.find(Index); - if (anIter == myShapeIndexToSubMesh.end()) + SMESHDS_SubMesh* SM = MeshElements( Index ); + if ( !SM ) { SM = new SMESHDS_SubMesh(this, Index); - myShapeIndexToSubMesh[Index]=SM; + mySubMeshHolder->Add( Index, SM ); } - else - SM = anIter->second; return SM; } @@ -1394,7 +1352,7 @@ const TopoDS_Shape& SMESHDS_Mesh::IndexToShape(int ShapeIndex) const int SMESHDS_Mesh::MaxSubMeshIndex() const { - return myShapeIndexToSubMesh.empty() ? 0 : myShapeIndexToSubMesh.rbegin()->first; + return mySubMeshHolder->GetMaxID(); } //======================================================================= @@ -1417,8 +1375,7 @@ int SMESHDS_Mesh::ShapeToIndex(const TopoDS_Shape & S) const //======================================================================= void SMESHDS_Mesh::SetNodeInVolume(const SMDS_MeshNode* aNode, int Index) { - //add(aNode, getSubmesh(Index)); - if ( add( aNode, getSubmesh( Index ))) + if ( add( aNode, NewSubMesh( Index ))) ((SMDS_MeshNode*) aNode)->SetPosition( SMDS_SpacePosition::originSpacePosition()); } @@ -1429,7 +1386,7 @@ void SMESHDS_Mesh::SetNodeInVolume(const SMDS_MeshNode* aNode, int Index) void SMESHDS_Mesh::SetNodeOnFace(const SMDS_MeshNode* aNode, int Index, double u, double v) { //Set Position on Node - if ( add( aNode, getSubmesh( Index ))) + if ( add( aNode, NewSubMesh( Index ))) const_cast< SMDS_MeshNode* > ( aNode )->SetPosition(SMDS_PositionPtr(new SMDS_FacePosition( u, v))); } @@ -1443,7 +1400,7 @@ void SMESHDS_Mesh::SetNodeOnEdge(const SMDS_MeshNode* aNode, double u) { //Set Position on Node - if ( add( aNode, getSubmesh( Index ))) + if ( add( aNode, NewSubMesh( Index ))) const_cast< SMDS_MeshNode* > ( aNode )->SetPosition(SMDS_PositionPtr(new SMDS_EdgePosition(u))); } @@ -1455,7 +1412,7 @@ void SMESHDS_Mesh::SetNodeOnEdge(const SMDS_MeshNode* aNode, void SMESHDS_Mesh::SetNodeOnVertex(const SMDS_MeshNode* aNode, int Index) { //Set Position on Node - if ( add( aNode, getSubmesh( Index ))) + if ( add( aNode, NewSubMesh( Index ))) const_cast< SMDS_MeshNode* > ( aNode )->SetPosition(SMDS_PositionPtr(new SMDS_VertexPosition())); } @@ -1467,7 +1424,7 @@ void SMESHDS_Mesh::SetNodeOnVertex(const SMDS_MeshNode* aNode, int Index) void SMESHDS_Mesh::SetMeshElementOnShape(const SMDS_MeshElement* anElement, int Index) { - add( anElement, getSubmesh( Index )); + add( anElement, NewSubMesh( Index )); } //======================================================================= @@ -1479,9 +1436,7 @@ SMESHDS_Mesh::~SMESHDS_Mesh() // myScript delete myScript; // submeshes - TShapeIndexToSubMesh::iterator i_sm = myShapeIndexToSubMesh.begin(); - for ( ; i_sm != myShapeIndexToSubMesh.end(); ++i_sm ) - delete i_sm->second; + delete mySubMeshHolder; } @@ -2279,20 +2234,20 @@ void SMESHDS_Mesh::compactMesh() int myCellsSize = myCells.size(); int newSmdsId = 0; for (int i = 0; i < myCellsSize; i++) + { + if (myCells[i]) { - if (myCells[i]) - { - newSmdsId++; // SMDS id start to 1 - assert(newSmdsId <= newCellSize); - newCells[newSmdsId] = myCells[i]; - newCells[newSmdsId]->setId(newSmdsId); - //MESSAGE("myCells["<< i << "] --> newCells[" << newSmdsId << "]"); - int idvtk = myCells[i]->getVtkId(); - //newSmdsToVtk[newSmdsId] = idvtk; - assert(idvtk < newCellSize); - newVtkToSmds[idvtk] = newSmdsId; - } + newSmdsId++; // SMDS id start to 1 + assert(newSmdsId <= newCellSize); + newCells[newSmdsId] = myCells[i]; + newCells[newSmdsId]->setId(newSmdsId); + //MESSAGE("myCells["<< i << "] --> newCells[" << newSmdsId << "]"); + int idvtk = myCells[i]->getVtkId(); + //newSmdsToVtk[newSmdsId] = idvtk; + assert(idvtk < newCellSize); + newVtkToSmds[idvtk] = newSmdsId; } + } myCells.swap(newCells); //myCellIdSmdsToVtk.swap(newSmdsToVtk); @@ -2305,12 +2260,9 @@ void SMESHDS_Mesh::compactMesh() // --- compact list myNodes and myElements in submeshes - map::iterator it = myShapeIndexToSubMesh.begin(); - for(; it != myShapeIndexToSubMesh.end(); ++it) - { - (*it).second->compactList(); - } - + SMESHDS_SubMeshIteratorPtr smIt = SubMeshes(); + while ( SMESHDS_SubMesh* sm = const_cast< SMESHDS_SubMesh* >( smIt->next() )) + sm->compactList(); } void SMESHDS_Mesh::CleanDownWardConnectivity() diff --git a/src/SMESHDS/SMESHDS_Mesh.hxx b/src/SMESHDS/SMESHDS_Mesh.hxx index 8b8fc0a55..e51df85d0 100644 --- a/src/SMESHDS/SMESHDS_Mesh.hxx +++ b/src/SMESHDS/SMESHDS_Mesh.hxx @@ -35,6 +35,8 @@ #include #include +#include + class TopoDS_Solid ; class TopoDS_Shell ; class TopoDS_Face ; @@ -50,8 +52,6 @@ class SMDS_MeshVolume ; class SMDS_Mesh0DElement; class SMDS_BallElement; -#include - /* * Using of native hash_map isn't portable and don't work on WIN32 platform. * So this functionality implement on new NCollection_DataMap technology @@ -566,9 +566,7 @@ public: SMESHDS_SubMesh * MeshElements(const TopoDS_Shape & S) const; SMESHDS_SubMesh * MeshElements(const int Index) const; std::list SubMeshIndices() const; - const std::map& SubMeshes() const - { return myShapeIndexToSubMesh; } - const TopoDS_Shape& GetCurrentSubShape() const { return myCurSubShape; } + SMESHDS_SubMeshIteratorPtr SubMeshes() const; bool HasHypothesis(const TopoDS_Shape & S); const std::list& GetHypothesis(const TopoDS_Shape & S) const; @@ -601,22 +599,14 @@ public: ~SMESHDS_Mesh(); private: - void addNodeToSubmesh( const SMDS_MeshNode* aNode, int Index ) - { - //Update or build submesh - std::map::iterator it = myShapeIndexToSubMesh.find( Index ); - if ( it == myShapeIndexToSubMesh.end() ) - it = myShapeIndexToSubMesh.insert( std::make_pair(Index, new SMESHDS_SubMesh(this, Index) )).first; - it->second->AddNode( aNode ); // add aNode to submesh - } - + ShapeToHypothesis myShapeToHypothesis; int myMeshID, myPersistentID; TopoDS_Shape myShape; - typedef std::map TShapeIndexToSubMesh; - TShapeIndexToSubMesh myShapeIndexToSubMesh; + class SubMeshHolder; + SubMeshHolder* mySubMeshHolder; TopTools_IndexedMapOfShape myIndexToShape; @@ -626,14 +616,8 @@ private: SMESHDS_Script* myScript; bool myIsEmbeddedMode; - // optimize addition of nodes/elements to submeshes by, SetNodeInVolume() etc: - // avoid search of submeshes in maps bool add( const SMDS_MeshElement* elem, SMESHDS_SubMesh* subMesh ); SMESHDS_SubMesh* getSubmesh( const TopoDS_Shape & shape); - SMESHDS_SubMesh* getSubmesh( const int Index ); - int myCurSubID; - TopoDS_Shape myCurSubShape; - SMESHDS_SubMesh* myCurSubMesh; }; diff --git a/src/SMESHDS/SMESHDS_TSubMeshHolder.hxx b/src/SMESHDS/SMESHDS_TSubMeshHolder.hxx new file mode 100644 index 000000000..b6fa226da --- /dev/null +++ b/src/SMESHDS/SMESHDS_TSubMeshHolder.hxx @@ -0,0 +1,143 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +#ifndef __SMESHDS_SubMeshHolder_HXX__ +#define __SMESHDS_SubMeshHolder_HXX__ + +#include +#include + +//======================================================================= +/*! + * \brief A binder of a sub-mesh to its ID which can be negative. Provides fast + * access to a sub-mesh by its ID. + * + * Issue 52457: Addition of hypotheses is 8 time longer than meshing. + */ +//======================================================================= + +template +class SMESHDS_TSubMeshHolder +{ + std::vector< SUBMESH* > myVec; // for ID >= 0 + std::map< int, SUBMESH* > myMap; // for ID < 0 + +public: + + ~SMESHDS_TSubMeshHolder() + { + DeleteAll(); + } + void Add( int id, SUBMESH* sm ) + { + if ( id < 0 ) + { + myMap[ id ] = sm; + } + else + { + if ( myVec.size() <= id ) + myVec.resize( id+1, (SUBMESH*) NULL ); + myVec[ id ] = sm; + } + } + SUBMESH* Get( int id ) const + { + if ( id < 0 ) + { + typename std::map< int, SUBMESH* >::const_iterator i2sm = myMap.find( id ); + return (SUBMESH*) ( i2sm == myMap.end() ? NULL : i2sm->second ); + } + else + { + return (SUBMESH*) ( id >= myVec.size() ? NULL : myVec[ id ]); + } + } + void DeleteAll() + { + for ( size_t i = 0; i < myVec.size(); ++i ) + delete myVec[i]; + myVec.clear(); + + typename std::map< int, SUBMESH* >::iterator i2sm = myMap.begin(); + for ( ; i2sm != myMap.end(); ++i2sm ) + delete i2sm->second; + myMap.clear(); + } + int GetMinID() const + { + return myMap.empty() ? 0 : myMap.begin()->first; + } + int GetMaxID() const + { + return myVec.empty() ? ( myMap.empty() ? 0 : myMap.rbegin()->first ) : myVec.size(); + } + + //----------------------------------------------------------------------- + struct Iterator : public SMDS_Iterator< SUBMESH* > + { + const SMESHDS_TSubMeshHolder* myHolder; + SUBMESH* myNext; + int myCurID, myEndID, myIDDelta; + + void init( const SMESHDS_TSubMeshHolder* holder, + int firstID, int endID, int delta ) + { + myHolder = holder; + myNext = 0; + myCurID = firstID; + myEndID = endID; + myIDDelta = delta; + + next(); + } + + bool more() + { + return myNext; + } + + SUBMESH* next() + { + SUBMESH* res = myNext; + myNext = 0; + while ( !myNext && myCurID != myEndID ) + { + myNext = myHolder->Get( myCurID ); + myCurID += myIDDelta; + } + return res; + } + virtual ~Iterator() {} + }; + //----------------------------------------------------------------------- + + SMDS_Iterator< SUBMESH* >* GetIterator(const bool reverse=false) const + { + Iterator* iter = new Iterator; + if ( reverse ) iter->init( this, GetMaxID(), GetMinID()-1, -1 ); + else iter->init( this, GetMinID(), GetMaxID()+1, +1 ); + return iter; + } +}; + + +#endif diff --git a/src/SMESH_I/SMESH_Gen_i.cxx b/src/SMESH_I/SMESH_Gen_i.cxx index 815426be4..7d1dbf9c8 100644 --- a/src/SMESH_I/SMESH_Gen_i.cxx +++ b/src/SMESH_I/SMESH_Gen_i.cxx @@ -3696,7 +3696,8 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, myLocMesh.ShapeToMesh( nullShape ); // remove shape referring data } - if ( !mySMESHDSMesh->SubMeshes().empty() ) + SMESHDS_SubMeshIteratorPtr smIt = mySMESHDSMesh->SubMeshes(); + if ( smIt->more() ) { // Store submeshes // ---------------- @@ -3706,52 +3707,9 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, // each element belongs to one or none submesh, // so for each node/element, we store a submesh ID - // Make maps of submesh IDs of elements sorted by element IDs - // typedef int TElemID; - // typedef int TSubMID; - // map< TElemID, TSubMID > eId2smId, nId2smId; - const map& aSubMeshes = mySMESHDSMesh->SubMeshes(); - map::const_iterator itSubM ( aSubMeshes.begin() ); - // SMDS_NodeIteratorPtr itNode; - // SMDS_ElemIteratorPtr itElem; - // for ( itSubM = aSubMeshes.begin(); itSubM != aSubMeshes.end() ; itSubM++ ) - // { - // TSubMID aSubMeID = itSubM->first; - // SMESHDS_SubMesh* aSubMesh = itSubM->second; - // if ( aSubMesh->IsComplexSubmesh() ) - // continue; // sub-mesh containing other sub-meshes - // // nodes - // for ( itNode = aSubMesh->GetNodes(); itNode->more(); ++hint) - // nId2smId.insert( nId2smId.back(), make_pair( itNode->next()->GetID(), aSubMeID )); - // // elements - // for ( itElem = aSubMesh->GetElements(); itElem->more(); ++hint) - // hint = eId2smId.insert( eId2smId.back(), make_pair( itElem->next()->GetID(), aSubMeID )); - // } - - // // Care of elements that are not on submeshes - // if ( mySMESHDSMesh->NbNodes() != nId2smId.size() ) { - // for ( itNode = mySMESHDSMesh->nodesIterator(); itNode->more(); ) - // /* --- stl_map.h says : */ - // /* A %map relies on unique keys and thus a %pair is only inserted if its */ - // /* first element (the key) is not already present in the %map. */ - // nId2smId.insert( make_pair( itNode->next()->GetID(), 0 )); - // } - // int nbElems = mySMESHDSMesh->GetMeshInfo().NbElements(); - // if ( nbElems != eId2smId.size() ) { - // for ( itElem = mySMESHDSMesh->elementsIterator(); itElem->more(); ) - // eId2smId.insert( make_pair( itElem->next()->GetID(), 0 )); - // } - // Store submesh IDs for ( int isNode = 0; isNode < 2; ++isNode ) { - // map< TElemID, TSubMID >& id2smId = isNode ? nId2smId : eId2smId; - // if ( id2smId.empty() ) continue; - // map< TElemID, TSubMID >::const_iterator id_smId = id2smId.begin(); - // // make and fill array of submesh IDs - // int* smIDs = new int [ id2smId.size() ]; - // for ( int i = 0; id_smId != id2smId.end(); ++id_smId, ++i ) - // smIDs[ i ] = id_smId->second; SMDS_ElemIteratorPtr eIt = mySMESHDSMesh->elementsIterator( isNode ? SMDSAbs_Node : SMDSAbs_All ); int nbElems = isNode ? mySMESHDSMesh->NbNodes() : mySMESHDSMesh->GetMeshInfo().NbElements(); @@ -3790,15 +3748,15 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, int nbEdgeNodes = 0, nbFaceNodes = 0; list aEdgeSM, aFaceSM; // loop on SMESHDS_SubMesh'es - for ( itSubM = aSubMeshes.begin(); itSubM != aSubMeshes.end() ; itSubM++ ) + while ( smIt->more() ) { - SMESHDS_SubMesh* aSubMesh = (*itSubM).second; + SMESHDS_SubMesh* aSubMesh = const_cast< SMESHDS_SubMesh* >( smIt->next() ); if ( aSubMesh->IsComplexSubmesh() ) continue; // submesh containing other submeshs int nbNodes = aSubMesh->NbNodes(); if ( nbNodes == 0 ) continue; - int aShapeID = (*itSubM).first; + int aShapeID = aSubMesh->GetID(); if ( aShapeID < 1 || aShapeID > mySMESHDSMesh->MaxShapeIndex() ) continue; int aShapeType = mySMESHDSMesh->IndexToShape( aShapeID ).ShapeType(); diff --git a/src/StdMeshers/StdMeshers_ProjectionUtils.cxx b/src/StdMeshers/StdMeshers_ProjectionUtils.cxx index 32ac43e84..92474f205 100644 --- a/src/StdMeshers/StdMeshers_ProjectionUtils.cxx +++ b/src/StdMeshers/StdMeshers_ProjectionUtils.cxx @@ -2132,7 +2132,7 @@ bool StdMeshers_ProjectionUtils::MakeComputed(SMESH_subMesh * sm, const int iter mesh->GetHypotheses( shape, hypoFilter, hyps, true, &assignedTo ); if ( nbAlgos > 1 ) // concurrent algos { - list smList; // where an algo is assigned + vector smList; // where an algo is assigned list< TopoDS_Shape >::iterator shapeIt = assignedTo.begin(); for ( ; shapeIt != assignedTo.end(); ++shapeIt ) smList.push_back( mesh->GetSubMesh( *shapeIt )); diff --git a/src/StdMeshers/StdMeshers_RadialQuadrangle_1D2D.cxx b/src/StdMeshers/StdMeshers_RadialQuadrangle_1D2D.cxx index 30612ef3d..cb6aa8f7f 100644 --- a/src/StdMeshers/StdMeshers_RadialQuadrangle_1D2D.cxx +++ b/src/StdMeshers/StdMeshers_RadialQuadrangle_1D2D.cxx @@ -994,9 +994,9 @@ bool StdMeshers_RadialQuadrangle_1D2D::computeLayerPositions(const gp_Pnt& if ( !edge.IsNull() ) { // find a hyp usable by TNodeDistributor - SMESH_HypoFilter hypKind; - TNodeDistributor::GetDistributor(*mesh)->InitCompatibleHypoFilter(hypKind,/*ignoreAux=*/1); - hyp1D = mesh->GetHypothesis( edge, hypKind, /*fromAncestors=*/true); + const SMESH_HypoFilter* hypKind = + TNodeDistributor::GetDistributor(*mesh)->GetCompatibleHypoFilter(/*ignoreAux=*/true); + hyp1D = mesh->GetHypothesis( edge, *hypKind, /*fromAncestors=*/true); } } if ( hyp1D ) // try to compute with hyp1D diff --git a/src/StdMeshers/StdMeshers_Regular_1D.cxx b/src/StdMeshers/StdMeshers_Regular_1D.cxx index f3449e85d..1c97ebc36 100644 --- a/src/StdMeshers/StdMeshers_Regular_1D.cxx +++ b/src/StdMeshers/StdMeshers_Regular_1D.cxx @@ -1336,12 +1336,11 @@ StdMeshers_Regular_1D::GetUsedHypothesis(SMESH_Mesh & aMesh, _usedHypList.clear(); _mainEdge.Nullify(); - SMESH_HypoFilter auxiliaryFilter, compatibleFilter; - auxiliaryFilter.Init( SMESH_HypoFilter::IsAuxiliary() ); - InitCompatibleHypoFilter( compatibleFilter, /*ignoreAux=*/true ); + SMESH_HypoFilter auxiliaryFilter( SMESH_HypoFilter::IsAuxiliary() ); + const SMESH_HypoFilter* compatibleFilter = GetCompatibleHypoFilter(/*ignoreAux=*/true ); // get non-auxiliary assigned directly to aShape - int nbHyp = aMesh.GetHypotheses( aShape, compatibleFilter, _usedHypList, false ); + int nbHyp = aMesh.GetHypotheses( aShape, *compatibleFilter, _usedHypList, false ); if (nbHyp == 0 && aShape.ShapeType() == TopAbs_EDGE) { @@ -1352,7 +1351,7 @@ StdMeshers_Regular_1D::GetUsedHypothesis(SMESH_Mesh & aMesh, { // Propagation of 1D hypothesis from on this edge; // get non-auxiliary assigned to _mainEdge - nbHyp = aMesh.GetHypotheses( _mainEdge, compatibleFilter, _usedHypList, true ); + nbHyp = aMesh.GetHypotheses( _mainEdge, *compatibleFilter, _usedHypList, true ); } } -- 2.39.2