SALOME - SMESH
SMESH_Algo.hxx
Go to the documentation of this file.
00001 //  Copyright (C) 2007-2008  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 //  SMESH SMESH : implementaion of SMESH idl descriptions
00023 //  File   : SMESH_Algo.hxx
00024 //  Author : Paul RASCLE, EDF
00025 //  Module : SMESH
00026 //
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 
00057 typedef std::map< SMESH_subMesh*, std::vector<int> > MapShapeNbElems;
00058 // vector must have size corresponding to EntityType_Last from SMDSAbs:
00059 typedef std::map< SMESH_subMesh*, std::vector<int> >::iterator MapShapeNbElemsItr;
00060 
00061 class SMESH_EXPORT SMESH_Algo:public SMESH_Hypothesis
00062 {
00063 public:
00070   SMESH_Algo(int hypId, int studyId, SMESH_Gen * gen);
00071 
00075   virtual ~ SMESH_Algo();
00076 
00082   virtual std::ostream & SaveTo(std::ostream & save);
00083 
00089   virtual std::istream & LoadFrom(std::istream & load);
00090 
00094   const std::vector < std::string > & GetCompatibleHypothesis();
00095 
00103   virtual bool CheckHypothesis(SMESH_Mesh&                          aMesh,
00104                                const TopoDS_Shape&                  aShape,
00105                                SMESH_Hypothesis::Hypothesis_Status& aStatus) = 0;
00116   virtual bool Compute(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape) = 0;
00117 
00126   virtual bool Compute(SMESH_Mesh & aMesh, SMESH_MesherHelper* aHelper);
00127 
00135   virtual bool Evaluate(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape,
00136                         MapShapeNbElems& aResMap) = 0;
00137 
00151   virtual const std::list <const SMESHDS_Hypothesis *> &
00152   GetUsedHypothesis(SMESH_Mesh &         aMesh,
00153                     const TopoDS_Shape & aShape,
00154                     const bool           ignoreAuxiliary=true);
00166   const std::list <const SMESHDS_Hypothesis *> &
00167   GetAppliedHypothesis(SMESH_Mesh &         aMesh,
00168                        const TopoDS_Shape & aShape,
00169                        const bool           ignoreAuxiliary=true);
00176   bool InitCompatibleHypoFilter( SMESH_HypoFilter & theFilter,
00177                                  const bool         ignoreAuxiliary) const;
00181   virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape);
00182   virtual bool SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh=0);
00186   SMESH_ComputeErrorPtr GetComputeError() const;
00190   void InitComputeError();
00191 
00192 public:
00193   // ==================================================================
00194   // Algo features influencing how Compute() is called:
00195   // in what turn and with what input shape
00196   // ==================================================================
00197 
00198   // SMESH_Hypothesis::GetDim();
00199   // 1 - dimention of target mesh
00200 
00201   bool OnlyUnaryInput() const { return _onlyUnaryInput; }
00202   // 2 - is collection of tesselatable shapes inacceptable as input;
00203   // "collection" means a shape containing shapes of dim equal
00204   // to GetDim().
00205   // Algo which can process a collection shape should expect
00206   // an input temporary shape that is neither MainShape nor
00207   // its child.
00208 
00209   bool NeedDescretBoundary() const { return _requireDescretBoundary; }
00210   // 3 - is a Dim-1 mesh prerequisite
00211 
00212   bool NeedShape() const { return _requireShape; }
00213   // 4 - is shape existance required
00214 
00215   bool SupportSubmeshes() const { return _supportSubmeshes; }
00216   // 5 - whether supports submeshes if !NeedDescretBoundary()
00217 
00218 
00219 public:
00220   // ==================================================================
00221   // Methods to track non hierarchical dependencies between submeshes 
00222   // ==================================================================
00223 
00232   virtual void SetEventListener(SMESH_subMesh* subMesh);
00233   
00240   virtual void SubmeshRestored(SMESH_subMesh* subMesh);
00241   
00242 public:
00243   // ==================================================================
00244   // Common algo utilities
00245   // ==================================================================
00253   static bool GetNodeParamOnEdge(const SMESHDS_Mesh*     theMesh,
00254                                  const TopoDS_Edge&      theEdge,
00255                                  std::vector< double > & theParams);
00264   static bool GetSortedNodesOnEdge(const SMESHDS_Mesh*                        theMesh,
00265                                    const TopoDS_Edge&                         theEdge,
00266                                    const bool                                 ignoreMediumNodes,
00267                                    std::map< double, const SMDS_MeshNode* > & theNodes);
00275   static bool IsReversedSubMesh (const TopoDS_Face&  theFace,
00276                                  SMESHDS_Mesh*       theMeshDS);
00282   static double EdgeLength(const TopoDS_Edge & E);
00283 
00290   static GeomAbs_Shape Continuity(const TopoDS_Edge & E1, const TopoDS_Edge & E2);
00291 
00295   static bool IsContinuous(const TopoDS_Edge & E1, const TopoDS_Edge & E2) {
00296     return ( Continuity( E1, E2 ) >= GeomAbs_G1 );
00297   }
00298 
00305   static const SMDS_MeshNode* VertexNode(const TopoDS_Vertex& V,
00306                                          const SMESHDS_Mesh* meshDS);
00307 
00308 protected:
00309 
00313   bool error(int error, const SMESH_Comment& comment = "");
00317   bool error(const SMESH_Comment& comment = "")
00318   { return error(COMPERR_ALGO_FAILED, comment); }
00322   bool error(SMESH_ComputeErrorPtr error);
00328   void addBadInputElement(const SMDS_MeshElement* elem);
00329 
00330 protected:
00331 
00332   std::vector<std::string>              _compatibleHypothesis;
00333   std::list<const SMESHDS_Hypothesis *> _appliedHypList;
00334   std::list<const SMESHDS_Hypothesis *> _usedHypList;
00335 
00336   // Algo features influencing which Compute() and how is called:
00337   // in what turn and with what input shape.
00338   // This fields must be redefined if necessary by each descendant at constructor.
00339   bool _onlyUnaryInput;         // mesh one shape of GetDim() at once. Default TRUE
00340   bool _requireDescretBoundary; // GetDim()-1 mesh must be present. Default TRUE
00341   bool _requireShape;           // work with GetDim()-1 mesh bound to geom only. Default TRUE
00342   bool _supportSubmeshes;       // if !_requireDescretBoundary. Default FALSE
00343 
00344   // quadratic mesh creation required,
00345   // is usually set trough SMESH_MesherHelper::IsQuadraticSubMesh()
00346   bool _quadraticMesh;
00347 
00348   int         _error;    
00349   std::string _comment;  
00350   std::list<const SMDS_MeshElement*> _badInputElements; 
00351 };
00352 
00353 #endif
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines