1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMDS : implementaion of Salome mesh data structure
24 // File : SMDS_Mesh.hxx
27 #ifndef _SMDS_Mesh_HeaderFile
28 #define _SMDS_Mesh_HeaderFile
30 #include "SMESH_SMDS.hxx"
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"
49 #include <boost/shared_ptr.hpp>
53 #include <vtkSystemIncludes.h>
56 #include "Utils_SALOME_Exception.hxx"
57 #define MYASSERT(val) if (!(val)) throw SALOME_Exception(LOCALIZED("assertion not verified"));
59 class SMDS_EXPORT SMDS_Mesh:public SMDS_MeshObject{
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;
69 //! to retreive this SMDS_Mesh instance from its elements (index stored in SMDS_Elements)
70 static std::vector<SMDS_Mesh*> _meshList;
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; }
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;
82 virtual SMDS_ElemIteratorPtr elementsIterator(SMDSAbs_ElementType type=SMDSAbs_All) const;
84 SMDSAbs_ElementType GetElementType( const int id, const bool iselem ) const;
86 SMDS_Mesh *AddSubMesh();
88 virtual SMDS_MeshNode* AddNodeWithID(double x, double y, double z, int ID);
89 virtual SMDS_MeshNode* AddNode(double x, double y, double z);
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);
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,
99 virtual SMDS_MeshEdge* AddEdge(const SMDS_MeshNode * n1,
100 const SMDS_MeshNode * n2);
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,
108 virtual SMDS_MeshEdge* AddEdge(const SMDS_MeshNode * n1,
109 const SMDS_MeshNode * n2,
110 const SMDS_MeshNode * n12);
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,
117 virtual SMDS_MeshFace* AddFace(const SMDS_MeshNode * n1,
118 const SMDS_MeshNode * n2,
119 const SMDS_MeshNode * n3);
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,
127 virtual SMDS_MeshFace* AddFace(const SMDS_MeshNode * n1,
128 const SMDS_MeshNode * n2,
129 const SMDS_MeshNode * n3,
130 const SMDS_MeshNode * n4);
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);
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);
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,
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);
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,
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);
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,
192 virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
193 const SMDS_MeshNode * n2,
194 const SMDS_MeshNode * n3,
195 const SMDS_MeshNode * n4);
197 virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4,
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,
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);
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,
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);
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,
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);
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);
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);
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);
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,
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);
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,
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,
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);
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,
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,
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);
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,
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,
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);
427 virtual SMDS_MeshFace* AddPolygonalFaceWithID (std::vector<int> nodes_ids,
430 virtual SMDS_MeshFace* AddPolygonalFaceWithID (std::vector<const SMDS_MeshNode*> nodes,
433 virtual SMDS_MeshFace* AddPolygonalFace (std::vector<const SMDS_MeshNode*> nodes);
435 virtual SMDS_MeshVolume* AddPolyhedralVolumeWithID
436 (std::vector<int> nodes_ids,
437 std::vector<int> quantities,
440 virtual SMDS_MeshVolume* AddPolyhedralVolumeWithID
441 (std::vector<const SMDS_MeshNode*> nodes,
442 std::vector<int> quantities,
445 virtual SMDS_MeshVolume* AddPolyhedralVolume
446 (std::vector<const SMDS_MeshNode*> nodes,
447 std::vector<int> quantities);
449 virtual SMDS_MeshVolume* AddVolumeFromVtkIds(const std::vector<vtkIdType>& vtkNodeIds);
451 virtual SMDS_MeshVolume* AddVolumeFromVtkIdsWithID(const std::vector<vtkIdType>& vtkNodeIds,
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);
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.
469 virtual void RemoveFreeElement(const SMDS_MeshElement * elem);
471 virtual void Clear();
473 virtual bool RemoveFromParent();
474 virtual bool RemoveSubMesh(const SMDS_Mesh * aMesh);
476 bool ChangeElementNodes(const SMDS_MeshElement * elem,
477 const SMDS_MeshNode * nodes[],
479 bool ChangePolyhedronNodes(const SMDS_MeshElement * elem,
480 const std::vector<const SMDS_MeshNode*>& nodes,
481 const std::vector<int> & quantities);
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();
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);
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);
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
538 static int CheckMemory(const bool doNotRaise=false) throw (std::bad_alloc);
540 int MaxNodeID() const;
541 int MinNodeID() const;
542 int MaxElementID() const;
543 int MinElementID() const;
545 const SMDS_MeshInfo& GetMeshInfo() const { return myInfo; }
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;
554 void DumpNodes() const;
555 void Dump0DElements() const;
556 void DumpEdges() const;
557 void DumpFaces() const;
558 void DumpVolumes() const;
559 void DebugStats() const;
561 virtual ~SMDS_Mesh();
563 bool hasConstructionEdges();
564 bool hasConstructionFaces();
565 bool hasInverseElements();
566 void setConstructionEdges(bool);
567 void setConstructionFaces(bool);
568 void setInverseElements(bool);
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
576 bool Contains (const SMDS_MeshElement* elem) const;
578 typedef std::vector<SMDS_MeshNode *> SetOfNodes;
579 typedef std::vector<SMDS_MeshCell *> SetOfCells;
581 void updateNodeMinMax();
582 void updateBoundingBox();
584 int fromVtkToSmds(int vtkid);
586 void incrementNodesCapacity(int nbNodes);
587 void incrementCellsCapacity(int nbCells);
588 void adjustStructure();
589 void dumpGrid(string ficdump="dumpGrid");
590 static int chunkSize;
592 //! low level modification: add, change or remove node or element
593 inline void setMyModified() { this->myModified = true; }
596 unsigned long GetMTime() const;
600 SMDS_Mesh(SMDS_Mesh * parent);
602 SMDS_MeshFace * createTriangle(const SMDS_MeshNode * node1,
603 const SMDS_MeshNode * node2,
604 const SMDS_MeshNode * node3,
606 SMDS_MeshFace * createQuadrangle(const SMDS_MeshNode * node1,
607 const SMDS_MeshNode * node2,
608 const SMDS_MeshNode * node3,
609 const SMDS_MeshNode * node4,
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);
622 bool registerElement(int ID, SMDS_MeshElement * element);
624 void addChildrenWithNodes(std::set<const SMDS_MeshElement*>& setOfChildren,
625 const SMDS_MeshElement * element,
626 std::set<const SMDS_MeshElement*>& nodes);
628 inline void adjustmyCellsCapacity(int ID)
631 myElementIDFactory->adjustMaxId(ID);
632 if (ID >= myCells.size())
633 myCells.resize(ID+SMDS_Mesh::chunkSize,0);
636 inline void adjustBoundingBox(double x, double y, double z)
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;
648 //! index of this SMDS_mesh in the static vector<SMDS_Mesh*> _meshList
651 //! actual nodes coordinates, cells definition and reverse connectivity are stored in a vtkUnstructuredGrid
652 SMDS_UnstructuredGrid* myGrid;
654 //! Small objects like SMDS_MeshNode are allocated by chunks to limit memory costs of new
655 ObjectPool<SMDS_MeshNode>* myNodePool;
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;
662 //! SMDS_MeshNodes refer to vtk nodes (vtk id = index in myNodes),store reference to this mesh, and subshape
665 //! SMDS_MeshCells refer to vtk cells (vtk id != index in myCells),store reference to this mesh, and subshape
668 //! for cells only: index = ID for SMDS users, value = ID in vtkUnstructuredGrid
669 //std::vector<int> myCellIdSmdsToVtk;
671 //! for cells only: index = ID in vtkUnstructuredGrid, value = ID for SMDS users
672 std::vector<int> myCellIdVtkToSmds;
674 SMDS_Mesh * myParent;
675 std::list<SMDS_Mesh *> myChildren;
676 SMDS_MeshNodeIDFactory *myNodeIDFactory;
677 SMDS_MeshElementIDFactory *myElementIDFactory;
678 SMDS_MeshInfo myInfo;
680 //! use a counter to keep track of modifications
681 unsigned long myModifTime, myCompactTime;
686 bool myHasConstructionEdges;
687 bool myHasConstructionFaces;
688 bool myHasInverseElements;
690 //! any add, remove or change of node or cell