Salome HOME
Fix bug 12796: Warning missed for the bad file 'test18.med'
[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_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; myShapeID=-1;}
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 inFaceNode - a node of element being created located inside a face
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* inFaceNode=0);
117
118   /*!
119    * \brief Check if inFaceNode argument is necessary for call GetNodeUV(F,..)
120     * \param F - the face
121     * \retval bool - return true if the face is periodic
122     *
123     * if F is Null, answer about subshape set through IsQuadraticSubMesh() or
124     * SetSubShape()
125    */
126   bool GetNodeUVneedInFaceNode(const TopoDS_Face& F = TopoDS_Face()) const;
127
128   /*!
129    * \brief Return  U on edge
130     * \param F - the edge
131     * \param n - the node
132     * \retval double - resulting U
133    * 
134    * Auxilary function called from GetMediumNode()
135    */
136   double GetNodeU(const TopoDS_Edge&  E,
137                   const SMDS_MeshNode* n);
138
139
140   /**
141    * Special function for search or creation medium node
142    */
143   const SMDS_MeshNode* GetMediumNode(const SMDS_MeshNode* n1,
144                                      const SMDS_MeshNode* n2,
145                                      const bool force3d);
146
147   /**
148    * Special function for creation quadratic edge
149    */
150   SMDS_QuadraticEdge* AddQuadraticEdge(const SMDS_MeshNode* n1,
151                                        const SMDS_MeshNode* n2,
152                                        const int id = 0, 
153                                        const bool force3d = true);
154
155   /**
156    * Special function for creation quadratic triangle
157    */
158   SMDS_MeshFace* AddFace(const SMDS_MeshNode* n1,
159                          const SMDS_MeshNode* n2,
160                          const SMDS_MeshNode* n3,
161                          const int id=0, 
162                          const bool force3d = false);
163
164   /**
165    * Special function for creation quadratic quadrangle
166    */
167   SMDS_MeshFace* AddFace(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 = false);
173
174   /**
175    * Special function for creation quadratic tetraahedron
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 int id = 0,
182                              const bool force3d = true);
183
184   /**
185    * Special function for creation quadratic pentahedron
186    */
187   SMDS_MeshVolume* AddVolume(const SMDS_MeshNode* n1,
188                              const SMDS_MeshNode* n2,
189                              const SMDS_MeshNode* n3,
190                              const SMDS_MeshNode* n4,
191                              const SMDS_MeshNode* n5,
192                              const SMDS_MeshNode* n6,
193                              const int id = 0, 
194                              const bool force3d = true);
195
196   /**
197    * Special function for creation quadratic hexahedron
198    */
199   SMDS_MeshVolume* AddVolume(const SMDS_MeshNode* n1,
200                              const SMDS_MeshNode* n2,
201                              const SMDS_MeshNode* n3,
202                              const SMDS_MeshNode* n4,
203                              const SMDS_MeshNode* n5,
204                              const SMDS_MeshNode* n6,
205                              const SMDS_MeshNode* n7,
206                              const SMDS_MeshNode* n8,
207                              const int id = 0, 
208                              bool force3d = true);
209
210   
211   /*!
212    * \brief Set order of elements to create
213     * \param theBuildQuadratic - to build quadratic or not
214    * 
215    * To be used for quadratic elements creation without preceding
216    * IsQuadraticSubMesh() or AddQuadraticEdge() call
217    */
218   void SetKeyIsQuadratic(const bool theBuildQuadratic)
219   { myCreateQuadratic = theBuildQuadratic; }
220
221   /*!
222    * \brief Set shape to make elements on
223     * \param subShape, subShapeID - shape or its ID (==SMESHDS_Mesh::ShapeToIndex(shape))
224    */
225   void SetSubShape(const int           subShapeID);
226   void SetSubShape(const TopoDS_Shape& subShape);
227
228   /*!
229    * \brief Return shape or its ID, on which created elements are added
230     * \retval TopoDS_Shape, int - shape or its ID
231    */
232   int          GetSubShapeID() { return myShapeID; }
233   TopoDS_Shape GetSubShape()   { return myShape; }
234
235  protected:
236
237   /*!
238    * \brief Select UV on either of 2 pcurves of a seam edge, closest to the given UV
239     * \param uv1 - UV on the seam
240     * \param uv2 - UV within a face
241     * \retval gp_Pnt2d - selected UV
242    */
243   gp_Pnt2d GetUVOnSeam( const gp_Pnt2d& uv1, const gp_Pnt2d& uv2 ) const;
244
245  private:
246
247   void* myMesh;
248
249   int myShapeID;
250
251   // Key for creation quadratic faces
252   bool myCreateQuadratic;
253
254   // special map for using during creation quadratic faces
255   NLinkNodeMap myNLinkNodeMap;
256
257   std::set< int > mySeamShapeIds;
258   double          myPar1, myPar2; // bounds of a closed periodic surface
259   int             myParIndex;     // bounds' index (1-U, 2-V)
260   TopoDS_Shape    myShape;
261
262 };
263
264
265 #endif