Salome HOME
bos #20256: [CEA 18523] Porting SMESH to int 64 bits
[modules/smesh.git] / src / SMESH / SMESH_ProxyMesh.hxx
1 // Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // File      : SMESH_ProxyMesh.hxx
21 // Created   : Thu Dec  2 10:05:35 2010
22 // Author    : Edward AGAPOV (eap)
23
24 #ifndef __SMESH_ProxyMesh_HXX__
25 #define __SMESH_ProxyMesh_HXX__
26
27 #include "SMESH_SMESH.hxx"
28
29 #include "SMDS_ElementHolder.hxx"
30 #include "SMESHDS_SubMesh.hxx"
31 #include "SMESH_TypeDefs.hxx"
32
33 #include <TopoDS_Shape.hxx>
34 #include <NCollection_DataMap.hxx>
35 #include <smIdType.hxx>
36
37 #include <map>
38 #include <vector>
39 #include <boost/shared_ptr.hpp>
40
41 class SMDS_MeshNode;
42 class SMDS_MeshElement;
43 class SMESHDS_Mesh;
44 class SMESH_Mesh;
45
46 /*!
47  * \brief Container of xD mesh elements substituting other ones in the
48  *        input mesh of an (x+1)D algorithm
49  */
50 class SMESH_EXPORT SMESH_ProxyMesh
51 {
52 public:
53
54   typedef boost::shared_ptr<SMESH_ProxyMesh> Ptr;
55
56   typedef std::map<const SMDS_MeshNode*, const SMDS_MeshNode*, TIDCompare > TN2NMap;
57
58   //--------------------------------------------------------------------------------
59   /*!
60    * \brief Proxy sub-mesh
61    */
62   class SMESH_EXPORT SubMesh : public SMESHDS_SubMesh
63   {
64   public:
65
66     const TN2NMap*       GetNodeNodeMap() const { return _n2n; }
67     const SMDS_MeshNode* GetProxyNode( const SMDS_MeshNode* n ) const;
68     const UVPtStructVec& GetUVPtStructVec() const { return _uvPtStructVec; }
69     virtual void         AddElement(const SMDS_MeshElement * e);
70     virtual smIdType     NbElements() const;
71     virtual smIdType     NbNodes() const;
72     virtual SMDS_ElemIteratorPtr GetElements() const;
73     virtual SMDS_NodeIteratorPtr GetNodes() const;
74     virtual void         Clear();
75     virtual bool         Contains(const SMDS_MeshElement * ME) const;
76
77     template< class ITERATOR >
78       void ChangeElements( ITERATOR it, ITERATOR end )
79     {
80       // change SubMesh contents without deleting tmp elements
81       // for which the caller is responsible
82       _elements.assign( it, end );
83     }
84     SubMesh(const SMDS_Mesh* mesh, int index=0);
85     virtual ~SubMesh() { Clear(); }
86
87   protected:
88     std::vector<const SMDS_MeshElement *> _elements;
89     TN2NMap*                              _n2n;
90     UVPtStructVec                         _uvPtStructVec; // for SubMesh of EDGE
91     friend class SMESH_ProxyMesh;
92
93   protected: // methods of SMDS_ElementHolder; remove elements before mesh compacting or clearing
94     virtual SMDS_ElemIteratorPtr getElements() { Clear(); return GetElements(); }
95     virtual void tmpClear() {}
96     virtual void add( const SMDS_MeshElement* /*element*/ ) {}
97     virtual void compact() {}
98     virtual void clear() { Clear(); }
99   };
100   //--------------------------------------------------------------------------------
101   // Public interface
102
103   SMESH_ProxyMesh();
104   SMESH_ProxyMesh(std::vector<SMESH_ProxyMesh::Ptr>& components);
105   SMESH_ProxyMesh(const SMESH_Mesh& mesh);
106   virtual ~SMESH_ProxyMesh();
107
108   // Returns a sub-mesh of a shape; it can be a proxy sub-mesh
109   const SMESHDS_SubMesh* GetSubMesh(const TopoDS_Shape& shape) const;
110
111   // Return a sub-mesh by a shape ID; it can be a proxy sub-mesh
112   const SMESHDS_SubMesh* GetSubMesh(const int shapeID) const;
113
114   // Return a proxy sub-mesh of a shape; it can be NULL
115   const SubMesh*         GetProxySubMesh(const TopoDS_Shape& shape) const;
116
117   // Return a proxy node of a node; the input node is returned if no proxy exists
118   const SMDS_MeshNode*   GetProxyNode( const SMDS_MeshNode* node ) const;
119
120   // Return number of proxy sub-meshes
121   int                    NbProxySubMeshes() const;
122
123   // Return iterator on all faces of the mesh taking into account substitutions.
124   // To be used in case of mesh without shape
125   SMDS_ElemIteratorPtr   GetFaces() const;
126
127   // Return iterator on all faces on the face taking into account substitutions
128   SMDS_ElemIteratorPtr   GetFaces(const TopoDS_Shape& face) const;
129
130   // Return total nb of faces taking into account substitutions
131   smIdType               NbFaces() const;
132
133   bool                   IsTemporary(const SMDS_MeshElement* elem ) const;
134
135   // Return iterator on inverse elements of a node that may be a proxy one
136   SMDS_ElemIteratorPtr   GetInverseElementIterator(const SMDS_MeshNode* node,
137                                                    SMDSAbs_ElementType  type) const;
138
139   // Check if a FACE has prisms on its both sides
140   static bool HasPrismsOnTwoSides( SMESHDS_SubMesh* faceSM );
141
142   SMESH_Mesh*            GetMesh() const { return const_cast<SMESH_Mesh*>( _mesh ); }
143
144   SMESHDS_Mesh*          GetMeshDS() const;
145
146   //--------------------------------------------------------------------------------
147   // Interface for descendants
148  protected:
149
150   void     setMesh(const SMESH_Mesh& mesh);
151
152   int      shapeIndex(const TopoDS_Shape& shape) const;
153
154   virtual SubMesh* newSubmesh(int index=0) const;
155
156   // Return a proxy sub-mesh; zero index is for the case of mesh w/o shape
157   SubMesh* findProxySubMesh(int shapeIndex=0) const;
158
159   // Return a proxy sub-mesh; it is created if not yet exists
160   SubMesh* getProxySubMesh(int shapeIndex);
161
162   // Return a proxy sub-mesh; it is created if not yet exists
163   SubMesh* getProxySubMesh(const TopoDS_Shape& shape=TopoDS_Shape());
164
165   // move proxy sub-mesh from other proxy mesh to this, returns true if sub-mesh found
166   bool     takeProxySubMesh( const TopoDS_Shape& shape, SMESH_ProxyMesh* proxyMesh );
167
168   // move tmp elements residing the _mesh from other proxy mesh to this
169   void     takeTmpElemsInMesh( SMESH_ProxyMesh* proxyMesh );
170
171   // removes tmp element from the _mesh
172   void     removeTmpElement( const SMDS_MeshElement* elem );
173
174   // stores tmp element residing the _mesh
175   void     storeTmpElement( const SMDS_MeshElement* elem );
176
177   // store node-node correspondence
178   void     setNode2Node(const SMDS_MeshNode* srcNode,
179                         const SMDS_MeshNode* proxyNode,
180                         const SubMesh*       subMesh);
181
182   // types of elements needed to implement NbFaces() and GetFaces();
183   // if _allowedTypes is empty, only elements from _subMeshes are returned,
184   // else elements of _mesh filtered using allowedTypes are additionally returned
185   std::vector< SMDSAbs_EntityType> _allowedTypes;
186
187  private:
188
189   const SMESH_Mesh*       _mesh;
190
191   // proxy sub-meshes; index in vector == shapeIndex(shape)
192   std::vector< SubMesh* > _subMeshes;
193
194   // tmp elements residing the _mesh, to be deleted at destruction
195   std::set< const SMDS_MeshElement* > _elemsInMesh;
196
197   // inverse elements of proxy nodes
198   typedef NCollection_DataMap< const SMDS_MeshNode*,
199                                std::vector< const SMDS_MeshElement* >,
200                                SMESH_Hasher                         > TNodeElemVecMap;
201   TNodeElemVecMap  _inverseElements;
202
203   // Complex submesh used to iterate over elements in other sub-meshes
204   mutable SubMesh* _subContainer;
205 };
206
207 #endif