1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH SMDS : implementaion of Salome mesh data structure
25 #pragma warning(disable:4786)
28 #include "utilities.h"
29 #include "SMDS_Mesh.hxx"
30 #include "SMDS_VolumeOfNodes.hxx"
31 #include "SMDS_VolumeOfFaces.hxx"
32 #include "SMDS_FaceOfNodes.hxx"
33 #include "SMDS_FaceOfEdges.hxx"
34 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
35 #include "SMDS_PolygonalFaceOfNodes.hxx"
36 #include "SMDS_QuadraticEdge.hxx"
37 #include "SMDS_QuadraticFaceOfNodes.hxx"
38 #include "SMDS_QuadraticVolumeOfNodes.hxx"
39 #include "SMDS_SpacePosition.hxx"
41 #include <vtkUnstructuredGrid.h>
48 #include <sys/sysinfo.h>
51 // number of added entities to check memory after
52 #define CHECKMEMORY_INTERVAL 1000
54 vector<SMDS_Mesh*> SMDS_Mesh::_meshList = vector<SMDS_Mesh*>();
55 int SMDS_Mesh::chunkSize = 1024;
58 //================================================================================
60 * \brief Raise an exception if free memory (ram+swap) too low
61 * \param doNotRaise - if true, suppres exception, just return free memory size
62 * \retval int - amount of available memory in MB or negative number in failure case
64 //================================================================================
66 int SMDS_Mesh::CheckMemory(const bool doNotRaise) throw (std::bad_alloc)
70 int err = sysinfo( &si );
74 static int limit = -1;
76 int status = system("SMDS_MemoryLimit"); // it returns lower limit of free RAM
78 limit = WEXITSTATUS(status);
83 limit = int( limit * 1.5 );
85 MESSAGE ( "SMDS_Mesh::CheckMemory() memory limit = " << limit << " MB" );
89 const unsigned long Mbyte = 1024 * 1024;
90 // compute separately to avoid overflow
92 ( si.freeram * si.mem_unit ) / Mbyte +
93 ( si.freeswap * si.mem_unit ) / Mbyte;
96 return freeMb - limit;
101 MESSAGE ("SMDS_Mesh::CheckMemory() throws as free memory too low: " << freeMb <<" MB" );
103 throw std::bad_alloc();
109 ///////////////////////////////////////////////////////////////////////////////
110 /// Create a new mesh object
111 ///////////////////////////////////////////////////////////////////////////////
112 SMDS_Mesh::SMDS_Mesh()
114 myNodeIDFactory(new SMDS_MeshNodeIDFactory()),
115 myElementIDFactory(new SMDS_MeshElementIDFactory()),
116 myHasConstructionEdges(false), myHasConstructionFaces(false),
117 myHasInverseElements(true),
118 myNodeMin(0), myNodeMax(0), myCellLinksSize(0),
119 myNodePool(0), myEdgePool(0), myFacePool(0), myVolumePool(0)
121 myMeshId = _meshList.size(); // --- index of the mesh to push back in the vector
122 MESSAGE("myMeshId=" << myMeshId);
123 MESSAGE("sizeof(SMDS_MeshElement) " << sizeof(SMDS_MeshElement) );
124 MESSAGE("sizeof(SMDS_MeshNode) " << sizeof(SMDS_MeshNode) );
125 MESSAGE("sizeof(SMDS_MeshCell) " << sizeof(SMDS_MeshCell) );
126 MESSAGE("sizeof(SMDS_VtkVolume) " << sizeof(SMDS_VtkVolume) );
127 MESSAGE("sizeof(SMDS_Position) " << sizeof(SMDS_Position) );
128 MESSAGE("sizeof(SMDS_SpacePosition) " << sizeof(SMDS_SpacePosition) );
129 myNodeIDFactory->SetMesh(this);
130 myElementIDFactory->SetMesh(this);
131 _meshList.push_back(this);
132 myNodePool = new ObjectPool<SMDS_MeshNode>(SMDS_Mesh::chunkSize);
133 myEdgePool = new ObjectPool<SMDS_VtkEdge>(SMDS_Mesh::chunkSize);
134 myFacePool = new ObjectPool<SMDS_VtkFace>(SMDS_Mesh::chunkSize);
135 myVolumePool = new ObjectPool<SMDS_VtkVolume>(SMDS_Mesh::chunkSize);
139 myIDElements.clear();
141 myGrid = vtkUnstructuredGrid::New();
142 myGrid->Initialize();
144 vtkPoints* points = vtkPoints::New();
145 points->SetNumberOfPoints(SMDS_Mesh::chunkSize);
146 myGrid->SetPoints( points );
148 myGrid->BuildLinks();
151 ///////////////////////////////////////////////////////////////////////////////
152 /// Create a new child mesh
153 /// Note that the tree structure of SMDS_Mesh seems to be unused in this version
154 /// (2003-09-08) of SMESH
155 ///////////////////////////////////////////////////////////////////////////////
156 SMDS_Mesh::SMDS_Mesh(SMDS_Mesh * parent)
157 :myParent(parent), myNodeIDFactory(parent->myNodeIDFactory),
158 myElementIDFactory(parent->myElementIDFactory),
159 myHasConstructionEdges(false), myHasConstructionFaces(false),
160 myHasInverseElements(true),
161 myNodePool(parent->myNodePool),
162 myEdgePool(parent->myEdgePool),
163 myFacePool(parent->myFacePool),
164 myVolumePool(parent->myVolumePool)
168 ///////////////////////////////////////////////////////////////////////////////
169 ///Create a submesh and add it to the current mesh
170 ///////////////////////////////////////////////////////////////////////////////
172 SMDS_Mesh *SMDS_Mesh::AddSubMesh()
174 SMDS_Mesh *submesh = new SMDS_Mesh(this);
175 myChildren.insert(myChildren.end(), submesh);
179 ///////////////////////////////////////////////////////////////////////////////
180 ///create a MeshNode and add it to the current Mesh
181 ///An ID is automatically assigned to the node.
182 ///@return : The created node
183 ///////////////////////////////////////////////////////////////////////////////
185 SMDS_MeshNode * SMDS_Mesh::AddNode(double x, double y, double z)
187 return SMDS_Mesh::AddNodeWithID(x,y,z,myNodeIDFactory->GetFreeID());
190 ///////////////////////////////////////////////////////////////////////////////
191 ///create a MeshNode and add it to the current Mesh
192 ///@param ID : The ID of the MeshNode to create
193 ///@return : The created node or NULL if a node with this ID already exists
194 ///////////////////////////////////////////////////////////////////////////////
195 SMDS_MeshNode * SMDS_Mesh::AddNodeWithID(double x, double y, double z, int ID)
197 // find the MeshNode corresponding to ID
198 const SMDS_MeshElement *node = myNodeIDFactory->MeshElement(ID);
200 //if ( myNodes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
201 //SMDS_MeshNode * node=new SMDS_MeshNode(ID, myMeshId, -1, x, y, z);
202 SMDS_MeshNode * node = myNodePool->getNew();
203 node->init(ID, myMeshId, -1, x, y, z);
204 if (ID >= myNodes.size())
206 myNodes.resize(ID+SMDS_Mesh::chunkSize, 0);
207 //MESSAGE(" ------------------ myNodes resize " << ID << " --> " << ID+SMDS_Mesh::chunkSize);
210 myNodeIDFactory->BindID(ID,node);
217 ///////////////////////////////////////////////////////////////////////////////
218 /// create a Mesh0DElement and add it to the current Mesh
219 /// @return : The created Mesh0DElement
220 ///////////////////////////////////////////////////////////////////////////////
221 SMDS_Mesh0DElement* SMDS_Mesh::Add0DElementWithID(int idnode, int ID)
223 SMDS_MeshNode * node = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode);
224 if (!node) return NULL;
225 return SMDS_Mesh::Add0DElementWithID(node, ID);
228 ///////////////////////////////////////////////////////////////////////////////
229 /// create a Mesh0DElement and add it to the current Mesh
230 /// @return : The created Mesh0DElement
231 ///////////////////////////////////////////////////////////////////////////////
232 SMDS_Mesh0DElement* SMDS_Mesh::Add0DElement(const SMDS_MeshNode * node)
234 return SMDS_Mesh::Add0DElementWithID(node, myElementIDFactory->GetFreeID());
237 ///////////////////////////////////////////////////////////////////////////////
238 /// Create a new Mesh0DElement and at it to the mesh
239 /// @param idnode ID of the node
240 /// @param ID ID of the 0D element to create
241 /// @return The created 0D element or NULL if an element with this
242 /// ID already exists or if input node is not found.
243 ///////////////////////////////////////////////////////////////////////////////
244 SMDS_Mesh0DElement* SMDS_Mesh::Add0DElementWithID(const SMDS_MeshNode * n, int ID)
248 //if (my0DElements.Extent() % CHECKMEMORY_INTERVAL == 0) CheckMemory();
249 //MESSAGE("Add0DElementWithID" << ID)
250 SMDS_Mesh0DElement * el0d = new SMDS_Mesh0DElement(n);
251 if (myElementIDFactory->BindID(ID, el0d)) {
252 SMDS_MeshNode *node = const_cast<SMDS_MeshNode*>(n);
253 //node->AddInverseElement(el0d);// --- fait avec BindID
254 adjustmyCellsCapacity(ID);
256 myInfo.myNb0DElements++;
264 ///////////////////////////////////////////////////////////////////////////////
265 /// create a MeshEdge and add it to the current Mesh
266 /// @return : The created MeshEdge
267 ///////////////////////////////////////////////////////////////////////////////
269 SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(int idnode1, int idnode2, int ID)
271 SMDS_MeshNode * node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
272 SMDS_MeshNode * node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
273 if(!node1 || !node2) return NULL;
274 return SMDS_Mesh::AddEdgeWithID(node1, node2, ID);
277 ///////////////////////////////////////////////////////////////////////////////
278 /// create a MeshEdge and add it to the current Mesh
279 /// @return : The created MeshEdge
280 ///////////////////////////////////////////////////////////////////////////////
282 SMDS_MeshEdge* SMDS_Mesh::AddEdge(const SMDS_MeshNode * node1,
283 const SMDS_MeshNode * node2)
285 return SMDS_Mesh::AddEdgeWithID(node1, node2, myElementIDFactory->GetFreeID());
288 ///////////////////////////////////////////////////////////////////////////////
289 /// Create a new edge and at it to the mesh
290 /// @param idnode1 ID of the first node
291 /// @param idnode2 ID of the second node
292 /// @param ID ID of the edge to create
293 /// @return The created edge or NULL if an element with this ID already exists or
294 /// if input nodes are not found.
295 ///////////////////////////////////////////////////////////////////////////////
297 SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
298 const SMDS_MeshNode * n2,
301 if ( !n1 || !n2 ) return 0;
302 SMDS_MeshEdge * edge = 0;
304 // --- retreive nodes ID
305 vector<vtkIdType> nodeIds;
307 nodeIds.push_back(n1->getId());
308 nodeIds.push_back(n2->getId());
310 SMDS_VtkEdge *edgevtk = myEdgePool->getNew();
311 edgevtk->init(nodeIds, this);
313 adjustmyCellsCapacity(ID);
317 if (edge && !registerElement(ID, edge))
319 RemoveElement(edge, false);
325 ///////////////////////////////////////////////////////////////////////////////
326 /// Add a triangle defined by its nodes. An ID is automatically affected to the
328 ///////////////////////////////////////////////////////////////////////////////
330 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
331 const SMDS_MeshNode * n2,
332 const SMDS_MeshNode * n3)
334 return SMDS_Mesh::AddFaceWithID(n1,n2,n3, myElementIDFactory->GetFreeID());
337 ///////////////////////////////////////////////////////////////////////////////
338 /// Add a triangle defined by its nodes IDs
339 ///////////////////////////////////////////////////////////////////////////////
341 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int idnode1, int idnode2, int idnode3, int ID)
343 SMDS_MeshNode * node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
344 SMDS_MeshNode * node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
345 SMDS_MeshNode * node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
346 if(!node1 || !node2 || !node3) return NULL;
347 return SMDS_Mesh::AddFaceWithID(node1, node2, node3, ID);
350 ///////////////////////////////////////////////////////////////////////////////
351 /// Add a triangle defined by its nodes
352 ///////////////////////////////////////////////////////////////////////////////
354 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
355 const SMDS_MeshNode * n2,
356 const SMDS_MeshNode * n3,
359 //MESSAGE("AddFaceWithID " << ID)
360 SMDS_MeshFace * face=createTriangle(n1, n2, n3, myElementIDFactory->GetFreeID());
362 if (face && !registerElement(ID, face)) {
363 RemoveElement(face, false);
369 ///////////////////////////////////////////////////////////////////////////////
370 /// Add a quadrangle defined by its nodes. An ID is automatically affected to the
372 ///////////////////////////////////////////////////////////////////////////////
374 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
375 const SMDS_MeshNode * n2,
376 const SMDS_MeshNode * n3,
377 const SMDS_MeshNode * n4)
379 return SMDS_Mesh::AddFaceWithID(n1,n2,n3, n4, myElementIDFactory->GetFreeID());
382 ///////////////////////////////////////////////////////////////////////////////
383 /// Add a quadrangle defined by its nodes IDs
384 ///////////////////////////////////////////////////////////////////////////////
386 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int idnode1,
392 SMDS_MeshNode *node1, *node2, *node3, *node4;
393 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
394 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
395 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
396 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
397 if(!node1 || !node2 || !node3 || !node4) return NULL;
398 return SMDS_Mesh::AddFaceWithID(node1, node2, node3, node4, ID);
401 ///////////////////////////////////////////////////////////////////////////////
402 /// Add a quadrangle defined by its nodes
403 ///////////////////////////////////////////////////////////////////////////////
405 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
406 const SMDS_MeshNode * n2,
407 const SMDS_MeshNode * n3,
408 const SMDS_MeshNode * n4,
411 //MESSAGE("AddFaceWithID " << ID);
412 SMDS_MeshFace * face=createQuadrangle(n1, n2, n3, n4, ID);
414 if (face && !registerElement(ID, face)) {
415 RemoveElement(face, false);
421 ///////////////////////////////////////////////////////////////////////////////
422 /// Add a triangle defined by its edges. An ID is automatically assigned to the
424 ///////////////////////////////////////////////////////////////////////////////
426 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshEdge * e1,
427 const SMDS_MeshEdge * e2,
428 const SMDS_MeshEdge * e3)
430 if (!hasConstructionEdges())
432 //MESSAGE("AddFaceWithID");
433 return AddFaceWithID(e1,e2,e3, myElementIDFactory->GetFreeID());
436 ///////////////////////////////////////////////////////////////////////////////
437 /// Add a triangle defined by its edges
438 ///////////////////////////////////////////////////////////////////////////////
440 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshEdge * e1,
441 const SMDS_MeshEdge * e2,
442 const SMDS_MeshEdge * e3,
445 if (!hasConstructionEdges())
447 if ( !e1 || !e2 || !e3 ) return 0;
449 //if ( myFaces.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
450 //MESSAGE("AddFaceWithID" << ID);
452 SMDS_MeshFace * face = new SMDS_FaceOfEdges(e1,e2,e3);
453 adjustmyCellsCapacity(ID);
455 myInfo.myNbTriangles++;
457 if (!registerElement(ID, face)) {
458 RemoveElement(face, false);
464 ///////////////////////////////////////////////////////////////////////////////
465 /// Add a quadrangle defined by its edges. An ID is automatically assigned to the
467 ///////////////////////////////////////////////////////////////////////////////
469 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshEdge * e1,
470 const SMDS_MeshEdge * e2,
471 const SMDS_MeshEdge * e3,
472 const SMDS_MeshEdge * e4)
474 if (!hasConstructionEdges())
476 //MESSAGE("AddFaceWithID" );
477 return AddFaceWithID(e1,e2,e3,e4, myElementIDFactory->GetFreeID());
480 ///////////////////////////////////////////////////////////////////////////////
481 /// Add a quadrangle defined by its edges
482 ///////////////////////////////////////////////////////////////////////////////
484 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshEdge * e1,
485 const SMDS_MeshEdge * e2,
486 const SMDS_MeshEdge * e3,
487 const SMDS_MeshEdge * e4,
490 if (!hasConstructionEdges())
492 //MESSAGE("AddFaceWithID" << ID);
493 if ( !e1 || !e2 || !e3 || !e4 ) return 0;
494 //if ( myFaces.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
495 SMDS_MeshFace * face = new SMDS_FaceOfEdges(e1,e2,e3,e4);
496 adjustmyCellsCapacity(ID);
498 myInfo.myNbQuadrangles++;
500 if (!registerElement(ID, face))
502 RemoveElement(face, false);
508 ///////////////////////////////////////////////////////////////////////////////
509 ///Create a new tetrahedron and add it to the mesh.
510 ///@return The created tetrahedron
511 ///////////////////////////////////////////////////////////////////////////////
513 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
514 const SMDS_MeshNode * n2,
515 const SMDS_MeshNode * n3,
516 const SMDS_MeshNode * n4)
518 int ID = myElementIDFactory->GetFreeID();
519 //MESSAGE("AddVolumeWithID " << ID);
520 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, ID);
521 if(v==NULL) myElementIDFactory->ReleaseID(ID);
525 ///////////////////////////////////////////////////////////////////////////////
526 ///Create a new tetrahedron and add it to the mesh.
527 ///@param ID The ID of the new volume
528 ///@return The created tetrahedron or NULL if an element with this ID already exists
529 ///or if input nodes are not found.
530 ///////////////////////////////////////////////////////////////////////////////
532 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
538 //MESSAGE("AddVolumeWithID" << ID);
539 SMDS_MeshNode *node1, *node2, *node3, *node4;
540 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
541 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
542 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
543 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
544 if(!node1 || !node2 || !node3 || !node4) return NULL;
545 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, ID);
548 ///////////////////////////////////////////////////////////////////////////////
549 ///Create a new tetrahedron and add it to the mesh.
550 ///@param ID The ID of the new volume
551 ///@return The created tetrahedron
552 ///////////////////////////////////////////////////////////////////////////////
554 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
555 const SMDS_MeshNode * n2,
556 const SMDS_MeshNode * n3,
557 const SMDS_MeshNode * n4,
560 //MESSAGE("AddVolumeWithID " << ID);
561 SMDS_MeshVolume* volume = 0;
562 if ( !n1 || !n2 || !n3 || !n4) return volume;
563 //if ( myVolumes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
564 if(hasConstructionFaces()) {
565 SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3);
566 SMDS_MeshFace * f2=FindFaceOrCreate(n1,n2,n4);
567 SMDS_MeshFace * f3=FindFaceOrCreate(n1,n3,n4);
568 SMDS_MeshFace * f4=FindFaceOrCreate(n2,n3,n4);
569 volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4);
570 adjustmyCellsCapacity(ID);
571 myCells[ID] = volume;
574 else if(hasConstructionEdges()) {
575 MESSAGE("Error : Not implemented");
579 // --- retrieve nodes ID
580 vector<vtkIdType> nodeIds;
582 nodeIds.push_back(n1->getId());
583 nodeIds.push_back(n3->getId()); // order SMDS-->VTK
584 nodeIds.push_back(n2->getId());
585 nodeIds.push_back(n4->getId());
587 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
588 volvtk->init(nodeIds, this);
590 adjustmyCellsCapacity(ID);
591 myCells[ID] = volume;
595 if (!registerElement(ID, volume)) {
596 RemoveElement(volume, false);
602 ///////////////////////////////////////////////////////////////////////////////
603 ///Create a new pyramid and add it to the mesh.
604 ///Nodes 1,2,3 and 4 define the base of the pyramid
605 ///@return The created pyramid
606 ///////////////////////////////////////////////////////////////////////////////
608 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
609 const SMDS_MeshNode * n2,
610 const SMDS_MeshNode * n3,
611 const SMDS_MeshNode * n4,
612 const SMDS_MeshNode * n5)
614 int ID = myElementIDFactory->GetFreeID();
615 //MESSAGE("AddVolumeWithID " << ID);
616 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, ID);
617 if(v==NULL) myElementIDFactory->ReleaseID(ID);
621 ///////////////////////////////////////////////////////////////////////////////
622 ///Create a new pyramid and add it to the mesh.
623 ///Nodes 1,2,3 and 4 define the base of the pyramid
624 ///@param ID The ID of the new volume
625 ///@return The created pyramid or NULL if an element with this ID already exists
626 ///or if input nodes are not found.
627 ///////////////////////////////////////////////////////////////////////////////
629 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
636 //MESSAGE("AddVolumeWithID " << ID);
637 SMDS_MeshNode *node1, *node2, *node3, *node4, *node5;
638 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
639 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
640 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
641 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
642 node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5);
643 if(!node1 || !node2 || !node3 || !node4 || !node5) return NULL;
644 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, ID);
647 ///////////////////////////////////////////////////////////////////////////////
648 ///Create a new pyramid and add it to the mesh.
649 ///Nodes 1,2,3 and 4 define the base of the pyramid
650 ///@param ID The ID of the new volume
651 ///@return The created pyramid
652 ///////////////////////////////////////////////////////////////////////////////
654 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
655 const SMDS_MeshNode * n2,
656 const SMDS_MeshNode * n3,
657 const SMDS_MeshNode * n4,
658 const SMDS_MeshNode * n5,
661 //MESSAGE("AddVolumeWithID " << ID);
662 SMDS_MeshVolume* volume = 0;
663 if ( !n1 || !n2 || !n3 || !n4 || !n5) return volume;
664 //if ( myVolumes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
665 if(hasConstructionFaces()) {
666 SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3,n4);
667 SMDS_MeshFace * f2=FindFaceOrCreate(n1,n2,n5);
668 SMDS_MeshFace * f3=FindFaceOrCreate(n2,n3,n5);
669 SMDS_MeshFace * f4=FindFaceOrCreate(n3,n4,n5);
670 volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4);
671 adjustmyCellsCapacity(ID);
672 myCells[ID] = volume;
673 myInfo.myNbPyramids++;
675 else if(hasConstructionEdges()) {
676 MESSAGE("Error : Not implemented");
680 // --- retrieve nodes ID
681 vector<vtkIdType> nodeIds;
683 nodeIds.push_back(n1->getId());
684 nodeIds.push_back(n4->getId());
685 nodeIds.push_back(n3->getId());
686 nodeIds.push_back(n2->getId());
687 nodeIds.push_back(n5->getId());
689 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
690 volvtk->init(nodeIds, this);
692 adjustmyCellsCapacity(ID);
693 myCells[ID] = volume;
694 myInfo.myNbPyramids++;
697 if (!registerElement(ID, volume)) {
698 RemoveElement(volume, false);
704 ///////////////////////////////////////////////////////////////////////////////
705 ///Create a new prism and add it to the mesh.
706 ///Nodes 1,2,3 is a triangle and 1,2,5,4 a quadrangle.
707 ///@return The created prism
708 ///////////////////////////////////////////////////////////////////////////////
710 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
711 const SMDS_MeshNode * n2,
712 const SMDS_MeshNode * n3,
713 const SMDS_MeshNode * n4,
714 const SMDS_MeshNode * n5,
715 const SMDS_MeshNode * n6)
717 int ID = myElementIDFactory->GetFreeID();
718 //MESSAGE("AddVolumeWithID " << ID);
719 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, ID);
720 if(v==NULL) myElementIDFactory->ReleaseID(ID);
724 ///////////////////////////////////////////////////////////////////////////////
725 ///Create a new prism and add it to the mesh.
726 ///Nodes 1,2,3 is a triangle and 1,2,5,4 a quadrangle.
727 ///@param ID The ID of the new volume
728 ///@return The created prism or NULL if an element with this ID already exists
729 ///or if input nodes are not found.
730 ///////////////////////////////////////////////////////////////////////////////
732 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
740 //MESSAGE("AddVolumeWithID " << ID);
741 SMDS_MeshNode *node1, *node2, *node3, *node4, *node5, *node6;
742 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
743 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
744 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
745 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
746 node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5);
747 node6 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode6);
748 if(!node1 || !node2 || !node3 || !node4 || !node5 || !node6) return NULL;
749 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, node6, ID);
752 ///////////////////////////////////////////////////////////////////////////////
753 ///Create a new prism and add it to the mesh.
754 ///Nodes 1,2,3 is a triangle and 1,2,5,4 a quadrangle.
755 ///@param ID The ID of the new volume
756 ///@return The created prism
757 ///////////////////////////////////////////////////////////////////////////////
759 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
760 const SMDS_MeshNode * n2,
761 const SMDS_MeshNode * n3,
762 const SMDS_MeshNode * n4,
763 const SMDS_MeshNode * n5,
764 const SMDS_MeshNode * n6,
767 //MESSAGE("AddVolumeWithID " << ID);
768 SMDS_MeshVolume* volume = 0;
769 if ( !n1 || !n2 || !n3 || !n4 || !n5 || !n6) return volume;
770 //if ( myVolumes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
771 if(hasConstructionFaces()) {
772 SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3);
773 SMDS_MeshFace * f2=FindFaceOrCreate(n4,n5,n6);
774 SMDS_MeshFace * f3=FindFaceOrCreate(n1,n4,n5,n2);
775 SMDS_MeshFace * f4=FindFaceOrCreate(n2,n5,n6,n3);
776 SMDS_MeshFace * f5=FindFaceOrCreate(n3,n6,n4,n1);
777 volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5);
778 adjustmyCellsCapacity(ID);
779 myCells[ID] = volume;
782 else if(hasConstructionEdges()) {
783 MESSAGE("Error : Not implemented");
787 // --- retrieve nodes ID
788 vector<vtkIdType> nodeIds;
790 nodeIds.push_back(n1->getId());
791 nodeIds.push_back(n3->getId());
792 nodeIds.push_back(n2->getId());
793 nodeIds.push_back(n4->getId());
794 nodeIds.push_back(n6->getId());
795 nodeIds.push_back(n5->getId());
797 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
798 volvtk->init(nodeIds, this);
800 adjustmyCellsCapacity(ID);
801 myCells[ID] = volume;
805 if (!registerElement(ID, volume)) {
806 RemoveElement(volume, false);
812 ///////////////////////////////////////////////////////////////////////////////
813 ///Create a new hexahedron and add it to the mesh.
814 ///Nodes 1,2,3,4 and 5,6,7,8 are quadrangle and 5,1 and 7,3 are an edges.
815 ///@return The created hexahedron
816 ///////////////////////////////////////////////////////////////////////////////
818 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
819 const SMDS_MeshNode * n2,
820 const SMDS_MeshNode * n3,
821 const SMDS_MeshNode * n4,
822 const SMDS_MeshNode * n5,
823 const SMDS_MeshNode * n6,
824 const SMDS_MeshNode * n7,
825 const SMDS_MeshNode * n8)
827 int ID = myElementIDFactory->GetFreeID();
828 //MESSAGE("AddVolumeWithID " << ID);
829 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, ID);
830 if(v==NULL) myElementIDFactory->ReleaseID(ID);
834 ///////////////////////////////////////////////////////////////////////////////
835 ///Create a new hexahedron and add it to the mesh.
836 ///Nodes 1,2,3,4 and 5,6,7,8 are quadrangle and 5,1 and 7,3 are an edges.
837 ///@param ID The ID of the new volume
838 ///@return The created hexahedron or NULL if an element with this ID already
839 ///exists or if input nodes are not found.
840 ///////////////////////////////////////////////////////////////////////////////
842 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
852 //MESSAGE("AddVolumeWithID " << ID);
853 SMDS_MeshNode *node1, *node2, *node3, *node4, *node5, *node6, *node7, *node8;
854 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
855 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
856 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
857 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
858 node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5);
859 node6 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode6);
860 node7 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode7);
861 node8 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode8);
862 if(!node1 || !node2 || !node3 || !node4 || !node5 || !node6 || !node7 || !node8)
864 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, node6,
868 ///////////////////////////////////////////////////////////////////////////////
869 ///Create a new hexahedron and add it to the mesh.
870 ///Nodes 1,2,3,4 and 5,6,7,8 are quadrangle and 5,1 and 7,3 are an edges.
871 ///@param ID The ID of the new volume
872 ///@return The created prism or NULL if an element with this ID already exists
873 ///or if input nodes are not found.
874 ///////////////////////////////////////////////////////////////////////////////
876 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
877 const SMDS_MeshNode * n2,
878 const SMDS_MeshNode * n3,
879 const SMDS_MeshNode * n4,
880 const SMDS_MeshNode * n5,
881 const SMDS_MeshNode * n6,
882 const SMDS_MeshNode * n7,
883 const SMDS_MeshNode * n8,
886 //MESSAGE("AddVolumeWithID " << ID);
887 SMDS_MeshVolume* volume = 0;
888 if ( !n1 || !n2 || !n3 || !n4 || !n5 || !n6 || !n7 || !n8) return volume;
889 //if ( myVolumes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
890 if(hasConstructionFaces()) {
891 SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3,n4);
892 SMDS_MeshFace * f2=FindFaceOrCreate(n5,n6,n7,n8);
893 SMDS_MeshFace * f3=FindFaceOrCreate(n1,n4,n8,n5);
894 SMDS_MeshFace * f4=FindFaceOrCreate(n1,n2,n6,n5);
895 SMDS_MeshFace * f5=FindFaceOrCreate(n2,n3,n7,n6);
896 SMDS_MeshFace * f6=FindFaceOrCreate(n3,n4,n8,n7);
897 volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5,f6);
898 adjustmyCellsCapacity(ID);
899 myCells[ID] = volume;
902 else if(hasConstructionEdges()) {
903 MESSAGE("Error : Not implemented");
907 // --- retrieve nodes ID
908 vector<vtkIdType> nodeIds;
910 nodeIds.push_back(n1->getId());
911 nodeIds.push_back(n4->getId());
912 nodeIds.push_back(n3->getId());
913 nodeIds.push_back(n2->getId());
914 nodeIds.push_back(n5->getId());
915 nodeIds.push_back(n8->getId());
916 nodeIds.push_back(n7->getId());
917 nodeIds.push_back(n6->getId());
919 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
920 volvtk->init(nodeIds, this);
922 adjustmyCellsCapacity(ID);
923 myCells[ID] = volume;
927 if (!registerElement(ID, volume)) {
928 RemoveElement(volume, false);
934 ///////////////////////////////////////////////////////////////////////////////
935 ///Create a new tetrahedron defined by its faces and add it to the mesh.
936 ///@return The created tetrahedron
937 ///////////////////////////////////////////////////////////////////////////////
939 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshFace * f1,
940 const SMDS_MeshFace * f2,
941 const SMDS_MeshFace * f3,
942 const SMDS_MeshFace * f4)
944 //MESSAGE("AddVolumeWithID");
945 if (!hasConstructionFaces())
947 return AddVolumeWithID(f1,f2,f3,f4, myElementIDFactory->GetFreeID());
950 ///////////////////////////////////////////////////////////////////////////////
951 ///Create a new tetrahedron defined by its faces and add it to the mesh.
952 ///@param ID The ID of the new volume
953 ///@return The created tetrahedron
954 ///////////////////////////////////////////////////////////////////////////////
956 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1,
957 const SMDS_MeshFace * f2,
958 const SMDS_MeshFace * f3,
959 const SMDS_MeshFace * f4,
962 //MESSAGE("AddVolumeWithID" << ID);
963 if (!hasConstructionFaces())
965 if ( !f1 || !f2 || !f3 || !f4) return 0;
966 //if ( myVolumes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
967 SMDS_MeshVolume * volume = new SMDS_VolumeOfFaces(f1,f2,f3,f4);
968 adjustmyCellsCapacity(ID);
969 myCells[ID] = volume;
972 if (!registerElement(ID, volume)) {
973 RemoveElement(volume, false);
979 ///////////////////////////////////////////////////////////////////////////////
980 ///Create a new pyramid defined by its faces and add it to the mesh.
981 ///@return The created pyramid
982 ///////////////////////////////////////////////////////////////////////////////
984 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshFace * f1,
985 const SMDS_MeshFace * f2,
986 const SMDS_MeshFace * f3,
987 const SMDS_MeshFace * f4,
988 const SMDS_MeshFace * f5)
990 //MESSAGE("AddVolumeWithID");
991 if (!hasConstructionFaces())
993 return AddVolumeWithID(f1,f2,f3,f4,f5, myElementIDFactory->GetFreeID());
996 ///////////////////////////////////////////////////////////////////////////////
997 ///Create a new pyramid defined by its faces and add it to the mesh.
998 ///@param ID The ID of the new volume
999 ///@return The created pyramid
1000 ///////////////////////////////////////////////////////////////////////////////
1002 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1,
1003 const SMDS_MeshFace * f2,
1004 const SMDS_MeshFace * f3,
1005 const SMDS_MeshFace * f4,
1006 const SMDS_MeshFace * f5,
1009 //MESSAGE("AddVolumeWithID" << ID);
1010 if (!hasConstructionFaces())
1012 if ( !f1 || !f2 || !f3 || !f4 || !f5) return 0;
1013 //if ( myVolumes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1014 SMDS_MeshVolume * volume = new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5);
1015 adjustmyCellsCapacity(ID);
1016 myCells[ID] = volume;
1017 myInfo.myNbPyramids++;
1019 if (!registerElement(ID, volume)) {
1020 RemoveElement(volume, false);
1026 ///////////////////////////////////////////////////////////////////////////////
1027 ///Create a new prism defined by its faces and add it to the mesh.
1028 ///@return The created prism
1029 ///////////////////////////////////////////////////////////////////////////////
1031 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshFace * f1,
1032 const SMDS_MeshFace * f2,
1033 const SMDS_MeshFace * f3,
1034 const SMDS_MeshFace * f4,
1035 const SMDS_MeshFace * f5,
1036 const SMDS_MeshFace * f6)
1038 //MESSAGE("AddVolumeWithID" );
1039 if (!hasConstructionFaces())
1041 return AddVolumeWithID(f1,f2,f3,f4,f5,f6, myElementIDFactory->GetFreeID());
1044 ///////////////////////////////////////////////////////////////////////////////
1045 ///Create a new prism defined by its faces and add it to the mesh.
1046 ///@param ID The ID of the new volume
1047 ///@return The created prism
1048 ///////////////////////////////////////////////////////////////////////////////
1050 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1,
1051 const SMDS_MeshFace * f2,
1052 const SMDS_MeshFace * f3,
1053 const SMDS_MeshFace * f4,
1054 const SMDS_MeshFace * f5,
1055 const SMDS_MeshFace * f6,
1058 //MESSAGE("AddVolumeWithID" << ID);
1059 if (!hasConstructionFaces())
1061 if ( !f1 || !f2 || !f3 || !f4 || !f5 || !f6) return 0;
1062 //if ( myVolumes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1063 SMDS_MeshVolume * volume = new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5,f6);
1064 adjustmyCellsCapacity(ID);
1065 myCells[ID] = volume;
1066 myInfo.myNbPrisms++;
1068 if (!registerElement(ID, volume)) {
1069 RemoveElement(volume, false);
1075 ///////////////////////////////////////////////////////////////////////////////
1076 /// Add a polygon defined by its nodes IDs
1077 ///////////////////////////////////////////////////////////////////////////////
1079 SMDS_MeshFace* SMDS_Mesh::AddPolygonalFaceWithID (std::vector<int> nodes_ids,
1082 int nbNodes = nodes_ids.size();
1083 std::vector<const SMDS_MeshNode*> nodes (nbNodes);
1084 for (int i = 0; i < nbNodes; i++) {
1085 nodes[i] = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nodes_ids[i]);
1086 if (!nodes[i]) return NULL;
1088 return SMDS_Mesh::AddPolygonalFaceWithID(nodes, ID);
1091 ///////////////////////////////////////////////////////////////////////////////
1092 /// Add a polygon defined by its nodes
1093 ///////////////////////////////////////////////////////////////////////////////
1095 SMDS_MeshFace* SMDS_Mesh::AddPolygonalFaceWithID
1096 (std::vector<const SMDS_MeshNode*> nodes,
1099 SMDS_MeshFace * face;
1101 //if ( myFaces.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1102 if (hasConstructionEdges())
1104 MESSAGE("Error : Not implemented");
1109 for ( int i = 0; i < nodes.size(); ++i )
1110 if ( !nodes[ i ] ) return 0;
1111 face = new SMDS_PolygonalFaceOfNodes(nodes);
1112 adjustmyCellsCapacity(ID);
1114 myInfo.myNbPolygons++;
1117 if (!registerElement(ID, face)) {
1118 RemoveElement(face, false);
1124 ///////////////////////////////////////////////////////////////////////////////
1125 /// Add a polygon defined by its nodes.
1126 /// An ID is automatically affected to the created face.
1127 ///////////////////////////////////////////////////////////////////////////////
1129 SMDS_MeshFace* SMDS_Mesh::AddPolygonalFace (std::vector<const SMDS_MeshNode*> nodes)
1131 return SMDS_Mesh::AddPolygonalFaceWithID(nodes, myElementIDFactory->GetFreeID());
1134 ///////////////////////////////////////////////////////////////////////////////
1135 /// Create a new polyhedral volume and add it to the mesh.
1136 /// @param ID The ID of the new volume
1137 /// @return The created volume or NULL if an element with this ID already exists
1138 /// or if input nodes are not found.
1139 ///////////////////////////////////////////////////////////////////////////////
1141 SMDS_MeshVolume * SMDS_Mesh::AddPolyhedralVolumeWithID
1142 (std::vector<int> nodes_ids,
1143 std::vector<int> quantities,
1146 int nbNodes = nodes_ids.size();
1147 std::vector<const SMDS_MeshNode*> nodes (nbNodes);
1148 for (int i = 0; i < nbNodes; i++) {
1149 nodes[i] = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nodes_ids[i]);
1150 if (!nodes[i]) return NULL;
1152 return SMDS_Mesh::AddPolyhedralVolumeWithID(nodes, quantities, ID);
1155 ///////////////////////////////////////////////////////////////////////////////
1156 /// Create a new polyhedral volume and add it to the mesh.
1157 /// @param ID The ID of the new volume
1158 /// @return The created volume
1159 ///////////////////////////////////////////////////////////////////////////////
1161 SMDS_MeshVolume* SMDS_Mesh::AddPolyhedralVolumeWithID
1162 (std::vector<const SMDS_MeshNode*> nodes,
1163 std::vector<int> quantities,
1166 SMDS_MeshVolume* volume;
1167 //if ( myVolumes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1168 if (hasConstructionFaces()) {
1169 MESSAGE("Error : Not implemented");
1171 } else if (hasConstructionEdges()) {
1172 MESSAGE("Error : Not implemented");
1175 for ( int i = 0; i < nodes.size(); ++i )
1176 if ( !nodes[ i ] ) return 0;
1177 volume = new SMDS_PolyhedralVolumeOfNodes(nodes, quantities);
1178 adjustmyCellsCapacity(ID);
1179 myCells[ID] = volume;
1180 myInfo.myNbPolyhedrons++;
1183 if (!registerElement(ID, volume)) {
1184 RemoveElement(volume, false);
1190 ///////////////////////////////////////////////////////////////////////////////
1191 /// Create a new polyhedral volume and add it to the mesh.
1192 /// @return The created volume
1193 ///////////////////////////////////////////////////////////////////////////////
1195 SMDS_MeshVolume* SMDS_Mesh::AddPolyhedralVolume
1196 (std::vector<const SMDS_MeshNode*> nodes,
1197 std::vector<int> quantities)
1199 int ID = myElementIDFactory->GetFreeID();
1200 SMDS_MeshVolume * v = SMDS_Mesh::AddPolyhedralVolumeWithID(nodes, quantities, ID);
1201 if (v == NULL) myElementIDFactory->ReleaseID(ID);
1205 ///////////////////////////////////////////////////////////////////////////////
1206 /// Registers element with the given ID, maintains inverse connections
1207 ///////////////////////////////////////////////////////////////////////////////
1208 bool SMDS_Mesh::registerElement(int ID, SMDS_MeshElement* element)
1210 //MESSAGE("registerElement " << ID)
1211 if ((ID < myIDElements.size()) && myIDElements[ID] >= 0) // --- already bound
1213 MESSAGE(" --------------------------------- already bound "<< ID << " " << myIDElements[ID]);
1218 element->myMeshId = myMeshId;
1220 SMDS_MeshCell *cell = dynamic_cast<SMDS_MeshCell*>(element);
1222 int vtkId = cell->getVtkId();
1224 vtkId = myElementIDFactory->SetInVtkGrid(element);
1226 if (ID >= myIDElements.size()) // --- resize local vector
1228 MESSAGE(" ------------------- resize myIDElements " << ID << " --> " << ID + SMDS_Mesh::chunkSize);
1229 myIDElements.resize(ID + SMDS_Mesh::chunkSize, -1); // fill new elements with -1
1232 myIDElements[ID] = vtkId;
1233 //MESSAGE("smds:" << ID << " vtk:" << cellId );
1235 if (vtkId >= myVtkIndex.size()) // --- resize local vector
1237 MESSAGE(" --------------------- resize myVtkIndex " << vtkId << " --> " << vtkId + SMDS_Mesh::chunkSize);
1238 myVtkIndex.resize(vtkId + SMDS_Mesh::chunkSize, -1);
1240 myVtkIndex[vtkId] = ID;
1242 myElementIDFactory->updateMinMax(ID);
1246 ///////////////////////////////////////////////////////////////////////////////
1247 /// Return the node whose ID is 'ID'.
1248 ///////////////////////////////////////////////////////////////////////////////
1249 const SMDS_MeshNode * SMDS_Mesh::FindNode(int ID) const
1251 if (ID < 0 || ID >= myNodes.size())
1253 MESSAGE("----------------------------------- bad ID " << ID << " " << myNodes.size());
1256 return (const SMDS_MeshNode *)myNodes[ID];
1259 ///////////////////////////////////////////////////////////////////////////////
1260 ///Create a triangle and add it to the current mesh. This method do not bind an
1261 ///ID to the create triangle.
1262 ///////////////////////////////////////////////////////////////////////////////
1263 SMDS_MeshFace * SMDS_Mesh::createTriangle(const SMDS_MeshNode * node1,
1264 const SMDS_MeshNode * node2,
1265 const SMDS_MeshNode * node3,
1268 if ( !node1 || !node2 || !node3) return 0;
1269 // if ( myFaces.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1270 if(hasConstructionEdges())
1272 SMDS_MeshEdge *edge1, *edge2, *edge3;
1273 edge1=FindEdgeOrCreate(node1,node2);
1274 edge2=FindEdgeOrCreate(node2,node3);
1275 edge3=FindEdgeOrCreate(node3,node1);
1277 //int ID = myElementIDFactory->GetFreeID(); // -PR- voir si on range cet element
1278 SMDS_MeshFace * face = new SMDS_FaceOfEdges(edge1,edge2,edge3);
1279 adjustmyCellsCapacity(ID);
1281 myInfo.myNbTriangles++;
1286 // --- retrieve nodes ID
1287 vector<vtkIdType> nodeIds;
1289 nodeIds.push_back(node1->getId());
1290 nodeIds.push_back(node2->getId());
1291 nodeIds.push_back(node3->getId());
1293 SMDS_MeshFace * face = 0;
1294 SMDS_VtkFace *facevtk = myFacePool->getNew();
1295 facevtk->init(nodeIds, this);
1297 adjustmyCellsCapacity(ID);
1299 myInfo.myNbTriangles++;
1304 ///////////////////////////////////////////////////////////////////////////////
1305 ///Create a quadrangle and add it to the current mesh. This methode do not bind
1306 ///a ID to the create triangle.
1307 ///////////////////////////////////////////////////////////////////////////////
1308 SMDS_MeshFace * SMDS_Mesh::createQuadrangle(const SMDS_MeshNode * node1,
1309 const SMDS_MeshNode * node2,
1310 const SMDS_MeshNode * node3,
1311 const SMDS_MeshNode * node4,
1314 if ( !node1 || !node2 || !node3 || !node4 ) return 0;
1315 // if ( myFaces.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1316 if(hasConstructionEdges())
1318 //MESSAGE("createQuadrangle hasConstructionEdges "<< ID);
1319 SMDS_MeshEdge *edge1, *edge2, *edge3, *edge4;
1320 edge1=FindEdgeOrCreate(node1,node2);
1321 edge2=FindEdgeOrCreate(node2,node3);
1322 edge3=FindEdgeOrCreate(node3,node4);
1323 edge4=FindEdgeOrCreate(node4,node1);
1325 SMDS_MeshFace * face = new SMDS_FaceOfEdges(edge1,edge2,edge3,edge4);
1326 adjustmyCellsCapacity(ID);
1328 myInfo.myNbQuadrangles++;
1333 // --- retrieve nodes ID
1334 vector<vtkIdType> nodeIds;
1336 nodeIds.push_back(node1->getId());
1337 nodeIds.push_back(node2->getId());
1338 nodeIds.push_back(node3->getId());
1339 nodeIds.push_back(node4->getId());
1341 SMDS_MeshFace * face = 0;
1342 SMDS_VtkFace *facevtk = myFacePool->getNew();
1343 facevtk->init(nodeIds, this);
1345 adjustmyCellsCapacity(ID);
1347 myInfo.myNbQuadrangles++;
1352 ///////////////////////////////////////////////////////////////////////////////
1353 /// Remove a node and all the elements which own this node
1354 ///////////////////////////////////////////////////////////////////////////////
1356 void SMDS_Mesh::RemoveNode(const SMDS_MeshNode * node)
1358 MESSAGE("RemoveNode");
1359 RemoveElement(node, true);
1362 ///////////////////////////////////////////////////////////////////////////////
1363 /// Remove an edge and all the elements which own this edge
1364 ///////////////////////////////////////////////////////////////////////////////
1366 void SMDS_Mesh::Remove0DElement(const SMDS_Mesh0DElement * elem0d)
1368 MESSAGE("Remove0DElement");
1369 RemoveElement(elem0d,true);
1372 ///////////////////////////////////////////////////////////////////////////////
1373 /// Remove an edge and all the elements which own this edge
1374 ///////////////////////////////////////////////////////////////////////////////
1376 void SMDS_Mesh::RemoveEdge(const SMDS_MeshEdge * edge)
1378 MESSAGE("RemoveEdge");
1379 RemoveElement(edge,true);
1382 ///////////////////////////////////////////////////////////////////////////////
1383 /// Remove an face and all the elements which own this face
1384 ///////////////////////////////////////////////////////////////////////////////
1386 void SMDS_Mesh::RemoveFace(const SMDS_MeshFace * face)
1388 MESSAGE("RemoveFace");
1389 RemoveElement(face, true);
1392 ///////////////////////////////////////////////////////////////////////////////
1394 ///////////////////////////////////////////////////////////////////////////////
1396 void SMDS_Mesh::RemoveVolume(const SMDS_MeshVolume * volume)
1398 MESSAGE("RemoveVolume");
1399 RemoveElement(volume, true);
1402 //=======================================================================
1403 //function : RemoveFromParent
1405 //=======================================================================
1407 bool SMDS_Mesh::RemoveFromParent()
1409 if (myParent==NULL) return false;
1410 else return (myParent->RemoveSubMesh(this));
1413 //=======================================================================
1414 //function : RemoveSubMesh
1416 //=======================================================================
1418 bool SMDS_Mesh::RemoveSubMesh(const SMDS_Mesh * aMesh)
1422 list<SMDS_Mesh *>::iterator itmsh=myChildren.begin();
1423 for (; itmsh!=myChildren.end() && !found; itmsh++)
1425 SMDS_Mesh * submesh = *itmsh;
1426 if (submesh == aMesh)
1429 myChildren.erase(itmsh);
1436 //=======================================================================
1437 //function : ChangeElementNodes
1439 //=======================================================================
1441 bool SMDS_Mesh::ChangeElementNodes(const SMDS_MeshElement * element,
1442 const SMDS_MeshNode * nodes[],
1445 MYASSERT(0); // REVOIR LES TYPES
1446 // keep current nodes of elem
1447 set<const SMDS_MeshElement*> oldNodes;
1448 SMDS_ElemIteratorPtr itn = element->nodesIterator();
1450 oldNodes.insert( itn->next() );
1452 if ( !element->IsPoly() )
1453 myInfo.remove( element ); // element may change type
1457 SMDS_MeshElement* elem = const_cast<SMDS_MeshElement*>(element);
1458 switch ( elem->GetType() )
1460 case SMDSAbs_0DElement: {
1461 if ( SMDS_Mesh0DElement* elem0d = dynamic_cast<SMDS_Mesh0DElement*>( elem ))
1462 Ok = elem0d->ChangeNode( nodes[0] );
1465 case SMDSAbs_Edge: {
1466 if ( nbnodes == 2 ) {
1467 if ( SMDS_VtkEdge* edge = dynamic_cast<SMDS_VtkEdge*>( elem ))
1468 Ok = edge->ChangeNodes( nodes[0], nodes[1] );
1470 else if ( nbnodes == 3 ) {
1471 if ( SMDS_QuadraticEdge* edge = dynamic_cast<SMDS_QuadraticEdge*>( elem ))
1472 Ok = edge->ChangeNodes( nodes[0], nodes[1], nodes[2] );
1476 case SMDSAbs_Face: {
1477 if ( SMDS_FaceOfNodes* face = dynamic_cast<SMDS_FaceOfNodes*>( elem ))
1478 Ok = face->ChangeNodes( nodes, nbnodes );
1480 if ( SMDS_QuadraticFaceOfNodes* QF = dynamic_cast<SMDS_QuadraticFaceOfNodes*>( elem ))
1481 Ok = QF->ChangeNodes( nodes, nbnodes );
1483 if (SMDS_PolygonalFaceOfNodes* face = dynamic_cast<SMDS_PolygonalFaceOfNodes*>(elem))
1484 Ok = face->ChangeNodes(nodes, nbnodes);
1487 case SMDSAbs_Volume: {
1488 if ( SMDS_VolumeOfNodes* vol = dynamic_cast<SMDS_VolumeOfNodes*>( elem ))
1489 Ok = vol->ChangeNodes( nodes, nbnodes );
1491 if ( SMDS_QuadraticVolumeOfNodes* QV = dynamic_cast<SMDS_QuadraticVolumeOfNodes*>( elem ))
1492 Ok = QV->ChangeNodes( nodes, nbnodes );
1496 MESSAGE ( "WRONG ELEM TYPE");
1499 if ( Ok ) { // update InverseElements
1501 set<const SMDS_MeshElement*>::iterator it;
1503 // AddInverseElement to new nodes
1504 for ( int i = 0; i < nbnodes; i++ ) {
1505 it = oldNodes.find( nodes[i] );
1506 if ( it == oldNodes.end() )
1508 const_cast<SMDS_MeshNode*>( nodes[i] )->AddInverseElement( elem );
1510 // remove from oldNodes a node that remains in elem
1511 oldNodes.erase( it );
1513 // RemoveInverseElement from the nodes removed from elem
1514 for ( it = oldNodes.begin(); it != oldNodes.end(); it++ )
1516 SMDS_MeshNode * n = static_cast<SMDS_MeshNode *>
1517 (const_cast<SMDS_MeshElement *>( *it ));
1518 n->RemoveInverseElement( elem );
1522 if ( !element->IsPoly() )
1523 myInfo.add( element ); // element may change type
1528 //=======================================================================
1529 //function : ChangePolyhedronNodes
1530 //purpose : to change nodes of polyhedral volume
1531 //=======================================================================
1532 bool SMDS_Mesh::ChangePolyhedronNodes (const SMDS_MeshElement * elem,
1533 const vector<const SMDS_MeshNode*>& nodes,
1534 const vector<int> & quantities)
1536 if (elem->GetType() != SMDSAbs_Volume) {
1537 MESSAGE("WRONG ELEM TYPE");
1541 const SMDS_PolyhedralVolumeOfNodes* vol = dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*>(elem);
1546 // keep current nodes of elem
1547 set<const SMDS_MeshElement*> oldNodes;
1548 SMDS_ElemIteratorPtr itn = elem->nodesIterator();
1549 while (itn->more()) {
1550 oldNodes.insert(itn->next());
1554 bool Ok = const_cast<SMDS_PolyhedralVolumeOfNodes*>(vol)->ChangeNodes(nodes, quantities);
1559 // update InverseElements
1561 // AddInverseElement to new nodes
1562 int nbnodes = nodes.size();
1563 set<const SMDS_MeshElement*>::iterator it;
1564 for (int i = 0; i < nbnodes; i++) {
1565 it = oldNodes.find(nodes[i]);
1566 if (it == oldNodes.end()) {
1568 const_cast<SMDS_MeshNode*>(nodes[i])->AddInverseElement(elem);
1570 // remove from oldNodes a node that remains in elem
1575 // RemoveInverseElement from the nodes removed from elem
1576 for (it = oldNodes.begin(); it != oldNodes.end(); it++) {
1577 SMDS_MeshNode * n = static_cast<SMDS_MeshNode *>
1578 (const_cast<SMDS_MeshElement *>( *it ));
1579 n->RemoveInverseElement(elem);
1586 //=======================================================================
1587 //function : Find0DElement
1589 //=======================================================================
1590 const SMDS_Mesh0DElement* SMDS_Mesh::Find0DElement(int idnode) const
1592 const SMDS_MeshNode * node = FindNode(idnode);
1593 if(node == NULL) return NULL;
1594 return Find0DElement(node);
1597 const SMDS_Mesh0DElement* SMDS_Mesh::Find0DElement(const SMDS_MeshNode * node)
1599 if (!node) return 0;
1600 const SMDS_Mesh0DElement* toReturn = NULL;
1601 SMDS_ElemIteratorPtr it1 = node->GetInverseElementIterator(SMDSAbs_0DElement);
1602 while (it1->more() && (toReturn == NULL)) {
1603 const SMDS_MeshElement* e = it1->next();
1604 if (e->NbNodes() == 1) {
1605 toReturn = static_cast<const SMDS_Mesh0DElement*>(e);
1611 //=======================================================================
1612 //function : Find0DElementOrCreate
1614 //=======================================================================
1615 //SMDS_Mesh0DElement* SMDS_Mesh::Find0DElementOrCreate(const SMDS_MeshNode * node)
1617 // if (!node) return 0;
1618 // SMDS_Mesh0DElement * toReturn = NULL;
1619 // toReturn = const_cast<SMDS_Mesh0DElement*>(Find0DElement(node));
1620 // if (toReturn == NULL) {
1621 // //if (my0DElements.Extent() % CHECKMEMORY_INTERVAL == 0) CheckMemory();
1622 // toReturn = new SMDS_Mesh0DElement(node);
1623 // my0DElements.Add(toReturn);
1624 // myInfo.myNb0DElements++;
1630 //=======================================================================
1631 //function : FindEdge
1633 //=======================================================================
1635 const SMDS_MeshEdge* SMDS_Mesh::FindEdge(int idnode1, int idnode2) const
1637 const SMDS_MeshNode * node1=FindNode(idnode1);
1638 const SMDS_MeshNode * node2=FindNode(idnode2);
1639 if((node1==NULL)||(node2==NULL)) return NULL;
1640 return FindEdge(node1,node2);
1643 //#include "Profiler.h"
1644 const SMDS_MeshEdge* SMDS_Mesh::FindEdge(const SMDS_MeshNode * node1,
1645 const SMDS_MeshNode * node2)
1647 if ( !node1 ) return 0;
1648 const SMDS_MeshEdge * toReturn=NULL;
1651 SMDS_ElemIteratorPtr it1=node1->GetInverseElementIterator(SMDSAbs_Edge);
1654 while(it1->more()) {
1655 const SMDS_MeshElement * e = it1->next();
1656 if ( e->NbNodes() == 2 && e->GetNodeIndex( node2 ) >= 0 ) {
1657 toReturn = static_cast<const SMDS_MeshEdge*>( e );
1666 //=======================================================================
1667 //function : FindEdgeOrCreate
1669 //=======================================================================
1671 SMDS_MeshEdge* SMDS_Mesh::FindEdgeOrCreate(const SMDS_MeshNode * node1,
1672 const SMDS_MeshNode * node2)
1674 if ( !node1 || !node2) return 0;
1675 SMDS_MeshEdge * toReturn=NULL;
1676 toReturn=const_cast<SMDS_MeshEdge*>(FindEdge(node1,node2));
1677 if(toReturn==NULL) {
1678 //if ( myEdges.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1679 int ID = myElementIDFactory->GetFreeID(); // -PR- voir si on range cet element
1680 adjustmyCellsCapacity(ID);
1681 vector<vtkIdType> nodeIds;
1683 nodeIds.push_back(node1->getId());
1684 nodeIds.push_back(node2->getId());
1686 SMDS_VtkEdge *edgevtk = myEdgePool->getNew();
1687 edgevtk->init(nodeIds, this);
1689 myCells[ID] = toReturn;
1696 //=======================================================================
1697 //function : FindEdge
1699 //=======================================================================
1701 const SMDS_MeshEdge* SMDS_Mesh::FindEdge(int idnode1, int idnode2,
1704 const SMDS_MeshNode * node1=FindNode(idnode1);
1705 const SMDS_MeshNode * node2=FindNode(idnode2);
1706 const SMDS_MeshNode * node3=FindNode(idnode3);
1707 return FindEdge(node1,node2,node3);
1710 const SMDS_MeshEdge* SMDS_Mesh::FindEdge(const SMDS_MeshNode * node1,
1711 const SMDS_MeshNode * node2,
1712 const SMDS_MeshNode * node3)
1714 if ( !node1 ) return 0;
1715 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Edge);
1716 while(it1->more()) {
1717 const SMDS_MeshElement * e = it1->next();
1718 if ( e->NbNodes() == 3 ) {
1719 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
1720 while(it2->more()) {
1721 const SMDS_MeshElement* n = it2->next();
1731 return static_cast<const SMDS_MeshEdge *> (e);
1738 //=======================================================================
1739 //function : FindFace
1741 //=======================================================================
1743 const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2,
1746 const SMDS_MeshNode * node1=FindNode(idnode1);
1747 const SMDS_MeshNode * node2=FindNode(idnode2);
1748 const SMDS_MeshNode * node3=FindNode(idnode3);
1749 return FindFace(node1, node2, node3);
1752 const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1,
1753 const SMDS_MeshNode *node2,
1754 const SMDS_MeshNode *node3)
1756 if ( !node1 ) return 0;
1757 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Face);
1758 while(it1->more()) {
1759 const SMDS_MeshElement * e = it1->next();
1760 if ( e->NbNodes() == 3 ) {
1761 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
1762 while(it2->more()) {
1763 const SMDS_MeshElement* n = it2->next();
1773 return static_cast<const SMDS_MeshFace *> (e);
1779 SMDS_MeshFace* SMDS_Mesh::FindFaceOrCreate(const SMDS_MeshNode *node1,
1780 const SMDS_MeshNode *node2,
1781 const SMDS_MeshNode *node3)
1783 SMDS_MeshFace * toReturn=NULL;
1784 toReturn = const_cast<SMDS_MeshFace*>(FindFace(node1,node2,node3));
1785 if(toReturn==NULL) {
1786 int ID = myElementIDFactory->GetFreeID();
1787 toReturn = createTriangle(node1,node2,node3, ID);
1793 //=======================================================================
1794 //function : FindFace
1796 //=======================================================================
1798 const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2,
1799 int idnode3, int idnode4) const
1801 const SMDS_MeshNode * node1=FindNode(idnode1);
1802 const SMDS_MeshNode * node2=FindNode(idnode2);
1803 const SMDS_MeshNode * node3=FindNode(idnode3);
1804 const SMDS_MeshNode * node4=FindNode(idnode4);
1805 return FindFace(node1, node2, node3, node4);
1808 const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1,
1809 const SMDS_MeshNode *node2,
1810 const SMDS_MeshNode *node3,
1811 const SMDS_MeshNode *node4)
1813 if ( !node1 ) return 0;
1814 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Face);
1815 while(it1->more()) {
1816 const SMDS_MeshElement * e = it1->next();
1817 if ( e->NbNodes() == 4 ) {
1818 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
1819 while(it2->more()) {
1820 const SMDS_MeshElement* n = it2->next();
1831 return static_cast<const SMDS_MeshFace *> (e);
1837 SMDS_MeshFace* SMDS_Mesh::FindFaceOrCreate(const SMDS_MeshNode *node1,
1838 const SMDS_MeshNode *node2,
1839 const SMDS_MeshNode *node3,
1840 const SMDS_MeshNode *node4)
1842 SMDS_MeshFace * toReturn=NULL;
1843 toReturn=const_cast<SMDS_MeshFace*>(FindFace(node1,node2,node3,node4));
1844 if(toReturn==NULL) {
1845 int ID = myElementIDFactory->GetFreeID();
1846 toReturn=createQuadrangle(node1,node2,node3,node4,ID);
1852 //=======================================================================
1853 //function : FindFace
1854 //purpose :quadratic triangle
1855 //=======================================================================
1857 const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2,
1858 int idnode3, int idnode4,
1859 int idnode5, int idnode6) const
1861 const SMDS_MeshNode * node1 = FindNode(idnode1);
1862 const SMDS_MeshNode * node2 = FindNode(idnode2);
1863 const SMDS_MeshNode * node3 = FindNode(idnode3);
1864 const SMDS_MeshNode * node4 = FindNode(idnode4);
1865 const SMDS_MeshNode * node5 = FindNode(idnode5);
1866 const SMDS_MeshNode * node6 = FindNode(idnode6);
1867 return FindFace(node1, node2, node3, node4, node5, node6);
1870 const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1,
1871 const SMDS_MeshNode *node2,
1872 const SMDS_MeshNode *node3,
1873 const SMDS_MeshNode *node4,
1874 const SMDS_MeshNode *node5,
1875 const SMDS_MeshNode *node6)
1877 if ( !node1 ) return 0;
1878 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Face);
1879 while(it1->more()) {
1880 const SMDS_MeshElement * e = it1->next();
1881 if ( e->NbNodes() == 6 ) {
1882 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
1883 while(it2->more()) {
1884 const SMDS_MeshElement* n = it2->next();
1897 return static_cast<const SMDS_MeshFace *> (e);
1904 //=======================================================================
1905 //function : FindFace
1906 //purpose : quadratic quadrangle
1907 //=======================================================================
1909 const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2,
1910 int idnode3, int idnode4,
1911 int idnode5, int idnode6,
1912 int idnode7, int idnode8) const
1914 const SMDS_MeshNode * node1 = FindNode(idnode1);
1915 const SMDS_MeshNode * node2 = FindNode(idnode2);
1916 const SMDS_MeshNode * node3 = FindNode(idnode3);
1917 const SMDS_MeshNode * node4 = FindNode(idnode4);
1918 const SMDS_MeshNode * node5 = FindNode(idnode5);
1919 const SMDS_MeshNode * node6 = FindNode(idnode6);
1920 const SMDS_MeshNode * node7 = FindNode(idnode7);
1921 const SMDS_MeshNode * node8 = FindNode(idnode8);
1922 return FindFace(node1, node2, node3, node4, node5, node6, node7, node8);
1925 const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1,
1926 const SMDS_MeshNode *node2,
1927 const SMDS_MeshNode *node3,
1928 const SMDS_MeshNode *node4,
1929 const SMDS_MeshNode *node5,
1930 const SMDS_MeshNode *node6,
1931 const SMDS_MeshNode *node7,
1932 const SMDS_MeshNode *node8)
1934 if ( !node1 ) return 0;
1935 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Face);
1936 while(it1->more()) {
1937 const SMDS_MeshElement * e = it1->next();
1938 if ( e->NbNodes() == 8 ) {
1939 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
1940 while(it2->more()) {
1941 const SMDS_MeshElement* n = it2->next();
1956 return static_cast<const SMDS_MeshFace *> (e);
1963 //=======================================================================
1964 //function : FindElement
1966 //=======================================================================
1968 const SMDS_MeshElement* SMDS_Mesh::FindElement(int IDelem) const
1970 if ((IDelem < 0) || IDelem >= myCells.size())
1972 MESSAGE("----------------------------------- bad IDelem " << IDelem << " " << myCells.size());
1975 return myCells[IDelem];
1978 //=======================================================================
1979 //function : FindFace
1980 //purpose : find polygon
1981 //=======================================================================
1983 const SMDS_MeshFace* SMDS_Mesh::FindFace (std::vector<int> nodes_ids) const
1985 int nbnodes = nodes_ids.size();
1986 std::vector<const SMDS_MeshNode *> poly_nodes (nbnodes);
1987 for (int inode = 0; inode < nbnodes; inode++) {
1988 const SMDS_MeshNode * node = FindNode(nodes_ids[inode]);
1989 if (node == NULL) return NULL;
1990 poly_nodes[inode] = node;
1992 return FindFace(poly_nodes);
1995 const SMDS_MeshFace* SMDS_Mesh::FindFace (std::vector<const SMDS_MeshNode *> nodes)
1997 if ( nodes.size() > 2 && nodes[0] ) {
1998 SMDS_ElemIteratorPtr itF = nodes[0]->GetInverseElementIterator(SMDSAbs_Face);
1999 while (itF->more()) {
2000 const SMDS_MeshElement* f = itF->next();
2001 if ( f->NbNodes() == nodes.size() ) {
2002 SMDS_ElemIteratorPtr it2 = f->nodesIterator();
2003 while(it2->more()) {
2004 if ( find( nodes.begin(), nodes.end(), it2->next() ) == nodes.end() ) {
2010 return static_cast<const SMDS_MeshFace *> (f);
2017 //=======================================================================
2018 //function : DumpNodes
2020 //=======================================================================
2022 void SMDS_Mesh::DumpNodes() const
2024 MESSAGE("dump nodes of mesh : ");
2025 SMDS_NodeIteratorPtr itnode=nodesIterator();
2026 while(itnode->more()) ; //MESSAGE(itnode->next());
2029 //=======================================================================
2030 //function : Dump0DElements
2032 //=======================================================================
2033 void SMDS_Mesh::Dump0DElements() const
2035 MESSAGE("dump 0D elements of mesh : ");
2036 SMDS_0DElementIteratorPtr it0d = elements0dIterator();
2037 while(it0d->more()) ; //MESSAGE(it0d->next());
2040 //=======================================================================
2041 //function : DumpEdges
2043 //=======================================================================
2045 void SMDS_Mesh::DumpEdges() const
2047 MESSAGE("dump edges of mesh : ");
2048 SMDS_EdgeIteratorPtr itedge=edgesIterator();
2049 while(itedge->more()) ; //MESSAGE(itedge->next());
2052 //=======================================================================
2053 //function : DumpFaces
2055 //=======================================================================
2057 void SMDS_Mesh::DumpFaces() const
2059 MESSAGE("dump faces of mesh : ");
2060 SMDS_FaceIteratorPtr itface=facesIterator();
2061 while(itface->more()) ; //MESSAGE(itface->next());
2064 //=======================================================================
2065 //function : DumpVolumes
2067 //=======================================================================
2069 void SMDS_Mesh::DumpVolumes() const
2071 MESSAGE("dump volumes of mesh : ");
2072 SMDS_VolumeIteratorPtr itvol=volumesIterator();
2073 while(itvol->more()) ; //MESSAGE(itvol->next());
2076 //=======================================================================
2077 //function : DebugStats
2079 //=======================================================================
2081 void SMDS_Mesh::DebugStats() const
2083 MESSAGE("Debug stats of mesh : ");
2085 MESSAGE("===== NODES ====="<<NbNodes());
2086 MESSAGE("===== 0DELEMS ====="<<Nb0DElements());
2087 MESSAGE("===== EDGES ====="<<NbEdges());
2088 MESSAGE("===== FACES ====="<<NbFaces());
2089 MESSAGE("===== VOLUMES ====="<<NbVolumes());
2091 MESSAGE("End Debug stats of mesh ");
2095 SMDS_NodeIteratorPtr itnode=nodesIterator();
2096 int sizeofnodes = 0;
2097 int sizeoffaces = 0;
2099 while(itnode->more())
2101 const SMDS_MeshNode *node = itnode->next();
2103 sizeofnodes += sizeof(*node);
2105 SMDS_ElemIteratorPtr it = node->GetInverseElementIterator();
2108 const SMDS_MeshElement *me = it->next();
2109 sizeofnodes += sizeof(me);
2113 SMDS_FaceIteratorPtr itface=facesIterator();
2114 while(itface->more())
2116 const SMDS_MeshElement *face = itface->next();
2117 sizeoffaces += sizeof(*face);
2120 MESSAGE("total size of node elements = " << sizeofnodes);;
2121 MESSAGE("total size of face elements = " << sizeoffaces);;
2126 ///////////////////////////////////////////////////////////////////////////////
2127 /// Return the number of nodes
2128 ///////////////////////////////////////////////////////////////////////////////
2129 int SMDS_Mesh::NbNodes() const
2131 return myNodes.size();
2134 ///////////////////////////////////////////////////////////////////////////////
2135 /// Return the number of 0D elements
2136 ///////////////////////////////////////////////////////////////////////////////
2137 int SMDS_Mesh::Nb0DElements() const
2139 return myInfo.Nb0DElements(); // -PR- a verfier
2142 ///////////////////////////////////////////////////////////////////////////////
2143 /// Return the number of edges (including construction edges)
2144 ///////////////////////////////////////////////////////////////////////////////
2145 int SMDS_Mesh::NbEdges() const
2147 return myInfo.NbEdges(); // -PR- a verfier
2150 ///////////////////////////////////////////////////////////////////////////////
2151 /// Return the number of faces (including construction faces)
2152 ///////////////////////////////////////////////////////////////////////////////
2153 int SMDS_Mesh::NbFaces() const
2155 return myInfo.NbFaces(); // -PR- a verfier
2158 ///////////////////////////////////////////////////////////////////////////////
2159 /// Return the number of volumes
2160 ///////////////////////////////////////////////////////////////////////////////
2161 int SMDS_Mesh::NbVolumes() const
2163 return myInfo.NbVolumes(); // -PR- a verfier
2166 ///////////////////////////////////////////////////////////////////////////////
2167 /// Return the number of child mesh of this mesh.
2168 /// Note that the tree structure of SMDS_Mesh seems to be unused in this version
2169 /// (2003-09-08) of SMESH
2170 ///////////////////////////////////////////////////////////////////////////////
2171 int SMDS_Mesh::NbSubMesh() const
2173 return myChildren.size();
2176 ///////////////////////////////////////////////////////////////////////////////
2177 /// Destroy the mesh and all its elements
2178 /// All pointer on elements owned by this mesh become illegals.
2179 ///////////////////////////////////////////////////////////////////////////////
2180 SMDS_Mesh::~SMDS_Mesh()
2182 list<SMDS_Mesh*>::iterator itc=myChildren.begin();
2183 while(itc!=myChildren.end())
2191 delete myNodeIDFactory;
2192 delete myElementIDFactory;
2196 SMDS_ElemIteratorPtr eIt = elementsIterator();
2197 while ( eIt->more() )
2198 myElementIDFactory->ReleaseID(eIt->next()->GetID());
2199 SMDS_NodeIteratorPtr itn = nodesIterator();
2201 myNodeIDFactory->ReleaseID(itn->next()->GetID());
2204 // SetOfNodes::Iterator itn(myNodes);
2205 // for (; itn.More(); itn.Next())
2206 // delete itn.Value();
2208 // SetOf0DElements::Iterator it0d (my0DElements);
2209 // for (; it0d.More(); it0d.Next())
2211 // SMDS_MeshElement* elem = it0d.Value();
2215 // SetOfEdges::Iterator ite(myEdges);
2216 // for (; ite.More(); ite.Next())
2218 // SMDS_MeshElement* elem = ite.Value();
2222 // SetOfFaces::Iterator itf(myFaces);
2223 // for (; itf.More(); itf.Next())
2225 // SMDS_MeshElement* elem = itf.Value();
2229 // SetOfVolumes::Iterator itv(myVolumes);
2230 // for (; itv.More(); itv.Next())
2232 // SMDS_MeshElement* elem = itv.Value();
2237 //================================================================================
2239 * \brief Clear all data
2241 //================================================================================
2243 void SMDS_Mesh::Clear()
2245 if (myParent!=NULL) {
2246 SMDS_ElemIteratorPtr eIt = elementsIterator();
2247 while ( eIt->more() )
2248 myElementIDFactory->ReleaseID(eIt->next()->GetID());
2249 SMDS_NodeIteratorPtr itn = nodesIterator();
2251 myNodeIDFactory->ReleaseID(itn->next()->GetID());
2254 myNodeIDFactory->Clear();
2255 myElementIDFactory->Clear();
2258 SMDS_ElemIteratorPtr itv = elementsIterator();
2263 // SMDS_VolumeIteratorPtr itv = volumesIterator();
2264 // while (itv->more())
2265 // delete itv->next();
2266 // myVolumes.Clear();
2268 // SMDS_FaceIteratorPtr itf = facesIterator();
2269 // while (itf->more())
2270 // delete itf->next();
2273 // SMDS_EdgeIteratorPtr ite = edgesIterator();
2274 // while (ite->more())
2275 // delete ite->next();
2278 // SMDS_0DElementIteratorPtr it0d = elements0dIterator();
2279 // while (it0d->more())
2280 // delete it0d->next();
2281 // my0DElements.Clear();
2283 SMDS_NodeIteratorPtr itn = nodesIterator();
2288 list<SMDS_Mesh*>::iterator itc=myChildren.begin();
2289 while(itc!=myChildren.end())
2295 ///////////////////////////////////////////////////////////////////////////////
2296 /// Return true if this mesh create faces with edges.
2297 /// A false returned value mean that faces are created with nodes. A concequence
2298 /// is, iteration on edges (SMDS_Element::edgesIterator) will be unavailable.
2299 ///////////////////////////////////////////////////////////////////////////////
2300 bool SMDS_Mesh::hasConstructionEdges()
2302 return myHasConstructionEdges;
2305 ///////////////////////////////////////////////////////////////////////////////
2306 /// Return true if this mesh create volumes with faces
2307 /// A false returned value mean that volumes are created with nodes or edges.
2308 /// (see hasConstructionEdges)
2309 /// A concequence is, iteration on faces (SMDS_Element::facesIterator) will be
2311 ///////////////////////////////////////////////////////////////////////////////
2312 bool SMDS_Mesh::hasConstructionFaces()
2314 return myHasConstructionFaces;
2317 ///////////////////////////////////////////////////////////////////////////////
2318 /// Return true if nodes are linked to the finit elements, they are belonging to.
2319 /// Currently, It always return true.
2320 ///////////////////////////////////////////////////////////////////////////////
2321 bool SMDS_Mesh::hasInverseElements()
2323 return myHasInverseElements;
2326 ///////////////////////////////////////////////////////////////////////////////
2327 /// Make this mesh creating construction edges (see hasConstructionEdges)
2328 /// @param b true to have construction edges, else false.
2329 ///////////////////////////////////////////////////////////////////////////////
2330 void SMDS_Mesh::setConstructionEdges(bool b)
2332 myHasConstructionEdges=b;
2335 ///////////////////////////////////////////////////////////////////////////////
2336 /// Make this mesh creating construction faces (see hasConstructionFaces)
2337 /// @param b true to have construction faces, else false.
2338 ///////////////////////////////////////////////////////////////////////////////
2339 void SMDS_Mesh::setConstructionFaces(bool b)
2341 myHasConstructionFaces=b;
2344 ///////////////////////////////////////////////////////////////////////////////
2345 /// Make this mesh creating link from nodes to elements (see hasInverseElements)
2346 /// @param b true to link nodes to elements, else false.
2347 ///////////////////////////////////////////////////////////////////////////////
2348 void SMDS_Mesh::setInverseElements(bool b)
2350 if(!b) MESSAGE("Error : inverseElement=false not implemented");
2351 myHasInverseElements=b;
2354 ///////////////////////////////////////////////////////////////////////////////
2355 ///Iterator on NCollection_Map
2356 ///////////////////////////////////////////////////////////////////////////////
2357 template <class MAP, typename ELEM=const SMDS_MeshElement*, class FATHER=SMDS_ElemIterator>
2358 struct MYNode_Map_Iterator: public FATHER
2362 MYNode_Map_Iterator(const MAP& map): _map(map) // map is a std::vector<ELEM>
2369 while (_ctr < _map.size())
2380 ELEM current = _map[_ctr];
2386 template <class MAP, typename ELEM=const SMDS_MeshElement*, class FATHER=SMDS_ElemIterator>
2387 struct MYElem_Map_Iterator: public FATHER
2392 MYElem_Map_Iterator(const MAP& map, int typ): _map(map) // map is a std::vector<ELEM>
2400 while (_ctr < _map.size())
2403 if ( (_type == SMDSAbs_All) || (_map[_ctr]->GetType() == _type))
2412 ELEM current = dynamic_cast<ELEM> (_map[_ctr]);
2418 ///////////////////////////////////////////////////////////////////////////////
2419 /// Return an iterator on nodes of the current mesh factory
2420 ///////////////////////////////////////////////////////////////////////////////
2422 SMDS_NodeIteratorPtr SMDS_Mesh::nodesIterator() const
2424 //return SMDS_NodeIteratorPtr
2425 // (new SMDS_Mesh_MyNodeIterator(myNodeIDFactory->elementsIterator()));
2426 typedef MYNode_Map_Iterator
2427 < SetOfNodes, const SMDS_MeshNode*, SMDS_NodeIterator > TIterator;
2428 return SMDS_NodeIteratorPtr(new TIterator(myNodes));
2431 ///////////////////////////////////////////////////////////////////////////////
2432 ///Return an iterator on 0D elements of the current mesh.
2433 ///////////////////////////////////////////////////////////////////////////////
2435 SMDS_0DElementIteratorPtr SMDS_Mesh::elements0dIterator() const
2437 typedef MYElem_Map_Iterator
2438 < SetOfCells, const SMDS_Mesh0DElement*, SMDS_0DElementIterator > TIterator;
2439 return SMDS_0DElementIteratorPtr(new TIterator(myCells, SMDSAbs_0DElement));
2442 ///////////////////////////////////////////////////////////////////////////////
2443 ///Return an iterator on edges of the current mesh.
2444 ///////////////////////////////////////////////////////////////////////////////
2446 SMDS_EdgeIteratorPtr SMDS_Mesh::edgesIterator() const
2448 typedef MYElem_Map_Iterator
2449 < SetOfCells, const SMDS_MeshEdge*, SMDS_EdgeIterator > TIterator;
2450 return SMDS_EdgeIteratorPtr(new TIterator(myCells, SMDSAbs_Edge));
2453 ///////////////////////////////////////////////////////////////////////////////
2454 ///Return an iterator on faces of the current mesh.
2455 ///////////////////////////////////////////////////////////////////////////////
2457 SMDS_FaceIteratorPtr SMDS_Mesh::facesIterator() const
2459 typedef MYElem_Map_Iterator
2460 < SetOfCells, const SMDS_MeshFace*, SMDS_FaceIterator > TIterator;
2461 return SMDS_FaceIteratorPtr(new TIterator(myCells, SMDSAbs_Face));
2464 ///////////////////////////////////////////////////////////////////////////////
2465 ///Return an iterator on volumes of the current mesh.
2466 ///////////////////////////////////////////////////////////////////////////////
2468 SMDS_VolumeIteratorPtr SMDS_Mesh::volumesIterator() const
2470 typedef MYElem_Map_Iterator
2471 < SetOfCells, const SMDS_MeshVolume*, SMDS_VolumeIterator > TIterator;
2472 return SMDS_VolumeIteratorPtr(new TIterator(myCells, SMDSAbs_Volume));
2475 ///////////////////////////////////////////////////////////////////////////////
2476 /// Return an iterator on elements of the current mesh factory
2477 ///////////////////////////////////////////////////////////////////////////////
2478 SMDS_ElemIteratorPtr SMDS_Mesh::elementsIterator(SMDSAbs_ElementType type) const
2482 return SMDS_ElemIteratorPtr (new MYElem_Map_Iterator< SetOfCells >(myCells, SMDSAbs_All));
2484 case SMDSAbs_Volume:
2485 return SMDS_ElemIteratorPtr (new MYElem_Map_Iterator< SetOfCells >(myCells, SMDSAbs_Volume));
2487 return SMDS_ElemIteratorPtr (new MYElem_Map_Iterator< SetOfCells >(myCells, SMDSAbs_Face));
2489 return SMDS_ElemIteratorPtr (new MYElem_Map_Iterator< SetOfCells >(myCells, SMDSAbs_Edge));
2490 case SMDSAbs_0DElement:
2491 return SMDS_ElemIteratorPtr (new MYElem_Map_Iterator< SetOfCells >(myCells, SMDSAbs_0DElement));
2493 return SMDS_ElemIteratorPtr (new MYElem_Map_Iterator< SetOfNodes >(myNodes, SMDSAbs_All));
2494 //return myNodeIDFactory->elementsIterator();
2497 return myElementIDFactory->elementsIterator();
2500 ///////////////////////////////////////////////////////////////////////////////
2501 /// Do intersection of sets (more than 2)
2502 ///////////////////////////////////////////////////////////////////////////////
2503 static set<const SMDS_MeshElement*> * intersectionOfSets(
2504 set<const SMDS_MeshElement*> vs[], int numberOfSets)
2506 set<const SMDS_MeshElement*>* rsetA=new set<const SMDS_MeshElement*>(vs[0]);
2507 set<const SMDS_MeshElement*>* rsetB;
2509 for(int i=0; i<numberOfSets-1; i++)
2511 rsetB=new set<const SMDS_MeshElement*>();
2513 rsetA->begin(), rsetA->end(),
2514 vs[i+1].begin(), vs[i+1].end(),
2515 inserter(*rsetB, rsetB->begin()));
2522 ///////////////////////////////////////////////////////////////////////////////
2523 /// Return the list of finite elements owning the given element: elements
2524 /// containing all the nodes of the given element, for instance faces and
2525 /// volumes containing a given edge.
2526 ///////////////////////////////////////////////////////////////////////////////
2527 static set<const SMDS_MeshElement*> * getFinitElements(const SMDS_MeshElement * element)
2529 int numberOfSets=element->NbNodes();
2530 set<const SMDS_MeshElement*> *initSet = new set<const SMDS_MeshElement*>[numberOfSets];
2532 SMDS_ElemIteratorPtr itNodes=element->nodesIterator();
2535 while(itNodes->more())
2537 const SMDS_MeshElement* node = itNodes->next();
2539 const SMDS_MeshNode * n=static_cast<const SMDS_MeshNode*>(node);
2540 SMDS_ElemIteratorPtr itFe = n->GetInverseElementIterator();
2542 //initSet[i]=set<const SMDS_MeshElement*>();
2545 const SMDS_MeshElement* elem = itFe->next();
2547 initSet[i].insert(elem);
2553 set<const SMDS_MeshElement*> *retSet=intersectionOfSets(initSet, numberOfSets);
2554 MESSAGE("nb elems " << i << " intersection " << retSet->size());
2559 ///////////////////////////////////////////////////////////////////////////////
2560 /// Return the list of nodes used only by the given elements
2561 ///////////////////////////////////////////////////////////////////////////////
2562 static set<const SMDS_MeshElement*> * getExclusiveNodes(
2563 set<const SMDS_MeshElement*>& elements)
2565 set<const SMDS_MeshElement*> * toReturn=new set<const SMDS_MeshElement*>();
2566 set<const SMDS_MeshElement*>::iterator itElements=elements.begin();
2568 while(itElements!=elements.end())
2570 SMDS_ElemIteratorPtr itNodes = (*itElements)->nodesIterator();
2573 while(itNodes->more())
2575 const SMDS_MeshNode * n=static_cast<const SMDS_MeshNode*>(itNodes->next());
2576 SMDS_ElemIteratorPtr itFe = n->GetInverseElementIterator();
2577 set<const SMDS_MeshElement*> s;
2579 s.insert(itFe->next());
2580 if(s==elements) toReturn->insert(n);
2586 ///////////////////////////////////////////////////////////////////////////////
2587 ///Find the children of an element that are made of given nodes
2588 ///@param setOfChildren The set in which matching children will be inserted
2589 ///@param element The element were to search matching children
2590 ///@param nodes The nodes that the children must have to be selected
2591 ///////////////////////////////////////////////////////////////////////////////
2592 void SMDS_Mesh::addChildrenWithNodes(set<const SMDS_MeshElement*>& setOfChildren,
2593 const SMDS_MeshElement * element,
2594 set<const SMDS_MeshElement*>& nodes)
2596 switch(element->GetType())
2599 MESSAGE("Internal Error: This should not happend");
2601 case SMDSAbs_0DElement:
2607 SMDS_ElemIteratorPtr itn=element->nodesIterator();
2610 const SMDS_MeshElement * e=itn->next();
2611 if(nodes.find(e)!=nodes.end())
2613 setOfChildren.insert(element);
2620 SMDS_ElemIteratorPtr itn=element->nodesIterator();
2623 const SMDS_MeshElement * e=itn->next();
2624 if(nodes.find(e)!=nodes.end())
2626 setOfChildren.insert(element);
2630 if(hasConstructionEdges())
2632 SMDS_ElemIteratorPtr ite=element->edgesIterator();
2634 addChildrenWithNodes(setOfChildren, ite->next(), nodes);
2637 case SMDSAbs_Volume:
2639 if(hasConstructionFaces())
2641 SMDS_ElemIteratorPtr ite=element->facesIterator();
2643 addChildrenWithNodes(setOfChildren, ite->next(), nodes);
2645 else if(hasConstructionEdges())
2647 SMDS_ElemIteratorPtr ite=element->edgesIterator();
2649 addChildrenWithNodes(setOfChildren, ite->next(), nodes);
2655 ///////////////////////////////////////////////////////////////////////////////
2656 ///@param elem The element to delete
2657 ///@param removenodes if true remaining nodes will be removed
2658 ///////////////////////////////////////////////////////////////////////////////
2659 void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem,
2660 const bool removenodes)
2662 list<const SMDS_MeshElement *> removedElems;
2663 list<const SMDS_MeshElement *> removedNodes;
2664 RemoveElement( elem, removedElems, removedNodes, removenodes );
2667 ///////////////////////////////////////////////////////////////////////////////
2668 ///@param elem The element to delete
2669 ///@param removedElems to be filled with all removed elements
2670 ///@param removedNodes to be filled with all removed nodes
2671 ///@param removenodes if true remaining nodes will be removed
2672 ///////////////////////////////////////////////////////////////////////////////
2673 void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem,
2674 list<const SMDS_MeshElement *>& removedElems,
2675 list<const SMDS_MeshElement *>& removedNodes,
2678 MESSAGE("SMDS_Mesh::RemoveElement " << elem->GetID() << " " << removenodes);
2679 // get finite elements built on elem
2680 set<const SMDS_MeshElement*> * s1;
2681 if (elem->GetType() == SMDSAbs_0DElement ||
2682 elem->GetType() == SMDSAbs_Edge && !hasConstructionEdges() ||
2683 elem->GetType() == SMDSAbs_Face && !hasConstructionFaces() ||
2684 elem->GetType() == SMDSAbs_Volume)
2686 s1 = new set<const SMDS_MeshElement*>();
2690 s1 = getFinitElements(elem);
2692 // get exclusive nodes (which would become free afterwards)
2693 set<const SMDS_MeshElement*> * s2;
2694 if (elem->GetType() == SMDSAbs_Node) // a node is removed
2696 // do not remove nodes except elem
2697 s2 = new set<const SMDS_MeshElement*>();
2702 s2 = getExclusiveNodes(*s1);
2704 // form the set of finite and construction elements to remove
2705 set<const SMDS_MeshElement*> s3;
2706 set<const SMDS_MeshElement*>::iterator it=s1->begin();
2707 while(it!=s1->end())
2709 addChildrenWithNodes(s3, *it ,*s2);
2713 if(elem->GetType()!=SMDSAbs_Node) s3.insert(elem);
2715 // remove finite and construction elements
2719 // Remove element from <InverseElements> of its nodes
2720 SMDS_ElemIteratorPtr itn=(*it)->nodesIterator();
2723 SMDS_MeshNode * n = static_cast<SMDS_MeshNode *>
2724 (const_cast<SMDS_MeshElement *>(itn->next()));
2725 n->RemoveInverseElement( (*it) );
2728 switch((*it)->GetType())
2731 MYASSERT("Internal Error: This should not happen");
2733 case SMDSAbs_0DElement:
2734 myCells[(*it)->GetID()] = 0; // -PR- ici ou dans myElementIDFactory->ReleaseID ?
2738 myCells[(*it)->GetID()] = 0;
2739 myInfo.RemoveEdge(*it);
2742 myCells[(*it)->GetID()] = 0;
2743 myInfo.RemoveFace(*it);
2745 case SMDSAbs_Volume:
2746 myCells[(*it)->GetID()] = 0;
2747 myInfo.RemoveVolume(*it);
2750 //MESSAGE( "SMDS: RM elem " << (*it)->GetID() );
2751 removedElems.push_back( (*it) );
2752 myElementIDFactory->ReleaseID((*it)->GetID());
2753 MYASSERT("problem delete elem")
2758 // remove exclusive (free) nodes
2762 while(it!=s2->end())
2764 //MESSAGE( "SMDS: RM node " << (*it)->GetID() );
2765 myNodes[(*it)->GetID()] = 0;
2767 myNodeIDFactory->ReleaseID((*it)->GetID());
2768 removedNodes.push_back( (*it) );
2769 MYASSERT("problem delete node")
2780 ///////////////////////////////////////////////////////////////////////////////
2781 ///@param elem The element to delete
2782 ///////////////////////////////////////////////////////////////////////////////
2783 void SMDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elem)
2785 int elemId = elem->GetID();
2786 //MESSAGE("SMDS_Mesh::RemoveFreeElement " << elemId);
2787 SMDSAbs_ElementType aType = elem->GetType();
2788 SMDS_MeshElement* todest = (SMDS_MeshElement*)(elem);
2789 if (aType == SMDSAbs_Node) {
2790 // only free node can be removed by this method
2791 const SMDS_MeshNode* n = static_cast<SMDS_MeshNode*>(todest);
2792 SMDS_ElemIteratorPtr itFe = n->GetInverseElementIterator();
2793 if (!itFe->more()) { // free node
2794 myNodes[elemId] = 0;
2796 myNodePool->destroy(static_cast<SMDS_MeshNode*>(todest));
2797 myNodeIDFactory->ReleaseID(elemId);
2800 if (hasConstructionEdges() || hasConstructionFaces())
2801 // this methods is only for meshes without descendants
2804 // Remove element from <InverseElements> of its nodes
2805 SMDS_ElemIteratorPtr itn = elem->nodesIterator();
2806 while (itn->more()) {
2807 SMDS_MeshNode * n = static_cast<SMDS_MeshNode *>
2808 (const_cast<SMDS_MeshElement *>(itn->next()));
2809 n->RemoveInverseElement(elem);
2812 // in meshes without descendants elements are always free
2814 case SMDSAbs_0DElement:
2815 myCells[elemId] = 0;
2816 myInfo.remove(elem);
2820 myCells[elemId] = 0;
2821 myInfo.RemoveEdge(elem);
2822 myEdgePool->destroy(static_cast<SMDS_VtkEdge*>(todest));
2825 myCells[elemId] = 0;
2826 myInfo.RemoveFace(elem);
2827 myFacePool->destroy(static_cast<SMDS_VtkFace*>(todest));
2829 case SMDSAbs_Volume:
2830 myCells[elemId] = 0;
2831 myInfo.RemoveVolume(elem);
2832 myVolumePool->destroy(static_cast<SMDS_VtkVolume*>(todest));
2837 myElementIDFactory->ReleaseID(elemId);
2842 * Checks if the element is present in mesh.
2843 * Useful to determine dead pointers.
2845 bool SMDS_Mesh::Contains (const SMDS_MeshElement* elem) const
2847 // we should not imply on validity of *elem, so iterate on containers
2848 // of all types in the hope of finding <elem> somewhere there
2849 SMDS_NodeIteratorPtr itn = nodesIterator();
2851 if (elem == itn->next())
2853 SMDS_0DElementIteratorPtr it0d = elements0dIterator();
2854 while (it0d->more())
2855 if (elem == it0d->next())
2857 SMDS_EdgeIteratorPtr ite = edgesIterator();
2859 if (elem == ite->next())
2861 SMDS_FaceIteratorPtr itf = facesIterator();
2863 if (elem == itf->next())
2865 SMDS_VolumeIteratorPtr itv = volumesIterator();
2867 if (elem == itv->next())
2872 //=======================================================================
2873 //function : MaxNodeID
2875 //=======================================================================
2877 int SMDS_Mesh::MaxNodeID() const
2882 //=======================================================================
2883 //function : MinNodeID
2885 //=======================================================================
2887 int SMDS_Mesh::MinNodeID() const
2892 //=======================================================================
2893 //function : MaxElementID
2895 //=======================================================================
2897 int SMDS_Mesh::MaxElementID() const
2899 return myElementIDFactory->GetMaxID();
2902 //=======================================================================
2903 //function : MinElementID
2905 //=======================================================================
2907 int SMDS_Mesh::MinElementID() const
2909 return myElementIDFactory->GetMinID();
2912 //=======================================================================
2913 //function : Renumber
2914 //purpose : Renumber all nodes or elements.
2915 //=======================================================================
2917 void SMDS_Mesh::Renumber (const bool isNodes, const int startID, const int deltaID)
2919 MESSAGE("Renumber");
2923 SMDS_MeshNodeIDFactory * idFactory =
2924 isNodes ? myNodeIDFactory : myElementIDFactory;
2926 // get existing elements in the order of ID increasing
2927 map<int,SMDS_MeshElement*> elemMap;
2928 SMDS_ElemIteratorPtr idElemIt = idFactory->elementsIterator();
2929 while ( idElemIt->more() ) {
2930 SMDS_MeshElement* elem = const_cast<SMDS_MeshElement*>(idElemIt->next());
2931 int id = elem->GetID();
2932 elemMap.insert(map<int,SMDS_MeshElement*>::value_type(id, elem));
2934 // release their ids
2935 map<int,SMDS_MeshElement*>::iterator elemIt = elemMap.begin();
2937 // for ( ; elemIt != elemMap.end(); elemIt++ )
2939 // int id = (*elemIt).first;
2940 // idFactory->ReleaseID( id );
2944 elemIt = elemMap.begin();
2945 for ( ; elemIt != elemMap.end(); elemIt++ )
2947 idFactory->BindID( ID, (*elemIt).second );
2952 //=======================================================================
2953 //function : GetElementType
2954 //purpose : Return type of element or node with id
2955 //=======================================================================
2957 SMDSAbs_ElementType SMDS_Mesh::GetElementType( const int id, const bool iselem ) const
2959 SMDS_MeshElement* elem = 0;
2961 elem = myElementIDFactory->MeshElement( id );
2963 elem = myNodeIDFactory->MeshElement( id );
2967 //throw SALOME_Exception(LOCALIZED ("this element isn't exist"));
2971 return elem->GetType();
2976 //********************************************************************
2977 //********************************************************************
2978 //******** *********
2979 //***** Methods for addition of quadratic elements ******
2980 //******** *********
2981 //********************************************************************
2982 //********************************************************************
2984 //=======================================================================
2985 //function : AddEdgeWithID
2987 //=======================================================================
2988 SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(int n1, int n2, int n12, int ID)
2990 return SMDS_Mesh::AddEdgeWithID
2991 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1),
2992 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2),
2993 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
2997 //=======================================================================
2998 //function : AddEdge
3000 //=======================================================================
3001 SMDS_MeshEdge* SMDS_Mesh::AddEdge(const SMDS_MeshNode* n1,
3002 const SMDS_MeshNode* n2,
3003 const SMDS_MeshNode* n12)
3005 return SMDS_Mesh::AddEdgeWithID(n1, n2, n12, myElementIDFactory->GetFreeID());
3008 //=======================================================================
3009 //function : AddEdgeWithID
3011 //=======================================================================
3012 SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
3013 const SMDS_MeshNode * n2,
3014 const SMDS_MeshNode * n12,
3017 if ( !n1 || !n2 || !n12 ) return 0;
3018 SMDS_QuadraticEdge* edge = new SMDS_QuadraticEdge(n1,n2,n12);
3019 if(myElementIDFactory->BindID(ID, edge)) {
3020 SMDS_MeshNode *node1,*node2, *node12;
3021 //node1 = const_cast<SMDS_MeshNode*>(n1);
3022 //node2 = const_cast<SMDS_MeshNode*>(n2);
3023 //node12 = const_cast<SMDS_MeshNode*>(n12);
3024 //node1->AddInverseElement(edge); // --- fait avec BindID
3025 //node2->AddInverseElement(edge);
3026 //node12->AddInverseElement(edge);
3027 adjustmyCellsCapacity(ID);
3029 myInfo.myNbQuadEdges++;
3039 //=======================================================================
3040 //function : AddFace
3042 //=======================================================================
3043 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
3044 const SMDS_MeshNode * n2,
3045 const SMDS_MeshNode * n3,
3046 const SMDS_MeshNode * n12,
3047 const SMDS_MeshNode * n23,
3048 const SMDS_MeshNode * n31)
3050 return SMDS_Mesh::AddFaceWithID(n1,n2,n3,n12,n23,n31,
3051 myElementIDFactory->GetFreeID());
3054 //=======================================================================
3055 //function : AddFaceWithID
3057 //=======================================================================
3058 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int n1, int n2, int n3,
3059 int n12,int n23,int n31, int ID)
3061 return SMDS_Mesh::AddFaceWithID
3062 ((SMDS_MeshNode *)myNodeIDFactory->MeshElement(n1) ,
3063 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n2) ,
3064 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n3) ,
3065 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n12),
3066 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n23),
3067 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n31),
3071 //=======================================================================
3072 //function : AddFaceWithID
3074 //=======================================================================
3075 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
3076 const SMDS_MeshNode * n2,
3077 const SMDS_MeshNode * n3,
3078 const SMDS_MeshNode * n12,
3079 const SMDS_MeshNode * n23,
3080 const SMDS_MeshNode * n31,
3083 if ( !n1 || !n2 || !n3 || !n12 || !n23 || !n31) return 0;
3084 if(hasConstructionEdges()) {
3085 // creation quadratic edges - not implemented
3088 SMDS_QuadraticFaceOfNodes* face =
3089 new SMDS_QuadraticFaceOfNodes(n1,n2,n3,n12,n23,n31);
3090 adjustmyCellsCapacity(ID);
3092 myInfo.myNbQuadTriangles++;
3094 if (!registerElement(ID, face)) {
3095 RemoveElement(face, false);
3102 //=======================================================================
3103 //function : AddFace
3105 //=======================================================================
3106 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
3107 const SMDS_MeshNode * n2,
3108 const SMDS_MeshNode * n3,
3109 const SMDS_MeshNode * n4,
3110 const SMDS_MeshNode * n12,
3111 const SMDS_MeshNode * n23,
3112 const SMDS_MeshNode * n34,
3113 const SMDS_MeshNode * n41)
3115 return SMDS_Mesh::AddFaceWithID(n1,n2,n3,n4,n12,n23,n34,n41,
3116 myElementIDFactory->GetFreeID());
3119 //=======================================================================
3120 //function : AddFaceWithID
3122 //=======================================================================
3123 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int n4,
3124 int n12,int n23,int n34,int n41, int ID)
3126 return SMDS_Mesh::AddFaceWithID
3127 ((SMDS_MeshNode *)myNodeIDFactory->MeshElement(n1) ,
3128 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n2) ,
3129 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n3) ,
3130 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n4) ,
3131 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n12),
3132 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n23),
3133 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n34),
3134 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n41),
3138 //=======================================================================
3139 //function : AddFaceWithID
3141 //=======================================================================
3142 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
3143 const SMDS_MeshNode * n2,
3144 const SMDS_MeshNode * n3,
3145 const SMDS_MeshNode * n4,
3146 const SMDS_MeshNode * n12,
3147 const SMDS_MeshNode * n23,
3148 const SMDS_MeshNode * n34,
3149 const SMDS_MeshNode * n41,
3152 if ( !n1 || !n2 || !n3 || !n4 || !n12 || !n23 || !n34 || !n41) return 0;
3153 if(hasConstructionEdges()) {
3154 // creation quadratic edges - not implemented
3156 SMDS_QuadraticFaceOfNodes* face =
3157 new SMDS_QuadraticFaceOfNodes(n1,n2,n3,n4,n12,n23,n34,n41);
3158 adjustmyCellsCapacity(ID);
3160 myInfo.myNbQuadQuadrangles++;
3162 if (!registerElement(ID, face)) {
3163 RemoveElement(face, false);
3170 //=======================================================================
3171 //function : AddVolume
3173 //=======================================================================
3174 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
3175 const SMDS_MeshNode * n2,
3176 const SMDS_MeshNode * n3,
3177 const SMDS_MeshNode * n4,
3178 const SMDS_MeshNode * n12,
3179 const SMDS_MeshNode * n23,
3180 const SMDS_MeshNode * n31,
3181 const SMDS_MeshNode * n14,
3182 const SMDS_MeshNode * n24,
3183 const SMDS_MeshNode * n34)
3185 int ID = myElementIDFactory->GetFreeID();
3186 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n12, n23,
3187 n31, n14, n24, n34, ID);
3188 if(v==NULL) myElementIDFactory->ReleaseID(ID);
3192 //=======================================================================
3193 //function : AddVolumeWithID
3195 //=======================================================================
3196 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4,
3197 int n12,int n23,int n31,
3198 int n14,int n24,int n34, int ID)
3200 return SMDS_Mesh::AddVolumeWithID
3201 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1) ,
3202 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2) ,
3203 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3) ,
3204 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4) ,
3205 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
3206 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
3207 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n31),
3208 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n14),
3209 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n24),
3210 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n34),
3214 //=======================================================================
3215 //function : AddVolumeWithID
3216 //purpose : 2d order tetrahedron of 10 nodes
3217 //=======================================================================
3218 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
3219 const SMDS_MeshNode * n2,
3220 const SMDS_MeshNode * n3,
3221 const SMDS_MeshNode * n4,
3222 const SMDS_MeshNode * n12,
3223 const SMDS_MeshNode * n23,
3224 const SMDS_MeshNode * n31,
3225 const SMDS_MeshNode * n14,
3226 const SMDS_MeshNode * n24,
3227 const SMDS_MeshNode * n34,
3230 if ( !n1 || !n2 || !n3 || !n4 || !n12 || !n23 || !n31 || !n14 || !n24 || !n34)
3232 if(hasConstructionFaces()) {
3233 // creation quadratic faces - not implemented
3236 SMDS_QuadraticVolumeOfNodes * volume =
3237 new SMDS_QuadraticVolumeOfNodes(n1,n2,n3,n4,n12,n23,n31,n14,n24,n34);
3238 adjustmyCellsCapacity(ID);
3239 myCells[ID] = volume;
3240 myInfo.myNbQuadTetras++;
3242 if (!registerElement(ID, volume)) {
3243 RemoveElement(volume, false);
3250 //=======================================================================
3251 //function : AddVolume
3253 //=======================================================================
3254 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
3255 const SMDS_MeshNode * n2,
3256 const SMDS_MeshNode * n3,
3257 const SMDS_MeshNode * n4,
3258 const SMDS_MeshNode * n5,
3259 const SMDS_MeshNode * n12,
3260 const SMDS_MeshNode * n23,
3261 const SMDS_MeshNode * n34,
3262 const SMDS_MeshNode * n41,
3263 const SMDS_MeshNode * n15,
3264 const SMDS_MeshNode * n25,
3265 const SMDS_MeshNode * n35,
3266 const SMDS_MeshNode * n45)
3268 int ID = myElementIDFactory->GetFreeID();
3269 SMDS_MeshVolume * v =
3270 SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n12, n23, n34, n41,
3271 n15, n25, n35, n45, ID);
3272 if(v==NULL) myElementIDFactory->ReleaseID(ID);
3276 //=======================================================================
3277 //function : AddVolumeWithID
3279 //=======================================================================
3280 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5,
3281 int n12,int n23,int n34,int n41,
3282 int n15,int n25,int n35,int n45, int ID)
3284 return SMDS_Mesh::AddVolumeWithID
3285 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1) ,
3286 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2) ,
3287 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3) ,
3288 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4) ,
3289 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5) ,
3290 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
3291 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
3292 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n34),
3293 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n41),
3294 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n15),
3295 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n25),
3296 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n35),
3297 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n45),
3301 //=======================================================================
3302 //function : AddVolumeWithID
3303 //purpose : 2d order pyramid of 13 nodes
3304 //=======================================================================
3305 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
3306 const SMDS_MeshNode * n2,
3307 const SMDS_MeshNode * n3,
3308 const SMDS_MeshNode * n4,
3309 const SMDS_MeshNode * n5,
3310 const SMDS_MeshNode * n12,
3311 const SMDS_MeshNode * n23,
3312 const SMDS_MeshNode * n34,
3313 const SMDS_MeshNode * n41,
3314 const SMDS_MeshNode * n15,
3315 const SMDS_MeshNode * n25,
3316 const SMDS_MeshNode * n35,
3317 const SMDS_MeshNode * n45,
3320 if (!n1 || !n2 || !n3 || !n4 || !n5 || !n12 || !n23 ||
3321 !n34 || !n41 || !n15 || !n25 || !n35 || !n45)
3323 if(hasConstructionFaces()) {
3324 // creation quadratic faces - not implemented
3327 SMDS_QuadraticVolumeOfNodes * volume =
3328 new SMDS_QuadraticVolumeOfNodes(n1,n2,n3,n4,n5,n12,n23,
3329 n34,n41,n15,n25,n35,n45);
3330 adjustmyCellsCapacity(ID);
3331 myCells[ID] = volume;
3332 myInfo.myNbQuadPyramids++;
3334 if (!registerElement(ID, volume)) {
3335 RemoveElement(volume, false);
3342 //=======================================================================
3343 //function : AddVolume
3345 //=======================================================================
3346 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
3347 const SMDS_MeshNode * n2,
3348 const SMDS_MeshNode * n3,
3349 const SMDS_MeshNode * n4,
3350 const SMDS_MeshNode * n5,
3351 const SMDS_MeshNode * n6,
3352 const SMDS_MeshNode * n12,
3353 const SMDS_MeshNode * n23,
3354 const SMDS_MeshNode * n31,
3355 const SMDS_MeshNode * n45,
3356 const SMDS_MeshNode * n56,
3357 const SMDS_MeshNode * n64,
3358 const SMDS_MeshNode * n14,
3359 const SMDS_MeshNode * n25,
3360 const SMDS_MeshNode * n36)
3362 int ID = myElementIDFactory->GetFreeID();
3363 SMDS_MeshVolume * v =
3364 SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n12, n23, n31,
3365 n45, n56, n64, n14, n25, n36, ID);
3366 if(v==NULL) myElementIDFactory->ReleaseID(ID);
3370 //=======================================================================
3371 //function : AddVolumeWithID
3373 //=======================================================================
3374 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3,
3375 int n4, int n5, int n6,
3376 int n12,int n23,int n31,
3377 int n45,int n56,int n64,
3378 int n14,int n25,int n36, int ID)
3380 return SMDS_Mesh::AddVolumeWithID
3381 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1) ,
3382 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2) ,
3383 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3) ,
3384 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4) ,
3385 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5) ,
3386 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n6) ,
3387 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
3388 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
3389 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n31),
3390 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n45),
3391 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n56),
3392 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n64),
3393 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n14),
3394 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n25),
3395 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n36),
3399 //=======================================================================
3400 //function : AddVolumeWithID
3401 //purpose : 2d order Pentahedron with 15 nodes
3402 //=======================================================================
3403 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
3404 const SMDS_MeshNode * n2,
3405 const SMDS_MeshNode * n3,
3406 const SMDS_MeshNode * n4,
3407 const SMDS_MeshNode * n5,
3408 const SMDS_MeshNode * n6,
3409 const SMDS_MeshNode * n12,
3410 const SMDS_MeshNode * n23,
3411 const SMDS_MeshNode * n31,
3412 const SMDS_MeshNode * n45,
3413 const SMDS_MeshNode * n56,
3414 const SMDS_MeshNode * n64,
3415 const SMDS_MeshNode * n14,
3416 const SMDS_MeshNode * n25,
3417 const SMDS_MeshNode * n36,
3420 if (!n1 || !n2 || !n3 || !n4 || !n5 || !n6 || !n12 || !n23 ||
3421 !n31 || !n45 || !n56 || !n64 || !n14 || !n25 || !n36)
3423 if(hasConstructionFaces()) {
3424 // creation quadratic faces - not implemented
3427 SMDS_QuadraticVolumeOfNodes * volume =
3428 new SMDS_QuadraticVolumeOfNodes(n1,n2,n3,n4,n5,n6,n12,n23,n31,
3429 n45,n56,n64,n14,n25,n36);
3430 adjustmyCellsCapacity(ID);
3431 myCells[ID] = volume;
3432 myInfo.myNbQuadPrisms++;
3434 if (!registerElement(ID, volume)) {
3435 RemoveElement(volume, false);
3442 //=======================================================================
3443 //function : AddVolume
3445 //=======================================================================
3446 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
3447 const SMDS_MeshNode * n2,
3448 const SMDS_MeshNode * n3,
3449 const SMDS_MeshNode * n4,
3450 const SMDS_MeshNode * n5,
3451 const SMDS_MeshNode * n6,
3452 const SMDS_MeshNode * n7,
3453 const SMDS_MeshNode * n8,
3454 const SMDS_MeshNode * n12,
3455 const SMDS_MeshNode * n23,
3456 const SMDS_MeshNode * n34,
3457 const SMDS_MeshNode * n41,
3458 const SMDS_MeshNode * n56,
3459 const SMDS_MeshNode * n67,
3460 const SMDS_MeshNode * n78,
3461 const SMDS_MeshNode * n85,
3462 const SMDS_MeshNode * n15,
3463 const SMDS_MeshNode * n26,
3464 const SMDS_MeshNode * n37,
3465 const SMDS_MeshNode * n48)
3467 int ID = myElementIDFactory->GetFreeID();
3468 SMDS_MeshVolume * v =
3469 SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, n12, n23, n34, n41,
3470 n56, n67, n78, n85, n15, n26, n37, n48, ID);
3471 if(v==NULL) myElementIDFactory->ReleaseID(ID);
3475 //=======================================================================
3476 //function : AddVolumeWithID
3478 //=======================================================================
3479 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4,
3480 int n5, int n6, int n7, int n8,
3481 int n12,int n23,int n34,int n41,
3482 int n56,int n67,int n78,int n85,
3483 int n15,int n26,int n37,int n48, int ID)
3485 return SMDS_Mesh::AddVolumeWithID
3486 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1),
3487 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2),
3488 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3),
3489 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4),
3490 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5),
3491 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n6),
3492 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n7),
3493 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n8),
3494 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
3495 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
3496 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n34),
3497 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n41),
3498 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n56),
3499 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n67),
3500 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n78),
3501 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n85),
3502 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n15),
3503 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n26),
3504 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n37),
3505 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n48),
3509 //=======================================================================
3510 //function : AddVolumeWithID
3511 //purpose : 2d order Hexahedrons with 20 nodes
3512 //=======================================================================
3513 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
3514 const SMDS_MeshNode * n2,
3515 const SMDS_MeshNode * n3,
3516 const SMDS_MeshNode * n4,
3517 const SMDS_MeshNode * n5,
3518 const SMDS_MeshNode * n6,
3519 const SMDS_MeshNode * n7,
3520 const SMDS_MeshNode * n8,
3521 const SMDS_MeshNode * n12,
3522 const SMDS_MeshNode * n23,
3523 const SMDS_MeshNode * n34,
3524 const SMDS_MeshNode * n41,
3525 const SMDS_MeshNode * n56,
3526 const SMDS_MeshNode * n67,
3527 const SMDS_MeshNode * n78,
3528 const SMDS_MeshNode * n85,
3529 const SMDS_MeshNode * n15,
3530 const SMDS_MeshNode * n26,
3531 const SMDS_MeshNode * n37,
3532 const SMDS_MeshNode * n48,
3535 if (!n1 || !n2 || !n3 || !n4 || !n5 || !n6 || !n7 || !n8 || !n12 || !n23 ||
3536 !n34 || !n41 || !n56 || !n67 || !n78 || !n85 || !n15 || !n26 || !n37 || !n48)
3538 if(hasConstructionFaces()) {
3540 // creation quadratic faces - not implemented
3542 SMDS_QuadraticVolumeOfNodes * volume =
3543 new SMDS_QuadraticVolumeOfNodes(n1,n2,n3,n4,n5,n6,n7,n8,n12,n23,n34,n41,
3544 n56,n67,n78,n85,n15,n26,n37,n48);
3545 adjustmyCellsCapacity(ID);
3546 myCells[ID] = volume;
3547 myInfo.myNbQuadHexas++;
3549 if (!registerElement(ID, volume)) {
3550 RemoveElement(volume, false);
3556 void SMDS_Mesh::updateNodeMinMax()
3559 while (!myNodes[myNodeMin] && (myNodeMin<myNodes.size()))
3561 myNodeMax=myNodes.size()-1;
3562 while (!myNodes[myNodeMax] && (myNodeMin>=0))
3566 void SMDS_Mesh::incrementNodesCapacity(int nbNodes)
3568 int val = myIDElements.size();
3569 MESSAGE(" ------------------- resize myIDElements " << val << " --> " << val + nbNodes);
3570 myIDElements.resize(val + nbNodes, -1); // fill new elements with -1
3571 val = myNodes.size();
3572 MESSAGE(" ------------------- resize myNodes " << val << " --> " << val + nbNodes);
3573 myNodes.resize(val +nbNodes, 0);
3576 void SMDS_Mesh::incrementCellsCapacity(int nbCells)
3578 int val = myVtkIndex.size();
3579 MESSAGE(" ------------------- resize myVtkIndex " << val << " --> " << val + nbCells);
3580 myVtkIndex.resize(val + nbCells, -1); // fill new elements with -1
3581 val = myCells.size();
3582 MESSAGE(" ------------------- resize myCells " << val << " --> " << val + nbCells);
3583 myNodes.resize(val +nbCells, 0);