Back to index

salome-smesh  6.5.0
SMDS_MeshElement.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SMESH SMDS : implementaion of Salome mesh data structure
00024 //  File   : SMDS_MeshElement.hxx
00025 //  Module : SMESH
00026 //
00027 #ifndef _SMDS_MeshElement_HeaderFile
00028 #define _SMDS_MeshElement_HeaderFile
00029 
00030 #include "SMESH_SMDS.hxx"
00031         
00032 #include "SMDSAbs_ElementType.hxx"
00033 #include "SMDS_MeshObject.hxx"
00034 #include "SMDS_ElemIterator.hxx"
00035 #include "SMDS_MeshElementIDFactory.hxx"
00036 #include "SMDS_StdIterator.hxx"
00037 
00038 #include <vector>
00039 #include <iostream>
00040 
00041 #include <vtkType.h>
00042 #include <vtkCellType.h>
00043 
00044 //typedef unsigned short UShortType;
00045 typedef short ShortType;
00046 typedef int   LongType;
00047 
00048 class SMDS_MeshNode;
00049 class SMDS_MeshEdge;
00050 class SMDS_MeshFace;
00051 class SMDS_Mesh;
00052 
00053 // ============================================================
00057 // ============================================================
00058 
00059 
00060 class SMDS_EXPORT SMDS_MeshElement:public SMDS_MeshObject
00061 {
00062 public:
00063 
00064   SMDS_ElemIteratorPtr nodesIterator() const;
00065   SMDS_ElemIteratorPtr edgesIterator() const;
00066   SMDS_ElemIteratorPtr facesIterator() const;
00067   virtual SMDS_ElemIteratorPtr elementsIterator(SMDSAbs_ElementType type) const;
00068   virtual SMDS_ElemIteratorPtr nodesIteratorToUNV() const;
00069   virtual SMDS_ElemIteratorPtr interlacedNodesElemIterator() const;
00070 
00071   // std-like iteration on nodes
00072   typedef SMDS_StdIterator< const SMDS_MeshNode*, SMDS_ElemIteratorPtr > iterator;
00073   iterator begin_nodes() const { return iterator( nodesIterator() ); }
00074   iterator end_nodes()   const { return iterator(); }
00075 
00076   virtual int NbNodes() const;
00077   virtual int NbEdges() const;
00078   virtual int NbFaces() const;
00079   inline int GetID() const { return myID; };
00080 
00082   virtual SMDSAbs_ElementType GetType() const = 0;
00083   virtual vtkIdType GetVtkType() const = 0;
00084   virtual bool IsPoly() const { return false; };
00085   virtual bool IsQuadratic() const;
00087   virtual SMDSAbs_EntityType  GetEntityType() const = 0;
00088 
00089   virtual bool IsMediumNode(const SMDS_MeshNode* node) const;
00090   virtual int  NbCornerNodes() const;
00091 
00092   friend SMDS_EXPORT std::ostream & operator <<(std::ostream & OS, const SMDS_MeshElement *);
00093   friend SMDS_EXPORT bool SMDS_MeshElementIDFactory::BindID(int ID,SMDS_MeshElement* elem);
00094   friend class SMDS_Mesh;
00095   friend class SMESHDS_Mesh;
00096   friend class SMESHDS_SubMesh;
00097   friend class SMDS_MeshElementIDFactory;
00098 
00099   // ===========================
00100   //  Access to nodes by index
00101   // ===========================
00107   virtual const SMDS_MeshNode* GetNode(const int ind) const;
00108 
00116   const SMDS_MeshNode* GetNodeWrap(const int ind) const { return GetNode( WrappedIndex( ind )); }
00117 
00123   virtual bool IsValidIndex(const int ind) const;
00124 
00130   int WrappedIndex(const int ind) const {
00131     if ( ind < 0 ) return NbNodes() + ind % NbNodes();
00132     if ( ind >= NbNodes() ) return ind % NbNodes();
00133     return ind;
00134   }
00135 
00141   int GetNodeIndex( const SMDS_MeshNode* node ) const;
00142 
00143   inline ShortType getMeshId() const {return myMeshId; }
00144   inline LongType  getshapeId() const {return myShapeId; }
00145   inline int getIdInShape() const { return myIdInShape; }
00146   inline int getVtkId() const { return myVtkID; }
00147 
00148 protected:
00149   inline void setId(int id) {myID = id; }
00150   inline void setShapeId(LongType shapeId) {myShapeId = shapeId; }
00151   inline void setIdInShape(int id) { myIdInShape = id; }
00152   inline void setVtkId(int vtkId) { myVtkID = vtkId; }
00153   SMDS_MeshElement(int ID=-1);
00154   SMDS_MeshElement(int id, ShortType meshId, LongType shapeId = 0);
00155   virtual void init(int id = -1, ShortType meshId = -1, LongType shapeId = 0);
00156   virtual void Print(std::ostream & OS) const;
00157 
00159   int myID;
00161   int myVtkID;
00163   ShortType myMeshId;
00165   LongType myShapeId;
00167   int myIdInShape;
00168 };
00169 
00170 
00171 // ============================================================
00175 // ============================================================
00176 
00177 struct TIDCompare {
00178   bool operator () (const SMDS_MeshElement* e1, const SMDS_MeshElement* e2) const
00179   { return e1->GetID() < e2->GetID(); }
00180 };
00181 
00182 #endif