1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMDS : implementaion of Salome mesh data structure
24 // File : SMDS_MeshElementIDFactory.cxx
25 // Author : Jean-Michel BOULCOURT
29 #pragma warning(disable:4786)
32 #include "SMDS_MeshElementIDFactory.hxx"
33 #include "SMDS_MeshElement.hxx"
34 #include "SMDS_Mesh.hxx"
36 #include "utilities.h"
38 #include "SMDS_UnstructuredGrid.hxx"
39 #include <vtkCellType.h>
45 //=======================================================================
46 //function : SMDS_MeshElementIDFactory
48 //=======================================================================
49 SMDS_MeshElementIDFactory::SMDS_MeshElementIDFactory():
50 SMDS_MeshNodeIDFactory()
54 int SMDS_MeshElementIDFactory::SetInVtkGrid(SMDS_MeshElement * elem)
56 // --- retrieve nodes ID
58 SMDS_MeshCell *cell = dynamic_cast<SMDS_MeshCell*>(elem);
60 vector<vtkIdType> nodeIds( elem->NbNodes() );
61 SMDS_ElemIteratorPtr it = elem->nodesIterator();
62 for( int i = 0; it->more(); ++i )
64 int nodeId = (static_cast<const SMDS_MeshNode*>(it->next()))->getVtkId();
68 // --- insert cell in vtkUnstructuredGrid
71 int cellId = myMesh->getGrid()->InsertNextLinkedCell(typ, nodeIds.size(), &nodeIds[0]);
72 cell->setVtkId(cellId);
76 //=======================================================================
79 //=======================================================================
81 bool SMDS_MeshElementIDFactory::BindID(int ID, SMDS_MeshElement * elem)
83 MESSAGE("SMDS_MeshElementIDFactory::BindID " << ID);
85 return myMesh->registerElement(ID, elem);
88 //=======================================================================
89 //function : MeshElement
91 //=======================================================================
92 SMDS_MeshElement* SMDS_MeshElementIDFactory::MeshElement(int ID)
94 if ( ID<1 || ID >= (int) myMesh->myCells.size() )
96 const SMDS_MeshElement* elem = GetMesh()->FindElement(ID);
97 return (SMDS_MeshElement*)(elem);
100 //=======================================================================
101 //function : GetFreeID
103 //=======================================================================
105 int SMDS_MeshElementIDFactory::GetFreeID()
109 ID = SMDS_MeshIDFactory::GetFreeID();
110 } while ( MeshElement( ID ));
114 //=======================================================================
115 //function : ReleaseID
117 //=======================================================================
118 void SMDS_MeshElementIDFactory::ReleaseID(int ID, int vtkId)
120 if (ID < 1) // TODO check case ID == O
122 MESSAGE("~~~~~~~~~~~~~~ SMDS_MeshElementIDFactory::ReleaseID ID = " << ID);
127 assert(vtkId < (int)myMesh->myCellIdVtkToSmds.size());
128 myMesh->myCellIdVtkToSmds[vtkId] = -1;
129 myMesh->setMyModified();
131 SMDS_MeshIDFactory::ReleaseID(ID);
138 //=======================================================================
139 //function : updateMinMax
141 //=======================================================================
143 void SMDS_MeshElementIDFactory::updateMinMax() const
147 for (size_t i = 0; i < myMesh->myCells.size(); i++)
149 if (myMesh->myCells[i])
151 int id = myMesh->myCells[i]->GetID();
158 if (myMin == INT_MAX)
162 //=======================================================================
163 //function : elementsIterator
164 //purpose : Return an iterator on elements of the factory
165 //=======================================================================
167 SMDS_ElemIteratorPtr SMDS_MeshElementIDFactory::elementsIterator() const
169 return myMesh->elementsIterator(SMDSAbs_All);
172 void SMDS_MeshElementIDFactory::Clear()
174 myMesh->myCellIdVtkToSmds.clear();
176 SMDS_MeshIDFactory::Clear();