Salome HOME
BUG SWP13024
[modules/smesh.git] / src / SMESH / SMESH_MesherHelper.hxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 //
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.
8 //
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.
13 //
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
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 // File:      SMESH_MesherHelper.hxx
21 // Created:   15.02.06 14:48:09
22 // Author:    Sergey KUUL
23 // Copyright: Open CASCADE 2006
24
25
26 #ifndef SMESH_MesherHelper_HeaderFile
27 #define SMESH_MesherHelper_HeaderFile
28
29 #include "SMESH_SMESH.hxx"
30
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>
37
38 #include <map>
39
40 typedef pair<const SMDS_MeshNode*, const SMDS_MeshNode*> NLink;
41 typedef map<NLink, const SMDS_MeshNode*> NLinkNodeMap;
42 typedef map<NLink, const SMDS_MeshNode*>::iterator ItNLinkNode;
43
44 /*!
45  * \brief It helps meshers to add elements
46  *
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()
50  * is called.
51  */
52
53 class SMESH_EXPORT SMESH_MesherHelper
54 {
55  public:
56   // ---------- PUBLIC METHODS ----------
57
58   /// Empty constructor
59   SMESH_MesherHelper(SMESH_Mesh& theMesh)
60     { myMesh=(void *)&theMesh; myCreateQuadratic = false; myShapeID=-1;}
61
62   SMESH_Mesh* GetMesh() const
63     { return (SMESH_Mesh*)myMesh; }
64     
65   /// Copy constructor
66   //Standard_EXPORT SMESH_MesherHelper (const SMESH_MesherHelper& theOther);
67
68   /// Destructor
69   //Standard_EXPORT virtual ~SMESH_MesherHelper ();
70
71   /**
72    * Check submesh for given shape
73    * Check if all elements on this shape
74    * are quadratic, if yes => set true to myCreateQuadratic 
75    * (default value is false). Also fill myNLinkNodeMap
76    * Returns myCreateQuadratic
77    */
78   bool IsQuadraticSubMesh(const TopoDS_Shape& theShape);
79
80   /*!
81    * \brief Returns true if given node is medium
82     * \param n - node to check
83     * \param typeToCheck - type of elements containing the node to ask about node status
84     * \retval bool - check result
85    */
86   static bool IsMedium(const SMDS_MeshNode*      node,
87                        const SMDSAbs_ElementType typeToCheck = SMDSAbs_All);
88
89   /**
90    * Auxilary function for filling myNLinkNodeMap
91    */
92   void AddNLinkNode(const SMDS_MeshNode* n1,
93                     const SMDS_MeshNode* n2,
94                     const SMDS_MeshNode* n12);
95
96   /**
97    * Auxilary function for filling myNLinkNodeMap
98    */
99   void AddNLinkNodeMap(const NLinkNodeMap& aMap)
100     { myNLinkNodeMap.insert(aMap.begin(), aMap.end()); }
101
102   /**
103    * Returns myNLinkNodeMap
104    */
105   const NLinkNodeMap& GetNLinkNodeMap() { return myNLinkNodeMap; }
106
107   /*!
108    * \brief Return node UV on face
109     * \param F - the face
110     * \param n - the node
111     * \param inFaceNode - a node of element being created located inside a face
112     * \retval gp_XY - resulting UV
113    * 
114    * Auxilary function called form GetMediumNode()
115    */
116   gp_XY GetNodeUV(const TopoDS_Face&   F,
117                   const SMDS_MeshNode* n,
118                   const SMDS_MeshNode* inFaceNode=0);
119
120   /*!
121    * \brief Check if inFaceNode argument is necessary for call GetNodeUV(F,..)
122     * \param F - the face
123     * \retval bool - return true if the face is periodic
124     *
125     * if F is Null, answer about subshape set through IsQuadraticSubMesh() or
126     * SetSubShape()
127    */
128   bool GetNodeUVneedInFaceNode(const TopoDS_Face& F = TopoDS_Face()) const;
129
130   /*!
131    * \brief Return  U on edge
132     * \param F - the edge
133     * \param n - the node
134     * \retval double - resulting U
135    * 
136    * Auxilary function called from GetMediumNode()
137    */
138   double GetNodeU(const TopoDS_Edge&  E,
139                   const SMDS_MeshNode* n);
140
141
142   /**
143    * Special function for search or creation medium node
144    */
145   const SMDS_MeshNode* GetMediumNode(const SMDS_MeshNode* n1,
146                                      const SMDS_MeshNode* n2,
147                                      const bool force3d);
148
149   /**
150    * Special function for creation quadratic edge
151    */
152   SMDS_QuadraticEdge* AddQuadraticEdge(const SMDS_MeshNode* n1,
153                                        const SMDS_MeshNode* n2,
154                                        const int id = 0, 
155                                        const bool force3d = true);
156
157   /**
158    * Special function for creation quadratic triangle
159    */
160   SMDS_MeshFace* AddFace(const SMDS_MeshNode* n1,
161                          const SMDS_MeshNode* n2,
162                          const SMDS_MeshNode* n3,
163                          const int id=0, 
164                          const bool force3d = false);
165
166   /**
167    * Special function for creation quadratic quadrangle
168    */
169   SMDS_MeshFace* AddFace(const SMDS_MeshNode* n1,
170                          const SMDS_MeshNode* n2,
171                          const SMDS_MeshNode* n3,
172                          const SMDS_MeshNode* n4,
173                          const int id = 0,
174                          const bool force3d = false);
175
176   /**
177    * Special function for creation quadratic tetraahedron
178    */
179   SMDS_MeshVolume* AddVolume(const SMDS_MeshNode* n1,
180                              const SMDS_MeshNode* n2,
181                              const SMDS_MeshNode* n3,
182                              const SMDS_MeshNode* n4,
183                              const int id = 0,
184                              const bool force3d = true);
185
186   /**
187    * Special function for creation quadratic pentahedron
188    */
189   SMDS_MeshVolume* AddVolume(const SMDS_MeshNode* n1,
190                              const SMDS_MeshNode* n2,
191                              const SMDS_MeshNode* n3,
192                              const SMDS_MeshNode* n4,
193                              const SMDS_MeshNode* n5,
194                              const SMDS_MeshNode* n6,
195                              const int id = 0, 
196                              const bool force3d = true);
197
198   /**
199    * Special function for creation quadratic hexahedron
200    */
201   SMDS_MeshVolume* AddVolume(const SMDS_MeshNode* n1,
202                              const SMDS_MeshNode* n2,
203                              const SMDS_MeshNode* n3,
204                              const SMDS_MeshNode* n4,
205                              const SMDS_MeshNode* n5,
206                              const SMDS_MeshNode* n6,
207                              const SMDS_MeshNode* n7,
208                              const SMDS_MeshNode* n8,
209                              const int id = 0, 
210                              bool force3d = true);
211
212   
213   /*!
214    * \brief Set order of elements to create
215     * \param theBuildQuadratic - to build quadratic or not
216    * 
217    * To be used for quadratic elements creation without preceding
218    * IsQuadraticSubMesh() or AddQuadraticEdge() call
219    */
220   void SetKeyIsQuadratic(const bool theBuildQuadratic)
221   { myCreateQuadratic = theBuildQuadratic; }
222
223   /*!
224    * \brief Set shape to make elements on
225     * \param subShape, subShapeID - shape or its ID (==SMESHDS_Mesh::ShapeToIndex(shape))
226    */
227   void SetSubShape(const int           subShapeID);
228   void SetSubShape(const TopoDS_Shape& subShape);
229
230   /*!
231    * \brief Return shape or its ID, on which created elements are added
232     * \retval TopoDS_Shape, int - shape or its ID
233    */
234   int          GetSubShapeID() { return myShapeID; }
235   TopoDS_Shape GetSubShape()   { return myShape; }
236
237  protected:
238
239   /*!
240    * \brief Select UV on either of 2 pcurves of a seam edge, closest to the given UV
241     * \param uv1 - UV on the seam
242     * \param uv2 - UV within a face
243     * \retval gp_Pnt2d - selected UV
244    */
245   gp_Pnt2d GetUVOnSeam( const gp_Pnt2d& uv1, const gp_Pnt2d& uv2 ) const;
246
247  private:
248
249   void* myMesh;
250
251   int myShapeID;
252
253   // Key for creation quadratic faces
254   bool myCreateQuadratic;
255
256   // special map for using during creation quadratic faces
257   NLinkNodeMap myNLinkNodeMap;
258
259   std::set< int > mySeamShapeIds;
260   double          myPar1, myPar2; // bounds of a closed periodic surface
261   int             myParIndex;     // bounds' index (1-U, 2-V)
262   TopoDS_Shape    myShape;
263
264 };
265
266
267 #endif