]> SALOME platform Git repositories - modules/smesh.git/blob - src/SMESH/SMESH_MesherHelper.hxx
Salome HOME
9e522d47ec80776c8539998d06bd52063365d594
[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/
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_Mesh.hxx>
30 #include <TopoDS_Shape.hxx>
31 #include <SMDS_MeshNode.hxx>
32 #include <TopoDS_Face.hxx>
33 #include <gp_Pnt2d.hxx>
34 #include <SMDS_QuadraticEdge.hxx>
35
36 #include <map>
37
38 typedef pair<const SMDS_MeshNode*, const SMDS_MeshNode*> NLink;
39 typedef map<NLink, const SMDS_MeshNode*> NLinkNodeMap;
40 typedef map<NLink, const SMDS_MeshNode*>::iterator ItNLinkNode;
41
42 /*!
43  * \brief It helps meshers to add elements
44  *
45  * It allow meshers not to care about creation of medium nodes
46  * when filling a quadratic mesh. Helper does it itself.
47  * It defines degree of elements to create when IsQuadraticSubMesh()
48  * is called.
49  */
50
51 class SMESH_MesherHelper
52 {
53  public:
54   // ---------- PUBLIC METHODS ----------
55
56   /// Empty constructor
57   SMESH_MesherHelper(SMESH_Mesh& theMesh)
58     { myMesh=(void *)&theMesh; myCreateQuadratic = false; }
59
60   SMESH_Mesh* GetMesh() const
61     { return (SMESH_Mesh*)myMesh; }
62     
63   /// Copy constructor
64   //Standard_EXPORT SMESH_MesherHelper (const SMESH_MesherHelper& theOther);
65
66   /// Destructor
67   //Standard_EXPORT virtual ~SMESH_MesherHelper ();
68
69   /**
70    * Check submesh for given shape
71    * Check if all elements on this shape
72    * are quadratic, if yes => set true to myCreateQuadratic 
73    * (default value is false). Also fill myNLinkNodeMap
74    * Returns myCreateQuadratic
75    */
76   bool IsQuadraticSubMesh(const TopoDS_Shape& theShape);
77
78   /*!
79    * \brief Returns true if given node is medium
80     * \param n - node to check
81     * \param typeToCheck - type of elements containing the node to ask about node status
82     * \retval bool - check result
83    */
84   static bool IsMedium(const SMDS_MeshNode*      node,
85                        const SMDSAbs_ElementType typeToCheck = SMDSAbs_All);
86
87   /**
88    * Auxilary function for filling myNLinkNodeMap
89    */
90   void AddNLinkNode(const SMDS_MeshNode* n1,
91                     const SMDS_MeshNode* n2,
92                     const SMDS_MeshNode* n12);
93
94   /**
95    * Auxilary function for filling myNLinkNodeMap
96    */
97   void AddNLinkNodeMap(const NLinkNodeMap& aMap)
98     { myNLinkNodeMap.insert(aMap.begin(), aMap.end()); }
99
100   /**
101    * Returns myNLinkNodeMap
102    */
103   const NLinkNodeMap& GetNLinkNodeMap() { return myNLinkNodeMap; }
104
105   /*!
106    * \brief Return node UV on face
107     * \param F - the face
108     * \param n - the node
109     * \param n2 - a medium node will be placed between n and n2
110     * \retval gp_XY - resulting UV
111    * 
112    * Auxilary function called form GetMediumNode()
113    */
114   gp_XY GetNodeUV(const TopoDS_Face&   F,
115                   const SMDS_MeshNode* n,
116                   const SMDS_MeshNode* n2=0);
117
118   /*!
119    * \brief Return  U on edge
120     * \param F - the edge
121     * \param n - the node
122     * \retval double - resulting U
123    * 
124    * Auxilary function called from GetMediumNode()
125    */
126   double GetNodeU(const TopoDS_Edge&  E,
127                   const SMDS_MeshNode* n);
128
129
130   /**
131    * Special function for search or creation medium node
132    */
133   const SMDS_MeshNode* GetMediumNode(const SMDS_MeshNode* n1,
134                                      const SMDS_MeshNode* n2,
135                                      const bool force3d);
136
137   /**
138    * Special function for creation quadratic edge
139    */
140   SMDS_QuadraticEdge* AddQuadraticEdge(const SMDS_MeshNode* n1,
141                                        const SMDS_MeshNode* n2,
142                                        const int id = 0, 
143                                        const bool force3d = true);
144
145   /**
146    * Special function for creation quadratic triangle
147    */
148   SMDS_MeshFace* AddFace(const SMDS_MeshNode* n1,
149                          const SMDS_MeshNode* n2,
150                          const SMDS_MeshNode* n3,
151                          const int id=0, 
152                          const bool force3d = false);
153
154   /**
155    * Special function for creation quadratic quadrangle
156    */
157   SMDS_MeshFace* AddFace(const SMDS_MeshNode* n1,
158                          const SMDS_MeshNode* n2,
159                          const SMDS_MeshNode* n3,
160                          const SMDS_MeshNode* n4,
161                          const int id = 0,
162                          const bool force3d = false);
163
164   /**
165    * Special function for creation quadratic tetraahedron
166    */
167   SMDS_MeshVolume* AddVolume(const SMDS_MeshNode* n1,
168                              const SMDS_MeshNode* n2,
169                              const SMDS_MeshNode* n3,
170                              const SMDS_MeshNode* n4,
171                              const int id = 0,
172                              const bool force3d = true);
173
174   /**
175    * Special function for creation quadratic pentahedron
176    */
177   SMDS_MeshVolume* AddVolume(const SMDS_MeshNode* n1,
178                              const SMDS_MeshNode* n2,
179                              const SMDS_MeshNode* n3,
180                              const SMDS_MeshNode* n4,
181                              const SMDS_MeshNode* n5,
182                              const SMDS_MeshNode* n6,
183                              const int id = 0, 
184                              const bool force3d = true);
185
186   /**
187    * Special function for creation quadratic hexahedron
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 SMDS_MeshNode* n7,
196                              const SMDS_MeshNode* n8,
197                              const int id = 0, 
198                              bool force3d = true);
199
200   
201   void SetKeyIsQuadratic(const bool theKey)
202     {myCreateQuadratic = theKey;};
203
204   void SetSubShape(const TopoDS_Shape& subShape);
205
206  protected:
207
208   /*!
209    * \brief Select UV on either of 2 pcurves of a seam edge, closest to the given UV
210     * \param uv1 - UV on the seam
211     * \param uv2 - UV within a face
212     * \retval gp_Pnt2d - selected UV
213    */
214   gp_Pnt2d GetUVOnSeam( const gp_Pnt2d& uv1, const gp_Pnt2d& uv2 ) const;
215
216  private:
217
218   void* myMesh;
219
220   int myShapeID;
221
222   // Key for creation quadratic faces
223   bool myCreateQuadratic;
224
225   // special map for using during creation quadratic faces
226   NLinkNodeMap myNLinkNodeMap;
227
228   std::set< int > mySeamShapeIds;
229   double          myPar1, myPar2; // bounds of a closed periodic surface
230   int             myParIndex;     // bounds' index (1-U, 2-V)
231   TopoDS_Shape    myShape;
232
233 };
234
235
236 #endif