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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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>
49 #include <NCollection_DataMap.hxx>
52 * Using of native haah_map isn't portable and don't work on WIN32 platform.
53 * So this functionality implement on new NCollection_DataMap technology
55 #include "SMESHDS_DataMapOfShape.hxx"
57 class SMESHDS_GroupBase;
59 class SMESHDS_EXPORT SMESHDS_Mesh:public SMDS_Mesh{
61 SMESHDS_Mesh(int theMeshID, bool theIsEmbeddedMode);
62 bool IsEmbeddedMode();
64 void ShapeToMesh(const TopoDS_Shape & S);
65 TopoDS_Shape ShapeToMesh() const;
66 bool AddHypothesis(const TopoDS_Shape & SS, const SMESHDS_Hypothesis * H);
67 bool RemoveHypothesis(const TopoDS_Shape & S, const SMESHDS_Hypothesis * H);
69 virtual SMDS_MeshNode* AddNodeWithID(double x, double y, double z, int ID);
70 virtual SMDS_MeshNode * AddNode(double x, double y, double z);
72 virtual SMDS_MeshEdge* AddEdgeWithID(int n1, int n2, int ID);
73 virtual SMDS_MeshEdge* AddEdgeWithID(const SMDS_MeshNode * n1,
74 const SMDS_MeshNode * n2,
76 virtual SMDS_MeshEdge* AddEdge(const SMDS_MeshNode * n1,
77 const SMDS_MeshNode * n2);
79 // 2d order edge with 3 nodes: n12 - node between n1 and n2
80 virtual SMDS_MeshEdge* AddEdgeWithID(int n1, int n2, int n12, int ID);
81 virtual SMDS_MeshEdge* AddEdgeWithID(const SMDS_MeshNode * n1,
82 const SMDS_MeshNode * n2,
83 const SMDS_MeshNode * n12,
85 virtual SMDS_MeshEdge* AddEdge(const SMDS_MeshNode * n1,
86 const SMDS_MeshNode * n2,
87 const SMDS_MeshNode * n12);
89 virtual SMDS_MeshFace* AddFaceWithID(int n1, int n2, int n3, int ID);
90 virtual SMDS_MeshFace* AddFaceWithID(const SMDS_MeshNode * n1,
91 const SMDS_MeshNode * n2,
92 const SMDS_MeshNode * n3,
94 virtual SMDS_MeshFace* AddFace(const SMDS_MeshNode * n1,
95 const SMDS_MeshNode * n2,
96 const SMDS_MeshNode * n3);
98 virtual SMDS_MeshFace* AddFaceWithID(int n1, int n2, int n3, int n4, int ID);
99 virtual SMDS_MeshFace* AddFaceWithID(const SMDS_MeshNode * n1,
100 const SMDS_MeshNode * n2,
101 const SMDS_MeshNode * n3,
102 const SMDS_MeshNode * n4,
104 virtual SMDS_MeshFace* AddFace(const SMDS_MeshNode * n1,
105 const SMDS_MeshNode * n2,
106 const SMDS_MeshNode * n3,
107 const SMDS_MeshNode * n4);
109 // 2d order triangle of 6 nodes
110 virtual SMDS_MeshFace* AddFaceWithID(int n1, int n2, int n3,
111 int n12,int n23,int n31, int ID);
112 virtual SMDS_MeshFace* AddFaceWithID(const SMDS_MeshNode * n1,
113 const SMDS_MeshNode * n2,
114 const SMDS_MeshNode * n3,
115 const SMDS_MeshNode * n12,
116 const SMDS_MeshNode * n23,
117 const SMDS_MeshNode * n31,
119 virtual SMDS_MeshFace* AddFace(const SMDS_MeshNode * n1,
120 const SMDS_MeshNode * n2,
121 const SMDS_MeshNode * n3,
122 const SMDS_MeshNode * n12,
123 const SMDS_MeshNode * n23,
124 const SMDS_MeshNode * n31);
126 // 2d order quadrangle
127 virtual SMDS_MeshFace* AddFaceWithID(int n1, int n2, int n3, int n4,
128 int n12,int n23,int n34,int n41, int ID);
129 virtual SMDS_MeshFace* AddFaceWithID(const SMDS_MeshNode * n1,
130 const SMDS_MeshNode * n2,
131 const SMDS_MeshNode * n3,
132 const SMDS_MeshNode * n4,
133 const SMDS_MeshNode * n12,
134 const SMDS_MeshNode * n23,
135 const SMDS_MeshNode * n34,
136 const SMDS_MeshNode * n41,
138 virtual SMDS_MeshFace* AddFace(const SMDS_MeshNode * n1,
139 const SMDS_MeshNode * n2,
140 const SMDS_MeshNode * n3,
141 const SMDS_MeshNode * n4,
142 const SMDS_MeshNode * n12,
143 const SMDS_MeshNode * n23,
144 const SMDS_MeshNode * n34,
145 const SMDS_MeshNode * n41);
147 virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int ID);
148 virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
149 const SMDS_MeshNode * n2,
150 const SMDS_MeshNode * n3,
151 const SMDS_MeshNode * n4,
153 virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
154 const SMDS_MeshNode * n2,
155 const SMDS_MeshNode * n3,
156 const SMDS_MeshNode * n4);
158 virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int ID);
159 virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
160 const SMDS_MeshNode * n2,
161 const SMDS_MeshNode * n3,
162 const SMDS_MeshNode * n4,
163 const SMDS_MeshNode * n5,
165 virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
166 const SMDS_MeshNode * n2,
167 const SMDS_MeshNode * n3,
168 const SMDS_MeshNode * n4,
169 const SMDS_MeshNode * n5);
171 virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int ID);
172 virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
173 const SMDS_MeshNode * n2,
174 const SMDS_MeshNode * n3,
175 const SMDS_MeshNode * n4,
176 const SMDS_MeshNode * n5,
177 const SMDS_MeshNode * n6,
179 virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
180 const SMDS_MeshNode * n2,
181 const SMDS_MeshNode * n3,
182 const SMDS_MeshNode * n4,
183 const SMDS_MeshNode * n5,
184 const SMDS_MeshNode * n6);
186 virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int ID);
187 virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
188 const SMDS_MeshNode * n2,
189 const SMDS_MeshNode * n3,
190 const SMDS_MeshNode * n4,
191 const SMDS_MeshNode * n5,
192 const SMDS_MeshNode * n6,
193 const SMDS_MeshNode * n7,
194 const SMDS_MeshNode * n8,
196 virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
197 const SMDS_MeshNode * n2,
198 const SMDS_MeshNode * n3,
199 const SMDS_MeshNode * n4,
200 const SMDS_MeshNode * n5,
201 const SMDS_MeshNode * n6,
202 const SMDS_MeshNode * n7,
203 const SMDS_MeshNode * n8);
205 // 2d order tetrahedron of 10 nodes
206 virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4,
207 int n12,int n23,int n31,
208 int n14,int n24,int n34, int ID);
209 virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
210 const SMDS_MeshNode * n2,
211 const SMDS_MeshNode * n3,
212 const SMDS_MeshNode * n4,
213 const SMDS_MeshNode * n12,
214 const SMDS_MeshNode * n23,
215 const SMDS_MeshNode * n31,
216 const SMDS_MeshNode * n14,
217 const SMDS_MeshNode * n24,
218 const SMDS_MeshNode * n34,
220 virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
221 const SMDS_MeshNode * n2,
222 const SMDS_MeshNode * n3,
223 const SMDS_MeshNode * n4,
224 const SMDS_MeshNode * n12,
225 const SMDS_MeshNode * n23,
226 const SMDS_MeshNode * n31,
227 const SMDS_MeshNode * n14,
228 const SMDS_MeshNode * n24,
229 const SMDS_MeshNode * n34);
231 // 2d order pyramid of 13 nodes
232 virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int n5,
233 int n12,int n23,int n34,int n41,
234 int n15,int n25,int n35,int n45,
236 virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
237 const SMDS_MeshNode * n2,
238 const SMDS_MeshNode * n3,
239 const SMDS_MeshNode * n4,
240 const SMDS_MeshNode * n5,
241 const SMDS_MeshNode * n12,
242 const SMDS_MeshNode * n23,
243 const SMDS_MeshNode * n34,
244 const SMDS_MeshNode * n41,
245 const SMDS_MeshNode * n15,
246 const SMDS_MeshNode * n25,
247 const SMDS_MeshNode * n35,
248 const SMDS_MeshNode * n45,
250 virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
251 const SMDS_MeshNode * n2,
252 const SMDS_MeshNode * n3,
253 const SMDS_MeshNode * n4,
254 const SMDS_MeshNode * n5,
255 const SMDS_MeshNode * n12,
256 const SMDS_MeshNode * n23,
257 const SMDS_MeshNode * n34,
258 const SMDS_MeshNode * n41,
259 const SMDS_MeshNode * n15,
260 const SMDS_MeshNode * n25,
261 const SMDS_MeshNode * n35,
262 const SMDS_MeshNode * n45);
264 // 2d order Pentahedron with 15 nodes
265 virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3,
266 int n4, int n5, int n6,
267 int n12,int n23,int n31,
268 int n45,int n56,int n64,
269 int n14,int n25,int n36,
271 virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
272 const SMDS_MeshNode * n2,
273 const SMDS_MeshNode * n3,
274 const SMDS_MeshNode * n4,
275 const SMDS_MeshNode * n5,
276 const SMDS_MeshNode * n6,
277 const SMDS_MeshNode * n12,
278 const SMDS_MeshNode * n23,
279 const SMDS_MeshNode * n31,
280 const SMDS_MeshNode * n45,
281 const SMDS_MeshNode * n56,
282 const SMDS_MeshNode * n64,
283 const SMDS_MeshNode * n14,
284 const SMDS_MeshNode * n25,
285 const SMDS_MeshNode * n36,
287 virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
288 const SMDS_MeshNode * n2,
289 const SMDS_MeshNode * n3,
290 const SMDS_MeshNode * n4,
291 const SMDS_MeshNode * n5,
292 const SMDS_MeshNode * n6,
293 const SMDS_MeshNode * n12,
294 const SMDS_MeshNode * n23,
295 const SMDS_MeshNode * n31,
296 const SMDS_MeshNode * n45,
297 const SMDS_MeshNode * n56,
298 const SMDS_MeshNode * n64,
299 const SMDS_MeshNode * n14,
300 const SMDS_MeshNode * n25,
301 const SMDS_MeshNode * n36);
303 // 2d order Hexahedrons with 20 nodes
304 virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4,
305 int n5, int n6, int n7, int n8,
306 int n12,int n23,int n34,int n41,
307 int n56,int n67,int n78,int n85,
308 int n15,int n26,int n37,int n48,
310 virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
311 const SMDS_MeshNode * n2,
312 const SMDS_MeshNode * n3,
313 const SMDS_MeshNode * n4,
314 const SMDS_MeshNode * n5,
315 const SMDS_MeshNode * n6,
316 const SMDS_MeshNode * n7,
317 const SMDS_MeshNode * n8,
318 const SMDS_MeshNode * n12,
319 const SMDS_MeshNode * n23,
320 const SMDS_MeshNode * n34,
321 const SMDS_MeshNode * n41,
322 const SMDS_MeshNode * n56,
323 const SMDS_MeshNode * n67,
324 const SMDS_MeshNode * n78,
325 const SMDS_MeshNode * n85,
326 const SMDS_MeshNode * n15,
327 const SMDS_MeshNode * n26,
328 const SMDS_MeshNode * n37,
329 const SMDS_MeshNode * n48,
331 virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
332 const SMDS_MeshNode * n2,
333 const SMDS_MeshNode * n3,
334 const SMDS_MeshNode * n4,
335 const SMDS_MeshNode * n5,
336 const SMDS_MeshNode * n6,
337 const SMDS_MeshNode * n7,
338 const SMDS_MeshNode * n8,
339 const SMDS_MeshNode * n12,
340 const SMDS_MeshNode * n23,
341 const SMDS_MeshNode * n34,
342 const SMDS_MeshNode * n41,
343 const SMDS_MeshNode * n56,
344 const SMDS_MeshNode * n67,
345 const SMDS_MeshNode * n78,
346 const SMDS_MeshNode * n85,
347 const SMDS_MeshNode * n15,
348 const SMDS_MeshNode * n26,
349 const SMDS_MeshNode * n37,
350 const SMDS_MeshNode * n48);
352 virtual SMDS_MeshFace* AddPolygonalFaceWithID (std::vector<int> nodes_ids,
355 virtual SMDS_MeshFace* AddPolygonalFaceWithID (std::vector<const SMDS_MeshNode*> nodes,
358 virtual SMDS_MeshFace* AddPolygonalFace (std::vector<const SMDS_MeshNode*> nodes);
360 virtual SMDS_MeshVolume* AddPolyhedralVolumeWithID
361 (std::vector<int> nodes_ids,
362 std::vector<int> quantities,
365 virtual SMDS_MeshVolume* AddPolyhedralVolumeWithID
366 (std::vector<const SMDS_MeshNode*> nodes,
367 std::vector<int> quantities,
370 virtual SMDS_MeshVolume* AddPolyhedralVolume
371 (std::vector<const SMDS_MeshNode*> nodes,
372 std::vector<int> quantities);
374 void MoveNode(const SMDS_MeshNode *, double x, double y, double z);
375 virtual void RemoveNode(const SMDS_MeshNode *);
376 void RemoveElement(const SMDS_MeshElement *);
378 /*! Remove only the given element/node and only if it is free.
379 * Methods do not work for meshes with descendants.
380 * Implemented for fast cleaning of meshes.
382 void RemoveFreeNode(const SMDS_MeshNode *, SMESHDS_SubMesh *);
383 void RemoveFreeElement(const SMDS_MeshElement *, SMESHDS_SubMesh *);
385 bool ChangeElementNodes(const SMDS_MeshElement * elem,
386 const SMDS_MeshNode * nodes[],
388 bool ChangePolygonNodes(const SMDS_MeshElement * elem,
389 std::vector<const SMDS_MeshNode*> nodes);
390 bool ChangePolyhedronNodes(const SMDS_MeshElement * elem,
391 std::vector<const SMDS_MeshNode*> nodes,
392 std::vector<int> quantities);
393 void Renumber (const bool isNodes, const int startID=1, const int deltaID=1);
395 void SetNodeInVolume(SMDS_MeshNode * aNode, const TopoDS_Shell & S);
396 void SetNodeInVolume(SMDS_MeshNode * aNode, const TopoDS_Solid & S);
397 void SetNodeOnFace(SMDS_MeshNode * aNode, const TopoDS_Face & S, double u=0., double v=0.);
398 void SetNodeOnEdge(SMDS_MeshNode * aNode, const TopoDS_Edge & S, double u=0.);
399 void SetNodeOnVertex(SMDS_MeshNode * aNode, const TopoDS_Vertex & S);
400 void UnSetNodeOnShape(const SMDS_MeshNode * aNode);
401 void SetMeshElementOnShape(const SMDS_MeshElement * anElt,
402 const TopoDS_Shape & S);
403 void UnSetMeshElementOnShape(const SMDS_MeshElement * anElt,
404 const TopoDS_Shape & S);
405 bool HasMeshElements(const TopoDS_Shape & S);
406 SMESHDS_SubMesh * MeshElements(const TopoDS_Shape & S) const;
407 SMESHDS_SubMesh * MeshElements(const int Index);
408 std::list<int> SubMeshIndices();
409 const std::map<int,SMESHDS_SubMesh*>& SubMeshes() const
410 { return myShapeIndexToSubMesh; }
412 bool HasHypothesis(const TopoDS_Shape & S);
413 const std::list<const SMESHDS_Hypothesis*>& GetHypothesis(const TopoDS_Shape & S) const;
414 SMESHDS_Script * GetScript();
416 int ShapeToIndex(const TopoDS_Shape & aShape) const;
417 const TopoDS_Shape& IndexToShape(int ShapeIndex) const;
418 int MaxShapeIndex() const { return myIndexToShape.Extent(); }
420 SMESHDS_SubMesh * NewSubMesh(int Index);
421 int AddCompoundSubmesh(const TopoDS_Shape& S, TopAbs_ShapeEnum type = TopAbs_SHAPE);
422 void SetNodeInVolume(const SMDS_MeshNode * aNode, int Index);
423 void SetNodeOnFace(SMDS_MeshNode * aNode, int Index , double u=0., double v=0.);
424 void SetNodeOnEdge(SMDS_MeshNode * aNode, int Index , double u=0.);
425 void SetNodeOnVertex(SMDS_MeshNode * aNode, int Index);
426 void SetMeshElementOnShape(const SMDS_MeshElement * anElt, int Index);
428 void AddGroup (SMESHDS_GroupBase* theGroup) { myGroups.insert(theGroup); }
429 void RemoveGroup (SMESHDS_GroupBase* theGroup) { myGroups.erase(theGroup); }
430 int GetNbGroups() const { return myGroups.size(); }
431 const std::set<SMESHDS_GroupBase*>& GetGroups() const { return myGroups; }
433 bool IsGroupOfSubShapes (const TopoDS_Shape& aSubShape) const;
438 void addNodeToSubmesh( const SMDS_MeshNode* aNode, int Index )
440 //Update or build submesh
441 map<int,SMESHDS_SubMesh*>::iterator it = myShapeIndexToSubMesh.find( Index );
442 if ( it == myShapeIndexToSubMesh.end() )
443 it = myShapeIndexToSubMesh.insert( make_pair(Index, new SMESHDS_SubMesh() )).first;
444 it->second->AddNode( aNode ); // add aNode to submesh
447 /*int HashCode( const TopoDS_Shape& S, const Standard_Integer theUpper ) const
449 return S.HashCode(2147483647);
452 typedef std::list<const SMESHDS_Hypothesis*> THypList;
454 typedef NCollection_DataMap< TopoDS_Shape, THypList > ShapeToHypothesis;
456 ShapeToHypothesis myShapeToHypothesis;
459 TopoDS_Shape myShape;
461 typedef std::map<int,SMESHDS_SubMesh*> TShapeIndexToSubMesh;
462 TShapeIndexToSubMesh myShapeIndexToSubMesh;
464 TopTools_IndexedMapOfShape myIndexToShape;
466 typedef std::set<SMESHDS_GroupBase*> TGroups;
469 SMESHDS_Script* myScript;
470 bool myIsEmbeddedMode;
472 // optimize addition of nodes/elements to submeshes by, SetNodeInVolume() etc:
473 // avoid search of submeshes in maps
474 bool add( const SMDS_MeshElement* elem, SMESHDS_SubMesh* subMesh );
475 SMESHDS_SubMesh* getSubmesh( const TopoDS_Shape & shape);
476 SMESHDS_SubMesh* getSubmesh( const int Index );
478 TopoDS_Shape myCurSubShape;
479 SMESHDS_SubMesh* myCurSubMesh;