]> SALOME platform Git repositories - modules/smesh.git/blob - src/SMDS/SMDS_Mesh.hxx
Salome HOME
untabify
[modules/smesh.git] / src / SMDS / SMDS_Mesh.hxx
1 // Copyright (C) 2007-2011  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.
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
23 //  SMESH SMDS : implementaion of Salome mesh data structure
24 //  File   : SMDS_Mesh.hxx
25 //  Module : SMESH
26 //
27 #ifndef _SMDS_Mesh_HeaderFile
28 #define _SMDS_Mesh_HeaderFile
29
30 #include "SMESH_SMDS.hxx"
31
32 #include "SMDS_MeshNode.hxx"
33 #include "SMDS_MeshCell.hxx"
34 #include "SMDS_Mesh0DElement.hxx"
35 #include "SMDS_MeshEdge.hxx"
36 #include "SMDS_MeshFace.hxx"
37 #include "SMDS_MeshVolume.hxx"
38 #include "SMDS_MeshNodeIDFactory.hxx"
39 #include "SMDS_MeshElementIDFactory.hxx"
40 #include "SMDS_MeshInfo.hxx"
41 #include "SMDS_ElemIterator.hxx"
42 #include "SMDS_VolumeOfNodes.hxx"
43 #include "SMDS_VtkEdge.hxx"
44 #include "SMDS_VtkFace.hxx"
45 #include "SMDS_VtkVolume.hxx"
46 #include "ObjectPool.hxx"
47 #include "SMDS_UnstructuredGrid.hxx"
48
49 #include <boost/shared_ptr.hpp>
50 #include <set>
51 #include <list>
52 #include <vector>
53 #include <vtkSystemIncludes.h>
54 #include <cassert>
55
56 #include "Utils_SALOME_Exception.hxx"
57 #define MYASSERT(val) if (!(val)) throw SALOME_Exception(LOCALIZED("assertion not verified"));
58
59 class SMDS_EXPORT SMDS_Mesh:public SMDS_MeshObject{
60 public:
61   friend class SMDS_MeshIDFactory;
62   friend class SMDS_MeshNodeIDFactory;
63   friend class SMDS_MeshElementIDFactory;
64   friend class SMDS_MeshVolumeVtkNodes;
65   friend class SMDS_MeshNode;
66
67   SMDS_Mesh();
68   
69   //! to retreive this SMDS_Mesh instance from its elements (index stored in SMDS_Elements)
70   static std::vector<SMDS_Mesh*> _meshList;
71
72   //! actual nodes coordinates, cells definition and reverse connectivity are stored in a vtkUnstructuredGrid
73   inline SMDS_UnstructuredGrid* getGrid() {return myGrid; }
74   inline int getMeshId() {return myMeshId; }
75
76   virtual SMDS_NodeIteratorPtr      nodesIterator     (bool idInceasingOrder=false) const;
77   virtual SMDS_0DElementIteratorPtr elements0dIterator(bool idInceasingOrder=false) const;
78   virtual SMDS_EdgeIteratorPtr      edgesIterator     (bool idInceasingOrder=false) const;
79   virtual SMDS_FaceIteratorPtr      facesIterator     (bool idInceasingOrder=false) const;
80   virtual SMDS_VolumeIteratorPtr    volumesIterator   (bool idInceasingOrder=false) const;
81
82   virtual SMDS_ElemIteratorPtr elementsIterator(SMDSAbs_ElementType type=SMDSAbs_All) const;
83
84   SMDSAbs_ElementType GetElementType( const int id, const bool iselem ) const;
85
86   SMDS_Mesh *AddSubMesh();
87
88   virtual SMDS_MeshNode* AddNodeWithID(double x, double y, double z, int ID);
89   virtual SMDS_MeshNode* AddNode(double x, double y, double z);
90
91   virtual SMDS_Mesh0DElement* Add0DElementWithID(int n, int ID);
92   virtual SMDS_Mesh0DElement* Add0DElementWithID(const SMDS_MeshNode * n, int ID);
93   virtual SMDS_Mesh0DElement* Add0DElement      (const SMDS_MeshNode * n);
94
95   virtual SMDS_MeshEdge* AddEdgeWithID(int n1, int n2, int ID);
96   virtual SMDS_MeshEdge* AddEdgeWithID(const SMDS_MeshNode * n1,
97                                        const SMDS_MeshNode * n2,
98                                        int ID);
99   virtual SMDS_MeshEdge* AddEdge(const SMDS_MeshNode * n1,
100                                  const SMDS_MeshNode * n2);
101
102   // 2d order edge with 3 nodes: n12 - node between n1 and n2
103   virtual SMDS_MeshEdge* AddEdgeWithID(int n1, int n2, int n12, int ID);
104   virtual SMDS_MeshEdge* AddEdgeWithID(const SMDS_MeshNode * n1,
105                                        const SMDS_MeshNode * n2,
106                                        const SMDS_MeshNode * n12,
107                                        int ID);
108   virtual SMDS_MeshEdge* AddEdge(const SMDS_MeshNode * n1,
109                                  const SMDS_MeshNode * n2,
110                                  const SMDS_MeshNode * n12);
111
112   virtual SMDS_MeshFace* AddFaceWithID(int n1, int n2, int n3, int ID);
113   virtual SMDS_MeshFace* AddFaceWithID(const SMDS_MeshNode * n1,
114                                        const SMDS_MeshNode * n2,
115                                        const SMDS_MeshNode * n3,
116                                        int ID);
117   virtual SMDS_MeshFace* AddFace(const SMDS_MeshNode * n1,
118                                  const SMDS_MeshNode * n2,
119                                  const SMDS_MeshNode * n3);
120
121   virtual SMDS_MeshFace* AddFaceWithID(int n1, int n2, int n3, int n4, int ID);
122   virtual SMDS_MeshFace* AddFaceWithID(const SMDS_MeshNode * n1,
123                                        const SMDS_MeshNode * n2,
124                                        const SMDS_MeshNode * n3,
125                                        const SMDS_MeshNode * n4,
126                                        int ID);
127   virtual SMDS_MeshFace* AddFace(const SMDS_MeshNode * n1,
128                                  const SMDS_MeshNode * n2,
129                                  const SMDS_MeshNode * n3,
130                                  const SMDS_MeshNode * n4);
131
132   virtual SMDS_MeshFace* AddFaceWithID(const SMDS_MeshEdge * e1,
133                                        const SMDS_MeshEdge * e2,
134                                        const SMDS_MeshEdge * e3, int ID);
135   virtual SMDS_MeshFace* AddFace(const SMDS_MeshEdge * e1,
136                                  const SMDS_MeshEdge * e2,
137                                  const SMDS_MeshEdge * e3);
138
139   virtual SMDS_MeshFace* AddFaceWithID(const SMDS_MeshEdge * e1,
140                                        const SMDS_MeshEdge * e2,
141                                        const SMDS_MeshEdge * e3,
142                                        const SMDS_MeshEdge * e4, int ID);
143   virtual SMDS_MeshFace* AddFace(const SMDS_MeshEdge * e1,
144                                  const SMDS_MeshEdge * e2,
145                                  const SMDS_MeshEdge * e3,
146                                  const SMDS_MeshEdge * e4);
147
148   // 2d order triangle of 6 nodes
149   virtual SMDS_MeshFace* AddFaceWithID(int n1, int n2, int n3,
150                                        int n12,int n23,int n31, int ID);
151   virtual SMDS_MeshFace* AddFaceWithID(const SMDS_MeshNode * n1,
152                                        const SMDS_MeshNode * n2,
153                                        const SMDS_MeshNode * n3,
154                                        const SMDS_MeshNode * n12,
155                                        const SMDS_MeshNode * n23,
156                                        const SMDS_MeshNode * n31,
157                                        int ID);
158   virtual SMDS_MeshFace* AddFace(const SMDS_MeshNode * n1,
159                                  const SMDS_MeshNode * n2,
160                                  const SMDS_MeshNode * n3,
161                                  const SMDS_MeshNode * n12,
162                                  const SMDS_MeshNode * n23,
163                                  const SMDS_MeshNode * n31);
164
165   // 2d order quadrangle
166   virtual SMDS_MeshFace* AddFaceWithID(int n1, int n2, int n3, int n4,
167                                        int n12,int n23,int n34,int n41, int ID);
168   virtual SMDS_MeshFace* AddFaceWithID(const SMDS_MeshNode * n1,
169                                        const SMDS_MeshNode * n2,
170                                        const SMDS_MeshNode * n3,
171                                        const SMDS_MeshNode * n4,
172                                        const SMDS_MeshNode * n12,
173                                        const SMDS_MeshNode * n23,
174                                        const SMDS_MeshNode * n34,
175                                        const SMDS_MeshNode * n41,
176                                        int ID);
177   virtual SMDS_MeshFace* AddFace(const SMDS_MeshNode * n1,
178                                  const SMDS_MeshNode * n2,
179                                  const SMDS_MeshNode * n3,
180                                  const SMDS_MeshNode * n4,
181                                  const SMDS_MeshNode * n12,
182                                  const SMDS_MeshNode * n23,
183                                  const SMDS_MeshNode * n34,
184                                  const SMDS_MeshNode * n41);
185
186   virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int ID);
187   virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
188                                            const SMDS_MeshNode * n2,
189                                            const SMDS_MeshNode * n3,
190                                            const SMDS_MeshNode * n4,
191                                            int ID);
192   virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
193                                      const SMDS_MeshNode * n2,
194                                      const SMDS_MeshNode * n3,
195                                      const SMDS_MeshNode * n4);
196
197   virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4,
198                                            int n5, int ID);
199   virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
200                                            const SMDS_MeshNode * n2,
201                                            const SMDS_MeshNode * n3,
202                                            const SMDS_MeshNode * n4,
203                                            const SMDS_MeshNode * n5,
204                                            int ID);
205   virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
206                                      const SMDS_MeshNode * n2,
207                                      const SMDS_MeshNode * n3,
208                                      const SMDS_MeshNode * n4,
209                                      const SMDS_MeshNode * n5);
210
211   virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4,
212                                            int n5, int n6, int ID);
213   virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
214                                            const SMDS_MeshNode * n2,
215                                            const SMDS_MeshNode * n3,
216                                            const SMDS_MeshNode * n4,
217                                            const SMDS_MeshNode * n5,
218                                            const SMDS_MeshNode * n6,
219                                            int ID);
220   virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
221                                      const SMDS_MeshNode * n2,
222                                      const SMDS_MeshNode * n3,
223                                      const SMDS_MeshNode * n4,
224                                      const SMDS_MeshNode * n5,
225                                      const SMDS_MeshNode * n6);
226
227   virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4,
228                                            int n5, int n6, int n7, int n8, int ID);
229   virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
230                                            const SMDS_MeshNode * n2,
231                                            const SMDS_MeshNode * n3,
232                                            const SMDS_MeshNode * n4,
233                                            const SMDS_MeshNode * n5,
234                                            const SMDS_MeshNode * n6,
235                                            const SMDS_MeshNode * n7,
236                                            const SMDS_MeshNode * n8,
237                                            int ID);
238   virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
239                                      const SMDS_MeshNode * n2,
240                                      const SMDS_MeshNode * n3,
241                                      const SMDS_MeshNode * n4,
242                                      const SMDS_MeshNode * n5,
243                                      const SMDS_MeshNode * n6,
244                                      const SMDS_MeshNode * n7,
245                                      const SMDS_MeshNode * n8);
246
247   virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshFace * f1,
248                                            const SMDS_MeshFace * f2,
249                                            const SMDS_MeshFace * f3,
250                                            const SMDS_MeshFace * f4, int ID);
251   virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshFace * f1,
252                                      const SMDS_MeshFace * f2,
253                                      const SMDS_MeshFace * f3,
254                                      const SMDS_MeshFace * f4);
255
256   virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshFace * f1,
257                                            const SMDS_MeshFace * f2,
258                                            const SMDS_MeshFace * f3,
259                                            const SMDS_MeshFace * f4,
260                                            const SMDS_MeshFace * f5, int ID);
261   virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshFace * f1,
262                                      const SMDS_MeshFace * f2,
263                                      const SMDS_MeshFace * f3,
264                                      const SMDS_MeshFace * f4,
265                                      const SMDS_MeshFace * f5);
266
267   virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshFace * f1,
268                                            const SMDS_MeshFace * f2,
269                                            const SMDS_MeshFace * f3,
270                                            const SMDS_MeshFace * f4,
271                                            const SMDS_MeshFace * f5,
272                                            const SMDS_MeshFace * f6, int ID);
273   virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshFace * f1,
274                                      const SMDS_MeshFace * f2,
275                                      const SMDS_MeshFace * f3,
276                                      const SMDS_MeshFace * f4,
277                                      const SMDS_MeshFace * f5,
278                                      const SMDS_MeshFace * f6);
279
280   // 2d order tetrahedron of 10 nodes
281   virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4,
282                                            int n12,int n23,int n31,
283                                            int n14,int n24,int n34, int ID);
284   virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
285                                            const SMDS_MeshNode * n2,
286                                            const SMDS_MeshNode * n3,
287                                            const SMDS_MeshNode * n4,
288                                            const SMDS_MeshNode * n12,
289                                            const SMDS_MeshNode * n23,
290                                            const SMDS_MeshNode * n31,
291                                            const SMDS_MeshNode * n14,
292                                            const SMDS_MeshNode * n24,
293                                            const SMDS_MeshNode * n34,
294                                            int ID);
295   virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
296                                      const SMDS_MeshNode * n2,
297                                      const SMDS_MeshNode * n3,
298                                      const SMDS_MeshNode * n4,
299                                      const SMDS_MeshNode * n12,
300                                      const SMDS_MeshNode * n23,
301                                      const SMDS_MeshNode * n31,
302                                      const SMDS_MeshNode * n14,
303                                      const SMDS_MeshNode * n24,
304                                      const SMDS_MeshNode * n34);
305
306   // 2d order pyramid of 13 nodes
307   virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int n5,
308                                            int n12,int n23,int n34,int n41,
309                                            int n15,int n25,int n35,int n45,
310                                            int ID);
311   virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
312                                            const SMDS_MeshNode * n2,
313                                            const SMDS_MeshNode * n3,
314                                            const SMDS_MeshNode * n4,
315                                            const SMDS_MeshNode * n5,
316                                            const SMDS_MeshNode * n12,
317                                            const SMDS_MeshNode * n23,
318                                            const SMDS_MeshNode * n34,
319                                            const SMDS_MeshNode * n41,
320                                            const SMDS_MeshNode * n15,
321                                            const SMDS_MeshNode * n25,
322                                            const SMDS_MeshNode * n35,
323                                            const SMDS_MeshNode * n45,
324                                            int ID);
325   virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
326                                      const SMDS_MeshNode * n2,
327                                      const SMDS_MeshNode * n3,
328                                      const SMDS_MeshNode * n4,
329                                      const SMDS_MeshNode * n5,
330                                      const SMDS_MeshNode * n12,
331                                      const SMDS_MeshNode * n23,
332                                      const SMDS_MeshNode * n34,
333                                      const SMDS_MeshNode * n41,
334                                      const SMDS_MeshNode * n15,
335                                      const SMDS_MeshNode * n25,
336                                      const SMDS_MeshNode * n35,
337                                      const SMDS_MeshNode * n45);
338
339   // 2d order Pentahedron with 15 nodes
340   virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3,
341                                            int n4, int n5, int n6,
342                                            int n12,int n23,int n31,
343                                            int n45,int n56,int n64,
344                                            int n14,int n25,int n36,
345                                            int ID);
346   virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
347                                            const SMDS_MeshNode * n2,
348                                            const SMDS_MeshNode * n3,
349                                            const SMDS_MeshNode * n4,
350                                            const SMDS_MeshNode * n5,
351                                            const SMDS_MeshNode * n6,
352                                            const SMDS_MeshNode * n12,
353                                            const SMDS_MeshNode * n23,
354                                            const SMDS_MeshNode * n31,
355                                            const SMDS_MeshNode * n45,
356                                            const SMDS_MeshNode * n56,
357                                            const SMDS_MeshNode * n64,
358                                            const SMDS_MeshNode * n14,
359                                            const SMDS_MeshNode * n25,
360                                            const SMDS_MeshNode * n36,
361                                            int ID);
362   virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
363                                      const SMDS_MeshNode * n2,
364                                      const SMDS_MeshNode * n3,
365                                      const SMDS_MeshNode * n4,
366                                      const SMDS_MeshNode * n5,
367                                      const SMDS_MeshNode * n6,
368                                      const SMDS_MeshNode * n12,
369                                      const SMDS_MeshNode * n23,
370                                      const SMDS_MeshNode * n31,
371                                      const SMDS_MeshNode * n45,
372                                      const SMDS_MeshNode * n56,
373                                      const SMDS_MeshNode * n64,
374                                      const SMDS_MeshNode * n14,
375                                      const SMDS_MeshNode * n25,
376                                      const SMDS_MeshNode * n36);
377
378   // 2d oreder Hexahedrons with 20 nodes
379   virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4,
380                                            int n5, int n6, int n7, int n8,
381                                            int n12,int n23,int n34,int n41,
382                                            int n56,int n67,int n78,int n85,
383                                            int n15,int n26,int n37,int n48,
384                                            int ID);
385   virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
386                                            const SMDS_MeshNode * n2,
387                                            const SMDS_MeshNode * n3,
388                                            const SMDS_MeshNode * n4,
389                                            const SMDS_MeshNode * n5,
390                                            const SMDS_MeshNode * n6,
391                                            const SMDS_MeshNode * n7,
392                                            const SMDS_MeshNode * n8,
393                                            const SMDS_MeshNode * n12,
394                                            const SMDS_MeshNode * n23,
395                                            const SMDS_MeshNode * n34,
396                                            const SMDS_MeshNode * n41,
397                                            const SMDS_MeshNode * n56,
398                                            const SMDS_MeshNode * n67,
399                                            const SMDS_MeshNode * n78,
400                                            const SMDS_MeshNode * n85,
401                                            const SMDS_MeshNode * n15,
402                                            const SMDS_MeshNode * n26,
403                                            const SMDS_MeshNode * n37,
404                                            const SMDS_MeshNode * n48,
405                                            int ID);
406   virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
407                                      const SMDS_MeshNode * n2,
408                                      const SMDS_MeshNode * n3,
409                                      const SMDS_MeshNode * n4,
410                                      const SMDS_MeshNode * n5,
411                                      const SMDS_MeshNode * n6,
412                                      const SMDS_MeshNode * n7,
413                                      const SMDS_MeshNode * n8,
414                                      const SMDS_MeshNode * n12,
415                                      const SMDS_MeshNode * n23,
416                                      const SMDS_MeshNode * n34,
417                                      const SMDS_MeshNode * n41,
418                                      const SMDS_MeshNode * n56,
419                                      const SMDS_MeshNode * n67,
420                                      const SMDS_MeshNode * n78,
421                                      const SMDS_MeshNode * n85,
422                                      const SMDS_MeshNode * n15,
423                                      const SMDS_MeshNode * n26,
424                                      const SMDS_MeshNode * n37,
425                                      const SMDS_MeshNode * n48);
426
427   virtual SMDS_MeshFace* AddPolygonalFaceWithID (std::vector<int> nodes_ids,
428                                                  const int        ID);
429
430   virtual SMDS_MeshFace* AddPolygonalFaceWithID (std::vector<const SMDS_MeshNode*> nodes,
431                                                  const int                         ID);
432
433   virtual SMDS_MeshFace* AddPolygonalFace (std::vector<const SMDS_MeshNode*> nodes);
434
435   virtual SMDS_MeshVolume* AddPolyhedralVolumeWithID
436                            (std::vector<int> nodes_ids,
437                             std::vector<int> quantities,
438                             const int        ID);
439
440   virtual SMDS_MeshVolume* AddPolyhedralVolumeWithID
441                            (std::vector<const SMDS_MeshNode*> nodes,
442                             std::vector<int>                  quantities,
443                             const int                         ID);
444
445   virtual SMDS_MeshVolume* AddPolyhedralVolume
446                            (std::vector<const SMDS_MeshNode*> nodes,
447                             std::vector<int>                  quantities);
448
449   virtual SMDS_MeshVolume* AddVolumeFromVtkIds(const std::vector<vtkIdType>& vtkNodeIds);
450
451   virtual SMDS_MeshVolume* AddVolumeFromVtkIdsWithID(const std::vector<vtkIdType>& vtkNodeIds,
452                                                      const int ID);
453
454   virtual void RemoveElement(const SMDS_MeshElement *        elem,
455                              std::list<const SMDS_MeshElement *>& removedElems,
456                              std::list<const SMDS_MeshElement *>& removedNodes,
457                              const bool                      removenodes = false);
458   virtual void RemoveElement(const SMDS_MeshElement * elem, bool removenodes = false);
459   virtual void RemoveNode(const SMDS_MeshNode * node);
460   virtual void Remove0DElement(const SMDS_Mesh0DElement * elem0d);
461   virtual void RemoveEdge(const SMDS_MeshEdge * edge);
462   virtual void RemoveFace(const SMDS_MeshFace * face);
463   virtual void RemoveVolume(const SMDS_MeshVolume * volume);
464
465   /*! Remove only the given element and only if it is free.
466    *  Method does not work for meshes with descendants.
467    *  Implemented for fast cleaning of meshes.
468    */
469   virtual void RemoveFreeElement(const SMDS_MeshElement * elem);
470
471   virtual void Clear();
472
473   virtual bool RemoveFromParent();
474   virtual bool RemoveSubMesh(const SMDS_Mesh * aMesh);
475
476   bool ChangeElementNodes(const SMDS_MeshElement * elem,
477                           const SMDS_MeshNode    * nodes[],
478                           const int                nbnodes);
479   bool ChangePolyhedronNodes(const SMDS_MeshElement *                 elem,
480                              const std::vector<const SMDS_MeshNode*>& nodes,
481                              const std::vector<int> &                 quantities);
482
483   virtual void Renumber (const bool isNodes, const int startID = 1, const int deltaID = 1);
484   // Renumber all nodes or elements.
485   virtual void compactMesh();
486
487   const SMDS_MeshNode *FindNode(int idnode) const;
488   const SMDS_MeshNode *FindNodeVtk(int idnode) const;
489   const SMDS_Mesh0DElement* Find0DElement(int idnode) const;
490   const SMDS_MeshEdge *FindEdge(int idnode1, int idnode2) const;
491   const SMDS_MeshEdge *FindEdge(int idnode1, int idnode2, int idnode3) const;
492   const SMDS_MeshFace *FindFace(int idnode1, int idnode2, int idnode3) const;
493   const SMDS_MeshFace *FindFace(int idnode1, int idnode2, int idnode3, int idnode4) const;
494   const SMDS_MeshFace *FindFace(int idnode1, int idnode2, int idnode3,
495                                 int idnode4, int idnode5, int idnode6) const;
496   const SMDS_MeshFace *FindFace(int idnode1, int idnode2, int idnode3, int idnode4,
497                                 int idnode5, int idnode6, int idnode7, int idnode8) const;
498   const SMDS_MeshElement *FindElement(int IDelem) const;
499   static const SMDS_Mesh0DElement* Find0DElement(const SMDS_MeshNode * n);
500   static const SMDS_MeshEdge* FindEdge(const SMDS_MeshNode * n1,
501                                        const SMDS_MeshNode * n2);
502   static const SMDS_MeshEdge* FindEdge(const SMDS_MeshNode * n1,
503                                        const SMDS_MeshNode * n2,
504                                        const SMDS_MeshNode * n3);
505   static const SMDS_MeshFace* FindFace(const SMDS_MeshNode *n1,
506                                        const SMDS_MeshNode *n2,
507                                        const SMDS_MeshNode *n3);
508   static const SMDS_MeshFace* FindFace(const SMDS_MeshNode *n1,
509                                        const SMDS_MeshNode *n2,
510                                        const SMDS_MeshNode *n3,
511                                        const SMDS_MeshNode *n4);
512   static const SMDS_MeshFace* FindFace(const SMDS_MeshNode *n1,
513                                        const SMDS_MeshNode *n2,
514                                        const SMDS_MeshNode *n3,
515                                        const SMDS_MeshNode *n4,
516                                        const SMDS_MeshNode *n5,
517                                        const SMDS_MeshNode *n6);
518   static const SMDS_MeshFace* FindFace(const SMDS_MeshNode *n1,
519                                        const SMDS_MeshNode *n2,
520                                        const SMDS_MeshNode *n3,
521                                        const SMDS_MeshNode *n4,
522                                        const SMDS_MeshNode *n5,
523                                        const SMDS_MeshNode *n6,
524                                        const SMDS_MeshNode *n7,
525                                        const SMDS_MeshNode *n8);
526
527   const SMDS_MeshFace *FindFace(const std::vector<int>& nodes_ids) const;
528   static const SMDS_MeshFace* FindFace(const std::vector<const SMDS_MeshNode *>& nodes);
529   static const SMDS_MeshElement* FindElement(const std::vector<const SMDS_MeshNode *>& nodes,
530                                              const SMDSAbs_ElementType                 type=SMDSAbs_All,
531                                              const bool                                noMedium=true);
532
533   /*!
534    * \brief Raise an exception if free memory (ram+swap) too low
535     * \param doNotRaise - if true, suppres exception, just return free memory size
536     * \retval int - amount of available memory in MB or negative number in failure case
537    */
538   static int CheckMemory(const bool doNotRaise=false) throw (std::bad_alloc);
539
540   int MaxNodeID() const;
541   int MinNodeID() const;
542   int MaxElementID() const;
543   int MinElementID() const;
544
545   const SMDS_MeshInfo& GetMeshInfo() const { return myInfo; }
546
547   virtual int NbNodes() const;
548   virtual int Nb0DElements() const;
549   virtual int NbEdges() const;
550   virtual int NbFaces() const;
551   virtual int NbVolumes() const;
552   virtual int NbSubMesh() const;
553
554   void DumpNodes() const;
555   void Dump0DElements() const;
556   void DumpEdges() const;
557   void DumpFaces() const;
558   void DumpVolumes() const;
559   void DebugStats() const;
560
561   virtual ~SMDS_Mesh();
562
563   bool hasConstructionEdges();
564   bool hasConstructionFaces();
565   bool hasInverseElements();
566   void setConstructionEdges(bool);
567   void setConstructionFaces(bool);
568   void setInverseElements(bool);
569
570   /*!
571    * Checks if the element is present in mesh.
572    * Useful to determine dead pointers.
573    * Use this function for debug purpose only! Do not check in the code
574    * using it even in _DEBUG_ mode
575    */
576   bool Contains (const SMDS_MeshElement* elem) const;
577
578   typedef std::vector<SMDS_MeshNode *> SetOfNodes;
579   typedef std::vector<SMDS_MeshCell *> SetOfCells;
580
581   void updateNodeMinMax();
582   void updateBoundingBox();
583   double getMaxDim();
584   int fromVtkToSmds(int vtkid);
585
586   void incrementNodesCapacity(int nbNodes);
587   void incrementCellsCapacity(int nbCells);
588   void adjustStructure();
589   void dumpGrid(string ficdump="dumpGrid");
590   static int chunkSize;
591
592   //! low level modification: add, change or remove node or element
593   inline void setMyModified() { this->myModified = true; }
594
595   void Modified();
596   unsigned long GetMTime() const;
597   bool isCompacted();
598
599 protected:
600   SMDS_Mesh(SMDS_Mesh * parent);
601
602   SMDS_MeshFace * createTriangle(const SMDS_MeshNode * node1,
603                                  const SMDS_MeshNode * node2,
604                                  const SMDS_MeshNode * node3,
605                                  int ID);
606   SMDS_MeshFace * createQuadrangle(const SMDS_MeshNode * node1,
607                                    const SMDS_MeshNode * node2,
608                                    const SMDS_MeshNode * node3,
609                                    const SMDS_MeshNode * node4,
610                                    int ID);
611 //  SMDS_Mesh0DElement* Find0DElementOrCreate(const SMDS_MeshNode * n);
612   SMDS_MeshEdge* FindEdgeOrCreate(const SMDS_MeshNode * n1,
613                                   const SMDS_MeshNode * n2);
614   SMDS_MeshFace* FindFaceOrCreate(const SMDS_MeshNode *n1,
615                                   const SMDS_MeshNode *n2,
616                                   const SMDS_MeshNode *n3);
617   SMDS_MeshFace* FindFaceOrCreate(const SMDS_MeshNode *n1,
618                                   const SMDS_MeshNode *n2,
619                                   const SMDS_MeshNode *n3,
620                                   const SMDS_MeshNode *n4);
621
622   bool registerElement(int ID, SMDS_MeshElement * element);
623
624   void addChildrenWithNodes(std::set<const SMDS_MeshElement*>& setOfChildren,
625                             const SMDS_MeshElement * element,
626                             std::set<const SMDS_MeshElement*>& nodes);
627
628   inline void adjustmyCellsCapacity(int ID)
629   {
630     assert(ID >= 0);
631     myElementIDFactory->adjustMaxId(ID);
632     if (ID >= myCells.size())
633       myCells.resize(ID+SMDS_Mesh::chunkSize,0);
634   }
635
636   inline void adjustBoundingBox(double x, double y, double z)
637   {
638     if (x > xmax) xmax = x;
639     else if (x < xmin) xmin = x;
640     if (y > ymax) ymax = y;
641     else if (y < ymin) ymin = y;
642     if (z > zmax) zmax = z;
643     else if (z < zmin) zmin = z;
644   }
645
646   // Fields PRIVATE
647
648   //! index of this SMDS_mesh in the static vector<SMDS_Mesh*> _meshList
649   int myMeshId;
650
651   //! actual nodes coordinates, cells definition and reverse connectivity are stored in a vtkUnstructuredGrid
652   SMDS_UnstructuredGrid*      myGrid;
653
654   //! Small objects like SMDS_MeshNode are allocated by chunks to limit memory costs of new
655   ObjectPool<SMDS_MeshNode>* myNodePool;
656
657   //! Small objects like SMDS_VtkVolume are allocated by chunks to limit memory costs of new
658   ObjectPool<SMDS_VtkVolume>* myVolumePool;
659   ObjectPool<SMDS_VtkFace>* myFacePool;
660   ObjectPool<SMDS_VtkEdge>* myEdgePool;
661
662   //! SMDS_MeshNodes refer to vtk nodes (vtk id = index in myNodes),store reference to this mesh, and subshape
663   SetOfNodes             myNodes;
664
665   //! SMDS_MeshCells refer to vtk cells (vtk id != index in myCells),store reference to this mesh, and subshape
666   SetOfCells             myCells;
667
668   //! for cells only: index = ID for SMDS users, value = ID in vtkUnstructuredGrid
669   //std::vector<int>       myCellIdSmdsToVtk;
670
671   //! for cells only: index = ID in vtkUnstructuredGrid, value = ID for SMDS users
672   std::vector<int>       myCellIdVtkToSmds;
673
674   SMDS_Mesh *            myParent;
675   std::list<SMDS_Mesh *> myChildren;
676   SMDS_MeshNodeIDFactory *myNodeIDFactory;
677   SMDS_MeshElementIDFactory *myElementIDFactory;
678   SMDS_MeshInfo          myInfo;
679
680   //! use a counter to keep track of modifications
681   unsigned long myModifTime, myCompactTime;
682
683   int myNodeMin;
684   int myNodeMax;
685
686   bool myHasConstructionEdges;
687   bool myHasConstructionFaces;
688   bool myHasInverseElements;
689
690   //! any add, remove or change of node or cell
691   bool myModified;
692
693   double xmin;
694   double xmax;
695   double ymin;
696   double ymax;
697   double zmin;
698   double zmax;
699 };
700
701
702 #endif