1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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
23 // SMESH SMESH : implementaion of SMESH idl descriptions
24 // File : SMESH_Algo.hxx
25 // Author : Paul RASCLE, EDF
28 #ifndef _SMESH_ALGO_HXX_
29 #define _SMESH_ALGO_HXX_
31 #include "SMESH_SMESH.hxx"
33 #include "SMDSAbs_ElementType.hxx"
34 #include "SMESH_Comment.hxx"
35 #include "SMESH_ComputeError.hxx"
36 #include "SMESH_Hypothesis.hxx"
38 #include <TopoDS_Shape.hxx>
39 #include <TopoDS_Edge.hxx>
40 #include <GeomAbs_Shape.hxx>
50 class SMESHDS_SubMesh;
52 class SMESH_HypoFilter;
54 class SMESH_MesherHelper;
55 class SMESH_ProxyMesh;
63 typedef std::map< SMESH_subMesh*, std::vector<int> > MapShapeNbElems;
64 typedef std::map< SMESH_subMesh*, std::vector<int> >::iterator MapShapeNbElemsItr;
66 // ==================================================================================
68 * \brief Root of all algorithms
70 * Methods of the class are grouped into several parts:
71 * - main lifecycle methods, like Compute()
72 * - methods describing features of the algorithm, like NeedShape()
73 * - methods related to dependencies between sub-meshes imposed by the algorith
74 * - static utilities, like EdgeLength()
76 // ==================================================================================
78 class SMESH_EXPORT SMESH_Algo : public SMESH_Hypothesis
81 //==================================================================================
83 * \brief Structure describing algorithm features
85 // --------------------------------------------------------------------------------
89 std::set<SMDSAbs_GeometryType> _inElemTypes; // acceptable types of input mesh element
90 std::set<SMDSAbs_GeometryType> _outElemTypes; // produced types of mesh elements
91 std::string _label; // GUI type name
93 bool IsCompatible( const Features& algo2 ) const;
96 * \brief Returns a structure describing algorithm features
98 static const Features& GetFeatures( const std::string& algoType );
99 const Features& GetFeatures() const { return GetFeatures( _name ); }
102 //==================================================================================
104 * \brief Creates algorithm
105 * \param hypId - algorithm ID
106 * \param studyId - study ID
107 * \param gen - SMESH_Gen
109 SMESH_Algo(int hypId, int studyId, SMESH_Gen * gen);
114 virtual ~ SMESH_Algo();
117 * \brief Saves nothing in a stream
118 * \param save - the stream
119 * \retval std::ostream & - the stream
121 virtual std::ostream & SaveTo(std::ostream & save);
124 * \brief Loads nothing from a stream
125 * \param load - the stream
126 * \retval std::ostream & - the stream
128 virtual std::istream & LoadFrom(std::istream & load);
131 * \brief Returns all types of compatible hypotheses
133 const std::vector < std::string > & GetCompatibleHypothesis();
136 * \brief Check hypothesis definition to mesh a shape
137 * \param aMesh - the mesh
138 * \param aShape - the shape
139 * \param aStatus - check result
140 * \retval bool - true if hypothesis is well defined
142 * Textual description of a problem can be stored in _comment field.
144 virtual bool CheckHypothesis(SMESH_Mesh& aMesh,
145 const TopoDS_Shape& aShape,
146 SMESH_Hypothesis::Hypothesis_Status& aStatus) = 0;
148 * \brief Computes mesh on a shape
149 * \param aMesh - the mesh
150 * \param aShape - the shape
151 * \retval bool - is a success
153 * Algorithms that !NeedDiscreteBoundary() || !OnlyUnaryInput() are
154 * to set SMESH_ComputeError returned by SMESH_submesh::GetComputeError()
155 * to report problematic sub-shapes
157 virtual bool Compute(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape) = 0;
160 * \brief Computes mesh without geometry
161 * \param aMesh - the mesh
162 * \param aHelper - helper that must be used for adding elements to \aaMesh
163 * \retval bool - is a success
165 * The method is called if ( !aMesh->HasShapeToMesh() )
167 virtual bool Compute(SMESH_Mesh & aMesh, SMESH_MesherHelper* aHelper);
170 * \brief Sets _computeCanceled to true. It's usage depends on
171 * implementation of a particular mesher.
173 virtual void CancelCompute();
176 * \brief If possible, returns progress of computation [0.,1.]
178 virtual double GetProgress() const;
181 * \brief evaluates size of prospective mesh on a shape
182 * \param aMesh - the mesh
183 * \param aShape - the shape
184 * \param aResMap - prospective number of elements by SMDSAbs_ElementType by a sub-mesh
185 * \retval bool - is a success
187 virtual bool Evaluate(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape,
188 MapShapeNbElems& aResMap) = 0;
191 * \brief Returns a list of compatible hypotheses used to mesh a shape
192 * \param aMesh - the mesh
193 * \param aShape - the shape
194 * \param ignoreAuxiliary - do not include auxiliary hypotheses in the list
195 * \retval const std::list <const SMESHDS_Hypothesis*> - hypotheses list
197 * List the hypothesis used by the algorithm associated to the shape.
198 * Hypothesis associated to father shape -are- taken into account (see
199 * GetAppliedHypothesis). Relevant hypothesis have a name (type) listed in
200 * the algorithm. This method could be surcharged by specific algorithms, in
201 * case of several hypothesis simultaneously applicable.
203 virtual const std::list <const SMESHDS_Hypothesis *> &
204 GetUsedHypothesis(SMESH_Mesh & aMesh,
205 const TopoDS_Shape & aShape,
206 const bool ignoreAuxiliary=true) const;
208 * \brief Returns a list of compatible hypotheses assigned to a shape in a mesh
209 * \param aMesh - the mesh
210 * \param aShape - the shape
211 * \param ignoreAuxiliary - do not include auxiliary hypotheses in the list
212 * \retval const std::list <const SMESHDS_Hypothesis*> - hypotheses list
214 * List the relevant hypothesis associated to the shape. Relevant hypothesis
215 * have a name (type) listed in the algorithm. Hypothesis associated to
216 * father shape -are not- taken into account (see GetUsedHypothesis)
218 const std::list <const SMESHDS_Hypothesis *> &
219 GetAppliedHypothesis(SMESH_Mesh & aMesh,
220 const TopoDS_Shape & aShape,
221 const bool ignoreAuxiliary=true) const;
223 * \brief Returns the filter recognizing only compatible hypotheses
224 * \param ignoreAuxiliary - make filter ignore compatible auxiliary hypotheses
225 * \retval SMESH_HypoFilter* - the filter that can be NULL
227 const SMESH_HypoFilter* GetCompatibleHypoFilter(const bool ignoreAuxiliary) const;
230 * \brief Just return false as the algorithm does not hold parameters values
232 virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape);
233 virtual bool SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh=0);
236 * \brief return compute error
238 SMESH_ComputeErrorPtr GetComputeError() const;
240 * \brief initialize compute error etc. before call of Compute()
242 void InitComputeError();
244 * \brief Return compute progress by nb of calls of this method
246 double GetProgressByTic() const;
248 * Return a vector of sub-meshes to Compute()
250 std::vector<SMESH_subMesh*>& SubMeshesToCompute() { return _smToCompute; }
253 // ==================================================================
254 // Algo features influencing how Compute() is called:
255 // in what turn and with what input shape
256 // ==================================================================
258 // SMESH_Hypothesis::GetDim();
259 // 1 - dimention of target mesh
261 bool OnlyUnaryInput() const { return _onlyUnaryInput; }
262 // 2 - is collection of tesselatable shapes inacceptable as input;
263 // "collection" means a shape containing shapes of dim equal
265 // Algo which can process a collection shape should expect
266 // an input temporary shape that is neither MainShape nor
269 bool NeedDiscreteBoundary() const { return _requireDiscreteBoundary; }
270 // 3 - is a Dim-1 mesh prerequisite
272 bool NeedShape() const { return _requireShape; }
273 // 4 - is shape existance required
275 bool SupportSubmeshes() const { return _supportSubmeshes; }
276 // 5 - whether supports submeshes if !NeedDiscreteBoundary()
278 bool NeedLowerHyps(int dim) const { return _neededLowerHyps[ dim ]; }
279 // 6 - if algo !NeedDiscreteBoundary() but requires presence of
280 // hypotheses of dimension <dim> to generate all-dimensional mesh.
281 // This info is used not to issue warnings on hiding of lower global algos.
284 // ==================================================================
285 // Methods to track non hierarchical dependencies between submeshes
286 // ==================================================================
289 * \brief Sets event listener to submeshes if necessary
290 * \param subMesh - submesh where algo is set
292 * This method is called when a submesh gets HYP_OK algo_state.
293 * After being set, event listener is notified on each event of a submesh.
294 * By default none listener is set
296 virtual void SetEventListener(SMESH_subMesh* subMesh);
299 * \brief Allow algo to do something after persistent restoration
300 * \param subMesh - restored submesh
302 * This method is called only if a submesh has HYP_OK algo_state.
304 virtual void SubmeshRestored(SMESH_subMesh* subMesh);
307 // ==================================================================
308 // Common algo utilities
309 // ==================================================================
311 * \brief Fill vector of node parameters on geometrical edge, including vertex nodes
312 * \param theMesh - The mesh containing nodes
313 * \param theEdge - The geometrical edge of interest
314 * \param theParams - The resulting vector of sorted node parameters
315 * \retval bool - false if not all parameters are OK
316 * \warning Nodes moved to other geometry by MergeNodes() are NOT returned.
318 static bool GetNodeParamOnEdge(const SMESHDS_Mesh* theMesh,
319 const TopoDS_Edge& theEdge,
320 std::vector< double > & theParams);
322 * \brief Fill map of node parameter on geometrical edge to node it-self
323 * \param theMesh - The mesh containing nodes
324 * \param theEdge - The geometrical edge of interest
325 * \param theNodes - The resulting map
326 * \param ignoreMediumNodes - to store medium nodes of quadratic elements or not
327 * \param typeToCheck - type of elements to check for medium nodes
328 * \retval bool - false if not all parameters are OK
329 * \warning Nodes moved to other geometry by MergeNodes() are NOT returned.
331 static bool GetSortedNodesOnEdge(const SMESHDS_Mesh* theMesh,
332 const TopoDS_Edge& theEdge,
333 const bool ignoreMediumNodes,
334 std::map< double, const SMDS_MeshNode* > & theNodes,
335 const SMDSAbs_ElementType typeToCheck = SMDSAbs_All);
338 * \brief Compute length of an edge
339 * \param E - the edge
340 * \retval double - the length
342 static double EdgeLength(const TopoDS_Edge & E);
344 int NumberOfPoints(SMESH_Mesh& aMesh,const TopoDS_Wire& W);
347 * \brief Return continuity of two edges
348 * \param E1 - the 1st edge
349 * \param E2 - the 2nd edge
350 * \retval GeomAbs_Shape - regularity at the junction between E1 and E2
352 static GeomAbs_Shape Continuity(TopoDS_Edge E1, TopoDS_Edge E2);
355 * \brief Return true if an edge can be considered as a continuation of another
357 static bool IsContinuous(const TopoDS_Edge & E1, const TopoDS_Edge & E2) {
358 return ( Continuity( E1, E2 ) >= GeomAbs_G1 );
361 * \brief Return true if an edge can be considered straight
363 static bool IsStraight( const TopoDS_Edge & E, const bool degenResult=false );
365 * \brief Return true if an edge has no 3D curve
367 static bool isDegenerated( const TopoDS_Edge & E );
370 * \brief Return the node built on a vertex
371 * \param V - the vertex
372 * \param meshDS - mesh data structure
373 * \retval const SMDS_MeshNode* - found node or NULL
375 static const SMDS_MeshNode* VertexNode(const TopoDS_Vertex& V, const SMESHDS_Mesh* meshDS);
378 * \brief Return the node built on a vertex.
379 * A node moved to other geometry by MergeNodes() is also returned.
380 * \param V - the vertex
382 * \retval const SMDS_MeshNode* - found node or NULL
384 static const SMDS_MeshNode* VertexNode(const TopoDS_Vertex& V, const SMESH_Mesh* mesh);
387 * \brief Return the node built on a vertex.
388 * A node moved to other geometry by MergeNodes() is also returned.
389 * \param V - the vertex
390 * \param edgeSM - sub-mesh of a meshed EDGE sharing the vertex
391 * \param mesh - the mesh
392 * \param checkV - if \c true, presence of a node on the vertex is checked
393 * \retval const SMDS_MeshNode* - found node or NULL
395 static const SMDS_MeshNode* VertexNode(const TopoDS_Vertex& V,
396 const SMESHDS_SubMesh* edgeSM,
397 const SMESH_Mesh* mesh,
398 const bool checkV=true);
400 enum EMeshError { MEr_OK = 0, MEr_HOLES, MEr_BAD_ORI, MEr_EMPTY };
403 * \brief Finds topological errors of a sub-mesh
405 static EMeshError GetMeshError(SMESH_subMesh* subMesh);
410 * \brief store error and comment and then return ( error == COMPERR_OK )
412 bool error(int error, const SMESH_Comment& comment = "");
414 * \brief store COMPERR_ALGO_FAILED error and comment and then return false
416 bool error(const SMESH_Comment& comment = "")
417 { return error(COMPERR_ALGO_FAILED, comment); }
419 * \brief store error and return error->IsOK()
421 bool error(SMESH_ComputeErrorPtr error);
423 * \brief store a bad input element preventing computation,
424 * which may be a temporary one i.e. not residing the mesh,
425 * then it will be deleted by InitComputeError()
427 void addBadInputElement(const SMDS_MeshElement* elem);
429 void addBadInputElements(const SMESHDS_SubMesh* sm,
430 const bool addNodes=false);
434 const SMESH_HypoFilter * _compatibleAllHypFilter;
435 const SMESH_HypoFilter * _compatibleNoAuxHypFilter;
436 std::vector<std::string> _compatibleHypothesis;
437 std::list<const SMESHDS_Hypothesis *> _appliedHypList;
438 std::list<const SMESHDS_Hypothesis *> _usedHypList;
441 // Algo features influencing which Compute() and how is called:
442 // in what turn and with what input shape.
443 // These fields must be redefined if necessary by each descendant at constructor.
444 bool _onlyUnaryInput; // mesh one shape of GetDim() at once. Default TRUE
445 bool _requireDiscreteBoundary;// GetDim()-1 mesh must be present. Default TRUE
446 bool _requireShape; // work with GetDim()-1 mesh bound to geom only. Default TRUE
447 bool _supportSubmeshes; // if !_requireDiscreteBoundary. Default FALSE
448 bool _neededLowerHyps[4]; // hyp dims needed by algo that !_requireDiscreteBoundary. Df. FALSE
450 // indicates if quadratic mesh creation is required,
451 // is usually set like this: _quadraticMesh = SMESH_MesherHelper::IsQuadraticSubMesh(shape)
454 int _error; //!< SMESH_ComputeErrorName or anything algo specific
455 std::string _comment; //!< any text explaining what is wrong in Compute()
456 std::list<const SMDS_MeshElement*> _badInputElements; //!< to explain COMPERR_BAD_INPUT_MESH
458 volatile bool _computeCanceled; //!< is set to True while computing to stop it
460 double _progress; /* progress of Compute() [0.,1.],
461 to be set by an algo really tracking the progress */
462 int _progressTic; // counter of calls from SMESH_Mesh::GetComputeProgress()
463 std::vector<SMESH_subMesh*> _smToCompute; // sub-meshes to Compute()
467 class SMESH_EXPORT SMESH_0D_Algo: public SMESH_Algo
470 SMESH_0D_Algo(int hypId, int studyId, SMESH_Gen* gen);
473 class SMESH_EXPORT SMESH_1D_Algo: public SMESH_Algo
476 SMESH_1D_Algo(int hypId, int studyId, SMESH_Gen* gen);
479 class SMESH_EXPORT SMESH_2D_Algo: public SMESH_Algo
482 SMESH_2D_Algo(int hypId, int studyId, SMESH_Gen* gen);
484 * \brief Method in which an algorithm generating a structured mesh
485 * fixes positions of in-face nodes after there movement
486 * due to insertion of viscous layers.
488 virtual bool FixInternalNodes(const SMESH_ProxyMesh& mesh,
489 const TopoDS_Face& face);
492 class SMESH_EXPORT SMESH_3D_Algo: public SMESH_Algo
495 SMESH_3D_Algo(int hypId, int studyId, SMESH_Gen* gen);