1 // Copyright (C) 2007-2008 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
22 // SMESH SMDS : implementaion of Salome mesh data structure
25 #pragma warning(disable:4786)
28 #include "utilities.h"
29 #include "SMDS_Mesh.hxx"
30 #include "SMDS_VolumeOfNodes.hxx"
31 #include "SMDS_VolumeOfFaces.hxx"
32 #include "SMDS_FaceOfNodes.hxx"
33 #include "SMDS_FaceOfEdges.hxx"
34 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
35 #include "SMDS_PolygonalFaceOfNodes.hxx"
36 #include "SMDS_QuadraticEdge.hxx"
37 #include "SMDS_QuadraticFaceOfNodes.hxx"
38 #include "SMDS_QuadraticVolumeOfNodes.hxx"
40 #include <vtkUnstructuredGrid.h>
47 #include <sys/sysinfo.h>
50 // number of added entitis to check memory after
51 #define CHECKMEMORY_INTERVAL 1000
53 vector<SMDS_Mesh*> SMDS_Mesh::_meshList = vector<SMDS_Mesh*>();
54 int SMDS_Mesh::chunkSize = 1024;
57 //================================================================================
59 * \brief Raise an exception if free memory (ram+swap) too low
60 * \param doNotRaise - if true, suppres exception, just return free memory size
61 * \retval int - amount of available memory in MB or negative number in failure case
63 //================================================================================
65 int SMDS_Mesh::CheckMemory(const bool doNotRaise) throw (std::bad_alloc)
69 int err = sysinfo( &si );
73 static int limit = -1;
75 int status = system("SMDS_MemoryLimit"); // it returns lower limit of free RAM
77 limit = WEXITSTATUS(status);
82 limit = int( limit * 1.5 );
84 MESSAGE ( "SMDS_Mesh::CheckMemory() memory limit = " << limit << " MB" );
88 const unsigned long Mbyte = 1024 * 1024;
89 // compute separately to avoid overflow
91 ( si.freeram * si.mem_unit ) / Mbyte +
92 ( si.freeswap * si.mem_unit ) / Mbyte;
95 return freeMb - limit;
100 MESSAGE ("SMDS_Mesh::CheckMemory() throws as free memory too low: " << freeMb <<" MB" );
102 throw std::bad_alloc();
108 ///////////////////////////////////////////////////////////////////////////////
109 /// Create a new mesh object
110 ///////////////////////////////////////////////////////////////////////////////
111 SMDS_Mesh::SMDS_Mesh()
113 myNodeIDFactory(new SMDS_MeshNodeIDFactory()),
114 myElementIDFactory(new SMDS_MeshElementIDFactory()),
115 myHasConstructionEdges(false), myHasConstructionFaces(false),
116 myHasInverseElements(true),
117 myNodeMin(0), myNodeMax(0), myCellLinksSize(0),
118 myNodePool(0), myVolumePool(0)
120 myMeshId = _meshList.size(); // --- index of the mesh to push back in the vector
121 MESSAGE("myMeshId=" << myMeshId);
122 myNodeIDFactory->SetMesh(this);
123 myElementIDFactory->SetMesh(this);
124 _meshList.push_back(this);
125 myNodePool = new ObjectPool<SMDS_MeshNode>(SMDS_Mesh::chunkSize);
126 myVolumePool = new ObjectPool<SMDS_VolumeVtkNodes>(SMDS_Mesh::chunkSize);
130 myIDElements.clear();
132 myGrid = vtkUnstructuredGrid::New();
133 myGrid->Initialize();
135 vtkPoints* points = vtkPoints::New();
136 points->SetNumberOfPoints(SMDS_Mesh::chunkSize);
137 myGrid->SetPoints( points );
139 myGrid->BuildLinks();
142 ///////////////////////////////////////////////////////////////////////////////
143 /// Create a new child mesh
144 /// Note that the tree structure of SMDS_Mesh seems to be unused in this version
145 /// (2003-09-08) of SMESH
146 ///////////////////////////////////////////////////////////////////////////////
147 SMDS_Mesh::SMDS_Mesh(SMDS_Mesh * parent)
148 :myParent(parent), myNodeIDFactory(parent->myNodeIDFactory),
149 myElementIDFactory(parent->myElementIDFactory),
150 myHasConstructionEdges(false), myHasConstructionFaces(false),
151 myHasInverseElements(true),
152 myNodePool(parent->myNodePool),
153 myVolumePool(parent->myVolumePool)
157 ///////////////////////////////////////////////////////////////////////////////
158 ///Create a submesh and add it to the current mesh
159 ///////////////////////////////////////////////////////////////////////////////
161 SMDS_Mesh *SMDS_Mesh::AddSubMesh()
163 SMDS_Mesh *submesh = new SMDS_Mesh(this);
164 myChildren.insert(myChildren.end(), submesh);
168 ///////////////////////////////////////////////////////////////////////////////
169 ///create a MeshNode and add it to the current Mesh
170 ///An ID is automatically assigned to the node.
171 ///@return : The created node
172 ///////////////////////////////////////////////////////////////////////////////
174 SMDS_MeshNode * SMDS_Mesh::AddNode(double x, double y, double z)
176 return SMDS_Mesh::AddNodeWithID(x,y,z,myNodeIDFactory->GetFreeID());
179 ///////////////////////////////////////////////////////////////////////////////
180 ///create a MeshNode and add it to the current Mesh
181 ///@param ID : The ID of the MeshNode to create
182 ///@return : The created node or NULL if a node with this ID already exists
183 ///////////////////////////////////////////////////////////////////////////////
184 SMDS_MeshNode * SMDS_Mesh::AddNodeWithID(double x, double y, double z, int ID)
186 // find the MeshNode corresponding to ID
187 const SMDS_MeshElement *node = myNodeIDFactory->MeshElement(ID);
189 //if ( myNodes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
190 //SMDS_MeshNode * node=new SMDS_MeshNode(ID, myMeshId, -1, x, y, z);
191 SMDS_MeshNode * node = myNodePool->getNew();
192 node->init(ID, myMeshId, -1, x, y, z);
193 if (ID >= myNodes.size())
195 myNodes.resize(ID+SMDS_Mesh::chunkSize, 0);
196 //MESSAGE(" ------------------ myNodes resize " << ID << " --> " << ID+SMDS_Mesh::chunkSize);
199 myNodeIDFactory->BindID(ID,node);
206 ///////////////////////////////////////////////////////////////////////////////
207 /// create a Mesh0DElement and add it to the current Mesh
208 /// @return : The created Mesh0DElement
209 ///////////////////////////////////////////////////////////////////////////////
210 SMDS_Mesh0DElement* SMDS_Mesh::Add0DElementWithID(int idnode, int ID)
212 SMDS_MeshNode * node = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode);
213 if (!node) return NULL;
214 return SMDS_Mesh::Add0DElementWithID(node, ID);
217 ///////////////////////////////////////////////////////////////////////////////
218 /// create a Mesh0DElement and add it to the current Mesh
219 /// @return : The created Mesh0DElement
220 ///////////////////////////////////////////////////////////////////////////////
221 SMDS_Mesh0DElement* SMDS_Mesh::Add0DElement(const SMDS_MeshNode * node)
223 return SMDS_Mesh::Add0DElementWithID(node, myElementIDFactory->GetFreeID());
226 ///////////////////////////////////////////////////////////////////////////////
227 /// Create a new Mesh0DElement and at it to the mesh
228 /// @param idnode ID of the node
229 /// @param ID ID of the 0D element to create
230 /// @return The created 0D element or NULL if an element with this
231 /// ID already exists or if input node is not found.
232 ///////////////////////////////////////////////////////////////////////////////
233 SMDS_Mesh0DElement* SMDS_Mesh::Add0DElementWithID(const SMDS_MeshNode * n, int ID)
237 //if (my0DElements.Extent() % CHECKMEMORY_INTERVAL == 0) CheckMemory();
238 //MESSAGE("Add0DElementWithID" << ID)
239 SMDS_Mesh0DElement * el0d = new SMDS_Mesh0DElement(n);
240 if (myElementIDFactory->BindID(ID, el0d)) {
241 SMDS_MeshNode *node = const_cast<SMDS_MeshNode*>(n);
242 //node->AddInverseElement(el0d);// --- fait avec BindID
243 adjustmyCellsCapacity(ID);
245 myInfo.myNb0DElements++;
253 ///////////////////////////////////////////////////////////////////////////////
254 /// create a MeshEdge and add it to the current Mesh
255 /// @return : The created MeshEdge
256 ///////////////////////////////////////////////////////////////////////////////
258 SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(int idnode1, int idnode2, int ID)
260 SMDS_MeshNode * node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
261 SMDS_MeshNode * node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
262 if(!node1 || !node2) return NULL;
263 return SMDS_Mesh::AddEdgeWithID(node1, node2, ID);
266 ///////////////////////////////////////////////////////////////////////////////
267 /// create a MeshEdge and add it to the current Mesh
268 /// @return : The created MeshEdge
269 ///////////////////////////////////////////////////////////////////////////////
271 SMDS_MeshEdge* SMDS_Mesh::AddEdge(const SMDS_MeshNode * node1,
272 const SMDS_MeshNode * node2)
274 return SMDS_Mesh::AddEdgeWithID(node1, node2, myElementIDFactory->GetFreeID());
277 ///////////////////////////////////////////////////////////////////////////////
278 /// Create a new edge and at it to the mesh
279 /// @param idnode1 ID of the first node
280 /// @param idnode2 ID of the second node
281 /// @param ID ID of the edge to create
282 /// @return The created edge or NULL if an element with this ID already exists or
283 /// if input nodes are not found.
284 ///////////////////////////////////////////////////////////////////////////////
286 SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
287 const SMDS_MeshNode * n2,
290 if ( !n1 || !n2 ) return 0;
292 //if ( myEdges.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
293 //MESSAGE("AddEdgeWithID " << ID)
294 SMDS_MeshEdge * edge=new SMDS_MeshEdge(n1,n2);
295 adjustmyCellsCapacity(ID);
299 if (edge && !registerElement(ID, edge))
301 RemoveElement(edge, false);
307 ///////////////////////////////////////////////////////////////////////////////
308 /// Add a triangle defined by its nodes. An ID is automatically affected to the
310 ///////////////////////////////////////////////////////////////////////////////
312 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
313 const SMDS_MeshNode * n2,
314 const SMDS_MeshNode * n3)
316 return SMDS_Mesh::AddFaceWithID(n1,n2,n3, myElementIDFactory->GetFreeID());
319 ///////////////////////////////////////////////////////////////////////////////
320 /// Add a triangle defined by its nodes IDs
321 ///////////////////////////////////////////////////////////////////////////////
323 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int idnode1, int idnode2, int idnode3, int ID)
325 SMDS_MeshNode * node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
326 SMDS_MeshNode * node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
327 SMDS_MeshNode * node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
328 if(!node1 || !node2 || !node3) return NULL;
329 return SMDS_Mesh::AddFaceWithID(node1, node2, node3, ID);
332 ///////////////////////////////////////////////////////////////////////////////
333 /// Add a triangle defined by its nodes
334 ///////////////////////////////////////////////////////////////////////////////
336 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
337 const SMDS_MeshNode * n2,
338 const SMDS_MeshNode * n3,
341 //MESSAGE("AddFaceWithID " << ID)
342 SMDS_MeshFace * face=createTriangle(n1, n2, n3);
344 if (face && !registerElement(ID, face)) {
345 RemoveElement(face, false);
351 ///////////////////////////////////////////////////////////////////////////////
352 /// Add a quadrangle defined by its nodes. An ID is automatically affected to the
354 ///////////////////////////////////////////////////////////////////////////////
356 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
357 const SMDS_MeshNode * n2,
358 const SMDS_MeshNode * n3,
359 const SMDS_MeshNode * n4)
361 return SMDS_Mesh::AddFaceWithID(n1,n2,n3, n4, myElementIDFactory->GetFreeID());
364 ///////////////////////////////////////////////////////////////////////////////
365 /// Add a quadrangle defined by its nodes IDs
366 ///////////////////////////////////////////////////////////////////////////////
368 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int idnode1,
374 SMDS_MeshNode *node1, *node2, *node3, *node4;
375 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
376 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
377 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
378 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
379 if(!node1 || !node2 || !node3 || !node4) return NULL;
380 return SMDS_Mesh::AddFaceWithID(node1, node2, node3, node4, ID);
383 ///////////////////////////////////////////////////////////////////////////////
384 /// Add a quadrangle defined by its nodes
385 ///////////////////////////////////////////////////////////////////////////////
387 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
388 const SMDS_MeshNode * n2,
389 const SMDS_MeshNode * n3,
390 const SMDS_MeshNode * n4,
393 //MESSAGE("AddFaceWithID " << ID);
394 SMDS_MeshFace * face=createQuadrangle(n1, n2, n3, n4, ID);
396 if (face && !registerElement(ID, face)) {
397 RemoveElement(face, false);
403 ///////////////////////////////////////////////////////////////////////////////
404 /// Add a triangle defined by its edges. An ID is automatically assigned to the
406 ///////////////////////////////////////////////////////////////////////////////
408 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshEdge * e1,
409 const SMDS_MeshEdge * e2,
410 const SMDS_MeshEdge * e3)
412 if (!hasConstructionEdges())
414 //MESSAGE("AddFaceWithID");
415 return AddFaceWithID(e1,e2,e3, myElementIDFactory->GetFreeID());
418 ///////////////////////////////////////////////////////////////////////////////
419 /// Add a triangle defined by its edges
420 ///////////////////////////////////////////////////////////////////////////////
422 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshEdge * e1,
423 const SMDS_MeshEdge * e2,
424 const SMDS_MeshEdge * e3,
427 if (!hasConstructionEdges())
429 if ( !e1 || !e2 || !e3 ) return 0;
431 //if ( myFaces.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
432 //MESSAGE("AddFaceWithID" << ID);
434 SMDS_MeshFace * face = new SMDS_FaceOfEdges(e1,e2,e3);
435 adjustmyCellsCapacity(ID);
437 myInfo.myNbTriangles++;
439 if (!registerElement(ID, face)) {
440 RemoveElement(face, false);
446 ///////////////////////////////////////////////////////////////////////////////
447 /// Add a quadrangle defined by its edges. An ID is automatically assigned to the
449 ///////////////////////////////////////////////////////////////////////////////
451 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshEdge * e1,
452 const SMDS_MeshEdge * e2,
453 const SMDS_MeshEdge * e3,
454 const SMDS_MeshEdge * e4)
456 if (!hasConstructionEdges())
458 //MESSAGE("AddFaceWithID" );
459 return AddFaceWithID(e1,e2,e3,e4, myElementIDFactory->GetFreeID());
462 ///////////////////////////////////////////////////////////////////////////////
463 /// Add a quadrangle defined by its edges
464 ///////////////////////////////////////////////////////////////////////////////
466 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshEdge * e1,
467 const SMDS_MeshEdge * e2,
468 const SMDS_MeshEdge * e3,
469 const SMDS_MeshEdge * e4,
472 if (!hasConstructionEdges())
474 //MESSAGE("AddFaceWithID" << ID);
475 if ( !e1 || !e2 || !e3 || !e4 ) return 0;
476 //if ( myFaces.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
477 SMDS_MeshFace * face = new SMDS_FaceOfEdges(e1,e2,e3,e4);
478 adjustmyCellsCapacity(ID);
480 myInfo.myNbQuadrangles++;
482 if (!registerElement(ID, face))
484 RemoveElement(face, false);
490 ///////////////////////////////////////////////////////////////////////////////
491 ///Create a new tetrahedron and add it to the mesh.
492 ///@return The created tetrahedron
493 ///////////////////////////////////////////////////////////////////////////////
495 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
496 const SMDS_MeshNode * n2,
497 const SMDS_MeshNode * n3,
498 const SMDS_MeshNode * n4)
500 int ID = myElementIDFactory->GetFreeID();
501 //MESSAGE("AddVolumeWithID " << ID);
502 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, ID);
503 if(v==NULL) myElementIDFactory->ReleaseID(ID);
507 ///////////////////////////////////////////////////////////////////////////////
508 ///Create a new tetrahedron and add it to the mesh.
509 ///@param ID The ID of the new volume
510 ///@return The created tetrahedron or NULL if an element with this ID already exists
511 ///or if input nodes are not found.
512 ///////////////////////////////////////////////////////////////////////////////
514 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
520 //MESSAGE("AddVolumeWithID" << ID);
521 SMDS_MeshNode *node1, *node2, *node3, *node4;
522 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
523 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
524 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
525 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
526 if(!node1 || !node2 || !node3 || !node4) return NULL;
527 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, ID);
530 ///////////////////////////////////////////////////////////////////////////////
531 ///Create a new tetrahedron and add it to the mesh.
532 ///@param ID The ID of the new volume
533 ///@return The created tetrahedron
534 ///////////////////////////////////////////////////////////////////////////////
536 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
537 const SMDS_MeshNode * n2,
538 const SMDS_MeshNode * n3,
539 const SMDS_MeshNode * n4,
542 //MESSAGE("AddVolumeWithID " << ID);
543 SMDS_MeshVolume* volume = 0;
544 if ( !n1 || !n2 || !n3 || !n4) return volume;
545 //if ( myVolumes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
546 if(hasConstructionFaces()) {
547 SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3);
548 SMDS_MeshFace * f2=FindFaceOrCreate(n1,n2,n4);
549 SMDS_MeshFace * f3=FindFaceOrCreate(n1,n3,n4);
550 SMDS_MeshFace * f4=FindFaceOrCreate(n2,n3,n4);
551 volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4);
552 adjustmyCellsCapacity(ID);
553 myCells[ID] = volume;
556 else if(hasConstructionEdges()) {
557 MESSAGE("Error : Not implemented");
561 volume=new SMDS_VolumeOfNodes(n1,n2,n3,n4);
562 adjustmyCellsCapacity(ID);
563 myCells[ID] = volume;
567 if (!registerElement(ID, volume)) {
568 RemoveElement(volume, false);
574 ///////////////////////////////////////////////////////////////////////////////
575 ///Create a new pyramid and add it to the mesh.
576 ///Nodes 1,2,3 and 4 define the base of the pyramid
577 ///@return The created pyramid
578 ///////////////////////////////////////////////////////////////////////////////
580 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
581 const SMDS_MeshNode * n2,
582 const SMDS_MeshNode * n3,
583 const SMDS_MeshNode * n4,
584 const SMDS_MeshNode * n5)
586 int ID = myElementIDFactory->GetFreeID();
587 //MESSAGE("AddVolumeWithID " << ID);
588 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, ID);
589 if(v==NULL) myElementIDFactory->ReleaseID(ID);
593 ///////////////////////////////////////////////////////////////////////////////
594 ///Create a new pyramid and add it to the mesh.
595 ///Nodes 1,2,3 and 4 define the base of the pyramid
596 ///@param ID The ID of the new volume
597 ///@return The created pyramid or NULL if an element with this ID already exists
598 ///or if input nodes are not found.
599 ///////////////////////////////////////////////////////////////////////////////
601 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
608 //MESSAGE("AddVolumeWithID " << ID);
609 SMDS_MeshNode *node1, *node2, *node3, *node4, *node5;
610 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
611 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
612 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
613 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
614 node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5);
615 if(!node1 || !node2 || !node3 || !node4 || !node5) return NULL;
616 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, ID);
619 ///////////////////////////////////////////////////////////////////////////////
620 ///Create a new pyramid and add it to the mesh.
621 ///Nodes 1,2,3 and 4 define the base of the pyramid
622 ///@param ID The ID of the new volume
623 ///@return The created pyramid
624 ///////////////////////////////////////////////////////////////////////////////
626 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
627 const SMDS_MeshNode * n2,
628 const SMDS_MeshNode * n3,
629 const SMDS_MeshNode * n4,
630 const SMDS_MeshNode * n5,
633 //MESSAGE("AddVolumeWithID " << ID);
634 SMDS_MeshVolume* volume = 0;
635 if ( !n1 || !n2 || !n3 || !n4 || !n5) return volume;
636 //if ( myVolumes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
637 if(hasConstructionFaces()) {
638 SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3,n4);
639 SMDS_MeshFace * f2=FindFaceOrCreate(n1,n2,n5);
640 SMDS_MeshFace * f3=FindFaceOrCreate(n2,n3,n5);
641 SMDS_MeshFace * f4=FindFaceOrCreate(n3,n4,n5);
642 volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4);
643 adjustmyCellsCapacity(ID);
644 myCells[ID] = volume;
645 myInfo.myNbPyramids++;
647 else if(hasConstructionEdges()) {
648 MESSAGE("Error : Not implemented");
652 volume=new SMDS_VolumeOfNodes(n1,n2,n3,n4,n5);
653 adjustmyCellsCapacity(ID);
654 myCells[ID] = volume;
655 myInfo.myNbPyramids++;
658 if (!registerElement(ID, volume)) {
659 RemoveElement(volume, false);
665 ///////////////////////////////////////////////////////////////////////////////
666 ///Create a new prism and add it to the mesh.
667 ///Nodes 1,2,3 is a triangle and 1,2,5,4 a quadrangle.
668 ///@return The created prism
669 ///////////////////////////////////////////////////////////////////////////////
671 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
672 const SMDS_MeshNode * n2,
673 const SMDS_MeshNode * n3,
674 const SMDS_MeshNode * n4,
675 const SMDS_MeshNode * n5,
676 const SMDS_MeshNode * n6)
678 int ID = myElementIDFactory->GetFreeID();
679 //MESSAGE("AddVolumeWithID " << ID);
680 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, ID);
681 if(v==NULL) myElementIDFactory->ReleaseID(ID);
685 ///////////////////////////////////////////////////////////////////////////////
686 ///Create a new prism and add it to the mesh.
687 ///Nodes 1,2,3 is a triangle and 1,2,5,4 a quadrangle.
688 ///@param ID The ID of the new volume
689 ///@return The created prism or NULL if an element with this ID already exists
690 ///or if input nodes are not found.
691 ///////////////////////////////////////////////////////////////////////////////
693 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
701 //MESSAGE("AddVolumeWithID " << ID);
702 SMDS_MeshNode *node1, *node2, *node3, *node4, *node5, *node6;
703 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
704 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
705 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
706 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
707 node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5);
708 node6 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode6);
709 if(!node1 || !node2 || !node3 || !node4 || !node5 || !node6) return NULL;
710 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, node6, ID);
713 ///////////////////////////////////////////////////////////////////////////////
714 ///Create a new prism and add it to the mesh.
715 ///Nodes 1,2,3 is a triangle and 1,2,5,4 a quadrangle.
716 ///@param ID The ID of the new volume
717 ///@return The created prism
718 ///////////////////////////////////////////////////////////////////////////////
720 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
721 const SMDS_MeshNode * n2,
722 const SMDS_MeshNode * n3,
723 const SMDS_MeshNode * n4,
724 const SMDS_MeshNode * n5,
725 const SMDS_MeshNode * n6,
728 //MESSAGE("AddVolumeWithID " << ID);
729 SMDS_MeshVolume* volume = 0;
730 if ( !n1 || !n2 || !n3 || !n4 || !n5 || !n6) return volume;
731 //if ( myVolumes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
732 if(hasConstructionFaces()) {
733 SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3);
734 SMDS_MeshFace * f2=FindFaceOrCreate(n4,n5,n6);
735 SMDS_MeshFace * f3=FindFaceOrCreate(n1,n4,n5,n2);
736 SMDS_MeshFace * f4=FindFaceOrCreate(n2,n5,n6,n3);
737 SMDS_MeshFace * f5=FindFaceOrCreate(n3,n6,n4,n1);
738 volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5);
739 adjustmyCellsCapacity(ID);
740 myCells[ID] = volume;
743 else if(hasConstructionEdges()) {
744 MESSAGE("Error : Not implemented");
748 volume=new SMDS_VolumeOfNodes(n1,n2,n3,n4,n5,n6);
749 adjustmyCellsCapacity(ID);
750 myCells[ID] = volume;
754 if (!registerElement(ID, volume)) {
755 RemoveElement(volume, false);
761 ///////////////////////////////////////////////////////////////////////////////
762 ///Create a new hexahedron and add it to the mesh.
763 ///Nodes 1,2,3,4 and 5,6,7,8 are quadrangle and 5,1 and 7,3 are an edges.
764 ///@return The created hexahedron
765 ///////////////////////////////////////////////////////////////////////////////
767 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
768 const SMDS_MeshNode * n2,
769 const SMDS_MeshNode * n3,
770 const SMDS_MeshNode * n4,
771 const SMDS_MeshNode * n5,
772 const SMDS_MeshNode * n6,
773 const SMDS_MeshNode * n7,
774 const SMDS_MeshNode * n8)
776 int ID = myElementIDFactory->GetFreeID();
777 //MESSAGE("AddVolumeWithID " << ID);
778 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, ID);
779 if(v==NULL) myElementIDFactory->ReleaseID(ID);
783 ///////////////////////////////////////////////////////////////////////////////
784 ///Create a new hexahedron and add it to the mesh.
785 ///Nodes 1,2,3,4 and 5,6,7,8 are quadrangle and 5,1 and 7,3 are an edges.
786 ///@param ID The ID of the new volume
787 ///@return The created hexahedron or NULL if an element with this ID already
788 ///exists or if input nodes are not found.
789 ///////////////////////////////////////////////////////////////////////////////
791 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
801 //MESSAGE("AddVolumeWithID " << ID);
802 SMDS_MeshNode *node1, *node2, *node3, *node4, *node5, *node6, *node7, *node8;
803 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
804 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
805 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
806 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
807 node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5);
808 node6 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode6);
809 node7 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode7);
810 node8 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode8);
811 if(!node1 || !node2 || !node3 || !node4 || !node5 || !node6 || !node7 || !node8)
813 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, node6,
817 ///////////////////////////////////////////////////////////////////////////////
818 ///Create a new hexahedron and add it to the mesh.
819 ///Nodes 1,2,3,4 and 5,6,7,8 are quadrangle and 5,1 and 7,3 are an edges.
820 ///@param ID The ID of the new volume
821 ///@return The created prism or NULL if an element with this ID already exists
822 ///or if input nodes are not found.
823 ///////////////////////////////////////////////////////////////////////////////
825 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
826 const SMDS_MeshNode * n2,
827 const SMDS_MeshNode * n3,
828 const SMDS_MeshNode * n4,
829 const SMDS_MeshNode * n5,
830 const SMDS_MeshNode * n6,
831 const SMDS_MeshNode * n7,
832 const SMDS_MeshNode * n8,
835 //MESSAGE("AddVolumeWithID " << ID);
836 SMDS_MeshVolume* volume = 0;
837 if ( !n1 || !n2 || !n3 || !n4 || !n5 || !n6 || !n7 || !n8) return volume;
838 //if ( myVolumes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
839 if(hasConstructionFaces()) {
840 SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3,n4);
841 SMDS_MeshFace * f2=FindFaceOrCreate(n5,n6,n7,n8);
842 SMDS_MeshFace * f3=FindFaceOrCreate(n1,n4,n8,n5);
843 SMDS_MeshFace * f4=FindFaceOrCreate(n1,n2,n6,n5);
844 SMDS_MeshFace * f5=FindFaceOrCreate(n2,n3,n7,n6);
845 SMDS_MeshFace * f6=FindFaceOrCreate(n3,n4,n8,n7);
846 volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5,f6);
847 adjustmyCellsCapacity(ID);
848 myCells[ID] = volume;
851 else if(hasConstructionEdges()) {
852 MESSAGE("Error : Not implemented");
856 // --- retreive nodes ID
857 vector<vtkIdType> nodeIds;
859 nodeIds.push_back(n1->getId());
860 nodeIds.push_back(n2->getId());
861 nodeIds.push_back(n3->getId());
862 nodeIds.push_back(n4->getId());
863 nodeIds.push_back(n5->getId());
864 nodeIds.push_back(n6->getId());
865 nodeIds.push_back(n7->getId());
866 nodeIds.push_back(n8->getId());
868 //volume = new SMDS_VolumeVtkNodes(nodeIds, this);
869 SMDS_VolumeVtkNodes *volvtk = myVolumePool->getNew();
870 volvtk->init(nodeIds, this);
872 adjustmyCellsCapacity(ID);
873 myCells[ID] = volume;
877 if (!registerElement(ID, volume)) {
878 RemoveElement(volume, false);
884 ///////////////////////////////////////////////////////////////////////////////
885 ///Create a new tetrahedron defined by its faces and add it to the mesh.
886 ///@return The created tetrahedron
887 ///////////////////////////////////////////////////////////////////////////////
889 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshFace * f1,
890 const SMDS_MeshFace * f2,
891 const SMDS_MeshFace * f3,
892 const SMDS_MeshFace * f4)
894 //MESSAGE("AddVolumeWithID");
895 if (!hasConstructionFaces())
897 return AddVolumeWithID(f1,f2,f3,f4, myElementIDFactory->GetFreeID());
900 ///////////////////////////////////////////////////////////////////////////////
901 ///Create a new tetrahedron defined by its faces and add it to the mesh.
902 ///@param ID The ID of the new volume
903 ///@return The created tetrahedron
904 ///////////////////////////////////////////////////////////////////////////////
906 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1,
907 const SMDS_MeshFace * f2,
908 const SMDS_MeshFace * f3,
909 const SMDS_MeshFace * f4,
912 //MESSAGE("AddVolumeWithID" << ID);
913 if (!hasConstructionFaces())
915 if ( !f1 || !f2 || !f3 || !f4) return 0;
916 //if ( myVolumes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
917 SMDS_MeshVolume * volume = new SMDS_VolumeOfFaces(f1,f2,f3,f4);
918 adjustmyCellsCapacity(ID);
919 myCells[ID] = volume;
922 if (!registerElement(ID, volume)) {
923 RemoveElement(volume, false);
929 ///////////////////////////////////////////////////////////////////////////////
930 ///Create a new pyramid defined by its faces and add it to the mesh.
931 ///@return The created pyramid
932 ///////////////////////////////////////////////////////////////////////////////
934 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshFace * f1,
935 const SMDS_MeshFace * f2,
936 const SMDS_MeshFace * f3,
937 const SMDS_MeshFace * f4,
938 const SMDS_MeshFace * f5)
940 //MESSAGE("AddVolumeWithID");
941 if (!hasConstructionFaces())
943 return AddVolumeWithID(f1,f2,f3,f4,f5, myElementIDFactory->GetFreeID());
946 ///////////////////////////////////////////////////////////////////////////////
947 ///Create a new pyramid defined by its faces and add it to the mesh.
948 ///@param ID The ID of the new volume
949 ///@return The created pyramid
950 ///////////////////////////////////////////////////////////////////////////////
952 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1,
953 const SMDS_MeshFace * f2,
954 const SMDS_MeshFace * f3,
955 const SMDS_MeshFace * f4,
956 const SMDS_MeshFace * f5,
959 //MESSAGE("AddVolumeWithID" << ID);
960 if (!hasConstructionFaces())
962 if ( !f1 || !f2 || !f3 || !f4 || !f5) return 0;
963 //if ( myVolumes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
964 SMDS_MeshVolume * volume = new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5);
965 adjustmyCellsCapacity(ID);
966 myCells[ID] = volume;
967 myInfo.myNbPyramids++;
969 if (!registerElement(ID, volume)) {
970 RemoveElement(volume, false);
976 ///////////////////////////////////////////////////////////////////////////////
977 ///Create a new prism defined by its faces and add it to the mesh.
978 ///@return The created prism
979 ///////////////////////////////////////////////////////////////////////////////
981 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshFace * f1,
982 const SMDS_MeshFace * f2,
983 const SMDS_MeshFace * f3,
984 const SMDS_MeshFace * f4,
985 const SMDS_MeshFace * f5,
986 const SMDS_MeshFace * f6)
988 //MESSAGE("AddVolumeWithID" );
989 if (!hasConstructionFaces())
991 return AddVolumeWithID(f1,f2,f3,f4,f5,f6, myElementIDFactory->GetFreeID());
994 ///////////////////////////////////////////////////////////////////////////////
995 ///Create a new prism defined by its faces and add it to the mesh.
996 ///@param ID The ID of the new volume
997 ///@return The created prism
998 ///////////////////////////////////////////////////////////////////////////////
1000 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1,
1001 const SMDS_MeshFace * f2,
1002 const SMDS_MeshFace * f3,
1003 const SMDS_MeshFace * f4,
1004 const SMDS_MeshFace * f5,
1005 const SMDS_MeshFace * f6,
1008 //MESSAGE("AddVolumeWithID" << ID);
1009 if (!hasConstructionFaces())
1011 if ( !f1 || !f2 || !f3 || !f4 || !f5 || !f6) return 0;
1012 //if ( myVolumes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1013 SMDS_MeshVolume * volume = new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5,f6);
1014 adjustmyCellsCapacity(ID);
1015 myCells[ID] = volume;
1016 myInfo.myNbPrisms++;
1018 if (!registerElement(ID, volume)) {
1019 RemoveElement(volume, false);
1025 ///////////////////////////////////////////////////////////////////////////////
1026 /// Add a polygon defined by its nodes IDs
1027 ///////////////////////////////////////////////////////////////////////////////
1029 SMDS_MeshFace* SMDS_Mesh::AddPolygonalFaceWithID (std::vector<int> nodes_ids,
1032 int nbNodes = nodes_ids.size();
1033 std::vector<const SMDS_MeshNode*> nodes (nbNodes);
1034 for (int i = 0; i < nbNodes; i++) {
1035 nodes[i] = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nodes_ids[i]);
1036 if (!nodes[i]) return NULL;
1038 return SMDS_Mesh::AddPolygonalFaceWithID(nodes, ID);
1041 ///////////////////////////////////////////////////////////////////////////////
1042 /// Add a polygon defined by its nodes
1043 ///////////////////////////////////////////////////////////////////////////////
1045 SMDS_MeshFace* SMDS_Mesh::AddPolygonalFaceWithID
1046 (std::vector<const SMDS_MeshNode*> nodes,
1049 SMDS_MeshFace * face;
1051 //if ( myFaces.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1052 if (hasConstructionEdges())
1054 MESSAGE("Error : Not implemented");
1059 for ( int i = 0; i < nodes.size(); ++i )
1060 if ( !nodes[ i ] ) return 0;
1061 face = new SMDS_PolygonalFaceOfNodes(nodes);
1062 adjustmyCellsCapacity(ID);
1064 myInfo.myNbPolygons++;
1067 if (!registerElement(ID, face)) {
1068 RemoveElement(face, false);
1074 ///////////////////////////////////////////////////////////////////////////////
1075 /// Add a polygon defined by its nodes.
1076 /// An ID is automatically affected to the created face.
1077 ///////////////////////////////////////////////////////////////////////////////
1079 SMDS_MeshFace* SMDS_Mesh::AddPolygonalFace (std::vector<const SMDS_MeshNode*> nodes)
1081 return SMDS_Mesh::AddPolygonalFaceWithID(nodes, myElementIDFactory->GetFreeID());
1084 ///////////////////////////////////////////////////////////////////////////////
1085 /// Create a new polyhedral volume and add it to the mesh.
1086 /// @param ID The ID of the new volume
1087 /// @return The created volume or NULL if an element with this ID already exists
1088 /// or if input nodes are not found.
1089 ///////////////////////////////////////////////////////////////////////////////
1091 SMDS_MeshVolume * SMDS_Mesh::AddPolyhedralVolumeWithID
1092 (std::vector<int> nodes_ids,
1093 std::vector<int> quantities,
1096 int nbNodes = nodes_ids.size();
1097 std::vector<const SMDS_MeshNode*> nodes (nbNodes);
1098 for (int i = 0; i < nbNodes; i++) {
1099 nodes[i] = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nodes_ids[i]);
1100 if (!nodes[i]) return NULL;
1102 return SMDS_Mesh::AddPolyhedralVolumeWithID(nodes, quantities, ID);
1105 ///////////////////////////////////////////////////////////////////////////////
1106 /// Create a new polyhedral volume and add it to the mesh.
1107 /// @param ID The ID of the new volume
1108 /// @return The created volume
1109 ///////////////////////////////////////////////////////////////////////////////
1111 SMDS_MeshVolume* SMDS_Mesh::AddPolyhedralVolumeWithID
1112 (std::vector<const SMDS_MeshNode*> nodes,
1113 std::vector<int> quantities,
1116 SMDS_MeshVolume* volume;
1117 //if ( myVolumes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1118 if (hasConstructionFaces()) {
1119 MESSAGE("Error : Not implemented");
1121 } else if (hasConstructionEdges()) {
1122 MESSAGE("Error : Not implemented");
1125 for ( int i = 0; i < nodes.size(); ++i )
1126 if ( !nodes[ i ] ) return 0;
1127 volume = new SMDS_PolyhedralVolumeOfNodes(nodes, quantities);
1128 adjustmyCellsCapacity(ID);
1129 myCells[ID] = volume;
1130 myInfo.myNbPolyhedrons++;
1133 if (!registerElement(ID, volume)) {
1134 RemoveElement(volume, false);
1140 ///////////////////////////////////////////////////////////////////////////////
1141 /// Create a new polyhedral volume and add it to the mesh.
1142 /// @return The created volume
1143 ///////////////////////////////////////////////////////////////////////////////
1145 SMDS_MeshVolume* SMDS_Mesh::AddPolyhedralVolume
1146 (std::vector<const SMDS_MeshNode*> nodes,
1147 std::vector<int> quantities)
1149 int ID = myElementIDFactory->GetFreeID();
1150 SMDS_MeshVolume * v = SMDS_Mesh::AddPolyhedralVolumeWithID(nodes, quantities, ID);
1151 if (v == NULL) myElementIDFactory->ReleaseID(ID);
1155 ///////////////////////////////////////////////////////////////////////////////
1156 /// Registers element with the given ID, maintains inverse connections
1157 ///////////////////////////////////////////////////////////////////////////////
1158 bool SMDS_Mesh::registerElement(int ID, SMDS_MeshElement* element)
1160 //MESSAGE("registerElement " << ID)
1161 if ((ID < myIDElements.size()) && myIDElements[ID] >= 0) // --- already bound
1163 MESSAGE(" --------------------------------- already bound "<< ID << " " << myIDElements[ID]);
1168 element->myMeshId = myMeshId;
1170 SMDS_MeshCell *cell = dynamic_cast<SMDS_MeshCell*>(element);
1172 int vtkId = cell->getVtkId();
1174 vtkId = myElementIDFactory->SetInVtkGrid(element);
1176 if (ID >= myIDElements.size()) // --- resize local vector
1178 MESSAGE(" ------------------- resize myIDElements " << ID << " --> " << ID + SMDS_Mesh::chunkSize);
1179 myIDElements.resize(ID + SMDS_Mesh::chunkSize, -1); // fill new elements with -1
1182 myIDElements[ID] = vtkId;
1183 //MESSAGE("smds:" << ID << " vtk:" << cellId );
1185 if (vtkId >= myVtkIndex.size()) // --- resize local vector
1187 MESSAGE(" --------------------- resize myVtkIndex " << vtkId << " --> " << vtkId + SMDS_Mesh::chunkSize);
1188 myVtkIndex.resize(vtkId + SMDS_Mesh::chunkSize, -1);
1190 myVtkIndex[vtkId] = ID;
1192 myElementIDFactory->updateMinMax(ID);
1196 ///////////////////////////////////////////////////////////////////////////////
1197 /// Return the node whose ID is 'ID'.
1198 ///////////////////////////////////////////////////////////////////////////////
1199 const SMDS_MeshNode * SMDS_Mesh::FindNode(int ID) const
1201 if (ID <0 || ID >= myNodes.size())
1203 return (const SMDS_MeshNode *)myNodes[ID];
1206 ///////////////////////////////////////////////////////////////////////////////
1207 ///Create a triangle and add it to the current mesh. This methode do not bind a
1208 ///ID to the create triangle.
1209 ///////////////////////////////////////////////////////////////////////////////
1210 SMDS_MeshFace * SMDS_Mesh::createTriangle(const SMDS_MeshNode * node1,
1211 const SMDS_MeshNode * node2,
1212 const SMDS_MeshNode * node3)
1214 if ( !node1 || !node2 || !node3) return 0;
1215 // if ( myFaces.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1216 if(hasConstructionEdges())
1218 SMDS_MeshEdge *edge1, *edge2, *edge3;
1219 edge1=FindEdgeOrCreate(node1,node2);
1220 edge2=FindEdgeOrCreate(node2,node3);
1221 edge3=FindEdgeOrCreate(node3,node1);
1223 int ID = myElementIDFactory->GetFreeID(); // -PR- voir si on range cet element
1224 SMDS_MeshFace * face = new SMDS_FaceOfEdges(edge1,edge2,edge3);
1225 adjustmyCellsCapacity(ID);
1227 myInfo.myNbTriangles++;
1232 int ID = myElementIDFactory->GetFreeID(); // -PR- voir si on range cet element
1233 SMDS_MeshFace * face = new SMDS_FaceOfNodes(node1,node2,node3);
1234 adjustmyCellsCapacity(ID);
1236 myInfo.myNbTriangles++;
1241 ///////////////////////////////////////////////////////////////////////////////
1242 ///Create a quadrangle and add it to the current mesh. This methode do not bind
1243 ///a ID to the create triangle.
1244 ///////////////////////////////////////////////////////////////////////////////
1245 SMDS_MeshFace * SMDS_Mesh::createQuadrangle(const SMDS_MeshNode * node1,
1246 const SMDS_MeshNode * node2,
1247 const SMDS_MeshNode * node3,
1248 const SMDS_MeshNode * node4,
1251 if ( !node1 || !node2 || !node3 || !node4 ) return 0;
1252 // if ( myFaces.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1253 if(hasConstructionEdges())
1255 //MESSAGE("createQuadrangle hasConstructionEdges "<< ID);
1256 SMDS_MeshEdge *edge1, *edge2, *edge3, *edge4;
1257 edge1=FindEdgeOrCreate(node1,node2);
1258 edge2=FindEdgeOrCreate(node2,node3);
1259 edge3=FindEdgeOrCreate(node3,node4);
1260 edge4=FindEdgeOrCreate(node4,node1);
1262 SMDS_MeshFace * face = new SMDS_FaceOfEdges(edge1,edge2,edge3,edge4);
1263 adjustmyCellsCapacity(ID);
1265 myInfo.myNbQuadrangles++;
1270 //MESSAGE("createQuadrangle " << ID);
1271 SMDS_MeshFace * face = new SMDS_FaceOfNodes(node1,node2,node3,node4);
1272 adjustmyCellsCapacity(ID);
1274 myInfo.myNbQuadrangles++;
1279 ///////////////////////////////////////////////////////////////////////////////
1280 /// Remove a node and all the elements which own this node
1281 ///////////////////////////////////////////////////////////////////////////////
1283 void SMDS_Mesh::RemoveNode(const SMDS_MeshNode * node)
1285 MESSAGE("RemoveNode");
1286 RemoveElement(node, true);
1289 ///////////////////////////////////////////////////////////////////////////////
1290 /// Remove an edge and all the elements which own this edge
1291 ///////////////////////////////////////////////////////////////////////////////
1293 void SMDS_Mesh::Remove0DElement(const SMDS_Mesh0DElement * elem0d)
1295 MESSAGE("Remove0DElement");
1296 RemoveElement(elem0d,true);
1299 ///////////////////////////////////////////////////////////////////////////////
1300 /// Remove an edge and all the elements which own this edge
1301 ///////////////////////////////////////////////////////////////////////////////
1303 void SMDS_Mesh::RemoveEdge(const SMDS_MeshEdge * edge)
1305 MESSAGE("RemoveEdge");
1306 RemoveElement(edge,true);
1309 ///////////////////////////////////////////////////////////////////////////////
1310 /// Remove an face and all the elements which own this face
1311 ///////////////////////////////////////////////////////////////////////////////
1313 void SMDS_Mesh::RemoveFace(const SMDS_MeshFace * face)
1315 MESSAGE("RemoveFace");
1316 RemoveElement(face, true);
1319 ///////////////////////////////////////////////////////////////////////////////
1321 ///////////////////////////////////////////////////////////////////////////////
1323 void SMDS_Mesh::RemoveVolume(const SMDS_MeshVolume * volume)
1325 MESSAGE("RemoveVolume");
1326 RemoveElement(volume, true);
1329 //=======================================================================
1330 //function : RemoveFromParent
1332 //=======================================================================
1334 bool SMDS_Mesh::RemoveFromParent()
1336 if (myParent==NULL) return false;
1337 else return (myParent->RemoveSubMesh(this));
1340 //=======================================================================
1341 //function : RemoveSubMesh
1343 //=======================================================================
1345 bool SMDS_Mesh::RemoveSubMesh(const SMDS_Mesh * aMesh)
1349 list<SMDS_Mesh *>::iterator itmsh=myChildren.begin();
1350 for (; itmsh!=myChildren.end() && !found; itmsh++)
1352 SMDS_Mesh * submesh = *itmsh;
1353 if (submesh == aMesh)
1356 myChildren.erase(itmsh);
1363 //=======================================================================
1364 //function : ChangeElementNodes
1366 //=======================================================================
1368 bool SMDS_Mesh::ChangeElementNodes(const SMDS_MeshElement * element,
1369 const SMDS_MeshNode * nodes[],
1372 // keep current nodes of elem
1373 set<const SMDS_MeshElement*> oldNodes;
1374 SMDS_ElemIteratorPtr itn = element->nodesIterator();
1376 oldNodes.insert( itn->next() );
1378 if ( !element->IsPoly() )
1379 myInfo.remove( element ); // element may change type
1383 SMDS_MeshElement* elem = const_cast<SMDS_MeshElement*>(element);
1384 switch ( elem->GetType() )
1386 case SMDSAbs_0DElement: {
1387 if ( SMDS_Mesh0DElement* elem0d = dynamic_cast<SMDS_Mesh0DElement*>( elem ))
1388 Ok = elem0d->ChangeNode( nodes[0] );
1391 case SMDSAbs_Edge: {
1392 if ( nbnodes == 2 ) {
1393 if ( SMDS_MeshEdge* edge = dynamic_cast<SMDS_MeshEdge*>( elem ))
1394 Ok = edge->ChangeNodes( nodes[0], nodes[1] );
1396 else if ( nbnodes == 3 ) {
1397 if ( SMDS_QuadraticEdge* edge = dynamic_cast<SMDS_QuadraticEdge*>( elem ))
1398 Ok = edge->ChangeNodes( nodes[0], nodes[1], nodes[2] );
1402 case SMDSAbs_Face: {
1403 if ( SMDS_FaceOfNodes* face = dynamic_cast<SMDS_FaceOfNodes*>( elem ))
1404 Ok = face->ChangeNodes( nodes, nbnodes );
1406 if ( SMDS_QuadraticFaceOfNodes* QF = dynamic_cast<SMDS_QuadraticFaceOfNodes*>( elem ))
1407 Ok = QF->ChangeNodes( nodes, nbnodes );
1409 if (SMDS_PolygonalFaceOfNodes* face = dynamic_cast<SMDS_PolygonalFaceOfNodes*>(elem))
1410 Ok = face->ChangeNodes(nodes, nbnodes);
1413 case SMDSAbs_Volume: {
1414 if ( SMDS_VolumeOfNodes* vol = dynamic_cast<SMDS_VolumeOfNodes*>( elem ))
1415 Ok = vol->ChangeNodes( nodes, nbnodes );
1417 if ( SMDS_QuadraticVolumeOfNodes* QV = dynamic_cast<SMDS_QuadraticVolumeOfNodes*>( elem ))
1418 Ok = QV->ChangeNodes( nodes, nbnodes );
1422 MESSAGE ( "WRONG ELEM TYPE");
1425 if ( Ok ) { // update InverseElements
1427 set<const SMDS_MeshElement*>::iterator it;
1429 // AddInverseElement to new nodes
1430 for ( int i = 0; i < nbnodes; i++ ) {
1431 it = oldNodes.find( nodes[i] );
1432 if ( it == oldNodes.end() )
1434 const_cast<SMDS_MeshNode*>( nodes[i] )->AddInverseElement( elem );
1436 // remove from oldNodes a node that remains in elem
1437 oldNodes.erase( it );
1439 // RemoveInverseElement from the nodes removed from elem
1440 for ( it = oldNodes.begin(); it != oldNodes.end(); it++ )
1442 SMDS_MeshNode * n = static_cast<SMDS_MeshNode *>
1443 (const_cast<SMDS_MeshElement *>( *it ));
1444 n->RemoveInverseElement( elem );
1448 if ( !element->IsPoly() )
1449 myInfo.add( element ); // element may change type
1454 //=======================================================================
1455 //function : ChangePolyhedronNodes
1456 //purpose : to change nodes of polyhedral volume
1457 //=======================================================================
1458 bool SMDS_Mesh::ChangePolyhedronNodes (const SMDS_MeshElement * elem,
1459 const vector<const SMDS_MeshNode*>& nodes,
1460 const vector<int> & quantities)
1462 if (elem->GetType() != SMDSAbs_Volume) {
1463 MESSAGE("WRONG ELEM TYPE");
1467 const SMDS_PolyhedralVolumeOfNodes* vol = dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*>(elem);
1472 // keep current nodes of elem
1473 set<const SMDS_MeshElement*> oldNodes;
1474 SMDS_ElemIteratorPtr itn = elem->nodesIterator();
1475 while (itn->more()) {
1476 oldNodes.insert(itn->next());
1480 bool Ok = const_cast<SMDS_PolyhedralVolumeOfNodes*>(vol)->ChangeNodes(nodes, quantities);
1485 // update InverseElements
1487 // AddInverseElement to new nodes
1488 int nbnodes = nodes.size();
1489 set<const SMDS_MeshElement*>::iterator it;
1490 for (int i = 0; i < nbnodes; i++) {
1491 it = oldNodes.find(nodes[i]);
1492 if (it == oldNodes.end()) {
1494 const_cast<SMDS_MeshNode*>(nodes[i])->AddInverseElement(elem);
1496 // remove from oldNodes a node that remains in elem
1501 // RemoveInverseElement from the nodes removed from elem
1502 for (it = oldNodes.begin(); it != oldNodes.end(); it++) {
1503 SMDS_MeshNode * n = static_cast<SMDS_MeshNode *>
1504 (const_cast<SMDS_MeshElement *>( *it ));
1505 n->RemoveInverseElement(elem);
1512 //=======================================================================
1513 //function : Find0DElement
1515 //=======================================================================
1516 const SMDS_Mesh0DElement* SMDS_Mesh::Find0DElement(int idnode) const
1518 const SMDS_MeshNode * node = FindNode(idnode);
1519 if(node == NULL) return NULL;
1520 return Find0DElement(node);
1523 const SMDS_Mesh0DElement* SMDS_Mesh::Find0DElement(const SMDS_MeshNode * node)
1525 if (!node) return 0;
1526 const SMDS_Mesh0DElement* toReturn = NULL;
1527 SMDS_ElemIteratorPtr it1 = node->GetInverseElementIterator(SMDSAbs_0DElement);
1528 while (it1->more() && (toReturn == NULL)) {
1529 const SMDS_MeshElement* e = it1->next();
1530 if (e->NbNodes() == 1) {
1531 toReturn = static_cast<const SMDS_Mesh0DElement*>(e);
1537 //=======================================================================
1538 //function : Find0DElementOrCreate
1540 //=======================================================================
1541 //SMDS_Mesh0DElement* SMDS_Mesh::Find0DElementOrCreate(const SMDS_MeshNode * node)
1543 // if (!node) return 0;
1544 // SMDS_Mesh0DElement * toReturn = NULL;
1545 // toReturn = const_cast<SMDS_Mesh0DElement*>(Find0DElement(node));
1546 // if (toReturn == NULL) {
1547 // //if (my0DElements.Extent() % CHECKMEMORY_INTERVAL == 0) CheckMemory();
1548 // toReturn = new SMDS_Mesh0DElement(node);
1549 // my0DElements.Add(toReturn);
1550 // myInfo.myNb0DElements++;
1556 //=======================================================================
1557 //function : FindEdge
1559 //=======================================================================
1561 const SMDS_MeshEdge* SMDS_Mesh::FindEdge(int idnode1, int idnode2) const
1563 const SMDS_MeshNode * node1=FindNode(idnode1);
1564 const SMDS_MeshNode * node2=FindNode(idnode2);
1565 if((node1==NULL)||(node2==NULL)) return NULL;
1566 return FindEdge(node1,node2);
1569 //#include "Profiler.h"
1570 const SMDS_MeshEdge* SMDS_Mesh::FindEdge(const SMDS_MeshNode * node1,
1571 const SMDS_MeshNode * node2)
1573 if ( !node1 ) return 0;
1574 const SMDS_MeshEdge * toReturn=NULL;
1577 SMDS_ElemIteratorPtr it1=node1->GetInverseElementIterator(SMDSAbs_Edge);
1580 while(it1->more()) {
1581 const SMDS_MeshElement * e = it1->next();
1582 if ( e->NbNodes() == 2 && e->GetNodeIndex( node2 ) >= 0 ) {
1583 toReturn = static_cast<const SMDS_MeshEdge*>( e );
1592 //=======================================================================
1593 //function : FindEdgeOrCreate
1595 //=======================================================================
1597 SMDS_MeshEdge* SMDS_Mesh::FindEdgeOrCreate(const SMDS_MeshNode * node1,
1598 const SMDS_MeshNode * node2)
1600 if ( !node1 || !node2) return 0;
1601 SMDS_MeshEdge * toReturn=NULL;
1602 toReturn=const_cast<SMDS_MeshEdge*>(FindEdge(node1,node2));
1603 if(toReturn==NULL) {
1604 //if ( myEdges.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1605 int ID = myElementIDFactory->GetFreeID(); // -PR- voir si on range cet element
1606 adjustmyCellsCapacity(ID);
1607 toReturn=new SMDS_MeshEdge(node1,node2);
1608 myCells[ID] = toReturn;
1615 //=======================================================================
1616 //function : FindEdge
1618 //=======================================================================
1620 const SMDS_MeshEdge* SMDS_Mesh::FindEdge(int idnode1, int idnode2,
1623 const SMDS_MeshNode * node1=FindNode(idnode1);
1624 const SMDS_MeshNode * node2=FindNode(idnode2);
1625 const SMDS_MeshNode * node3=FindNode(idnode3);
1626 return FindEdge(node1,node2,node3);
1629 const SMDS_MeshEdge* SMDS_Mesh::FindEdge(const SMDS_MeshNode * node1,
1630 const SMDS_MeshNode * node2,
1631 const SMDS_MeshNode * node3)
1633 if ( !node1 ) return 0;
1634 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Edge);
1635 while(it1->more()) {
1636 const SMDS_MeshElement * e = it1->next();
1637 if ( e->NbNodes() == 3 ) {
1638 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
1639 while(it2->more()) {
1640 const SMDS_MeshElement* n = it2->next();
1650 return static_cast<const SMDS_MeshEdge *> (e);
1657 //=======================================================================
1658 //function : FindFace
1660 //=======================================================================
1662 const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2,
1665 const SMDS_MeshNode * node1=FindNode(idnode1);
1666 const SMDS_MeshNode * node2=FindNode(idnode2);
1667 const SMDS_MeshNode * node3=FindNode(idnode3);
1668 return FindFace(node1, node2, node3);
1671 const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1,
1672 const SMDS_MeshNode *node2,
1673 const SMDS_MeshNode *node3)
1675 if ( !node1 ) return 0;
1676 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Face);
1677 while(it1->more()) {
1678 const SMDS_MeshElement * e = it1->next();
1679 if ( e->NbNodes() == 3 ) {
1680 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
1681 while(it2->more()) {
1682 const SMDS_MeshElement* n = it2->next();
1692 return static_cast<const SMDS_MeshFace *> (e);
1698 SMDS_MeshFace* SMDS_Mesh::FindFaceOrCreate(const SMDS_MeshNode *node1,
1699 const SMDS_MeshNode *node2,
1700 const SMDS_MeshNode *node3)
1702 SMDS_MeshFace * toReturn=NULL;
1703 toReturn = const_cast<SMDS_MeshFace*>(FindFace(node1,node2,node3));
1704 if(toReturn==NULL) {
1705 toReturn = createTriangle(node1,node2,node3);
1711 //=======================================================================
1712 //function : FindFace
1714 //=======================================================================
1716 const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2,
1717 int idnode3, int idnode4) const
1719 const SMDS_MeshNode * node1=FindNode(idnode1);
1720 const SMDS_MeshNode * node2=FindNode(idnode2);
1721 const SMDS_MeshNode * node3=FindNode(idnode3);
1722 const SMDS_MeshNode * node4=FindNode(idnode4);
1723 return FindFace(node1, node2, node3, node4);
1726 const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1,
1727 const SMDS_MeshNode *node2,
1728 const SMDS_MeshNode *node3,
1729 const SMDS_MeshNode *node4)
1731 if ( !node1 ) return 0;
1732 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Face);
1733 while(it1->more()) {
1734 const SMDS_MeshElement * e = it1->next();
1735 if ( e->NbNodes() == 4 ) {
1736 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
1737 while(it2->more()) {
1738 const SMDS_MeshElement* n = it2->next();
1749 return static_cast<const SMDS_MeshFace *> (e);
1755 SMDS_MeshFace* SMDS_Mesh::FindFaceOrCreate(const SMDS_MeshNode *node1,
1756 const SMDS_MeshNode *node2,
1757 const SMDS_MeshNode *node3,
1758 const SMDS_MeshNode *node4)
1760 SMDS_MeshFace * toReturn=NULL;
1761 toReturn=const_cast<SMDS_MeshFace*>(FindFace(node1,node2,node3,node4));
1762 if(toReturn==NULL) {
1763 int ID = myElementIDFactory->GetFreeID();
1764 toReturn=createQuadrangle(node1,node2,node3,node4,ID);
1770 //=======================================================================
1771 //function : FindFace
1772 //purpose :quadratic triangle
1773 //=======================================================================
1775 const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2,
1776 int idnode3, int idnode4,
1777 int idnode5, int idnode6) const
1779 const SMDS_MeshNode * node1 = FindNode(idnode1);
1780 const SMDS_MeshNode * node2 = FindNode(idnode2);
1781 const SMDS_MeshNode * node3 = FindNode(idnode3);
1782 const SMDS_MeshNode * node4 = FindNode(idnode4);
1783 const SMDS_MeshNode * node5 = FindNode(idnode5);
1784 const SMDS_MeshNode * node6 = FindNode(idnode6);
1785 return FindFace(node1, node2, node3, node4, node5, node6);
1788 const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1,
1789 const SMDS_MeshNode *node2,
1790 const SMDS_MeshNode *node3,
1791 const SMDS_MeshNode *node4,
1792 const SMDS_MeshNode *node5,
1793 const SMDS_MeshNode *node6)
1795 if ( !node1 ) return 0;
1796 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Face);
1797 while(it1->more()) {
1798 const SMDS_MeshElement * e = it1->next();
1799 if ( e->NbNodes() == 6 ) {
1800 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
1801 while(it2->more()) {
1802 const SMDS_MeshElement* n = it2->next();
1815 return static_cast<const SMDS_MeshFace *> (e);
1822 //=======================================================================
1823 //function : FindFace
1824 //purpose : quadratic quadrangle
1825 //=======================================================================
1827 const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2,
1828 int idnode3, int idnode4,
1829 int idnode5, int idnode6,
1830 int idnode7, int idnode8) const
1832 const SMDS_MeshNode * node1 = FindNode(idnode1);
1833 const SMDS_MeshNode * node2 = FindNode(idnode2);
1834 const SMDS_MeshNode * node3 = FindNode(idnode3);
1835 const SMDS_MeshNode * node4 = FindNode(idnode4);
1836 const SMDS_MeshNode * node5 = FindNode(idnode5);
1837 const SMDS_MeshNode * node6 = FindNode(idnode6);
1838 const SMDS_MeshNode * node7 = FindNode(idnode7);
1839 const SMDS_MeshNode * node8 = FindNode(idnode8);
1840 return FindFace(node1, node2, node3, node4, node5, node6, node7, node8);
1843 const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1,
1844 const SMDS_MeshNode *node2,
1845 const SMDS_MeshNode *node3,
1846 const SMDS_MeshNode *node4,
1847 const SMDS_MeshNode *node5,
1848 const SMDS_MeshNode *node6,
1849 const SMDS_MeshNode *node7,
1850 const SMDS_MeshNode *node8)
1852 if ( !node1 ) return 0;
1853 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Face);
1854 while(it1->more()) {
1855 const SMDS_MeshElement * e = it1->next();
1856 if ( e->NbNodes() == 8 ) {
1857 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
1858 while(it2->more()) {
1859 const SMDS_MeshElement* n = it2->next();
1874 return static_cast<const SMDS_MeshFace *> (e);
1881 //=======================================================================
1882 //function : FindElement
1884 //=======================================================================
1886 const SMDS_MeshElement* SMDS_Mesh::FindElement(int IDelem) const
1888 if ((IDelem < 0) || IDelem >= myCells.size())
1890 return myCells[IDelem];
1893 //=======================================================================
1894 //function : FindFace
1895 //purpose : find polygon
1896 //=======================================================================
1898 const SMDS_MeshFace* SMDS_Mesh::FindFace (std::vector<int> nodes_ids) const
1900 int nbnodes = nodes_ids.size();
1901 std::vector<const SMDS_MeshNode *> poly_nodes (nbnodes);
1902 for (int inode = 0; inode < nbnodes; inode++) {
1903 const SMDS_MeshNode * node = FindNode(nodes_ids[inode]);
1904 if (node == NULL) return NULL;
1905 poly_nodes[inode] = node;
1907 return FindFace(poly_nodes);
1910 const SMDS_MeshFace* SMDS_Mesh::FindFace (std::vector<const SMDS_MeshNode *> nodes)
1912 if ( nodes.size() > 2 && nodes[0] ) {
1913 SMDS_ElemIteratorPtr itF = nodes[0]->GetInverseElementIterator(SMDSAbs_Face);
1914 while (itF->more()) {
1915 const SMDS_MeshElement* f = itF->next();
1916 if ( f->NbNodes() == nodes.size() ) {
1917 SMDS_ElemIteratorPtr it2 = f->nodesIterator();
1918 while(it2->more()) {
1919 if ( find( nodes.begin(), nodes.end(), it2->next() ) == nodes.end() ) {
1925 return static_cast<const SMDS_MeshFace *> (f);
1932 //=======================================================================
1933 //function : DumpNodes
1935 //=======================================================================
1937 void SMDS_Mesh::DumpNodes() const
1939 MESSAGE("dump nodes of mesh : ");
1940 SMDS_NodeIteratorPtr itnode=nodesIterator();
1941 while(itnode->more()) ; //MESSAGE(itnode->next());
1944 //=======================================================================
1945 //function : Dump0DElements
1947 //=======================================================================
1948 void SMDS_Mesh::Dump0DElements() const
1950 MESSAGE("dump 0D elements of mesh : ");
1951 SMDS_0DElementIteratorPtr it0d = elements0dIterator();
1952 while(it0d->more()) ; //MESSAGE(it0d->next());
1955 //=======================================================================
1956 //function : DumpEdges
1958 //=======================================================================
1960 void SMDS_Mesh::DumpEdges() const
1962 MESSAGE("dump edges of mesh : ");
1963 SMDS_EdgeIteratorPtr itedge=edgesIterator();
1964 while(itedge->more()) ; //MESSAGE(itedge->next());
1967 //=======================================================================
1968 //function : DumpFaces
1970 //=======================================================================
1972 void SMDS_Mesh::DumpFaces() const
1974 MESSAGE("dump faces of mesh : ");
1975 SMDS_FaceIteratorPtr itface=facesIterator();
1976 while(itface->more()) ; //MESSAGE(itface->next());
1979 //=======================================================================
1980 //function : DumpVolumes
1982 //=======================================================================
1984 void SMDS_Mesh::DumpVolumes() const
1986 MESSAGE("dump volumes of mesh : ");
1987 SMDS_VolumeIteratorPtr itvol=volumesIterator();
1988 while(itvol->more()) ; //MESSAGE(itvol->next());
1991 //=======================================================================
1992 //function : DebugStats
1994 //=======================================================================
1996 void SMDS_Mesh::DebugStats() const
1998 MESSAGE("Debug stats of mesh : ");
2000 MESSAGE("===== NODES ====="<<NbNodes());
2001 MESSAGE("===== 0DELEMS ====="<<Nb0DElements());
2002 MESSAGE("===== EDGES ====="<<NbEdges());
2003 MESSAGE("===== FACES ====="<<NbFaces());
2004 MESSAGE("===== VOLUMES ====="<<NbVolumes());
2006 MESSAGE("End Debug stats of mesh ");
2010 SMDS_NodeIteratorPtr itnode=nodesIterator();
2011 int sizeofnodes = 0;
2012 int sizeoffaces = 0;
2014 while(itnode->more())
2016 const SMDS_MeshNode *node = itnode->next();
2018 sizeofnodes += sizeof(*node);
2020 SMDS_ElemIteratorPtr it = node->GetInverseElementIterator();
2023 const SMDS_MeshElement *me = it->next();
2024 sizeofnodes += sizeof(me);
2028 SMDS_FaceIteratorPtr itface=facesIterator();
2029 while(itface->more())
2031 const SMDS_MeshElement *face = itface->next();
2032 sizeoffaces += sizeof(*face);
2035 MESSAGE("total size of node elements = " << sizeofnodes);;
2036 MESSAGE("total size of face elements = " << sizeoffaces);;
2041 ///////////////////////////////////////////////////////////////////////////////
2042 /// Return the number of nodes
2043 ///////////////////////////////////////////////////////////////////////////////
2044 int SMDS_Mesh::NbNodes() const
2046 return myNodes.size();
2049 ///////////////////////////////////////////////////////////////////////////////
2050 /// Return the number of 0D elements
2051 ///////////////////////////////////////////////////////////////////////////////
2052 int SMDS_Mesh::Nb0DElements() const
2054 return myInfo.Nb0DElements(); // -PR- a verfier
2057 ///////////////////////////////////////////////////////////////////////////////
2058 /// Return the number of edges (including construction edges)
2059 ///////////////////////////////////////////////////////////////////////////////
2060 int SMDS_Mesh::NbEdges() const
2062 return myInfo.NbEdges(); // -PR- a verfier
2065 ///////////////////////////////////////////////////////////////////////////////
2066 /// Return the number of faces (including construction faces)
2067 ///////////////////////////////////////////////////////////////////////////////
2068 int SMDS_Mesh::NbFaces() const
2070 return myInfo.NbFaces(); // -PR- a verfier
2073 ///////////////////////////////////////////////////////////////////////////////
2074 /// Return the number of volumes
2075 ///////////////////////////////////////////////////////////////////////////////
2076 int SMDS_Mesh::NbVolumes() const
2078 return myInfo.NbVolumes(); // -PR- a verfier
2081 ///////////////////////////////////////////////////////////////////////////////
2082 /// Return the number of child mesh of this mesh.
2083 /// Note that the tree structure of SMDS_Mesh seems to be unused in this version
2084 /// (2003-09-08) of SMESH
2085 ///////////////////////////////////////////////////////////////////////////////
2086 int SMDS_Mesh::NbSubMesh() const
2088 return myChildren.size();
2091 ///////////////////////////////////////////////////////////////////////////////
2092 /// Destroy the mesh and all its elements
2093 /// All pointer on elements owned by this mesh become illegals.
2094 ///////////////////////////////////////////////////////////////////////////////
2095 SMDS_Mesh::~SMDS_Mesh()
2097 list<SMDS_Mesh*>::iterator itc=myChildren.begin();
2098 while(itc!=myChildren.end())
2106 delete myNodeIDFactory;
2107 delete myElementIDFactory;
2111 SMDS_ElemIteratorPtr eIt = elementsIterator();
2112 while ( eIt->more() )
2113 myElementIDFactory->ReleaseID(eIt->next()->GetID());
2114 SMDS_NodeIteratorPtr itn = nodesIterator();
2116 myNodeIDFactory->ReleaseID(itn->next()->GetID());
2119 // SetOfNodes::Iterator itn(myNodes);
2120 // for (; itn.More(); itn.Next())
2121 // delete itn.Value();
2123 // SetOf0DElements::Iterator it0d (my0DElements);
2124 // for (; it0d.More(); it0d.Next())
2126 // SMDS_MeshElement* elem = it0d.Value();
2130 // SetOfEdges::Iterator ite(myEdges);
2131 // for (; ite.More(); ite.Next())
2133 // SMDS_MeshElement* elem = ite.Value();
2137 // SetOfFaces::Iterator itf(myFaces);
2138 // for (; itf.More(); itf.Next())
2140 // SMDS_MeshElement* elem = itf.Value();
2144 // SetOfVolumes::Iterator itv(myVolumes);
2145 // for (; itv.More(); itv.Next())
2147 // SMDS_MeshElement* elem = itv.Value();
2152 //================================================================================
2154 * \brief Clear all data
2156 //================================================================================
2158 void SMDS_Mesh::Clear()
2160 if (myParent!=NULL) {
2161 SMDS_ElemIteratorPtr eIt = elementsIterator();
2162 while ( eIt->more() )
2163 myElementIDFactory->ReleaseID(eIt->next()->GetID());
2164 SMDS_NodeIteratorPtr itn = nodesIterator();
2166 myNodeIDFactory->ReleaseID(itn->next()->GetID());
2169 myNodeIDFactory->Clear();
2170 myElementIDFactory->Clear();
2173 SMDS_ElemIteratorPtr itv = elementsIterator();
2178 // SMDS_VolumeIteratorPtr itv = volumesIterator();
2179 // while (itv->more())
2180 // delete itv->next();
2181 // myVolumes.Clear();
2183 // SMDS_FaceIteratorPtr itf = facesIterator();
2184 // while (itf->more())
2185 // delete itf->next();
2188 // SMDS_EdgeIteratorPtr ite = edgesIterator();
2189 // while (ite->more())
2190 // delete ite->next();
2193 // SMDS_0DElementIteratorPtr it0d = elements0dIterator();
2194 // while (it0d->more())
2195 // delete it0d->next();
2196 // my0DElements.Clear();
2198 SMDS_NodeIteratorPtr itn = nodesIterator();
2203 list<SMDS_Mesh*>::iterator itc=myChildren.begin();
2204 while(itc!=myChildren.end())
2210 ///////////////////////////////////////////////////////////////////////////////
2211 /// Return true if this mesh create faces with edges.
2212 /// A false returned value mean that faces are created with nodes. A concequence
2213 /// is, iteration on edges (SMDS_Element::edgesIterator) will be unavailable.
2214 ///////////////////////////////////////////////////////////////////////////////
2215 bool SMDS_Mesh::hasConstructionEdges()
2217 return myHasConstructionEdges;
2220 ///////////////////////////////////////////////////////////////////////////////
2221 /// Return true if this mesh create volumes with faces
2222 /// A false returned value mean that volumes are created with nodes or edges.
2223 /// (see hasConstructionEdges)
2224 /// A concequence is, iteration on faces (SMDS_Element::facesIterator) will be
2226 ///////////////////////////////////////////////////////////////////////////////
2227 bool SMDS_Mesh::hasConstructionFaces()
2229 return myHasConstructionFaces;
2232 ///////////////////////////////////////////////////////////////////////////////
2233 /// Return true if nodes are linked to the finit elements, they are belonging to.
2234 /// Currently, It always return true.
2235 ///////////////////////////////////////////////////////////////////////////////
2236 bool SMDS_Mesh::hasInverseElements()
2238 return myHasInverseElements;
2241 ///////////////////////////////////////////////////////////////////////////////
2242 /// Make this mesh creating construction edges (see hasConstructionEdges)
2243 /// @param b true to have construction edges, else false.
2244 ///////////////////////////////////////////////////////////////////////////////
2245 void SMDS_Mesh::setConstructionEdges(bool b)
2247 myHasConstructionEdges=b;
2250 ///////////////////////////////////////////////////////////////////////////////
2251 /// Make this mesh creating construction faces (see hasConstructionFaces)
2252 /// @param b true to have construction faces, else false.
2253 ///////////////////////////////////////////////////////////////////////////////
2254 void SMDS_Mesh::setConstructionFaces(bool b)
2256 myHasConstructionFaces=b;
2259 ///////////////////////////////////////////////////////////////////////////////
2260 /// Make this mesh creating link from nodes to elements (see hasInverseElements)
2261 /// @param b true to link nodes to elements, else false.
2262 ///////////////////////////////////////////////////////////////////////////////
2263 void SMDS_Mesh::setInverseElements(bool b)
2265 if(!b) MESSAGE("Error : inverseElement=false not implemented");
2266 myHasInverseElements=b;
2269 ///////////////////////////////////////////////////////////////////////////////
2270 ///Iterator on NCollection_Map
2271 ///////////////////////////////////////////////////////////////////////////////
2272 template <class MAP, typename ELEM=const SMDS_MeshElement*, class FATHER=SMDS_ElemIterator>
2273 struct MYNode_Map_Iterator: public FATHER
2277 MYNode_Map_Iterator(const MAP& map): _map(map) // map is a std::vector<ELEM>
2284 while (_ctr < _map.size())
2295 ELEM current = _map[_ctr];
2301 template <class MAP, typename ELEM=const SMDS_MeshElement*, class FATHER=SMDS_ElemIterator>
2302 struct MYElem_Map_Iterator: public FATHER
2307 MYElem_Map_Iterator(const MAP& map, int typ): _map(map) // map is a std::vector<ELEM>
2315 while (_ctr < _map.size())
2318 if ( (_type == SMDSAbs_All) || (_map[_ctr]->GetType() == _type))
2327 ELEM current = dynamic_cast<ELEM> (_map[_ctr]);
2333 ///////////////////////////////////////////////////////////////////////////////
2334 /// Return an iterator on nodes of the current mesh factory
2335 ///////////////////////////////////////////////////////////////////////////////
2337 SMDS_NodeIteratorPtr SMDS_Mesh::nodesIterator() const
2339 //return SMDS_NodeIteratorPtr
2340 // (new SMDS_Mesh_MyNodeIterator(myNodeIDFactory->elementsIterator()));
2341 typedef MYNode_Map_Iterator
2342 < SetOfNodes, const SMDS_MeshNode*, SMDS_NodeIterator > TIterator;
2343 return SMDS_NodeIteratorPtr(new TIterator(myNodes));
2346 ///////////////////////////////////////////////////////////////////////////////
2347 ///Return an iterator on 0D elements of the current mesh.
2348 ///////////////////////////////////////////////////////////////////////////////
2350 SMDS_0DElementIteratorPtr SMDS_Mesh::elements0dIterator() const
2352 typedef MYElem_Map_Iterator
2353 < SetOfCells, const SMDS_Mesh0DElement*, SMDS_0DElementIterator > TIterator;
2354 return SMDS_0DElementIteratorPtr(new TIterator(myCells, SMDSAbs_0DElement));
2357 ///////////////////////////////////////////////////////////////////////////////
2358 ///Return an iterator on edges of the current mesh.
2359 ///////////////////////////////////////////////////////////////////////////////
2361 SMDS_EdgeIteratorPtr SMDS_Mesh::edgesIterator() const
2363 typedef MYElem_Map_Iterator
2364 < SetOfCells, const SMDS_MeshEdge*, SMDS_EdgeIterator > TIterator;
2365 return SMDS_EdgeIteratorPtr(new TIterator(myCells, SMDSAbs_Edge));
2368 ///////////////////////////////////////////////////////////////////////////////
2369 ///Return an iterator on faces of the current mesh.
2370 ///////////////////////////////////////////////////////////////////////////////
2372 SMDS_FaceIteratorPtr SMDS_Mesh::facesIterator() const
2374 typedef MYElem_Map_Iterator
2375 < SetOfCells, const SMDS_MeshFace*, SMDS_FaceIterator > TIterator;
2376 return SMDS_FaceIteratorPtr(new TIterator(myCells, SMDSAbs_Face));
2379 ///////////////////////////////////////////////////////////////////////////////
2380 ///Return an iterator on volumes of the current mesh.
2381 ///////////////////////////////////////////////////////////////////////////////
2383 SMDS_VolumeIteratorPtr SMDS_Mesh::volumesIterator() const
2385 typedef MYElem_Map_Iterator
2386 < SetOfCells, const SMDS_MeshVolume*, SMDS_VolumeIterator > TIterator;
2387 return SMDS_VolumeIteratorPtr(new TIterator(myCells, SMDSAbs_Volume));
2390 ///////////////////////////////////////////////////////////////////////////////
2391 /// Return an iterator on elements of the current mesh factory
2392 ///////////////////////////////////////////////////////////////////////////////
2393 SMDS_ElemIteratorPtr SMDS_Mesh::elementsIterator(SMDSAbs_ElementType type) const
2397 return SMDS_ElemIteratorPtr (new MYElem_Map_Iterator< SetOfCells >(myCells, SMDSAbs_All));
2399 case SMDSAbs_Volume:
2400 return SMDS_ElemIteratorPtr (new MYElem_Map_Iterator< SetOfCells >(myCells, SMDSAbs_Volume));
2402 return SMDS_ElemIteratorPtr (new MYElem_Map_Iterator< SetOfCells >(myCells, SMDSAbs_Face));
2404 return SMDS_ElemIteratorPtr (new MYElem_Map_Iterator< SetOfCells >(myCells, SMDSAbs_Edge));
2405 case SMDSAbs_0DElement:
2406 return SMDS_ElemIteratorPtr (new MYElem_Map_Iterator< SetOfCells >(myCells, SMDSAbs_0DElement));
2408 return SMDS_ElemIteratorPtr (new MYElem_Map_Iterator< SetOfNodes >(myNodes, SMDSAbs_All));
2409 //return myNodeIDFactory->elementsIterator();
2412 return myElementIDFactory->elementsIterator();
2415 ///////////////////////////////////////////////////////////////////////////////
2416 /// Do intersection of sets (more than 2)
2417 ///////////////////////////////////////////////////////////////////////////////
2418 static set<const SMDS_MeshElement*> * intersectionOfSets(
2419 set<const SMDS_MeshElement*> vs[], int numberOfSets)
2421 set<const SMDS_MeshElement*>* rsetA=new set<const SMDS_MeshElement*>(vs[0]);
2422 set<const SMDS_MeshElement*>* rsetB;
2424 for(int i=0; i<numberOfSets-1; i++)
2426 rsetB=new set<const SMDS_MeshElement*>();
2428 rsetA->begin(), rsetA->end(),
2429 vs[i+1].begin(), vs[i+1].end(),
2430 inserter(*rsetB, rsetB->begin()));
2437 ///////////////////////////////////////////////////////////////////////////////
2438 /// Return the list of finit elements owning the given element
2439 ///////////////////////////////////////////////////////////////////////////////
2440 static set<const SMDS_MeshElement*> * getFinitElements(const SMDS_MeshElement * element)
2442 int numberOfSets=element->NbNodes();
2443 set<const SMDS_MeshElement*> *initSet = new set<const SMDS_MeshElement*>[numberOfSets];
2445 SMDS_ElemIteratorPtr itNodes=element->nodesIterator();
2448 while(itNodes->more())
2450 const SMDS_MeshNode * n=static_cast<const SMDS_MeshNode*>(itNodes->next());
2451 SMDS_ElemIteratorPtr itFe = n->GetInverseElementIterator();
2453 //initSet[i]=set<const SMDS_MeshElement*>();
2455 initSet[i].insert(itFe->next());
2459 set<const SMDS_MeshElement*> *retSet=intersectionOfSets(initSet, numberOfSets);
2464 ///////////////////////////////////////////////////////////////////////////////
2465 /// Return the list of nodes used only by the given elements
2466 ///////////////////////////////////////////////////////////////////////////////
2467 static set<const SMDS_MeshElement*> * getExclusiveNodes(
2468 set<const SMDS_MeshElement*>& elements)
2470 set<const SMDS_MeshElement*> * toReturn=new set<const SMDS_MeshElement*>();
2471 set<const SMDS_MeshElement*>::iterator itElements=elements.begin();
2473 while(itElements!=elements.end())
2475 SMDS_ElemIteratorPtr itNodes = (*itElements)->nodesIterator();
2478 while(itNodes->more())
2480 const SMDS_MeshNode * n=static_cast<const SMDS_MeshNode*>(itNodes->next());
2481 SMDS_ElemIteratorPtr itFe = n->GetInverseElementIterator();
2482 set<const SMDS_MeshElement*> s;
2484 s.insert(itFe->next());
2485 if(s==elements) toReturn->insert(n);
2491 ///////////////////////////////////////////////////////////////////////////////
2492 ///Find the children of an element that are made of given nodes
2493 ///@param setOfChildren The set in which matching children will be inserted
2494 ///@param element The element were to search matching children
2495 ///@param nodes The nodes that the children must have to be selected
2496 ///////////////////////////////////////////////////////////////////////////////
2497 void SMDS_Mesh::addChildrenWithNodes(set<const SMDS_MeshElement*>& setOfChildren,
2498 const SMDS_MeshElement * element,
2499 set<const SMDS_MeshElement*>& nodes)
2501 switch(element->GetType())
2504 MESSAGE("Internal Error: This should not happend");
2506 case SMDSAbs_0DElement:
2512 SMDS_ElemIteratorPtr itn=element->nodesIterator();
2515 const SMDS_MeshElement * e=itn->next();
2516 if(nodes.find(e)!=nodes.end())
2518 setOfChildren.insert(element);
2525 SMDS_ElemIteratorPtr itn=element->nodesIterator();
2528 const SMDS_MeshElement * e=itn->next();
2529 if(nodes.find(e)!=nodes.end())
2531 setOfChildren.insert(element);
2535 if(hasConstructionEdges())
2537 SMDS_ElemIteratorPtr ite=element->edgesIterator();
2539 addChildrenWithNodes(setOfChildren, ite->next(), nodes);
2542 case SMDSAbs_Volume:
2544 if(hasConstructionFaces())
2546 SMDS_ElemIteratorPtr ite=element->facesIterator();
2548 addChildrenWithNodes(setOfChildren, ite->next(), nodes);
2550 else if(hasConstructionEdges())
2552 SMDS_ElemIteratorPtr ite=element->edgesIterator();
2554 addChildrenWithNodes(setOfChildren, ite->next(), nodes);
2560 ///////////////////////////////////////////////////////////////////////////////
2561 ///@param elem The element to delete
2562 ///@param removenodes if true remaining nodes will be removed
2563 ///////////////////////////////////////////////////////////////////////////////
2564 void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem,
2565 const bool removenodes)
2567 list<const SMDS_MeshElement *> removedElems;
2568 list<const SMDS_MeshElement *> removedNodes;
2569 RemoveElement( elem, removedElems, removedNodes, removenodes );
2572 ///////////////////////////////////////////////////////////////////////////////
2573 ///@param elem The element to delete
2574 ///@param removedElems contains all removed elements
2575 ///@param removedNodes contains all removed nodes
2576 ///@param removenodes if true remaining nodes will be removed
2577 ///////////////////////////////////////////////////////////////////////////////
2578 void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem,
2579 list<const SMDS_MeshElement *>& removedElems,
2580 list<const SMDS_MeshElement *>& removedNodes,
2583 // get finite elements built on elem
2584 set<const SMDS_MeshElement*> * s1;
2585 if (elem->GetType() == SMDSAbs_0DElement ||
2586 elem->GetType() == SMDSAbs_Edge && !hasConstructionEdges() ||
2587 elem->GetType() == SMDSAbs_Face && !hasConstructionFaces() ||
2588 elem->GetType() == SMDSAbs_Volume)
2590 s1 = new set<const SMDS_MeshElement*>();
2594 s1 = getFinitElements(elem);
2596 // get exclusive nodes (which would become free afterwards)
2597 set<const SMDS_MeshElement*> * s2;
2598 if (elem->GetType() == SMDSAbs_Node) // a node is removed
2600 // do not remove nodes except elem
2601 s2 = new set<const SMDS_MeshElement*>();
2606 s2 = getExclusiveNodes(*s1);
2608 // form the set of finite and construction elements to remove
2609 set<const SMDS_MeshElement*> s3;
2610 set<const SMDS_MeshElement*>::iterator it=s1->begin();
2611 while(it!=s1->end())
2613 addChildrenWithNodes(s3, *it ,*s2);
2617 if(elem->GetType()!=SMDSAbs_Node) s3.insert(elem);
2619 // remove finite and construction elements
2623 // Remove element from <InverseElements> of its nodes
2624 SMDS_ElemIteratorPtr itn=(*it)->nodesIterator();
2627 SMDS_MeshNode * n = static_cast<SMDS_MeshNode *>
2628 (const_cast<SMDS_MeshElement *>(itn->next()));
2629 n->RemoveInverseElement( (*it) );
2632 switch((*it)->GetType())
2635 MESSAGE("Internal Error: This should not happen");
2637 case SMDSAbs_0DElement:
2638 myCells[(*it)->GetID()] = 0; // -PR- ici ou dans myElementIDFactory->ReleaseID ?
2642 myCells[(*it)->GetID()] = 0;
2643 myInfo.RemoveEdge(*it);
2646 myCells[(*it)->GetID()] = 0;
2647 myInfo.RemoveFace(*it);
2649 case SMDSAbs_Volume:
2650 myCells[(*it)->GetID()] = 0;
2651 myInfo.RemoveVolume(*it);
2654 //MESSAGE( "SMDS: RM elem " << (*it)->GetID() );
2655 removedElems.push_back( (*it) );
2656 myElementIDFactory->ReleaseID((*it)->GetID());
2661 // remove exclusive (free) nodes
2665 while(it!=s2->end())
2667 //MESSAGE( "SMDS: RM node " << (*it)->GetID() );
2668 myNodes[(*it)->GetID()] = 0;
2670 myNodeIDFactory->ReleaseID((*it)->GetID());
2671 removedNodes.push_back( (*it) );
2682 ///////////////////////////////////////////////////////////////////////////////
2683 ///@param elem The element to delete
2684 ///////////////////////////////////////////////////////////////////////////////
2685 void SMDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elem)
2687 SMDSAbs_ElementType aType = elem->GetType();
2688 if (aType == SMDSAbs_Node) {
2689 // only free node can be removed by this method
2690 const SMDS_MeshNode* n = static_cast<const SMDS_MeshNode*>(elem);
2691 SMDS_ElemIteratorPtr itFe = n->GetInverseElementIterator();
2692 if (!itFe->more()) { // free node
2693 myNodes[elem->GetID()] = 0;
2695 myNodeIDFactory->ReleaseID(elem->GetID());
2699 if (hasConstructionEdges() || hasConstructionFaces())
2700 // this methods is only for meshes without descendants
2703 // Remove element from <InverseElements> of its nodes
2704 SMDS_ElemIteratorPtr itn = elem->nodesIterator();
2705 while (itn->more()) {
2706 SMDS_MeshNode * n = static_cast<SMDS_MeshNode *>
2707 (const_cast<SMDS_MeshElement *>(itn->next()));
2708 n->RemoveInverseElement(elem);
2711 // in meshes without descendants elements are always free
2713 case SMDSAbs_0DElement:
2714 myCells[elem->GetID()] = 0;
2715 myInfo.remove(elem);
2718 myCells[elem->GetID()] = 0;
2719 myInfo.RemoveEdge(elem);
2722 myCells[elem->GetID()] = 0;
2723 myInfo.RemoveFace(elem);
2725 case SMDSAbs_Volume:
2726 myCells[elem->GetID()] = 0;
2727 myInfo.RemoveVolume(elem);
2732 myElementIDFactory->ReleaseID(elem->GetID());
2738 * Checks if the element is present in mesh.
2739 * Useful to determine dead pointers.
2741 bool SMDS_Mesh::Contains (const SMDS_MeshElement* elem) const
2743 // we should not imply on validity of *elem, so iterate on containers
2744 // of all types in the hope of finding <elem> somewhere there
2745 SMDS_NodeIteratorPtr itn = nodesIterator();
2747 if (elem == itn->next())
2749 SMDS_0DElementIteratorPtr it0d = elements0dIterator();
2750 while (it0d->more())
2751 if (elem == it0d->next())
2753 SMDS_EdgeIteratorPtr ite = edgesIterator();
2755 if (elem == ite->next())
2757 SMDS_FaceIteratorPtr itf = facesIterator();
2759 if (elem == itf->next())
2761 SMDS_VolumeIteratorPtr itv = volumesIterator();
2763 if (elem == itv->next())
2768 //=======================================================================
2769 //function : MaxNodeID
2771 //=======================================================================
2773 int SMDS_Mesh::MaxNodeID() const
2778 //=======================================================================
2779 //function : MinNodeID
2781 //=======================================================================
2783 int SMDS_Mesh::MinNodeID() const
2788 //=======================================================================
2789 //function : MaxElementID
2791 //=======================================================================
2793 int SMDS_Mesh::MaxElementID() const
2795 return myElementIDFactory->GetMaxID();
2798 //=======================================================================
2799 //function : MinElementID
2801 //=======================================================================
2803 int SMDS_Mesh::MinElementID() const
2805 return myElementIDFactory->GetMinID();
2808 //=======================================================================
2809 //function : Renumber
2810 //purpose : Renumber all nodes or elements.
2811 //=======================================================================
2813 void SMDS_Mesh::Renumber (const bool isNodes, const int startID, const int deltaID)
2815 MESSAGE("Renumber");
2819 SMDS_MeshNodeIDFactory * idFactory =
2820 isNodes ? myNodeIDFactory : myElementIDFactory;
2822 // get existing elements in the order of ID increasing
2823 map<int,SMDS_MeshElement*> elemMap;
2824 SMDS_ElemIteratorPtr idElemIt = idFactory->elementsIterator();
2825 while ( idElemIt->more() ) {
2826 SMDS_MeshElement* elem = const_cast<SMDS_MeshElement*>(idElemIt->next());
2827 int id = elem->GetID();
2828 elemMap.insert(map<int,SMDS_MeshElement*>::value_type(id, elem));
2830 // release their ids
2831 map<int,SMDS_MeshElement*>::iterator elemIt = elemMap.begin();
2833 // for ( ; elemIt != elemMap.end(); elemIt++ )
2835 // int id = (*elemIt).first;
2836 // idFactory->ReleaseID( id );
2840 elemIt = elemMap.begin();
2841 for ( ; elemIt != elemMap.end(); elemIt++ )
2843 idFactory->BindID( ID, (*elemIt).second );
2848 //=======================================================================
2849 //function : GetElementType
2850 //purpose : Return type of element or node with id
2851 //=======================================================================
2853 SMDSAbs_ElementType SMDS_Mesh::GetElementType( const int id, const bool iselem ) const
2855 SMDS_MeshElement* elem = 0;
2857 elem = myElementIDFactory->MeshElement( id );
2859 elem = myNodeIDFactory->MeshElement( id );
2863 //throw SALOME_Exception(LOCALIZED ("this element isn't exist"));
2867 return elem->GetType();
2872 //********************************************************************
2873 //********************************************************************
2874 //******** *********
2875 //***** Methods for addition of quadratic elements ******
2876 //******** *********
2877 //********************************************************************
2878 //********************************************************************
2880 //=======================================================================
2881 //function : AddEdgeWithID
2883 //=======================================================================
2884 SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(int n1, int n2, int n12, int ID)
2886 return SMDS_Mesh::AddEdgeWithID
2887 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1),
2888 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2),
2889 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
2893 //=======================================================================
2894 //function : AddEdge
2896 //=======================================================================
2897 SMDS_MeshEdge* SMDS_Mesh::AddEdge(const SMDS_MeshNode* n1,
2898 const SMDS_MeshNode* n2,
2899 const SMDS_MeshNode* n12)
2901 return SMDS_Mesh::AddEdgeWithID(n1, n2, n12, myElementIDFactory->GetFreeID());
2904 //=======================================================================
2905 //function : AddEdgeWithID
2907 //=======================================================================
2908 SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
2909 const SMDS_MeshNode * n2,
2910 const SMDS_MeshNode * n12,
2913 if ( !n1 || !n2 || !n12 ) return 0;
2914 SMDS_QuadraticEdge* edge = new SMDS_QuadraticEdge(n1,n2,n12);
2915 if(myElementIDFactory->BindID(ID, edge)) {
2916 SMDS_MeshNode *node1,*node2, *node12;
2917 //node1 = const_cast<SMDS_MeshNode*>(n1);
2918 //node2 = const_cast<SMDS_MeshNode*>(n2);
2919 //node12 = const_cast<SMDS_MeshNode*>(n12);
2920 //node1->AddInverseElement(edge); // --- fait avec BindID
2921 //node2->AddInverseElement(edge);
2922 //node12->AddInverseElement(edge);
2923 adjustmyCellsCapacity(ID);
2925 myInfo.myNbQuadEdges++;
2935 //=======================================================================
2936 //function : AddFace
2938 //=======================================================================
2939 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
2940 const SMDS_MeshNode * n2,
2941 const SMDS_MeshNode * n3,
2942 const SMDS_MeshNode * n12,
2943 const SMDS_MeshNode * n23,
2944 const SMDS_MeshNode * n31)
2946 return SMDS_Mesh::AddFaceWithID(n1,n2,n3,n12,n23,n31,
2947 myElementIDFactory->GetFreeID());
2950 //=======================================================================
2951 //function : AddFaceWithID
2953 //=======================================================================
2954 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int n1, int n2, int n3,
2955 int n12,int n23,int n31, int ID)
2957 return SMDS_Mesh::AddFaceWithID
2958 ((SMDS_MeshNode *)myNodeIDFactory->MeshElement(n1) ,
2959 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n2) ,
2960 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n3) ,
2961 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n12),
2962 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n23),
2963 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n31),
2967 //=======================================================================
2968 //function : AddFaceWithID
2970 //=======================================================================
2971 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
2972 const SMDS_MeshNode * n2,
2973 const SMDS_MeshNode * n3,
2974 const SMDS_MeshNode * n12,
2975 const SMDS_MeshNode * n23,
2976 const SMDS_MeshNode * n31,
2979 if ( !n1 || !n2 || !n3 || !n12 || !n23 || !n31) return 0;
2980 if(hasConstructionEdges()) {
2981 // creation quadratic edges - not implemented
2984 SMDS_QuadraticFaceOfNodes* face =
2985 new SMDS_QuadraticFaceOfNodes(n1,n2,n3,n12,n23,n31);
2986 adjustmyCellsCapacity(ID);
2988 myInfo.myNbQuadTriangles++;
2990 if (!registerElement(ID, face)) {
2991 RemoveElement(face, false);
2998 //=======================================================================
2999 //function : AddFace
3001 //=======================================================================
3002 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
3003 const SMDS_MeshNode * n2,
3004 const SMDS_MeshNode * n3,
3005 const SMDS_MeshNode * n4,
3006 const SMDS_MeshNode * n12,
3007 const SMDS_MeshNode * n23,
3008 const SMDS_MeshNode * n34,
3009 const SMDS_MeshNode * n41)
3011 return SMDS_Mesh::AddFaceWithID(n1,n2,n3,n4,n12,n23,n34,n41,
3012 myElementIDFactory->GetFreeID());
3015 //=======================================================================
3016 //function : AddFaceWithID
3018 //=======================================================================
3019 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int n4,
3020 int n12,int n23,int n34,int n41, int ID)
3022 return SMDS_Mesh::AddFaceWithID
3023 ((SMDS_MeshNode *)myNodeIDFactory->MeshElement(n1) ,
3024 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n2) ,
3025 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n3) ,
3026 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n4) ,
3027 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n12),
3028 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n23),
3029 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n34),
3030 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n41),
3034 //=======================================================================
3035 //function : AddFaceWithID
3037 //=======================================================================
3038 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
3039 const SMDS_MeshNode * n2,
3040 const SMDS_MeshNode * n3,
3041 const SMDS_MeshNode * n4,
3042 const SMDS_MeshNode * n12,
3043 const SMDS_MeshNode * n23,
3044 const SMDS_MeshNode * n34,
3045 const SMDS_MeshNode * n41,
3048 if ( !n1 || !n2 || !n3 || !n4 || !n12 || !n23 || !n34 || !n41) return 0;
3049 if(hasConstructionEdges()) {
3050 // creation quadratic edges - not implemented
3052 SMDS_QuadraticFaceOfNodes* face =
3053 new SMDS_QuadraticFaceOfNodes(n1,n2,n3,n4,n12,n23,n34,n41);
3054 adjustmyCellsCapacity(ID);
3056 myInfo.myNbQuadQuadrangles++;
3058 if (!registerElement(ID, face)) {
3059 RemoveElement(face, false);
3066 //=======================================================================
3067 //function : AddVolume
3069 //=======================================================================
3070 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
3071 const SMDS_MeshNode * n2,
3072 const SMDS_MeshNode * n3,
3073 const SMDS_MeshNode * n4,
3074 const SMDS_MeshNode * n12,
3075 const SMDS_MeshNode * n23,
3076 const SMDS_MeshNode * n31,
3077 const SMDS_MeshNode * n14,
3078 const SMDS_MeshNode * n24,
3079 const SMDS_MeshNode * n34)
3081 int ID = myElementIDFactory->GetFreeID();
3082 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n12, n23,
3083 n31, n14, n24, n34, ID);
3084 if(v==NULL) myElementIDFactory->ReleaseID(ID);
3088 //=======================================================================
3089 //function : AddVolumeWithID
3091 //=======================================================================
3092 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4,
3093 int n12,int n23,int n31,
3094 int n14,int n24,int n34, int ID)
3096 return SMDS_Mesh::AddVolumeWithID
3097 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1) ,
3098 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2) ,
3099 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3) ,
3100 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4) ,
3101 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
3102 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
3103 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n31),
3104 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n14),
3105 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n24),
3106 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n34),
3110 //=======================================================================
3111 //function : AddVolumeWithID
3112 //purpose : 2d order tetrahedron of 10 nodes
3113 //=======================================================================
3114 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
3115 const SMDS_MeshNode * n2,
3116 const SMDS_MeshNode * n3,
3117 const SMDS_MeshNode * n4,
3118 const SMDS_MeshNode * n12,
3119 const SMDS_MeshNode * n23,
3120 const SMDS_MeshNode * n31,
3121 const SMDS_MeshNode * n14,
3122 const SMDS_MeshNode * n24,
3123 const SMDS_MeshNode * n34,
3126 if ( !n1 || !n2 || !n3 || !n4 || !n12 || !n23 || !n31 || !n14 || !n24 || !n34)
3128 if(hasConstructionFaces()) {
3129 // creation quadratic faces - not implemented
3132 SMDS_QuadraticVolumeOfNodes * volume =
3133 new SMDS_QuadraticVolumeOfNodes(n1,n2,n3,n4,n12,n23,n31,n14,n24,n34);
3134 adjustmyCellsCapacity(ID);
3135 myCells[ID] = volume;
3136 myInfo.myNbQuadTetras++;
3138 if (!registerElement(ID, volume)) {
3139 RemoveElement(volume, false);
3146 //=======================================================================
3147 //function : AddVolume
3149 //=======================================================================
3150 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
3151 const SMDS_MeshNode * n2,
3152 const SMDS_MeshNode * n3,
3153 const SMDS_MeshNode * n4,
3154 const SMDS_MeshNode * n5,
3155 const SMDS_MeshNode * n12,
3156 const SMDS_MeshNode * n23,
3157 const SMDS_MeshNode * n34,
3158 const SMDS_MeshNode * n41,
3159 const SMDS_MeshNode * n15,
3160 const SMDS_MeshNode * n25,
3161 const SMDS_MeshNode * n35,
3162 const SMDS_MeshNode * n45)
3164 int ID = myElementIDFactory->GetFreeID();
3165 SMDS_MeshVolume * v =
3166 SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n12, n23, n34, n41,
3167 n15, n25, n35, n45, ID);
3168 if(v==NULL) myElementIDFactory->ReleaseID(ID);
3172 //=======================================================================
3173 //function : AddVolumeWithID
3175 //=======================================================================
3176 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5,
3177 int n12,int n23,int n34,int n41,
3178 int n15,int n25,int n35,int n45, int ID)
3180 return SMDS_Mesh::AddVolumeWithID
3181 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1) ,
3182 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2) ,
3183 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3) ,
3184 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4) ,
3185 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5) ,
3186 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
3187 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
3188 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n34),
3189 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n41),
3190 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n15),
3191 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n25),
3192 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n35),
3193 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n45),
3197 //=======================================================================
3198 //function : AddVolumeWithID
3199 //purpose : 2d order pyramid of 13 nodes
3200 //=======================================================================
3201 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
3202 const SMDS_MeshNode * n2,
3203 const SMDS_MeshNode * n3,
3204 const SMDS_MeshNode * n4,
3205 const SMDS_MeshNode * n5,
3206 const SMDS_MeshNode * n12,
3207 const SMDS_MeshNode * n23,
3208 const SMDS_MeshNode * n34,
3209 const SMDS_MeshNode * n41,
3210 const SMDS_MeshNode * n15,
3211 const SMDS_MeshNode * n25,
3212 const SMDS_MeshNode * n35,
3213 const SMDS_MeshNode * n45,
3216 if (!n1 || !n2 || !n3 || !n4 || !n5 || !n12 || !n23 ||
3217 !n34 || !n41 || !n15 || !n25 || !n35 || !n45)
3219 if(hasConstructionFaces()) {
3220 // creation quadratic faces - not implemented
3223 SMDS_QuadraticVolumeOfNodes * volume =
3224 new SMDS_QuadraticVolumeOfNodes(n1,n2,n3,n4,n5,n12,n23,
3225 n34,n41,n15,n25,n35,n45);
3226 adjustmyCellsCapacity(ID);
3227 myCells[ID] = volume;
3228 myInfo.myNbQuadPyramids++;
3230 if (!registerElement(ID, volume)) {
3231 RemoveElement(volume, false);
3238 //=======================================================================
3239 //function : AddVolume
3241 //=======================================================================
3242 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
3243 const SMDS_MeshNode * n2,
3244 const SMDS_MeshNode * n3,
3245 const SMDS_MeshNode * n4,
3246 const SMDS_MeshNode * n5,
3247 const SMDS_MeshNode * n6,
3248 const SMDS_MeshNode * n12,
3249 const SMDS_MeshNode * n23,
3250 const SMDS_MeshNode * n31,
3251 const SMDS_MeshNode * n45,
3252 const SMDS_MeshNode * n56,
3253 const SMDS_MeshNode * n64,
3254 const SMDS_MeshNode * n14,
3255 const SMDS_MeshNode * n25,
3256 const SMDS_MeshNode * n36)
3258 int ID = myElementIDFactory->GetFreeID();
3259 SMDS_MeshVolume * v =
3260 SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n12, n23, n31,
3261 n45, n56, n64, n14, n25, n36, ID);
3262 if(v==NULL) myElementIDFactory->ReleaseID(ID);
3266 //=======================================================================
3267 //function : AddVolumeWithID
3269 //=======================================================================
3270 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3,
3271 int n4, int n5, int n6,
3272 int n12,int n23,int n31,
3273 int n45,int n56,int n64,
3274 int n14,int n25,int n36, int ID)
3276 return SMDS_Mesh::AddVolumeWithID
3277 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1) ,
3278 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2) ,
3279 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3) ,
3280 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4) ,
3281 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5) ,
3282 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n6) ,
3283 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
3284 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
3285 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n31),
3286 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n45),
3287 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n56),
3288 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n64),
3289 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n14),
3290 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n25),
3291 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n36),
3295 //=======================================================================
3296 //function : AddVolumeWithID
3297 //purpose : 2d order Pentahedron with 15 nodes
3298 //=======================================================================
3299 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
3300 const SMDS_MeshNode * n2,
3301 const SMDS_MeshNode * n3,
3302 const SMDS_MeshNode * n4,
3303 const SMDS_MeshNode * n5,
3304 const SMDS_MeshNode * n6,
3305 const SMDS_MeshNode * n12,
3306 const SMDS_MeshNode * n23,
3307 const SMDS_MeshNode * n31,
3308 const SMDS_MeshNode * n45,
3309 const SMDS_MeshNode * n56,
3310 const SMDS_MeshNode * n64,
3311 const SMDS_MeshNode * n14,
3312 const SMDS_MeshNode * n25,
3313 const SMDS_MeshNode * n36,
3316 if (!n1 || !n2 || !n3 || !n4 || !n5 || !n6 || !n12 || !n23 ||
3317 !n31 || !n45 || !n56 || !n64 || !n14 || !n25 || !n36)
3319 if(hasConstructionFaces()) {
3320 // creation quadratic faces - not implemented
3323 SMDS_QuadraticVolumeOfNodes * volume =
3324 new SMDS_QuadraticVolumeOfNodes(n1,n2,n3,n4,n5,n6,n12,n23,n31,
3325 n45,n56,n64,n14,n25,n36);
3326 adjustmyCellsCapacity(ID);
3327 myCells[ID] = volume;
3328 myInfo.myNbQuadPrisms++;
3330 if (!registerElement(ID, volume)) {
3331 RemoveElement(volume, false);
3338 //=======================================================================
3339 //function : AddVolume
3341 //=======================================================================
3342 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
3343 const SMDS_MeshNode * n2,
3344 const SMDS_MeshNode * n3,
3345 const SMDS_MeshNode * n4,
3346 const SMDS_MeshNode * n5,
3347 const SMDS_MeshNode * n6,
3348 const SMDS_MeshNode * n7,
3349 const SMDS_MeshNode * n8,
3350 const SMDS_MeshNode * n12,
3351 const SMDS_MeshNode * n23,
3352 const SMDS_MeshNode * n34,
3353 const SMDS_MeshNode * n41,
3354 const SMDS_MeshNode * n56,
3355 const SMDS_MeshNode * n67,
3356 const SMDS_MeshNode * n78,
3357 const SMDS_MeshNode * n85,
3358 const SMDS_MeshNode * n15,
3359 const SMDS_MeshNode * n26,
3360 const SMDS_MeshNode * n37,
3361 const SMDS_MeshNode * n48)
3363 int ID = myElementIDFactory->GetFreeID();
3364 SMDS_MeshVolume * v =
3365 SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, n12, n23, n34, n41,
3366 n56, n67, n78, n85, n15, n26, n37, n48, ID);
3367 if(v==NULL) myElementIDFactory->ReleaseID(ID);
3371 //=======================================================================
3372 //function : AddVolumeWithID
3374 //=======================================================================
3375 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4,
3376 int n5, int n6, int n7, int n8,
3377 int n12,int n23,int n34,int n41,
3378 int n56,int n67,int n78,int n85,
3379 int n15,int n26,int n37,int n48, int ID)
3381 return SMDS_Mesh::AddVolumeWithID
3382 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1),
3383 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2),
3384 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3),
3385 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4),
3386 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5),
3387 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n6),
3388 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n7),
3389 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n8),
3390 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
3391 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
3392 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n34),
3393 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n41),
3394 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n56),
3395 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n67),
3396 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n78),
3397 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n85),
3398 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n15),
3399 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n26),
3400 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n37),
3401 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n48),
3405 //=======================================================================
3406 //function : AddVolumeWithID
3407 //purpose : 2d order Hexahedrons with 20 nodes
3408 //=======================================================================
3409 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
3410 const SMDS_MeshNode * n2,
3411 const SMDS_MeshNode * n3,
3412 const SMDS_MeshNode * n4,
3413 const SMDS_MeshNode * n5,
3414 const SMDS_MeshNode * n6,
3415 const SMDS_MeshNode * n7,
3416 const SMDS_MeshNode * n8,
3417 const SMDS_MeshNode * n12,
3418 const SMDS_MeshNode * n23,
3419 const SMDS_MeshNode * n34,
3420 const SMDS_MeshNode * n41,
3421 const SMDS_MeshNode * n56,
3422 const SMDS_MeshNode * n67,
3423 const SMDS_MeshNode * n78,
3424 const SMDS_MeshNode * n85,
3425 const SMDS_MeshNode * n15,
3426 const SMDS_MeshNode * n26,
3427 const SMDS_MeshNode * n37,
3428 const SMDS_MeshNode * n48,
3431 if (!n1 || !n2 || !n3 || !n4 || !n5 || !n6 || !n7 || !n8 || !n12 || !n23 ||
3432 !n34 || !n41 || !n56 || !n67 || !n78 || !n85 || !n15 || !n26 || !n37 || !n48)
3434 if(hasConstructionFaces()) {
3436 // creation quadratic faces - not implemented
3438 SMDS_QuadraticVolumeOfNodes * volume =
3439 new SMDS_QuadraticVolumeOfNodes(n1,n2,n3,n4,n5,n6,n7,n8,n12,n23,n34,n41,
3440 n56,n67,n78,n85,n15,n26,n37,n48);
3441 adjustmyCellsCapacity(ID);
3442 myCells[ID] = volume;
3443 myInfo.myNbQuadHexas++;
3445 if (!registerElement(ID, volume)) {
3446 RemoveElement(volume, false);
3452 void SMDS_Mesh::updateNodeMinMax()
3455 while (!myNodes[myNodeMin] && (myNodeMin<myNodes.size()))
3457 myNodeMax=myNodes.size()-1;
3458 while (!myNodes[myNodeMax] && (myNodeMin>=0))
3462 void SMDS_Mesh::incrementNodesCapacity(int nbNodes)
3464 int val = myIDElements.size();
3465 MESSAGE(" ------------------- resize myIDElements " << val << " --> " << val + nbNodes);
3466 myIDElements.resize(val + nbNodes, -1); // fill new elements with -1
3467 val = myNodes.size();
3468 MESSAGE(" ------------------- resize myNodes " << val << " --> " << val + nbNodes);
3469 myNodes.resize(val +nbNodes, 0);
3472 void SMDS_Mesh::incrementCellsCapacity(int nbCells)
3474 int val = myVtkIndex.size();
3475 MESSAGE(" ------------------- resize myVtkIndex " << val << " --> " << val + nbCells);
3476 myVtkIndex.resize(val + nbCells, -1); // fill new elements with -1
3477 val = myCells.size();
3478 MESSAGE(" ------------------- resize myCells " << val << " --> " << val + nbCells);
3479 myNodes.resize(val +nbCells, 0);