Salome HOME
Update of CheckDone
[modules/smesh.git] / src / SMDS / SMDS_MeshElement.hxx
1 // Copyright (C) 2007-2024  CEA, EDF, 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 //  File   : SMDS_MeshElement.hxx
25 //  Module : SMESH
26 //
27 #ifndef _SMDS_MeshElement_HeaderFile
28 #define _SMDS_MeshElement_HeaderFile
29
30 #include "SMESH_SMDS.hxx"
31         
32 #include "SMDSAbs_ElementType.hxx"
33 #include "SMDS_MeshObject.hxx"
34 #include "SMDS_ElemIterator.hxx"
35 #include "SMDS_StdIterator.hxx"
36
37 #include <iostream>
38
39 #include <vtkType.h>
40 #include <vtkCellType.h>
41 #include <smIdType.hxx>
42
43 class SMDS_ElementChunk;
44 class SMDS_Mesh;
45 class SMDS_MeshNode;
46 class SMDS_UnstructuredGrid;
47
48 // ============================================================
49 /*!
50  * \brief Base class for elements
51  */
52 // ============================================================
53
54
55 class SMDS_EXPORT SMDS_MeshElement : public SMDS_MeshObject
56 {
57 public:
58
59   // ===========================
60   // Access to nodes
61   // ===========================
62   virtual SMDS_ElemIteratorPtr nodesIterator() const = 0;
63
64   virtual SMDS_NodeIteratorPtr nodeIterator() const = 0;
65   virtual SMDS_NodeIteratorPtr interlacedNodesIterator() const { return nodeIterator(); }
66   virtual SMDS_NodeIteratorPtr nodesIteratorToUNV() const  { return nodeIterator(); }
67
68   // std-like iteration on nodes
69   typedef SMDS_StdIterator< const SMDS_MeshNode*, SMDS_NodeIteratorPtr > iterator;
70   iterator begin_nodes() const { return iterator( nodeIterator() ); }
71   iterator end_nodes()   const { return iterator(); }
72
73   // ===========================
74   // Type of element
75   // ===========================
76   virtual int NbNodes() const = 0;
77   virtual int NbEdges() const = 0;
78   virtual int NbFaces() const = 0;
79
80   virtual SMDSAbs_ElementType  GetType() const = 0;
81   virtual SMDSAbs_EntityType   GetEntityType() const = 0;
82   virtual SMDSAbs_GeometryType GetGeomType() const = 0;
83   virtual VTKCellType          GetVtkType() const = 0;
84
85   virtual bool IsPoly() const = 0;
86   virtual bool IsQuadratic() const = 0;
87   virtual bool IsMediumNode(const SMDS_MeshNode* node) const;
88   virtual int  NbCornerNodes() const = 0;
89
90   // ===========================
91   //  Access to nodes by index
92   // ===========================
93   /*!
94    * \brief Return node by its index
95     * \param ind - node index
96     * \retval const SMDS_MeshNode* - the node
97    */
98   virtual const SMDS_MeshNode* GetNode(const int ind) const = 0;
99
100   /*!
101    * \brief Return node by its index
102     * \param ind - node index
103     * \retval const SMDS_MeshNode* - the node
104    * 
105    * Index is wrapped if it is out of a valid range of corner nodes
106    */
107   const SMDS_MeshNode* GetNodeWrap(const int ind) const { return GetNode( WrappedIndex( ind )); }
108
109   /*!
110    * \brief Return true if index of node is valid (0 <= ind < NbNodes())
111     * \param ind - node index
112     * \retval bool - index check result
113    */
114   virtual bool IsValidIndex(const int ind) const;
115
116   /*!
117    * \brief Return a valid corner node index, fixing the given one if necessary
118     * \param ind - node index
119     * \retval int - valid node index
120    */
121   int WrappedIndex(const int ind) const;
122
123   /*!
124    * \brief Check if a node belongs to the element
125     * \param node - the node to check
126     * \retval int - node index within the element, -1 if not found
127    */
128   virtual int GetNodeIndex( const SMDS_MeshNode* node ) const;
129
130
131   virtual smIdType  GetID() const;
132   virtual vtkIdType GetVtkID()   const;
133   virtual int  getshapeId() const { return GetShapeID(); }
134   virtual int  GetShapeID() const;
135
136   // mark this element; to be used in algos
137   virtual void setIsMarked( bool is ) const;
138   virtual bool isMarked() const;
139
140   // element can be allocated but "not used"
141   bool IsNull() const { return myHolder == 0; }
142
143   SMDS_Mesh* GetMesh() const;
144
145   void Print(std::ostream & OS) const;
146
147   friend SMDS_EXPORT std::ostream & operator <<(std::ostream & OS, const SMDS_MeshElement *);
148   friend class SMDS_ElementFactory;
149   friend class SMESHDS_SubMesh;
150
151   /*!
152    * \brief Filters of elements, to be used with SMDS_SetIterator
153    */
154   struct Filter
155   {
156     virtual bool operator()(const SMDS_MeshElement* e) const = 0;
157     virtual ~Filter() {}
158   };
159   struct NonNullFilter: public Filter
160   {
161     bool operator()(const SMDS_MeshElement* e) const { return e; }
162   };
163   struct TypeFilter : public Filter
164   {
165     SMDSAbs_ElementType _type;
166     TypeFilter( SMDSAbs_ElementType t = SMDSAbs_NbElementTypes ):_type(t) {}
167     bool operator()(const SMDS_MeshElement* e) const { return e && e->GetType() == _type; }
168   };
169   struct EntityFilter : public Filter
170   {
171     SMDSAbs_EntityType _type;
172     EntityFilter( SMDSAbs_EntityType t = SMDSEntity_Last ):_type(t) {}
173     bool operator()(const SMDS_MeshElement* e) const { return e && e->GetEntityType() == _type; }
174   };
175   struct GeomFilter : public Filter
176   {
177     SMDSAbs_GeometryType _type;
178     GeomFilter( SMDSAbs_GeometryType t = SMDSGeom_NONE ):_type(t) {}
179     bool operator()(const SMDS_MeshElement* e) const { return e && e->GetGeomType() == _type; }
180   };
181
182  protected:
183
184   SMDS_MeshElement();
185
186   void setVtkID(const vtkIdType vtkID );
187   virtual void setShapeID( const int shapeID ) const;
188
189   SMDS_UnstructuredGrid* getGrid() const;
190
191  protected:
192
193   SMDS_ElementChunk* myHolder;
194 };
195
196 // ============================================================
197 /*!
198  * \brief Comparator of elements by ID for usage in std containers
199  */
200 // ============================================================
201
202 struct TIDTypeCompare {
203   bool operator () (const SMDS_MeshElement* e1, const SMDS_MeshElement* e2) const
204   { return e1->GetType() == e2->GetType() ? e1->GetID() < e2->GetID() : e1->GetType() < e2->GetType(); }
205 };
206
207 // WARNING: this comparator makes impossible to store both nodes and elements in the same set
208 // because there are nodes and elements with the same ID. Use TIDTypeCompare for such containers.
209 struct TIDCompare {
210   bool operator () (const SMDS_MeshElement* e1, const SMDS_MeshElement* e2) const
211   { return e1->GetID() < e2->GetID(); }
212 };
213
214 #endif