Back to index

salome-smesh  6.5.0
SMESH_Algo.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SMESH SMESH : implementaion of SMESH idl descriptions
00024 //  File   : SMESH_Algo.hxx
00025 //  Author : Paul RASCLE, EDF
00026 //  Module : SMESH
00027 //
00028 #ifndef _SMESH_ALGO_HXX_
00029 #define _SMESH_ALGO_HXX_
00030 
00031 #include "SMESH_SMESH.hxx"
00032 
00033 #include "SMESH_Hypothesis.hxx"
00034 #include "SMESH_ComputeError.hxx"
00035 #include "SMESH_Comment.hxx"
00036 
00037 #include <TopoDS_Shape.hxx>
00038 #include <TopoDS_Edge.hxx>
00039 #include <GeomAbs_Shape.hxx>
00040 
00041 #include <string>
00042 #include <vector>
00043 #include <list>
00044 #include <map>
00045 
00046 class SMESH_Gen;
00047 class SMESH_Mesh;
00048 class SMESH_HypoFilter;
00049 class TopoDS_Vertex;
00050 class TopoDS_Face;
00051 class TopoDS_Shape;
00052 class SMESHDS_Mesh;
00053 class SMDS_MeshNode;
00054 class SMESH_subMesh;
00055 class SMESH_MesherHelper;
00056 class gp_XYZ;
00057 
00058 typedef std::map< SMESH_subMesh*, std::vector<int> >           MapShapeNbElems;
00059 typedef std::map< SMESH_subMesh*, std::vector<int> >::iterator MapShapeNbElemsItr;
00060 
00070 class SMESH_EXPORT SMESH_Algo:public SMESH_Hypothesis
00071 {
00072 public:
00079   SMESH_Algo(int hypId, int studyId, SMESH_Gen * gen);
00080 
00084   virtual ~ SMESH_Algo();
00085 
00091   virtual std::ostream & SaveTo(std::ostream & save);
00092 
00098   virtual std::istream & LoadFrom(std::istream & load);
00099 
00103   const std::vector < std::string > & GetCompatibleHypothesis();
00104 
00112   virtual bool CheckHypothesis(SMESH_Mesh&                          aMesh,
00113                                const TopoDS_Shape&                  aShape,
00114                                SMESH_Hypothesis::Hypothesis_Status& aStatus) = 0;
00125   virtual bool Compute(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape) = 0;
00126 
00135   virtual bool Compute(SMESH_Mesh & aMesh, SMESH_MesherHelper* aHelper);
00136 
00137 #ifdef WITH_SMESH_CANCEL_COMPUTE
00138   virtual void CancelCompute();
00139 #endif
00140 
00148   virtual bool Evaluate(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape,
00149                         MapShapeNbElems& aResMap) = 0;
00150 
00164   virtual const std::list <const SMESHDS_Hypothesis *> &
00165   GetUsedHypothesis(SMESH_Mesh &         aMesh,
00166                     const TopoDS_Shape & aShape,
00167                     const bool           ignoreAuxiliary=true);
00179   const list <const SMESHDS_Hypothesis *> &
00180   GetAppliedHypothesis(SMESH_Mesh &         aMesh,
00181                        const TopoDS_Shape & aShape,
00182                        const bool           ignoreAuxiliary=true);
00189   bool InitCompatibleHypoFilter( SMESH_HypoFilter & theFilter,
00190                                  const bool         ignoreAuxiliary) const;
00194   virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape);
00195   virtual bool SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh=0);
00199   SMESH_ComputeErrorPtr GetComputeError() const;
00203   void InitComputeError();
00204 
00205 public:
00206   // ==================================================================
00207   // Algo features influencing how Compute() is called:
00208   // in what turn and with what input shape
00209   // ==================================================================
00210 
00211   // SMESH_Hypothesis::GetDim();
00212   // 1 - dimention of target mesh
00213 
00214   bool OnlyUnaryInput() const { return _onlyUnaryInput; }
00215   // 2 - is collection of tesselatable shapes inacceptable as input;
00216   // "collection" means a shape containing shapes of dim equal
00217   // to GetDim().
00218   // Algo which can process a collection shape should expect
00219   // an input temporary shape that is neither MainShape nor
00220   // its child.
00221 
00222   bool NeedDiscreteBoundary() const { return _requireDiscreteBoundary; }
00223   // 3 - is a Dim-1 mesh prerequisite
00224 
00225   bool NeedShape() const { return _requireShape; }
00226   // 4 - is shape existance required
00227 
00228   bool SupportSubmeshes() const { return _supportSubmeshes; }
00229   // 5 - whether supports submeshes if !NeedDiscreteBoundary()
00230 
00231 
00232 public:
00233   // ==================================================================
00234   // Methods to track non hierarchical dependencies between submeshes 
00235   // ==================================================================
00236 
00245   virtual void SetEventListener(SMESH_subMesh* subMesh);
00246   
00253   virtual void SubmeshRestored(SMESH_subMesh* subMesh);
00254   
00255 public:
00256   // ==================================================================
00257   // Common algo utilities
00258   // ==================================================================
00266   static bool GetNodeParamOnEdge(const SMESHDS_Mesh*     theMesh,
00267                                  const TopoDS_Edge&      theEdge,
00268                                  std::vector< double > & theParams);
00277   static bool GetSortedNodesOnEdge(const SMESHDS_Mesh*                        theMesh,
00278                                    const TopoDS_Edge&                         theEdge,
00279                                    const bool                                 ignoreMediumNodes,
00280                                    std::map< double, const SMDS_MeshNode* > & theNodes);
00288   static bool IsReversedSubMesh (const TopoDS_Face&  theFace,
00289                                  SMESHDS_Mesh*       theMeshDS);
00295   static double EdgeLength(const TopoDS_Edge & E);
00296 
00300   static bool FaceNormal(const SMDS_MeshElement* F, gp_XYZ& normal, bool normalized=true);
00301 
00308   static GeomAbs_Shape Continuity(TopoDS_Edge E1, TopoDS_Edge E2);
00309 
00313   static bool IsContinuous(const TopoDS_Edge & E1, const TopoDS_Edge & E2) {
00314     return ( Continuity( E1, E2 ) >= GeomAbs_G1 );
00315   }
00316 
00323   static const SMDS_MeshNode* VertexNode(const TopoDS_Vertex& V, const SMESHDS_Mesh* meshDS);
00324 
00328   static std::vector< const SMDS_MeshNode*> GetCommonNodes(const SMDS_MeshElement* e1,
00329                                                            const SMDS_MeshElement* e2);
00330 
00331   enum EMeshError { MEr_OK = 0, MEr_HOLES, MEr_BAD_ORI, MEr_EMPTY };
00332 
00336   static EMeshError GetMeshError(SMESH_subMesh* subMesh);
00337 
00338  protected:
00339 
00343   bool error(int error, const SMESH_Comment& comment = "");
00347   bool error(const SMESH_Comment& comment = "")
00348   { return error(COMPERR_ALGO_FAILED, comment); }
00352   bool error(SMESH_ComputeErrorPtr error);
00358   void addBadInputElement(const SMDS_MeshElement* elem);
00359 
00360 protected:
00361 
00362   std::vector<std::string>              _compatibleHypothesis;
00363   std::list<const SMESHDS_Hypothesis *> _appliedHypList;
00364   std::list<const SMESHDS_Hypothesis *> _usedHypList;
00365 
00366   // Algo features influencing which Compute() and how is called:
00367   // in what turn and with what input shape.
00368   // These fields must be redefined if necessary by each descendant at constructor.
00369   bool _onlyUnaryInput;         // mesh one shape of GetDim() at once. Default TRUE
00370   bool _requireDiscreteBoundary; // GetDim()-1 mesh must be present. Default TRUE
00371   bool _requireShape;           // work with GetDim()-1 mesh bound to geom only. Default TRUE
00372   bool _supportSubmeshes;       // if !_requireDiscreteBoundary. Default FALSE
00373 
00374   // quadratic mesh creation required,
00375   // is usually set trough SMESH_MesherHelper::IsQuadraticSubMesh()
00376   bool _quadraticMesh;
00377 
00378   int         _error;    
00379   std::string _comment;  
00380   std::list<const SMDS_MeshElement*> _badInputElements; 
00381 };
00382 
00383 #endif