Salome HOME
0023544: SMESH's performance issues
[modules/smesh.git] / src / SMDS / SMDS_ElementHolder.hxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  File   : SMDS_ElementHolder.hxx
23 //  Module : SMESH
24 //
25 #ifndef _SMDS_ElementHolder_HeaderFile
26 #define _SMDS_ElementHolder_HeaderFile
27
28 #include "SMESH_SMDS.hxx"
29
30 #include "SMDS_ElemIterator.hxx"
31
32 #include <vector>
33 #include <set>
34
35 class SMDS_Mesh;
36 class SMDS_MeshElement;
37
38 //------------------------------------------------------------------------------------
39 /*!
40  * \brief Base class of object holding SMDS_MeshElement pointers.
41  *        Registering such an object in SMDS_Mesh assures that the
42  *        pointers remain valid after compacting the mesh
43  */
44 class SMDS_EXPORT SMDS_ElementHolder
45 {
46  public:
47
48   //! register self in the mesh
49   SMDS_ElementHolder( const SMDS_Mesh* mesh );
50
51   //! un-register self from the mesh
52   virtual ~SMDS_ElementHolder();
53
54
55  protected:
56
57   //!< the descendant object return its elements just before the mesh compacting
58   virtual SMDS_ElemIteratorPtr getElements() = 0;
59
60   //!< the descendant object temporary remove its elements
61   virtual void tmpClear() = 0;
62
63   //!< the descendant object re-add its elements after the mesh compacting
64   virtual void add( const SMDS_MeshElement* element ) = 0;
65
66   //!< the descendant squeeze its element storage after re-adding elements
67   virtual void compact() = 0;
68
69   //!< allow the descendant treat its elements before mesh clearing
70   virtual void clear() {}
71
72   SMDS_Mesh* myMesh;
73
74
75  private: // methods called by SMDS_Mesh
76
77   friend class SMDS_Mesh;
78
79   //! store vtkIDs of elements
80   void beforeCompacting();
81
82   //! restore pointers to elements
83   void restoreElements( const std::vector<int>& idNodessOldToNew,
84                         const std::vector<int>& idCellsOldToNew );
85
86
87   std::vector<const SMDS_MeshElement*>      myExternalElems; //!< elements not contained in the mesh
88   std::vector< int >                        myVtkIDs;        //!< vtk IDs of elements
89   std::vector< bool >                       myIsNode;
90   std::set< SMDS_ElementHolder* >::iterator myPtrInMesh;
91 };
92
93 #endif