Speed up "Clear mesh data"

This commit is contained in:
eap 2008-10-13 08:14:40 +00:00
parent b45fb08505
commit f7e5178009
17 changed files with 196 additions and 49 deletions

View File

@ -61,6 +61,7 @@ module SMESH
CHANGE_ELEMENT_NODES, CHANGE_ELEMENT_NODES,
CHANGE_POLYHEDRON_NODES, CHANGE_POLYHEDRON_NODES,
RENUMBER, RENUMBER,
CLEAR_MESH,
ADD_QUADEDGE, ADD_QUADEDGE,
ADD_QUADTRIANGLE, ADD_QUADTRIANGLE,
ADD_QUADQUADRANGLE, ADD_QUADQUADRANGLE,

View File

@ -1843,6 +1843,20 @@ SMDS_Mesh::~SMDS_Mesh()
itc++; itc++;
} }
if(myParent==NULL)
{
delete myNodeIDFactory;
delete myElementIDFactory;
}
else
{
SMDS_ElemIteratorPtr eIt = elementsIterator();
while ( eIt->more() )
myElementIDFactory->ReleaseID(eIt->next()->GetID());
SMDS_NodeIteratorPtr itn = nodesIterator();
while (itn->more())
myNodeIDFactory->ReleaseID(itn->next()->GetID());
}
SetOfNodes::Iterator itn(myNodes); SetOfNodes::Iterator itn(myNodes);
for (; itn.More(); itn.Next()) for (; itn.More(); itn.Next())
delete itn.Value(); delete itn.Value();
@ -1851,8 +1865,6 @@ SMDS_Mesh::~SMDS_Mesh()
for (; ite.More(); ite.Next()) for (; ite.More(); ite.Next())
{ {
SMDS_MeshElement* elem = ite.Value(); SMDS_MeshElement* elem = ite.Value();
if(myParent!=NULL)
myElementIDFactory->ReleaseID(elem->GetID());
delete elem; delete elem;
} }
@ -1860,8 +1872,6 @@ SMDS_Mesh::~SMDS_Mesh()
for (; itf.More(); itf.Next()) for (; itf.More(); itf.Next())
{ {
SMDS_MeshElement* elem = itf.Value(); SMDS_MeshElement* elem = itf.Value();
if(myParent!=NULL)
myElementIDFactory->ReleaseID(elem->GetID());
delete elem; delete elem;
} }
@ -1869,16 +1879,56 @@ SMDS_Mesh::~SMDS_Mesh()
for (; itv.More(); itv.Next()) for (; itv.More(); itv.Next())
{ {
SMDS_MeshElement* elem = itv.Value(); SMDS_MeshElement* elem = itv.Value();
if(myParent!=NULL)
myElementIDFactory->ReleaseID(elem->GetID());
delete elem; delete elem;
} }
if(myParent==NULL) }
{
delete myNodeIDFactory; //================================================================================
delete myElementIDFactory; /*!
* \brief Clear all data
*/
//================================================================================
void SMDS_Mesh::Clear()
{
if (myParent!=NULL) {
SMDS_ElemIteratorPtr eIt = elementsIterator();
while ( eIt->more() )
myElementIDFactory->ReleaseID(eIt->next()->GetID());
SMDS_NodeIteratorPtr itn = nodesIterator();
while (itn->more())
myNodeIDFactory->ReleaseID(itn->next()->GetID());
} }
else {
myNodeIDFactory->Clear();
myElementIDFactory->Clear();
}
SMDS_VolumeIteratorPtr itv = volumesIterator();
while (itv->more())
delete itv->next();
myVolumes.Clear();
SMDS_FaceIteratorPtr itf = facesIterator();
while (itf->more())
delete itf->next();
myFaces.Clear();
SMDS_EdgeIteratorPtr ite = edgesIterator();
while (ite->more())
delete ite->next();
myEdges.Clear();
SMDS_NodeIteratorPtr itn = nodesIterator();
while (itn->more())
delete itn->next();
myNodes.Clear();
list<SMDS_Mesh*>::iterator itc=myChildren.begin();
while(itc!=myChildren.end())
(*itc)->Clear();
myInfo = SMDS_MeshInfo();
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -429,6 +429,8 @@ public:
* Implemented for fast cleaning of meshes. * Implemented for fast cleaning of meshes.
*/ */
virtual void RemoveFreeElement(const SMDS_MeshElement * elem); virtual void RemoveFreeElement(const SMDS_MeshElement * elem);
virtual void Clear();
virtual bool RemoveFromParent(); virtual bool RemoveFromParent();
virtual bool RemoveSubMesh(const SMDS_Mesh * aMesh); virtual bool RemoveSubMesh(const SMDS_Mesh * aMesh);

View File

@ -167,3 +167,10 @@ SMDS_ElemIteratorPtr SMDS_MeshElementIDFactory::elementsIterator() const
return SMDS_ElemIteratorPtr return SMDS_ElemIteratorPtr
(new SMDS_Fact_MyElemIterator(myIDElements)); (new SMDS_Fact_MyElemIterator(myIDElements));
} }
void SMDS_MeshElementIDFactory::Clear()
{
myIDElements.Clear();
myMin = myMax = 0;
SMDS_MeshIDFactory::Clear();
}

View File

@ -49,6 +49,7 @@ public:
int GetMaxID() const; int GetMaxID() const;
int GetMinID() const; int GetMinID() const;
SMDS_ElemIteratorPtr elementsIterator() const; SMDS_ElemIteratorPtr elementsIterator() const;
virtual void Clear();
private: private:
void updateMinMax() const; void updateMinMax() const;
void updateMinMax(int id) const void updateMinMax(int id) const

View File

@ -81,3 +81,9 @@ void SMDS_MeshIDFactory::ReleaseID(const int ID)
} }
} }
} }
void SMDS_MeshIDFactory::Clear()
{
myMaxID = 0;
myPoolOfID.clear();
}

View File

@ -35,9 +35,10 @@
class SMDS_EXPORT SMDS_MeshIDFactory:public SMDS_MeshObject class SMDS_EXPORT SMDS_MeshIDFactory:public SMDS_MeshObject
{ {
public: public:
virtual int GetFreeID(); virtual int GetFreeID();
virtual void ReleaseID(int ID); virtual void ReleaseID(int ID);
virtual void Clear();
protected: protected:
SMDS_MeshIDFactory(); SMDS_MeshIDFactory();

View File

@ -210,46 +210,59 @@ const TopoDS_Solid& SMESH_Mesh::PseudoShape()
void SMESH_Mesh::Clear() void SMESH_Mesh::Clear()
{ {
// clear sub-meshes; get ready to re-compute as a side-effect // clear mesh data
_myMeshDS->ClearMesh();
if ( SMESH_subMesh *sm = GetSubMeshContaining( GetShapeToMesh() ) ) // update compute state of submeshes
{ if ( SMESH_subMesh *sm = GetSubMeshContaining( GetShapeToMesh() ) ) {
SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true, SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true,
/*complexShapeFirst=*/false); /*complexShapeFirst=*/false);
while ( smIt->more() ) while ( smIt->more() ) {
{
sm = smIt->next(); sm = smIt->next();
TopAbs_ShapeEnum shapeType = sm->GetSubShape().ShapeType();
if ( shapeType == TopAbs_VERTEX || shapeType < TopAbs_SOLID )
// all other shapes depends on vertices so they are already cleaned
sm->ComputeStateEngine( SMESH_subMesh::CLEAN );
// to recompute even if failed
sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE ); sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
} }
} }
// clear entities not on sub-meshes // // clear sub-meshes; get ready to re-compute as a side-effect
SMDS_VolumeIteratorPtr vIt = _myMeshDS->volumesIterator(); // if ( SMESH_subMesh *sm = GetSubMeshContaining( GetShapeToMesh() ) )
while ( vIt->more() ) // {
_myMeshDS->RemoveFreeElement( vIt->next(), 0 ); // SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true,
// /*complexShapeFirst=*/false);
// while ( smIt->more() )
// {
// sm = smIt->next();
// TopAbs_ShapeEnum shapeType = sm->GetSubShape().ShapeType();
// if ( shapeType == TopAbs_VERTEX || shapeType < TopAbs_SOLID )
// // all other shapes depends on vertices so they are already cleaned
// sm->ComputeStateEngine( SMESH_subMesh::CLEAN );
// // to recompute even if failed
// sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
// }
// }
SMDS_FaceIteratorPtr fIt = _myMeshDS->facesIterator(); // // clear entities not on sub-meshes
while ( fIt->more() )
_myMeshDS->RemoveFreeElement( fIt->next(), 0 );
SMDS_EdgeIteratorPtr eIt = _myMeshDS->edgesIterator(); // SMDS_VolumeIteratorPtr vIt = _myMeshDS->volumesIterator();
while ( eIt->more() ) // while ( vIt->more() )
_myMeshDS->RemoveFreeElement( eIt->next(), 0 ); // _myMeshDS->RemoveFreeElement( vIt->next(), 0 );
SMDS_NodeIteratorPtr nIt = _myMeshDS->nodesIterator(); // SMDS_FaceIteratorPtr fIt = _myMeshDS->facesIterator();
while ( nIt->more() ) { // while ( fIt->more() )
const SMDS_MeshNode * node = nIt->next(); // _myMeshDS->RemoveFreeElement( fIt->next(), 0 );
if ( node->NbInverseElements() == 0 )
_myMeshDS->RemoveFreeNode( node, 0 ); // SMDS_EdgeIteratorPtr eIt = _myMeshDS->edgesIterator();
else // while ( eIt->more() )
_myMeshDS->RemoveNode(node); // _myMeshDS->RemoveFreeElement( eIt->next(), 0 );
}
// SMDS_NodeIteratorPtr nIt = _myMeshDS->nodesIterator();
// while ( nIt->more() ) {
// const SMDS_MeshNode * node = nIt->next();
// if ( node->NbInverseElements() == 0 )
// _myMeshDS->RemoveFreeNode( node, 0 );
// else
// _myMeshDS->RemoveNode(node);
// }
} }
//======================================================================= //=======================================================================

View File

@ -195,7 +195,7 @@ void SMESH_subMesh::SetIsAlwaysComputed(bool isAlCo)
bool SMESH_subMesh::IsEmpty() const bool SMESH_subMesh::IsEmpty() const
{ {
if (SMESHDS_SubMesh * subMeshDS = ((SMESH_subMesh*)this)->GetSubMeshDS()) if (SMESHDS_SubMesh * subMeshDS = ((SMESH_subMesh*)this)->GetSubMeshDS())
return (!subMeshDS->GetNodes()->more() && !subMeshDS->GetElements()->more()); return (!subMeshDS->NbElements() && !subMeshDS->NbNodes());
return true; return true;
} }

View File

@ -727,6 +727,10 @@ SMESH_Client::Update(bool theIsClear)
case SMESH::ADD_QUADPENTAHEDRON: AddQuadPentasWithID ( mySMDSMesh, aSeq, anId ); break; case SMESH::ADD_QUADPENTAHEDRON: AddQuadPentasWithID ( mySMDSMesh, aSeq, anId ); break;
case SMESH::ADD_QUADHEXAHEDRON : AddQuadHexasWithID ( mySMDSMesh, aSeq, anId ); break; case SMESH::ADD_QUADHEXAHEDRON : AddQuadHexasWithID ( mySMDSMesh, aSeq, anId ); break;
case SMESH::CLEAR_MESH:
mySMDSMesh->Clear();
break;
case SMESH::REMOVE_NODE: case SMESH::REMOVE_NODE:
for( ; anElemId < aNbElems; anElemId++ ) for( ; anElemId < aNbElems; anElemId++ )
mySMDSMesh->RemoveNode( FindNode( mySMDSMesh, anIndexes[anElemId] ) ); mySMDSMesh->RemoveNode( FindNode( mySMDSMesh, anIndexes[anElemId] ) );

View File

@ -46,6 +46,7 @@ enum SMESHDS_CommandType {
SMESHDS_ChangeElementNodes, SMESHDS_ChangeElementNodes,
SMESHDS_ChangePolyhedronNodes, SMESHDS_ChangePolyhedronNodes,
SMESHDS_Renumber, SMESHDS_Renumber,
SMESHDS_ClearAll,
// special types for quadratic elements // special types for quadratic elements
SMESHDS_AddQuadEdge, SMESHDS_AddQuadEdge,
SMESHDS_AddQuadTriangle, SMESHDS_AddQuadTriangle,

View File

@ -769,13 +769,11 @@ void SMESHDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elt, SMESHDS_SubMe
// Rm from group // Rm from group
// Node can belong to several groups // Node can belong to several groups
if (!myGroups.empty()) { set<SMESHDS_GroupBase*>::iterator GrIt = myGroups.begin();
set<SMESHDS_GroupBase*>::iterator GrIt = myGroups.begin(); for (; GrIt != myGroups.end(); GrIt++) {
for (; GrIt != myGroups.end(); GrIt++) { SMESHDS_Group* group = dynamic_cast<SMESHDS_Group*>(*GrIt);
SMESHDS_Group* group = dynamic_cast<SMESHDS_Group*>(*GrIt); if (group && !group->IsEmpty())
if (!group || group->IsEmpty()) continue;
group->SMDSGroup().Remove(elt); group->SMDSGroup().Remove(elt);
}
} }
// Rm from sub-mesh // Rm from sub-mesh
@ -786,6 +784,33 @@ void SMESHDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elt, SMESHDS_SubMe
SMDS_Mesh::RemoveFreeElement(elt); SMDS_Mesh::RemoveFreeElement(elt);
} }
//================================================================================
/*!
* \brief Remove all data from the mesh
*/
//================================================================================
void SMESHDS_Mesh::ClearMesh()
{
myScript->ClearMesh();
SMDS_Mesh::Clear();
// clear submeshes
map<int,SMESHDS_SubMesh*>::iterator sub, subEnd = myShapeIndexToSubMesh.end();
for ( sub = myShapeIndexToSubMesh.begin(); sub != subEnd; ++sub )
sub->second->Clear();
// clear groups
TGroups::iterator group, groupEnd = myGroups.end();
for ( group = myGroups.begin(); group != groupEnd; ++group ) {
if ( SMESHDS_Group* g = dynamic_cast<SMESHDS_Group*>(*group)) {
SMDSAbs_ElementType groupType = g->GetType();
g->Clear();
g->SetType( groupType );
}
}
}
//================================================================================ //================================================================================
/*! /*!
* \brief return submesh by shape * \brief return submesh by shape

View File

@ -382,6 +382,8 @@ public:
void RemoveFreeNode(const SMDS_MeshNode *, SMESHDS_SubMesh *); void RemoveFreeNode(const SMDS_MeshNode *, SMESHDS_SubMesh *);
void RemoveFreeElement(const SMDS_MeshElement *, SMESHDS_SubMesh *); void RemoveFreeElement(const SMDS_MeshElement *, SMESHDS_SubMesh *);
void ClearMesh();
bool ChangeElementNodes(const SMDS_MeshElement * elem, bool ChangeElementNodes(const SMDS_MeshElement * elem,
const SMDS_MeshNode * nodes[], const SMDS_MeshNode * nodes[],
const int nbnodes); const int nbnodes);

View File

@ -317,7 +317,21 @@ void SMESHDS_Script::Renumber (const bool isNodes, const int startID, const int
myIsModified = true; myIsModified = true;
return; return;
} }
getCommand(SMESHDS_Renumber)->Renumber( isNodes, startID, deltaID ); getCommand(SMESHDS_Renumber);
}
//=======================================================================
//function : ClearMesh
//purpose :
//=======================================================================
void SMESHDS_Script::ClearMesh ()
{
if(myIsEmbeddedMode){
myIsModified = true;
return;
}
Clear();// previous commands become useless to reproduce on client side
getCommand(SMESHDS_ClearAll);
} }
//======================================================================= //=======================================================================

View File

@ -93,6 +93,7 @@ class SMESHDS_EXPORT SMESHDS_Script
std::vector<int> nodes_ids, std::vector<int> nodes_ids,
std::vector<int> quantities); std::vector<int> quantities);
void Renumber (const bool isNodes, const int startID, const int deltaID); void Renumber (const bool isNodes, const int startID, const int deltaID);
void ClearMesh();
void Clear(); void Clear();
const std::list<SMESHDS_Command*> & GetCommands(); const std::list<SMESHDS_Command*> & GetCommands();

View File

@ -311,3 +311,19 @@ SMESHDS_SubMeshIteratorPtr SMESHDS_SubMesh::GetSubMeshIterator() const
( new SMDS_SetIterator< const SMESHDS_SubMesh*, TIterator >( mySubMeshes.begin(), ( new SMDS_SetIterator< const SMESHDS_SubMesh*, TIterator >( mySubMeshes.begin(),
mySubMeshes.end())); mySubMeshes.end()));
} }
//=======================================================================
//function : Clear
//purpose : remove the contents
//=======================================================================
void SMESHDS_SubMesh::Clear()
{
myElements.clear();
myNodes.clear();
SMESHDS_SubMeshIteratorPtr sub = GetSubMeshIterator();
while ( sub->more() ) {
if ( SMESHDS_SubMesh* sm = (SMESHDS_SubMesh*) sub->next())
sm->Clear();
}
}

View File

@ -62,6 +62,9 @@ class SMESHDS_EXPORT SMESHDS_SubMesh
SMDS_NodeIteratorPtr GetNodes() const; SMDS_NodeIteratorPtr GetNodes() const;
bool Contains(const SMDS_MeshElement * ME) const; // check if elem or node is in bool Contains(const SMDS_MeshElement * ME) const; // check if elem or node is in
// clear the contents
void Clear();
private: private:
//const SMDS_Mesh * myMesh; //const SMDS_Mesh * myMesh;
std::set<const SMDS_MeshElement*> myElements; std::set<const SMDS_MeshElement*> myElements;