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 // ---------- PUBLIC INSTANCE METHODS ----------
113 SMESH_MesherHelper(SMESH_Mesh& theMesh);
115 SMESH_Mesh* GetMesh() const { return myMesh; }
117 SMESHDS_Mesh* GetMeshDS() const { return GetMesh()->GetMeshDS(); }
120 * Check submesh for given shape: if all elements on this shape are quadratic,
121 * quadratic elements will be created. Also fill myNLinkNodeMap
123 bool IsQuadraticSubMesh(const TopoDS_Shape& theShape);
125 * \brief Set order of elements to create without calling IsQuadraticSubMesh()
127 void SetIsQuadratic(const bool theBuildQuadratic)
128 { myCreateQuadratic = theBuildQuadratic; }
130 * \brief Return myCreateQuadratic flag
132 bool GetIsQuadratic() const { return myCreateQuadratic; }
135 * \brief To set created elements on the shape set by IsQuadraticSubMesh()
136 * or the next methods. By defaul elements are set on the shape if
137 * a mesh has no shape to be meshed
139 void SetElementsOnShape(bool toSet) { mySetElemOnShape = toSet; }
142 * \brief Set shape to make elements on without calling IsQuadraticSubMesh()
144 void SetSubShape(const int subShapeID);//!==SMESHDS_Mesh::ShapeToIndex(shape)
145 void SetSubShape(const TopoDS_Shape& subShape);
147 * \brief Return ID of the shape set by IsQuadraticSubMesh() or SetSubShape()
148 * \retval int - shape index in SMESHDS
150 int GetSubShapeID() const { return myShapeID; }
152 * \brief Return the shape set by IsQuadraticSubMesh() or SetSubShape()
154 TopoDS_Shape GetSubShape() const { return myShape; }
159 SMDS_MeshNode* AddNode(double x, double y, double z, int ID = 0);
161 * Creates quadratic or linear edge
163 SMDS_MeshEdge* AddEdge(const SMDS_MeshNode* n1,
164 const SMDS_MeshNode* n2,
166 const bool force3d = true);
168 * Creates quadratic or linear triangle
170 SMDS_MeshFace* AddFace(const SMDS_MeshNode* n1,
171 const SMDS_MeshNode* n2,
172 const SMDS_MeshNode* n3,
174 const bool force3d = false);
176 * Creates quadratic or linear quadrangle
178 SMDS_MeshFace* AddFace(const SMDS_MeshNode* n1,
179 const SMDS_MeshNode* n2,
180 const SMDS_MeshNode* n3,
181 const SMDS_MeshNode* n4,
183 const bool force3d = false);
185 * Creates quadratic or linear tetraahedron
187 SMDS_MeshVolume* AddVolume(const SMDS_MeshNode* n1,
188 const SMDS_MeshNode* n2,
189 const SMDS_MeshNode* n3,
190 const SMDS_MeshNode* n4,
192 const bool force3d = true);
194 * Creates quadratic or linear pyramid
196 SMDS_MeshVolume* AddVolume(const SMDS_MeshNode* n1,
197 const SMDS_MeshNode* n2,
198 const SMDS_MeshNode* n3,
199 const SMDS_MeshNode* n4,
200 const SMDS_MeshNode* n5,
202 const bool force3d = true);
204 * Creates quadratic or linear pentahedron
206 SMDS_MeshVolume* AddVolume(const SMDS_MeshNode* n1,
207 const SMDS_MeshNode* n2,
208 const SMDS_MeshNode* n3,
209 const SMDS_MeshNode* n4,
210 const SMDS_MeshNode* n5,
211 const SMDS_MeshNode* n6,
213 const bool force3d = true);
215 * Creates quadratic or linear hexahedron
217 SMDS_MeshVolume* AddVolume(const SMDS_MeshNode* n1,
218 const SMDS_MeshNode* n2,
219 const SMDS_MeshNode* n3,
220 const SMDS_MeshNode* n4,
221 const SMDS_MeshNode* n5,
222 const SMDS_MeshNode* n6,
223 const SMDS_MeshNode* n7,
224 const SMDS_MeshNode* n8,
226 bool force3d = true);
228 * \brief Return U of the given node on the edge
230 double GetNodeU(const TopoDS_Edge& theEdge,
231 const SMDS_MeshNode* theNode);
233 * \brief Return node UV on face
234 * \param inFaceNode - a node of element being created located inside a face
236 gp_XY GetNodeUV(const TopoDS_Face& F,
237 const SMDS_MeshNode* n,
238 const SMDS_MeshNode* inFaceNode=0) const;
240 * \brief Check if inFaceNode argument is necessary for call GetNodeUV(F,..)
241 * \retval bool - return true if the face is periodic
243 * if F is Null, answer about subshape set through IsQuadraticSubMesh() or
246 bool GetNodeUVneedInFaceNode(const TopoDS_Face& F = TopoDS_Face()) const;
249 * \brief Check if shape is a degenerated edge or it's vertex
250 * \param subShape - edge or vertex index in SMESHDS
251 * \retval bool - true if subShape is a degenerated shape
253 * It works only if IsQuadraticSubMesh() or SetSubShape() has been called
255 bool IsDegenShape(const int subShape) const
256 { return myDegenShapeIds.find( subShape ) != myDegenShapeIds.end(); }
258 * \brief Check if shape is a seam edge or it's vertex
259 * \param subShape - edge or vertex index in SMESHDS
260 * \retval bool - true if subShape is a seam shape
262 * It works only if IsQuadraticSubMesh() or SetSubShape() has been called.
263 * Seam shape has two 2D alternative represenations on the face
265 bool IsSeamShape(const int subShape) const
266 { return mySeamShapeIds.find( subShape ) != mySeamShapeIds.end(); }
268 * \brief Check if shape is a seam edge or it's vertex
269 * \param subShape - edge or vertex
270 * \retval bool - true if subShape is a seam shape
272 * It works only if IsQuadraticSubMesh() or SetSubShape() has been called.
273 * Seam shape has two 2D alternative represenations on the face
275 bool IsSeamShape(const TopoDS_Shape& subShape) const
276 { return IsSeamShape( GetMeshDS()->ShapeToIndex( subShape )); }
278 * \brief Return true if an edge or a vertex encounters twice in face wire
279 * \param subShape - Id of edge or vertex
281 bool IsRealSeam(const int subShape) const
282 { return mySeamShapeIds.find( -subShape ) != mySeamShapeIds.end(); }
284 * \brief Return true if an edge or a vertex encounters twice in face wire
285 * \param subShape - edge or vertex
287 bool IsRealSeam(const TopoDS_Shape& subShape) const
288 { return IsRealSeam( GetMeshDS()->ShapeToIndex( subShape)); }
290 * \brief Check if the shape set through IsQuadraticSubMesh() or SetSubShape()
292 * \retval bool - true if it has
294 bool HasSeam() const { return !mySeamShapeIds.empty(); }
296 * \brief Return index of periodic parametric direction of a closed face
297 * \retval int - 1 for U, 2 for V direction
299 int GetPeriodicIndex() const { return myParIndex; }
301 * \brief Return an alternative parameter for a node on seam
303 double GetOtherParam(const double param) const;
306 * Special function for search or creation medium node
308 const SMDS_MeshNode* GetMediumNode(const SMDS_MeshNode* n1,
309 const SMDS_MeshNode* n2,
312 * Auxilary function for filling myNLinkNodeMap
314 void AddNLinkNode(const SMDS_MeshNode* n1,
315 const SMDS_MeshNode* n2,
316 const SMDS_MeshNode* n12);
318 * Auxilary function for filling myNLinkNodeMap
320 void AddNLinkNodeMap(const NLinkNodeMap& aMap)
321 { myNLinkNodeMap.insert(aMap.begin(), aMap.end()); }
324 * Returns myNLinkNodeMap
326 const NLinkNodeMap& GetNLinkNodeMap() const { return myNLinkNodeMap; }
329 * Check mesh without geometry for: if all elements on this shape are quadratic,
330 * quadratic elements will be created.
331 * Used then generated 3D mesh without geometry.
333 enum MType{ LINEAR, QUADRATIC, COMP };
334 MType IsQuadraticMesh();
339 * \brief Select UV on either of 2 pcurves of a seam edge, closest to the given UV
340 * \param uv1 - UV on the seam
341 * \param uv2 - UV within a face
342 * \retval gp_Pnt2d - selected UV
344 gp_Pnt2d GetUVOnSeam( const gp_Pnt2d& uv1, const gp_Pnt2d& uv2 ) const;
348 // Forbiden copy constructor
349 SMESH_MesherHelper (const SMESH_MesherHelper& theOther) {};
351 // special map for using during creation of quadratic elements
352 NLinkNodeMap myNLinkNodeMap;
354 std::set< int > myDegenShapeIds;
355 std::set< int > mySeamShapeIds;
356 double myPar1, myPar2; // bounds of a closed periodic surface
357 int myParIndex; // bounds' index (1-U, 2-V)
359 TopoDS_Shape myShape;
363 // to create quadratic elements
364 bool myCreateQuadratic;
365 bool mySetElemOnShape;