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 Load nodes bound to face into a map of node columns
62 * \param theParam2ColumnMap - map of node columns to fill
63 * \param theFace - the face on which nodes are searched for
64 * \param theBaseEdge - the edge nodes of which are columns' bases
65 * \param theMesh - the mesh containing nodes
66 * \retval bool - false if something is wrong
68 * The key of the map is a normalized parameter of each
69 * base node on theBaseEdge.
70 * This method works in supposition that nodes on the face
71 * forms a rectangular grid and elements can be quardrangles or triangles
73 static bool LoadNodeColumns(TParam2ColumnMap & theParam2ColumnMap,
74 const TopoDS_Face& theFace,
75 const TopoDS_Edge& theBaseEdge,
76 SMESHDS_Mesh* theMesh);
78 * \brief Return support shape of a node
79 * \param node - the node
80 * \param meshDS - mesh DS
81 * \retval TopoDS_Shape - found support shape
83 static const TopoDS_Shape& GetSubShapeByNode(const SMDS_MeshNode* node,
85 { return meshDS->IndexToShape( node->GetPosition()->GetShapeId() ); }
88 * \brief Return a valid node index, fixing the given one if necessary
89 * \param ind - node index
90 * \param nbNodes - total nb of nodes
91 * \retval int - valid node index
93 static int WrapIndex(const int ind, const int nbNodes) {
94 if ( ind < 0 ) return nbNodes + ind % nbNodes;
95 if ( ind >= nbNodes ) return ind % nbNodes;
100 // ---------- PUBLIC METHODS ----------
102 /// Empty constructor
103 SMESH_MesherHelper(SMESH_Mesh& theMesh)
104 { myMesh=(void *)&theMesh; myCreateQuadratic = false; myShapeID=-1;}
106 SMESH_Mesh* GetMesh() const { return (SMESH_Mesh*)myMesh; }
108 SMESHDS_Mesh* GetMeshDS() const { return GetMesh()->GetMeshDS(); }
111 //Standard_EXPORT SMESH_MesherHelper (const SMESH_MesherHelper& theOther);
114 //Standard_EXPORT virtual ~SMESH_MesherHelper ();
117 * Check submesh for given shape
118 * Check if all elements on this shape
119 * are quadratic, if yes => set true to myCreateQuadratic
120 * (default value is false). Also fill myNLinkNodeMap
121 * Returns myCreateQuadratic
123 bool IsQuadraticSubMesh(const TopoDS_Shape& theShape);
126 * \brief Returns true if given node is medium
127 * \param n - node to check
128 * \param typeToCheck - type of elements containing the node to ask about node status
129 * \retval bool - check result
131 static bool IsMedium(const SMDS_MeshNode* node,
132 const SMDSAbs_ElementType typeToCheck = SMDSAbs_All);
135 * Auxilary function for filling myNLinkNodeMap
137 void AddNLinkNode(const SMDS_MeshNode* n1,
138 const SMDS_MeshNode* n2,
139 const SMDS_MeshNode* n12);
142 * Auxilary function for filling myNLinkNodeMap
144 void AddNLinkNodeMap(const NLinkNodeMap& aMap)
145 { myNLinkNodeMap.insert(aMap.begin(), aMap.end()); }
148 * Returns myNLinkNodeMap
150 const NLinkNodeMap& GetNLinkNodeMap() { return myNLinkNodeMap; }
153 * \brief Return node UV on face
154 * \param F - the face
155 * \param n - the node
156 * \param inFaceNode - a node of element being created located inside a face
157 * \retval gp_XY - resulting UV
159 * Auxilary function called form GetMediumNode()
161 gp_XY GetNodeUV(const TopoDS_Face& F,
162 const SMDS_MeshNode* n,
163 const SMDS_MeshNode* inFaceNode=0) const;
166 * \brief Check if inFaceNode argument is necessary for call GetNodeUV(F,..)
167 * \param F - the face
168 * \retval bool - return true if the face is periodic
170 * if F is Null, answer about subshape set through IsQuadraticSubMesh() or
173 bool GetNodeUVneedInFaceNode(const TopoDS_Face& F = TopoDS_Face()) const;
176 * \brief Return U on edge
177 * \param F - the edge
178 * \param n - the node
179 * \retval double - resulting U
181 * Auxilary function called from GetMediumNode()
183 double GetNodeU(const TopoDS_Edge& E,
184 const SMDS_MeshNode* n);
188 * Special function for search or creation medium node
190 const SMDS_MeshNode* GetMediumNode(const SMDS_MeshNode* n1,
191 const SMDS_MeshNode* n2,
195 * Special function for creation quadratic edge
197 SMDS_QuadraticEdge* AddQuadraticEdge(const SMDS_MeshNode* n1,
198 const SMDS_MeshNode* n2,
200 const bool force3d = true);
203 * Special function for creation quadratic triangle
205 SMDS_MeshFace* AddFace(const SMDS_MeshNode* n1,
206 const SMDS_MeshNode* n2,
207 const SMDS_MeshNode* n3,
209 const bool force3d = false);
212 * Special function for creation quadratic quadrangle
214 SMDS_MeshFace* AddFace(const SMDS_MeshNode* n1,
215 const SMDS_MeshNode* n2,
216 const SMDS_MeshNode* n3,
217 const SMDS_MeshNode* n4,
219 const bool force3d = false);
222 * Special function for creation quadratic tetraahedron
224 SMDS_MeshVolume* AddVolume(const SMDS_MeshNode* n1,
225 const SMDS_MeshNode* n2,
226 const SMDS_MeshNode* n3,
227 const SMDS_MeshNode* n4,
229 const bool force3d = true);
233 * Special function for creation quadratic pyramid
235 SMDS_MeshVolume* AddVolume(const SMDS_MeshNode* n1,
236 const SMDS_MeshNode* n2,
237 const SMDS_MeshNode* n3,
238 const SMDS_MeshNode* n4,
239 const SMDS_MeshNode* n5,
241 const bool force3d = true);
244 * Special function for creation quadratic pentahedron
246 SMDS_MeshVolume* AddVolume(const SMDS_MeshNode* n1,
247 const SMDS_MeshNode* n2,
248 const SMDS_MeshNode* n3,
249 const SMDS_MeshNode* n4,
250 const SMDS_MeshNode* n5,
251 const SMDS_MeshNode* n6,
253 const bool force3d = true);
256 * Special function for creation quadratic hexahedron
258 SMDS_MeshVolume* AddVolume(const SMDS_MeshNode* n1,
259 const SMDS_MeshNode* n2,
260 const SMDS_MeshNode* n3,
261 const SMDS_MeshNode* n4,
262 const SMDS_MeshNode* n5,
263 const SMDS_MeshNode* n6,
264 const SMDS_MeshNode* n7,
265 const SMDS_MeshNode* n8,
267 bool force3d = true);
271 * \brief Set order of elements to create
272 * \param theBuildQuadratic - to build quadratic or not
274 * To be used for quadratic elements creation without preceding
275 * IsQuadraticSubMesh() or AddQuadraticEdge() call
277 void SetKeyIsQuadratic(const bool theBuildQuadratic)
278 { myCreateQuadratic = theBuildQuadratic; }
281 * \brief Return myCreateQuadratic flag
282 * \retval bool - myCreateQuadratic value
284 bool GetIsQuadratic() const { return myCreateQuadratic; }
287 * \brief Set shape to make elements on
288 * \param subShape, subShapeID - shape or its ID (==SMESHDS_Mesh::ShapeToIndex(shape))
290 void SetSubShape(const int subShapeID);
291 void SetSubShape(const TopoDS_Shape& subShape);
294 * \brief Return shape or its ID, on which created elements are added
295 * \retval int - shape index in SMESHDS
297 * Shape is set by calling either IsQuadraticSubMesh() or SetSubShape()
299 int GetSubShapeID() const { return myShapeID; }
301 * \brief Return shape or its ID, on which created elements are added
302 * \retval TopoDS_Shape - shape
304 * Shape is set by calling either IsQuadraticSubMesh() or SetSubShape()
306 TopoDS_Shape GetSubShape() const { return myShape; }
309 * \brief Check if shape is a seam edge or it's vertex
310 * \param subShape - edge or vertex index in SMESHDS
311 * \retval bool - true if subShape is a seam shape
313 * It works only if IsQuadraticSubMesh() or SetSubShape() has been called
315 bool IsSeamShape(const int subShape) const
316 { return mySeamShapeIds.find( subShape ) != mySeamShapeIds.end(); }
318 * \brief Check if shape is a seam edge or it's vertex
319 * \param subShape - edge or vertex
320 * \retval bool - true if subShape is a seam shape
322 * It works only if IsQuadraticSubMesh() or SetSubShape() has been called
324 bool IsSeamShape(const TopoDS_Shape& subShape) const
325 { return IsSeamShape( GetMeshDS()->ShapeToIndex( subShape )); }
328 * \brief Check if the shape set through IsQuadraticSubMesh() or SetSubShape()
330 * \retval bool - true if it has
332 bool HasSeam() const { return !mySeamShapeIds.empty(); }
335 * \brief Return index of periodic parametric direction of a closed face
336 * \retval int - 1 for U, 2 for V direction
338 int GetPeriodicIndex() const { return myParIndex; }
343 * \brief Select UV on either of 2 pcurves of a seam edge, closest to the given UV
344 * \param uv1 - UV on the seam
345 * \param uv2 - UV within a face
346 * \retval gp_Pnt2d - selected UV
348 gp_Pnt2d GetUVOnSeam( const gp_Pnt2d& uv1, const gp_Pnt2d& uv2 ) const;
356 // Key for creation quadratic faces
357 bool myCreateQuadratic;
359 // special map for using during creation quadratic faces
360 NLinkNodeMap myNLinkNodeMap;
362 std::set< int > mySeamShapeIds;
363 double myPar1, myPar2; // bounds of a closed periodic surface
364 int myParIndex; // bounds' index (1-U, 2-V)
365 TopoDS_Shape myShape;