1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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>
59 #include <sys/sysinfo.h>
62 // number of added entities to check memory after
63 #define CHECKMEMORY_INTERVAL 100000
65 vector<SMDS_Mesh*> SMDS_Mesh::_meshList = vector<SMDS_Mesh*>();
66 int SMDS_Mesh::chunkSize = 1024;
69 //================================================================================
71 * \brief Raise an exception if free memory (ram+swap) too low
72 * \param doNotRaise - if true, suppres exception, just return free memory size
73 * \retval int - amount of available memory in MB or negative number in failure case
75 //================================================================================
77 int SMDS_Mesh::CheckMemory(const bool doNotRaise) throw (std::bad_alloc)
81 int err = sysinfo( &si );
85 const unsigned long Mbyte = 1024 * 1024;
87 static int limit = -1;
89 int status = system("SMDS_MemoryLimit"); // it returns lower limit of free RAM
91 limit = WEXITSTATUS(status);
94 double factor = ( si.totalswap == 0 ) ? 0.1 : 0.2;
95 limit = int(( factor * si.totalram * si.mem_unit ) / Mbyte );
100 limit = int ( limit * 1.5 );
101 MESSAGE ( "SMDS_Mesh::CheckMemory() memory limit = " << limit << " MB" );
104 // compute separately to avoid overflow
106 ( si.freeram * si.mem_unit ) / Mbyte +
107 ( si.freeswap * si.mem_unit ) / Mbyte;
108 //cout << "freeMb = " << freeMb << " limit = " << limit << endl;
110 if ( freeMb > limit )
111 return freeMb - limit;
116 MESSAGE ("SMDS_Mesh::CheckMemory() throws as free memory too low: " << freeMb <<" MB" );
117 throw std::bad_alloc();
123 ///////////////////////////////////////////////////////////////////////////////
124 /// Create a new mesh object
125 ///////////////////////////////////////////////////////////////////////////////
126 SMDS_Mesh::SMDS_Mesh()
128 myNodeIDFactory(new SMDS_MeshNodeIDFactory()),
129 myElementIDFactory(new SMDS_MeshElementIDFactory()),
130 myHasConstructionEdges(false), myHasConstructionFaces(false),
131 myHasInverseElements(true),
132 myNodeMin(0), myNodeMax(0),
133 myNodePool(0), myEdgePool(0), myFacePool(0), myVolumePool(0),myBallPool(0),
134 myModified(false), myModifTime(0), myCompactTime(0),
135 xmin(0), xmax(0), ymin(0), ymax(0), zmin(0), zmax(0)
137 myMeshId = _meshList.size(); // --- index of the mesh to push back in the vector
138 MESSAGE("myMeshId=" << myMeshId);
139 MESSAGE("sizeof(SMDS_MeshElement) " << sizeof(SMDS_MeshElement) );
140 MESSAGE("sizeof(SMDS_MeshNode) " << sizeof(SMDS_MeshNode) );
141 MESSAGE("sizeof(SMDS_MeshCell) " << sizeof(SMDS_MeshCell) );
142 MESSAGE("sizeof(SMDS_VtkVolume) " << sizeof(SMDS_VtkVolume) );
143 MESSAGE("sizeof(SMDS_Position) " << sizeof(SMDS_Position) );
144 MESSAGE("sizeof(SMDS_SpacePosition) " << sizeof(SMDS_SpacePosition) );
145 myNodeIDFactory->SetMesh(this);
146 myElementIDFactory->SetMesh(this);
147 _meshList.push_back(this);
148 myNodePool = new ObjectPool<SMDS_MeshNode>(SMDS_Mesh::chunkSize);
149 myEdgePool = new ObjectPool<SMDS_VtkEdge>(SMDS_Mesh::chunkSize);
150 myFacePool = new ObjectPool<SMDS_VtkFace>(SMDS_Mesh::chunkSize);
151 myVolumePool = new ObjectPool<SMDS_VtkVolume>(SMDS_Mesh::chunkSize);
152 myBallPool = new ObjectPool<SMDS_BallElement>(SMDS_Mesh::chunkSize);
156 //myCellIdSmdsToVtk.clear();
157 myCellIdVtkToSmds.clear();
158 myGrid = SMDS_UnstructuredGrid::New();
159 myGrid->setSMDS_mesh(this);
160 myGrid->Initialize();
162 vtkPoints* points = vtkPoints::New();
163 // rnv: to fix bug "21125: EDF 1233 SMESH: Degrardation of precision in a test case for quadratic conversion"
164 // using double type for storing coordinates of nodes instead float.
165 points->SetDataType(VTK_DOUBLE);
166 points->SetNumberOfPoints(SMDS_Mesh::chunkSize);
167 myGrid->SetPoints( points );
169 myGrid->BuildLinks();
173 ///////////////////////////////////////////////////////////////////////////////
174 /// Create a new child mesh
175 /// Note that the tree structure of SMDS_Mesh seems to be unused in this version
176 /// (2003-09-08) of SMESH
177 ///////////////////////////////////////////////////////////////////////////////
178 SMDS_Mesh::SMDS_Mesh(SMDS_Mesh * parent)
179 :myParent(parent), myNodeIDFactory(parent->myNodeIDFactory),
180 myElementIDFactory(parent->myElementIDFactory),
181 myHasConstructionEdges(false), myHasConstructionFaces(false),
182 myHasInverseElements(true),
183 myNodePool(parent->myNodePool),
184 myEdgePool(parent->myEdgePool),
185 myFacePool(parent->myFacePool),
186 myVolumePool(parent->myVolumePool),
187 myBallPool(parent->myBallPool)
191 ///////////////////////////////////////////////////////////////////////////////
192 ///Create a submesh and add it to the current mesh
193 ///////////////////////////////////////////////////////////////////////////////
195 SMDS_Mesh *SMDS_Mesh::AddSubMesh()
197 SMDS_Mesh *submesh = new SMDS_Mesh(this);
198 myChildren.insert(myChildren.end(), submesh);
202 ///////////////////////////////////////////////////////////////////////////////
203 ///create a MeshNode and add it to the current Mesh
204 ///An ID is automatically assigned to the node.
205 ///@return : The created node
206 ///////////////////////////////////////////////////////////////////////////////
208 SMDS_MeshNode * SMDS_Mesh::AddNode(double x, double y, double z)
210 return SMDS_Mesh::AddNodeWithID(x,y,z,myNodeIDFactory->GetFreeID());
213 ///////////////////////////////////////////////////////////////////////////////
214 ///create a MeshNode and add it to the current Mesh
215 ///@param ID : The ID of the MeshNode to create
216 ///@return : The created node or NULL if a node with this ID already exists
217 ///////////////////////////////////////////////////////////////////////////////
218 SMDS_MeshNode * SMDS_Mesh::AddNodeWithID(double x, double y, double z, int ID)
220 // find the MeshNode corresponding to ID
221 const SMDS_MeshElement *node = myNodeIDFactory->MeshElement(ID);
225 MESSAGE("=============> Bad Node Id: " << ID);
226 ID = myNodeIDFactory->GetFreeID();
228 myNodeIDFactory->adjustMaxId(ID);
229 SMDS_MeshNode * node = myNodePool->getNew();
230 node->init(ID, myMeshId, 0, x, y, z);
232 if (ID >= myNodes.size())
234 myNodes.resize(ID+SMDS_Mesh::chunkSize, 0);
235 // MESSAGE(" ------------------ myNodes resize " << ID << " --> " << ID+SMDS_Mesh::chunkSize);
238 myNodeIDFactory->BindID(ID,node);
241 this->adjustBoundingBox(x, y, z);
247 ///////////////////////////////////////////////////////////////////////////////
248 /// create a Mesh0DElement and add it to the current Mesh
249 /// @return : The created Mesh0DElement
250 ///////////////////////////////////////////////////////////////////////////////
251 SMDS_Mesh0DElement* SMDS_Mesh::Add0DElementWithID(int idnode, int ID)
253 SMDS_MeshNode * node = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode);
254 if (!node) return NULL;
255 return SMDS_Mesh::Add0DElementWithID(node, ID);
258 ///////////////////////////////////////////////////////////////////////////////
259 /// create a Mesh0DElement and add it to the current Mesh
260 /// @return : The created Mesh0DElement
261 ///////////////////////////////////////////////////////////////////////////////
262 SMDS_Mesh0DElement* SMDS_Mesh::Add0DElement(const SMDS_MeshNode * node)
264 return SMDS_Mesh::Add0DElementWithID(node, myElementIDFactory->GetFreeID());
267 ///////////////////////////////////////////////////////////////////////////////
268 /// Create a new Mesh0DElement and at it to the mesh
269 /// @param idnode ID of the node
270 /// @param ID ID of the 0D element to create
271 /// @return The created 0D element or NULL if an element with this
272 /// ID already exists or if input node is not found.
273 ///////////////////////////////////////////////////////////////////////////////
274 SMDS_Mesh0DElement* SMDS_Mesh::Add0DElementWithID(const SMDS_MeshNode * n, int ID)
278 if (Nb0DElements() % CHECKMEMORY_INTERVAL == 0) CheckMemory();
279 //MESSAGE("Add0DElementWithID" << ID)
280 SMDS_Mesh0DElement * el0d = new SMDS_Mesh0DElement(n);
281 if (myElementIDFactory->BindID(ID, el0d)) {
282 //SMDS_MeshNode *node = const_cast<SMDS_MeshNode*>(n);
283 //node->AddInverseElement(el0d);// --- fait avec BindID
284 adjustmyCellsCapacity(ID);
286 myInfo.myNb0DElements++;
294 ///////////////////////////////////////////////////////////////////////////////
295 /// create a Ball and add it to the current Mesh
296 /// @return : The created Ball
297 ///////////////////////////////////////////////////////////////////////////////
298 SMDS_BallElement* SMDS_Mesh::AddBallWithID(int idnode, double diameter, int ID)
300 SMDS_MeshNode * node = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode);
301 if (!node) return NULL;
302 return SMDS_Mesh::AddBallWithID(node, diameter, ID);
305 ///////////////////////////////////////////////////////////////////////////////
306 /// create a Ball and add it to the current Mesh
307 /// @return : The created Ball
308 ///////////////////////////////////////////////////////////////////////////////
309 SMDS_BallElement* SMDS_Mesh::AddBall(const SMDS_MeshNode * node, double diameter)
311 return SMDS_Mesh::AddBallWithID(node, diameter, myElementIDFactory->GetFreeID());
314 ///////////////////////////////////////////////////////////////////////////////
315 /// Create a new Ball and at it to the mesh
316 /// @param idnode ID of the node
317 // @param diameter ball diameter
318 /// @param ID ID of the 0D element to create
319 /// @return The created 0D element or NULL if an element with this
320 /// ID already exists or if input node is not found.
321 ///////////////////////////////////////////////////////////////////////////////
322 SMDS_BallElement* SMDS_Mesh::AddBallWithID(const SMDS_MeshNode * n, double diameter, int ID)
326 if (NbBalls() % CHECKMEMORY_INTERVAL == 0) CheckMemory();
328 SMDS_BallElement *ball = myBallPool->getNew();
329 ball->init(n->getVtkId(), diameter, this);
330 if (!this->registerElement(ID,ball))
332 this->myGrid->GetCellTypesArray()->SetValue(ball->getVtkId(), VTK_EMPTY_CELL);
333 myBallPool->destroy(ball);
336 adjustmyCellsCapacity(ID);
342 ///////////////////////////////////////////////////////////////////////////////
343 /// create a MeshEdge and add it to the current Mesh
344 /// @return : The created MeshEdge
345 ///////////////////////////////////////////////////////////////////////////////
347 SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(int idnode1, int idnode2, int ID)
349 SMDS_MeshNode * node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
350 SMDS_MeshNode * node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
351 if(!node1 || !node2) return NULL;
352 return SMDS_Mesh::AddEdgeWithID(node1, node2, ID);
355 ///////////////////////////////////////////////////////////////////////////////
356 /// create a MeshEdge and add it to the current Mesh
357 /// @return : The created MeshEdge
358 ///////////////////////////////////////////////////////////////////////////////
360 SMDS_MeshEdge* SMDS_Mesh::AddEdge(const SMDS_MeshNode * node1,
361 const SMDS_MeshNode * node2)
363 return SMDS_Mesh::AddEdgeWithID(node1, node2, myElementIDFactory->GetFreeID());
366 ///////////////////////////////////////////////////////////////////////////////
367 /// Create a new edge and at it to the mesh
368 /// @param idnode1 ID of the first node
369 /// @param idnode2 ID of the second node
370 /// @param ID ID of the edge to create
371 /// @return The created edge or NULL if an element with this ID already exists or
372 /// if input nodes are not found.
373 ///////////////////////////////////////////////////////////////////////////////
375 SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
376 const SMDS_MeshNode * n2,
379 if ( !n1 || !n2 ) return 0;
380 SMDS_MeshEdge * edge = 0;
382 // --- retreive nodes ID
383 vector<vtkIdType> nodeIds;
385 nodeIds.push_back(n1->getVtkId());
386 nodeIds.push_back(n2->getVtkId());
388 SMDS_VtkEdge *edgevtk = myEdgePool->getNew();
389 edgevtk->init(nodeIds, this);
390 if (!this->registerElement(ID,edgevtk))
392 this->myGrid->GetCellTypesArray()->SetValue(edgevtk->getVtkId(), VTK_EMPTY_CELL);
393 myEdgePool->destroy(edgevtk);
397 adjustmyCellsCapacity(ID);
401 // if (edge && !registerElement(ID, edge))
403 // RemoveElement(edge, false);
409 ///////////////////////////////////////////////////////////////////////////////
410 /// Add a triangle defined by its nodes. An ID is automatically affected to the
412 ///////////////////////////////////////////////////////////////////////////////
414 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
415 const SMDS_MeshNode * n2,
416 const SMDS_MeshNode * n3)
418 return SMDS_Mesh::AddFaceWithID(n1,n2,n3, myElementIDFactory->GetFreeID());
421 ///////////////////////////////////////////////////////////////////////////////
422 /// Add a triangle defined by its nodes IDs
423 ///////////////////////////////////////////////////////////////////////////////
425 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int idnode1, int idnode2, int idnode3, int ID)
427 SMDS_MeshNode * node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
428 SMDS_MeshNode * node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
429 SMDS_MeshNode * node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
430 if(!node1 || !node2 || !node3) return NULL;
431 return SMDS_Mesh::AddFaceWithID(node1, node2, node3, ID);
434 ///////////////////////////////////////////////////////////////////////////////
435 /// Add a triangle defined by its nodes
436 ///////////////////////////////////////////////////////////////////////////////
438 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
439 const SMDS_MeshNode * n2,
440 const SMDS_MeshNode * n3,
443 //MESSAGE("AddFaceWithID " << ID)
444 SMDS_MeshFace * face=createTriangle(n1, n2, n3, ID);
446 // if (face && !registerElement(ID, face)) {
447 // RemoveElement(face, false);
453 ///////////////////////////////////////////////////////////////////////////////
454 /// Add a quadrangle defined by its nodes. An ID is automatically affected to the
456 ///////////////////////////////////////////////////////////////////////////////
458 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
459 const SMDS_MeshNode * n2,
460 const SMDS_MeshNode * n3,
461 const SMDS_MeshNode * n4)
463 return SMDS_Mesh::AddFaceWithID(n1,n2,n3, n4, myElementIDFactory->GetFreeID());
466 ///////////////////////////////////////////////////////////////////////////////
467 /// Add a quadrangle defined by its nodes IDs
468 ///////////////////////////////////////////////////////////////////////////////
470 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int idnode1,
476 SMDS_MeshNode *node1, *node2, *node3, *node4;
477 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
478 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
479 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
480 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
481 if(!node1 || !node2 || !node3 || !node4) return NULL;
482 return SMDS_Mesh::AddFaceWithID(node1, node2, node3, node4, ID);
485 ///////////////////////////////////////////////////////////////////////////////
486 /// Add a quadrangle defined by its nodes
487 ///////////////////////////////////////////////////////////////////////////////
489 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
490 const SMDS_MeshNode * n2,
491 const SMDS_MeshNode * n3,
492 const SMDS_MeshNode * n4,
495 //MESSAGE("AddFaceWithID " << ID);
496 SMDS_MeshFace * face=createQuadrangle(n1, n2, n3, n4, ID);
498 // if (face && !registerElement(ID, face)) {
499 // RemoveElement(face, false);
505 ///////////////////////////////////////////////////////////////////////////////
506 /// Add a triangle defined by its edges. An ID is automatically assigned to the
508 ///////////////////////////////////////////////////////////////////////////////
510 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshEdge * e1,
511 const SMDS_MeshEdge * e2,
512 const SMDS_MeshEdge * e3)
514 if (!hasConstructionEdges())
516 //MESSAGE("AddFaceWithID");
517 return AddFaceWithID(e1,e2,e3, myElementIDFactory->GetFreeID());
520 ///////////////////////////////////////////////////////////////////////////////
521 /// Add a triangle defined by its edges
522 ///////////////////////////////////////////////////////////////////////////////
524 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshEdge * e1,
525 const SMDS_MeshEdge * e2,
526 const SMDS_MeshEdge * e3,
529 if (!hasConstructionEdges())
531 if ( !e1 || !e2 || !e3 ) return 0;
533 if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
534 MESSAGE("AddFaceWithID" << ID);
536 SMDS_MeshFace * face = new SMDS_FaceOfEdges(e1,e2,e3);
537 adjustmyCellsCapacity(ID);
539 myInfo.myNbTriangles++;
541 if (!registerElement(ID, face)) {
542 registerElement(myElementIDFactory->GetFreeID(), face);
543 //RemoveElement(face, false);
549 ///////////////////////////////////////////////////////////////////////////////
550 /// Add a quadrangle defined by its edges. An ID is automatically assigned to the
552 ///////////////////////////////////////////////////////////////////////////////
554 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshEdge * e1,
555 const SMDS_MeshEdge * e2,
556 const SMDS_MeshEdge * e3,
557 const SMDS_MeshEdge * e4)
559 if (!hasConstructionEdges())
561 //MESSAGE("AddFaceWithID" );
562 return AddFaceWithID(e1,e2,e3,e4, myElementIDFactory->GetFreeID());
565 ///////////////////////////////////////////////////////////////////////////////
566 /// Add a quadrangle defined by its edges
567 ///////////////////////////////////////////////////////////////////////////////
569 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshEdge * e1,
570 const SMDS_MeshEdge * e2,
571 const SMDS_MeshEdge * e3,
572 const SMDS_MeshEdge * e4,
575 if (!hasConstructionEdges())
577 MESSAGE("AddFaceWithID" << ID);
578 if ( !e1 || !e2 || !e3 || !e4 ) return 0;
579 if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
580 SMDS_MeshFace * face = new SMDS_FaceOfEdges(e1,e2,e3,e4);
581 adjustmyCellsCapacity(ID);
583 myInfo.myNbQuadrangles++;
585 if (!registerElement(ID, face))
587 registerElement(myElementIDFactory->GetFreeID(), face);
588 //RemoveElement(face, false);
594 ///////////////////////////////////////////////////////////////////////////////
595 ///Create a new tetrahedron and add it to the mesh.
596 ///@return The created tetrahedron
597 ///////////////////////////////////////////////////////////////////////////////
599 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
600 const SMDS_MeshNode * n2,
601 const SMDS_MeshNode * n3,
602 const SMDS_MeshNode * n4)
604 int ID = myElementIDFactory->GetFreeID();
605 //MESSAGE("AddVolumeWithID " << ID);
606 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, ID);
607 if(v==NULL) myElementIDFactory->ReleaseID(ID);
611 ///////////////////////////////////////////////////////////////////////////////
612 ///Create a new tetrahedron and add it to the mesh.
613 ///@param ID The ID of the new volume
614 ///@return The created tetrahedron or NULL if an element with this ID already exists
615 ///or if input nodes are not found.
616 ///////////////////////////////////////////////////////////////////////////////
618 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
624 //MESSAGE("AddVolumeWithID" << ID);
625 SMDS_MeshNode *node1, *node2, *node3, *node4;
626 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
627 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
628 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
629 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
630 if(!node1 || !node2 || !node3 || !node4) return NULL;
631 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, ID);
634 ///////////////////////////////////////////////////////////////////////////////
635 ///Create a new tetrahedron and add it to the mesh.
636 ///@param ID The ID of the new volume
637 ///@return The created tetrahedron
638 ///////////////////////////////////////////////////////////////////////////////
640 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
641 const SMDS_MeshNode * n2,
642 const SMDS_MeshNode * n3,
643 const SMDS_MeshNode * n4,
646 //MESSAGE("AddVolumeWithID " << ID);
647 SMDS_MeshVolume* volume = 0;
648 if ( !n1 || !n2 || !n3 || !n4) return volume;
649 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
650 if(hasConstructionFaces()) {
651 SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3);
652 SMDS_MeshFace * f2=FindFaceOrCreate(n1,n2,n4);
653 SMDS_MeshFace * f3=FindFaceOrCreate(n1,n3,n4);
654 SMDS_MeshFace * f4=FindFaceOrCreate(n2,n3,n4);
655 volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4);
656 adjustmyCellsCapacity(ID);
657 myCells[ID] = volume;
660 else if(hasConstructionEdges()) {
661 MESSAGE("Error : Not implemented");
665 // --- retrieve nodes ID
666 vector<vtkIdType> nodeIds;
668 nodeIds.push_back(n1->getVtkId());
669 nodeIds.push_back(n3->getVtkId()); // order SMDS-->VTK
670 nodeIds.push_back(n2->getVtkId());
671 nodeIds.push_back(n4->getVtkId());
673 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
674 volvtk->init(nodeIds, this);
675 if (!this->registerElement(ID,volvtk))
677 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
678 myVolumePool->destroy(volvtk);
682 adjustmyCellsCapacity(ID);
683 myCells[ID] = volume;
687 // if (!registerElement(ID, volume)) {
688 // RemoveElement(volume, false);
694 ///////////////////////////////////////////////////////////////////////////////
695 ///Create a new pyramid and add it to the mesh.
696 ///Nodes 1,2,3 and 4 define the base of the pyramid
697 ///@return The created pyramid
698 ///////////////////////////////////////////////////////////////////////////////
700 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
701 const SMDS_MeshNode * n2,
702 const SMDS_MeshNode * n3,
703 const SMDS_MeshNode * n4,
704 const SMDS_MeshNode * n5)
706 int ID = myElementIDFactory->GetFreeID();
707 //MESSAGE("AddVolumeWithID " << ID);
708 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, ID);
709 if(v==NULL) myElementIDFactory->ReleaseID(ID);
713 ///////////////////////////////////////////////////////////////////////////////
714 ///Create a new pyramid and add it to the mesh.
715 ///Nodes 1,2,3 and 4 define the base of the pyramid
716 ///@param ID The ID of the new volume
717 ///@return The created pyramid or NULL if an element with this ID already exists
718 ///or if input nodes are not found.
719 ///////////////////////////////////////////////////////////////////////////////
721 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
728 //MESSAGE("AddVolumeWithID " << ID);
729 SMDS_MeshNode *node1, *node2, *node3, *node4, *node5;
730 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
731 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
732 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
733 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
734 node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5);
735 if(!node1 || !node2 || !node3 || !node4 || !node5) return NULL;
736 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, ID);
739 ///////////////////////////////////////////////////////////////////////////////
740 ///Create a new pyramid and add it to the mesh.
741 ///Nodes 1,2,3 and 4 define the base of the pyramid
742 ///@param ID The ID of the new volume
743 ///@return The created pyramid
744 ///////////////////////////////////////////////////////////////////////////////
746 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
747 const SMDS_MeshNode * n2,
748 const SMDS_MeshNode * n3,
749 const SMDS_MeshNode * n4,
750 const SMDS_MeshNode * n5,
753 //MESSAGE("AddVolumeWithID " << ID);
754 SMDS_MeshVolume* volume = 0;
755 if ( !n1 || !n2 || !n3 || !n4 || !n5) return volume;
756 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
757 if(hasConstructionFaces()) {
758 SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3,n4);
759 SMDS_MeshFace * f2=FindFaceOrCreate(n1,n2,n5);
760 SMDS_MeshFace * f3=FindFaceOrCreate(n2,n3,n5);
761 SMDS_MeshFace * f4=FindFaceOrCreate(n3,n4,n5);
762 volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4);
763 adjustmyCellsCapacity(ID);
764 myCells[ID] = volume;
765 myInfo.myNbPyramids++;
767 else if(hasConstructionEdges()) {
768 MESSAGE("Error : Not implemented");
772 // --- retrieve nodes ID
773 vector<vtkIdType> nodeIds;
775 nodeIds.push_back(n1->getVtkId());
776 nodeIds.push_back(n4->getVtkId());
777 nodeIds.push_back(n3->getVtkId());
778 nodeIds.push_back(n2->getVtkId());
779 nodeIds.push_back(n5->getVtkId());
781 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
782 volvtk->init(nodeIds, this);
783 if (!this->registerElement(ID,volvtk))
785 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
786 myVolumePool->destroy(volvtk);
790 adjustmyCellsCapacity(ID);
791 myCells[ID] = volume;
792 myInfo.myNbPyramids++;
795 // if (!registerElement(ID, volume)) {
796 // RemoveElement(volume, false);
802 ///////////////////////////////////////////////////////////////////////////////
803 ///Create a new prism and add it to the mesh.
804 ///Nodes 1,2,3 is a triangle and 1,2,5,4 a quadrangle.
805 ///@return The created prism
806 ///////////////////////////////////////////////////////////////////////////////
808 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
809 const SMDS_MeshNode * n2,
810 const SMDS_MeshNode * n3,
811 const SMDS_MeshNode * n4,
812 const SMDS_MeshNode * n5,
813 const SMDS_MeshNode * n6)
815 int ID = myElementIDFactory->GetFreeID();
816 //MESSAGE("AddVolumeWithID " << ID);
817 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, ID);
818 if(v==NULL) myElementIDFactory->ReleaseID(ID);
822 ///////////////////////////////////////////////////////////////////////////////
823 ///Create a new prism and add it to the mesh.
824 ///Nodes 1,2,3 is a triangle and 1,2,5,4 a quadrangle.
825 ///@param ID The ID of the new volume
826 ///@return The created prism or NULL if an element with this ID already exists
827 ///or if input nodes are not found.
828 ///////////////////////////////////////////////////////////////////////////////
830 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
838 //MESSAGE("AddVolumeWithID " << ID);
839 SMDS_MeshNode *node1, *node2, *node3, *node4, *node5, *node6;
840 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
841 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
842 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
843 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
844 node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5);
845 node6 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode6);
846 if(!node1 || !node2 || !node3 || !node4 || !node5 || !node6) return NULL;
847 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, node6, ID);
850 ///////////////////////////////////////////////////////////////////////////////
851 ///Create a new prism and add it to the mesh.
852 ///Nodes 1,2,3 is a triangle and 1,2,5,4 a quadrangle.
853 ///@param ID The ID of the new volume
854 ///@return The created prism
855 ///////////////////////////////////////////////////////////////////////////////
857 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
858 const SMDS_MeshNode * n2,
859 const SMDS_MeshNode * n3,
860 const SMDS_MeshNode * n4,
861 const SMDS_MeshNode * n5,
862 const SMDS_MeshNode * n6,
865 //MESSAGE("AddVolumeWithID " << ID);
866 SMDS_MeshVolume* volume = 0;
867 if ( !n1 || !n2 || !n3 || !n4 || !n5 || !n6) return volume;
868 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
869 if(hasConstructionFaces()) {
870 SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3);
871 SMDS_MeshFace * f2=FindFaceOrCreate(n4,n5,n6);
872 SMDS_MeshFace * f3=FindFaceOrCreate(n1,n4,n5,n2);
873 SMDS_MeshFace * f4=FindFaceOrCreate(n2,n5,n6,n3);
874 SMDS_MeshFace * f5=FindFaceOrCreate(n3,n6,n4,n1);
875 volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5);
876 adjustmyCellsCapacity(ID);
877 myCells[ID] = volume;
880 else if(hasConstructionEdges()) {
881 MESSAGE("Error : Not implemented");
885 // --- retrieve nodes ID
886 vector<vtkIdType> nodeIds;
888 nodeIds.push_back(n1->getVtkId());
889 nodeIds.push_back(n2->getVtkId());
890 nodeIds.push_back(n3->getVtkId());
891 nodeIds.push_back(n4->getVtkId());
892 nodeIds.push_back(n5->getVtkId());
893 nodeIds.push_back(n6->getVtkId());
895 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
896 volvtk->init(nodeIds, this);
897 if (!this->registerElement(ID,volvtk))
899 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
900 myVolumePool->destroy(volvtk);
904 adjustmyCellsCapacity(ID);
905 myCells[ID] = volume;
909 // if (!registerElement(ID, volume)) {
910 // RemoveElement(volume, false);
916 ///////////////////////////////////////////////////////////////////////////////
917 ///Create a new hexagonal prism and add it to the mesh.
918 ///@return The created prism
919 ///////////////////////////////////////////////////////////////////////////////
921 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
922 const SMDS_MeshNode * n2,
923 const SMDS_MeshNode * n3,
924 const SMDS_MeshNode * n4,
925 const SMDS_MeshNode * n5,
926 const SMDS_MeshNode * n6,
927 const SMDS_MeshNode * n7,
928 const SMDS_MeshNode * n8,
929 const SMDS_MeshNode * n9,
930 const SMDS_MeshNode * n10,
931 const SMDS_MeshNode * n11,
932 const SMDS_MeshNode * n12)
934 int ID = myElementIDFactory->GetFreeID();
935 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6,
936 n7, n8, n9, n10, n11, n12,
938 if(v==NULL) myElementIDFactory->ReleaseID(ID);
942 ///////////////////////////////////////////////////////////////////////////////
943 ///Create a new hexagonal prism and add it to the mesh.
944 ///@param ID The ID of the new volume
945 ///@return The created prism or NULL if an element with this ID already exists
946 ///or if input nodes are not found.
947 ///////////////////////////////////////////////////////////////////////////////
949 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
963 SMDS_MeshNode *node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
964 SMDS_MeshNode *node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
965 SMDS_MeshNode *node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
966 SMDS_MeshNode *node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
967 SMDS_MeshNode *node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5);
968 SMDS_MeshNode *node6 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode6);
969 SMDS_MeshNode *node7 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode7);
970 SMDS_MeshNode *node8 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode8);
971 SMDS_MeshNode *node9 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode9);
972 SMDS_MeshNode *node10 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode10);
973 SMDS_MeshNode *node11 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode11);
974 SMDS_MeshNode *node12 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode12);
975 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, node6,
976 node7, node8, node9, node10, node11, node12,
980 ///////////////////////////////////////////////////////////////////////////////
981 ///Create a new hexagonal prism and add it to the mesh.
982 ///@param ID The ID of the new volume
983 ///@return The created prism
984 ///////////////////////////////////////////////////////////////////////////////
986 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
987 const SMDS_MeshNode * n2,
988 const SMDS_MeshNode * n3,
989 const SMDS_MeshNode * n4,
990 const SMDS_MeshNode * n5,
991 const SMDS_MeshNode * n6,
992 const SMDS_MeshNode * n7,
993 const SMDS_MeshNode * n8,
994 const SMDS_MeshNode * n9,
995 const SMDS_MeshNode * n10,
996 const SMDS_MeshNode * n11,
997 const SMDS_MeshNode * n12,
1000 SMDS_MeshVolume* volume = 0;
1001 if(!n1 || !n2 || !n3 || !n4 || !n5 || !n6 ||
1002 !n7 || !n8 || !n9 || !n10 || !n11 || !n12 )
1004 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1005 if(hasConstructionFaces()) {
1006 MESSAGE("Error : Not implemented");
1009 else if(hasConstructionEdges()) {
1010 MESSAGE("Error : Not implemented");
1014 // --- retrieve nodes ID
1015 vector<vtkIdType> nodeIds;
1016 nodeIds.push_back(n1->getVtkId());
1017 nodeIds.push_back(n6->getVtkId());
1018 nodeIds.push_back(n5->getVtkId());
1019 nodeIds.push_back(n4->getVtkId());
1020 nodeIds.push_back(n3->getVtkId());
1021 nodeIds.push_back(n2->getVtkId());
1023 nodeIds.push_back(n7->getVtkId());
1024 nodeIds.push_back(n12->getVtkId());
1025 nodeIds.push_back(n11->getVtkId());
1026 nodeIds.push_back(n10->getVtkId());
1027 nodeIds.push_back(n9->getVtkId());
1028 nodeIds.push_back(n8->getVtkId());
1030 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
1031 volvtk->init(nodeIds, this);
1032 if (!this->registerElement(ID,volvtk))
1034 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
1035 myVolumePool->destroy(volvtk);
1039 adjustmyCellsCapacity(ID);
1040 myCells[ID] = volume;
1041 myInfo.myNbHexPrism++;
1047 ///////////////////////////////////////////////////////////////////////////////
1048 ///Create a new hexahedron and add it to the mesh.
1049 ///Nodes 1,2,3,4 and 5,6,7,8 are quadrangle and 5,1 and 7,3 are an edges.
1050 ///@return The created hexahedron
1051 ///////////////////////////////////////////////////////////////////////////////
1053 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
1054 const SMDS_MeshNode * n2,
1055 const SMDS_MeshNode * n3,
1056 const SMDS_MeshNode * n4,
1057 const SMDS_MeshNode * n5,
1058 const SMDS_MeshNode * n6,
1059 const SMDS_MeshNode * n7,
1060 const SMDS_MeshNode * n8)
1062 int ID = myElementIDFactory->GetFreeID();
1063 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, ID);
1064 if(v==NULL) myElementIDFactory->ReleaseID(ID);
1068 ///////////////////////////////////////////////////////////////////////////////
1069 ///Create a new hexahedron and add it to the mesh.
1070 ///Nodes 1,2,3,4 and 5,6,7,8 are quadrangle and 5,1 and 7,3 are an edges.
1071 ///@param ID The ID of the new volume
1072 ///@return The created hexahedron or NULL if an element with this ID already
1073 ///exists or if input nodes are not found.
1074 ///////////////////////////////////////////////////////////////////////////////
1076 SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
1086 //MESSAGE("AddVolumeWithID " << ID);
1087 SMDS_MeshNode *node1, *node2, *node3, *node4, *node5, *node6, *node7, *node8;
1088 node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
1089 node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
1090 node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
1091 node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
1092 node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5);
1093 node6 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode6);
1094 node7 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode7);
1095 node8 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode8);
1096 if(!node1 || !node2 || !node3 || !node4 || !node5 || !node6 || !node7 || !node8)
1098 return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, node6,
1102 ///////////////////////////////////////////////////////////////////////////////
1103 ///Create a new hexahedron and add it to the mesh.
1104 ///Nodes 1,2,3,4 and 5,6,7,8 are quadrangle and 5,1 and 7,3 are an edges.
1105 ///@param ID The ID of the new volume
1106 ///@return The created prism or NULL if an element with this ID already exists
1107 ///or if input nodes are not found.
1108 ///////////////////////////////////////////////////////////////////////////////
1110 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
1111 const SMDS_MeshNode * n2,
1112 const SMDS_MeshNode * n3,
1113 const SMDS_MeshNode * n4,
1114 const SMDS_MeshNode * n5,
1115 const SMDS_MeshNode * n6,
1116 const SMDS_MeshNode * n7,
1117 const SMDS_MeshNode * n8,
1120 //MESSAGE("AddVolumeWithID " << ID);
1121 SMDS_MeshVolume* volume = 0;
1122 if ( !n1 || !n2 || !n3 || !n4 || !n5 || !n6 || !n7 || !n8) return volume;
1123 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1124 if(hasConstructionFaces()) {
1125 SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3,n4);
1126 SMDS_MeshFace * f2=FindFaceOrCreate(n5,n6,n7,n8);
1127 SMDS_MeshFace * f3=FindFaceOrCreate(n1,n4,n8,n5);
1128 SMDS_MeshFace * f4=FindFaceOrCreate(n1,n2,n6,n5);
1129 SMDS_MeshFace * f5=FindFaceOrCreate(n2,n3,n7,n6);
1130 SMDS_MeshFace * f6=FindFaceOrCreate(n3,n4,n8,n7);
1131 volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5,f6);
1132 adjustmyCellsCapacity(ID);
1133 myCells[ID] = volume;
1136 else if(hasConstructionEdges()) {
1137 MESSAGE("Error : Not implemented");
1141 // --- retrieve nodes ID
1142 vector<vtkIdType> nodeIds;
1144 nodeIds.push_back(n1->getVtkId());
1145 nodeIds.push_back(n4->getVtkId());
1146 nodeIds.push_back(n3->getVtkId());
1147 nodeIds.push_back(n2->getVtkId());
1148 nodeIds.push_back(n5->getVtkId());
1149 nodeIds.push_back(n8->getVtkId());
1150 nodeIds.push_back(n7->getVtkId());
1151 nodeIds.push_back(n6->getVtkId());
1153 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
1154 volvtk->init(nodeIds, this);
1155 if (!this->registerElement(ID,volvtk))
1157 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
1158 myVolumePool->destroy(volvtk);
1162 adjustmyCellsCapacity(ID);
1163 myCells[ID] = volume;
1167 // if (!registerElement(ID, volume)) {
1168 // RemoveElement(volume, false);
1174 ///////////////////////////////////////////////////////////////////////////////
1175 ///Create a new tetrahedron defined by its faces and add it to the mesh.
1176 ///@return The created tetrahedron
1177 ///////////////////////////////////////////////////////////////////////////////
1179 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshFace * f1,
1180 const SMDS_MeshFace * f2,
1181 const SMDS_MeshFace * f3,
1182 const SMDS_MeshFace * f4)
1184 //MESSAGE("AddVolumeWithID");
1185 if (!hasConstructionFaces())
1187 return AddVolumeWithID(f1,f2,f3,f4, myElementIDFactory->GetFreeID());
1190 ///////////////////////////////////////////////////////////////////////////////
1191 ///Create a new tetrahedron defined by its faces and add it to the mesh.
1192 ///@param ID The ID of the new volume
1193 ///@return The created tetrahedron
1194 ///////////////////////////////////////////////////////////////////////////////
1196 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1,
1197 const SMDS_MeshFace * f2,
1198 const SMDS_MeshFace * f3,
1199 const SMDS_MeshFace * f4,
1202 MESSAGE("AddVolumeWithID" << ID);
1203 if (!hasConstructionFaces())
1205 if ( !f1 || !f2 || !f3 || !f4) return 0;
1206 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1207 SMDS_MeshVolume * volume = new SMDS_VolumeOfFaces(f1,f2,f3,f4);
1208 adjustmyCellsCapacity(ID);
1209 myCells[ID] = volume;
1210 myInfo.myNbTetras++;
1212 if (!registerElement(ID, volume)) {
1213 registerElement(myElementIDFactory->GetFreeID(), volume);
1214 //RemoveElement(volume, false);
1220 ///////////////////////////////////////////////////////////////////////////////
1221 ///Create a new pyramid defined by its faces and add it to the mesh.
1222 ///@return The created pyramid
1223 ///////////////////////////////////////////////////////////////////////////////
1225 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshFace * f1,
1226 const SMDS_MeshFace * f2,
1227 const SMDS_MeshFace * f3,
1228 const SMDS_MeshFace * f4,
1229 const SMDS_MeshFace * f5)
1231 //MESSAGE("AddVolumeWithID");
1232 if (!hasConstructionFaces())
1234 return AddVolumeWithID(f1,f2,f3,f4,f5, myElementIDFactory->GetFreeID());
1237 ///////////////////////////////////////////////////////////////////////////////
1238 ///Create a new pyramid defined by its faces and add it to the mesh.
1239 ///@param ID The ID of the new volume
1240 ///@return The created pyramid
1241 ///////////////////////////////////////////////////////////////////////////////
1243 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1,
1244 const SMDS_MeshFace * f2,
1245 const SMDS_MeshFace * f3,
1246 const SMDS_MeshFace * f4,
1247 const SMDS_MeshFace * f5,
1250 MESSAGE("AddVolumeWithID" << ID);
1251 if (!hasConstructionFaces())
1253 if ( !f1 || !f2 || !f3 || !f4 || !f5) return 0;
1254 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1255 SMDS_MeshVolume * volume = new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5);
1256 adjustmyCellsCapacity(ID);
1257 myCells[ID] = volume;
1258 myInfo.myNbPyramids++;
1260 if (!registerElement(ID, volume)) {
1261 registerElement(myElementIDFactory->GetFreeID(), volume);
1262 //RemoveElement(volume, false);
1268 ///////////////////////////////////////////////////////////////////////////////
1269 ///Create a new prism defined by its faces and add it to the mesh.
1270 ///@return The created prism
1271 ///////////////////////////////////////////////////////////////////////////////
1273 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshFace * f1,
1274 const SMDS_MeshFace * f2,
1275 const SMDS_MeshFace * f3,
1276 const SMDS_MeshFace * f4,
1277 const SMDS_MeshFace * f5,
1278 const SMDS_MeshFace * f6)
1280 //MESSAGE("AddVolumeWithID" );
1281 if (!hasConstructionFaces())
1283 return AddVolumeWithID(f1,f2,f3,f4,f5,f6, myElementIDFactory->GetFreeID());
1286 ///////////////////////////////////////////////////////////////////////////////
1287 ///Create a new prism defined by its faces and add it to the mesh.
1288 ///@param ID The ID of the new volume
1289 ///@return The created prism
1290 ///////////////////////////////////////////////////////////////////////////////
1292 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1,
1293 const SMDS_MeshFace * f2,
1294 const SMDS_MeshFace * f3,
1295 const SMDS_MeshFace * f4,
1296 const SMDS_MeshFace * f5,
1297 const SMDS_MeshFace * f6,
1300 MESSAGE("AddVolumeWithID" << ID);
1301 if (!hasConstructionFaces())
1303 if ( !f1 || !f2 || !f3 || !f4 || !f5 || !f6) return 0;
1304 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1305 SMDS_MeshVolume * volume = new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5,f6);
1306 adjustmyCellsCapacity(ID);
1307 myCells[ID] = volume;
1308 myInfo.myNbPrisms++;
1310 if (!registerElement(ID, volume)) {
1311 registerElement(myElementIDFactory->GetFreeID(), volume);
1312 //RemoveElement(volume, false);
1318 ///////////////////////////////////////////////////////////////////////////////
1319 /// Add a polygon defined by its nodes IDs
1320 ///////////////////////////////////////////////////////////////////////////////
1322 SMDS_MeshFace* SMDS_Mesh::AddPolygonalFaceWithID (const vector<int> & nodes_ids,
1325 int nbNodes = nodes_ids.size();
1326 vector<const SMDS_MeshNode*> nodes (nbNodes);
1327 for (int i = 0; i < nbNodes; i++) {
1328 nodes[i] = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nodes_ids[i]);
1329 if (!nodes[i]) return NULL;
1331 return SMDS_Mesh::AddPolygonalFaceWithID(nodes, ID);
1334 ///////////////////////////////////////////////////////////////////////////////
1335 /// Add a polygon defined by its nodes
1336 ///////////////////////////////////////////////////////////////////////////////
1338 SMDS_MeshFace* SMDS_Mesh::AddPolygonalFaceWithID
1339 (const vector<const SMDS_MeshNode*> & nodes,
1342 SMDS_MeshFace * face;
1344 if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1345 if (hasConstructionEdges())
1347 MESSAGE("Error : Not implemented");
1352 //#ifdef VTK_HAVE_POLYHEDRON
1353 //MESSAGE("AddPolygonalFaceWithID vtk " << ID);
1354 vector<vtkIdType> nodeIds;
1356 vector<const SMDS_MeshNode*>::const_iterator it = nodes.begin();
1357 for ( ; it != nodes.end(); ++it)
1358 nodeIds.push_back((*it)->getVtkId());
1360 SMDS_VtkFace *facevtk = myFacePool->getNew();
1361 facevtk->initPoly(nodeIds, this);
1362 if (!this->registerElement(ID,facevtk))
1364 this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL);
1365 myFacePool->destroy(facevtk);
1370 // MESSAGE("AddPolygonalFaceWithID smds " << ID);
1371 // for ( int i = 0; i < nodes.size(); ++i )
1372 // if ( !nodes[ i ] ) return 0;
1373 // face = new SMDS_PolygonalFaceOfNodes(nodes);
1375 adjustmyCellsCapacity(ID);
1377 myInfo.myNbPolygons++;
1380 //#ifndef VTK_HAVE_POLYHEDRON
1381 // if (!registerElement(ID, face))
1383 // registerElement(myElementIDFactory->GetFreeID(), face);
1384 // //RemoveElement(face, false);
1391 ///////////////////////////////////////////////////////////////////////////////
1392 /// Add a polygon defined by its nodes.
1393 /// An ID is automatically affected to the created face.
1394 ///////////////////////////////////////////////////////////////////////////////
1396 SMDS_MeshFace* SMDS_Mesh::AddPolygonalFace (const vector<const SMDS_MeshNode*> & nodes)
1398 return SMDS_Mesh::AddPolygonalFaceWithID(nodes, myElementIDFactory->GetFreeID());
1401 ///////////////////////////////////////////////////////////////////////////////
1402 /// Create a new polyhedral volume and add it to the mesh.
1403 /// @param ID The ID of the new volume
1404 /// @return The created volume or NULL if an element with this ID already exists
1405 /// or if input nodes are not found.
1406 ///////////////////////////////////////////////////////////////////////////////
1408 SMDS_MeshVolume * SMDS_Mesh::AddPolyhedralVolumeWithID
1409 (const vector<int> & nodes_ids,
1410 const vector<int> & quantities,
1413 int nbNodes = nodes_ids.size();
1414 vector<const SMDS_MeshNode*> nodes (nbNodes);
1415 for (int i = 0; i < nbNodes; i++) {
1416 nodes[i] = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nodes_ids[i]);
1417 if (!nodes[i]) return NULL;
1419 return SMDS_Mesh::AddPolyhedralVolumeWithID(nodes, quantities, ID);
1422 ///////////////////////////////////////////////////////////////////////////////
1423 /// Create a new polyhedral volume and add it to the mesh.
1424 /// @param ID The ID of the new volume
1425 /// @return The created volume
1426 ///////////////////////////////////////////////////////////////////////////////
1428 SMDS_MeshVolume* SMDS_Mesh::AddPolyhedralVolumeWithID
1429 (const vector<const SMDS_MeshNode*>& nodes,
1430 const vector<int> & quantities,
1433 SMDS_MeshVolume* volume = 0;
1434 if ( nodes.empty() || quantities.empty() )
1436 if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1437 if (hasConstructionFaces())
1439 MESSAGE("Error : Not implemented");
1442 else if (hasConstructionEdges())
1444 MESSAGE("Error : Not implemented");
1449 //#ifdef VTK_HAVE_POLYHEDRON
1450 //MESSAGE("AddPolyhedralVolumeWithID vtk " << ID);
1451 vector<vtkIdType> nodeIds;
1453 vector<const SMDS_MeshNode*>::const_iterator it = nodes.begin();
1454 for (; it != nodes.end(); ++it)
1455 nodeIds.push_back((*it)->getVtkId());
1457 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
1458 volvtk->initPoly(nodeIds, quantities, this);
1459 if (!this->registerElement(ID, volvtk))
1461 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
1462 myVolumePool->destroy(volvtk);
1467 // MESSAGE("AddPolyhedralVolumeWithID smds " << ID);
1468 // for ( int i = 0; i < nodes.size(); ++i )
1469 // if ( !nodes[ i ] ) return 0;
1470 // volume = new SMDS_PolyhedralVolumeOfNodes(nodes, quantities);
1472 adjustmyCellsCapacity(ID);
1473 myCells[ID] = volume;
1474 myInfo.myNbPolyhedrons++;
1477 //#ifndef VTK_HAVE_POLYHEDRON
1478 // if (!registerElement(ID, volume))
1480 // registerElement(myElementIDFactory->GetFreeID(), volume);
1481 // //RemoveElement(volume, false);
1488 ///////////////////////////////////////////////////////////////////////////////
1489 /// Create a new polyhedral volume and add it to the mesh.
1490 /// @return The created volume
1491 ///////////////////////////////////////////////////////////////////////////////
1493 SMDS_MeshVolume* SMDS_Mesh::AddPolyhedralVolume
1494 (const vector<const SMDS_MeshNode*> & nodes,
1495 const vector<int> & quantities)
1497 int ID = myElementIDFactory->GetFreeID();
1498 SMDS_MeshVolume * v = SMDS_Mesh::AddPolyhedralVolumeWithID(nodes, quantities, ID);
1499 if (v == NULL) myElementIDFactory->ReleaseID(ID);
1503 SMDS_MeshVolume* SMDS_Mesh::AddVolumeFromVtkIds(const std::vector<vtkIdType>& vtkNodeIds)
1505 int ID = myElementIDFactory->GetFreeID();
1506 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeFromVtkIdsWithID(vtkNodeIds, ID);
1507 if (v == NULL) myElementIDFactory->ReleaseID(ID);
1511 SMDS_MeshVolume* SMDS_Mesh::AddVolumeFromVtkIdsWithID(const std::vector<vtkIdType>& vtkNodeIds, const int ID)
1513 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
1514 volvtk->init(vtkNodeIds, this);
1515 if (!this->registerElement(ID,volvtk))
1517 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
1518 myVolumePool->destroy(volvtk);
1521 adjustmyCellsCapacity(ID);
1522 myCells[ID] = volvtk;
1523 vtkIdType aVtkType = volvtk->GetVtkType();
1527 myInfo.myNbTetras++;
1530 myInfo.myNbPyramids++;
1533 myInfo.myNbPrisms++;
1535 case VTK_HEXAHEDRON:
1538 case VTK_QUADRATIC_TETRA:
1539 myInfo.myNbQuadTetras++;
1541 case VTK_QUADRATIC_PYRAMID:
1542 myInfo.myNbQuadPyramids++;
1544 case VTK_QUADRATIC_WEDGE:
1545 myInfo.myNbQuadPrisms++;
1547 case VTK_QUADRATIC_HEXAHEDRON:
1548 myInfo.myNbQuadHexas++;
1550 //#ifdef VTK_HAVE_POLYHEDRON
1551 case VTK_POLYHEDRON:
1552 myInfo.myNbPolyhedrons++;
1556 myInfo.myNbPolyhedrons++;
1562 SMDS_MeshFace* SMDS_Mesh::AddFaceFromVtkIds(const std::vector<vtkIdType>& vtkNodeIds)
1564 int ID = myElementIDFactory->GetFreeID();
1565 SMDS_MeshFace * f = SMDS_Mesh::AddFaceFromVtkIdsWithID(vtkNodeIds, ID);
1566 if (f == NULL) myElementIDFactory->ReleaseID(ID);
1570 SMDS_MeshFace* SMDS_Mesh::AddFaceFromVtkIdsWithID(const std::vector<vtkIdType>& vtkNodeIds, const int ID)
1572 SMDS_VtkFace *facevtk = myFacePool->getNew();
1573 facevtk->init(vtkNodeIds, this);
1574 if (!this->registerElement(ID,facevtk))
1576 this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL);
1577 myFacePool->destroy(facevtk);
1580 adjustmyCellsCapacity(ID);
1581 myCells[ID] = facevtk;
1582 vtkIdType aVtkType = facevtk->GetVtkType();
1586 myInfo.myNbTriangles++;
1589 myInfo.myNbQuadrangles++;
1591 case VTK_QUADRATIC_TRIANGLE:
1592 myInfo.myNbQuadTriangles++;
1594 case VTK_QUADRATIC_QUAD:
1595 myInfo.myNbQuadQuadrangles++;
1597 case VTK_BIQUADRATIC_QUAD:
1598 myInfo.myNbBiQuadQuadrangles++;
1601 myInfo.myNbPolygons++;
1604 myInfo.myNbPolygons++;
1609 ///////////////////////////////////////////////////////////////////////////////
1610 /// Registers element with the given ID, maintains inverse connections
1611 ///////////////////////////////////////////////////////////////////////////////
1612 bool SMDS_Mesh::registerElement(int ID, SMDS_MeshElement* element)
1614 //MESSAGE("registerElement " << ID);
1615 if ((ID >=0) && (ID < myCells.size()) && myCells[ID]) // --- already bound
1617 MESSAGE(" ------------------ already bound "<< ID << " " << myCells[ID]->getVtkId());
1622 element->myMeshId = myMeshId;
1624 SMDS_MeshCell *cell = dynamic_cast<SMDS_MeshCell*>(element);
1626 int vtkId = cell->getVtkId();
1628 vtkId = myElementIDFactory->SetInVtkGrid(element);
1630 if (vtkId >= myCellIdVtkToSmds.size()) // --- resize local vector
1632 // MESSAGE(" --------------------- resize myCellIdVtkToSmds " << vtkId << " --> " << vtkId + SMDS_Mesh::chunkSize);
1633 myCellIdVtkToSmds.resize(vtkId + SMDS_Mesh::chunkSize, -1);
1635 myCellIdVtkToSmds[vtkId] = ID;
1637 myElementIDFactory->updateMinMax(ID);
1641 ///////////////////////////////////////////////////////////////////////////////
1642 /// Return the node whose SMDS ID is 'ID'.
1643 ///////////////////////////////////////////////////////////////////////////////
1644 const SMDS_MeshNode * SMDS_Mesh::FindNode(int ID) const
1646 if (ID < 1 || ID >= myNodes.size())
1648 // MESSAGE("------------------------------------------------------------------------- ");
1649 // MESSAGE("----------------------------------- bad ID " << ID << " " << myNodes.size());
1650 // MESSAGE("------------------------------------------------------------------------- ");
1653 return (const SMDS_MeshNode *)myNodes[ID];
1656 ///////////////////////////////////////////////////////////////////////////////
1657 /// Return the node whose VTK ID is 'vtkId'.
1658 ///////////////////////////////////////////////////////////////////////////////
1659 const SMDS_MeshNode * SMDS_Mesh::FindNodeVtk(int vtkId) const
1661 // TODO if needed use mesh->nodeIdFromVtkToSmds
1662 if (vtkId < 0 || vtkId >= (myNodes.size() -1))
1664 MESSAGE("------------------------------------------------------------------------- ");
1665 MESSAGE("---------------------------- bad VTK ID " << vtkId << " " << myNodes.size());
1666 MESSAGE("------------------------------------------------------------------------- ");
1669 return (const SMDS_MeshNode *)myNodes[vtkId+1];
1672 ///////////////////////////////////////////////////////////////////////////////
1673 ///Create a triangle and add it to the current mesh. This method do not bind an
1674 ///ID to the create triangle.
1675 ///////////////////////////////////////////////////////////////////////////////
1676 SMDS_MeshFace * SMDS_Mesh::createTriangle(const SMDS_MeshNode * node1,
1677 const SMDS_MeshNode * node2,
1678 const SMDS_MeshNode * node3,
1681 if ( !node1 || !node2 || !node3) return 0;
1682 if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1683 if(hasConstructionEdges())
1685 SMDS_MeshEdge *edge1, *edge2, *edge3;
1686 edge1=FindEdgeOrCreate(node1,node2);
1687 edge2=FindEdgeOrCreate(node2,node3);
1688 edge3=FindEdgeOrCreate(node3,node1);
1690 //int ID = myElementIDFactory->GetFreeID(); // -PR- voir si on range cet element
1691 SMDS_MeshFace * face = new SMDS_FaceOfEdges(edge1,edge2,edge3);
1692 adjustmyCellsCapacity(ID);
1694 myInfo.myNbTriangles++;
1699 // --- retrieve nodes ID
1700 vector<vtkIdType> nodeIds;
1702 nodeIds.push_back(node1->getVtkId());
1703 nodeIds.push_back(node2->getVtkId());
1704 nodeIds.push_back(node3->getVtkId());
1706 SMDS_MeshFace * face = 0;
1707 SMDS_VtkFace *facevtk = myFacePool->getNew();
1708 facevtk->init(nodeIds, this); // put in vtkUnstructuredGrid
1709 if (!this->registerElement(ID,facevtk))
1711 this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL);
1712 myFacePool->destroy(facevtk);
1716 adjustmyCellsCapacity(ID);
1718 //MESSAGE("createTriangle " << ID << " " << face);
1719 myInfo.myNbTriangles++;
1724 ///////////////////////////////////////////////////////////////////////////////
1725 ///Create a quadrangle and add it to the current mesh. This methode do not bind
1726 ///a ID to the create triangle.
1727 ///////////////////////////////////////////////////////////////////////////////
1728 SMDS_MeshFace * SMDS_Mesh::createQuadrangle(const SMDS_MeshNode * node1,
1729 const SMDS_MeshNode * node2,
1730 const SMDS_MeshNode * node3,
1731 const SMDS_MeshNode * node4,
1734 if ( !node1 || !node2 || !node3 || !node4 ) return 0;
1735 if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
1736 if(hasConstructionEdges())
1738 //MESSAGE("createQuadrangle hasConstructionEdges "<< ID);
1739 SMDS_MeshEdge *edge1, *edge2, *edge3, *edge4;
1740 edge1=FindEdgeOrCreate(node1,node2);
1741 edge2=FindEdgeOrCreate(node2,node3);
1742 edge3=FindEdgeOrCreate(node3,node4);
1743 edge4=FindEdgeOrCreate(node4,node1);
1745 SMDS_MeshFace * face = new SMDS_FaceOfEdges(edge1,edge2,edge3,edge4);
1746 adjustmyCellsCapacity(ID);
1748 myInfo.myNbQuadrangles++;
1753 // --- retrieve nodes ID
1754 vector<vtkIdType> nodeIds;
1756 nodeIds.push_back(node1->getVtkId());
1757 nodeIds.push_back(node2->getVtkId());
1758 nodeIds.push_back(node3->getVtkId());
1759 nodeIds.push_back(node4->getVtkId());
1761 SMDS_MeshFace * face = 0;
1762 SMDS_VtkFace *facevtk = myFacePool->getNew();
1763 facevtk->init(nodeIds, this);
1764 if (!this->registerElement(ID,facevtk))
1766 this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL);
1767 myFacePool->destroy(facevtk);
1771 adjustmyCellsCapacity(ID);
1773 myInfo.myNbQuadrangles++;
1778 ///////////////////////////////////////////////////////////////////////////////
1779 /// Remove a node and all the elements which own this node
1780 ///////////////////////////////////////////////////////////////////////////////
1782 void SMDS_Mesh::RemoveNode(const SMDS_MeshNode * node)
1784 MESSAGE("RemoveNode");
1785 RemoveElement(node, true);
1788 ///////////////////////////////////////////////////////////////////////////////
1789 /// Remove an edge and all the elements which own this edge
1790 ///////////////////////////////////////////////////////////////////////////////
1792 void SMDS_Mesh::Remove0DElement(const SMDS_Mesh0DElement * elem0d)
1794 MESSAGE("Remove0DElement");
1795 RemoveElement(elem0d,true);
1798 ///////////////////////////////////////////////////////////////////////////////
1799 /// Remove an edge and all the elements which own this edge
1800 ///////////////////////////////////////////////////////////////////////////////
1802 void SMDS_Mesh::RemoveEdge(const SMDS_MeshEdge * edge)
1804 MESSAGE("RemoveEdge");
1805 RemoveElement(edge,true);
1808 ///////////////////////////////////////////////////////////////////////////////
1809 /// Remove an face and all the elements which own this face
1810 ///////////////////////////////////////////////////////////////////////////////
1812 void SMDS_Mesh::RemoveFace(const SMDS_MeshFace * face)
1814 MESSAGE("RemoveFace");
1815 RemoveElement(face, true);
1818 ///////////////////////////////////////////////////////////////////////////////
1820 ///////////////////////////////////////////////////////////////////////////////
1822 void SMDS_Mesh::RemoveVolume(const SMDS_MeshVolume * volume)
1824 MESSAGE("RemoveVolume");
1825 RemoveElement(volume, true);
1828 //=======================================================================
1829 //function : RemoveFromParent
1831 //=======================================================================
1833 bool SMDS_Mesh::RemoveFromParent()
1835 if (myParent==NULL) return false;
1836 else return (myParent->RemoveSubMesh(this));
1839 //=======================================================================
1840 //function : RemoveSubMesh
1842 //=======================================================================
1844 bool SMDS_Mesh::RemoveSubMesh(const SMDS_Mesh * aMesh)
1848 list<SMDS_Mesh *>::iterator itmsh=myChildren.begin();
1849 for (; itmsh!=myChildren.end() && !found; itmsh++)
1851 SMDS_Mesh * submesh = *itmsh;
1852 if (submesh == aMesh)
1855 myChildren.erase(itmsh);
1862 //=======================================================================
1863 //function : ChangeElementNodes
1865 //=======================================================================
1867 bool SMDS_Mesh::ChangeElementNodes(const SMDS_MeshElement * element,
1868 const SMDS_MeshNode * nodes[],
1871 MESSAGE("SMDS_Mesh::ChangeElementNodes");
1872 // keep current nodes of elem
1873 set<const SMDS_MeshNode*> oldNodes( element->begin_nodes(), element->end_nodes() );
1877 SMDS_MeshCell* cell = dynamic_cast<SMDS_MeshCell*>((SMDS_MeshElement*) element);
1880 Ok = cell->vtkOrder(nodes, nbnodes);
1881 Ok = cell->ChangeNodes(nodes, nbnodes);
1884 if ( Ok ) { // update InverseElements
1886 set<const SMDS_MeshNode*>::iterator it;
1888 // AddInverseElement to new nodes
1889 for ( int i = 0; i < nbnodes; i++ ) {
1890 it = oldNodes.find( nodes[i] );
1891 if ( it == oldNodes.end() )
1893 const_cast<SMDS_MeshNode*>( nodes[i] )->AddInverseElement( cell );
1895 // remove from oldNodes a node that remains in elem
1896 oldNodes.erase( it );
1898 // RemoveInverseElement from the nodes removed from elem
1899 for ( it = oldNodes.begin(); it != oldNodes.end(); it++ )
1901 SMDS_MeshNode * n = const_cast<SMDS_MeshNode *>( *it );
1902 n->RemoveInverseElement( cell );
1909 //=======================================================================
1910 //function : ChangePolyhedronNodes
1911 //purpose : to change nodes of polyhedral volume
1912 //=======================================================================
1913 bool SMDS_Mesh::ChangePolyhedronNodes (const SMDS_MeshElement * elem,
1914 const vector<const SMDS_MeshNode*>& nodes,
1915 const vector<int> & quantities)
1917 if (elem->GetType() != SMDSAbs_Volume) {
1918 MESSAGE("WRONG ELEM TYPE");
1922 const SMDS_VtkVolume* vol = dynamic_cast<const SMDS_VtkVolume*>(elem);
1927 // keep current nodes of elem
1928 set<const SMDS_MeshElement*> oldNodes;
1929 SMDS_ElemIteratorPtr itn = elem->nodesIterator();
1930 while (itn->more()) {
1931 oldNodes.insert(itn->next());
1935 // TODO remove this function
1936 //bool Ok = const_cast<SMDS_VtkVolume*>(vol)->ChangeNodes(nodes, quantities);
1942 // update InverseElements
1944 // AddInverseElement to new nodes
1945 int nbnodes = nodes.size();
1946 set<const SMDS_MeshElement*>::iterator it;
1947 for (int i = 0; i < nbnodes; i++) {
1948 it = oldNodes.find(nodes[i]);
1949 if (it == oldNodes.end()) {
1951 const_cast<SMDS_MeshNode*>(nodes[i])->AddInverseElement(elem);
1953 // remove from oldNodes a node that remains in elem
1958 // RemoveInverseElement from the nodes removed from elem
1959 for (it = oldNodes.begin(); it != oldNodes.end(); it++) {
1960 SMDS_MeshNode * n = static_cast<SMDS_MeshNode *>
1961 (const_cast<SMDS_MeshElement *>( *it ));
1962 n->RemoveInverseElement(elem);
1969 //=======================================================================
1970 //function : Find0DElement
1972 //=======================================================================
1973 const SMDS_Mesh0DElement* SMDS_Mesh::Find0DElement(int idnode) const
1975 const SMDS_MeshNode * node = FindNode(idnode);
1976 if(node == NULL) return NULL;
1977 return Find0DElement(node);
1980 const SMDS_Mesh0DElement* SMDS_Mesh::Find0DElement(const SMDS_MeshNode * node)
1982 if (!node) return 0;
1983 const SMDS_Mesh0DElement* toReturn = NULL;
1984 SMDS_ElemIteratorPtr it1 = node->GetInverseElementIterator(SMDSAbs_0DElement);
1985 while (it1->more() && (toReturn == NULL)) {
1986 const SMDS_MeshElement* e = it1->next();
1987 if (e->NbNodes() == 1) {
1988 toReturn = static_cast<const SMDS_Mesh0DElement*>(e);
1994 //=======================================================================
1995 //function : FindBall
1997 //=======================================================================
1999 const SMDS_BallElement* SMDS_Mesh::FindBall(int idnode) const
2001 const SMDS_MeshNode * node = FindNode(idnode);
2002 if(node == NULL) return NULL;
2003 return FindBall(node);
2006 const SMDS_BallElement* SMDS_Mesh::FindBall(const SMDS_MeshNode * node)
2008 if (!node) return 0;
2009 const SMDS_BallElement* toReturn = NULL;
2010 SMDS_ElemIteratorPtr it1 = node->GetInverseElementIterator(SMDSAbs_Ball);
2011 while (it1->more() && (toReturn == NULL)) {
2012 const SMDS_MeshElement* e = it1->next();
2013 if (e->GetGeomType() == SMDSGeom_BALL)
2014 toReturn = static_cast<const SMDS_BallElement*>(e);
2019 //=======================================================================
2020 //function : Find0DElementOrCreate
2022 //=======================================================================
2023 //SMDS_Mesh0DElement* SMDS_Mesh::Find0DElementOrCreate(const SMDS_MeshNode * node)
2025 // if (!node) return 0;
2026 // SMDS_Mesh0DElement * toReturn = NULL;
2027 // toReturn = const_cast<SMDS_Mesh0DElement*>(Find0DElement(node));
2028 // if (toReturn == NULL) {
2029 // //if (my0DElements.Extent() % CHECKMEMORY_INTERVAL == 0) CheckMemory();
2030 // toReturn = new SMDS_Mesh0DElement(node);
2031 // my0DElements.Add(toReturn);
2032 // myInfo.myNb0DElements++;
2038 //=======================================================================
2039 //function : FindEdge
2041 //=======================================================================
2043 const SMDS_MeshEdge* SMDS_Mesh::FindEdge(int idnode1, int idnode2) const
2045 const SMDS_MeshNode * node1=FindNode(idnode1);
2046 const SMDS_MeshNode * node2=FindNode(idnode2);
2047 if((node1==NULL)||(node2==NULL)) return NULL;
2048 return FindEdge(node1,node2);
2051 //#include "Profiler.h"
2052 const SMDS_MeshEdge* SMDS_Mesh::FindEdge(const SMDS_MeshNode * node1,
2053 const SMDS_MeshNode * node2)
2055 if ( !node1 ) return 0;
2056 const SMDS_MeshEdge * toReturn=NULL;
2059 SMDS_ElemIteratorPtr it1=node1->GetInverseElementIterator(SMDSAbs_Edge);
2062 while(it1->more()) {
2063 const SMDS_MeshElement * e = it1->next();
2064 if ( e->NbNodes() == 2 && e->GetNodeIndex( node2 ) >= 0 ) {
2065 toReturn = static_cast<const SMDS_MeshEdge*>( e );
2074 //=======================================================================
2075 //function : FindEdgeOrCreate
2077 //=======================================================================
2079 SMDS_MeshEdge* SMDS_Mesh::FindEdgeOrCreate(const SMDS_MeshNode * node1,
2080 const SMDS_MeshNode * node2)
2082 if ( !node1 || !node2) return 0;
2083 SMDS_MeshEdge * toReturn=NULL;
2084 toReturn=const_cast<SMDS_MeshEdge*>(FindEdge(node1,node2));
2085 if(toReturn==NULL) {
2086 if ( NbEdges() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
2087 int ID = myElementIDFactory->GetFreeID(); // -PR- voir si on range cet element
2088 adjustmyCellsCapacity(ID);
2089 vector<vtkIdType> nodeIds;
2091 nodeIds.push_back(node1->getVtkId());
2092 nodeIds.push_back(node2->getVtkId());
2094 SMDS_VtkEdge *edgevtk = myEdgePool->getNew();
2095 edgevtk->init(nodeIds, this);
2096 if (!this->registerElement(ID,edgevtk))
2098 this->myGrid->GetCellTypesArray()->SetValue(edgevtk->getVtkId(), VTK_EMPTY_CELL);
2099 myEdgePool->destroy(edgevtk);
2103 myCells[ID] = toReturn;
2110 //=======================================================================
2111 //function : FindEdge
2113 //=======================================================================
2115 const SMDS_MeshEdge* SMDS_Mesh::FindEdge(int idnode1, int idnode2,
2118 const SMDS_MeshNode * node1=FindNode(idnode1);
2119 const SMDS_MeshNode * node2=FindNode(idnode2);
2120 const SMDS_MeshNode * node3=FindNode(idnode3);
2121 return FindEdge(node1,node2,node3);
2124 const SMDS_MeshEdge* SMDS_Mesh::FindEdge(const SMDS_MeshNode * node1,
2125 const SMDS_MeshNode * node2,
2126 const SMDS_MeshNode * node3)
2128 if ( !node1 ) return 0;
2129 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Edge);
2130 while(it1->more()) {
2131 const SMDS_MeshElement * e = it1->next();
2132 if ( e->NbNodes() == 3 ) {
2133 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
2134 while(it2->more()) {
2135 const SMDS_MeshElement* n = it2->next();
2145 return static_cast<const SMDS_MeshEdge *> (e);
2152 //=======================================================================
2153 //function : FindFace
2155 //=======================================================================
2157 const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2,
2160 const SMDS_MeshNode * node1=FindNode(idnode1);
2161 const SMDS_MeshNode * node2=FindNode(idnode2);
2162 const SMDS_MeshNode * node3=FindNode(idnode3);
2163 return FindFace(node1, node2, node3);
2166 const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1,
2167 const SMDS_MeshNode *node2,
2168 const SMDS_MeshNode *node3)
2170 if ( !node1 ) return 0;
2171 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Face);
2172 while(it1->more()) {
2173 const SMDS_MeshElement * e = it1->next();
2174 if ( e->NbNodes() == 3 ) {
2175 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
2176 while(it2->more()) {
2177 const SMDS_MeshElement* n = it2->next();
2187 return static_cast<const SMDS_MeshFace *> (e);
2193 SMDS_MeshFace* SMDS_Mesh::FindFaceOrCreate(const SMDS_MeshNode *node1,
2194 const SMDS_MeshNode *node2,
2195 const SMDS_MeshNode *node3)
2197 SMDS_MeshFace * toReturn=NULL;
2198 toReturn = const_cast<SMDS_MeshFace*>(FindFace(node1,node2,node3));
2199 if(toReturn==NULL) {
2200 int ID = myElementIDFactory->GetFreeID();
2201 toReturn = createTriangle(node1,node2,node3, ID);
2207 //=======================================================================
2208 //function : FindFace
2210 //=======================================================================
2212 const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2,
2213 int idnode3, int idnode4) const
2215 const SMDS_MeshNode * node1=FindNode(idnode1);
2216 const SMDS_MeshNode * node2=FindNode(idnode2);
2217 const SMDS_MeshNode * node3=FindNode(idnode3);
2218 const SMDS_MeshNode * node4=FindNode(idnode4);
2219 return FindFace(node1, node2, node3, node4);
2222 const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1,
2223 const SMDS_MeshNode *node2,
2224 const SMDS_MeshNode *node3,
2225 const SMDS_MeshNode *node4)
2227 if ( !node1 ) return 0;
2228 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Face);
2229 while(it1->more()) {
2230 const SMDS_MeshElement * e = it1->next();
2231 if ( e->NbNodes() == 4 ) {
2232 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
2233 while(it2->more()) {
2234 const SMDS_MeshElement* n = it2->next();
2245 return static_cast<const SMDS_MeshFace *> (e);
2251 SMDS_MeshFace* SMDS_Mesh::FindFaceOrCreate(const SMDS_MeshNode *node1,
2252 const SMDS_MeshNode *node2,
2253 const SMDS_MeshNode *node3,
2254 const SMDS_MeshNode *node4)
2256 SMDS_MeshFace * toReturn=NULL;
2257 toReturn=const_cast<SMDS_MeshFace*>(FindFace(node1,node2,node3,node4));
2258 if(toReturn==NULL) {
2259 int ID = myElementIDFactory->GetFreeID();
2260 toReturn=createQuadrangle(node1,node2,node3,node4,ID);
2266 //=======================================================================
2267 //function : FindFace
2268 //purpose :quadratic triangle
2269 //=======================================================================
2271 const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2,
2272 int idnode3, int idnode4,
2273 int idnode5, int idnode6) const
2275 const SMDS_MeshNode * node1 = FindNode(idnode1);
2276 const SMDS_MeshNode * node2 = FindNode(idnode2);
2277 const SMDS_MeshNode * node3 = FindNode(idnode3);
2278 const SMDS_MeshNode * node4 = FindNode(idnode4);
2279 const SMDS_MeshNode * node5 = FindNode(idnode5);
2280 const SMDS_MeshNode * node6 = FindNode(idnode6);
2281 return FindFace(node1, node2, node3, node4, node5, node6);
2284 const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1,
2285 const SMDS_MeshNode *node2,
2286 const SMDS_MeshNode *node3,
2287 const SMDS_MeshNode *node4,
2288 const SMDS_MeshNode *node5,
2289 const SMDS_MeshNode *node6)
2291 if ( !node1 ) return 0;
2292 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Face);
2293 while(it1->more()) {
2294 const SMDS_MeshElement * e = it1->next();
2295 if ( e->NbNodes() == 6 ) {
2296 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
2297 while(it2->more()) {
2298 const SMDS_MeshElement* n = it2->next();
2311 return static_cast<const SMDS_MeshFace *> (e);
2318 //=======================================================================
2319 //function : FindFace
2320 //purpose : quadratic quadrangle
2321 //=======================================================================
2323 const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2,
2324 int idnode3, int idnode4,
2325 int idnode5, int idnode6,
2326 int idnode7, int idnode8) const
2328 const SMDS_MeshNode * node1 = FindNode(idnode1);
2329 const SMDS_MeshNode * node2 = FindNode(idnode2);
2330 const SMDS_MeshNode * node3 = FindNode(idnode3);
2331 const SMDS_MeshNode * node4 = FindNode(idnode4);
2332 const SMDS_MeshNode * node5 = FindNode(idnode5);
2333 const SMDS_MeshNode * node6 = FindNode(idnode6);
2334 const SMDS_MeshNode * node7 = FindNode(idnode7);
2335 const SMDS_MeshNode * node8 = FindNode(idnode8);
2336 return FindFace(node1, node2, node3, node4, node5, node6, node7, node8);
2339 const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1,
2340 const SMDS_MeshNode *node2,
2341 const SMDS_MeshNode *node3,
2342 const SMDS_MeshNode *node4,
2343 const SMDS_MeshNode *node5,
2344 const SMDS_MeshNode *node6,
2345 const SMDS_MeshNode *node7,
2346 const SMDS_MeshNode *node8)
2348 if ( !node1 ) return 0;
2349 SMDS_ElemIteratorPtr it1 = node1->GetInverseElementIterator(SMDSAbs_Face);
2350 while(it1->more()) {
2351 const SMDS_MeshElement * e = it1->next();
2352 if ( e->NbNodes() == 8 ) {
2353 SMDS_ElemIteratorPtr it2 = e->nodesIterator();
2354 while(it2->more()) {
2355 const SMDS_MeshElement* n = it2->next();
2370 return static_cast<const SMDS_MeshFace *> (e);
2377 //=======================================================================
2378 //function : FindElement
2380 //=======================================================================
2382 const SMDS_MeshElement* SMDS_Mesh::FindElement(int IDelem) const
2384 if ((IDelem <= 0) || IDelem >= myCells.size())
2386 MESSAGE("--------------------------------------------------------------------------------- ");
2387 MESSAGE("----------------------------------- bad IDelem " << IDelem << " " << myCells.size());
2388 MESSAGE("--------------------------------------------------------------------------------- ");
2389 // TODO raise an exception
2393 return myCells[IDelem];
2396 //=======================================================================
2397 //function : FindFace
2398 //purpose : find polygon
2399 //=======================================================================
2401 const SMDS_MeshFace* SMDS_Mesh::FindFace (const vector<int>& nodes_ids) const
2403 int nbnodes = nodes_ids.size();
2404 vector<const SMDS_MeshNode *> poly_nodes (nbnodes);
2405 for (int inode = 0; inode < nbnodes; inode++) {
2406 const SMDS_MeshNode * node = FindNode(nodes_ids[inode]);
2407 if (node == NULL) return NULL;
2408 poly_nodes[inode] = node;
2410 return FindFace(poly_nodes);
2413 const SMDS_MeshFace* SMDS_Mesh::FindFace (const vector<const SMDS_MeshNode *>& nodes)
2415 return (const SMDS_MeshFace*) FindElement( nodes, SMDSAbs_Face );
2419 //================================================================================
2421 * \brief Return element based on all given nodes
2422 * \param nodes - node of element
2423 * \param type - type of element
2424 * \param noMedium - true if medium nodes of quadratic element are not included in <nodes>
2425 * \retval const SMDS_MeshElement* - found element or NULL
2427 //================================================================================
2429 const SMDS_MeshElement* SMDS_Mesh::FindElement (const vector<const SMDS_MeshNode *>& nodes,
2430 const SMDSAbs_ElementType type,
2431 const bool noMedium)
2433 if ( nodes.size() > 0 && nodes[0] )
2435 SMDS_ElemIteratorPtr itF = nodes[0]->GetInverseElementIterator(type);
2438 const SMDS_MeshElement* e = itF->next();
2439 int nbNodesToCheck = noMedium ? e->NbCornerNodes() : e->NbNodes();
2440 if ( nbNodesToCheck == nodes.size() )
2442 for ( int i = 1; e && i < nodes.size(); ++ i )
2444 int nodeIndex = e->GetNodeIndex( nodes[ i ]);
2445 if ( nodeIndex < 0 || nodeIndex >= nbNodesToCheck )
2449 return static_cast<const SMDS_MeshFace *> (e);
2456 //=======================================================================
2457 //function : DumpNodes
2459 //=======================================================================
2461 void SMDS_Mesh::DumpNodes() const
2463 MESSAGE("dump nodes of mesh : ");
2464 SMDS_NodeIteratorPtr itnode=nodesIterator();
2465 while(itnode->more()) ; //MESSAGE(itnode->next());
2468 //=======================================================================
2469 //function : Dump0DElements
2471 //=======================================================================
2472 void SMDS_Mesh::Dump0DElements() const
2474 MESSAGE("dump 0D elements of mesh : ");
2475 SMDS_ElemIteratorPtr it0d = elementsIterator(SMDSAbs_0DElement);
2476 while(it0d->more()) ; //MESSAGE(it0d->next());
2479 //=======================================================================
2480 //function : DumpEdges
2482 //=======================================================================
2484 void SMDS_Mesh::DumpEdges() const
2486 MESSAGE("dump edges of mesh : ");
2487 SMDS_EdgeIteratorPtr itedge=edgesIterator();
2488 while(itedge->more()) ; //MESSAGE(itedge->next());
2491 //=======================================================================
2492 //function : DumpFaces
2494 //=======================================================================
2496 void SMDS_Mesh::DumpFaces() const
2498 MESSAGE("dump faces of mesh : ");
2499 SMDS_FaceIteratorPtr itface=facesIterator();
2500 while(itface->more()) ; //MESSAGE(itface->next());
2503 //=======================================================================
2504 //function : DumpVolumes
2506 //=======================================================================
2508 void SMDS_Mesh::DumpVolumes() const
2510 MESSAGE("dump volumes of mesh : ");
2511 SMDS_VolumeIteratorPtr itvol=volumesIterator();
2512 while(itvol->more()) ; //MESSAGE(itvol->next());
2515 //=======================================================================
2516 //function : DebugStats
2518 //=======================================================================
2520 void SMDS_Mesh::DebugStats() const
2522 MESSAGE("Debug stats of mesh : ");
2524 MESSAGE("===== NODES ====="<<NbNodes());
2525 MESSAGE("===== 0DELEMS ====="<<Nb0DElements());
2526 MESSAGE("===== EDGES ====="<<NbEdges());
2527 MESSAGE("===== FACES ====="<<NbFaces());
2528 MESSAGE("===== VOLUMES ====="<<NbVolumes());
2530 MESSAGE("End Debug stats of mesh ");
2534 SMDS_NodeIteratorPtr itnode=nodesIterator();
2535 int sizeofnodes = 0;
2536 int sizeoffaces = 0;
2538 while(itnode->more())
2540 const SMDS_MeshNode *node = itnode->next();
2542 sizeofnodes += sizeof(*node);
2544 SMDS_ElemIteratorPtr it = node->GetInverseElementIterator();
2547 const SMDS_MeshElement *me = it->next();
2548 sizeofnodes += sizeof(me);
2552 SMDS_FaceIteratorPtr itface=facesIterator();
2553 while(itface->more())
2555 const SMDS_MeshElement *face = itface->next();
2556 sizeoffaces += sizeof(*face);
2559 MESSAGE("total size of node elements = " << sizeofnodes);;
2560 MESSAGE("total size of face elements = " << sizeoffaces);;
2565 ///////////////////////////////////////////////////////////////////////////////
2566 /// Return the number of nodes
2567 ///////////////////////////////////////////////////////////////////////////////
2568 int SMDS_Mesh::NbNodes() const
2570 //MESSAGE(myGrid->GetNumberOfPoints());
2571 //MESSAGE(myInfo.NbNodes());
2572 //MESSAGE(myNodeMax);
2573 return myInfo.NbNodes();
2576 ///////////////////////////////////////////////////////////////////////////////
2577 /// Return the number of 0D elements
2578 ///////////////////////////////////////////////////////////////////////////////
2579 int SMDS_Mesh::Nb0DElements() const
2581 return myInfo.Nb0DElements();
2584 ///////////////////////////////////////////////////////////////////////////////
2585 /// Return the number of 0D elements
2586 ///////////////////////////////////////////////////////////////////////////////
2587 int SMDS_Mesh::NbBalls() const
2589 return myInfo.NbBalls();
2592 ///////////////////////////////////////////////////////////////////////////////
2593 /// Return the number of edges (including construction edges)
2594 ///////////////////////////////////////////////////////////////////////////////
2595 int SMDS_Mesh::NbEdges() const
2597 return myInfo.NbEdges();
2600 ///////////////////////////////////////////////////////////////////////////////
2601 /// Return the number of faces (including construction faces)
2602 ///////////////////////////////////////////////////////////////////////////////
2603 int SMDS_Mesh::NbFaces() const
2605 return myInfo.NbFaces();
2608 ///////////////////////////////////////////////////////////////////////////////
2609 /// Return the number of volumes
2610 ///////////////////////////////////////////////////////////////////////////////
2611 int SMDS_Mesh::NbVolumes() const
2613 return myInfo.NbVolumes();
2616 ///////////////////////////////////////////////////////////////////////////////
2617 /// Return the number of child mesh of this mesh.
2618 /// Note that the tree structure of SMDS_Mesh is unused in SMESH
2619 ///////////////////////////////////////////////////////////////////////////////
2620 int SMDS_Mesh::NbSubMesh() const
2622 return myChildren.size();
2625 ///////////////////////////////////////////////////////////////////////////////
2626 /// Destroy the mesh and all its elements
2627 /// All pointer on elements owned by this mesh become illegals.
2628 ///////////////////////////////////////////////////////////////////////////////
2629 SMDS_Mesh::~SMDS_Mesh()
2631 list<SMDS_Mesh*>::iterator itc=myChildren.begin();
2632 while(itc!=myChildren.end())
2640 delete myNodeIDFactory;
2641 delete myElementIDFactory;
2645 SMDS_ElemIteratorPtr eIt = elementsIterator();
2646 while ( eIt->more() )
2648 const SMDS_MeshElement *elem = eIt->next();
2649 myElementIDFactory->ReleaseID(elem->GetID(), elem->getVtkId());
2651 SMDS_NodeIteratorPtr itn = nodesIterator();
2654 const SMDS_MeshNode *node = itn->next();
2655 ((SMDS_MeshNode*)node)->SetPosition(SMDS_SpacePosition::originSpacePosition());
2656 myNodeIDFactory->ReleaseID(node->GetID(), node->getVtkId());
2661 //================================================================================
2663 * \brief Clear all data
2665 //================================================================================
2667 void SMDS_Mesh::Clear()
2669 MESSAGE("SMDS_Mesh::Clear");
2672 SMDS_ElemIteratorPtr eIt = elementsIterator();
2673 while ( eIt->more() )
2675 const SMDS_MeshElement *elem = eIt->next();
2676 myElementIDFactory->ReleaseID(elem->GetID(), elem->getVtkId());
2678 SMDS_NodeIteratorPtr itn = nodesIterator();
2681 const SMDS_MeshNode *node = itn->next();
2682 myNodeIDFactory->ReleaseID(node->GetID(), node->getVtkId());
2687 myNodeIDFactory->Clear();
2688 myElementIDFactory->Clear();
2691 SMDS_ElemIteratorPtr itv = elementsIterator();
2694 SMDS_MeshElement* elem = (SMDS_MeshElement*)(itv->next());
2695 SMDSAbs_ElementType aType = elem->GetType();
2698 case SMDSAbs_0DElement:
2702 myEdgePool->destroy(static_cast<SMDS_VtkEdge*>(elem));
2705 myFacePool->destroy(static_cast<SMDS_VtkFace*>(elem));
2707 case SMDSAbs_Volume:
2708 myVolumePool->destroy(static_cast<SMDS_VtkVolume*>(elem));
2711 myBallPool->destroy(static_cast<SMDS_BallElement*>(elem));
2718 myCellIdVtkToSmds.clear();
2719 //myCellIdSmdsToVtk.clear();
2721 SMDS_NodeIteratorPtr itn = nodesIterator();
2724 SMDS_MeshNode *node = (SMDS_MeshNode*)(itn->next());
2725 node->SetPosition(SMDS_SpacePosition::originSpacePosition());
2726 myNodePool->destroy(node);
2730 list<SMDS_Mesh*>::iterator itc=myChildren.begin();
2731 while(itc!=myChildren.end())
2741 myGrid->Initialize();
2743 vtkPoints* points = vtkPoints::New();
2744 // rnv: to fix bug "21125: EDF 1233 SMESH: Degrardation of precision in a test case for quadratic conversion"
2745 // using double type for storing coordinates of nodes instead float.
2746 points->SetDataType(VTK_DOUBLE);
2747 points->SetNumberOfPoints(0 /*SMDS_Mesh::chunkSize*/);
2748 myGrid->SetPoints( points );
2750 myGrid->BuildLinks();
2753 ///////////////////////////////////////////////////////////////////////////////
2754 /// Return true if this mesh create faces with edges.
2755 /// A false returned value mean that faces are created with nodes. A concequence
2756 /// is, iteration on edges (SMDS_Element::edgesIterator) will be unavailable.
2757 ///////////////////////////////////////////////////////////////////////////////
2758 bool SMDS_Mesh::hasConstructionEdges()
2760 return myHasConstructionEdges;
2763 ///////////////////////////////////////////////////////////////////////////////
2764 /// Return true if this mesh create volumes with faces
2765 /// A false returned value mean that volumes are created with nodes or edges.
2766 /// (see hasConstructionEdges)
2767 /// A concequence is, iteration on faces (SMDS_Element::facesIterator) will be
2769 ///////////////////////////////////////////////////////////////////////////////
2770 bool SMDS_Mesh::hasConstructionFaces()
2772 return myHasConstructionFaces;
2775 ///////////////////////////////////////////////////////////////////////////////
2776 /// Return true if nodes are linked to the finit elements, they are belonging to.
2777 /// Currently, It always return true.
2778 ///////////////////////////////////////////////////////////////////////////////
2779 bool SMDS_Mesh::hasInverseElements()
2781 return myHasInverseElements;
2784 ///////////////////////////////////////////////////////////////////////////////
2785 /// Make this mesh creating construction edges (see hasConstructionEdges)
2786 /// @param b true to have construction edges, else false.
2787 ///////////////////////////////////////////////////////////////////////////////
2788 void SMDS_Mesh::setConstructionEdges(bool b)
2790 myHasConstructionEdges=b;
2793 ///////////////////////////////////////////////////////////////////////////////
2794 /// Make this mesh creating construction faces (see hasConstructionFaces)
2795 /// @param b true to have construction faces, else false.
2796 ///////////////////////////////////////////////////////////////////////////////
2797 void SMDS_Mesh::setConstructionFaces(bool b)
2799 myHasConstructionFaces=b;
2802 ///////////////////////////////////////////////////////////////////////////////
2803 /// Make this mesh creating link from nodes to elements (see hasInverseElements)
2804 /// @param b true to link nodes to elements, else false.
2805 ///////////////////////////////////////////////////////////////////////////////
2806 void SMDS_Mesh::setInverseElements(bool b)
2808 if(!b) MESSAGE("Error : inverseElement=false not implemented");
2809 myHasInverseElements=b;
2814 //================================================================================
2816 * \brief Iterator on elements in id increasing order
2818 //================================================================================
2820 template <typename ELEM=const SMDS_MeshElement*>
2821 class IdSortedIterator : public SMDS_Iterator<ELEM>
2823 SMDS_MeshElementIDFactory& myIDFact;
2824 int myID, myMaxID, myNbFound, myTotalNb;
2825 SMDSAbs_ElementType myType;
2829 IdSortedIterator(const SMDS_MeshElementIDFactory& fact,
2830 const SMDSAbs_ElementType type, // SMDSAbs_All NOT allowed!!!
2833 myID(1), myMaxID( myIDFact.GetMaxID() ),myNbFound(0), myTotalNb( totalNb ),
2845 ELEM current = myElem;
2847 for ( myElem = 0; !myElem && myNbFound < myTotalNb && myID <= myMaxID; ++myID )
2848 if ((myElem = (ELEM) myIDFact.MeshElement( myID ))
2849 && myElem->GetType() != myType )
2852 myNbFound += bool(myElem);
2858 typedef SMDS::NonNullFilter<const SMDS_MeshNode*> NonNullNodeFilter;
2859 typedef SMDS::NonNullFilter<const SMDS_MeshElement*> NonNullElemFilter;
2860 typedef SMDS_Mesh::SetOfNodes::const_iterator SetOfNodesIter;
2861 typedef SMDS_Mesh::SetOfCells::const_iterator SetOfCellsIter;
2862 typedef SMDS::SimpleAccessor<const SMDS_MeshNode*, SetOfNodesIter> NodeInSetOfNodes;
2863 typedef SMDS::SimpleAccessor<const SMDS_MeshElement*,SetOfCellsIter> CellInSetOfCells;
2865 #define TypedElemIterator(elemType) \
2866 SMDS_SetIterator < const elemType*, \
2868 SMDS::SimpleAccessor<const elemType*,SetOfCellsIter>, \
2869 SMDS_MeshElement::TypeFilter \
2873 ///////////////////////////////////////////////////////////////////////////////
2874 /// Return an iterator on nodes of the current mesh factory
2875 ///////////////////////////////////////////////////////////////////////////////
2877 SMDS_NodeIteratorPtr SMDS_Mesh::nodesIterator(bool idInceasingOrder) const
2879 typedef SMDS_SetIterator
2880 <const SMDS_MeshNode*, SetOfNodesIter, NodeInSetOfNodes, NonNullNodeFilter> TIterator;
2881 // naturally always sorted by ID
2882 return SMDS_NodeIteratorPtr( new TIterator(myNodes.begin(), myNodes.end()));
2885 SMDS_ElemIteratorPtr SMDS_Mesh::elementGeomIterator(SMDSAbs_GeometryType type) const
2887 typedef SMDS_SetIterator
2888 < const SMDS_MeshElement*, SetOfCellsIter, CellInSetOfCells, SMDS_MeshElement::GeomFilter >
2890 // naturally always sorted by ID
2891 return SMDS_ElemIteratorPtr
2892 (new TIterator(myCells.begin(), myCells.end(), SMDS_MeshElement::GeomFilter( type )));
2895 SMDS_ElemIteratorPtr SMDS_Mesh::elementEntityIterator(SMDSAbs_EntityType type) const
2897 typedef SMDS_SetIterator
2898 < const SMDS_MeshElement*, SetOfCellsIter, CellInSetOfCells, SMDS_MeshElement::EntityFilter >
2900 // naturally always sorted by ID
2901 return SMDS_ElemIteratorPtr
2902 (new TIterator(myCells.begin(), myCells.end(), SMDS_MeshElement::EntityFilter( type )));
2905 ///////////////////////////////////////////////////////////////////////////////
2906 /// Return an iterator on elements of the current mesh factory
2907 ///////////////////////////////////////////////////////////////////////////////
2908 SMDS_ElemIteratorPtr SMDS_Mesh::elementsIterator(SMDSAbs_ElementType type) const
2910 // naturally always sorted by ID
2911 if ( type == SMDSAbs_All )
2913 typedef SMDS_SetIterator
2914 < const SMDS_MeshElement*, SetOfCellsIter, CellInSetOfCells, NonNullElemFilter >
2916 return SMDS_ElemIteratorPtr (new TIterator(myCells.begin(), myCells.end()));
2920 typedef SMDS_SetIterator
2921 < const SMDS_MeshElement*, SetOfCellsIter, CellInSetOfCells, SMDS_MeshElement::TypeFilter >
2923 // naturally always sorted by ID
2924 return SMDS_ElemIteratorPtr
2925 (new TIterator(myCells.begin(), myCells.end(), SMDS_MeshElement::TypeFilter( type )));
2929 ///////////////////////////////////////////////////////////////////////////////
2930 ///Return an iterator on edges of the current mesh.
2931 ///////////////////////////////////////////////////////////////////////////////
2933 SMDS_EdgeIteratorPtr SMDS_Mesh::edgesIterator(bool idInceasingOrder) const
2935 // naturally always sorted by ID
2936 typedef TypedElemIterator( SMDS_MeshEdge ) TIterator;
2937 return SMDS_EdgeIteratorPtr
2938 (new TIterator(myCells.begin(), myCells.end(), SMDS_MeshElement::TypeFilter( SMDSAbs_Edge )));
2941 ///////////////////////////////////////////////////////////////////////////////
2942 ///Return an iterator on faces of the current mesh.
2943 ///////////////////////////////////////////////////////////////////////////////
2945 SMDS_FaceIteratorPtr SMDS_Mesh::facesIterator(bool idInceasingOrder) const
2947 // naturally always sorted by ID
2948 typedef TypedElemIterator( SMDS_MeshFace ) TIterator;
2949 return SMDS_FaceIteratorPtr
2950 (new TIterator(myCells.begin(), myCells.end(), SMDS_MeshElement::TypeFilter( SMDSAbs_Face )));
2953 ///////////////////////////////////////////////////////////////////////////////
2954 ///Return an iterator on volumes of the current mesh.
2955 ///////////////////////////////////////////////////////////////////////////////
2957 SMDS_VolumeIteratorPtr SMDS_Mesh::volumesIterator(bool idInceasingOrder) const
2959 // naturally always sorted by ID
2960 typedef TypedElemIterator( SMDS_MeshVolume ) TIterator;
2961 return SMDS_VolumeIteratorPtr
2962 (new TIterator(myCells.begin(), myCells.end(), SMDS_MeshElement::TypeFilter( SMDSAbs_Volume )));
2965 ///////////////////////////////////////////////////////////////////////////////
2966 /// Do intersection of sets (more than 2)
2967 ///////////////////////////////////////////////////////////////////////////////
2968 static set<const SMDS_MeshElement*> * intersectionOfSets(
2969 set<const SMDS_MeshElement*> vs[], int numberOfSets)
2971 set<const SMDS_MeshElement*>* rsetA=new set<const SMDS_MeshElement*>(vs[0]);
2972 set<const SMDS_MeshElement*>* rsetB;
2974 for(int i=0; i<numberOfSets-1; i++)
2976 rsetB=new set<const SMDS_MeshElement*>();
2978 rsetA->begin(), rsetA->end(),
2979 vs[i+1].begin(), vs[i+1].end(),
2980 inserter(*rsetB, rsetB->begin()));
2987 ///////////////////////////////////////////////////////////////////////////////
2988 /// Return the list of finite elements owning the given element: elements
2989 /// containing all the nodes of the given element, for instance faces and
2990 /// volumes containing a given edge.
2991 ///////////////////////////////////////////////////////////////////////////////
2992 static set<const SMDS_MeshElement*> * getFinitElements(const SMDS_MeshElement * element)
2994 int numberOfSets=element->NbNodes();
2995 set<const SMDS_MeshElement*> *initSet = new set<const SMDS_MeshElement*>[numberOfSets];
2997 SMDS_ElemIteratorPtr itNodes=element->nodesIterator();
3000 while(itNodes->more())
3002 const SMDS_MeshElement* node = itNodes->next();
3004 const SMDS_MeshNode * n=static_cast<const SMDS_MeshNode*>(node);
3005 SMDS_ElemIteratorPtr itFe = n->GetInverseElementIterator();
3007 //initSet[i]=set<const SMDS_MeshElement*>();
3010 const SMDS_MeshElement* elem = itFe->next();
3012 initSet[i].insert(elem);
3018 set<const SMDS_MeshElement*> *retSet=intersectionOfSets(initSet, numberOfSets);
3019 // MESSAGE("nb elems " << i << " intersection " << retSet->size());
3024 ///////////////////////////////////////////////////////////////////////////////
3025 /// Return the list of nodes used only by the given elements
3026 ///////////////////////////////////////////////////////////////////////////////
3027 static set<const SMDS_MeshElement*> * getExclusiveNodes(
3028 set<const SMDS_MeshElement*>& elements)
3030 set<const SMDS_MeshElement*> * toReturn=new set<const SMDS_MeshElement*>();
3031 set<const SMDS_MeshElement*>::iterator itElements=elements.begin();
3033 while(itElements!=elements.end())
3035 SMDS_ElemIteratorPtr itNodes = (*itElements)->nodesIterator();
3038 while(itNodes->more())
3040 const SMDS_MeshNode * n=static_cast<const SMDS_MeshNode*>(itNodes->next());
3041 SMDS_ElemIteratorPtr itFe = n->GetInverseElementIterator();
3042 set<const SMDS_MeshElement*> s;
3044 s.insert(itFe->next());
3045 if(s==elements) toReturn->insert(n);
3051 ///////////////////////////////////////////////////////////////////////////////
3052 ///Find the children of an element that are made of given nodes
3053 ///@param setOfChildren The set in which matching children will be inserted
3054 ///@param element The element were to search matching children
3055 ///@param nodes The nodes that the children must have to be selected
3056 ///////////////////////////////////////////////////////////////////////////////
3057 void SMDS_Mesh::addChildrenWithNodes(set<const SMDS_MeshElement*>& setOfChildren,
3058 const SMDS_MeshElement * element,
3059 set<const SMDS_MeshElement*>& nodes)
3061 switch(element->GetType())
3064 MESSAGE("Internal Error: This should not happen");
3066 case SMDSAbs_0DElement:
3072 SMDS_ElemIteratorPtr itn=element->nodesIterator();
3075 const SMDS_MeshElement * e=itn->next();
3076 if(nodes.find(e)!=nodes.end())
3078 setOfChildren.insert(element);
3085 SMDS_ElemIteratorPtr itn=element->nodesIterator();
3088 const SMDS_MeshElement * e=itn->next();
3089 if(nodes.find(e)!=nodes.end())
3091 setOfChildren.insert(element);
3095 if(hasConstructionEdges())
3097 SMDS_ElemIteratorPtr ite=element->edgesIterator();
3099 addChildrenWithNodes(setOfChildren, ite->next(), nodes);
3102 case SMDSAbs_Volume:
3104 if(hasConstructionFaces())
3106 SMDS_ElemIteratorPtr ite=element->facesIterator();
3108 addChildrenWithNodes(setOfChildren, ite->next(), nodes);
3110 else if(hasConstructionEdges())
3112 SMDS_ElemIteratorPtr ite=element->edgesIterator();
3114 addChildrenWithNodes(setOfChildren, ite->next(), nodes);
3120 ///////////////////////////////////////////////////////////////////////////////
3121 ///@param elem The element to delete
3122 ///@param removenodes if true remaining nodes will be removed
3123 ///////////////////////////////////////////////////////////////////////////////
3124 void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem,
3125 const bool removenodes)
3127 list<const SMDS_MeshElement *> removedElems;
3128 list<const SMDS_MeshElement *> removedNodes;
3129 RemoveElement( elem, removedElems, removedNodes, removenodes );
3132 ///////////////////////////////////////////////////////////////////////////////
3133 ///@param elem The element to delete
3134 ///@param removedElems to be filled with all removed elements
3135 ///@param removedNodes to be filled with all removed nodes
3136 ///@param removenodes if true remaining nodes will be removed
3137 ///////////////////////////////////////////////////////////////////////////////
3138 void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem,
3139 list<const SMDS_MeshElement *>& removedElems,
3140 list<const SMDS_MeshElement *>& removedNodes,
3143 //MESSAGE("SMDS_Mesh::RemoveElement " << elem->getVtkId() << " " << removenodes);
3144 // get finite elements built on elem
3145 set<const SMDS_MeshElement*> * s1;
3146 if ( (elem->GetType() == SMDSAbs_0DElement)
3147 || ((elem->GetType() == SMDSAbs_Edge) && !hasConstructionEdges())
3148 || ((elem->GetType() == SMDSAbs_Face) && !hasConstructionFaces())
3149 || (elem->GetType() == SMDSAbs_Volume) )
3151 s1 = new set<const SMDS_MeshElement*> ();
3155 s1 = getFinitElements(elem);
3157 // get exclusive nodes (which would become free afterwards)
3158 set<const SMDS_MeshElement*> * s2;
3159 if (elem->GetType() == SMDSAbs_Node) // a node is removed
3161 // do not remove nodes except elem
3162 s2 = new set<const SMDS_MeshElement*> ();
3167 s2 = getExclusiveNodes(*s1);
3169 // form the set of finite and construction elements to remove
3170 set<const SMDS_MeshElement*> s3;
3171 set<const SMDS_MeshElement*>::iterator it = s1->begin();
3172 while (it != s1->end())
3174 addChildrenWithNodes(s3, *it, *s2);
3178 if (elem->GetType() != SMDSAbs_Node)
3181 // remove finite and construction elements
3183 while (it != s3.end())
3185 // Remove element from <InverseElements> of its nodes
3186 SMDS_ElemIteratorPtr itn = (*it)->nodesIterator();
3189 SMDS_MeshNode * n = static_cast<SMDS_MeshNode *> (const_cast<SMDS_MeshElement *> (itn->next()));
3190 n->RemoveInverseElement((*it));
3192 int IdToRemove = (*it)->GetID();
3193 int vtkid = (*it)->getVtkId();
3194 //MESSAGE("elem Id to remove " << IdToRemove << " vtkid " << vtkid <<
3195 // " vtktype " << (*it)->GetVtkType() << " type " << (*it)->GetType());
3196 switch ((*it)->GetType())
3199 MYASSERT("Internal Error: This should not happen")
3202 case SMDSAbs_0DElement:
3203 if (IdToRemove >= 0)
3205 myCells[IdToRemove] = 0; // -PR- ici ou dans myElementIDFactory->ReleaseID ?
3208 removedElems.push_back((*it));
3209 myElementIDFactory->ReleaseID(IdToRemove, vtkid);
3213 if (IdToRemove >= 0)
3215 myCells[IdToRemove] = 0;
3216 myInfo.RemoveEdge(*it);
3218 removedElems.push_back((*it));
3219 myElementIDFactory->ReleaseID(IdToRemove, vtkid);
3220 if (const SMDS_VtkEdge* vtkElem = dynamic_cast<const SMDS_VtkEdge*>(*it))
3221 myEdgePool->destroy((SMDS_VtkEdge*) vtkElem);
3226 if (IdToRemove >= 0)
3228 myCells[IdToRemove] = 0;
3229 myInfo.RemoveFace(*it);
3231 removedElems.push_back((*it));
3232 myElementIDFactory->ReleaseID(IdToRemove, vtkid);
3233 if (const SMDS_VtkFace* vtkElem = dynamic_cast<const SMDS_VtkFace*>(*it))
3234 myFacePool->destroy((SMDS_VtkFace*) vtkElem);
3238 case SMDSAbs_Volume:
3239 if (IdToRemove >= 0)
3241 myCells[IdToRemove] = 0;
3242 myInfo.RemoveVolume(*it);
3244 removedElems.push_back((*it));
3245 myElementIDFactory->ReleaseID(IdToRemove, vtkid);
3246 if (const SMDS_VtkVolume* vtkElem = dynamic_cast<const SMDS_VtkVolume*>(*it))
3247 myVolumePool->destroy((SMDS_VtkVolume*) vtkElem);
3252 if (IdToRemove >= 0)
3254 myCells[IdToRemove] = 0;
3257 removedElems.push_back((*it));
3258 myElementIDFactory->ReleaseID(IdToRemove, vtkid);
3259 if (const SMDS_BallElement* vtkElem = dynamic_cast<const SMDS_BallElement*>(*it))
3260 myBallPool->destroy(const_cast<SMDS_BallElement*>( vtkElem ));
3267 //MESSAGE("VTK_EMPTY_CELL in " << vtkid);
3268 this->myGrid->GetCellTypesArray()->SetValue(vtkid, VTK_EMPTY_CELL);
3273 // remove exclusive (free) nodes
3277 while (it != s2->end())
3279 int IdToRemove = (*it)->GetID();
3280 //MESSAGE( "SMDS: RM node " << IdToRemove);
3281 if (IdToRemove >= 0)
3283 myNodes[IdToRemove] = 0;
3286 myNodeIDFactory->ReleaseID((*it)->GetID(), (*it)->getVtkId());
3287 removedNodes.push_back((*it));
3288 if (const SMDS_MeshNode* vtkElem = dynamic_cast<const SMDS_MeshNode*>(*it))
3290 ((SMDS_MeshNode*)vtkElem)->SetPosition(SMDS_SpacePosition::originSpacePosition());
3291 myNodePool->destroy((SMDS_MeshNode*) vtkElem);
3304 ///////////////////////////////////////////////////////////////////////////////
3305 ///@param elem The element to delete
3306 ///////////////////////////////////////////////////////////////////////////////
3307 void SMDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elem)
3309 int elemId = elem->GetID();
3310 int vtkId = elem->getVtkId();
3311 //MESSAGE("RemoveFreeElement " << elemId);
3312 SMDSAbs_ElementType aType = elem->GetType();
3313 SMDS_MeshElement* todest = (SMDS_MeshElement*)(elem);
3314 if (aType == SMDSAbs_Node) {
3315 //MESSAGE("Remove free node " << elemId);
3316 // only free node can be removed by this method
3317 const SMDS_MeshNode* n = static_cast<SMDS_MeshNode*>(todest);
3318 SMDS_ElemIteratorPtr itFe = n->GetInverseElementIterator();
3319 if (!itFe->more()) { // free node
3320 myNodes[elemId] = 0;
3322 ((SMDS_MeshNode*) n)->SetPosition(SMDS_SpacePosition::originSpacePosition());
3323 myNodePool->destroy(static_cast<SMDS_MeshNode*>(todest));
3324 myNodeIDFactory->ReleaseID(elemId, vtkId);
3327 if (hasConstructionEdges() || hasConstructionFaces())
3328 // this methods is only for meshes without descendants
3331 //MESSAGE("Remove free element " << elemId);
3332 // Remove element from <InverseElements> of its nodes
3333 SMDS_ElemIteratorPtr itn = elem->nodesIterator();
3334 while (itn->more()) {
3335 SMDS_MeshNode * n = static_cast<SMDS_MeshNode *>
3336 (const_cast<SMDS_MeshElement *>(itn->next()));
3337 n->RemoveInverseElement(elem);
3340 // in meshes without descendants elements are always free
3342 case SMDSAbs_0DElement:
3343 myCells[elemId] = 0;
3344 myInfo.remove(elem);
3348 myCells[elemId] = 0;
3349 myInfo.RemoveEdge(elem);
3350 myEdgePool->destroy(static_cast<SMDS_VtkEdge*>(todest));
3353 myCells[elemId] = 0;
3354 myInfo.RemoveFace(elem);
3355 myFacePool->destroy(static_cast<SMDS_VtkFace*>(todest));
3357 case SMDSAbs_Volume:
3358 myCells[elemId] = 0;
3359 myInfo.RemoveVolume(elem);
3360 myVolumePool->destroy(static_cast<SMDS_VtkVolume*>(todest));
3363 myCells[elemId] = 0;
3364 myInfo.remove(elem);
3365 myBallPool->destroy(static_cast<SMDS_BallElement*>(todest));
3370 myElementIDFactory->ReleaseID(elemId, vtkId);
3372 this->myGrid->GetCellTypesArray()->SetValue(vtkId, VTK_EMPTY_CELL);
3373 // --- to do: keep vtkid in a list of reusable cells
3378 * Checks if the element is present in mesh.
3379 * Useful to determine dead pointers.
3381 bool SMDS_Mesh::Contains (const SMDS_MeshElement* elem) const
3383 // we should not imply on validity of *elem, so iterate on containers
3384 // of all types in the hope of finding <elem> somewhere there
3385 SMDS_NodeIteratorPtr itn = nodesIterator();
3387 if (elem == itn->next())
3389 SMDS_ElemIteratorPtr ite = elementsIterator();
3391 if (elem == ite->next())
3396 //=======================================================================
3397 //function : MaxNodeID
3399 //=======================================================================
3401 int SMDS_Mesh::MaxNodeID() const
3406 //=======================================================================
3407 //function : MinNodeID
3409 //=======================================================================
3411 int SMDS_Mesh::MinNodeID() const
3416 //=======================================================================
3417 //function : MaxElementID
3419 //=======================================================================
3421 int SMDS_Mesh::MaxElementID() const
3423 return myElementIDFactory->GetMaxID();
3426 //=======================================================================
3427 //function : MinElementID
3429 //=======================================================================
3431 int SMDS_Mesh::MinElementID() const
3433 return myElementIDFactory->GetMinID();
3436 //=======================================================================
3437 //function : Renumber
3438 //purpose : Renumber all nodes or elements.
3439 //=======================================================================
3441 void SMDS_Mesh::Renumber (const bool isNodes, const int startID, const int deltaID)
3443 MESSAGE("Renumber");
3447 SMDS_MeshNodeIDFactory * idFactory =
3448 isNodes ? myNodeIDFactory : myElementIDFactory;
3450 // get existing elements in the order of ID increasing
3451 map<int,SMDS_MeshElement*> elemMap;
3452 SMDS_ElemIteratorPtr idElemIt = idFactory->elementsIterator();
3453 while ( idElemIt->more() ) {
3454 SMDS_MeshElement* elem = const_cast<SMDS_MeshElement*>(idElemIt->next());
3455 int id = elem->GetID();
3456 elemMap.insert(map<int,SMDS_MeshElement*>::value_type(id, elem));
3458 // release their ids
3459 map<int,SMDS_MeshElement*>::iterator elemIt = elemMap.begin();
3461 // for ( ; elemIt != elemMap.end(); elemIt++ )
3463 // int id = (*elemIt).first;
3464 // idFactory->ReleaseID( id );
3468 elemIt = elemMap.begin();
3469 for ( ; elemIt != elemMap.end(); elemIt++ )
3471 idFactory->BindID( ID, (*elemIt).second );
3476 //=======================================================================
3477 //function : GetElementType
3478 //purpose : Return type of element or node with id
3479 //=======================================================================
3481 SMDSAbs_ElementType SMDS_Mesh::GetElementType( const int id, const bool iselem ) const
3483 SMDS_MeshElement* elem = 0;
3485 elem = myElementIDFactory->MeshElement( id );
3487 elem = myNodeIDFactory->MeshElement( id );
3491 //throw SALOME_Exception(LOCALIZED ("this element isn't exist"));
3495 return elem->GetType();
3500 //********************************************************************
3501 //********************************************************************
3502 //******** *********
3503 //***** Methods for addition of quadratic elements ******
3504 //******** *********
3505 //********************************************************************
3506 //********************************************************************
3508 //=======================================================================
3509 //function : AddEdgeWithID
3511 //=======================================================================
3512 SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(int n1, int n2, int n12, int ID)
3514 return SMDS_Mesh::AddEdgeWithID
3515 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1),
3516 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2),
3517 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
3521 //=======================================================================
3522 //function : AddEdge
3524 //=======================================================================
3525 SMDS_MeshEdge* SMDS_Mesh::AddEdge(const SMDS_MeshNode* n1,
3526 const SMDS_MeshNode* n2,
3527 const SMDS_MeshNode* n12)
3529 return SMDS_Mesh::AddEdgeWithID(n1, n2, n12, myElementIDFactory->GetFreeID());
3532 //=======================================================================
3533 //function : AddEdgeWithID
3535 //=======================================================================
3536 SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
3537 const SMDS_MeshNode * n2,
3538 const SMDS_MeshNode * n12,
3541 if ( !n1 || !n2 || !n12 ) return 0;
3543 // --- retrieve nodes ID
3544 vector<vtkIdType> nodeIds;
3546 nodeIds.push_back(n1->getVtkId());
3547 nodeIds.push_back(n2->getVtkId());
3548 nodeIds.push_back(n12->getVtkId());
3550 SMDS_MeshEdge * edge = 0;
3551 SMDS_VtkEdge *edgevtk = myEdgePool->getNew();
3552 edgevtk->init(nodeIds, this);
3553 if (!this->registerElement(ID,edgevtk))
3555 this->myGrid->GetCellTypesArray()->SetValue(edgevtk->getVtkId(), VTK_EMPTY_CELL);
3556 myEdgePool->destroy(edgevtk);
3560 adjustmyCellsCapacity(ID);
3562 myInfo.myNbQuadEdges++;
3564 // if (!registerElement(ID, edge)) {
3565 // RemoveElement(edge, false);
3573 //=======================================================================
3574 //function : AddFace
3576 //=======================================================================
3577 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
3578 const SMDS_MeshNode * n2,
3579 const SMDS_MeshNode * n3,
3580 const SMDS_MeshNode * n12,
3581 const SMDS_MeshNode * n23,
3582 const SMDS_MeshNode * n31)
3584 return SMDS_Mesh::AddFaceWithID(n1,n2,n3,n12,n23,n31,
3585 myElementIDFactory->GetFreeID());
3588 //=======================================================================
3589 //function : AddFaceWithID
3591 //=======================================================================
3592 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int n1, int n2, int n3,
3593 int n12,int n23,int n31, int ID)
3595 return SMDS_Mesh::AddFaceWithID
3596 ((SMDS_MeshNode *)myNodeIDFactory->MeshElement(n1) ,
3597 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n2) ,
3598 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n3) ,
3599 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n12),
3600 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n23),
3601 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n31),
3605 //=======================================================================
3606 //function : AddFaceWithID
3608 //=======================================================================
3609 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
3610 const SMDS_MeshNode * n2,
3611 const SMDS_MeshNode * n3,
3612 const SMDS_MeshNode * n12,
3613 const SMDS_MeshNode * n23,
3614 const SMDS_MeshNode * n31,
3617 if ( !n1 || !n2 || !n3 || !n12 || !n23 || !n31) return 0;
3618 if(hasConstructionEdges()) {
3619 // creation quadratic edges - not implemented
3624 // --- retrieve nodes ID
3625 vector<vtkIdType> nodeIds;
3627 nodeIds.push_back(n1->getVtkId());
3628 nodeIds.push_back(n2->getVtkId());
3629 nodeIds.push_back(n3->getVtkId());
3630 nodeIds.push_back(n12->getVtkId());
3631 nodeIds.push_back(n23->getVtkId());
3632 nodeIds.push_back(n31->getVtkId());
3634 SMDS_MeshFace * face = 0;
3635 SMDS_VtkFace *facevtk = myFacePool->getNew();
3636 facevtk->init(nodeIds, this);
3637 if (!this->registerElement(ID,facevtk))
3639 this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL);
3640 myFacePool->destroy(facevtk);
3644 adjustmyCellsCapacity(ID);
3646 myInfo.myNbQuadTriangles++;
3648 // if (!registerElement(ID, face)) {
3649 // RemoveElement(face, false);
3657 //=======================================================================
3658 //function : AddFace
3660 //=======================================================================
3661 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
3662 const SMDS_MeshNode * n2,
3663 const SMDS_MeshNode * n3,
3664 const SMDS_MeshNode * n4,
3665 const SMDS_MeshNode * n12,
3666 const SMDS_MeshNode * n23,
3667 const SMDS_MeshNode * n34,
3668 const SMDS_MeshNode * n41)
3670 return SMDS_Mesh::AddFaceWithID(n1,n2,n3,n4,n12,n23,n34,n41,
3671 myElementIDFactory->GetFreeID());
3674 //=======================================================================
3675 //function : AddFaceWithID
3677 //=======================================================================
3678 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int n4,
3679 int n12,int n23,int n34,int n41, int ID)
3681 return SMDS_Mesh::AddFaceWithID
3682 ((SMDS_MeshNode *)myNodeIDFactory->MeshElement(n1) ,
3683 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n2) ,
3684 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n3) ,
3685 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n4) ,
3686 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n12),
3687 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n23),
3688 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n34),
3689 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n41),
3693 //=======================================================================
3694 //function : AddFaceWithID
3696 //=======================================================================
3697 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
3698 const SMDS_MeshNode * n2,
3699 const SMDS_MeshNode * n3,
3700 const SMDS_MeshNode * n4,
3701 const SMDS_MeshNode * n12,
3702 const SMDS_MeshNode * n23,
3703 const SMDS_MeshNode * n34,
3704 const SMDS_MeshNode * n41,
3707 if ( !n1 || !n2 || !n3 || !n4 || !n12 || !n23 || !n34 || !n41) return 0;
3708 if(hasConstructionEdges()) {
3709 // creation quadratic edges - not implemented
3714 // --- retrieve nodes ID
3715 vector<vtkIdType> nodeIds;
3717 nodeIds.push_back(n1->getVtkId());
3718 nodeIds.push_back(n2->getVtkId());
3719 nodeIds.push_back(n3->getVtkId());
3720 nodeIds.push_back(n4->getVtkId());
3721 nodeIds.push_back(n12->getVtkId());
3722 nodeIds.push_back(n23->getVtkId());
3723 nodeIds.push_back(n34->getVtkId());
3724 nodeIds.push_back(n41->getVtkId());
3726 SMDS_MeshFace * face = 0;
3727 SMDS_VtkFace *facevtk = myFacePool->getNew();
3728 facevtk->init(nodeIds, this);
3729 if (!this->registerElement(ID,facevtk))
3731 this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL);
3732 myFacePool->destroy(facevtk);
3736 adjustmyCellsCapacity(ID);
3738 myInfo.myNbQuadQuadrangles++;
3740 // if (!registerElement(ID, face)) {
3741 // RemoveElement(face, false);
3748 //=======================================================================
3749 //function : AddFace
3751 //=======================================================================
3752 SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
3753 const SMDS_MeshNode * n2,
3754 const SMDS_MeshNode * n3,
3755 const SMDS_MeshNode * n4,
3756 const SMDS_MeshNode * n12,
3757 const SMDS_MeshNode * n23,
3758 const SMDS_MeshNode * n34,
3759 const SMDS_MeshNode * n41,
3760 const SMDS_MeshNode * nCenter)
3762 return SMDS_Mesh::AddFaceWithID(n1,n2,n3,n4,n12,n23,n34,n41,nCenter,
3763 myElementIDFactory->GetFreeID());
3766 //=======================================================================
3767 //function : AddFaceWithID
3769 //=======================================================================
3770 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int n4,
3771 int n12,int n23,int n34,int n41, int nCenter, int ID)
3773 return SMDS_Mesh::AddFaceWithID
3774 ((SMDS_MeshNode *)myNodeIDFactory->MeshElement(n1) ,
3775 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n2) ,
3776 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n3) ,
3777 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n4) ,
3778 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n12),
3779 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n23),
3780 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n34),
3781 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n41),
3782 (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nCenter),
3786 //=======================================================================
3787 //function : AddFaceWithID
3789 //=======================================================================
3790 SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
3791 const SMDS_MeshNode * n2,
3792 const SMDS_MeshNode * n3,
3793 const SMDS_MeshNode * n4,
3794 const SMDS_MeshNode * n12,
3795 const SMDS_MeshNode * n23,
3796 const SMDS_MeshNode * n34,
3797 const SMDS_MeshNode * n41,
3798 const SMDS_MeshNode * nCenter,
3801 if ( !n1 || !n2 || !n3 || !n4 || !n12 || !n23 || !n34 || !n41 || !nCenter) return 0;
3802 if(hasConstructionEdges()) {
3803 // creation quadratic edges - not implemented
3808 // --- retrieve nodes ID
3809 vector<vtkIdType> nodeIds;
3811 nodeIds.push_back(n1->getVtkId());
3812 nodeIds.push_back(n2->getVtkId());
3813 nodeIds.push_back(n3->getVtkId());
3814 nodeIds.push_back(n4->getVtkId());
3815 nodeIds.push_back(n12->getVtkId());
3816 nodeIds.push_back(n23->getVtkId());
3817 nodeIds.push_back(n34->getVtkId());
3818 nodeIds.push_back(n41->getVtkId());
3819 nodeIds.push_back(nCenter->getVtkId());
3821 SMDS_MeshFace * face = 0;
3822 SMDS_VtkFace *facevtk = myFacePool->getNew();
3823 facevtk->init(nodeIds, this);
3824 if (!this->registerElement(ID,facevtk))
3826 this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL);
3827 myFacePool->destroy(facevtk);
3831 adjustmyCellsCapacity(ID);
3833 myInfo.myNbBiQuadQuadrangles++;
3835 // if (!registerElement(ID, face)) {
3836 // RemoveElement(face, false);
3844 //=======================================================================
3845 //function : AddVolume
3847 //=======================================================================
3848 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
3849 const SMDS_MeshNode * n2,
3850 const SMDS_MeshNode * n3,
3851 const SMDS_MeshNode * n4,
3852 const SMDS_MeshNode * n12,
3853 const SMDS_MeshNode * n23,
3854 const SMDS_MeshNode * n31,
3855 const SMDS_MeshNode * n14,
3856 const SMDS_MeshNode * n24,
3857 const SMDS_MeshNode * n34)
3859 int ID = myElementIDFactory->GetFreeID();
3860 SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n12, n23,
3861 n31, n14, n24, n34, ID);
3862 if(v==NULL) myElementIDFactory->ReleaseID(ID);
3866 //=======================================================================
3867 //function : AddVolumeWithID
3869 //=======================================================================
3870 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4,
3871 int n12,int n23,int n31,
3872 int n14,int n24,int n34, int ID)
3874 return SMDS_Mesh::AddVolumeWithID
3875 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1) ,
3876 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2) ,
3877 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3) ,
3878 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4) ,
3879 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
3880 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
3881 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n31),
3882 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n14),
3883 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n24),
3884 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n34),
3888 //=======================================================================
3889 //function : AddVolumeWithID
3890 //purpose : 2d order tetrahedron of 10 nodes
3891 //=======================================================================
3892 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
3893 const SMDS_MeshNode * n2,
3894 const SMDS_MeshNode * n3,
3895 const SMDS_MeshNode * n4,
3896 const SMDS_MeshNode * n12,
3897 const SMDS_MeshNode * n23,
3898 const SMDS_MeshNode * n31,
3899 const SMDS_MeshNode * n14,
3900 const SMDS_MeshNode * n24,
3901 const SMDS_MeshNode * n34,
3904 if ( !n1 || !n2 || !n3 || !n4 || !n12 || !n23 || !n31 || !n14 || !n24 || !n34)
3906 if(hasConstructionFaces()) {
3907 // creation quadratic faces - not implemented
3910 // --- retrieve nodes ID
3911 vector<vtkIdType> nodeIds;
3913 nodeIds.push_back(n1->getVtkId());
3914 nodeIds.push_back(n3->getVtkId());
3915 nodeIds.push_back(n2->getVtkId());
3916 nodeIds.push_back(n4->getVtkId());
3918 nodeIds.push_back(n31->getVtkId());
3919 nodeIds.push_back(n23->getVtkId());
3920 nodeIds.push_back(n12->getVtkId());
3922 nodeIds.push_back(n14->getVtkId());
3923 nodeIds.push_back(n34->getVtkId());
3924 nodeIds.push_back(n24->getVtkId());
3926 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
3927 volvtk->init(nodeIds, this);
3928 if (!this->registerElement(ID,volvtk))
3930 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
3931 myVolumePool->destroy(volvtk);
3934 adjustmyCellsCapacity(ID);
3935 myCells[ID] = volvtk;
3936 myInfo.myNbQuadTetras++;
3938 // if (!registerElement(ID, volvtk)) {
3939 // RemoveElement(volvtk, false);
3946 //=======================================================================
3947 //function : AddVolume
3949 //=======================================================================
3950 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
3951 const SMDS_MeshNode * n2,
3952 const SMDS_MeshNode * n3,
3953 const SMDS_MeshNode * n4,
3954 const SMDS_MeshNode * n5,
3955 const SMDS_MeshNode * n12,
3956 const SMDS_MeshNode * n23,
3957 const SMDS_MeshNode * n34,
3958 const SMDS_MeshNode * n41,
3959 const SMDS_MeshNode * n15,
3960 const SMDS_MeshNode * n25,
3961 const SMDS_MeshNode * n35,
3962 const SMDS_MeshNode * n45)
3964 int ID = myElementIDFactory->GetFreeID();
3965 SMDS_MeshVolume * v =
3966 SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n12, n23, n34, n41,
3967 n15, n25, n35, n45, ID);
3968 if(v==NULL) myElementIDFactory->ReleaseID(ID);
3972 //=======================================================================
3973 //function : AddVolumeWithID
3975 //=======================================================================
3976 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5,
3977 int n12,int n23,int n34,int n41,
3978 int n15,int n25,int n35,int n45, int ID)
3980 return SMDS_Mesh::AddVolumeWithID
3981 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1) ,
3982 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2) ,
3983 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3) ,
3984 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4) ,
3985 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5) ,
3986 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
3987 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
3988 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n34),
3989 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n41),
3990 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n15),
3991 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n25),
3992 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n35),
3993 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n45),
3997 //=======================================================================
3998 //function : AddVolumeWithID
3999 //purpose : 2d order pyramid of 13 nodes
4000 //=======================================================================
4001 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
4002 const SMDS_MeshNode * n2,
4003 const SMDS_MeshNode * n3,
4004 const SMDS_MeshNode * n4,
4005 const SMDS_MeshNode * n5,
4006 const SMDS_MeshNode * n12,
4007 const SMDS_MeshNode * n23,
4008 const SMDS_MeshNode * n34,
4009 const SMDS_MeshNode * n41,
4010 const SMDS_MeshNode * n15,
4011 const SMDS_MeshNode * n25,
4012 const SMDS_MeshNode * n35,
4013 const SMDS_MeshNode * n45,
4016 if (!n1 || !n2 || !n3 || !n4 || !n5 || !n12 || !n23 ||
4017 !n34 || !n41 || !n15 || !n25 || !n35 || !n45)
4019 if(hasConstructionFaces()) {
4020 // creation quadratic faces - not implemented
4023 // --- retrieve nodes ID
4024 vector<vtkIdType> nodeIds;
4026 nodeIds.push_back(n1->getVtkId());
4027 nodeIds.push_back(n4->getVtkId());
4028 nodeIds.push_back(n3->getVtkId());
4029 nodeIds.push_back(n2->getVtkId());
4030 nodeIds.push_back(n5->getVtkId());
4032 nodeIds.push_back(n41->getVtkId());
4033 nodeIds.push_back(n34->getVtkId());
4034 nodeIds.push_back(n23->getVtkId());
4035 nodeIds.push_back(n12->getVtkId());
4037 nodeIds.push_back(n15->getVtkId());
4038 nodeIds.push_back(n45->getVtkId());
4039 nodeIds.push_back(n35->getVtkId());
4040 nodeIds.push_back(n25->getVtkId());
4042 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
4043 volvtk->init(nodeIds, this);
4044 if (!this->registerElement(ID,volvtk))
4046 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
4047 myVolumePool->destroy(volvtk);
4050 adjustmyCellsCapacity(ID);
4051 myCells[ID] = volvtk;
4052 myInfo.myNbQuadPyramids++;
4054 // if (!registerElement(ID, volvtk)) {
4055 // RemoveElement(volvtk, false);
4062 //=======================================================================
4063 //function : AddVolume
4065 //=======================================================================
4066 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
4067 const SMDS_MeshNode * n2,
4068 const SMDS_MeshNode * n3,
4069 const SMDS_MeshNode * n4,
4070 const SMDS_MeshNode * n5,
4071 const SMDS_MeshNode * n6,
4072 const SMDS_MeshNode * n12,
4073 const SMDS_MeshNode * n23,
4074 const SMDS_MeshNode * n31,
4075 const SMDS_MeshNode * n45,
4076 const SMDS_MeshNode * n56,
4077 const SMDS_MeshNode * n64,
4078 const SMDS_MeshNode * n14,
4079 const SMDS_MeshNode * n25,
4080 const SMDS_MeshNode * n36)
4082 int ID = myElementIDFactory->GetFreeID();
4083 SMDS_MeshVolume * v =
4084 SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n12, n23, n31,
4085 n45, n56, n64, n14, n25, n36, ID);
4086 if(v==NULL) myElementIDFactory->ReleaseID(ID);
4090 //=======================================================================
4091 //function : AddVolumeWithID
4093 //=======================================================================
4094 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3,
4095 int n4, int n5, int n6,
4096 int n12,int n23,int n31,
4097 int n45,int n56,int n64,
4098 int n14,int n25,int n36, int ID)
4100 return SMDS_Mesh::AddVolumeWithID
4101 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1) ,
4102 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2) ,
4103 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3) ,
4104 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4) ,
4105 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5) ,
4106 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n6) ,
4107 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
4108 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
4109 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n31),
4110 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n45),
4111 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n56),
4112 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n64),
4113 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n14),
4114 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n25),
4115 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n36),
4119 //=======================================================================
4120 //function : AddVolumeWithID
4121 //purpose : 2d order Pentahedron with 15 nodes
4122 //=======================================================================
4123 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
4124 const SMDS_MeshNode * n2,
4125 const SMDS_MeshNode * n3,
4126 const SMDS_MeshNode * n4,
4127 const SMDS_MeshNode * n5,
4128 const SMDS_MeshNode * n6,
4129 const SMDS_MeshNode * n12,
4130 const SMDS_MeshNode * n23,
4131 const SMDS_MeshNode * n31,
4132 const SMDS_MeshNode * n45,
4133 const SMDS_MeshNode * n56,
4134 const SMDS_MeshNode * n64,
4135 const SMDS_MeshNode * n14,
4136 const SMDS_MeshNode * n25,
4137 const SMDS_MeshNode * n36,
4140 if (!n1 || !n2 || !n3 || !n4 || !n5 || !n6 || !n12 || !n23 ||
4141 !n31 || !n45 || !n56 || !n64 || !n14 || !n25 || !n36)
4143 if(hasConstructionFaces()) {
4144 // creation quadratic faces - not implemented
4147 // --- retrieve nodes ID
4148 vector<vtkIdType> nodeIds;
4150 nodeIds.push_back(n1->getVtkId());
4151 nodeIds.push_back(n2->getVtkId());
4152 nodeIds.push_back(n3->getVtkId());
4154 nodeIds.push_back(n4->getVtkId());
4155 nodeIds.push_back(n5->getVtkId());
4156 nodeIds.push_back(n6->getVtkId());
4158 nodeIds.push_back(n12->getVtkId());
4159 nodeIds.push_back(n23->getVtkId());
4160 nodeIds.push_back(n31->getVtkId());
4162 nodeIds.push_back(n45->getVtkId());
4163 nodeIds.push_back(n56->getVtkId());
4164 nodeIds.push_back(n64->getVtkId());
4166 nodeIds.push_back(n14->getVtkId());
4167 nodeIds.push_back(n25->getVtkId());
4168 nodeIds.push_back(n36->getVtkId());
4170 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
4171 volvtk->init(nodeIds, this);
4172 if (!this->registerElement(ID,volvtk))
4174 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
4175 myVolumePool->destroy(volvtk);
4178 adjustmyCellsCapacity(ID);
4179 myCells[ID] = volvtk;
4180 myInfo.myNbQuadPrisms++;
4182 // if (!registerElement(ID, volvtk)) {
4183 // RemoveElement(volvtk, false);
4190 //=======================================================================
4191 //function : AddVolume
4193 //=======================================================================
4194 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
4195 const SMDS_MeshNode * n2,
4196 const SMDS_MeshNode * n3,
4197 const SMDS_MeshNode * n4,
4198 const SMDS_MeshNode * n5,
4199 const SMDS_MeshNode * n6,
4200 const SMDS_MeshNode * n7,
4201 const SMDS_MeshNode * n8,
4202 const SMDS_MeshNode * n12,
4203 const SMDS_MeshNode * n23,
4204 const SMDS_MeshNode * n34,
4205 const SMDS_MeshNode * n41,
4206 const SMDS_MeshNode * n56,
4207 const SMDS_MeshNode * n67,
4208 const SMDS_MeshNode * n78,
4209 const SMDS_MeshNode * n85,
4210 const SMDS_MeshNode * n15,
4211 const SMDS_MeshNode * n26,
4212 const SMDS_MeshNode * n37,
4213 const SMDS_MeshNode * n48)
4215 int ID = myElementIDFactory->GetFreeID();
4216 SMDS_MeshVolume * v =
4217 SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, n12, n23, n34, n41,
4218 n56, n67, n78, n85, n15, n26, n37, n48, ID);
4219 if(v==NULL) myElementIDFactory->ReleaseID(ID);
4223 //=======================================================================
4224 //function : AddVolumeWithID
4226 //=======================================================================
4227 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4,
4228 int n5, int n6, int n7, int n8,
4229 int n12,int n23,int n34,int n41,
4230 int n56,int n67,int n78,int n85,
4231 int n15,int n26,int n37,int n48, int ID)
4233 return SMDS_Mesh::AddVolumeWithID
4234 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1),
4235 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2),
4236 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3),
4237 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4),
4238 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5),
4239 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n6),
4240 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n7),
4241 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n8),
4242 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
4243 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
4244 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n34),
4245 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n41),
4246 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n56),
4247 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n67),
4248 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n78),
4249 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n85),
4250 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n15),
4251 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n26),
4252 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n37),
4253 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n48),
4257 //=======================================================================
4258 //function : AddVolumeWithID
4259 //purpose : 2d order Hexahedrons with 20 nodes
4260 //=======================================================================
4261 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
4262 const SMDS_MeshNode * n2,
4263 const SMDS_MeshNode * n3,
4264 const SMDS_MeshNode * n4,
4265 const SMDS_MeshNode * n5,
4266 const SMDS_MeshNode * n6,
4267 const SMDS_MeshNode * n7,
4268 const SMDS_MeshNode * n8,
4269 const SMDS_MeshNode * n12,
4270 const SMDS_MeshNode * n23,
4271 const SMDS_MeshNode * n34,
4272 const SMDS_MeshNode * n41,
4273 const SMDS_MeshNode * n56,
4274 const SMDS_MeshNode * n67,
4275 const SMDS_MeshNode * n78,
4276 const SMDS_MeshNode * n85,
4277 const SMDS_MeshNode * n15,
4278 const SMDS_MeshNode * n26,
4279 const SMDS_MeshNode * n37,
4280 const SMDS_MeshNode * n48,
4283 if (!n1 || !n2 || !n3 || !n4 || !n5 || !n6 || !n7 || !n8 || !n12 || !n23 ||
4284 !n34 || !n41 || !n56 || !n67 || !n78 || !n85 || !n15 || !n26 || !n37 || !n48)
4286 if(hasConstructionFaces()) {
4288 // creation quadratic faces - not implemented
4290 // --- retrieve nodes ID
4291 vector<vtkIdType> nodeIds;
4293 nodeIds.push_back(n1->getVtkId());
4294 nodeIds.push_back(n4->getVtkId());
4295 nodeIds.push_back(n3->getVtkId());
4296 nodeIds.push_back(n2->getVtkId());
4298 nodeIds.push_back(n5->getVtkId());
4299 nodeIds.push_back(n8->getVtkId());
4300 nodeIds.push_back(n7->getVtkId());
4301 nodeIds.push_back(n6->getVtkId());
4303 nodeIds.push_back(n41->getVtkId());
4304 nodeIds.push_back(n34->getVtkId());
4305 nodeIds.push_back(n23->getVtkId());
4306 nodeIds.push_back(n12->getVtkId());
4308 nodeIds.push_back(n85->getVtkId());
4309 nodeIds.push_back(n78->getVtkId());
4310 nodeIds.push_back(n67->getVtkId());
4311 nodeIds.push_back(n56->getVtkId());
4313 nodeIds.push_back(n15->getVtkId());
4314 nodeIds.push_back(n48->getVtkId());
4315 nodeIds.push_back(n37->getVtkId());
4316 nodeIds.push_back(n26->getVtkId());
4318 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
4319 volvtk->init(nodeIds, this);
4320 if (!this->registerElement(ID,volvtk))
4322 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
4323 myVolumePool->destroy(volvtk);
4326 adjustmyCellsCapacity(ID);
4327 myCells[ID] = volvtk;
4328 myInfo.myNbQuadHexas++;
4330 // if (!registerElement(ID, volvtk)) {
4331 // RemoveElement(volvtk, false);
4337 //=======================================================================
4338 //function : AddVolume
4340 //=======================================================================
4341 SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
4342 const SMDS_MeshNode * n2,
4343 const SMDS_MeshNode * n3,
4344 const SMDS_MeshNode * n4,
4345 const SMDS_MeshNode * n5,
4346 const SMDS_MeshNode * n6,
4347 const SMDS_MeshNode * n7,
4348 const SMDS_MeshNode * n8,
4349 const SMDS_MeshNode * n12,
4350 const SMDS_MeshNode * n23,
4351 const SMDS_MeshNode * n34,
4352 const SMDS_MeshNode * n41,
4353 const SMDS_MeshNode * n56,
4354 const SMDS_MeshNode * n67,
4355 const SMDS_MeshNode * n78,
4356 const SMDS_MeshNode * n85,
4357 const SMDS_MeshNode * n15,
4358 const SMDS_MeshNode * n26,
4359 const SMDS_MeshNode * n37,
4360 const SMDS_MeshNode * n48,
4361 const SMDS_MeshNode * n1234,
4362 const SMDS_MeshNode * n1256,
4363 const SMDS_MeshNode * n2367,
4364 const SMDS_MeshNode * n3478,
4365 const SMDS_MeshNode * n1458,
4366 const SMDS_MeshNode * n5678,
4367 const SMDS_MeshNode * nCenter)
4369 int ID = myElementIDFactory->GetFreeID();
4370 SMDS_MeshVolume * v =
4371 SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, n12, n23, n34, n41,
4372 n56, n67, n78, n85, n15, n26, n37, n48,
4373 n1234, n1256, n2367, n3478, n1458, n5678, nCenter,
4375 if(v==NULL) myElementIDFactory->ReleaseID(ID);
4379 //=======================================================================
4380 //function : AddVolumeWithID
4382 //=======================================================================
4383 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4,
4384 int n5, int n6, int n7, int n8,
4385 int n12,int n23,int n34,int n41,
4386 int n56,int n67,int n78,int n85,
4387 int n15,int n26,int n37,int n48,
4388 int n1234,int n1256,int n2367,int n3478,
4389 int n1458,int n5678,int nCenter, int ID)
4391 return SMDS_Mesh::AddVolumeWithID
4392 ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1),
4393 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2),
4394 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3),
4395 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4),
4396 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5),
4397 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n6),
4398 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n7),
4399 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n8),
4400 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12),
4401 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23),
4402 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n34),
4403 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n41),
4404 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n56),
4405 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n67),
4406 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n78),
4407 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n85),
4408 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n15),
4409 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n26),
4410 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n37),
4411 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n48),
4412 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1234),
4413 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1256),
4414 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2367),
4415 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3478),
4416 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1458),
4417 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5678),
4418 (SMDS_MeshNode*) myNodeIDFactory->MeshElement(nCenter),
4422 //=======================================================================
4423 //function : AddVolumeWithID
4424 //purpose : 2d order Hexahedrons with 20 nodes
4425 //=======================================================================
4426 SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
4427 const SMDS_MeshNode * n2,
4428 const SMDS_MeshNode * n3,
4429 const SMDS_MeshNode * n4,
4430 const SMDS_MeshNode * n5,
4431 const SMDS_MeshNode * n6,
4432 const SMDS_MeshNode * n7,
4433 const SMDS_MeshNode * n8,
4434 const SMDS_MeshNode * n12,
4435 const SMDS_MeshNode * n23,
4436 const SMDS_MeshNode * n34,
4437 const SMDS_MeshNode * n41,
4438 const SMDS_MeshNode * n56,
4439 const SMDS_MeshNode * n67,
4440 const SMDS_MeshNode * n78,
4441 const SMDS_MeshNode * n85,
4442 const SMDS_MeshNode * n15,
4443 const SMDS_MeshNode * n26,
4444 const SMDS_MeshNode * n37,
4445 const SMDS_MeshNode * n48,
4446 const SMDS_MeshNode * n1234,
4447 const SMDS_MeshNode * n1256,
4448 const SMDS_MeshNode * n2367,
4449 const SMDS_MeshNode * n3478,
4450 const SMDS_MeshNode * n1458,
4451 const SMDS_MeshNode * n5678,
4452 const SMDS_MeshNode * nCenter,
4455 if (!n1 || !n2 || !n3 || !n4 || !n5 || !n6 || !n7 || !n8 || !n12 || !n23 ||
4456 !n34 || !n41 || !n56 || !n67 || !n78 || !n85 || !n15 || !n26 || !n37 || !n48 ||
4457 !n1234 || !n1256 || !n2367 || !n3478 || !n1458 || !n5678 || !nCenter )
4459 if(hasConstructionFaces()) {
4461 // creation quadratic faces - not implemented
4463 // --- retrieve nodes ID
4464 vector<vtkIdType> nodeIds;
4466 nodeIds.push_back(n1->getVtkId());
4467 nodeIds.push_back(n4->getVtkId());
4468 nodeIds.push_back(n3->getVtkId());
4469 nodeIds.push_back(n2->getVtkId());
4471 nodeIds.push_back(n5->getVtkId());
4472 nodeIds.push_back(n8->getVtkId());
4473 nodeIds.push_back(n7->getVtkId());
4474 nodeIds.push_back(n6->getVtkId());
4476 nodeIds.push_back(n41->getVtkId());
4477 nodeIds.push_back(n34->getVtkId());
4478 nodeIds.push_back(n23->getVtkId());
4479 nodeIds.push_back(n12->getVtkId());
4481 nodeIds.push_back(n85->getVtkId());
4482 nodeIds.push_back(n78->getVtkId());
4483 nodeIds.push_back(n67->getVtkId());
4484 nodeIds.push_back(n56->getVtkId());
4486 nodeIds.push_back(n15->getVtkId());
4487 nodeIds.push_back(n48->getVtkId());
4488 nodeIds.push_back(n37->getVtkId());
4489 nodeIds.push_back(n26->getVtkId());
4491 nodeIds.push_back(n1256->getVtkId());
4492 nodeIds.push_back(n3478->getVtkId());
4493 nodeIds.push_back(n1458->getVtkId());
4494 nodeIds.push_back(n2367->getVtkId());
4495 nodeIds.push_back(n1234->getVtkId());
4496 nodeIds.push_back(n5678->getVtkId());
4497 nodeIds.push_back(nCenter->getVtkId());
4499 SMDS_VtkVolume *volvtk = myVolumePool->getNew();
4500 volvtk->init(nodeIds, this);
4501 if (!this->registerElement(ID,volvtk))
4503 this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
4504 myVolumePool->destroy(volvtk);
4507 adjustmyCellsCapacity(ID);
4508 myCells[ID] = volvtk;
4509 myInfo.myNbTriQuadHexas++;
4515 void SMDS_Mesh::updateNodeMinMax()
4518 if (myNodes.size() == 0)
4523 while (!myNodes[myNodeMin] && (myNodeMin<myNodes.size()))
4525 myNodeMax=myNodes.size()-1;
4526 while (!myNodes[myNodeMax] && (myNodeMin>=0))
4530 void SMDS_Mesh::incrementNodesCapacity(int nbNodes)
4532 // int val = myCellIdSmdsToVtk.size();
4533 // MESSAGE(" ------------------- resize myCellIdSmdsToVtk " << val << " --> " << val + nbNodes);
4534 // myCellIdSmdsToVtk.resize(val + nbNodes, -1); // fill new elements with -1
4535 int val = myNodes.size();
4536 MESSAGE(" ------------------- resize myNodes " << val << " --> " << val + nbNodes);
4537 myNodes.resize(val +nbNodes, 0);
4540 void SMDS_Mesh::incrementCellsCapacity(int nbCells)
4542 int val = myCellIdVtkToSmds.size();
4543 MESSAGE(" ------------------- resize myCellIdVtkToSmds " << val << " --> " << val + nbCells);
4544 myCellIdVtkToSmds.resize(val + nbCells, -1); // fill new elements with -1
4545 val = myCells.size();
4546 MESSAGE(" ------------------- resize myCells " << val << " --> " << val + nbCells);
4547 myNodes.resize(val +nbCells, 0);
4550 void SMDS_Mesh::adjustStructure()
4552 myGrid->GetPoints()->GetData()->SetNumberOfTuples(myNodeIDFactory->GetMaxID());
4555 void SMDS_Mesh::dumpGrid(string ficdump)
4557 MESSAGE("SMDS_Mesh::dumpGrid " << ficdump);
4558 // vtkUnstructuredGridWriter* aWriter = vtkUnstructuredGridWriter::New();
4559 // aWriter->SetFileName(ficdump.c_str());
4560 // aWriter->SetInput(myGrid);
4561 // if(myGrid->GetNumberOfCells())
4563 // aWriter->Write();
4565 // aWriter->Delete();
4566 ficdump = ficdump + "_connectivity";
4567 ofstream ficcon(ficdump.c_str(), ios::out);
4568 int nbPoints = myGrid->GetNumberOfPoints();
4569 ficcon << "-------------------------------- points " << nbPoints << endl;
4570 for (int i=0; i<nbPoints; i++)
4572 ficcon << i << " " << *(myGrid->GetPoint(i)) << " " << *(myGrid->GetPoint(i)+1) << " " << " " << *(myGrid->GetPoint(i)+2) << endl;
4574 int nbCells = myGrid->GetNumberOfCells();
4575 ficcon << "-------------------------------- cells " << nbCells << endl;
4576 for (int i=0; i<nbCells; i++)
4578 // MESSAGE(i << " " << myGrid->GetCell(i));
4579 // MESSAGE(" " << myGrid->GetCell(i)->GetCellType());
4580 ficcon << i << " - " << myGrid->GetCell(i)->GetCellType() << " -";
4581 int nbptcell = myGrid->GetCell(i)->GetNumberOfPoints();
4582 vtkIdList *listid = myGrid->GetCell(i)->GetPointIds();
4583 for (int j=0; j<nbptcell; j++)
4585 ficcon << " " << listid->GetId(j);
4589 ficcon << "-------------------------------- connectivity " << nbPoints << endl;
4590 vtkCellLinks *links = myGrid->GetCellLinks();
4591 for (int i=0; i<nbPoints; i++)
4593 int ncells = links->GetNcells(i);
4594 vtkIdType *cells = links->GetCells(i);
4595 ficcon << i << " - " << ncells << " -";
4596 for (int j=0; j<ncells; j++)
4598 ficcon << " " << cells[j];
4606 void SMDS_Mesh::compactMesh()
4608 MESSAGE("SMDS_Mesh::compactMesh do nothing!");
4611 int SMDS_Mesh::fromVtkToSmds(int vtkid)
4613 if (vtkid >= 0 && vtkid < myCellIdVtkToSmds.size())
4614 return myCellIdVtkToSmds[vtkid];
4615 throw SALOME_Exception(LOCALIZED ("vtk id out of bounds"));
4618 void SMDS_Mesh::updateBoundingBox()
4623 vtkPoints *points = myGrid->GetPoints();
4624 int myNodesSize = this->myNodes.size();
4625 for (int i = 0; i < myNodesSize; i++)
4627 if (SMDS_MeshNode *n = myNodes[i])
4630 points->GetPoint(n->myVtkID, coords);
4631 if (coords[0] < xmin) xmin = coords[0];
4632 else if (coords[0] > xmax) xmax = coords[0];
4633 if (coords[1] < ymin) ymin = coords[1];
4634 else if (coords[1] > ymax) ymax = coords[1];
4635 if (coords[2] < zmin) zmin = coords[2];
4636 else if (coords[2] > zmax) zmax = coords[2];
4641 double SMDS_Mesh::getMaxDim()
4643 double dmax = 1.e-3;
4644 if ((xmax - xmin) > dmax) dmax = xmax -xmin;
4645 if ((ymax - ymin) > dmax) dmax = ymax -ymin;
4646 if ((zmax - zmin) > dmax) dmax = zmax -zmin;
4647 MESSAGE("getMaxDim " << dmax);
4651 //! modification that needs compact structure and redraw
4652 void SMDS_Mesh::Modified()
4654 if (this->myModified)
4656 this->myModifTime++;
4657 MESSAGE("modified");
4662 //! get last modification timeStamp
4663 unsigned long SMDS_Mesh::GetMTime() const
4665 return this->myModifTime;
4668 bool SMDS_Mesh::isCompacted()
4670 if (this->myModifTime > this->myCompactTime)
4672 MESSAGE(" *** isCompacted " << myCompactTime << " < " << myModifTime);
4673 this->myCompactTime = this->myModifTime;