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
23 // SMESH SMDS : implementation of Salome mesh data structure
26 #pragma warning(disable:4786)
29 #include "SMDS_MeshElement.hxx"
31 #include "SMDS_Mesh.hxx"
32 #include "SMDS_ElementFactory.hxx"
34 #include "utilities.h"
36 //================================================================================
38 * \brief Constructor of a non-used element
40 //================================================================================
42 SMDS_MeshElement::SMDS_MeshElement(): myHolder(0)
46 //================================================================================
48 * \brief Check if a node is a medium node of a quadratic cell
50 //================================================================================
52 bool SMDS_MeshElement::IsMediumNode(const SMDS_MeshNode* node) const
54 return !( GetNodeIndex( node ) < NbCornerNodes() );
57 //================================================================================
59 * \brief Return true if index of node is valid (0 <= ind < NbNodes())
60 * \param ind - node index
61 * \retval bool - index check result
63 //================================================================================
65 bool SMDS_MeshElement::IsValidIndex(const int ind) const
67 return ( ind>-1 && ind<NbNodes() );
70 //================================================================================
72 * \brief Return a valid corner node index, fixing the given one if necessary
73 * \param ind - node index
74 * \retval int - valid node index
76 //================================================================================
78 int SMDS_MeshElement::WrappedIndex(const int ind) const
80 if ( ind < 0 ) return NbCornerNodes() + ind % NbCornerNodes();
81 if ( ind >= NbCornerNodes() ) return ind % NbCornerNodes();
85 //================================================================================
87 * \brief Check if a node belongs to the element
88 * \param node - the node to check
89 * \retval int - node index within the element, -1 if not found
91 //================================================================================
93 int SMDS_MeshElement::GetNodeIndex( const SMDS_MeshNode* node ) const
95 SMDS_ElemIteratorPtr nIt = nodesIterator();
96 for ( int i = 0; nIt->more(); ++i )
97 if ( nIt->next() == node )
102 //================================================================================
104 * \brief Return ID of an element
106 //================================================================================
108 int SMDS_MeshElement::GetID() const
110 return myHolder ? myHolder->GetID( this ) : -1;
113 //================================================================================
115 * \brief Set ID of a shape this element was generated on
117 //================================================================================
119 void SMDS_MeshElement::setShapeID( const int shapeID ) const
121 const_cast<SMDS_ElementChunk*>( myHolder )->SetShapeID( this, shapeID );
124 //================================================================================
126 * \brief Return ID of a shape this element was generated on
128 //================================================================================
130 int SMDS_MeshElement::GetShapeID() const
132 return myHolder->GetShapeID( this );
135 //================================================================================
137 * \brief Return VTK ID of this element
139 //================================================================================
141 int SMDS_MeshElement::GetVtkID() const
143 return myHolder->GetVtkID( this );
146 //================================================================================
148 * \brief Mark this element
150 //================================================================================
152 void SMDS_MeshElement::setIsMarked( bool is ) const
154 const_cast<SMDS_ElementChunk*>( myHolder )->SetIsMarked( this, is );
157 //================================================================================
159 * \brief Check if this element is marked
161 //================================================================================
163 bool SMDS_MeshElement::isMarked() const
165 return myHolder->IsMarked( this );
168 //================================================================================
170 * \brief Store VTK ID
172 //================================================================================
174 void SMDS_MeshElement::setVtkID( const int vtkID )
176 myHolder->SetVTKID( this, vtkID );
179 //================================================================================
181 * \brief Return the mesh this element belongs to
183 //================================================================================
185 SMDS_Mesh* SMDS_MeshElement::GetMesh() const
187 return const_cast<SMDS_ElementChunk*>( myHolder )->GetMesh();
190 //================================================================================
192 * \brief Return a SMDS_UnstructuredGrid
194 //================================================================================
196 SMDS_UnstructuredGrid* SMDS_MeshElement::getGrid() const
198 return const_cast<SMDS_ElementChunk*>( myHolder )->GetMesh()->GetGrid();
201 //================================================================================
205 //================================================================================
207 void SMDS_MeshElement::Print(ostream & OS) const
209 OS << "dump of mesh element" << endl;
212 ostream & operator <<(ostream & OS, const SMDS_MeshElement * e)