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
23 // Copyright: Open CASCADE 2006
26 #ifndef SMESH_MesherHelper_HeaderFile
27 #define SMESH_MesherHelper_HeaderFile
29 #include "SMESH_SMESH.hxx"
31 #include <SMESH_Mesh.hxx>
32 #include <TopoDS_Shape.hxx>
33 #include <SMDS_MeshNode.hxx>
34 #include <TopoDS_Face.hxx>
35 #include <gp_Pnt2d.hxx>
36 #include <SMDS_QuadraticEdge.hxx>
40 typedef pair<const SMDS_MeshNode*, const SMDS_MeshNode*> NLink;
41 typedef map<NLink, const SMDS_MeshNode*> NLinkNodeMap;
42 typedef map<NLink, const SMDS_MeshNode*>::iterator ItNLinkNode;
45 * \brief It helps meshers to add elements
47 * It allow meshers not to care about creation of medium nodes
48 * when filling a quadratic mesh. Helper does it itself.
49 * It defines degree of elements to create when IsQuadraticSubMesh()
53 class SMESH_EXPORT SMESH_MesherHelper
56 // ---------- PUBLIC METHODS ----------
59 SMESH_MesherHelper(SMESH_Mesh& theMesh)
60 { myMesh=(void *)&theMesh; myCreateQuadratic = false; myShapeID=-1;}
62 SMESH_Mesh* GetMesh() const
63 { return (SMESH_Mesh*)myMesh; }
66 //Standard_EXPORT SMESH_MesherHelper (const SMESH_MesherHelper& theOther);
69 //Standard_EXPORT virtual ~SMESH_MesherHelper ();
72 * Check submesh for given shape
73 * Check if all elements on this shape
74 * are quadratic, if yes => set true to myCreateQuadratic
75 * (default value is false). Also fill myNLinkNodeMap
76 * Returns myCreateQuadratic
78 bool IsQuadraticSubMesh(const TopoDS_Shape& theShape);
81 * \brief Returns true if given node is medium
82 * \param n - node to check
83 * \param typeToCheck - type of elements containing the node to ask about node status
84 * \retval bool - check result
86 static bool IsMedium(const SMDS_MeshNode* node,
87 const SMDSAbs_ElementType typeToCheck = SMDSAbs_All);
90 * Auxilary function for filling myNLinkNodeMap
92 void AddNLinkNode(const SMDS_MeshNode* n1,
93 const SMDS_MeshNode* n2,
94 const SMDS_MeshNode* n12);
97 * Auxilary function for filling myNLinkNodeMap
99 void AddNLinkNodeMap(const NLinkNodeMap& aMap)
100 { myNLinkNodeMap.insert(aMap.begin(), aMap.end()); }
103 * Returns myNLinkNodeMap
105 const NLinkNodeMap& GetNLinkNodeMap() { return myNLinkNodeMap; }
108 * \brief Return node UV on face
109 * \param F - the face
110 * \param n - the node
111 * \param inFaceNode - a node of element being created located inside a face
112 * \retval gp_XY - resulting UV
114 * Auxilary function called form GetMediumNode()
116 gp_XY GetNodeUV(const TopoDS_Face& F,
117 const SMDS_MeshNode* n,
118 const SMDS_MeshNode* inFaceNode=0);
121 * \brief Check if inFaceNode argument is necessary for call GetNodeUV(F,..)
122 * \param F - the face
123 * \retval bool - return true if the face is periodic
125 * if F is Null, answer about subshape set through IsQuadraticSubMesh() or
128 bool GetNodeUVneedInFaceNode(const TopoDS_Face& F = TopoDS_Face()) const;
131 * \brief Return U on edge
132 * \param F - the edge
133 * \param n - the node
134 * \retval double - resulting U
136 * Auxilary function called from GetMediumNode()
138 double GetNodeU(const TopoDS_Edge& E,
139 const SMDS_MeshNode* n);
143 * Special function for search or creation medium node
145 const SMDS_MeshNode* GetMediumNode(const SMDS_MeshNode* n1,
146 const SMDS_MeshNode* n2,
150 * Special function for creation quadratic edge
152 SMDS_QuadraticEdge* AddQuadraticEdge(const SMDS_MeshNode* n1,
153 const SMDS_MeshNode* n2,
155 const bool force3d = true);
158 * Special function for creation quadratic triangle
160 SMDS_MeshFace* AddFace(const SMDS_MeshNode* n1,
161 const SMDS_MeshNode* n2,
162 const SMDS_MeshNode* n3,
164 const bool force3d = false);
167 * Special function for creation quadratic quadrangle
169 SMDS_MeshFace* AddFace(const SMDS_MeshNode* n1,
170 const SMDS_MeshNode* n2,
171 const SMDS_MeshNode* n3,
172 const SMDS_MeshNode* n4,
174 const bool force3d = false);
177 * Special function for creation quadratic tetraahedron
179 SMDS_MeshVolume* AddVolume(const SMDS_MeshNode* n1,
180 const SMDS_MeshNode* n2,
181 const SMDS_MeshNode* n3,
182 const SMDS_MeshNode* n4,
184 const bool force3d = true);
187 * Special function for creation quadratic pentahedron
189 SMDS_MeshVolume* AddVolume(const SMDS_MeshNode* n1,
190 const SMDS_MeshNode* n2,
191 const SMDS_MeshNode* n3,
192 const SMDS_MeshNode* n4,
193 const SMDS_MeshNode* n5,
194 const SMDS_MeshNode* n6,
196 const bool force3d = true);
199 * Special function for creation quadratic hexahedron
201 SMDS_MeshVolume* AddVolume(const SMDS_MeshNode* n1,
202 const SMDS_MeshNode* n2,
203 const SMDS_MeshNode* n3,
204 const SMDS_MeshNode* n4,
205 const SMDS_MeshNode* n5,
206 const SMDS_MeshNode* n6,
207 const SMDS_MeshNode* n7,
208 const SMDS_MeshNode* n8,
210 bool force3d = true);
214 * \brief Set order of elements to create
215 * \param theBuildQuadratic - to build quadratic or not
217 * To be used for quadratic elements creation without preceding
218 * IsQuadraticSubMesh() or AddQuadraticEdge() call
220 void SetKeyIsQuadratic(const bool theBuildQuadratic)
221 { myCreateQuadratic = theBuildQuadratic; }
224 * \brief Set shape to make elements on
225 * \param subShape, subShapeID - shape or its ID (==SMESHDS_Mesh::ShapeToIndex(shape))
227 void SetSubShape(const int subShapeID);
228 void SetSubShape(const TopoDS_Shape& subShape);
231 * \brief Return shape or its ID, on which created elements are added
232 * \retval TopoDS_Shape, int - shape or its ID
234 int GetSubShapeID() { return myShapeID; }
235 TopoDS_Shape GetSubShape() { return myShape; }
240 * \brief Select UV on either of 2 pcurves of a seam edge, closest to the given UV
241 * \param uv1 - UV on the seam
242 * \param uv2 - UV within a face
243 * \retval gp_Pnt2d - selected UV
245 gp_Pnt2d GetUVOnSeam( const gp_Pnt2d& uv1, const gp_Pnt2d& uv2 ) const;
253 // Key for creation quadratic faces
254 bool myCreateQuadratic;
256 // special map for using during creation quadratic faces
257 NLinkNodeMap myNLinkNodeMap;
259 std::set< int > mySeamShapeIds;
260 double myPar1, myPar2; // bounds of a closed periodic surface
261 int myParIndex; // bounds' index (1-U, 2-V)
262 TopoDS_Shape myShape;