SALOME - SMESH
SMESH_Algo.hxx
Go to the documentation of this file.
1 // Copyright (C) 2007-2008 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.
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 // SMESH SMESH : implementaion of SMESH idl descriptions
23 // File : SMESH_Algo.hxx
24 // Author : Paul RASCLE, EDF
25 // Module : SMESH
26 //
27 
28 #ifndef _SMESH_ALGO_HXX_
29 #define _SMESH_ALGO_HXX_
30 
31 #include "SMESH_SMESH.hxx"
32 
33 #include "SMESH_Hypothesis.hxx"
34 #include "SMESH_ComputeError.hxx"
35 #include "SMESH_Comment.hxx"
36 
37 #include <TopoDS_Shape.hxx>
38 #include <TopoDS_Edge.hxx>
39 #include <GeomAbs_Shape.hxx>
40 
41 #include <string>
42 #include <vector>
43 #include <list>
44 #include <map>
45 
46 class SMESH_Gen;
47 class SMESH_Mesh;
48 class SMESH_HypoFilter;
49 class TopoDS_Vertex;
50 class TopoDS_Face;
51 class TopoDS_Shape;
52 class SMESHDS_Mesh;
53 class SMDS_MeshNode;
54 class SMESH_subMesh;
55 class SMESH_MesherHelper;
56 
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;
60 
62 {
63 public:
70  SMESH_Algo(int hypId, int studyId, SMESH_Gen * gen);
71 
75  virtual ~ SMESH_Algo();
76 
82  virtual std::ostream & SaveTo(std::ostream & save);
83 
89  virtual std::istream & LoadFrom(std::istream & load);
90 
94  const std::vector < std::string > & GetCompatibleHypothesis();
95 
103  virtual bool CheckHypothesis(SMESH_Mesh& aMesh,
104  const TopoDS_Shape& aShape,
116  virtual bool Compute(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape) = 0;
117 
126  virtual bool Compute(SMESH_Mesh & aMesh, SMESH_MesherHelper* aHelper);
127 
135  virtual bool Evaluate(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape,
136  MapShapeNbElems& aResMap) = 0;
137 
151  virtual const std::list <const SMESHDS_Hypothesis *> &
153  const TopoDS_Shape & aShape,
154  const bool ignoreAuxiliary=true);
166  const std::list <const SMESHDS_Hypothesis *> &
168  const TopoDS_Shape & aShape,
169  const bool ignoreAuxiliary=true);
177  const bool ignoreAuxiliary) const;
181  virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape);
182  virtual bool SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh=0);
191 
192 public:
193  // ==================================================================
194  // Algo features influencing how Compute() is called:
195  // in what turn and with what input shape
196  // ==================================================================
197 
198  // SMESH_Hypothesis::GetDim();
199  // 1 - dimention of target mesh
200 
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
204  // to GetDim().
205  // Algo which can process a collection shape should expect
206  // an input temporary shape that is neither MainShape nor
207  // its child.
208 
209  bool NeedDescretBoundary() const { return _requireDescretBoundary; }
210  // 3 - is a Dim-1 mesh prerequisite
211 
212  bool NeedShape() const { return _requireShape; }
213  // 4 - is shape existance required
214 
215  bool SupportSubmeshes() const { return _supportSubmeshes; }
216  // 5 - whether supports submeshes if !NeedDescretBoundary()
217 
218 
219 public:
220  // ==================================================================
221  // Methods to track non hierarchical dependencies between submeshes
222  // ==================================================================
223 
232  virtual void SetEventListener(SMESH_subMesh* subMesh);
233 
240  virtual void SubmeshRestored(SMESH_subMesh* subMesh);
241 
242 public:
243  // ==================================================================
244  // Common algo utilities
245  // ==================================================================
253  static bool GetNodeParamOnEdge(const SMESHDS_Mesh* theMesh,
254  const TopoDS_Edge& theEdge,
255  std::vector< double > & theParams);
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);
275  static bool IsReversedSubMesh (const TopoDS_Face& theFace,
276  SMESHDS_Mesh* theMeshDS);
282  static double EdgeLength(const TopoDS_Edge & E);
283 
290  static GeomAbs_Shape Continuity(const TopoDS_Edge & E1, const TopoDS_Edge & E2);
291 
295  static bool IsContinuous(const TopoDS_Edge & E1, const TopoDS_Edge & E2) {
296  return ( Continuity( E1, E2 ) >= GeomAbs_G1 );
297  }
298 
305  static const SMDS_MeshNode* VertexNode(const TopoDS_Vertex& V,
306  const SMESHDS_Mesh* meshDS);
307 
308 protected:
309 
313  bool error(int error, const SMESH_Comment& comment = "");
317  bool error(const SMESH_Comment& comment = "")
318  { return error(COMPERR_ALGO_FAILED, comment); }
329 
330 protected:
331 
332  std::vector<std::string> _compatibleHypothesis;
333  std::list<const SMESHDS_Hypothesis *> _appliedHypList;
334  std::list<const SMESHDS_Hypothesis *> _usedHypList;
335 
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
343 
344  // quadratic mesh creation required,
345  // is usually set trough SMESH_MesherHelper::IsQuadraticSubMesh()
347 
348  int _error;
349  std::string _comment;
350  std::list<const SMDS_MeshElement*> _badInputElements;
351 };
352 
353 #endif
std::map< SMESH_subMesh *, std::vector< int > >::iterator MapShapeNbElemsItr
Definition: SMESH_Algo.hxx:59
std::map< SMESH_subMesh *, std::vector< int > > MapShapeNbElems
Definition: SMESH_Algo.hxx:55
@ COMPERR_ALGO_FAILED
algo failed for some reason
boost::shared_ptr< SMESH_ComputeError > SMESH_ComputeErrorPtr
#define SMESH_EXPORT
Definition: SMESH_SMESH.hxx:36
Base class for elements.
bool _supportSubmeshes
Definition: SMESH_Algo.hxx:342
static double EdgeLength(const TopoDS_Edge &E)
Compute length of an edge.
virtual bool SetParametersByMesh(const SMESH_Mesh *theMesh, const TopoDS_Shape &theShape)
Just return false as the algorithm does not hold parameters values.
static bool GetSortedNodesOnEdge(const SMESHDS_Mesh *theMesh, const TopoDS_Edge &theEdge, const bool ignoreMediumNodes, std::map< double, const SMDS_MeshNode * > &theNodes)
Fill map of node parameter on geometrical edge to node it-self.
bool NeedDescretBoundary() const
Definition: SMESH_Algo.hxx:209
bool _requireShape
Definition: SMESH_Algo.hxx:341
static bool GetNodeParamOnEdge(const SMESHDS_Mesh *theMesh, const TopoDS_Edge &theEdge, std::vector< double > &theParams)
Fill vector of node parameters on geometrical edge, including vertex nodes.
virtual bool Evaluate(SMESH_Mesh &aMesh, const TopoDS_Shape &aShape, MapShapeNbElems &aResMap)=0
evaluates size of prospective mesh on a shape
SMESH_ComputeErrorPtr GetComputeError() const
return compute error
std::list< const SMESHDS_Hypothesis * > _usedHypList
Definition: SMESH_Algo.hxx:334
virtual bool SetParametersByDefaults(const TDefaults &dflts, const SMESH_Mesh *theMesh=0)
Initialize my parameter values by default parameters.
bool error(SMESH_ComputeErrorPtr error)
store error and return error->IsOK()
std::list< const SMESHDS_Hypothesis * > _appliedHypList
Definition: SMESH_Algo.hxx:333
virtual void SubmeshRestored(SMESH_subMesh *subMesh)
Allow algo to do something after persistent restoration.
bool SupportSubmeshes() const
Definition: SMESH_Algo.hxx:215
const std::vector< std::string > & GetCompatibleHypothesis()
Returns all types of compatible hypotheses.
bool _quadraticMesh
Definition: SMESH_Algo.hxx:346
void addBadInputElement(const SMDS_MeshElement *elem)
store a bad input element preventing computation, which may be a temporary one i.e....
bool NeedShape() const
Definition: SMESH_Algo.hxx:212
virtual std::ostream & SaveTo(std::ostream &save)
Saves nothing in a stream.
virtual bool CheckHypothesis(SMESH_Mesh &aMesh, const TopoDS_Shape &aShape, SMESH_Hypothesis::Hypothesis_Status &aStatus)=0
Check hypothesis definition to mesh a shape.
virtual bool Compute(SMESH_Mesh &aMesh, SMESH_MesherHelper *aHelper)
Computes mesh without geometry.
int _error
SMESH_ComputeErrorName or anything algo specific.
Definition: SMESH_Algo.hxx:348
std::list< const SMDS_MeshElement * > _badInputElements
to explain COMPERR_BAD_INPUT_MESH
Definition: SMESH_Algo.hxx:350
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:295
static const SMDS_MeshNode * VertexNode(const TopoDS_Vertex &V, const SMESHDS_Mesh *meshDS)
Return the node built on a vertex.
static GeomAbs_Shape Continuity(const TopoDS_Edge &E1, const TopoDS_Edge &E2)
Return continuity of two edges.
virtual void SetEventListener(SMESH_subMesh *subMesh)
Sets event listener to submeshes if necessary.
bool _requireDescretBoundary
Definition: SMESH_Algo.hxx:340
bool error(const SMESH_Comment &comment="")
store COMPERR_ALGO_FAILED error and comment and then return false
Definition: SMESH_Algo.hxx:317
const std::list< const SMESHDS_Hypothesis * > & GetAppliedHypothesis(SMESH_Mesh &aMesh, const TopoDS_Shape &aShape, const bool ignoreAuxiliary=true)
Returns a list of compatible hypotheses assigned to a shape in a mesh.
SMESH_Algo(int hypId, int studyId, SMESH_Gen *gen)
Creates algorithm.
virtual const std::list< const SMESHDS_Hypothesis * > & GetUsedHypothesis(SMESH_Mesh &aMesh, const TopoDS_Shape &aShape, const bool ignoreAuxiliary=true)
Returns a list of compatible hypotheses used to mesh a shape.
bool OnlyUnaryInput() const
Definition: SMESH_Algo.hxx:201
virtual bool Compute(SMESH_Mesh &aMesh, const TopoDS_Shape &aShape)=0
Computes mesh on a shape.
virtual std::istream & LoadFrom(std::istream &load)
Loads nothing from a stream.
bool _onlyUnaryInput
Definition: SMESH_Algo.hxx:339
std::string _comment
any text explaining what is wrong in Compute()
Definition: SMESH_Algo.hxx:349
bool error(int error, const SMESH_Comment &comment="")
store error and comment and then return ( error == COMPERR_OK )
bool InitCompatibleHypoFilter(SMESH_HypoFilter &theFilter, const bool ignoreAuxiliary) const
Make the filter recognize only compatible hypotheses.
virtual ~ SMESH_Algo()
Destructor.
std::vector< std::string > _compatibleHypothesis
Definition: SMESH_Algo.hxx:332
void InitComputeError()
initialize compute error
static bool IsReversedSubMesh(const TopoDS_Face &theFace, SMESHDS_Mesh *theMeshDS)
Find out elements orientation on a geometrical face.
Class to generate string from any type.