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 myNodeMin(0), myNodeMax(0),
134 myHasConstructionEdges(false), myHasConstructionFaces(false),
135 myHasInverseElements(true),
136 xmin(0), xmax(0), ymin(0), ymax(0), zmin(0), zmax(0)
138 myMeshId = _meshList.size(); // --- index of the mesh to push back in the vector
139 myNodeIDFactory->SetMesh(this);
140 myElementIDFactory->SetMesh(this);
141 _meshList.push_back(this);
142 myNodePool = new ObjectPool<SMDS_MeshNode>(SMDS_Mesh::chunkSize);
143 myEdgePool = new ObjectPool<SMDS_VtkEdge>(SMDS_Mesh::chunkSize);
144 myFacePool = new ObjectPool<SMDS_VtkFace>(SMDS_Mesh::chunkSize);
145 myVolumePool = new ObjectPool<SMDS_VtkVolume>(SMDS_Mesh::chunkSize);
146 myBallPool = new ObjectPool<SMDS_BallElement>(SMDS_Mesh::chunkSize);
150 //myCellIdSmdsToVtk.clear();
151 myCellIdVtkToSmds.clear();
152 myGrid = SMDS_UnstructuredGrid::New();
153 myGrid->setSMDS_mesh(this);
154 myGrid->Initialize();
156 vtkPoints* points = vtkPoints::New();
157 // bug "21125: EDF 1233 SMESH: Degrardation of precision in a test case for quadratic conversion"
158 // Use double type for storing coordinates of nodes instead of float.
159 points->SetDataType(VTK_DOUBLE);
160 points->SetNumberOfPoints(0 /*SMDS_Mesh::chunkSize*/);
161 myGrid->SetPoints( points );
163 myGrid->BuildLinks();
166 // initialize static maps in SMDS_MeshCell, to be thread-safe
169 SMDS_MeshCell::toVtkType( SMDSEntity_Node );
170 SMDS_MeshCell::toVtkOrder( SMDSEntity_Node );
171 SMDS_MeshCell::reverseSmdsOrder( SMDSEntity_Node );
172 SMDS_MeshCell::interlacedSmdsOrder( SMDSEntity_Node );
173 SMDS_MeshCell::toSmdsType( VTK_VERTEX );
174 SMDS_MeshCell::fromVtkOrder( SMDSEntity_Node );
178 ///////////////////////////////////////////////////////////////////////////////
179 /// Create a new child mesh
180 /// Note that the tree structure of SMDS_Mesh seems to be unused in this version
181 /// (2003-09-08) of SMESH
182 ///////////////////////////////////////////////////////////////////////////////
183 SMDS_Mesh::SMDS_Mesh(SMDS_Mesh * parent):
184 myNodePool(parent->myNodePool),
185 myVolumePool(parent->myVolumePool),
186 myFacePool(parent->myFacePool),
187 myEdgePool(parent->myEdgePool),
188 myBallPool(parent->myBallPool),
189 myParent(parent), myNodeIDFactory(parent->myNodeIDFactory),
190 myElementIDFactory(parent->myElementIDFactory),
191 myHasConstructionEdges(false), myHasConstructionFaces(false),
192 myHasInverseElements(true)
196 ///////////////////////////////////////////////////////////////////////////////
197 ///Create a submesh and add it to the current mesh
198 ///////////////////////////////////////////////////////////////////////////////
200 SMDS_Mesh *SMDS_Mesh::AddSubMesh()
202 SMDS_Mesh *submesh = new SMDS_Mesh(this);
203 myChildren.insert(myChildren.end(), submesh);
207 ///////////////////////////////////////////////////////////////////////////////
208 ///create a MeshNode and add it to the current Mesh
209 ///An ID is automatically assigned to the node.
210 ///@return : The created node
211 ///////////////////////////////////////////////////////////////////////////////
213 SMDS_MeshNode * SMDS_Mesh::AddNode(double x, double y, double z)
215 return SMDS_Mesh::AddNodeWithID(x,y,z,myNodeIDFactory->GetFreeID());
218 ///////////////////////////////////////////////////////////////////////////////
219 ///create a MeshNode and add it to the current Mesh
220 ///@param ID : The ID of the MeshNode to create
221 ///@return : The created node or NULL if a node with this ID already exists
222 ///////////////////////////////////////////////////////////////////////////////
223 SMDS_MeshNode * SMDS_Mesh::AddNodeWithID(double x, double y, double z, int ID)
225 // find the MeshNode corresponding to ID
226 const SMDS_MeshElement *node = myNodeIDFactory->MeshElement(ID);
230 MESSAGE("=============> Bad Node Id: " << ID);
231 ID = myNodeIDFactory->GetFreeID();
233 myNodeIDFactory->adjustMaxId(ID);
234 SMDS_MeshNode * node = myNodePool->getNew();
235 node->init(ID, myMeshId, 0, x, y, z);
237 if (ID >= (int)myNodes.size())
239 myNodes.resize(ID+SMDS_Mesh::chunkSize, 0);
240 // MESSAGE(" ------------------ myNodes resize " << ID << " --> " << ID+SMDS_Mesh::chunkSize);
243 myNodeIDFactory->BindID(ID,node);
246 this->adjustBoundingBox(x, y, z);
252 ///////////////////////////////////////////////////////////////////////////////
253 /// create a Mesh0DElement and add it to the current Mesh
254 /// @return : The created Mesh0DElement
255 ///////////////////////////////////////////////////////////////////////////////
256 SMDS_Mesh0DElement* SMDS_Mesh::Add0DElementWithID(int idnode, int ID)
258 SMDS_MeshNode * node = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode);
259 if (!node) return NULL;
260 return SMDS_Mesh::Add0DElementWithID(node, ID);
263 ///////////////////////////////////////////////////////////////////////////////
264 /// create a Mesh0DElement and add it to the current Mesh
265 /// @return : The created Mesh0DElement
266 ///////////////////////////////////////////////////////////////////////////////
267 SMDS_Mesh0DElement* SMDS_Mesh::Add0DElement(const SMDS_MeshNode * node)
269 return SMDS_Mesh::Add0DElementWithID(node, myElementIDFactory->GetFreeID());
272 ///////////////////////////////////////////////////////////////////////////////
273 /// Create a new Mesh0DElement and at it to the mesh
274 /// @param idnode ID of the node
275 /// @param ID ID of the 0D element to create
276 /// @return The created 0D element or NULL if an element with this
277 /// ID already exists or if input node is not found.
278 ///////////////////////////////////////////////////////////////////////////////
279 SMDS_Mesh0DElement* SMDS_Mesh::Add0DElementWithID(const SMDS_MeshNode * n, int ID)
283 if (Nb0DElements() % CHECKMEMORY_INTERVAL == 0) CheckMemory();
284 //MESSAGE("Add0DElementWithID" << ID)
285 SMDS_Mesh0DElement * el0d = new SMDS_Mesh0DElement(n);
286 if (myElementIDFactory->BindID(ID, el0d)) {
287 //SMDS_MeshNode *node = const_cast<SMDS_MeshNode*>(n);
288 //node->AddInverseElement(el0d);// --- fait avec BindID
289 adjustmyCellsCapacity(ID);
291 myInfo.myNb0DElements++;
299 ///////////////////////////////////////////////////////////////////////////////
300 /// create a Ball and add it to the current Mesh
301 /// @return : The created Ball
302 ///////////////////////////////////////////////////////////////////////////////
303 SMDS_BallElement* SMDS_Mesh::AddBallWithID(int idnode, double diameter, int ID)
305 SMDS_MeshNode * node = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode);
306 if (!node) return NULL;
307 return SMDS_Mesh::AddBallWithID(node, diameter, ID);
310 ///////////////////////////////////////////////////////////////////////////////
311 /// create a Ball and add it to the current Mesh
312 /// @return : The created Ball
313 ///////////////////////////////////////////////////////////////////////////////
314 SMDS_BallElement* SMDS_Mesh::AddBall(const SMDS_MeshNode * node, double diameter)
316 return SMDS_Mesh::AddBallWithID(node, diameter, myElementIDFactory->GetFreeID());
319 ///////////////////////////////////////////////////////////////////////////////
320 /// Create a new Ball and at it to the mesh
321 /// @param idnode ID of the node
322 // @param diameter ball diameter
323 /// @param ID ID of the 0D element to create
324 /// @return The created 0D element or NULL if an element with this
325 /// ID already exists or if input node is not found.
326 ///////////////////////////////////////////////////////////////////////////////
327 SMDS_BallElement* SMDS_Mesh::AddBallWithID(const SMDS_MeshNode * n, double diameter, int ID)
331 if (NbBalls() % CHECKMEMORY_INTERVAL == 0) CheckMemory();
333 SMDS_BallElement *ball = myBallPool->getNew();
334 ball->init(n->getVtkId(), diameter, this);
335 if (!this->registerElement(ID,ball))
337 this->myGrid->GetCellTypesArray()->SetValue(ball->getVtkId(), VTK_EMPTY_CELL);
338 myBallPool->destroy(ball);
341 adjustmyCellsCapacity(ID);
347 ///////////////////////////////////////////////////////////////////////////////
348 /// create a MeshEdge and add it to the current Mesh
349 /// @return : The created MeshEdge
350 ///////////////////////////////////////////////////////////////////////////////
352 SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(int idnode1, int idnode2, int ID)
354 SMDS_MeshNode * node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
355 SMDS_MeshNode * node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
356 if(!node1 || !node2) return NULL;
357 return SMDS_Mesh::AddEdgeWithID(node1, node2, ID);
360 ///////////////////////////////////////////////////////////////////////////////
361 /// create a MeshEdge and add it to the current Mesh
362 /// @return : The created MeshEdge
363 ///////////////////////////////////////////////////////////////////////////////
365 SMDS_MeshEdge* SMDS_Mesh::AddEdge(const SMDS_MeshNode * node1,
366 const SMDS_MeshNode * node2)
368 return SMDS_Mesh::AddEdgeWithID(node1, node2, myElementIDFactory->GetFreeID());
371 ///////////////////////////////////////////////////////////////////////////////
372 /// Create a new edge and at it to the mesh
373 /// @param idnode1 ID of the first node
374 /// @param idnode2 ID of the second node
375 /// @param ID ID of the edge to create
376 /// @return The created edge or NULL if an element with this ID already exists or
377 /// if input nodes are not found.
378 ///////////////////////////////////////////////////////////////////////////////
380 SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
381 const SMDS_MeshNode * n2,
384 if ( !n1 || !n2 ) return 0;
385 SMDS_MeshEdge * edge = 0;
387 // --- retreive nodes ID
388 vector<vtkIdType> nodeIds;
390 nodeIds.push_back(n1->getVtkId());
391 nodeIds.push_back(n2->getVtkId());
393 SMDS_VtkEdge *edgevtk = myEdgePool->getNew();
394 edgevtk->init(nodeIds, this);
395 if (!this->registerElement(ID,edgevtk))
397 this->myGrid->GetCellTypesArray()->SetValue(edgevtk->getVtkId(), VTK_EMPTY_CELL);
398 myEdgePool->destroy(edgevtk);
402 adjustmyCellsCapacity(ID);
406 // if (edge && !registerElement(ID, edge))
408 // RemoveElement(edge, false);
414 ///////////////////////////////////////////////////////////////////////////////
415 /// Add a triangle defined by its nodes. An ID is automatically affected to the
417 ///////////////////////////////////////////////////////////////////////////////
419 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
420 const SMDS_MeshNode * n2,
421 const SMDS_MeshNode * n3)
423 return SMDS_Mesh::AddFaceWithID(n1,n2,n3, myElementIDFactory->GetFreeID());
426 ///////////////////////////////////////////////////////////////////////////////
427 /// Add a triangle defined by its nodes IDs
428 ///////////////////////////////////////////////////////////////////////////////
430 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int idnode1, int idnode2, int idnode3, int ID)
432 SMDS_MeshNode * node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
433 SMDS_MeshNode * node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
434 SMDS_MeshNode * node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
435 if(!node1 || !node2 || !node3) return NULL;
436 return SMDS_Mesh::AddFaceWithID(node1, node2, node3, ID);
439 ///////////////////////////////////////////////////////////////////////////////
440 /// Add a triangle defined by its nodes
441 ///////////////////////////////////////////////////////////////////////////////
443 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
444 const SMDS_MeshNode * n2,
445 const SMDS_MeshNode * n3,
448 //MESSAGE("AddFaceWithID " << ID)
449 SMDS_MeshFace * face=createTriangle(n1, n2, n3, ID);
451 // if (face && !registerElement(ID, face)) {
452 // RemoveElement(face, false);
458 ///////////////////////////////////////////////////////////////////////////////
459 /// Add a quadrangle defined by its nodes. An ID is automatically affected to the
461 ///////////////////////////////////////////////////////////////////////////////
463 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
464 const SMDS_MeshNode * n2,
465 const SMDS_MeshNode * n3,
466 const SMDS_MeshNode * n4)
468 return SMDS_Mesh::AddFaceWithID(n1,n2,n3, n4, myElementIDFactory->GetFreeID());
471 ///////////////////////////////////////////////////////////////////////////////
472 /// Add a quadrangle defined by its nodes IDs
473 ///////////////////////////////////////////////////////////////////////////////
475 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int idnode1,
481 SMDS_MeshNode *node1, *node2, *node3, *node4;
482 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
483 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
484 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
485 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
486 if(!node1 || !node2 || !node3 || !node4) return NULL;
487 return SMDS_Mesh::AddFaceWithID(node1, node2, node3, node4, ID);
490 ///////////////////////////////////////////////////////////////////////////////
491 /// Add a quadrangle defined by its nodes
492 ///////////////////////////////////////////////////////////////////////////////
494 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
495 const SMDS_MeshNode * n2,
496 const SMDS_MeshNode * n3,
497 const SMDS_MeshNode * n4,
500 //MESSAGE("AddFaceWithID " << ID);
501 SMDS_MeshFace * face=createQuadrangle(n1, n2, n3, n4, ID);
503 // if (face && !registerElement(ID, face)) {
504 // RemoveElement(face, false);
510 ///////////////////////////////////////////////////////////////////////////////
511 /// Add a triangle defined by its edges. An ID is automatically assigned to the
513 ///////////////////////////////////////////////////////////////////////////////
515 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshEdge * e1,
516 const SMDS_MeshEdge * e2,
517 const SMDS_MeshEdge * e3)
519 if (!hasConstructionEdges())
521 //MESSAGE("AddFaceWithID");
522 return AddFaceWithID(e1,e2,e3, myElementIDFactory->GetFreeID());
525 ///////////////////////////////////////////////////////////////////////////////
526 /// Add a triangle defined by its edges
527 ///////////////////////////////////////////////////////////////////////////////
529 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshEdge * e1,
530 const SMDS_MeshEdge * e2,
531 const SMDS_MeshEdge * e3,
534 if (!hasConstructionEdges())
536 if ( !e1 || !e2 || !e3 ) return 0;
538 if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
540 SMDS_MeshFace * face = new SMDS_FaceOfEdges(e1,e2,e3);
541 adjustmyCellsCapacity(ID);
543 myInfo.myNbTriangles++;
545 if (!registerElement(ID, face)) {
546 registerElement(myElementIDFactory->GetFreeID(), face);
547 //RemoveElement(face, false);
553 ///////////////////////////////////////////////////////////////////////////////
554 /// Add a quadrangle defined by its edges. An ID is automatically assigned to the
556 ///////////////////////////////////////////////////////////////////////////////
558 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshEdge * e1,
559 const SMDS_MeshEdge * e2,
560 const SMDS_MeshEdge * e3,
561 const SMDS_MeshEdge * e4)
563 if (!hasConstructionEdges())
565 return AddFaceWithID(e1,e2,e3,e4, myElementIDFactory->GetFreeID());
568 ///////////////////////////////////////////////////////////////////////////////
569 /// Add a quadrangle defined by its edges
570 ///////////////////////////////////////////////////////////////////////////////
572 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshEdge * e1,
573 const SMDS_MeshEdge * e2,
574 const SMDS_MeshEdge * e3,
575 const SMDS_MeshEdge * e4,
578 if (!hasConstructionEdges())
580 if ( !e1 || !e2 || !e3 || !e4 ) return 0;
581 if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
582 SMDS_MeshFace * face = new SMDS_FaceOfEdges(e1,e2,e3,e4);
583 adjustmyCellsCapacity(ID);
585 myInfo.myNbQuadrangles++;
587 if (!registerElement(ID, face))
589 registerElement(myElementIDFactory->GetFreeID(), face);
590 //RemoveElement(face, false);
596 ///////////////////////////////////////////////////////////////////////////////
597 ///Create a new tetrahedron and add it to the mesh.
598 ///@return The created tetrahedron
599 ///////////////////////////////////////////////////////////////////////////////
601 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
602 const SMDS_MeshNode * n2,
603 const SMDS_MeshNode * n3,
604 const SMDS_MeshNode * n4)
606 int ID = myElementIDFactory->GetFreeID();
607 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, ID);
608 if(v==NULL) myElementIDFactory->ReleaseID(ID);
612 ///////////////////////////////////////////////////////////////////////////////
613 ///Create a new tetrahedron and add it to the mesh.
614 ///@param ID The ID of the new volume
615 ///@return The created tetrahedron or NULL if an element with this ID already exists
616 ///or if input nodes are not found.
617 ///////////////////////////////////////////////////////////////////////////////
619 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
625 SMDS_MeshNode *node1, *node2, *node3, *node4;
626 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
627 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
628 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
629 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
630 if(!node1 || !node2 || !node3 || !node4) return NULL;
631 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, ID);
634 ///////////////////////////////////////////////////////////////////////////////
635 ///Create a new tetrahedron and add it to the mesh.
636 ///@param ID The ID of the new volume
637 ///@return The created tetrahedron
638 ///////////////////////////////////////////////////////////////////////////////
640 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
641 const SMDS_MeshNode * n2,
642 const SMDS_MeshNode * n3,
643 const SMDS_MeshNode * n4,
646 SMDS_MeshVolume* volume = 0;
647 if ( !n1 || !n2 || !n3 || !n4) return volume;
648 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
649 if(hasConstructionFaces()) {
650 SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3);
651 SMDS_MeshFace * f2=FindFaceOrCreate(n1,n2,n4);
652 SMDS_MeshFace * f3=FindFaceOrCreate(n1,n3,n4);
653 SMDS_MeshFace * f4=FindFaceOrCreate(n2,n3,n4);
654 volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4);
655 adjustmyCellsCapacity(ID);
656 myCells[ID] = volume;
659 else if(hasConstructionEdges()) {
663 // --- retrieve nodes ID
665 myNodeIds[0] = n1->getVtkId();
666 myNodeIds[1] = n3->getVtkId(); // order SMDS-->VTK
667 myNodeIds[2] = n2->getVtkId();
668 myNodeIds[3] = n4->getVtkId();
670 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
671 volvtk->init(myNodeIds, this);
672 if (!this->registerElement(ID,volvtk))
674 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
675 myVolumePool->destroy(volvtk);
679 adjustmyCellsCapacity(ID);
680 myCells[ID] = volume;
684 // if (!registerElement(ID, volume)) {
685 // RemoveElement(volume, false);
691 ///////////////////////////////////////////////////////////////////////////////
692 ///Create a new pyramid and add it to the mesh.
693 ///Nodes 1,2,3 and 4 define the base of the pyramid
694 ///@return The created pyramid
695 ///////////////////////////////////////////////////////////////////////////////
697 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
698 const SMDS_MeshNode * n2,
699 const SMDS_MeshNode * n3,
700 const SMDS_MeshNode * n4,
701 const SMDS_MeshNode * n5)
703 int ID = myElementIDFactory->GetFreeID();
704 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, ID);
705 if(v==NULL) myElementIDFactory->ReleaseID(ID);
709 ///////////////////////////////////////////////////////////////////////////////
710 ///Create a new pyramid and add it to the mesh.
711 ///Nodes 1,2,3 and 4 define the base of the pyramid
712 ///@param ID The ID of the new volume
713 ///@return The created pyramid or NULL if an element with this ID already exists
714 ///or if input nodes are not found.
715 ///////////////////////////////////////////////////////////////////////////////
717 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
724 SMDS_MeshNode *node1, *node2, *node3, *node4, *node5;
725 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
726 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
727 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
728 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
729 node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5);
730 if(!node1 || !node2 || !node3 || !node4 || !node5) return NULL;
731 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, ID);
734 ///////////////////////////////////////////////////////////////////////////////
735 ///Create a new pyramid and add it to the mesh.
736 ///Nodes 1,2,3 and 4 define the base of the pyramid
737 ///@param ID The ID of the new volume
738 ///@return The created pyramid
739 ///////////////////////////////////////////////////////////////////////////////
741 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
742 const SMDS_MeshNode * n2,
743 const SMDS_MeshNode * n3,
744 const SMDS_MeshNode * n4,
745 const SMDS_MeshNode * n5,
748 SMDS_MeshVolume* volume = 0;
749 if ( !n1 || !n2 || !n3 || !n4 || !n5) return volume;
750 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
751 if(hasConstructionFaces()) {
752 SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3,n4);
753 SMDS_MeshFace * f2=FindFaceOrCreate(n1,n2,n5);
754 SMDS_MeshFace * f3=FindFaceOrCreate(n2,n3,n5);
755 SMDS_MeshFace * f4=FindFaceOrCreate(n3,n4,n5);
756 volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4);
757 adjustmyCellsCapacity(ID);
758 myCells[ID] = volume;
759 myInfo.myNbPyramids++;
761 else if(hasConstructionEdges()) {
765 // --- retrieve nodes ID
767 myNodeIds[0] = n1->getVtkId();
768 myNodeIds[1] = n4->getVtkId();
769 myNodeIds[2] = n3->getVtkId();
770 myNodeIds[3] = n2->getVtkId();
771 myNodeIds[4] = n5->getVtkId();
773 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
774 volvtk->init(myNodeIds, this);
775 if (!this->registerElement(ID,volvtk))
777 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
778 myVolumePool->destroy(volvtk);
782 adjustmyCellsCapacity(ID);
783 myCells[ID] = volume;
784 myInfo.myNbPyramids++;
787 // if (!registerElement(ID, volume)) {
788 // RemoveElement(volume, false);
794 ///////////////////////////////////////////////////////////////////////////////
795 ///Create a new prism and add it to the mesh.
796 ///Nodes 1,2,3 is a triangle and 1,2,5,4 a quadrangle.
797 ///@return The created prism
798 ///////////////////////////////////////////////////////////////////////////////
800 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
801 const SMDS_MeshNode * n2,
802 const SMDS_MeshNode * n3,
803 const SMDS_MeshNode * n4,
804 const SMDS_MeshNode * n5,
805 const SMDS_MeshNode * n6)
807 int ID = myElementIDFactory->GetFreeID();
808 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, ID);
809 if(v==NULL) myElementIDFactory->ReleaseID(ID);
813 ///////////////////////////////////////////////////////////////////////////////
814 ///Create a new prism and add it to the mesh.
815 ///Nodes 1,2,3 is a triangle and 1,2,5,4 a quadrangle.
816 ///@param ID The ID of the new volume
817 ///@return The created prism or NULL if an element with this ID already exists
818 ///or if input nodes are not found.
819 ///////////////////////////////////////////////////////////////////////////////
821 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
829 SMDS_MeshNode *node1, *node2, *node3, *node4, *node5, *node6;
830 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
831 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
832 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
833 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
834 node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5);
835 node6 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode6);
836 if(!node1 || !node2 || !node3 || !node4 || !node5 || !node6) return NULL;
837 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, node6, ID);
840 ///////////////////////////////////////////////////////////////////////////////
841 ///Create a new prism and add it to the mesh.
842 ///Nodes 1,2,3 is a triangle and 1,2,5,4 a quadrangle.
843 ///@param ID The ID of the new volume
844 ///@return The created prism
845 ///////////////////////////////////////////////////////////////////////////////
847 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
848 const SMDS_MeshNode * n2,
849 const SMDS_MeshNode * n3,
850 const SMDS_MeshNode * n4,
851 const SMDS_MeshNode * n5,
852 const SMDS_MeshNode * n6,
855 SMDS_MeshVolume* volume = 0;
856 if ( !n1 || !n2 || !n3 || !n4 || !n5 || !n6) return volume;
857 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
858 if(hasConstructionFaces()) {
859 SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3);
860 SMDS_MeshFace * f2=FindFaceOrCreate(n4,n5,n6);
861 SMDS_MeshFace * f3=FindFaceOrCreate(n1,n4,n5,n2);
862 SMDS_MeshFace * f4=FindFaceOrCreate(n2,n5,n6,n3);
863 SMDS_MeshFace * f5=FindFaceOrCreate(n3,n6,n4,n1);
864 volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5);
865 adjustmyCellsCapacity(ID);
866 myCells[ID] = volume;
869 else if(hasConstructionEdges()) {
873 // --- retrieve nodes ID
875 myNodeIds[0] = n1->getVtkId();
876 myNodeIds[1] = n2->getVtkId();
877 myNodeIds[2] = n3->getVtkId();
878 myNodeIds[3] = n4->getVtkId();
879 myNodeIds[4] = n5->getVtkId();
880 myNodeIds[5] = n6->getVtkId();
882 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
883 volvtk->init(myNodeIds, this);
884 if (!this->registerElement(ID,volvtk))
886 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
887 myVolumePool->destroy(volvtk);
891 adjustmyCellsCapacity(ID);
892 myCells[ID] = volume;
896 // if (!registerElement(ID, volume)) {
897 // RemoveElement(volume, false);
903 ///////////////////////////////////////////////////////////////////////////////
904 ///Create a new hexagonal prism and add it to the mesh.
905 ///@return The created prism
906 ///////////////////////////////////////////////////////////////////////////////
908 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
909 const SMDS_MeshNode * n2,
910 const SMDS_MeshNode * n3,
911 const SMDS_MeshNode * n4,
912 const SMDS_MeshNode * n5,
913 const SMDS_MeshNode * n6,
914 const SMDS_MeshNode * n7,
915 const SMDS_MeshNode * n8,
916 const SMDS_MeshNode * n9,
917 const SMDS_MeshNode * n10,
918 const SMDS_MeshNode * n11,
919 const SMDS_MeshNode * n12)
921 int ID = myElementIDFactory->GetFreeID();
922 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6,
923 n7, n8, n9, n10, n11, n12,
925 if(v==NULL) myElementIDFactory->ReleaseID(ID);
929 ///////////////////////////////////////////////////////////////////////////////
930 ///Create a new hexagonal prism and add it to the mesh.
931 ///@param ID The ID of the new volume
932 ///@return The created prism or NULL if an element with this ID already exists
933 ///or if input nodes are not found.
934 ///////////////////////////////////////////////////////////////////////////////
936 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
950 SMDS_MeshNode *node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
951 SMDS_MeshNode *node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
952 SMDS_MeshNode *node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
953 SMDS_MeshNode *node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
954 SMDS_MeshNode *node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5);
955 SMDS_MeshNode *node6 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode6);
956 SMDS_MeshNode *node7 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode7);
957 SMDS_MeshNode *node8 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode8);
958 SMDS_MeshNode *node9 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode9);
959 SMDS_MeshNode *node10 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode10);
960 SMDS_MeshNode *node11 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode11);
961 SMDS_MeshNode *node12 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode12);
962 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, node6,
963 node7, node8, node9, node10, node11, node12,
967 ///////////////////////////////////////////////////////////////////////////////
968 ///Create a new hexagonal prism and add it to the mesh.
969 ///@param ID The ID of the new volume
970 ///@return The created prism
971 ///////////////////////////////////////////////////////////////////////////////
973 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
974 const SMDS_MeshNode * n2,
975 const SMDS_MeshNode * n3,
976 const SMDS_MeshNode * n4,
977 const SMDS_MeshNode * n5,
978 const SMDS_MeshNode * n6,
979 const SMDS_MeshNode * n7,
980 const SMDS_MeshNode * n8,
981 const SMDS_MeshNode * n9,
982 const SMDS_MeshNode * n10,
983 const SMDS_MeshNode * n11,
984 const SMDS_MeshNode * n12,
987 SMDS_MeshVolume* volume = 0;
988 if(!n1 || !n2 || !n3 || !n4 || !n5 || !n6 ||
989 !n7 || !n8 || !n9 || !n10 || !n11 || !n12 )
991 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
992 if(hasConstructionFaces()) {
995 else if(hasConstructionEdges()) {
999 // --- retrieve nodes ID
1000 myNodeIds.resize(12);
1001 myNodeIds[0] = n1->getVtkId();
1002 myNodeIds[1] = n6->getVtkId();
1003 myNodeIds[2] = n5->getVtkId();
1004 myNodeIds[3] = n4->getVtkId();
1005 myNodeIds[4] = n3->getVtkId();
1006 myNodeIds[5] = n2->getVtkId();
1008 myNodeIds[6] = n7->getVtkId();
1009 myNodeIds[7] = n12->getVtkId();
1010 myNodeIds[8] = n11->getVtkId();
1011 myNodeIds[9] = n10->getVtkId();
1012 myNodeIds[10] = n9->getVtkId();
1013 myNodeIds[11] = n8->getVtkId();
1015 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
1016 volvtk->init(myNodeIds, this);
1017 if (!this->registerElement(ID,volvtk))
1019 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
1020 myVolumePool->destroy(volvtk);
1024 adjustmyCellsCapacity(ID);
1025 myCells[ID] = volume;
1026 myInfo.myNbHexPrism++;
1032 ///////////////////////////////////////////////////////////////////////////////
1033 ///Create a new hexahedron and add it to the mesh.
1034 ///Nodes 1,2,3,4 and 5,6,7,8 are quadrangle and 5,1 and 7,3 are an edges.
1035 ///@return The created hexahedron
1036 ///////////////////////////////////////////////////////////////////////////////
1038 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
1039 const SMDS_MeshNode * n2,
1040 const SMDS_MeshNode * n3,
1041 const SMDS_MeshNode * n4,
1042 const SMDS_MeshNode * n5,
1043 const SMDS_MeshNode * n6,
1044 const SMDS_MeshNode * n7,
1045 const SMDS_MeshNode * n8)
1047 int ID = myElementIDFactory->GetFreeID();
1048 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, ID);
1049 if(v==NULL) myElementIDFactory->ReleaseID(ID);
1053 ///////////////////////////////////////////////////////////////////////////////
1054 ///Create a new hexahedron and add it to the mesh.
1055 ///Nodes 1,2,3,4 and 5,6,7,8 are quadrangle and 5,1 and 7,3 are an edges.
1056 ///@param ID The ID of the new volume
1057 ///@return The created hexahedron or NULL if an element with this ID already
1058 ///exists or if input nodes are not found.
1059 ///////////////////////////////////////////////////////////////////////////////
1061 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
1071 SMDS_MeshNode *node1, *node2, *node3, *node4, *node5, *node6, *node7, *node8;
1072 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
1073 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
1074 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
1075 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
1076 node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5);
1077 node6 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode6);
1078 node7 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode7);
1079 node8 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode8);
1080 if(!node1 || !node2 || !node3 || !node4 || !node5 || !node6 || !node7 || !node8)
1082 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, node6,
1086 ///////////////////////////////////////////////////////////////////////////////
1087 ///Create a new hexahedron and add it to the mesh.
1088 ///Nodes 1,2,3,4 and 5,6,7,8 are quadrangle and 5,1 and 7,3 are an edges.
1089 ///@param ID The ID of the new volume
1090 ///@return The created prism or NULL if an element with this ID already exists
1091 ///or if input nodes are not found.
1092 ///////////////////////////////////////////////////////////////////////////////
1094 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
1095 const SMDS_MeshNode * n2,
1096 const SMDS_MeshNode * n3,
1097 const SMDS_MeshNode * n4,
1098 const SMDS_MeshNode * n5,
1099 const SMDS_MeshNode * n6,
1100 const SMDS_MeshNode * n7,
1101 const SMDS_MeshNode * n8,
1104 SMDS_MeshVolume* volume = 0;
1105 if ( !n1 || !n2 || !n3 || !n4 || !n5 || !n6 || !n7 || !n8) return volume;
1106 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1107 if(hasConstructionFaces()) {
1108 SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3,n4);
1109 SMDS_MeshFace * f2=FindFaceOrCreate(n5,n6,n7,n8);
1110 SMDS_MeshFace * f3=FindFaceOrCreate(n1,n4,n8,n5);
1111 SMDS_MeshFace * f4=FindFaceOrCreate(n1,n2,n6,n5);
1112 SMDS_MeshFace * f5=FindFaceOrCreate(n2,n3,n7,n6);
1113 SMDS_MeshFace * f6=FindFaceOrCreate(n3,n4,n8,n7);
1114 volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5,f6);
1115 adjustmyCellsCapacity(ID);
1116 myCells[ID] = volume;
1119 else if(hasConstructionEdges()) {
1123 // --- retrieve nodes ID
1124 myNodeIds.resize(8);
1125 myNodeIds[0] = n1->getVtkId();
1126 myNodeIds[1] = n4->getVtkId();
1127 myNodeIds[2] = n3->getVtkId();
1128 myNodeIds[3] = n2->getVtkId();
1129 myNodeIds[4] = n5->getVtkId();
1130 myNodeIds[5] = n8->getVtkId();
1131 myNodeIds[6] = n7->getVtkId();
1132 myNodeIds[7] = n6->getVtkId();
1134 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
1135 volvtk->init(myNodeIds, this);
1136 if (!this->registerElement(ID,volvtk))
1138 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
1139 myVolumePool->destroy(volvtk);
1143 adjustmyCellsCapacity(ID);
1144 myCells[ID] = volume;
1148 // if (!registerElement(ID, volume)) {
1149 // RemoveElement(volume, false);
1155 ///////////////////////////////////////////////////////////////////////////////
1156 ///Create a new tetrahedron defined by its faces and add it to the mesh.
1157 ///@return The created tetrahedron
1158 ///////////////////////////////////////////////////////////////////////////////
1160 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshFace * f1,
1161 const SMDS_MeshFace * f2,
1162 const SMDS_MeshFace * f3,
1163 const SMDS_MeshFace * f4)
1165 if (!hasConstructionFaces())
1167 return AddVolumeWithID(f1,f2,f3,f4, myElementIDFactory->GetFreeID());
1170 ///////////////////////////////////////////////////////////////////////////////
1171 ///Create a new tetrahedron defined by its faces and add it to the mesh.
1172 ///@param ID The ID of the new volume
1173 ///@return The created tetrahedron
1174 ///////////////////////////////////////////////////////////////////////////////
1176 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1,
1177 const SMDS_MeshFace * f2,
1178 const SMDS_MeshFace * f3,
1179 const SMDS_MeshFace * f4,
1182 if (!hasConstructionFaces())
1184 if ( !f1 || !f2 || !f3 || !f4) return 0;
1185 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1186 SMDS_MeshVolume * volume = new SMDS_VolumeOfFaces(f1,f2,f3,f4);
1187 adjustmyCellsCapacity(ID);
1188 myCells[ID] = volume;
1189 myInfo.myNbTetras++;
1191 if (!registerElement(ID, volume)) {
1192 registerElement(myElementIDFactory->GetFreeID(), volume);
1193 //RemoveElement(volume, false);
1199 ///////////////////////////////////////////////////////////////////////////////
1200 ///Create a new pyramid defined by its faces and add it to the mesh.
1201 ///@return The created pyramid
1202 ///////////////////////////////////////////////////////////////////////////////
1204 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshFace * f1,
1205 const SMDS_MeshFace * f2,
1206 const SMDS_MeshFace * f3,
1207 const SMDS_MeshFace * f4,
1208 const SMDS_MeshFace * f5)
1210 if (!hasConstructionFaces())
1212 return AddVolumeWithID(f1,f2,f3,f4,f5, myElementIDFactory->GetFreeID());
1215 ///////////////////////////////////////////////////////////////////////////////
1216 ///Create a new pyramid defined by its faces and add it to the mesh.
1217 ///@param ID The ID of the new volume
1218 ///@return The created pyramid
1219 ///////////////////////////////////////////////////////////////////////////////
1221 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1,
1222 const SMDS_MeshFace * f2,
1223 const SMDS_MeshFace * f3,
1224 const SMDS_MeshFace * f4,
1225 const SMDS_MeshFace * f5,
1228 if (!hasConstructionFaces())
1230 if ( !f1 || !f2 || !f3 || !f4 || !f5) return 0;
1231 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1232 SMDS_MeshVolume * volume = new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5);
1233 adjustmyCellsCapacity(ID);
1234 myCells[ID] = volume;
1235 myInfo.myNbPyramids++;
1237 if (!registerElement(ID, volume)) {
1238 registerElement(myElementIDFactory->GetFreeID(), volume);
1239 //RemoveElement(volume, false);
1245 ///////////////////////////////////////////////////////////////////////////////
1246 ///Create a new prism defined by its faces and add it to the mesh.
1247 ///@return The created prism
1248 ///////////////////////////////////////////////////////////////////////////////
1250 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshFace * f1,
1251 const SMDS_MeshFace * f2,
1252 const SMDS_MeshFace * f3,
1253 const SMDS_MeshFace * f4,
1254 const SMDS_MeshFace * f5,
1255 const SMDS_MeshFace * f6)
1257 if (!hasConstructionFaces())
1259 return AddVolumeWithID(f1,f2,f3,f4,f5,f6, myElementIDFactory->GetFreeID());
1262 ///////////////////////////////////////////////////////////////////////////////
1263 ///Create a new prism defined by its faces and add it to the mesh.
1264 ///@param ID The ID of the new volume
1265 ///@return The created prism
1266 ///////////////////////////////////////////////////////////////////////////////
1268 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1,
1269 const SMDS_MeshFace * f2,
1270 const SMDS_MeshFace * f3,
1271 const SMDS_MeshFace * f4,
1272 const SMDS_MeshFace * f5,
1273 const SMDS_MeshFace * f6,
1276 if (!hasConstructionFaces())
1278 if ( !f1 || !f2 || !f3 || !f4 || !f5 || !f6) return 0;
1279 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1280 SMDS_MeshVolume * volume = new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5,f6);
1281 adjustmyCellsCapacity(ID);
1282 myCells[ID] = volume;
1283 myInfo.myNbPrisms++;
1285 if (!registerElement(ID, volume)) {
1286 registerElement(myElementIDFactory->GetFreeID(), volume);
1287 //RemoveElement(volume, false);
1293 ///////////////////////////////////////////////////////////////////////////////
1294 /// Add a polygon defined by its nodes IDs
1295 ///////////////////////////////////////////////////////////////////////////////
1297 SMDS_MeshFace* SMDS_Mesh::AddPolygonalFaceWithID (const vector<int> & nodes_ids,
1300 int nbNodes = nodes_ids.size();
1301 vector<const SMDS_MeshNode*> nodes (nbNodes);
1302 for (int i = 0; i < nbNodes; i++) {
1303 nodes[i] = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nodes_ids[i]);
1304 if (!nodes[i]) return NULL;
1306 return SMDS_Mesh::AddPolygonalFaceWithID(nodes, ID);
1309 ///////////////////////////////////////////////////////////////////////////////
1310 /// Add a polygon defined by its nodes
1311 ///////////////////////////////////////////////////////////////////////////////
1314 SMDS_Mesh::AddPolygonalFaceWithID (const vector<const SMDS_MeshNode*> & nodes,
1317 SMDS_MeshFace * face;
1319 if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1320 if (hasConstructionEdges())
1326 myNodeIds.resize( nodes.size() );
1327 for ( size_t i = 0; i < nodes.size(); ++i )
1328 myNodeIds[i] = nodes[i]->getVtkId();
1330 SMDS_VtkFace *facevtk = myFacePool->getNew();
1331 facevtk->initPoly(myNodeIds, this);
1332 if (!this->registerElement(ID,facevtk))
1334 this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL);
1335 myFacePool->destroy(facevtk);
1340 adjustmyCellsCapacity(ID);
1342 myInfo.myNbPolygons++;
1348 ///////////////////////////////////////////////////////////////////////////////
1349 /// Add a polygon defined by its nodes.
1350 /// An ID is automatically affected to the created face.
1351 ///////////////////////////////////////////////////////////////////////////////
1353 SMDS_MeshFace* SMDS_Mesh::AddPolygonalFace (const vector<const SMDS_MeshNode*> & nodes)
1355 return SMDS_Mesh::AddPolygonalFaceWithID(nodes, myElementIDFactory->GetFreeID());
1358 ///////////////////////////////////////////////////////////////////////////////
1359 /// Add a quadratic polygon defined by its nodes IDs
1360 ///////////////////////////////////////////////////////////////////////////////
1362 SMDS_MeshFace* SMDS_Mesh::AddQuadPolygonalFaceWithID (const vector<int> & nodes_ids,
1365 vector<const SMDS_MeshNode*> nodes( nodes_ids.size() );
1366 for ( size_t i = 0; i < nodes.size(); i++) {
1367 nodes[i] = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nodes_ids[i]);
1368 if (!nodes[i]) return NULL;
1370 return SMDS_Mesh::AddQuadPolygonalFaceWithID(nodes, ID);
1373 ///////////////////////////////////////////////////////////////////////////////
1374 /// Add a quadratic polygon defined by its nodes
1375 ///////////////////////////////////////////////////////////////////////////////
1378 SMDS_Mesh::AddQuadPolygonalFaceWithID (const vector<const SMDS_MeshNode*> & nodes,
1381 SMDS_MeshFace * face;
1383 if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1384 if (hasConstructionEdges())
1390 myNodeIds.resize( nodes.size() );
1391 for ( size_t i = 0; i < nodes.size(); ++i )
1392 myNodeIds[i] = nodes[i]->getVtkId();
1394 SMDS_VtkFace *facevtk = myFacePool->getNew();
1395 facevtk->initQuadPoly(myNodeIds, this);
1396 if (!this->registerElement(ID,facevtk))
1398 this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL);
1399 myFacePool->destroy(facevtk);
1403 adjustmyCellsCapacity(ID);
1405 myInfo.myNbQuadPolygons++;
1410 ///////////////////////////////////////////////////////////////////////////////
1411 /// Add a quadratic polygon defined by its nodes.
1412 /// An ID is automatically affected to the created face.
1413 ///////////////////////////////////////////////////////////////////////////////
1415 SMDS_MeshFace* SMDS_Mesh::AddQuadPolygonalFace (const vector<const SMDS_MeshNode*> & nodes)
1417 return SMDS_Mesh::AddQuadPolygonalFaceWithID(nodes, myElementIDFactory->GetFreeID());
1420 ///////////////////////////////////////////////////////////////////////////////
1421 /// Create a new polyhedral volume and add it to the mesh.
1422 /// @param ID The ID of the new volume
1423 /// @return The created volume or NULL if an element with this ID already exists
1424 /// or if input nodes are not found.
1425 ///////////////////////////////////////////////////////////////////////////////
1427 SMDS_MeshVolume * SMDS_Mesh::AddPolyhedralVolumeWithID
1428 (const vector<int> & nodes_ids,
1429 const vector<int> & quantities,
1432 int nbNodes = nodes_ids.size();
1433 vector<const SMDS_MeshNode*> nodes (nbNodes);
1434 for (int i = 0; i < nbNodes; i++) {
1435 nodes[i] = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nodes_ids[i]);
1436 if (!nodes[i]) return NULL;
1438 return SMDS_Mesh::AddPolyhedralVolumeWithID(nodes, quantities, ID);
1441 ///////////////////////////////////////////////////////////////////////////////
1442 /// Create a new polyhedral volume and add it to the mesh.
1443 /// @param ID The ID of the new volume
1444 /// @return The created volume
1445 ///////////////////////////////////////////////////////////////////////////////
1448 SMDS_Mesh::AddPolyhedralVolumeWithID (const vector<const SMDS_MeshNode*>& nodes,
1449 const vector<int> & quantities,
1452 SMDS_MeshVolume* volume = 0;
1453 if ( nodes.empty() || quantities.empty() )
1455 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1456 if (hasConstructionFaces())
1460 else if (hasConstructionEdges())
1466 //#ifdef VTK_HAVE_POLYHEDRON
1467 myNodeIds.resize( nodes.size() );
1468 for ( size_t i = 0; i < nodes.size(); ++i )
1469 myNodeIds[i] = nodes[i]->getVtkId();
1471 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
1472 volvtk->initPoly(myNodeIds, quantities, this);
1473 if (!this->registerElement(ID, volvtk))
1475 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
1476 myVolumePool->destroy(volvtk);
1481 // for ( int i = 0; i < nodes.size(); ++i )
1482 // if ( !nodes[ i ] ) return 0;
1483 // volume = new SMDS_PolyhedralVolumeOfNodes(nodes, quantities);
1485 adjustmyCellsCapacity(ID);
1486 myCells[ID] = volume;
1487 myInfo.myNbPolyhedrons++;
1490 //#ifndef VTK_HAVE_POLYHEDRON
1491 // if (!registerElement(ID, volume))
1493 // registerElement(myElementIDFactory->GetFreeID(), volume);
1494 // //RemoveElement(volume, false);
1501 ///////////////////////////////////////////////////////////////////////////////
1502 /// Create a new polyhedral volume and add it to the mesh.
1503 /// @return The created volume
1504 ///////////////////////////////////////////////////////////////////////////////
1506 SMDS_MeshVolume* SMDS_Mesh::AddPolyhedralVolume
1507 (const vector<const SMDS_MeshNode*> & nodes,
1508 const vector<int> & quantities)
1510 int ID = myElementIDFactory->GetFreeID();
1511 SMDS_MeshVolume * v = SMDS_Mesh::AddPolyhedralVolumeWithID(nodes, quantities, ID);
1512 if (v == NULL) myElementIDFactory->ReleaseID(ID);
1516 SMDS_MeshVolume* SMDS_Mesh::AddVolumeFromVtkIds(const std::vector<vtkIdType>& vtkNodeIds)
1518 int ID = myElementIDFactory->GetFreeID();
1519 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeFromVtkIdsWithID(vtkNodeIds, ID);
1520 if (v == NULL) myElementIDFactory->ReleaseID(ID);
1524 SMDS_MeshVolume* SMDS_Mesh::AddVolumeFromVtkIdsWithID(const std::vector<vtkIdType>& vtkNodeIds, const int ID)
1526 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
1527 volvtk->init(vtkNodeIds, this);
1528 if (!this->registerElement(ID,volvtk))
1530 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
1531 myVolumePool->destroy(volvtk);
1534 adjustmyCellsCapacity(ID);
1535 myCells[ID] = volvtk;
1536 vtkIdType aVtkType = volvtk->GetVtkType();
1540 myInfo.myNbTetras++;
1543 myInfo.myNbPyramids++;
1546 myInfo.myNbPrisms++;
1548 case VTK_HEXAHEDRON:
1551 case VTK_QUADRATIC_TETRA:
1552 myInfo.myNbQuadTetras++;
1554 case VTK_QUADRATIC_PYRAMID:
1555 myInfo.myNbQuadPyramids++;
1557 case VTK_QUADRATIC_WEDGE:
1558 myInfo.myNbQuadPrisms++;
1560 case VTK_QUADRATIC_HEXAHEDRON:
1561 myInfo.myNbQuadHexas++;
1563 //#ifdef VTK_HAVE_POLYHEDRON
1564 case VTK_POLYHEDRON:
1565 myInfo.myNbPolyhedrons++;
1569 myInfo.myNbPolyhedrons++;
1575 SMDS_MeshFace* SMDS_Mesh::AddFaceFromVtkIds(const std::vector<vtkIdType>& vtkNodeIds)
1577 int ID = myElementIDFactory->GetFreeID();
1578 SMDS_MeshFace * f = SMDS_Mesh::AddFaceFromVtkIdsWithID(vtkNodeIds, ID);
1579 if (f == NULL) myElementIDFactory->ReleaseID(ID);
1583 SMDS_MeshFace* SMDS_Mesh::AddFaceFromVtkIdsWithID(const std::vector<vtkIdType>& vtkNodeIds, const int ID)
1585 SMDS_VtkFace *facevtk = myFacePool->getNew();
1586 facevtk->init(vtkNodeIds, this);
1587 if (!this->registerElement(ID,facevtk))
1589 this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL);
1590 myFacePool->destroy(facevtk);
1593 adjustmyCellsCapacity(ID);
1594 myCells[ID] = facevtk;
1595 vtkIdType aVtkType = facevtk->GetVtkType();
1599 myInfo.myNbTriangles++;
1602 myInfo.myNbQuadrangles++;
1604 case VTK_QUADRATIC_TRIANGLE:
1605 myInfo.myNbQuadTriangles++;
1607 case VTK_QUADRATIC_QUAD:
1608 myInfo.myNbQuadQuadrangles++;
1610 case VTK_BIQUADRATIC_QUAD:
1611 myInfo.myNbBiQuadQuadrangles++;
1613 case VTK_BIQUADRATIC_TRIANGLE:
1614 myInfo.myNbBiQuadTriangles++;
1617 myInfo.myNbPolygons++;
1620 myInfo.myNbPolygons++;
1625 ///////////////////////////////////////////////////////////////////////////////
1626 /// Registers element with the given ID, maintains inverse connections
1627 ///////////////////////////////////////////////////////////////////////////////
1628 bool SMDS_Mesh::registerElement(int ID, SMDS_MeshElement* element)
1630 if ((ID >=0) && (ID < (int)myCells.size()) && myCells[ID]) // --- already bound
1632 MESSAGE(" ------------------ already bound "<< ID << " " << myCells[ID]->getVtkId());
1637 element->myMeshId = myMeshId;
1639 SMDS_MeshCell *cell = dynamic_cast<SMDS_MeshCell*>(element);
1641 int vtkId = cell->getVtkId();
1643 vtkId = myElementIDFactory->SetInVtkGrid(element);
1645 if (vtkId >= (int)myCellIdVtkToSmds.size()) // --- resize local vector
1647 myCellIdVtkToSmds.resize(vtkId + SMDS_Mesh::chunkSize, -1);
1649 myCellIdVtkToSmds[vtkId] = ID;
1651 myElementIDFactory->updateMinMax(ID);
1655 //=======================================================================
1656 //function : MoveNode
1658 //=======================================================================
1660 void SMDS_Mesh::MoveNode(const SMDS_MeshNode *n, double x, double y, double z)
1662 SMDS_MeshNode * node=const_cast<SMDS_MeshNode*>(n);
1663 node->setXYZ(x,y,z);
1666 ///////////////////////////////////////////////////////////////////////////////
1667 /// Return the node whose SMDS ID is 'ID'.
1668 ///////////////////////////////////////////////////////////////////////////////
1669 const SMDS_MeshNode * SMDS_Mesh::FindNode(int ID) const
1671 if (ID < 1 || ID >= (int)myNodes.size())
1675 return (const SMDS_MeshNode *)myNodes[ID];
1678 ///////////////////////////////////////////////////////////////////////////////
1679 /// Return the node whose VTK ID is 'vtkId'.
1680 ///////////////////////////////////////////////////////////////////////////////
1681 const SMDS_MeshNode * SMDS_Mesh::FindNodeVtk(int vtkId) const
1683 // TODO if needed use mesh->nodeIdFromVtkToSmds
1684 if ( vtkId < 0 || vtkId+1 >= (int) myNodes.size() )
1686 MESSAGE("------------------------------------------------------------------------- ");
1687 MESSAGE("---------------------------- bad VTK ID " << vtkId << " " << myNodes.size());
1688 MESSAGE("------------------------------------------------------------------------- ");
1691 return (const SMDS_MeshNode *)myNodes[vtkId+1];
1694 ///////////////////////////////////////////////////////////////////////////////
1695 ///Create a triangle and add it to the current mesh. This method do not bind an
1696 ///ID to the create triangle.
1697 ///////////////////////////////////////////////////////////////////////////////
1698 SMDS_MeshFace * SMDS_Mesh::createTriangle(const SMDS_MeshNode * node1,
1699 const SMDS_MeshNode * node2,
1700 const SMDS_MeshNode * node3,
1703 if ( !node1 || !node2 || !node3) return 0;
1704 if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1705 if(hasConstructionEdges())
1707 SMDS_MeshEdge *edge1, *edge2, *edge3;
1708 edge1=FindEdgeOrCreate(node1,node2);
1709 edge2=FindEdgeOrCreate(node2,node3);
1710 edge3=FindEdgeOrCreate(node3,node1);
1712 //int ID = myElementIDFactory->GetFreeID(); // -PR- voir si on range cet element
1713 SMDS_MeshFace * face = new SMDS_FaceOfEdges(edge1,edge2,edge3);
1714 adjustmyCellsCapacity(ID);
1716 myInfo.myNbTriangles++;
1721 // --- retrieve nodes ID
1722 myNodeIds.resize(3);
1723 myNodeIds[0] = node1->getVtkId();
1724 myNodeIds[1] = node2->getVtkId();
1725 myNodeIds[2] = node3->getVtkId();
1727 SMDS_MeshFace * face = 0;
1728 SMDS_VtkFace *facevtk = myFacePool->getNew();
1729 facevtk->init(myNodeIds, this); // put in vtkUnstructuredGrid
1730 if (!this->registerElement(ID,facevtk))
1732 this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL);
1733 myFacePool->destroy(facevtk);
1737 adjustmyCellsCapacity(ID);
1739 myInfo.myNbTriangles++;
1744 ///////////////////////////////////////////////////////////////////////////////
1745 ///Create a quadrangle and add it to the current mesh. This methode do not bind
1746 ///a ID to the create triangle.
1747 ///////////////////////////////////////////////////////////////////////////////
1748 SMDS_MeshFace * SMDS_Mesh::createQuadrangle(const SMDS_MeshNode * node1,
1749 const SMDS_MeshNode * node2,
1750 const SMDS_MeshNode * node3,
1751 const SMDS_MeshNode * node4,
1754 if ( !node1 || !node2 || !node3 || !node4 ) return 0;
1755 if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1756 if(hasConstructionEdges())
1758 SMDS_MeshEdge *edge1, *edge2, *edge3, *edge4;
1759 edge1=FindEdgeOrCreate(node1,node2);
1760 edge2=FindEdgeOrCreate(node2,node3);
1761 edge3=FindEdgeOrCreate(node3,node4);
1762 edge4=FindEdgeOrCreate(node4,node1);
1764 SMDS_MeshFace * face = new SMDS_FaceOfEdges(edge1,edge2,edge3,edge4);
1765 adjustmyCellsCapacity(ID);
1767 myInfo.myNbQuadrangles++;
1772 // --- retrieve nodes ID
1773 myNodeIds.resize(4);
1774 myNodeIds[0] = node1->getVtkId();
1775 myNodeIds[1] = node2->getVtkId();
1776 myNodeIds[2] = node3->getVtkId();
1777 myNodeIds[3] = node4->getVtkId();
1779 SMDS_MeshFace * face = 0;
1780 SMDS_VtkFace *facevtk = myFacePool->getNew();
1781 facevtk->init(myNodeIds, this);
1782 if (!this->registerElement(ID,facevtk))
1784 this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL);
1785 myFacePool->destroy(facevtk);
1789 adjustmyCellsCapacity(ID);
1791 myInfo.myNbQuadrangles++;
1796 ///////////////////////////////////////////////////////////////////////////////
1797 /// Remove a node and all the elements which own this node
1798 ///////////////////////////////////////////////////////////////////////////////
1800 void SMDS_Mesh::RemoveNode(const SMDS_MeshNode * node)
1802 RemoveElement(node, true);
1805 ///////////////////////////////////////////////////////////////////////////////
1806 /// Remove an edge and all the elements which own this edge
1807 ///////////////////////////////////////////////////////////////////////////////
1809 void SMDS_Mesh::Remove0DElement(const SMDS_Mesh0DElement * elem0d)
1811 RemoveElement(elem0d,true);
1814 ///////////////////////////////////////////////////////////////////////////////
1815 /// Remove an edge and all the elements which own this edge
1816 ///////////////////////////////////////////////////////////////////////////////
1818 void SMDS_Mesh::RemoveEdge(const SMDS_MeshEdge * edge)
1820 RemoveElement(edge,true);
1823 ///////////////////////////////////////////////////////////////////////////////
1824 /// Remove an face and all the elements which own this face
1825 ///////////////////////////////////////////////////////////////////////////////
1827 void SMDS_Mesh::RemoveFace(const SMDS_MeshFace * face)
1829 RemoveElement(face, true);
1832 ///////////////////////////////////////////////////////////////////////////////
1834 ///////////////////////////////////////////////////////////////////////////////
1836 void SMDS_Mesh::RemoveVolume(const SMDS_MeshVolume * volume)
1838 RemoveElement(volume, true);
1841 //=======================================================================
1842 //function : RemoveFromParent
1844 //=======================================================================
1846 bool SMDS_Mesh::RemoveFromParent()
1848 if (myParent==NULL) return false;
1849 else return (myParent->RemoveSubMesh(this));
1852 //=======================================================================
1853 //function : RemoveSubMesh
1855 //=======================================================================
1857 bool SMDS_Mesh::RemoveSubMesh(const SMDS_Mesh * aMesh)
1861 list<SMDS_Mesh *>::iterator itmsh=myChildren.begin();
1862 for (; itmsh!=myChildren.end() && !found; itmsh++)
1864 SMDS_Mesh * submesh = *itmsh;
1865 if (submesh == aMesh)
1868 myChildren.erase(itmsh);
1875 //=======================================================================
1876 //function : ChangeElementNodes
1878 //=======================================================================
1880 bool SMDS_Mesh::ChangeElementNodes(const SMDS_MeshElement * element,
1881 const SMDS_MeshNode * nodes[],
1884 // keep current nodes of elem
1885 set<const SMDS_MeshNode*> oldNodes( element->begin_nodes(), element->end_nodes() );
1889 SMDS_MeshCell* cell = dynamic_cast<SMDS_MeshCell*>((SMDS_MeshElement*) element);
1892 Ok = cell->vtkOrder(nodes, nbnodes);
1893 Ok = cell->ChangeNodes(nodes, nbnodes);
1896 if ( Ok ) { // update InverseElements
1898 set<const SMDS_MeshNode*>::iterator it;
1900 // AddInverseElement to new nodes
1901 for ( int i = 0; i < nbnodes; i++ ) {
1902 it = oldNodes.find( nodes[i] );
1903 if ( it == oldNodes.end() )
1905 const_cast<SMDS_MeshNode*>( nodes[i] )->AddInverseElement( cell );
1907 // remove from oldNodes a node that remains in elem
1908 oldNodes.erase( it );
1910 // RemoveInverseElement from the nodes removed from elem
1911 for ( it = oldNodes.begin(); it != oldNodes.end(); it++ )
1913 SMDS_MeshNode * n = const_cast<SMDS_MeshNode *>( *it );
1914 n->RemoveInverseElement( cell );
1921 //=======================================================================
1922 //function : ChangePolyhedronNodes
1923 //purpose : to change nodes of polyhedral volume
1924 //=======================================================================
1925 bool SMDS_Mesh::ChangePolyhedronNodes (const SMDS_MeshElement * elem,
1926 const vector<const SMDS_MeshNode*>& nodes,
1927 const vector<int> & quantities)
1929 if (elem->GetType() != SMDSAbs_Volume) {
1930 MESSAGE("WRONG ELEM TYPE");
1934 const SMDS_VtkVolume* vol = dynamic_cast<const SMDS_VtkVolume*>(elem);
1939 // keep current nodes of elem
1940 set<const SMDS_MeshElement*> oldNodes;
1941 SMDS_ElemIteratorPtr itn = elem->nodesIterator();
1942 while (itn->more()) {
1943 oldNodes.insert(itn->next());
1947 // TODO remove this function
1948 //bool Ok = const_cast<SMDS_VtkVolume*>(vol)->ChangeNodes(nodes, quantities);
1954 // update InverseElements
1956 // AddInverseElement to new nodes
1957 int nbnodes = nodes.size();
1958 set<const SMDS_MeshElement*>::iterator it;
1959 for (int i = 0; i < nbnodes; i++) {
1960 it = oldNodes.find(nodes[i]);
1961 if (it == oldNodes.end()) {
1963 const_cast<SMDS_MeshNode*>(nodes[i])->AddInverseElement(elem);
1965 // remove from oldNodes a node that remains in elem
1970 // RemoveInverseElement from the nodes removed from elem
1971 for (it = oldNodes.begin(); it != oldNodes.end(); it++) {
1972 SMDS_MeshNode * n = static_cast<SMDS_MeshNode *>
1973 (const_cast<SMDS_MeshElement *>( *it ));
1974 n->RemoveInverseElement(elem);
1981 //=======================================================================
1982 //function : Find0DElement
1984 //=======================================================================
1985 const SMDS_Mesh0DElement* SMDS_Mesh::Find0DElement(int idnode) const
1987 const SMDS_MeshNode * node = FindNode(idnode);
1988 if(node == NULL) return NULL;
1989 return Find0DElement(node);
1992 const SMDS_Mesh0DElement* SMDS_Mesh::Find0DElement(const SMDS_MeshNode * node)
1994 if (!node) return 0;
1995 const SMDS_Mesh0DElement* toReturn = NULL;
1996 SMDS_ElemIteratorPtr it1 = node->GetInverseElementIterator(SMDSAbs_0DElement);
1997 while (it1->more() && (toReturn == NULL)) {
1998 const SMDS_MeshElement* e = it1->next();
1999 if (e->NbNodes() == 1) {
2000 toReturn = static_cast<const SMDS_Mesh0DElement*>(e);
2006 //=======================================================================
2007 //function : FindBall
2009 //=======================================================================
2011 const SMDS_BallElement* SMDS_Mesh::FindBall(int idnode) const
2013 const SMDS_MeshNode * node = FindNode(idnode);
2014 if(node == NULL) return NULL;
2015 return FindBall(node);
2018 const SMDS_BallElement* SMDS_Mesh::FindBall(const SMDS_MeshNode * node)
2020 if (!node) return 0;
2021 const SMDS_BallElement* toReturn = NULL;
2022 SMDS_ElemIteratorPtr it1 = node->GetInverseElementIterator(SMDSAbs_Ball);
2023 while (it1->more() && (toReturn == NULL)) {
2024 const SMDS_MeshElement* e = it1->next();
2025 if (e->GetGeomType() == SMDSGeom_BALL)
2026 toReturn = static_cast<const SMDS_BallElement*>(e);
2031 //=======================================================================
2032 //function : Find0DElementOrCreate
2034 //=======================================================================
2035 //SMDS_Mesh0DElement* SMDS_Mesh::Find0DElementOrCreate(const SMDS_MeshNode * node)
2037 // if (!node) return 0;
2038 // SMDS_Mesh0DElement * toReturn = NULL;
2039 // toReturn = const_cast<SMDS_Mesh0DElement*>(Find0DElement(node));
2040 // if (toReturn == NULL) {
2041 // //if (my0DElements.Extent() % CHECKMEMORY_INTERVAL == 0) CheckMemory();
2042 // toReturn = new SMDS_Mesh0DElement(node);
2043 // my0DElements.Add(toReturn);
2044 // myInfo.myNb0DElements++;
2050 //=======================================================================
2051 //function : FindEdge
2053 //=======================================================================
2055 const SMDS_MeshEdge* SMDS_Mesh::FindEdge(int idnode1, int idnode2) const
2057 const SMDS_MeshNode * node1=FindNode(idnode1);
2058 const SMDS_MeshNode * node2=FindNode(idnode2);
2059 if((node1==NULL)||(node2==NULL)) return NULL;
2060 return FindEdge(node1,node2);
2063 //#include "Profiler.h"
2064 const SMDS_MeshEdge* SMDS_Mesh::FindEdge(const SMDS_MeshNode * node1,
2065 const SMDS_MeshNode * node2)
2067 if ( !node1 ) return 0;
2068 const SMDS_MeshEdge * toReturn=NULL;
2071 SMDS_ElemIteratorPtr it1=node1->GetInverseElementIterator(SMDSAbs_Edge);
2074 while(it1->more()) {
2075 const SMDS_MeshElement * e = it1->next();
2076 if ( e->NbNodes() == 2 && e->GetNodeIndex( node2 ) >= 0 ) {
2077 toReturn = static_cast<const SMDS_MeshEdge*>( e );
2086 //=======================================================================
2087 //function : FindEdgeOrCreate
2089 //=======================================================================
2091 SMDS_MeshEdge* SMDS_Mesh::FindEdgeOrCreate(const SMDS_MeshNode * node1,
2092 const SMDS_MeshNode * node2)
2094 if ( !node1 || !node2) return 0;
2095 SMDS_MeshEdge * toReturn=NULL;
2096 toReturn=const_cast<SMDS_MeshEdge*>(FindEdge(node1,node2));
2097 if(toReturn==NULL) {
2098 if ( NbEdges() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
2099 int ID = myElementIDFactory->GetFreeID(); // -PR- voir si on range cet element
2100 adjustmyCellsCapacity(ID);
2101 myNodeIds.resize(2);
2102 myNodeIds[0] = node1->getVtkId();
2103 myNodeIds[1] = node2->getVtkId();
2105 SMDS_VtkEdge *edgevtk = myEdgePool->getNew();
2106 edgevtk->init(myNodeIds, this);
2107 if (!this->registerElement(ID,edgevtk))
2109 this->myGrid->GetCellTypesArray()->SetValue(edgevtk->getVtkId(), VTK_EMPTY_CELL);
2110 myEdgePool->destroy(edgevtk);
2114 myCells[ID] = toReturn;
2121 //=======================================================================
2122 //function : FindEdge
2124 //=======================================================================
2126 const SMDS_MeshEdge* SMDS_Mesh::FindEdge(int idnode1, int idnode2,
2129 const SMDS_MeshNode * node1=FindNode(idnode1);
2130 const SMDS_MeshNode * node2=FindNode(idnode2);
2131 const SMDS_MeshNode * node3=FindNode(idnode3);
2132 return FindEdge(node1,node2,node3);
2135 const SMDS_MeshEdge* SMDS_Mesh::FindEdge(const SMDS_MeshNode * node1,
2136 const SMDS_MeshNode * node2,
2137 const SMDS_MeshNode * node3)
2139 if ( !node1 ) return 0;
2140 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Edge);
2141 while(it1->more()) {
2142 const SMDS_MeshElement * e = it1->next();
2143 if ( e->NbNodes() == 3 ) {
2144 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
2145 while(it2->more()) {
2146 const SMDS_MeshElement* n = it2->next();
2156 return static_cast<const SMDS_MeshEdge *> (e);
2163 //=======================================================================
2164 //function : FindFace
2166 //=======================================================================
2168 const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2,
2171 const SMDS_MeshNode * node1=FindNode(idnode1);
2172 const SMDS_MeshNode * node2=FindNode(idnode2);
2173 const SMDS_MeshNode * node3=FindNode(idnode3);
2174 return FindFace(node1, node2, node3);
2177 const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1,
2178 const SMDS_MeshNode *node2,
2179 const SMDS_MeshNode *node3)
2181 if ( !node1 ) return 0;
2182 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Face);
2183 while(it1->more()) {
2184 const SMDS_MeshElement * e = it1->next();
2185 if ( e->NbNodes() == 3 ) {
2186 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
2187 while(it2->more()) {
2188 const SMDS_MeshElement* n = it2->next();
2198 return static_cast<const SMDS_MeshFace *> (e);
2204 SMDS_MeshFace* SMDS_Mesh::FindFaceOrCreate(const SMDS_MeshNode *node1,
2205 const SMDS_MeshNode *node2,
2206 const SMDS_MeshNode *node3)
2208 SMDS_MeshFace * toReturn=NULL;
2209 toReturn = const_cast<SMDS_MeshFace*>(FindFace(node1,node2,node3));
2210 if(toReturn==NULL) {
2211 int ID = myElementIDFactory->GetFreeID();
2212 toReturn = createTriangle(node1,node2,node3, ID);
2218 //=======================================================================
2219 //function : FindFace
2221 //=======================================================================
2223 const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2,
2224 int idnode3, int idnode4) const
2226 const SMDS_MeshNode * node1=FindNode(idnode1);
2227 const SMDS_MeshNode * node2=FindNode(idnode2);
2228 const SMDS_MeshNode * node3=FindNode(idnode3);
2229 const SMDS_MeshNode * node4=FindNode(idnode4);
2230 return FindFace(node1, node2, node3, node4);
2233 const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1,
2234 const SMDS_MeshNode *node2,
2235 const SMDS_MeshNode *node3,
2236 const SMDS_MeshNode *node4)
2238 if ( !node1 ) return 0;
2239 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Face);
2240 while(it1->more()) {
2241 const SMDS_MeshElement * e = it1->next();
2242 if ( e->NbNodes() == 4 ) {
2243 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
2244 while(it2->more()) {
2245 const SMDS_MeshElement* n = it2->next();
2256 return static_cast<const SMDS_MeshFace *> (e);
2262 SMDS_MeshFace* SMDS_Mesh::FindFaceOrCreate(const SMDS_MeshNode *node1,
2263 const SMDS_MeshNode *node2,
2264 const SMDS_MeshNode *node3,
2265 const SMDS_MeshNode *node4)
2267 SMDS_MeshFace * toReturn=NULL;
2268 toReturn=const_cast<SMDS_MeshFace*>(FindFace(node1,node2,node3,node4));
2269 if(toReturn==NULL) {
2270 int ID = myElementIDFactory->GetFreeID();
2271 toReturn=createQuadrangle(node1,node2,node3,node4,ID);
2277 //=======================================================================
2278 //function : FindFace
2279 //purpose :quadratic triangle
2280 //=======================================================================
2282 const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2,
2283 int idnode3, int idnode4,
2284 int idnode5, int idnode6) const
2286 const SMDS_MeshNode * node1 = FindNode(idnode1);
2287 const SMDS_MeshNode * node2 = FindNode(idnode2);
2288 const SMDS_MeshNode * node3 = FindNode(idnode3);
2289 const SMDS_MeshNode * node4 = FindNode(idnode4);
2290 const SMDS_MeshNode * node5 = FindNode(idnode5);
2291 const SMDS_MeshNode * node6 = FindNode(idnode6);
2292 return FindFace(node1, node2, node3, node4, node5, node6);
2295 const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1,
2296 const SMDS_MeshNode *node2,
2297 const SMDS_MeshNode *node3,
2298 const SMDS_MeshNode *node4,
2299 const SMDS_MeshNode *node5,
2300 const SMDS_MeshNode *node6)
2302 if ( !node1 ) return 0;
2303 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Face);
2304 while(it1->more()) {
2305 const SMDS_MeshElement * e = it1->next();
2306 if ( e->NbNodes() == 6 ) {
2307 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
2308 while(it2->more()) {
2309 const SMDS_MeshElement* n = it2->next();
2322 return static_cast<const SMDS_MeshFace *> (e);
2329 //=======================================================================
2330 //function : FindFace
2331 //purpose : quadratic quadrangle
2332 //=======================================================================
2334 const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2,
2335 int idnode3, int idnode4,
2336 int idnode5, int idnode6,
2337 int idnode7, int idnode8) const
2339 const SMDS_MeshNode * node1 = FindNode(idnode1);
2340 const SMDS_MeshNode * node2 = FindNode(idnode2);
2341 const SMDS_MeshNode * node3 = FindNode(idnode3);
2342 const SMDS_MeshNode * node4 = FindNode(idnode4);
2343 const SMDS_MeshNode * node5 = FindNode(idnode5);
2344 const SMDS_MeshNode * node6 = FindNode(idnode6);
2345 const SMDS_MeshNode * node7 = FindNode(idnode7);
2346 const SMDS_MeshNode * node8 = FindNode(idnode8);
2347 return FindFace(node1, node2, node3, node4, node5, node6, node7, node8);
2350 const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1,
2351 const SMDS_MeshNode *node2,
2352 const SMDS_MeshNode *node3,
2353 const SMDS_MeshNode *node4,
2354 const SMDS_MeshNode *node5,
2355 const SMDS_MeshNode *node6,
2356 const SMDS_MeshNode *node7,
2357 const SMDS_MeshNode *node8)
2359 if ( !node1 ) return 0;
2360 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Face);
2361 while(it1->more()) {
2362 const SMDS_MeshElement * e = it1->next();
2363 if ( e->NbNodes() == 8 ) {
2364 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
2365 while(it2->more()) {
2366 const SMDS_MeshElement* n = it2->next();
2381 return static_cast<const SMDS_MeshFace *> (e);
2388 //=======================================================================
2389 //function : FindElement
2391 //=======================================================================
2393 const SMDS_MeshElement* SMDS_Mesh::FindElement(int IDelem) const
2395 if ( IDelem <= 0 || IDelem >= (int)myCells.size() )
2399 return myCells[IDelem];
2402 //=======================================================================
2403 //function : FindFace
2404 //purpose : find polygon
2405 //=======================================================================
2407 const SMDS_MeshFace* SMDS_Mesh::FindFace (const vector<int>& nodes_ids) const
2409 int nbnodes = nodes_ids.size();
2410 vector<const SMDS_MeshNode *> poly_nodes (nbnodes);
2411 for (int inode = 0; inode < nbnodes; inode++) {
2412 const SMDS_MeshNode * node = FindNode(nodes_ids[inode]);
2413 if (node == NULL) return NULL;
2414 poly_nodes[inode] = node;
2416 return FindFace(poly_nodes);
2419 const SMDS_MeshFace* SMDS_Mesh::FindFace (const vector<const SMDS_MeshNode *>& nodes)
2421 return (const SMDS_MeshFace*) FindElement( nodes, SMDSAbs_Face );
2425 //================================================================================
2427 * \brief Return element based on all given nodes
2428 * \param nodes - node of element
2429 * \param type - type of element
2430 * \param noMedium - true if medium nodes of quadratic element are not included in <nodes>
2431 * \retval const SMDS_MeshElement* - found element or NULL
2433 //================================================================================
2435 const SMDS_MeshElement* SMDS_Mesh::FindElement (const vector<const SMDS_MeshNode *>& nodes,
2436 const SMDSAbs_ElementType type,
2437 const bool noMedium)
2439 if ( nodes.size() > 0 && nodes[0] )
2441 SMDS_ElemIteratorPtr itF = nodes[0]->GetInverseElementIterator(type);
2444 const SMDS_MeshElement* e = itF->next();
2445 int nbNodesToCheck = noMedium ? e->NbCornerNodes() : e->NbNodes();
2446 if ( nbNodesToCheck == (int)nodes.size() )
2448 for ( size_t i = 1; e && i < nodes.size(); ++i )
2450 int nodeIndex = e->GetNodeIndex( nodes[ i ]);
2451 if ( nodeIndex < 0 || nodeIndex >= nbNodesToCheck )
2462 //=======================================================================
2463 //function : DumpNodes
2465 //=======================================================================
2467 void SMDS_Mesh::DumpNodes() const
2469 SMDS_NodeIteratorPtr itnode=nodesIterator();
2470 while(itnode->more()) ; //MESSAGE(itnode->next());
2473 //=======================================================================
2474 //function : Dump0DElements
2476 //=======================================================================
2477 void SMDS_Mesh::Dump0DElements() const
2479 SMDS_ElemIteratorPtr it0d = elementsIterator(SMDSAbs_0DElement);
2480 while(it0d->more()) ; //MESSAGE(it0d->next());
2483 //=======================================================================
2484 //function : DumpEdges
2486 //=======================================================================
2488 void SMDS_Mesh::DumpEdges() const
2490 SMDS_EdgeIteratorPtr itedge=edgesIterator();
2491 while(itedge->more()) ; //MESSAGE(itedge->next());
2494 //=======================================================================
2495 //function : DumpFaces
2497 //=======================================================================
2499 void SMDS_Mesh::DumpFaces() const
2501 SMDS_FaceIteratorPtr itface=facesIterator();
2502 while(itface->more()) ; //MESSAGE(itface->next());
2505 //=======================================================================
2506 //function : DumpVolumes
2508 //=======================================================================
2510 void SMDS_Mesh::DumpVolumes() const
2512 SMDS_VolumeIteratorPtr itvol=volumesIterator();
2513 while(itvol->more()) ; //MESSAGE(itvol->next());
2516 //=======================================================================
2517 //function : DebugStats
2519 //=======================================================================
2521 void SMDS_Mesh::DebugStats() const
2523 MESSAGE("Debug stats of mesh : ");
2525 MESSAGE("===== NODES ====="<<NbNodes());
2526 MESSAGE("===== 0DELEMS ====="<<Nb0DElements());
2527 MESSAGE("===== EDGES ====="<<NbEdges());
2528 MESSAGE("===== FACES ====="<<NbFaces());
2529 MESSAGE("===== VOLUMES ====="<<NbVolumes());
2531 MESSAGE("End Debug stats of mesh ");
2535 SMDS_NodeIteratorPtr itnode=nodesIterator();
2536 int sizeofnodes = 0;
2537 int sizeoffaces = 0;
2539 while(itnode->more())
2541 const SMDS_MeshNode *node = itnode->next();
2543 sizeofnodes += sizeof(*node);
2545 SMDS_ElemIteratorPtr it = node->GetInverseElementIterator();
2548 const SMDS_MeshElement *me = it->next();
2549 sizeofnodes += sizeof(me);
2553 SMDS_FaceIteratorPtr itface=facesIterator();
2554 while(itface->more())
2556 const SMDS_MeshElement *face = itface->next();
2557 sizeoffaces += sizeof(*face);
2560 MESSAGE("total size of node elements = " << sizeofnodes);;
2561 MESSAGE("total size of face elements = " << sizeoffaces);;
2566 ///////////////////////////////////////////////////////////////////////////////
2567 /// Return the number of nodes
2568 ///////////////////////////////////////////////////////////////////////////////
2569 int SMDS_Mesh::NbNodes() const
2571 return myInfo.NbNodes();
2574 ///////////////////////////////////////////////////////////////////////////////
2575 /// Return the number of 0D elements
2576 ///////////////////////////////////////////////////////////////////////////////
2577 int SMDS_Mesh::Nb0DElements() const
2579 return myInfo.Nb0DElements();
2582 ///////////////////////////////////////////////////////////////////////////////
2583 /// Return the number of 0D elements
2584 ///////////////////////////////////////////////////////////////////////////////
2585 int SMDS_Mesh::NbBalls() const
2587 return myInfo.NbBalls();
2590 ///////////////////////////////////////////////////////////////////////////////
2591 /// Return the number of edges (including construction edges)
2592 ///////////////////////////////////////////////////////////////////////////////
2593 int SMDS_Mesh::NbEdges() const
2595 return myInfo.NbEdges();
2598 ///////////////////////////////////////////////////////////////////////////////
2599 /// Return the number of faces (including construction faces)
2600 ///////////////////////////////////////////////////////////////////////////////
2601 int SMDS_Mesh::NbFaces() const
2603 return myInfo.NbFaces();
2606 ///////////////////////////////////////////////////////////////////////////////
2607 /// Return the number of volumes
2608 ///////////////////////////////////////////////////////////////////////////////
2609 int SMDS_Mesh::NbVolumes() const
2611 return myInfo.NbVolumes();
2614 ///////////////////////////////////////////////////////////////////////////////
2615 /// Return the number of child mesh of this mesh.
2616 /// Note that the tree structure of SMDS_Mesh is unused in SMESH
2617 ///////////////////////////////////////////////////////////////////////////////
2618 int SMDS_Mesh::NbSubMesh() const
2620 return myChildren.size();
2623 ///////////////////////////////////////////////////////////////////////////////
2624 /// Destroy the mesh and all its elements
2625 /// All pointer on elements owned by this mesh become illegals.
2626 ///////////////////////////////////////////////////////////////////////////////
2627 SMDS_Mesh::~SMDS_Mesh()
2629 list<SMDS_Mesh*>::iterator itc=myChildren.begin();
2630 while(itc!=myChildren.end())
2638 delete myNodeIDFactory;
2639 delete myElementIDFactory;
2643 SMDS_ElemIteratorPtr eIt = elementsIterator();
2644 while ( eIt->more() )
2646 const SMDS_MeshElement *elem = eIt->next();
2647 myElementIDFactory->ReleaseID(elem->GetID(), elem->getVtkId());
2649 SMDS_NodeIteratorPtr itn = nodesIterator();
2652 const SMDS_MeshNode *node = itn->next();
2653 ((SMDS_MeshNode*)node)->SetPosition(SMDS_SpacePosition::originSpacePosition());
2654 myNodeIDFactory->ReleaseID(node->GetID(), node->getVtkId());
2660 delete myVolumePool;
2666 //================================================================================
2668 * \brief Clear all data
2670 //================================================================================
2672 void SMDS_Mesh::Clear()
2676 SMDS_ElemIteratorPtr eIt = elementsIterator();
2677 while ( eIt->more() )
2679 const SMDS_MeshElement *elem = eIt->next();
2680 myElementIDFactory->ReleaseID(elem->GetID(), elem->getVtkId());
2682 SMDS_NodeIteratorPtr itn = nodesIterator();
2685 const SMDS_MeshNode *node = itn->next();
2686 myNodeIDFactory->ReleaseID(node->GetID(), node->getVtkId());
2691 myNodeIDFactory->Clear();
2692 myElementIDFactory->Clear();
2695 // SMDS_ElemIteratorPtr itv = elementsIterator();
2696 // while (itv->more())
2698 // SMDS_MeshElement* elem = (SMDS_MeshElement*)(itv->next());
2699 // SMDSAbs_ElementType aType = elem->GetType();
2702 // case SMDSAbs_0DElement:
2705 // case SMDSAbs_Edge:
2706 // myEdgePool->destroy(static_cast<SMDS_VtkEdge*>(elem));
2708 // case SMDSAbs_Face:
2709 // myFacePool->destroy(static_cast<SMDS_VtkFace*>(elem));
2711 // case SMDSAbs_Volume:
2712 // myVolumePool->destroy(static_cast<SMDS_VtkVolume*>(elem));
2714 // case SMDSAbs_Ball:
2715 // myBallPool->destroy(static_cast<SMDS_BallElement*>(elem));
2721 myVolumePool->clear();
2722 myFacePool->clear();
2723 myEdgePool->clear();
2724 myBallPool->clear();
2726 clearVector( myCells );
2727 clearVector( myCellIdVtkToSmds );
2729 SMDS_NodeIteratorPtr itn = nodesIterator();
2732 SMDS_MeshNode *node = (SMDS_MeshNode*)(itn->next());
2733 node->SetPosition(SMDS_SpacePosition::originSpacePosition());
2734 //myNodePool->destroy(node);
2736 myNodePool->clear();
2737 clearVector( myNodes );
2739 list<SMDS_Mesh*>::iterator itc=myChildren.begin();
2740 while(itc!=myChildren.end())
2751 myGrid->Initialize();
2753 vtkPoints* points = vtkPoints::New();
2754 // rnv: to fix bug "21125: EDF 1233 SMESH: Degrardation of precision in a test case for quadratic conversion"
2755 // using double type for storing coordinates of nodes instead float.
2756 points->SetDataType(VTK_DOUBLE);
2757 points->SetNumberOfPoints(0 /*SMDS_Mesh::chunkSize*/);
2758 myGrid->SetPoints( points );
2760 myGrid->BuildLinks();
2763 ///////////////////////////////////////////////////////////////////////////////
2764 /// Return true if this mesh create faces with edges.
2765 /// A false returned value mean that faces are created with nodes. A concequence
2766 /// is, iteration on edges (SMDS_Element::edgesIterator) will be unavailable.
2767 ///////////////////////////////////////////////////////////////////////////////
2768 bool SMDS_Mesh::hasConstructionEdges()
2770 return myHasConstructionEdges;
2773 ///////////////////////////////////////////////////////////////////////////////
2774 /// Return true if this mesh create volumes with faces
2775 /// A false returned value mean that volumes are created with nodes or edges.
2776 /// (see hasConstructionEdges)
2777 /// A concequence is, iteration on faces (SMDS_Element::facesIterator) will be
2779 ///////////////////////////////////////////////////////////////////////////////
2780 bool SMDS_Mesh::hasConstructionFaces()
2782 return myHasConstructionFaces;
2785 ///////////////////////////////////////////////////////////////////////////////
2786 /// Return true if nodes are linked to the finit elements, they are belonging to.
2787 /// Currently, It always return true.
2788 ///////////////////////////////////////////////////////////////////////////////
2789 bool SMDS_Mesh::hasInverseElements()
2791 return myHasInverseElements;
2794 ///////////////////////////////////////////////////////////////////////////////
2795 /// Make this mesh creating construction edges (see hasConstructionEdges)
2796 /// @param b true to have construction edges, else false.
2797 ///////////////////////////////////////////////////////////////////////////////
2798 void SMDS_Mesh::setConstructionEdges(bool b)
2800 myHasConstructionEdges=b;
2803 ///////////////////////////////////////////////////////////////////////////////
2804 /// Make this mesh creating construction faces (see hasConstructionFaces)
2805 /// @param b true to have construction faces, else false.
2806 ///////////////////////////////////////////////////////////////////////////////
2807 void SMDS_Mesh::setConstructionFaces(bool b)
2809 myHasConstructionFaces=b;
2812 ///////////////////////////////////////////////////////////////////////////////
2813 /// Make this mesh creating link from nodes to elements (see hasInverseElements)
2814 /// @param b true to link nodes to elements, else false.
2815 ///////////////////////////////////////////////////////////////////////////////
2816 void SMDS_Mesh::setInverseElements(bool b)
2818 if(!b) MESSAGE("Error : inverseElement=false not implemented");
2819 myHasInverseElements=b;
2824 //================================================================================
2826 * \brief Iterator on elements in id increasing order
2828 //================================================================================
2830 template <typename ELEM=const SMDS_MeshElement*>
2831 class IdSortedIterator : public SMDS_Iterator<ELEM>
2833 SMDS_MeshElementIDFactory& myIDFact;
2834 int myID, myMaxID, myNbFound, myTotalNb;
2835 SMDSAbs_ElementType myType;
2839 IdSortedIterator(const SMDS_MeshElementIDFactory& fact,
2840 const SMDSAbs_ElementType type, // SMDSAbs_All NOT allowed!!!
2843 myID(1), myMaxID( myIDFact.GetMaxID() ),myNbFound(0), myTotalNb( totalNb ),
2855 ELEM current = myElem;
2857 for ( myElem = 0; !myElem && myNbFound < myTotalNb && myID <= myMaxID; ++myID )
2858 if ((myElem = (ELEM) myIDFact.MeshElement( myID ))
2859 && myElem->GetType() != myType )
2862 myNbFound += bool(myElem);
2868 //================================================================================
2870 * \brief Iterator on vector of elements, possibly being resized while iteration
2872 //================================================================================
2874 template<typename RETURN_VALUE,
2875 typename VECTOR_VALUE=SMDS_MeshCell*,
2876 typename VALUE_FILTER=SMDS::NonNullFilter<VECTOR_VALUE> >
2877 class ElemVecIterator: public SMDS_Iterator<RETURN_VALUE>
2879 const std::vector<VECTOR_VALUE>& _vector;
2882 VALUE_FILTER _filter;
2884 ElemVecIterator(const std::vector<VECTOR_VALUE>& vec,
2885 const VALUE_FILTER& filter=VALUE_FILTER() )
2886 :_vector( vec ), _index(0), _more( !vec.empty() ), _filter( filter )
2888 if ( _more && !_filter( _vector[ _index ]))
2895 virtual RETURN_VALUE next()
2897 if ( !_more ) return NULL;
2898 VECTOR_VALUE current = _vector[ _index ];
2900 while ( !_more && ++_index < _vector.size() )
2901 _more = _filter( _vector[ _index ]);
2902 return (RETURN_VALUE) current;
2907 ///////////////////////////////////////////////////////////////////////////////
2908 /// Return an iterator on nodes of the current mesh factory
2909 ///////////////////////////////////////////////////////////////////////////////
2911 SMDS_NodeIteratorPtr SMDS_Mesh::nodesIterator(bool idInceasingOrder) const
2913 // naturally always sorted by ID
2914 typedef ElemVecIterator<const SMDS_MeshNode*, SMDS_MeshNode*> TIterator;
2915 return SMDS_NodeIteratorPtr( new TIterator(myNodes));
2918 SMDS_ElemIteratorPtr SMDS_Mesh::elementGeomIterator(SMDSAbs_GeometryType type) const
2920 // naturally always sorted by ID
2921 typedef ElemVecIterator
2922 < const SMDS_MeshElement*, SMDS_MeshCell*, SMDS_MeshElement::GeomFilter > TIterator;
2923 return SMDS_ElemIteratorPtr
2924 (new TIterator(myCells, SMDS_MeshElement::GeomFilter( type )));
2927 SMDS_ElemIteratorPtr SMDS_Mesh::elementEntityIterator(SMDSAbs_EntityType type) const
2929 if ( type == SMDSEntity_Node )
2931 typedef ElemVecIterator<const SMDS_MeshElement*, SMDS_MeshNode*> TIterator;
2932 return SMDS_ElemIteratorPtr( new TIterator(myNodes));
2934 // naturally always sorted by ID
2935 typedef ElemVecIterator
2936 < const SMDS_MeshElement*, SMDS_MeshCell*, SMDS_MeshElement::EntityFilter > TIterator;
2937 return SMDS_ElemIteratorPtr
2938 (new TIterator(myCells, SMDS_MeshElement::EntityFilter( type )));
2941 ///////////////////////////////////////////////////////////////////////////////
2942 /// Return an iterator on elements of the current mesh factory
2943 ///////////////////////////////////////////////////////////////////////////////
2944 SMDS_ElemIteratorPtr SMDS_Mesh::elementsIterator(SMDSAbs_ElementType type) const
2946 // naturally always sorted by ID
2950 return SMDS_ElemIteratorPtr (new ElemVecIterator<const SMDS_MeshElement*>(myCells));
2953 return SMDS_ElemIteratorPtr
2954 ( new ElemVecIterator<const SMDS_MeshElement*, SMDS_MeshNode*>( myNodes ));
2957 typedef ElemVecIterator
2958 < const SMDS_MeshElement*, SMDS_MeshCell*, SMDS_MeshElement::TypeFilter > TIterator;
2959 return SMDS_ElemIteratorPtr (new TIterator(myCells, SMDS_MeshElement::TypeFilter( type )));
2961 return SMDS_ElemIteratorPtr();
2964 ///////////////////////////////////////////////////////////////////////////////
2965 ///Return an iterator on edges of the current mesh.
2966 ///////////////////////////////////////////////////////////////////////////////
2968 SMDS_EdgeIteratorPtr SMDS_Mesh::edgesIterator(bool idInceasingOrder) const
2970 // naturally always sorted by ID
2971 typedef ElemVecIterator
2972 < const SMDS_MeshEdge*, SMDS_MeshCell*, SMDS_MeshElement::TypeFilter > TIterator;
2973 return SMDS_EdgeIteratorPtr
2974 (new TIterator(myCells, SMDS_MeshElement::TypeFilter( SMDSAbs_Edge )));
2977 ///////////////////////////////////////////////////////////////////////////////
2978 ///Return an iterator on faces of the current mesh.
2979 ///////////////////////////////////////////////////////////////////////////////
2981 SMDS_FaceIteratorPtr SMDS_Mesh::facesIterator(bool idInceasingOrder) const
2983 // naturally always sorted by ID
2984 typedef ElemVecIterator
2985 < const SMDS_MeshFace*, SMDS_MeshCell*, SMDS_MeshElement::TypeFilter > TIterator;
2986 return SMDS_FaceIteratorPtr
2987 (new TIterator(myCells, SMDS_MeshElement::TypeFilter( SMDSAbs_Face )));
2990 ///////////////////////////////////////////////////////////////////////////////
2991 ///Return an iterator on volumes of the current mesh.
2992 ///////////////////////////////////////////////////////////////////////////////
2994 SMDS_VolumeIteratorPtr SMDS_Mesh::volumesIterator(bool idInceasingOrder) const
2996 // naturally always sorted by ID
2997 typedef ElemVecIterator
2998 < const SMDS_MeshVolume*, SMDS_MeshCell*, SMDS_MeshElement::TypeFilter > TIterator;
2999 return SMDS_VolumeIteratorPtr
3000 (new TIterator(myCells, SMDS_MeshElement::TypeFilter( SMDSAbs_Volume )));
3003 ///////////////////////////////////////////////////////////////////////////////
3004 /// Do intersection of sets (more than 2)
3005 ///////////////////////////////////////////////////////////////////////////////
3006 static set<const SMDS_MeshElement*> * intersectionOfSets(
3007 set<const SMDS_MeshElement*> vs[], int numberOfSets)
3009 set<const SMDS_MeshElement*>* rsetA=new set<const SMDS_MeshElement*>(vs[0]);
3010 set<const SMDS_MeshElement*>* rsetB;
3012 for(int i=0; i<numberOfSets-1; i++)
3014 rsetB=new set<const SMDS_MeshElement*>();
3016 rsetA->begin(), rsetA->end(),
3017 vs[i+1].begin(), vs[i+1].end(),
3018 inserter(*rsetB, rsetB->begin()));
3025 ///////////////////////////////////////////////////////////////////////////////
3026 /// Return the list of finite elements owning the given element: elements
3027 /// containing all the nodes of the given element, for instance faces and
3028 /// volumes containing a given edge.
3029 ///////////////////////////////////////////////////////////////////////////////
3030 static set<const SMDS_MeshElement*> * getFinitElements(const SMDS_MeshElement * element)
3032 int numberOfSets=element->NbNodes();
3033 set<const SMDS_MeshElement*> *initSet = new set<const SMDS_MeshElement*>[numberOfSets];
3035 SMDS_ElemIteratorPtr itNodes=element->nodesIterator();
3038 while ( itNodes->more() )
3040 const SMDS_MeshElement* node = itNodes->next();
3042 const SMDS_MeshNode * n=static_cast<const SMDS_MeshNode*>(node);
3043 SMDS_ElemIteratorPtr itFe = n->GetInverseElementIterator();
3045 while ( itFe->more() )
3047 const SMDS_MeshElement* elem = itFe->next();
3049 initSet[i].insert(elem);
3054 set<const SMDS_MeshElement*> *retSet = intersectionOfSets( initSet, numberOfSets );
3059 ///////////////////////////////////////////////////////////////////////////////
3060 /// Return the list of nodes used only by the given elements
3061 ///////////////////////////////////////////////////////////////////////////////
3062 static set<const SMDS_MeshElement*> * getExclusiveNodes(set<const SMDS_MeshElement*>& elements)
3064 set<const SMDS_MeshElement*> * toReturn=new set<const SMDS_MeshElement*>();
3065 set<const SMDS_MeshElement*>::iterator itElements=elements.begin();
3067 while(itElements!=elements.end())
3069 SMDS_ElemIteratorPtr itNodes = (*itElements)->nodesIterator();
3072 while(itNodes->more())
3074 const SMDS_MeshNode * n=static_cast<const SMDS_MeshNode*>(itNodes->next());
3075 SMDS_ElemIteratorPtr itFe = n->GetInverseElementIterator();
3076 set<const SMDS_MeshElement*> s;
3078 s.insert(itFe->next());
3079 if(s==elements) toReturn->insert(n);
3085 ///////////////////////////////////////////////////////////////////////////////
3086 ///Find the children of an element that are made of given nodes
3087 ///@param setOfChildren The set in which matching children will be inserted
3088 ///@param element The element were to search matching children
3089 ///@param nodes The nodes that the children must have to be selected
3090 ///////////////////////////////////////////////////////////////////////////////
3091 void SMDS_Mesh::addChildrenWithNodes(set<const SMDS_MeshElement*>& setOfChildren,
3092 const SMDS_MeshElement * element,
3093 set<const SMDS_MeshElement*>& nodes)
3095 switch(element->GetType())
3098 MESSAGE("Internal Error: This should not happen");
3100 case SMDSAbs_0DElement:
3107 SMDS_ElemIteratorPtr itn=element->nodesIterator();
3110 const SMDS_MeshElement * e=itn->next();
3111 if(nodes.find(e)!=nodes.end())
3113 setOfChildren.insert(element);
3120 SMDS_ElemIteratorPtr itn=element->nodesIterator();
3123 const SMDS_MeshElement * e=itn->next();
3124 if(nodes.find(e)!=nodes.end())
3126 setOfChildren.insert(element);
3130 if(hasConstructionEdges())
3132 SMDS_ElemIteratorPtr ite=element->edgesIterator();
3134 addChildrenWithNodes(setOfChildren, ite->next(), nodes);
3137 case SMDSAbs_Volume:
3139 if(hasConstructionFaces())
3141 SMDS_ElemIteratorPtr ite=element->facesIterator();
3143 addChildrenWithNodes(setOfChildren, ite->next(), nodes);
3145 else if(hasConstructionEdges())
3147 SMDS_ElemIteratorPtr ite=element->edgesIterator();
3149 addChildrenWithNodes(setOfChildren, ite->next(), nodes);
3152 case SMDSAbs_NbElementTypes:
3153 case SMDSAbs_All: break;
3157 ///////////////////////////////////////////////////////////////////////////////
3158 ///@param elem The element to delete
3159 ///@param removenodes if true remaining nodes will be removed
3160 ///////////////////////////////////////////////////////////////////////////////
3161 void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem,
3162 const bool removenodes)
3164 list<const SMDS_MeshElement *> removedElems;
3165 list<const SMDS_MeshElement *> removedNodes;
3166 RemoveElement( elem, removedElems, removedNodes, removenodes );
3169 ///////////////////////////////////////////////////////////////////////////////
3170 ///@param elem The element to delete
3171 ///@param removedElems to be filled with all removed elements
3172 ///@param removedNodes to be filled with all removed nodes
3173 ///@param removenodes if true remaining nodes will be removed
3174 ///////////////////////////////////////////////////////////////////////////////
3175 void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem,
3176 list<const SMDS_MeshElement *>& removedElems,
3177 list<const SMDS_MeshElement *>& removedNodes,
3180 // get finite elements built on elem
3181 set<const SMDS_MeshElement*> * s1;
3182 if ( (elem->GetType() == SMDSAbs_0DElement)
3183 || ((elem->GetType() == SMDSAbs_Edge) && !hasConstructionEdges())
3184 || ((elem->GetType() == SMDSAbs_Face) && !hasConstructionFaces())
3185 || (elem->GetType() == SMDSAbs_Volume) )
3187 s1 = new set<const SMDS_MeshElement*> ();
3191 s1 = getFinitElements(elem);
3193 // get exclusive nodes (which would become free afterwards)
3194 set<const SMDS_MeshElement*> * s2;
3195 if (elem->GetType() == SMDSAbs_Node) // a node is removed
3197 // do not remove nodes except elem
3198 s2 = new set<const SMDS_MeshElement*> ();
3203 s2 = getExclusiveNodes(*s1);
3205 // form the set of finite and construction elements to remove
3206 set<const SMDS_MeshElement*> s3;
3207 set<const SMDS_MeshElement*>::iterator it = s1->begin();
3208 while (it != s1->end())
3210 addChildrenWithNodes(s3, *it, *s2);
3214 if (elem->GetType() != SMDSAbs_Node)
3217 // remove finite and construction elements
3219 while (it != s3.end())
3221 // Remove element from <InverseElements> of its nodes
3222 SMDS_ElemIteratorPtr itn = (*it)->nodesIterator();
3225 SMDS_MeshNode * n = static_cast<SMDS_MeshNode *> (const_cast<SMDS_MeshElement *> (itn->next()));
3226 n->RemoveInverseElement((*it));
3228 int IdToRemove = (*it)->GetID();
3229 int vtkid = (*it)->getVtkId();
3230 switch ((*it)->GetType())
3233 MYASSERT("Internal Error: This should not happen");
3235 case SMDSAbs_0DElement:
3236 if (IdToRemove >= 0)
3238 myCells[IdToRemove] = 0; // -PR- ici ou dans myElementIDFactory->ReleaseID ?
3241 removedElems.push_back((*it));
3242 myElementIDFactory->ReleaseID(IdToRemove, vtkid);
3246 if (IdToRemove >= 0)
3248 myCells[IdToRemove] = 0;
3249 myInfo.RemoveEdge(*it);
3251 removedElems.push_back((*it));
3252 myElementIDFactory->ReleaseID(IdToRemove, vtkid);
3253 if (const SMDS_VtkEdge* vtkElem = dynamic_cast<const SMDS_VtkEdge*>(*it))
3254 myEdgePool->destroy((SMDS_VtkEdge*) vtkElem);
3256 ((SMDS_MeshElement*) *it)->init( -1, -1, -1 ); // avoid reuse
3261 if (IdToRemove >= 0)
3263 myCells[IdToRemove] = 0;
3264 myInfo.RemoveFace(*it);
3266 removedElems.push_back((*it));
3267 myElementIDFactory->ReleaseID(IdToRemove, vtkid);
3268 if (const SMDS_VtkFace* vtkElem = dynamic_cast<const SMDS_VtkFace*>(*it))
3269 myFacePool->destroy((SMDS_VtkFace*) vtkElem);
3271 ((SMDS_MeshElement*) *it)->init( -1, -1, -1 ); // avoid reuse
3275 case SMDSAbs_Volume:
3276 if (IdToRemove >= 0)
3278 myCells[IdToRemove] = 0;
3279 myInfo.RemoveVolume(*it);
3281 removedElems.push_back((*it));
3282 myElementIDFactory->ReleaseID(IdToRemove, vtkid);
3283 if (const SMDS_VtkVolume* vtkElem = dynamic_cast<const SMDS_VtkVolume*>(*it))
3284 myVolumePool->destroy((SMDS_VtkVolume*) vtkElem);
3286 ((SMDS_MeshElement*) *it)->init( -1, -1, -1 ); // avoid reuse
3291 if (IdToRemove >= 0)
3293 myCells[IdToRemove] = 0;
3296 removedElems.push_back((*it));
3297 myElementIDFactory->ReleaseID(IdToRemove, vtkid);
3298 if (const SMDS_BallElement* vtkElem = dynamic_cast<const SMDS_BallElement*>(*it))
3299 myBallPool->destroy(const_cast<SMDS_BallElement*>( vtkElem ));
3301 ((SMDS_MeshElement*) *it)->init( -1, -1, -1 ); // avoid reuse
3306 case SMDSAbs_All: // avoid compilation warning
3307 case SMDSAbs_NbElementTypes: break;
3311 this->myGrid->GetCellTypesArray()->SetValue(vtkid, VTK_EMPTY_CELL);
3316 // remove exclusive (free) nodes
3320 while (it != s2->end())
3322 int IdToRemove = (*it)->GetID();
3323 if (IdToRemove >= 0)
3325 myNodes[IdToRemove] = 0;
3328 myNodeIDFactory->ReleaseID((*it)->GetID(), (*it)->getVtkId());
3329 removedNodes.push_back((*it));
3330 if (const SMDS_MeshNode* vtkElem = dynamic_cast<const SMDS_MeshNode*>(*it))
3332 ((SMDS_MeshNode*)vtkElem)->SetPosition(SMDS_SpacePosition::originSpacePosition());
3333 myNodePool->destroy((SMDS_MeshNode*) vtkElem);
3346 ///////////////////////////////////////////////////////////////////////////////
3347 ///@param elem The element to delete
3348 ///////////////////////////////////////////////////////////////////////////////
3349 void SMDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elem)
3351 int elemId = elem->GetID();
3352 int vtkId = elem->getVtkId();
3353 SMDSAbs_ElementType aType = elem->GetType();
3354 SMDS_MeshElement* todest = (SMDS_MeshElement*)(elem);
3355 if (aType == SMDSAbs_Node) {
3356 // only free node can be removed by this method
3357 const SMDS_MeshNode* n = static_cast<SMDS_MeshNode*>(todest);
3358 SMDS_ElemIteratorPtr itFe = n->GetInverseElementIterator();
3359 if (!itFe->more()) { // free node
3360 myNodes[elemId] = 0;
3362 ((SMDS_MeshNode*) n)->SetPosition(SMDS_SpacePosition::originSpacePosition());
3363 ((SMDS_MeshNode*) n)->SMDS_MeshElement::init( -1, -1, -1 ); // avoid reuse
3364 myNodePool->destroy(static_cast<SMDS_MeshNode*>(todest));
3365 myNodeIDFactory->ReleaseID(elemId, vtkId);
3368 if (hasConstructionEdges() || hasConstructionFaces())
3369 // this methods is only for meshes without descendants
3372 // Remove element from <InverseElements> of its nodes
3373 SMDS_ElemIteratorPtr itn = elem->nodesIterator();
3374 while (itn->more()) {
3375 SMDS_MeshNode * n = static_cast<SMDS_MeshNode *>
3376 (const_cast<SMDS_MeshElement *>(itn->next()));
3377 n->RemoveInverseElement(elem);
3380 // in meshes without descendants elements are always free
3382 case SMDSAbs_0DElement:
3383 myCells[elemId] = 0;
3384 myInfo.remove(elem);
3389 myCells[elemId] = 0;
3390 myInfo.RemoveEdge(elem);
3391 myEdgePool->destroy(static_cast<SMDS_VtkEdge*>(todest));
3394 myCells[elemId] = 0;
3395 myInfo.RemoveFace(elem);
3396 myFacePool->destroy(static_cast<SMDS_VtkFace*>(todest));
3398 case SMDSAbs_Volume:
3399 myCells[elemId] = 0;
3400 myInfo.RemoveVolume(elem);
3401 myVolumePool->destroy(static_cast<SMDS_VtkVolume*>(todest));
3404 myCells[elemId] = 0;
3405 myInfo.remove(elem);
3406 myBallPool->destroy(static_cast<SMDS_BallElement*>(todest));
3411 myElementIDFactory->ReleaseID(elemId, vtkId);
3413 this->myGrid->GetCellTypesArray()->SetValue(vtkId, VTK_EMPTY_CELL);
3414 // --- to do: keep vtkid in a list of reusable cells
3417 ((SMDS_MeshElement*) elem)->init( -1, -1, -1 ); // avoid reuse
3422 * Checks if the element is present in mesh.
3423 * Useful to determine dead pointers.
3425 bool SMDS_Mesh::Contains (const SMDS_MeshElement* elem) const
3427 // we should not imply on validity of *elem, so iterate on containers
3428 // of all types in the hope of finding <elem> somewhere there
3429 SMDS_NodeIteratorPtr itn = nodesIterator();
3431 if (elem == itn->next())
3433 SMDS_ElemIteratorPtr ite = elementsIterator();
3435 if (elem == ite->next())
3440 //=======================================================================
3441 //function : MaxNodeID
3443 //=======================================================================
3445 int SMDS_Mesh::MaxNodeID() const
3450 //=======================================================================
3451 //function : MinNodeID
3453 //=======================================================================
3455 int SMDS_Mesh::MinNodeID() const
3460 //=======================================================================
3461 //function : MaxElementID
3463 //=======================================================================
3465 int SMDS_Mesh::MaxElementID() const
3467 return myElementIDFactory->GetMaxID();
3470 //=======================================================================
3471 //function : MinElementID
3473 //=======================================================================
3475 int SMDS_Mesh::MinElementID() const
3477 return myElementIDFactory->GetMinID();
3480 //=======================================================================
3481 //function : Renumber
3482 //purpose : Renumber all nodes or elements.
3483 //=======================================================================
3485 void SMDS_Mesh::Renumber (const bool isNodes, const int startID, const int deltaID)
3490 SMDS_MeshNodeIDFactory * idFactory =
3491 isNodes ? myNodeIDFactory : myElementIDFactory;
3493 // get existing elements in the order of ID increasing
3494 map<int,SMDS_MeshElement*> elemMap;
3495 SMDS_ElemIteratorPtr idElemIt = idFactory->elementsIterator();
3496 while ( idElemIt->more() ) {
3497 SMDS_MeshElement* elem = const_cast<SMDS_MeshElement*>(idElemIt->next());
3498 int id = elem->GetID();
3499 elemMap.insert(map<int,SMDS_MeshElement*>::value_type(id, elem));
3501 // release their ids
3502 map<int,SMDS_MeshElement*>::iterator elemIt = elemMap.begin();
3504 // for ( ; elemIt != elemMap.end(); elemIt++ )
3506 // int id = (*elemIt).first;
3507 // idFactory->ReleaseID( id );
3511 elemIt = elemMap.begin();
3512 for ( ; elemIt != elemMap.end(); elemIt++ )
3514 idFactory->BindID( ID, (*elemIt).second );
3519 //=======================================================================
3520 //function : GetElementType
3521 //purpose : Return type of element or node with id
3522 //=======================================================================
3524 SMDSAbs_ElementType SMDS_Mesh::GetElementType( const int id, const bool iselem ) const
3526 SMDS_MeshElement* elem = 0;
3528 elem = myElementIDFactory->MeshElement( id );
3530 elem = myNodeIDFactory->MeshElement( id );
3534 //throw SALOME_Exception(LOCALIZED ("this element isn't exist"));
3538 return elem->GetType();
3543 //********************************************************************
3544 //********************************************************************
3545 //******** *********
3546 //***** Methods for addition of quadratic elements ******
3547 //******** *********
3548 //********************************************************************
3549 //********************************************************************
3551 //=======================================================================
3552 //function : AddEdgeWithID
3554 //=======================================================================
3555 SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(int n1, int n2, int n12, int ID)
3557 return SMDS_Mesh::AddEdgeWithID
3558 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1),
3559 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2),
3560 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
3564 //=======================================================================
3565 //function : AddEdge
3567 //=======================================================================
3568 SMDS_MeshEdge* SMDS_Mesh::AddEdge(const SMDS_MeshNode* n1,
3569 const SMDS_MeshNode* n2,
3570 const SMDS_MeshNode* n12)
3572 return SMDS_Mesh::AddEdgeWithID(n1, n2, n12, myElementIDFactory->GetFreeID());
3575 //=======================================================================
3576 //function : AddEdgeWithID
3578 //=======================================================================
3579 SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
3580 const SMDS_MeshNode * n2,
3581 const SMDS_MeshNode * n12,
3584 if ( !n1 || !n2 || !n12 ) return 0;
3586 // --- retrieve nodes ID
3587 myNodeIds.resize(3);
3588 myNodeIds[0] = n1->getVtkId();
3589 myNodeIds[1] = n2->getVtkId();
3590 myNodeIds[2] = n12->getVtkId();
3592 SMDS_MeshEdge * edge = 0;
3593 SMDS_VtkEdge *edgevtk = myEdgePool->getNew();
3594 edgevtk->init(myNodeIds, this);
3595 if (!this->registerElement(ID,edgevtk))
3597 this->myGrid->GetCellTypesArray()->SetValue(edgevtk->getVtkId(), VTK_EMPTY_CELL);
3598 myEdgePool->destroy(edgevtk);
3602 adjustmyCellsCapacity(ID);
3604 myInfo.myNbQuadEdges++;
3606 // if (!registerElement(ID, edge)) {
3607 // RemoveElement(edge, false);
3615 //=======================================================================
3616 //function : AddFace
3618 //=======================================================================
3619 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
3620 const SMDS_MeshNode * n2,
3621 const SMDS_MeshNode * n3,
3622 const SMDS_MeshNode * n12,
3623 const SMDS_MeshNode * n23,
3624 const SMDS_MeshNode * n31)
3626 return SMDS_Mesh::AddFaceWithID(n1,n2,n3,n12,n23,n31,
3627 myElementIDFactory->GetFreeID());
3630 //=======================================================================
3631 //function : AddFaceWithID
3633 //=======================================================================
3634 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int n1, int n2, int n3,
3635 int n12,int n23,int n31, int ID)
3637 return SMDS_Mesh::AddFaceWithID
3638 ((SMDS_MeshNode *)myNodeIDFactory->MeshElement(n1) ,
3639 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n2) ,
3640 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n3) ,
3641 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n12),
3642 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n23),
3643 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n31),
3647 //=======================================================================
3648 //function : AddFaceWithID
3650 //=======================================================================
3651 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
3652 const SMDS_MeshNode * n2,
3653 const SMDS_MeshNode * n3,
3654 const SMDS_MeshNode * n12,
3655 const SMDS_MeshNode * n23,
3656 const SMDS_MeshNode * n31,
3659 if ( !n1 || !n2 || !n3 || !n12 || !n23 || !n31) return 0;
3660 if(hasConstructionEdges()) {
3661 // creation quadratic edges - not implemented
3666 // --- retrieve nodes ID
3667 myNodeIds.resize(6);
3668 myNodeIds[0] = n1->getVtkId();
3669 myNodeIds[1] = n2->getVtkId();
3670 myNodeIds[2] = n3->getVtkId();
3671 myNodeIds[3] = n12->getVtkId();
3672 myNodeIds[4] = n23->getVtkId();
3673 myNodeIds[5] = n31->getVtkId();
3675 SMDS_MeshFace * face = 0;
3676 SMDS_VtkFace *facevtk = myFacePool->getNew();
3677 facevtk->init(myNodeIds, this);
3678 if (!this->registerElement(ID,facevtk))
3680 this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL);
3681 myFacePool->destroy(facevtk);
3685 adjustmyCellsCapacity(ID);
3687 myInfo.myNbQuadTriangles++;
3689 // if (!registerElement(ID, face)) {
3690 // RemoveElement(face, false);
3698 //=======================================================================
3699 //function : AddFace
3701 //=======================================================================
3702 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
3703 const SMDS_MeshNode * n2,
3704 const SMDS_MeshNode * n3,
3705 const SMDS_MeshNode * n12,
3706 const SMDS_MeshNode * n23,
3707 const SMDS_MeshNode * n31,
3708 const SMDS_MeshNode * nCenter)
3710 return SMDS_Mesh::AddFaceWithID(n1,n2,n3,n12,n23,n31,nCenter,
3711 myElementIDFactory->GetFreeID());
3714 //=======================================================================
3715 //function : AddFaceWithID
3717 //=======================================================================
3718 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int n1, int n2, int n3,
3719 int n12,int n23,int n31, int nCenter, int ID)
3721 return SMDS_Mesh::AddFaceWithID
3722 ((SMDS_MeshNode *)myNodeIDFactory->MeshElement(n1) ,
3723 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n2) ,
3724 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n3) ,
3725 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n12),
3726 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n23),
3727 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n31),
3728 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nCenter),
3732 //=======================================================================
3733 //function : AddFaceWithID
3735 //=======================================================================
3736 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
3737 const SMDS_MeshNode * n2,
3738 const SMDS_MeshNode * n3,
3739 const SMDS_MeshNode * n12,
3740 const SMDS_MeshNode * n23,
3741 const SMDS_MeshNode * n31,
3742 const SMDS_MeshNode * nCenter,
3745 if ( !n1 || !n2 || !n3 || !n12 || !n23 || !n31 || !nCenter) return 0;
3746 if(hasConstructionEdges()) {
3747 // creation quadratic edges - not implemented
3752 // --- retrieve nodes ID
3753 myNodeIds.resize(7);
3754 myNodeIds[0] = n1->getVtkId();
3755 myNodeIds[1] = n2->getVtkId();
3756 myNodeIds[2] = n3->getVtkId();
3757 myNodeIds[3] = n12->getVtkId();
3758 myNodeIds[4] = n23->getVtkId();
3759 myNodeIds[5] = n31->getVtkId();
3760 myNodeIds[6] = nCenter->getVtkId();
3762 SMDS_MeshFace * face = 0;
3763 SMDS_VtkFace *facevtk = myFacePool->getNew();
3764 facevtk->init(myNodeIds, this);
3765 if (!this->registerElement(ID,facevtk))
3767 this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL);
3768 myFacePool->destroy(facevtk);
3772 adjustmyCellsCapacity(ID);
3774 myInfo.myNbBiQuadTriangles++;
3776 // if (!registerElement(ID, face)) {
3777 // RemoveElement(face, false);
3785 //=======================================================================
3786 //function : AddFace
3788 //=======================================================================
3789 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
3790 const SMDS_MeshNode * n2,
3791 const SMDS_MeshNode * n3,
3792 const SMDS_MeshNode * n4,
3793 const SMDS_MeshNode * n12,
3794 const SMDS_MeshNode * n23,
3795 const SMDS_MeshNode * n34,
3796 const SMDS_MeshNode * n41)
3798 return SMDS_Mesh::AddFaceWithID(n1,n2,n3,n4,n12,n23,n34,n41,
3799 myElementIDFactory->GetFreeID());
3802 //=======================================================================
3803 //function : AddFaceWithID
3805 //=======================================================================
3806 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int n4,
3807 int n12,int n23,int n34,int n41, int ID)
3809 return SMDS_Mesh::AddFaceWithID
3810 ((SMDS_MeshNode *)myNodeIDFactory->MeshElement(n1) ,
3811 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n2) ,
3812 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n3) ,
3813 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n4) ,
3814 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n12),
3815 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n23),
3816 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n34),
3817 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n41),
3821 //=======================================================================
3822 //function : AddFaceWithID
3824 //=======================================================================
3825 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
3826 const SMDS_MeshNode * n2,
3827 const SMDS_MeshNode * n3,
3828 const SMDS_MeshNode * n4,
3829 const SMDS_MeshNode * n12,
3830 const SMDS_MeshNode * n23,
3831 const SMDS_MeshNode * n34,
3832 const SMDS_MeshNode * n41,
3835 if ( !n1 || !n2 || !n3 || !n4 || !n12 || !n23 || !n34 || !n41) return 0;
3836 if(hasConstructionEdges()) {
3837 // creation quadratic edges - not implemented
3842 // --- retrieve nodes ID
3843 myNodeIds.resize(8);
3844 myNodeIds[0] = n1->getVtkId();
3845 myNodeIds[1] = n2->getVtkId();
3846 myNodeIds[2] = n3->getVtkId();
3847 myNodeIds[3] = n4->getVtkId();
3848 myNodeIds[4] = n12->getVtkId();
3849 myNodeIds[5] = n23->getVtkId();
3850 myNodeIds[6] = n34->getVtkId();
3851 myNodeIds[7] = n41->getVtkId();
3853 SMDS_MeshFace * face = 0;
3854 SMDS_VtkFace *facevtk = myFacePool->getNew();
3855 facevtk->init(myNodeIds, this);
3856 if (!this->registerElement(ID,facevtk))
3858 this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL);
3859 myFacePool->destroy(facevtk);
3863 adjustmyCellsCapacity(ID);
3865 myInfo.myNbQuadQuadrangles++;
3867 // if (!registerElement(ID, face)) {
3868 // RemoveElement(face, false);
3875 //=======================================================================
3876 //function : AddFace
3878 //=======================================================================
3879 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
3880 const SMDS_MeshNode * n2,
3881 const SMDS_MeshNode * n3,
3882 const SMDS_MeshNode * n4,
3883 const SMDS_MeshNode * n12,
3884 const SMDS_MeshNode * n23,
3885 const SMDS_MeshNode * n34,
3886 const SMDS_MeshNode * n41,
3887 const SMDS_MeshNode * nCenter)
3889 return SMDS_Mesh::AddFaceWithID(n1,n2,n3,n4,n12,n23,n34,n41,nCenter,
3890 myElementIDFactory->GetFreeID());
3893 //=======================================================================
3894 //function : AddFaceWithID
3896 //=======================================================================
3897 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int n4,
3898 int n12,int n23,int n34,int n41, int nCenter, int ID)
3900 return SMDS_Mesh::AddFaceWithID
3901 ((SMDS_MeshNode *)myNodeIDFactory->MeshElement(n1) ,
3902 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n2) ,
3903 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n3) ,
3904 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n4) ,
3905 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n12),
3906 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n23),
3907 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n34),
3908 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n41),
3909 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nCenter),
3913 //=======================================================================
3914 //function : AddFaceWithID
3916 //=======================================================================
3917 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
3918 const SMDS_MeshNode * n2,
3919 const SMDS_MeshNode * n3,
3920 const SMDS_MeshNode * n4,
3921 const SMDS_MeshNode * n12,
3922 const SMDS_MeshNode * n23,
3923 const SMDS_MeshNode * n34,
3924 const SMDS_MeshNode * n41,
3925 const SMDS_MeshNode * nCenter,
3928 if ( !n1 || !n2 || !n3 || !n4 || !n12 || !n23 || !n34 || !n41 || !nCenter) return 0;
3929 if(hasConstructionEdges()) {
3930 // creation quadratic edges - not implemented
3935 // --- retrieve nodes ID
3936 myNodeIds.resize(9);
3937 myNodeIds[0] = n1->getVtkId();
3938 myNodeIds[1] = n2->getVtkId();
3939 myNodeIds[2] = n3->getVtkId();
3940 myNodeIds[3] = n4->getVtkId();
3941 myNodeIds[4] = n12->getVtkId();
3942 myNodeIds[5] = n23->getVtkId();
3943 myNodeIds[6] = n34->getVtkId();
3944 myNodeIds[7] = n41->getVtkId();
3945 myNodeIds[8] = nCenter->getVtkId();
3947 SMDS_MeshFace * face = 0;
3948 SMDS_VtkFace *facevtk = myFacePool->getNew();
3949 facevtk->init(myNodeIds, this);
3950 if (!this->registerElement(ID,facevtk))
3952 this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL);
3953 myFacePool->destroy(facevtk);
3957 adjustmyCellsCapacity(ID);
3959 myInfo.myNbBiQuadQuadrangles++;
3961 // if (!registerElement(ID, face)) {
3962 // RemoveElement(face, false);
3970 //=======================================================================
3971 //function : AddVolume
3973 //=======================================================================
3974 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
3975 const SMDS_MeshNode * n2,
3976 const SMDS_MeshNode * n3,
3977 const SMDS_MeshNode * n4,
3978 const SMDS_MeshNode * n12,
3979 const SMDS_MeshNode * n23,
3980 const SMDS_MeshNode * n31,
3981 const SMDS_MeshNode * n14,
3982 const SMDS_MeshNode * n24,
3983 const SMDS_MeshNode * n34)
3985 int ID = myElementIDFactory->GetFreeID();
3986 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n12, n23,
3987 n31, n14, n24, n34, ID);
3988 if(v==NULL) myElementIDFactory->ReleaseID(ID);
3992 //=======================================================================
3993 //function : AddVolumeWithID
3995 //=======================================================================
3996 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4,
3997 int n12,int n23,int n31,
3998 int n14,int n24,int n34, int ID)
4000 return SMDS_Mesh::AddVolumeWithID
4001 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1) ,
4002 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2) ,
4003 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3) ,
4004 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4) ,
4005 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
4006 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
4007 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n31),
4008 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n14),
4009 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n24),
4010 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n34),
4014 //=======================================================================
4015 //function : AddVolumeWithID
4016 //purpose : 2d order tetrahedron of 10 nodes
4017 //=======================================================================
4018 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
4019 const SMDS_MeshNode * n2,
4020 const SMDS_MeshNode * n3,
4021 const SMDS_MeshNode * n4,
4022 const SMDS_MeshNode * n12,
4023 const SMDS_MeshNode * n23,
4024 const SMDS_MeshNode * n31,
4025 const SMDS_MeshNode * n14,
4026 const SMDS_MeshNode * n24,
4027 const SMDS_MeshNode * n34,
4030 if ( !n1 || !n2 || !n3 || !n4 || !n12 || !n23 || !n31 || !n14 || !n24 || !n34)
4032 if(hasConstructionFaces()) {
4033 // creation quadratic faces - not implemented
4036 // --- retrieve nodes ID
4037 myNodeIds.resize(10);
4038 myNodeIds[0] = n1->getVtkId();
4039 myNodeIds[1] = n3->getVtkId();
4040 myNodeIds[2] = n2->getVtkId();
4041 myNodeIds[3] = n4->getVtkId();
4043 myNodeIds[4] = n31->getVtkId();
4044 myNodeIds[5] = n23->getVtkId();
4045 myNodeIds[6] = n12->getVtkId();
4047 myNodeIds[7] = n14->getVtkId();
4048 myNodeIds[8] = n34->getVtkId();
4049 myNodeIds[9] = n24->getVtkId();
4051 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
4052 volvtk->init(myNodeIds, this);
4053 if (!this->registerElement(ID,volvtk))
4055 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
4056 myVolumePool->destroy(volvtk);
4059 adjustmyCellsCapacity(ID);
4060 myCells[ID] = volvtk;
4061 myInfo.myNbQuadTetras++;
4063 // if (!registerElement(ID, volvtk)) {
4064 // RemoveElement(volvtk, false);
4071 //=======================================================================
4072 //function : AddVolume
4074 //=======================================================================
4075 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
4076 const SMDS_MeshNode * n2,
4077 const SMDS_MeshNode * n3,
4078 const SMDS_MeshNode * n4,
4079 const SMDS_MeshNode * n5,
4080 const SMDS_MeshNode * n12,
4081 const SMDS_MeshNode * n23,
4082 const SMDS_MeshNode * n34,
4083 const SMDS_MeshNode * n41,
4084 const SMDS_MeshNode * n15,
4085 const SMDS_MeshNode * n25,
4086 const SMDS_MeshNode * n35,
4087 const SMDS_MeshNode * n45)
4089 int ID = myElementIDFactory->GetFreeID();
4090 SMDS_MeshVolume * v =
4091 SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n12, n23, n34, n41,
4092 n15, n25, n35, n45, ID);
4093 if(v==NULL) myElementIDFactory->ReleaseID(ID);
4097 //=======================================================================
4098 //function : AddVolumeWithID
4100 //=======================================================================
4101 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5,
4102 int n12,int n23,int n34,int n41,
4103 int n15,int n25,int n35,int n45, int ID)
4105 return SMDS_Mesh::AddVolumeWithID
4106 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1) ,
4107 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2) ,
4108 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3) ,
4109 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4) ,
4110 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5) ,
4111 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
4112 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
4113 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n34),
4114 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n41),
4115 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n15),
4116 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n25),
4117 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n35),
4118 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n45),
4122 //=======================================================================
4123 //function : AddVolumeWithID
4124 //purpose : 2d order pyramid of 13 nodes
4125 //=======================================================================
4126 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
4127 const SMDS_MeshNode * n2,
4128 const SMDS_MeshNode * n3,
4129 const SMDS_MeshNode * n4,
4130 const SMDS_MeshNode * n5,
4131 const SMDS_MeshNode * n12,
4132 const SMDS_MeshNode * n23,
4133 const SMDS_MeshNode * n34,
4134 const SMDS_MeshNode * n41,
4135 const SMDS_MeshNode * n15,
4136 const SMDS_MeshNode * n25,
4137 const SMDS_MeshNode * n35,
4138 const SMDS_MeshNode * n45,
4141 if (!n1 || !n2 || !n3 || !n4 || !n5 || !n12 || !n23 ||
4142 !n34 || !n41 || !n15 || !n25 || !n35 || !n45)
4144 if(hasConstructionFaces()) {
4145 // creation quadratic faces - not implemented
4148 // --- retrieve nodes ID
4149 myNodeIds.resize(13);
4150 myNodeIds[0] = n1->getVtkId();
4151 myNodeIds[1] = n4->getVtkId();
4152 myNodeIds[2] = n3->getVtkId();
4153 myNodeIds[3] = n2->getVtkId();
4154 myNodeIds[4] = n5->getVtkId();
4156 myNodeIds[5] = n41->getVtkId();
4157 myNodeIds[6] = n34->getVtkId();
4158 myNodeIds[7] = n23->getVtkId();
4159 myNodeIds[8] = n12->getVtkId();
4161 myNodeIds[9] = n15->getVtkId();
4162 myNodeIds[10] = n45->getVtkId();
4163 myNodeIds[11] = n35->getVtkId();
4164 myNodeIds[12] = n25->getVtkId();
4166 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
4167 volvtk->init(myNodeIds, this);
4168 if (!this->registerElement(ID,volvtk))
4170 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
4171 myVolumePool->destroy(volvtk);
4174 adjustmyCellsCapacity(ID);
4175 myCells[ID] = volvtk;
4176 myInfo.myNbQuadPyramids++;
4178 // if (!registerElement(ID, volvtk)) {
4179 // RemoveElement(volvtk, false);
4186 //=======================================================================
4187 //function : AddVolume
4189 //=======================================================================
4190 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
4191 const SMDS_MeshNode * n2,
4192 const SMDS_MeshNode * n3,
4193 const SMDS_MeshNode * n4,
4194 const SMDS_MeshNode * n5,
4195 const SMDS_MeshNode * n6,
4196 const SMDS_MeshNode * n12,
4197 const SMDS_MeshNode * n23,
4198 const SMDS_MeshNode * n31,
4199 const SMDS_MeshNode * n45,
4200 const SMDS_MeshNode * n56,
4201 const SMDS_MeshNode * n64,
4202 const SMDS_MeshNode * n14,
4203 const SMDS_MeshNode * n25,
4204 const SMDS_MeshNode * n36)
4206 int ID = myElementIDFactory->GetFreeID();
4207 SMDS_MeshVolume * v =
4208 SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n12, n23, n31,
4209 n45, n56, n64, n14, n25, n36, ID);
4210 if(v==NULL) myElementIDFactory->ReleaseID(ID);
4214 //=======================================================================
4215 //function : AddVolumeWithID
4217 //=======================================================================
4218 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3,
4219 int n4, int n5, int n6,
4220 int n12,int n23,int n31,
4221 int n45,int n56,int n64,
4222 int n14,int n25,int n36, int ID)
4224 return SMDS_Mesh::AddVolumeWithID
4225 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1) ,
4226 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2) ,
4227 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3) ,
4228 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4) ,
4229 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5) ,
4230 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n6) ,
4231 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
4232 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
4233 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n31),
4234 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n45),
4235 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n56),
4236 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n64),
4237 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n14),
4238 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n25),
4239 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n36),
4243 //=======================================================================
4244 //function : AddVolumeWithID
4245 //purpose : 2d order Pentahedron with 15 nodes
4246 //=======================================================================
4247 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
4248 const SMDS_MeshNode * n2,
4249 const SMDS_MeshNode * n3,
4250 const SMDS_MeshNode * n4,
4251 const SMDS_MeshNode * n5,
4252 const SMDS_MeshNode * n6,
4253 const SMDS_MeshNode * n12,
4254 const SMDS_MeshNode * n23,
4255 const SMDS_MeshNode * n31,
4256 const SMDS_MeshNode * n45,
4257 const SMDS_MeshNode * n56,
4258 const SMDS_MeshNode * n64,
4259 const SMDS_MeshNode * n14,
4260 const SMDS_MeshNode * n25,
4261 const SMDS_MeshNode * n36,
4264 if (!n1 || !n2 || !n3 || !n4 || !n5 || !n6 || !n12 || !n23 ||
4265 !n31 || !n45 || !n56 || !n64 || !n14 || !n25 || !n36)
4267 if(hasConstructionFaces()) {
4268 // creation quadratic faces - not implemented
4271 // --- retrieve nodes ID
4272 myNodeIds.resize(15);
4273 myNodeIds[0] = n1->getVtkId();
4274 myNodeIds[1] = n2->getVtkId();
4275 myNodeIds[2] = n3->getVtkId();
4277 myNodeIds[3] = n4->getVtkId();
4278 myNodeIds[4] = n5->getVtkId();
4279 myNodeIds[5] = n6->getVtkId();
4281 myNodeIds[6] = n12->getVtkId();
4282 myNodeIds[7] = n23->getVtkId();
4283 myNodeIds[8] = n31->getVtkId();
4285 myNodeIds[9] = n45->getVtkId();
4286 myNodeIds[10] = n56->getVtkId();
4287 myNodeIds[11] = n64->getVtkId();
4289 myNodeIds[12] = n14->getVtkId();
4290 myNodeIds[13] = n25->getVtkId();
4291 myNodeIds[14] = n36->getVtkId();
4293 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
4294 volvtk->init(myNodeIds, this);
4295 if (!this->registerElement(ID,volvtk))
4297 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
4298 myVolumePool->destroy(volvtk);
4301 adjustmyCellsCapacity(ID);
4302 myCells[ID] = volvtk;
4303 myInfo.myNbQuadPrisms++;
4305 // if (!registerElement(ID, volvtk)) {
4306 // RemoveElement(volvtk, false);
4313 //=======================================================================
4314 //function : AddVolume
4316 //=======================================================================
4317 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
4318 const SMDS_MeshNode * n2,
4319 const SMDS_MeshNode * n3,
4320 const SMDS_MeshNode * n4,
4321 const SMDS_MeshNode * n5,
4322 const SMDS_MeshNode * n6,
4323 const SMDS_MeshNode * n7,
4324 const SMDS_MeshNode * n8,
4325 const SMDS_MeshNode * n12,
4326 const SMDS_MeshNode * n23,
4327 const SMDS_MeshNode * n34,
4328 const SMDS_MeshNode * n41,
4329 const SMDS_MeshNode * n56,
4330 const SMDS_MeshNode * n67,
4331 const SMDS_MeshNode * n78,
4332 const SMDS_MeshNode * n85,
4333 const SMDS_MeshNode * n15,
4334 const SMDS_MeshNode * n26,
4335 const SMDS_MeshNode * n37,
4336 const SMDS_MeshNode * n48)
4338 int ID = myElementIDFactory->GetFreeID();
4339 SMDS_MeshVolume * v =
4340 SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, n12, n23, n34, n41,
4341 n56, n67, n78, n85, n15, n26, n37, n48, ID);
4342 if(v==NULL) myElementIDFactory->ReleaseID(ID);
4346 //=======================================================================
4347 //function : AddVolumeWithID
4349 //=======================================================================
4350 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4,
4351 int n5, int n6, int n7, int n8,
4352 int n12,int n23,int n34,int n41,
4353 int n56,int n67,int n78,int n85,
4354 int n15,int n26,int n37,int n48, int ID)
4356 return SMDS_Mesh::AddVolumeWithID
4357 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1),
4358 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2),
4359 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3),
4360 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4),
4361 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5),
4362 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n6),
4363 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n7),
4364 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n8),
4365 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
4366 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
4367 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n34),
4368 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n41),
4369 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n56),
4370 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n67),
4371 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n78),
4372 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n85),
4373 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n15),
4374 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n26),
4375 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n37),
4376 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n48),
4380 //=======================================================================
4381 //function : AddVolumeWithID
4382 //purpose : 2d order Hexahedrons with 20 nodes
4383 //=======================================================================
4384 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
4385 const SMDS_MeshNode * n2,
4386 const SMDS_MeshNode * n3,
4387 const SMDS_MeshNode * n4,
4388 const SMDS_MeshNode * n5,
4389 const SMDS_MeshNode * n6,
4390 const SMDS_MeshNode * n7,
4391 const SMDS_MeshNode * n8,
4392 const SMDS_MeshNode * n12,
4393 const SMDS_MeshNode * n23,
4394 const SMDS_MeshNode * n34,
4395 const SMDS_MeshNode * n41,
4396 const SMDS_MeshNode * n56,
4397 const SMDS_MeshNode * n67,
4398 const SMDS_MeshNode * n78,
4399 const SMDS_MeshNode * n85,
4400 const SMDS_MeshNode * n15,
4401 const SMDS_MeshNode * n26,
4402 const SMDS_MeshNode * n37,
4403 const SMDS_MeshNode * n48,
4406 if (!n1 || !n2 || !n3 || !n4 || !n5 || !n6 || !n7 || !n8 || !n12 || !n23 ||
4407 !n34 || !n41 || !n56 || !n67 || !n78 || !n85 || !n15 || !n26 || !n37 || !n48)
4409 if(hasConstructionFaces()) {
4411 // creation quadratic faces - not implemented
4413 // --- retrieve nodes ID
4414 myNodeIds.resize(20);
4415 myNodeIds[0] = n1->getVtkId();
4416 myNodeIds[1] = n4->getVtkId();
4417 myNodeIds[2] = n3->getVtkId();
4418 myNodeIds[3] = n2->getVtkId();
4420 myNodeIds[4] = n5->getVtkId();
4421 myNodeIds[5] = n8->getVtkId();
4422 myNodeIds[6] = n7->getVtkId();
4423 myNodeIds[7] = n6->getVtkId();
4425 myNodeIds[8] = n41->getVtkId();
4426 myNodeIds[9] = n34->getVtkId();
4427 myNodeIds[10] = n23->getVtkId();
4428 myNodeIds[11] = n12->getVtkId();
4430 myNodeIds[12] = n85->getVtkId();
4431 myNodeIds[13] = n78->getVtkId();
4432 myNodeIds[14] = n67->getVtkId();
4433 myNodeIds[15] = n56->getVtkId();
4435 myNodeIds[16] = n15->getVtkId();
4436 myNodeIds[17] = n48->getVtkId();
4437 myNodeIds[18] = n37->getVtkId();
4438 myNodeIds[19] = n26->getVtkId();
4440 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
4441 volvtk->init(myNodeIds, this);
4442 if (!this->registerElement(ID,volvtk))
4444 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
4445 myVolumePool->destroy(volvtk);
4448 adjustmyCellsCapacity(ID);
4449 myCells[ID] = volvtk;
4450 myInfo.myNbQuadHexas++;
4452 // if (!registerElement(ID, volvtk)) {
4453 // RemoveElement(volvtk, false);
4459 //=======================================================================
4460 //function : AddVolume
4462 //=======================================================================
4463 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
4464 const SMDS_MeshNode * n2,
4465 const SMDS_MeshNode * n3,
4466 const SMDS_MeshNode * n4,
4467 const SMDS_MeshNode * n5,
4468 const SMDS_MeshNode * n6,
4469 const SMDS_MeshNode * n7,
4470 const SMDS_MeshNode * n8,
4471 const SMDS_MeshNode * n12,
4472 const SMDS_MeshNode * n23,
4473 const SMDS_MeshNode * n34,
4474 const SMDS_MeshNode * n41,
4475 const SMDS_MeshNode * n56,
4476 const SMDS_MeshNode * n67,
4477 const SMDS_MeshNode * n78,
4478 const SMDS_MeshNode * n85,
4479 const SMDS_MeshNode * n15,
4480 const SMDS_MeshNode * n26,
4481 const SMDS_MeshNode * n37,
4482 const SMDS_MeshNode * n48,
4483 const SMDS_MeshNode * n1234,
4484 const SMDS_MeshNode * n1256,
4485 const SMDS_MeshNode * n2367,
4486 const SMDS_MeshNode * n3478,
4487 const SMDS_MeshNode * n1458,
4488 const SMDS_MeshNode * n5678,
4489 const SMDS_MeshNode * nCenter)
4491 int ID = myElementIDFactory->GetFreeID();
4492 SMDS_MeshVolume * v =
4493 SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, n12, n23, n34, n41,
4494 n56, n67, n78, n85, n15, n26, n37, n48,
4495 n1234, n1256, n2367, n3478, n1458, n5678, nCenter,
4497 if(v==NULL) myElementIDFactory->ReleaseID(ID);
4501 //=======================================================================
4502 //function : AddVolumeWithID
4504 //=======================================================================
4505 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4,
4506 int n5, int n6, int n7, int n8,
4507 int n12,int n23,int n34,int n41,
4508 int n56,int n67,int n78,int n85,
4509 int n15,int n26,int n37,int n48,
4510 int n1234,int n1256,int n2367,int n3478,
4511 int n1458,int n5678,int nCenter, int ID)
4513 return SMDS_Mesh::AddVolumeWithID
4514 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1),
4515 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2),
4516 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3),
4517 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4),
4518 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5),
4519 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n6),
4520 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n7),
4521 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n8),
4522 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
4523 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
4524 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n34),
4525 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n41),
4526 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n56),
4527 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n67),
4528 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n78),
4529 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n85),
4530 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n15),
4531 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n26),
4532 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n37),
4533 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n48),
4534 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1234),
4535 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1256),
4536 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2367),
4537 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3478),
4538 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1458),
4539 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5678),
4540 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(nCenter),
4544 //=======================================================================
4545 //function : AddVolumeWithID
4546 //purpose : 2d order Hexahedrons with 20 nodes
4547 //=======================================================================
4548 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
4549 const SMDS_MeshNode * n2,
4550 const SMDS_MeshNode * n3,
4551 const SMDS_MeshNode * n4,
4552 const SMDS_MeshNode * n5,
4553 const SMDS_MeshNode * n6,
4554 const SMDS_MeshNode * n7,
4555 const SMDS_MeshNode * n8,
4556 const SMDS_MeshNode * n12,
4557 const SMDS_MeshNode * n23,
4558 const SMDS_MeshNode * n34,
4559 const SMDS_MeshNode * n41,
4560 const SMDS_MeshNode * n56,
4561 const SMDS_MeshNode * n67,
4562 const SMDS_MeshNode * n78,
4563 const SMDS_MeshNode * n85,
4564 const SMDS_MeshNode * n15,
4565 const SMDS_MeshNode * n26,
4566 const SMDS_MeshNode * n37,
4567 const SMDS_MeshNode * n48,
4568 const SMDS_MeshNode * n1234,
4569 const SMDS_MeshNode * n1256,
4570 const SMDS_MeshNode * n2367,
4571 const SMDS_MeshNode * n3478,
4572 const SMDS_MeshNode * n1458,
4573 const SMDS_MeshNode * n5678,
4574 const SMDS_MeshNode * nCenter,
4577 if (!n1 || !n2 || !n3 || !n4 || !n5 || !n6 || !n7 || !n8 || !n12 || !n23 ||
4578 !n34 || !n41 || !n56 || !n67 || !n78 || !n85 || !n15 || !n26 || !n37 || !n48 ||
4579 !n1234 || !n1256 || !n2367 || !n3478 || !n1458 || !n5678 || !nCenter )
4581 if(hasConstructionFaces()) {
4583 // creation quadratic faces - not implemented
4585 // --- retrieve nodes ID
4586 myNodeIds.resize(27);
4587 myNodeIds[0] = n1->getVtkId();
4588 myNodeIds[1] = n4->getVtkId();
4589 myNodeIds[2] = n3->getVtkId();
4590 myNodeIds[3] = n2->getVtkId();
4592 myNodeIds[4] = n5->getVtkId();
4593 myNodeIds[5] = n8->getVtkId();
4594 myNodeIds[6] = n7->getVtkId();
4595 myNodeIds[7] = n6->getVtkId();
4597 myNodeIds[8] = n41->getVtkId();
4598 myNodeIds[9] = n34->getVtkId();
4599 myNodeIds[10] = n23->getVtkId();
4600 myNodeIds[11] = n12->getVtkId();
4602 myNodeIds[12] = n85->getVtkId();
4603 myNodeIds[13] = n78->getVtkId();
4604 myNodeIds[14] = n67->getVtkId();
4605 myNodeIds[15] = n56->getVtkId();
4607 myNodeIds[16] = n15->getVtkId();
4608 myNodeIds[17] = n48->getVtkId();
4609 myNodeIds[18] = n37->getVtkId();
4610 myNodeIds[19] = n26->getVtkId();
4612 myNodeIds[20] = n1256->getVtkId();
4613 myNodeIds[21] = n3478->getVtkId();
4614 myNodeIds[22] = n1458->getVtkId();
4615 myNodeIds[23] = n2367->getVtkId();
4616 myNodeIds[24] = n1234->getVtkId();
4617 myNodeIds[25] = n5678->getVtkId();
4618 myNodeIds[26] = nCenter->getVtkId();
4620 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
4621 volvtk->init(myNodeIds, this);
4622 if (!this->registerElement(ID,volvtk))
4624 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
4625 myVolumePool->destroy(volvtk);
4628 adjustmyCellsCapacity(ID);
4629 myCells[ID] = volvtk;
4630 myInfo.myNbTriQuadHexas++;
4636 void SMDS_Mesh::updateNodeMinMax()
4639 if (myNodes.size() == 0)
4644 while ( !myNodes[myNodeMin] && myNodeMin < (int)myNodes.size() )
4646 myNodeMax=myNodes.size()-1;
4647 while (!myNodes[myNodeMax] && (myNodeMin>=0))
4651 void SMDS_Mesh::incrementNodesCapacity(int nbNodes)
4653 // int val = myCellIdSmdsToVtk.size();
4654 // MESSAGE(" ------------------- resize myCellIdSmdsToVtk " << val << " --> " << val + nbNodes);
4655 // myCellIdSmdsToVtk.resize(val + nbNodes, -1); // fill new elements with -1
4656 int val = myNodes.size();
4657 myNodes.resize(val +nbNodes, 0);
4660 void SMDS_Mesh::incrementCellsCapacity(int nbCells)
4662 int val = myCellIdVtkToSmds.size();
4663 myCellIdVtkToSmds.resize(val + nbCells, -1); // fill new elements with -1
4664 val = myCells.size();
4665 myNodes.resize(val +nbCells, 0);
4668 void SMDS_Mesh::adjustStructure()
4670 myGrid->GetPoints()->GetData()->SetNumberOfTuples(myNodeIDFactory->GetMaxID());
4673 void SMDS_Mesh::dumpGrid(string ficdump)
4675 // vtkUnstructuredGridWriter* aWriter = vtkUnstructuredGridWriter::New();
4676 // aWriter->SetFileName(ficdump.c_str());
4677 // aWriter->SetInput(myGrid);
4678 // if(myGrid->GetNumberOfCells())
4680 // aWriter->Write();
4682 // aWriter->Delete();
4683 ficdump = ficdump + "_connectivity";
4684 ofstream ficcon(ficdump.c_str(), ios::out);
4685 int nbPoints = myGrid->GetNumberOfPoints();
4686 ficcon << "-------------------------------- points " << nbPoints << endl;
4687 for (int i=0; i<nbPoints; i++)
4689 ficcon << i << " " << *(myGrid->GetPoint(i)) << " " << *(myGrid->GetPoint(i)+1) << " " << " " << *(myGrid->GetPoint(i)+2) << endl;
4691 int nbCells = myGrid->GetNumberOfCells();
4692 ficcon << "-------------------------------- cells " << nbCells << endl;
4693 for (int i=0; i<nbCells; i++)
4695 ficcon << i << " - " << myGrid->GetCell(i)->GetCellType() << " -";
4696 int nbptcell = myGrid->GetCell(i)->GetNumberOfPoints();
4697 vtkIdList *listid = myGrid->GetCell(i)->GetPointIds();
4698 for (int j=0; j<nbptcell; j++)
4700 ficcon << " " << listid->GetId(j);
4704 ficcon << "-------------------------------- connectivity " << nbPoints << endl;
4705 vtkCellLinks *links = myGrid->GetCellLinks();
4706 for (int i=0; i<nbPoints; i++)
4708 int ncells = links->GetNcells(i);
4709 vtkIdType *cells = links->GetCells(i);
4710 ficcon << i << " - " << ncells << " -";
4711 for (int j=0; j<ncells; j++)
4713 ficcon << " " << cells[j];
4721 void SMDS_Mesh::compactMesh()
4723 MESSAGE("SMDS_Mesh::compactMesh do nothing!");
4726 int SMDS_Mesh::fromVtkToSmds(int vtkid)
4728 if (vtkid >= 0 && vtkid < (int)myCellIdVtkToSmds.size())
4729 return myCellIdVtkToSmds[vtkid];
4730 throw SALOME_Exception(LOCALIZED ("vtk id out of bounds"));
4733 void SMDS_Mesh::updateBoundingBox()
4738 vtkPoints *points = myGrid->GetPoints();
4739 int myNodesSize = this->myNodes.size();
4740 for (int i = 0; i < myNodesSize; i++)
4742 if (SMDS_MeshNode *n = myNodes[i])
4745 points->GetPoint(n->myVtkID, coords);
4746 if (coords[0] < xmin) xmin = coords[0];
4747 else if (coords[0] > xmax) xmax = coords[0];
4748 if (coords[1] < ymin) ymin = coords[1];
4749 else if (coords[1] > ymax) ymax = coords[1];
4750 if (coords[2] < zmin) zmin = coords[2];
4751 else if (coords[2] > zmax) zmax = coords[2];
4756 double SMDS_Mesh::getMaxDim()
4758 double dmax = 1.e-3;
4759 if ((xmax - xmin) > dmax) dmax = xmax -xmin;
4760 if ((ymax - ymin) > dmax) dmax = ymax -ymin;
4761 if ((zmax - zmin) > dmax) dmax = zmax -zmin;
4765 //! modification that needs compact structure and redraw
4766 void SMDS_Mesh::Modified()
4768 if (this->myModified)
4770 this->myModifTime++;
4775 //! get last modification timeStamp
4776 unsigned long SMDS_Mesh::GetMTime() const
4778 return this->myModifTime;
4781 bool SMDS_Mesh::isCompacted()
4783 if (this->myModifTime > this->myCompactTime)
4785 this->myCompactTime = this->myModifTime;