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 "SMDS_Mesh.hxx"
31 #include "SMDS_MeshNode.hxx"
32 #include "SMDS_MeshEdge.hxx"
33 #include "SMDS_MeshFace.hxx"
34 #include "SMDS_MeshVolume.hxx"
35 #include "SMESHDS_Hypothesis.hxx"
36 #include "SMESHDS_SubMesh.hxx"
37 #include "SMESHDS_Script.hxx"
39 #include <TopTools_IndexedMapOfShape.hxx>
40 #include <TopoDS_Shape.hxx>
41 #include <TopoDS_Solid.hxx>
42 #include <TopoDS_Shell.hxx>
43 #include <TopoDS_Face.hxx>
44 #include <TopoDS_Vertex.hxx>
45 #include <TopoDS_Edge.hxx>
51 //Not portable see http://gcc.gnu.org/onlinedocs/libstdc++/faq/index.html#5_4 to know more.
55 namespace gstd { using ::hash_map; }; // inherit globals
57 #include <ext/hash_map>
58 #if __GNUC_MINOR__ == 0
59 namespace gstd = std; // GCC 3.0
61 namespace gstd = ::__gnu_cxx; // GCC 3.1 and later
63 #else // GCC 4.0 and later
64 #include <ext/hash_map>
65 namespace gstd = ::__gnu_cxx;
67 #else // ... there are other compilers, right?
71 #if defined WNT && defined WIN32 && defined SMESHDS_EXPORTS
72 #define SMESHDS_WNT_EXPORT __declspec( dllexport )
74 #define SMESHDS_WNT_EXPORT
77 class SMESHDS_GroupBase;
79 class SMESHDS_WNT_EXPORT SMESHDS_Mesh:public SMDS_Mesh{
81 SMESHDS_Mesh(int theMeshID, bool theIsEmbeddedMode);
82 bool IsEmbeddedMode();
84 void ShapeToMesh(const TopoDS_Shape & S);
85 TopoDS_Shape ShapeToMesh() const;
86 bool AddHypothesis(const TopoDS_Shape & SS, const SMESHDS_Hypothesis * H);
87 bool RemoveHypothesis(const TopoDS_Shape & S, const SMESHDS_Hypothesis * H);
89 virtual SMDS_MeshNode* AddNodeWithID(double x, double y, double z, int ID);
90 virtual SMDS_MeshNode * AddNode(double x, double y, double z);
92 virtual SMDS_MeshEdge* AddEdgeWithID(int n1, int n2, int ID);
93 virtual SMDS_MeshEdge* AddEdgeWithID(const SMDS_MeshNode * n1,
94 const SMDS_MeshNode * n2,
96 virtual SMDS_MeshEdge* AddEdge(const SMDS_MeshNode * n1,
97 const SMDS_MeshNode * n2);
99 // 2d order edge with 3 nodes: n12 - node between n1 and n2
100 virtual SMDS_MeshEdge* AddEdgeWithID(int n1, int n2, int n12, int ID);
101 virtual SMDS_MeshEdge* AddEdgeWithID(const SMDS_MeshNode * n1,
102 const SMDS_MeshNode * n2,
103 const SMDS_MeshNode * n12,
105 virtual SMDS_MeshEdge* AddEdge(const SMDS_MeshNode * n1,
106 const SMDS_MeshNode * n2,
107 const SMDS_MeshNode * n12);
109 virtual SMDS_MeshFace* AddFaceWithID(int n1, int n2, int n3, int ID);
110 virtual SMDS_MeshFace* AddFaceWithID(const SMDS_MeshNode * n1,
111 const SMDS_MeshNode * n2,
112 const SMDS_MeshNode * n3,
114 virtual SMDS_MeshFace* AddFace(const SMDS_MeshNode * n1,
115 const SMDS_MeshNode * n2,
116 const SMDS_MeshNode * n3);
118 virtual SMDS_MeshFace* AddFaceWithID(int n1, int n2, int n3, int n4, int ID);
119 virtual SMDS_MeshFace* AddFaceWithID(const SMDS_MeshNode * n1,
120 const SMDS_MeshNode * n2,
121 const SMDS_MeshNode * n3,
122 const SMDS_MeshNode * n4,
124 virtual SMDS_MeshFace* AddFace(const SMDS_MeshNode * n1,
125 const SMDS_MeshNode * n2,
126 const SMDS_MeshNode * n3,
127 const SMDS_MeshNode * n4);
129 // 2d order triangle of 6 nodes
130 virtual SMDS_MeshFace* AddFaceWithID(int n1, int n2, int n3,
131 int n12,int n23,int n31, int ID);
132 virtual SMDS_MeshFace* AddFaceWithID(const SMDS_MeshNode * n1,
133 const SMDS_MeshNode * n2,
134 const SMDS_MeshNode * n3,
135 const SMDS_MeshNode * n12,
136 const SMDS_MeshNode * n23,
137 const SMDS_MeshNode * n31,
139 virtual SMDS_MeshFace* AddFace(const SMDS_MeshNode * n1,
140 const SMDS_MeshNode * n2,
141 const SMDS_MeshNode * n3,
142 const SMDS_MeshNode * n12,
143 const SMDS_MeshNode * n23,
144 const SMDS_MeshNode * n31);
146 // 2d order quadrangle
147 virtual SMDS_MeshFace* AddFaceWithID(int n1, int n2, int n3, int n4,
148 int n12,int n23,int n34,int n41, int ID);
149 virtual SMDS_MeshFace* AddFaceWithID(const SMDS_MeshNode * n1,
150 const SMDS_MeshNode * n2,
151 const SMDS_MeshNode * n3,
152 const SMDS_MeshNode * n4,
153 const SMDS_MeshNode * n12,
154 const SMDS_MeshNode * n23,
155 const SMDS_MeshNode * n34,
156 const SMDS_MeshNode * n41,
158 virtual SMDS_MeshFace* AddFace(const SMDS_MeshNode * n1,
159 const SMDS_MeshNode * n2,
160 const SMDS_MeshNode * n3,
161 const SMDS_MeshNode * n4,
162 const SMDS_MeshNode * n12,
163 const SMDS_MeshNode * n23,
164 const SMDS_MeshNode * n34,
165 const SMDS_MeshNode * n41);
167 virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int ID);
168 virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
169 const SMDS_MeshNode * n2,
170 const SMDS_MeshNode * n3,
171 const SMDS_MeshNode * n4,
173 virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
174 const SMDS_MeshNode * n2,
175 const SMDS_MeshNode * n3,
176 const SMDS_MeshNode * n4);
178 virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int ID);
179 virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
180 const SMDS_MeshNode * n2,
181 const SMDS_MeshNode * n3,
182 const SMDS_MeshNode * n4,
183 const SMDS_MeshNode * n5,
185 virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
186 const SMDS_MeshNode * n2,
187 const SMDS_MeshNode * n3,
188 const SMDS_MeshNode * n4,
189 const SMDS_MeshNode * n5);
191 virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int ID);
192 virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
193 const SMDS_MeshNode * n2,
194 const SMDS_MeshNode * n3,
195 const SMDS_MeshNode * n4,
196 const SMDS_MeshNode * n5,
197 const SMDS_MeshNode * n6,
199 virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
200 const SMDS_MeshNode * n2,
201 const SMDS_MeshNode * n3,
202 const SMDS_MeshNode * n4,
203 const SMDS_MeshNode * n5,
204 const SMDS_MeshNode * n6);
206 virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int ID);
207 virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
208 const SMDS_MeshNode * n2,
209 const SMDS_MeshNode * n3,
210 const SMDS_MeshNode * n4,
211 const SMDS_MeshNode * n5,
212 const SMDS_MeshNode * n6,
213 const SMDS_MeshNode * n7,
214 const SMDS_MeshNode * n8,
216 virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
217 const SMDS_MeshNode * n2,
218 const SMDS_MeshNode * n3,
219 const SMDS_MeshNode * n4,
220 const SMDS_MeshNode * n5,
221 const SMDS_MeshNode * n6,
222 const SMDS_MeshNode * n7,
223 const SMDS_MeshNode * n8);
225 // 2d order tetrahedron of 10 nodes
226 virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4,
227 int n12,int n23,int n31,
228 int n14,int n24,int n34, int ID);
229 virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
230 const SMDS_MeshNode * n2,
231 const SMDS_MeshNode * n3,
232 const SMDS_MeshNode * n4,
233 const SMDS_MeshNode * n12,
234 const SMDS_MeshNode * n23,
235 const SMDS_MeshNode * n31,
236 const SMDS_MeshNode * n14,
237 const SMDS_MeshNode * n24,
238 const SMDS_MeshNode * n34,
240 virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
241 const SMDS_MeshNode * n2,
242 const SMDS_MeshNode * n3,
243 const SMDS_MeshNode * n4,
244 const SMDS_MeshNode * n12,
245 const SMDS_MeshNode * n23,
246 const SMDS_MeshNode * n31,
247 const SMDS_MeshNode * n14,
248 const SMDS_MeshNode * n24,
249 const SMDS_MeshNode * n34);
251 // 2d order pyramid of 13 nodes
252 virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int n5,
253 int n12,int n23,int n34,int n41,
254 int n15,int n25,int n35,int n45,
256 virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
257 const SMDS_MeshNode * n2,
258 const SMDS_MeshNode * n3,
259 const SMDS_MeshNode * n4,
260 const SMDS_MeshNode * n5,
261 const SMDS_MeshNode * n12,
262 const SMDS_MeshNode * n23,
263 const SMDS_MeshNode * n34,
264 const SMDS_MeshNode * n41,
265 const SMDS_MeshNode * n15,
266 const SMDS_MeshNode * n25,
267 const SMDS_MeshNode * n35,
268 const SMDS_MeshNode * n45,
270 virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
271 const SMDS_MeshNode * n2,
272 const SMDS_MeshNode * n3,
273 const SMDS_MeshNode * n4,
274 const SMDS_MeshNode * n5,
275 const SMDS_MeshNode * n12,
276 const SMDS_MeshNode * n23,
277 const SMDS_MeshNode * n34,
278 const SMDS_MeshNode * n41,
279 const SMDS_MeshNode * n15,
280 const SMDS_MeshNode * n25,
281 const SMDS_MeshNode * n35,
282 const SMDS_MeshNode * n45);
284 // 2d order Pentahedron with 15 nodes
285 virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3,
286 int n4, int n5, int n6,
287 int n12,int n23,int n31,
288 int n45,int n56,int n64,
289 int n14,int n25,int n36,
291 virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
292 const SMDS_MeshNode * n2,
293 const SMDS_MeshNode * n3,
294 const SMDS_MeshNode * n4,
295 const SMDS_MeshNode * n5,
296 const SMDS_MeshNode * n6,
297 const SMDS_MeshNode * n12,
298 const SMDS_MeshNode * n23,
299 const SMDS_MeshNode * n31,
300 const SMDS_MeshNode * n45,
301 const SMDS_MeshNode * n56,
302 const SMDS_MeshNode * n64,
303 const SMDS_MeshNode * n14,
304 const SMDS_MeshNode * n25,
305 const SMDS_MeshNode * n36,
307 virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
308 const SMDS_MeshNode * n2,
309 const SMDS_MeshNode * n3,
310 const SMDS_MeshNode * n4,
311 const SMDS_MeshNode * n5,
312 const SMDS_MeshNode * n6,
313 const SMDS_MeshNode * n12,
314 const SMDS_MeshNode * n23,
315 const SMDS_MeshNode * n31,
316 const SMDS_MeshNode * n45,
317 const SMDS_MeshNode * n56,
318 const SMDS_MeshNode * n64,
319 const SMDS_MeshNode * n14,
320 const SMDS_MeshNode * n25,
321 const SMDS_MeshNode * n36);
323 // 2d order Hexahedrons with 20 nodes
324 virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4,
325 int n5, int n6, int n7, int n8,
326 int n12,int n23,int n34,int n41,
327 int n56,int n67,int n78,int n85,
328 int n15,int n26,int n37,int n48,
330 virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
331 const SMDS_MeshNode * n2,
332 const SMDS_MeshNode * n3,
333 const SMDS_MeshNode * n4,
334 const SMDS_MeshNode * n5,
335 const SMDS_MeshNode * n6,
336 const SMDS_MeshNode * n7,
337 const SMDS_MeshNode * n8,
338 const SMDS_MeshNode * n12,
339 const SMDS_MeshNode * n23,
340 const SMDS_MeshNode * n34,
341 const SMDS_MeshNode * n41,
342 const SMDS_MeshNode * n56,
343 const SMDS_MeshNode * n67,
344 const SMDS_MeshNode * n78,
345 const SMDS_MeshNode * n85,
346 const SMDS_MeshNode * n15,
347 const SMDS_MeshNode * n26,
348 const SMDS_MeshNode * n37,
349 const SMDS_MeshNode * n48,
351 virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
352 const SMDS_MeshNode * n2,
353 const SMDS_MeshNode * n3,
354 const SMDS_MeshNode * n4,
355 const SMDS_MeshNode * n5,
356 const SMDS_MeshNode * n6,
357 const SMDS_MeshNode * n7,
358 const SMDS_MeshNode * n8,
359 const SMDS_MeshNode * n12,
360 const SMDS_MeshNode * n23,
361 const SMDS_MeshNode * n34,
362 const SMDS_MeshNode * n41,
363 const SMDS_MeshNode * n56,
364 const SMDS_MeshNode * n67,
365 const SMDS_MeshNode * n78,
366 const SMDS_MeshNode * n85,
367 const SMDS_MeshNode * n15,
368 const SMDS_MeshNode * n26,
369 const SMDS_MeshNode * n37,
370 const SMDS_MeshNode * n48);
372 virtual SMDS_MeshFace* AddPolygonalFaceWithID (std::vector<int> nodes_ids,
375 virtual SMDS_MeshFace* AddPolygonalFaceWithID (std::vector<const SMDS_MeshNode*> nodes,
378 virtual SMDS_MeshFace* AddPolygonalFace (std::vector<const SMDS_MeshNode*> nodes);
380 virtual SMDS_MeshVolume* AddPolyhedralVolumeWithID
381 (std::vector<int> nodes_ids,
382 std::vector<int> quantities,
385 virtual SMDS_MeshVolume* AddPolyhedralVolumeWithID
386 (std::vector<const SMDS_MeshNode*> nodes,
387 std::vector<int> quantities,
390 virtual SMDS_MeshVolume* AddPolyhedralVolume
391 (std::vector<const SMDS_MeshNode*> nodes,
392 std::vector<int> quantities);
394 void MoveNode(const SMDS_MeshNode *, double x, double y, double z);
395 virtual void RemoveNode(const SMDS_MeshNode *);
396 void RemoveElement(const SMDS_MeshElement *);
398 /*! Remove only the given element/node and only if it is free.
399 * Methods do not work for meshes with descendants.
400 * Implemented for fast cleaning of meshes.
402 void RemoveFreeNode(const SMDS_MeshNode *, SMESHDS_SubMesh *);
403 void RemoveFreeElement(const SMDS_MeshElement *, SMESHDS_SubMesh *);
405 bool ChangeElementNodes(const SMDS_MeshElement * elem,
406 const SMDS_MeshNode * nodes[],
408 bool ChangePolygonNodes(const SMDS_MeshElement * elem,
409 std::vector<const SMDS_MeshNode*> nodes);
410 bool ChangePolyhedronNodes(const SMDS_MeshElement * elem,
411 std::vector<const SMDS_MeshNode*> nodes,
412 std::vector<int> quantities);
413 void Renumber (const bool isNodes, const int startID=1, const int deltaID=1);
415 void SetNodeInVolume(SMDS_MeshNode * aNode, const TopoDS_Shell & S);
416 void SetNodeInVolume(SMDS_MeshNode * aNode, const TopoDS_Solid & S);
417 void SetNodeOnFace(SMDS_MeshNode * aNode, const TopoDS_Face & S, double u=0., double v=0.);
418 void SetNodeOnEdge(SMDS_MeshNode * aNode, const TopoDS_Edge & S, double u=0.);
419 void SetNodeOnVertex(SMDS_MeshNode * aNode, const TopoDS_Vertex & S);
420 void UnSetNodeOnShape(const SMDS_MeshNode * aNode);
421 void SetMeshElementOnShape(const SMDS_MeshElement * anElt,
422 const TopoDS_Shape & S);
423 void UnSetMeshElementOnShape(const SMDS_MeshElement * anElt,
424 const TopoDS_Shape & S);
425 bool HasMeshElements(const TopoDS_Shape & S);
426 SMESHDS_SubMesh * MeshElements(const TopoDS_Shape & S) const;
427 SMESHDS_SubMesh * MeshElements(const int Index);
428 std::list<int> SubMeshIndices();
429 const std::map<int,SMESHDS_SubMesh*>& SubMeshes() const
430 { return myShapeIndexToSubMesh; }
432 bool HasHypothesis(const TopoDS_Shape & S);
433 const std::list<const SMESHDS_Hypothesis*>& GetHypothesis(const TopoDS_Shape & S) const;
434 SMESHDS_Script * GetScript();
436 int ShapeToIndex(const TopoDS_Shape & aShape) const;
437 const TopoDS_Shape& IndexToShape(int ShapeIndex) const;
438 int MaxShapeIndex() const { return myIndexToShape.Extent(); }
440 SMESHDS_SubMesh * NewSubMesh(int Index);
441 int AddCompoundSubmesh(const TopoDS_Shape& S, TopAbs_ShapeEnum type = TopAbs_SHAPE);
442 void SetNodeInVolume(const SMDS_MeshNode * aNode, int Index);
443 void SetNodeOnFace(SMDS_MeshNode * aNode, int Index , double u=0., double v=0.);
444 void SetNodeOnEdge(SMDS_MeshNode * aNode, int Index , double u=0.);
445 void SetNodeOnVertex(SMDS_MeshNode * aNode, int Index);
446 void SetMeshElementOnShape(const SMDS_MeshElement * anElt, int Index);
448 void AddGroup (SMESHDS_GroupBase* theGroup) { myGroups.insert(theGroup); }
449 void RemoveGroup (SMESHDS_GroupBase* theGroup) { myGroups.erase(theGroup); }
450 int GetNbGroups() const { return myGroups.size(); }
451 const std::set<SMESHDS_GroupBase*>& GetGroups() const { return myGroups; }
453 bool IsGroupOfSubShapes (const TopoDS_Shape& aSubShape) const;
459 struct HashTopoDS_Shape{
460 size_t operator()(const TopoDS_Shape& S) const {
461 return S.HashCode(2147483647);
465 typedef gstd::hash_compare< TopoDS_Shape, less<TopoDS_Shape> > HashTopoDS;
467 class HashTopoDS_Shape : public HashTopoDS {
470 size_t operator()(const TopoDS_Shape& S) const {
471 return S.HashCode(2147483647);
474 bool operator()(const TopoDS_Shape& S1,const TopoDS_Shape& S2) const {
483 typedef std::list<const SMESHDS_Hypothesis*> THypList;
486 typedef gstd::hash_map<TopoDS_Shape,THypList,HashTopoDS_Shape> ShapeToHypothesis;
488 typedef gstd::hash_map<TopoDS_Shape,THypList,HashTopoDS_Shape> ShapeToHypothesis;
491 ShapeToHypothesis myShapeToHypothesis;
494 TopoDS_Shape myShape;
496 typedef std::map<int,SMESHDS_SubMesh*> TShapeIndexToSubMesh;
497 TShapeIndexToSubMesh myShapeIndexToSubMesh;
499 TopTools_IndexedMapOfShape myIndexToShape;
501 typedef std::set<SMESHDS_GroupBase*> TGroups;
504 SMESHDS_Script* myScript;
505 bool myIsEmbeddedMode;
507 // optimize addition of nodes/elements to submeshes by, SetNodeInVolume() etc:
508 // avoid search of submeshes in maps
509 bool add( const SMDS_MeshElement* elem, SMESHDS_SubMesh* subMesh );
510 SMESHDS_SubMesh* getSubmesh( const TopoDS_Shape & shape);
511 SMESHDS_SubMesh* getSubmesh( const int Index );
513 TopoDS_Shape myCurSubShape;
514 SMESHDS_SubMesh* myCurSubMesh;