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_Mesh.hxx>
30 #include <TopoDS_Shape.hxx>
31 #include <SMDS_MeshNode.hxx>
32 #include <TopoDS_Face.hxx>
33 #include <gp_Pnt2d.hxx>
34 #include <SMDS_QuadraticEdge.hxx>
38 typedef pair<const SMDS_MeshNode*, const SMDS_MeshNode*> NLink;
39 typedef map<NLink, const SMDS_MeshNode*> NLinkNodeMap;
40 typedef map<NLink, const SMDS_MeshNode*>::iterator ItNLinkNode;
43 * \brief It helps meshers to add elements
45 * It allow meshers not to care about creation of medium nodes
46 * when filling a quadratic mesh. Helper does it itself.
47 * It defines degree of elements to create when IsQuadraticSubMesh()
51 class SMESH_MesherHelper
54 // ---------- PUBLIC METHODS ----------
57 SMESH_MesherHelper(SMESH_Mesh& theMesh)
58 { myMesh=(void *)&theMesh; myCreateQuadratic = false; myShapeID=-1;}
60 SMESH_Mesh* GetMesh() const
61 { return (SMESH_Mesh*)myMesh; }
64 //Standard_EXPORT SMESH_MesherHelper (const SMESH_MesherHelper& theOther);
67 //Standard_EXPORT virtual ~SMESH_MesherHelper ();
70 * Check submesh for given shape
71 * Check if all elements on this shape
72 * are quadratic, if yes => set true to myCreateQuadratic
73 * (default value is false). Also fill myNLinkNodeMap
74 * Returns myCreateQuadratic
76 bool IsQuadraticSubMesh(const TopoDS_Shape& theShape);
79 * \brief Returns true if given node is medium
80 * \param n - node to check
81 * \param typeToCheck - type of elements containing the node to ask about node status
82 * \retval bool - check result
84 static bool IsMedium(const SMDS_MeshNode* node,
85 const SMDSAbs_ElementType typeToCheck = SMDSAbs_All);
88 * Auxilary function for filling myNLinkNodeMap
90 void AddNLinkNode(const SMDS_MeshNode* n1,
91 const SMDS_MeshNode* n2,
92 const SMDS_MeshNode* n12);
95 * Auxilary function for filling myNLinkNodeMap
97 void AddNLinkNodeMap(const NLinkNodeMap& aMap)
98 { myNLinkNodeMap.insert(aMap.begin(), aMap.end()); }
101 * Returns myNLinkNodeMap
103 const NLinkNodeMap& GetNLinkNodeMap() { return myNLinkNodeMap; }
106 * \brief Return node UV on face
107 * \param F - the face
108 * \param n - the node
109 * \param inFaceNode - a node of element being created located inside a face
110 * \retval gp_XY - resulting UV
112 * Auxilary function called form GetMediumNode()
114 gp_XY GetNodeUV(const TopoDS_Face& F,
115 const SMDS_MeshNode* n,
116 const SMDS_MeshNode* inFaceNode=0);
119 * \brief Check if inFaceNode argument is necessary for call GetNodeUV(F,..)
120 * \param F - the face
121 * \retval bool - return true if the face is periodic
123 * if F is Null, answer about subshape set through IsQuadraticSubMesh() or
126 bool GetNodeUVneedInFaceNode(const TopoDS_Face& F = TopoDS_Face()) const;
129 * \brief Return U on edge
130 * \param F - the edge
131 * \param n - the node
132 * \retval double - resulting U
134 * Auxilary function called from GetMediumNode()
136 double GetNodeU(const TopoDS_Edge& E,
137 const SMDS_MeshNode* n);
141 * Special function for search or creation medium node
143 const SMDS_MeshNode* GetMediumNode(const SMDS_MeshNode* n1,
144 const SMDS_MeshNode* n2,
148 * Special function for creation quadratic edge
150 SMDS_QuadraticEdge* AddQuadraticEdge(const SMDS_MeshNode* n1,
151 const SMDS_MeshNode* n2,
153 const bool force3d = true);
156 * Special function for creation quadratic triangle
158 SMDS_MeshFace* AddFace(const SMDS_MeshNode* n1,
159 const SMDS_MeshNode* n2,
160 const SMDS_MeshNode* n3,
162 const bool force3d = false);
165 * Special function for creation quadratic quadrangle
167 SMDS_MeshFace* AddFace(const SMDS_MeshNode* n1,
168 const SMDS_MeshNode* n2,
169 const SMDS_MeshNode* n3,
170 const SMDS_MeshNode* n4,
172 const bool force3d = false);
175 * Special function for creation quadratic tetraahedron
177 SMDS_MeshVolume* AddVolume(const SMDS_MeshNode* n1,
178 const SMDS_MeshNode* n2,
179 const SMDS_MeshNode* n3,
180 const SMDS_MeshNode* n4,
182 const bool force3d = true);
185 * Special function for creation quadratic pentahedron
187 SMDS_MeshVolume* AddVolume(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,
194 const bool force3d = true);
197 * Special function for creation quadratic hexahedron
199 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,
205 const SMDS_MeshNode* n7,
206 const SMDS_MeshNode* n8,
208 bool force3d = true);
212 * \brief Set order of elements to create
213 * \param theBuildQuadratic - to build quadratic or not
215 * To be used for quadratic elements creation without preceding
216 * IsQuadraticSubMesh() or AddQuadraticEdge() call
218 void SetKeyIsQuadratic(const bool theBuildQuadratic)
219 { myCreateQuadratic = theBuildQuadratic; }
222 * \brief Set shape to make elements on
223 * \param subShape, subShapeID - shape or its ID (==SMESHDS_Mesh::ShapeToIndex(shape))
225 void SetSubShape(const int subShapeID);
226 void SetSubShape(const TopoDS_Shape& subShape);
229 * \brief Return shape or its ID, on which created elements are added
230 * \retval TopoDS_Shape, int - shape or its ID
232 int GetSubShapeID() { return myShapeID; }
233 TopoDS_Shape GetSubShape() { return myShape; }
238 * \brief Select UV on either of 2 pcurves of a seam edge, closest to the given UV
239 * \param uv1 - UV on the seam
240 * \param uv2 - UV within a face
241 * \retval gp_Pnt2d - selected UV
243 gp_Pnt2d GetUVOnSeam( const gp_Pnt2d& uv1, const gp_Pnt2d& uv2 ) const;
251 // Key for creation quadratic faces
252 bool myCreateQuadratic;
254 // special map for using during creation quadratic faces
255 NLinkNodeMap myNLinkNodeMap;
257 std::set< int > mySeamShapeIds;
258 double myPar1, myPar2; // bounds of a closed periodic surface
259 int myParIndex; // bounds' index (1-U, 2-V)
260 TopoDS_Shape myShape;