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