Salome HOME
bos #20256: [CEA 18523] Porting SMESH to int 64 bits
[modules/smesh.git] / src / SMDS / SMDS_MeshElement.cxx
1 // Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SMESH SMDS : implementation of Salome mesh data structure
24 //
25 #ifdef _MSC_VER
26 #pragma warning(disable:4786)
27 #endif
28
29 #include "SMDS_MeshElement.hxx"
30
31 #include "SMDS_Mesh.hxx"
32 #include "SMDS_ElementFactory.hxx"
33
34 #include "utilities.h"
35
36 //================================================================================
37 /*!
38  * \brief Constructor of a non-used element
39  */
40 //================================================================================
41
42 SMDS_MeshElement::SMDS_MeshElement(): myHolder(0)
43 {
44 }
45
46 //================================================================================
47 /*!
48  * \brief Check if a node is a medium node of a quadratic cell
49  */
50 //================================================================================
51
52 bool SMDS_MeshElement::IsMediumNode(const SMDS_MeshNode* node) const
53 {
54   return !( GetNodeIndex( node ) < NbCornerNodes() );
55 }
56
57 //================================================================================
58 /*!
59  * \brief Return true if index of node is valid (0 <= ind < NbNodes())
60  *  \param ind - node index
61  *  \retval bool - index check result
62  */
63 //================================================================================
64
65 bool SMDS_MeshElement::IsValidIndex(const int ind) const
66 {
67   return ( ind>-1 && ind<NbNodes() );
68 }
69
70 //================================================================================
71 /*!
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
75  */
76 //================================================================================
77
78 int SMDS_MeshElement::WrappedIndex(const int ind) const
79 {
80   if ( ind < 0 ) return NbCornerNodes() + ind % NbCornerNodes();
81   if ( ind >= NbCornerNodes() ) return ind % NbCornerNodes();
82   return ind;
83 }
84
85 //================================================================================
86 /*!
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
90  */
91 //================================================================================
92
93 int SMDS_MeshElement::GetNodeIndex( const SMDS_MeshNode* node ) const
94 {
95   SMDS_ElemIteratorPtr nIt = nodesIterator();
96   for ( int i = 0; nIt->more(); ++i )
97     if ( nIt->next() == node )
98       return i;
99   return -1;
100 }
101
102 //================================================================================
103 /*!
104  * \brief Return ID of an element
105  */
106 //================================================================================
107
108 smIdType SMDS_MeshElement::GetID() const
109 {
110   return myHolder ? myHolder->GetID( this ) : -1;
111 }
112
113 //================================================================================
114 /*!
115  * \brief Set ID of a shape this element was generated on
116  */
117 //================================================================================
118
119 void SMDS_MeshElement::setShapeID( const int shapeID ) const
120 {
121   const_cast<SMDS_ElementChunk*>( myHolder )->SetShapeID( this, shapeID );
122 }
123
124 //================================================================================
125 /*!
126  * \brief Return ID of a shape this element was generated on
127  */
128 //================================================================================
129
130 int SMDS_MeshElement::GetShapeID() const
131 {
132   return myHolder->GetShapeID( this );
133 }
134
135 //================================================================================
136 /*!
137  * \brief Return VTK ID of this element
138  */
139 //================================================================================
140
141 vtkIdType SMDS_MeshElement::GetVtkID() const
142 {
143   return myHolder->GetVtkID( this );
144 }
145
146 //================================================================================
147 /*!
148  * \brief Mark this element
149  */
150 //================================================================================
151
152 void SMDS_MeshElement::setIsMarked( bool is ) const
153 {
154   const_cast<SMDS_ElementChunk*>( myHolder )->SetIsMarked( this, is );
155 }
156
157 //================================================================================
158 /*!
159  * \brief Check if this element is marked
160  */
161 //================================================================================
162
163 bool SMDS_MeshElement::isMarked() const
164 {
165   return myHolder->IsMarked( this );
166 }
167
168 //================================================================================
169 /*!
170  * \brief Store VTK ID
171  */
172 //================================================================================
173
174 void SMDS_MeshElement::setVtkID( const vtkIdType vtkID )
175 {
176   myHolder->SetVTKID( this, vtkID );
177 }
178
179 //================================================================================
180 /*!
181  * \brief Return the mesh this element belongs to
182  */
183 //================================================================================
184
185 SMDS_Mesh* SMDS_MeshElement::GetMesh() const
186 {
187   return const_cast<SMDS_ElementChunk*>( myHolder )->GetMesh();
188 }
189
190 //================================================================================
191 /*!
192  * \brief Return a SMDS_UnstructuredGrid
193  */
194 //================================================================================
195
196 SMDS_UnstructuredGrid* SMDS_MeshElement::getGrid() const
197 {
198   return const_cast<SMDS_ElementChunk*>( myHolder )->GetMesh()->GetGrid();
199 }
200
201 //================================================================================
202 /*!
203  * \brief Print self
204  */
205 //================================================================================
206
207 void SMDS_MeshElement::Print(ostream & OS) const
208 {
209   OS << "dump of mesh element" << endl;
210 }
211
212 ostream & operator <<(ostream & OS, const SMDS_MeshElement * e)
213 {
214   e->Print(OS);
215   return OS;
216 }