]> SALOME platform Git repositories - modules/smesh.git/commitdiff
Salome HOME
Speed up "Clear mesh data"
authoreap <eap@opencascade.com>
Mon, 13 Oct 2008 08:14:09 +0000 (08:14 +0000)
committereap <eap@opencascade.com>
Mon, 13 Oct 2008 08:14:09 +0000 (08:14 +0000)
17 files changed:
idl/SMESH_Mesh.idl
src/SMDS/SMDS_Mesh.cxx
src/SMDS/SMDS_Mesh.hxx
src/SMDS/SMDS_MeshElementIDFactory.cxx
src/SMDS/SMDS_MeshElementIDFactory.hxx
src/SMDS/SMDS_MeshIDFactory.cxx
src/SMDS/SMDS_MeshIDFactory.hxx
src/SMESH/SMESH_Mesh.cxx
src/SMESH/SMESH_subMesh.cxx
src/SMESHClient/SMESH_Client.cxx
src/SMESHDS/SMESHDS_CommandType.hxx
src/SMESHDS/SMESHDS_Mesh.cxx
src/SMESHDS/SMESHDS_Mesh.hxx
src/SMESHDS/SMESHDS_Script.cxx
src/SMESHDS/SMESHDS_Script.hxx
src/SMESHDS/SMESHDS_SubMesh.cxx
src/SMESHDS/SMESHDS_SubMesh.hxx

index a29123bc965e44a936fef918ef680ec882cc254f..646bbc658e414f282e052bd281dd5bd6a7f15777 100644 (file)
@@ -61,6 +61,7 @@ module SMESH
       CHANGE_ELEMENT_NODES,
       CHANGE_POLYHEDRON_NODES,
       RENUMBER,
+      CLEAR_MESH,
       ADD_QUADEDGE,
       ADD_QUADTRIANGLE,
       ADD_QUADQUADRANGLE,
index 02180dc5ab1892810a54fcaf24f01014fb2c66c9..1283fb5e365d1aae27338e20f39b3ecad20e77b5 100644 (file)
@@ -1843,6 +1843,20 @@ SMDS_Mesh::~SMDS_Mesh()
     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);
   for (; itn.More(); itn.Next())
     delete itn.Value();
@@ -1851,8 +1865,6 @@ SMDS_Mesh::~SMDS_Mesh()
   for (; ite.More(); ite.Next())
   {
     SMDS_MeshElement* elem = ite.Value();
-    if(myParent!=NULL)
-      myElementIDFactory->ReleaseID(elem->GetID());
     delete elem;
   }
 
@@ -1860,8 +1872,6 @@ SMDS_Mesh::~SMDS_Mesh()
   for (; itf.More(); itf.Next())
   {
     SMDS_MeshElement* elem = itf.Value();
-    if(myParent!=NULL)
-      myElementIDFactory->ReleaseID(elem->GetID());
     delete elem;
   }
 
@@ -1869,16 +1879,56 @@ SMDS_Mesh::~SMDS_Mesh()
   for (; itv.More(); itv.Next())
   {
     SMDS_MeshElement* elem = itv.Value();
-    if(myParent!=NULL)
-      myElementIDFactory->ReleaseID(elem->GetID());
     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();
 }
 
 ///////////////////////////////////////////////////////////////////////////////
index c4c0098c2bf8bce9c6953bb51638fe779335e479..b75ed3da7ce748412e1b5e753957ea66efc9a05c 100644 (file)
@@ -429,6 +429,8 @@ public:
    *  Implemented for fast cleaning of meshes.
    */
   virtual void RemoveFreeElement(const SMDS_MeshElement * elem);
+
+  virtual void Clear();
   
   virtual bool RemoveFromParent();
   virtual bool RemoveSubMesh(const SMDS_Mesh * aMesh);
index cac5fc1c6f7ca387218772d3f7c5f2e3b670ca2f..24c7b7c4506d410317b3112b9e74deec9560bb1b 100644 (file)
@@ -167,3 +167,10 @@ SMDS_ElemIteratorPtr SMDS_MeshElementIDFactory::elementsIterator() const
   return SMDS_ElemIteratorPtr
     (new SMDS_Fact_MyElemIterator(myIDElements));
 }
+
+void SMDS_MeshElementIDFactory::Clear()
+{
+  myIDElements.Clear();
+  myMin = myMax = 0;
+  SMDS_MeshIDFactory::Clear();
+}
index b78358f30060866f806050a92b9aa5e502528362..c783e4cabe57eaeae6176d76644efbc16379b02c 100644 (file)
@@ -49,6 +49,7 @@ public:
   int GetMaxID() const;
   int GetMinID() const;
   SMDS_ElemIteratorPtr elementsIterator() const;
+  virtual void Clear();
 private:
   void updateMinMax() const;
   void updateMinMax(int id) const
index 989e42be33d85bb5244680f546aefd49547a9d8f..1adbda4fbc37c48b86ad51893e87c48cb8b09f6e 100644 (file)
@@ -81,3 +81,9 @@ void SMDS_MeshIDFactory::ReleaseID(const int ID)
     }
   }
 }
+
+void SMDS_MeshIDFactory::Clear()
+{
+  myMaxID = 0;
+  myPoolOfID.clear();
+}
index 8e57247dad9b3876094e99cb614bc1af5d98c9b3..92783f1175bc1f85e12dfa8349d1c99a58415bdb 100644 (file)
 
 class SMDS_EXPORT SMDS_MeshIDFactory:public SMDS_MeshObject
 {
-  public:
-       virtual int GetFreeID();
-       virtual void ReleaseID(int ID);
+public:
+  virtual int  GetFreeID();
+  virtual void ReleaseID(int ID);
+  virtual void Clear();
 
   protected:
        SMDS_MeshIDFactory();
index 4c3c0a6a0b4a760a958746f4af08bc720a0d67c9..c811621c020bdf25a351e1d144c47ba989f40b92 100644 (file)
@@ -212,46 +212,59 @@ const TopoDS_Solid& SMESH_Mesh::PseudoShape()
 
 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,
                                                              /*complexShapeFirst=*/false);
-    while ( smIt->more() )
-    {
+    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 );
     }
   }
 
-  // clear entities not on sub-meshes
-
-  SMDS_VolumeIteratorPtr vIt = _myMeshDS->volumesIterator();
-  while ( vIt->more() )
-    _myMeshDS->RemoveFreeElement( vIt->next(), 0 );
-
-  SMDS_FaceIteratorPtr fIt = _myMeshDS->facesIterator();
-  while ( fIt->more() )
-    _myMeshDS->RemoveFreeElement( fIt->next(), 0 );
-
-  SMDS_EdgeIteratorPtr eIt = _myMeshDS->edgesIterator();
-  while ( eIt->more() )
-    _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);
-  }
+//   // clear sub-meshes; get ready to re-compute as a side-effect 
+
+//   if ( SMESH_subMesh *sm = GetSubMeshContaining( GetShapeToMesh() ) )
+//   {
+//     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 );
+//     }
+//   }
+
+//   // clear entities not on sub-meshes
+
+//   SMDS_VolumeIteratorPtr vIt = _myMeshDS->volumesIterator();
+//   while ( vIt->more() )
+//     _myMeshDS->RemoveFreeElement( vIt->next(), 0 );
+
+//   SMDS_FaceIteratorPtr fIt = _myMeshDS->facesIterator();
+//   while ( fIt->more() )
+//     _myMeshDS->RemoveFreeElement( fIt->next(), 0 );
+
+//   SMDS_EdgeIteratorPtr eIt = _myMeshDS->edgesIterator();
+//   while ( eIt->more() )
+//     _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);
+//   }
 }
 
 //=======================================================================
index 8842e046427da7a2035e28dc1caaf6e3c43855de..8945f5e26d4dc7960c50bfbe6c0561fd0d533562 100644 (file)
@@ -195,7 +195,7 @@ void SMESH_subMesh::SetIsAlwaysComputed(bool isAlCo)
 bool SMESH_subMesh::IsEmpty() const
 {
   if (SMESHDS_SubMesh * subMeshDS = ((SMESH_subMesh*)this)->GetSubMeshDS())
-    return (!subMeshDS->GetNodes()->more() && !subMeshDS->GetElements()->more());
+    return (!subMeshDS->NbElements() && !subMeshDS->NbNodes());
   return true;
 }
 
@@ -513,7 +513,8 @@ bool SMESH_subMesh::CanAddHypothesis(const SMESH_Hypothesis* theHypothesis) cons
   int aShapeDim = SMESH_Gen::GetShapeDim(_subShape);
   if (aHypDim == 3 && aShapeDim == 3) {
     // check case of open shell
-    if (_subShape.ShapeType() == TopAbs_SHELL && !_subShape.Closed())
+    //if (_subShape.ShapeType() == TopAbs_SHELL && !_subShape.Closed())
+    if (_subShape.ShapeType() == TopAbs_SHELL && !BRep_Tool::IsClosed(_subShape))
       return false;
   }
   if ( aHypDim <= aShapeDim )
index bb6e933181dee50b02b5fc2cddc496bd753e4b11..9b40329f2601b922dd962327a2c3176295915797 100644 (file)
@@ -729,6 +729,10 @@ SMESH_Client::Update(bool theIsClear)
         case SMESH::ADD_QUADPENTAHEDRON: AddQuadPentasWithID  ( mySMDSMesh, aSeq, anId ); break;
         case SMESH::ADD_QUADHEXAHEDRON : AddQuadHexasWithID   ( mySMDSMesh, aSeq, anId ); break;
 
+        case SMESH::CLEAR_MESH:
+          mySMDSMesh->Clear();
+          break;
+
         case SMESH::REMOVE_NODE:
           for( ; anElemId < aNbElems; anElemId++ )
             mySMDSMesh->RemoveNode( FindNode( mySMDSMesh, anIndexes[anElemId] ) );
index 9a11105b17001dfb06b1ba169ddd6026579b9b47..d4200609e41576cb4afc8ab508afaeb651ef4310 100644 (file)
@@ -46,6 +46,7 @@ enum SMESHDS_CommandType {
   SMESHDS_ChangeElementNodes,
   SMESHDS_ChangePolyhedronNodes,
   SMESHDS_Renumber,
+  SMESHDS_ClearAll,
   // special types for quadratic elements
   SMESHDS_AddQuadEdge,
   SMESHDS_AddQuadTriangle,
index 18b13fc5d4ccc2f4b1bf57e70f1c1c598e8c3371..da435996b7c69e36c490be34a8e9290cfbb3b7e4 100644 (file)
@@ -769,13 +769,11 @@ void SMESHDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elt, SMESHDS_SubMe
 
   // Rm from group
   // Node can belong to several groups
-  if (!myGroups.empty()) {
-    set<SMESHDS_GroupBase*>::iterator GrIt = myGroups.begin();
-    for (; GrIt != myGroups.end(); GrIt++) {
-      SMESHDS_Group* group = dynamic_cast<SMESHDS_Group*>(*GrIt);
-      if (!group || group->IsEmpty()) continue;
+  set<SMESHDS_GroupBase*>::iterator GrIt = myGroups.begin();
+  for (; GrIt != myGroups.end(); GrIt++) {
+    SMESHDS_Group* group = dynamic_cast<SMESHDS_Group*>(*GrIt);
+    if (group && !group->IsEmpty())
       group->SMDSGroup().Remove(elt);
-    }
   }
 
   // Rm from sub-mesh
@@ -786,6 +784,33 @@ void SMESHDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elt, SMESHDS_SubMe
   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
index 1cc122d46c248b46d8aabb8ccb1e4d81f9a07238..f600112c3c541a7e12a625edbd3674346518194c 100644 (file)
@@ -382,6 +382,8 @@ public:
   void RemoveFreeNode(const SMDS_MeshNode *, SMESHDS_SubMesh *);
   void RemoveFreeElement(const SMDS_MeshElement *, SMESHDS_SubMesh *);
 
+  void ClearMesh();
+
   bool ChangeElementNodes(const SMDS_MeshElement * elem,
                           const SMDS_MeshNode    * nodes[],
                           const int                nbnodes);
index d5eea6ecc1308341d15b5e54b143dca13b1e27db..d04795b0b0c44eef5ca4b663f288b049e81e609f 100644 (file)
@@ -317,7 +317,21 @@ void SMESHDS_Script::Renumber (const bool isNodes, const int startID, const int
     myIsModified = true;
     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);
 }
 
 //=======================================================================
index 781fc9910f054b2e02131a4161c4f80f9a36df84..8706bfa22885e1e21c8e3a4e5c3770da65636f8a 100644 (file)
@@ -93,6 +93,7 @@ class SMESHDS_EXPORT SMESHDS_Script
                                    std::vector<int> nodes_ids,
                                    std::vector<int> quantities);
        void Renumber (const bool isNodes, const int startID, const int deltaID);
+       void ClearMesh();
        void Clear();
        const std::list<SMESHDS_Command*> & GetCommands();
 
index 7cc19700d64fc320431415a1b4a7a7097be241c9..0da2a95f83e741ce6f6e57f5cf3d3ada753d6e41 100644 (file)
@@ -311,3 +311,19 @@ SMESHDS_SubMeshIteratorPtr SMESHDS_SubMesh::GetSubMeshIterator() const
     ( new SMDS_SetIterator< const SMESHDS_SubMesh*, TIterator >( mySubMeshes.begin(),
                                                                  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();
+  }
+}
index bc0ccce2a92ddce1f28bbfe2a991e6dd1d9a69dc..e42893368df246217ae2be7c22b3373a736ae6de 100644 (file)
@@ -62,6 +62,9 @@ class SMESHDS_EXPORT SMESHDS_SubMesh
   SMDS_NodeIteratorPtr GetNodes() const;
   bool Contains(const SMDS_MeshElement * ME) const;      // check if elem or node is in
 
+  // clear the contents
+  void Clear();
+
  private:
   //const SMDS_Mesh * myMesh;
   std::set<const SMDS_MeshElement*> myElements;