1 // Copyright (C) 2007-2023 CEA, EDF, 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
24 // File : SMDS_MeshElement.hxx
27 #ifndef _SMDS_MeshElement_HeaderFile
28 #define _SMDS_MeshElement_HeaderFile
30 #include "SMESH_SMDS.hxx"
32 #include "SMDSAbs_ElementType.hxx"
33 #include "SMDS_MeshObject.hxx"
34 #include "SMDS_ElemIterator.hxx"
35 #include "SMDS_StdIterator.hxx"
40 #include <vtkCellType.h>
41 #include <smIdType.hxx>
43 class SMDS_ElementChunk;
46 class SMDS_UnstructuredGrid;
48 // ============================================================
50 * \brief Base class for elements
52 // ============================================================
55 class SMDS_EXPORT SMDS_MeshElement : public SMDS_MeshObject
59 // ===========================
61 // ===========================
62 virtual SMDS_ElemIteratorPtr nodesIterator() const = 0;
64 virtual SMDS_NodeIteratorPtr nodeIterator() const = 0;
65 virtual SMDS_NodeIteratorPtr interlacedNodesIterator() const { return nodeIterator(); }
66 virtual SMDS_NodeIteratorPtr nodesIteratorToUNV() const { return nodeIterator(); }
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(); }
73 // ===========================
75 // ===========================
76 virtual int NbNodes() const = 0;
77 virtual int NbEdges() const = 0;
78 virtual int NbFaces() const = 0;
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;
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;
90 // ===========================
91 // Access to nodes by index
92 // ===========================
94 * \brief Return node by its index
95 * \param ind - node index
96 * \retval const SMDS_MeshNode* - the node
98 virtual const SMDS_MeshNode* GetNode(const int ind) const = 0;
101 * \brief Return node by its index
102 * \param ind - node index
103 * \retval const SMDS_MeshNode* - the node
105 * Index is wrapped if it is out of a valid range of corner nodes
107 const SMDS_MeshNode* GetNodeWrap(const int ind) const { return GetNode( WrappedIndex( ind )); }
110 * \brief Return true if index of node is valid (0 <= ind < NbNodes())
111 * \param ind - node index
112 * \retval bool - index check result
114 virtual bool IsValidIndex(const int ind) const;
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
121 int WrappedIndex(const int ind) const;
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
128 virtual int GetNodeIndex( const SMDS_MeshNode* node ) const;
131 virtual smIdType GetID() const;
132 virtual vtkIdType GetVtkID() const;
133 virtual int getshapeId() const { return GetShapeID(); }
134 virtual int GetShapeID() const;
136 // mark this element; to be used in algos
137 virtual void setIsMarked( bool is ) const;
138 virtual bool isMarked() const;
140 // element can be allocated but "not used"
141 bool IsNull() const { return myHolder == 0; }
143 SMDS_Mesh* GetMesh() const;
145 void Print(std::ostream & OS) const;
147 friend SMDS_EXPORT std::ostream & operator <<(std::ostream & OS, const SMDS_MeshElement *);
148 friend class SMDS_ElementFactory;
149 friend class SMESHDS_SubMesh;
152 * \brief Filters of elements, to be used with SMDS_SetIterator
156 virtual bool operator()(const SMDS_MeshElement* e) const = 0;
159 struct NonNullFilter: public Filter
161 bool operator()(const SMDS_MeshElement* e) const { return e; }
163 struct TypeFilter : public Filter
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; }
169 struct EntityFilter : public Filter
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; }
175 struct GeomFilter : public Filter
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; }
186 void setVtkID(const vtkIdType vtkID );
187 virtual void setShapeID( const int shapeID ) const;
189 SMDS_UnstructuredGrid* getGrid() const;
193 SMDS_ElementChunk* myHolder;
196 // ============================================================
198 * \brief Comparator of elements by ID for usage in std containers
200 // ============================================================
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(); }
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.
210 bool operator () (const SMDS_MeshElement* e1, const SMDS_MeshElement* e2) const
211 { return e1->GetID() < e2->GetID(); }