1 // SMESH SMESHDS : management of mesh data and SMESH document
3 // Copyright (C) 2003 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.
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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHDS_Mesh.hxx
27 #ifndef _SMESHDS_Mesh_HeaderFile
28 #define _SMESHDS_Mesh_HeaderFile
30 #include "SMESH_SMESHDS.hxx"
32 #include "SMDS_Mesh.hxx"
33 #include "SMDS_MeshNode.hxx"
34 #include "SMDS_MeshEdge.hxx"
35 #include "SMDS_MeshFace.hxx"
36 #include "SMDS_MeshVolume.hxx"
37 #include "SMESHDS_Hypothesis.hxx"
38 #include "SMESHDS_SubMesh.hxx"
39 #include "SMESHDS_Script.hxx"
41 #include <TopTools_IndexedMapOfShape.hxx>
42 #include <TopoDS_Shape.hxx>
43 #include <TopoDS_Solid.hxx>
44 #include <TopoDS_Shell.hxx>
45 #include <TopoDS_Face.hxx>
46 #include <TopoDS_Vertex.hxx>
47 #include <TopoDS_Edge.hxx>
53 //Not portable see http://gcc.gnu.org/onlinedocs/libstdc++/faq/index.html#5_4 to know more.
57 namespace gstd { using ::hash_map; }; // inherit globals
59 #include <ext/hash_map>
60 #if __GNUC_MINOR__ == 0
61 namespace gstd = std; // GCC 3.0
63 namespace gstd = ::__gnu_cxx; // GCC 3.1 and later
65 #else // GCC 4.0 and later
66 #include <ext/hash_map>
67 namespace gstd = ::__gnu_cxx;
69 #else // ... there are other compilers, right?
73 class SMESHDS_GroupBase;
75 class SMESHDS_EXPORT SMESHDS_Mesh:public SMDS_Mesh{
77 SMESHDS_Mesh(int MeshID);
78 void ShapeToMesh(const TopoDS_Shape & S);
79 bool AddHypothesis(const TopoDS_Shape & SS, const SMESHDS_Hypothesis * H);
80 bool RemoveHypothesis(const TopoDS_Shape & S, const SMESHDS_Hypothesis * H);
82 virtual SMDS_MeshNode* AddNodeWithID(double x, double y, double z, int ID);
83 virtual SMDS_MeshNode * AddNode(double x, double y, double z);
85 virtual SMDS_MeshEdge* AddEdgeWithID(int n1, int n2, int ID);
86 virtual SMDS_MeshEdge* AddEdgeWithID(const SMDS_MeshNode * n1,
87 const SMDS_MeshNode * n2,
89 virtual SMDS_MeshEdge* AddEdge(const SMDS_MeshNode * n1,
90 const SMDS_MeshNode * n2);
92 virtual SMDS_MeshFace* AddFaceWithID(int n1, int n2, int n3, int ID);
93 virtual SMDS_MeshFace* AddFaceWithID(const SMDS_MeshNode * n1,
94 const SMDS_MeshNode * n2,
95 const SMDS_MeshNode * n3,
97 virtual SMDS_MeshFace* AddFace(const SMDS_MeshNode * n1,
98 const SMDS_MeshNode * n2,
99 const SMDS_MeshNode * n3);
101 virtual SMDS_MeshFace* AddFaceWithID(int n1, int n2, int n3, int n4, int ID);
102 virtual SMDS_MeshFace* AddFaceWithID(const SMDS_MeshNode * n1,
103 const SMDS_MeshNode * n2,
104 const SMDS_MeshNode * n3,
105 const SMDS_MeshNode * n4,
107 virtual SMDS_MeshFace* AddFace(const SMDS_MeshNode * n1,
108 const SMDS_MeshNode * n2,
109 const SMDS_MeshNode * n3,
110 const SMDS_MeshNode * n4);
112 virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int ID);
113 virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
114 const SMDS_MeshNode * n2,
115 const SMDS_MeshNode * n3,
116 const SMDS_MeshNode * n4,
118 virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
119 const SMDS_MeshNode * n2,
120 const SMDS_MeshNode * n3,
121 const SMDS_MeshNode * n4);
123 virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int ID);
124 virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
125 const SMDS_MeshNode * n2,
126 const SMDS_MeshNode * n3,
127 const SMDS_MeshNode * n4,
128 const SMDS_MeshNode * n5,
130 virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
131 const SMDS_MeshNode * n2,
132 const SMDS_MeshNode * n3,
133 const SMDS_MeshNode * n4,
134 const SMDS_MeshNode * n5);
136 virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int ID);
137 virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
138 const SMDS_MeshNode * n2,
139 const SMDS_MeshNode * n3,
140 const SMDS_MeshNode * n4,
141 const SMDS_MeshNode * n5,
142 const SMDS_MeshNode * n6,
144 virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
145 const SMDS_MeshNode * n2,
146 const SMDS_MeshNode * n3,
147 const SMDS_MeshNode * n4,
148 const SMDS_MeshNode * n5,
149 const SMDS_MeshNode * n6);
151 virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int ID);
152 virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
153 const SMDS_MeshNode * n2,
154 const SMDS_MeshNode * n3,
155 const SMDS_MeshNode * n4,
156 const SMDS_MeshNode * n5,
157 const SMDS_MeshNode * n6,
158 const SMDS_MeshNode * n7,
159 const SMDS_MeshNode * n8,
161 virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
162 const SMDS_MeshNode * n2,
163 const SMDS_MeshNode * n3,
164 const SMDS_MeshNode * n4,
165 const SMDS_MeshNode * n5,
166 const SMDS_MeshNode * n6,
167 const SMDS_MeshNode * n7,
168 const SMDS_MeshNode * n8);
170 virtual SMDS_MeshFace* AddPolygonalFaceWithID (std::vector<int> nodes_ids,
173 virtual SMDS_MeshFace* AddPolygonalFaceWithID (std::vector<const SMDS_MeshNode*> nodes,
176 virtual SMDS_MeshFace* AddPolygonalFace (std::vector<const SMDS_MeshNode*> nodes);
178 virtual SMDS_MeshVolume* AddPolyhedralVolumeWithID
179 (std::vector<int> nodes_ids,
180 std::vector<int> quantities,
183 virtual SMDS_MeshVolume* AddPolyhedralVolumeWithID
184 (std::vector<const SMDS_MeshNode*> nodes,
185 std::vector<int> quantities,
188 virtual SMDS_MeshVolume* AddPolyhedralVolume
189 (std::vector<const SMDS_MeshNode*> nodes,
190 std::vector<int> quantities);
192 void MoveNode(const SMDS_MeshNode *, double x, double y, double z);
193 virtual void RemoveNode(const SMDS_MeshNode *);
194 void RemoveElement(const SMDS_MeshElement *);
195 bool ChangeElementNodes(const SMDS_MeshElement * elem,
196 const SMDS_MeshNode * nodes[],
198 bool ChangePolygonNodes(const SMDS_MeshElement * elem,
199 std::vector<const SMDS_MeshNode*> nodes);
200 bool ChangePolyhedronNodes(const SMDS_MeshElement * elem,
201 std::vector<const SMDS_MeshNode*> nodes,
202 std::vector<int> quantities);
203 void Renumber (const bool isNodes, const int startID=1, const int deltaID=1);
205 void SetNodeInVolume(SMDS_MeshNode * aNode, const TopoDS_Shell & S);
206 void SetNodeInVolume(SMDS_MeshNode * aNode, const TopoDS_Solid & S);
207 void SetNodeOnFace(SMDS_MeshNode * aNode, const TopoDS_Face & S, double u=0., double v=0.);
208 void SetNodeOnEdge(SMDS_MeshNode * aNode, const TopoDS_Edge & S, double u=0.);
209 void SetNodeOnVertex(SMDS_MeshNode * aNode, const TopoDS_Vertex & S);
210 void UnSetNodeOnShape(const SMDS_MeshNode * aNode);
211 void SetMeshElementOnShape(const SMDS_MeshElement * anElt,
212 const TopoDS_Shape & S);
213 void UnSetMeshElementOnShape(const SMDS_MeshElement * anElt,
214 const TopoDS_Shape & S);
215 TopoDS_Shape ShapeToMesh() const;
216 bool HasMeshElements(const TopoDS_Shape & S);
217 SMESHDS_SubMesh * MeshElements(const TopoDS_Shape & S) const;
218 SMESHDS_SubMesh * MeshElements(const int Index);
219 std::list<int> SubMeshIndices();
220 const std::map<int,SMESHDS_SubMesh*>& SubMeshes()
221 { return myShapeIndexToSubMesh; }
223 bool HasHypothesis(const TopoDS_Shape & S);
224 const std::list<const SMESHDS_Hypothesis*>& GetHypothesis(const TopoDS_Shape & S) const;
225 SMESHDS_Script * GetScript();
227 int ShapeToIndex(const TopoDS_Shape & aShape) const;
228 TopoDS_Shape IndexToShape(int ShapeIndex);
230 SMESHDS_SubMesh * NewSubMesh(int Index);
231 int AddCompoundSubmesh(const TopoDS_Shape& S, TopAbs_ShapeEnum type = TopAbs_SHAPE);
232 void SetNodeInVolume(const SMDS_MeshNode * aNode, int Index);
233 void SetNodeOnFace(SMDS_MeshNode * aNode, int Index , double u=0., double v=0.);
234 void SetNodeOnEdge(SMDS_MeshNode * aNode, int Index , double u=0.);
235 void SetNodeOnVertex(SMDS_MeshNode * aNode, int Index);
236 void SetMeshElementOnShape(const SMDS_MeshElement * anElt, int Index);
238 void AddGroup (SMESHDS_GroupBase* theGroup) { myGroups.insert(theGroup); }
239 void RemoveGroup (SMESHDS_GroupBase* theGroup) { myGroups.erase(theGroup); }
240 int GetNbGroups() const { return myGroups.size(); }
241 const std::set<SMESHDS_GroupBase*>& GetGroups() const { return myGroups; }
243 bool IsGroupOfSubShapes (const TopoDS_Shape& aSubShape) const;
249 struct HashTopoDS_Shape{
250 size_t operator()(const TopoDS_Shape& S) const {
251 return S.HashCode(2147483647);
255 typedef gstd::hash_compare< TopoDS_Shape, less<TopoDS_Shape> > HashTopoDS;
257 class HashTopoDS_Shape : public HashTopoDS {
260 size_t operator()(const TopoDS_Shape& S) const {
261 return S.HashCode(2147483647);
264 bool operator()(const TopoDS_Shape& S1,const TopoDS_Shape& S2) const {
273 void addNodeToSubmesh( const SMDS_MeshNode* aNode, int Index )
275 //Update or build submesh
276 map<int,SMESHDS_SubMesh*>::iterator it = myShapeIndexToSubMesh.find( Index );
277 if ( it == myShapeIndexToSubMesh.end() )
278 it = myShapeIndexToSubMesh.insert( make_pair(Index, new SMESHDS_SubMesh() )).first;
279 it->second->AddNode( aNode ); // add aNode to submesh
282 typedef std::list<const SMESHDS_Hypothesis*> THypList;
285 typedef gstd::hash_map<TopoDS_Shape,THypList,HashTopoDS_Shape> ShapeToHypothesis;
287 typedef gstd::hash_map<TopoDS_Shape,THypList,HashTopoDS_Shape> ShapeToHypothesis;
290 ShapeToHypothesis myShapeToHypothesis;
293 TopoDS_Shape myShape;
295 typedef std::map<int,SMESHDS_SubMesh*> TShapeIndexToSubMesh;
296 TShapeIndexToSubMesh myShapeIndexToSubMesh;
298 TopTools_IndexedMapOfShape myIndexToShape;
300 typedef std::set<SMESHDS_GroupBase*> TGroups;
303 SMESHDS_Script* myScript;