1 // Copyright (C) 2007-2020 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
22 // File : SMDS_ElementHolder.cxx
26 #include "SMDS_ElementHolder.hxx"
28 #include "ObjectPool.hxx"
29 #include "SMDS_CellOfNodes.hxx"
30 #include "SMDS_Mesh.hxx"
32 //=======================================================================
33 //function : SMDS_ElementHolder
34 //purpose : register self in the mesh
35 //=======================================================================
37 SMDS_ElementHolder::SMDS_ElementHolder( const SMDS_Mesh* mesh )
38 : myMesh( const_cast< SMDS_Mesh* >( mesh ))
41 myPtrInMesh = myMesh->myElemHolders.insert( this ).first;
44 //=======================================================================
45 //function : ~SMDS_ElementHolder
46 //purpose : un-register self from the mesh
47 //=======================================================================
49 SMDS_ElementHolder::~SMDS_ElementHolder()
52 myMesh->myElemHolders.erase( myPtrInMesh );
55 //=======================================================================
56 //function : beforeCompacting
57 //purpose : store vtkIDs of elements
58 //=======================================================================
60 void SMDS_ElementHolder::beforeCompacting()
63 for ( SMDS_ElemIteratorPtr it = getElements(); it->more(); ++i )
65 const SMDS_MeshElement* e = it->next();
67 if ( e->IsNull() && !dynamic_cast<const SMDS_CellOfNodes*>( e ))
68 continue; // removed element
69 myIsNode.push_back( e->GetType() == SMDSAbs_Node );
70 if ( myMesh->Contains( e ))
72 myVtkIDs.push_back( e->GetVtkID() );
76 myExternalElems.push_back( e );
77 myVtkIDs.push_back( -1 * (int)myExternalElems.size() );
82 //=======================================================================
83 //function : restoreElements
84 //purpose : restore pointers to elements
85 //=======================================================================
87 void SMDS_ElementHolder::restoreElements( const std::vector<int>& idNodesOldToNew,
88 const std::vector<int>& idCellsOldToNew )
92 const SMDS_MeshElement* elem;
94 std::vector< bool >::iterator isNode = myIsNode.begin();
95 for ( size_t i = 0; i < myVtkIDs.size(); ++i, ++isNode )
97 int vtkID = myVtkIDs[i];
100 elem = myExternalElems[ (-vtkID)-1 ];
104 if ( vtkID < (int)idNodesOldToNew.size() )
105 elem = myMesh->FindNodeVtk( idNodesOldToNew[ vtkID ]);
107 elem = myMesh->FindNodeVtk( vtkID );
111 if ( vtkID < (int)idCellsOldToNew.size() )
112 elem = myMesh->FindElementVtk( idCellsOldToNew[ vtkID ]);
114 elem = myMesh->FindElementVtk( vtkID );
119 clearVector( myExternalElems );
120 clearVector( myVtkIDs );
121 clearVector( myIsNode );