1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File: SMESH_MesherHelper.hxx
21 // Created: 15.02.06 14:48:09
22 // Author: Sergey KUUL
25 #ifndef SMESH_MesherHelper_HeaderFile
26 #define SMESH_MesherHelper_HeaderFile
28 #include "SMESH_SMESH.hxx"
30 #include <SMESH_Mesh.hxx>
31 #include <TopoDS_Shape.hxx>
32 #include <SMDS_MeshNode.hxx>
33 #include <TopoDS_Face.hxx>
34 #include <gp_Pnt2d.hxx>
35 #include <SMDS_QuadraticEdge.hxx>
39 typedef pair<const SMDS_MeshNode*, const SMDS_MeshNode*> NLink;
40 typedef map<NLink, const SMDS_MeshNode*> NLinkNodeMap;
41 typedef map<NLink, const SMDS_MeshNode*>::iterator ItNLinkNode;
44 * \brief It helps meshers to add elements
46 * It allow meshers not to care about creation of medium nodes
47 * when filling a quadratic mesh. Helper does it itself.
48 * It defines degree of elements to create when IsQuadraticSubMesh()
52 typedef std::vector<const SMDS_MeshNode* > TNodeColumn;
53 typedef std::map< double, TNodeColumn > TParam2ColumnMap;
55 class SMESH_EXPORT SMESH_MesherHelper
58 // ---------- PUBLIC UTILITIES ----------
61 * \brief Returns true if given node is medium
62 * \param n - node to check
63 * \param typeToCheck - type of elements containing the node to ask about node status
64 * \retval bool - check result
66 static bool IsMedium(const SMDS_MeshNode* node,
67 const SMDSAbs_ElementType typeToCheck = SMDSAbs_All);
70 * \brief Load nodes bound to face into a map of node columns
71 * \param theParam2ColumnMap - map of node columns to fill
72 * \param theFace - the face on which nodes are searched for
73 * \param theBaseEdge - the edge nodes of which are columns' bases
74 * \param theMesh - the mesh containing nodes
75 * \retval bool - false if something is wrong
77 * The key of the map is a normalized parameter of each
78 * base node on theBaseEdge.
79 * This method works in supposition that nodes on the face
80 * forms a rectangular grid and elements can be quardrangles or triangles
82 static bool LoadNodeColumns(TParam2ColumnMap & theParam2ColumnMap,
83 const TopoDS_Face& theFace,
84 const TopoDS_Edge& theBaseEdge,
85 SMESHDS_Mesh* theMesh);
87 * \brief Return support shape of a node
88 * \param node - the node
89 * \param meshDS - mesh DS
90 * \retval TopoDS_Shape - found support shape
92 static const TopoDS_Shape& GetSubShapeByNode(const SMDS_MeshNode* node,
94 { return meshDS->IndexToShape( node->GetPosition()->GetShapeId() ); }
97 * \brief Return a valid node index, fixing the given one if necessary
98 * \param ind - node index
99 * \param nbNodes - total nb of nodes
100 * \retval int - valid node index
102 static int WrapIndex(const int ind, const int nbNodes) {
103 if ( ind < 0 ) return nbNodes + ind % nbNodes;
104 if ( ind >= nbNodes ) return ind % nbNodes;
109 // ---------- PUBLIC INSTANCE METHODS ----------
112 SMESH_MesherHelper(SMESH_Mesh& theMesh);
114 SMESH_Mesh* GetMesh() const { return myMesh; }
116 SMESHDS_Mesh* GetMeshDS() const { return GetMesh()->GetMeshDS(); }
119 * Check submesh for given shape: if all elements on this shape are quadratic,
120 * quadratic elements will be created. Also fill myNLinkNodeMap
122 bool IsQuadraticSubMesh(const TopoDS_Shape& theShape);
124 * \brief Set order of elements to create without calling IsQuadraticSubMesh()
126 void SetIsQuadratic(const bool theBuildQuadratic)
127 { myCreateQuadratic = theBuildQuadratic; }
129 * \brief Return myCreateQuadratic flag
131 bool GetIsQuadratic() const { return myCreateQuadratic; }
134 * \brief To set created elements on the shape set by IsQuadraticSubMesh()
135 * or the next methods. By defaul elements are set on the shape if
136 * a mesh has no shape to be meshed
138 void SetElementsOnShape(bool toSet) { mySetElemOnShape = toSet; }
141 * \brief Set shape to make elements on without calling IsQuadraticSubMesh()
143 void SetSubShape(const int subShapeID);//!==SMESHDS_Mesh::ShapeToIndex(shape)
144 void SetSubShape(const TopoDS_Shape& subShape);
146 * \brief Return ID of the shape set by IsQuadraticSubMesh() or SetSubShape()
147 * \retval int - shape index in SMESHDS
149 int GetSubShapeID() const { return myShapeID; }
151 * \brief Return the shape set by IsQuadraticSubMesh() or SetSubShape()
153 TopoDS_Shape GetSubShape() const { return myShape; }
158 SMDS_MeshNode* AddNode(double x, double y, double z, int ID = 0);
160 * Creates quadratic or linear edge
162 SMDS_MeshEdge* AddEdge(const SMDS_MeshNode* n1,
163 const SMDS_MeshNode* n2,
165 const bool force3d = true);
167 * Creates quadratic or linear triangle
169 SMDS_MeshFace* AddFace(const SMDS_MeshNode* n1,
170 const SMDS_MeshNode* n2,
171 const SMDS_MeshNode* n3,
173 const bool force3d = false);
175 * Creates quadratic or linear quadrangle
177 SMDS_MeshFace* AddFace(const SMDS_MeshNode* n1,
178 const SMDS_MeshNode* n2,
179 const SMDS_MeshNode* n3,
180 const SMDS_MeshNode* n4,
182 const bool force3d = false);
184 * Creates quadratic or linear tetraahedron
186 SMDS_MeshVolume* AddVolume(const SMDS_MeshNode* n1,
187 const SMDS_MeshNode* n2,
188 const SMDS_MeshNode* n3,
189 const SMDS_MeshNode* n4,
191 const bool force3d = true);
193 * Creates quadratic or linear pyramid
195 SMDS_MeshVolume* AddVolume(const SMDS_MeshNode* n1,
196 const SMDS_MeshNode* n2,
197 const SMDS_MeshNode* n3,
198 const SMDS_MeshNode* n4,
199 const SMDS_MeshNode* n5,
201 const bool force3d = true);
203 * Creates quadratic or linear pentahedron
205 SMDS_MeshVolume* AddVolume(const SMDS_MeshNode* n1,
206 const SMDS_MeshNode* n2,
207 const SMDS_MeshNode* n3,
208 const SMDS_MeshNode* n4,
209 const SMDS_MeshNode* n5,
210 const SMDS_MeshNode* n6,
212 const bool force3d = true);
214 * Creates quadratic or linear hexahedron
216 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 bool force3d = true);
227 * \brief Return U of the given node on the edge
229 double GetNodeU(const TopoDS_Edge& theEdge,
230 const SMDS_MeshNode* theNode);
232 * \brief Return node UV on face
233 * \param inFaceNode - a node of element being created located inside a face
235 gp_XY GetNodeUV(const TopoDS_Face& F,
236 const SMDS_MeshNode* n,
237 const SMDS_MeshNode* inFaceNode=0) const;
239 * \brief Check if inFaceNode argument is necessary for call GetNodeUV(F,..)
240 * \retval bool - return true if the face is periodic
242 * if F is Null, answer about subshape set through IsQuadraticSubMesh() or
245 bool GetNodeUVneedInFaceNode(const TopoDS_Face& F = TopoDS_Face()) const;
248 * \brief Check if shape is a degenerated edge or it's vertex
249 * \param subShape - edge or vertex index in SMESHDS
250 * \retval bool - true if subShape is a degenerated shape
252 * It works only if IsQuadraticSubMesh() or SetSubShape() has been called
254 bool IsDegenShape(const int subShape) const
255 { return myDegenShapeIds.find( subShape ) != myDegenShapeIds.end(); }
257 * \brief Check if shape is a seam edge or it's vertex
258 * \param subShape - edge or vertex index in SMESHDS
259 * \retval bool - true if subShape is a seam shape
261 * It works only if IsQuadraticSubMesh() or SetSubShape() has been called
263 bool IsSeamShape(const int subShape) const
264 { return mySeamShapeIds.find( subShape ) != mySeamShapeIds.end(); }
266 * \brief Check if shape is a seam edge or it's vertex
267 * \param subShape - edge or vertex
268 * \retval bool - true if subShape is a seam shape
270 * It works only if IsQuadraticSubMesh() or SetSubShape() has been called
272 bool IsSeamShape(const TopoDS_Shape& subShape) const
273 { return IsSeamShape( GetMeshDS()->ShapeToIndex( subShape )); }
275 * \brief Check if the shape set through IsQuadraticSubMesh() or SetSubShape()
277 * \retval bool - true if it has
279 bool HasSeam() const { return !mySeamShapeIds.empty(); }
281 * \brief Return index of periodic parametric direction of a closed face
282 * \retval int - 1 for U, 2 for V direction
284 int GetPeriodicIndex() const { return myParIndex; }
287 * Special function for search or creation medium node
289 const SMDS_MeshNode* GetMediumNode(const SMDS_MeshNode* n1,
290 const SMDS_MeshNode* n2,
293 * Auxilary function for filling myNLinkNodeMap
295 void AddNLinkNode(const SMDS_MeshNode* n1,
296 const SMDS_MeshNode* n2,
297 const SMDS_MeshNode* n12);
299 * Auxilary function for filling myNLinkNodeMap
301 void AddNLinkNodeMap(const NLinkNodeMap& aMap)
302 { myNLinkNodeMap.insert(aMap.begin(), aMap.end()); }
305 * Returns myNLinkNodeMap
307 const NLinkNodeMap& GetNLinkNodeMap() const { return myNLinkNodeMap; }
310 * Check mesh without geometry for: if all elements on this shape are quadratic,
311 * quadratic elements will be created.
312 * Used then generated 3D mesh without geometry.
314 enum MType{ LINEAR, QUADRATIC, COMP };
315 MType IsQuadraticMesh();
320 * \brief Select UV on either of 2 pcurves of a seam edge, closest to the given UV
321 * \param uv1 - UV on the seam
322 * \param uv2 - UV within a face
323 * \retval gp_Pnt2d - selected UV
325 gp_Pnt2d GetUVOnSeam( const gp_Pnt2d& uv1, const gp_Pnt2d& uv2 ) const;
329 // Forbiden copy constructor
330 SMESH_MesherHelper (const SMESH_MesherHelper& theOther) {};
332 // special map for using during creation of quadratic elements
333 NLinkNodeMap myNLinkNodeMap;
335 std::set< int > myDegenShapeIds;
336 std::set< int > mySeamShapeIds;
337 double myPar1, myPar2; // bounds of a closed periodic surface
338 int myParIndex; // bounds' index (1-U, 2-V)
340 TopoDS_Shape myShape;
344 // to create quadratic elements
345 bool myCreateQuadratic;
346 bool mySetElemOnShape;