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"
45 #include <sys/sysinfo.h>
48 // number of added entitis to check memory after
49 #define CHECKMEMORY_INTERVAL 1000
51 //================================================================================
53 * \brief Raise an exception if free memory (ram+swap) too low
54 * \param doNotRaise - if true, suppres exception, just return free memory size
55 * \retval int - amount of available memory in MB or negative number in failure case
57 //================================================================================
59 int SMDS_Mesh::CheckMemory(const bool doNotRaise) throw (std::bad_alloc)
63 int err = sysinfo( &si );
67 static int limit = -1;
69 int status = system("SMDS_MemoryLimit"); // it returns lower limit of free RAM
71 limit = WEXITSTATUS(status);
76 limit = int( limit * 1.5 );
78 MESSAGE ( "SMDS_Mesh::CheckMemory() memory limit = " << limit << " MB" );
82 const unsigned long Mbyte = 1024 * 1024;
83 // compute separately to avoid overflow
85 ( si.freeram * si.mem_unit ) / Mbyte +
86 ( si.freeswap * si.mem_unit ) / Mbyte;
89 return freeMb - limit;
94 MESSAGE ("SMDS_Mesh::CheckMemory() throws as free memory too low: " << freeMb <<" MB" );
96 throw std::bad_alloc();
102 ///////////////////////////////////////////////////////////////////////////////
103 /// Create a new mesh object
104 ///////////////////////////////////////////////////////////////////////////////
105 SMDS_Mesh::SMDS_Mesh()
107 myNodeIDFactory(new SMDS_MeshElementIDFactory()),
108 myElementIDFactory(new SMDS_MeshElementIDFactory()),
109 myHasConstructionEdges(false), myHasConstructionFaces(false),
110 myHasInverseElements(true)
114 ///////////////////////////////////////////////////////////////////////////////
115 /// Create a new child mesh
116 /// Note that the tree structure of SMDS_Mesh seems to be unused in this version
117 /// (2003-09-08) of SMESH
118 ///////////////////////////////////////////////////////////////////////////////
119 SMDS_Mesh::SMDS_Mesh(SMDS_Mesh * parent)
120 :myParent(parent), myNodeIDFactory(parent->myNodeIDFactory),
121 myElementIDFactory(parent->myElementIDFactory),
122 myHasConstructionEdges(false), myHasConstructionFaces(false),
123 myHasInverseElements(true)
127 ///////////////////////////////////////////////////////////////////////////////
128 ///Create a submesh and add it to the current mesh
129 ///////////////////////////////////////////////////////////////////////////////
131 SMDS_Mesh *SMDS_Mesh::AddSubMesh()
133 SMDS_Mesh *submesh = new SMDS_Mesh(this);
134 myChildren.insert(myChildren.end(), submesh);
138 ///////////////////////////////////////////////////////////////////////////////
139 ///create a MeshNode and add it to the current Mesh
140 ///An ID is automatically assigned to the node.
141 ///@return : The created node
142 ///////////////////////////////////////////////////////////////////////////////
144 SMDS_MeshNode * SMDS_Mesh::AddNode(double x, double y, double z)
146 return SMDS_Mesh::AddNodeWithID(x,y,z,myNodeIDFactory->GetFreeID());
149 ///////////////////////////////////////////////////////////////////////////////
150 ///create a MeshNode and add it to the current Mesh
151 ///@param ID : The ID of the MeshNode to create
152 ///@return : The created node or NULL if a node with this ID already exists
153 ///////////////////////////////////////////////////////////////////////////////
154 SMDS_MeshNode * SMDS_Mesh::AddNodeWithID(double x, double y, double z, int ID)
156 // find the MeshNode corresponding to ID
157 const SMDS_MeshElement *node = myNodeIDFactory->MeshElement(ID);
159 if ( myNodes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
160 SMDS_MeshNode * node=new SMDS_MeshNode(x, y, z);
162 myNodeIDFactory->BindID(ID,node);
169 ///////////////////////////////////////////////////////////////////////////////
170 /// create a Mesh0DElement and add it to the current Mesh
171 /// @return : The created Mesh0DElement
172 ///////////////////////////////////////////////////////////////////////////////
173 SMDS_Mesh0DElement* SMDS_Mesh::Add0DElementWithID(int idnode, int ID)
175 SMDS_MeshNode * node = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode);
176 if (!node) return NULL;
177 return SMDS_Mesh::Add0DElementWithID(node, ID);
180 ///////////////////////////////////////////////////////////////////////////////
181 /// create a Mesh0DElement and add it to the current Mesh
182 /// @return : The created Mesh0DElement
183 ///////////////////////////////////////////////////////////////////////////////
184 SMDS_Mesh0DElement* SMDS_Mesh::Add0DElement(const SMDS_MeshNode * node)
186 return SMDS_Mesh::Add0DElementWithID(node, myElementIDFactory->GetFreeID());
189 ///////////////////////////////////////////////////////////////////////////////
190 /// Create a new Mesh0DElement and at it to the mesh
191 /// @param idnode ID of the node
192 /// @param ID ID of the 0D element to create
193 /// @return The created 0D element or NULL if an element with this
194 /// ID already exists or if input node is not found.
195 ///////////////////////////////////////////////////////////////////////////////
196 SMDS_Mesh0DElement* SMDS_Mesh::Add0DElementWithID(const SMDS_MeshNode * n, int ID)
200 if (my0DElements.Extent() % CHECKMEMORY_INTERVAL == 0) CheckMemory();
202 SMDS_Mesh0DElement * el0d = new SMDS_Mesh0DElement(n);
203 if (myElementIDFactory->BindID(ID, el0d)) {
204 SMDS_MeshNode *node = const_cast<SMDS_MeshNode*>(n);
205 node->AddInverseElement(el0d);
206 my0DElements.Add(el0d);
207 myInfo.myNb0DElements++;
215 ///////////////////////////////////////////////////////////////////////////////
216 /// create a MeshEdge and add it to the current Mesh
217 /// @return : The created MeshEdge
218 ///////////////////////////////////////////////////////////////////////////////
220 SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(int idnode1, int idnode2, int ID)
222 SMDS_MeshNode * node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
223 SMDS_MeshNode * node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
224 if(!node1 || !node2) return NULL;
225 return SMDS_Mesh::AddEdgeWithID(node1, node2, ID);
228 ///////////////////////////////////////////////////////////////////////////////
229 /// create a MeshEdge and add it to the current Mesh
230 /// @return : The created MeshEdge
231 ///////////////////////////////////////////////////////////////////////////////
233 SMDS_MeshEdge* SMDS_Mesh::AddEdge(const SMDS_MeshNode * node1,
234 const SMDS_MeshNode * node2)
236 return SMDS_Mesh::AddEdgeWithID(node1, node2, myElementIDFactory->GetFreeID());
239 ///////////////////////////////////////////////////////////////////////////////
240 /// Create a new edge and at it to the mesh
241 /// @param idnode1 ID of the first node
242 /// @param idnode2 ID of the second node
243 /// @param ID ID of the edge to create
244 /// @return The created edge or NULL if an element with this ID already exists or
245 /// if input nodes are not found.
246 ///////////////////////////////////////////////////////////////////////////////
248 SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
249 const SMDS_MeshNode * n2,
252 if ( !n1 || !n2 ) return 0;
254 if ( myEdges.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
256 SMDS_MeshEdge * edge=new SMDS_MeshEdge(n1,n2);
257 if(myElementIDFactory->BindID(ID, edge)) {
258 SMDS_MeshNode *node1,*node2;
259 node1=const_cast<SMDS_MeshNode*>(n1);
260 node2=const_cast<SMDS_MeshNode*>(n2);
261 node1->AddInverseElement(edge);
262 node2->AddInverseElement(edge);
273 ///////////////////////////////////////////////////////////////////////////////
274 /// Add a triangle defined by its nodes. An ID is automatically affected to the
276 ///////////////////////////////////////////////////////////////////////////////
278 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
279 const SMDS_MeshNode * n2,
280 const SMDS_MeshNode * n3)
282 return SMDS_Mesh::AddFaceWithID(n1,n2,n3, myElementIDFactory->GetFreeID());
285 ///////////////////////////////////////////////////////////////////////////////
286 /// Add a triangle defined by its nodes IDs
287 ///////////////////////////////////////////////////////////////////////////////
289 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int idnode1, int idnode2, int idnode3, int ID)
291 SMDS_MeshNode * node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
292 SMDS_MeshNode * node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
293 SMDS_MeshNode * node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
294 if(!node1 || !node2 || !node3) return NULL;
295 return SMDS_Mesh::AddFaceWithID(node1, node2, node3, ID);
298 ///////////////////////////////////////////////////////////////////////////////
299 /// Add a triangle defined by its nodes
300 ///////////////////////////////////////////////////////////////////////////////
302 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
303 const SMDS_MeshNode * n2,
304 const SMDS_MeshNode * n3,
307 SMDS_MeshFace * face=createTriangle(n1, n2, n3);
309 if (face && !registerElement(ID, face)) {
310 RemoveElement(face, false);
316 ///////////////////////////////////////////////////////////////////////////////
317 /// Add a quadrangle defined by its nodes. An ID is automatically affected to the
319 ///////////////////////////////////////////////////////////////////////////////
321 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
322 const SMDS_MeshNode * n2,
323 const SMDS_MeshNode * n3,
324 const SMDS_MeshNode * n4)
326 return SMDS_Mesh::AddFaceWithID(n1,n2,n3, n4, myElementIDFactory->GetFreeID());
329 ///////////////////////////////////////////////////////////////////////////////
330 /// Add a quadrangle defined by its nodes IDs
331 ///////////////////////////////////////////////////////////////////////////////
333 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int idnode1,
339 SMDS_MeshNode *node1, *node2, *node3, *node4;
340 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
341 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
342 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
343 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
344 if(!node1 || !node2 || !node3 || !node4) return NULL;
345 return SMDS_Mesh::AddFaceWithID(node1, node2, node3, node4, ID);
348 ///////////////////////////////////////////////////////////////////////////////
349 /// Add a quadrangle defined by its nodes
350 ///////////////////////////////////////////////////////////////////////////////
352 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
353 const SMDS_MeshNode * n2,
354 const SMDS_MeshNode * n3,
355 const SMDS_MeshNode * n4,
358 SMDS_MeshFace * face=createQuadrangle(n1, n2, n3, n4);
360 if (face && !registerElement(ID, face)) {
361 RemoveElement(face, false);
367 ///////////////////////////////////////////////////////////////////////////////
368 /// Add a triangle defined by its edges. An ID is automatically assigned to the
370 ///////////////////////////////////////////////////////////////////////////////
372 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshEdge * e1,
373 const SMDS_MeshEdge * e2,
374 const SMDS_MeshEdge * e3)
376 if (!hasConstructionEdges())
378 return AddFaceWithID(e1,e2,e3, myElementIDFactory->GetFreeID());
381 ///////////////////////////////////////////////////////////////////////////////
382 /// Add a triangle defined by its edges
383 ///////////////////////////////////////////////////////////////////////////////
385 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshEdge * e1,
386 const SMDS_MeshEdge * e2,
387 const SMDS_MeshEdge * e3,
390 if (!hasConstructionEdges())
392 if ( !e1 || !e2 || !e3 ) return 0;
394 if ( myFaces.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
396 SMDS_MeshFace * face = new SMDS_FaceOfEdges(e1,e2,e3);
398 myInfo.myNbTriangles++;
400 if (!registerElement(ID, face)) {
401 RemoveElement(face, false);
407 ///////////////////////////////////////////////////////////////////////////////
408 /// Add a quadrangle defined by its edges. An ID is automatically assigned to the
410 ///////////////////////////////////////////////////////////////////////////////
412 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshEdge * e1,
413 const SMDS_MeshEdge * e2,
414 const SMDS_MeshEdge * e3,
415 const SMDS_MeshEdge * e4)
417 if (!hasConstructionEdges())
419 return AddFaceWithID(e1,e2,e3,e4, myElementIDFactory->GetFreeID());
422 ///////////////////////////////////////////////////////////////////////////////
423 /// Add a quadrangle defined by its edges
424 ///////////////////////////////////////////////////////////////////////////////
426 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshEdge * e1,
427 const SMDS_MeshEdge * e2,
428 const SMDS_MeshEdge * e3,
429 const SMDS_MeshEdge * e4,
432 if (!hasConstructionEdges())
434 if ( !e1 || !e2 || !e3 || !e4 ) return 0;
435 if ( myFaces.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
436 SMDS_MeshFace * face = new SMDS_FaceOfEdges(e1,e2,e3,e4);
438 myInfo.myNbQuadrangles++;
440 if (!registerElement(ID, face))
442 RemoveElement(face, false);
448 ///////////////////////////////////////////////////////////////////////////////
449 ///Create a new tetrahedron and add it to the mesh.
450 ///@return The created tetrahedron
451 ///////////////////////////////////////////////////////////////////////////////
453 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
454 const SMDS_MeshNode * n2,
455 const SMDS_MeshNode * n3,
456 const SMDS_MeshNode * n4)
458 int ID = myElementIDFactory->GetFreeID();
459 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, ID);
460 if(v==NULL) myElementIDFactory->ReleaseID(ID);
464 ///////////////////////////////////////////////////////////////////////////////
465 ///Create a new tetrahedron and add it to the mesh.
466 ///@param ID The ID of the new volume
467 ///@return The created tetrahedron or NULL if an element with this ID already exists
468 ///or if input nodes are not found.
469 ///////////////////////////////////////////////////////////////////////////////
471 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
477 SMDS_MeshNode *node1, *node2, *node3, *node4;
478 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
479 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
480 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
481 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
482 if(!node1 || !node2 || !node3 || !node4) return NULL;
483 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, ID);
486 ///////////////////////////////////////////////////////////////////////////////
487 ///Create a new tetrahedron and add it to the mesh.
488 ///@param ID The ID of the new volume
489 ///@return The created tetrahedron
490 ///////////////////////////////////////////////////////////////////////////////
492 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
493 const SMDS_MeshNode * n2,
494 const SMDS_MeshNode * n3,
495 const SMDS_MeshNode * n4,
498 SMDS_MeshVolume* volume = 0;
499 if ( !n1 || !n2 || !n3 || !n4) return volume;
500 if ( myVolumes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
501 if(hasConstructionFaces()) {
502 SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3);
503 SMDS_MeshFace * f2=FindFaceOrCreate(n1,n2,n4);
504 SMDS_MeshFace * f3=FindFaceOrCreate(n1,n3,n4);
505 SMDS_MeshFace * f4=FindFaceOrCreate(n2,n3,n4);
506 volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4);
507 myVolumes.Add(volume);
510 else if(hasConstructionEdges()) {
511 MESSAGE("Error : Not implemented");
515 volume=new SMDS_VolumeOfNodes(n1,n2,n3,n4);
516 myVolumes.Add(volume);
520 if (!registerElement(ID, volume)) {
521 RemoveElement(volume, false);
527 ///////////////////////////////////////////////////////////////////////////////
528 ///Create a new pyramid and add it to the mesh.
529 ///Nodes 1,2,3 and 4 define the base of the pyramid
530 ///@return The created pyramid
531 ///////////////////////////////////////////////////////////////////////////////
533 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
534 const SMDS_MeshNode * n2,
535 const SMDS_MeshNode * n3,
536 const SMDS_MeshNode * n4,
537 const SMDS_MeshNode * n5)
539 int ID = myElementIDFactory->GetFreeID();
540 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, ID);
541 if(v==NULL) myElementIDFactory->ReleaseID(ID);
545 ///////////////////////////////////////////////////////////////////////////////
546 ///Create a new pyramid and add it to the mesh.
547 ///Nodes 1,2,3 and 4 define the base of the pyramid
548 ///@param ID The ID of the new volume
549 ///@return The created pyramid or NULL if an element with this ID already exists
550 ///or if input nodes are not found.
551 ///////////////////////////////////////////////////////////////////////////////
553 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
560 SMDS_MeshNode *node1, *node2, *node3, *node4, *node5;
561 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
562 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
563 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
564 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
565 node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5);
566 if(!node1 || !node2 || !node3 || !node4 || !node5) return NULL;
567 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, ID);
570 ///////////////////////////////////////////////////////////////////////////////
571 ///Create a new pyramid and add it to the mesh.
572 ///Nodes 1,2,3 and 4 define the base of the pyramid
573 ///@param ID The ID of the new volume
574 ///@return The created pyramid
575 ///////////////////////////////////////////////////////////////////////////////
577 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
578 const SMDS_MeshNode * n2,
579 const SMDS_MeshNode * n3,
580 const SMDS_MeshNode * n4,
581 const SMDS_MeshNode * n5,
584 SMDS_MeshVolume* volume = 0;
585 if ( !n1 || !n2 || !n3 || !n4 || !n5) return volume;
586 if ( myVolumes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
587 if(hasConstructionFaces()) {
588 SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3,n4);
589 SMDS_MeshFace * f2=FindFaceOrCreate(n1,n2,n5);
590 SMDS_MeshFace * f3=FindFaceOrCreate(n2,n3,n5);
591 SMDS_MeshFace * f4=FindFaceOrCreate(n3,n4,n5);
592 volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4);
593 myVolumes.Add(volume);
594 myInfo.myNbPyramids++;
596 else if(hasConstructionEdges()) {
597 MESSAGE("Error : Not implemented");
601 volume=new SMDS_VolumeOfNodes(n1,n2,n3,n4,n5);
602 myVolumes.Add(volume);
603 myInfo.myNbPyramids++;
606 if (!registerElement(ID, volume)) {
607 RemoveElement(volume, false);
613 ///////////////////////////////////////////////////////////////////////////////
614 ///Create a new prism and add it to the mesh.
615 ///Nodes 1,2,3 is a triangle and 1,2,5,4 a quadrangle.
616 ///@return The created prism
617 ///////////////////////////////////////////////////////////////////////////////
619 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
620 const SMDS_MeshNode * n2,
621 const SMDS_MeshNode * n3,
622 const SMDS_MeshNode * n4,
623 const SMDS_MeshNode * n5,
624 const SMDS_MeshNode * n6)
626 int ID = myElementIDFactory->GetFreeID();
627 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, ID);
628 if(v==NULL) myElementIDFactory->ReleaseID(ID);
632 ///////////////////////////////////////////////////////////////////////////////
633 ///Create a new prism and add it to the mesh.
634 ///Nodes 1,2,3 is a triangle and 1,2,5,4 a quadrangle.
635 ///@param ID The ID of the new volume
636 ///@return The created prism or NULL if an element with this ID already exists
637 ///or if input nodes are not found.
638 ///////////////////////////////////////////////////////////////////////////////
640 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
648 SMDS_MeshNode *node1, *node2, *node3, *node4, *node5, *node6;
649 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
650 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
651 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
652 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
653 node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5);
654 node6 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode6);
655 if(!node1 || !node2 || !node3 || !node4 || !node5 || !node6) return NULL;
656 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, node6, ID);
659 ///////////////////////////////////////////////////////////////////////////////
660 ///Create a new prism and add it to the mesh.
661 ///Nodes 1,2,3 is a triangle and 1,2,5,4 a quadrangle.
662 ///@param ID The ID of the new volume
663 ///@return The created prism
664 ///////////////////////////////////////////////////////////////////////////////
666 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
667 const SMDS_MeshNode * n2,
668 const SMDS_MeshNode * n3,
669 const SMDS_MeshNode * n4,
670 const SMDS_MeshNode * n5,
671 const SMDS_MeshNode * n6,
674 SMDS_MeshVolume* volume = 0;
675 if ( !n1 || !n2 || !n3 || !n4 || !n5 || !n6) return volume;
676 if ( myVolumes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
677 if(hasConstructionFaces()) {
678 SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3);
679 SMDS_MeshFace * f2=FindFaceOrCreate(n4,n5,n6);
680 SMDS_MeshFace * f3=FindFaceOrCreate(n1,n4,n5,n2);
681 SMDS_MeshFace * f4=FindFaceOrCreate(n2,n5,n6,n3);
682 SMDS_MeshFace * f5=FindFaceOrCreate(n3,n6,n4,n1);
683 volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5);
684 myVolumes.Add(volume);
687 else if(hasConstructionEdges()) {
688 MESSAGE("Error : Not implemented");
692 volume=new SMDS_VolumeOfNodes(n1,n2,n3,n4,n5,n6);
693 myVolumes.Add(volume);
697 if (!registerElement(ID, volume)) {
698 RemoveElement(volume, false);
704 ///////////////////////////////////////////////////////////////////////////////
705 ///Create a new hexahedron and add it to the mesh.
706 ///Nodes 1,2,3,4 and 5,6,7,8 are quadrangle and 5,1 and 7,3 are an edges.
707 ///@return The created hexahedron
708 ///////////////////////////////////////////////////////////////////////////////
710 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
711 const SMDS_MeshNode * n2,
712 const SMDS_MeshNode * n3,
713 const SMDS_MeshNode * n4,
714 const SMDS_MeshNode * n5,
715 const SMDS_MeshNode * n6,
716 const SMDS_MeshNode * n7,
717 const SMDS_MeshNode * n8)
719 int ID = myElementIDFactory->GetFreeID();
720 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, ID);
721 if(v==NULL) myElementIDFactory->ReleaseID(ID);
725 ///////////////////////////////////////////////////////////////////////////////
726 ///Create a new hexahedron and add it to the mesh.
727 ///Nodes 1,2,3,4 and 5,6,7,8 are quadrangle and 5,1 and 7,3 are an edges.
728 ///@param ID The ID of the new volume
729 ///@return The created hexahedron or NULL if an element with this ID already
730 ///exists or if input nodes are not found.
731 ///////////////////////////////////////////////////////////////////////////////
733 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
743 SMDS_MeshNode *node1, *node2, *node3, *node4, *node5, *node6, *node7, *node8;
744 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
745 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
746 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
747 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
748 node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5);
749 node6 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode6);
750 node7 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode7);
751 node8 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode8);
752 if(!node1 || !node2 || !node3 || !node4 || !node5 || !node6 || !node7 || !node8)
754 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, node6,
758 ///////////////////////////////////////////////////////////////////////////////
759 ///Create a new hexahedron and add it to the mesh.
760 ///Nodes 1,2,3,4 and 5,6,7,8 are quadrangle and 5,1 and 7,3 are an edges.
761 ///@param ID The ID of the new volume
762 ///@return The created prism or NULL if an element with this ID already exists
763 ///or if input nodes are not found.
764 ///////////////////////////////////////////////////////////////////////////////
766 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
767 const SMDS_MeshNode * n2,
768 const SMDS_MeshNode * n3,
769 const SMDS_MeshNode * n4,
770 const SMDS_MeshNode * n5,
771 const SMDS_MeshNode * n6,
772 const SMDS_MeshNode * n7,
773 const SMDS_MeshNode * n8,
776 SMDS_MeshVolume* volume = 0;
777 if ( !n1 || !n2 || !n3 || !n4 || !n5 || !n6 || !n7 || !n8) return volume;
778 if ( myVolumes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
779 if(hasConstructionFaces()) {
780 SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3,n4);
781 SMDS_MeshFace * f2=FindFaceOrCreate(n5,n6,n7,n8);
782 SMDS_MeshFace * f3=FindFaceOrCreate(n1,n4,n8,n5);
783 SMDS_MeshFace * f4=FindFaceOrCreate(n1,n2,n6,n5);
784 SMDS_MeshFace * f5=FindFaceOrCreate(n2,n3,n7,n6);
785 SMDS_MeshFace * f6=FindFaceOrCreate(n3,n4,n8,n7);
786 volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5,f6);
787 myVolumes.Add(volume);
790 else if(hasConstructionEdges()) {
791 MESSAGE("Error : Not implemented");
795 // volume=new SMDS_HexahedronOfNodes(n1,n2,n3,n4,n5,n6,n7,n8);
796 volume=new SMDS_VolumeOfNodes(n1,n2,n3,n4,n5,n6,n7,n8);
797 myVolumes.Add(volume);
801 if (!registerElement(ID, volume)) {
802 RemoveElement(volume, false);
808 ///////////////////////////////////////////////////////////////////////////////
809 ///Create a new tetrahedron defined by its faces and add it to the mesh.
810 ///@return The created tetrahedron
811 ///////////////////////////////////////////////////////////////////////////////
813 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshFace * f1,
814 const SMDS_MeshFace * f2,
815 const SMDS_MeshFace * f3,
816 const SMDS_MeshFace * f4)
818 if (!hasConstructionFaces())
820 return AddVolumeWithID(f1,f2,f3,f4, myElementIDFactory->GetFreeID());
823 ///////////////////////////////////////////////////////////////////////////////
824 ///Create a new tetrahedron defined by its faces and add it to the mesh.
825 ///@param ID The ID of the new volume
826 ///@return The created tetrahedron
827 ///////////////////////////////////////////////////////////////////////////////
829 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1,
830 const SMDS_MeshFace * f2,
831 const SMDS_MeshFace * f3,
832 const SMDS_MeshFace * f4,
835 if (!hasConstructionFaces())
837 if ( !f1 || !f2 || !f3 || !f4) return 0;
838 if ( myVolumes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
839 SMDS_MeshVolume * volume = new SMDS_VolumeOfFaces(f1,f2,f3,f4);
840 myVolumes.Add(volume);
843 if (!registerElement(ID, volume)) {
844 RemoveElement(volume, false);
850 ///////////////////////////////////////////////////////////////////////////////
851 ///Create a new pyramid defined by its faces and add it to the mesh.
852 ///@return The created pyramid
853 ///////////////////////////////////////////////////////////////////////////////
855 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshFace * f1,
856 const SMDS_MeshFace * f2,
857 const SMDS_MeshFace * f3,
858 const SMDS_MeshFace * f4,
859 const SMDS_MeshFace * f5)
861 if (!hasConstructionFaces())
863 return AddVolumeWithID(f1,f2,f3,f4,f5, myElementIDFactory->GetFreeID());
866 ///////////////////////////////////////////////////////////////////////////////
867 ///Create a new pyramid defined by its faces and add it to the mesh.
868 ///@param ID The ID of the new volume
869 ///@return The created pyramid
870 ///////////////////////////////////////////////////////////////////////////////
872 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1,
873 const SMDS_MeshFace * f2,
874 const SMDS_MeshFace * f3,
875 const SMDS_MeshFace * f4,
876 const SMDS_MeshFace * f5,
879 if (!hasConstructionFaces())
881 if ( !f1 || !f2 || !f3 || !f4 || !f5) return 0;
882 if ( myVolumes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
883 SMDS_MeshVolume * volume = new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5);
884 myVolumes.Add(volume);
885 myInfo.myNbPyramids++;
887 if (!registerElement(ID, volume)) {
888 RemoveElement(volume, false);
894 ///////////////////////////////////////////////////////////////////////////////
895 ///Create a new prism defined by its faces and add it to the mesh.
896 ///@return The created prism
897 ///////////////////////////////////////////////////////////////////////////////
899 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshFace * f1,
900 const SMDS_MeshFace * f2,
901 const SMDS_MeshFace * f3,
902 const SMDS_MeshFace * f4,
903 const SMDS_MeshFace * f5,
904 const SMDS_MeshFace * f6)
906 if (!hasConstructionFaces())
908 return AddVolumeWithID(f1,f2,f3,f4,f5,f6, myElementIDFactory->GetFreeID());
911 ///////////////////////////////////////////////////////////////////////////////
912 ///Create a new prism defined by its faces and add it to the mesh.
913 ///@param ID The ID of the new volume
914 ///@return The created prism
915 ///////////////////////////////////////////////////////////////////////////////
917 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1,
918 const SMDS_MeshFace * f2,
919 const SMDS_MeshFace * f3,
920 const SMDS_MeshFace * f4,
921 const SMDS_MeshFace * f5,
922 const SMDS_MeshFace * f6,
925 if (!hasConstructionFaces())
927 if ( !f1 || !f2 || !f3 || !f4 || !f5 || !f6) return 0;
928 if ( myVolumes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
929 SMDS_MeshVolume * volume = new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5,f6);
930 myVolumes.Add(volume);
933 if (!registerElement(ID, volume)) {
934 RemoveElement(volume, false);
940 ///////////////////////////////////////////////////////////////////////////////
941 /// Add a polygon defined by its nodes IDs
942 ///////////////////////////////////////////////////////////////////////////////
944 SMDS_MeshFace* SMDS_Mesh::AddPolygonalFaceWithID (std::vector<int> nodes_ids,
947 int nbNodes = nodes_ids.size();
948 std::vector<const SMDS_MeshNode*> nodes (nbNodes);
949 for (int i = 0; i < nbNodes; i++) {
950 nodes[i] = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nodes_ids[i]);
951 if (!nodes[i]) return NULL;
953 return SMDS_Mesh::AddPolygonalFaceWithID(nodes, ID);
956 ///////////////////////////////////////////////////////////////////////////////
957 /// Add a polygon defined by its nodes
958 ///////////////////////////////////////////////////////////////////////////////
960 SMDS_MeshFace* SMDS_Mesh::AddPolygonalFaceWithID
961 (std::vector<const SMDS_MeshNode*> nodes,
964 SMDS_MeshFace * face;
966 if ( myFaces.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
967 if (hasConstructionEdges())
969 MESSAGE("Error : Not implemented");
974 for ( int i = 0; i < nodes.size(); ++i )
975 if ( !nodes[ i ] ) return 0;
976 face = new SMDS_PolygonalFaceOfNodes(nodes);
978 myInfo.myNbPolygons++;
981 if (!registerElement(ID, face)) {
982 RemoveElement(face, false);
988 ///////////////////////////////////////////////////////////////////////////////
989 /// Add a polygon defined by its nodes.
990 /// An ID is automatically affected to the created face.
991 ///////////////////////////////////////////////////////////////////////////////
993 SMDS_MeshFace* SMDS_Mesh::AddPolygonalFace (std::vector<const SMDS_MeshNode*> nodes)
995 return SMDS_Mesh::AddPolygonalFaceWithID(nodes, myElementIDFactory->GetFreeID());
998 ///////////////////////////////////////////////////////////////////////////////
999 /// Create a new polyhedral volume and add it to the mesh.
1000 /// @param ID The ID of the new volume
1001 /// @return The created volume or NULL if an element with this ID already exists
1002 /// or if input nodes are not found.
1003 ///////////////////////////////////////////////////////////////////////////////
1005 SMDS_MeshVolume * SMDS_Mesh::AddPolyhedralVolumeWithID
1006 (std::vector<int> nodes_ids,
1007 std::vector<int> quantities,
1010 int nbNodes = nodes_ids.size();
1011 std::vector<const SMDS_MeshNode*> nodes (nbNodes);
1012 for (int i = 0; i < nbNodes; i++) {
1013 nodes[i] = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nodes_ids[i]);
1014 if (!nodes[i]) return NULL;
1016 return SMDS_Mesh::AddPolyhedralVolumeWithID(nodes, quantities, ID);
1019 ///////////////////////////////////////////////////////////////////////////////
1020 /// Create a new polyhedral volume and add it to the mesh.
1021 /// @param ID The ID of the new volume
1022 /// @return The created volume
1023 ///////////////////////////////////////////////////////////////////////////////
1025 SMDS_MeshVolume* SMDS_Mesh::AddPolyhedralVolumeWithID
1026 (std::vector<const SMDS_MeshNode*> nodes,
1027 std::vector<int> quantities,
1030 SMDS_MeshVolume* volume;
1031 if ( myVolumes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1032 if (hasConstructionFaces()) {
1033 MESSAGE("Error : Not implemented");
1035 } else if (hasConstructionEdges()) {
1036 MESSAGE("Error : Not implemented");
1039 for ( int i = 0; i < nodes.size(); ++i )
1040 if ( !nodes[ i ] ) return 0;
1041 volume = new SMDS_PolyhedralVolumeOfNodes(nodes, quantities);
1042 myVolumes.Add(volume);
1043 myInfo.myNbPolyhedrons++;
1046 if (!registerElement(ID, volume)) {
1047 RemoveElement(volume, false);
1053 ///////////////////////////////////////////////////////////////////////////////
1054 /// Create a new polyhedral volume and add it to the mesh.
1055 /// @return The created volume
1056 ///////////////////////////////////////////////////////////////////////////////
1058 SMDS_MeshVolume* SMDS_Mesh::AddPolyhedralVolume
1059 (std::vector<const SMDS_MeshNode*> nodes,
1060 std::vector<int> quantities)
1062 int ID = myElementIDFactory->GetFreeID();
1063 SMDS_MeshVolume * v = SMDS_Mesh::AddPolyhedralVolumeWithID(nodes, quantities, ID);
1064 if (v == NULL) myElementIDFactory->ReleaseID(ID);
1068 ///////////////////////////////////////////////////////////////////////////////
1069 /// Registers element with the given ID, maintains inverse connections
1070 ///////////////////////////////////////////////////////////////////////////////
1071 bool SMDS_Mesh::registerElement(int ID, SMDS_MeshElement * element)
1073 if (myElementIDFactory->BindID(ID, element)) {
1074 SMDS_ElemIteratorPtr it = element->nodesIterator();
1075 while (it->more()) {
1076 SMDS_MeshNode *node = static_cast<SMDS_MeshNode*>
1077 (const_cast<SMDS_MeshElement*>(it->next()));
1078 node->AddInverseElement(element);
1085 ///////////////////////////////////////////////////////////////////////////////
1086 /// Return the node whose ID is 'ID'.
1087 ///////////////////////////////////////////////////////////////////////////////
1088 const SMDS_MeshNode * SMDS_Mesh::FindNode(int ID) const
1090 return (const SMDS_MeshNode *)myNodeIDFactory->MeshElement(ID);
1093 ///////////////////////////////////////////////////////////////////////////////
1094 ///Create a triangle and add it to the current mesh. This methode do not bind a
1095 ///ID to the create triangle.
1096 ///////////////////////////////////////////////////////////////////////////////
1097 SMDS_MeshFace * SMDS_Mesh::createTriangle(const SMDS_MeshNode * node1,
1098 const SMDS_MeshNode * node2,
1099 const SMDS_MeshNode * node3)
1101 if ( !node1 || !node2 || !node3) return 0;
1102 if ( myFaces.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1103 if(hasConstructionEdges())
1105 SMDS_MeshEdge *edge1, *edge2, *edge3;
1106 edge1=FindEdgeOrCreate(node1,node2);
1107 edge2=FindEdgeOrCreate(node2,node3);
1108 edge3=FindEdgeOrCreate(node3,node1);
1110 SMDS_MeshFace * face = new SMDS_FaceOfEdges(edge1,edge2,edge3);
1112 myInfo.myNbTriangles++;
1117 SMDS_MeshFace * face = new SMDS_FaceOfNodes(node1,node2,node3);
1119 myInfo.myNbTriangles++;
1124 ///////////////////////////////////////////////////////////////////////////////
1125 ///Create a quadrangle and add it to the current mesh. This methode do not bind
1126 ///a ID to the create triangle.
1127 ///////////////////////////////////////////////////////////////////////////////
1128 SMDS_MeshFace * SMDS_Mesh::createQuadrangle(const SMDS_MeshNode * node1,
1129 const SMDS_MeshNode * node2,
1130 const SMDS_MeshNode * node3,
1131 const SMDS_MeshNode * node4)
1133 if ( !node1 || !node2 || !node3 || !node4 ) return 0;
1134 if ( myFaces.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1135 if(hasConstructionEdges())
1137 SMDS_MeshEdge *edge1, *edge2, *edge3, *edge4;
1138 edge1=FindEdgeOrCreate(node1,node2);
1139 edge2=FindEdgeOrCreate(node2,node3);
1140 edge3=FindEdgeOrCreate(node3,node4);
1141 edge4=FindEdgeOrCreate(node4,node1);
1143 SMDS_MeshFace * face = new SMDS_FaceOfEdges(edge1,edge2,edge3,edge4);
1145 myInfo.myNbQuadrangles++;
1150 SMDS_MeshFace * face = new SMDS_FaceOfNodes(node1,node2,node3,node4);
1152 myInfo.myNbQuadrangles++;
1157 ///////////////////////////////////////////////////////////////////////////////
1158 /// Remove a node and all the elements which own this node
1159 ///////////////////////////////////////////////////////////////////////////////
1161 void SMDS_Mesh::RemoveNode(const SMDS_MeshNode * node)
1163 RemoveElement(node, true);
1166 ///////////////////////////////////////////////////////////////////////////////
1167 /// Remove an edge and all the elements which own this edge
1168 ///////////////////////////////////////////////////////////////////////////////
1170 void SMDS_Mesh::Remove0DElement(const SMDS_Mesh0DElement * elem0d)
1172 RemoveElement(elem0d,true);
1175 ///////////////////////////////////////////////////////////////////////////////
1176 /// Remove an edge and all the elements which own this edge
1177 ///////////////////////////////////////////////////////////////////////////////
1179 void SMDS_Mesh::RemoveEdge(const SMDS_MeshEdge * edge)
1181 RemoveElement(edge,true);
1184 ///////////////////////////////////////////////////////////////////////////////
1185 /// Remove an face and all the elements which own this face
1186 ///////////////////////////////////////////////////////////////////////////////
1188 void SMDS_Mesh::RemoveFace(const SMDS_MeshFace * face)
1190 RemoveElement(face, true);
1193 ///////////////////////////////////////////////////////////////////////////////
1195 ///////////////////////////////////////////////////////////////////////////////
1197 void SMDS_Mesh::RemoveVolume(const SMDS_MeshVolume * volume)
1199 RemoveElement(volume, true);
1202 //=======================================================================
1203 //function : RemoveFromParent
1205 //=======================================================================
1207 bool SMDS_Mesh::RemoveFromParent()
1209 if (myParent==NULL) return false;
1210 else return (myParent->RemoveSubMesh(this));
1213 //=======================================================================
1214 //function : RemoveSubMesh
1216 //=======================================================================
1218 bool SMDS_Mesh::RemoveSubMesh(const SMDS_Mesh * aMesh)
1222 list<SMDS_Mesh *>::iterator itmsh=myChildren.begin();
1223 for (; itmsh!=myChildren.end() && !found; itmsh++)
1225 SMDS_Mesh * submesh = *itmsh;
1226 if (submesh == aMesh)
1229 myChildren.erase(itmsh);
1236 //=======================================================================
1237 //function : ChangeElementNodes
1239 //=======================================================================
1241 bool SMDS_Mesh::ChangeElementNodes(const SMDS_MeshElement * element,
1242 const SMDS_MeshNode * nodes[],
1245 // keep current nodes of elem
1246 set<const SMDS_MeshElement*> oldNodes;
1247 SMDS_ElemIteratorPtr itn = element->nodesIterator();
1249 oldNodes.insert( itn->next() );
1251 if ( !element->IsPoly() )
1252 myInfo.remove( element ); // element may change type
1256 SMDS_MeshElement* elem = const_cast<SMDS_MeshElement*>(element);
1257 switch ( elem->GetType() )
1259 case SMDSAbs_0DElement: {
1260 if ( SMDS_Mesh0DElement* elem0d = dynamic_cast<SMDS_Mesh0DElement*>( elem ))
1261 Ok = elem0d->ChangeNode( nodes[0] );
1264 case SMDSAbs_Edge: {
1265 if ( nbnodes == 2 ) {
1266 if ( SMDS_MeshEdge* edge = dynamic_cast<SMDS_MeshEdge*>( elem ))
1267 Ok = edge->ChangeNodes( nodes[0], nodes[1] );
1269 else if ( nbnodes == 3 ) {
1270 if ( SMDS_QuadraticEdge* edge = dynamic_cast<SMDS_QuadraticEdge*>( elem ))
1271 Ok = edge->ChangeNodes( nodes[0], nodes[1], nodes[2] );
1275 case SMDSAbs_Face: {
1276 if ( SMDS_FaceOfNodes* face = dynamic_cast<SMDS_FaceOfNodes*>( elem ))
1277 Ok = face->ChangeNodes( nodes, nbnodes );
1279 if ( SMDS_QuadraticFaceOfNodes* QF = dynamic_cast<SMDS_QuadraticFaceOfNodes*>( elem ))
1280 Ok = QF->ChangeNodes( nodes, nbnodes );
1282 if (SMDS_PolygonalFaceOfNodes* face = dynamic_cast<SMDS_PolygonalFaceOfNodes*>(elem))
1283 Ok = face->ChangeNodes(nodes, nbnodes);
1286 case SMDSAbs_Volume: {
1287 if ( SMDS_VolumeOfNodes* vol = dynamic_cast<SMDS_VolumeOfNodes*>( elem ))
1288 Ok = vol->ChangeNodes( nodes, nbnodes );
1290 if ( SMDS_QuadraticVolumeOfNodes* QV = dynamic_cast<SMDS_QuadraticVolumeOfNodes*>( elem ))
1291 Ok = QV->ChangeNodes( nodes, nbnodes );
1295 MESSAGE ( "WRONG ELEM TYPE");
1298 if ( Ok ) { // update InverseElements
1300 set<const SMDS_MeshElement*>::iterator it;
1302 // AddInverseElement to new nodes
1303 for ( int i = 0; i < nbnodes; i++ ) {
1304 it = oldNodes.find( nodes[i] );
1305 if ( it == oldNodes.end() )
1307 const_cast<SMDS_MeshNode*>( nodes[i] )->AddInverseElement( elem );
1309 // remove from oldNodes a node that remains in elem
1310 oldNodes.erase( it );
1312 // RemoveInverseElement from the nodes removed from elem
1313 for ( it = oldNodes.begin(); it != oldNodes.end(); it++ )
1315 SMDS_MeshNode * n = static_cast<SMDS_MeshNode *>
1316 (const_cast<SMDS_MeshElement *>( *it ));
1317 n->RemoveInverseElement( elem );
1321 if ( !element->IsPoly() )
1322 myInfo.add( element ); // element may change type
1327 //=======================================================================
1328 //function : ChangePolyhedronNodes
1329 //purpose : to change nodes of polyhedral volume
1330 //=======================================================================
1331 bool SMDS_Mesh::ChangePolyhedronNodes (const SMDS_MeshElement * elem,
1332 const vector<const SMDS_MeshNode*>& nodes,
1333 const vector<int> & quantities)
1335 if (elem->GetType() != SMDSAbs_Volume) {
1336 MESSAGE("WRONG ELEM TYPE");
1340 const SMDS_PolyhedralVolumeOfNodes* vol = dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*>(elem);
1345 // keep current nodes of elem
1346 set<const SMDS_MeshElement*> oldNodes;
1347 SMDS_ElemIteratorPtr itn = elem->nodesIterator();
1348 while (itn->more()) {
1349 oldNodes.insert(itn->next());
1353 bool Ok = const_cast<SMDS_PolyhedralVolumeOfNodes*>(vol)->ChangeNodes(nodes, quantities);
1358 // update InverseElements
1360 // AddInverseElement to new nodes
1361 int nbnodes = nodes.size();
1362 set<const SMDS_MeshElement*>::iterator it;
1363 for (int i = 0; i < nbnodes; i++) {
1364 it = oldNodes.find(nodes[i]);
1365 if (it == oldNodes.end()) {
1367 const_cast<SMDS_MeshNode*>(nodes[i])->AddInverseElement(elem);
1369 // remove from oldNodes a node that remains in elem
1374 // RemoveInverseElement from the nodes removed from elem
1375 for (it = oldNodes.begin(); it != oldNodes.end(); it++) {
1376 SMDS_MeshNode * n = static_cast<SMDS_MeshNode *>
1377 (const_cast<SMDS_MeshElement *>( *it ));
1378 n->RemoveInverseElement(elem);
1385 //=======================================================================
1386 //function : Find0DElement
1388 //=======================================================================
1389 const SMDS_Mesh0DElement* SMDS_Mesh::Find0DElement(int idnode) const
1391 const SMDS_MeshNode * node = FindNode(idnode);
1392 if(node == NULL) return NULL;
1393 return Find0DElement(node);
1396 const SMDS_Mesh0DElement* SMDS_Mesh::Find0DElement(const SMDS_MeshNode * node)
1398 if (!node) return 0;
1399 const SMDS_Mesh0DElement* toReturn = NULL;
1400 SMDS_ElemIteratorPtr it1 = node->GetInverseElementIterator(SMDSAbs_0DElement);
1401 while (it1->more() && (toReturn == NULL)) {
1402 const SMDS_MeshElement* e = it1->next();
1403 if (e->NbNodes() == 1) {
1404 toReturn = static_cast<const SMDS_Mesh0DElement*>(e);
1410 //=======================================================================
1411 //function : Find0DElementOrCreate
1413 //=======================================================================
1414 SMDS_Mesh0DElement* SMDS_Mesh::Find0DElementOrCreate(const SMDS_MeshNode * node)
1416 if (!node) return 0;
1417 SMDS_Mesh0DElement * toReturn = NULL;
1418 toReturn = const_cast<SMDS_Mesh0DElement*>(Find0DElement(node));
1419 if (toReturn == NULL) {
1420 if (my0DElements.Extent() % CHECKMEMORY_INTERVAL == 0) CheckMemory();
1421 toReturn = new SMDS_Mesh0DElement(node);
1422 my0DElements.Add(toReturn);
1423 myInfo.myNb0DElements++;
1429 //=======================================================================
1430 //function : FindEdge
1432 //=======================================================================
1434 const SMDS_MeshEdge* SMDS_Mesh::FindEdge(int idnode1, int idnode2) const
1436 const SMDS_MeshNode * node1=FindNode(idnode1);
1437 const SMDS_MeshNode * node2=FindNode(idnode2);
1438 if((node1==NULL)||(node2==NULL)) return NULL;
1439 return FindEdge(node1,node2);
1442 //#include "Profiler.h"
1443 const SMDS_MeshEdge* SMDS_Mesh::FindEdge(const SMDS_MeshNode * node1,
1444 const SMDS_MeshNode * node2)
1446 if ( !node1 ) return 0;
1447 const SMDS_MeshEdge * toReturn=NULL;
1450 SMDS_ElemIteratorPtr it1=node1->GetInverseElementIterator(SMDSAbs_Edge);
1453 while(it1->more()) {
1454 const SMDS_MeshElement * e = it1->next();
1455 if ( e->NbNodes() == 2 && e->GetNodeIndex( node2 ) >= 0 ) {
1456 toReturn = static_cast<const SMDS_MeshEdge*>( e );
1465 //=======================================================================
1466 //function : FindEdgeOrCreate
1468 //=======================================================================
1470 SMDS_MeshEdge* SMDS_Mesh::FindEdgeOrCreate(const SMDS_MeshNode * node1,
1471 const SMDS_MeshNode * node2)
1473 if ( !node1 || !node2) return 0;
1474 SMDS_MeshEdge * toReturn=NULL;
1475 toReturn=const_cast<SMDS_MeshEdge*>(FindEdge(node1,node2));
1476 if(toReturn==NULL) {
1477 if ( myEdges.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1478 toReturn=new SMDS_MeshEdge(node1,node2);
1479 myEdges.Add(toReturn);
1486 //=======================================================================
1487 //function : FindEdge
1489 //=======================================================================
1491 const SMDS_MeshEdge* SMDS_Mesh::FindEdge(int idnode1, int idnode2,
1494 const SMDS_MeshNode * node1=FindNode(idnode1);
1495 const SMDS_MeshNode * node2=FindNode(idnode2);
1496 const SMDS_MeshNode * node3=FindNode(idnode3);
1497 return FindEdge(node1,node2,node3);
1500 const SMDS_MeshEdge* SMDS_Mesh::FindEdge(const SMDS_MeshNode * node1,
1501 const SMDS_MeshNode * node2,
1502 const SMDS_MeshNode * node3)
1504 if ( !node1 ) return 0;
1505 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Edge);
1506 while(it1->more()) {
1507 const SMDS_MeshElement * e = it1->next();
1508 if ( e->NbNodes() == 3 ) {
1509 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
1510 while(it2->more()) {
1511 const SMDS_MeshElement* n = it2->next();
1521 return static_cast<const SMDS_MeshEdge *> (e);
1528 //=======================================================================
1529 //function : FindFace
1531 //=======================================================================
1533 const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2,
1536 const SMDS_MeshNode * node1=FindNode(idnode1);
1537 const SMDS_MeshNode * node2=FindNode(idnode2);
1538 const SMDS_MeshNode * node3=FindNode(idnode3);
1539 return FindFace(node1, node2, node3);
1542 const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1,
1543 const SMDS_MeshNode *node2,
1544 const SMDS_MeshNode *node3)
1546 if ( !node1 ) return 0;
1547 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Face);
1548 while(it1->more()) {
1549 const SMDS_MeshElement * e = it1->next();
1550 if ( e->NbNodes() == 3 ) {
1551 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
1552 while(it2->more()) {
1553 const SMDS_MeshElement* n = it2->next();
1563 return static_cast<const SMDS_MeshFace *> (e);
1569 SMDS_MeshFace* SMDS_Mesh::FindFaceOrCreate(const SMDS_MeshNode *node1,
1570 const SMDS_MeshNode *node2,
1571 const SMDS_MeshNode *node3)
1573 SMDS_MeshFace * toReturn=NULL;
1574 toReturn = const_cast<SMDS_MeshFace*>(FindFace(node1,node2,node3));
1575 if(toReturn==NULL) {
1576 toReturn = createTriangle(node1,node2,node3);
1582 //=======================================================================
1583 //function : FindFace
1585 //=======================================================================
1587 const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2,
1588 int idnode3, int idnode4) const
1590 const SMDS_MeshNode * node1=FindNode(idnode1);
1591 const SMDS_MeshNode * node2=FindNode(idnode2);
1592 const SMDS_MeshNode * node3=FindNode(idnode3);
1593 const SMDS_MeshNode * node4=FindNode(idnode4);
1594 return FindFace(node1, node2, node3, node4);
1597 const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1,
1598 const SMDS_MeshNode *node2,
1599 const SMDS_MeshNode *node3,
1600 const SMDS_MeshNode *node4)
1602 if ( !node1 ) return 0;
1603 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Face);
1604 while(it1->more()) {
1605 const SMDS_MeshElement * e = it1->next();
1606 if ( e->NbNodes() == 4 ) {
1607 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
1608 while(it2->more()) {
1609 const SMDS_MeshElement* n = it2->next();
1620 return static_cast<const SMDS_MeshFace *> (e);
1626 SMDS_MeshFace* SMDS_Mesh::FindFaceOrCreate(const SMDS_MeshNode *node1,
1627 const SMDS_MeshNode *node2,
1628 const SMDS_MeshNode *node3,
1629 const SMDS_MeshNode *node4)
1631 SMDS_MeshFace * toReturn=NULL;
1632 toReturn=const_cast<SMDS_MeshFace*>(FindFace(node1,node2,node3,node4));
1633 if(toReturn==NULL) {
1634 toReturn=createQuadrangle(node1,node2,node3,node4);
1640 //=======================================================================
1641 //function : FindFace
1642 //purpose :quadratic triangle
1643 //=======================================================================
1645 const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2,
1646 int idnode3, int idnode4,
1647 int idnode5, int idnode6) const
1649 const SMDS_MeshNode * node1 = FindNode(idnode1);
1650 const SMDS_MeshNode * node2 = FindNode(idnode2);
1651 const SMDS_MeshNode * node3 = FindNode(idnode3);
1652 const SMDS_MeshNode * node4 = FindNode(idnode4);
1653 const SMDS_MeshNode * node5 = FindNode(idnode5);
1654 const SMDS_MeshNode * node6 = FindNode(idnode6);
1655 return FindFace(node1, node2, node3, node4, node5, node6);
1658 const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1,
1659 const SMDS_MeshNode *node2,
1660 const SMDS_MeshNode *node3,
1661 const SMDS_MeshNode *node4,
1662 const SMDS_MeshNode *node5,
1663 const SMDS_MeshNode *node6)
1665 if ( !node1 ) return 0;
1666 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Face);
1667 while(it1->more()) {
1668 const SMDS_MeshElement * e = it1->next();
1669 if ( e->NbNodes() == 6 ) {
1670 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
1671 while(it2->more()) {
1672 const SMDS_MeshElement* n = it2->next();
1685 return static_cast<const SMDS_MeshFace *> (e);
1692 //=======================================================================
1693 //function : FindFace
1694 //purpose : quadratic quadrangle
1695 //=======================================================================
1697 const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2,
1698 int idnode3, int idnode4,
1699 int idnode5, int idnode6,
1700 int idnode7, int idnode8) const
1702 const SMDS_MeshNode * node1 = FindNode(idnode1);
1703 const SMDS_MeshNode * node2 = FindNode(idnode2);
1704 const SMDS_MeshNode * node3 = FindNode(idnode3);
1705 const SMDS_MeshNode * node4 = FindNode(idnode4);
1706 const SMDS_MeshNode * node5 = FindNode(idnode5);
1707 const SMDS_MeshNode * node6 = FindNode(idnode6);
1708 const SMDS_MeshNode * node7 = FindNode(idnode7);
1709 const SMDS_MeshNode * node8 = FindNode(idnode8);
1710 return FindFace(node1, node2, node3, node4, node5, node6, node7, node8);
1713 const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1,
1714 const SMDS_MeshNode *node2,
1715 const SMDS_MeshNode *node3,
1716 const SMDS_MeshNode *node4,
1717 const SMDS_MeshNode *node5,
1718 const SMDS_MeshNode *node6,
1719 const SMDS_MeshNode *node7,
1720 const SMDS_MeshNode *node8)
1722 if ( !node1 ) return 0;
1723 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Face);
1724 while(it1->more()) {
1725 const SMDS_MeshElement * e = it1->next();
1726 if ( e->NbNodes() == 8 ) {
1727 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
1728 while(it2->more()) {
1729 const SMDS_MeshElement* n = it2->next();
1744 return static_cast<const SMDS_MeshFace *> (e);
1751 //=======================================================================
1752 //function : FindElement
1754 //=======================================================================
1756 const SMDS_MeshElement* SMDS_Mesh::FindElement(int IDelem) const
1758 return myElementIDFactory->MeshElement(IDelem);
1761 //=======================================================================
1762 //function : FindFace
1763 //purpose : find polygon
1764 //=======================================================================
1766 const SMDS_MeshFace* SMDS_Mesh::FindFace (const std::vector<int>& nodes_ids) const
1768 int nbnodes = nodes_ids.size();
1769 std::vector<const SMDS_MeshNode *> poly_nodes (nbnodes);
1770 for (int inode = 0; inode < nbnodes; inode++) {
1771 const SMDS_MeshNode * node = FindNode(nodes_ids[inode]);
1772 if (node == NULL) return NULL;
1773 poly_nodes[inode] = node;
1775 return FindFace(poly_nodes);
1778 const SMDS_MeshFace* SMDS_Mesh::FindFace (const std::vector<const SMDS_MeshNode *>& nodes)
1780 if ( nodes.size() > 2 && nodes[0] ) {
1781 SMDS_ElemIteratorPtr itF = nodes[0]->GetInverseElementIterator(SMDSAbs_Face);
1782 while (itF->more()) {
1783 const SMDS_MeshElement* f = itF->next();
1784 if ( f->NbNodes() == nodes.size() ) {
1785 for ( int i = 1; f && i < nodes.size(); ++ i )
1786 if ( f->GetNodeIndex( nodes[ i ]) < 0 )
1789 return static_cast<const SMDS_MeshFace *> (f);
1796 //=======================================================================
1797 //function : DumpNodes
1799 //=======================================================================
1801 void SMDS_Mesh::DumpNodes() const
1803 MESSAGE("dump nodes of mesh : ");
1804 SMDS_NodeIteratorPtr itnode=nodesIterator();
1805 while(itnode->more()) MESSAGE(itnode->next());
1808 //=======================================================================
1809 //function : Dump0DElements
1811 //=======================================================================
1812 void SMDS_Mesh::Dump0DElements() const
1814 MESSAGE("dump 0D elements of mesh : ");
1815 SMDS_0DElementIteratorPtr it0d = elements0dIterator();
1816 while(it0d->more()) MESSAGE(it0d->next());
1819 //=======================================================================
1820 //function : DumpEdges
1822 //=======================================================================
1824 void SMDS_Mesh::DumpEdges() const
1826 MESSAGE("dump edges of mesh : ");
1827 SMDS_EdgeIteratorPtr itedge=edgesIterator();
1828 while(itedge->more()) MESSAGE(itedge->next());
1831 //=======================================================================
1832 //function : DumpFaces
1834 //=======================================================================
1836 void SMDS_Mesh::DumpFaces() const
1838 MESSAGE("dump faces of mesh : ");
1839 SMDS_FaceIteratorPtr itface=facesIterator();
1840 while(itface->more()) MESSAGE(itface->next());
1843 //=======================================================================
1844 //function : DumpVolumes
1846 //=======================================================================
1848 void SMDS_Mesh::DumpVolumes() const
1850 MESSAGE("dump volumes of mesh : ");
1851 SMDS_VolumeIteratorPtr itvol=volumesIterator();
1852 while(itvol->more()) MESSAGE(itvol->next());
1855 //=======================================================================
1856 //function : DebugStats
1858 //=======================================================================
1860 void SMDS_Mesh::DebugStats() const
1862 MESSAGE("Debug stats of mesh : ");
1864 MESSAGE("===== NODES ====="<<NbNodes());
1865 MESSAGE("===== 0DELEMS ====="<<Nb0DElements());
1866 MESSAGE("===== EDGES ====="<<NbEdges());
1867 MESSAGE("===== FACES ====="<<NbFaces());
1868 MESSAGE("===== VOLUMES ====="<<NbVolumes());
1870 MESSAGE("End Debug stats of mesh ");
1874 SMDS_NodeIteratorPtr itnode=nodesIterator();
1875 int sizeofnodes = 0;
1876 int sizeoffaces = 0;
1878 while(itnode->more())
1880 const SMDS_MeshNode *node = itnode->next();
1882 sizeofnodes += sizeof(*node);
1884 SMDS_ElemIteratorPtr it = node->GetInverseElementIterator();
1887 const SMDS_MeshElement *me = it->next();
1888 sizeofnodes += sizeof(me);
1892 SMDS_FaceIteratorPtr itface=facesIterator();
1893 while(itface->more())
1895 const SMDS_MeshElement *face = itface->next();
1896 sizeoffaces += sizeof(*face);
1899 MESSAGE("total size of node elements = " << sizeofnodes);;
1900 MESSAGE("total size of face elements = " << sizeoffaces);;
1905 ///////////////////////////////////////////////////////////////////////////////
1906 /// Return the number of nodes
1907 ///////////////////////////////////////////////////////////////////////////////
1908 int SMDS_Mesh::NbNodes() const
1910 return myNodes.Size();
1913 ///////////////////////////////////////////////////////////////////////////////
1914 /// Return the number of 0D elements
1915 ///////////////////////////////////////////////////////////////////////////////
1916 int SMDS_Mesh::Nb0DElements() const
1918 return my0DElements.Size();
1921 ///////////////////////////////////////////////////////////////////////////////
1922 /// Return the number of edges (including construction edges)
1923 ///////////////////////////////////////////////////////////////////////////////
1924 int SMDS_Mesh::NbEdges() const
1926 return myEdges.Size();
1929 ///////////////////////////////////////////////////////////////////////////////
1930 /// Return the number of faces (including construction faces)
1931 ///////////////////////////////////////////////////////////////////////////////
1932 int SMDS_Mesh::NbFaces() const
1934 return myFaces.Size();
1937 ///////////////////////////////////////////////////////////////////////////////
1938 /// Return the number of volumes
1939 ///////////////////////////////////////////////////////////////////////////////
1940 int SMDS_Mesh::NbVolumes() const
1942 return myVolumes.Size();
1945 ///////////////////////////////////////////////////////////////////////////////
1946 /// Return the number of child mesh of this mesh.
1947 /// Note that the tree structure of SMDS_Mesh seems to be unused in this version
1948 /// (2003-09-08) of SMESH
1949 ///////////////////////////////////////////////////////////////////////////////
1950 int SMDS_Mesh::NbSubMesh() const
1952 return myChildren.size();
1955 ///////////////////////////////////////////////////////////////////////////////
1956 /// Destroy the mesh and all its elements
1957 /// All pointer on elements owned by this mesh become illegals.
1958 ///////////////////////////////////////////////////////////////////////////////
1959 SMDS_Mesh::~SMDS_Mesh()
1961 list<SMDS_Mesh*>::iterator itc=myChildren.begin();
1962 while(itc!=myChildren.end())
1970 delete myNodeIDFactory;
1971 delete myElementIDFactory;
1975 SMDS_ElemIteratorPtr eIt = elementsIterator();
1976 while ( eIt->more() )
1977 myElementIDFactory->ReleaseID(eIt->next()->GetID());
1978 SMDS_NodeIteratorPtr itn = nodesIterator();
1980 myNodeIDFactory->ReleaseID(itn->next()->GetID());
1983 SetOfNodes::Iterator itn(myNodes);
1984 for (; itn.More(); itn.Next())
1987 SetOf0DElements::Iterator it0d (my0DElements);
1988 for (; it0d.More(); it0d.Next())
1990 SMDS_MeshElement* elem = it0d.Value();
1994 SetOfEdges::Iterator ite(myEdges);
1995 for (; ite.More(); ite.Next())
1997 SMDS_MeshElement* elem = ite.Value();
2001 SetOfFaces::Iterator itf(myFaces);
2002 for (; itf.More(); itf.Next())
2004 SMDS_MeshElement* elem = itf.Value();
2008 SetOfVolumes::Iterator itv(myVolumes);
2009 for (; itv.More(); itv.Next())
2011 SMDS_MeshElement* elem = itv.Value();
2016 //================================================================================
2018 * \brief Clear all data
2020 //================================================================================
2022 void SMDS_Mesh::Clear()
2024 if (myParent!=NULL) {
2025 SMDS_ElemIteratorPtr eIt = elementsIterator();
2026 while ( eIt->more() )
2027 myElementIDFactory->ReleaseID(eIt->next()->GetID());
2028 SMDS_NodeIteratorPtr itn = nodesIterator();
2030 myNodeIDFactory->ReleaseID(itn->next()->GetID());
2033 myNodeIDFactory->Clear();
2034 myElementIDFactory->Clear();
2037 SMDS_VolumeIteratorPtr itv = volumesIterator();
2042 SMDS_FaceIteratorPtr itf = facesIterator();
2047 SMDS_EdgeIteratorPtr ite = edgesIterator();
2052 SMDS_0DElementIteratorPtr it0d = elements0dIterator();
2053 while (it0d->more())
2054 delete it0d->next();
2055 my0DElements.Clear();
2057 SMDS_NodeIteratorPtr itn = nodesIterator();
2062 list<SMDS_Mesh*>::iterator itc=myChildren.begin();
2063 while(itc!=myChildren.end())
2069 ///////////////////////////////////////////////////////////////////////////////
2070 /// Return true if this mesh create faces with edges.
2071 /// A false returned value mean that faces are created with nodes. A concequence
2072 /// is, iteration on edges (SMDS_Element::edgesIterator) will be unavailable.
2073 ///////////////////////////////////////////////////////////////////////////////
2074 bool SMDS_Mesh::hasConstructionEdges()
2076 return myHasConstructionEdges;
2079 ///////////////////////////////////////////////////////////////////////////////
2080 /// Return true if this mesh create volumes with faces
2081 /// A false returned value mean that volumes are created with nodes or edges.
2082 /// (see hasConstructionEdges)
2083 /// A concequence is, iteration on faces (SMDS_Element::facesIterator) will be
2085 ///////////////////////////////////////////////////////////////////////////////
2086 bool SMDS_Mesh::hasConstructionFaces()
2088 return myHasConstructionFaces;
2091 ///////////////////////////////////////////////////////////////////////////////
2092 /// Return true if nodes are linked to the finit elements, they are belonging to.
2093 /// Currently, It always return true.
2094 ///////////////////////////////////////////////////////////////////////////////
2095 bool SMDS_Mesh::hasInverseElements()
2097 return myHasInverseElements;
2100 ///////////////////////////////////////////////////////////////////////////////
2101 /// Make this mesh creating construction edges (see hasConstructionEdges)
2102 /// @param b true to have construction edges, else false.
2103 ///////////////////////////////////////////////////////////////////////////////
2104 void SMDS_Mesh::setConstructionEdges(bool b)
2106 myHasConstructionEdges=b;
2109 ///////////////////////////////////////////////////////////////////////////////
2110 /// Make this mesh creating construction faces (see hasConstructionFaces)
2111 /// @param b true to have construction faces, else false.
2112 ///////////////////////////////////////////////////////////////////////////////
2113 void SMDS_Mesh::setConstructionFaces(bool b)
2115 myHasConstructionFaces=b;
2118 ///////////////////////////////////////////////////////////////////////////////
2119 /// Make this mesh creating link from nodes to elements (see hasInverseElements)
2120 /// @param b true to link nodes to elements, else false.
2121 ///////////////////////////////////////////////////////////////////////////////
2122 void SMDS_Mesh::setInverseElements(bool b)
2124 if(!b) MESSAGE("Error : inverseElement=false not implemented");
2125 myHasInverseElements=b;
2130 ///////////////////////////////////////////////////////////////////////////////
2131 ///Iterator on NCollection_Map
2132 ///////////////////////////////////////////////////////////////////////////////
2133 template <class MAP, typename ELEM=const SMDS_MeshElement*, class FATHER=SMDS_ElemIterator>
2134 struct MYNCollection_Map_Iterator: public FATHER
2136 typename MAP::Iterator myIterator;
2138 MYNCollection_Map_Iterator(const MAP& map):myIterator(map){}
2142 while(myIterator.More())
2144 if(myIterator.Value()->GetID()!=-1)
2153 ELEM current = (ELEM) myIterator.Value();
2158 //================================================================================
2160 * \brief Iterator on elements in id increasing order
2162 //================================================================================
2164 template <typename ELEM=const SMDS_MeshElement*>
2165 class IdSortedIterator : public SMDS_Iterator<ELEM>
2167 const SMDS_MeshElementIDFactory& myIDFact;
2172 IdSortedIterator(const SMDS_MeshElementIDFactory& fact)
2173 :myIDFact( fact ), myID(1), myMaxID( myIDFact.GetMaxID() ), myElem(0)
2183 ELEM current = myElem;
2184 for ( myElem = 0; myID <= myMaxID && !myElem; ++myID )
2185 myElem = (ELEM) myIDFact.MeshElement( myID );
2191 ///////////////////////////////////////////////////////////////////////////////
2192 /// Return an iterator on nodes of the current mesh factory
2193 ///////////////////////////////////////////////////////////////////////////////
2195 SMDS_NodeIteratorPtr SMDS_Mesh::nodesIterator(bool idInceasingOrder) const
2197 typedef MYNCollection_Map_Iterator
2198 < SetOfNodes, const SMDS_MeshNode*, SMDS_NodeIterator > TIterator;
2199 typedef IdSortedIterator< const SMDS_MeshNode* > TSortedIterator;
2200 return ( idInceasingOrder ?
2201 SMDS_NodeIteratorPtr( new TSortedIterator( *myNodeIDFactory )) :
2202 SMDS_NodeIteratorPtr( new TIterator(myNodes)));
2205 ///////////////////////////////////////////////////////////////////////////////
2206 ///Return an iterator on 0D elements of the current mesh.
2207 ///////////////////////////////////////////////////////////////////////////////
2209 SMDS_0DElementIteratorPtr SMDS_Mesh::elements0dIterator() const
2211 typedef MYNCollection_Map_Iterator
2212 < SetOf0DElements, const SMDS_Mesh0DElement*, SMDS_0DElementIterator > TIterator;
2213 return SMDS_0DElementIteratorPtr(new TIterator(my0DElements));
2216 ///////////////////////////////////////////////////////////////////////////////
2217 ///Return an iterator on edges of the current mesh.
2218 ///////////////////////////////////////////////////////////////////////////////
2220 SMDS_EdgeIteratorPtr SMDS_Mesh::edgesIterator() const
2222 typedef MYNCollection_Map_Iterator
2223 < SetOfEdges, const SMDS_MeshEdge*, SMDS_EdgeIterator > TIterator;
2224 return SMDS_EdgeIteratorPtr(new TIterator(myEdges));
2227 ///////////////////////////////////////////////////////////////////////////////
2228 ///Return an iterator on faces of the current mesh.
2229 ///////////////////////////////////////////////////////////////////////////////
2231 SMDS_FaceIteratorPtr SMDS_Mesh::facesIterator() const
2233 typedef MYNCollection_Map_Iterator
2234 < SetOfFaces, const SMDS_MeshFace*, SMDS_FaceIterator > TIterator;
2235 return SMDS_FaceIteratorPtr(new TIterator(myFaces));
2238 ///////////////////////////////////////////////////////////////////////////////
2239 ///Return an iterator on volumes of the current mesh.
2240 ///////////////////////////////////////////////////////////////////////////////
2242 SMDS_VolumeIteratorPtr SMDS_Mesh::volumesIterator() const
2244 typedef MYNCollection_Map_Iterator
2245 < SetOfVolumes, const SMDS_MeshVolume*, SMDS_VolumeIterator > TIterator;
2246 return SMDS_VolumeIteratorPtr(new TIterator(myVolumes));
2249 ///////////////////////////////////////////////////////////////////////////////
2250 /// Return an iterator on elements of the current mesh factory
2251 ///////////////////////////////////////////////////////////////////////////////
2252 SMDS_ElemIteratorPtr SMDS_Mesh::elementsIterator(SMDSAbs_ElementType type) const
2257 case SMDSAbs_Volume:
2258 return SMDS_ElemIteratorPtr (new MYNCollection_Map_Iterator< SetOfVolumes >(myVolumes));
2260 return SMDS_ElemIteratorPtr (new MYNCollection_Map_Iterator< SetOfFaces >(myFaces));
2262 return SMDS_ElemIteratorPtr (new MYNCollection_Map_Iterator< SetOfEdges >(myEdges));
2263 case SMDSAbs_0DElement:
2264 return SMDS_ElemIteratorPtr (new MYNCollection_Map_Iterator< SetOf0DElements >(my0DElements));
2266 return myNodeIDFactory->elementsIterator();
2269 return myElementIDFactory->elementsIterator();
2272 ///////////////////////////////////////////////////////////////////////////////
2273 /// Do intersection of sets (more than 2)
2274 ///////////////////////////////////////////////////////////////////////////////
2275 static set<const SMDS_MeshElement*> * intersectionOfSets(
2276 set<const SMDS_MeshElement*> vs[], int numberOfSets)
2278 set<const SMDS_MeshElement*>* rsetA=new set<const SMDS_MeshElement*>(vs[0]);
2279 set<const SMDS_MeshElement*>* rsetB;
2281 for(int i=0; i<numberOfSets-1; i++)
2283 rsetB=new set<const SMDS_MeshElement*>();
2285 rsetA->begin(), rsetA->end(),
2286 vs[i+1].begin(), vs[i+1].end(),
2287 inserter(*rsetB, rsetB->begin()));
2294 ///////////////////////////////////////////////////////////////////////////////
2295 /// Return the list of finit elements owning the given element
2296 ///////////////////////////////////////////////////////////////////////////////
2297 static set<const SMDS_MeshElement*> * getFinitElements(const SMDS_MeshElement * element)
2299 int numberOfSets=element->NbNodes();
2300 set<const SMDS_MeshElement*> *initSet = new set<const SMDS_MeshElement*>[numberOfSets];
2302 SMDS_ElemIteratorPtr itNodes=element->nodesIterator();
2305 while(itNodes->more())
2307 const SMDS_MeshNode * n=static_cast<const SMDS_MeshNode*>(itNodes->next());
2308 SMDS_ElemIteratorPtr itFe = n->GetInverseElementIterator();
2310 //initSet[i]=set<const SMDS_MeshElement*>();
2312 initSet[i].insert(itFe->next());
2316 set<const SMDS_MeshElement*> *retSet=intersectionOfSets(initSet, numberOfSets);
2321 ///////////////////////////////////////////////////////////////////////////////
2322 /// Return the list of nodes used only by the given elements
2323 ///////////////////////////////////////////////////////////////////////////////
2324 static set<const SMDS_MeshElement*> * getExclusiveNodes(
2325 set<const SMDS_MeshElement*>& elements)
2327 set<const SMDS_MeshElement*> * toReturn=new set<const SMDS_MeshElement*>();
2328 set<const SMDS_MeshElement*>::iterator itElements=elements.begin();
2330 while(itElements!=elements.end())
2332 SMDS_ElemIteratorPtr itNodes = (*itElements)->nodesIterator();
2335 while(itNodes->more())
2337 const SMDS_MeshNode * n=static_cast<const SMDS_MeshNode*>(itNodes->next());
2338 SMDS_ElemIteratorPtr itFe = n->GetInverseElementIterator();
2339 set<const SMDS_MeshElement*> s;
2341 s.insert(itFe->next());
2342 if(s==elements) toReturn->insert(n);
2348 ///////////////////////////////////////////////////////////////////////////////
2349 ///Find the children of an element that are made of given nodes
2350 ///@param setOfChildren The set in which matching children will be inserted
2351 ///@param element The element were to search matching children
2352 ///@param nodes The nodes that the children must have to be selected
2353 ///////////////////////////////////////////////////////////////////////////////
2354 void SMDS_Mesh::addChildrenWithNodes(set<const SMDS_MeshElement*>& setOfChildren,
2355 const SMDS_MeshElement * element,
2356 set<const SMDS_MeshElement*>& nodes)
2358 switch(element->GetType())
2361 MESSAGE("Internal Error: This should not happend");
2363 case SMDSAbs_0DElement:
2369 SMDS_ElemIteratorPtr itn=element->nodesIterator();
2372 const SMDS_MeshElement * e=itn->next();
2373 if(nodes.find(e)!=nodes.end())
2375 setOfChildren.insert(element);
2382 SMDS_ElemIteratorPtr itn=element->nodesIterator();
2385 const SMDS_MeshElement * e=itn->next();
2386 if(nodes.find(e)!=nodes.end())
2388 setOfChildren.insert(element);
2392 if(hasConstructionEdges())
2394 SMDS_ElemIteratorPtr ite=element->edgesIterator();
2396 addChildrenWithNodes(setOfChildren, ite->next(), nodes);
2399 case SMDSAbs_Volume:
2401 if(hasConstructionFaces())
2403 SMDS_ElemIteratorPtr ite=element->facesIterator();
2405 addChildrenWithNodes(setOfChildren, ite->next(), nodes);
2407 else if(hasConstructionEdges())
2409 SMDS_ElemIteratorPtr ite=element->edgesIterator();
2411 addChildrenWithNodes(setOfChildren, ite->next(), nodes);
2417 ///////////////////////////////////////////////////////////////////////////////
2418 ///@param elem The element to delete
2419 ///@param removenodes if true remaining nodes will be removed
2420 ///////////////////////////////////////////////////////////////////////////////
2421 void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem,
2422 const bool removenodes)
2424 list<const SMDS_MeshElement *> removedElems;
2425 list<const SMDS_MeshElement *> removedNodes;
2426 RemoveElement( elem, removedElems, removedNodes, removenodes );
2429 ///////////////////////////////////////////////////////////////////////////////
2430 ///@param elem The element to delete
2431 ///@param removedElems contains all removed elements
2432 ///@param removedNodes contains all removed nodes
2433 ///@param removenodes if true remaining nodes will be removed
2434 ///////////////////////////////////////////////////////////////////////////////
2435 void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem,
2436 list<const SMDS_MeshElement *>& removedElems,
2437 list<const SMDS_MeshElement *>& removedNodes,
2440 // get finite elements built on elem
2441 set<const SMDS_MeshElement*> * s1;
2442 if (elem->GetType() == SMDSAbs_0DElement ||
2443 elem->GetType() == SMDSAbs_Edge && !hasConstructionEdges() ||
2444 elem->GetType() == SMDSAbs_Face && !hasConstructionFaces() ||
2445 elem->GetType() == SMDSAbs_Volume)
2447 s1 = new set<const SMDS_MeshElement*>();
2451 s1 = getFinitElements(elem);
2453 // get exclusive nodes (which would become free afterwards)
2454 set<const SMDS_MeshElement*> * s2;
2455 if (elem->GetType() == SMDSAbs_Node) // a node is removed
2457 // do not remove nodes except elem
2458 s2 = new set<const SMDS_MeshElement*>();
2463 s2 = getExclusiveNodes(*s1);
2465 // form the set of finite and construction elements to remove
2466 set<const SMDS_MeshElement*> s3;
2467 set<const SMDS_MeshElement*>::iterator it=s1->begin();
2468 while(it!=s1->end())
2470 addChildrenWithNodes(s3, *it ,*s2);
2474 if(elem->GetType()!=SMDSAbs_Node) s3.insert(elem);
2476 // remove finite and construction elements
2480 // Remove element from <InverseElements> of its nodes
2481 SMDS_ElemIteratorPtr itn=(*it)->nodesIterator();
2484 SMDS_MeshNode * n = static_cast<SMDS_MeshNode *>
2485 (const_cast<SMDS_MeshElement *>(itn->next()));
2486 n->RemoveInverseElement( (*it) );
2489 switch((*it)->GetType())
2492 MESSAGE("Internal Error: This should not happen");
2494 case SMDSAbs_0DElement:
2495 my0DElements.Remove(static_cast<SMDS_Mesh0DElement*>
2496 (const_cast<SMDS_MeshElement*>(*it)));
2497 //myInfo.Remove0DElement(*it);
2501 myEdges.Remove(static_cast<SMDS_MeshEdge*>
2502 (const_cast<SMDS_MeshElement*>(*it)));
2503 myInfo.RemoveEdge(*it);
2506 myFaces.Remove(static_cast<SMDS_MeshFace*>
2507 (const_cast<SMDS_MeshElement*>(*it)));
2508 myInfo.RemoveFace(*it);
2510 case SMDSAbs_Volume:
2511 myVolumes.Remove(static_cast<SMDS_MeshVolume*>
2512 (const_cast<SMDS_MeshElement*>(*it)));
2513 myInfo.RemoveVolume(*it);
2516 //MESSAGE( "SMDS: RM elem " << (*it)->GetID() );
2517 removedElems.push_back( (*it) );
2518 myElementIDFactory->ReleaseID((*it)->GetID());
2523 // remove exclusive (free) nodes
2527 while(it!=s2->end())
2529 //MESSAGE( "SMDS: RM node " << (*it)->GetID() );
2530 myNodes.Remove(static_cast<SMDS_MeshNode*>
2531 (const_cast<SMDS_MeshElement*>(*it)));
2533 myNodeIDFactory->ReleaseID((*it)->GetID());
2534 removedNodes.push_back( (*it) );
2545 ///////////////////////////////////////////////////////////////////////////////
2546 ///@param elem The element to delete
2547 ///////////////////////////////////////////////////////////////////////////////
2548 void SMDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elem)
2550 SMDSAbs_ElementType aType = elem->GetType();
2551 if (aType == SMDSAbs_Node) {
2552 // only free node can be removed by this method
2553 const SMDS_MeshNode* n = static_cast<const SMDS_MeshNode*>(elem);
2554 SMDS_ElemIteratorPtr itFe = n->GetInverseElementIterator();
2555 if (!itFe->more()) { // free node
2556 myNodes.Remove(const_cast<SMDS_MeshNode*>(n));
2558 myNodeIDFactory->ReleaseID(elem->GetID());
2562 if (hasConstructionEdges() || hasConstructionFaces())
2563 // this methods is only for meshes without descendants
2566 // Remove element from <InverseElements> of its nodes
2567 SMDS_ElemIteratorPtr itn = elem->nodesIterator();
2568 while (itn->more()) {
2569 SMDS_MeshNode * n = static_cast<SMDS_MeshNode *>
2570 (const_cast<SMDS_MeshElement *>(itn->next()));
2571 n->RemoveInverseElement(elem);
2574 // in meshes without descendants elements are always free
2576 case SMDSAbs_0DElement:
2577 my0DElements.Remove(static_cast<SMDS_Mesh0DElement*>
2578 (const_cast<SMDS_MeshElement*>(elem)));
2579 //myInfo.Remove0DElement(elem);
2580 myInfo.remove(elem);
2583 myEdges.Remove(static_cast<SMDS_MeshEdge*>
2584 (const_cast<SMDS_MeshElement*>(elem)));
2585 myInfo.RemoveEdge(elem);
2588 myFaces.Remove(static_cast<SMDS_MeshFace*>
2589 (const_cast<SMDS_MeshElement*>(elem)));
2590 myInfo.RemoveFace(elem);
2592 case SMDSAbs_Volume:
2593 myVolumes.Remove(static_cast<SMDS_MeshVolume*>
2594 (const_cast<SMDS_MeshElement*>(elem)));
2595 myInfo.RemoveVolume(elem);
2600 myElementIDFactory->ReleaseID(elem->GetID());
2606 * Checks if the element is present in mesh.
2607 * Useful to determine dead pointers.
2609 bool SMDS_Mesh::Contains (const SMDS_MeshElement* elem) const
2611 // we should not imply on validity of *elem, so iterate on containers
2612 // of all types in the hope of finding <elem> somewhere there
2613 SMDS_NodeIteratorPtr itn = nodesIterator();
2615 if (elem == itn->next())
2617 SMDS_0DElementIteratorPtr it0d = elements0dIterator();
2618 while (it0d->more())
2619 if (elem == it0d->next())
2621 SMDS_EdgeIteratorPtr ite = edgesIterator();
2623 if (elem == ite->next())
2625 SMDS_FaceIteratorPtr itf = facesIterator();
2627 if (elem == itf->next())
2629 SMDS_VolumeIteratorPtr itv = volumesIterator();
2631 if (elem == itv->next())
2636 //=======================================================================
2637 //function : MaxNodeID
2639 //=======================================================================
2641 int SMDS_Mesh::MaxNodeID() const
2643 return myNodeIDFactory->GetMaxID();
2646 //=======================================================================
2647 //function : MinNodeID
2649 //=======================================================================
2651 int SMDS_Mesh::MinNodeID() const
2653 return myNodeIDFactory->GetMinID();
2656 //=======================================================================
2657 //function : MaxElementID
2659 //=======================================================================
2661 int SMDS_Mesh::MaxElementID() const
2663 return myElementIDFactory->GetMaxID();
2666 //=======================================================================
2667 //function : MinElementID
2669 //=======================================================================
2671 int SMDS_Mesh::MinElementID() const
2673 return myElementIDFactory->GetMinID();
2676 //=======================================================================
2677 //function : Renumber
2678 //purpose : Renumber all nodes or elements.
2679 //=======================================================================
2681 void SMDS_Mesh::Renumber (const bool isNodes, const int startID, const int deltaID)
2686 SMDS_MeshElementIDFactory * idFactory =
2687 isNodes ? myNodeIDFactory : myElementIDFactory;
2689 // get existing elements in the order of ID increasing
2690 map<int,SMDS_MeshElement*> elemMap;
2691 SMDS_ElemIteratorPtr idElemIt = idFactory->elementsIterator();
2692 while ( idElemIt->more() ) {
2693 SMDS_MeshElement* elem = const_cast<SMDS_MeshElement*>(idElemIt->next());
2694 int id = elem->GetID();
2695 elemMap.insert(map<int,SMDS_MeshElement*>::value_type(id, elem));
2697 // release their ids
2698 map<int,SMDS_MeshElement*>::iterator elemIt = elemMap.begin();
2700 // for ( ; elemIt != elemMap.end(); elemIt++ )
2702 // int id = (*elemIt).first;
2703 // idFactory->ReleaseID( id );
2707 elemIt = elemMap.begin();
2708 for ( ; elemIt != elemMap.end(); elemIt++ )
2710 idFactory->BindID( ID, (*elemIt).second );
2715 //=======================================================================
2716 //function : GetElementType
2717 //purpose : Return type of element or node with id
2718 //=======================================================================
2720 SMDSAbs_ElementType SMDS_Mesh::GetElementType( const int id, const bool iselem ) const
2722 SMDS_MeshElement* elem = 0;
2724 elem = myElementIDFactory->MeshElement( id );
2726 elem = myNodeIDFactory->MeshElement( id );
2730 //throw SALOME_Exception(LOCALIZED ("this element isn't exist"));
2734 return elem->GetType();
2739 //********************************************************************
2740 //********************************************************************
2741 //******** *********
2742 //***** Methods for addition of quadratic elements ******
2743 //******** *********
2744 //********************************************************************
2745 //********************************************************************
2747 //=======================================================================
2748 //function : AddEdgeWithID
2750 //=======================================================================
2751 SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(int n1, int n2, int n12, int ID)
2753 return SMDS_Mesh::AddEdgeWithID
2754 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1),
2755 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2),
2756 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
2760 //=======================================================================
2761 //function : AddEdge
2763 //=======================================================================
2764 SMDS_MeshEdge* SMDS_Mesh::AddEdge(const SMDS_MeshNode* n1,
2765 const SMDS_MeshNode* n2,
2766 const SMDS_MeshNode* n12)
2768 return SMDS_Mesh::AddEdgeWithID(n1, n2, n12, myElementIDFactory->GetFreeID());
2771 //=======================================================================
2772 //function : AddEdgeWithID
2774 //=======================================================================
2775 SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
2776 const SMDS_MeshNode * n2,
2777 const SMDS_MeshNode * n12,
2780 if ( !n1 || !n2 || !n12 ) return 0;
2781 SMDS_QuadraticEdge* edge = new SMDS_QuadraticEdge(n1,n2,n12);
2782 if(myElementIDFactory->BindID(ID, edge)) {
2783 SMDS_MeshNode *node1,*node2, *node12;
2784 node1 = const_cast<SMDS_MeshNode*>(n1);
2785 node2 = const_cast<SMDS_MeshNode*>(n2);
2786 node12 = const_cast<SMDS_MeshNode*>(n12);
2787 node1->AddInverseElement(edge);
2788 node2->AddInverseElement(edge);
2789 node12->AddInverseElement(edge);
2791 myInfo.myNbQuadEdges++;
2801 //=======================================================================
2802 //function : AddFace
2804 //=======================================================================
2805 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
2806 const SMDS_MeshNode * n2,
2807 const SMDS_MeshNode * n3,
2808 const SMDS_MeshNode * n12,
2809 const SMDS_MeshNode * n23,
2810 const SMDS_MeshNode * n31)
2812 return SMDS_Mesh::AddFaceWithID(n1,n2,n3,n12,n23,n31,
2813 myElementIDFactory->GetFreeID());
2816 //=======================================================================
2817 //function : AddFaceWithID
2819 //=======================================================================
2820 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int n1, int n2, int n3,
2821 int n12,int n23,int n31, int ID)
2823 return SMDS_Mesh::AddFaceWithID
2824 ((SMDS_MeshNode *)myNodeIDFactory->MeshElement(n1) ,
2825 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n2) ,
2826 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n3) ,
2827 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n12),
2828 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n23),
2829 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n31),
2833 //=======================================================================
2834 //function : AddFaceWithID
2836 //=======================================================================
2837 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
2838 const SMDS_MeshNode * n2,
2839 const SMDS_MeshNode * n3,
2840 const SMDS_MeshNode * n12,
2841 const SMDS_MeshNode * n23,
2842 const SMDS_MeshNode * n31,
2845 if ( !n1 || !n2 || !n3 || !n12 || !n23 || !n31) return 0;
2846 if(hasConstructionEdges()) {
2847 // creation quadratic edges - not implemented
2850 SMDS_QuadraticFaceOfNodes* face =
2851 new SMDS_QuadraticFaceOfNodes(n1,n2,n3,n12,n23,n31);
2853 myInfo.myNbQuadTriangles++;
2855 if (!registerElement(ID, face)) {
2856 RemoveElement(face, false);
2863 //=======================================================================
2864 //function : AddFace
2866 //=======================================================================
2867 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
2868 const SMDS_MeshNode * n2,
2869 const SMDS_MeshNode * n3,
2870 const SMDS_MeshNode * n4,
2871 const SMDS_MeshNode * n12,
2872 const SMDS_MeshNode * n23,
2873 const SMDS_MeshNode * n34,
2874 const SMDS_MeshNode * n41)
2876 return SMDS_Mesh::AddFaceWithID(n1,n2,n3,n4,n12,n23,n34,n41,
2877 myElementIDFactory->GetFreeID());
2880 //=======================================================================
2881 //function : AddFaceWithID
2883 //=======================================================================
2884 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int n4,
2885 int n12,int n23,int n34,int n41, int ID)
2887 return SMDS_Mesh::AddFaceWithID
2888 ((SMDS_MeshNode *)myNodeIDFactory->MeshElement(n1) ,
2889 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n2) ,
2890 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n3) ,
2891 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n4) ,
2892 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n12),
2893 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n23),
2894 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n34),
2895 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n41),
2899 //=======================================================================
2900 //function : AddFaceWithID
2902 //=======================================================================
2903 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
2904 const SMDS_MeshNode * n2,
2905 const SMDS_MeshNode * n3,
2906 const SMDS_MeshNode * n4,
2907 const SMDS_MeshNode * n12,
2908 const SMDS_MeshNode * n23,
2909 const SMDS_MeshNode * n34,
2910 const SMDS_MeshNode * n41,
2913 if ( !n1 || !n2 || !n3 || !n4 || !n12 || !n23 || !n34 || !n41) return 0;
2914 if(hasConstructionEdges()) {
2915 // creation quadratic edges - not implemented
2917 SMDS_QuadraticFaceOfNodes* face =
2918 new SMDS_QuadraticFaceOfNodes(n1,n2,n3,n4,n12,n23,n34,n41);
2920 myInfo.myNbQuadQuadrangles++;
2922 if (!registerElement(ID, face)) {
2923 RemoveElement(face, false);
2930 //=======================================================================
2931 //function : AddVolume
2933 //=======================================================================
2934 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
2935 const SMDS_MeshNode * n2,
2936 const SMDS_MeshNode * n3,
2937 const SMDS_MeshNode * n4,
2938 const SMDS_MeshNode * n12,
2939 const SMDS_MeshNode * n23,
2940 const SMDS_MeshNode * n31,
2941 const SMDS_MeshNode * n14,
2942 const SMDS_MeshNode * n24,
2943 const SMDS_MeshNode * n34)
2945 int ID = myElementIDFactory->GetFreeID();
2946 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n12, n23,
2947 n31, n14, n24, n34, ID);
2948 if(v==NULL) myElementIDFactory->ReleaseID(ID);
2952 //=======================================================================
2953 //function : AddVolumeWithID
2955 //=======================================================================
2956 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4,
2957 int n12,int n23,int n31,
2958 int n14,int n24,int n34, int ID)
2960 return SMDS_Mesh::AddVolumeWithID
2961 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1) ,
2962 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2) ,
2963 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3) ,
2964 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4) ,
2965 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
2966 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
2967 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n31),
2968 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n14),
2969 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n24),
2970 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n34),
2974 //=======================================================================
2975 //function : AddVolumeWithID
2976 //purpose : 2d order tetrahedron of 10 nodes
2977 //=======================================================================
2978 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
2979 const SMDS_MeshNode * n2,
2980 const SMDS_MeshNode * n3,
2981 const SMDS_MeshNode * n4,
2982 const SMDS_MeshNode * n12,
2983 const SMDS_MeshNode * n23,
2984 const SMDS_MeshNode * n31,
2985 const SMDS_MeshNode * n14,
2986 const SMDS_MeshNode * n24,
2987 const SMDS_MeshNode * n34,
2990 if ( !n1 || !n2 || !n3 || !n4 || !n12 || !n23 || !n31 || !n14 || !n24 || !n34)
2992 if(hasConstructionFaces()) {
2993 // creation quadratic faces - not implemented
2996 SMDS_QuadraticVolumeOfNodes * volume =
2997 new SMDS_QuadraticVolumeOfNodes(n1,n2,n3,n4,n12,n23,n31,n14,n24,n34);
2998 myVolumes.Add(volume);
2999 myInfo.myNbQuadTetras++;
3001 if (!registerElement(ID, volume)) {
3002 RemoveElement(volume, false);
3009 //=======================================================================
3010 //function : AddVolume
3012 //=======================================================================
3013 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
3014 const SMDS_MeshNode * n2,
3015 const SMDS_MeshNode * n3,
3016 const SMDS_MeshNode * n4,
3017 const SMDS_MeshNode * n5,
3018 const SMDS_MeshNode * n12,
3019 const SMDS_MeshNode * n23,
3020 const SMDS_MeshNode * n34,
3021 const SMDS_MeshNode * n41,
3022 const SMDS_MeshNode * n15,
3023 const SMDS_MeshNode * n25,
3024 const SMDS_MeshNode * n35,
3025 const SMDS_MeshNode * n45)
3027 int ID = myElementIDFactory->GetFreeID();
3028 SMDS_MeshVolume * v =
3029 SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n12, n23, n34, n41,
3030 n15, n25, n35, n45, ID);
3031 if(v==NULL) myElementIDFactory->ReleaseID(ID);
3035 //=======================================================================
3036 //function : AddVolumeWithID
3038 //=======================================================================
3039 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5,
3040 int n12,int n23,int n34,int n41,
3041 int n15,int n25,int n35,int n45, int ID)
3043 return SMDS_Mesh::AddVolumeWithID
3044 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1) ,
3045 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2) ,
3046 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3) ,
3047 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4) ,
3048 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5) ,
3049 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
3050 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
3051 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n34),
3052 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n41),
3053 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n15),
3054 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n25),
3055 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n35),
3056 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n45),
3060 //=======================================================================
3061 //function : AddVolumeWithID
3062 //purpose : 2d order pyramid of 13 nodes
3063 //=======================================================================
3064 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
3065 const SMDS_MeshNode * n2,
3066 const SMDS_MeshNode * n3,
3067 const SMDS_MeshNode * n4,
3068 const SMDS_MeshNode * n5,
3069 const SMDS_MeshNode * n12,
3070 const SMDS_MeshNode * n23,
3071 const SMDS_MeshNode * n34,
3072 const SMDS_MeshNode * n41,
3073 const SMDS_MeshNode * n15,
3074 const SMDS_MeshNode * n25,
3075 const SMDS_MeshNode * n35,
3076 const SMDS_MeshNode * n45,
3079 if (!n1 || !n2 || !n3 || !n4 || !n5 || !n12 || !n23 ||
3080 !n34 || !n41 || !n15 || !n25 || !n35 || !n45)
3082 if(hasConstructionFaces()) {
3083 // creation quadratic faces - not implemented
3086 SMDS_QuadraticVolumeOfNodes * volume =
3087 new SMDS_QuadraticVolumeOfNodes(n1,n2,n3,n4,n5,n12,n23,
3088 n34,n41,n15,n25,n35,n45);
3089 myVolumes.Add(volume);
3090 myInfo.myNbQuadPyramids++;
3092 if (!registerElement(ID, volume)) {
3093 RemoveElement(volume, false);
3100 //=======================================================================
3101 //function : AddVolume
3103 //=======================================================================
3104 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
3105 const SMDS_MeshNode * n2,
3106 const SMDS_MeshNode * n3,
3107 const SMDS_MeshNode * n4,
3108 const SMDS_MeshNode * n5,
3109 const SMDS_MeshNode * n6,
3110 const SMDS_MeshNode * n12,
3111 const SMDS_MeshNode * n23,
3112 const SMDS_MeshNode * n31,
3113 const SMDS_MeshNode * n45,
3114 const SMDS_MeshNode * n56,
3115 const SMDS_MeshNode * n64,
3116 const SMDS_MeshNode * n14,
3117 const SMDS_MeshNode * n25,
3118 const SMDS_MeshNode * n36)
3120 int ID = myElementIDFactory->GetFreeID();
3121 SMDS_MeshVolume * v =
3122 SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n12, n23, n31,
3123 n45, n56, n64, n14, n25, n36, ID);
3124 if(v==NULL) myElementIDFactory->ReleaseID(ID);
3128 //=======================================================================
3129 //function : AddVolumeWithID
3131 //=======================================================================
3132 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3,
3133 int n4, int n5, int n6,
3134 int n12,int n23,int n31,
3135 int n45,int n56,int n64,
3136 int n14,int n25,int n36, int ID)
3138 return SMDS_Mesh::AddVolumeWithID
3139 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1) ,
3140 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2) ,
3141 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3) ,
3142 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4) ,
3143 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5) ,
3144 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n6) ,
3145 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
3146 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
3147 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n31),
3148 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n45),
3149 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n56),
3150 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n64),
3151 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n14),
3152 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n25),
3153 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n36),
3157 //=======================================================================
3158 //function : AddVolumeWithID
3159 //purpose : 2d order Pentahedron with 15 nodes
3160 //=======================================================================
3161 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
3162 const SMDS_MeshNode * n2,
3163 const SMDS_MeshNode * n3,
3164 const SMDS_MeshNode * n4,
3165 const SMDS_MeshNode * n5,
3166 const SMDS_MeshNode * n6,
3167 const SMDS_MeshNode * n12,
3168 const SMDS_MeshNode * n23,
3169 const SMDS_MeshNode * n31,
3170 const SMDS_MeshNode * n45,
3171 const SMDS_MeshNode * n56,
3172 const SMDS_MeshNode * n64,
3173 const SMDS_MeshNode * n14,
3174 const SMDS_MeshNode * n25,
3175 const SMDS_MeshNode * n36,
3178 if (!n1 || !n2 || !n3 || !n4 || !n5 || !n6 || !n12 || !n23 ||
3179 !n31 || !n45 || !n56 || !n64 || !n14 || !n25 || !n36)
3181 if(hasConstructionFaces()) {
3182 // creation quadratic faces - not implemented
3185 SMDS_QuadraticVolumeOfNodes * volume =
3186 new SMDS_QuadraticVolumeOfNodes(n1,n2,n3,n4,n5,n6,n12,n23,n31,
3187 n45,n56,n64,n14,n25,n36);
3188 myVolumes.Add(volume);
3189 myInfo.myNbQuadPrisms++;
3191 if (!registerElement(ID, volume)) {
3192 RemoveElement(volume, false);
3199 //=======================================================================
3200 //function : AddVolume
3202 //=======================================================================
3203 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
3204 const SMDS_MeshNode * n2,
3205 const SMDS_MeshNode * n3,
3206 const SMDS_MeshNode * n4,
3207 const SMDS_MeshNode * n5,
3208 const SMDS_MeshNode * n6,
3209 const SMDS_MeshNode * n7,
3210 const SMDS_MeshNode * n8,
3211 const SMDS_MeshNode * n12,
3212 const SMDS_MeshNode * n23,
3213 const SMDS_MeshNode * n34,
3214 const SMDS_MeshNode * n41,
3215 const SMDS_MeshNode * n56,
3216 const SMDS_MeshNode * n67,
3217 const SMDS_MeshNode * n78,
3218 const SMDS_MeshNode * n85,
3219 const SMDS_MeshNode * n15,
3220 const SMDS_MeshNode * n26,
3221 const SMDS_MeshNode * n37,
3222 const SMDS_MeshNode * n48)
3224 int ID = myElementIDFactory->GetFreeID();
3225 SMDS_MeshVolume * v =
3226 SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, n12, n23, n34, n41,
3227 n56, n67, n78, n85, n15, n26, n37, n48, ID);
3228 if(v==NULL) myElementIDFactory->ReleaseID(ID);
3232 //=======================================================================
3233 //function : AddVolumeWithID
3235 //=======================================================================
3236 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4,
3237 int n5, int n6, int n7, int n8,
3238 int n12,int n23,int n34,int n41,
3239 int n56,int n67,int n78,int n85,
3240 int n15,int n26,int n37,int n48, int ID)
3242 return SMDS_Mesh::AddVolumeWithID
3243 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1),
3244 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2),
3245 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3),
3246 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4),
3247 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5),
3248 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n6),
3249 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n7),
3250 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n8),
3251 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
3252 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
3253 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n34),
3254 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n41),
3255 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n56),
3256 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n67),
3257 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n78),
3258 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n85),
3259 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n15),
3260 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n26),
3261 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n37),
3262 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n48),
3266 //=======================================================================
3267 //function : AddVolumeWithID
3268 //purpose : 2d order Hexahedrons with 20 nodes
3269 //=======================================================================
3270 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
3271 const SMDS_MeshNode * n2,
3272 const SMDS_MeshNode * n3,
3273 const SMDS_MeshNode * n4,
3274 const SMDS_MeshNode * n5,
3275 const SMDS_MeshNode * n6,
3276 const SMDS_MeshNode * n7,
3277 const SMDS_MeshNode * n8,
3278 const SMDS_MeshNode * n12,
3279 const SMDS_MeshNode * n23,
3280 const SMDS_MeshNode * n34,
3281 const SMDS_MeshNode * n41,
3282 const SMDS_MeshNode * n56,
3283 const SMDS_MeshNode * n67,
3284 const SMDS_MeshNode * n78,
3285 const SMDS_MeshNode * n85,
3286 const SMDS_MeshNode * n15,
3287 const SMDS_MeshNode * n26,
3288 const SMDS_MeshNode * n37,
3289 const SMDS_MeshNode * n48,
3292 if (!n1 || !n2 || !n3 || !n4 || !n5 || !n6 || !n7 || !n8 || !n12 || !n23 ||
3293 !n34 || !n41 || !n56 || !n67 || !n78 || !n85 || !n15 || !n26 || !n37 || !n48)
3295 if(hasConstructionFaces()) {
3297 // creation quadratic faces - not implemented
3299 SMDS_QuadraticVolumeOfNodes * volume =
3300 new SMDS_QuadraticVolumeOfNodes(n1,n2,n3,n4,n5,n6,n7,n8,n12,n23,n34,n41,
3301 n56,n67,n78,n85,n15,n26,n37,n48);
3302 myVolumes.Add(volume);
3303 myInfo.myNbQuadHexas++;
3305 if (!registerElement(ID, volume)) {
3306 RemoveElement(volume, false);