X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSMDS%2FSMDS_MeshElementIDFactory.cxx;h=cee7145626d7f9727a719c647bb48716dfe8d92e;hb=aa67cc96d730566d202d1014d97b7f0b3a4d71f4;hp=d635b0110c15ea89c0360c75d87946aaa202f336;hpb=13b8c20dfc9f5bedf2dd4699ac1e05a8d4227791;p=modules%2Fsmesh.git diff --git a/src/SMDS/SMDS_MeshElementIDFactory.cxx b/src/SMDS/SMDS_MeshElementIDFactory.cxx index d635b0110..cee714562 100644 --- a/src/SMDS/SMDS_MeshElementIDFactory.cxx +++ b/src/SMDS/SMDS_MeshElementIDFactory.cxx @@ -1,52 +1,113 @@ -// SMESH SMDS : implementaion of Salome mesh data structure +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. // -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. // +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + +// SMESH SMDS : implementaion of Salome mesh data structure // File : SMDS_MeshElementIDFactory.cxx // Author : Jean-Michel BOULCOURT // Module : SMESH - +// +#ifdef _MSC_VER +#pragma warning(disable:4786) +#endif #include "SMDS_MeshElementIDFactory.hxx" #include "SMDS_MeshElement.hxx" +#include "SMDS_Mesh.hxx" + +#include "utilities.h" + +#include +#include + +using namespace std; //======================================================================= //function : SMDS_MeshElementIDFactory //purpose : //======================================================================= -SMDS_MeshElementIDFactory::SMDS_MeshElementIDFactory():SMDS_MeshIDFactory() +SMDS_MeshElementIDFactory::SMDS_MeshElementIDFactory(): + SMDS_MeshNodeIDFactory() { +// myIDElements.clear(); +// myVtkIndex.clear(); + myVtkCellTypes.clear(); + myVtkCellTypes.reserve(SMDSEntity_Last); + myVtkCellTypes[SMDSEntity_Node] = VTK_VERTEX; + myVtkCellTypes[SMDSEntity_0D] = VTK_VERTEX; + myVtkCellTypes[SMDSEntity_Edge] = VTK_LINE; + myVtkCellTypes[SMDSEntity_Quad_Edge] = VTK_QUADRATIC_EDGE; + myVtkCellTypes[SMDSEntity_Triangle] = VTK_TRIANGLE; + myVtkCellTypes[SMDSEntity_Quad_Triangle] = VTK_QUADRATIC_TRIANGLE; + myVtkCellTypes[SMDSEntity_Quadrangle] = VTK_QUAD; + myVtkCellTypes[SMDSEntity_Quad_Quadrangle] = VTK_QUADRATIC_TRIANGLE; + myVtkCellTypes[SMDSEntity_Polygon] = VTK_POLYGON; + myVtkCellTypes[SMDSEntity_Quad_Polygon] = VTK_POLYGON; // -PR- verifer + myVtkCellTypes[SMDSEntity_Tetra] = VTK_TETRA; + myVtkCellTypes[SMDSEntity_Quad_Tetra] = VTK_QUADRATIC_TETRA; + myVtkCellTypes[SMDSEntity_Pyramid] = VTK_PYRAMID; + myVtkCellTypes[SMDSEntity_Quad_Pyramid] = VTK_CONVEX_POINT_SET; + myVtkCellTypes[SMDSEntity_Hexa] = VTK_HEXAHEDRON; + myVtkCellTypes[SMDSEntity_Quad_Hexa] = VTK_QUADRATIC_HEXAHEDRON; + myVtkCellTypes[SMDSEntity_Penta] = VTK_WEDGE; + myVtkCellTypes[SMDSEntity_Quad_Penta] = VTK_QUADRATIC_WEDGE; + myVtkCellTypes[SMDSEntity_Polyhedra] = VTK_CONVEX_POINT_SET; + myVtkCellTypes[SMDSEntity_Quad_Polyhedra] = VTK_CONVEX_POINT_SET; +} + +int SMDS_MeshElementIDFactory::SetInVtkGrid(SMDS_MeshElement * elem) +{ + // --- retreive nodes ID + + vector nodeIds; + SMDS_ElemIteratorPtr it = elem->nodesIterator(); + while(it->more()) + { + int nodeId = it->next()->GetID(); + //MESSAGE(" node in cell " << ID << " : " <getGrid(); + int typ = GetVtkCellType(elem->GetType()); + int cellId = grid->InsertNextLinkedCell(typ, nodeIds.size(), &nodeIds[0]); + SMDS_MeshCell *cell = dynamic_cast(elem); + assert(cell); + cell->setVtkId(cellId); + //MESSAGE("SMDS_MeshElementIDFactory::SetInVtkGrid " << cellId); + return cellId; } //======================================================================= //function : BindID //purpose : //======================================================================= + bool SMDS_MeshElementIDFactory::BindID(int ID, SMDS_MeshElement * elem) { - bool bound=myIDElements.insert( - map::value_type(ID,elem)).second; - if(bound) elem->myID=ID; - return bound; + MESSAGE("SMDS_MeshElementIDFactory::BindID " << ID); + SetInVtkGrid(elem); + return myMesh->registerElement(ID, elem); } //======================================================================= @@ -55,6 +116,67 @@ bool SMDS_MeshElementIDFactory::BindID(int ID, SMDS_MeshElement * elem) //======================================================================= SMDS_MeshElement* SMDS_MeshElementIDFactory::MeshElement(int ID) { - map::iterator it=myIDElements.find(ID); - if(it==myIDElements.end()) return NULL; else return (*it).second; + if ((ID<0) || (ID>myMax) || (myMesh->myIDElements[ID]<0)) + return NULL; + const SMDS_MeshElement* elem = GetMesh()->FindElement(ID); + return (SMDS_MeshElement*)(elem); +} + +//======================================================================= +//function : ReleaseID +//purpose : +//======================================================================= +void SMDS_MeshElementIDFactory::ReleaseID(const int ID) +{ + int vtkId = myMesh->myIDElements[ID]; + //MESSAGE("~~~~~~~~~~~~~~ SMDS_MeshElementIDFactory::ReleaseID smdsId vtkId " << ID << " " << vtkId); + myMesh->myIDElements[ID] = -1; + myMesh->myVtkIndex[vtkId] = -1; + SMDS_MeshIDFactory::ReleaseID(ID); + if (ID == myMax) + myMax = 0; + if (ID == myMin) + myMax = 0; +} + +//======================================================================= +//function : updateMinMax +//purpose : +//======================================================================= + +void SMDS_MeshElementIDFactory::updateMinMax() const +{ + myMin = IntegerLast(); + myMax = 0; + for (int i=0; imyIDElements.size(); i++) + if (int id=myMesh->myIDElements[i] >=0) + { + if (id > myMax) myMax = id; + if (id < myMin) myMin = id; + } + if (myMin == IntegerLast()) + myMin = 0; +} + +//======================================================================= +//function : elementsIterator +//purpose : Return an iterator on elements of the factory +//======================================================================= + +SMDS_ElemIteratorPtr SMDS_MeshElementIDFactory::elementsIterator() const +{ + return myMesh->elementsIterator(SMDSAbs_All); +} + +void SMDS_MeshElementIDFactory::Clear() +{ + myMesh->myIDElements.clear(); + myMin = myMax = 0; + SMDS_MeshIDFactory::Clear(); +} + +int SMDS_MeshElementIDFactory::GetVtkCellType(int SMDSType) +{ + assert((SMDSType >=0) && (SMDSType< SMDSEntity_Last)); + return myVtkCellTypes[SMDSType]; }