1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH SMESH : implementaion of SMESH idl descriptions
23 // File : SMESH_Algo.hxx
24 // Author : Paul RASCLE, EDF
28 #ifndef _SMESH_ALGO_HXX_
29 #define _SMESH_ALGO_HXX_
31 #include "SMESH_SMESH.hxx"
33 #include "SMESH_Hypothesis.hxx"
34 #include "SMESH_ComputeError.hxx"
35 #include "SMESH_Comment.hxx"
37 #include <TopoDS_Shape.hxx>
38 #include <TopoDS_Edge.hxx>
39 #include <GeomAbs_Shape.hxx>
48 class SMESH_HypoFilter;
55 class SMESH_MesherHelper;
57 typedef std::map< SMESH_subMesh*, std::vector<int> > MapShapeNbElems;
58 // vector must have size corresponding to EntityType_Last from SMDSAbs:
59 typedef std::map< SMESH_subMesh*, std::vector<int> >::iterator MapShapeNbElemsItr;
61 class SMESH_EXPORT SMESH_Algo:public SMESH_Hypothesis
65 * \brief Creates algorithm
66 * \param hypId - algorithm ID
67 * \param studyId - study ID
68 * \param gen - SMESH_Gen
70 SMESH_Algo(int hypId, int studyId, SMESH_Gen * gen);
75 virtual ~ SMESH_Algo();
78 * \brief Saves nothing in a stream
79 * \param save - the stream
80 * \retval virtual std::ostream & - the stream
82 virtual std::ostream & SaveTo(std::ostream & save);
85 * \brief Loads nothing from a stream
86 * \param load - the stream
87 * \retval virtual std::ostream & - the stream
89 virtual std::istream & LoadFrom(std::istream & load);
92 * \brief Returns all types of compatible hypotheses
94 const std::vector < std::string > & GetCompatibleHypothesis();
97 * \brief Check hypothesis definition to mesh a shape
98 * \param aMesh - the mesh
99 * \param aShape - the shape
100 * \param aStatus - check result
101 * \retval bool - true if hypothesis is well defined
103 virtual bool CheckHypothesis(SMESH_Mesh& aMesh,
104 const TopoDS_Shape& aShape,
105 SMESH_Hypothesis::Hypothesis_Status& aStatus) = 0;
107 * \brief Computes mesh on a shape
108 * \param aMesh - the mesh
109 * \param aShape - the shape
110 * \retval bool - is a success
112 * Algorithms that !NeedDescretBoundary() || !OnlyUnaryInput() are
113 * to set SMESH_ComputeError returned by SMESH_submesh::GetComputeError()
114 * to report problematic subshapes
116 virtual bool Compute(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape) = 0;
119 * \brief Computes mesh without geometry
120 * \param aMesh - the mesh
121 * \param aHelper - helper that must be used for adding elements to \aaMesh
122 * \retval bool - is a success
124 * The method is called if ( !aMesh->HasShapeToMesh() )
126 virtual bool Compute(SMESH_Mesh & aMesh, SMESH_MesherHelper* aHelper);
129 * \brief evaluates size of prospective mesh on a shape
130 * \param aMesh - the mesh
131 * \param aShape - the shape
132 * \param aNbElems - prospective number of elements by types
133 * \retval bool - is a success
135 virtual bool Evaluate(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape,
136 MapShapeNbElems& aResMap) = 0;
139 * \brief Returns a list of compatible hypotheses used to mesh a shape
140 * \param aMesh - the mesh
141 * \param aShape - the shape
142 * \param ignoreAuxiliary - do not include auxiliary hypotheses in the list
143 * \retval const std::list <const SMESHDS_Hypothesis*> - hypotheses list
145 * List the hypothesis used by the algorithm associated to the shape.
146 * Hypothesis associated to father shape -are- taken into account (see
147 * GetAppliedHypothesis). Relevant hypothesis have a name (type) listed in
148 * the algorithm. This method could be surcharged by specific algorithms, in
149 * case of several hypothesis simultaneously applicable.
151 virtual const std::list <const SMESHDS_Hypothesis *> &
152 GetUsedHypothesis(SMESH_Mesh & aMesh,
153 const TopoDS_Shape & aShape,
154 const bool ignoreAuxiliary=true);
156 * \brief Returns a list of compatible hypotheses assigned to a shape in a mesh
157 * \param aMesh - the mesh
158 * \param aShape - the shape
159 * \param ignoreAuxiliary - do not include auxiliary hypotheses in the list
160 * \retval const std::list <const SMESHDS_Hypothesis*> - hypotheses list
162 * List the relevant hypothesis associated to the shape. Relevant hypothesis
163 * have a name (type) listed in the algorithm. Hypothesis associated to
164 * father shape -are not- taken into account (see GetUsedHypothesis)
166 const list <const SMESHDS_Hypothesis *> &
167 GetAppliedHypothesis(SMESH_Mesh & aMesh,
168 const TopoDS_Shape & aShape,
169 const bool ignoreAuxiliary=true);
171 * \brief Make the filter recognize only compatible hypotheses
172 * \param theFilter - the filter to initialize
173 * \param ignoreAuxiliary - make filter ignore compatible auxiliary hypotheses
174 * \retval bool - true if the algo has compatible hypotheses
176 bool InitCompatibleHypoFilter( SMESH_HypoFilter & theFilter,
177 const bool ignoreAuxiliary) const;
179 * \brief Just return false as the algorithm does not hold parameters values
181 virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape);
182 virtual bool SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh=0);
184 * \brief return compute error
186 SMESH_ComputeErrorPtr GetComputeError() const;
188 * \brief initialize compute error
190 void InitComputeError();
193 // ==================================================================
194 // Algo features influencing how Compute() is called:
195 // in what turn and with what input shape
196 // ==================================================================
198 // SMESH_Hypothesis::GetDim();
199 // 1 - dimention of target mesh
201 bool OnlyUnaryInput() const { return _onlyUnaryInput; }
202 // 2 - is collection of tesselatable shapes inacceptable as input;
203 // "collection" means a shape containing shapes of dim equal
205 // Algo which can process a collection shape should expect
206 // an input temporary shape that is neither MainShape nor
209 bool NeedDescretBoundary() const { return _requireDescretBoundary; }
210 // 3 - is a Dim-1 mesh prerequisite
212 bool NeedShape() const { return _requireShape; }
213 // 4 - is shape existance required
215 bool SupportSubmeshes() const { return _supportSubmeshes; }
216 // 5 - whether supports submeshes if !NeedDescretBoundary()
220 // ==================================================================
221 // Methods to track non hierarchical dependencies between submeshes
222 // ==================================================================
225 * \brief Sets event listener to submeshes if necessary
226 * \param subMesh - submesh where algo is set
228 * This method is called when a submesh gets HYP_OK algo_state.
229 * After being set, event listener is notified on each event of a submesh.
230 * By default non listener is set
232 virtual void SetEventListener(SMESH_subMesh* subMesh);
235 * \brief Allow algo to do something after persistent restoration
236 * \param subMesh - restored submesh
238 * This method is called only if a submesh has HYP_OK algo_state.
240 virtual void SubmeshRestored(SMESH_subMesh* subMesh);
243 // ==================================================================
244 // Common algo utilities
245 // ==================================================================
247 * \brief Fill vector of node parameters on geometrical edge, including vertex nodes
248 * \param theMesh - The mesh containing nodes
249 * \param theEdge - The geometrical edge of interest
250 * \param theParams - The resulting vector of sorted node parameters
251 * \retval bool - false if not all parameters are OK
253 static bool GetNodeParamOnEdge(const SMESHDS_Mesh* theMesh,
254 const TopoDS_Edge& theEdge,
255 std::vector< double > & theParams);
257 * \brief Fill map of node parameter on geometrical edge to node it-self
258 * \param theMesh - The mesh containing nodes
259 * \param theEdge - The geometrical edge of interest
260 * \param theNodes - The resulting map
261 * \param ignoreMediumNodes - to store medium nodes of quadratic elements or not
262 * \retval bool - false if not all parameters are OK
264 static bool GetSortedNodesOnEdge(const SMESHDS_Mesh* theMesh,
265 const TopoDS_Edge& theEdge,
266 const bool ignoreMediumNodes,
267 std::map< double, const SMDS_MeshNode* > & theNodes);
269 * \brief Find out elements orientation on a geometrical face
270 * \param theFace - The face correctly oriented in the shape being meshed
271 * \param theMeshDS - The mesh data structure
272 * \retval bool - true if the face normal and the normal of first element
273 * in the correspoding submesh point in different directions
275 static bool IsReversedSubMesh (const TopoDS_Face& theFace,
276 SMESHDS_Mesh* theMeshDS);
278 * \brief Compute length of an edge
279 * \param E - the edge
280 * \retval double - the length
282 static double EdgeLength(const TopoDS_Edge & E);
285 * \brief Return continuity of two edges
286 * \param E1 - the 1st edge
287 * \param E2 - the 2nd edge
288 * \retval GeomAbs_Shape - regularity at the junction between E1 and E2
290 static GeomAbs_Shape Continuity(const TopoDS_Edge & E1, const TopoDS_Edge & E2);
293 * \brief Return true if an edge can be considered as a continuation of another
295 static bool IsContinuous(const TopoDS_Edge & E1, const TopoDS_Edge & E2) {
296 return ( Continuity( E1, E2 ) >= GeomAbs_G1 );
300 * \brief Return the node built on a vertex
301 * \param V - the vertex
302 * \param meshDS - mesh
303 * \retval const SMDS_MeshNode* - found node or NULL
305 static const SMDS_MeshNode* VertexNode(const TopoDS_Vertex& V,
306 const SMESHDS_Mesh* meshDS);
311 * \brief store error and comment and then return ( error == COMPERR_OK )
313 bool error(int error, const SMESH_Comment& comment = "");
315 * \brief store COMPERR_ALGO_FAILED error and comment and then return false
317 bool error(const SMESH_Comment& comment = "")
318 { return error(COMPERR_ALGO_FAILED, comment); }
320 * \brief store error and return error->IsOK()
322 bool error(SMESH_ComputeErrorPtr error);
324 * \brief store a bad input element preventing computation,
325 * which may be a temporary one i.e. not residing the mesh,
326 * then it will be deleted by InitComputeError()
328 void addBadInputElement(const SMDS_MeshElement* elem);
332 std::vector<std::string> _compatibleHypothesis;
333 std::list<const SMESHDS_Hypothesis *> _appliedHypList;
334 std::list<const SMESHDS_Hypothesis *> _usedHypList;
336 // Algo features influencing which Compute() and how is called:
337 // in what turn and with what input shape.
338 // This fields must be redefined if necessary by each descendant at constructor.
339 bool _onlyUnaryInput; // mesh one shape of GetDim() at once. Default TRUE
340 bool _requireDescretBoundary; // GetDim()-1 mesh must be present. Default TRUE
341 bool _requireShape; // work with GetDim()-1 mesh bound to geom only. Default TRUE
342 bool _supportSubmeshes; // if !_requireDescretBoundary. Default FALSE
344 // quadratic mesh creation required,
345 // is usually set trough SMESH_MesherHelper::IsQuadraticSubMesh()
348 int _error; //!< SMESH_ComputeErrorName or anything algo specific
349 std::string _comment; //!< any text explaining what is wrong in Compute()
350 std::list<const SMDS_MeshElement*> _badInputElements; //!< to explain COMPERR_BAD_INPUT_MESH