Version: 8.3.0
SMESH_Algo.hxx
Go to the documentation of this file.
1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, 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 : implementaion 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 
33 #include "SMDSAbs_ElementType.hxx"
34 #include "SMESH_Comment.hxx"
35 #include "SMESH_ComputeError.hxx"
36 #include "SMESH_Hypothesis.hxx"
37 
38 #include <GeomAbs_Shape.hxx>
39 
40 #include <string>
41 #include <vector>
42 #include <list>
43 #include <map>
44 #include <set>
45 
46 class SMDS_MeshNode;
47 class SMESHDS_Mesh;
48 class SMESHDS_SubMesh;
49 class SMESH_Gen;
50 class SMESH_HypoFilter;
51 class SMESH_Mesh;
52 class SMESH_MesherHelper;
53 class SMESH_ProxyMesh;
54 class SMESH_subMesh;
55 class TopoDS_Edge;
56 class TopoDS_Face;
57 class TopoDS_Shape;
58 class TopoDS_Vertex;
59 class TopoDS_Wire;
60 class gp_XYZ;
61 
62 typedef std::map< SMESH_subMesh*, std::vector<int> > MapShapeNbElems;
63 typedef std::map< SMESH_subMesh*, std::vector<int> >::iterator MapShapeNbElemsItr;
64 
65 // ==================================================================================
75 // ==================================================================================
76 
78 {
79  public:
80  //==================================================================================
84  // --------------------------------------------------------------------------------
85  struct Features
86  {
87  int _dim;
88  std::set<SMDSAbs_GeometryType> _inElemTypes; // acceptable types of input mesh element
89  std::set<SMDSAbs_GeometryType> _outElemTypes; // produced types of mesh elements
90  std::string _label; // GUI type name
91 
92  bool IsCompatible( const Features& algo2 ) const;
93  };
97  static const Features& GetFeatures( const std::string& algoType );
98  const Features& GetFeatures() const { return GetFeatures( _name ); }
99 
100  public:
101  //==================================================================================
108  SMESH_Algo(int hypId, int studyId, SMESH_Gen * gen);
109 
113  virtual ~ SMESH_Algo();
114 
120  virtual std::ostream & SaveTo(std::ostream & save);
121 
127  virtual std::istream & LoadFrom(std::istream & load);
128 
132  const std::vector < std::string > & GetCompatibleHypothesis();
133 
143  virtual bool CheckHypothesis(SMESH_Mesh& aMesh,
144  const TopoDS_Shape& aShape,
156  virtual bool Compute(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape) = 0;
157 
166  virtual bool Compute(SMESH_Mesh & aMesh, SMESH_MesherHelper* aHelper);
167 
172  virtual void CancelCompute();
173 
177  virtual double GetProgress() const;
178 
186  virtual bool Evaluate(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape,
187  MapShapeNbElems& aResMap) = 0;
188 
202  virtual const std::list <const SMESHDS_Hypothesis *> &
203  GetUsedHypothesis(SMESH_Mesh & aMesh,
204  const TopoDS_Shape & aShape,
205  const bool ignoreAuxiliary=true) const;
217  const std::list <const SMESHDS_Hypothesis *> &
218  GetAppliedHypothesis(SMESH_Mesh & aMesh,
219  const TopoDS_Shape & aShape,
220  const bool ignoreAuxiliary=true) const;
226  const SMESH_HypoFilter* GetCompatibleHypoFilter(const bool ignoreAuxiliary) const;
227 
231  virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape);
232  virtual bool SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh=0);
233 
237  SMESH_ComputeErrorPtr GetComputeError() const;
241  void InitComputeError();
245  double GetProgressByTic() const;
249  std::vector<SMESH_subMesh*>& SubMeshesToCompute() { return _smToCompute; }
250 
251 public:
252  // ==================================================================
253  // Algo features influencing how Compute() is called:
254  // in what turn and with what input shape
255  // ==================================================================
256 
257  // SMESH_Hypothesis::GetDim();
258  // 1 - dimension of target mesh
259 
260  bool OnlyUnaryInput() const { return _onlyUnaryInput; }
261  // 2 - is collection of tesselatable shapes inacceptable as input;
262  // "collection" means a shape containing shapes of dim equal
263  // to GetDim().
264  // Algo which can process a collection shape should expect
265  // an input temporary shape that is neither MainShape nor
266  // its child.
267 
268  bool NeedDiscreteBoundary() const { return _requireDiscreteBoundary; }
269  // 3 - is a Dim-1 mesh prerequisite
270 
271  bool NeedShape() const { return _requireShape; }
272  // 4 - is shape existence required
273 
274  bool SupportSubmeshes() const { return _supportSubmeshes; }
275  // 5 - whether supports submeshes if !NeedDiscreteBoundary()
276 
277  bool NeedLowerHyps(int dim) const { return _neededLowerHyps[ dim ]; }
278  // 6 - if algo !NeedDiscreteBoundary() but requires presence of
279  // hypotheses of dimension <dim> to generate all-dimensional mesh.
280  // This info is used not to issue warnings on hiding of lower global algos.
281 
282 public:
283  // ==================================================================
284  // Methods to track non hierarchical dependencies between submeshes
285  // ==================================================================
286 
295  virtual void SetEventListener(SMESH_subMesh* subMesh);
296 
303  virtual void SubmeshRestored(SMESH_subMesh* subMesh);
304 
305 public:
306  // ==================================================================
307  // Common algo utilities
308  // ==================================================================
317  static bool GetNodeParamOnEdge(const SMESHDS_Mesh* theMesh,
318  const TopoDS_Edge& theEdge,
319  std::vector< double > & theParams);
330  static bool GetSortedNodesOnEdge(const SMESHDS_Mesh* theMesh,
331  const TopoDS_Edge& theEdge,
332  const bool ignoreMediumNodes,
333  std::map< double, const SMDS_MeshNode* > & theNodes,
334  const SMDSAbs_ElementType typeToCheck = SMDSAbs_All);
335 
341  static double EdgeLength(const TopoDS_Edge & E);
342 
343  int NumberOfPoints(SMESH_Mesh& aMesh,const TopoDS_Wire& W);
344 
351  static GeomAbs_Shape Continuity(const TopoDS_Edge& E1, const TopoDS_Edge& E2);
352 
356  static bool IsContinuous(const TopoDS_Edge & E1, const TopoDS_Edge & E2) {
357  return ( Continuity( E1, E2 ) >= GeomAbs_G1 );
358  }
362  static bool IsStraight( const TopoDS_Edge & E, const bool degenResult=false );
366  static bool isDegenerated( const TopoDS_Edge & E, const bool checkLength=false );
367 
374  static const SMDS_MeshNode* VertexNode(const TopoDS_Vertex& V, const SMESHDS_Mesh* meshDS);
375 
383  static const SMDS_MeshNode* VertexNode(const TopoDS_Vertex& V, const SMESH_Mesh* mesh);
384 
394  static const SMDS_MeshNode* VertexNode(const TopoDS_Vertex& V,
395  const SMESHDS_SubMesh* edgeSM,
396  const SMESH_Mesh* mesh,
397  const bool checkV=true);
398 
399  enum EMeshError { MEr_OK = 0, MEr_HOLES, MEr_BAD_ORI, MEr_EMPTY };
400 
404  static EMeshError GetMeshError(SMESH_subMesh* subMesh);
405 
406  protected:
407 
411  bool error(int error, const SMESH_Comment& comment = "");
415  bool error(const SMESH_Comment& comment = "")
416  { return error(COMPERR_ALGO_FAILED, comment); }
420  bool error(SMESH_ComputeErrorPtr error);
426  void addBadInputElement(const SMDS_MeshElement* elem);
427 
428  void addBadInputElements(const SMESHDS_SubMesh* sm,
429  const bool addNodes=false);
430 
431 protected:
432 
435  std::vector<std::string> _compatibleHypothesis;
436  std::list<const SMESHDS_Hypothesis *> _appliedHypList;
437  std::list<const SMESHDS_Hypothesis *> _usedHypList;
438 
439 
440  // Algo features influencing which Compute() and how is called:
441  // in what turn and with what input shape.
442  // These fields must be redefined if necessary by each descendant at constructor.
443  bool _onlyUnaryInput; // mesh one shape of GetDim() at once. Default TRUE
444  bool _requireDiscreteBoundary;// GetDim()-1 mesh must be present. Default TRUE
445  bool _requireShape; // work with GetDim()-1 mesh bound to geom only. Default TRUE
446  bool _supportSubmeshes; // if !_requireDiscreteBoundary. Default FALSE
447  bool _neededLowerHyps[4]; // hyp dims needed by algo that !_requireDiscreteBoundary. Df. FALSE
448 
449  // indicates if quadratic mesh creation is required,
450  // is usually set like this: _quadraticMesh = SMESH_MesherHelper::IsQuadraticSubMesh(shape)
452 
453  int _error;
454  std::string _comment;
455  std::list<const SMDS_MeshElement*> _badInputElements;
456 
457  volatile bool _computeCanceled;
458 
459  double _progress; /* progress of Compute() [0.,1.],
460  to be set by an algo really tracking the progress */
461  int _progressTic; // counter of calls from SMESH_Mesh::GetComputeProgress()
462  std::vector<SMESH_subMesh*> _smToCompute; // sub-meshes to Compute()
463 };
464 
465 
467 {
468 public:
469  SMESH_0D_Algo(int hypId, int studyId, SMESH_Gen* gen);
470 };
471 
473 {
474 public:
475  SMESH_1D_Algo(int hypId, int studyId, SMESH_Gen* gen);
476 };
477 
479 {
480 public:
481  SMESH_2D_Algo(int hypId, int studyId, SMESH_Gen* gen);
487  virtual bool FixInternalNodes(const SMESH_ProxyMesh& mesh,
488  const TopoDS_Face& face);
489 };
490 
492 {
493 public:
494  SMESH_3D_Algo(int hypId, int studyId, SMESH_Gen* gen);
495 };
496 
497 #endif