1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File: SMESH_MesherHelper.hxx
23 // Created: 15.02.06 14:48:09
24 // Author: Sergey KUUL
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 std::pair<const SMDS_MeshNode*, const SMDS_MeshNode*> NLink;
41 typedef std::map<NLink, const SMDS_MeshNode*> NLinkNodeMap;
42 typedef std::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 typedef std::vector<const SMDS_MeshNode* > TNodeColumn;
54 typedef std::map< double, TNodeColumn > TParam2ColumnMap;
56 class SMESH_EXPORT SMESH_MesherHelper
59 // ---------- PUBLIC UTILITIES ----------
62 * \brief Returns true if given node is medium
63 * \param n - node to check
64 * \param typeToCheck - type of elements containing the node to ask about node status
65 * \retval bool - check result
67 static bool IsMedium(const SMDS_MeshNode* node,
68 const SMDSAbs_ElementType typeToCheck = SMDSAbs_All);
71 * \brief Load nodes bound to face into a map of node columns
72 * \param theParam2ColumnMap - map of node columns to fill
73 * \param theFace - the face on which nodes are searched for
74 * \param theBaseEdge - the edge nodes of which are columns' bases
75 * \param theMesh - the mesh containing nodes
76 * \retval bool - false if something is wrong
78 * The key of the map is a normalized parameter of each
79 * base node on theBaseEdge.
80 * This method works in supposition that nodes on the face
81 * forms a rectangular grid and elements can be quardrangles or triangles
83 static bool LoadNodeColumns(TParam2ColumnMap & theParam2ColumnMap,
84 const TopoDS_Face& theFace,
85 const TopoDS_Edge& theBaseEdge,
86 SMESHDS_Mesh* theMesh);
88 * \brief Return support shape of a node
89 * \param node - the node
90 * \param meshDS - mesh DS
91 * \retval TopoDS_Shape - found support shape
93 static const TopoDS_Shape& GetSubShapeByNode(const SMDS_MeshNode* node,
95 { return meshDS->IndexToShape( node->GetPosition()->GetShapeId() ); }
98 * \brief Return a valid node index, fixing the given one if necessary
99 * \param ind - node index
100 * \param nbNodes - total nb of nodes
101 * \retval int - valid node index
103 static int WrapIndex(const int ind, const int nbNodes) {
104 if ( ind < 0 ) return nbNodes + ind % nbNodes;
105 if ( ind >= nbNodes ) return ind % nbNodes;
110 * \brief Return number of unique ancestors of the shape
112 static int NbAncestors(const TopoDS_Shape& shape,
113 const SMESH_Mesh& mesh,
114 TopAbs_ShapeEnum ancestorType=TopAbs_SHAPE);
117 // ---------- PUBLIC INSTANCE METHODS ----------
120 SMESH_MesherHelper(SMESH_Mesh& theMesh);
122 SMESH_Mesh* GetMesh() const { return myMesh; }
124 SMESHDS_Mesh* GetMeshDS() const { return GetMesh()->GetMeshDS(); }
127 * Check submesh for given shape: if all elements on this shape are quadratic,
128 * quadratic elements will be created. Also fill myNLinkNodeMap
130 bool IsQuadraticSubMesh(const TopoDS_Shape& theShape);
132 * \brief Set order of elements to create without calling IsQuadraticSubMesh()
134 void SetIsQuadratic(const bool theBuildQuadratic)
135 { myCreateQuadratic = theBuildQuadratic; }
137 * \brief Return myCreateQuadratic flag
139 bool GetIsQuadratic() const { return myCreateQuadratic; }
142 * \brief To set created elements on the shape set by IsQuadraticSubMesh()
143 * or the next methods. By defaul elements are set on the shape if
144 * a mesh has no shape to be meshed
146 void SetElementsOnShape(bool toSet) { mySetElemOnShape = toSet; }
149 * \brief Set shape to make elements on without calling IsQuadraticSubMesh()
151 void SetSubShape(const int subShapeID);//!==SMESHDS_Mesh::ShapeToIndex(shape)
152 void SetSubShape(const TopoDS_Shape& subShape);
154 * \brief Return ID of the shape set by IsQuadraticSubMesh() or SetSubShape()
155 * \retval int - shape index in SMESHDS
157 int GetSubShapeID() const { return myShapeID; }
159 * \brief Return the shape set by IsQuadraticSubMesh() or SetSubShape()
161 TopoDS_Shape GetSubShape() const { return myShape; }
166 SMDS_MeshNode* AddNode(double x, double y, double z, int ID = 0);
168 * Creates quadratic or linear edge
170 SMDS_MeshEdge* AddEdge(const SMDS_MeshNode* n1,
171 const SMDS_MeshNode* n2,
173 const bool force3d = true);
175 * Creates quadratic or linear triangle
177 SMDS_MeshFace* AddFace(const SMDS_MeshNode* n1,
178 const SMDS_MeshNode* n2,
179 const SMDS_MeshNode* n3,
181 const bool force3d = false);
183 * Creates quadratic or linear quadrangle
185 SMDS_MeshFace* AddFace(const SMDS_MeshNode* n1,
186 const SMDS_MeshNode* n2,
187 const SMDS_MeshNode* n3,
188 const SMDS_MeshNode* n4,
190 const bool force3d = false);
192 * Creates quadratic or linear tetraahedron
194 SMDS_MeshVolume* AddVolume(const SMDS_MeshNode* n1,
195 const SMDS_MeshNode* n2,
196 const SMDS_MeshNode* n3,
197 const SMDS_MeshNode* n4,
199 const bool force3d = true);
201 * Creates quadratic or linear pyramid
203 SMDS_MeshVolume* AddVolume(const SMDS_MeshNode* n1,
204 const SMDS_MeshNode* n2,
205 const SMDS_MeshNode* n3,
206 const SMDS_MeshNode* n4,
207 const SMDS_MeshNode* n5,
209 const bool force3d = true);
211 * Creates quadratic or linear pentahedron
213 SMDS_MeshVolume* AddVolume(const SMDS_MeshNode* n1,
214 const SMDS_MeshNode* n2,
215 const SMDS_MeshNode* n3,
216 const SMDS_MeshNode* n4,
217 const SMDS_MeshNode* n5,
218 const SMDS_MeshNode* n6,
220 const bool force3d = true);
222 * Creates quadratic or linear hexahedron
224 SMDS_MeshVolume* AddVolume(const SMDS_MeshNode* n1,
225 const SMDS_MeshNode* n2,
226 const SMDS_MeshNode* n3,
227 const SMDS_MeshNode* n4,
228 const SMDS_MeshNode* n5,
229 const SMDS_MeshNode* n6,
230 const SMDS_MeshNode* n7,
231 const SMDS_MeshNode* n8,
233 bool force3d = true);
235 * \brief Return U of the given node on the edge
237 double GetNodeU(const TopoDS_Edge& theEdge,
238 const SMDS_MeshNode* theNode);
240 * \brief Return node UV on face
241 * \param inFaceNode - a node of element being created located inside a face
243 gp_XY GetNodeUV(const TopoDS_Face& F,
244 const SMDS_MeshNode* n,
245 const SMDS_MeshNode* inFaceNode=0) const;
247 * \brief Check if inFaceNode argument is necessary for call GetNodeUV(F,..)
248 * \retval bool - return true if the face is periodic
250 * if F is Null, answer about subshape set through IsQuadraticSubMesh() or
253 bool GetNodeUVneedInFaceNode(const TopoDS_Face& F = TopoDS_Face()) const;
256 * \brief Check if shape is a degenerated edge or it's vertex
257 * \param subShape - edge or vertex index in SMESHDS
258 * \retval bool - true if subShape is a degenerated shape
260 * It works only if IsQuadraticSubMesh() or SetSubShape() has been called
262 bool IsDegenShape(const int subShape) const
263 { return myDegenShapeIds.find( subShape ) != myDegenShapeIds.end(); }
265 * \brief Check if shape is a seam edge or it's vertex
266 * \param subShape - edge or vertex index in SMESHDS
267 * \retval bool - true if subShape is a seam shape
269 * It works only if IsQuadraticSubMesh() or SetSubShape() has been called.
270 * Seam shape has two 2D alternative represenations on the face
272 bool IsSeamShape(const int subShape) const
273 { return mySeamShapeIds.find( subShape ) != mySeamShapeIds.end(); }
275 * \brief Check if shape is a seam edge or it's vertex
276 * \param subShape - edge or vertex
277 * \retval bool - true if subShape is a seam shape
279 * It works only if IsQuadraticSubMesh() or SetSubShape() has been called.
280 * Seam shape has two 2D alternative represenations on the face
282 bool IsSeamShape(const TopoDS_Shape& subShape) const
283 { return IsSeamShape( GetMeshDS()->ShapeToIndex( subShape )); }
285 * \brief Return true if an edge or a vertex encounters twice in face wire
286 * \param subShape - Id of edge or vertex
288 bool IsRealSeam(const int subShape) const
289 { return mySeamShapeIds.find( -subShape ) != mySeamShapeIds.end(); }
291 * \brief Return true if an edge or a vertex encounters twice in face wire
292 * \param subShape - edge or vertex
294 bool IsRealSeam(const TopoDS_Shape& subShape) const
295 { return IsRealSeam( GetMeshDS()->ShapeToIndex( subShape)); }
297 * \brief Check if the shape set through IsQuadraticSubMesh() or SetSubShape()
299 * \retval bool - true if it has
301 bool HasSeam() const { return !mySeamShapeIds.empty(); }
303 * \brief Return index of periodic parametric direction of a closed face
304 * \retval int - 1 for U, 2 for V direction
306 int GetPeriodicIndex() const { return myParIndex; }
308 * \brief Return an alternative parameter for a node on seam
310 double GetOtherParam(const double param) const;
313 * Special function for search or creation medium node
315 const SMDS_MeshNode* GetMediumNode(const SMDS_MeshNode* n1,
316 const SMDS_MeshNode* n2,
319 * Auxilary function for filling myNLinkNodeMap
321 void AddNLinkNode(const SMDS_MeshNode* n1,
322 const SMDS_MeshNode* n2,
323 const SMDS_MeshNode* n12);
325 * Auxilary function for filling myNLinkNodeMap
327 void AddNLinkNodeMap(const NLinkNodeMap& aMap)
328 { myNLinkNodeMap.insert(aMap.begin(), aMap.end()); }
331 * Returns myNLinkNodeMap
333 const NLinkNodeMap& GetNLinkNodeMap() const { return myNLinkNodeMap; }
336 * Check mesh without geometry for: if all elements on this shape are quadratic,
337 * quadratic elements will be created.
338 * Used then generated 3D mesh without geometry.
340 enum MType{ LINEAR, QUADRATIC, COMP };
341 MType IsQuadraticMesh();
346 * \brief Select UV on either of 2 pcurves of a seam edge, closest to the given UV
347 * \param uv1 - UV on the seam
348 * \param uv2 - UV within a face
349 * \retval gp_Pnt2d - selected UV
351 gp_Pnt2d GetUVOnSeam( const gp_Pnt2d& uv1, const gp_Pnt2d& uv2 ) const;
355 // Forbiden copy constructor
356 SMESH_MesherHelper (const SMESH_MesherHelper& theOther) {};
358 // special map for using during creation of quadratic elements
359 NLinkNodeMap myNLinkNodeMap;
361 std::set< int > myDegenShapeIds;
362 std::set< int > mySeamShapeIds;
363 double myPar1, myPar2; // bounds of a closed periodic surface
364 int myParIndex; // bounds' index (1-U, 2-V)
366 TopoDS_Shape myShape;
370 // to create quadratic elements
371 bool myCreateQuadratic;
372 bool mySetElemOnShape;