//=============================================================================
DriverMED_FamilyPtrList
DriverMED_Family
-::MakeFamilies(const SMESHDS_SubMeshPtrMap& theSubMeshes,
+::MakeFamilies(SMESHDS_SubMeshIteratorPtr theSubMeshes,
const SMESHDS_GroupBasePtrList& theGroups,
const bool doGroupOfNodes,
const bool doGroupOfEdges,
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);
*/
static
DriverMED_FamilyPtrList
- MakeFamilies (const SMESHDS_SubMeshPtrMap& theSubMeshes,
+ MakeFamilies (SMESHDS_SubMeshIteratorPtr theSubMeshes,
const SMESHDS_GroupBasePtrList& theGroups,
const bool doGroupOfNodes,
const bool doGroupOfEdges,
void DriverMED_W_SMESHDS_Mesh::AddSubMesh(SMESHDS_SubMesh* theSubMesh, int theID)
{
- mySubMeshes[theID] = theSubMesh;
+ mySubMeshes.push_back( theSubMesh );
}
void DriverMED_W_SMESHDS_Mesh::AddGroupOfNodes()
// return elem_famNum->second;
return aDefaultFamilyId;
}
+
+ //================================================================================
+ /*!
+ * \brief Returns iterator on sub-meshes
+ */
+ //================================================================================
+
+ SMESHDS_SubMeshIteratorPtr getIterator( std::vector<SMESHDS_SubMesh*>& 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()
myDoGroupOfBalls && nbBalls);
} else {
aFamilies = DriverMED_Family::MakeFamilies
- (mySubMeshes, myGroups,
+ (getIterator( mySubMeshes ), myGroups,
myDoGroupOfNodes && nbNodes,
myDoGroupOfEdges && nbEdges,
myDoGroupOfFaces && nbFaces,
MED::EVersion myMedVersion;
std::list<SMESHDS_GroupBase*> myGroups;
bool myAllSubMeshes;
- std::map<int,SMESHDS_SubMesh*> mySubMeshes;
+ std::vector<SMESHDS_SubMesh*> mySubMeshes;
bool myDoGroupOfNodes;
bool myDoGroupOfEdges;
bool myDoGroupOfFaces;
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;
SMESH_Algo::~SMESH_Algo()
{
+ delete _compatibleNoAuxHypFilter;
+ // delete _compatibleAllHypFilter; -- _compatibleNoAuxHypFilter does it!!!
}
//=============================================================================
{
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
}
{
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;
}
//================================================================================
/*!
- * \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;
}
//================================================================================
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
*/
protected:
+ const SMESH_HypoFilter * _compatibleAllHypFilter;
+ const SMESH_HypoFilter * _compatibleNoAuxHypFilter;
std::vector<std::string> _compatibleHypothesis;
std::list<const SMESHDS_Hypothesis *> _appliedHypList;
std::list<const SMESHDS_Hypothesis *> _usedHypList;
+
// Algo features influencing which Compute() and how is called:
// in what turn and with what input shape.
// 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 ))
// --------------------------------
// 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();
// ------------------------------------------------------------
// 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;
// ----------------------------------------------------------
// 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() );
//=======================================================================
SMESH_HypoFilter::SMESH_HypoFilter()
+ : myNbPredicates(0)
{
}
//=======================================================================
SMESH_HypoFilter::SMESH_HypoFilter( SMESH_HypoPredicate* aPredicate, bool notNegate )
+ : myNbPredicates(0)
{
add( notNegate ? AND : AND_NOT, aPredicate );
}
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<SMESH_HypoPredicate*>::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;
SMESH_HypoFilter & SMESH_HypoFilter::Init ( SMESH_HypoPredicate* aPredicate, bool notNegate )
{
- list<SMESH_HypoPredicate*>::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;
SMESH_HypoFilter::~SMESH_HypoFilter()
{
- Init(0);
+ SMESH_HypoPredicate** pred = &myPredicates[0];
+ SMESH_HypoPredicate** end = &myPredicates[myNbPredicates];
+ for ( ; pred != end; ++pred )
+ delete *pred;
+ myNbPredicates = 0;
}
// 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 );
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
/*!
* \brief return true if contains no predicates
*/
- bool IsAny() const { return myPredicates.empty(); }
+ bool IsAny() const { return myNbPredicates > 0; }
~SMESH_HypoFilter();
protected:
// fields
- std::list<SMESH_HypoPredicate*> myPredicates;
+ //std::list<SMESH_HypoPredicate*> myPredicates;
+ SMESH_HypoPredicate* myPredicates[100];
+ int myNbPredicates;
// private methods
{
if ( pred ) {
pred->_logical_op = bool_op;
- myPredicates.push_back( pred );
+ myPredicates[ myNbPredicates++ ] = pred;
}
}
//
#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"
typedef SMESH_HypoFilter THypType;
+class SMESH_Mesh::SubMeshHolder : public SMESHDS_TSubMeshHolder< SMESH_subMesh >
+{
+};
+
//=============================================================================
/*!
*
_shapeDiagonal = 0.0;
_callUp = NULL;
_myMeshDS->ShapeToMesh( PseudoShape() );
+ _subMeshHolder = new SubMeshHolder;
}
//================================================================================
_shapeDiagonal( 0.0 ),
_callUp( 0 )
{
+ _subMeshHolder = new SubMeshHolder;
}
namespace
_mapGroup.clear();
// delete sub-meshes
- map <int, SMESH_subMesh*>::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;
{
// removal of a shape to mesh, delete objects referring to sub-shapes:
// - sub-meshes
- map <int, SMESH_subMesh *>::iterator i_sm = _mapSubMesh.begin();
- for ( ; i_sm != _mapSubMesh.end(); ++i_sm )
- delete i_sm->second;
- _mapSubMesh.clear();
+ _subMeshHolder->DeleteAll();
// - groups on geometry
map <int, SMESH_Group *>::iterator i_gr = _mapGroup.begin();
while ( i_gr != _mapGroup.end() ) {
SMESH_Mesh::GetHypothesisList(const TopoDS_Shape & aSubShape) const
throw(SALOME_Exception)
{
- Unexpect aCatch(SalomeException);
return _myMeshDS->GetHypothesis(aSubShape);
}
if ( andAncestors )
{
// user sorted submeshes of ancestors, according to stored submesh priority
- const list<SMESH_subMesh*> smList = getAncestorsSubMeshes( aSubShape );
- list<SMESH_subMesh*>::const_iterator smIt = smList.begin();
- for ( ; smIt != smList.end(); smIt++ )
+ getAncestorsSubMeshes( aSubShape, _ancestorSubMeshes );
+ vector<SMESH_subMesh*>::const_iterator smIt = _ancestorSubMeshes.begin();
+ for ( ; smIt != _ancestorSubMeshes.end(); smIt++ )
{
const TopoDS_Shape& curSh = (*smIt)->GetSubShape();
const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(curSh);
TopTools_MapOfShape map;
// user sorted submeshes of ancestors, according to stored submesh priority
- const list<SMESH_subMesh*> smList = getAncestorsSubMeshes( aSubShape );
- list<SMESH_subMesh*>::const_iterator smIt = smList.begin();
- for ( ; smIt != smList.end(); smIt++ )
+ getAncestorsSubMeshes( aSubShape, _ancestorSubMeshes );
+ vector<SMESH_subMesh*>::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<const SMESHDS_Hypothesis*>& 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++;
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
// if ( !index )
// return NULL; // neither sub-shape nor a group
- map <int, SMESH_subMesh *>::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;
}
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 <int, SMESH_subMesh *>::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
SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const int aShapeID) const
throw(SALOME_Exception)
{
- Unexpect aCatch(SalomeException);
-
- map <int, SMESH_subMesh *>::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
SMESH_Mesh::GetGroupSubMeshesContaining(const TopoDS_Shape & aSubShape) const
throw(SALOME_Exception)
{
- Unexpect aCatch(SalomeException);
list<SMESH_subMesh*> found;
SMESH_subMesh * subMesh = GetSubMeshContaining(aSubShape);
return found;
// submeshes of groups have max IDs, so search from the map end
- map<int, SMESH_subMesh *>::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 {
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() );
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 <const SMESHDS_Hypothesis * > 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;
}
//=============================================================================
*/
//=============================================================================
-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
if (_callUp)
_callUp->HypothesisModified();
- const SMESH_Algo *foundAlgo = 0;
- SMESH_HypoFilter algoKind, compatibleHypoKind;
+ SMESH_Algo *algo;
+ const SMESH_HypoFilter* compatibleHypoKind;
list <const SMESHDS_Hypothesis * > 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<const SMESH_Algo*>
- ( 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 ));
}
}
}
// 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 <int, SMESH_subMesh*>::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<SMESH_Mesh*>(this)->_isModified = false;
void SMESH_Mesh::fillAncestorsMap(const TopoDS_Shape& theShape)
{
-
int desType, ancType;
if ( !theShape.IsSame( GetShapeToMesh()) && theShape.ShapeType() == TopAbs_COMPOUND )
{
*/
//=============================================================================
-bool SMESH_Mesh::SortByMeshOrder(list<SMESH_subMesh*>& theListToSort) const
+ bool SMESH_Mesh::SortByMeshOrder(std::vector<SMESH_subMesh*>& theListToSort) const
{
if ( !_mySubMeshOrder.size() || theListToSort.size() < 2)
return true;
bool res = false;
- list<SMESH_subMesh*> onlyOrderedList;
+ vector<SMESH_subMesh*> onlyOrderedList;
// collect all ordered submeshes in one list as pointers
// and get their positions within theListToSort
- typedef list<SMESH_subMesh*>::iterator TPosInList;
+ typedef vector<SMESH_subMesh*>::iterator TPosInList;
map< int, TPosInList > sortedPos;
TPosInList smBeg = theListToSort.begin(), smEnd = theListToSort.end();
TListOfListOfInt::const_iterator listIdsIt = _mySubMeshOrder.begin();
return res;
res = true;
- list<SMESH_subMesh*>::iterator onlyBIt = onlyOrderedList.begin();
- list<SMESH_subMesh*>::iterator onlyEIt = onlyOrderedList.end();
+ vector<SMESH_subMesh*>::iterator onlyBIt = onlyOrderedList.begin();
+ vector<SMESH_subMesh*>::iterator onlyEIt = onlyOrderedList.end();
// iterate on ordered submeshes and insert them in detected positions
map< int, TPosInList >::iterator i_pos = sortedPos.begin();
*/
//=============================================================================
-list<SMESH_subMesh*>
-SMESH_Mesh::getAncestorsSubMeshes (const TopoDS_Shape& theSubShape) const
+void SMESH_Mesh::getAncestorsSubMeshes (const TopoDS_Shape& theSubShape,
+ std::vector< SMESH_subMesh* >& theSubMeshes) const
{
- list<SMESH_subMesh*> 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 );
}
*/
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
*/
const TListOfListOfInt& GetMeshOrder() const;
// sort submeshes according to stored mesh order
- bool SortByMeshOrder(std::list<SMESH_subMesh*>& theListToSort) const;
+ bool SortByMeshOrder(std::vector<SMESH_subMesh*>& theListToSort) const;
// return true if given order of sub-meshes is OK
bool IsOrderOK( const SMESH_subMesh* smBefore,
private:
void fillAncestorsMap(const TopoDS_Shape& theShape);
- std::list<SMESH_subMesh*> 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)
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 <SMESH_subMesh*> _subMeshesUsingHypothesisList;
+ //std::list <SMESH_subMesh*> _subMeshesUsingHypothesisList;
SMESHDS_Document * _myDocument;
SMESHDS_Mesh * _myMeshDS;
SMESH_Gen * _gen;
- std::map <int, SMESH_subMesh*> _mapSubMesh;
- std::map <int, SMESH_Group*> _mapGroup;
+ std::map <int, SMESH_Group*> _mapGroup;
+
+ class SubMeshHolder;
+ SubMeshHolder* _subMeshHolder;
bool _isAutoColor;
bool _isModified; //!< modified since last total re-compute, issue 0020693
TopTools_IndexedDataMapOfShapeListOfShape _mapAncestors;
+ mutable std::vector<SMESH_subMesh*> _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;
}
else
{
- const map<int,SMESHDS_SubMesh*>& id2sm = GetMeshDS()->SubMeshes();
- map<int,SMESHDS_SubMesh*>::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;
}
//
#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 <Standard_ErrorHandler.hxx>
#include <Standard_OutOfRange.hxx>
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);
}
// - hypotheses
myShapeToHypothesis.Clear();
// - shape indices in SMDS_Position of nodes
- map<int,SMESHDS_SubMesh*>::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<SMESHDS_GroupBase*>::iterator gr = myGroups.begin();
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<const SMESHDS_Hypothesis *> aList;
- myShapeToHypothesis.Bind(SS.Oriented(TopAbs_FORWARD), aList);
+ myShapeToHypothesis.Bind(SS/*.Oriented(TopAbs_FORWARD)*/, aList);
}
list<const SMESHDS_Hypothesis *>& 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<const SMESHDS_Hypothesis*>::iterator ith = find(alist.begin(),alist.end(), H );
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<const SMESHDS_Hypothesis *>& alist=myShapeToHypothesis.ChangeFind( S.Oriented(TopAbs_FORWARD) );
+ list<const SMESHDS_Hypothesis *>& alist=myShapeToHypothesis.ChangeFind( S/*.Oriented(TopAbs_FORWARD)*/ );
list<const SMESHDS_Hypothesis*>::iterator ith=find(alist.begin(),alist.end(), H );
if (ith != alist.end())
{
//purpose :
//=======================================================================
-static void removeFromContainers (map<int,SMESHDS_SubMesh*>& theSubMeshes,
+static void removeFromContainers (SMESHDS_Mesh* theMesh,
set<SMESHDS_GroupBase*>& theGroups,
list<const SMDS_MeshElement*>& theElems,
const bool isNode)
// 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<const SMDS_MeshElement *>::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<const SMDS_MeshNode*> (*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 );
}
}
//=======================================================================
//function : RemoveNode
-//purpose :
+//purpose :
//=======================================================================
void SMESHDS_Mesh::RemoveNode(const SMDS_MeshNode * n)
{
if ( n->NbInverseElements() == 0 && !(hasConstructionEdges() || hasConstructionFaces()))
{
- SMESHDS_SubMesh* subMesh=0;
- map<int,SMESHDS_SubMesh*>::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<const SMDS_MeshElement *> removedElems;
list<const SMDS_MeshElement *> 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 );
}
//=======================================================================
{
SMESHDS_SubMesh* subMesh=0;
if ( elt->getshapeId() > 0 )
- {
- map<int,SMESHDS_SubMesh*>::iterator SubIt = myShapeIndexToSubMesh.find( elt->getshapeId() );
- if ( SubIt != myShapeIndexToSubMesh.end() )
- subMesh = SubIt->second;
- }
+ subMesh = MeshElements( elt->getshapeId() );
+
RemoveFreeElement( elt, subMesh, true);
return;
}
SMDS_Mesh::RemoveElement(elt, removedElems, removedNodes, false);
- removeFromContainers( myShapeIndexToSubMesh, myGroups, removedElems, false );
+ removeFromContainers( this, myGroups, removedElems, false );
}
//=======================================================================
SMDS_Mesh::Clear();
// clear submeshes
- map<int,SMESHDS_SubMesh*>::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();
* \brief return submesh by shape
* \param shape - the sub-shape
* \retval SMESHDS_SubMesh* - the found submesh
- *
- * search of submeshes is optimized
*/
//================================================================================
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<int,SMESHDS_SubMesh*>::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 ));
}
//================================================================================
void SMESHDS_Mesh::UnSetNodeOnShape(const SMDS_MeshNode* aNode)
{
int shapeId = aNode->getshapeId();
- if (shapeId >= 0)
- {
- map<int, SMESHDS_SubMesh*>::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);
}
//=======================================================================
void SMESHDS_Mesh::UnSetMeshElementOnShape(const SMDS_MeshElement * elem,
const TopoDS_Shape & S)
{
- int Index = myIndexToShape.FindIndex(S);
-
- map<int,SMESHDS_SubMesh*>::iterator it = myShapeIndexToSubMesh.find( Index );
- if ( it != myShapeIndexToSubMesh.end() )
- {
- if (elem->GetType() == SMDSAbs_Node)
- it->second->RemoveNode(static_cast<const SMDS_MeshNode*> (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<const SMDS_MeshNode*> (elem), /*deleted=*/false);
+ else
+ sm->RemoveElement(elem, /*deleted=*/false);
+ }
}
//=======================================================================
//=======================================================================
TopoDS_Shape SMESHDS_Mesh::ShapeToMesh() const
{
- return myShape;
+ return myShape;
}
//=======================================================================
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 );
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
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 ));
}
//=======================================================================
list<int> SMESHDS_Mesh::SubMeshIndices() const
{
list<int> anIndices;
- std::map<int,SMESHDS_SubMesh*>::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 :
const list<const SMESHDS_Hypothesis*>&
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<const SMESHDS_Hypothesis*> empty;
return empty;
//=======================================================================
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 );
}
//=======================================================================
//=======================================================================
bool SMESHDS_Mesh::HasHypothesis(const TopoDS_Shape & S)
{
- return myShapeToHypothesis.IsBound(S.Oriented(TopAbs_FORWARD));
+ return myShapeToHypothesis.IsBound(S/*.Oriented(TopAbs_FORWARD)*/);
}
//=======================================================================
//=======================================================================
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;
}
int SMESHDS_Mesh::MaxSubMeshIndex() const
{
- return myShapeIndexToSubMesh.empty() ? 0 : myShapeIndexToSubMesh.rbegin()->first;
+ return mySubMeshHolder->GetMaxID();
}
//=======================================================================
//=======================================================================
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());
}
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)));
}
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)));
}
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()));
}
void SMESHDS_Mesh::SetMeshElementOnShape(const SMDS_MeshElement* anElement,
int Index)
{
- add( anElement, getSubmesh( Index ));
+ add( anElement, NewSubMesh( Index ));
}
//=======================================================================
// myScript
delete myScript;
// submeshes
- TShapeIndexToSubMesh::iterator i_sm = myShapeIndexToSubMesh.begin();
- for ( ; i_sm != myShapeIndexToSubMesh.end(); ++i_sm )
- delete i_sm->second;
+ delete mySubMeshHolder;
}
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);
// --- compact list myNodes and myElements in submeshes
- map<int,SMESHDS_SubMesh*>::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()
#include <TopTools_IndexedMapOfShape.hxx>
#include <TopoDS_Shape.hxx>
+#include <map>
+
class TopoDS_Solid ;
class TopoDS_Shell ;
class TopoDS_Face ;
class SMDS_Mesh0DElement;
class SMDS_BallElement;
-#include <map>
-
/*
* Using of native hash_map isn't portable and don't work on WIN32 platform.
* So this functionality implement on new NCollection_DataMap technology
SMESHDS_SubMesh * MeshElements(const TopoDS_Shape & S) const;
SMESHDS_SubMesh * MeshElements(const int Index) const;
std::list<int> SubMeshIndices() const;
- const std::map<int,SMESHDS_SubMesh*>& SubMeshes() const
- { return myShapeIndexToSubMesh; }
- const TopoDS_Shape& GetCurrentSubShape() const { return myCurSubShape; }
+ SMESHDS_SubMeshIteratorPtr SubMeshes() const;
bool HasHypothesis(const TopoDS_Shape & S);
const std::list<const SMESHDS_Hypothesis*>& GetHypothesis(const TopoDS_Shape & S) const;
~SMESHDS_Mesh();
private:
- void addNodeToSubmesh( const SMDS_MeshNode* aNode, int Index )
- {
- //Update or build submesh
- std::map<int,SMESHDS_SubMesh*>::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<int,SMESHDS_SubMesh*> TShapeIndexToSubMesh;
- TShapeIndexToSubMesh myShapeIndexToSubMesh;
+ class SubMeshHolder;
+ SubMeshHolder* mySubMeshHolder;
TopTools_IndexedMapOfShape myIndexToShape;
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;
};
--- /dev/null
+// 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 <vector>
+#include <map>
+
+//=======================================================================
+/*!
+ * \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 SUBMESH>
+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<SUBMESH>* myHolder;
+ SUBMESH* myNext;
+ int myCurID, myEndID, myIDDelta;
+
+ void init( const SMESHDS_TSubMeshHolder<SUBMESH>* 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
myLocMesh.ShapeToMesh( nullShape ); // remove shape referring data
}
- if ( !mySMESHDSMesh->SubMeshes().empty() )
+ SMESHDS_SubMeshIteratorPtr smIt = mySMESHDSMesh->SubMeshes();
+ if ( smIt->more() )
{
// Store submeshes
// ----------------
// 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<int,SMESHDS_SubMesh*>& aSubMeshes = mySMESHDSMesh->SubMeshes();
- map<int,SMESHDS_SubMesh*>::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();
int nbEdgeNodes = 0, nbFaceNodes = 0;
list<SMESHDS_SubMesh*> 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();
mesh->GetHypotheses( shape, hypoFilter, hyps, true, &assignedTo );
if ( nbAlgos > 1 ) // concurrent algos
{
- list<SMESH_subMesh*> smList; // where an algo is assigned
+ vector<SMESH_subMesh*> smList; // where an algo is assigned
list< TopoDS_Shape >::iterator shapeIt = assignedTo.begin();
for ( ; shapeIt != assignedTo.end(); ++shapeIt )
smList.push_back( mesh->GetSubMesh( *shapeIt ));
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
_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)
{
{
// Propagation of 1D hypothesis from <aMainEdge> on this edge;
// get non-auxiliary assigned to _mainEdge
- nbHyp = aMesh.GetHypotheses( _mainEdge, compatibleFilter, _usedHypList, true );
+ nbHyp = aMesh.GetHypotheses( _mainEdge, *compatibleFilter, _usedHypList, true );
}
}