1 // Copyright (C) 2007-2014 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()
129 myNodeIDFactory(new SMDS_MeshNodeIDFactory()),
130 myElementIDFactory(new SMDS_MeshElementIDFactory()),
131 myHasConstructionEdges(false), myHasConstructionFaces(false),
132 myHasInverseElements(true),
133 myNodeMin(0), myNodeMax(0),
134 myNodePool(0), myEdgePool(0), myFacePool(0), myVolumePool(0),myBallPool(0),
135 myModified(false), myModifTime(0), myCompactTime(0),
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 MESSAGE("myMeshId=" << myMeshId);
140 MESSAGE("sizeof(SMDS_MeshElement) " << sizeof(SMDS_MeshElement) );
141 MESSAGE("sizeof(SMDS_MeshNode) " << sizeof(SMDS_MeshNode) );
142 MESSAGE("sizeof(SMDS_MeshCell) " << sizeof(SMDS_MeshCell) );
143 MESSAGE("sizeof(SMDS_VtkVolume) " << sizeof(SMDS_VtkVolume) );
144 MESSAGE("sizeof(SMDS_Position) " << sizeof(SMDS_Position) );
145 MESSAGE("sizeof(SMDS_SpacePosition) " << sizeof(SMDS_SpacePosition) );
146 myNodeIDFactory->SetMesh(this);
147 myElementIDFactory->SetMesh(this);
148 _meshList.push_back(this);
149 myNodePool = new ObjectPool<SMDS_MeshNode>(SMDS_Mesh::chunkSize);
150 myEdgePool = new ObjectPool<SMDS_VtkEdge>(SMDS_Mesh::chunkSize);
151 myFacePool = new ObjectPool<SMDS_VtkFace>(SMDS_Mesh::chunkSize);
152 myVolumePool = new ObjectPool<SMDS_VtkVolume>(SMDS_Mesh::chunkSize);
153 myBallPool = new ObjectPool<SMDS_BallElement>(SMDS_Mesh::chunkSize);
157 //myCellIdSmdsToVtk.clear();
158 myCellIdVtkToSmds.clear();
159 myGrid = SMDS_UnstructuredGrid::New();
160 myGrid->setSMDS_mesh(this);
161 myGrid->Initialize();
163 vtkPoints* points = vtkPoints::New();
164 // bug "21125: EDF 1233 SMESH: Degrardation of precision in a test case for quadratic conversion"
165 // Use double type for storing coordinates of nodes instead of float.
166 points->SetDataType(VTK_DOUBLE);
167 points->SetNumberOfPoints(0 /*SMDS_Mesh::chunkSize*/);
168 myGrid->SetPoints( points );
170 myGrid->BuildLinks();
174 ///////////////////////////////////////////////////////////////////////////////
175 /// Create a new child mesh
176 /// Note that the tree structure of SMDS_Mesh seems to be unused in this version
177 /// (2003-09-08) of SMESH
178 ///////////////////////////////////////////////////////////////////////////////
179 SMDS_Mesh::SMDS_Mesh(SMDS_Mesh * parent)
180 :myParent(parent), myNodeIDFactory(parent->myNodeIDFactory),
181 myElementIDFactory(parent->myElementIDFactory),
182 myHasConstructionEdges(false), myHasConstructionFaces(false),
183 myHasInverseElements(true),
184 myNodePool(parent->myNodePool),
185 myEdgePool(parent->myEdgePool),
186 myFacePool(parent->myFacePool),
187 myVolumePool(parent->myVolumePool),
188 myBallPool(parent->myBallPool)
192 ///////////////////////////////////////////////////////////////////////////////
193 ///Create a submesh and add it to the current mesh
194 ///////////////////////////////////////////////////////////////////////////////
196 SMDS_Mesh *SMDS_Mesh::AddSubMesh()
198 SMDS_Mesh *submesh = new SMDS_Mesh(this);
199 myChildren.insert(myChildren.end(), submesh);
203 ///////////////////////////////////////////////////////////////////////////////
204 ///create a MeshNode and add it to the current Mesh
205 ///An ID is automatically assigned to the node.
206 ///@return : The created node
207 ///////////////////////////////////////////////////////////////////////////////
209 SMDS_MeshNode * SMDS_Mesh::AddNode(double x, double y, double z)
211 return SMDS_Mesh::AddNodeWithID(x,y,z,myNodeIDFactory->GetFreeID());
214 ///////////////////////////////////////////////////////////////////////////////
215 ///create a MeshNode and add it to the current Mesh
216 ///@param ID : The ID of the MeshNode to create
217 ///@return : The created node or NULL if a node with this ID already exists
218 ///////////////////////////////////////////////////////////////////////////////
219 SMDS_MeshNode * SMDS_Mesh::AddNodeWithID(double x, double y, double z, int ID)
221 // find the MeshNode corresponding to ID
222 const SMDS_MeshElement *node = myNodeIDFactory->MeshElement(ID);
226 MESSAGE("=============> Bad Node Id: " << ID);
227 ID = myNodeIDFactory->GetFreeID();
229 myNodeIDFactory->adjustMaxId(ID);
230 SMDS_MeshNode * node = myNodePool->getNew();
231 node->init(ID, myMeshId, 0, x, y, z);
233 if (ID >= myNodes.size())
235 myNodes.resize(ID+SMDS_Mesh::chunkSize, 0);
236 // MESSAGE(" ------------------ myNodes resize " << ID << " --> " << ID+SMDS_Mesh::chunkSize);
239 myNodeIDFactory->BindID(ID,node);
242 this->adjustBoundingBox(x, y, z);
248 ///////////////////////////////////////////////////////////////////////////////
249 /// create a Mesh0DElement and add it to the current Mesh
250 /// @return : The created Mesh0DElement
251 ///////////////////////////////////////////////////////////////////////////////
252 SMDS_Mesh0DElement* SMDS_Mesh::Add0DElementWithID(int idnode, int ID)
254 SMDS_MeshNode * node = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode);
255 if (!node) return NULL;
256 return SMDS_Mesh::Add0DElementWithID(node, ID);
259 ///////////////////////////////////////////////////////////////////////////////
260 /// create a Mesh0DElement and add it to the current Mesh
261 /// @return : The created Mesh0DElement
262 ///////////////////////////////////////////////////////////////////////////////
263 SMDS_Mesh0DElement* SMDS_Mesh::Add0DElement(const SMDS_MeshNode * node)
265 return SMDS_Mesh::Add0DElementWithID(node, myElementIDFactory->GetFreeID());
268 ///////////////////////////////////////////////////////////////////////////////
269 /// Create a new Mesh0DElement and at it to the mesh
270 /// @param idnode ID of the node
271 /// @param ID ID of the 0D element to create
272 /// @return The created 0D element or NULL if an element with this
273 /// ID already exists or if input node is not found.
274 ///////////////////////////////////////////////////////////////////////////////
275 SMDS_Mesh0DElement* SMDS_Mesh::Add0DElementWithID(const SMDS_MeshNode * n, int ID)
279 if (Nb0DElements() % CHECKMEMORY_INTERVAL == 0) CheckMemory();
280 //MESSAGE("Add0DElementWithID" << ID)
281 SMDS_Mesh0DElement * el0d = new SMDS_Mesh0DElement(n);
282 if (myElementIDFactory->BindID(ID, el0d)) {
283 //SMDS_MeshNode *node = const_cast<SMDS_MeshNode*>(n);
284 //node->AddInverseElement(el0d);// --- fait avec BindID
285 adjustmyCellsCapacity(ID);
287 myInfo.myNb0DElements++;
295 ///////////////////////////////////////////////////////////////////////////////
296 /// create a Ball and add it to the current Mesh
297 /// @return : The created Ball
298 ///////////////////////////////////////////////////////////////////////////////
299 SMDS_BallElement* SMDS_Mesh::AddBallWithID(int idnode, double diameter, int ID)
301 SMDS_MeshNode * node = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode);
302 if (!node) return NULL;
303 return SMDS_Mesh::AddBallWithID(node, diameter, ID);
306 ///////////////////////////////////////////////////////////////////////////////
307 /// create a Ball and add it to the current Mesh
308 /// @return : The created Ball
309 ///////////////////////////////////////////////////////////////////////////////
310 SMDS_BallElement* SMDS_Mesh::AddBall(const SMDS_MeshNode * node, double diameter)
312 return SMDS_Mesh::AddBallWithID(node, diameter, myElementIDFactory->GetFreeID());
315 ///////////////////////////////////////////////////////////////////////////////
316 /// Create a new Ball and at it to the mesh
317 /// @param idnode ID of the node
318 // @param diameter ball diameter
319 /// @param ID ID of the 0D element to create
320 /// @return The created 0D element or NULL if an element with this
321 /// ID already exists or if input node is not found.
322 ///////////////////////////////////////////////////////////////////////////////
323 SMDS_BallElement* SMDS_Mesh::AddBallWithID(const SMDS_MeshNode * n, double diameter, int ID)
327 if (NbBalls() % CHECKMEMORY_INTERVAL == 0) CheckMemory();
329 SMDS_BallElement *ball = myBallPool->getNew();
330 ball->init(n->getVtkId(), diameter, this);
331 if (!this->registerElement(ID,ball))
333 this->myGrid->GetCellTypesArray()->SetValue(ball->getVtkId(), VTK_EMPTY_CELL);
334 myBallPool->destroy(ball);
337 adjustmyCellsCapacity(ID);
343 ///////////////////////////////////////////////////////////////////////////////
344 /// create a MeshEdge and add it to the current Mesh
345 /// @return : The created MeshEdge
346 ///////////////////////////////////////////////////////////////////////////////
348 SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(int idnode1, int idnode2, int ID)
350 SMDS_MeshNode * node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
351 SMDS_MeshNode * node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
352 if(!node1 || !node2) return NULL;
353 return SMDS_Mesh::AddEdgeWithID(node1, node2, ID);
356 ///////////////////////////////////////////////////////////////////////////////
357 /// create a MeshEdge and add it to the current Mesh
358 /// @return : The created MeshEdge
359 ///////////////////////////////////////////////////////////////////////////////
361 SMDS_MeshEdge* SMDS_Mesh::AddEdge(const SMDS_MeshNode * node1,
362 const SMDS_MeshNode * node2)
364 return SMDS_Mesh::AddEdgeWithID(node1, node2, myElementIDFactory->GetFreeID());
367 ///////////////////////////////////////////////////////////////////////////////
368 /// Create a new edge and at it to the mesh
369 /// @param idnode1 ID of the first node
370 /// @param idnode2 ID of the second node
371 /// @param ID ID of the edge to create
372 /// @return The created edge or NULL if an element with this ID already exists or
373 /// if input nodes are not found.
374 ///////////////////////////////////////////////////////////////////////////////
376 SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
377 const SMDS_MeshNode * n2,
380 if ( !n1 || !n2 ) return 0;
381 SMDS_MeshEdge * edge = 0;
383 // --- retreive nodes ID
384 vector<vtkIdType> nodeIds;
386 nodeIds.push_back(n1->getVtkId());
387 nodeIds.push_back(n2->getVtkId());
389 SMDS_VtkEdge *edgevtk = myEdgePool->getNew();
390 edgevtk->init(nodeIds, this);
391 if (!this->registerElement(ID,edgevtk))
393 this->myGrid->GetCellTypesArray()->SetValue(edgevtk->getVtkId(), VTK_EMPTY_CELL);
394 myEdgePool->destroy(edgevtk);
398 adjustmyCellsCapacity(ID);
402 // if (edge && !registerElement(ID, edge))
404 // RemoveElement(edge, false);
410 ///////////////////////////////////////////////////////////////////////////////
411 /// Add a triangle defined by its nodes. An ID is automatically affected to the
413 ///////////////////////////////////////////////////////////////////////////////
415 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
416 const SMDS_MeshNode * n2,
417 const SMDS_MeshNode * n3)
419 return SMDS_Mesh::AddFaceWithID(n1,n2,n3, myElementIDFactory->GetFreeID());
422 ///////////////////////////////////////////////////////////////////////////////
423 /// Add a triangle defined by its nodes IDs
424 ///////////////////////////////////////////////////////////////////////////////
426 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int idnode1, int idnode2, int idnode3, int ID)
428 SMDS_MeshNode * node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
429 SMDS_MeshNode * node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
430 SMDS_MeshNode * node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
431 if(!node1 || !node2 || !node3) return NULL;
432 return SMDS_Mesh::AddFaceWithID(node1, node2, node3, ID);
435 ///////////////////////////////////////////////////////////////////////////////
436 /// Add a triangle defined by its nodes
437 ///////////////////////////////////////////////////////////////////////////////
439 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
440 const SMDS_MeshNode * n2,
441 const SMDS_MeshNode * n3,
444 //MESSAGE("AddFaceWithID " << ID)
445 SMDS_MeshFace * face=createTriangle(n1, n2, n3, ID);
447 // if (face && !registerElement(ID, face)) {
448 // RemoveElement(face, false);
454 ///////////////////////////////////////////////////////////////////////////////
455 /// Add a quadrangle defined by its nodes. An ID is automatically affected to the
457 ///////////////////////////////////////////////////////////////////////////////
459 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
460 const SMDS_MeshNode * n2,
461 const SMDS_MeshNode * n3,
462 const SMDS_MeshNode * n4)
464 return SMDS_Mesh::AddFaceWithID(n1,n2,n3, n4, myElementIDFactory->GetFreeID());
467 ///////////////////////////////////////////////////////////////////////////////
468 /// Add a quadrangle defined by its nodes IDs
469 ///////////////////////////////////////////////////////////////////////////////
471 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int idnode1,
477 SMDS_MeshNode *node1, *node2, *node3, *node4;
478 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
479 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
480 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
481 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
482 if(!node1 || !node2 || !node3 || !node4) return NULL;
483 return SMDS_Mesh::AddFaceWithID(node1, node2, node3, node4, ID);
486 ///////////////////////////////////////////////////////////////////////////////
487 /// Add a quadrangle defined by its nodes
488 ///////////////////////////////////////////////////////////////////////////////
490 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
491 const SMDS_MeshNode * n2,
492 const SMDS_MeshNode * n3,
493 const SMDS_MeshNode * n4,
496 //MESSAGE("AddFaceWithID " << ID);
497 SMDS_MeshFace * face=createQuadrangle(n1, n2, n3, n4, ID);
499 // if (face && !registerElement(ID, face)) {
500 // RemoveElement(face, false);
506 ///////////////////////////////////////////////////////////////////////////////
507 /// Add a triangle defined by its edges. An ID is automatically assigned to the
509 ///////////////////////////////////////////////////////////////////////////////
511 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshEdge * e1,
512 const SMDS_MeshEdge * e2,
513 const SMDS_MeshEdge * e3)
515 if (!hasConstructionEdges())
517 //MESSAGE("AddFaceWithID");
518 return AddFaceWithID(e1,e2,e3, myElementIDFactory->GetFreeID());
521 ///////////////////////////////////////////////////////////////////////////////
522 /// Add a triangle defined by its edges
523 ///////////////////////////////////////////////////////////////////////////////
525 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshEdge * e1,
526 const SMDS_MeshEdge * e2,
527 const SMDS_MeshEdge * e3,
530 if (!hasConstructionEdges())
532 if ( !e1 || !e2 || !e3 ) return 0;
534 if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
535 MESSAGE("AddFaceWithID" << ID);
537 SMDS_MeshFace * face = new SMDS_FaceOfEdges(e1,e2,e3);
538 adjustmyCellsCapacity(ID);
540 myInfo.myNbTriangles++;
542 if (!registerElement(ID, face)) {
543 registerElement(myElementIDFactory->GetFreeID(), face);
544 //RemoveElement(face, false);
550 ///////////////////////////////////////////////////////////////////////////////
551 /// Add a quadrangle defined by its edges. An ID is automatically assigned to the
553 ///////////////////////////////////////////////////////////////////////////////
555 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshEdge * e1,
556 const SMDS_MeshEdge * e2,
557 const SMDS_MeshEdge * e3,
558 const SMDS_MeshEdge * e4)
560 if (!hasConstructionEdges())
562 //MESSAGE("AddFaceWithID" );
563 return AddFaceWithID(e1,e2,e3,e4, myElementIDFactory->GetFreeID());
566 ///////////////////////////////////////////////////////////////////////////////
567 /// Add a quadrangle defined by its edges
568 ///////////////////////////////////////////////////////////////////////////////
570 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshEdge * e1,
571 const SMDS_MeshEdge * e2,
572 const SMDS_MeshEdge * e3,
573 const SMDS_MeshEdge * e4,
576 if (!hasConstructionEdges())
578 MESSAGE("AddFaceWithID" << ID);
579 if ( !e1 || !e2 || !e3 || !e4 ) return 0;
580 if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
581 SMDS_MeshFace * face = new SMDS_FaceOfEdges(e1,e2,e3,e4);
582 adjustmyCellsCapacity(ID);
584 myInfo.myNbQuadrangles++;
586 if (!registerElement(ID, face))
588 registerElement(myElementIDFactory->GetFreeID(), face);
589 //RemoveElement(face, false);
595 ///////////////////////////////////////////////////////////////////////////////
596 ///Create a new tetrahedron and add it to the mesh.
597 ///@return The created tetrahedron
598 ///////////////////////////////////////////////////////////////////////////////
600 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
601 const SMDS_MeshNode * n2,
602 const SMDS_MeshNode * n3,
603 const SMDS_MeshNode * n4)
605 int ID = myElementIDFactory->GetFreeID();
606 //MESSAGE("AddVolumeWithID " << ID);
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 //MESSAGE("AddVolumeWithID" << ID);
626 SMDS_MeshNode *node1, *node2, *node3, *node4;
627 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
628 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
629 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
630 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
631 if(!node1 || !node2 || !node3 || !node4) return NULL;
632 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, ID);
635 ///////////////////////////////////////////////////////////////////////////////
636 ///Create a new tetrahedron and add it to the mesh.
637 ///@param ID The ID of the new volume
638 ///@return The created tetrahedron
639 ///////////////////////////////////////////////////////////////////////////////
641 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
642 const SMDS_MeshNode * n2,
643 const SMDS_MeshNode * n3,
644 const SMDS_MeshNode * n4,
647 //MESSAGE("AddVolumeWithID " << ID);
648 SMDS_MeshVolume* volume = 0;
649 if ( !n1 || !n2 || !n3 || !n4) return volume;
650 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
651 if(hasConstructionFaces()) {
652 SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3);
653 SMDS_MeshFace * f2=FindFaceOrCreate(n1,n2,n4);
654 SMDS_MeshFace * f3=FindFaceOrCreate(n1,n3,n4);
655 SMDS_MeshFace * f4=FindFaceOrCreate(n2,n3,n4);
656 volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4);
657 adjustmyCellsCapacity(ID);
658 myCells[ID] = volume;
661 else if(hasConstructionEdges()) {
662 MESSAGE("Error : Not implemented");
666 // --- retrieve nodes ID
667 vector<vtkIdType> nodeIds;
669 nodeIds.push_back(n1->getVtkId());
670 nodeIds.push_back(n3->getVtkId()); // order SMDS-->VTK
671 nodeIds.push_back(n2->getVtkId());
672 nodeIds.push_back(n4->getVtkId());
674 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
675 volvtk->init(nodeIds, this);
676 if (!this->registerElement(ID,volvtk))
678 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
679 myVolumePool->destroy(volvtk);
683 adjustmyCellsCapacity(ID);
684 myCells[ID] = volume;
688 // if (!registerElement(ID, volume)) {
689 // RemoveElement(volume, false);
695 ///////////////////////////////////////////////////////////////////////////////
696 ///Create a new pyramid and add it to the mesh.
697 ///Nodes 1,2,3 and 4 define the base of the pyramid
698 ///@return The created pyramid
699 ///////////////////////////////////////////////////////////////////////////////
701 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
702 const SMDS_MeshNode * n2,
703 const SMDS_MeshNode * n3,
704 const SMDS_MeshNode * n4,
705 const SMDS_MeshNode * n5)
707 int ID = myElementIDFactory->GetFreeID();
708 //MESSAGE("AddVolumeWithID " << ID);
709 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, ID);
710 if(v==NULL) myElementIDFactory->ReleaseID(ID);
714 ///////////////////////////////////////////////////////////////////////////////
715 ///Create a new pyramid and add it to the mesh.
716 ///Nodes 1,2,3 and 4 define the base of the pyramid
717 ///@param ID The ID of the new volume
718 ///@return The created pyramid or NULL if an element with this ID already exists
719 ///or if input nodes are not found.
720 ///////////////////////////////////////////////////////////////////////////////
722 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
729 //MESSAGE("AddVolumeWithID " << ID);
730 SMDS_MeshNode *node1, *node2, *node3, *node4, *node5;
731 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
732 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
733 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
734 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
735 node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5);
736 if(!node1 || !node2 || !node3 || !node4 || !node5) return NULL;
737 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, ID);
740 ///////////////////////////////////////////////////////////////////////////////
741 ///Create a new pyramid and add it to the mesh.
742 ///Nodes 1,2,3 and 4 define the base of the pyramid
743 ///@param ID The ID of the new volume
744 ///@return The created pyramid
745 ///////////////////////////////////////////////////////////////////////////////
747 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
748 const SMDS_MeshNode * n2,
749 const SMDS_MeshNode * n3,
750 const SMDS_MeshNode * n4,
751 const SMDS_MeshNode * n5,
754 //MESSAGE("AddVolumeWithID " << ID);
755 SMDS_MeshVolume* volume = 0;
756 if ( !n1 || !n2 || !n3 || !n4 || !n5) return volume;
757 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
758 if(hasConstructionFaces()) {
759 SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3,n4);
760 SMDS_MeshFace * f2=FindFaceOrCreate(n1,n2,n5);
761 SMDS_MeshFace * f3=FindFaceOrCreate(n2,n3,n5);
762 SMDS_MeshFace * f4=FindFaceOrCreate(n3,n4,n5);
763 volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4);
764 adjustmyCellsCapacity(ID);
765 myCells[ID] = volume;
766 myInfo.myNbPyramids++;
768 else if(hasConstructionEdges()) {
769 MESSAGE("Error : Not implemented");
773 // --- retrieve nodes ID
774 vector<vtkIdType> nodeIds;
776 nodeIds.push_back(n1->getVtkId());
777 nodeIds.push_back(n4->getVtkId());
778 nodeIds.push_back(n3->getVtkId());
779 nodeIds.push_back(n2->getVtkId());
780 nodeIds.push_back(n5->getVtkId());
782 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
783 volvtk->init(nodeIds, this);
784 if (!this->registerElement(ID,volvtk))
786 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
787 myVolumePool->destroy(volvtk);
791 adjustmyCellsCapacity(ID);
792 myCells[ID] = volume;
793 myInfo.myNbPyramids++;
796 // if (!registerElement(ID, volume)) {
797 // RemoveElement(volume, false);
803 ///////////////////////////////////////////////////////////////////////////////
804 ///Create a new prism and add it to the mesh.
805 ///Nodes 1,2,3 is a triangle and 1,2,5,4 a quadrangle.
806 ///@return The created prism
807 ///////////////////////////////////////////////////////////////////////////////
809 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
810 const SMDS_MeshNode * n2,
811 const SMDS_MeshNode * n3,
812 const SMDS_MeshNode * n4,
813 const SMDS_MeshNode * n5,
814 const SMDS_MeshNode * n6)
816 int ID = myElementIDFactory->GetFreeID();
817 //MESSAGE("AddVolumeWithID " << ID);
818 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, ID);
819 if(v==NULL) myElementIDFactory->ReleaseID(ID);
823 ///////////////////////////////////////////////////////////////////////////////
824 ///Create a new prism and add it to the mesh.
825 ///Nodes 1,2,3 is a triangle and 1,2,5,4 a quadrangle.
826 ///@param ID The ID of the new volume
827 ///@return The created prism or NULL if an element with this ID already exists
828 ///or if input nodes are not found.
829 ///////////////////////////////////////////////////////////////////////////////
831 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
839 //MESSAGE("AddVolumeWithID " << ID);
840 SMDS_MeshNode *node1, *node2, *node3, *node4, *node5, *node6;
841 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
842 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
843 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
844 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
845 node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5);
846 node6 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode6);
847 if(!node1 || !node2 || !node3 || !node4 || !node5 || !node6) return NULL;
848 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, node6, ID);
851 ///////////////////////////////////////////////////////////////////////////////
852 ///Create a new prism and add it to the mesh.
853 ///Nodes 1,2,3 is a triangle and 1,2,5,4 a quadrangle.
854 ///@param ID The ID of the new volume
855 ///@return The created prism
856 ///////////////////////////////////////////////////////////////////////////////
858 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
859 const SMDS_MeshNode * n2,
860 const SMDS_MeshNode * n3,
861 const SMDS_MeshNode * n4,
862 const SMDS_MeshNode * n5,
863 const SMDS_MeshNode * n6,
866 //MESSAGE("AddVolumeWithID " << ID);
867 SMDS_MeshVolume* volume = 0;
868 if ( !n1 || !n2 || !n3 || !n4 || !n5 || !n6) return volume;
869 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
870 if(hasConstructionFaces()) {
871 SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3);
872 SMDS_MeshFace * f2=FindFaceOrCreate(n4,n5,n6);
873 SMDS_MeshFace * f3=FindFaceOrCreate(n1,n4,n5,n2);
874 SMDS_MeshFace * f4=FindFaceOrCreate(n2,n5,n6,n3);
875 SMDS_MeshFace * f5=FindFaceOrCreate(n3,n6,n4,n1);
876 volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5);
877 adjustmyCellsCapacity(ID);
878 myCells[ID] = volume;
881 else if(hasConstructionEdges()) {
882 MESSAGE("Error : Not implemented");
886 // --- retrieve nodes ID
887 vector<vtkIdType> nodeIds;
889 nodeIds.push_back(n1->getVtkId());
890 nodeIds.push_back(n2->getVtkId());
891 nodeIds.push_back(n3->getVtkId());
892 nodeIds.push_back(n4->getVtkId());
893 nodeIds.push_back(n5->getVtkId());
894 nodeIds.push_back(n6->getVtkId());
896 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
897 volvtk->init(nodeIds, this);
898 if (!this->registerElement(ID,volvtk))
900 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
901 myVolumePool->destroy(volvtk);
905 adjustmyCellsCapacity(ID);
906 myCells[ID] = volume;
910 // if (!registerElement(ID, volume)) {
911 // RemoveElement(volume, false);
917 ///////////////////////////////////////////////////////////////////////////////
918 ///Create a new hexagonal prism and add it to the mesh.
919 ///@return The created prism
920 ///////////////////////////////////////////////////////////////////////////////
922 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
923 const SMDS_MeshNode * n2,
924 const SMDS_MeshNode * n3,
925 const SMDS_MeshNode * n4,
926 const SMDS_MeshNode * n5,
927 const SMDS_MeshNode * n6,
928 const SMDS_MeshNode * n7,
929 const SMDS_MeshNode * n8,
930 const SMDS_MeshNode * n9,
931 const SMDS_MeshNode * n10,
932 const SMDS_MeshNode * n11,
933 const SMDS_MeshNode * n12)
935 int ID = myElementIDFactory->GetFreeID();
936 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6,
937 n7, n8, n9, n10, n11, n12,
939 if(v==NULL) myElementIDFactory->ReleaseID(ID);
943 ///////////////////////////////////////////////////////////////////////////////
944 ///Create a new hexagonal prism and add it to the mesh.
945 ///@param ID The ID of the new volume
946 ///@return The created prism or NULL if an element with this ID already exists
947 ///or if input nodes are not found.
948 ///////////////////////////////////////////////////////////////////////////////
950 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
964 SMDS_MeshNode *node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
965 SMDS_MeshNode *node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
966 SMDS_MeshNode *node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
967 SMDS_MeshNode *node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
968 SMDS_MeshNode *node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5);
969 SMDS_MeshNode *node6 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode6);
970 SMDS_MeshNode *node7 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode7);
971 SMDS_MeshNode *node8 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode8);
972 SMDS_MeshNode *node9 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode9);
973 SMDS_MeshNode *node10 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode10);
974 SMDS_MeshNode *node11 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode11);
975 SMDS_MeshNode *node12 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode12);
976 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, node6,
977 node7, node8, node9, node10, node11, node12,
981 ///////////////////////////////////////////////////////////////////////////////
982 ///Create a new hexagonal prism and add it to the mesh.
983 ///@param ID The ID of the new volume
984 ///@return The created prism
985 ///////////////////////////////////////////////////////////////////////////////
987 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
988 const SMDS_MeshNode * n2,
989 const SMDS_MeshNode * n3,
990 const SMDS_MeshNode * n4,
991 const SMDS_MeshNode * n5,
992 const SMDS_MeshNode * n6,
993 const SMDS_MeshNode * n7,
994 const SMDS_MeshNode * n8,
995 const SMDS_MeshNode * n9,
996 const SMDS_MeshNode * n10,
997 const SMDS_MeshNode * n11,
998 const SMDS_MeshNode * n12,
1001 SMDS_MeshVolume* volume = 0;
1002 if(!n1 || !n2 || !n3 || !n4 || !n5 || !n6 ||
1003 !n7 || !n8 || !n9 || !n10 || !n11 || !n12 )
1005 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1006 if(hasConstructionFaces()) {
1007 MESSAGE("Error : Not implemented");
1010 else if(hasConstructionEdges()) {
1011 MESSAGE("Error : Not implemented");
1015 // --- retrieve nodes ID
1016 vector<vtkIdType> nodeIds;
1017 nodeIds.push_back(n1->getVtkId());
1018 nodeIds.push_back(n6->getVtkId());
1019 nodeIds.push_back(n5->getVtkId());
1020 nodeIds.push_back(n4->getVtkId());
1021 nodeIds.push_back(n3->getVtkId());
1022 nodeIds.push_back(n2->getVtkId());
1024 nodeIds.push_back(n7->getVtkId());
1025 nodeIds.push_back(n12->getVtkId());
1026 nodeIds.push_back(n11->getVtkId());
1027 nodeIds.push_back(n10->getVtkId());
1028 nodeIds.push_back(n9->getVtkId());
1029 nodeIds.push_back(n8->getVtkId());
1031 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
1032 volvtk->init(nodeIds, this);
1033 if (!this->registerElement(ID,volvtk))
1035 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
1036 myVolumePool->destroy(volvtk);
1040 adjustmyCellsCapacity(ID);
1041 myCells[ID] = volume;
1042 myInfo.myNbHexPrism++;
1048 ///////////////////////////////////////////////////////////////////////////////
1049 ///Create a new hexahedron and add it to the mesh.
1050 ///Nodes 1,2,3,4 and 5,6,7,8 are quadrangle and 5,1 and 7,3 are an edges.
1051 ///@return The created hexahedron
1052 ///////////////////////////////////////////////////////////////////////////////
1054 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
1055 const SMDS_MeshNode * n2,
1056 const SMDS_MeshNode * n3,
1057 const SMDS_MeshNode * n4,
1058 const SMDS_MeshNode * n5,
1059 const SMDS_MeshNode * n6,
1060 const SMDS_MeshNode * n7,
1061 const SMDS_MeshNode * n8)
1063 int ID = myElementIDFactory->GetFreeID();
1064 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, ID);
1065 if(v==NULL) myElementIDFactory->ReleaseID(ID);
1069 ///////////////////////////////////////////////////////////////////////////////
1070 ///Create a new hexahedron and add it to the mesh.
1071 ///Nodes 1,2,3,4 and 5,6,7,8 are quadrangle and 5,1 and 7,3 are an edges.
1072 ///@param ID The ID of the new volume
1073 ///@return The created hexahedron or NULL if an element with this ID already
1074 ///exists or if input nodes are not found.
1075 ///////////////////////////////////////////////////////////////////////////////
1077 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
1087 //MESSAGE("AddVolumeWithID " << ID);
1088 SMDS_MeshNode *node1, *node2, *node3, *node4, *node5, *node6, *node7, *node8;
1089 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
1090 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
1091 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
1092 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
1093 node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5);
1094 node6 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode6);
1095 node7 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode7);
1096 node8 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode8);
1097 if(!node1 || !node2 || !node3 || !node4 || !node5 || !node6 || !node7 || !node8)
1099 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, node6,
1103 ///////////////////////////////////////////////////////////////////////////////
1104 ///Create a new hexahedron and add it to the mesh.
1105 ///Nodes 1,2,3,4 and 5,6,7,8 are quadrangle and 5,1 and 7,3 are an edges.
1106 ///@param ID The ID of the new volume
1107 ///@return The created prism or NULL if an element with this ID already exists
1108 ///or if input nodes are not found.
1109 ///////////////////////////////////////////////////////////////////////////////
1111 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
1112 const SMDS_MeshNode * n2,
1113 const SMDS_MeshNode * n3,
1114 const SMDS_MeshNode * n4,
1115 const SMDS_MeshNode * n5,
1116 const SMDS_MeshNode * n6,
1117 const SMDS_MeshNode * n7,
1118 const SMDS_MeshNode * n8,
1121 //MESSAGE("AddVolumeWithID " << ID);
1122 SMDS_MeshVolume* volume = 0;
1123 if ( !n1 || !n2 || !n3 || !n4 || !n5 || !n6 || !n7 || !n8) return volume;
1124 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1125 if(hasConstructionFaces()) {
1126 SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3,n4);
1127 SMDS_MeshFace * f2=FindFaceOrCreate(n5,n6,n7,n8);
1128 SMDS_MeshFace * f3=FindFaceOrCreate(n1,n4,n8,n5);
1129 SMDS_MeshFace * f4=FindFaceOrCreate(n1,n2,n6,n5);
1130 SMDS_MeshFace * f5=FindFaceOrCreate(n2,n3,n7,n6);
1131 SMDS_MeshFace * f6=FindFaceOrCreate(n3,n4,n8,n7);
1132 volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5,f6);
1133 adjustmyCellsCapacity(ID);
1134 myCells[ID] = volume;
1137 else if(hasConstructionEdges()) {
1138 MESSAGE("Error : Not implemented");
1142 // --- retrieve nodes ID
1143 vector<vtkIdType> nodeIds;
1145 nodeIds.push_back(n1->getVtkId());
1146 nodeIds.push_back(n4->getVtkId());
1147 nodeIds.push_back(n3->getVtkId());
1148 nodeIds.push_back(n2->getVtkId());
1149 nodeIds.push_back(n5->getVtkId());
1150 nodeIds.push_back(n8->getVtkId());
1151 nodeIds.push_back(n7->getVtkId());
1152 nodeIds.push_back(n6->getVtkId());
1154 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
1155 volvtk->init(nodeIds, this);
1156 if (!this->registerElement(ID,volvtk))
1158 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
1159 myVolumePool->destroy(volvtk);
1163 adjustmyCellsCapacity(ID);
1164 myCells[ID] = volume;
1168 // if (!registerElement(ID, volume)) {
1169 // RemoveElement(volume, false);
1175 ///////////////////////////////////////////////////////////////////////////////
1176 ///Create a new tetrahedron defined by its faces and add it to the mesh.
1177 ///@return The created tetrahedron
1178 ///////////////////////////////////////////////////////////////////////////////
1180 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshFace * f1,
1181 const SMDS_MeshFace * f2,
1182 const SMDS_MeshFace * f3,
1183 const SMDS_MeshFace * f4)
1185 //MESSAGE("AddVolumeWithID");
1186 if (!hasConstructionFaces())
1188 return AddVolumeWithID(f1,f2,f3,f4, myElementIDFactory->GetFreeID());
1191 ///////////////////////////////////////////////////////////////////////////////
1192 ///Create a new tetrahedron defined by its faces and add it to the mesh.
1193 ///@param ID The ID of the new volume
1194 ///@return The created tetrahedron
1195 ///////////////////////////////////////////////////////////////////////////////
1197 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1,
1198 const SMDS_MeshFace * f2,
1199 const SMDS_MeshFace * f3,
1200 const SMDS_MeshFace * f4,
1203 MESSAGE("AddVolumeWithID" << ID);
1204 if (!hasConstructionFaces())
1206 if ( !f1 || !f2 || !f3 || !f4) return 0;
1207 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1208 SMDS_MeshVolume * volume = new SMDS_VolumeOfFaces(f1,f2,f3,f4);
1209 adjustmyCellsCapacity(ID);
1210 myCells[ID] = volume;
1211 myInfo.myNbTetras++;
1213 if (!registerElement(ID, volume)) {
1214 registerElement(myElementIDFactory->GetFreeID(), volume);
1215 //RemoveElement(volume, false);
1221 ///////////////////////////////////////////////////////////////////////////////
1222 ///Create a new pyramid defined by its faces and add it to the mesh.
1223 ///@return The created pyramid
1224 ///////////////////////////////////////////////////////////////////////////////
1226 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshFace * f1,
1227 const SMDS_MeshFace * f2,
1228 const SMDS_MeshFace * f3,
1229 const SMDS_MeshFace * f4,
1230 const SMDS_MeshFace * f5)
1232 //MESSAGE("AddVolumeWithID");
1233 if (!hasConstructionFaces())
1235 return AddVolumeWithID(f1,f2,f3,f4,f5, myElementIDFactory->GetFreeID());
1238 ///////////////////////////////////////////////////////////////////////////////
1239 ///Create a new pyramid defined by its faces and add it to the mesh.
1240 ///@param ID The ID of the new volume
1241 ///@return The created pyramid
1242 ///////////////////////////////////////////////////////////////////////////////
1244 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1,
1245 const SMDS_MeshFace * f2,
1246 const SMDS_MeshFace * f3,
1247 const SMDS_MeshFace * f4,
1248 const SMDS_MeshFace * f5,
1251 MESSAGE("AddVolumeWithID" << ID);
1252 if (!hasConstructionFaces())
1254 if ( !f1 || !f2 || !f3 || !f4 || !f5) return 0;
1255 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1256 SMDS_MeshVolume * volume = new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5);
1257 adjustmyCellsCapacity(ID);
1258 myCells[ID] = volume;
1259 myInfo.myNbPyramids++;
1261 if (!registerElement(ID, volume)) {
1262 registerElement(myElementIDFactory->GetFreeID(), volume);
1263 //RemoveElement(volume, false);
1269 ///////////////////////////////////////////////////////////////////////////////
1270 ///Create a new prism defined by its faces and add it to the mesh.
1271 ///@return The created prism
1272 ///////////////////////////////////////////////////////////////////////////////
1274 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshFace * f1,
1275 const SMDS_MeshFace * f2,
1276 const SMDS_MeshFace * f3,
1277 const SMDS_MeshFace * f4,
1278 const SMDS_MeshFace * f5,
1279 const SMDS_MeshFace * f6)
1281 //MESSAGE("AddVolumeWithID" );
1282 if (!hasConstructionFaces())
1284 return AddVolumeWithID(f1,f2,f3,f4,f5,f6, myElementIDFactory->GetFreeID());
1287 ///////////////////////////////////////////////////////////////////////////////
1288 ///Create a new prism defined by its faces and add it to the mesh.
1289 ///@param ID The ID of the new volume
1290 ///@return The created prism
1291 ///////////////////////////////////////////////////////////////////////////////
1293 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1,
1294 const SMDS_MeshFace * f2,
1295 const SMDS_MeshFace * f3,
1296 const SMDS_MeshFace * f4,
1297 const SMDS_MeshFace * f5,
1298 const SMDS_MeshFace * f6,
1301 MESSAGE("AddVolumeWithID" << ID);
1302 if (!hasConstructionFaces())
1304 if ( !f1 || !f2 || !f3 || !f4 || !f5 || !f6) return 0;
1305 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1306 SMDS_MeshVolume * volume = new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5,f6);
1307 adjustmyCellsCapacity(ID);
1308 myCells[ID] = volume;
1309 myInfo.myNbPrisms++;
1311 if (!registerElement(ID, volume)) {
1312 registerElement(myElementIDFactory->GetFreeID(), volume);
1313 //RemoveElement(volume, false);
1319 ///////////////////////////////////////////////////////////////////////////////
1320 /// Add a polygon defined by its nodes IDs
1321 ///////////////////////////////////////////////////////////////////////////////
1323 SMDS_MeshFace* SMDS_Mesh::AddPolygonalFaceWithID (const vector<int> & nodes_ids,
1326 int nbNodes = nodes_ids.size();
1327 vector<const SMDS_MeshNode*> nodes (nbNodes);
1328 for (int i = 0; i < nbNodes; i++) {
1329 nodes[i] = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nodes_ids[i]);
1330 if (!nodes[i]) return NULL;
1332 return SMDS_Mesh::AddPolygonalFaceWithID(nodes, ID);
1335 ///////////////////////////////////////////////////////////////////////////////
1336 /// Add a polygon defined by its nodes
1337 ///////////////////////////////////////////////////////////////////////////////
1339 SMDS_MeshFace* SMDS_Mesh::AddPolygonalFaceWithID
1340 (const vector<const SMDS_MeshNode*> & nodes,
1343 SMDS_MeshFace * face;
1345 if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1346 if (hasConstructionEdges())
1348 MESSAGE("Error : Not implemented");
1353 //#ifdef VTK_HAVE_POLYHEDRON
1354 //MESSAGE("AddPolygonalFaceWithID vtk " << ID);
1355 vector<vtkIdType> nodeIds;
1357 vector<const SMDS_MeshNode*>::const_iterator it = nodes.begin();
1358 for ( ; it != nodes.end(); ++it)
1359 nodeIds.push_back((*it)->getVtkId());
1361 SMDS_VtkFace *facevtk = myFacePool->getNew();
1362 facevtk->initPoly(nodeIds, this);
1363 if (!this->registerElement(ID,facevtk))
1365 this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL);
1366 myFacePool->destroy(facevtk);
1371 // MESSAGE("AddPolygonalFaceWithID smds " << ID);
1372 // for ( int i = 0; i < nodes.size(); ++i )
1373 // if ( !nodes[ i ] ) return 0;
1374 // face = new SMDS_PolygonalFaceOfNodes(nodes);
1376 adjustmyCellsCapacity(ID);
1378 myInfo.myNbPolygons++;
1381 //#ifndef VTK_HAVE_POLYHEDRON
1382 // if (!registerElement(ID, face))
1384 // registerElement(myElementIDFactory->GetFreeID(), face);
1385 // //RemoveElement(face, false);
1392 ///////////////////////////////////////////////////////////////////////////////
1393 /// Add a polygon defined by its nodes.
1394 /// An ID is automatically affected to the created face.
1395 ///////////////////////////////////////////////////////////////////////////////
1397 SMDS_MeshFace* SMDS_Mesh::AddPolygonalFace (const vector<const SMDS_MeshNode*> & nodes)
1399 return SMDS_Mesh::AddPolygonalFaceWithID(nodes, myElementIDFactory->GetFreeID());
1402 ///////////////////////////////////////////////////////////////////////////////
1403 /// Create a new polyhedral volume and add it to the mesh.
1404 /// @param ID The ID of the new volume
1405 /// @return The created volume or NULL if an element with this ID already exists
1406 /// or if input nodes are not found.
1407 ///////////////////////////////////////////////////////////////////////////////
1409 SMDS_MeshVolume * SMDS_Mesh::AddPolyhedralVolumeWithID
1410 (const vector<int> & nodes_ids,
1411 const vector<int> & quantities,
1414 int nbNodes = nodes_ids.size();
1415 vector<const SMDS_MeshNode*> nodes (nbNodes);
1416 for (int i = 0; i < nbNodes; i++) {
1417 nodes[i] = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nodes_ids[i]);
1418 if (!nodes[i]) return NULL;
1420 return SMDS_Mesh::AddPolyhedralVolumeWithID(nodes, quantities, ID);
1423 ///////////////////////////////////////////////////////////////////////////////
1424 /// Create a new polyhedral volume and add it to the mesh.
1425 /// @param ID The ID of the new volume
1426 /// @return The created volume
1427 ///////////////////////////////////////////////////////////////////////////////
1429 SMDS_MeshVolume* SMDS_Mesh::AddPolyhedralVolumeWithID
1430 (const vector<const SMDS_MeshNode*>& nodes,
1431 const vector<int> & quantities,
1434 SMDS_MeshVolume* volume = 0;
1435 if ( nodes.empty() || quantities.empty() )
1437 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1438 if (hasConstructionFaces())
1440 MESSAGE("Error : Not implemented");
1443 else if (hasConstructionEdges())
1445 MESSAGE("Error : Not implemented");
1450 //#ifdef VTK_HAVE_POLYHEDRON
1451 //MESSAGE("AddPolyhedralVolumeWithID vtk " << ID);
1452 vector<vtkIdType> nodeIds;
1454 vector<const SMDS_MeshNode*>::const_iterator it = nodes.begin();
1455 for (; it != nodes.end(); ++it)
1456 nodeIds.push_back((*it)->getVtkId());
1458 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
1459 volvtk->initPoly(nodeIds, quantities, this);
1460 if (!this->registerElement(ID, volvtk))
1462 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
1463 myVolumePool->destroy(volvtk);
1468 // MESSAGE("AddPolyhedralVolumeWithID smds " << ID);
1469 // for ( int i = 0; i < nodes.size(); ++i )
1470 // if ( !nodes[ i ] ) return 0;
1471 // volume = new SMDS_PolyhedralVolumeOfNodes(nodes, quantities);
1473 adjustmyCellsCapacity(ID);
1474 myCells[ID] = volume;
1475 myInfo.myNbPolyhedrons++;
1478 //#ifndef VTK_HAVE_POLYHEDRON
1479 // if (!registerElement(ID, volume))
1481 // registerElement(myElementIDFactory->GetFreeID(), volume);
1482 // //RemoveElement(volume, false);
1489 ///////////////////////////////////////////////////////////////////////////////
1490 /// Create a new polyhedral volume and add it to the mesh.
1491 /// @return The created volume
1492 ///////////////////////////////////////////////////////////////////////////////
1494 SMDS_MeshVolume* SMDS_Mesh::AddPolyhedralVolume
1495 (const vector<const SMDS_MeshNode*> & nodes,
1496 const vector<int> & quantities)
1498 int ID = myElementIDFactory->GetFreeID();
1499 SMDS_MeshVolume * v = SMDS_Mesh::AddPolyhedralVolumeWithID(nodes, quantities, ID);
1500 if (v == NULL) myElementIDFactory->ReleaseID(ID);
1504 SMDS_MeshVolume* SMDS_Mesh::AddVolumeFromVtkIds(const std::vector<vtkIdType>& vtkNodeIds)
1506 int ID = myElementIDFactory->GetFreeID();
1507 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeFromVtkIdsWithID(vtkNodeIds, ID);
1508 if (v == NULL) myElementIDFactory->ReleaseID(ID);
1512 SMDS_MeshVolume* SMDS_Mesh::AddVolumeFromVtkIdsWithID(const std::vector<vtkIdType>& vtkNodeIds, const int ID)
1514 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
1515 volvtk->init(vtkNodeIds, this);
1516 if (!this->registerElement(ID,volvtk))
1518 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
1519 myVolumePool->destroy(volvtk);
1522 adjustmyCellsCapacity(ID);
1523 myCells[ID] = volvtk;
1524 vtkIdType aVtkType = volvtk->GetVtkType();
1528 myInfo.myNbTetras++;
1531 myInfo.myNbPyramids++;
1534 myInfo.myNbPrisms++;
1536 case VTK_HEXAHEDRON:
1539 case VTK_QUADRATIC_TETRA:
1540 myInfo.myNbQuadTetras++;
1542 case VTK_QUADRATIC_PYRAMID:
1543 myInfo.myNbQuadPyramids++;
1545 case VTK_QUADRATIC_WEDGE:
1546 myInfo.myNbQuadPrisms++;
1548 case VTK_QUADRATIC_HEXAHEDRON:
1549 myInfo.myNbQuadHexas++;
1551 //#ifdef VTK_HAVE_POLYHEDRON
1552 case VTK_POLYHEDRON:
1553 myInfo.myNbPolyhedrons++;
1557 myInfo.myNbPolyhedrons++;
1563 SMDS_MeshFace* SMDS_Mesh::AddFaceFromVtkIds(const std::vector<vtkIdType>& vtkNodeIds)
1565 int ID = myElementIDFactory->GetFreeID();
1566 SMDS_MeshFace * f = SMDS_Mesh::AddFaceFromVtkIdsWithID(vtkNodeIds, ID);
1567 if (f == NULL) myElementIDFactory->ReleaseID(ID);
1571 SMDS_MeshFace* SMDS_Mesh::AddFaceFromVtkIdsWithID(const std::vector<vtkIdType>& vtkNodeIds, const int ID)
1573 SMDS_VtkFace *facevtk = myFacePool->getNew();
1574 facevtk->init(vtkNodeIds, this);
1575 if (!this->registerElement(ID,facevtk))
1577 this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL);
1578 myFacePool->destroy(facevtk);
1581 adjustmyCellsCapacity(ID);
1582 myCells[ID] = facevtk;
1583 vtkIdType aVtkType = facevtk->GetVtkType();
1587 myInfo.myNbTriangles++;
1590 myInfo.myNbQuadrangles++;
1592 case VTK_QUADRATIC_TRIANGLE:
1593 myInfo.myNbQuadTriangles++;
1595 case VTK_QUADRATIC_QUAD:
1596 myInfo.myNbQuadQuadrangles++;
1598 case VTK_BIQUADRATIC_QUAD:
1599 myInfo.myNbBiQuadQuadrangles++;
1601 case VTK_BIQUADRATIC_TRIANGLE:
1602 myInfo.myNbBiQuadTriangles++;
1605 myInfo.myNbPolygons++;
1608 myInfo.myNbPolygons++;
1613 ///////////////////////////////////////////////////////////////////////////////
1614 /// Registers element with the given ID, maintains inverse connections
1615 ///////////////////////////////////////////////////////////////////////////////
1616 bool SMDS_Mesh::registerElement(int ID, SMDS_MeshElement* element)
1618 //MESSAGE("registerElement " << ID);
1619 if ((ID >=0) && (ID < myCells.size()) && myCells[ID]) // --- already bound
1621 MESSAGE(" ------------------ already bound "<< ID << " " << myCells[ID]->getVtkId());
1626 element->myMeshId = myMeshId;
1628 SMDS_MeshCell *cell = dynamic_cast<SMDS_MeshCell*>(element);
1630 int vtkId = cell->getVtkId();
1632 vtkId = myElementIDFactory->SetInVtkGrid(element);
1634 if (vtkId >= myCellIdVtkToSmds.size()) // --- resize local vector
1636 // MESSAGE(" --------------------- resize myCellIdVtkToSmds " << vtkId << " --> " << vtkId + SMDS_Mesh::chunkSize);
1637 myCellIdVtkToSmds.resize(vtkId + SMDS_Mesh::chunkSize, -1);
1639 myCellIdVtkToSmds[vtkId] = ID;
1641 myElementIDFactory->updateMinMax(ID);
1645 //=======================================================================
1646 //function : MoveNode
1648 //=======================================================================
1650 void SMDS_Mesh::MoveNode(const SMDS_MeshNode *n, double x, double y, double z)
1652 SMDS_MeshNode * node=const_cast<SMDS_MeshNode*>(n);
1653 node->setXYZ(x,y,z);
1656 ///////////////////////////////////////////////////////////////////////////////
1657 /// Return the node whose SMDS ID is 'ID'.
1658 ///////////////////////////////////////////////////////////////////////////////
1659 const SMDS_MeshNode * SMDS_Mesh::FindNode(int ID) const
1661 if (ID < 1 || ID >= myNodes.size())
1663 // MESSAGE("------------------------------------------------------------------------- ");
1664 // MESSAGE("----------------------------------- bad ID " << ID << " " << myNodes.size());
1665 // MESSAGE("------------------------------------------------------------------------- ");
1668 return (const SMDS_MeshNode *)myNodes[ID];
1671 ///////////////////////////////////////////////////////////////////////////////
1672 /// Return the node whose VTK ID is 'vtkId'.
1673 ///////////////////////////////////////////////////////////////////////////////
1674 const SMDS_MeshNode * SMDS_Mesh::FindNodeVtk(int vtkId) const
1676 // TODO if needed use mesh->nodeIdFromVtkToSmds
1677 if (vtkId < 0 || vtkId >= (myNodes.size() -1))
1679 MESSAGE("------------------------------------------------------------------------- ");
1680 MESSAGE("---------------------------- bad VTK ID " << vtkId << " " << myNodes.size());
1681 MESSAGE("------------------------------------------------------------------------- ");
1684 return (const SMDS_MeshNode *)myNodes[vtkId+1];
1687 ///////////////////////////////////////////////////////////////////////////////
1688 ///Create a triangle and add it to the current mesh. This method do not bind an
1689 ///ID to the create triangle.
1690 ///////////////////////////////////////////////////////////////////////////////
1691 SMDS_MeshFace * SMDS_Mesh::createTriangle(const SMDS_MeshNode * node1,
1692 const SMDS_MeshNode * node2,
1693 const SMDS_MeshNode * node3,
1696 if ( !node1 || !node2 || !node3) return 0;
1697 if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1698 if(hasConstructionEdges())
1700 SMDS_MeshEdge *edge1, *edge2, *edge3;
1701 edge1=FindEdgeOrCreate(node1,node2);
1702 edge2=FindEdgeOrCreate(node2,node3);
1703 edge3=FindEdgeOrCreate(node3,node1);
1705 //int ID = myElementIDFactory->GetFreeID(); // -PR- voir si on range cet element
1706 SMDS_MeshFace * face = new SMDS_FaceOfEdges(edge1,edge2,edge3);
1707 adjustmyCellsCapacity(ID);
1709 myInfo.myNbTriangles++;
1714 // --- retrieve nodes ID
1715 vector<vtkIdType> nodeIds;
1717 nodeIds.push_back(node1->getVtkId());
1718 nodeIds.push_back(node2->getVtkId());
1719 nodeIds.push_back(node3->getVtkId());
1721 SMDS_MeshFace * face = 0;
1722 SMDS_VtkFace *facevtk = myFacePool->getNew();
1723 facevtk->init(nodeIds, this); // put in vtkUnstructuredGrid
1724 if (!this->registerElement(ID,facevtk))
1726 this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL);
1727 myFacePool->destroy(facevtk);
1731 adjustmyCellsCapacity(ID);
1733 //MESSAGE("createTriangle " << ID << " " << face);
1734 myInfo.myNbTriangles++;
1739 ///////////////////////////////////////////////////////////////////////////////
1740 ///Create a quadrangle and add it to the current mesh. This methode do not bind
1741 ///a ID to the create triangle.
1742 ///////////////////////////////////////////////////////////////////////////////
1743 SMDS_MeshFace * SMDS_Mesh::createQuadrangle(const SMDS_MeshNode * node1,
1744 const SMDS_MeshNode * node2,
1745 const SMDS_MeshNode * node3,
1746 const SMDS_MeshNode * node4,
1749 if ( !node1 || !node2 || !node3 || !node4 ) return 0;
1750 if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1751 if(hasConstructionEdges())
1753 //MESSAGE("createQuadrangle hasConstructionEdges "<< ID);
1754 SMDS_MeshEdge *edge1, *edge2, *edge3, *edge4;
1755 edge1=FindEdgeOrCreate(node1,node2);
1756 edge2=FindEdgeOrCreate(node2,node3);
1757 edge3=FindEdgeOrCreate(node3,node4);
1758 edge4=FindEdgeOrCreate(node4,node1);
1760 SMDS_MeshFace * face = new SMDS_FaceOfEdges(edge1,edge2,edge3,edge4);
1761 adjustmyCellsCapacity(ID);
1763 myInfo.myNbQuadrangles++;
1768 // --- retrieve nodes ID
1769 vector<vtkIdType> nodeIds;
1771 nodeIds.push_back(node1->getVtkId());
1772 nodeIds.push_back(node2->getVtkId());
1773 nodeIds.push_back(node3->getVtkId());
1774 nodeIds.push_back(node4->getVtkId());
1776 SMDS_MeshFace * face = 0;
1777 SMDS_VtkFace *facevtk = myFacePool->getNew();
1778 facevtk->init(nodeIds, this);
1779 if (!this->registerElement(ID,facevtk))
1781 this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL);
1782 myFacePool->destroy(facevtk);
1786 adjustmyCellsCapacity(ID);
1788 myInfo.myNbQuadrangles++;
1793 ///////////////////////////////////////////////////////////////////////////////
1794 /// Remove a node and all the elements which own this node
1795 ///////////////////////////////////////////////////////////////////////////////
1797 void SMDS_Mesh::RemoveNode(const SMDS_MeshNode * node)
1799 MESSAGE("RemoveNode");
1800 RemoveElement(node, true);
1803 ///////////////////////////////////////////////////////////////////////////////
1804 /// Remove an edge and all the elements which own this edge
1805 ///////////////////////////////////////////////////////////////////////////////
1807 void SMDS_Mesh::Remove0DElement(const SMDS_Mesh0DElement * elem0d)
1809 MESSAGE("Remove0DElement");
1810 RemoveElement(elem0d,true);
1813 ///////////////////////////////////////////////////////////////////////////////
1814 /// Remove an edge and all the elements which own this edge
1815 ///////////////////////////////////////////////////////////////////////////////
1817 void SMDS_Mesh::RemoveEdge(const SMDS_MeshEdge * edge)
1819 MESSAGE("RemoveEdge");
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 MESSAGE("RemoveFace");
1830 RemoveElement(face, true);
1833 ///////////////////////////////////////////////////////////////////////////////
1835 ///////////////////////////////////////////////////////////////////////////////
1837 void SMDS_Mesh::RemoveVolume(const SMDS_MeshVolume * volume)
1839 MESSAGE("RemoveVolume");
1840 RemoveElement(volume, true);
1843 //=======================================================================
1844 //function : RemoveFromParent
1846 //=======================================================================
1848 bool SMDS_Mesh::RemoveFromParent()
1850 if (myParent==NULL) return false;
1851 else return (myParent->RemoveSubMesh(this));
1854 //=======================================================================
1855 //function : RemoveSubMesh
1857 //=======================================================================
1859 bool SMDS_Mesh::RemoveSubMesh(const SMDS_Mesh * aMesh)
1863 list<SMDS_Mesh *>::iterator itmsh=myChildren.begin();
1864 for (; itmsh!=myChildren.end() && !found; itmsh++)
1866 SMDS_Mesh * submesh = *itmsh;
1867 if (submesh == aMesh)
1870 myChildren.erase(itmsh);
1877 //=======================================================================
1878 //function : ChangeElementNodes
1880 //=======================================================================
1882 bool SMDS_Mesh::ChangeElementNodes(const SMDS_MeshElement * element,
1883 const SMDS_MeshNode * nodes[],
1886 MESSAGE("SMDS_Mesh::ChangeElementNodes");
1887 // keep current nodes of elem
1888 set<const SMDS_MeshNode*> oldNodes( element->begin_nodes(), element->end_nodes() );
1892 SMDS_MeshCell* cell = dynamic_cast<SMDS_MeshCell*>((SMDS_MeshElement*) element);
1895 Ok = cell->vtkOrder(nodes, nbnodes);
1896 Ok = cell->ChangeNodes(nodes, nbnodes);
1899 if ( Ok ) { // update InverseElements
1901 set<const SMDS_MeshNode*>::iterator it;
1903 // AddInverseElement to new nodes
1904 for ( int i = 0; i < nbnodes; i++ ) {
1905 it = oldNodes.find( nodes[i] );
1906 if ( it == oldNodes.end() )
1908 const_cast<SMDS_MeshNode*>( nodes[i] )->AddInverseElement( cell );
1910 // remove from oldNodes a node that remains in elem
1911 oldNodes.erase( it );
1913 // RemoveInverseElement from the nodes removed from elem
1914 for ( it = oldNodes.begin(); it != oldNodes.end(); it++ )
1916 SMDS_MeshNode * n = const_cast<SMDS_MeshNode *>( *it );
1917 n->RemoveInverseElement( cell );
1924 //=======================================================================
1925 //function : ChangePolyhedronNodes
1926 //purpose : to change nodes of polyhedral volume
1927 //=======================================================================
1928 bool SMDS_Mesh::ChangePolyhedronNodes (const SMDS_MeshElement * elem,
1929 const vector<const SMDS_MeshNode*>& nodes,
1930 const vector<int> & quantities)
1932 if (elem->GetType() != SMDSAbs_Volume) {
1933 MESSAGE("WRONG ELEM TYPE");
1937 const SMDS_VtkVolume* vol = dynamic_cast<const SMDS_VtkVolume*>(elem);
1942 // keep current nodes of elem
1943 set<const SMDS_MeshElement*> oldNodes;
1944 SMDS_ElemIteratorPtr itn = elem->nodesIterator();
1945 while (itn->more()) {
1946 oldNodes.insert(itn->next());
1950 // TODO remove this function
1951 //bool Ok = const_cast<SMDS_VtkVolume*>(vol)->ChangeNodes(nodes, quantities);
1957 // update InverseElements
1959 // AddInverseElement to new nodes
1960 int nbnodes = nodes.size();
1961 set<const SMDS_MeshElement*>::iterator it;
1962 for (int i = 0; i < nbnodes; i++) {
1963 it = oldNodes.find(nodes[i]);
1964 if (it == oldNodes.end()) {
1966 const_cast<SMDS_MeshNode*>(nodes[i])->AddInverseElement(elem);
1968 // remove from oldNodes a node that remains in elem
1973 // RemoveInverseElement from the nodes removed from elem
1974 for (it = oldNodes.begin(); it != oldNodes.end(); it++) {
1975 SMDS_MeshNode * n = static_cast<SMDS_MeshNode *>
1976 (const_cast<SMDS_MeshElement *>( *it ));
1977 n->RemoveInverseElement(elem);
1984 //=======================================================================
1985 //function : Find0DElement
1987 //=======================================================================
1988 const SMDS_Mesh0DElement* SMDS_Mesh::Find0DElement(int idnode) const
1990 const SMDS_MeshNode * node = FindNode(idnode);
1991 if(node == NULL) return NULL;
1992 return Find0DElement(node);
1995 const SMDS_Mesh0DElement* SMDS_Mesh::Find0DElement(const SMDS_MeshNode * node)
1997 if (!node) return 0;
1998 const SMDS_Mesh0DElement* toReturn = NULL;
1999 SMDS_ElemIteratorPtr it1 = node->GetInverseElementIterator(SMDSAbs_0DElement);
2000 while (it1->more() && (toReturn == NULL)) {
2001 const SMDS_MeshElement* e = it1->next();
2002 if (e->NbNodes() == 1) {
2003 toReturn = static_cast<const SMDS_Mesh0DElement*>(e);
2009 //=======================================================================
2010 //function : FindBall
2012 //=======================================================================
2014 const SMDS_BallElement* SMDS_Mesh::FindBall(int idnode) const
2016 const SMDS_MeshNode * node = FindNode(idnode);
2017 if(node == NULL) return NULL;
2018 return FindBall(node);
2021 const SMDS_BallElement* SMDS_Mesh::FindBall(const SMDS_MeshNode * node)
2023 if (!node) return 0;
2024 const SMDS_BallElement* toReturn = NULL;
2025 SMDS_ElemIteratorPtr it1 = node->GetInverseElementIterator(SMDSAbs_Ball);
2026 while (it1->more() && (toReturn == NULL)) {
2027 const SMDS_MeshElement* e = it1->next();
2028 if (e->GetGeomType() == SMDSGeom_BALL)
2029 toReturn = static_cast<const SMDS_BallElement*>(e);
2034 //=======================================================================
2035 //function : Find0DElementOrCreate
2037 //=======================================================================
2038 //SMDS_Mesh0DElement* SMDS_Mesh::Find0DElementOrCreate(const SMDS_MeshNode * node)
2040 // if (!node) return 0;
2041 // SMDS_Mesh0DElement * toReturn = NULL;
2042 // toReturn = const_cast<SMDS_Mesh0DElement*>(Find0DElement(node));
2043 // if (toReturn == NULL) {
2044 // //if (my0DElements.Extent() % CHECKMEMORY_INTERVAL == 0) CheckMemory();
2045 // toReturn = new SMDS_Mesh0DElement(node);
2046 // my0DElements.Add(toReturn);
2047 // myInfo.myNb0DElements++;
2053 //=======================================================================
2054 //function : FindEdge
2056 //=======================================================================
2058 const SMDS_MeshEdge* SMDS_Mesh::FindEdge(int idnode1, int idnode2) const
2060 const SMDS_MeshNode * node1=FindNode(idnode1);
2061 const SMDS_MeshNode * node2=FindNode(idnode2);
2062 if((node1==NULL)||(node2==NULL)) return NULL;
2063 return FindEdge(node1,node2);
2066 //#include "Profiler.h"
2067 const SMDS_MeshEdge* SMDS_Mesh::FindEdge(const SMDS_MeshNode * node1,
2068 const SMDS_MeshNode * node2)
2070 if ( !node1 ) return 0;
2071 const SMDS_MeshEdge * toReturn=NULL;
2074 SMDS_ElemIteratorPtr it1=node1->GetInverseElementIterator(SMDSAbs_Edge);
2077 while(it1->more()) {
2078 const SMDS_MeshElement * e = it1->next();
2079 if ( e->NbNodes() == 2 && e->GetNodeIndex( node2 ) >= 0 ) {
2080 toReturn = static_cast<const SMDS_MeshEdge*>( e );
2089 //=======================================================================
2090 //function : FindEdgeOrCreate
2092 //=======================================================================
2094 SMDS_MeshEdge* SMDS_Mesh::FindEdgeOrCreate(const SMDS_MeshNode * node1,
2095 const SMDS_MeshNode * node2)
2097 if ( !node1 || !node2) return 0;
2098 SMDS_MeshEdge * toReturn=NULL;
2099 toReturn=const_cast<SMDS_MeshEdge*>(FindEdge(node1,node2));
2100 if(toReturn==NULL) {
2101 if ( NbEdges() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
2102 int ID = myElementIDFactory->GetFreeID(); // -PR- voir si on range cet element
2103 adjustmyCellsCapacity(ID);
2104 vector<vtkIdType> nodeIds;
2106 nodeIds.push_back(node1->getVtkId());
2107 nodeIds.push_back(node2->getVtkId());
2109 SMDS_VtkEdge *edgevtk = myEdgePool->getNew();
2110 edgevtk->init(nodeIds, this);
2111 if (!this->registerElement(ID,edgevtk))
2113 this->myGrid->GetCellTypesArray()->SetValue(edgevtk->getVtkId(), VTK_EMPTY_CELL);
2114 myEdgePool->destroy(edgevtk);
2118 myCells[ID] = toReturn;
2125 //=======================================================================
2126 //function : FindEdge
2128 //=======================================================================
2130 const SMDS_MeshEdge* SMDS_Mesh::FindEdge(int idnode1, int idnode2,
2133 const SMDS_MeshNode * node1=FindNode(idnode1);
2134 const SMDS_MeshNode * node2=FindNode(idnode2);
2135 const SMDS_MeshNode * node3=FindNode(idnode3);
2136 return FindEdge(node1,node2,node3);
2139 const SMDS_MeshEdge* SMDS_Mesh::FindEdge(const SMDS_MeshNode * node1,
2140 const SMDS_MeshNode * node2,
2141 const SMDS_MeshNode * node3)
2143 if ( !node1 ) return 0;
2144 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Edge);
2145 while(it1->more()) {
2146 const SMDS_MeshElement * e = it1->next();
2147 if ( e->NbNodes() == 3 ) {
2148 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
2149 while(it2->more()) {
2150 const SMDS_MeshElement* n = it2->next();
2160 return static_cast<const SMDS_MeshEdge *> (e);
2167 //=======================================================================
2168 //function : FindFace
2170 //=======================================================================
2172 const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2,
2175 const SMDS_MeshNode * node1=FindNode(idnode1);
2176 const SMDS_MeshNode * node2=FindNode(idnode2);
2177 const SMDS_MeshNode * node3=FindNode(idnode3);
2178 return FindFace(node1, node2, node3);
2181 const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1,
2182 const SMDS_MeshNode *node2,
2183 const SMDS_MeshNode *node3)
2185 if ( !node1 ) return 0;
2186 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Face);
2187 while(it1->more()) {
2188 const SMDS_MeshElement * e = it1->next();
2189 if ( e->NbNodes() == 3 ) {
2190 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
2191 while(it2->more()) {
2192 const SMDS_MeshElement* n = it2->next();
2202 return static_cast<const SMDS_MeshFace *> (e);
2208 SMDS_MeshFace* SMDS_Mesh::FindFaceOrCreate(const SMDS_MeshNode *node1,
2209 const SMDS_MeshNode *node2,
2210 const SMDS_MeshNode *node3)
2212 SMDS_MeshFace * toReturn=NULL;
2213 toReturn = const_cast<SMDS_MeshFace*>(FindFace(node1,node2,node3));
2214 if(toReturn==NULL) {
2215 int ID = myElementIDFactory->GetFreeID();
2216 toReturn = createTriangle(node1,node2,node3, ID);
2222 //=======================================================================
2223 //function : FindFace
2225 //=======================================================================
2227 const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2,
2228 int idnode3, int idnode4) const
2230 const SMDS_MeshNode * node1=FindNode(idnode1);
2231 const SMDS_MeshNode * node2=FindNode(idnode2);
2232 const SMDS_MeshNode * node3=FindNode(idnode3);
2233 const SMDS_MeshNode * node4=FindNode(idnode4);
2234 return FindFace(node1, node2, node3, node4);
2237 const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1,
2238 const SMDS_MeshNode *node2,
2239 const SMDS_MeshNode *node3,
2240 const SMDS_MeshNode *node4)
2242 if ( !node1 ) return 0;
2243 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Face);
2244 while(it1->more()) {
2245 const SMDS_MeshElement * e = it1->next();
2246 if ( e->NbNodes() == 4 ) {
2247 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
2248 while(it2->more()) {
2249 const SMDS_MeshElement* n = it2->next();
2260 return static_cast<const SMDS_MeshFace *> (e);
2266 SMDS_MeshFace* SMDS_Mesh::FindFaceOrCreate(const SMDS_MeshNode *node1,
2267 const SMDS_MeshNode *node2,
2268 const SMDS_MeshNode *node3,
2269 const SMDS_MeshNode *node4)
2271 SMDS_MeshFace * toReturn=NULL;
2272 toReturn=const_cast<SMDS_MeshFace*>(FindFace(node1,node2,node3,node4));
2273 if(toReturn==NULL) {
2274 int ID = myElementIDFactory->GetFreeID();
2275 toReturn=createQuadrangle(node1,node2,node3,node4,ID);
2281 //=======================================================================
2282 //function : FindFace
2283 //purpose :quadratic triangle
2284 //=======================================================================
2286 const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2,
2287 int idnode3, int idnode4,
2288 int idnode5, int idnode6) const
2290 const SMDS_MeshNode * node1 = FindNode(idnode1);
2291 const SMDS_MeshNode * node2 = FindNode(idnode2);
2292 const SMDS_MeshNode * node3 = FindNode(idnode3);
2293 const SMDS_MeshNode * node4 = FindNode(idnode4);
2294 const SMDS_MeshNode * node5 = FindNode(idnode5);
2295 const SMDS_MeshNode * node6 = FindNode(idnode6);
2296 return FindFace(node1, node2, node3, node4, node5, node6);
2299 const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1,
2300 const SMDS_MeshNode *node2,
2301 const SMDS_MeshNode *node3,
2302 const SMDS_MeshNode *node4,
2303 const SMDS_MeshNode *node5,
2304 const SMDS_MeshNode *node6)
2306 if ( !node1 ) return 0;
2307 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Face);
2308 while(it1->more()) {
2309 const SMDS_MeshElement * e = it1->next();
2310 if ( e->NbNodes() == 6 ) {
2311 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
2312 while(it2->more()) {
2313 const SMDS_MeshElement* n = it2->next();
2326 return static_cast<const SMDS_MeshFace *> (e);
2333 //=======================================================================
2334 //function : FindFace
2335 //purpose : quadratic quadrangle
2336 //=======================================================================
2338 const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2,
2339 int idnode3, int idnode4,
2340 int idnode5, int idnode6,
2341 int idnode7, int idnode8) const
2343 const SMDS_MeshNode * node1 = FindNode(idnode1);
2344 const SMDS_MeshNode * node2 = FindNode(idnode2);
2345 const SMDS_MeshNode * node3 = FindNode(idnode3);
2346 const SMDS_MeshNode * node4 = FindNode(idnode4);
2347 const SMDS_MeshNode * node5 = FindNode(idnode5);
2348 const SMDS_MeshNode * node6 = FindNode(idnode6);
2349 const SMDS_MeshNode * node7 = FindNode(idnode7);
2350 const SMDS_MeshNode * node8 = FindNode(idnode8);
2351 return FindFace(node1, node2, node3, node4, node5, node6, node7, node8);
2354 const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1,
2355 const SMDS_MeshNode *node2,
2356 const SMDS_MeshNode *node3,
2357 const SMDS_MeshNode *node4,
2358 const SMDS_MeshNode *node5,
2359 const SMDS_MeshNode *node6,
2360 const SMDS_MeshNode *node7,
2361 const SMDS_MeshNode *node8)
2363 if ( !node1 ) return 0;
2364 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Face);
2365 while(it1->more()) {
2366 const SMDS_MeshElement * e = it1->next();
2367 if ( e->NbNodes() == 8 ) {
2368 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
2369 while(it2->more()) {
2370 const SMDS_MeshElement* n = it2->next();
2385 return static_cast<const SMDS_MeshFace *> (e);
2392 //=======================================================================
2393 //function : FindElement
2395 //=======================================================================
2397 const SMDS_MeshElement* SMDS_Mesh::FindElement(int IDelem) const
2399 if ((IDelem <= 0) || IDelem >= myCells.size())
2401 MESSAGE("--------------------------------------------------------------------------------- ");
2402 MESSAGE("----------------------------------- bad IDelem " << IDelem << " " << myCells.size());
2403 MESSAGE("--------------------------------------------------------------------------------- ");
2404 // TODO raise an exception
2408 return myCells[IDelem];
2411 //=======================================================================
2412 //function : FindFace
2413 //purpose : find polygon
2414 //=======================================================================
2416 const SMDS_MeshFace* SMDS_Mesh::FindFace (const vector<int>& nodes_ids) const
2418 int nbnodes = nodes_ids.size();
2419 vector<const SMDS_MeshNode *> poly_nodes (nbnodes);
2420 for (int inode = 0; inode < nbnodes; inode++) {
2421 const SMDS_MeshNode * node = FindNode(nodes_ids[inode]);
2422 if (node == NULL) return NULL;
2423 poly_nodes[inode] = node;
2425 return FindFace(poly_nodes);
2428 const SMDS_MeshFace* SMDS_Mesh::FindFace (const vector<const SMDS_MeshNode *>& nodes)
2430 return (const SMDS_MeshFace*) FindElement( nodes, SMDSAbs_Face );
2434 //================================================================================
2436 * \brief Return element based on all given nodes
2437 * \param nodes - node of element
2438 * \param type - type of element
2439 * \param noMedium - true if medium nodes of quadratic element are not included in <nodes>
2440 * \retval const SMDS_MeshElement* - found element or NULL
2442 //================================================================================
2444 const SMDS_MeshElement* SMDS_Mesh::FindElement (const vector<const SMDS_MeshNode *>& nodes,
2445 const SMDSAbs_ElementType type,
2446 const bool noMedium)
2448 if ( nodes.size() > 0 && nodes[0] )
2450 SMDS_ElemIteratorPtr itF = nodes[0]->GetInverseElementIterator(type);
2453 const SMDS_MeshElement* e = itF->next();
2454 int nbNodesToCheck = noMedium ? e->NbCornerNodes() : e->NbNodes();
2455 if ( nbNodesToCheck == nodes.size() )
2457 for ( int i = 1; e && i < nodes.size(); ++ i )
2459 int nodeIndex = e->GetNodeIndex( nodes[ i ]);
2460 if ( nodeIndex < 0 || nodeIndex >= nbNodesToCheck )
2471 //=======================================================================
2472 //function : DumpNodes
2474 //=======================================================================
2476 void SMDS_Mesh::DumpNodes() const
2478 MESSAGE("dump nodes of mesh : ");
2479 SMDS_NodeIteratorPtr itnode=nodesIterator();
2480 while(itnode->more()) ; //MESSAGE(itnode->next());
2483 //=======================================================================
2484 //function : Dump0DElements
2486 //=======================================================================
2487 void SMDS_Mesh::Dump0DElements() const
2489 MESSAGE("dump 0D elements of mesh : ");
2490 SMDS_ElemIteratorPtr it0d = elementsIterator(SMDSAbs_0DElement);
2491 while(it0d->more()) ; //MESSAGE(it0d->next());
2494 //=======================================================================
2495 //function : DumpEdges
2497 //=======================================================================
2499 void SMDS_Mesh::DumpEdges() const
2501 MESSAGE("dump edges of mesh : ");
2502 SMDS_EdgeIteratorPtr itedge=edgesIterator();
2503 while(itedge->more()) ; //MESSAGE(itedge->next());
2506 //=======================================================================
2507 //function : DumpFaces
2509 //=======================================================================
2511 void SMDS_Mesh::DumpFaces() const
2513 MESSAGE("dump faces of mesh : ");
2514 SMDS_FaceIteratorPtr itface=facesIterator();
2515 while(itface->more()) ; //MESSAGE(itface->next());
2518 //=======================================================================
2519 //function : DumpVolumes
2521 //=======================================================================
2523 void SMDS_Mesh::DumpVolumes() const
2525 MESSAGE("dump volumes of mesh : ");
2526 SMDS_VolumeIteratorPtr itvol=volumesIterator();
2527 while(itvol->more()) ; //MESSAGE(itvol->next());
2530 //=======================================================================
2531 //function : DebugStats
2533 //=======================================================================
2535 void SMDS_Mesh::DebugStats() const
2537 MESSAGE("Debug stats of mesh : ");
2539 MESSAGE("===== NODES ====="<<NbNodes());
2540 MESSAGE("===== 0DELEMS ====="<<Nb0DElements());
2541 MESSAGE("===== EDGES ====="<<NbEdges());
2542 MESSAGE("===== FACES ====="<<NbFaces());
2543 MESSAGE("===== VOLUMES ====="<<NbVolumes());
2545 MESSAGE("End Debug stats of mesh ");
2549 SMDS_NodeIteratorPtr itnode=nodesIterator();
2550 int sizeofnodes = 0;
2551 int sizeoffaces = 0;
2553 while(itnode->more())
2555 const SMDS_MeshNode *node = itnode->next();
2557 sizeofnodes += sizeof(*node);
2559 SMDS_ElemIteratorPtr it = node->GetInverseElementIterator();
2562 const SMDS_MeshElement *me = it->next();
2563 sizeofnodes += sizeof(me);
2567 SMDS_FaceIteratorPtr itface=facesIterator();
2568 while(itface->more())
2570 const SMDS_MeshElement *face = itface->next();
2571 sizeoffaces += sizeof(*face);
2574 MESSAGE("total size of node elements = " << sizeofnodes);;
2575 MESSAGE("total size of face elements = " << sizeoffaces);;
2580 ///////////////////////////////////////////////////////////////////////////////
2581 /// Return the number of nodes
2582 ///////////////////////////////////////////////////////////////////////////////
2583 int SMDS_Mesh::NbNodes() const
2585 //MESSAGE(myGrid->GetNumberOfPoints());
2586 //MESSAGE(myInfo.NbNodes());
2587 //MESSAGE(myNodeMax);
2588 return myInfo.NbNodes();
2591 ///////////////////////////////////////////////////////////////////////////////
2592 /// Return the number of 0D elements
2593 ///////////////////////////////////////////////////////////////////////////////
2594 int SMDS_Mesh::Nb0DElements() const
2596 return myInfo.Nb0DElements();
2599 ///////////////////////////////////////////////////////////////////////////////
2600 /// Return the number of 0D elements
2601 ///////////////////////////////////////////////////////////////////////////////
2602 int SMDS_Mesh::NbBalls() const
2604 return myInfo.NbBalls();
2607 ///////////////////////////////////////////////////////////////////////////////
2608 /// Return the number of edges (including construction edges)
2609 ///////////////////////////////////////////////////////////////////////////////
2610 int SMDS_Mesh::NbEdges() const
2612 return myInfo.NbEdges();
2615 ///////////////////////////////////////////////////////////////////////////////
2616 /// Return the number of faces (including construction faces)
2617 ///////////////////////////////////////////////////////////////////////////////
2618 int SMDS_Mesh::NbFaces() const
2620 return myInfo.NbFaces();
2623 ///////////////////////////////////////////////////////////////////////////////
2624 /// Return the number of volumes
2625 ///////////////////////////////////////////////////////////////////////////////
2626 int SMDS_Mesh::NbVolumes() const
2628 return myInfo.NbVolumes();
2631 ///////////////////////////////////////////////////////////////////////////////
2632 /// Return the number of child mesh of this mesh.
2633 /// Note that the tree structure of SMDS_Mesh is unused in SMESH
2634 ///////////////////////////////////////////////////////////////////////////////
2635 int SMDS_Mesh::NbSubMesh() const
2637 return myChildren.size();
2640 ///////////////////////////////////////////////////////////////////////////////
2641 /// Destroy the mesh and all its elements
2642 /// All pointer on elements owned by this mesh become illegals.
2643 ///////////////////////////////////////////////////////////////////////////////
2644 SMDS_Mesh::~SMDS_Mesh()
2646 list<SMDS_Mesh*>::iterator itc=myChildren.begin();
2647 while(itc!=myChildren.end())
2655 delete myNodeIDFactory;
2656 delete myElementIDFactory;
2660 SMDS_ElemIteratorPtr eIt = elementsIterator();
2661 while ( eIt->more() )
2663 const SMDS_MeshElement *elem = eIt->next();
2664 myElementIDFactory->ReleaseID(elem->GetID(), elem->getVtkId());
2666 SMDS_NodeIteratorPtr itn = nodesIterator();
2669 const SMDS_MeshNode *node = itn->next();
2670 ((SMDS_MeshNode*)node)->SetPosition(SMDS_SpacePosition::originSpacePosition());
2671 myNodeIDFactory->ReleaseID(node->GetID(), node->getVtkId());
2677 delete myVolumePool;
2683 //================================================================================
2685 * \brief Clear all data
2687 //================================================================================
2689 void SMDS_Mesh::Clear()
2691 MESSAGE("SMDS_Mesh::Clear");
2694 SMDS_ElemIteratorPtr eIt = elementsIterator();
2695 while ( eIt->more() )
2697 const SMDS_MeshElement *elem = eIt->next();
2698 myElementIDFactory->ReleaseID(elem->GetID(), elem->getVtkId());
2700 SMDS_NodeIteratorPtr itn = nodesIterator();
2703 const SMDS_MeshNode *node = itn->next();
2704 myNodeIDFactory->ReleaseID(node->GetID(), node->getVtkId());
2709 myNodeIDFactory->Clear();
2710 myElementIDFactory->Clear();
2713 // SMDS_ElemIteratorPtr itv = elementsIterator();
2714 // while (itv->more())
2716 // SMDS_MeshElement* elem = (SMDS_MeshElement*)(itv->next());
2717 // SMDSAbs_ElementType aType = elem->GetType();
2720 // case SMDSAbs_0DElement:
2723 // case SMDSAbs_Edge:
2724 // myEdgePool->destroy(static_cast<SMDS_VtkEdge*>(elem));
2726 // case SMDSAbs_Face:
2727 // myFacePool->destroy(static_cast<SMDS_VtkFace*>(elem));
2729 // case SMDSAbs_Volume:
2730 // myVolumePool->destroy(static_cast<SMDS_VtkVolume*>(elem));
2732 // case SMDSAbs_Ball:
2733 // myBallPool->destroy(static_cast<SMDS_BallElement*>(elem));
2739 myVolumePool->clear();
2740 myFacePool->clear();
2741 myEdgePool->clear();
2742 myBallPool->clear();
2744 clearVector( myCells );
2745 clearVector( myCellIdVtkToSmds );
2747 SMDS_NodeIteratorPtr itn = nodesIterator();
2750 SMDS_MeshNode *node = (SMDS_MeshNode*)(itn->next());
2751 node->SetPosition(SMDS_SpacePosition::originSpacePosition());
2752 //myNodePool->destroy(node);
2754 myNodePool->clear();
2755 clearVector( myNodes );
2757 list<SMDS_Mesh*>::iterator itc=myChildren.begin();
2758 while(itc!=myChildren.end())
2769 myGrid->Initialize();
2771 vtkPoints* points = vtkPoints::New();
2772 // rnv: to fix bug "21125: EDF 1233 SMESH: Degrardation of precision in a test case for quadratic conversion"
2773 // using double type for storing coordinates of nodes instead float.
2774 points->SetDataType(VTK_DOUBLE);
2775 points->SetNumberOfPoints(0 /*SMDS_Mesh::chunkSize*/);
2776 myGrid->SetPoints( points );
2778 myGrid->BuildLinks();
2781 ///////////////////////////////////////////////////////////////////////////////
2782 /// Return true if this mesh create faces with edges.
2783 /// A false returned value mean that faces are created with nodes. A concequence
2784 /// is, iteration on edges (SMDS_Element::edgesIterator) will be unavailable.
2785 ///////////////////////////////////////////////////////////////////////////////
2786 bool SMDS_Mesh::hasConstructionEdges()
2788 return myHasConstructionEdges;
2791 ///////////////////////////////////////////////////////////////////////////////
2792 /// Return true if this mesh create volumes with faces
2793 /// A false returned value mean that volumes are created with nodes or edges.
2794 /// (see hasConstructionEdges)
2795 /// A concequence is, iteration on faces (SMDS_Element::facesIterator) will be
2797 ///////////////////////////////////////////////////////////////////////////////
2798 bool SMDS_Mesh::hasConstructionFaces()
2800 return myHasConstructionFaces;
2803 ///////////////////////////////////////////////////////////////////////////////
2804 /// Return true if nodes are linked to the finit elements, they are belonging to.
2805 /// Currently, It always return true.
2806 ///////////////////////////////////////////////////////////////////////////////
2807 bool SMDS_Mesh::hasInverseElements()
2809 return myHasInverseElements;
2812 ///////////////////////////////////////////////////////////////////////////////
2813 /// Make this mesh creating construction edges (see hasConstructionEdges)
2814 /// @param b true to have construction edges, else false.
2815 ///////////////////////////////////////////////////////////////////////////////
2816 void SMDS_Mesh::setConstructionEdges(bool b)
2818 myHasConstructionEdges=b;
2821 ///////////////////////////////////////////////////////////////////////////////
2822 /// Make this mesh creating construction faces (see hasConstructionFaces)
2823 /// @param b true to have construction faces, else false.
2824 ///////////////////////////////////////////////////////////////////////////////
2825 void SMDS_Mesh::setConstructionFaces(bool b)
2827 myHasConstructionFaces=b;
2830 ///////////////////////////////////////////////////////////////////////////////
2831 /// Make this mesh creating link from nodes to elements (see hasInverseElements)
2832 /// @param b true to link nodes to elements, else false.
2833 ///////////////////////////////////////////////////////////////////////////////
2834 void SMDS_Mesh::setInverseElements(bool b)
2836 if(!b) MESSAGE("Error : inverseElement=false not implemented");
2837 myHasInverseElements=b;
2842 //================================================================================
2844 * \brief Iterator on elements in id increasing order
2846 //================================================================================
2848 template <typename ELEM=const SMDS_MeshElement*>
2849 class IdSortedIterator : public SMDS_Iterator<ELEM>
2851 SMDS_MeshElementIDFactory& myIDFact;
2852 int myID, myMaxID, myNbFound, myTotalNb;
2853 SMDSAbs_ElementType myType;
2857 IdSortedIterator(const SMDS_MeshElementIDFactory& fact,
2858 const SMDSAbs_ElementType type, // SMDSAbs_All NOT allowed!!!
2861 myID(1), myMaxID( myIDFact.GetMaxID() ),myNbFound(0), myTotalNb( totalNb ),
2873 ELEM current = myElem;
2875 for ( myElem = 0; !myElem && myNbFound < myTotalNb && myID <= myMaxID; ++myID )
2876 if ((myElem = (ELEM) myIDFact.MeshElement( myID ))
2877 && myElem->GetType() != myType )
2880 myNbFound += bool(myElem);
2886 //================================================================================
2888 * \brief Iterator on vector of elements, possibly being resized while iteration
2890 //================================================================================
2892 template<typename RETURN_VALUE,
2893 typename VECTOR_VALUE=SMDS_MeshCell*,
2894 typename VALUE_FILTER=SMDS::NonNullFilter<VECTOR_VALUE> >
2895 class ElemVecIterator: public SMDS_Iterator<RETURN_VALUE>
2897 const std::vector<VECTOR_VALUE>& _vector;
2900 VALUE_FILTER _filter;
2902 ElemVecIterator(const std::vector<VECTOR_VALUE>& vec,
2903 const VALUE_FILTER& filter=VALUE_FILTER() )
2904 :_vector( vec ), _index(0), _more( !vec.empty() ), _filter( filter )
2906 if ( _more && !_filter( _vector[ _index ]))
2913 virtual RETURN_VALUE next()
2915 if ( !_more ) return NULL;
2916 VECTOR_VALUE current = _vector[ _index ];
2918 while ( !_more && ++_index < _vector.size() )
2919 _more = _filter( _vector[ _index ]);
2920 return (RETURN_VALUE) current;
2925 ///////////////////////////////////////////////////////////////////////////////
2926 /// Return an iterator on nodes of the current mesh factory
2927 ///////////////////////////////////////////////////////////////////////////////
2929 SMDS_NodeIteratorPtr SMDS_Mesh::nodesIterator(bool idInceasingOrder) const
2931 // naturally always sorted by ID
2932 typedef ElemVecIterator<const SMDS_MeshNode*, SMDS_MeshNode*> TIterator;
2933 return SMDS_NodeIteratorPtr( new TIterator(myNodes));
2936 SMDS_ElemIteratorPtr SMDS_Mesh::elementGeomIterator(SMDSAbs_GeometryType type) const
2938 // naturally always sorted by ID
2939 typedef ElemVecIterator
2940 < const SMDS_MeshElement*, SMDS_MeshCell*, SMDS_MeshElement::GeomFilter > TIterator;
2941 return SMDS_ElemIteratorPtr
2942 (new TIterator(myCells, SMDS_MeshElement::GeomFilter( type )));
2945 SMDS_ElemIteratorPtr SMDS_Mesh::elementEntityIterator(SMDSAbs_EntityType type) const
2947 if ( type == SMDSEntity_Node )
2949 typedef ElemVecIterator<const SMDS_MeshElement*, SMDS_MeshNode*> TIterator;
2950 return SMDS_ElemIteratorPtr( new TIterator(myNodes));
2952 // naturally always sorted by ID
2953 typedef ElemVecIterator
2954 < const SMDS_MeshElement*, SMDS_MeshCell*, SMDS_MeshElement::EntityFilter > TIterator;
2955 return SMDS_ElemIteratorPtr
2956 (new TIterator(myCells, SMDS_MeshElement::EntityFilter( type )));
2959 ///////////////////////////////////////////////////////////////////////////////
2960 /// Return an iterator on elements of the current mesh factory
2961 ///////////////////////////////////////////////////////////////////////////////
2962 SMDS_ElemIteratorPtr SMDS_Mesh::elementsIterator(SMDSAbs_ElementType type) const
2964 // naturally always sorted by ID
2968 return SMDS_ElemIteratorPtr (new ElemVecIterator<const SMDS_MeshElement*>(myCells));
2971 return SMDS_ElemIteratorPtr
2972 ( new ElemVecIterator<const SMDS_MeshElement*, SMDS_MeshNode*>( myNodes ));
2975 typedef ElemVecIterator
2976 < const SMDS_MeshElement*, SMDS_MeshCell*, SMDS_MeshElement::TypeFilter > TIterator;
2977 return SMDS_ElemIteratorPtr (new TIterator(myCells, SMDS_MeshElement::TypeFilter( type )));
2979 return SMDS_ElemIteratorPtr();
2982 ///////////////////////////////////////////////////////////////////////////////
2983 ///Return an iterator on edges of the current mesh.
2984 ///////////////////////////////////////////////////////////////////////////////
2986 SMDS_EdgeIteratorPtr SMDS_Mesh::edgesIterator(bool idInceasingOrder) const
2988 // naturally always sorted by ID
2989 typedef ElemVecIterator
2990 < const SMDS_MeshEdge*, SMDS_MeshCell*, SMDS_MeshElement::TypeFilter > TIterator;
2991 return SMDS_EdgeIteratorPtr
2992 (new TIterator(myCells, SMDS_MeshElement::TypeFilter( SMDSAbs_Edge )));
2995 ///////////////////////////////////////////////////////////////////////////////
2996 ///Return an iterator on faces of the current mesh.
2997 ///////////////////////////////////////////////////////////////////////////////
2999 SMDS_FaceIteratorPtr SMDS_Mesh::facesIterator(bool idInceasingOrder) const
3001 // naturally always sorted by ID
3002 typedef ElemVecIterator
3003 < const SMDS_MeshFace*, SMDS_MeshCell*, SMDS_MeshElement::TypeFilter > TIterator;
3004 return SMDS_FaceIteratorPtr
3005 (new TIterator(myCells, SMDS_MeshElement::TypeFilter( SMDSAbs_Face )));
3008 ///////////////////////////////////////////////////////////////////////////////
3009 ///Return an iterator on volumes of the current mesh.
3010 ///////////////////////////////////////////////////////////////////////////////
3012 SMDS_VolumeIteratorPtr SMDS_Mesh::volumesIterator(bool idInceasingOrder) const
3014 // naturally always sorted by ID
3015 typedef ElemVecIterator
3016 < const SMDS_MeshVolume*, SMDS_MeshCell*, SMDS_MeshElement::TypeFilter > TIterator;
3017 return SMDS_VolumeIteratorPtr
3018 (new TIterator(myCells, SMDS_MeshElement::TypeFilter( SMDSAbs_Volume )));
3021 ///////////////////////////////////////////////////////////////////////////////
3022 /// Do intersection of sets (more than 2)
3023 ///////////////////////////////////////////////////////////////////////////////
3024 static set<const SMDS_MeshElement*> * intersectionOfSets(
3025 set<const SMDS_MeshElement*> vs[], int numberOfSets)
3027 set<const SMDS_MeshElement*>* rsetA=new set<const SMDS_MeshElement*>(vs[0]);
3028 set<const SMDS_MeshElement*>* rsetB;
3030 for(int i=0; i<numberOfSets-1; i++)
3032 rsetB=new set<const SMDS_MeshElement*>();
3034 rsetA->begin(), rsetA->end(),
3035 vs[i+1].begin(), vs[i+1].end(),
3036 inserter(*rsetB, rsetB->begin()));
3043 ///////////////////////////////////////////////////////////////////////////////
3044 /// Return the list of finite elements owning the given element: elements
3045 /// containing all the nodes of the given element, for instance faces and
3046 /// volumes containing a given edge.
3047 ///////////////////////////////////////////////////////////////////////////////
3048 static set<const SMDS_MeshElement*> * getFinitElements(const SMDS_MeshElement * element)
3050 int numberOfSets=element->NbNodes();
3051 set<const SMDS_MeshElement*> *initSet = new set<const SMDS_MeshElement*>[numberOfSets];
3053 SMDS_ElemIteratorPtr itNodes=element->nodesIterator();
3056 while(itNodes->more())
3058 const SMDS_MeshElement* node = itNodes->next();
3060 const SMDS_MeshNode * n=static_cast<const SMDS_MeshNode*>(node);
3061 SMDS_ElemIteratorPtr itFe = n->GetInverseElementIterator();
3063 //initSet[i]=set<const SMDS_MeshElement*>();
3066 const SMDS_MeshElement* elem = itFe->next();
3068 initSet[i].insert(elem);
3074 set<const SMDS_MeshElement*> *retSet=intersectionOfSets(initSet, numberOfSets);
3075 // MESSAGE("nb elems " << i << " intersection " << retSet->size());
3080 ///////////////////////////////////////////////////////////////////////////////
3081 /// Return the list of nodes used only by the given elements
3082 ///////////////////////////////////////////////////////////////////////////////
3083 static set<const SMDS_MeshElement*> * getExclusiveNodes(
3084 set<const SMDS_MeshElement*>& elements)
3086 set<const SMDS_MeshElement*> * toReturn=new set<const SMDS_MeshElement*>();
3087 set<const SMDS_MeshElement*>::iterator itElements=elements.begin();
3089 while(itElements!=elements.end())
3091 SMDS_ElemIteratorPtr itNodes = (*itElements)->nodesIterator();
3094 while(itNodes->more())
3096 const SMDS_MeshNode * n=static_cast<const SMDS_MeshNode*>(itNodes->next());
3097 SMDS_ElemIteratorPtr itFe = n->GetInverseElementIterator();
3098 set<const SMDS_MeshElement*> s;
3100 s.insert(itFe->next());
3101 if(s==elements) toReturn->insert(n);
3107 ///////////////////////////////////////////////////////////////////////////////
3108 ///Find the children of an element that are made of given nodes
3109 ///@param setOfChildren The set in which matching children will be inserted
3110 ///@param element The element were to search matching children
3111 ///@param nodes The nodes that the children must have to be selected
3112 ///////////////////////////////////////////////////////////////////////////////
3113 void SMDS_Mesh::addChildrenWithNodes(set<const SMDS_MeshElement*>& setOfChildren,
3114 const SMDS_MeshElement * element,
3115 set<const SMDS_MeshElement*>& nodes)
3117 switch(element->GetType())
3120 MESSAGE("Internal Error: This should not happen");
3122 case SMDSAbs_0DElement:
3128 SMDS_ElemIteratorPtr itn=element->nodesIterator();
3131 const SMDS_MeshElement * e=itn->next();
3132 if(nodes.find(e)!=nodes.end())
3134 setOfChildren.insert(element);
3141 SMDS_ElemIteratorPtr itn=element->nodesIterator();
3144 const SMDS_MeshElement * e=itn->next();
3145 if(nodes.find(e)!=nodes.end())
3147 setOfChildren.insert(element);
3151 if(hasConstructionEdges())
3153 SMDS_ElemIteratorPtr ite=element->edgesIterator();
3155 addChildrenWithNodes(setOfChildren, ite->next(), nodes);
3158 case SMDSAbs_Volume:
3160 if(hasConstructionFaces())
3162 SMDS_ElemIteratorPtr ite=element->facesIterator();
3164 addChildrenWithNodes(setOfChildren, ite->next(), nodes);
3166 else if(hasConstructionEdges())
3168 SMDS_ElemIteratorPtr ite=element->edgesIterator();
3170 addChildrenWithNodes(setOfChildren, ite->next(), nodes);
3176 ///////////////////////////////////////////////////////////////////////////////
3177 ///@param elem The element to delete
3178 ///@param removenodes if true remaining nodes will be removed
3179 ///////////////////////////////////////////////////////////////////////////////
3180 void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem,
3181 const bool removenodes)
3183 list<const SMDS_MeshElement *> removedElems;
3184 list<const SMDS_MeshElement *> removedNodes;
3185 RemoveElement( elem, removedElems, removedNodes, removenodes );
3188 ///////////////////////////////////////////////////////////////////////////////
3189 ///@param elem The element to delete
3190 ///@param removedElems to be filled with all removed elements
3191 ///@param removedNodes to be filled with all removed nodes
3192 ///@param removenodes if true remaining nodes will be removed
3193 ///////////////////////////////////////////////////////////////////////////////
3194 void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem,
3195 list<const SMDS_MeshElement *>& removedElems,
3196 list<const SMDS_MeshElement *>& removedNodes,
3199 //MESSAGE("SMDS_Mesh::RemoveElement " << elem->getVtkId() << " " << removenodes);
3200 // get finite elements built on elem
3201 set<const SMDS_MeshElement*> * s1;
3202 if ( (elem->GetType() == SMDSAbs_0DElement)
3203 || ((elem->GetType() == SMDSAbs_Edge) && !hasConstructionEdges())
3204 || ((elem->GetType() == SMDSAbs_Face) && !hasConstructionFaces())
3205 || (elem->GetType() == SMDSAbs_Volume) )
3207 s1 = new set<const SMDS_MeshElement*> ();
3211 s1 = getFinitElements(elem);
3213 // get exclusive nodes (which would become free afterwards)
3214 set<const SMDS_MeshElement*> * s2;
3215 if (elem->GetType() == SMDSAbs_Node) // a node is removed
3217 // do not remove nodes except elem
3218 s2 = new set<const SMDS_MeshElement*> ();
3223 s2 = getExclusiveNodes(*s1);
3225 // form the set of finite and construction elements to remove
3226 set<const SMDS_MeshElement*> s3;
3227 set<const SMDS_MeshElement*>::iterator it = s1->begin();
3228 while (it != s1->end())
3230 addChildrenWithNodes(s3, *it, *s2);
3234 if (elem->GetType() != SMDSAbs_Node)
3237 // remove finite and construction elements
3239 while (it != s3.end())
3241 // Remove element from <InverseElements> of its nodes
3242 SMDS_ElemIteratorPtr itn = (*it)->nodesIterator();
3245 SMDS_MeshNode * n = static_cast<SMDS_MeshNode *> (const_cast<SMDS_MeshElement *> (itn->next()));
3246 n->RemoveInverseElement((*it));
3248 int IdToRemove = (*it)->GetID();
3249 int vtkid = (*it)->getVtkId();
3250 //MESSAGE("elem Id to remove " << IdToRemove << " vtkid " << vtkid <<
3251 // " vtktype " << (*it)->GetVtkType() << " type " << (*it)->GetType());
3252 switch ((*it)->GetType())
3255 MYASSERT("Internal Error: This should not happen")
3258 case SMDSAbs_0DElement:
3259 if (IdToRemove >= 0)
3261 myCells[IdToRemove] = 0; // -PR- ici ou dans myElementIDFactory->ReleaseID ?
3264 removedElems.push_back((*it));
3265 myElementIDFactory->ReleaseID(IdToRemove, vtkid);
3269 if (IdToRemove >= 0)
3271 myCells[IdToRemove] = 0;
3272 myInfo.RemoveEdge(*it);
3274 removedElems.push_back((*it));
3275 myElementIDFactory->ReleaseID(IdToRemove, vtkid);
3276 if (const SMDS_VtkEdge* vtkElem = dynamic_cast<const SMDS_VtkEdge*>(*it))
3277 myEdgePool->destroy((SMDS_VtkEdge*) vtkElem);
3282 if (IdToRemove >= 0)
3284 myCells[IdToRemove] = 0;
3285 myInfo.RemoveFace(*it);
3287 removedElems.push_back((*it));
3288 myElementIDFactory->ReleaseID(IdToRemove, vtkid);
3289 if (const SMDS_VtkFace* vtkElem = dynamic_cast<const SMDS_VtkFace*>(*it))
3290 myFacePool->destroy((SMDS_VtkFace*) vtkElem);
3294 case SMDSAbs_Volume:
3295 if (IdToRemove >= 0)
3297 myCells[IdToRemove] = 0;
3298 myInfo.RemoveVolume(*it);
3300 removedElems.push_back((*it));
3301 myElementIDFactory->ReleaseID(IdToRemove, vtkid);
3302 if (const SMDS_VtkVolume* vtkElem = dynamic_cast<const SMDS_VtkVolume*>(*it))
3303 myVolumePool->destroy((SMDS_VtkVolume*) vtkElem);
3308 if (IdToRemove >= 0)
3310 myCells[IdToRemove] = 0;
3313 removedElems.push_back((*it));
3314 myElementIDFactory->ReleaseID(IdToRemove, vtkid);
3315 if (const SMDS_BallElement* vtkElem = dynamic_cast<const SMDS_BallElement*>(*it))
3316 myBallPool->destroy(const_cast<SMDS_BallElement*>( vtkElem ));
3323 //MESSAGE("VTK_EMPTY_CELL in " << vtkid);
3324 this->myGrid->GetCellTypesArray()->SetValue(vtkid, VTK_EMPTY_CELL);
3329 // remove exclusive (free) nodes
3333 while (it != s2->end())
3335 int IdToRemove = (*it)->GetID();
3336 //MESSAGE( "SMDS: RM node " << IdToRemove);
3337 if (IdToRemove >= 0)
3339 myNodes[IdToRemove] = 0;
3342 myNodeIDFactory->ReleaseID((*it)->GetID(), (*it)->getVtkId());
3343 removedNodes.push_back((*it));
3344 if (const SMDS_MeshNode* vtkElem = dynamic_cast<const SMDS_MeshNode*>(*it))
3346 ((SMDS_MeshNode*)vtkElem)->SetPosition(SMDS_SpacePosition::originSpacePosition());
3347 myNodePool->destroy((SMDS_MeshNode*) vtkElem);
3360 ///////////////////////////////////////////////////////////////////////////////
3361 ///@param elem The element to delete
3362 ///////////////////////////////////////////////////////////////////////////////
3363 void SMDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elem)
3365 int elemId = elem->GetID();
3366 int vtkId = elem->getVtkId();
3367 //MESSAGE("RemoveFreeElement " << elemId);
3368 SMDSAbs_ElementType aType = elem->GetType();
3369 SMDS_MeshElement* todest = (SMDS_MeshElement*)(elem);
3370 if (aType == SMDSAbs_Node) {
3371 //MESSAGE("Remove free node " << elemId);
3372 // only free node can be removed by this method
3373 const SMDS_MeshNode* n = static_cast<SMDS_MeshNode*>(todest);
3374 SMDS_ElemIteratorPtr itFe = n->GetInverseElementIterator();
3375 if (!itFe->more()) { // free node
3376 myNodes[elemId] = 0;
3378 ((SMDS_MeshNode*) n)->SetPosition(SMDS_SpacePosition::originSpacePosition());
3379 ((SMDS_MeshNode*) n)->SMDS_MeshElement::init( -1, -1, -1 ); // avoid reuse
3380 myNodePool->destroy(static_cast<SMDS_MeshNode*>(todest));
3381 myNodeIDFactory->ReleaseID(elemId, vtkId);
3384 if (hasConstructionEdges() || hasConstructionFaces())
3385 // this methods is only for meshes without descendants
3388 //MESSAGE("Remove free element " << elemId);
3389 // Remove element from <InverseElements> of its nodes
3390 SMDS_ElemIteratorPtr itn = elem->nodesIterator();
3391 while (itn->more()) {
3392 SMDS_MeshNode * n = static_cast<SMDS_MeshNode *>
3393 (const_cast<SMDS_MeshElement *>(itn->next()));
3394 n->RemoveInverseElement(elem);
3397 // in meshes without descendants elements are always free
3399 case SMDSAbs_0DElement:
3400 myCells[elemId] = 0;
3401 myInfo.remove(elem);
3405 myCells[elemId] = 0;
3406 myInfo.RemoveEdge(elem);
3407 myEdgePool->destroy(static_cast<SMDS_VtkEdge*>(todest));
3410 myCells[elemId] = 0;
3411 myInfo.RemoveFace(elem);
3412 myFacePool->destroy(static_cast<SMDS_VtkFace*>(todest));
3414 case SMDSAbs_Volume:
3415 myCells[elemId] = 0;
3416 myInfo.RemoveVolume(elem);
3417 myVolumePool->destroy(static_cast<SMDS_VtkVolume*>(todest));
3420 myCells[elemId] = 0;
3421 myInfo.remove(elem);
3422 myBallPool->destroy(static_cast<SMDS_BallElement*>(todest));
3427 myElementIDFactory->ReleaseID(elemId, vtkId);
3429 this->myGrid->GetCellTypesArray()->SetValue(vtkId, VTK_EMPTY_CELL);
3430 // --- to do: keep vtkid in a list of reusable cells
3435 * Checks if the element is present in mesh.
3436 * Useful to determine dead pointers.
3438 bool SMDS_Mesh::Contains (const SMDS_MeshElement* elem) const
3440 // we should not imply on validity of *elem, so iterate on containers
3441 // of all types in the hope of finding <elem> somewhere there
3442 SMDS_NodeIteratorPtr itn = nodesIterator();
3444 if (elem == itn->next())
3446 SMDS_ElemIteratorPtr ite = elementsIterator();
3448 if (elem == ite->next())
3453 //=======================================================================
3454 //function : MaxNodeID
3456 //=======================================================================
3458 int SMDS_Mesh::MaxNodeID() const
3463 //=======================================================================
3464 //function : MinNodeID
3466 //=======================================================================
3468 int SMDS_Mesh::MinNodeID() const
3473 //=======================================================================
3474 //function : MaxElementID
3476 //=======================================================================
3478 int SMDS_Mesh::MaxElementID() const
3480 return myElementIDFactory->GetMaxID();
3483 //=======================================================================
3484 //function : MinElementID
3486 //=======================================================================
3488 int SMDS_Mesh::MinElementID() const
3490 return myElementIDFactory->GetMinID();
3493 //=======================================================================
3494 //function : Renumber
3495 //purpose : Renumber all nodes or elements.
3496 //=======================================================================
3498 void SMDS_Mesh::Renumber (const bool isNodes, const int startID, const int deltaID)
3500 MESSAGE("Renumber");
3504 SMDS_MeshNodeIDFactory * idFactory =
3505 isNodes ? myNodeIDFactory : myElementIDFactory;
3507 // get existing elements in the order of ID increasing
3508 map<int,SMDS_MeshElement*> elemMap;
3509 SMDS_ElemIteratorPtr idElemIt = idFactory->elementsIterator();
3510 while ( idElemIt->more() ) {
3511 SMDS_MeshElement* elem = const_cast<SMDS_MeshElement*>(idElemIt->next());
3512 int id = elem->GetID();
3513 elemMap.insert(map<int,SMDS_MeshElement*>::value_type(id, elem));
3515 // release their ids
3516 map<int,SMDS_MeshElement*>::iterator elemIt = elemMap.begin();
3518 // for ( ; elemIt != elemMap.end(); elemIt++ )
3520 // int id = (*elemIt).first;
3521 // idFactory->ReleaseID( id );
3525 elemIt = elemMap.begin();
3526 for ( ; elemIt != elemMap.end(); elemIt++ )
3528 idFactory->BindID( ID, (*elemIt).second );
3533 //=======================================================================
3534 //function : GetElementType
3535 //purpose : Return type of element or node with id
3536 //=======================================================================
3538 SMDSAbs_ElementType SMDS_Mesh::GetElementType( const int id, const bool iselem ) const
3540 SMDS_MeshElement* elem = 0;
3542 elem = myElementIDFactory->MeshElement( id );
3544 elem = myNodeIDFactory->MeshElement( id );
3548 //throw SALOME_Exception(LOCALIZED ("this element isn't exist"));
3552 return elem->GetType();
3557 //********************************************************************
3558 //********************************************************************
3559 //******** *********
3560 //***** Methods for addition of quadratic elements ******
3561 //******** *********
3562 //********************************************************************
3563 //********************************************************************
3565 //=======================================================================
3566 //function : AddEdgeWithID
3568 //=======================================================================
3569 SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(int n1, int n2, int n12, int ID)
3571 return SMDS_Mesh::AddEdgeWithID
3572 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1),
3573 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2),
3574 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
3578 //=======================================================================
3579 //function : AddEdge
3581 //=======================================================================
3582 SMDS_MeshEdge* SMDS_Mesh::AddEdge(const SMDS_MeshNode* n1,
3583 const SMDS_MeshNode* n2,
3584 const SMDS_MeshNode* n12)
3586 return SMDS_Mesh::AddEdgeWithID(n1, n2, n12, myElementIDFactory->GetFreeID());
3589 //=======================================================================
3590 //function : AddEdgeWithID
3592 //=======================================================================
3593 SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
3594 const SMDS_MeshNode * n2,
3595 const SMDS_MeshNode * n12,
3598 if ( !n1 || !n2 || !n12 ) return 0;
3600 // --- retrieve nodes ID
3601 vector<vtkIdType> nodeIds;
3603 nodeIds.push_back(n1->getVtkId());
3604 nodeIds.push_back(n2->getVtkId());
3605 nodeIds.push_back(n12->getVtkId());
3607 SMDS_MeshEdge * edge = 0;
3608 SMDS_VtkEdge *edgevtk = myEdgePool->getNew();
3609 edgevtk->init(nodeIds, this);
3610 if (!this->registerElement(ID,edgevtk))
3612 this->myGrid->GetCellTypesArray()->SetValue(edgevtk->getVtkId(), VTK_EMPTY_CELL);
3613 myEdgePool->destroy(edgevtk);
3617 adjustmyCellsCapacity(ID);
3619 myInfo.myNbQuadEdges++;
3621 // if (!registerElement(ID, edge)) {
3622 // RemoveElement(edge, false);
3630 //=======================================================================
3631 //function : AddFace
3633 //=======================================================================
3634 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
3635 const SMDS_MeshNode * n2,
3636 const SMDS_MeshNode * n3,
3637 const SMDS_MeshNode * n12,
3638 const SMDS_MeshNode * n23,
3639 const SMDS_MeshNode * n31)
3641 return SMDS_Mesh::AddFaceWithID(n1,n2,n3,n12,n23,n31,
3642 myElementIDFactory->GetFreeID());
3645 //=======================================================================
3646 //function : AddFaceWithID
3648 //=======================================================================
3649 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int n1, int n2, int n3,
3650 int n12,int n23,int n31, int ID)
3652 return SMDS_Mesh::AddFaceWithID
3653 ((SMDS_MeshNode *)myNodeIDFactory->MeshElement(n1) ,
3654 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n2) ,
3655 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n3) ,
3656 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n12),
3657 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n23),
3658 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n31),
3662 //=======================================================================
3663 //function : AddFaceWithID
3665 //=======================================================================
3666 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
3667 const SMDS_MeshNode * n2,
3668 const SMDS_MeshNode * n3,
3669 const SMDS_MeshNode * n12,
3670 const SMDS_MeshNode * n23,
3671 const SMDS_MeshNode * n31,
3674 if ( !n1 || !n2 || !n3 || !n12 || !n23 || !n31) return 0;
3675 if(hasConstructionEdges()) {
3676 // creation quadratic edges - not implemented
3681 // --- retrieve nodes ID
3682 vector<vtkIdType> nodeIds;
3684 nodeIds.push_back(n1->getVtkId());
3685 nodeIds.push_back(n2->getVtkId());
3686 nodeIds.push_back(n3->getVtkId());
3687 nodeIds.push_back(n12->getVtkId());
3688 nodeIds.push_back(n23->getVtkId());
3689 nodeIds.push_back(n31->getVtkId());
3691 SMDS_MeshFace * face = 0;
3692 SMDS_VtkFace *facevtk = myFacePool->getNew();
3693 facevtk->init(nodeIds, this);
3694 if (!this->registerElement(ID,facevtk))
3696 this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL);
3697 myFacePool->destroy(facevtk);
3701 adjustmyCellsCapacity(ID);
3703 myInfo.myNbQuadTriangles++;
3705 // if (!registerElement(ID, face)) {
3706 // RemoveElement(face, false);
3714 //=======================================================================
3715 //function : AddFace
3717 //=======================================================================
3718 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
3719 const SMDS_MeshNode * n2,
3720 const SMDS_MeshNode * n3,
3721 const SMDS_MeshNode * n12,
3722 const SMDS_MeshNode * n23,
3723 const SMDS_MeshNode * n31,
3724 const SMDS_MeshNode * nCenter)
3726 return SMDS_Mesh::AddFaceWithID(n1,n2,n3,n12,n23,n31,nCenter,
3727 myElementIDFactory->GetFreeID());
3730 //=======================================================================
3731 //function : AddFaceWithID
3733 //=======================================================================
3734 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int n1, int n2, int n3,
3735 int n12,int n23,int n31, int nCenter, int ID)
3737 return SMDS_Mesh::AddFaceWithID
3738 ((SMDS_MeshNode *)myNodeIDFactory->MeshElement(n1) ,
3739 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n2) ,
3740 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n3) ,
3741 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n12),
3742 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n23),
3743 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n31),
3744 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nCenter),
3748 //=======================================================================
3749 //function : AddFaceWithID
3751 //=======================================================================
3752 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
3753 const SMDS_MeshNode * n2,
3754 const SMDS_MeshNode * n3,
3755 const SMDS_MeshNode * n12,
3756 const SMDS_MeshNode * n23,
3757 const SMDS_MeshNode * n31,
3758 const SMDS_MeshNode * nCenter,
3761 if ( !n1 || !n2 || !n3 || !n12 || !n23 || !n31 || !nCenter) return 0;
3762 if(hasConstructionEdges()) {
3763 // creation quadratic edges - not implemented
3768 // --- retrieve nodes ID
3769 vector<vtkIdType> nodeIds;
3771 nodeIds.push_back(n1->getVtkId());
3772 nodeIds.push_back(n2->getVtkId());
3773 nodeIds.push_back(n3->getVtkId());
3774 nodeIds.push_back(n12->getVtkId());
3775 nodeIds.push_back(n23->getVtkId());
3776 nodeIds.push_back(n31->getVtkId());
3777 nodeIds.push_back(nCenter->getVtkId());
3779 SMDS_MeshFace * face = 0;
3780 SMDS_VtkFace *facevtk = myFacePool->getNew();
3781 facevtk->init(nodeIds, this);
3782 if (!this->registerElement(ID,facevtk))
3784 this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL);
3785 myFacePool->destroy(facevtk);
3789 adjustmyCellsCapacity(ID);
3791 myInfo.myNbBiQuadTriangles++;
3793 // if (!registerElement(ID, face)) {
3794 // RemoveElement(face, false);
3802 //=======================================================================
3803 //function : AddFace
3805 //=======================================================================
3806 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
3807 const SMDS_MeshNode * n2,
3808 const SMDS_MeshNode * n3,
3809 const SMDS_MeshNode * n4,
3810 const SMDS_MeshNode * n12,
3811 const SMDS_MeshNode * n23,
3812 const SMDS_MeshNode * n34,
3813 const SMDS_MeshNode * n41)
3815 return SMDS_Mesh::AddFaceWithID(n1,n2,n3,n4,n12,n23,n34,n41,
3816 myElementIDFactory->GetFreeID());
3819 //=======================================================================
3820 //function : AddFaceWithID
3822 //=======================================================================
3823 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int n4,
3824 int n12,int n23,int n34,int n41, int ID)
3826 return SMDS_Mesh::AddFaceWithID
3827 ((SMDS_MeshNode *)myNodeIDFactory->MeshElement(n1) ,
3828 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n2) ,
3829 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n3) ,
3830 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n4) ,
3831 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n12),
3832 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n23),
3833 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n34),
3834 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n41),
3838 //=======================================================================
3839 //function : AddFaceWithID
3841 //=======================================================================
3842 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
3843 const SMDS_MeshNode * n2,
3844 const SMDS_MeshNode * n3,
3845 const SMDS_MeshNode * n4,
3846 const SMDS_MeshNode * n12,
3847 const SMDS_MeshNode * n23,
3848 const SMDS_MeshNode * n34,
3849 const SMDS_MeshNode * n41,
3852 if ( !n1 || !n2 || !n3 || !n4 || !n12 || !n23 || !n34 || !n41) return 0;
3853 if(hasConstructionEdges()) {
3854 // creation quadratic edges - not implemented
3859 // --- retrieve nodes ID
3860 vector<vtkIdType> nodeIds;
3862 nodeIds.push_back(n1->getVtkId());
3863 nodeIds.push_back(n2->getVtkId());
3864 nodeIds.push_back(n3->getVtkId());
3865 nodeIds.push_back(n4->getVtkId());
3866 nodeIds.push_back(n12->getVtkId());
3867 nodeIds.push_back(n23->getVtkId());
3868 nodeIds.push_back(n34->getVtkId());
3869 nodeIds.push_back(n41->getVtkId());
3871 SMDS_MeshFace * face = 0;
3872 SMDS_VtkFace *facevtk = myFacePool->getNew();
3873 facevtk->init(nodeIds, this);
3874 if (!this->registerElement(ID,facevtk))
3876 this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL);
3877 myFacePool->destroy(facevtk);
3881 adjustmyCellsCapacity(ID);
3883 myInfo.myNbQuadQuadrangles++;
3885 // if (!registerElement(ID, face)) {
3886 // RemoveElement(face, false);
3893 //=======================================================================
3894 //function : AddFace
3896 //=======================================================================
3897 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
3898 const SMDS_MeshNode * n2,
3899 const SMDS_MeshNode * n3,
3900 const SMDS_MeshNode * n4,
3901 const SMDS_MeshNode * n12,
3902 const SMDS_MeshNode * n23,
3903 const SMDS_MeshNode * n34,
3904 const SMDS_MeshNode * n41,
3905 const SMDS_MeshNode * nCenter)
3907 return SMDS_Mesh::AddFaceWithID(n1,n2,n3,n4,n12,n23,n34,n41,nCenter,
3908 myElementIDFactory->GetFreeID());
3911 //=======================================================================
3912 //function : AddFaceWithID
3914 //=======================================================================
3915 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int n4,
3916 int n12,int n23,int n34,int n41, int nCenter, int ID)
3918 return SMDS_Mesh::AddFaceWithID
3919 ((SMDS_MeshNode *)myNodeIDFactory->MeshElement(n1) ,
3920 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n2) ,
3921 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n3) ,
3922 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n4) ,
3923 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n12),
3924 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n23),
3925 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n34),
3926 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n41),
3927 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nCenter),
3931 //=======================================================================
3932 //function : AddFaceWithID
3934 //=======================================================================
3935 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
3936 const SMDS_MeshNode * n2,
3937 const SMDS_MeshNode * n3,
3938 const SMDS_MeshNode * n4,
3939 const SMDS_MeshNode * n12,
3940 const SMDS_MeshNode * n23,
3941 const SMDS_MeshNode * n34,
3942 const SMDS_MeshNode * n41,
3943 const SMDS_MeshNode * nCenter,
3946 if ( !n1 || !n2 || !n3 || !n4 || !n12 || !n23 || !n34 || !n41 || !nCenter) return 0;
3947 if(hasConstructionEdges()) {
3948 // creation quadratic edges - not implemented
3953 // --- retrieve nodes ID
3954 vector<vtkIdType> nodeIds;
3956 nodeIds.push_back(n1->getVtkId());
3957 nodeIds.push_back(n2->getVtkId());
3958 nodeIds.push_back(n3->getVtkId());
3959 nodeIds.push_back(n4->getVtkId());
3960 nodeIds.push_back(n12->getVtkId());
3961 nodeIds.push_back(n23->getVtkId());
3962 nodeIds.push_back(n34->getVtkId());
3963 nodeIds.push_back(n41->getVtkId());
3964 nodeIds.push_back(nCenter->getVtkId());
3966 SMDS_MeshFace * face = 0;
3967 SMDS_VtkFace *facevtk = myFacePool->getNew();
3968 facevtk->init(nodeIds, this);
3969 if (!this->registerElement(ID,facevtk))
3971 this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL);
3972 myFacePool->destroy(facevtk);
3976 adjustmyCellsCapacity(ID);
3978 myInfo.myNbBiQuadQuadrangles++;
3980 // if (!registerElement(ID, face)) {
3981 // RemoveElement(face, false);
3989 //=======================================================================
3990 //function : AddVolume
3992 //=======================================================================
3993 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
3994 const SMDS_MeshNode * n2,
3995 const SMDS_MeshNode * n3,
3996 const SMDS_MeshNode * n4,
3997 const SMDS_MeshNode * n12,
3998 const SMDS_MeshNode * n23,
3999 const SMDS_MeshNode * n31,
4000 const SMDS_MeshNode * n14,
4001 const SMDS_MeshNode * n24,
4002 const SMDS_MeshNode * n34)
4004 int ID = myElementIDFactory->GetFreeID();
4005 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n12, n23,
4006 n31, n14, n24, n34, ID);
4007 if(v==NULL) myElementIDFactory->ReleaseID(ID);
4011 //=======================================================================
4012 //function : AddVolumeWithID
4014 //=======================================================================
4015 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4,
4016 int n12,int n23,int n31,
4017 int n14,int n24,int n34, int ID)
4019 return SMDS_Mesh::AddVolumeWithID
4020 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1) ,
4021 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2) ,
4022 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3) ,
4023 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4) ,
4024 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
4025 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
4026 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n31),
4027 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n14),
4028 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n24),
4029 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n34),
4033 //=======================================================================
4034 //function : AddVolumeWithID
4035 //purpose : 2d order tetrahedron of 10 nodes
4036 //=======================================================================
4037 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
4038 const SMDS_MeshNode * n2,
4039 const SMDS_MeshNode * n3,
4040 const SMDS_MeshNode * n4,
4041 const SMDS_MeshNode * n12,
4042 const SMDS_MeshNode * n23,
4043 const SMDS_MeshNode * n31,
4044 const SMDS_MeshNode * n14,
4045 const SMDS_MeshNode * n24,
4046 const SMDS_MeshNode * n34,
4049 if ( !n1 || !n2 || !n3 || !n4 || !n12 || !n23 || !n31 || !n14 || !n24 || !n34)
4051 if(hasConstructionFaces()) {
4052 // creation quadratic faces - not implemented
4055 // --- retrieve nodes ID
4056 vector<vtkIdType> nodeIds;
4058 nodeIds.push_back(n1->getVtkId());
4059 nodeIds.push_back(n3->getVtkId());
4060 nodeIds.push_back(n2->getVtkId());
4061 nodeIds.push_back(n4->getVtkId());
4063 nodeIds.push_back(n31->getVtkId());
4064 nodeIds.push_back(n23->getVtkId());
4065 nodeIds.push_back(n12->getVtkId());
4067 nodeIds.push_back(n14->getVtkId());
4068 nodeIds.push_back(n34->getVtkId());
4069 nodeIds.push_back(n24->getVtkId());
4071 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
4072 volvtk->init(nodeIds, this);
4073 if (!this->registerElement(ID,volvtk))
4075 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
4076 myVolumePool->destroy(volvtk);
4079 adjustmyCellsCapacity(ID);
4080 myCells[ID] = volvtk;
4081 myInfo.myNbQuadTetras++;
4083 // if (!registerElement(ID, volvtk)) {
4084 // RemoveElement(volvtk, false);
4091 //=======================================================================
4092 //function : AddVolume
4094 //=======================================================================
4095 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
4096 const SMDS_MeshNode * n2,
4097 const SMDS_MeshNode * n3,
4098 const SMDS_MeshNode * n4,
4099 const SMDS_MeshNode * n5,
4100 const SMDS_MeshNode * n12,
4101 const SMDS_MeshNode * n23,
4102 const SMDS_MeshNode * n34,
4103 const SMDS_MeshNode * n41,
4104 const SMDS_MeshNode * n15,
4105 const SMDS_MeshNode * n25,
4106 const SMDS_MeshNode * n35,
4107 const SMDS_MeshNode * n45)
4109 int ID = myElementIDFactory->GetFreeID();
4110 SMDS_MeshVolume * v =
4111 SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n12, n23, n34, n41,
4112 n15, n25, n35, n45, ID);
4113 if(v==NULL) myElementIDFactory->ReleaseID(ID);
4117 //=======================================================================
4118 //function : AddVolumeWithID
4120 //=======================================================================
4121 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5,
4122 int n12,int n23,int n34,int n41,
4123 int n15,int n25,int n35,int n45, int ID)
4125 return SMDS_Mesh::AddVolumeWithID
4126 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1) ,
4127 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2) ,
4128 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3) ,
4129 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4) ,
4130 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5) ,
4131 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
4132 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
4133 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n34),
4134 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n41),
4135 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n15),
4136 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n25),
4137 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n35),
4138 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n45),
4142 //=======================================================================
4143 //function : AddVolumeWithID
4144 //purpose : 2d order pyramid of 13 nodes
4145 //=======================================================================
4146 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
4147 const SMDS_MeshNode * n2,
4148 const SMDS_MeshNode * n3,
4149 const SMDS_MeshNode * n4,
4150 const SMDS_MeshNode * n5,
4151 const SMDS_MeshNode * n12,
4152 const SMDS_MeshNode * n23,
4153 const SMDS_MeshNode * n34,
4154 const SMDS_MeshNode * n41,
4155 const SMDS_MeshNode * n15,
4156 const SMDS_MeshNode * n25,
4157 const SMDS_MeshNode * n35,
4158 const SMDS_MeshNode * n45,
4161 if (!n1 || !n2 || !n3 || !n4 || !n5 || !n12 || !n23 ||
4162 !n34 || !n41 || !n15 || !n25 || !n35 || !n45)
4164 if(hasConstructionFaces()) {
4165 // creation quadratic faces - not implemented
4168 // --- retrieve nodes ID
4169 vector<vtkIdType> nodeIds;
4171 nodeIds.push_back(n1->getVtkId());
4172 nodeIds.push_back(n4->getVtkId());
4173 nodeIds.push_back(n3->getVtkId());
4174 nodeIds.push_back(n2->getVtkId());
4175 nodeIds.push_back(n5->getVtkId());
4177 nodeIds.push_back(n41->getVtkId());
4178 nodeIds.push_back(n34->getVtkId());
4179 nodeIds.push_back(n23->getVtkId());
4180 nodeIds.push_back(n12->getVtkId());
4182 nodeIds.push_back(n15->getVtkId());
4183 nodeIds.push_back(n45->getVtkId());
4184 nodeIds.push_back(n35->getVtkId());
4185 nodeIds.push_back(n25->getVtkId());
4187 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
4188 volvtk->init(nodeIds, this);
4189 if (!this->registerElement(ID,volvtk))
4191 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
4192 myVolumePool->destroy(volvtk);
4195 adjustmyCellsCapacity(ID);
4196 myCells[ID] = volvtk;
4197 myInfo.myNbQuadPyramids++;
4199 // if (!registerElement(ID, volvtk)) {
4200 // RemoveElement(volvtk, false);
4207 //=======================================================================
4208 //function : AddVolume
4210 //=======================================================================
4211 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
4212 const SMDS_MeshNode * n2,
4213 const SMDS_MeshNode * n3,
4214 const SMDS_MeshNode * n4,
4215 const SMDS_MeshNode * n5,
4216 const SMDS_MeshNode * n6,
4217 const SMDS_MeshNode * n12,
4218 const SMDS_MeshNode * n23,
4219 const SMDS_MeshNode * n31,
4220 const SMDS_MeshNode * n45,
4221 const SMDS_MeshNode * n56,
4222 const SMDS_MeshNode * n64,
4223 const SMDS_MeshNode * n14,
4224 const SMDS_MeshNode * n25,
4225 const SMDS_MeshNode * n36)
4227 int ID = myElementIDFactory->GetFreeID();
4228 SMDS_MeshVolume * v =
4229 SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n12, n23, n31,
4230 n45, n56, n64, n14, n25, n36, ID);
4231 if(v==NULL) myElementIDFactory->ReleaseID(ID);
4235 //=======================================================================
4236 //function : AddVolumeWithID
4238 //=======================================================================
4239 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3,
4240 int n4, int n5, int n6,
4241 int n12,int n23,int n31,
4242 int n45,int n56,int n64,
4243 int n14,int n25,int n36, int ID)
4245 return SMDS_Mesh::AddVolumeWithID
4246 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1) ,
4247 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2) ,
4248 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3) ,
4249 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4) ,
4250 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5) ,
4251 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n6) ,
4252 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
4253 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
4254 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n31),
4255 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n45),
4256 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n56),
4257 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n64),
4258 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n14),
4259 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n25),
4260 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n36),
4264 //=======================================================================
4265 //function : AddVolumeWithID
4266 //purpose : 2d order Pentahedron with 15 nodes
4267 //=======================================================================
4268 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
4269 const SMDS_MeshNode * n2,
4270 const SMDS_MeshNode * n3,
4271 const SMDS_MeshNode * n4,
4272 const SMDS_MeshNode * n5,
4273 const SMDS_MeshNode * n6,
4274 const SMDS_MeshNode * n12,
4275 const SMDS_MeshNode * n23,
4276 const SMDS_MeshNode * n31,
4277 const SMDS_MeshNode * n45,
4278 const SMDS_MeshNode * n56,
4279 const SMDS_MeshNode * n64,
4280 const SMDS_MeshNode * n14,
4281 const SMDS_MeshNode * n25,
4282 const SMDS_MeshNode * n36,
4285 if (!n1 || !n2 || !n3 || !n4 || !n5 || !n6 || !n12 || !n23 ||
4286 !n31 || !n45 || !n56 || !n64 || !n14 || !n25 || !n36)
4288 if(hasConstructionFaces()) {
4289 // creation quadratic faces - not implemented
4292 // --- retrieve nodes ID
4293 vector<vtkIdType> nodeIds;
4295 nodeIds.push_back(n1->getVtkId());
4296 nodeIds.push_back(n2->getVtkId());
4297 nodeIds.push_back(n3->getVtkId());
4299 nodeIds.push_back(n4->getVtkId());
4300 nodeIds.push_back(n5->getVtkId());
4301 nodeIds.push_back(n6->getVtkId());
4303 nodeIds.push_back(n12->getVtkId());
4304 nodeIds.push_back(n23->getVtkId());
4305 nodeIds.push_back(n31->getVtkId());
4307 nodeIds.push_back(n45->getVtkId());
4308 nodeIds.push_back(n56->getVtkId());
4309 nodeIds.push_back(n64->getVtkId());
4311 nodeIds.push_back(n14->getVtkId());
4312 nodeIds.push_back(n25->getVtkId());
4313 nodeIds.push_back(n36->getVtkId());
4315 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
4316 volvtk->init(nodeIds, this);
4317 if (!this->registerElement(ID,volvtk))
4319 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
4320 myVolumePool->destroy(volvtk);
4323 adjustmyCellsCapacity(ID);
4324 myCells[ID] = volvtk;
4325 myInfo.myNbQuadPrisms++;
4327 // if (!registerElement(ID, volvtk)) {
4328 // RemoveElement(volvtk, false);
4335 //=======================================================================
4336 //function : AddVolume
4338 //=======================================================================
4339 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
4340 const SMDS_MeshNode * n2,
4341 const SMDS_MeshNode * n3,
4342 const SMDS_MeshNode * n4,
4343 const SMDS_MeshNode * n5,
4344 const SMDS_MeshNode * n6,
4345 const SMDS_MeshNode * n7,
4346 const SMDS_MeshNode * n8,
4347 const SMDS_MeshNode * n12,
4348 const SMDS_MeshNode * n23,
4349 const SMDS_MeshNode * n34,
4350 const SMDS_MeshNode * n41,
4351 const SMDS_MeshNode * n56,
4352 const SMDS_MeshNode * n67,
4353 const SMDS_MeshNode * n78,
4354 const SMDS_MeshNode * n85,
4355 const SMDS_MeshNode * n15,
4356 const SMDS_MeshNode * n26,
4357 const SMDS_MeshNode * n37,
4358 const SMDS_MeshNode * n48)
4360 int ID = myElementIDFactory->GetFreeID();
4361 SMDS_MeshVolume * v =
4362 SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, n12, n23, n34, n41,
4363 n56, n67, n78, n85, n15, n26, n37, n48, ID);
4364 if(v==NULL) myElementIDFactory->ReleaseID(ID);
4368 //=======================================================================
4369 //function : AddVolumeWithID
4371 //=======================================================================
4372 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4,
4373 int n5, int n6, int n7, int n8,
4374 int n12,int n23,int n34,int n41,
4375 int n56,int n67,int n78,int n85,
4376 int n15,int n26,int n37,int n48, int ID)
4378 return SMDS_Mesh::AddVolumeWithID
4379 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1),
4380 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2),
4381 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3),
4382 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4),
4383 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5),
4384 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n6),
4385 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n7),
4386 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n8),
4387 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
4388 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
4389 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n34),
4390 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n41),
4391 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n56),
4392 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n67),
4393 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n78),
4394 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n85),
4395 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n15),
4396 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n26),
4397 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n37),
4398 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n48),
4402 //=======================================================================
4403 //function : AddVolumeWithID
4404 //purpose : 2d order Hexahedrons with 20 nodes
4405 //=======================================================================
4406 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
4407 const SMDS_MeshNode * n2,
4408 const SMDS_MeshNode * n3,
4409 const SMDS_MeshNode * n4,
4410 const SMDS_MeshNode * n5,
4411 const SMDS_MeshNode * n6,
4412 const SMDS_MeshNode * n7,
4413 const SMDS_MeshNode * n8,
4414 const SMDS_MeshNode * n12,
4415 const SMDS_MeshNode * n23,
4416 const SMDS_MeshNode * n34,
4417 const SMDS_MeshNode * n41,
4418 const SMDS_MeshNode * n56,
4419 const SMDS_MeshNode * n67,
4420 const SMDS_MeshNode * n78,
4421 const SMDS_MeshNode * n85,
4422 const SMDS_MeshNode * n15,
4423 const SMDS_MeshNode * n26,
4424 const SMDS_MeshNode * n37,
4425 const SMDS_MeshNode * n48,
4428 if (!n1 || !n2 || !n3 || !n4 || !n5 || !n6 || !n7 || !n8 || !n12 || !n23 ||
4429 !n34 || !n41 || !n56 || !n67 || !n78 || !n85 || !n15 || !n26 || !n37 || !n48)
4431 if(hasConstructionFaces()) {
4433 // creation quadratic faces - not implemented
4435 // --- retrieve nodes ID
4436 vector<vtkIdType> nodeIds;
4438 nodeIds.push_back(n1->getVtkId());
4439 nodeIds.push_back(n4->getVtkId());
4440 nodeIds.push_back(n3->getVtkId());
4441 nodeIds.push_back(n2->getVtkId());
4443 nodeIds.push_back(n5->getVtkId());
4444 nodeIds.push_back(n8->getVtkId());
4445 nodeIds.push_back(n7->getVtkId());
4446 nodeIds.push_back(n6->getVtkId());
4448 nodeIds.push_back(n41->getVtkId());
4449 nodeIds.push_back(n34->getVtkId());
4450 nodeIds.push_back(n23->getVtkId());
4451 nodeIds.push_back(n12->getVtkId());
4453 nodeIds.push_back(n85->getVtkId());
4454 nodeIds.push_back(n78->getVtkId());
4455 nodeIds.push_back(n67->getVtkId());
4456 nodeIds.push_back(n56->getVtkId());
4458 nodeIds.push_back(n15->getVtkId());
4459 nodeIds.push_back(n48->getVtkId());
4460 nodeIds.push_back(n37->getVtkId());
4461 nodeIds.push_back(n26->getVtkId());
4463 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
4464 volvtk->init(nodeIds, this);
4465 if (!this->registerElement(ID,volvtk))
4467 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
4468 myVolumePool->destroy(volvtk);
4471 adjustmyCellsCapacity(ID);
4472 myCells[ID] = volvtk;
4473 myInfo.myNbQuadHexas++;
4475 // if (!registerElement(ID, volvtk)) {
4476 // RemoveElement(volvtk, false);
4482 //=======================================================================
4483 //function : AddVolume
4485 //=======================================================================
4486 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
4487 const SMDS_MeshNode * n2,
4488 const SMDS_MeshNode * n3,
4489 const SMDS_MeshNode * n4,
4490 const SMDS_MeshNode * n5,
4491 const SMDS_MeshNode * n6,
4492 const SMDS_MeshNode * n7,
4493 const SMDS_MeshNode * n8,
4494 const SMDS_MeshNode * n12,
4495 const SMDS_MeshNode * n23,
4496 const SMDS_MeshNode * n34,
4497 const SMDS_MeshNode * n41,
4498 const SMDS_MeshNode * n56,
4499 const SMDS_MeshNode * n67,
4500 const SMDS_MeshNode * n78,
4501 const SMDS_MeshNode * n85,
4502 const SMDS_MeshNode * n15,
4503 const SMDS_MeshNode * n26,
4504 const SMDS_MeshNode * n37,
4505 const SMDS_MeshNode * n48,
4506 const SMDS_MeshNode * n1234,
4507 const SMDS_MeshNode * n1256,
4508 const SMDS_MeshNode * n2367,
4509 const SMDS_MeshNode * n3478,
4510 const SMDS_MeshNode * n1458,
4511 const SMDS_MeshNode * n5678,
4512 const SMDS_MeshNode * nCenter)
4514 int ID = myElementIDFactory->GetFreeID();
4515 SMDS_MeshVolume * v =
4516 SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, n12, n23, n34, n41,
4517 n56, n67, n78, n85, n15, n26, n37, n48,
4518 n1234, n1256, n2367, n3478, n1458, n5678, nCenter,
4520 if(v==NULL) myElementIDFactory->ReleaseID(ID);
4524 //=======================================================================
4525 //function : AddVolumeWithID
4527 //=======================================================================
4528 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4,
4529 int n5, int n6, int n7, int n8,
4530 int n12,int n23,int n34,int n41,
4531 int n56,int n67,int n78,int n85,
4532 int n15,int n26,int n37,int n48,
4533 int n1234,int n1256,int n2367,int n3478,
4534 int n1458,int n5678,int nCenter, int ID)
4536 return SMDS_Mesh::AddVolumeWithID
4537 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1),
4538 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2),
4539 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3),
4540 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4),
4541 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5),
4542 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n6),
4543 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n7),
4544 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n8),
4545 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
4546 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
4547 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n34),
4548 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n41),
4549 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n56),
4550 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n67),
4551 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n78),
4552 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n85),
4553 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n15),
4554 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n26),
4555 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n37),
4556 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n48),
4557 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1234),
4558 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1256),
4559 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2367),
4560 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3478),
4561 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1458),
4562 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5678),
4563 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(nCenter),
4567 //=======================================================================
4568 //function : AddVolumeWithID
4569 //purpose : 2d order Hexahedrons with 20 nodes
4570 //=======================================================================
4571 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
4572 const SMDS_MeshNode * n2,
4573 const SMDS_MeshNode * n3,
4574 const SMDS_MeshNode * n4,
4575 const SMDS_MeshNode * n5,
4576 const SMDS_MeshNode * n6,
4577 const SMDS_MeshNode * n7,
4578 const SMDS_MeshNode * n8,
4579 const SMDS_MeshNode * n12,
4580 const SMDS_MeshNode * n23,
4581 const SMDS_MeshNode * n34,
4582 const SMDS_MeshNode * n41,
4583 const SMDS_MeshNode * n56,
4584 const SMDS_MeshNode * n67,
4585 const SMDS_MeshNode * n78,
4586 const SMDS_MeshNode * n85,
4587 const SMDS_MeshNode * n15,
4588 const SMDS_MeshNode * n26,
4589 const SMDS_MeshNode * n37,
4590 const SMDS_MeshNode * n48,
4591 const SMDS_MeshNode * n1234,
4592 const SMDS_MeshNode * n1256,
4593 const SMDS_MeshNode * n2367,
4594 const SMDS_MeshNode * n3478,
4595 const SMDS_MeshNode * n1458,
4596 const SMDS_MeshNode * n5678,
4597 const SMDS_MeshNode * nCenter,
4600 if (!n1 || !n2 || !n3 || !n4 || !n5 || !n6 || !n7 || !n8 || !n12 || !n23 ||
4601 !n34 || !n41 || !n56 || !n67 || !n78 || !n85 || !n15 || !n26 || !n37 || !n48 ||
4602 !n1234 || !n1256 || !n2367 || !n3478 || !n1458 || !n5678 || !nCenter )
4604 if(hasConstructionFaces()) {
4606 // creation quadratic faces - not implemented
4608 // --- retrieve nodes ID
4609 vector<vtkIdType> nodeIds;
4611 nodeIds.push_back(n1->getVtkId());
4612 nodeIds.push_back(n4->getVtkId());
4613 nodeIds.push_back(n3->getVtkId());
4614 nodeIds.push_back(n2->getVtkId());
4616 nodeIds.push_back(n5->getVtkId());
4617 nodeIds.push_back(n8->getVtkId());
4618 nodeIds.push_back(n7->getVtkId());
4619 nodeIds.push_back(n6->getVtkId());
4621 nodeIds.push_back(n41->getVtkId());
4622 nodeIds.push_back(n34->getVtkId());
4623 nodeIds.push_back(n23->getVtkId());
4624 nodeIds.push_back(n12->getVtkId());
4626 nodeIds.push_back(n85->getVtkId());
4627 nodeIds.push_back(n78->getVtkId());
4628 nodeIds.push_back(n67->getVtkId());
4629 nodeIds.push_back(n56->getVtkId());
4631 nodeIds.push_back(n15->getVtkId());
4632 nodeIds.push_back(n48->getVtkId());
4633 nodeIds.push_back(n37->getVtkId());
4634 nodeIds.push_back(n26->getVtkId());
4636 nodeIds.push_back(n1256->getVtkId());
4637 nodeIds.push_back(n3478->getVtkId());
4638 nodeIds.push_back(n1458->getVtkId());
4639 nodeIds.push_back(n2367->getVtkId());
4640 nodeIds.push_back(n1234->getVtkId());
4641 nodeIds.push_back(n5678->getVtkId());
4642 nodeIds.push_back(nCenter->getVtkId());
4644 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
4645 volvtk->init(nodeIds, this);
4646 if (!this->registerElement(ID,volvtk))
4648 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
4649 myVolumePool->destroy(volvtk);
4652 adjustmyCellsCapacity(ID);
4653 myCells[ID] = volvtk;
4654 myInfo.myNbTriQuadHexas++;
4660 void SMDS_Mesh::updateNodeMinMax()
4663 if (myNodes.size() == 0)
4668 while (!myNodes[myNodeMin] && (myNodeMin<myNodes.size()))
4670 myNodeMax=myNodes.size()-1;
4671 while (!myNodes[myNodeMax] && (myNodeMin>=0))
4675 void SMDS_Mesh::incrementNodesCapacity(int nbNodes)
4677 // int val = myCellIdSmdsToVtk.size();
4678 // MESSAGE(" ------------------- resize myCellIdSmdsToVtk " << val << " --> " << val + nbNodes);
4679 // myCellIdSmdsToVtk.resize(val + nbNodes, -1); // fill new elements with -1
4680 int val = myNodes.size();
4681 MESSAGE(" ------------------- resize myNodes " << val << " --> " << val + nbNodes);
4682 myNodes.resize(val +nbNodes, 0);
4685 void SMDS_Mesh::incrementCellsCapacity(int nbCells)
4687 int val = myCellIdVtkToSmds.size();
4688 MESSAGE(" ------------------- resize myCellIdVtkToSmds " << val << " --> " << val + nbCells);
4689 myCellIdVtkToSmds.resize(val + nbCells, -1); // fill new elements with -1
4690 val = myCells.size();
4691 MESSAGE(" ------------------- resize myCells " << val << " --> " << val + nbCells);
4692 myNodes.resize(val +nbCells, 0);
4695 void SMDS_Mesh::adjustStructure()
4697 myGrid->GetPoints()->GetData()->SetNumberOfTuples(myNodeIDFactory->GetMaxID());
4700 void SMDS_Mesh::dumpGrid(string ficdump)
4702 MESSAGE("SMDS_Mesh::dumpGrid " << ficdump);
4703 // vtkUnstructuredGridWriter* aWriter = vtkUnstructuredGridWriter::New();
4704 // aWriter->SetFileName(ficdump.c_str());
4705 // aWriter->SetInput(myGrid);
4706 // if(myGrid->GetNumberOfCells())
4708 // aWriter->Write();
4710 // aWriter->Delete();
4711 ficdump = ficdump + "_connectivity";
4712 ofstream ficcon(ficdump.c_str(), ios::out);
4713 int nbPoints = myGrid->GetNumberOfPoints();
4714 ficcon << "-------------------------------- points " << nbPoints << endl;
4715 for (int i=0; i<nbPoints; i++)
4717 ficcon << i << " " << *(myGrid->GetPoint(i)) << " " << *(myGrid->GetPoint(i)+1) << " " << " " << *(myGrid->GetPoint(i)+2) << endl;
4719 int nbCells = myGrid->GetNumberOfCells();
4720 ficcon << "-------------------------------- cells " << nbCells << endl;
4721 for (int i=0; i<nbCells; i++)
4723 // MESSAGE(i << " " << myGrid->GetCell(i));
4724 // MESSAGE(" " << myGrid->GetCell(i)->GetCellType());
4725 ficcon << i << " - " << myGrid->GetCell(i)->GetCellType() << " -";
4726 int nbptcell = myGrid->GetCell(i)->GetNumberOfPoints();
4727 vtkIdList *listid = myGrid->GetCell(i)->GetPointIds();
4728 for (int j=0; j<nbptcell; j++)
4730 ficcon << " " << listid->GetId(j);
4734 ficcon << "-------------------------------- connectivity " << nbPoints << endl;
4735 vtkCellLinks *links = myGrid->GetCellLinks();
4736 for (int i=0; i<nbPoints; i++)
4738 int ncells = links->GetNcells(i);
4739 vtkIdType *cells = links->GetCells(i);
4740 ficcon << i << " - " << ncells << " -";
4741 for (int j=0; j<ncells; j++)
4743 ficcon << " " << cells[j];
4751 void SMDS_Mesh::compactMesh()
4753 MESSAGE("SMDS_Mesh::compactMesh do nothing!");
4756 int SMDS_Mesh::fromVtkToSmds(int vtkid)
4758 if (vtkid >= 0 && vtkid < myCellIdVtkToSmds.size())
4759 return myCellIdVtkToSmds[vtkid];
4760 throw SALOME_Exception(LOCALIZED ("vtk id out of bounds"));
4763 void SMDS_Mesh::updateBoundingBox()
4768 vtkPoints *points = myGrid->GetPoints();
4769 int myNodesSize = this->myNodes.size();
4770 for (int i = 0; i < myNodesSize; i++)
4772 if (SMDS_MeshNode *n = myNodes[i])
4775 points->GetPoint(n->myVtkID, coords);
4776 if (coords[0] < xmin) xmin = coords[0];
4777 else if (coords[0] > xmax) xmax = coords[0];
4778 if (coords[1] < ymin) ymin = coords[1];
4779 else if (coords[1] > ymax) ymax = coords[1];
4780 if (coords[2] < zmin) zmin = coords[2];
4781 else if (coords[2] > zmax) zmax = coords[2];
4786 double SMDS_Mesh::getMaxDim()
4788 double dmax = 1.e-3;
4789 if ((xmax - xmin) > dmax) dmax = xmax -xmin;
4790 if ((ymax - ymin) > dmax) dmax = ymax -ymin;
4791 if ((zmax - zmin) > dmax) dmax = zmax -zmin;
4792 MESSAGE("getMaxDim " << dmax);
4796 //! modification that needs compact structure and redraw
4797 void SMDS_Mesh::Modified()
4799 if (this->myModified)
4801 this->myModifTime++;
4802 MESSAGE("modified");
4807 //! get last modification timeStamp
4808 unsigned long SMDS_Mesh::GetMTime() const
4810 return this->myModifTime;
4813 bool SMDS_Mesh::isCompacted()
4815 if (this->myModifTime > this->myCompactTime)
4817 MESSAGE(" *** isCompacted " << myCompactTime << " < " << myModifTime);
4818 this->myCompactTime = this->myModifTime;