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
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>
42 class SMDS_ElementChunk;
45 class SMDS_UnstructuredGrid;
47 // ============================================================
49 * \brief Base class for elements
51 // ============================================================
54 class SMDS_EXPORT SMDS_MeshElement : public SMDS_MeshObject
58 // ===========================
60 // ===========================
61 virtual SMDS_ElemIteratorPtr nodesIterator() const = 0;
63 virtual SMDS_NodeIteratorPtr nodeIterator() const = 0;
64 virtual SMDS_NodeIteratorPtr interlacedNodesIterator() const { return nodeIterator(); }
65 virtual SMDS_NodeIteratorPtr nodesIteratorToUNV() const { return nodeIterator(); }
67 // std-like iteration on nodes
68 typedef SMDS_StdIterator< const SMDS_MeshNode*, SMDS_NodeIteratorPtr > iterator;
69 iterator begin_nodes() const { return iterator( nodeIterator() ); }
70 iterator end_nodes() const { return iterator(); }
72 // ===========================
74 // ===========================
75 virtual int NbNodes() const = 0;
76 virtual int NbEdges() const = 0;
77 virtual int NbFaces() const = 0;
79 virtual SMDSAbs_ElementType GetType() const = 0;
80 virtual SMDSAbs_EntityType GetEntityType() const = 0;
81 virtual SMDSAbs_GeometryType GetGeomType() const = 0;
82 virtual VTKCellType GetVtkType() const = 0;
84 virtual bool IsPoly() const = 0;
85 virtual bool IsQuadratic() const = 0;
86 virtual bool IsMediumNode(const SMDS_MeshNode* node) const;
87 virtual int NbCornerNodes() const = 0;
89 // ===========================
90 // Access to nodes by index
91 // ===========================
93 * \brief Return node by its index
94 * \param ind - node index
95 * \retval const SMDS_MeshNode* - the node
97 virtual const SMDS_MeshNode* GetNode(const int ind) const = 0;
100 * \brief Return node by its index
101 * \param ind - node index
102 * \retval const SMDS_MeshNode* - the node
104 * Index is wrapped if it is out of a valid range of corner nodes
106 const SMDS_MeshNode* GetNodeWrap(const int ind) const { return GetNode( WrappedIndex( ind )); }
109 * \brief Return true if index of node is valid (0 <= ind < NbNodes())
110 * \param ind - node index
111 * \retval bool - index check result
113 virtual bool IsValidIndex(const int ind) const;
116 * \brief Return a valid corner node index, fixing the given one if necessary
117 * \param ind - node index
118 * \retval int - valid node index
120 int WrappedIndex(const int ind) const;
123 * \brief Check if a node belongs to the element
124 * \param node - the node to check
125 * \retval int - node index within the element, -1 if not found
127 virtual int GetNodeIndex( const SMDS_MeshNode* node ) const;
130 virtual int GetID() const;
131 virtual int GetVtkID() const;
132 virtual int getshapeId() const { return GetShapeID(); }
133 virtual int GetShapeID() const;
135 // mark this element; to be used in algos
136 virtual void setIsMarked( bool is ) const;
137 virtual bool isMarked() const;
139 // element can be allocated but "not used"
140 bool IsNull() const { return myHolder == 0; }
142 SMDS_Mesh* GetMesh() const;
144 void Print(std::ostream & OS) const;
146 friend SMDS_EXPORT std::ostream & operator <<(std::ostream & OS, const SMDS_MeshElement *);
147 friend class SMDS_ElementFactory;
148 friend class SMESHDS_SubMesh;
151 * \brief Filters of elements, to be used with SMDS_SetIterator
155 virtual bool operator()(const SMDS_MeshElement* e) const = 0;
158 struct NonNullFilter: public Filter
160 bool operator()(const SMDS_MeshElement* e) const { return e; }
162 struct TypeFilter : public Filter
164 SMDSAbs_ElementType _type;
165 TypeFilter( SMDSAbs_ElementType t = SMDSAbs_NbElementTypes ):_type(t) {}
166 bool operator()(const SMDS_MeshElement* e) const { return e && e->GetType() == _type; }
168 struct EntityFilter : public Filter
170 SMDSAbs_EntityType _type;
171 EntityFilter( SMDSAbs_EntityType t = SMDSEntity_Last ):_type(t) {}
172 bool operator()(const SMDS_MeshElement* e) const { return e && e->GetEntityType() == _type; }
174 struct GeomFilter : public Filter
176 SMDSAbs_GeometryType _type;
177 GeomFilter( SMDSAbs_GeometryType t = SMDSGeom_NONE ):_type(t) {}
178 bool operator()(const SMDS_MeshElement* e) const { return e && e->GetGeomType() == _type; }
185 void setVtkID(const int vtkID );
186 virtual void setShapeID( const int shapeID ) const;
188 SMDS_UnstructuredGrid* getGrid() const;
192 SMDS_ElementChunk* myHolder;
195 // ============================================================
197 * \brief Comparator of elements by ID for usage in std containers
199 // ============================================================
201 struct TIDTypeCompare {
202 bool operator () (const SMDS_MeshElement* e1, const SMDS_MeshElement* e2) const
203 { return e1->GetType() == e2->GetType() ? e1->GetID() < e2->GetID() : e1->GetType() < e2->GetType(); }
206 // WARNING: this comparator makes impossible to store both nodes and elements in the same set
207 // because there are nodes and elements with the same ID. Use TIDTypeCompare for such containers.
209 bool operator () (const SMDS_MeshElement* e1, const SMDS_MeshElement* e2) const
210 { return e1->GetID() < e2->GetID(); }