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_Mesh.hxx>
29 #include <TopoDS_Shape.hxx>
30 #include <SMDS_MeshNode.hxx>
31 #include <TopoDS_Face.hxx>
32 #include <gp_Pnt2d.hxx>
33 #include <SMDS_QuadraticEdge.hxx>
37 typedef pair<const SMDS_MeshNode*, const SMDS_MeshNode*> NLink;
38 typedef map<NLink, const SMDS_MeshNode*> NLinkNodeMap;
39 typedef map<NLink, const SMDS_MeshNode*>::iterator ItNLinkNode;
42 * \brief It helps meshers to add elements
44 * It allow meshers not to care about creation of medium nodes
45 * when filling a quadratic mesh. Helper does it itself.
46 * It defines degree of elements to create when IsQuadraticSubMesh()
50 typedef std::vector<const SMDS_MeshNode* > TNodeColumn;
51 typedef std::map< double, TNodeColumn > TParam2ColumnMap;
53 class SMESH_MesherHelper
56 // ---------- PUBLIC UTILITIES ----------
59 * \brief Load nodes bound to face into a map of node columns
60 * \param theParam2ColumnMap - map of node columns to fill
61 * \param theFace - the face on which nodes are searched for
62 * \param theBaseEdge - the edge nodes of which are columns' bases
63 * \param theMesh - the mesh containing nodes
64 * \retval bool - false if something is wrong
66 * The key of the map is a normalized parameter of each
67 * base node on theBaseEdge.
68 * This method works in supposition that nodes on the face
69 * forms a rectangular grid and elements can be quardrangles or triangles
71 static bool LoadNodeColumns(TParam2ColumnMap & theParam2ColumnMap,
72 const TopoDS_Face& theFace,
73 const TopoDS_Edge& theBaseEdge,
74 SMESHDS_Mesh* theMesh);
76 * \brief Return support shape of a node
77 * \param node - the node
78 * \param meshDS - mesh DS
79 * \retval TopoDS_Shape - found support shape
81 static const TopoDS_Shape& GetSubShapeByNode(const SMDS_MeshNode* node,
83 { return meshDS->IndexToShape( node->GetPosition()->GetShapeId() ); }
86 * \brief Return a valid node index, fixing the given one if necessary
87 * \param ind - node index
88 * \param nbNodes - total nb of nodes
89 * \retval int - valid node index
91 static int WrapIndex(const int ind, const int nbNodes) {
92 if ( ind < 0 ) return nbNodes + ind % nbNodes;
93 if ( ind >= nbNodes ) return ind % nbNodes;
98 // ---------- PUBLIC METHODS ----------
100 /// Empty constructor
101 SMESH_MesherHelper(SMESH_Mesh& theMesh)
102 { myMesh=(void *)&theMesh; myCreateQuadratic = false; myShapeID=-1;}
104 SMESH_Mesh* GetMesh() const { return (SMESH_Mesh*)myMesh; }
106 SMESHDS_Mesh* GetMeshDS() const { return GetMesh()->GetMeshDS(); }
109 //Standard_EXPORT SMESH_MesherHelper (const SMESH_MesherHelper& theOther);
112 //Standard_EXPORT virtual ~SMESH_MesherHelper ();
115 * Check submesh for given shape
116 * Check if all elements on this shape
117 * are quadratic, if yes => set true to myCreateQuadratic
118 * (default value is false). Also fill myNLinkNodeMap
119 * Returns myCreateQuadratic
121 bool IsQuadraticSubMesh(const TopoDS_Shape& theShape);
124 * \brief Returns true if given node is medium
125 * \param n - node to check
126 * \param typeToCheck - type of elements containing the node to ask about node status
127 * \retval bool - check result
129 static bool IsMedium(const SMDS_MeshNode* node,
130 const SMDSAbs_ElementType typeToCheck = SMDSAbs_All);
133 * Auxilary function for filling myNLinkNodeMap
135 void AddNLinkNode(const SMDS_MeshNode* n1,
136 const SMDS_MeshNode* n2,
137 const SMDS_MeshNode* n12);
140 * Auxilary function for filling myNLinkNodeMap
142 void AddNLinkNodeMap(const NLinkNodeMap& aMap)
143 { myNLinkNodeMap.insert(aMap.begin(), aMap.end()); }
146 * Returns myNLinkNodeMap
148 const NLinkNodeMap& GetNLinkNodeMap() { return myNLinkNodeMap; }
151 * \brief Return node UV on face
152 * \param F - the face
153 * \param n - the node
154 * \param inFaceNode - a node of element being created located inside a face
155 * \retval gp_XY - resulting UV
157 * Auxilary function called form GetMediumNode()
159 gp_XY GetNodeUV(const TopoDS_Face& F,
160 const SMDS_MeshNode* n,
161 const SMDS_MeshNode* inFaceNode=0) const;
164 * \brief Check if inFaceNode argument is necessary for call GetNodeUV(F,..)
165 * \param F - the face
166 * \retval bool - return true if the face is periodic
168 * if F is Null, answer about subshape set through IsQuadraticSubMesh() or
171 bool GetNodeUVneedInFaceNode(const TopoDS_Face& F = TopoDS_Face()) const;
174 * \brief Return U on edge
175 * \param F - the edge
176 * \param n - the node
177 * \retval double - resulting U
179 * Auxilary function called from GetMediumNode()
181 double GetNodeU(const TopoDS_Edge& E,
182 const SMDS_MeshNode* n);
186 * Special function for search or creation medium node
188 const SMDS_MeshNode* GetMediumNode(const SMDS_MeshNode* n1,
189 const SMDS_MeshNode* n2,
193 * Special function for creation quadratic edge
195 SMDS_QuadraticEdge* AddQuadraticEdge(const SMDS_MeshNode* n1,
196 const SMDS_MeshNode* n2,
198 const bool force3d = true);
201 * Special function for creation quadratic triangle
203 SMDS_MeshFace* AddFace(const SMDS_MeshNode* n1,
204 const SMDS_MeshNode* n2,
205 const SMDS_MeshNode* n3,
207 const bool force3d = false);
210 * Special function for creation quadratic quadrangle
212 SMDS_MeshFace* AddFace(const SMDS_MeshNode* n1,
213 const SMDS_MeshNode* n2,
214 const SMDS_MeshNode* n3,
215 const SMDS_MeshNode* n4,
217 const bool force3d = false);
220 * Special function for creation quadratic tetraahedron
222 SMDS_MeshVolume* AddVolume(const SMDS_MeshNode* n1,
223 const SMDS_MeshNode* n2,
224 const SMDS_MeshNode* n3,
225 const SMDS_MeshNode* n4,
227 const bool force3d = true);
231 * Special function for creation quadratic pyramid
233 SMDS_MeshVolume* AddVolume(const SMDS_MeshNode* n1,
234 const SMDS_MeshNode* n2,
235 const SMDS_MeshNode* n3,
236 const SMDS_MeshNode* n4,
237 const SMDS_MeshNode* n5,
239 const bool force3d = true);
242 * Special function for creation quadratic pentahedron
244 SMDS_MeshVolume* AddVolume(const SMDS_MeshNode* n1,
245 const SMDS_MeshNode* n2,
246 const SMDS_MeshNode* n3,
247 const SMDS_MeshNode* n4,
248 const SMDS_MeshNode* n5,
249 const SMDS_MeshNode* n6,
251 const bool force3d = true);
254 * Special function for creation quadratic hexahedron
256 SMDS_MeshVolume* AddVolume(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* n6,
262 const SMDS_MeshNode* n7,
263 const SMDS_MeshNode* n8,
265 bool force3d = true);
269 * \brief Set order of elements to create
270 * \param theBuildQuadratic - to build quadratic or not
272 * To be used for quadratic elements creation without preceding
273 * IsQuadraticSubMesh() or AddQuadraticEdge() call
275 void SetKeyIsQuadratic(const bool theBuildQuadratic)
276 { myCreateQuadratic = theBuildQuadratic; }
279 * \brief Return myCreateQuadratic flag
280 * \retval bool - myCreateQuadratic value
282 bool GetIsQuadratic() const { return myCreateQuadratic; }
285 * \brief Set shape to make elements on
286 * \param subShape, subShapeID - shape or its ID (==SMESHDS_Mesh::ShapeToIndex(shape))
288 void SetSubShape(const int subShapeID);
289 void SetSubShape(const TopoDS_Shape& subShape);
292 * \brief Return shape or its ID, on which created elements are added
293 * \retval int - shape index in SMESHDS
295 * Shape is set by calling either IsQuadraticSubMesh() or SetSubShape()
297 int GetSubShapeID() const { return myShapeID; }
299 * \brief Return shape or its ID, on which created elements are added
300 * \retval TopoDS_Shape - shape
302 * Shape is set by calling either IsQuadraticSubMesh() or SetSubShape()
304 TopoDS_Shape GetSubShape() const { return myShape; }
307 * \brief Check if shape is a seam edge or it's vertex
308 * \param subShape - edge or vertex index in SMESHDS
309 * \retval bool - true if subShape is a seam shape
311 * It works only if IsQuadraticSubMesh() or SetSubShape() has been called
313 bool IsSeamShape(const int subShape) const
314 { return mySeamShapeIds.find( subShape ) != mySeamShapeIds.end(); }
316 * \brief Check if shape is a seam edge or it's vertex
317 * \param subShape - edge or vertex
318 * \retval bool - true if subShape is a seam shape
320 * It works only if IsQuadraticSubMesh() or SetSubShape() has been called
322 bool IsSeamShape(const TopoDS_Shape& subShape) const
323 { return IsSeamShape( GetMeshDS()->ShapeToIndex( subShape )); }
326 * \brief Check if the shape set through IsQuadraticSubMesh() or SetSubShape()
328 * \retval bool - true if it has
330 bool HasSeam() const { return !mySeamShapeIds.empty(); }
333 * \brief Return index of periodic parametric direction of a closed face
334 * \retval int - 1 for U, 2 for V direction
336 int GetPeriodicIndex() const { return myParIndex; }
341 * \brief Select UV on either of 2 pcurves of a seam edge, closest to the given UV
342 * \param uv1 - UV on the seam
343 * \param uv2 - UV within a face
344 * \retval gp_Pnt2d - selected UV
346 gp_Pnt2d GetUVOnSeam( const gp_Pnt2d& uv1, const gp_Pnt2d& uv2 ) const;
354 // Key for creation quadratic faces
355 bool myCreateQuadratic;
357 // special map for using during creation quadratic faces
358 NLinkNodeMap myNLinkNodeMap;
360 std::set< int > mySeamShapeIds;
361 double myPar1, myPar2; // bounds of a closed periodic surface
362 int myParIndex; // bounds' index (1-U, 2-V)
363 TopoDS_Shape myShape;