1 // SMESH SMDS : implementaion of Salome mesh data structure
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #pragma warning(disable:4786)
26 #include "utilities.h"
27 #include "SMDS_Mesh.hxx"
28 #include "SMDS_VolumeOfNodes.hxx"
29 #include "SMDS_VolumeOfFaces.hxx"
30 #include "SMDS_FaceOfNodes.hxx"
31 #include "SMDS_FaceOfEdges.hxx"
32 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
33 #include "SMDS_PolygonalFaceOfNodes.hxx"
34 #include "SMDS_QuadraticEdge.hxx"
35 #include "SMDS_QuadraticFaceOfNodes.hxx"
36 #include "SMDS_QuadraticVolumeOfNodes.hxx"
43 #include <sys/sysinfo.h>
46 //================================================================================
48 * \brief Raise an exception if free memory (ram+swap) too low
49 * \param doNotRaise - if true, suppres exception, just return free memory size
50 * \retval int - amount of available memory in MB or negative number in failure case
52 //================================================================================
54 int SMDS_Mesh::CheckMemory(const bool doNotRaise) throw (std::bad_alloc)
58 int err = sysinfo( &si );
62 const unsigned long Mbyte = 1024 * 1024;
63 // compute separately to avoid overflow
65 ( si.freeram * si.mem_unit ) / Mbyte +
66 ( si.freeswap * si.mem_unit ) / Mbyte;
73 cout<<"SMDS_Mesh::CheckMemory() throws std::bad_alloc() as freeMb="<<freeMb<<endl;
74 throw std::bad_alloc();
80 ///////////////////////////////////////////////////////////////////////////////
81 /// Create a new mesh object
82 ///////////////////////////////////////////////////////////////////////////////
83 SMDS_Mesh::SMDS_Mesh()
85 myNodeIDFactory(new SMDS_MeshElementIDFactory()),
86 myElementIDFactory(new SMDS_MeshElementIDFactory()),
87 myHasConstructionEdges(false), myHasConstructionFaces(false),
88 myHasInverseElements(true)
92 ///////////////////////////////////////////////////////////////////////////////
93 /// Create a new child mesh
94 /// Note that the tree structure of SMDS_Mesh seems to be unused in this version
95 /// (2003-09-08) of SMESH
96 ///////////////////////////////////////////////////////////////////////////////
97 SMDS_Mesh::SMDS_Mesh(SMDS_Mesh * parent)
98 :myParent(parent), myNodeIDFactory(parent->myNodeIDFactory),
99 myElementIDFactory(parent->myElementIDFactory),
100 myHasConstructionEdges(false), myHasConstructionFaces(false),
101 myHasInverseElements(true)
105 ///////////////////////////////////////////////////////////////////////////////
106 ///Create a submesh and add it to the current mesh
107 ///////////////////////////////////////////////////////////////////////////////
109 SMDS_Mesh *SMDS_Mesh::AddSubMesh()
111 SMDS_Mesh *submesh = new SMDS_Mesh(this);
112 myChildren.insert(myChildren.end(), submesh);
116 ///////////////////////////////////////////////////////////////////////////////
117 ///create a MeshNode and add it to the current Mesh
118 ///An ID is automatically assigned to the node.
119 ///@return : The created node
120 ///////////////////////////////////////////////////////////////////////////////
122 SMDS_MeshNode * SMDS_Mesh::AddNode(double x, double y, double z)
124 return SMDS_Mesh::AddNodeWithID(x,y,z,myNodeIDFactory->GetFreeID());
127 ///////////////////////////////////////////////////////////////////////////////
128 ///create a MeshNode and add it to the current Mesh
129 ///@param ID : The ID of the MeshNode to create
130 ///@return : The created node or NULL if a node with this ID already exists
131 ///////////////////////////////////////////////////////////////////////////////
132 SMDS_MeshNode * SMDS_Mesh::AddNodeWithID(double x, double y, double z, int ID)
134 // find the MeshNode corresponding to ID
135 const SMDS_MeshElement *node = myNodeIDFactory->MeshElement(ID);
138 SMDS_MeshNode * node=new SMDS_MeshNode(x, y, z);
140 myNodeIDFactory->BindID(ID,node);
146 ///////////////////////////////////////////////////////////////////////////////
147 /// create a MeshEdge and add it to the current Mesh
148 /// @return : The created MeshEdge
149 ///////////////////////////////////////////////////////////////////////////////
151 SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(int idnode1, int idnode2, int ID)
153 SMDS_MeshNode * node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
154 SMDS_MeshNode * node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
155 if(!node1 || !node2) return NULL;
156 return SMDS_Mesh::AddEdgeWithID(node1, node2, ID);
159 ///////////////////////////////////////////////////////////////////////////////
160 /// create a MeshEdge and add it to the current Mesh
161 /// @return : The created MeshEdge
162 ///////////////////////////////////////////////////////////////////////////////
164 SMDS_MeshEdge* SMDS_Mesh::AddEdge(const SMDS_MeshNode * node1,
165 const SMDS_MeshNode * node2)
167 return SMDS_Mesh::AddEdgeWithID(node1, node2, myElementIDFactory->GetFreeID());
170 ///////////////////////////////////////////////////////////////////////////////
171 /// Create a new edge and at it to the mesh
172 /// @param idnode1 ID of the first node
173 /// @param idnode2 ID of the second node
174 /// @param ID ID of the edge to create
175 /// @return The created edge or NULL if an element with this ID already exists or
176 /// if input nodes are not found.
177 ///////////////////////////////////////////////////////////////////////////////
179 SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
180 const SMDS_MeshNode * n2,
183 if ( !n1 || !n2 ) return 0;
186 SMDS_MeshEdge * edge=new SMDS_MeshEdge(n1,n2);
187 if(myElementIDFactory->BindID(ID, edge)) {
188 SMDS_MeshNode *node1,*node2;
189 node1=const_cast<SMDS_MeshNode*>(n1);
190 node2=const_cast<SMDS_MeshNode*>(n2);
191 node1->AddInverseElement(edge);
192 node2->AddInverseElement(edge);
202 ///////////////////////////////////////////////////////////////////////////////
203 /// Add a triangle defined by its nodes. An ID is automatically affected to the
205 ///////////////////////////////////////////////////////////////////////////////
207 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
208 const SMDS_MeshNode * n2,
209 const SMDS_MeshNode * n3)
211 return SMDS_Mesh::AddFaceWithID(n1,n2,n3, myElementIDFactory->GetFreeID());
214 ///////////////////////////////////////////////////////////////////////////////
215 /// Add a triangle defined by its nodes IDs
216 ///////////////////////////////////////////////////////////////////////////////
218 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int idnode1, int idnode2, int idnode3, int ID)
220 SMDS_MeshNode * node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
221 SMDS_MeshNode * node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
222 SMDS_MeshNode * node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
223 if(!node1 || !node2 || !node3) return NULL;
224 return SMDS_Mesh::AddFaceWithID(node1, node2, node3, ID);
227 ///////////////////////////////////////////////////////////////////////////////
228 /// Add a triangle defined by its nodes
229 ///////////////////////////////////////////////////////////////////////////////
231 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
232 const SMDS_MeshNode * n2,
233 const SMDS_MeshNode * n3,
236 SMDS_MeshFace * face=createTriangle(n1, n2, n3);
238 if (face && !registerElement(ID, face)) {
239 RemoveElement(face, false);
245 ///////////////////////////////////////////////////////////////////////////////
246 /// Add a quadrangle defined by its nodes. An ID is automatically affected to the
248 ///////////////////////////////////////////////////////////////////////////////
250 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
251 const SMDS_MeshNode * n2,
252 const SMDS_MeshNode * n3,
253 const SMDS_MeshNode * n4)
255 return SMDS_Mesh::AddFaceWithID(n1,n2,n3, n4, myElementIDFactory->GetFreeID());
258 ///////////////////////////////////////////////////////////////////////////////
259 /// Add a quadrangle defined by its nodes IDs
260 ///////////////////////////////////////////////////////////////////////////////
262 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int idnode1,
268 SMDS_MeshNode *node1, *node2, *node3, *node4;
269 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
270 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
271 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
272 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
273 if(!node1 || !node2 || !node3 || !node4) return NULL;
274 return SMDS_Mesh::AddFaceWithID(node1, node2, node3, node4, ID);
277 ///////////////////////////////////////////////////////////////////////////////
278 /// Add a quadrangle defined by its nodes
279 ///////////////////////////////////////////////////////////////////////////////
281 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
282 const SMDS_MeshNode * n2,
283 const SMDS_MeshNode * n3,
284 const SMDS_MeshNode * n4,
287 SMDS_MeshFace * face=createQuadrangle(n1, n2, n3, n4);
289 if (face && !registerElement(ID, face)) {
290 RemoveElement(face, false);
296 ///////////////////////////////////////////////////////////////////////////////
297 /// Add a triangle defined by its edges. An ID is automatically assigned to the
299 ///////////////////////////////////////////////////////////////////////////////
301 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshEdge * e1,
302 const SMDS_MeshEdge * e2,
303 const SMDS_MeshEdge * e3)
305 if (!hasConstructionEdges())
307 return AddFaceWithID(e1,e2,e3, myElementIDFactory->GetFreeID());
310 ///////////////////////////////////////////////////////////////////////////////
311 /// Add a triangle defined by its edges
312 ///////////////////////////////////////////////////////////////////////////////
314 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshEdge * e1,
315 const SMDS_MeshEdge * e2,
316 const SMDS_MeshEdge * e3,
319 if (!hasConstructionEdges())
321 if ( !e1 || !e2 || !e3 ) return 0;
324 SMDS_MeshFace * face = new SMDS_FaceOfEdges(e1,e2,e3);
327 if (!registerElement(ID, face)) {
328 RemoveElement(face, false);
334 ///////////////////////////////////////////////////////////////////////////////
335 /// Add a quadrangle defined by its edges. An ID is automatically assigned to the
337 ///////////////////////////////////////////////////////////////////////////////
339 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshEdge * e1,
340 const SMDS_MeshEdge * e2,
341 const SMDS_MeshEdge * e3,
342 const SMDS_MeshEdge * e4)
344 if (!hasConstructionEdges())
346 return AddFaceWithID(e1,e2,e3,e4, myElementIDFactory->GetFreeID());
349 ///////////////////////////////////////////////////////////////////////////////
350 /// Add a quadrangle defined by its edges
351 ///////////////////////////////////////////////////////////////////////////////
353 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshEdge * e1,
354 const SMDS_MeshEdge * e2,
355 const SMDS_MeshEdge * e3,
356 const SMDS_MeshEdge * e4,
359 if (!hasConstructionEdges())
361 if ( !e1 || !e2 || !e3 || !e4 ) return 0;
363 SMDS_MeshFace * face = new SMDS_FaceOfEdges(e1,e2,e3,e4);
366 if (!registerElement(ID, face))
368 RemoveElement(face, false);
374 ///////////////////////////////////////////////////////////////////////////////
375 ///Create a new tetrahedron and add it to the mesh.
376 ///@return The created tetrahedron
377 ///////////////////////////////////////////////////////////////////////////////
379 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
380 const SMDS_MeshNode * n2,
381 const SMDS_MeshNode * n3,
382 const SMDS_MeshNode * n4)
384 int ID = myElementIDFactory->GetFreeID();
385 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, ID);
386 if(v==NULL) myElementIDFactory->ReleaseID(ID);
390 ///////////////////////////////////////////////////////////////////////////////
391 ///Create a new tetrahedron and add it to the mesh.
392 ///@param ID The ID of the new volume
393 ///@return The created tetrahedron or NULL if an element with this ID already exists
394 ///or if input nodes are not found.
395 ///////////////////////////////////////////////////////////////////////////////
397 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
403 SMDS_MeshNode *node1, *node2, *node3, *node4;
404 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
405 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
406 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
407 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
408 if(!node1 || !node2 || !node3 || !node4) return NULL;
409 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, ID);
412 ///////////////////////////////////////////////////////////////////////////////
413 ///Create a new tetrahedron and add it to the mesh.
414 ///@param ID The ID of the new volume
415 ///@return The created tetrahedron
416 ///////////////////////////////////////////////////////////////////////////////
418 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
419 const SMDS_MeshNode * n2,
420 const SMDS_MeshNode * n3,
421 const SMDS_MeshNode * n4,
424 SMDS_MeshVolume* volume = 0;
425 if ( !n1 || !n2 || !n3 || !n4) return volume;
427 if(hasConstructionFaces()) {
428 SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3);
429 SMDS_MeshFace * f2=FindFaceOrCreate(n1,n2,n4);
430 SMDS_MeshFace * f3=FindFaceOrCreate(n1,n3,n4);
431 SMDS_MeshFace * f4=FindFaceOrCreate(n2,n3,n4);
432 volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4);
433 myVolumes.Add(volume);
435 else if(hasConstructionEdges()) {
436 MESSAGE("Error : Not implemented");
440 volume=new SMDS_VolumeOfNodes(n1,n2,n3,n4);
441 myVolumes.Add(volume);
444 if (!registerElement(ID, volume)) {
445 RemoveElement(volume, false);
451 ///////////////////////////////////////////////////////////////////////////////
452 ///Create a new pyramid and add it to the mesh.
453 ///Nodes 1,2,3 and 4 define the base of the pyramid
454 ///@return The created pyramid
455 ///////////////////////////////////////////////////////////////////////////////
457 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
458 const SMDS_MeshNode * n2,
459 const SMDS_MeshNode * n3,
460 const SMDS_MeshNode * n4,
461 const SMDS_MeshNode * n5)
463 int ID = myElementIDFactory->GetFreeID();
464 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, ID);
465 if(v==NULL) myElementIDFactory->ReleaseID(ID);
469 ///////////////////////////////////////////////////////////////////////////////
470 ///Create a new pyramid and add it to the mesh.
471 ///Nodes 1,2,3 and 4 define the base of the pyramid
472 ///@param ID The ID of the new volume
473 ///@return The created pyramid or NULL if an element with this ID already exists
474 ///or if input nodes are not found.
475 ///////////////////////////////////////////////////////////////////////////////
477 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
484 SMDS_MeshNode *node1, *node2, *node3, *node4, *node5;
485 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
486 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
487 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
488 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
489 node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5);
490 if(!node1 || !node2 || !node3 || !node4 || !node5) return NULL;
491 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, ID);
494 ///////////////////////////////////////////////////////////////////////////////
495 ///Create a new pyramid and add it to the mesh.
496 ///Nodes 1,2,3 and 4 define the base of the pyramid
497 ///@param ID The ID of the new volume
498 ///@return The created pyramid
499 ///////////////////////////////////////////////////////////////////////////////
501 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
502 const SMDS_MeshNode * n2,
503 const SMDS_MeshNode * n3,
504 const SMDS_MeshNode * n4,
505 const SMDS_MeshNode * n5,
508 SMDS_MeshVolume* volume = 0;
509 if ( !n1 || !n2 || !n3 || !n4 || !n5) return volume;
511 if(hasConstructionFaces()) {
512 SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3,n4);
513 SMDS_MeshFace * f2=FindFaceOrCreate(n1,n2,n5);
514 SMDS_MeshFace * f3=FindFaceOrCreate(n2,n3,n5);
515 SMDS_MeshFace * f4=FindFaceOrCreate(n3,n4,n5);
516 volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4);
517 myVolumes.Add(volume);
519 else if(hasConstructionEdges()) {
520 MESSAGE("Error : Not implemented");
524 volume=new SMDS_VolumeOfNodes(n1,n2,n3,n4,n5);
525 myVolumes.Add(volume);
528 if (!registerElement(ID, volume)) {
529 RemoveElement(volume, false);
535 ///////////////////////////////////////////////////////////////////////////////
536 ///Create a new prism and add it to the mesh.
537 ///Nodes 1,2,3 is a triangle and 1,2,5,4 a quadrangle.
538 ///@return The created prism
539 ///////////////////////////////////////////////////////////////////////////////
541 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
542 const SMDS_MeshNode * n2,
543 const SMDS_MeshNode * n3,
544 const SMDS_MeshNode * n4,
545 const SMDS_MeshNode * n5,
546 const SMDS_MeshNode * n6)
548 int ID = myElementIDFactory->GetFreeID();
549 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, ID);
550 if(v==NULL) myElementIDFactory->ReleaseID(ID);
554 ///////////////////////////////////////////////////////////////////////////////
555 ///Create a new prism and add it to the mesh.
556 ///Nodes 1,2,3 is a triangle and 1,2,5,4 a quadrangle.
557 ///@param ID The ID of the new volume
558 ///@return The created prism or NULL if an element with this ID already exists
559 ///or if input nodes are not found.
560 ///////////////////////////////////////////////////////////////////////////////
562 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
570 SMDS_MeshNode *node1, *node2, *node3, *node4, *node5, *node6;
571 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
572 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
573 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
574 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
575 node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5);
576 node6 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode6);
577 if(!node1 || !node2 || !node3 || !node4 || !node5 || !node6) return NULL;
578 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, node6, ID);
581 ///////////////////////////////////////////////////////////////////////////////
582 ///Create a new prism and add it to the mesh.
583 ///Nodes 1,2,3 is a triangle and 1,2,5,4 a quadrangle.
584 ///@param ID The ID of the new volume
585 ///@return The created prism
586 ///////////////////////////////////////////////////////////////////////////////
588 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
589 const SMDS_MeshNode * n2,
590 const SMDS_MeshNode * n3,
591 const SMDS_MeshNode * n4,
592 const SMDS_MeshNode * n5,
593 const SMDS_MeshNode * n6,
596 SMDS_MeshVolume* volume = 0;
597 if ( !n1 || !n2 || !n3 || !n4 || !n5 || !n6) return volume;
599 if(hasConstructionFaces()) {
600 SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3);
601 SMDS_MeshFace * f2=FindFaceOrCreate(n4,n5,n6);
602 SMDS_MeshFace * f3=FindFaceOrCreate(n1,n4,n5,n2);
603 SMDS_MeshFace * f4=FindFaceOrCreate(n2,n5,n6,n3);
604 SMDS_MeshFace * f5=FindFaceOrCreate(n3,n6,n4,n1);
605 volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5);
606 myVolumes.Add(volume);
608 else if(hasConstructionEdges()) {
609 MESSAGE("Error : Not implemented");
613 volume=new SMDS_VolumeOfNodes(n1,n2,n3,n4,n5,n6);
614 myVolumes.Add(volume);
617 if (!registerElement(ID, volume)) {
618 RemoveElement(volume, false);
624 ///////////////////////////////////////////////////////////////////////////////
625 ///Create a new hexahedron and add it to the mesh.
626 ///Nodes 1,2,3,4 and 5,6,7,8 are quadrangle and 5,1 and 7,3 are an edges.
627 ///@return The created hexahedron
628 ///////////////////////////////////////////////////////////////////////////////
630 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
631 const SMDS_MeshNode * n2,
632 const SMDS_MeshNode * n3,
633 const SMDS_MeshNode * n4,
634 const SMDS_MeshNode * n5,
635 const SMDS_MeshNode * n6,
636 const SMDS_MeshNode * n7,
637 const SMDS_MeshNode * n8)
639 int ID = myElementIDFactory->GetFreeID();
640 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, ID);
641 if(v==NULL) myElementIDFactory->ReleaseID(ID);
645 ///////////////////////////////////////////////////////////////////////////////
646 ///Create a new hexahedron and add it to the mesh.
647 ///Nodes 1,2,3,4 and 5,6,7,8 are quadrangle and 5,1 and 7,3 are an edges.
648 ///@param ID The ID of the new volume
649 ///@return The created hexahedron or NULL if an element with this ID already
650 ///exists or if input nodes are not found.
651 ///////////////////////////////////////////////////////////////////////////////
653 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
663 SMDS_MeshNode *node1, *node2, *node3, *node4, *node5, *node6, *node7, *node8;
664 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
665 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
666 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
667 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
668 node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5);
669 node6 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode6);
670 node7 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode7);
671 node8 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode8);
672 if(!node1 || !node2 || !node3 || !node4 || !node5 || !node6 || !node7 || !node8)
674 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, node6,
678 ///////////////////////////////////////////////////////////////////////////////
679 ///Create a new hexahedron and add it to the mesh.
680 ///Nodes 1,2,3,4 and 5,6,7,8 are quadrangle and 5,1 and 7,3 are an edges.
681 ///@param ID The ID of the new volume
682 ///@return The created prism or NULL if an element with this ID already exists
683 ///or if input nodes are not found.
684 ///////////////////////////////////////////////////////////////////////////////
686 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
687 const SMDS_MeshNode * n2,
688 const SMDS_MeshNode * n3,
689 const SMDS_MeshNode * n4,
690 const SMDS_MeshNode * n5,
691 const SMDS_MeshNode * n6,
692 const SMDS_MeshNode * n7,
693 const SMDS_MeshNode * n8,
696 SMDS_MeshVolume* volume = 0;
697 if ( !n1 || !n2 || !n3 || !n4 || !n5 || !n6 || !n7 || !n8) return volume;
699 if(hasConstructionFaces()) {
700 SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3,n4);
701 SMDS_MeshFace * f2=FindFaceOrCreate(n5,n6,n7,n8);
702 SMDS_MeshFace * f3=FindFaceOrCreate(n1,n4,n8,n5);
703 SMDS_MeshFace * f4=FindFaceOrCreate(n1,n2,n6,n5);
704 SMDS_MeshFace * f5=FindFaceOrCreate(n2,n3,n7,n6);
705 SMDS_MeshFace * f6=FindFaceOrCreate(n3,n4,n8,n7);
706 volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5,f6);
707 myVolumes.Add(volume);
709 else if(hasConstructionEdges()) {
710 MESSAGE("Error : Not implemented");
714 // volume=new SMDS_HexahedronOfNodes(n1,n2,n3,n4,n5,n6,n7,n8);
715 volume=new SMDS_VolumeOfNodes(n1,n2,n3,n4,n5,n6,n7,n8);
716 myVolumes.Add(volume);
719 if (!registerElement(ID, volume)) {
720 RemoveElement(volume, false);
726 ///////////////////////////////////////////////////////////////////////////////
727 ///Create a new tetrahedron defined by its faces and add it to the mesh.
728 ///@return The created tetrahedron
729 ///////////////////////////////////////////////////////////////////////////////
731 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshFace * f1,
732 const SMDS_MeshFace * f2,
733 const SMDS_MeshFace * f3,
734 const SMDS_MeshFace * f4)
736 if (!hasConstructionFaces())
738 return AddVolumeWithID(f1,f2,f3,f4, myElementIDFactory->GetFreeID());
741 ///////////////////////////////////////////////////////////////////////////////
742 ///Create a new tetrahedron defined by its faces and add it to the mesh.
743 ///@param ID The ID of the new volume
744 ///@return The created tetrahedron
745 ///////////////////////////////////////////////////////////////////////////////
747 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1,
748 const SMDS_MeshFace * f2,
749 const SMDS_MeshFace * f3,
750 const SMDS_MeshFace * f4,
753 if (!hasConstructionFaces())
755 if ( !f1 || !f2 || !f3 || !f4) return 0;
757 SMDS_MeshVolume * volume = new SMDS_VolumeOfFaces(f1,f2,f3,f4);
758 myVolumes.Add(volume);
760 if (!registerElement(ID, volume)) {
761 RemoveElement(volume, false);
767 ///////////////////////////////////////////////////////////////////////////////
768 ///Create a new pyramid defined by its faces and add it to the mesh.
769 ///@return The created pyramid
770 ///////////////////////////////////////////////////////////////////////////////
772 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshFace * f1,
773 const SMDS_MeshFace * f2,
774 const SMDS_MeshFace * f3,
775 const SMDS_MeshFace * f4,
776 const SMDS_MeshFace * f5)
778 if (!hasConstructionFaces())
780 return AddVolumeWithID(f1,f2,f3,f4,f5, myElementIDFactory->GetFreeID());
783 ///////////////////////////////////////////////////////////////////////////////
784 ///Create a new pyramid defined by its faces and add it to the mesh.
785 ///@param ID The ID of the new volume
786 ///@return The created pyramid
787 ///////////////////////////////////////////////////////////////////////////////
789 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1,
790 const SMDS_MeshFace * f2,
791 const SMDS_MeshFace * f3,
792 const SMDS_MeshFace * f4,
793 const SMDS_MeshFace * f5,
796 if (!hasConstructionFaces())
798 if ( !f1 || !f2 || !f3 || !f4 || !f5) return 0;
800 SMDS_MeshVolume * volume = new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5);
801 myVolumes.Add(volume);
803 if (!registerElement(ID, volume)) {
804 RemoveElement(volume, false);
810 ///////////////////////////////////////////////////////////////////////////////
811 ///Create a new prism defined by its faces and add it to the mesh.
812 ///@return The created prism
813 ///////////////////////////////////////////////////////////////////////////////
815 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshFace * f1,
816 const SMDS_MeshFace * f2,
817 const SMDS_MeshFace * f3,
818 const SMDS_MeshFace * f4,
819 const SMDS_MeshFace * f5,
820 const SMDS_MeshFace * f6)
822 if (!hasConstructionFaces())
824 return AddVolumeWithID(f1,f2,f3,f4,f5,f6, myElementIDFactory->GetFreeID());
827 ///////////////////////////////////////////////////////////////////////////////
828 ///Create a new prism defined by its faces and add it to the mesh.
829 ///@param ID The ID of the new volume
830 ///@return The created prism
831 ///////////////////////////////////////////////////////////////////////////////
833 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1,
834 const SMDS_MeshFace * f2,
835 const SMDS_MeshFace * f3,
836 const SMDS_MeshFace * f4,
837 const SMDS_MeshFace * f5,
838 const SMDS_MeshFace * f6,
841 if (!hasConstructionFaces())
843 if ( !f1 || !f2 || !f3 || !f4 || !f5 || !f6) return 0;
845 SMDS_MeshVolume * volume = new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5,f6);
846 myVolumes.Add(volume);
848 if (!registerElement(ID, volume)) {
849 RemoveElement(volume, false);
855 ///////////////////////////////////////////////////////////////////////////////
856 /// Add a polygon defined by its nodes IDs
857 ///////////////////////////////////////////////////////////////////////////////
859 SMDS_MeshFace* SMDS_Mesh::AddPolygonalFaceWithID (std::vector<int> nodes_ids,
862 int nbNodes = nodes_ids.size();
863 std::vector<const SMDS_MeshNode*> nodes (nbNodes);
864 for (int i = 0; i < nbNodes; i++) {
865 nodes[i] = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nodes_ids[i]);
866 if (!nodes[i]) return NULL;
868 return SMDS_Mesh::AddPolygonalFaceWithID(nodes, ID);
871 ///////////////////////////////////////////////////////////////////////////////
872 /// Add a polygon defined by its nodes
873 ///////////////////////////////////////////////////////////////////////////////
875 SMDS_MeshFace* SMDS_Mesh::AddPolygonalFaceWithID
876 (std::vector<const SMDS_MeshNode*> nodes,
879 SMDS_MeshFace * face;
882 if (hasConstructionEdges())
884 MESSAGE("Error : Not implemented");
889 for ( int i = 0; i < nodes.size(); ++i )
890 if ( !nodes[ i ] ) return 0;
891 face = new SMDS_PolygonalFaceOfNodes(nodes);
895 if (!registerElement(ID, face)) {
896 RemoveElement(face, false);
902 ///////////////////////////////////////////////////////////////////////////////
903 /// Add a polygon defined by its nodes.
904 /// An ID is automatically affected to the created face.
905 ///////////////////////////////////////////////////////////////////////////////
907 SMDS_MeshFace* SMDS_Mesh::AddPolygonalFace (std::vector<const SMDS_MeshNode*> nodes)
909 return SMDS_Mesh::AddPolygonalFaceWithID(nodes, myElementIDFactory->GetFreeID());
912 ///////////////////////////////////////////////////////////////////////////////
913 /// Create a new polyhedral volume and add it to the mesh.
914 /// @param ID The ID of the new volume
915 /// @return The created volume or NULL if an element with this ID already exists
916 /// or if input nodes are not found.
917 ///////////////////////////////////////////////////////////////////////////////
919 SMDS_MeshVolume * SMDS_Mesh::AddPolyhedralVolumeWithID
920 (std::vector<int> nodes_ids,
921 std::vector<int> quantities,
924 int nbNodes = nodes_ids.size();
925 std::vector<const SMDS_MeshNode*> nodes (nbNodes);
926 for (int i = 0; i < nbNodes; i++) {
927 nodes[i] = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nodes_ids[i]);
928 if (!nodes[i]) return NULL;
930 return SMDS_Mesh::AddPolyhedralVolumeWithID(nodes, quantities, ID);
933 ///////////////////////////////////////////////////////////////////////////////
934 /// Create a new polyhedral volume and add it to the mesh.
935 /// @param ID The ID of the new volume
936 /// @return The created volume
937 ///////////////////////////////////////////////////////////////////////////////
939 SMDS_MeshVolume* SMDS_Mesh::AddPolyhedralVolumeWithID
940 (std::vector<const SMDS_MeshNode*> nodes,
941 std::vector<int> quantities,
944 SMDS_MeshVolume* volume;
946 if (hasConstructionFaces()) {
947 MESSAGE("Error : Not implemented");
949 } else if (hasConstructionEdges()) {
950 MESSAGE("Error : Not implemented");
953 for ( int i = 0; i < nodes.size(); ++i )
954 if ( !nodes[ i ] ) return 0;
955 volume = new SMDS_PolyhedralVolumeOfNodes(nodes, quantities);
956 myVolumes.Add(volume);
959 if (!registerElement(ID, volume)) {
960 RemoveElement(volume, false);
966 ///////////////////////////////////////////////////////////////////////////////
967 /// Create a new polyhedral volume and add it to the mesh.
968 /// @return The created volume
969 ///////////////////////////////////////////////////////////////////////////////
971 SMDS_MeshVolume* SMDS_Mesh::AddPolyhedralVolume
972 (std::vector<const SMDS_MeshNode*> nodes,
973 std::vector<int> quantities)
975 int ID = myElementIDFactory->GetFreeID();
976 SMDS_MeshVolume * v = SMDS_Mesh::AddPolyhedralVolumeWithID(nodes, quantities, ID);
977 if (v == NULL) myElementIDFactory->ReleaseID(ID);
981 ///////////////////////////////////////////////////////////////////////////////
982 /// Registers element with the given ID, maintains inverse connections
983 ///////////////////////////////////////////////////////////////////////////////
984 bool SMDS_Mesh::registerElement(int ID, SMDS_MeshElement * element)
986 if (myElementIDFactory->BindID(ID, element)) {
987 SMDS_ElemIteratorPtr it = element->nodesIterator();
989 SMDS_MeshNode *node = static_cast<SMDS_MeshNode*>
990 (const_cast<SMDS_MeshElement*>(it->next()));
991 node->AddInverseElement(element);
998 ///////////////////////////////////////////////////////////////////////////////
999 /// Return the node whose ID is 'ID'.
1000 ///////////////////////////////////////////////////////////////////////////////
1001 const SMDS_MeshNode * SMDS_Mesh::FindNode(int ID) const
1003 return (const SMDS_MeshNode *)myNodeIDFactory->MeshElement(ID);
1006 ///////////////////////////////////////////////////////////////////////////////
1007 ///Create a triangle and add it to the current mesh. This methode do not bind a
1008 ///ID to the create triangle.
1009 ///////////////////////////////////////////////////////////////////////////////
1010 SMDS_MeshFace * SMDS_Mesh::createTriangle(const SMDS_MeshNode * node1,
1011 const SMDS_MeshNode * node2,
1012 const SMDS_MeshNode * node3)
1014 if ( !node1 || !node2 || !node3) return 0;
1016 if(hasConstructionEdges())
1018 SMDS_MeshEdge *edge1, *edge2, *edge3;
1019 edge1=FindEdgeOrCreate(node1,node2);
1020 edge2=FindEdgeOrCreate(node2,node3);
1021 edge3=FindEdgeOrCreate(node3,node1);
1023 SMDS_MeshFace * face = new SMDS_FaceOfEdges(edge1,edge2,edge3);
1029 SMDS_MeshFace * face = new SMDS_FaceOfNodes(node1,node2,node3);
1035 ///////////////////////////////////////////////////////////////////////////////
1036 ///Create a quadrangle and add it to the current mesh. This methode do not bind
1037 ///a ID to the create triangle.
1038 ///////////////////////////////////////////////////////////////////////////////
1039 SMDS_MeshFace * SMDS_Mesh::createQuadrangle(const SMDS_MeshNode * node1,
1040 const SMDS_MeshNode * node2,
1041 const SMDS_MeshNode * node3,
1042 const SMDS_MeshNode * node4)
1044 if ( !node1 || !node2 || !node3 || !node4 ) return 0;
1046 if(hasConstructionEdges())
1048 SMDS_MeshEdge *edge1, *edge2, *edge3, *edge4;
1049 edge1=FindEdgeOrCreate(node1,node2);
1050 edge2=FindEdgeOrCreate(node2,node3);
1051 edge3=FindEdgeOrCreate(node3,node4);
1052 edge4=FindEdgeOrCreate(node4,node1);
1054 SMDS_MeshFace * face = new SMDS_FaceOfEdges(edge1,edge2,edge3,edge4);
1060 SMDS_MeshFace * face = new SMDS_FaceOfNodes(node1,node2,node3,node4);
1066 ///////////////////////////////////////////////////////////////////////////////
1067 /// Remove a node and all the elements which own this node
1068 ///////////////////////////////////////////////////////////////////////////////
1070 void SMDS_Mesh::RemoveNode(const SMDS_MeshNode * node)
1072 RemoveElement(node, true);
1075 ///////////////////////////////////////////////////////////////////////////////
1076 /// Remove an edge and all the elements which own this edge
1077 ///////////////////////////////////////////////////////////////////////////////
1079 void SMDS_Mesh::RemoveEdge(const SMDS_MeshEdge * edge)
1081 RemoveElement(edge,true);
1084 ///////////////////////////////////////////////////////////////////////////////
1085 /// Remove an face and all the elements which own this face
1086 ///////////////////////////////////////////////////////////////////////////////
1088 void SMDS_Mesh::RemoveFace(const SMDS_MeshFace * face)
1090 RemoveElement(face, true);
1093 ///////////////////////////////////////////////////////////////////////////////
1095 ///////////////////////////////////////////////////////////////////////////////
1097 void SMDS_Mesh::RemoveVolume(const SMDS_MeshVolume * volume)
1099 RemoveElement(volume, true);
1102 //=======================================================================
1103 //function : RemoveFromParent
1105 //=======================================================================
1107 bool SMDS_Mesh::RemoveFromParent()
1109 if (myParent==NULL) return false;
1110 else return (myParent->RemoveSubMesh(this));
1113 //=======================================================================
1114 //function : RemoveSubMesh
1116 //=======================================================================
1118 bool SMDS_Mesh::RemoveSubMesh(const SMDS_Mesh * aMesh)
1122 list<SMDS_Mesh *>::iterator itmsh=myChildren.begin();
1123 for (; itmsh!=myChildren.end() && !found; itmsh++)
1125 SMDS_Mesh * submesh = *itmsh;
1126 if (submesh == aMesh)
1129 myChildren.erase(itmsh);
1136 //=======================================================================
1137 //function : ChangeElementNodes
1139 //=======================================================================
1141 bool SMDS_Mesh::ChangeElementNodes(const SMDS_MeshElement * elem,
1142 const SMDS_MeshNode * nodes[],
1145 // keep current nodes of elem
1146 set<const SMDS_MeshElement*> oldNodes;
1147 SMDS_ElemIteratorPtr itn = elem->nodesIterator();
1149 oldNodes.insert( itn->next() );
1153 switch ( elem->GetType() )
1155 case SMDSAbs_Edge: {
1156 if ( nbnodes == 2 ) {
1157 const SMDS_MeshEdge* edge = dynamic_cast<const SMDS_MeshEdge*>( elem );
1159 Ok = const_cast<SMDS_MeshEdge*>( edge )->ChangeNodes( nodes[0], nodes[1] );
1161 else if ( nbnodes == 3 ) {
1162 const SMDS_QuadraticEdge* edge = dynamic_cast<const SMDS_QuadraticEdge*>( elem );
1164 Ok = const_cast<SMDS_QuadraticEdge*>( edge )->ChangeNodes( nodes[0], nodes[1], nodes[2] );
1168 case SMDSAbs_Face: {
1169 const SMDS_FaceOfNodes* face = dynamic_cast<const SMDS_FaceOfNodes*>( elem );
1171 Ok = const_cast<SMDS_FaceOfNodes*>( face )->ChangeNodes( nodes, nbnodes );
1174 const SMDS_QuadraticFaceOfNodes* QF =
1175 dynamic_cast<const SMDS_QuadraticFaceOfNodes*>( elem );
1177 Ok = const_cast<SMDS_QuadraticFaceOfNodes*>( QF )->ChangeNodes( nodes, nbnodes );
1181 const SMDS_PolygonalFaceOfNodes* face = dynamic_cast<const SMDS_PolygonalFaceOfNodes*>(elem);
1183 Ok = const_cast<SMDS_PolygonalFaceOfNodes*>(face)->ChangeNodes(nodes, nbnodes);
1190 //case SMDSAbs_PolygonalFace: {
1191 // const SMDS_PolygonalFaceOfNodes* face = dynamic_cast<const SMDS_PolygonalFaceOfNodes*>(elem);
1193 // Ok = const_cast<SMDS_PolygonalFaceOfNodes*>(face)->ChangeNodes(nodes, nbnodes);
1197 case SMDSAbs_Volume: {
1198 const SMDS_VolumeOfNodes* vol = dynamic_cast<const SMDS_VolumeOfNodes*>( elem );
1200 Ok = const_cast<SMDS_VolumeOfNodes*>( vol )->ChangeNodes( nodes, nbnodes );
1203 const SMDS_QuadraticVolumeOfNodes* QV = dynamic_cast<const SMDS_QuadraticVolumeOfNodes*>( elem );
1205 Ok = const_cast<SMDS_QuadraticVolumeOfNodes*>( QV )->ChangeNodes( nodes, nbnodes );
1211 MESSAGE ( "WRONG ELEM TYPE");
1214 if ( Ok ) { // update InverseElements
1216 // AddInverseElement to new nodes
1217 for ( int i = 0; i < nbnodes; i++ )
1218 if ( oldNodes.find( nodes[i] ) == oldNodes.end() )
1220 const_cast<SMDS_MeshNode*>( nodes[i] )->AddInverseElement( elem );
1222 // remove from oldNodes a node that remains in elem
1223 oldNodes.erase( nodes[i] );
1226 // RemoveInverseElement from the nodes removed from elem
1227 set<const SMDS_MeshElement*>::iterator it;
1228 for ( it = oldNodes.begin(); it != oldNodes.end(); it++ )
1230 SMDS_MeshNode * n = static_cast<SMDS_MeshNode *>
1231 (const_cast<SMDS_MeshElement *>( *it ));
1232 n->RemoveInverseElement( elem );
1236 //MESSAGE ( "::ChangeNodes() Ok = " << Ok);
1241 //=======================================================================
1242 //function : ChangePolyhedronNodes
1243 //purpose : to change nodes of polyhedral volume
1244 //=======================================================================
1245 bool SMDS_Mesh::ChangePolyhedronNodes (const SMDS_MeshElement * elem,
1246 std::vector<const SMDS_MeshNode*> nodes,
1247 std::vector<int> quantities)
1249 if (elem->GetType() != SMDSAbs_Volume) {
1250 MESSAGE("WRONG ELEM TYPE");
1254 const SMDS_PolyhedralVolumeOfNodes* vol = dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*>(elem);
1259 // keep current nodes of elem
1260 set<const SMDS_MeshElement*> oldNodes;
1261 SMDS_ElemIteratorPtr itn = elem->nodesIterator();
1262 while (itn->more()) {
1263 oldNodes.insert(itn->next());
1267 bool Ok = const_cast<SMDS_PolyhedralVolumeOfNodes*>(vol)->ChangeNodes(nodes, quantities);
1272 // update InverseElements
1274 // AddInverseElement to new nodes
1275 int nbnodes = nodes.size();
1276 for (int i = 0; i < nbnodes; i++) {
1277 if (oldNodes.find(nodes[i]) == oldNodes.end()) {
1279 const_cast<SMDS_MeshNode*>(nodes[i])->AddInverseElement(elem);
1281 // remove from oldNodes a node that remains in elem
1282 oldNodes.erase(nodes[i]);
1286 // RemoveInverseElement from the nodes removed from elem
1287 set<const SMDS_MeshElement*>::iterator it;
1288 for (it = oldNodes.begin(); it != oldNodes.end(); it++) {
1289 SMDS_MeshNode * n = static_cast<SMDS_MeshNode *>
1290 (const_cast<SMDS_MeshElement *>( *it ));
1291 n->RemoveInverseElement(elem);
1298 //=======================================================================
1299 //function : FindEdge
1301 //=======================================================================
1303 const SMDS_MeshEdge* SMDS_Mesh::FindEdge(int idnode1, int idnode2) const
1305 const SMDS_MeshNode * node1=FindNode(idnode1);
1306 const SMDS_MeshNode * node2=FindNode(idnode2);
1307 if((node1==NULL)||(node2==NULL)) return NULL;
1308 return FindEdge(node1,node2);
1311 //#include "Profiler.h"
1312 const SMDS_MeshEdge* SMDS_Mesh::FindEdge(const SMDS_MeshNode * node1,
1313 const SMDS_MeshNode * node2)
1315 if ( !node1 ) return 0;
1316 const SMDS_MeshEdge * toReturn=NULL;
1319 SMDS_ElemIteratorPtr it1=node1->GetInverseElementIterator(SMDSAbs_Edge);
1322 while(it1->more()) {
1323 const SMDS_MeshElement * e = it1->next();
1324 if ( e->NbNodes() == 2 && e->GetNodeIndex( node2 ) >= 0 ) {
1325 toReturn = static_cast<const SMDS_MeshEdge*>( e );
1334 //=======================================================================
1335 //function : FindEdgeOrCreate
1337 //=======================================================================
1339 SMDS_MeshEdge* SMDS_Mesh::FindEdgeOrCreate(const SMDS_MeshNode * node1,
1340 const SMDS_MeshNode * node2)
1342 if ( !node1 || !node2) return 0;
1343 SMDS_MeshEdge * toReturn=NULL;
1344 toReturn=const_cast<SMDS_MeshEdge*>(FindEdge(node1,node2));
1345 if(toReturn==NULL) {
1347 toReturn=new SMDS_MeshEdge(node1,node2);
1348 myEdges.Add(toReturn);
1354 //=======================================================================
1355 //function : FindEdge
1357 //=======================================================================
1359 const SMDS_MeshEdge* SMDS_Mesh::FindEdge(int idnode1, int idnode2,
1362 const SMDS_MeshNode * node1=FindNode(idnode1);
1363 const SMDS_MeshNode * node2=FindNode(idnode2);
1364 const SMDS_MeshNode * node3=FindNode(idnode3);
1365 return FindEdge(node1,node2,node3);
1368 const SMDS_MeshEdge* SMDS_Mesh::FindEdge(const SMDS_MeshNode * node1,
1369 const SMDS_MeshNode * node2,
1370 const SMDS_MeshNode * node3)
1372 if ( !node1 ) return 0;
1373 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Edge);
1374 while(it1->more()) {
1375 const SMDS_MeshElement * e = it1->next();
1376 if ( e->NbNodes() == 3 ) {
1377 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
1378 while(it2->more()) {
1379 const SMDS_MeshElement* n = it2->next();
1389 return static_cast<const SMDS_MeshEdge *> (e);
1396 //=======================================================================
1397 //function : FindFace
1399 //=======================================================================
1401 const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2,
1404 const SMDS_MeshNode * node1=FindNode(idnode1);
1405 const SMDS_MeshNode * node2=FindNode(idnode2);
1406 const SMDS_MeshNode * node3=FindNode(idnode3);
1407 return FindFace(node1, node2, node3);
1410 const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1,
1411 const SMDS_MeshNode *node2,
1412 const SMDS_MeshNode *node3)
1414 if ( !node1 ) return 0;
1415 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Face);
1416 while(it1->more()) {
1417 const SMDS_MeshElement * e = it1->next();
1418 if ( e->NbNodes() == 3 ) {
1419 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
1420 while(it2->more()) {
1421 const SMDS_MeshElement* n = it2->next();
1431 return static_cast<const SMDS_MeshFace *> (e);
1437 SMDS_MeshFace* SMDS_Mesh::FindFaceOrCreate(const SMDS_MeshNode *node1,
1438 const SMDS_MeshNode *node2,
1439 const SMDS_MeshNode *node3)
1441 SMDS_MeshFace * toReturn=NULL;
1442 toReturn = const_cast<SMDS_MeshFace*>(FindFace(node1,node2,node3));
1443 if(toReturn==NULL) {
1444 toReturn = createTriangle(node1,node2,node3);
1450 //=======================================================================
1451 //function : FindFace
1453 //=======================================================================
1455 const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2,
1456 int idnode3, int idnode4) const
1458 const SMDS_MeshNode * node1=FindNode(idnode1);
1459 const SMDS_MeshNode * node2=FindNode(idnode2);
1460 const SMDS_MeshNode * node3=FindNode(idnode3);
1461 const SMDS_MeshNode * node4=FindNode(idnode4);
1462 return FindFace(node1, node2, node3, node4);
1465 const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1,
1466 const SMDS_MeshNode *node2,
1467 const SMDS_MeshNode *node3,
1468 const SMDS_MeshNode *node4)
1470 if ( !node1 ) return 0;
1471 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Face);
1472 while(it1->more()) {
1473 const SMDS_MeshElement * e = it1->next();
1474 if ( e->NbNodes() == 4 ) {
1475 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
1476 while(it2->more()) {
1477 const SMDS_MeshElement* n = it2->next();
1488 return static_cast<const SMDS_MeshFace *> (e);
1494 SMDS_MeshFace* SMDS_Mesh::FindFaceOrCreate(const SMDS_MeshNode *node1,
1495 const SMDS_MeshNode *node2,
1496 const SMDS_MeshNode *node3,
1497 const SMDS_MeshNode *node4)
1499 SMDS_MeshFace * toReturn=NULL;
1500 toReturn=const_cast<SMDS_MeshFace*>(FindFace(node1,node2,node3,node4));
1501 if(toReturn==NULL) {
1502 toReturn=createQuadrangle(node1,node2,node3,node4);
1508 //=======================================================================
1509 //function : FindFace
1510 //purpose :quadratic triangle
1511 //=======================================================================
1513 const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2,
1514 int idnode3, int idnode4,
1515 int idnode5, int idnode6) const
1517 const SMDS_MeshNode * node1 = FindNode(idnode1);
1518 const SMDS_MeshNode * node2 = FindNode(idnode2);
1519 const SMDS_MeshNode * node3 = FindNode(idnode3);
1520 const SMDS_MeshNode * node4 = FindNode(idnode4);
1521 const SMDS_MeshNode * node5 = FindNode(idnode5);
1522 const SMDS_MeshNode * node6 = FindNode(idnode6);
1523 return FindFace(node1, node2, node3, node4, node5, node6);
1526 const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1,
1527 const SMDS_MeshNode *node2,
1528 const SMDS_MeshNode *node3,
1529 const SMDS_MeshNode *node4,
1530 const SMDS_MeshNode *node5,
1531 const SMDS_MeshNode *node6)
1533 if ( !node1 ) return 0;
1534 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Face);
1535 while(it1->more()) {
1536 const SMDS_MeshElement * e = it1->next();
1537 if ( e->NbNodes() == 6 ) {
1538 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
1539 while(it2->more()) {
1540 const SMDS_MeshElement* n = it2->next();
1553 return static_cast<const SMDS_MeshFace *> (e);
1560 //=======================================================================
1561 //function : FindFace
1562 //purpose : quadratic quadrangle
1563 //=======================================================================
1565 const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2,
1566 int idnode3, int idnode4,
1567 int idnode5, int idnode6,
1568 int idnode7, int idnode8) const
1570 const SMDS_MeshNode * node1 = FindNode(idnode1);
1571 const SMDS_MeshNode * node2 = FindNode(idnode2);
1572 const SMDS_MeshNode * node3 = FindNode(idnode3);
1573 const SMDS_MeshNode * node4 = FindNode(idnode4);
1574 const SMDS_MeshNode * node5 = FindNode(idnode5);
1575 const SMDS_MeshNode * node6 = FindNode(idnode6);
1576 const SMDS_MeshNode * node7 = FindNode(idnode7);
1577 const SMDS_MeshNode * node8 = FindNode(idnode8);
1578 return FindFace(node1, node2, node3, node4, node5, node6, node7, node8);
1581 const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1,
1582 const SMDS_MeshNode *node2,
1583 const SMDS_MeshNode *node3,
1584 const SMDS_MeshNode *node4,
1585 const SMDS_MeshNode *node5,
1586 const SMDS_MeshNode *node6,
1587 const SMDS_MeshNode *node7,
1588 const SMDS_MeshNode *node8)
1590 if ( !node1 ) return 0;
1591 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Face);
1592 while(it1->more()) {
1593 const SMDS_MeshElement * e = it1->next();
1594 if ( e->NbNodes() == 8 ) {
1595 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
1596 while(it2->more()) {
1597 const SMDS_MeshElement* n = it2->next();
1612 return static_cast<const SMDS_MeshFace *> (e);
1619 //=======================================================================
1620 //function : FindElement
1622 //=======================================================================
1624 const SMDS_MeshElement* SMDS_Mesh::FindElement(int IDelem) const
1626 return myElementIDFactory->MeshElement(IDelem);
1629 //=======================================================================
1630 //function : FindFace
1631 //purpose : find polygon
1632 //=======================================================================
1634 const SMDS_MeshFace* SMDS_Mesh::FindFace (std::vector<int> nodes_ids) const
1636 int nbnodes = nodes_ids.size();
1637 std::vector<const SMDS_MeshNode *> poly_nodes (nbnodes);
1638 for (int inode = 0; inode < nbnodes; inode++) {
1639 const SMDS_MeshNode * node = FindNode(nodes_ids[inode]);
1640 if (node == NULL) return NULL;
1642 return FindFace(poly_nodes);
1645 const SMDS_MeshFace* SMDS_Mesh::FindFace (std::vector<const SMDS_MeshNode *> nodes)
1647 if ( nodes.size() > 2 && nodes[0] ) {
1648 SMDS_ElemIteratorPtr itF = nodes[0]->GetInverseElementIterator(SMDSAbs_Face);
1649 while (itF->more()) {
1650 const SMDS_MeshElement* f = itF->next();
1651 if ( f->NbNodes() == nodes.size() ) {
1652 SMDS_ElemIteratorPtr it2 = f->nodesIterator();
1653 while(it2->more()) {
1654 if ( find( nodes.begin(), nodes.end(), it2->next() ) == nodes.end() ) {
1660 return static_cast<const SMDS_MeshFace *> (f);
1667 //=======================================================================
1668 //function : DumpNodes
1670 //=======================================================================
1672 void SMDS_Mesh::DumpNodes() const
1674 MESSAGE("dump nodes of mesh : ");
1675 SMDS_NodeIteratorPtr itnode=nodesIterator();
1676 while(itnode->more()) MESSAGE(itnode->next());
1679 //=======================================================================
1680 //function : DumpEdges
1682 //=======================================================================
1684 void SMDS_Mesh::DumpEdges() const
1686 MESSAGE("dump edges of mesh : ");
1687 SMDS_EdgeIteratorPtr itedge=edgesIterator();
1688 while(itedge->more()) MESSAGE(itedge->next());
1691 //=======================================================================
1692 //function : DumpFaces
1694 //=======================================================================
1696 void SMDS_Mesh::DumpFaces() const
1698 MESSAGE("dump faces of mesh : ");
1699 SMDS_FaceIteratorPtr itface=facesIterator();
1700 while(itface->more()) MESSAGE(itface->next());
1703 //=======================================================================
1704 //function : DumpVolumes
1706 //=======================================================================
1708 void SMDS_Mesh::DumpVolumes() const
1710 MESSAGE("dump volumes of mesh : ");
1711 SMDS_VolumeIteratorPtr itvol=volumesIterator();
1712 while(itvol->more()) MESSAGE(itvol->next());
1715 //=======================================================================
1716 //function : DebugStats
1718 //=======================================================================
1720 void SMDS_Mesh::DebugStats() const
1722 MESSAGE("Debug stats of mesh : ");
1724 MESSAGE("===== NODES ====="<<NbNodes());
1725 MESSAGE("===== EDGES ====="<<NbEdges());
1726 MESSAGE("===== FACES ====="<<NbFaces());
1727 MESSAGE("===== VOLUMES ====="<<NbVolumes());
1729 MESSAGE("End Debug stats of mesh ");
1733 SMDS_NodeIteratorPtr itnode=nodesIterator();
1734 int sizeofnodes = 0;
1735 int sizeoffaces = 0;
1737 while(itnode->more())
1739 const SMDS_MeshNode *node = itnode->next();
1741 sizeofnodes += sizeof(*node);
1743 SMDS_ElemIteratorPtr it = node->GetInverseElementIterator();
1746 const SMDS_MeshElement *me = it->next();
1747 sizeofnodes += sizeof(me);
1752 SMDS_FaceIteratorPtr itface=facesIterator();
1753 while(itface->more())
1755 const SMDS_MeshElement *face = itface->next();
1756 sizeoffaces += sizeof(*face);
1759 MESSAGE("total size of node elements = " << sizeofnodes);;
1760 MESSAGE("total size of face elements = " << sizeoffaces);;
1765 ///////////////////////////////////////////////////////////////////////////////
1766 /// Return the number of nodes
1767 ///////////////////////////////////////////////////////////////////////////////
1768 int SMDS_Mesh::NbNodes() const
1770 return myNodes.Size();
1773 ///////////////////////////////////////////////////////////////////////////////
1774 /// Return the number of edges (including construction edges)
1775 ///////////////////////////////////////////////////////////////////////////////
1776 int SMDS_Mesh::NbEdges() const
1778 return myEdges.Size();
1781 ///////////////////////////////////////////////////////////////////////////////
1782 /// Return the number of faces (including construction faces)
1783 ///////////////////////////////////////////////////////////////////////////////
1784 int SMDS_Mesh::NbFaces() const
1786 return myFaces.Size();
1789 ///////////////////////////////////////////////////////////////////////////////
1790 /// Return the number of volumes
1791 ///////////////////////////////////////////////////////////////////////////////
1792 int SMDS_Mesh::NbVolumes() const
1794 return myVolumes.Size();
1797 ///////////////////////////////////////////////////////////////////////////////
1798 /// Return the number of child mesh of this mesh.
1799 /// Note that the tree structure of SMDS_Mesh seems to be unused in this version
1800 /// (2003-09-08) of SMESH
1801 ///////////////////////////////////////////////////////////////////////////////
1802 int SMDS_Mesh::NbSubMesh() const
1804 return myChildren.size();
1807 ///////////////////////////////////////////////////////////////////////////////
1808 /// Destroy the mesh and all its elements
1809 /// All pointer on elements owned by this mesh become illegals.
1810 ///////////////////////////////////////////////////////////////////////////////
1811 SMDS_Mesh::~SMDS_Mesh()
1813 list<SMDS_Mesh*>::iterator itc=myChildren.begin();
1814 while(itc!=myChildren.end())
1820 SetOfNodes::Iterator itn(myNodes);
1821 for (; itn.More(); itn.Next())
1824 SetOfEdges::Iterator ite(myEdges);
1825 for (; ite.More(); ite.Next())
1827 SMDS_MeshElement* elem = ite.Value();
1829 myElementIDFactory->ReleaseID(elem->GetID());
1833 SetOfFaces::Iterator itf(myFaces);
1834 for (; itf.More(); itf.Next())
1836 SMDS_MeshElement* elem = itf.Value();
1838 myElementIDFactory->ReleaseID(elem->GetID());
1842 SetOfVolumes::Iterator itv(myVolumes);
1843 for (; itv.More(); itv.Next())
1845 SMDS_MeshElement* elem = itv.Value();
1847 myElementIDFactory->ReleaseID(elem->GetID());
1853 delete myNodeIDFactory;
1854 delete myElementIDFactory;
1858 ///////////////////////////////////////////////////////////////////////////////
1859 /// Return true if this mesh create faces with edges.
1860 /// A false returned value mean that faces are created with nodes. A concequence
1861 /// is, iteration on edges (SMDS_Element::edgesIterator) will be unavailable.
1862 ///////////////////////////////////////////////////////////////////////////////
1863 bool SMDS_Mesh::hasConstructionEdges()
1865 return myHasConstructionEdges;
1868 ///////////////////////////////////////////////////////////////////////////////
1869 /// Return true if this mesh create volumes with faces
1870 /// A false returned value mean that volumes are created with nodes or edges.
1871 /// (see hasConstructionEdges)
1872 /// A concequence is, iteration on faces (SMDS_Element::facesIterator) will be
1874 ///////////////////////////////////////////////////////////////////////////////
1875 bool SMDS_Mesh::hasConstructionFaces()
1877 return myHasConstructionFaces;
1880 ///////////////////////////////////////////////////////////////////////////////
1881 /// Return true if nodes are linked to the finit elements, they are belonging to.
1882 /// Currently, It always return true.
1883 ///////////////////////////////////////////////////////////////////////////////
1884 bool SMDS_Mesh::hasInverseElements()
1886 return myHasInverseElements;
1889 ///////////////////////////////////////////////////////////////////////////////
1890 /// Make this mesh creating construction edges (see hasConstructionEdges)
1891 /// @param b true to have construction edges, else false.
1892 ///////////////////////////////////////////////////////////////////////////////
1893 void SMDS_Mesh::setConstructionEdges(bool b)
1895 myHasConstructionEdges=b;
1898 ///////////////////////////////////////////////////////////////////////////////
1899 /// Make this mesh creating construction faces (see hasConstructionFaces)
1900 /// @param b true to have construction faces, else false.
1901 ///////////////////////////////////////////////////////////////////////////////
1902 void SMDS_Mesh::setConstructionFaces(bool b)
1904 myHasConstructionFaces=b;
1907 ///////////////////////////////////////////////////////////////////////////////
1908 /// Make this mesh creating link from nodes to elements (see hasInverseElements)
1909 /// @param b true to link nodes to elements, else false.
1910 ///////////////////////////////////////////////////////////////////////////////
1911 void SMDS_Mesh::setInverseElements(bool b)
1913 if(!b) MESSAGE("Error : inverseElement=false not implemented");
1914 myHasInverseElements=b;
1917 ///////////////////////////////////////////////////////////////////////////////
1918 /// Return an iterator on nodes of the current mesh factory
1919 ///////////////////////////////////////////////////////////////////////////////
1920 class SMDS_Mesh_MyNodeIterator:public SMDS_NodeIterator
1922 SMDS_ElemIteratorPtr myIterator;
1924 SMDS_Mesh_MyNodeIterator(const SMDS_ElemIteratorPtr& it):myIterator(it)
1929 return myIterator->more();
1932 const SMDS_MeshNode* next()
1934 return static_cast<const SMDS_MeshNode*>(myIterator->next());
1938 SMDS_NodeIteratorPtr SMDS_Mesh::nodesIterator() const
1940 return SMDS_NodeIteratorPtr
1941 (new SMDS_Mesh_MyNodeIterator(myNodeIDFactory->elementsIterator()));
1944 ///////////////////////////////////////////////////////////////////////////////
1945 /// Return an iterator on elements of the current mesh factory
1946 ///////////////////////////////////////////////////////////////////////////////
1947 SMDS_ElemIteratorPtr SMDS_Mesh::elementsIterator() const
1949 return myElementIDFactory->elementsIterator();
1952 ///////////////////////////////////////////////////////////////////////////////
1953 ///Return an iterator on edges of the current mesh.
1954 ///////////////////////////////////////////////////////////////////////////////
1955 class SMDS_Mesh_MyEdgeIterator:public SMDS_EdgeIterator
1957 typedef SMDS_Mesh::SetOfEdges SetOfEdges;
1958 SetOfEdges::Iterator myIterator;
1960 SMDS_Mesh_MyEdgeIterator(const SetOfEdges& s):myIterator(s)
1965 while(myIterator.More())
1967 if(myIterator.Value()->GetID()!=-1)
1974 const SMDS_MeshEdge* next()
1976 const SMDS_MeshEdge* current = myIterator.Value();
1982 SMDS_EdgeIteratorPtr SMDS_Mesh::edgesIterator() const
1984 return SMDS_EdgeIteratorPtr(new SMDS_Mesh_MyEdgeIterator(myEdges));
1987 ///////////////////////////////////////////////////////////////////////////////
1988 ///Return an iterator on faces of the current mesh.
1989 ///////////////////////////////////////////////////////////////////////////////
1990 class SMDS_Mesh_MyFaceIterator:public SMDS_FaceIterator
1992 typedef SMDS_Mesh::SetOfFaces SetOfFaces;
1993 SetOfFaces::Iterator myIterator;
1995 SMDS_Mesh_MyFaceIterator(const SetOfFaces& s):myIterator(s)
2000 while(myIterator.More())
2002 if(myIterator.Value()->GetID()!=-1)
2009 const SMDS_MeshFace* next()
2011 const SMDS_MeshFace* current = myIterator.Value();
2017 SMDS_FaceIteratorPtr SMDS_Mesh::facesIterator() const
2019 return SMDS_FaceIteratorPtr(new SMDS_Mesh_MyFaceIterator(myFaces));
2022 ///////////////////////////////////////////////////////////////////////////////
2023 ///Return an iterator on volumes of the current mesh.
2024 ///////////////////////////////////////////////////////////////////////////////
2025 class SMDS_Mesh_MyVolumeIterator:public SMDS_VolumeIterator
2027 typedef SMDS_Mesh::SetOfVolumes SetOfVolumes;
2028 SetOfVolumes::Iterator myIterator;
2030 SMDS_Mesh_MyVolumeIterator(const SetOfVolumes& s):myIterator(s)
2035 return myIterator.More() != Standard_False;
2038 const SMDS_MeshVolume* next()
2040 const SMDS_MeshVolume* current = myIterator.Value();
2046 SMDS_VolumeIteratorPtr SMDS_Mesh::volumesIterator() const
2048 return SMDS_VolumeIteratorPtr(new SMDS_Mesh_MyVolumeIterator(myVolumes));
2051 ///////////////////////////////////////////////////////////////////////////////
2052 /// Do intersection of sets (more than 2)
2053 ///////////////////////////////////////////////////////////////////////////////
2054 static set<const SMDS_MeshElement*> * intersectionOfSets(
2055 set<const SMDS_MeshElement*> vs[], int numberOfSets)
2057 set<const SMDS_MeshElement*>* rsetA=new set<const SMDS_MeshElement*>(vs[0]);
2058 set<const SMDS_MeshElement*>* rsetB;
2060 for(int i=0; i<numberOfSets-1; i++)
2062 rsetB=new set<const SMDS_MeshElement*>();
2064 rsetA->begin(), rsetA->end(),
2065 vs[i+1].begin(), vs[i+1].end(),
2066 inserter(*rsetB, rsetB->begin()));
2073 ///////////////////////////////////////////////////////////////////////////////
2074 /// Return the list of finit elements owning the given element
2075 ///////////////////////////////////////////////////////////////////////////////
2076 static set<const SMDS_MeshElement*> * getFinitElements(const SMDS_MeshElement * element)
2078 int numberOfSets=element->NbNodes();
2079 set<const SMDS_MeshElement*> *initSet = new set<const SMDS_MeshElement*>[numberOfSets];
2081 SMDS_ElemIteratorPtr itNodes=element->nodesIterator();
2084 while(itNodes->more())
2086 const SMDS_MeshNode * n=static_cast<const SMDS_MeshNode*>(itNodes->next());
2087 SMDS_ElemIteratorPtr itFe = n->GetInverseElementIterator();
2089 //initSet[i]=set<const SMDS_MeshElement*>();
2091 initSet[i].insert(itFe->next());
2095 set<const SMDS_MeshElement*> *retSet=intersectionOfSets(initSet, numberOfSets);
2100 ///////////////////////////////////////////////////////////////////////////////
2101 /// Return the list of nodes used only by the given elements
2102 ///////////////////////////////////////////////////////////////////////////////
2103 static set<const SMDS_MeshElement*> * getExclusiveNodes(
2104 set<const SMDS_MeshElement*>& elements)
2106 set<const SMDS_MeshElement*> * toReturn=new set<const SMDS_MeshElement*>();
2107 set<const SMDS_MeshElement*>::iterator itElements=elements.begin();
2109 while(itElements!=elements.end())
2111 SMDS_ElemIteratorPtr itNodes = (*itElements)->nodesIterator();
2114 while(itNodes->more())
2116 const SMDS_MeshNode * n=static_cast<const SMDS_MeshNode*>(itNodes->next());
2117 SMDS_ElemIteratorPtr itFe = n->GetInverseElementIterator();
2118 set<const SMDS_MeshElement*> s;
2120 s.insert(itFe->next());
2121 if(s==elements) toReturn->insert(n);
2127 ///////////////////////////////////////////////////////////////////////////////
2128 ///Find the children of an element that are made of given nodes
2129 ///@param setOfChildren The set in which matching children will be inserted
2130 ///@param element The element were to search matching children
2131 ///@param nodes The nodes that the children must have to be selected
2132 ///////////////////////////////////////////////////////////////////////////////
2133 void SMDS_Mesh::addChildrenWithNodes(set<const SMDS_MeshElement*>& setOfChildren,
2134 const SMDS_MeshElement * element, set<const SMDS_MeshElement*>& nodes)
2137 switch(element->GetType())
2140 MESSAGE("Internal Error: This should not append");
2144 SMDS_ElemIteratorPtr itn=element->nodesIterator();
2147 const SMDS_MeshElement * e=itn->next();
2148 if(nodes.find(e)!=nodes.end())
2150 setOfChildren.insert(element);
2157 SMDS_ElemIteratorPtr itn=element->nodesIterator();
2160 const SMDS_MeshElement * e=itn->next();
2161 if(nodes.find(e)!=nodes.end())
2163 setOfChildren.insert(element);
2167 if(hasConstructionEdges())
2169 SMDS_ElemIteratorPtr ite=element->edgesIterator();
2171 addChildrenWithNodes(setOfChildren, ite->next(), nodes);
2174 case SMDSAbs_Volume:
2176 if(hasConstructionFaces())
2178 SMDS_ElemIteratorPtr ite=element->facesIterator();
2180 addChildrenWithNodes(setOfChildren, ite->next(), nodes);
2182 else if(hasConstructionEdges())
2184 SMDS_ElemIteratorPtr ite=element->edgesIterator();
2186 addChildrenWithNodes(setOfChildren, ite->next(), nodes);
2192 ///////////////////////////////////////////////////////////////////////////////
2193 ///@param elem The element to delete
2194 ///@param removenodes if true remaining nodes will be removed
2195 ///////////////////////////////////////////////////////////////////////////////
2196 void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem,
2197 const bool removenodes)
2199 list<const SMDS_MeshElement *> removedElems;
2200 list<const SMDS_MeshElement *> removedNodes;
2201 RemoveElement( elem, removedElems, removedNodes, removenodes );
2204 ///////////////////////////////////////////////////////////////////////////////
2205 ///@param elem The element to delete
2206 ///@param removedElems contains all removed elements
2207 ///@param removedNodes contains all removed nodes
2208 ///@param removenodes if true remaining nodes will be removed
2209 ///////////////////////////////////////////////////////////////////////////////
2210 void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem,
2211 list<const SMDS_MeshElement *>& removedElems,
2212 list<const SMDS_MeshElement *>& removedNodes,
2215 // get finite elements built on elem
2216 set<const SMDS_MeshElement*> * s1;
2217 if (!hasConstructionEdges() && elem->GetType() == SMDSAbs_Edge ||
2218 !hasConstructionFaces() && elem->GetType() == SMDSAbs_Face ||
2219 elem->GetType() == SMDSAbs_Volume)
2221 s1 = new set<const SMDS_MeshElement*>();
2225 s1 = getFinitElements(elem);
2227 // get exclusive nodes (which would become free afterwards)
2228 set<const SMDS_MeshElement*> * s2;
2229 if (elem->GetType() == SMDSAbs_Node) // a node is removed
2231 // do not remove nodes except elem
2232 s2 = new set<const SMDS_MeshElement*>();
2237 s2 = getExclusiveNodes(*s1);
2239 // form the set of finite and construction elements to remove
2240 set<const SMDS_MeshElement*> s3;
2241 set<const SMDS_MeshElement*>::iterator it=s1->begin();
2242 while(it!=s1->end())
2244 addChildrenWithNodes(s3, *it ,*s2);
2248 if(elem->GetType()!=SMDSAbs_Node) s3.insert(elem);
2250 // remove finite and construction elements
2254 // Remove element from <InverseElements> of its nodes
2255 SMDS_ElemIteratorPtr itn=(*it)->nodesIterator();
2258 SMDS_MeshNode * n = static_cast<SMDS_MeshNode *>
2259 (const_cast<SMDS_MeshElement *>(itn->next()));
2260 n->RemoveInverseElement( (*it) );
2263 switch((*it)->GetType())
2266 MESSAGE("Internal Error: This should not happen");
2269 myEdges.Remove(static_cast<SMDS_MeshEdge*>
2270 (const_cast<SMDS_MeshElement*>(*it)));
2273 myFaces.Remove(static_cast<SMDS_MeshFace*>
2274 (const_cast<SMDS_MeshElement*>(*it)));
2276 case SMDSAbs_Volume:
2277 myVolumes.Remove(static_cast<SMDS_MeshVolume*>
2278 (const_cast<SMDS_MeshElement*>(*it)));
2281 //MESSAGE( "SMDS: RM elem " << (*it)->GetID() );
2282 removedElems.push_back( (*it) );
2283 myElementIDFactory->ReleaseID((*it)->GetID());
2288 // remove exclusive (free) nodes
2292 while(it!=s2->end())
2294 //MESSAGE( "SMDS: RM node " << (*it)->GetID() );
2295 myNodes.Remove(static_cast<SMDS_MeshNode*>
2296 (const_cast<SMDS_MeshElement*>(*it)));
2297 myNodeIDFactory->ReleaseID((*it)->GetID());
2298 removedNodes.push_back( (*it) );
2309 ///////////////////////////////////////////////////////////////////////////////
2310 ///@param elem The element to delete
2311 ///////////////////////////////////////////////////////////////////////////////
2312 void SMDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elem)
2314 SMDSAbs_ElementType aType = elem->GetType();
2315 if (aType == SMDSAbs_Node) {
2316 // only free node can be removed by this method
2317 const SMDS_MeshNode* n = static_cast<const SMDS_MeshNode*>(elem);
2318 SMDS_ElemIteratorPtr itFe = n->GetInverseElementIterator();
2319 if (!itFe->more()) { // free node
2320 myNodes.Remove(const_cast<SMDS_MeshNode*>(n));
2321 myNodeIDFactory->ReleaseID(elem->GetID());
2325 if (hasConstructionEdges() || hasConstructionFaces())
2326 // this methods is only for meshes without descendants
2329 // Remove element from <InverseElements> of its nodes
2330 SMDS_ElemIteratorPtr itn = elem->nodesIterator();
2331 while (itn->more()) {
2332 SMDS_MeshNode * n = static_cast<SMDS_MeshNode *>
2333 (const_cast<SMDS_MeshElement *>(itn->next()));
2334 n->RemoveInverseElement(elem);
2337 // in meshes without descendants elements are always free
2340 myEdges.Remove(static_cast<SMDS_MeshEdge*>
2341 (const_cast<SMDS_MeshElement*>(elem)));
2344 myFaces.Remove(static_cast<SMDS_MeshFace*>
2345 (const_cast<SMDS_MeshElement*>(elem)));
2347 case SMDSAbs_Volume:
2348 myVolumes.Remove(static_cast<SMDS_MeshVolume*>
2349 (const_cast<SMDS_MeshElement*>(elem)));
2354 myElementIDFactory->ReleaseID(elem->GetID());
2360 * Checks if the element is present in mesh.
2361 * Useful to determine dead pointers.
2363 bool SMDS_Mesh::Contains (const SMDS_MeshElement* elem) const
2365 // we should not imply on validity of *elem, so iterate on containers
2366 // of all types in the hope of finding <elem> somewhere there
2367 SMDS_NodeIteratorPtr itn = nodesIterator();
2369 if (elem == itn->next())
2371 SMDS_EdgeIteratorPtr ite = edgesIterator();
2373 if (elem == ite->next())
2375 SMDS_FaceIteratorPtr itf = facesIterator();
2377 if (elem == itf->next())
2379 SMDS_VolumeIteratorPtr itv = volumesIterator();
2381 if (elem == itv->next())
2386 //=======================================================================
2387 //function : MaxNodeID
2389 //=======================================================================
2391 int SMDS_Mesh::MaxNodeID() const
2393 return myNodeIDFactory->GetMaxID();
2396 //=======================================================================
2397 //function : MinNodeID
2399 //=======================================================================
2401 int SMDS_Mesh::MinNodeID() const
2403 return myNodeIDFactory->GetMinID();
2406 //=======================================================================
2407 //function : MaxElementID
2409 //=======================================================================
2411 int SMDS_Mesh::MaxElementID() const
2413 return myElementIDFactory->GetMaxID();
2416 //=======================================================================
2417 //function : MinElementID
2419 //=======================================================================
2421 int SMDS_Mesh::MinElementID() const
2423 return myElementIDFactory->GetMinID();
2426 //=======================================================================
2427 //function : Renumber
2428 //purpose : Renumber all nodes or elements.
2429 //=======================================================================
2431 void SMDS_Mesh::Renumber (const bool isNodes, const int startID, const int deltaID)
2436 SMDS_MeshElementIDFactory * idFactory =
2437 isNodes ? myNodeIDFactory : myElementIDFactory;
2439 // get existing elements in the order of ID increasing
2440 map<int,SMDS_MeshElement*> elemMap;
2441 SMDS_ElemIteratorPtr idElemIt = idFactory->elementsIterator();
2442 while ( idElemIt->more() ) {
2443 SMDS_MeshElement* elem = const_cast<SMDS_MeshElement*>(idElemIt->next());
2444 int id = elem->GetID();
2445 elemMap.insert(map<int,SMDS_MeshElement*>::value_type(id, elem));
2447 // release their ids
2448 map<int,SMDS_MeshElement*>::iterator elemIt = elemMap.begin();
2449 for ( ; elemIt != elemMap.end(); elemIt++ )
2451 int id = (*elemIt).first;
2452 idFactory->ReleaseID( id );
2456 elemIt = elemMap.begin();
2457 for ( ; elemIt != elemMap.end(); elemIt++ )
2459 idFactory->BindID( ID, (*elemIt).second );
2464 //=======================================================================
2465 //function : GetElementType
2466 //purpose : Return type of element or node with id
2467 //=======================================================================
2469 SMDSAbs_ElementType SMDS_Mesh::GetElementType( const int id, const bool iselem ) const
2471 SMDS_MeshElement* elem = 0;
2473 elem = myElementIDFactory->MeshElement( id );
2475 elem = myNodeIDFactory->MeshElement( id );
2479 //throw SALOME_Exception(LOCALIZED ("this element isn't exist"));
2483 return elem->GetType();
2488 //********************************************************************
2489 //********************************************************************
2490 //******** *********
2491 //***** Methods for addition of quadratic elements ******
2492 //******** *********
2493 //********************************************************************
2494 //********************************************************************
2496 //=======================================================================
2497 //function : AddEdgeWithID
2499 //=======================================================================
2500 SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(int n1, int n2, int n12, int ID)
2502 return SMDS_Mesh::AddEdgeWithID
2503 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1),
2504 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2),
2505 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
2509 //=======================================================================
2510 //function : AddEdge
2512 //=======================================================================
2513 SMDS_MeshEdge* SMDS_Mesh::AddEdge(const SMDS_MeshNode* n1,
2514 const SMDS_MeshNode* n2,
2515 const SMDS_MeshNode* n12)
2517 return SMDS_Mesh::AddEdgeWithID(n1, n2, n12, myElementIDFactory->GetFreeID());
2520 //=======================================================================
2521 //function : AddEdgeWithID
2523 //=======================================================================
2524 SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
2525 const SMDS_MeshNode * n2,
2526 const SMDS_MeshNode * n12,
2529 if ( !n1 || !n2 || !n12 ) return 0;
2530 SMDS_QuadraticEdge* edge = new SMDS_QuadraticEdge(n1,n2,n12);
2531 if(myElementIDFactory->BindID(ID, edge)) {
2532 SMDS_MeshNode *node1,*node2, *node12;
2533 node1 = const_cast<SMDS_MeshNode*>(n1);
2534 node2 = const_cast<SMDS_MeshNode*>(n2);
2535 node12 = const_cast<SMDS_MeshNode*>(n12);
2536 node1->AddInverseElement(edge);
2537 node2->AddInverseElement(edge);
2538 node12->AddInverseElement(edge);
2549 //=======================================================================
2550 //function : AddFace
2552 //=======================================================================
2553 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
2554 const SMDS_MeshNode * n2,
2555 const SMDS_MeshNode * n3,
2556 const SMDS_MeshNode * n12,
2557 const SMDS_MeshNode * n23,
2558 const SMDS_MeshNode * n31)
2560 return SMDS_Mesh::AddFaceWithID(n1,n2,n3,n12,n23,n31,
2561 myElementIDFactory->GetFreeID());
2564 //=======================================================================
2565 //function : AddFaceWithID
2567 //=======================================================================
2568 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int n1, int n2, int n3,
2569 int n12,int n23,int n31, int ID)
2571 return SMDS_Mesh::AddFaceWithID
2572 ((SMDS_MeshNode *)myNodeIDFactory->MeshElement(n1) ,
2573 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n2) ,
2574 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n3) ,
2575 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n12),
2576 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n23),
2577 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n31),
2581 //=======================================================================
2582 //function : AddFaceWithID
2584 //=======================================================================
2585 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
2586 const SMDS_MeshNode * n2,
2587 const SMDS_MeshNode * n3,
2588 const SMDS_MeshNode * n12,
2589 const SMDS_MeshNode * n23,
2590 const SMDS_MeshNode * n31,
2593 if ( !n1 || !n2 || !n3 || !n12 || !n23 || !n31) return 0;
2594 if(hasConstructionEdges()) {
2595 // creation quadratic edges - not implemented
2598 SMDS_QuadraticFaceOfNodes* face =
2599 new SMDS_QuadraticFaceOfNodes(n1,n2,n3,n12,n23,n31);
2602 if (!registerElement(ID, face)) {
2603 RemoveElement(face, false);
2610 //=======================================================================
2611 //function : AddFace
2613 //=======================================================================
2614 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
2615 const SMDS_MeshNode * n2,
2616 const SMDS_MeshNode * n3,
2617 const SMDS_MeshNode * n4,
2618 const SMDS_MeshNode * n12,
2619 const SMDS_MeshNode * n23,
2620 const SMDS_MeshNode * n34,
2621 const SMDS_MeshNode * n41)
2623 return SMDS_Mesh::AddFaceWithID(n1,n2,n3,n4,n12,n23,n34,n41,
2624 myElementIDFactory->GetFreeID());
2627 //=======================================================================
2628 //function : AddFaceWithID
2630 //=======================================================================
2631 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int n4,
2632 int n12,int n23,int n34,int n41, int ID)
2634 return SMDS_Mesh::AddFaceWithID
2635 ((SMDS_MeshNode *)myNodeIDFactory->MeshElement(n1) ,
2636 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n2) ,
2637 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n3) ,
2638 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n4) ,
2639 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n12),
2640 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n23),
2641 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n34),
2642 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n41),
2646 //=======================================================================
2647 //function : AddFaceWithID
2649 //=======================================================================
2650 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
2651 const SMDS_MeshNode * n2,
2652 const SMDS_MeshNode * n3,
2653 const SMDS_MeshNode * n4,
2654 const SMDS_MeshNode * n12,
2655 const SMDS_MeshNode * n23,
2656 const SMDS_MeshNode * n34,
2657 const SMDS_MeshNode * n41,
2660 if ( !n1 || !n2 || !n3 || !n4 || !n12 || !n23 || !n34 || !n41) return 0;
2661 if(hasConstructionEdges()) {
2662 // creation quadratic edges - not implemented
2664 SMDS_QuadraticFaceOfNodes* face =
2665 new SMDS_QuadraticFaceOfNodes(n1,n2,n3,n4,n12,n23,n34,n41);
2668 if (!registerElement(ID, face)) {
2669 RemoveElement(face, false);
2676 //=======================================================================
2677 //function : AddVolume
2679 //=======================================================================
2680 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
2681 const SMDS_MeshNode * n2,
2682 const SMDS_MeshNode * n3,
2683 const SMDS_MeshNode * n4,
2684 const SMDS_MeshNode * n12,
2685 const SMDS_MeshNode * n23,
2686 const SMDS_MeshNode * n31,
2687 const SMDS_MeshNode * n14,
2688 const SMDS_MeshNode * n24,
2689 const SMDS_MeshNode * n34)
2691 int ID = myElementIDFactory->GetFreeID();
2692 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n12, n23,
2693 n31, n14, n24, n34, ID);
2694 if(v==NULL) myElementIDFactory->ReleaseID(ID);
2698 //=======================================================================
2699 //function : AddVolumeWithID
2701 //=======================================================================
2702 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4,
2703 int n12,int n23,int n31,
2704 int n14,int n24,int n34, int ID)
2706 return SMDS_Mesh::AddVolumeWithID
2707 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1) ,
2708 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2) ,
2709 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3) ,
2710 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4) ,
2711 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
2712 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
2713 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n31),
2714 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n14),
2715 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n24),
2716 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n34),
2720 //=======================================================================
2721 //function : AddVolumeWithID
2722 //purpose : 2d order tetrahedron of 10 nodes
2723 //=======================================================================
2724 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
2725 const SMDS_MeshNode * n2,
2726 const SMDS_MeshNode * n3,
2727 const SMDS_MeshNode * n4,
2728 const SMDS_MeshNode * n12,
2729 const SMDS_MeshNode * n23,
2730 const SMDS_MeshNode * n31,
2731 const SMDS_MeshNode * n14,
2732 const SMDS_MeshNode * n24,
2733 const SMDS_MeshNode * n34,
2736 if ( !n1 || !n2 || !n3 || !n4 || !n12 || !n23 || !n31 || !n14 || !n24 || !n34)
2738 if(hasConstructionFaces()) {
2739 // creation quadratic faces - not implemented
2742 SMDS_QuadraticVolumeOfNodes * volume =
2743 new SMDS_QuadraticVolumeOfNodes(n1,n2,n3,n4,n12,n23,n31,n14,n24,n34);
2744 myVolumes.Add(volume);
2746 if (!registerElement(ID, volume)) {
2747 RemoveElement(volume, false);
2754 //=======================================================================
2755 //function : AddVolume
2757 //=======================================================================
2758 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
2759 const SMDS_MeshNode * n2,
2760 const SMDS_MeshNode * n3,
2761 const SMDS_MeshNode * n4,
2762 const SMDS_MeshNode * n5,
2763 const SMDS_MeshNode * n12,
2764 const SMDS_MeshNode * n23,
2765 const SMDS_MeshNode * n34,
2766 const SMDS_MeshNode * n41,
2767 const SMDS_MeshNode * n15,
2768 const SMDS_MeshNode * n25,
2769 const SMDS_MeshNode * n35,
2770 const SMDS_MeshNode * n45)
2772 int ID = myElementIDFactory->GetFreeID();
2773 SMDS_MeshVolume * v =
2774 SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n12, n23, n34, n41,
2775 n15, n25, n35, n45, ID);
2776 if(v==NULL) myElementIDFactory->ReleaseID(ID);
2780 //=======================================================================
2781 //function : AddVolumeWithID
2783 //=======================================================================
2784 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5,
2785 int n12,int n23,int n34,int n41,
2786 int n15,int n25,int n35,int n45, int ID)
2788 return SMDS_Mesh::AddVolumeWithID
2789 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1) ,
2790 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2) ,
2791 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3) ,
2792 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4) ,
2793 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5) ,
2794 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
2795 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
2796 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n34),
2797 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n41),
2798 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n15),
2799 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n25),
2800 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n35),
2801 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n45),
2805 //=======================================================================
2806 //function : AddVolumeWithID
2807 //purpose : 2d order pyramid of 13 nodes
2808 //=======================================================================
2809 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
2810 const SMDS_MeshNode * n2,
2811 const SMDS_MeshNode * n3,
2812 const SMDS_MeshNode * n4,
2813 const SMDS_MeshNode * n5,
2814 const SMDS_MeshNode * n12,
2815 const SMDS_MeshNode * n23,
2816 const SMDS_MeshNode * n34,
2817 const SMDS_MeshNode * n41,
2818 const SMDS_MeshNode * n15,
2819 const SMDS_MeshNode * n25,
2820 const SMDS_MeshNode * n35,
2821 const SMDS_MeshNode * n45,
2824 if (!n1 || !n2 || !n3 || !n4 || !n5 || !n12 || !n23 ||
2825 !n34 || !n41 || !n15 || !n25 || !n35 || !n45)
2827 if(hasConstructionFaces()) {
2828 // creation quadratic faces - not implemented
2831 SMDS_QuadraticVolumeOfNodes * volume =
2832 new SMDS_QuadraticVolumeOfNodes(n1,n2,n3,n4,n5,n12,n23,
2833 n34,n41,n15,n25,n35,n45);
2834 myVolumes.Add(volume);
2836 if (!registerElement(ID, volume)) {
2837 RemoveElement(volume, false);
2844 //=======================================================================
2845 //function : AddVolume
2847 //=======================================================================
2848 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
2849 const SMDS_MeshNode * n2,
2850 const SMDS_MeshNode * n3,
2851 const SMDS_MeshNode * n4,
2852 const SMDS_MeshNode * n5,
2853 const SMDS_MeshNode * n6,
2854 const SMDS_MeshNode * n12,
2855 const SMDS_MeshNode * n23,
2856 const SMDS_MeshNode * n31,
2857 const SMDS_MeshNode * n45,
2858 const SMDS_MeshNode * n56,
2859 const SMDS_MeshNode * n64,
2860 const SMDS_MeshNode * n14,
2861 const SMDS_MeshNode * n25,
2862 const SMDS_MeshNode * n36)
2864 int ID = myElementIDFactory->GetFreeID();
2865 SMDS_MeshVolume * v =
2866 SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n12, n23, n31,
2867 n45, n56, n64, n14, n25, n36, ID);
2868 if(v==NULL) myElementIDFactory->ReleaseID(ID);
2872 //=======================================================================
2873 //function : AddVolumeWithID
2875 //=======================================================================
2876 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3,
2877 int n4, int n5, int n6,
2878 int n12,int n23,int n31,
2879 int n45,int n56,int n64,
2880 int n14,int n25,int n36, int ID)
2882 return SMDS_Mesh::AddVolumeWithID
2883 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1) ,
2884 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2) ,
2885 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3) ,
2886 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4) ,
2887 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5) ,
2888 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n6) ,
2889 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
2890 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
2891 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n31),
2892 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n45),
2893 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n56),
2894 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n64),
2895 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n14),
2896 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n25),
2897 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n36),
2901 //=======================================================================
2902 //function : AddVolumeWithID
2903 //purpose : 2d order Pentahedron with 15 nodes
2904 //=======================================================================
2905 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
2906 const SMDS_MeshNode * n2,
2907 const SMDS_MeshNode * n3,
2908 const SMDS_MeshNode * n4,
2909 const SMDS_MeshNode * n5,
2910 const SMDS_MeshNode * n6,
2911 const SMDS_MeshNode * n12,
2912 const SMDS_MeshNode * n23,
2913 const SMDS_MeshNode * n31,
2914 const SMDS_MeshNode * n45,
2915 const SMDS_MeshNode * n56,
2916 const SMDS_MeshNode * n64,
2917 const SMDS_MeshNode * n14,
2918 const SMDS_MeshNode * n25,
2919 const SMDS_MeshNode * n36,
2922 if (!n1 || !n2 || !n3 || !n4 || !n5 || !n6 || !n12 || !n23 ||
2923 !n31 || !n45 || !n56 || !n64 || !n14 || !n25 || !n36)
2925 if(hasConstructionFaces()) {
2926 // creation quadratic faces - not implemented
2929 SMDS_QuadraticVolumeOfNodes * volume =
2930 new SMDS_QuadraticVolumeOfNodes(n1,n2,n3,n4,n5,n6,n12,n23,n31,
2931 n45,n56,n64,n14,n25,n36);
2932 myVolumes.Add(volume);
2934 if (!registerElement(ID, volume)) {
2935 RemoveElement(volume, false);
2942 //=======================================================================
2943 //function : AddVolume
2945 //=======================================================================
2946 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
2947 const SMDS_MeshNode * n2,
2948 const SMDS_MeshNode * n3,
2949 const SMDS_MeshNode * n4,
2950 const SMDS_MeshNode * n5,
2951 const SMDS_MeshNode * n6,
2952 const SMDS_MeshNode * n7,
2953 const SMDS_MeshNode * n8,
2954 const SMDS_MeshNode * n12,
2955 const SMDS_MeshNode * n23,
2956 const SMDS_MeshNode * n34,
2957 const SMDS_MeshNode * n41,
2958 const SMDS_MeshNode * n56,
2959 const SMDS_MeshNode * n67,
2960 const SMDS_MeshNode * n78,
2961 const SMDS_MeshNode * n85,
2962 const SMDS_MeshNode * n15,
2963 const SMDS_MeshNode * n26,
2964 const SMDS_MeshNode * n37,
2965 const SMDS_MeshNode * n48)
2967 int ID = myElementIDFactory->GetFreeID();
2968 SMDS_MeshVolume * v =
2969 SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, n12, n23, n34, n41,
2970 n56, n67, n78, n85, n15, n26, n37, n48, ID);
2971 if(v==NULL) myElementIDFactory->ReleaseID(ID);
2975 //=======================================================================
2976 //function : AddVolumeWithID
2978 //=======================================================================
2979 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4,
2980 int n5, int n6, int n7, int n8,
2981 int n12,int n23,int n34,int n41,
2982 int n56,int n67,int n78,int n85,
2983 int n15,int n26,int n37,int n48, int ID)
2985 return SMDS_Mesh::AddVolumeWithID
2986 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1),
2987 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2),
2988 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3),
2989 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4),
2990 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5),
2991 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n6),
2992 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n7),
2993 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n8),
2994 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
2995 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
2996 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n34),
2997 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n41),
2998 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n56),
2999 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n67),
3000 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n78),
3001 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n85),
3002 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n15),
3003 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n26),
3004 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n37),
3005 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n48),
3009 //=======================================================================
3010 //function : AddVolumeWithID
3011 //purpose : 2d order Hexahedrons with 20 nodes
3012 //=======================================================================
3013 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(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 * n6,
3019 const SMDS_MeshNode * n7,
3020 const SMDS_MeshNode * n8,
3021 const SMDS_MeshNode * n12,
3022 const SMDS_MeshNode * n23,
3023 const SMDS_MeshNode * n34,
3024 const SMDS_MeshNode * n41,
3025 const SMDS_MeshNode * n56,
3026 const SMDS_MeshNode * n67,
3027 const SMDS_MeshNode * n78,
3028 const SMDS_MeshNode * n85,
3029 const SMDS_MeshNode * n15,
3030 const SMDS_MeshNode * n26,
3031 const SMDS_MeshNode * n37,
3032 const SMDS_MeshNode * n48,
3035 if (!n1 || !n2 || !n3 || !n4 || !n5 || !n6 || !n7 || !n8 || !n12 || !n23 ||
3036 !n34 || !n41 || !n56 || !n67 || !n78 || !n85 || !n15 || !n26 || !n37 || !n48)
3038 if(hasConstructionFaces()) {
3040 // creation quadratic faces - not implemented
3042 SMDS_QuadraticVolumeOfNodes * volume =
3043 new SMDS_QuadraticVolumeOfNodes(n1,n2,n3,n4,n5,n6,n7,n8,n12,n23,n34,n41,
3044 n56,n67,n78,n85,n15,n26,n37,n48);
3045 myVolumes.Add(volume);
3047 if (!registerElement(ID, volume)) {
3048 RemoveElement(volume, false);