1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMDS : implementation of Salome mesh data structure
26 #pragma warning(disable:4786)
29 #include "SMDS_FaceOfEdges.hxx"
30 #include "SMDS_FaceOfNodes.hxx"
31 #include "SMDS_Mesh.hxx"
32 #include "SMDS_PolygonalFaceOfNodes.hxx"
33 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
34 #include "SMDS_QuadraticEdge.hxx"
35 #include "SMDS_QuadraticFaceOfNodes.hxx"
36 #include "SMDS_QuadraticVolumeOfNodes.hxx"
37 #include "SMDS_SetIterator.hxx"
38 #include "SMDS_SpacePosition.hxx"
39 #include "SMDS_UnstructuredGrid.hxx"
40 #include "SMDS_VolumeOfFaces.hxx"
41 #include "SMDS_VolumeOfNodes.hxx"
43 #include "utilities.h"
45 #include <vtkUnstructuredGrid.h>
46 #include <vtkUnstructuredGridWriter.h>
47 #include <vtkUnsignedCharArray.h>
49 #include <vtkCellLinks.h>
50 #include <vtkIdList.h>
60 #include <sys/sysinfo.h>
63 // number of added entities to check memory after
64 #define CHECKMEMORY_INTERVAL 100000
66 vector<SMDS_Mesh*> SMDS_Mesh::_meshList = vector<SMDS_Mesh*>();
67 int SMDS_Mesh::chunkSize = 1024;
70 //================================================================================
72 * \brief Raise an exception if free memory (ram+swap) too low
73 * \param doNotRaise - if true, suppres exception, just return free memory size
74 * \retval int - amount of available memory in MB or negative number in failure case
76 //================================================================================
78 int SMDS_Mesh::CheckMemory(const bool doNotRaise) throw (std::bad_alloc)
82 int err = sysinfo( &si );
86 const unsigned long Mbyte = 1024 * 1024;
88 static int limit = -1;
90 int status = system("SMDS_MemoryLimit"); // it returns lower limit of free RAM
92 limit = WEXITSTATUS(status);
95 double factor = ( si.totalswap == 0 ) ? 0.1 : 0.2;
96 limit = int(( factor * si.totalram * si.mem_unit ) / Mbyte );
101 limit = int ( limit * 1.5 );
102 MESSAGE ( "SMDS_Mesh::CheckMemory() memory limit = " << limit << " MB" );
105 // compute separately to avoid overflow
107 ( si.freeram * si.mem_unit ) / Mbyte +
108 ( si.freeswap * si.mem_unit ) / Mbyte;
109 //cout << "freeMb = " << freeMb << " limit = " << limit << endl;
111 if ( freeMb > limit )
112 return freeMb - limit;
117 MESSAGE ("SMDS_Mesh::CheckMemory() throws as free memory too low: " << freeMb <<" MB" );
118 throw std::bad_alloc();
124 ///////////////////////////////////////////////////////////////////////////////
125 /// Create a new mesh object
126 ///////////////////////////////////////////////////////////////////////////////
127 SMDS_Mesh::SMDS_Mesh():
128 myNodePool(0), myVolumePool(0), myFacePool(0), myEdgePool(0), myBallPool(0),
130 myNodeIDFactory(new SMDS_MeshNodeIDFactory()),
131 myElementIDFactory(new SMDS_MeshElementIDFactory()),
132 myModified(false), myModifTime(0), myCompactTime(0),
133 myHasConstructionEdges(false), myHasConstructionFaces(false),
134 myHasInverseElements(true),
135 xmin(0), xmax(0), ymin(0), ymax(0), zmin(0), zmax(0)
137 myMeshId = _meshList.size(); // --- index of the mesh to push back in the vector
138 myNodeIDFactory->SetMesh(this);
139 myElementIDFactory->SetMesh(this);
140 _meshList.push_back(this);
141 myNodePool = new ObjectPool<SMDS_MeshNode>(SMDS_Mesh::chunkSize);
142 myEdgePool = new ObjectPool<SMDS_VtkEdge>(SMDS_Mesh::chunkSize);
143 myFacePool = new ObjectPool<SMDS_VtkFace>(SMDS_Mesh::chunkSize);
144 myVolumePool = new ObjectPool<SMDS_VtkVolume>(SMDS_Mesh::chunkSize);
145 myBallPool = new ObjectPool<SMDS_BallElement>(SMDS_Mesh::chunkSize);
149 //myCellIdSmdsToVtk.clear();
150 myCellIdVtkToSmds.clear();
151 myGrid = SMDS_UnstructuredGrid::New();
152 myGrid->setSMDS_mesh(this);
153 myGrid->Initialize();
155 vtkPoints* points = vtkPoints::New();
156 // bug "21125: EDF 1233 SMESH: Degrardation of precision in a test case for quadratic conversion"
157 // Use double type for storing coordinates of nodes instead of float.
158 points->SetDataType(VTK_DOUBLE);
159 points->SetNumberOfPoints(0 /*SMDS_Mesh::chunkSize*/);
160 myGrid->SetPoints( points );
162 //myGrid->BuildLinks();
165 // initialize static maps in SMDS_MeshCell, to be thread-safe
168 SMDS_MeshCell::toVtkType( SMDSEntity_Node );
169 SMDS_MeshCell::toVtkOrder( SMDSEntity_Node );
170 SMDS_MeshCell::reverseSmdsOrder( SMDSEntity_Node );
171 SMDS_MeshCell::interlacedSmdsOrder( SMDSEntity_Node );
172 SMDS_MeshCell::toSmdsType( VTK_VERTEX );
173 SMDS_MeshCell::fromVtkOrder( SMDSEntity_Node );
177 ///////////////////////////////////////////////////////////////////////////////
178 /// Create a new child mesh
179 /// Note that the tree structure of SMDS_Mesh seems to be unused in this version
180 /// (2003-09-08) of SMESH
181 ///////////////////////////////////////////////////////////////////////////////
182 SMDS_Mesh::SMDS_Mesh(SMDS_Mesh * parent):
183 myNodePool(parent->myNodePool),
184 myVolumePool(parent->myVolumePool),
185 myFacePool(parent->myFacePool),
186 myEdgePool(parent->myEdgePool),
187 myBallPool(parent->myBallPool),
188 myParent(parent), myNodeIDFactory(parent->myNodeIDFactory),
189 myElementIDFactory(parent->myElementIDFactory),
190 myHasConstructionEdges(false), myHasConstructionFaces(false),
191 myHasInverseElements(true)
195 ///////////////////////////////////////////////////////////////////////////////
196 ///Create a submesh and add it to the current mesh
197 ///////////////////////////////////////////////////////////////////////////////
199 SMDS_Mesh *SMDS_Mesh::AddSubMesh()
201 SMDS_Mesh *submesh = new SMDS_Mesh(this);
202 myChildren.insert(myChildren.end(), submesh);
206 ///////////////////////////////////////////////////////////////////////////////
207 ///create a MeshNode and add it to the current Mesh
208 ///An ID is automatically assigned to the node.
209 ///@return : The created node
210 ///////////////////////////////////////////////////////////////////////////////
212 SMDS_MeshNode * SMDS_Mesh::AddNode(double x, double y, double z)
214 return SMDS_Mesh::AddNodeWithID(x,y,z,myNodeIDFactory->GetFreeID());
217 ///////////////////////////////////////////////////////////////////////////////
218 ///create a MeshNode and add it to the current Mesh
219 ///@param ID : The ID of the MeshNode to create
220 ///@return : The created node or NULL if a node with this ID already exists
221 ///////////////////////////////////////////////////////////////////////////////
222 SMDS_MeshNode * SMDS_Mesh::AddNodeWithID(double x, double y, double z, int ID)
224 // find the MeshNode corresponding to ID
225 const SMDS_MeshElement *node = myNodeIDFactory->MeshElement(ID);
229 MESSAGE("=============> Bad Node Id: " << ID);
230 ID = myNodeIDFactory->GetFreeID();
232 myNodeIDFactory->adjustMaxId(ID);
233 SMDS_MeshNode * node = myNodePool->getNew();
234 node->init(ID, myMeshId, 0, x, y, z);
236 if (ID >= (int)myNodes.size())
238 myNodes.resize(ID+SMDS_Mesh::chunkSize, 0);
239 // MESSAGE(" ------------------ myNodes resize " << ID << " --> " << ID+SMDS_Mesh::chunkSize);
242 myNodeIDFactory->BindID(ID,node);
245 this->adjustBoundingBox(x, y, z);
251 ///////////////////////////////////////////////////////////////////////////////
252 /// create a Mesh0DElement and add it to the current Mesh
253 /// @return : The created Mesh0DElement
254 ///////////////////////////////////////////////////////////////////////////////
255 SMDS_Mesh0DElement* SMDS_Mesh::Add0DElementWithID(int idnode, int ID)
257 SMDS_MeshNode * node = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode);
258 if (!node) return NULL;
259 return SMDS_Mesh::Add0DElementWithID(node, ID);
262 ///////////////////////////////////////////////////////////////////////////////
263 /// create a Mesh0DElement and add it to the current Mesh
264 /// @return : The created Mesh0DElement
265 ///////////////////////////////////////////////////////////////////////////////
266 SMDS_Mesh0DElement* SMDS_Mesh::Add0DElement(const SMDS_MeshNode * node)
268 return SMDS_Mesh::Add0DElementWithID(node, myElementIDFactory->GetFreeID());
271 ///////////////////////////////////////////////////////////////////////////////
272 /// Create a new Mesh0DElement and at it to the mesh
273 /// @param idnode ID of the node
274 /// @param ID ID of the 0D element to create
275 /// @return The created 0D element or NULL if an element with this
276 /// ID already exists or if input node is not found.
277 ///////////////////////////////////////////////////////////////////////////////
278 SMDS_Mesh0DElement* SMDS_Mesh::Add0DElementWithID(const SMDS_MeshNode * n, int ID)
282 if (Nb0DElements() % CHECKMEMORY_INTERVAL == 0) CheckMemory();
283 //MESSAGE("Add0DElementWithID" << ID)
284 SMDS_Mesh0DElement * el0d = new SMDS_Mesh0DElement(n);
285 if (myElementIDFactory->BindID(ID, el0d)) {
286 //SMDS_MeshNode *node = const_cast<SMDS_MeshNode*>(n);
287 //node->AddInverseElement(el0d);// --- fait avec BindID
288 adjustmyCellsCapacity(ID);
290 myInfo.myNb0DElements++;
298 ///////////////////////////////////////////////////////////////////////////////
299 /// create a Ball and add it to the current Mesh
300 /// @return : The created Ball
301 ///////////////////////////////////////////////////////////////////////////////
302 SMDS_BallElement* SMDS_Mesh::AddBallWithID(int idnode, double diameter, int ID)
304 SMDS_MeshNode * node = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode);
305 if (!node) return NULL;
306 return SMDS_Mesh::AddBallWithID(node, diameter, ID);
309 ///////////////////////////////////////////////////////////////////////////////
310 /// create a Ball and add it to the current Mesh
311 /// @return : The created Ball
312 ///////////////////////////////////////////////////////////////////////////////
313 SMDS_BallElement* SMDS_Mesh::AddBall(const SMDS_MeshNode * node, double diameter)
315 return SMDS_Mesh::AddBallWithID(node, diameter, myElementIDFactory->GetFreeID());
318 ///////////////////////////////////////////////////////////////////////////////
319 /// Create a new Ball and at it to the mesh
320 /// @param idnode ID of the node
321 // @param diameter ball diameter
322 /// @param ID ID of the 0D element to create
323 /// @return The created 0D element or NULL if an element with this
324 /// ID already exists or if input node is not found.
325 ///////////////////////////////////////////////////////////////////////////////
326 SMDS_BallElement* SMDS_Mesh::AddBallWithID(const SMDS_MeshNode * n, double diameter, int ID)
330 if (NbBalls() % CHECKMEMORY_INTERVAL == 0) CheckMemory();
332 SMDS_BallElement *ball = myBallPool->getNew();
333 ball->init(n->getVtkId(), diameter, this);
334 if (!this->registerElement(ID,ball))
336 this->myGrid->GetCellTypesArray()->SetValue(ball->getVtkId(), VTK_EMPTY_CELL);
337 myBallPool->destroy(ball);
340 adjustmyCellsCapacity(ID);
346 ///////////////////////////////////////////////////////////////////////////////
347 /// create a MeshEdge and add it to the current Mesh
348 /// @return : The created MeshEdge
349 ///////////////////////////////////////////////////////////////////////////////
351 SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(int idnode1, int idnode2, int ID)
353 SMDS_MeshNode * node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
354 SMDS_MeshNode * node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
355 if(!node1 || !node2) return NULL;
356 return SMDS_Mesh::AddEdgeWithID(node1, node2, ID);
359 ///////////////////////////////////////////////////////////////////////////////
360 /// create a MeshEdge and add it to the current Mesh
361 /// @return : The created MeshEdge
362 ///////////////////////////////////////////////////////////////////////////////
364 SMDS_MeshEdge* SMDS_Mesh::AddEdge(const SMDS_MeshNode * node1,
365 const SMDS_MeshNode * node2)
367 return SMDS_Mesh::AddEdgeWithID(node1, node2, myElementIDFactory->GetFreeID());
370 ///////////////////////////////////////////////////////////////////////////////
371 /// Create a new edge and at it to the mesh
372 /// @param idnode1 ID of the first node
373 /// @param idnode2 ID of the second node
374 /// @param ID ID of the edge to create
375 /// @return The created edge or NULL if an element with this ID already exists or
376 /// if input nodes are not found.
377 ///////////////////////////////////////////////////////////////////////////////
379 SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
380 const SMDS_MeshNode * n2,
383 if ( !n1 || !n2 ) return 0;
384 SMDS_MeshEdge * edge = 0;
386 // --- retreive nodes ID
387 vector<vtkIdType> nodeIds;
389 nodeIds.push_back(n1->getVtkId());
390 nodeIds.push_back(n2->getVtkId());
392 SMDS_VtkEdge *edgevtk = myEdgePool->getNew();
393 edgevtk->init(nodeIds, this);
394 if (!this->registerElement(ID,edgevtk))
396 this->myGrid->GetCellTypesArray()->SetValue(edgevtk->getVtkId(), VTK_EMPTY_CELL);
397 myEdgePool->destroy(edgevtk);
401 adjustmyCellsCapacity(ID);
405 // if (edge && !registerElement(ID, edge))
407 // RemoveElement(edge, false);
413 ///////////////////////////////////////////////////////////////////////////////
414 /// Add a triangle defined by its nodes. An ID is automatically affected to the
416 ///////////////////////////////////////////////////////////////////////////////
418 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
419 const SMDS_MeshNode * n2,
420 const SMDS_MeshNode * n3)
422 return SMDS_Mesh::AddFaceWithID(n1,n2,n3, myElementIDFactory->GetFreeID());
425 ///////////////////////////////////////////////////////////////////////////////
426 /// Add a triangle defined by its nodes IDs
427 ///////////////////////////////////////////////////////////////////////////////
429 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int idnode1, int idnode2, int idnode3, int ID)
431 SMDS_MeshNode * node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
432 SMDS_MeshNode * node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
433 SMDS_MeshNode * node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
434 if(!node1 || !node2 || !node3) return NULL;
435 return SMDS_Mesh::AddFaceWithID(node1, node2, node3, ID);
438 ///////////////////////////////////////////////////////////////////////////////
439 /// Add a triangle defined by its nodes
440 ///////////////////////////////////////////////////////////////////////////////
442 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
443 const SMDS_MeshNode * n2,
444 const SMDS_MeshNode * n3,
447 //MESSAGE("AddFaceWithID " << ID)
448 SMDS_MeshFace * face=createTriangle(n1, n2, n3, ID);
450 // if (face && !registerElement(ID, face)) {
451 // RemoveElement(face, false);
457 ///////////////////////////////////////////////////////////////////////////////
458 /// Add a quadrangle defined by its nodes. An ID is automatically affected to the
460 ///////////////////////////////////////////////////////////////////////////////
462 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
463 const SMDS_MeshNode * n2,
464 const SMDS_MeshNode * n3,
465 const SMDS_MeshNode * n4)
467 return SMDS_Mesh::AddFaceWithID(n1,n2,n3, n4, myElementIDFactory->GetFreeID());
470 ///////////////////////////////////////////////////////////////////////////////
471 /// Add a quadrangle defined by its nodes IDs
472 ///////////////////////////////////////////////////////////////////////////////
474 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int idnode1,
480 SMDS_MeshNode *node1, *node2, *node3, *node4;
481 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
482 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
483 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
484 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
485 if(!node1 || !node2 || !node3 || !node4) return NULL;
486 return SMDS_Mesh::AddFaceWithID(node1, node2, node3, node4, ID);
489 ///////////////////////////////////////////////////////////////////////////////
490 /// Add a quadrangle defined by its nodes
491 ///////////////////////////////////////////////////////////////////////////////
493 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
494 const SMDS_MeshNode * n2,
495 const SMDS_MeshNode * n3,
496 const SMDS_MeshNode * n4,
499 //MESSAGE("AddFaceWithID " << ID);
500 SMDS_MeshFace * face=createQuadrangle(n1, n2, n3, n4, ID);
502 // if (face && !registerElement(ID, face)) {
503 // RemoveElement(face, false);
509 ///////////////////////////////////////////////////////////////////////////////
510 /// Add a triangle defined by its edges. An ID is automatically assigned to the
512 ///////////////////////////////////////////////////////////////////////////////
514 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshEdge * e1,
515 const SMDS_MeshEdge * e2,
516 const SMDS_MeshEdge * e3)
518 if (!hasConstructionEdges())
520 //MESSAGE("AddFaceWithID");
521 return AddFaceWithID(e1,e2,e3, myElementIDFactory->GetFreeID());
524 ///////////////////////////////////////////////////////////////////////////////
525 /// Add a triangle defined by its edges
526 ///////////////////////////////////////////////////////////////////////////////
528 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshEdge * e1,
529 const SMDS_MeshEdge * e2,
530 const SMDS_MeshEdge * e3,
533 if (!hasConstructionEdges())
535 if ( !e1 || !e2 || !e3 ) return 0;
537 if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
539 SMDS_MeshFace * face = new SMDS_FaceOfEdges(e1,e2,e3);
540 adjustmyCellsCapacity(ID);
542 myInfo.myNbTriangles++;
544 if (!registerElement(ID, face)) {
545 registerElement(myElementIDFactory->GetFreeID(), face);
546 //RemoveElement(face, false);
552 ///////////////////////////////////////////////////////////////////////////////
553 /// Add a quadrangle defined by its edges. An ID is automatically assigned to the
555 ///////////////////////////////////////////////////////////////////////////////
557 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshEdge * e1,
558 const SMDS_MeshEdge * e2,
559 const SMDS_MeshEdge * e3,
560 const SMDS_MeshEdge * e4)
562 if (!hasConstructionEdges())
564 return AddFaceWithID(e1,e2,e3,e4, myElementIDFactory->GetFreeID());
567 ///////////////////////////////////////////////////////////////////////////////
568 /// Add a quadrangle defined by its edges
569 ///////////////////////////////////////////////////////////////////////////////
571 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshEdge * e1,
572 const SMDS_MeshEdge * e2,
573 const SMDS_MeshEdge * e3,
574 const SMDS_MeshEdge * e4,
577 if (!hasConstructionEdges())
579 if ( !e1 || !e2 || !e3 || !e4 ) return 0;
580 if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
581 SMDS_MeshFace * face = new SMDS_FaceOfEdges(e1,e2,e3,e4);
582 adjustmyCellsCapacity(ID);
584 myInfo.myNbQuadrangles++;
586 if (!registerElement(ID, face))
588 registerElement(myElementIDFactory->GetFreeID(), face);
589 //RemoveElement(face, false);
595 ///////////////////////////////////////////////////////////////////////////////
596 ///Create a new tetrahedron and add it to the mesh.
597 ///@return The created tetrahedron
598 ///////////////////////////////////////////////////////////////////////////////
600 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
601 const SMDS_MeshNode * n2,
602 const SMDS_MeshNode * n3,
603 const SMDS_MeshNode * n4)
605 int ID = myElementIDFactory->GetFreeID();
606 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, ID);
607 if(v==NULL) myElementIDFactory->ReleaseID(ID);
611 ///////////////////////////////////////////////////////////////////////////////
612 ///Create a new tetrahedron and add it to the mesh.
613 ///@param ID The ID of the new volume
614 ///@return The created tetrahedron or NULL if an element with this ID already exists
615 ///or if input nodes are not found.
616 ///////////////////////////////////////////////////////////////////////////////
618 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
624 SMDS_MeshNode *node1, *node2, *node3, *node4;
625 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
626 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
627 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
628 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
629 if(!node1 || !node2 || !node3 || !node4) return NULL;
630 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, ID);
633 ///////////////////////////////////////////////////////////////////////////////
634 ///Create a new tetrahedron and add it to the mesh.
635 ///@param ID The ID of the new volume
636 ///@return The created tetrahedron
637 ///////////////////////////////////////////////////////////////////////////////
639 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
640 const SMDS_MeshNode * n2,
641 const SMDS_MeshNode * n3,
642 const SMDS_MeshNode * n4,
645 SMDS_MeshVolume* volume = 0;
646 if ( !n1 || !n2 || !n3 || !n4) return volume;
647 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
648 if(hasConstructionFaces()) {
649 SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3);
650 SMDS_MeshFace * f2=FindFaceOrCreate(n1,n2,n4);
651 SMDS_MeshFace * f3=FindFaceOrCreate(n1,n3,n4);
652 SMDS_MeshFace * f4=FindFaceOrCreate(n2,n3,n4);
653 volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4);
654 adjustmyCellsCapacity(ID);
655 myCells[ID] = volume;
658 else if(hasConstructionEdges()) {
662 // --- retrieve nodes ID
664 myNodeIds[0] = n1->getVtkId();
665 myNodeIds[1] = n3->getVtkId(); // order SMDS-->VTK
666 myNodeIds[2] = n2->getVtkId();
667 myNodeIds[3] = n4->getVtkId();
669 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
670 volvtk->init(myNodeIds, this);
671 if (!this->registerElement(ID,volvtk))
673 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
674 myVolumePool->destroy(volvtk);
678 adjustmyCellsCapacity(ID);
679 myCells[ID] = volume;
683 // if (!registerElement(ID, volume)) {
684 // RemoveElement(volume, false);
690 ///////////////////////////////////////////////////////////////////////////////
691 ///Create a new pyramid and add it to the mesh.
692 ///Nodes 1,2,3 and 4 define the base of the pyramid
693 ///@return The created pyramid
694 ///////////////////////////////////////////////////////////////////////////////
696 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
697 const SMDS_MeshNode * n2,
698 const SMDS_MeshNode * n3,
699 const SMDS_MeshNode * n4,
700 const SMDS_MeshNode * n5)
702 int ID = myElementIDFactory->GetFreeID();
703 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, ID);
704 if(v==NULL) myElementIDFactory->ReleaseID(ID);
708 ///////////////////////////////////////////////////////////////////////////////
709 ///Create a new pyramid and add it to the mesh.
710 ///Nodes 1,2,3 and 4 define the base of the pyramid
711 ///@param ID The ID of the new volume
712 ///@return The created pyramid or NULL if an element with this ID already exists
713 ///or if input nodes are not found.
714 ///////////////////////////////////////////////////////////////////////////////
716 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
723 SMDS_MeshNode *node1, *node2, *node3, *node4, *node5;
724 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
725 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
726 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
727 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
728 node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5);
729 if(!node1 || !node2 || !node3 || !node4 || !node5) return NULL;
730 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, ID);
733 ///////////////////////////////////////////////////////////////////////////////
734 ///Create a new pyramid and add it to the mesh.
735 ///Nodes 1,2,3 and 4 define the base of the pyramid
736 ///@param ID The ID of the new volume
737 ///@return The created pyramid
738 ///////////////////////////////////////////////////////////////////////////////
740 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
741 const SMDS_MeshNode * n2,
742 const SMDS_MeshNode * n3,
743 const SMDS_MeshNode * n4,
744 const SMDS_MeshNode * n5,
747 SMDS_MeshVolume* volume = 0;
748 if ( !n1 || !n2 || !n3 || !n4 || !n5) return volume;
749 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
750 if(hasConstructionFaces()) {
751 SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3,n4);
752 SMDS_MeshFace * f2=FindFaceOrCreate(n1,n2,n5);
753 SMDS_MeshFace * f3=FindFaceOrCreate(n2,n3,n5);
754 SMDS_MeshFace * f4=FindFaceOrCreate(n3,n4,n5);
755 volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4);
756 adjustmyCellsCapacity(ID);
757 myCells[ID] = volume;
758 myInfo.myNbPyramids++;
760 else if(hasConstructionEdges()) {
764 // --- retrieve nodes ID
766 myNodeIds[0] = n1->getVtkId();
767 myNodeIds[1] = n4->getVtkId();
768 myNodeIds[2] = n3->getVtkId();
769 myNodeIds[3] = n2->getVtkId();
770 myNodeIds[4] = n5->getVtkId();
772 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
773 volvtk->init(myNodeIds, this);
774 if (!this->registerElement(ID,volvtk))
776 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
777 myVolumePool->destroy(volvtk);
781 adjustmyCellsCapacity(ID);
782 myCells[ID] = volume;
783 myInfo.myNbPyramids++;
786 // if (!registerElement(ID, volume)) {
787 // RemoveElement(volume, false);
793 ///////////////////////////////////////////////////////////////////////////////
794 ///Create a new prism and add it to the mesh.
795 ///Nodes 1,2,3 is a triangle and 1,2,5,4 a quadrangle.
796 ///@return The created prism
797 ///////////////////////////////////////////////////////////////////////////////
799 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
800 const SMDS_MeshNode * n2,
801 const SMDS_MeshNode * n3,
802 const SMDS_MeshNode * n4,
803 const SMDS_MeshNode * n5,
804 const SMDS_MeshNode * n6)
806 int ID = myElementIDFactory->GetFreeID();
807 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, ID);
808 if(v==NULL) myElementIDFactory->ReleaseID(ID);
812 ///////////////////////////////////////////////////////////////////////////////
813 ///Create a new prism and add it to the mesh.
814 ///Nodes 1,2,3 is a triangle and 1,2,5,4 a quadrangle.
815 ///@param ID The ID of the new volume
816 ///@return The created prism or NULL if an element with this ID already exists
817 ///or if input nodes are not found.
818 ///////////////////////////////////////////////////////////////////////////////
820 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
828 SMDS_MeshNode *node1, *node2, *node3, *node4, *node5, *node6;
829 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
830 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
831 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
832 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
833 node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5);
834 node6 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode6);
835 if(!node1 || !node2 || !node3 || !node4 || !node5 || !node6) return NULL;
836 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, node6, ID);
839 ///////////////////////////////////////////////////////////////////////////////
840 ///Create a new prism and add it to the mesh.
841 ///Nodes 1,2,3 is a triangle and 1,2,5,4 a quadrangle.
842 ///@param ID The ID of the new volume
843 ///@return The created prism
844 ///////////////////////////////////////////////////////////////////////////////
846 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
847 const SMDS_MeshNode * n2,
848 const SMDS_MeshNode * n3,
849 const SMDS_MeshNode * n4,
850 const SMDS_MeshNode * n5,
851 const SMDS_MeshNode * n6,
854 SMDS_MeshVolume* volume = 0;
855 if ( !n1 || !n2 || !n3 || !n4 || !n5 || !n6) return volume;
856 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
857 if(hasConstructionFaces()) {
858 SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3);
859 SMDS_MeshFace * f2=FindFaceOrCreate(n4,n5,n6);
860 SMDS_MeshFace * f3=FindFaceOrCreate(n1,n4,n5,n2);
861 SMDS_MeshFace * f4=FindFaceOrCreate(n2,n5,n6,n3);
862 SMDS_MeshFace * f5=FindFaceOrCreate(n3,n6,n4,n1);
863 volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5);
864 adjustmyCellsCapacity(ID);
865 myCells[ID] = volume;
868 else if(hasConstructionEdges()) {
872 // --- retrieve nodes ID
874 myNodeIds[0] = n1->getVtkId();
875 myNodeIds[1] = n2->getVtkId();
876 myNodeIds[2] = n3->getVtkId();
877 myNodeIds[3] = n4->getVtkId();
878 myNodeIds[4] = n5->getVtkId();
879 myNodeIds[5] = n6->getVtkId();
881 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
882 volvtk->init(myNodeIds, this);
883 if (!this->registerElement(ID,volvtk))
885 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
886 myVolumePool->destroy(volvtk);
890 adjustmyCellsCapacity(ID);
891 myCells[ID] = volume;
895 // if (!registerElement(ID, volume)) {
896 // RemoveElement(volume, false);
902 ///////////////////////////////////////////////////////////////////////////////
903 ///Create a new hexagonal prism and add it to the mesh.
904 ///@return The created prism
905 ///////////////////////////////////////////////////////////////////////////////
907 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
908 const SMDS_MeshNode * n2,
909 const SMDS_MeshNode * n3,
910 const SMDS_MeshNode * n4,
911 const SMDS_MeshNode * n5,
912 const SMDS_MeshNode * n6,
913 const SMDS_MeshNode * n7,
914 const SMDS_MeshNode * n8,
915 const SMDS_MeshNode * n9,
916 const SMDS_MeshNode * n10,
917 const SMDS_MeshNode * n11,
918 const SMDS_MeshNode * n12)
920 int ID = myElementIDFactory->GetFreeID();
921 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6,
922 n7, n8, n9, n10, n11, n12,
924 if(v==NULL) myElementIDFactory->ReleaseID(ID);
928 ///////////////////////////////////////////////////////////////////////////////
929 ///Create a new hexagonal prism and add it to the mesh.
930 ///@param ID The ID of the new volume
931 ///@return The created prism or NULL if an element with this ID already exists
932 ///or if input nodes are not found.
933 ///////////////////////////////////////////////////////////////////////////////
935 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
949 SMDS_MeshNode *node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
950 SMDS_MeshNode *node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
951 SMDS_MeshNode *node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
952 SMDS_MeshNode *node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
953 SMDS_MeshNode *node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5);
954 SMDS_MeshNode *node6 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode6);
955 SMDS_MeshNode *node7 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode7);
956 SMDS_MeshNode *node8 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode8);
957 SMDS_MeshNode *node9 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode9);
958 SMDS_MeshNode *node10 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode10);
959 SMDS_MeshNode *node11 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode11);
960 SMDS_MeshNode *node12 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode12);
961 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, node6,
962 node7, node8, node9, node10, node11, node12,
966 ///////////////////////////////////////////////////////////////////////////////
967 ///Create a new hexagonal prism and add it to the mesh.
968 ///@param ID The ID of the new volume
969 ///@return The created prism
970 ///////////////////////////////////////////////////////////////////////////////
972 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
973 const SMDS_MeshNode * n2,
974 const SMDS_MeshNode * n3,
975 const SMDS_MeshNode * n4,
976 const SMDS_MeshNode * n5,
977 const SMDS_MeshNode * n6,
978 const SMDS_MeshNode * n7,
979 const SMDS_MeshNode * n8,
980 const SMDS_MeshNode * n9,
981 const SMDS_MeshNode * n10,
982 const SMDS_MeshNode * n11,
983 const SMDS_MeshNode * n12,
986 SMDS_MeshVolume* volume = 0;
987 if(!n1 || !n2 || !n3 || !n4 || !n5 || !n6 ||
988 !n7 || !n8 || !n9 || !n10 || !n11 || !n12 )
990 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
991 if(hasConstructionFaces()) {
994 else if(hasConstructionEdges()) {
998 // --- retrieve nodes ID
999 myNodeIds.resize(12);
1000 myNodeIds[0] = n1->getVtkId();
1001 myNodeIds[1] = n6->getVtkId();
1002 myNodeIds[2] = n5->getVtkId();
1003 myNodeIds[3] = n4->getVtkId();
1004 myNodeIds[4] = n3->getVtkId();
1005 myNodeIds[5] = n2->getVtkId();
1007 myNodeIds[6] = n7->getVtkId();
1008 myNodeIds[7] = n12->getVtkId();
1009 myNodeIds[8] = n11->getVtkId();
1010 myNodeIds[9] = n10->getVtkId();
1011 myNodeIds[10] = n9->getVtkId();
1012 myNodeIds[11] = n8->getVtkId();
1014 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
1015 volvtk->init(myNodeIds, this);
1016 if (!this->registerElement(ID,volvtk))
1018 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
1019 myVolumePool->destroy(volvtk);
1023 adjustmyCellsCapacity(ID);
1024 myCells[ID] = volume;
1025 myInfo.myNbHexPrism++;
1031 ///////////////////////////////////////////////////////////////////////////////
1032 ///Create a new hexahedron and add it to the mesh.
1033 ///Nodes 1,2,3,4 and 5,6,7,8 are quadrangle and 5,1 and 7,3 are an edges.
1034 ///@return The created hexahedron
1035 ///////////////////////////////////////////////////////////////////////////////
1037 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
1038 const SMDS_MeshNode * n2,
1039 const SMDS_MeshNode * n3,
1040 const SMDS_MeshNode * n4,
1041 const SMDS_MeshNode * n5,
1042 const SMDS_MeshNode * n6,
1043 const SMDS_MeshNode * n7,
1044 const SMDS_MeshNode * n8)
1046 int ID = myElementIDFactory->GetFreeID();
1047 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, ID);
1048 if(v==NULL) myElementIDFactory->ReleaseID(ID);
1052 ///////////////////////////////////////////////////////////////////////////////
1053 ///Create a new hexahedron and add it to the mesh.
1054 ///Nodes 1,2,3,4 and 5,6,7,8 are quadrangle and 5,1 and 7,3 are an edges.
1055 ///@param ID The ID of the new volume
1056 ///@return The created hexahedron or NULL if an element with this ID already
1057 ///exists or if input nodes are not found.
1058 ///////////////////////////////////////////////////////////////////////////////
1060 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
1070 SMDS_MeshNode *node1, *node2, *node3, *node4, *node5, *node6, *node7, *node8;
1071 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
1072 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
1073 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
1074 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
1075 node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5);
1076 node6 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode6);
1077 node7 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode7);
1078 node8 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode8);
1079 if(!node1 || !node2 || !node3 || !node4 || !node5 || !node6 || !node7 || !node8)
1081 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, node6,
1085 ///////////////////////////////////////////////////////////////////////////////
1086 ///Create a new hexahedron and add it to the mesh.
1087 ///Nodes 1,2,3,4 and 5,6,7,8 are quadrangle and 5,1 and 7,3 are an edges.
1088 ///@param ID The ID of the new volume
1089 ///@return The created prism or NULL if an element with this ID already exists
1090 ///or if input nodes are not found.
1091 ///////////////////////////////////////////////////////////////////////////////
1093 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
1094 const SMDS_MeshNode * n2,
1095 const SMDS_MeshNode * n3,
1096 const SMDS_MeshNode * n4,
1097 const SMDS_MeshNode * n5,
1098 const SMDS_MeshNode * n6,
1099 const SMDS_MeshNode * n7,
1100 const SMDS_MeshNode * n8,
1103 SMDS_MeshVolume* volume = 0;
1104 if ( !n1 || !n2 || !n3 || !n4 || !n5 || !n6 || !n7 || !n8) return volume;
1105 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1106 if(hasConstructionFaces()) {
1107 SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3,n4);
1108 SMDS_MeshFace * f2=FindFaceOrCreate(n5,n6,n7,n8);
1109 SMDS_MeshFace * f3=FindFaceOrCreate(n1,n4,n8,n5);
1110 SMDS_MeshFace * f4=FindFaceOrCreate(n1,n2,n6,n5);
1111 SMDS_MeshFace * f5=FindFaceOrCreate(n2,n3,n7,n6);
1112 SMDS_MeshFace * f6=FindFaceOrCreate(n3,n4,n8,n7);
1113 volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5,f6);
1114 adjustmyCellsCapacity(ID);
1115 myCells[ID] = volume;
1118 else if(hasConstructionEdges()) {
1122 // --- retrieve nodes ID
1123 myNodeIds.resize(8);
1124 myNodeIds[0] = n1->getVtkId();
1125 myNodeIds[1] = n4->getVtkId();
1126 myNodeIds[2] = n3->getVtkId();
1127 myNodeIds[3] = n2->getVtkId();
1128 myNodeIds[4] = n5->getVtkId();
1129 myNodeIds[5] = n8->getVtkId();
1130 myNodeIds[6] = n7->getVtkId();
1131 myNodeIds[7] = n6->getVtkId();
1133 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
1134 volvtk->init(myNodeIds, this);
1135 if (!this->registerElement(ID,volvtk))
1137 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
1138 myVolumePool->destroy(volvtk);
1142 adjustmyCellsCapacity(ID);
1143 myCells[ID] = volume;
1147 // if (!registerElement(ID, volume)) {
1148 // RemoveElement(volume, false);
1154 ///////////////////////////////////////////////////////////////////////////////
1155 ///Create a new tetrahedron defined by its faces and add it to the mesh.
1156 ///@return The created tetrahedron
1157 ///////////////////////////////////////////////////////////////////////////////
1159 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshFace * f1,
1160 const SMDS_MeshFace * f2,
1161 const SMDS_MeshFace * f3,
1162 const SMDS_MeshFace * f4)
1164 if (!hasConstructionFaces())
1166 return AddVolumeWithID(f1,f2,f3,f4, myElementIDFactory->GetFreeID());
1169 ///////////////////////////////////////////////////////////////////////////////
1170 ///Create a new tetrahedron defined by its faces and add it to the mesh.
1171 ///@param ID The ID of the new volume
1172 ///@return The created tetrahedron
1173 ///////////////////////////////////////////////////////////////////////////////
1175 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1,
1176 const SMDS_MeshFace * f2,
1177 const SMDS_MeshFace * f3,
1178 const SMDS_MeshFace * f4,
1181 if (!hasConstructionFaces())
1183 if ( !f1 || !f2 || !f3 || !f4) return 0;
1184 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1185 SMDS_MeshVolume * volume = new SMDS_VolumeOfFaces(f1,f2,f3,f4);
1186 adjustmyCellsCapacity(ID);
1187 myCells[ID] = volume;
1188 myInfo.myNbTetras++;
1190 if (!registerElement(ID, volume)) {
1191 registerElement(myElementIDFactory->GetFreeID(), volume);
1192 //RemoveElement(volume, false);
1198 ///////////////////////////////////////////////////////////////////////////////
1199 ///Create a new pyramid defined by its faces and add it to the mesh.
1200 ///@return The created pyramid
1201 ///////////////////////////////////////////////////////////////////////////////
1203 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshFace * f1,
1204 const SMDS_MeshFace * f2,
1205 const SMDS_MeshFace * f3,
1206 const SMDS_MeshFace * f4,
1207 const SMDS_MeshFace * f5)
1209 if (!hasConstructionFaces())
1211 return AddVolumeWithID(f1,f2,f3,f4,f5, myElementIDFactory->GetFreeID());
1214 ///////////////////////////////////////////////////////////////////////////////
1215 ///Create a new pyramid defined by its faces and add it to the mesh.
1216 ///@param ID The ID of the new volume
1217 ///@return The created pyramid
1218 ///////////////////////////////////////////////////////////////////////////////
1220 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1,
1221 const SMDS_MeshFace * f2,
1222 const SMDS_MeshFace * f3,
1223 const SMDS_MeshFace * f4,
1224 const SMDS_MeshFace * f5,
1227 if (!hasConstructionFaces())
1229 if ( !f1 || !f2 || !f3 || !f4 || !f5) return 0;
1230 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1231 SMDS_MeshVolume * volume = new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5);
1232 adjustmyCellsCapacity(ID);
1233 myCells[ID] = volume;
1234 myInfo.myNbPyramids++;
1236 if (!registerElement(ID, volume)) {
1237 registerElement(myElementIDFactory->GetFreeID(), volume);
1238 //RemoveElement(volume, false);
1244 ///////////////////////////////////////////////////////////////////////////////
1245 ///Create a new prism defined by its faces and add it to the mesh.
1246 ///@return The created prism
1247 ///////////////////////////////////////////////////////////////////////////////
1249 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshFace * f1,
1250 const SMDS_MeshFace * f2,
1251 const SMDS_MeshFace * f3,
1252 const SMDS_MeshFace * f4,
1253 const SMDS_MeshFace * f5,
1254 const SMDS_MeshFace * f6)
1256 if (!hasConstructionFaces())
1258 return AddVolumeWithID(f1,f2,f3,f4,f5,f6, myElementIDFactory->GetFreeID());
1261 ///////////////////////////////////////////////////////////////////////////////
1262 ///Create a new prism defined by its faces and add it to the mesh.
1263 ///@param ID The ID of the new volume
1264 ///@return The created prism
1265 ///////////////////////////////////////////////////////////////////////////////
1267 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1,
1268 const SMDS_MeshFace * f2,
1269 const SMDS_MeshFace * f3,
1270 const SMDS_MeshFace * f4,
1271 const SMDS_MeshFace * f5,
1272 const SMDS_MeshFace * f6,
1275 if (!hasConstructionFaces())
1277 if ( !f1 || !f2 || !f3 || !f4 || !f5 || !f6) return 0;
1278 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1279 SMDS_MeshVolume * volume = new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5,f6);
1280 adjustmyCellsCapacity(ID);
1281 myCells[ID] = volume;
1282 myInfo.myNbPrisms++;
1284 if (!registerElement(ID, volume)) {
1285 registerElement(myElementIDFactory->GetFreeID(), volume);
1286 //RemoveElement(volume, false);
1292 ///////////////////////////////////////////////////////////////////////////////
1293 /// Add a polygon defined by its nodes IDs
1294 ///////////////////////////////////////////////////////////////////////////////
1296 SMDS_MeshFace* SMDS_Mesh::AddPolygonalFaceWithID (const vector<int> & nodes_ids,
1299 int nbNodes = nodes_ids.size();
1300 vector<const SMDS_MeshNode*> nodes (nbNodes);
1301 for (int i = 0; i < nbNodes; i++) {
1302 nodes[i] = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nodes_ids[i]);
1303 if (!nodes[i]) return NULL;
1305 return SMDS_Mesh::AddPolygonalFaceWithID(nodes, ID);
1308 ///////////////////////////////////////////////////////////////////////////////
1309 /// Add a polygon defined by its nodes
1310 ///////////////////////////////////////////////////////////////////////////////
1313 SMDS_Mesh::AddPolygonalFaceWithID (const vector<const SMDS_MeshNode*> & nodes,
1316 SMDS_MeshFace * face;
1318 if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1319 if (hasConstructionEdges())
1325 myNodeIds.resize( nodes.size() );
1326 for ( size_t i = 0; i < nodes.size(); ++i )
1327 myNodeIds[i] = nodes[i]->getVtkId();
1329 SMDS_VtkFace *facevtk = myFacePool->getNew();
1330 facevtk->initPoly(myNodeIds, this);
1331 if (!this->registerElement(ID,facevtk))
1333 this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL);
1334 myFacePool->destroy(facevtk);
1339 adjustmyCellsCapacity(ID);
1341 myInfo.myNbPolygons++;
1347 ///////////////////////////////////////////////////////////////////////////////
1348 /// Add a polygon defined by its nodes.
1349 /// An ID is automatically affected to the created face.
1350 ///////////////////////////////////////////////////////////////////////////////
1352 SMDS_MeshFace* SMDS_Mesh::AddPolygonalFace (const vector<const SMDS_MeshNode*> & nodes)
1354 return SMDS_Mesh::AddPolygonalFaceWithID(nodes, myElementIDFactory->GetFreeID());
1357 ///////////////////////////////////////////////////////////////////////////////
1358 /// Add a quadratic polygon defined by its nodes IDs
1359 ///////////////////////////////////////////////////////////////////////////////
1361 SMDS_MeshFace* SMDS_Mesh::AddQuadPolygonalFaceWithID (const vector<int> & nodes_ids,
1364 vector<const SMDS_MeshNode*> nodes( nodes_ids.size() );
1365 for ( size_t i = 0; i < nodes.size(); i++) {
1366 nodes[i] = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nodes_ids[i]);
1367 if (!nodes[i]) return NULL;
1369 return SMDS_Mesh::AddQuadPolygonalFaceWithID(nodes, ID);
1372 ///////////////////////////////////////////////////////////////////////////////
1373 /// Add a quadratic polygon defined by its nodes
1374 ///////////////////////////////////////////////////////////////////////////////
1377 SMDS_Mesh::AddQuadPolygonalFaceWithID (const vector<const SMDS_MeshNode*> & nodes,
1380 SMDS_MeshFace * face;
1382 if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1383 if (hasConstructionEdges())
1389 myNodeIds.resize( nodes.size() );
1390 for ( size_t i = 0; i < nodes.size(); ++i )
1391 myNodeIds[i] = nodes[i]->getVtkId();
1393 SMDS_VtkFace *facevtk = myFacePool->getNew();
1394 facevtk->initQuadPoly(myNodeIds, this);
1395 if (!this->registerElement(ID,facevtk))
1397 this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL);
1398 myFacePool->destroy(facevtk);
1402 adjustmyCellsCapacity(ID);
1404 myInfo.myNbQuadPolygons++;
1409 ///////////////////////////////////////////////////////////////////////////////
1410 /// Add a quadratic polygon defined by its nodes.
1411 /// An ID is automatically affected to the created face.
1412 ///////////////////////////////////////////////////////////////////////////////
1414 SMDS_MeshFace* SMDS_Mesh::AddQuadPolygonalFace (const vector<const SMDS_MeshNode*> & nodes)
1416 return SMDS_Mesh::AddQuadPolygonalFaceWithID(nodes, myElementIDFactory->GetFreeID());
1419 ///////////////////////////////////////////////////////////////////////////////
1420 /// Create a new polyhedral volume and add it to the mesh.
1421 /// @param ID The ID of the new volume
1422 /// @return The created volume or NULL if an element with this ID already exists
1423 /// or if input nodes are not found.
1424 ///////////////////////////////////////////////////////////////////////////////
1426 SMDS_MeshVolume * SMDS_Mesh::AddPolyhedralVolumeWithID
1427 (const vector<int> & nodes_ids,
1428 const vector<int> & quantities,
1431 int nbNodes = nodes_ids.size();
1432 vector<const SMDS_MeshNode*> nodes (nbNodes);
1433 for (int i = 0; i < nbNodes; i++) {
1434 nodes[i] = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nodes_ids[i]);
1435 if (!nodes[i]) return NULL;
1437 return SMDS_Mesh::AddPolyhedralVolumeWithID(nodes, quantities, ID);
1440 ///////////////////////////////////////////////////////////////////////////////
1441 /// Create a new polyhedral volume and add it to the mesh.
1442 /// @param ID The ID of the new volume
1443 /// @return The created volume
1444 ///////////////////////////////////////////////////////////////////////////////
1447 SMDS_Mesh::AddPolyhedralVolumeWithID (const vector<const SMDS_MeshNode*>& nodes,
1448 const vector<int> & quantities,
1451 SMDS_MeshVolume* volume = 0;
1452 if ( nodes.empty() || quantities.empty() )
1454 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1455 if (hasConstructionFaces())
1459 else if (hasConstructionEdges())
1465 //#ifdef VTK_HAVE_POLYHEDRON
1466 myNodeIds.resize( nodes.size() );
1467 for ( size_t i = 0; i < nodes.size(); ++i )
1468 myNodeIds[i] = nodes[i]->getVtkId();
1470 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
1471 volvtk->initPoly(myNodeIds, quantities, this);
1472 if (!this->registerElement(ID, volvtk))
1474 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
1475 myVolumePool->destroy(volvtk);
1480 // for ( int i = 0; i < nodes.size(); ++i )
1481 // if ( !nodes[ i ] ) return 0;
1482 // volume = new SMDS_PolyhedralVolumeOfNodes(nodes, quantities);
1484 adjustmyCellsCapacity(ID);
1485 myCells[ID] = volume;
1486 myInfo.myNbPolyhedrons++;
1489 //#ifndef VTK_HAVE_POLYHEDRON
1490 // if (!registerElement(ID, volume))
1492 // registerElement(myElementIDFactory->GetFreeID(), volume);
1493 // //RemoveElement(volume, false);
1500 ///////////////////////////////////////////////////////////////////////////////
1501 /// Create a new polyhedral volume and add it to the mesh.
1502 /// @return The created volume
1503 ///////////////////////////////////////////////////////////////////////////////
1505 SMDS_MeshVolume* SMDS_Mesh::AddPolyhedralVolume
1506 (const vector<const SMDS_MeshNode*> & nodes,
1507 const vector<int> & quantities)
1509 int ID = myElementIDFactory->GetFreeID();
1510 SMDS_MeshVolume * v = SMDS_Mesh::AddPolyhedralVolumeWithID(nodes, quantities, ID);
1511 if (v == NULL) myElementIDFactory->ReleaseID(ID);
1515 SMDS_MeshVolume* SMDS_Mesh::AddVolumeFromVtkIds(const std::vector<vtkIdType>& vtkNodeIds)
1517 int ID = myElementIDFactory->GetFreeID();
1518 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeFromVtkIdsWithID(vtkNodeIds, ID);
1519 if (v == NULL) myElementIDFactory->ReleaseID(ID);
1523 SMDS_MeshVolume* SMDS_Mesh::AddVolumeFromVtkIdsWithID(const std::vector<vtkIdType>& vtkNodeIds, const int ID)
1525 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
1526 volvtk->init(vtkNodeIds, this);
1527 if (!this->registerElement(ID,volvtk))
1529 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
1530 myVolumePool->destroy(volvtk);
1533 adjustmyCellsCapacity(ID);
1534 myCells[ID] = volvtk;
1535 vtkIdType aVtkType = volvtk->GetVtkType();
1539 myInfo.myNbTetras++;
1542 myInfo.myNbPyramids++;
1545 myInfo.myNbPrisms++;
1547 case VTK_HEXAHEDRON:
1550 case VTK_QUADRATIC_TETRA:
1551 myInfo.myNbQuadTetras++;
1553 case VTK_QUADRATIC_PYRAMID:
1554 myInfo.myNbQuadPyramids++;
1556 case VTK_QUADRATIC_WEDGE:
1557 myInfo.myNbQuadPrisms++;
1559 case VTK_QUADRATIC_HEXAHEDRON:
1560 myInfo.myNbQuadHexas++;
1562 //#ifdef VTK_HAVE_POLYHEDRON
1563 case VTK_POLYHEDRON:
1564 myInfo.myNbPolyhedrons++;
1568 myInfo.myNbPolyhedrons++;
1574 SMDS_MeshFace* SMDS_Mesh::AddFaceFromVtkIds(const std::vector<vtkIdType>& vtkNodeIds)
1576 int ID = myElementIDFactory->GetFreeID();
1577 SMDS_MeshFace * f = SMDS_Mesh::AddFaceFromVtkIdsWithID(vtkNodeIds, ID);
1578 if (f == NULL) myElementIDFactory->ReleaseID(ID);
1582 SMDS_MeshFace* SMDS_Mesh::AddFaceFromVtkIdsWithID(const std::vector<vtkIdType>& vtkNodeIds, const int ID)
1584 SMDS_VtkFace *facevtk = myFacePool->getNew();
1585 facevtk->init(vtkNodeIds, this);
1586 if (!this->registerElement(ID,facevtk))
1588 this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL);
1589 myFacePool->destroy(facevtk);
1592 adjustmyCellsCapacity(ID);
1593 myCells[ID] = facevtk;
1594 vtkIdType aVtkType = facevtk->GetVtkType();
1598 myInfo.myNbTriangles++;
1601 myInfo.myNbQuadrangles++;
1603 case VTK_QUADRATIC_TRIANGLE:
1604 myInfo.myNbQuadTriangles++;
1606 case VTK_QUADRATIC_QUAD:
1607 myInfo.myNbQuadQuadrangles++;
1609 case VTK_BIQUADRATIC_QUAD:
1610 myInfo.myNbBiQuadQuadrangles++;
1612 case VTK_BIQUADRATIC_TRIANGLE:
1613 myInfo.myNbBiQuadTriangles++;
1616 myInfo.myNbPolygons++;
1619 myInfo.myNbPolygons++;
1624 ///////////////////////////////////////////////////////////////////////////////
1625 /// Registers element with the given ID, maintains inverse connections
1626 ///////////////////////////////////////////////////////////////////////////////
1627 bool SMDS_Mesh::registerElement(int ID, SMDS_MeshElement* element)
1629 if ((ID >=0) && (ID < (int)myCells.size()) && myCells[ID]) // --- already bound
1631 MESSAGE(" ------------------ already bound "<< ID << " " << myCells[ID]->getVtkId());
1636 element->myMeshId = myMeshId;
1638 SMDS_MeshCell *cell = dynamic_cast<SMDS_MeshCell*>(element);
1640 int vtkId = cell->getVtkId();
1642 vtkId = myElementIDFactory->SetInVtkGrid(element);
1644 if (vtkId >= (int)myCellIdVtkToSmds.size()) // --- resize local vector
1646 myCellIdVtkToSmds.resize(vtkId + SMDS_Mesh::chunkSize, -1);
1648 myCellIdVtkToSmds[vtkId] = ID;
1650 myElementIDFactory->updateMinMax(ID);
1654 //=======================================================================
1655 //function : MoveNode
1657 //=======================================================================
1659 void SMDS_Mesh::MoveNode(const SMDS_MeshNode *n, double x, double y, double z)
1661 SMDS_MeshNode * node=const_cast<SMDS_MeshNode*>(n);
1662 node->setXYZ(x,y,z);
1665 ///////////////////////////////////////////////////////////////////////////////
1666 /// Return the node whose SMDS ID is 'ID'.
1667 ///////////////////////////////////////////////////////////////////////////////
1668 const SMDS_MeshNode * SMDS_Mesh::FindNode(int ID) const
1670 if (ID < 1 || ID >= (int)myNodes.size())
1674 return (const SMDS_MeshNode *)myNodes[ID];
1677 ///////////////////////////////////////////////////////////////////////////////
1678 /// Return the node whose VTK ID is 'vtkId'.
1679 ///////////////////////////////////////////////////////////////////////////////
1680 const SMDS_MeshNode * SMDS_Mesh::FindNodeVtk(int vtkId) const
1682 // TODO if needed use mesh->nodeIdFromVtkToSmds
1683 if ( vtkId < 0 || vtkId+1 >= (int) myNodes.size() )
1685 MESSAGE("------------------------------------------------------------------------- ");
1686 MESSAGE("---------------------------- bad VTK ID " << vtkId << " " << myNodes.size());
1687 MESSAGE("------------------------------------------------------------------------- ");
1690 return (const SMDS_MeshNode *)myNodes[vtkId+1];
1693 ///////////////////////////////////////////////////////////////////////////////
1694 ///Create a triangle and add it to the current mesh. This method do not bind an
1695 ///ID to the create triangle.
1696 ///////////////////////////////////////////////////////////////////////////////
1697 SMDS_MeshFace * SMDS_Mesh::createTriangle(const SMDS_MeshNode * node1,
1698 const SMDS_MeshNode * node2,
1699 const SMDS_MeshNode * node3,
1702 if ( !node1 || !node2 || !node3) return 0;
1703 if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1704 if(hasConstructionEdges())
1706 SMDS_MeshEdge *edge1, *edge2, *edge3;
1707 edge1=FindEdgeOrCreate(node1,node2);
1708 edge2=FindEdgeOrCreate(node2,node3);
1709 edge3=FindEdgeOrCreate(node3,node1);
1711 //int ID = myElementIDFactory->GetFreeID(); // -PR- voir si on range cet element
1712 SMDS_MeshFace * face = new SMDS_FaceOfEdges(edge1,edge2,edge3);
1713 adjustmyCellsCapacity(ID);
1715 myInfo.myNbTriangles++;
1720 // --- retrieve nodes ID
1721 myNodeIds.resize(3);
1722 myNodeIds[0] = node1->getVtkId();
1723 myNodeIds[1] = node2->getVtkId();
1724 myNodeIds[2] = node3->getVtkId();
1726 SMDS_MeshFace * face = 0;
1727 SMDS_VtkFace *facevtk = myFacePool->getNew();
1728 facevtk->init(myNodeIds, this); // put in vtkUnstructuredGrid
1729 if (!this->registerElement(ID,facevtk))
1731 this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL);
1732 myFacePool->destroy(facevtk);
1736 adjustmyCellsCapacity(ID);
1738 myInfo.myNbTriangles++;
1743 ///////////////////////////////////////////////////////////////////////////////
1744 ///Create a quadrangle and add it to the current mesh. This methode do not bind
1745 ///a ID to the create triangle.
1746 ///////////////////////////////////////////////////////////////////////////////
1747 SMDS_MeshFace * SMDS_Mesh::createQuadrangle(const SMDS_MeshNode * node1,
1748 const SMDS_MeshNode * node2,
1749 const SMDS_MeshNode * node3,
1750 const SMDS_MeshNode * node4,
1753 if ( !node1 || !node2 || !node3 || !node4 ) return 0;
1754 if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1755 if(hasConstructionEdges())
1757 SMDS_MeshEdge *edge1, *edge2, *edge3, *edge4;
1758 edge1=FindEdgeOrCreate(node1,node2);
1759 edge2=FindEdgeOrCreate(node2,node3);
1760 edge3=FindEdgeOrCreate(node3,node4);
1761 edge4=FindEdgeOrCreate(node4,node1);
1763 SMDS_MeshFace * face = new SMDS_FaceOfEdges(edge1,edge2,edge3,edge4);
1764 adjustmyCellsCapacity(ID);
1766 myInfo.myNbQuadrangles++;
1771 // --- retrieve nodes ID
1772 myNodeIds.resize(4);
1773 myNodeIds[0] = node1->getVtkId();
1774 myNodeIds[1] = node2->getVtkId();
1775 myNodeIds[2] = node3->getVtkId();
1776 myNodeIds[3] = node4->getVtkId();
1778 SMDS_MeshFace * face = 0;
1779 SMDS_VtkFace *facevtk = myFacePool->getNew();
1780 facevtk->init(myNodeIds, this);
1781 if (!this->registerElement(ID,facevtk))
1783 this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL);
1784 myFacePool->destroy(facevtk);
1788 adjustmyCellsCapacity(ID);
1790 myInfo.myNbQuadrangles++;
1795 ///////////////////////////////////////////////////////////////////////////////
1796 /// Remove a node and all the elements which own this node
1797 ///////////////////////////////////////////////////////////////////////////////
1799 void SMDS_Mesh::RemoveNode(const SMDS_MeshNode * node)
1801 RemoveElement(node, true);
1804 ///////////////////////////////////////////////////////////////////////////////
1805 /// Remove an edge and all the elements which own this edge
1806 ///////////////////////////////////////////////////////////////////////////////
1808 void SMDS_Mesh::Remove0DElement(const SMDS_Mesh0DElement * elem0d)
1810 RemoveElement(elem0d,true);
1813 ///////////////////////////////////////////////////////////////////////////////
1814 /// Remove an edge and all the elements which own this edge
1815 ///////////////////////////////////////////////////////////////////////////////
1817 void SMDS_Mesh::RemoveEdge(const SMDS_MeshEdge * edge)
1819 RemoveElement(edge,true);
1822 ///////////////////////////////////////////////////////////////////////////////
1823 /// Remove an face and all the elements which own this face
1824 ///////////////////////////////////////////////////////////////////////////////
1826 void SMDS_Mesh::RemoveFace(const SMDS_MeshFace * face)
1828 RemoveElement(face, true);
1831 ///////////////////////////////////////////////////////////////////////////////
1833 ///////////////////////////////////////////////////////////////////////////////
1835 void SMDS_Mesh::RemoveVolume(const SMDS_MeshVolume * volume)
1837 RemoveElement(volume, true);
1840 //=======================================================================
1841 //function : RemoveFromParent
1843 //=======================================================================
1845 bool SMDS_Mesh::RemoveFromParent()
1847 if (myParent==NULL) return false;
1848 else return (myParent->RemoveSubMesh(this));
1851 //=======================================================================
1852 //function : RemoveSubMesh
1854 //=======================================================================
1856 bool SMDS_Mesh::RemoveSubMesh(const SMDS_Mesh * aMesh)
1860 list<SMDS_Mesh *>::iterator itmsh=myChildren.begin();
1861 for (; itmsh!=myChildren.end() && !found; itmsh++)
1863 SMDS_Mesh * submesh = *itmsh;
1864 if (submesh == aMesh)
1867 myChildren.erase(itmsh);
1874 //=======================================================================
1875 //function : ChangeElementNodes
1877 //=======================================================================
1879 bool SMDS_Mesh::ChangeElementNodes(const SMDS_MeshElement * element,
1880 const SMDS_MeshNode * nodes[],
1883 // keep current nodes of elem
1884 set<const SMDS_MeshNode*> oldNodes( element->begin_nodes(), element->end_nodes() );
1888 SMDS_MeshCell* cell = dynamic_cast<SMDS_MeshCell*>((SMDS_MeshElement*) element);
1891 Ok = cell->vtkOrder(nodes, nbnodes);
1892 Ok = cell->ChangeNodes(nodes, nbnodes);
1895 if ( Ok ) { // update InverseElements
1897 set<const SMDS_MeshNode*>::iterator it;
1899 // AddInverseElement to new nodes
1900 for ( int i = 0; i < nbnodes; i++ ) {
1901 it = oldNodes.find( nodes[i] );
1902 if ( it == oldNodes.end() )
1904 const_cast<SMDS_MeshNode*>( nodes[i] )->AddInverseElement( cell );
1906 // remove from oldNodes a node that remains in elem
1907 oldNodes.erase( it );
1909 // RemoveInverseElement from the nodes removed from elem
1910 for ( it = oldNodes.begin(); it != oldNodes.end(); it++ )
1912 SMDS_MeshNode * n = const_cast<SMDS_MeshNode *>( *it );
1913 n->RemoveInverseElement( cell );
1920 //=======================================================================
1921 //function : ChangePolyhedronNodes
1922 //purpose : to change nodes of polyhedral volume
1923 //=======================================================================
1924 bool SMDS_Mesh::ChangePolyhedronNodes (const SMDS_MeshElement * elem,
1925 const vector<const SMDS_MeshNode*>& nodes,
1926 const vector<int> & quantities)
1928 if (elem->GetType() != SMDSAbs_Volume) {
1929 MESSAGE("WRONG ELEM TYPE");
1933 const SMDS_VtkVolume* vol = dynamic_cast<const SMDS_VtkVolume*>(elem);
1938 // keep current nodes of elem
1939 set<const SMDS_MeshElement*> oldNodes;
1940 SMDS_ElemIteratorPtr itn = elem->nodesIterator();
1941 while (itn->more()) {
1942 oldNodes.insert(itn->next());
1946 // TODO remove this function
1947 //bool Ok = const_cast<SMDS_VtkVolume*>(vol)->ChangeNodes(nodes, quantities);
1953 // update InverseElements
1955 // AddInverseElement to new nodes
1956 int nbnodes = nodes.size();
1957 set<const SMDS_MeshElement*>::iterator it;
1958 for (int i = 0; i < nbnodes; i++) {
1959 it = oldNodes.find(nodes[i]);
1960 if (it == oldNodes.end()) {
1962 const_cast<SMDS_MeshNode*>(nodes[i])->AddInverseElement(elem);
1964 // remove from oldNodes a node that remains in elem
1969 // RemoveInverseElement from the nodes removed from elem
1970 for (it = oldNodes.begin(); it != oldNodes.end(); it++) {
1971 SMDS_MeshNode * n = static_cast<SMDS_MeshNode *>
1972 (const_cast<SMDS_MeshElement *>( *it ));
1973 n->RemoveInverseElement(elem);
1980 //=======================================================================
1981 //function : Find0DElement
1983 //=======================================================================
1984 const SMDS_Mesh0DElement* SMDS_Mesh::Find0DElement(int idnode) const
1986 const SMDS_MeshNode * node = FindNode(idnode);
1987 if(node == NULL) return NULL;
1988 return Find0DElement(node);
1991 const SMDS_Mesh0DElement* SMDS_Mesh::Find0DElement(const SMDS_MeshNode * node)
1993 if (!node) return 0;
1994 const SMDS_Mesh0DElement* toReturn = NULL;
1995 SMDS_ElemIteratorPtr it1 = node->GetInverseElementIterator(SMDSAbs_0DElement);
1996 while (it1->more() && (toReturn == NULL)) {
1997 const SMDS_MeshElement* e = it1->next();
1998 if (e->NbNodes() == 1) {
1999 toReturn = static_cast<const SMDS_Mesh0DElement*>(e);
2005 //=======================================================================
2006 //function : FindBall
2008 //=======================================================================
2010 const SMDS_BallElement* SMDS_Mesh::FindBall(int idnode) const
2012 const SMDS_MeshNode * node = FindNode(idnode);
2013 if(node == NULL) return NULL;
2014 return FindBall(node);
2017 const SMDS_BallElement* SMDS_Mesh::FindBall(const SMDS_MeshNode * node)
2019 if (!node) return 0;
2020 const SMDS_BallElement* toReturn = NULL;
2021 SMDS_ElemIteratorPtr it1 = node->GetInverseElementIterator(SMDSAbs_Ball);
2022 while (it1->more() && (toReturn == NULL)) {
2023 const SMDS_MeshElement* e = it1->next();
2024 if (e->GetGeomType() == SMDSGeom_BALL)
2025 toReturn = static_cast<const SMDS_BallElement*>(e);
2030 //=======================================================================
2031 //function : Find0DElementOrCreate
2033 //=======================================================================
2034 //SMDS_Mesh0DElement* SMDS_Mesh::Find0DElementOrCreate(const SMDS_MeshNode * node)
2036 // if (!node) return 0;
2037 // SMDS_Mesh0DElement * toReturn = NULL;
2038 // toReturn = const_cast<SMDS_Mesh0DElement*>(Find0DElement(node));
2039 // if (toReturn == NULL) {
2040 // //if (my0DElements.Extent() % CHECKMEMORY_INTERVAL == 0) CheckMemory();
2041 // toReturn = new SMDS_Mesh0DElement(node);
2042 // my0DElements.Add(toReturn);
2043 // myInfo.myNb0DElements++;
2049 //=======================================================================
2050 //function : FindEdge
2052 //=======================================================================
2054 const SMDS_MeshEdge* SMDS_Mesh::FindEdge(int idnode1, int idnode2) const
2056 const SMDS_MeshNode * node1=FindNode(idnode1);
2057 const SMDS_MeshNode * node2=FindNode(idnode2);
2058 if((node1==NULL)||(node2==NULL)) return NULL;
2059 return FindEdge(node1,node2);
2062 //#include "Profiler.h"
2063 const SMDS_MeshEdge* SMDS_Mesh::FindEdge(const SMDS_MeshNode * node1,
2064 const SMDS_MeshNode * node2)
2066 if ( !node1 ) return 0;
2067 const SMDS_MeshEdge * toReturn=NULL;
2070 SMDS_ElemIteratorPtr it1=node1->GetInverseElementIterator(SMDSAbs_Edge);
2073 while(it1->more()) {
2074 const SMDS_MeshElement * e = it1->next();
2075 if ( e->NbNodes() == 2 && e->GetNodeIndex( node2 ) >= 0 ) {
2076 toReturn = static_cast<const SMDS_MeshEdge*>( e );
2085 //=======================================================================
2086 //function : FindEdgeOrCreate
2088 //=======================================================================
2090 SMDS_MeshEdge* SMDS_Mesh::FindEdgeOrCreate(const SMDS_MeshNode * node1,
2091 const SMDS_MeshNode * node2)
2093 if ( !node1 || !node2) return 0;
2094 SMDS_MeshEdge * toReturn=NULL;
2095 toReturn=const_cast<SMDS_MeshEdge*>(FindEdge(node1,node2));
2096 if(toReturn==NULL) {
2097 if ( NbEdges() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
2098 int ID = myElementIDFactory->GetFreeID(); // -PR- voir si on range cet element
2099 adjustmyCellsCapacity(ID);
2100 myNodeIds.resize(2);
2101 myNodeIds[0] = node1->getVtkId();
2102 myNodeIds[1] = node2->getVtkId();
2104 SMDS_VtkEdge *edgevtk = myEdgePool->getNew();
2105 edgevtk->init(myNodeIds, this);
2106 if (!this->registerElement(ID,edgevtk))
2108 this->myGrid->GetCellTypesArray()->SetValue(edgevtk->getVtkId(), VTK_EMPTY_CELL);
2109 myEdgePool->destroy(edgevtk);
2113 myCells[ID] = toReturn;
2120 //=======================================================================
2121 //function : FindEdge
2123 //=======================================================================
2125 const SMDS_MeshEdge* SMDS_Mesh::FindEdge(int idnode1, int idnode2,
2128 const SMDS_MeshNode * node1=FindNode(idnode1);
2129 const SMDS_MeshNode * node2=FindNode(idnode2);
2130 const SMDS_MeshNode * node3=FindNode(idnode3);
2131 return FindEdge(node1,node2,node3);
2134 const SMDS_MeshEdge* SMDS_Mesh::FindEdge(const SMDS_MeshNode * node1,
2135 const SMDS_MeshNode * node2,
2136 const SMDS_MeshNode * node3)
2138 if ( !node1 ) return 0;
2139 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Edge);
2140 while(it1->more()) {
2141 const SMDS_MeshElement * e = it1->next();
2142 if ( e->NbNodes() == 3 ) {
2143 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
2144 while(it2->more()) {
2145 const SMDS_MeshElement* n = it2->next();
2155 return static_cast<const SMDS_MeshEdge *> (e);
2162 //=======================================================================
2163 //function : FindFace
2165 //=======================================================================
2167 const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2,
2170 const SMDS_MeshNode * node1=FindNode(idnode1);
2171 const SMDS_MeshNode * node2=FindNode(idnode2);
2172 const SMDS_MeshNode * node3=FindNode(idnode3);
2173 return FindFace(node1, node2, node3);
2176 const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1,
2177 const SMDS_MeshNode *node2,
2178 const SMDS_MeshNode *node3)
2180 if ( !node1 ) return 0;
2181 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Face);
2182 while(it1->more()) {
2183 const SMDS_MeshElement * e = it1->next();
2184 if ( e->NbNodes() == 3 ) {
2185 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
2186 while(it2->more()) {
2187 const SMDS_MeshElement* n = it2->next();
2197 return static_cast<const SMDS_MeshFace *> (e);
2203 SMDS_MeshFace* SMDS_Mesh::FindFaceOrCreate(const SMDS_MeshNode *node1,
2204 const SMDS_MeshNode *node2,
2205 const SMDS_MeshNode *node3)
2207 SMDS_MeshFace * toReturn=NULL;
2208 toReturn = const_cast<SMDS_MeshFace*>(FindFace(node1,node2,node3));
2209 if(toReturn==NULL) {
2210 int ID = myElementIDFactory->GetFreeID();
2211 toReturn = createTriangle(node1,node2,node3, ID);
2217 //=======================================================================
2218 //function : FindFace
2220 //=======================================================================
2222 const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2,
2223 int idnode3, int idnode4) const
2225 const SMDS_MeshNode * node1=FindNode(idnode1);
2226 const SMDS_MeshNode * node2=FindNode(idnode2);
2227 const SMDS_MeshNode * node3=FindNode(idnode3);
2228 const SMDS_MeshNode * node4=FindNode(idnode4);
2229 return FindFace(node1, node2, node3, node4);
2232 const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1,
2233 const SMDS_MeshNode *node2,
2234 const SMDS_MeshNode *node3,
2235 const SMDS_MeshNode *node4)
2237 if ( !node1 ) return 0;
2238 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Face);
2239 while(it1->more()) {
2240 const SMDS_MeshElement * e = it1->next();
2241 if ( e->NbNodes() == 4 ) {
2242 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
2243 while(it2->more()) {
2244 const SMDS_MeshElement* n = it2->next();
2255 return static_cast<const SMDS_MeshFace *> (e);
2261 SMDS_MeshFace* SMDS_Mesh::FindFaceOrCreate(const SMDS_MeshNode *node1,
2262 const SMDS_MeshNode *node2,
2263 const SMDS_MeshNode *node3,
2264 const SMDS_MeshNode *node4)
2266 SMDS_MeshFace * toReturn=NULL;
2267 toReturn=const_cast<SMDS_MeshFace*>(FindFace(node1,node2,node3,node4));
2268 if(toReturn==NULL) {
2269 int ID = myElementIDFactory->GetFreeID();
2270 toReturn=createQuadrangle(node1,node2,node3,node4,ID);
2276 //=======================================================================
2277 //function : FindFace
2278 //purpose :quadratic triangle
2279 //=======================================================================
2281 const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2,
2282 int idnode3, int idnode4,
2283 int idnode5, int idnode6) const
2285 const SMDS_MeshNode * node1 = FindNode(idnode1);
2286 const SMDS_MeshNode * node2 = FindNode(idnode2);
2287 const SMDS_MeshNode * node3 = FindNode(idnode3);
2288 const SMDS_MeshNode * node4 = FindNode(idnode4);
2289 const SMDS_MeshNode * node5 = FindNode(idnode5);
2290 const SMDS_MeshNode * node6 = FindNode(idnode6);
2291 return FindFace(node1, node2, node3, node4, node5, node6);
2294 const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1,
2295 const SMDS_MeshNode *node2,
2296 const SMDS_MeshNode *node3,
2297 const SMDS_MeshNode *node4,
2298 const SMDS_MeshNode *node5,
2299 const SMDS_MeshNode *node6)
2301 if ( !node1 ) return 0;
2302 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Face);
2303 while(it1->more()) {
2304 const SMDS_MeshElement * e = it1->next();
2305 if ( e->NbNodes() == 6 ) {
2306 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
2307 while(it2->more()) {
2308 const SMDS_MeshElement* n = it2->next();
2321 return static_cast<const SMDS_MeshFace *> (e);
2328 //=======================================================================
2329 //function : FindFace
2330 //purpose : quadratic quadrangle
2331 //=======================================================================
2333 const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2,
2334 int idnode3, int idnode4,
2335 int idnode5, int idnode6,
2336 int idnode7, int idnode8) const
2338 const SMDS_MeshNode * node1 = FindNode(idnode1);
2339 const SMDS_MeshNode * node2 = FindNode(idnode2);
2340 const SMDS_MeshNode * node3 = FindNode(idnode3);
2341 const SMDS_MeshNode * node4 = FindNode(idnode4);
2342 const SMDS_MeshNode * node5 = FindNode(idnode5);
2343 const SMDS_MeshNode * node6 = FindNode(idnode6);
2344 const SMDS_MeshNode * node7 = FindNode(idnode7);
2345 const SMDS_MeshNode * node8 = FindNode(idnode8);
2346 return FindFace(node1, node2, node3, node4, node5, node6, node7, node8);
2349 const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1,
2350 const SMDS_MeshNode *node2,
2351 const SMDS_MeshNode *node3,
2352 const SMDS_MeshNode *node4,
2353 const SMDS_MeshNode *node5,
2354 const SMDS_MeshNode *node6,
2355 const SMDS_MeshNode *node7,
2356 const SMDS_MeshNode *node8)
2358 if ( !node1 ) return 0;
2359 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Face);
2360 while(it1->more()) {
2361 const SMDS_MeshElement * e = it1->next();
2362 if ( e->NbNodes() == 8 ) {
2363 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
2364 while(it2->more()) {
2365 const SMDS_MeshElement* n = it2->next();
2380 return static_cast<const SMDS_MeshFace *> (e);
2387 //=======================================================================
2388 //function : FindElement
2390 //=======================================================================
2392 const SMDS_MeshElement* SMDS_Mesh::FindElement(int IDelem) const
2394 if ( IDelem <= 0 || IDelem >= (int)myCells.size() )
2398 return myCells[IDelem];
2401 //=======================================================================
2402 //function : FindFace
2403 //purpose : find polygon
2404 //=======================================================================
2406 const SMDS_MeshFace* SMDS_Mesh::FindFace (const vector<int>& nodes_ids) const
2408 int nbnodes = nodes_ids.size();
2409 vector<const SMDS_MeshNode *> poly_nodes (nbnodes);
2410 for (int inode = 0; inode < nbnodes; inode++) {
2411 const SMDS_MeshNode * node = FindNode(nodes_ids[inode]);
2412 if (node == NULL) return NULL;
2413 poly_nodes[inode] = node;
2415 return FindFace(poly_nodes);
2418 const SMDS_MeshFace* SMDS_Mesh::FindFace (const vector<const SMDS_MeshNode *>& nodes)
2420 return (const SMDS_MeshFace*) FindElement( nodes, SMDSAbs_Face );
2424 //================================================================================
2426 * \brief Return element based on all given nodes
2427 * \param nodes - node of element
2428 * \param type - type of element
2429 * \param noMedium - true if medium nodes of quadratic element are not included in <nodes>
2430 * \retval const SMDS_MeshElement* - found element or NULL
2432 //================================================================================
2434 const SMDS_MeshElement* SMDS_Mesh::FindElement (const vector<const SMDS_MeshNode *>& nodes,
2435 const SMDSAbs_ElementType type,
2436 const bool noMedium)
2438 if ( nodes.size() > 0 && nodes[0] )
2440 SMDS_ElemIteratorPtr itF = nodes[0]->GetInverseElementIterator(type);
2443 const SMDS_MeshElement* e = itF->next();
2444 int nbNodesToCheck = noMedium ? e->NbCornerNodes() : e->NbNodes();
2445 if ( nbNodesToCheck == (int)nodes.size() )
2447 for ( size_t i = 1; e && i < nodes.size(); ++i )
2449 int nodeIndex = e->GetNodeIndex( nodes[ i ]);
2450 if ( nodeIndex < 0 || nodeIndex >= nbNodesToCheck )
2461 //=======================================================================
2462 //function : DumpNodes
2464 //=======================================================================
2466 void SMDS_Mesh::DumpNodes() const
2468 SMDS_NodeIteratorPtr itnode=nodesIterator();
2469 while(itnode->more()) ; //MESSAGE(itnode->next());
2472 //=======================================================================
2473 //function : Dump0DElements
2475 //=======================================================================
2476 void SMDS_Mesh::Dump0DElements() const
2478 SMDS_ElemIteratorPtr it0d = elementsIterator(SMDSAbs_0DElement);
2479 while(it0d->more()) ; //MESSAGE(it0d->next());
2482 //=======================================================================
2483 //function : DumpEdges
2485 //=======================================================================
2487 void SMDS_Mesh::DumpEdges() const
2489 SMDS_EdgeIteratorPtr itedge=edgesIterator();
2490 while(itedge->more()) ; //MESSAGE(itedge->next());
2493 //=======================================================================
2494 //function : DumpFaces
2496 //=======================================================================
2498 void SMDS_Mesh::DumpFaces() const
2500 SMDS_FaceIteratorPtr itface=facesIterator();
2501 while(itface->more()) ; //MESSAGE(itface->next());
2504 //=======================================================================
2505 //function : DumpVolumes
2507 //=======================================================================
2509 void SMDS_Mesh::DumpVolumes() const
2511 SMDS_VolumeIteratorPtr itvol=volumesIterator();
2512 while(itvol->more()) ; //MESSAGE(itvol->next());
2515 //=======================================================================
2516 //function : DebugStats
2518 //=======================================================================
2520 void SMDS_Mesh::DebugStats() const
2522 MESSAGE("Debug stats of mesh : ");
2524 MESSAGE("===== NODES ====="<<NbNodes());
2525 MESSAGE("===== 0DELEMS ====="<<Nb0DElements());
2526 MESSAGE("===== EDGES ====="<<NbEdges());
2527 MESSAGE("===== FACES ====="<<NbFaces());
2528 MESSAGE("===== VOLUMES ====="<<NbVolumes());
2530 MESSAGE("End Debug stats of mesh ");
2534 SMDS_NodeIteratorPtr itnode=nodesIterator();
2535 int sizeofnodes = 0;
2536 int sizeoffaces = 0;
2538 while(itnode->more())
2540 const SMDS_MeshNode *node = itnode->next();
2542 sizeofnodes += sizeof(*node);
2544 SMDS_ElemIteratorPtr it = node->GetInverseElementIterator();
2547 const SMDS_MeshElement *me = it->next();
2548 sizeofnodes += sizeof(me);
2552 SMDS_FaceIteratorPtr itface=facesIterator();
2553 while(itface->more())
2555 const SMDS_MeshElement *face = itface->next();
2556 sizeoffaces += sizeof(*face);
2559 MESSAGE("total size of node elements = " << sizeofnodes);;
2560 MESSAGE("total size of face elements = " << sizeoffaces);;
2565 ///////////////////////////////////////////////////////////////////////////////
2566 /// Return the number of nodes
2567 ///////////////////////////////////////////////////////////////////////////////
2568 int SMDS_Mesh::NbNodes() const
2570 return myInfo.NbNodes();
2573 ///////////////////////////////////////////////////////////////////////////////
2574 /// Return the number of 0D elements
2575 ///////////////////////////////////////////////////////////////////////////////
2576 int SMDS_Mesh::Nb0DElements() const
2578 return myInfo.Nb0DElements();
2581 ///////////////////////////////////////////////////////////////////////////////
2582 /// Return the number of 0D elements
2583 ///////////////////////////////////////////////////////////////////////////////
2584 int SMDS_Mesh::NbBalls() const
2586 return myInfo.NbBalls();
2589 ///////////////////////////////////////////////////////////////////////////////
2590 /// Return the number of edges (including construction edges)
2591 ///////////////////////////////////////////////////////////////////////////////
2592 int SMDS_Mesh::NbEdges() const
2594 return myInfo.NbEdges();
2597 ///////////////////////////////////////////////////////////////////////////////
2598 /// Return the number of faces (including construction faces)
2599 ///////////////////////////////////////////////////////////////////////////////
2600 int SMDS_Mesh::NbFaces() const
2602 return myInfo.NbFaces();
2605 ///////////////////////////////////////////////////////////////////////////////
2606 /// Return the number of volumes
2607 ///////////////////////////////////////////////////////////////////////////////
2608 int SMDS_Mesh::NbVolumes() const
2610 return myInfo.NbVolumes();
2613 ///////////////////////////////////////////////////////////////////////////////
2614 /// Return the number of child mesh of this mesh.
2615 /// Note that the tree structure of SMDS_Mesh is unused in SMESH
2616 ///////////////////////////////////////////////////////////////////////////////
2617 int SMDS_Mesh::NbSubMesh() const
2619 return myChildren.size();
2622 ///////////////////////////////////////////////////////////////////////////////
2623 /// Destroy the mesh and all its elements
2624 /// All pointer on elements owned by this mesh become illegals.
2625 ///////////////////////////////////////////////////////////////////////////////
2626 SMDS_Mesh::~SMDS_Mesh()
2628 list<SMDS_Mesh*>::iterator itc=myChildren.begin();
2629 while(itc!=myChildren.end())
2637 delete myNodeIDFactory;
2638 delete myElementIDFactory;
2642 SMDS_ElemIteratorPtr eIt = elementsIterator();
2643 while ( eIt->more() )
2645 const SMDS_MeshElement *elem = eIt->next();
2646 myElementIDFactory->ReleaseID(elem->GetID(), elem->getVtkId());
2648 SMDS_NodeIteratorPtr itn = nodesIterator();
2651 const SMDS_MeshNode *node = itn->next();
2652 ((SMDS_MeshNode*)node)->SetPosition(SMDS_SpacePosition::originSpacePosition());
2653 myNodeIDFactory->ReleaseID(node->GetID(), node->getVtkId());
2659 delete myVolumePool;
2665 //================================================================================
2667 * \brief Clear all data
2669 //================================================================================
2671 void SMDS_Mesh::Clear()
2675 SMDS_ElemIteratorPtr eIt = elementsIterator();
2676 while ( eIt->more() )
2678 const SMDS_MeshElement *elem = eIt->next();
2679 myElementIDFactory->ReleaseID(elem->GetID(), elem->getVtkId());
2681 SMDS_NodeIteratorPtr itn = nodesIterator();
2684 const SMDS_MeshNode *node = itn->next();
2685 myNodeIDFactory->ReleaseID(node->GetID(), node->getVtkId());
2690 myNodeIDFactory->Clear();
2691 myElementIDFactory->Clear();
2694 // SMDS_ElemIteratorPtr itv = elementsIterator();
2695 // while (itv->more())
2697 // SMDS_MeshElement* elem = (SMDS_MeshElement*)(itv->next());
2698 // SMDSAbs_ElementType aType = elem->GetType();
2701 // case SMDSAbs_0DElement:
2704 // case SMDSAbs_Edge:
2705 // myEdgePool->destroy(static_cast<SMDS_VtkEdge*>(elem));
2707 // case SMDSAbs_Face:
2708 // myFacePool->destroy(static_cast<SMDS_VtkFace*>(elem));
2710 // case SMDSAbs_Volume:
2711 // myVolumePool->destroy(static_cast<SMDS_VtkVolume*>(elem));
2713 // case SMDSAbs_Ball:
2714 // myBallPool->destroy(static_cast<SMDS_BallElement*>(elem));
2720 myVolumePool->clear();
2721 myFacePool->clear();
2722 myEdgePool->clear();
2723 myBallPool->clear();
2725 clearVector( myCells );
2726 clearVector( myCellIdVtkToSmds );
2728 SMDS_NodeIteratorPtr itn = nodesIterator();
2731 SMDS_MeshNode *node = (SMDS_MeshNode*)(itn->next());
2732 node->SetPosition(SMDS_SpacePosition::originSpacePosition());
2733 //myNodePool->destroy(node);
2735 myNodePool->clear();
2736 clearVector( myNodes );
2738 list<SMDS_Mesh*>::iterator itc=myChildren.begin();
2739 while(itc!=myChildren.end())
2750 myGrid->Initialize();
2752 vtkPoints* points = vtkPoints::New();
2753 // rnv: to fix bug "21125: EDF 1233 SMESH: Degrardation of precision in a test case for quadratic conversion"
2754 // using double type for storing coordinates of nodes instead float.
2755 points->SetDataType(VTK_DOUBLE);
2756 points->SetNumberOfPoints(0 /*SMDS_Mesh::chunkSize*/);
2757 myGrid->SetPoints( points );
2759 myGrid->DeleteLinks();
2762 ///////////////////////////////////////////////////////////////////////////////
2763 /// Return true if this mesh create faces with edges.
2764 /// A false returned value mean that faces are created with nodes. A concequence
2765 /// is, iteration on edges (SMDS_Element::edgesIterator) will be unavailable.
2766 ///////////////////////////////////////////////////////////////////////////////
2767 bool SMDS_Mesh::hasConstructionEdges()
2769 return myHasConstructionEdges;
2772 ///////////////////////////////////////////////////////////////////////////////
2773 /// Return true if this mesh create volumes with faces
2774 /// A false returned value mean that volumes are created with nodes or edges.
2775 /// (see hasConstructionEdges)
2776 /// A concequence is, iteration on faces (SMDS_Element::facesIterator) will be
2778 ///////////////////////////////////////////////////////////////////////////////
2779 bool SMDS_Mesh::hasConstructionFaces()
2781 return myHasConstructionFaces;
2784 ///////////////////////////////////////////////////////////////////////////////
2785 /// Return true if nodes are linked to the finit elements, they are belonging to.
2786 /// Currently, It always return true.
2787 ///////////////////////////////////////////////////////////////////////////////
2788 bool SMDS_Mesh::hasInverseElements()
2790 return myHasInverseElements;
2793 ///////////////////////////////////////////////////////////////////////////////
2794 /// Make this mesh creating construction edges (see hasConstructionEdges)
2795 /// @param b true to have construction edges, else false.
2796 ///////////////////////////////////////////////////////////////////////////////
2797 void SMDS_Mesh::setConstructionEdges(bool b)
2799 myHasConstructionEdges=b;
2802 ///////////////////////////////////////////////////////////////////////////////
2803 /// Make this mesh creating construction faces (see hasConstructionFaces)
2804 /// @param b true to have construction faces, else false.
2805 ///////////////////////////////////////////////////////////////////////////////
2806 void SMDS_Mesh::setConstructionFaces(bool b)
2808 myHasConstructionFaces=b;
2811 ///////////////////////////////////////////////////////////////////////////////
2812 /// Make this mesh creating link from nodes to elements (see hasInverseElements)
2813 /// @param b true to link nodes to elements, else false.
2814 ///////////////////////////////////////////////////////////////////////////////
2815 void SMDS_Mesh::setInverseElements(bool b)
2817 if(!b) MESSAGE("Error : inverseElement=false not implemented");
2818 myHasInverseElements=b;
2823 //================================================================================
2825 * \brief Iterator on elements in id increasing order
2827 //================================================================================
2829 template <typename ELEM=const SMDS_MeshElement*>
2830 class IdSortedIterator : public SMDS_Iterator<ELEM>
2832 SMDS_MeshElementIDFactory& myIDFact;
2833 int myID, myMaxID, myNbFound, myTotalNb;
2834 SMDSAbs_ElementType myType;
2838 IdSortedIterator(const SMDS_MeshElementIDFactory& fact,
2839 const SMDSAbs_ElementType type, // SMDSAbs_All NOT allowed!!!
2842 myID(1), myMaxID( myIDFact.GetMaxID() ),myNbFound(0), myTotalNb( totalNb ),
2854 ELEM current = myElem;
2856 for ( myElem = 0; !myElem && myNbFound < myTotalNb && myID <= myMaxID; ++myID )
2857 if ((myElem = (ELEM) myIDFact.MeshElement( myID ))
2858 && myElem->GetType() != myType )
2861 myNbFound += bool(myElem);
2867 //================================================================================
2869 * \brief Iterator on vector of elements, possibly being resized while iteration
2871 //================================================================================
2873 template<typename RETURN_VALUE,
2874 typename VECTOR_VALUE=SMDS_MeshCell*,
2875 typename VALUE_FILTER=SMDS::NonNullFilter<VECTOR_VALUE> >
2876 class ElemVecIterator: public SMDS_Iterator<RETURN_VALUE>
2878 const std::vector<VECTOR_VALUE>& _vector;
2881 VALUE_FILTER _filter;
2883 ElemVecIterator(const std::vector<VECTOR_VALUE>& vec,
2884 const VALUE_FILTER& filter=VALUE_FILTER() )
2885 :_vector( vec ), _index(0), _more( !vec.empty() ), _filter( filter )
2887 if ( _more && !_filter( _vector[ _index ]))
2894 virtual RETURN_VALUE next()
2896 if ( !_more ) return NULL;
2897 VECTOR_VALUE current = _vector[ _index ];
2899 while ( !_more && ++_index < _vector.size() )
2900 _more = _filter( _vector[ _index ]);
2901 return (RETURN_VALUE) current;
2906 ///////////////////////////////////////////////////////////////////////////////
2907 /// Return an iterator on nodes of the current mesh factory
2908 ///////////////////////////////////////////////////////////////////////////////
2910 SMDS_NodeIteratorPtr SMDS_Mesh::nodesIterator(bool idInceasingOrder) const
2912 // naturally always sorted by ID
2913 typedef ElemVecIterator<const SMDS_MeshNode*, SMDS_MeshNode*> TIterator;
2914 return SMDS_NodeIteratorPtr( new TIterator(myNodes));
2917 SMDS_ElemIteratorPtr SMDS_Mesh::elementGeomIterator(SMDSAbs_GeometryType type) const
2919 // naturally always sorted by ID
2920 typedef ElemVecIterator
2921 < const SMDS_MeshElement*, SMDS_MeshCell*, SMDS_MeshElement::GeomFilter > TIterator;
2922 return SMDS_ElemIteratorPtr
2923 (new TIterator(myCells, SMDS_MeshElement::GeomFilter( type )));
2926 SMDS_ElemIteratorPtr SMDS_Mesh::elementEntityIterator(SMDSAbs_EntityType type) const
2928 if ( type == SMDSEntity_Node )
2930 typedef ElemVecIterator<const SMDS_MeshElement*, SMDS_MeshNode*> TIterator;
2931 return SMDS_ElemIteratorPtr( new TIterator(myNodes));
2933 // naturally always sorted by ID
2934 typedef ElemVecIterator
2935 < const SMDS_MeshElement*, SMDS_MeshCell*, SMDS_MeshElement::EntityFilter > TIterator;
2936 return SMDS_ElemIteratorPtr
2937 (new TIterator(myCells, SMDS_MeshElement::EntityFilter( type )));
2940 ///////////////////////////////////////////////////////////////////////////////
2941 /// Return an iterator on elements of the current mesh factory
2942 ///////////////////////////////////////////////////////////////////////////////
2943 SMDS_ElemIteratorPtr SMDS_Mesh::elementsIterator(SMDSAbs_ElementType type) const
2945 // naturally always sorted by ID
2949 return SMDS_ElemIteratorPtr (new ElemVecIterator<const SMDS_MeshElement*>(myCells));
2952 return SMDS_ElemIteratorPtr
2953 ( new ElemVecIterator<const SMDS_MeshElement*, SMDS_MeshNode*>( myNodes ));
2956 typedef ElemVecIterator
2957 < const SMDS_MeshElement*, SMDS_MeshCell*, SMDS_MeshElement::TypeFilter > TIterator;
2958 return SMDS_ElemIteratorPtr (new TIterator(myCells, SMDS_MeshElement::TypeFilter( type )));
2960 return SMDS_ElemIteratorPtr();
2963 ///////////////////////////////////////////////////////////////////////////////
2964 ///Return an iterator on edges of the current mesh.
2965 ///////////////////////////////////////////////////////////////////////////////
2967 SMDS_EdgeIteratorPtr SMDS_Mesh::edgesIterator(bool idInceasingOrder) const
2969 // naturally always sorted by ID
2970 typedef ElemVecIterator
2971 < const SMDS_MeshEdge*, SMDS_MeshCell*, SMDS_MeshElement::TypeFilter > TIterator;
2972 return SMDS_EdgeIteratorPtr
2973 (new TIterator(myCells, SMDS_MeshElement::TypeFilter( SMDSAbs_Edge )));
2976 ///////////////////////////////////////////////////////////////////////////////
2977 ///Return an iterator on faces of the current mesh.
2978 ///////////////////////////////////////////////////////////////////////////////
2980 SMDS_FaceIteratorPtr SMDS_Mesh::facesIterator(bool idInceasingOrder) const
2982 // naturally always sorted by ID
2983 typedef ElemVecIterator
2984 < const SMDS_MeshFace*, SMDS_MeshCell*, SMDS_MeshElement::TypeFilter > TIterator;
2985 return SMDS_FaceIteratorPtr
2986 (new TIterator(myCells, SMDS_MeshElement::TypeFilter( SMDSAbs_Face )));
2989 ///////////////////////////////////////////////////////////////////////////////
2990 ///Return an iterator on volumes of the current mesh.
2991 ///////////////////////////////////////////////////////////////////////////////
2993 SMDS_VolumeIteratorPtr SMDS_Mesh::volumesIterator(bool idInceasingOrder) const
2995 // naturally always sorted by ID
2996 typedef ElemVecIterator
2997 < const SMDS_MeshVolume*, SMDS_MeshCell*, SMDS_MeshElement::TypeFilter > TIterator;
2998 return SMDS_VolumeIteratorPtr
2999 (new TIterator(myCells, SMDS_MeshElement::TypeFilter( SMDSAbs_Volume )));
3002 ///////////////////////////////////////////////////////////////////////////////
3003 /// Do intersection of sets (more than 2)
3004 ///////////////////////////////////////////////////////////////////////////////
3005 static set<const SMDS_MeshElement*> * intersectionOfSets(
3006 set<const SMDS_MeshElement*> vs[], int numberOfSets)
3008 set<const SMDS_MeshElement*>* rsetA=new set<const SMDS_MeshElement*>(vs[0]);
3009 set<const SMDS_MeshElement*>* rsetB;
3011 for(int i=0; i<numberOfSets-1; i++)
3013 rsetB=new set<const SMDS_MeshElement*>();
3015 rsetA->begin(), rsetA->end(),
3016 vs[i+1].begin(), vs[i+1].end(),
3017 inserter(*rsetB, rsetB->begin()));
3024 ///////////////////////////////////////////////////////////////////////////////
3025 /// Return the list of finite elements owning the given element: elements
3026 /// containing all the nodes of the given element, for instance faces and
3027 /// volumes containing a given edge.
3028 ///////////////////////////////////////////////////////////////////////////////
3029 static set<const SMDS_MeshElement*> * getFinitElements(const SMDS_MeshElement * element)
3031 int numberOfSets=element->NbNodes();
3032 set<const SMDS_MeshElement*> *initSet = new set<const SMDS_MeshElement*>[numberOfSets];
3034 SMDS_ElemIteratorPtr itNodes=element->nodesIterator();
3037 while ( itNodes->more() )
3039 const SMDS_MeshElement* node = itNodes->next();
3041 const SMDS_MeshNode * n=static_cast<const SMDS_MeshNode*>(node);
3042 SMDS_ElemIteratorPtr itFe = n->GetInverseElementIterator();
3044 while ( itFe->more() )
3046 const SMDS_MeshElement* elem = itFe->next();
3048 initSet[i].insert(elem);
3053 set<const SMDS_MeshElement*> *retSet = intersectionOfSets( initSet, numberOfSets );
3058 ///////////////////////////////////////////////////////////////////////////////
3059 /// Return the list of nodes used only by the given elements
3060 ///////////////////////////////////////////////////////////////////////////////
3061 static set<const SMDS_MeshElement*> * getExclusiveNodes(set<const SMDS_MeshElement*>& elements)
3063 set<const SMDS_MeshElement*> * toReturn=new set<const SMDS_MeshElement*>();
3064 set<const SMDS_MeshElement*>::iterator itElements=elements.begin();
3066 while(itElements!=elements.end())
3068 SMDS_ElemIteratorPtr itNodes = (*itElements)->nodesIterator();
3071 while(itNodes->more())
3073 const SMDS_MeshNode * n=static_cast<const SMDS_MeshNode*>(itNodes->next());
3074 SMDS_ElemIteratorPtr itFe = n->GetInverseElementIterator();
3075 set<const SMDS_MeshElement*> s;
3077 s.insert(itFe->next());
3078 if(s==elements) toReturn->insert(n);
3084 ///////////////////////////////////////////////////////////////////////////////
3085 ///Find the children of an element that are made of given nodes
3086 ///@param setOfChildren The set in which matching children will be inserted
3087 ///@param element The element were to search matching children
3088 ///@param nodes The nodes that the children must have to be selected
3089 ///////////////////////////////////////////////////////////////////////////////
3090 void SMDS_Mesh::addChildrenWithNodes(set<const SMDS_MeshElement*>& setOfChildren,
3091 const SMDS_MeshElement * element,
3092 set<const SMDS_MeshElement*>& nodes)
3094 switch(element->GetType())
3097 MESSAGE("Internal Error: This should not happen");
3099 case SMDSAbs_0DElement:
3106 SMDS_ElemIteratorPtr itn=element->nodesIterator();
3109 const SMDS_MeshElement * e=itn->next();
3110 if(nodes.find(e)!=nodes.end())
3112 setOfChildren.insert(element);
3119 SMDS_ElemIteratorPtr itn=element->nodesIterator();
3122 const SMDS_MeshElement * e=itn->next();
3123 if(nodes.find(e)!=nodes.end())
3125 setOfChildren.insert(element);
3129 if(hasConstructionEdges())
3131 SMDS_ElemIteratorPtr ite=element->edgesIterator();
3133 addChildrenWithNodes(setOfChildren, ite->next(), nodes);
3136 case SMDSAbs_Volume:
3138 if(hasConstructionFaces())
3140 SMDS_ElemIteratorPtr ite=element->facesIterator();
3142 addChildrenWithNodes(setOfChildren, ite->next(), nodes);
3144 else if(hasConstructionEdges())
3146 SMDS_ElemIteratorPtr ite=element->edgesIterator();
3148 addChildrenWithNodes(setOfChildren, ite->next(), nodes);
3151 case SMDSAbs_NbElementTypes:
3152 case SMDSAbs_All: break;
3156 ///////////////////////////////////////////////////////////////////////////////
3157 ///@param elem The element to delete
3158 ///@param removenodes if true remaining nodes will be removed
3159 ///////////////////////////////////////////////////////////////////////////////
3160 void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem,
3161 const bool removenodes)
3163 list<const SMDS_MeshElement *> removedElems;
3164 list<const SMDS_MeshElement *> removedNodes;
3165 RemoveElement( elem, removedElems, removedNodes, removenodes );
3168 ///////////////////////////////////////////////////////////////////////////////
3169 ///@param elem The element to delete
3170 ///@param removedElems to be filled with all removed elements
3171 ///@param removedNodes to be filled with all removed nodes
3172 ///@param removenodes if true remaining nodes will be removed
3173 ///////////////////////////////////////////////////////////////////////////////
3174 void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem,
3175 list<const SMDS_MeshElement *>& removedElems,
3176 list<const SMDS_MeshElement *>& removedNodes,
3179 // get finite elements built on elem
3180 set<const SMDS_MeshElement*> * s1;
3181 if ( (elem->GetType() == SMDSAbs_0DElement)
3182 || ((elem->GetType() == SMDSAbs_Edge) && !hasConstructionEdges())
3183 || ((elem->GetType() == SMDSAbs_Face) && !hasConstructionFaces())
3184 || (elem->GetType() == SMDSAbs_Volume) )
3186 s1 = new set<const SMDS_MeshElement*> ();
3190 s1 = getFinitElements(elem);
3192 // get exclusive nodes (which would become free afterwards)
3193 set<const SMDS_MeshElement*> * s2;
3194 if (elem->GetType() == SMDSAbs_Node) // a node is removed
3196 // do not remove nodes except elem
3197 s2 = new set<const SMDS_MeshElement*> ();
3202 s2 = getExclusiveNodes(*s1);
3204 // form the set of finite and construction elements to remove
3205 set<const SMDS_MeshElement*> s3;
3206 set<const SMDS_MeshElement*>::iterator it = s1->begin();
3207 while (it != s1->end())
3209 addChildrenWithNodes(s3, *it, *s2);
3213 if (elem->GetType() != SMDSAbs_Node)
3216 // remove finite and construction elements
3218 while (it != s3.end())
3220 // Remove element from <InverseElements> of its nodes
3221 SMDS_ElemIteratorPtr itn = (*it)->nodesIterator();
3224 SMDS_MeshNode * n = static_cast<SMDS_MeshNode *> (const_cast<SMDS_MeshElement *> (itn->next()));
3225 n->RemoveInverseElement((*it));
3227 int IdToRemove = (*it)->GetID();
3228 int vtkid = (*it)->getVtkId();
3229 switch ((*it)->GetType())
3232 MYASSERT("Internal Error: This should not happen");
3234 case SMDSAbs_0DElement:
3235 if (IdToRemove >= 0)
3237 myCells[IdToRemove] = 0; // -PR- ici ou dans myElementIDFactory->ReleaseID ?
3240 removedElems.push_back((*it));
3241 myElementIDFactory->ReleaseID(IdToRemove, vtkid);
3245 if (IdToRemove >= 0)
3247 myCells[IdToRemove] = 0;
3248 myInfo.RemoveEdge(*it);
3250 removedElems.push_back((*it));
3251 myElementIDFactory->ReleaseID(IdToRemove, vtkid);
3252 if (const SMDS_VtkEdge* vtkElem = dynamic_cast<const SMDS_VtkEdge*>(*it))
3253 myEdgePool->destroy((SMDS_VtkEdge*) vtkElem);
3255 ((SMDS_MeshElement*) *it)->init( -1, -1, -1 ); // avoid reuse
3260 if (IdToRemove >= 0)
3262 myCells[IdToRemove] = 0;
3263 myInfo.RemoveFace(*it);
3265 removedElems.push_back((*it));
3266 myElementIDFactory->ReleaseID(IdToRemove, vtkid);
3267 if (const SMDS_VtkFace* vtkElem = dynamic_cast<const SMDS_VtkFace*>(*it))
3268 myFacePool->destroy((SMDS_VtkFace*) vtkElem);
3270 ((SMDS_MeshElement*) *it)->init( -1, -1, -1 ); // avoid reuse
3274 case SMDSAbs_Volume:
3275 if (IdToRemove >= 0)
3277 myCells[IdToRemove] = 0;
3278 myInfo.RemoveVolume(*it);
3280 removedElems.push_back((*it));
3281 myElementIDFactory->ReleaseID(IdToRemove, vtkid);
3282 if (const SMDS_VtkVolume* vtkElem = dynamic_cast<const SMDS_VtkVolume*>(*it))
3283 myVolumePool->destroy((SMDS_VtkVolume*) vtkElem);
3285 ((SMDS_MeshElement*) *it)->init( -1, -1, -1 ); // avoid reuse
3290 if (IdToRemove >= 0)
3292 myCells[IdToRemove] = 0;
3295 removedElems.push_back((*it));
3296 myElementIDFactory->ReleaseID(IdToRemove, vtkid);
3297 if (const SMDS_BallElement* vtkElem = dynamic_cast<const SMDS_BallElement*>(*it))
3298 myBallPool->destroy(const_cast<SMDS_BallElement*>( vtkElem ));
3300 ((SMDS_MeshElement*) *it)->init( -1, -1, -1 ); // avoid reuse
3305 case SMDSAbs_All: // avoid compilation warning
3306 case SMDSAbs_NbElementTypes: break;
3310 this->myGrid->GetCellTypesArray()->SetValue(vtkid, VTK_EMPTY_CELL);
3315 // remove exclusive (free) nodes
3319 while (it != s2->end())
3321 int IdToRemove = (*it)->GetID();
3322 if (IdToRemove >= 0)
3324 myNodes[IdToRemove] = 0;
3327 myNodeIDFactory->ReleaseID((*it)->GetID(), (*it)->getVtkId());
3328 removedNodes.push_back((*it));
3329 if (const SMDS_MeshNode* vtkElem = dynamic_cast<const SMDS_MeshNode*>(*it))
3331 ((SMDS_MeshNode*)vtkElem)->SetPosition(SMDS_SpacePosition::originSpacePosition());
3332 myNodePool->destroy((SMDS_MeshNode*) vtkElem);
3345 ///////////////////////////////////////////////////////////////////////////////
3346 ///@param elem The element to delete
3347 ///////////////////////////////////////////////////////////////////////////////
3348 void SMDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elem)
3350 int elemId = elem->GetID();
3351 int vtkId = elem->getVtkId();
3352 SMDSAbs_ElementType aType = elem->GetType();
3353 SMDS_MeshElement* todest = (SMDS_MeshElement*)(elem);
3354 if (aType == SMDSAbs_Node) {
3355 // only free node can be removed by this method
3356 const SMDS_MeshNode* n = static_cast<SMDS_MeshNode*>(todest);
3357 SMDS_ElemIteratorPtr itFe = n->GetInverseElementIterator();
3358 if (!itFe->more()) { // free node
3359 myNodes[elemId] = 0;
3361 ((SMDS_MeshNode*) n)->SetPosition(SMDS_SpacePosition::originSpacePosition());
3362 ((SMDS_MeshNode*) n)->SMDS_MeshElement::init( -1, -1, -1 ); // avoid reuse
3363 myNodePool->destroy(static_cast<SMDS_MeshNode*>(todest));
3364 myNodeIDFactory->ReleaseID(elemId, vtkId);
3367 if (hasConstructionEdges() || hasConstructionFaces())
3368 // this methods is only for meshes without descendants
3371 // Remove element from <InverseElements> of its nodes
3372 SMDS_ElemIteratorPtr itn = elem->nodesIterator();
3373 while (itn->more()) {
3374 SMDS_MeshNode * n = static_cast<SMDS_MeshNode *>
3375 (const_cast<SMDS_MeshElement *>(itn->next()));
3376 n->RemoveInverseElement(elem);
3379 // in meshes without descendants elements are always free
3381 case SMDSAbs_0DElement:
3382 myCells[elemId] = 0;
3383 myInfo.remove(elem);
3388 myCells[elemId] = 0;
3389 myInfo.RemoveEdge(elem);
3390 myEdgePool->destroy(static_cast<SMDS_VtkEdge*>(todest));
3393 myCells[elemId] = 0;
3394 myInfo.RemoveFace(elem);
3395 myFacePool->destroy(static_cast<SMDS_VtkFace*>(todest));
3397 case SMDSAbs_Volume:
3398 myCells[elemId] = 0;
3399 myInfo.RemoveVolume(elem);
3400 myVolumePool->destroy(static_cast<SMDS_VtkVolume*>(todest));
3403 myCells[elemId] = 0;
3404 myInfo.remove(elem);
3405 myBallPool->destroy(static_cast<SMDS_BallElement*>(todest));
3410 myElementIDFactory->ReleaseID(elemId, vtkId);
3412 this->myGrid->GetCellTypesArray()->SetValue(vtkId, VTK_EMPTY_CELL);
3413 // --- to do: keep vtkid in a list of reusable cells
3416 ((SMDS_MeshElement*) elem)->init( -1, -1, -1 ); // avoid reuse
3421 * Checks if the element is present in mesh.
3422 * Useful to determine dead pointers.
3424 bool SMDS_Mesh::Contains (const SMDS_MeshElement* elem) const
3426 // we should not rely on validity of *elem, so iterate on containers
3427 // of all types in the hope of finding <elem> somewhere there
3428 SMDS_NodeIteratorPtr itn = nodesIterator();
3430 if (elem == itn->next())
3432 SMDS_ElemIteratorPtr ite = elementsIterator();
3434 if (elem == ite->next())
3439 //=======================================================================
3440 //function : MaxNodeID
3442 //=======================================================================
3444 int SMDS_Mesh::MaxNodeID() const
3446 return myNodeIDFactory->GetMaxID();
3449 //=======================================================================
3450 //function : MinNodeID
3452 //=======================================================================
3454 int SMDS_Mesh::MinNodeID() const
3456 return myNodeIDFactory->GetMinID();
3459 //=======================================================================
3460 //function : MaxElementID
3462 //=======================================================================
3464 int SMDS_Mesh::MaxElementID() const
3466 return myElementIDFactory->GetMaxID();
3469 //=======================================================================
3470 //function : MinElementID
3472 //=======================================================================
3474 int SMDS_Mesh::MinElementID() const
3476 return myElementIDFactory->GetMinID();
3479 //=======================================================================
3480 //function : Renumber
3481 //purpose : Renumber all nodes or elements.
3482 //=======================================================================
3484 void SMDS_Mesh::Renumber (const bool isNodes, const int startID, const int deltaID)
3489 SMDS_MeshNodeIDFactory * idFactory =
3490 isNodes ? myNodeIDFactory : myElementIDFactory;
3492 // get existing elements in the order of ID increasing
3493 map<int,SMDS_MeshElement*> elemMap;
3494 SMDS_ElemIteratorPtr idElemIt = idFactory->elementsIterator();
3495 while ( idElemIt->more() ) {
3496 SMDS_MeshElement* elem = const_cast<SMDS_MeshElement*>(idElemIt->next());
3497 int id = elem->GetID();
3498 elemMap.insert(map<int,SMDS_MeshElement*>::value_type(id, elem));
3500 // release their ids
3501 map<int,SMDS_MeshElement*>::iterator elemIt = elemMap.begin();
3503 // for ( ; elemIt != elemMap.end(); elemIt++ )
3505 // int id = (*elemIt).first;
3506 // idFactory->ReleaseID( id );
3510 elemIt = elemMap.begin();
3511 for ( ; elemIt != elemMap.end(); elemIt++ )
3513 idFactory->BindID( ID, (*elemIt).second );
3518 //=======================================================================
3519 //function : GetElementType
3520 //purpose : Return type of element or node with id
3521 //=======================================================================
3523 SMDSAbs_ElementType SMDS_Mesh::GetElementType( const int id, const bool iselem ) const
3525 SMDS_MeshElement* elem = 0;
3527 elem = myElementIDFactory->MeshElement( id );
3529 elem = myNodeIDFactory->MeshElement( id );
3533 //throw SALOME_Exception(LOCALIZED ("this element isn't exist"));
3537 return elem->GetType();
3542 //********************************************************************
3543 //********************************************************************
3544 //******** *********
3545 //***** Methods for addition of quadratic elements ******
3546 //******** *********
3547 //********************************************************************
3548 //********************************************************************
3550 //=======================================================================
3551 //function : AddEdgeWithID
3553 //=======================================================================
3554 SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(int n1, int n2, int n12, int ID)
3556 return SMDS_Mesh::AddEdgeWithID
3557 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1),
3558 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2),
3559 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
3563 //=======================================================================
3564 //function : AddEdge
3566 //=======================================================================
3567 SMDS_MeshEdge* SMDS_Mesh::AddEdge(const SMDS_MeshNode* n1,
3568 const SMDS_MeshNode* n2,
3569 const SMDS_MeshNode* n12)
3571 return SMDS_Mesh::AddEdgeWithID(n1, n2, n12, myElementIDFactory->GetFreeID());
3574 //=======================================================================
3575 //function : AddEdgeWithID
3577 //=======================================================================
3578 SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
3579 const SMDS_MeshNode * n2,
3580 const SMDS_MeshNode * n12,
3583 if ( !n1 || !n2 || !n12 ) return 0;
3585 // --- retrieve nodes ID
3586 myNodeIds.resize(3);
3587 myNodeIds[0] = n1->getVtkId();
3588 myNodeIds[1] = n2->getVtkId();
3589 myNodeIds[2] = n12->getVtkId();
3591 SMDS_MeshEdge * edge = 0;
3592 SMDS_VtkEdge *edgevtk = myEdgePool->getNew();
3593 edgevtk->init(myNodeIds, this);
3594 if (!this->registerElement(ID,edgevtk))
3596 this->myGrid->GetCellTypesArray()->SetValue(edgevtk->getVtkId(), VTK_EMPTY_CELL);
3597 myEdgePool->destroy(edgevtk);
3601 adjustmyCellsCapacity(ID);
3603 myInfo.myNbQuadEdges++;
3605 // if (!registerElement(ID, edge)) {
3606 // RemoveElement(edge, false);
3614 //=======================================================================
3615 //function : AddFace
3617 //=======================================================================
3618 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
3619 const SMDS_MeshNode * n2,
3620 const SMDS_MeshNode * n3,
3621 const SMDS_MeshNode * n12,
3622 const SMDS_MeshNode * n23,
3623 const SMDS_MeshNode * n31)
3625 return SMDS_Mesh::AddFaceWithID(n1,n2,n3,n12,n23,n31,
3626 myElementIDFactory->GetFreeID());
3629 //=======================================================================
3630 //function : AddFaceWithID
3632 //=======================================================================
3633 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int n1, int n2, int n3,
3634 int n12,int n23,int n31, int ID)
3636 return SMDS_Mesh::AddFaceWithID
3637 ((SMDS_MeshNode *)myNodeIDFactory->MeshElement(n1) ,
3638 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n2) ,
3639 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n3) ,
3640 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n12),
3641 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n23),
3642 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n31),
3646 //=======================================================================
3647 //function : AddFaceWithID
3649 //=======================================================================
3650 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
3651 const SMDS_MeshNode * n2,
3652 const SMDS_MeshNode * n3,
3653 const SMDS_MeshNode * n12,
3654 const SMDS_MeshNode * n23,
3655 const SMDS_MeshNode * n31,
3658 if ( !n1 || !n2 || !n3 || !n12 || !n23 || !n31) return 0;
3659 if(hasConstructionEdges()) {
3660 // creation quadratic edges - not implemented
3665 // --- retrieve nodes ID
3666 myNodeIds.resize(6);
3667 myNodeIds[0] = n1->getVtkId();
3668 myNodeIds[1] = n2->getVtkId();
3669 myNodeIds[2] = n3->getVtkId();
3670 myNodeIds[3] = n12->getVtkId();
3671 myNodeIds[4] = n23->getVtkId();
3672 myNodeIds[5] = n31->getVtkId();
3674 SMDS_MeshFace * face = 0;
3675 SMDS_VtkFace *facevtk = myFacePool->getNew();
3676 facevtk->init(myNodeIds, this);
3677 if (!this->registerElement(ID,facevtk))
3679 this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL);
3680 myFacePool->destroy(facevtk);
3684 adjustmyCellsCapacity(ID);
3686 myInfo.myNbQuadTriangles++;
3688 // if (!registerElement(ID, face)) {
3689 // RemoveElement(face, false);
3697 //=======================================================================
3698 //function : AddFace
3700 //=======================================================================
3701 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
3702 const SMDS_MeshNode * n2,
3703 const SMDS_MeshNode * n3,
3704 const SMDS_MeshNode * n12,
3705 const SMDS_MeshNode * n23,
3706 const SMDS_MeshNode * n31,
3707 const SMDS_MeshNode * nCenter)
3709 return SMDS_Mesh::AddFaceWithID(n1,n2,n3,n12,n23,n31,nCenter,
3710 myElementIDFactory->GetFreeID());
3713 //=======================================================================
3714 //function : AddFaceWithID
3716 //=======================================================================
3717 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int n1, int n2, int n3,
3718 int n12,int n23,int n31, int nCenter, int ID)
3720 return SMDS_Mesh::AddFaceWithID
3721 ((SMDS_MeshNode *)myNodeIDFactory->MeshElement(n1) ,
3722 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n2) ,
3723 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n3) ,
3724 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n12),
3725 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n23),
3726 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n31),
3727 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nCenter),
3731 //=======================================================================
3732 //function : AddFaceWithID
3734 //=======================================================================
3735 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
3736 const SMDS_MeshNode * n2,
3737 const SMDS_MeshNode * n3,
3738 const SMDS_MeshNode * n12,
3739 const SMDS_MeshNode * n23,
3740 const SMDS_MeshNode * n31,
3741 const SMDS_MeshNode * nCenter,
3744 if ( !n1 || !n2 || !n3 || !n12 || !n23 || !n31 || !nCenter) return 0;
3745 if(hasConstructionEdges()) {
3746 // creation quadratic edges - not implemented
3751 // --- retrieve nodes ID
3752 myNodeIds.resize(7);
3753 myNodeIds[0] = n1->getVtkId();
3754 myNodeIds[1] = n2->getVtkId();
3755 myNodeIds[2] = n3->getVtkId();
3756 myNodeIds[3] = n12->getVtkId();
3757 myNodeIds[4] = n23->getVtkId();
3758 myNodeIds[5] = n31->getVtkId();
3759 myNodeIds[6] = nCenter->getVtkId();
3761 SMDS_MeshFace * face = 0;
3762 SMDS_VtkFace *facevtk = myFacePool->getNew();
3763 facevtk->init(myNodeIds, this);
3764 if (!this->registerElement(ID,facevtk))
3766 this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL);
3767 myFacePool->destroy(facevtk);
3771 adjustmyCellsCapacity(ID);
3773 myInfo.myNbBiQuadTriangles++;
3775 // if (!registerElement(ID, face)) {
3776 // RemoveElement(face, false);
3784 //=======================================================================
3785 //function : AddFace
3787 //=======================================================================
3788 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
3789 const SMDS_MeshNode * n2,
3790 const SMDS_MeshNode * n3,
3791 const SMDS_MeshNode * n4,
3792 const SMDS_MeshNode * n12,
3793 const SMDS_MeshNode * n23,
3794 const SMDS_MeshNode * n34,
3795 const SMDS_MeshNode * n41)
3797 return SMDS_Mesh::AddFaceWithID(n1,n2,n3,n4,n12,n23,n34,n41,
3798 myElementIDFactory->GetFreeID());
3801 //=======================================================================
3802 //function : AddFaceWithID
3804 //=======================================================================
3805 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int n4,
3806 int n12,int n23,int n34,int n41, int ID)
3808 return SMDS_Mesh::AddFaceWithID
3809 ((SMDS_MeshNode *)myNodeIDFactory->MeshElement(n1) ,
3810 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n2) ,
3811 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n3) ,
3812 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n4) ,
3813 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n12),
3814 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n23),
3815 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n34),
3816 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n41),
3820 //=======================================================================
3821 //function : AddFaceWithID
3823 //=======================================================================
3824 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
3825 const SMDS_MeshNode * n2,
3826 const SMDS_MeshNode * n3,
3827 const SMDS_MeshNode * n4,
3828 const SMDS_MeshNode * n12,
3829 const SMDS_MeshNode * n23,
3830 const SMDS_MeshNode * n34,
3831 const SMDS_MeshNode * n41,
3834 if ( !n1 || !n2 || !n3 || !n4 || !n12 || !n23 || !n34 || !n41) return 0;
3835 if(hasConstructionEdges()) {
3836 // creation quadratic edges - not implemented
3841 // --- retrieve nodes ID
3842 myNodeIds.resize(8);
3843 myNodeIds[0] = n1->getVtkId();
3844 myNodeIds[1] = n2->getVtkId();
3845 myNodeIds[2] = n3->getVtkId();
3846 myNodeIds[3] = n4->getVtkId();
3847 myNodeIds[4] = n12->getVtkId();
3848 myNodeIds[5] = n23->getVtkId();
3849 myNodeIds[6] = n34->getVtkId();
3850 myNodeIds[7] = n41->getVtkId();
3852 SMDS_MeshFace * face = 0;
3853 SMDS_VtkFace *facevtk = myFacePool->getNew();
3854 facevtk->init(myNodeIds, this);
3855 if (!this->registerElement(ID,facevtk))
3857 this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL);
3858 myFacePool->destroy(facevtk);
3862 adjustmyCellsCapacity(ID);
3864 myInfo.myNbQuadQuadrangles++;
3866 // if (!registerElement(ID, face)) {
3867 // RemoveElement(face, false);
3874 //=======================================================================
3875 //function : AddFace
3877 //=======================================================================
3878 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
3879 const SMDS_MeshNode * n2,
3880 const SMDS_MeshNode * n3,
3881 const SMDS_MeshNode * n4,
3882 const SMDS_MeshNode * n12,
3883 const SMDS_MeshNode * n23,
3884 const SMDS_MeshNode * n34,
3885 const SMDS_MeshNode * n41,
3886 const SMDS_MeshNode * nCenter)
3888 return SMDS_Mesh::AddFaceWithID(n1,n2,n3,n4,n12,n23,n34,n41,nCenter,
3889 myElementIDFactory->GetFreeID());
3892 //=======================================================================
3893 //function : AddFaceWithID
3895 //=======================================================================
3896 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int n4,
3897 int n12,int n23,int n34,int n41, int nCenter, int ID)
3899 return SMDS_Mesh::AddFaceWithID
3900 ((SMDS_MeshNode *)myNodeIDFactory->MeshElement(n1) ,
3901 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n2) ,
3902 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n3) ,
3903 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n4) ,
3904 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n12),
3905 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n23),
3906 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n34),
3907 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n41),
3908 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nCenter),
3912 //=======================================================================
3913 //function : AddFaceWithID
3915 //=======================================================================
3916 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
3917 const SMDS_MeshNode * n2,
3918 const SMDS_MeshNode * n3,
3919 const SMDS_MeshNode * n4,
3920 const SMDS_MeshNode * n12,
3921 const SMDS_MeshNode * n23,
3922 const SMDS_MeshNode * n34,
3923 const SMDS_MeshNode * n41,
3924 const SMDS_MeshNode * nCenter,
3927 if ( !n1 || !n2 || !n3 || !n4 || !n12 || !n23 || !n34 || !n41 || !nCenter) return 0;
3928 if(hasConstructionEdges()) {
3929 // creation quadratic edges - not implemented
3934 // --- retrieve nodes ID
3935 myNodeIds.resize(9);
3936 myNodeIds[0] = n1->getVtkId();
3937 myNodeIds[1] = n2->getVtkId();
3938 myNodeIds[2] = n3->getVtkId();
3939 myNodeIds[3] = n4->getVtkId();
3940 myNodeIds[4] = n12->getVtkId();
3941 myNodeIds[5] = n23->getVtkId();
3942 myNodeIds[6] = n34->getVtkId();
3943 myNodeIds[7] = n41->getVtkId();
3944 myNodeIds[8] = nCenter->getVtkId();
3946 SMDS_MeshFace * face = 0;
3947 SMDS_VtkFace *facevtk = myFacePool->getNew();
3948 facevtk->init(myNodeIds, this);
3949 if (!this->registerElement(ID,facevtk))
3951 this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL);
3952 myFacePool->destroy(facevtk);
3956 adjustmyCellsCapacity(ID);
3958 myInfo.myNbBiQuadQuadrangles++;
3960 // if (!registerElement(ID, face)) {
3961 // RemoveElement(face, false);
3969 //=======================================================================
3970 //function : AddVolume
3972 //=======================================================================
3973 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
3974 const SMDS_MeshNode * n2,
3975 const SMDS_MeshNode * n3,
3976 const SMDS_MeshNode * n4,
3977 const SMDS_MeshNode * n12,
3978 const SMDS_MeshNode * n23,
3979 const SMDS_MeshNode * n31,
3980 const SMDS_MeshNode * n14,
3981 const SMDS_MeshNode * n24,
3982 const SMDS_MeshNode * n34)
3984 int ID = myElementIDFactory->GetFreeID();
3985 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n12, n23,
3986 n31, n14, n24, n34, ID);
3987 if(v==NULL) myElementIDFactory->ReleaseID(ID);
3991 //=======================================================================
3992 //function : AddVolumeWithID
3994 //=======================================================================
3995 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4,
3996 int n12,int n23,int n31,
3997 int n14,int n24,int n34, int ID)
3999 return SMDS_Mesh::AddVolumeWithID
4000 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1) ,
4001 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2) ,
4002 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3) ,
4003 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4) ,
4004 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
4005 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
4006 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n31),
4007 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n14),
4008 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n24),
4009 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n34),
4013 //=======================================================================
4014 //function : AddVolumeWithID
4015 //purpose : 2d order tetrahedron of 10 nodes
4016 //=======================================================================
4017 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
4018 const SMDS_MeshNode * n2,
4019 const SMDS_MeshNode * n3,
4020 const SMDS_MeshNode * n4,
4021 const SMDS_MeshNode * n12,
4022 const SMDS_MeshNode * n23,
4023 const SMDS_MeshNode * n31,
4024 const SMDS_MeshNode * n14,
4025 const SMDS_MeshNode * n24,
4026 const SMDS_MeshNode * n34,
4029 if ( !n1 || !n2 || !n3 || !n4 || !n12 || !n23 || !n31 || !n14 || !n24 || !n34)
4031 if(hasConstructionFaces()) {
4032 // creation quadratic faces - not implemented
4035 // --- retrieve nodes ID
4036 myNodeIds.resize(10);
4037 myNodeIds[0] = n1->getVtkId();
4038 myNodeIds[1] = n3->getVtkId();
4039 myNodeIds[2] = n2->getVtkId();
4040 myNodeIds[3] = n4->getVtkId();
4042 myNodeIds[4] = n31->getVtkId();
4043 myNodeIds[5] = n23->getVtkId();
4044 myNodeIds[6] = n12->getVtkId();
4046 myNodeIds[7] = n14->getVtkId();
4047 myNodeIds[8] = n34->getVtkId();
4048 myNodeIds[9] = n24->getVtkId();
4050 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
4051 volvtk->init(myNodeIds, this);
4052 if (!this->registerElement(ID,volvtk))
4054 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
4055 myVolumePool->destroy(volvtk);
4058 adjustmyCellsCapacity(ID);
4059 myCells[ID] = volvtk;
4060 myInfo.myNbQuadTetras++;
4062 // if (!registerElement(ID, volvtk)) {
4063 // RemoveElement(volvtk, false);
4070 //=======================================================================
4071 //function : AddVolume
4073 //=======================================================================
4074 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
4075 const SMDS_MeshNode * n2,
4076 const SMDS_MeshNode * n3,
4077 const SMDS_MeshNode * n4,
4078 const SMDS_MeshNode * n5,
4079 const SMDS_MeshNode * n12,
4080 const SMDS_MeshNode * n23,
4081 const SMDS_MeshNode * n34,
4082 const SMDS_MeshNode * n41,
4083 const SMDS_MeshNode * n15,
4084 const SMDS_MeshNode * n25,
4085 const SMDS_MeshNode * n35,
4086 const SMDS_MeshNode * n45)
4088 int ID = myElementIDFactory->GetFreeID();
4089 SMDS_MeshVolume * v =
4090 SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n12, n23, n34, n41,
4091 n15, n25, n35, n45, ID);
4092 if(v==NULL) myElementIDFactory->ReleaseID(ID);
4096 //=======================================================================
4097 //function : AddVolumeWithID
4099 //=======================================================================
4100 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5,
4101 int n12,int n23,int n34,int n41,
4102 int n15,int n25,int n35,int n45, int ID)
4104 return SMDS_Mesh::AddVolumeWithID
4105 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1) ,
4106 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2) ,
4107 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3) ,
4108 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4) ,
4109 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5) ,
4110 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
4111 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
4112 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n34),
4113 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n41),
4114 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n15),
4115 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n25),
4116 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n35),
4117 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n45),
4121 //=======================================================================
4122 //function : AddVolumeWithID
4123 //purpose : 2d order pyramid of 13 nodes
4124 //=======================================================================
4125 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
4126 const SMDS_MeshNode * n2,
4127 const SMDS_MeshNode * n3,
4128 const SMDS_MeshNode * n4,
4129 const SMDS_MeshNode * n5,
4130 const SMDS_MeshNode * n12,
4131 const SMDS_MeshNode * n23,
4132 const SMDS_MeshNode * n34,
4133 const SMDS_MeshNode * n41,
4134 const SMDS_MeshNode * n15,
4135 const SMDS_MeshNode * n25,
4136 const SMDS_MeshNode * n35,
4137 const SMDS_MeshNode * n45,
4140 if (!n1 || !n2 || !n3 || !n4 || !n5 || !n12 || !n23 ||
4141 !n34 || !n41 || !n15 || !n25 || !n35 || !n45)
4143 if(hasConstructionFaces()) {
4144 // creation quadratic faces - not implemented
4147 // --- retrieve nodes ID
4148 myNodeIds.resize(13);
4149 myNodeIds[0] = n1->getVtkId();
4150 myNodeIds[1] = n4->getVtkId();
4151 myNodeIds[2] = n3->getVtkId();
4152 myNodeIds[3] = n2->getVtkId();
4153 myNodeIds[4] = n5->getVtkId();
4155 myNodeIds[5] = n41->getVtkId();
4156 myNodeIds[6] = n34->getVtkId();
4157 myNodeIds[7] = n23->getVtkId();
4158 myNodeIds[8] = n12->getVtkId();
4160 myNodeIds[9] = n15->getVtkId();
4161 myNodeIds[10] = n45->getVtkId();
4162 myNodeIds[11] = n35->getVtkId();
4163 myNodeIds[12] = n25->getVtkId();
4165 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
4166 volvtk->init(myNodeIds, this);
4167 if (!this->registerElement(ID,volvtk))
4169 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
4170 myVolumePool->destroy(volvtk);
4173 adjustmyCellsCapacity(ID);
4174 myCells[ID] = volvtk;
4175 myInfo.myNbQuadPyramids++;
4177 // if (!registerElement(ID, volvtk)) {
4178 // RemoveElement(volvtk, false);
4185 //=======================================================================
4186 //function : AddVolume
4188 //=======================================================================
4189 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
4190 const SMDS_MeshNode * n2,
4191 const SMDS_MeshNode * n3,
4192 const SMDS_MeshNode * n4,
4193 const SMDS_MeshNode * n5,
4194 const SMDS_MeshNode * n6,
4195 const SMDS_MeshNode * n12,
4196 const SMDS_MeshNode * n23,
4197 const SMDS_MeshNode * n31,
4198 const SMDS_MeshNode * n45,
4199 const SMDS_MeshNode * n56,
4200 const SMDS_MeshNode * n64,
4201 const SMDS_MeshNode * n14,
4202 const SMDS_MeshNode * n25,
4203 const SMDS_MeshNode * n36)
4205 int ID = myElementIDFactory->GetFreeID();
4206 SMDS_MeshVolume * v =
4207 SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n12, n23, n31,
4208 n45, n56, n64, n14, n25, n36, ID);
4209 if(v==NULL) myElementIDFactory->ReleaseID(ID);
4213 //=======================================================================
4214 //function : AddVolumeWithID
4216 //=======================================================================
4217 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3,
4218 int n4, int n5, int n6,
4219 int n12,int n23,int n31,
4220 int n45,int n56,int n64,
4221 int n14,int n25,int n36, int ID)
4223 return SMDS_Mesh::AddVolumeWithID
4224 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1) ,
4225 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2) ,
4226 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3) ,
4227 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4) ,
4228 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5) ,
4229 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n6) ,
4230 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
4231 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
4232 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n31),
4233 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n45),
4234 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n56),
4235 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n64),
4236 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n14),
4237 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n25),
4238 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n36),
4242 //=======================================================================
4243 //function : AddVolumeWithID
4244 //purpose : 2d order Pentahedron with 15 nodes
4245 //=======================================================================
4246 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
4247 const SMDS_MeshNode * n2,
4248 const SMDS_MeshNode * n3,
4249 const SMDS_MeshNode * n4,
4250 const SMDS_MeshNode * n5,
4251 const SMDS_MeshNode * n6,
4252 const SMDS_MeshNode * n12,
4253 const SMDS_MeshNode * n23,
4254 const SMDS_MeshNode * n31,
4255 const SMDS_MeshNode * n45,
4256 const SMDS_MeshNode * n56,
4257 const SMDS_MeshNode * n64,
4258 const SMDS_MeshNode * n14,
4259 const SMDS_MeshNode * n25,
4260 const SMDS_MeshNode * n36,
4263 if (!n1 || !n2 || !n3 || !n4 || !n5 || !n6 || !n12 || !n23 ||
4264 !n31 || !n45 || !n56 || !n64 || !n14 || !n25 || !n36)
4266 if(hasConstructionFaces()) {
4267 // creation quadratic faces - not implemented
4270 // --- retrieve nodes ID
4271 myNodeIds.resize(15);
4272 myNodeIds[0] = n1->getVtkId();
4273 myNodeIds[1] = n2->getVtkId();
4274 myNodeIds[2] = n3->getVtkId();
4276 myNodeIds[3] = n4->getVtkId();
4277 myNodeIds[4] = n5->getVtkId();
4278 myNodeIds[5] = n6->getVtkId();
4280 myNodeIds[6] = n12->getVtkId();
4281 myNodeIds[7] = n23->getVtkId();
4282 myNodeIds[8] = n31->getVtkId();
4284 myNodeIds[9] = n45->getVtkId();
4285 myNodeIds[10] = n56->getVtkId();
4286 myNodeIds[11] = n64->getVtkId();
4288 myNodeIds[12] = n14->getVtkId();
4289 myNodeIds[13] = n25->getVtkId();
4290 myNodeIds[14] = n36->getVtkId();
4292 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
4293 volvtk->init(myNodeIds, this);
4294 if (!this->registerElement(ID,volvtk))
4296 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
4297 myVolumePool->destroy(volvtk);
4300 adjustmyCellsCapacity(ID);
4301 myCells[ID] = volvtk;
4302 myInfo.myNbQuadPrisms++;
4304 // if (!registerElement(ID, volvtk)) {
4305 // RemoveElement(volvtk, false);
4312 //=======================================================================
4313 //function : AddVolume
4315 //=======================================================================
4316 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
4317 const SMDS_MeshNode * n2,
4318 const SMDS_MeshNode * n3,
4319 const SMDS_MeshNode * n4,
4320 const SMDS_MeshNode * n5,
4321 const SMDS_MeshNode * n6,
4322 const SMDS_MeshNode * n7,
4323 const SMDS_MeshNode * n8,
4324 const SMDS_MeshNode * n12,
4325 const SMDS_MeshNode * n23,
4326 const SMDS_MeshNode * n34,
4327 const SMDS_MeshNode * n41,
4328 const SMDS_MeshNode * n56,
4329 const SMDS_MeshNode * n67,
4330 const SMDS_MeshNode * n78,
4331 const SMDS_MeshNode * n85,
4332 const SMDS_MeshNode * n15,
4333 const SMDS_MeshNode * n26,
4334 const SMDS_MeshNode * n37,
4335 const SMDS_MeshNode * n48)
4337 int ID = myElementIDFactory->GetFreeID();
4338 SMDS_MeshVolume * v =
4339 SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, n12, n23, n34, n41,
4340 n56, n67, n78, n85, n15, n26, n37, n48, ID);
4341 if(v==NULL) myElementIDFactory->ReleaseID(ID);
4345 //=======================================================================
4346 //function : AddVolumeWithID
4348 //=======================================================================
4349 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4,
4350 int n5, int n6, int n7, int n8,
4351 int n12,int n23,int n34,int n41,
4352 int n56,int n67,int n78,int n85,
4353 int n15,int n26,int n37,int n48, int ID)
4355 return SMDS_Mesh::AddVolumeWithID
4356 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1),
4357 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2),
4358 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3),
4359 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4),
4360 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5),
4361 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n6),
4362 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n7),
4363 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n8),
4364 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
4365 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
4366 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n34),
4367 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n41),
4368 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n56),
4369 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n67),
4370 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n78),
4371 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n85),
4372 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n15),
4373 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n26),
4374 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n37),
4375 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n48),
4379 //=======================================================================
4380 //function : AddVolumeWithID
4381 //purpose : 2d order Hexahedrons with 20 nodes
4382 //=======================================================================
4383 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
4384 const SMDS_MeshNode * n2,
4385 const SMDS_MeshNode * n3,
4386 const SMDS_MeshNode * n4,
4387 const SMDS_MeshNode * n5,
4388 const SMDS_MeshNode * n6,
4389 const SMDS_MeshNode * n7,
4390 const SMDS_MeshNode * n8,
4391 const SMDS_MeshNode * n12,
4392 const SMDS_MeshNode * n23,
4393 const SMDS_MeshNode * n34,
4394 const SMDS_MeshNode * n41,
4395 const SMDS_MeshNode * n56,
4396 const SMDS_MeshNode * n67,
4397 const SMDS_MeshNode * n78,
4398 const SMDS_MeshNode * n85,
4399 const SMDS_MeshNode * n15,
4400 const SMDS_MeshNode * n26,
4401 const SMDS_MeshNode * n37,
4402 const SMDS_MeshNode * n48,
4405 if (!n1 || !n2 || !n3 || !n4 || !n5 || !n6 || !n7 || !n8 || !n12 || !n23 ||
4406 !n34 || !n41 || !n56 || !n67 || !n78 || !n85 || !n15 || !n26 || !n37 || !n48)
4408 if(hasConstructionFaces()) {
4410 // creation quadratic faces - not implemented
4412 // --- retrieve nodes ID
4413 myNodeIds.resize(20);
4414 myNodeIds[0] = n1->getVtkId();
4415 myNodeIds[1] = n4->getVtkId();
4416 myNodeIds[2] = n3->getVtkId();
4417 myNodeIds[3] = n2->getVtkId();
4419 myNodeIds[4] = n5->getVtkId();
4420 myNodeIds[5] = n8->getVtkId();
4421 myNodeIds[6] = n7->getVtkId();
4422 myNodeIds[7] = n6->getVtkId();
4424 myNodeIds[8] = n41->getVtkId();
4425 myNodeIds[9] = n34->getVtkId();
4426 myNodeIds[10] = n23->getVtkId();
4427 myNodeIds[11] = n12->getVtkId();
4429 myNodeIds[12] = n85->getVtkId();
4430 myNodeIds[13] = n78->getVtkId();
4431 myNodeIds[14] = n67->getVtkId();
4432 myNodeIds[15] = n56->getVtkId();
4434 myNodeIds[16] = n15->getVtkId();
4435 myNodeIds[17] = n48->getVtkId();
4436 myNodeIds[18] = n37->getVtkId();
4437 myNodeIds[19] = n26->getVtkId();
4439 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
4440 volvtk->init(myNodeIds, this);
4441 if (!this->registerElement(ID,volvtk))
4443 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
4444 myVolumePool->destroy(volvtk);
4447 adjustmyCellsCapacity(ID);
4448 myCells[ID] = volvtk;
4449 myInfo.myNbQuadHexas++;
4451 // if (!registerElement(ID, volvtk)) {
4452 // RemoveElement(volvtk, false);
4458 //=======================================================================
4459 //function : AddVolume
4461 //=======================================================================
4462 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
4463 const SMDS_MeshNode * n2,
4464 const SMDS_MeshNode * n3,
4465 const SMDS_MeshNode * n4,
4466 const SMDS_MeshNode * n5,
4467 const SMDS_MeshNode * n6,
4468 const SMDS_MeshNode * n7,
4469 const SMDS_MeshNode * n8,
4470 const SMDS_MeshNode * n12,
4471 const SMDS_MeshNode * n23,
4472 const SMDS_MeshNode * n34,
4473 const SMDS_MeshNode * n41,
4474 const SMDS_MeshNode * n56,
4475 const SMDS_MeshNode * n67,
4476 const SMDS_MeshNode * n78,
4477 const SMDS_MeshNode * n85,
4478 const SMDS_MeshNode * n15,
4479 const SMDS_MeshNode * n26,
4480 const SMDS_MeshNode * n37,
4481 const SMDS_MeshNode * n48,
4482 const SMDS_MeshNode * n1234,
4483 const SMDS_MeshNode * n1256,
4484 const SMDS_MeshNode * n2367,
4485 const SMDS_MeshNode * n3478,
4486 const SMDS_MeshNode * n1458,
4487 const SMDS_MeshNode * n5678,
4488 const SMDS_MeshNode * nCenter)
4490 int ID = myElementIDFactory->GetFreeID();
4491 SMDS_MeshVolume * v =
4492 SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, n12, n23, n34, n41,
4493 n56, n67, n78, n85, n15, n26, n37, n48,
4494 n1234, n1256, n2367, n3478, n1458, n5678, nCenter,
4496 if(v==NULL) myElementIDFactory->ReleaseID(ID);
4500 //=======================================================================
4501 //function : AddVolumeWithID
4503 //=======================================================================
4504 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4,
4505 int n5, int n6, int n7, int n8,
4506 int n12,int n23,int n34,int n41,
4507 int n56,int n67,int n78,int n85,
4508 int n15,int n26,int n37,int n48,
4509 int n1234,int n1256,int n2367,int n3478,
4510 int n1458,int n5678,int nCenter, int ID)
4512 return SMDS_Mesh::AddVolumeWithID
4513 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1),
4514 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2),
4515 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3),
4516 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4),
4517 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5),
4518 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n6),
4519 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n7),
4520 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n8),
4521 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
4522 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
4523 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n34),
4524 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n41),
4525 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n56),
4526 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n67),
4527 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n78),
4528 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n85),
4529 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n15),
4530 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n26),
4531 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n37),
4532 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n48),
4533 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1234),
4534 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1256),
4535 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2367),
4536 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3478),
4537 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1458),
4538 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5678),
4539 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(nCenter),
4543 //=======================================================================
4544 //function : AddVolumeWithID
4545 //purpose : 2d order Hexahedrons with 20 nodes
4546 //=======================================================================
4547 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
4548 const SMDS_MeshNode * n2,
4549 const SMDS_MeshNode * n3,
4550 const SMDS_MeshNode * n4,
4551 const SMDS_MeshNode * n5,
4552 const SMDS_MeshNode * n6,
4553 const SMDS_MeshNode * n7,
4554 const SMDS_MeshNode * n8,
4555 const SMDS_MeshNode * n12,
4556 const SMDS_MeshNode * n23,
4557 const SMDS_MeshNode * n34,
4558 const SMDS_MeshNode * n41,
4559 const SMDS_MeshNode * n56,
4560 const SMDS_MeshNode * n67,
4561 const SMDS_MeshNode * n78,
4562 const SMDS_MeshNode * n85,
4563 const SMDS_MeshNode * n15,
4564 const SMDS_MeshNode * n26,
4565 const SMDS_MeshNode * n37,
4566 const SMDS_MeshNode * n48,
4567 const SMDS_MeshNode * n1234,
4568 const SMDS_MeshNode * n1256,
4569 const SMDS_MeshNode * n2367,
4570 const SMDS_MeshNode * n3478,
4571 const SMDS_MeshNode * n1458,
4572 const SMDS_MeshNode * n5678,
4573 const SMDS_MeshNode * nCenter,
4576 if (!n1 || !n2 || !n3 || !n4 || !n5 || !n6 || !n7 || !n8 || !n12 || !n23 ||
4577 !n34 || !n41 || !n56 || !n67 || !n78 || !n85 || !n15 || !n26 || !n37 || !n48 ||
4578 !n1234 || !n1256 || !n2367 || !n3478 || !n1458 || !n5678 || !nCenter )
4580 if(hasConstructionFaces()) {
4582 // creation quadratic faces - not implemented
4584 // --- retrieve nodes ID
4585 myNodeIds.resize(27);
4586 myNodeIds[0] = n1->getVtkId();
4587 myNodeIds[1] = n4->getVtkId();
4588 myNodeIds[2] = n3->getVtkId();
4589 myNodeIds[3] = n2->getVtkId();
4591 myNodeIds[4] = n5->getVtkId();
4592 myNodeIds[5] = n8->getVtkId();
4593 myNodeIds[6] = n7->getVtkId();
4594 myNodeIds[7] = n6->getVtkId();
4596 myNodeIds[8] = n41->getVtkId();
4597 myNodeIds[9] = n34->getVtkId();
4598 myNodeIds[10] = n23->getVtkId();
4599 myNodeIds[11] = n12->getVtkId();
4601 myNodeIds[12] = n85->getVtkId();
4602 myNodeIds[13] = n78->getVtkId();
4603 myNodeIds[14] = n67->getVtkId();
4604 myNodeIds[15] = n56->getVtkId();
4606 myNodeIds[16] = n15->getVtkId();
4607 myNodeIds[17] = n48->getVtkId();
4608 myNodeIds[18] = n37->getVtkId();
4609 myNodeIds[19] = n26->getVtkId();
4611 myNodeIds[20] = n1256->getVtkId();
4612 myNodeIds[21] = n3478->getVtkId();
4613 myNodeIds[22] = n1458->getVtkId();
4614 myNodeIds[23] = n2367->getVtkId();
4615 myNodeIds[24] = n1234->getVtkId();
4616 myNodeIds[25] = n5678->getVtkId();
4617 myNodeIds[26] = nCenter->getVtkId();
4619 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
4620 volvtk->init(myNodeIds, this);
4621 if (!this->registerElement(ID,volvtk))
4623 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
4624 myVolumePool->destroy(volvtk);
4627 adjustmyCellsCapacity(ID);
4628 myCells[ID] = volvtk;
4629 myInfo.myNbTriQuadHexas++;
4634 void SMDS_Mesh::dumpGrid(string ficdump)
4636 // vtkUnstructuredGridWriter* aWriter = vtkUnstructuredGridWriter::New();
4637 // aWriter->SetFileName(ficdump.c_str());
4638 // aWriter->SetInput(myGrid);
4639 // if(myGrid->GetNumberOfCells())
4641 // aWriter->Write();
4643 // aWriter->Delete();
4644 ficdump = ficdump + "_connectivity";
4645 ofstream ficcon(ficdump.c_str(), ios::out);
4646 int nbPoints = myGrid->GetNumberOfPoints();
4647 ficcon << "-------------------------------- points " << nbPoints << endl;
4648 for (int i=0; i<nbPoints; i++)
4650 ficcon << i << " " << *(myGrid->GetPoint(i)) << " " << *(myGrid->GetPoint(i)+1) << " " << " " << *(myGrid->GetPoint(i)+2) << endl;
4652 int nbCells = myGrid->GetNumberOfCells();
4653 ficcon << "-------------------------------- cells " << nbCells << endl;
4654 for (int i=0; i<nbCells; i++)
4656 ficcon << i << " - " << myGrid->GetCell(i)->GetCellType() << " -";
4657 int nbptcell = myGrid->GetCell(i)->GetNumberOfPoints();
4658 vtkIdList *listid = myGrid->GetCell(i)->GetPointIds();
4659 for (int j=0; j<nbptcell; j++)
4661 ficcon << " " << listid->GetId(j);
4665 ficcon << "-------------------------------- connectivity " << nbPoints << endl;
4666 vtkCellLinks *links = myGrid->GetLinks();
4667 for (int i=0; i<nbPoints; i++)
4669 int ncells = links->GetNcells(i);
4670 vtkIdType *cells = links->GetCells(i);
4671 ficcon << i << " - " << ncells << " -";
4672 for (int j=0; j<ncells; j++)
4674 ficcon << " " << cells[j];
4682 void SMDS_Mesh::compactMesh()
4684 this->myCompactTime = this->myModifTime;
4687 int SMDS_Mesh::fromVtkToSmds(int vtkid)
4689 if (vtkid >= 0 && vtkid < (int)myCellIdVtkToSmds.size())
4690 return myCellIdVtkToSmds[vtkid];
4691 throw SALOME_Exception(LOCALIZED ("vtk id out of bounds"));
4694 // void SMDS_Mesh::updateBoundingBox()
4696 // xmin = 0; xmax = 0;
4697 // ymin = 0; ymax = 0;
4698 // zmin = 0; zmax = 0;
4699 // vtkPoints *points = myGrid->GetPoints();
4700 // int myNodesSize = this->myNodes.size();
4701 // for (int i = 0; i < myNodesSize; i++)
4703 // if (SMDS_MeshNode *n = myNodes[i])
4705 // double coords[3];
4706 // points->GetPoint(n->myVtkID, coords);
4707 // if (coords[0] < xmin) xmin = coords[0];
4708 // else if (coords[0] > xmax) xmax = coords[0];
4709 // if (coords[1] < ymin) ymin = coords[1];
4710 // else if (coords[1] > ymax) ymax = coords[1];
4711 // if (coords[2] < zmin) zmin = coords[2];
4712 // else if (coords[2] > zmax) zmax = coords[2];
4717 double SMDS_Mesh::getMaxDim()
4719 double dmax = 1.e-3;
4720 if ((xmax - xmin) > dmax) dmax = xmax -xmin;
4721 if ((ymax - ymin) > dmax) dmax = ymax -ymin;
4722 if ((zmax - zmin) > dmax) dmax = zmax -zmin;
4726 //! modification that needs compact structure and redraw
4727 void SMDS_Mesh::Modified()
4729 if (this->myModified)
4731 this->myModifTime++;
4736 //! get last modification timeStamp
4737 unsigned long SMDS_Mesh::GetMTime() const
4739 return this->myModifTime;
4742 bool SMDS_Mesh::isCompacted()
4744 return this->myCompactTime == this->myModifTime;