Salome HOME
PAL13615 (EDF PAL 315/31 GEOM SMESH : meshing of a "5 edges quadrangle")
[modules/smesh.git] / src / SMESH / SMESH_Algo.hxx
1 //  SMESH SMESH : implementaion of SMESH idl descriptions
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : SMESH_Algo.hxx
25 //  Author : Paul RASCLE, EDF
26 //  Module : SMESH
27 //  $Header$
28
29 #ifndef _SMESH_ALGO_HXX_
30 #define _SMESH_ALGO_HXX_
31
32 #include "SMESH_Hypothesis.hxx"
33
34 #include <TopoDS_Shape.hxx>
35 #include <TopoDS_Edge.hxx>
36 #include <gp_XY.hxx>
37 #include <GeomAbs_Shape.hxx>
38
39 #include <string>
40 #include <vector>
41 #include <list>
42 #include <map>
43
44 class SMESH_Gen;
45 class SMESH_Mesh;
46 class SMESH_HypoFilter;
47 class TopoDS_Vertex;
48 class TopoDS_Face;
49 class TopoDS_Shape;
50 class SMESHDS_Mesh;
51 class SMDS_MeshNode;
52 class SMESH_subMesh;
53 class SMESH_MesherHelper;
54
55 class SMESH_Algo:public SMESH_Hypothesis
56 {
57 public:
58   /*!
59    * \brief Creates algorithm
60     * \param hypId - algorithm ID
61     * \param studyId - study ID
62     * \param gen - SMESH_Gen
63    */
64   SMESH_Algo(int hypId, int studyId, SMESH_Gen * gen);
65
66   /*!
67    * \brief Destructor
68    */
69   virtual ~ SMESH_Algo();
70
71   /*!
72    * \brief Saves nothing in a stream
73     * \param save - the stream
74     * \retval virtual std::ostream & - the stream
75    */
76   virtual std::ostream & SaveTo(std::ostream & save);
77
78   /*!
79    * \brief Loads nothing from a stream
80     * \param load - the stream
81     * \retval virtual std::ostream & - the stream
82    */
83   virtual std::istream & LoadFrom(std::istream & load);
84
85   /*!
86    * \brief Returns all types of compatible hypotheses
87    */
88   const std::vector < std::string > & GetCompatibleHypothesis();
89
90   /*!
91    * \brief Check hypothesis definition to mesh a shape
92     * \param aMesh - the mesh
93     * \param aShape - the shape
94     * \param aStatus - check result
95     * \retval bool - true if hypothesis is well defined
96    */
97   virtual bool CheckHypothesis(SMESH_Mesh&                          aMesh,
98                                const TopoDS_Shape&                  aShape,
99                                SMESH_Hypothesis::Hypothesis_Status& aStatus) = 0;
100   /*!
101    * \brief Computes mesh on a shape
102     * \param aMesh - the mesh
103     * \param aShape - the shape
104     * \retval bool - is a success
105    */
106   virtual bool Compute(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape) = 0;
107
108   /*!
109    * \brief Computes mesh without geometry
110     * \param aMesh - the mesh
111     * \param aHelper - helper that must be used for adding elements to \aaMesh
112     * \retval bool - is a success
113     *
114     * The method is called if ( !aMesh->HasShapeToMesh() )
115    */
116   virtual bool Compute(SMESH_Mesh & aMesh, SMESH_MesherHelper* aHelper);
117
118   /*!
119    * \brief Returns a list of compatible hypotheses used to mesh a shape
120     * \param aMesh - the mesh 
121     * \param aShape - the shape
122     * \param ignoreAuxiliary - do not include auxiliary hypotheses in the list
123     * \retval const std::list <const SMESHDS_Hypothesis*> - hypotheses list
124    * 
125    *  List the hypothesis used by the algorithm associated to the shape.
126    *  Hypothesis associated to father shape -are- taken into account (see
127    *  GetAppliedHypothesis). Relevant hypothesis have a name (type) listed in
128    *  the algorithm. This method could be surcharged by specific algorithms, in 
129    *  case of several hypothesis simultaneously applicable.
130    */
131   virtual const std::list <const SMESHDS_Hypothesis *> &
132   GetUsedHypothesis(SMESH_Mesh &         aMesh,
133                     const TopoDS_Shape & aShape,
134                     const bool           ignoreAuxiliary=true);
135   /*!
136    * \brief Returns a list of compatible hypotheses assigned to a shape in a mesh
137     * \param aMesh - the mesh 
138     * \param aShape - the shape
139     * \param ignoreAuxiliary - do not include auxiliary hypotheses in the list
140     * \retval const std::list <const SMESHDS_Hypothesis*> - hypotheses list
141    * 
142    *  List the relevant hypothesis associated to the shape. Relevant hypothesis
143    *  have a name (type) listed in the algorithm. Hypothesis associated to
144    *  father shape -are not- taken into account (see GetUsedHypothesis)
145    */
146   const list <const SMESHDS_Hypothesis *> &
147   GetAppliedHypothesis(SMESH_Mesh &         aMesh,
148                        const TopoDS_Shape & aShape,
149                        const bool           ignoreAuxiliary=true);
150   /*!
151    * \brief Make the filter recognize only compatible hypotheses
152    * \param theFilter - the filter to initialize
153    * \param ignoreAuxiliary - make filter ignore compatible auxiliary hypotheses
154    * \retval bool - true if the algo has compatible hypotheses
155    */
156   bool InitCompatibleHypoFilter( SMESH_HypoFilter & theFilter,
157                                  const bool         ignoreAuxiliary) const;
158   /*!
159    * \brief Initialize my parameter values by the mesh built on the geometry
160    * \param theMesh - the built mesh
161    * \param theShape - the geometry of interest
162    * \retval bool - true if parameter values have been successfully defined
163    *
164    * Just return false as the algorithm does not hold parameters values
165    */
166   virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh,
167                                    const TopoDS_Shape& theShape);
168
169
170 public:
171   // ==================================================================
172   // Algo features influencing how Compute() is called:
173   // in what turn and with what input shape
174   // ==================================================================
175
176   // SMESH_Hypothesis::GetDim();
177   // 1 - dimention of target mesh
178
179   bool OnlyUnaryInput() const { return _onlyUnaryInput; }
180   // 2 - is collection of tesselatable shapes inacceptable as input;
181   // "collection" means a shape containing shapes of dim equal
182   // to GetDim().
183   // Algo which can process a collection shape should expect
184   // an input temporary shape that is neither MainShape nor
185   // its child.
186
187   bool NeedDescretBoundary() const { return _requireDescretBoundary; }
188   // 3 - is a Dim-1 mesh prerequisite
189
190   bool NeedShape() const { return _requireShape; }
191   // 4 - is shape existance required
192
193 public:
194   // ==================================================================
195   // Methods to track non hierarchical dependencies between submeshes 
196   // ==================================================================
197
198   /*!
199    * \brief Sets event listener to submeshes if necessary
200     * \param subMesh - submesh where algo is set
201    *
202    * This method is called when a submesh gets HYP_OK algo_state.
203    * After being set, event listener is notified on each event of a submesh.
204    * By default non listener is set
205    */
206   virtual void SetEventListener(SMESH_subMesh* subMesh);
207   
208   /*!
209    * \brief Allow algo to do something after persistent restoration
210     * \param subMesh - restored submesh
211    *
212    * This method is called only if a submesh has HYP_OK algo_state.
213    */
214   virtual void SubmeshRestored(SMESH_subMesh* subMesh);
215   
216 public:
217   // ==================================================================
218   // Common algo utilities
219   // ==================================================================
220   /*!
221    * \brief Fill vector of node parameters on geometrical edge, including vertex nodes
222    * \param theMesh - The mesh containing nodes
223    * \param theEdge - The geometrical edge of interest
224    * \param theParams - The resulting vector of sorted node parameters
225    * \retval bool - false if not all parameters are OK
226    */
227   static bool GetNodeParamOnEdge(const SMESHDS_Mesh*     theMesh,
228                                  const TopoDS_Edge&      theEdge,
229                                  std::vector< double > & theParams);
230   /*!
231    * \brief Find out elements orientation on a geometrical face
232    * \param theFace - The face correctly oriented in the shape being meshed
233    * \param theMeshDS - The mesh data structure
234    * \retval bool - true if the face normal and the normal of first element
235    *                in the correspoding submesh point in different directions
236    */
237   static bool IsReversedSubMesh (const TopoDS_Face&  theFace,
238                                  SMESHDS_Mesh*       theMeshDS);
239   /*!
240    * \brief Compute length of an edge
241     * \param E - the edge
242     * \retval double - the length
243    */
244   static double EdgeLength(const TopoDS_Edge & E);
245
246   /*!
247    * \brief Return continuity of two edges
248     * \param E1 - the 1st edge
249     * \param E2 - the 2nd edge
250     * \retval GeomAbs_Shape - regularity at the junction between E1 and E2
251    */
252   static GeomAbs_Shape Continuity(const TopoDS_Edge & E1,
253                                   const TopoDS_Edge & E2);
254
255   /*!
256    * \brief Return the node built on a vertex
257     * \param V - the vertex
258     * \param meshDS - mesh
259     * \retval const SMDS_MeshNode* - found node or NULL
260    */
261   static const SMDS_MeshNode* VertexNode(const TopoDS_Vertex& V,
262                                          SMESHDS_Mesh*        meshDS);
263
264 protected:
265   std::vector<std::string> _compatibleHypothesis;
266   std::list<const SMESHDS_Hypothesis *> _appliedHypList;
267   std::list<const SMESHDS_Hypothesis *> _usedHypList;
268
269   bool _onlyUnaryInput;
270   bool _requireDescretBoundary;
271   bool _requireShape;
272
273   // quadratic mesh creation required
274   bool _quadraticMesh;
275 };
276
277 #endif