Version: 9.16.0
SMESH_Algo.hxx
Go to the documentation of this file.
1// Copyright (C) 2007-2026 CEA, EDF, OPEN CASCADE
2//
3// Copyright (C) 2003-2007 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, or (at your option) any later version.
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// SMESH SMESH : implementation of SMESH idl descriptions
24// File : SMESH_Algo.hxx
25// Author : Paul RASCLE, EDF
26// Module : SMESH
27//
28#ifndef _SMESH_ALGO_HXX_
29#define _SMESH_ALGO_HXX_
30
31#include "SMESH_SMESH.hxx"
32
34#include "SMESH_Comment.hxx"
36#include "SMESH_Hypothesis.hxx"
37
38#include <GeomAbs_Shape.hxx>
39#include <TopoDS_Shape.hxx>
40
41#include <string>
42#include <vector>
43#include <list>
44#include <map>
45#include <set>
46
47class SMDS_MeshNode;
48class SMESHDS_Mesh;
49class SMESHDS_SubMesh;
50class SMESH_Gen;
52class SMESH_Mesh;
54class SMESH_ProxyMesh;
55class SMESH_subMesh;
56class TopoDS_Edge;
57class TopoDS_Face;
58class TopoDS_Shape;
59class TopoDS_Vertex;
60class TopoDS_Wire;
61class gp_XYZ;
62
63typedef std::map< SMESH_subMesh*, std::vector<smIdType> > MapShapeNbElems;
64typedef std::map< SMESH_subMesh*, std::vector<smIdType> >::iterator MapShapeNbElemsItr;
65
66// ==================================================================================
76// ==================================================================================
77
79{
80 public:
81 //==================================================================================
85 // --------------------------------------------------------------------------------
86 struct Features
87 {
88 int _dim;
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
92
93 Features(): _dim( -1 ) {}
94 bool IsCompatible( const Features& algo2 ) const;
95 };
99 static const Features& GetFeatures( const std::string& algoType );
100 const Features& GetFeatures() const { return GetFeatures( _name ); }
101
102 public:
103 //==================================================================================
109 SMESH_Algo(int hypId, SMESH_Gen * gen);
110
114 virtual ~ SMESH_Algo();
115
121 virtual std::ostream & SaveTo(std::ostream & save);
122
128 virtual std::istream & LoadFrom(std::istream & load);
129
133 const std::vector < std::string > & GetCompatibleHypothesis();
134
144 virtual bool CheckHypothesis(SMESH_Mesh& aMesh,
145 const TopoDS_Shape& aShape,
157 virtual bool Compute(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape) = 0;
158
167 virtual bool Compute(SMESH_Mesh & aMesh, SMESH_MesherHelper* aHelper);
168
176 virtual bool IsApplicableToShape(const TopoDS_Shape & shape, bool toCheckAll) const;
177
182 virtual void CancelCompute();
183
187 virtual double GetProgress() const;
188
196 virtual bool Evaluate(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape,
197 MapShapeNbElems& aResMap) = 0;
198
212 virtual const std::list <const SMESHDS_Hypothesis *> &
213 GetUsedHypothesis(SMESH_Mesh & aMesh,
214 const TopoDS_Shape & aShape,
215 const bool ignoreAuxiliary=true) const;
219 virtual const std::list < TopoDS_Shape > & GetAssignedShapes() const;
225 const SMESH_HypoFilter* GetCompatibleHypoFilter(const bool ignoreAuxiliary) const;
226
230 virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape);
231 virtual bool SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh=0);
232
236 SMESH_ComputeErrorPtr GetComputeError() const;
240 void InitComputeError();
244 double GetProgressByTic() const;
248 std::vector<SMESH_subMesh*>& SubMeshesToCompute() { return _smToCompute; }
249
250public:
251 // ==================================================================
252 // Algo features influencing how Compute() is called:
253 // in what turn and with what input shape
254 // ==================================================================
255
256 // SMESH_Hypothesis::GetDim();
257 // 1 - dimension of target mesh
258
259 bool OnlyUnaryInput() const { return _onlyUnaryInput; }
260 // 2 - is collection of tesselatable shapes inacceptable as input;
261 // "collection" means a shape containing shapes of dim equal
262 // to GetDim().
263 // Algo which can process a collection shape should expect
264 // an input temporary shape that is neither MainShape nor
265 // its child.
266
267 bool NeedDiscreteBoundary() const { return _requireDiscreteBoundary; }
268 // 3 - is a Dim-1 mesh prerequisite
269
270 bool NeedShape() const { return _requireShape; }
271 // 4 - is shape existence required
272
273 bool SupportSubmeshes() const { return _supportSubmeshes; }
274 // 5 - whether supports submeshes if !NeedDiscreteBoundary()
275
276 bool NeedLowerHyps(int dim) const { return _neededLowerHyps[ dim ]; }
277 // 6 - if algo !NeedDiscreteBoundary() but requires presence of
278 // hypotheses of dimension <dim> to generate all-dimensional mesh.
279 // This info is used not to issue warnings on hiding of lower global algos.
280 //
281
282 virtual void setSubMeshesToCompute(SMESH_subMesh * aSubMesh) {SubMeshesToCompute().assign( 1, aSubMesh );}
283
284public:
285 // ==================================================================
286 // Methods to track non hierarchical dependencies between submeshes
287 // ==================================================================
288
297 virtual void SetEventListener(SMESH_subMesh* subMesh);
298
305 virtual void SubmeshRestored(SMESH_subMesh* subMesh);
306
307public:
308 // ==================================================================
309 // Common algo utilities
310 // ==================================================================
319 static bool GetNodeParamOnEdge(const SMESHDS_Mesh* theMesh,
320 const TopoDS_Edge& theEdge,
321 std::vector< double > & theParams);
332 static bool GetSortedNodesOnEdge(const SMESHDS_Mesh* theMesh,
333 const TopoDS_Edge& theEdge,
334 const bool ignoreMediumNodes,
335 std::map< double, const SMDS_MeshNode* > & theNodes,
336 const SMDSAbs_ElementType typeToCheck = SMDSAbs_All);
337
343 static double EdgeLength(const TopoDS_Edge & E);
344
345 smIdType NumberOfPoints(SMESH_Mesh& aMesh,const TopoDS_Wire& W);
346
353 static GeomAbs_Shape Continuity(const TopoDS_Edge& E1, const TopoDS_Edge& E2);
354
358 static bool IsContinuous(const TopoDS_Edge & E1, const TopoDS_Edge & E2) {
359 return ( Continuity( E1, E2 ) >= GeomAbs_G1 );
360 }
364 static bool IsStraight( const TopoDS_Edge & E, const bool degenResult=false );
368 static bool isDegenerated( const TopoDS_Edge & E, const bool checkLength=false );
369
376 static const SMDS_MeshNode* VertexNode(const TopoDS_Vertex& V, const SMESHDS_Mesh* meshDS);
377
385 static const SMDS_MeshNode* VertexNode(const TopoDS_Vertex& V, const SMESH_Mesh* mesh);
386
396 static const SMDS_MeshNode* VertexNode(const TopoDS_Vertex& V,
397 const SMESHDS_SubMesh* edgeSM,
398 const SMESH_Mesh* mesh,
399 const bool checkV=true);
400
401 enum EMeshError { MEr_OK = 0, MEr_HOLES, MEr_BAD_ORI, MEr_EMPTY };
402
406 static EMeshError GetMeshError(SMESH_subMesh* subMesh);
407
408 protected:
409
413 bool error(int error, const SMESH_Comment& comment = "");
417 bool error(const SMESH_Comment& comment = "")
418 { return error(COMPERR_ALGO_FAILED, comment); }
422 bool error(SMESH_ComputeErrorPtr error);
428 void addBadInputElement(const SMDS_MeshElement* elem);
429
430 void addBadInputElements(const SMESHDS_SubMesh* sm,
431 const bool addNodes=false);
432
433protected:
434
437 std::vector<std::string> _compatibleHypothesis;
438 std::list<const SMESHDS_Hypothesis *> _usedHypList;
439 std::list<TopoDS_Shape> _assigedShapeList; // _usedHypList assigned to
440
441
442 // Algo features influencing which Compute() and how is called:
443 // in what turn and with what input shape.
444 // These fields must be redefined if necessary by each descendant at constructor.
445 bool _onlyUnaryInput; // mesh one shape of GetDim() at once. Default TRUE
446 bool _requireDiscreteBoundary;// GetDim()-1 mesh must be present. Default TRUE
447 bool _requireShape; // work with GetDim()-1 mesh bound to geom only. Default TRUE
448 bool _supportSubmeshes; // if !_requireDiscreteBoundary. Default FALSE
449 bool _neededLowerHyps[4]; // hyp dims needed by algo that !_requireDiscreteBoundary. Df. FALSE
450
451 // indicates if quadratic mesh creation is required,
452 // is usually set like this: _quadraticMesh = SMESH_MesherHelper::IsQuadraticSubMesh(shape)
454
455 int _error;
456 std::string _comment;
457 std::list<const SMDS_MeshElement*> _badInputElements;
459
460 volatile bool _computeCanceled;
461
462 double _progress; /* progress of Compute() [0.,1.],
463 to be set by an algo really tracking the progress */
464 int _progressTic; // counter of calls from SMESH_Mesh::GetComputeProgress()
465 std::vector<SMESH_subMesh*> _smToCompute; // sub-meshes to Compute()
466};
467
468
470{
471public:
472 SMESH_0D_Algo(int hypId, SMESH_Gen* gen);
473};
474
476{
477public:
478 SMESH_1D_Algo(int hypId, SMESH_Gen* gen);
486 virtual bool IsApplicableToShape(const TopoDS_Shape & shape, bool toCheckAll) const;
487};
488
490{
491public:
492 SMESH_2D_Algo(int hypId, SMESH_Gen* gen);
500 virtual bool IsApplicableToShape(const TopoDS_Shape & shape, bool toCheckAll) const;
506 virtual bool FixInternalNodes(const SMESH_ProxyMesh& mesh,
507 const TopoDS_Face& face);
508};
509
511{
512public:
513 SMESH_3D_Algo(int hypId, SMESH_Gen* gen);
521 virtual bool IsApplicableToShape(const TopoDS_Shape & shape, bool toCheckAll) const;
522};
523
524#endif
SMDSAbs_ElementType
Type (node, edge, face or volume) of elements.
Definition: SMDSAbs_ElementType.hxx:34
@ SMDSAbs_All
Definition: SMDSAbs_ElementType.hxx:35
std::map< SMESH_subMesh *, std::vector< smIdType > > MapShapeNbElems
Definition: SMESH_Algo.hxx:63
std::map< SMESH_subMesh *, std::vector< smIdType > >::iterator MapShapeNbElemsItr
Definition: SMESH_Algo.hxx:64
@ COMPERR_ALGO_FAILED
algo failed for some reason
Definition: SMESH_ComputeError.hxx:53
boost::shared_ptr< SMESH_ComputeError > SMESH_ComputeErrorPtr
Definition: SMESH_ComputeError.hxx:38
#define SMESH_EXPORT
Definition: SMESH_SMESH.hxx:37
Base class for elements.
Definition: SMDS_MeshElement.hxx:56
Definition: SMDS_MeshNode.hxx:36
Definition: SMDS_Mesh.hxx:53
virtual std::istream & LoadFrom(std::istream &load)=0
virtual std::ostream & SaveTo(std::ostream &save)=0
Definition: SMESHDS_Mesh.hxx:98
Definition: SMESHDS_SubMesh.hxx:48
Definition: SMESH_Algo.hxx:470
Definition: SMESH_Algo.hxx:476
Definition: SMESH_Algo.hxx:490
Definition: SMESH_Algo.hxx:511
Root of all algorithms.
Definition: SMESH_Algo.hxx:79
bool _supportSubmeshes
Definition: SMESH_Algo.hxx:448
std::list< TopoDS_Shape > _assigedShapeList
Definition: SMESH_Algo.hxx:439
bool NeedDiscreteBoundary() const
Definition: SMESH_Algo.hxx:267
double _progress
Definition: SMESH_Algo.hxx:462
bool _requireShape
Definition: SMESH_Algo.hxx:447
virtual bool Evaluate(SMESH_Mesh &aMesh, const TopoDS_Shape &aShape, MapShapeNbElems &aResMap)=0
evaluates size of prospective mesh on a shape
std::vector< SMESH_subMesh * > & SubMeshesToCompute()
Return a vector of sub-meshes to Compute()
Definition: SMESH_Algo.hxx:248
const SMDS_Mesh * _mesh
mesh being computed, needed to create SMESH_BadInputElements
Definition: SMESH_Algo.hxx:458
std::list< const SMESHDS_Hypothesis * > _usedHypList
Definition: SMESH_Algo.hxx:438
EMeshError
Definition: SMESH_Algo.hxx:401
int _progressTic
Definition: SMESH_Algo.hxx:464
bool SupportSubmeshes() const
Definition: SMESH_Algo.hxx:273
bool _quadraticMesh
Definition: SMESH_Algo.hxx:453
volatile bool _computeCanceled
is set to True while computing to stop it
Definition: SMESH_Algo.hxx:460
bool NeedShape() const
Definition: SMESH_Algo.hxx:270
virtual bool CheckHypothesis(SMESH_Mesh &aMesh, const TopoDS_Shape &aShape, SMESH_Hypothesis::Hypothesis_Status &aStatus)=0
Check hypothesis definition to mesh a shape.
int _error
SMESH_ComputeErrorName or anything algo specific.
Definition: SMESH_Algo.hxx:455
std::list< const SMDS_MeshElement * > _badInputElements
to explain COMPERR_BAD_INPUT_MESH
Definition: SMESH_Algo.hxx:457
const SMESH_HypoFilter * _compatibleAllHypFilter
Definition: SMESH_Algo.hxx:435
std::vector< SMESH_subMesh * > _smToCompute
Definition: SMESH_Algo.hxx:465
static bool IsContinuous(const TopoDS_Edge &E1, const TopoDS_Edge &E2)
Return true if an edge can be considered as a continuation of another.
Definition: SMESH_Algo.hxx:358
bool NeedLowerHyps(int dim) const
Definition: SMESH_Algo.hxx:276
bool error(const SMESH_Comment &comment="")
store COMPERR_ALGO_FAILED error and comment and then return false
Definition: SMESH_Algo.hxx:417
virtual void setSubMeshesToCompute(SMESH_subMesh *aSubMesh)
Definition: SMESH_Algo.hxx:282
bool OnlyUnaryInput() const
Definition: SMESH_Algo.hxx:259
virtual bool Compute(SMESH_Mesh &aMesh, const TopoDS_Shape &aShape)=0
Computes mesh on a shape.
const Features & GetFeatures() const
Definition: SMESH_Algo.hxx:100
bool _onlyUnaryInput
Definition: SMESH_Algo.hxx:445
std::string _comment
any text explaining what is wrong in Compute()
Definition: SMESH_Algo.hxx:456
const SMESH_HypoFilter * _compatibleNoAuxHypFilter
Definition: SMESH_Algo.hxx:436
std::vector< std::string > _compatibleHypothesis
Definition: SMESH_Algo.hxx:437
bool _requireDiscreteBoundary
Definition: SMESH_Algo.hxx:446
Class to generate string from any type.
Definition: SMESH_Comment.hxx:37
Definition: SMESH_Gen.hxx:68
Definition: SMESH_HypoFilter.hxx:57
Definition: SMESH_Hypothesis.hxx:48
Hypothesis_Status
Definition: SMESH_Hypothesis.hxx:51
virtual bool SetParametersByDefaults(const TDefaults &dflts, const SMESH_Mesh *theMesh=0)=0
Initialize my parameter values by default parameters.
virtual bool SetParametersByMesh(const SMESH_Mesh *theMesh, const TopoDS_Shape &theShape)=0
Initialize my parameter values by the mesh built on the geometry.
Definition: SMESH_Mesh.hxx:80
It helps meshers to add elements and provides other utilities.
Definition: SMESH_MesherHelper.hxx:84
Container of xD mesh elements substituting other ones in the input mesh of an (x+1)D algorithm.
Definition: SMESH_ProxyMesh.hxx:51
Definition: SMESH_subMesh.hxx:61
void SetEventListener(SMESH_subMesh *subMesh, TopoDS_Shape srcShape, SMESH_Mesh *srcMesh)
Set event listeners to submesh with projection algo.
Definition: StdMeshers_ProjectionUtils.cxx:2546
Structure describing algorithm features.
Definition: SMESH_Algo.hxx:87
std::set< SMDSAbs_GeometryType > _inElemTypes
Definition: SMESH_Algo.hxx:89
std::set< SMDSAbs_GeometryType > _outElemTypes
Definition: SMESH_Algo.hxx:90
std::string _label
Definition: SMESH_Algo.hxx:91
int _dim
Definition: SMESH_Algo.hxx:88
Features()
Definition: SMESH_Algo.hxx:93
Definition: SMESH_Hypothesis.hxx:100