src/Controls/SMESH_ControlsDef.hxx

Go to the documentation of this file.
00001 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00002 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
00003 // 
00004 //  This library is free software; you can redistribute it and/or 
00005 //  modify it under the terms of the GNU Lesser General Public 
00006 //  License as published by the Free Software Foundation; either 
00007 //  version 2.1 of the License. 
00008 // 
00009 //  This library is distributed in the hope that it will be useful, 
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
00012 //  Lesser General Public License for more details. 
00013 // 
00014 //  You should have received a copy of the GNU Lesser General Public 
00015 //  License along with this library; if not, write to the Free Software 
00016 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
00017 // 
00018 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00019 
00020 #ifndef _SMESH_CONTROLSDEF_HXX_
00021 #define _SMESH_CONTROLSDEF_HXX_
00022 
00023 #include <set>
00024 #include <map>
00025 #include <vector>
00026 #include <boost/shared_ptr.hpp>
00027 #include <gp_XYZ.hxx>
00028 //#include <Geom_Surface.hxx>
00029 #include <GeomAPI_ProjectPointOnSurf.hxx>
00030 #include <TColStd_SequenceOfInteger.hxx>
00031 #include <TColStd_MapOfInteger.hxx>
00032 #include <TCollection_AsciiString.hxx>
00033 #include <TopoDS_Face.hxx>
00034 
00035 #include "SMDSAbs_ElementType.hxx"
00036 #include "SMDS_MeshNode.hxx"
00037 
00038 #include "SMESH_Controls.hxx"
00039 
00040 class SMDS_MeshElement;
00041 class SMDS_MeshFace;
00042 class SMDS_MeshNode;
00043 class SMDS_Mesh;
00044 
00045 class SMESHDS_Mesh;
00046 class SMESHDS_SubMesh;
00047 
00048 class gp_Pnt;
00049 //class TopoDS_Shape;
00050 
00051 
00052 namespace SMESH{
00053   namespace Controls{
00054 
00055     class TSequenceOfXYZ: public std::vector<gp_XYZ>
00056     {
00057     public:
00058       typedef std::vector<gp_XYZ> TSuperClass;
00059       TSequenceOfXYZ()
00060       {}
00061 
00062       TSequenceOfXYZ(size_type n):
00063      TSuperClass(n)
00064       {}
00065 
00066       TSequenceOfXYZ(size_type n, const value_type& t):
00067      TSuperClass(n,t)
00068       {}
00069 
00070       TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ):
00071      TSuperClass(theSequenceOfXYZ)
00072       {}
00073 
00074       template <class InputIterator>
00075       TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd):
00076      TSuperClass(theBegin,theEnd)
00077       {}
00078 
00079       TSequenceOfXYZ& operator=(const TSequenceOfXYZ& theSequenceOfXYZ){
00080      TSuperClass::operator=(theSequenceOfXYZ);
00081      return *this;
00082       }
00083 
00084       reference operator()(size_type n){
00085      return TSuperClass::operator[](n-1);
00086       }
00087 
00088       const_reference operator()(size_type n) const{
00089      return TSuperClass::operator[](n-1);
00090       }
00091 
00092     private:
00093       reference operator[](size_type n);
00094 
00095       const_reference operator[](size_type n) const;
00096     };
00097 
00098     /*
00099       Class       : Functor
00100       Description : Root of all Functors
00101     */
00102     class Functor
00103     {
00104     public:
00105       ~Functor(){}
00106       virtual void SetMesh( const SMDS_Mesh* theMesh ) = 0;
00107       virtual SMDSAbs_ElementType GetType() const = 0;
00108     };
00109 
00110     /*
00111       Class       : NumericalFunctor
00112       Description : Root of all Functors returning numeric value
00113     */
00114     class NumericalFunctor: public virtual Functor{
00115     public:
00116       NumericalFunctor();
00117       virtual void SetMesh( const SMDS_Mesh* theMesh );
00118       virtual double GetValue( long theElementId );
00119       virtual double GetValue(const TSequenceOfXYZ& thePoints) { return -1.0;};
00120       virtual SMDSAbs_ElementType GetType() const = 0;
00121       virtual double GetBadRate( double Value, int nbNodes ) const = 0;
00122       long  GetPrecision() const;
00123       void  SetPrecision( const long thePrecision );
00124       
00125       bool GetPoints(const int theId, 
00126                TSequenceOfXYZ& theRes) const;
00127       static bool GetPoints(const SMDS_MeshElement* theElem, 
00128                    TSequenceOfXYZ& theRes);
00129     protected:
00130       const SMDS_Mesh* myMesh;
00131       const SMDS_MeshElement* myCurrElement;
00132       long       myPrecision;
00133     };
00134   
00135   
00136     /*
00137       Class       : Volume
00138       Description : Functor calculating volume of 3D mesh element
00139     */
00140     class Volume: public virtual NumericalFunctor{
00141     public:
00142       virtual double GetValue( long theElementId );
00143       //virtual double GetValue( const TSequenceOfXYZ& thePoints );
00144       virtual double GetBadRate( double Value, int nbNodes ) const;
00145       virtual SMDSAbs_ElementType GetType() const;
00146     };
00147   
00148   
00149     /*
00150       Class       : SMESH_MinimumAngle
00151       Description : Functor for calculation of minimum angle
00152     */
00153     class MinimumAngle: public virtual NumericalFunctor{
00154     public:
00155       virtual double GetValue( const TSequenceOfXYZ& thePoints );
00156       virtual double GetBadRate( double Value, int nbNodes ) const;
00157       virtual SMDSAbs_ElementType GetType() const;
00158     };
00159   
00160   
00161     /*
00162       Class       : AspectRatio
00163       Description : Functor for calculating aspect ratio
00164     */
00165     class AspectRatio: public virtual NumericalFunctor{
00166     public:
00167       virtual double GetValue( const TSequenceOfXYZ& thePoints );
00168       virtual double GetBadRate( double Value, int nbNodes ) const;
00169       virtual SMDSAbs_ElementType GetType() const;
00170     };
00171   
00172   
00173     /*
00174       Class       : AspectRatio3D
00175       Description : Functor for calculating aspect ratio of 3D elems.
00176     */
00177     class AspectRatio3D: public virtual NumericalFunctor{
00178     public:
00179       virtual double GetValue( const TSequenceOfXYZ& thePoints );
00180       virtual double GetBadRate( double Value, int nbNodes ) const;
00181       virtual SMDSAbs_ElementType GetType() const;
00182     };
00183   
00184   
00185     /*
00186       Class       : Warping
00187       Description : Functor for calculating warping
00188     */
00189     class Warping: public virtual NumericalFunctor{
00190     public:
00191       virtual double GetValue( const TSequenceOfXYZ& thePoints );
00192       virtual double GetBadRate( double Value, int nbNodes ) const;
00193       virtual SMDSAbs_ElementType GetType() const;
00194       
00195     private:
00196       double ComputeA( const gp_XYZ&, const gp_XYZ&, const gp_XYZ&, const gp_XYZ& ) const;
00197     };
00198   
00199   
00200     /*
00201       Class       : Taper
00202       Description : Functor for calculating taper
00203     */
00204     class Taper: public virtual NumericalFunctor{
00205     public:
00206       virtual double GetValue( const TSequenceOfXYZ& thePoints );
00207       virtual double GetBadRate( double Value, int nbNodes ) const;
00208       virtual SMDSAbs_ElementType GetType() const;
00209     };
00210     
00211   
00212     /*
00213       Class       : Skew
00214       Description : Functor for calculating skew in degrees
00215     */
00216     class Skew: public virtual NumericalFunctor{
00217     public:
00218       virtual double GetValue( const TSequenceOfXYZ& thePoints );
00219       virtual double GetBadRate( double Value, int nbNodes ) const;
00220       virtual SMDSAbs_ElementType GetType() const;
00221     };
00222   
00223     
00224     /*
00225       Class       : Area
00226       Description : Functor for calculating area
00227     */
00228     class Area: public virtual NumericalFunctor{
00229     public:
00230       virtual double GetValue( const TSequenceOfXYZ& thePoints );
00231       virtual double GetBadRate( double Value, int nbNodes ) const;
00232       virtual SMDSAbs_ElementType GetType() const;
00233     };
00234   
00235   
00236     /*
00237       Class       : Length
00238       Description : Functor for calculating length of edge
00239     */
00240     class Length: public virtual NumericalFunctor{
00241     public:
00242       virtual double GetValue( const TSequenceOfXYZ& thePoints );
00243       virtual double GetBadRate( double Value, int nbNodes ) const;
00244       virtual SMDSAbs_ElementType GetType() const;
00245     };
00246   
00247     /*
00248       Class       : Length2D
00249       Description : Functor for calculating length of edge
00250     */
00251     class Length2D: public virtual NumericalFunctor{
00252     public:
00253       virtual double GetValue( long theElementId );
00254       virtual double GetBadRate( double Value, int nbNodes ) const;
00255       virtual SMDSAbs_ElementType GetType() const;
00256       struct Value{
00257      double myLength;
00258      long myPntId[2];
00259      Value(double theLength, long thePntId1, long thePntId2);
00260      bool operator<(const Value& x) const;
00261       };
00262       typedef std::set<Value> TValues;
00263       void GetValues(TValues& theValues);
00264       
00265     };
00266     typedef boost::shared_ptr<Length2D> Length2DPtr;
00267 
00268     /*
00269       Class       : MultiConnection
00270       Description : Functor for calculating number of faces conneted to the edge
00271     */
00272     class MultiConnection: public virtual NumericalFunctor{
00273     public:
00274       virtual double GetValue( long theElementId );
00275       virtual double GetValue( const TSequenceOfXYZ& thePoints );
00276       virtual double GetBadRate( double Value, int nbNodes ) const;
00277       virtual SMDSAbs_ElementType GetType() const;
00278     };
00279     
00280     /*
00281       Class       : MultiConnection2D
00282       Description : Functor for calculating number of faces conneted to the edge
00283     */
00284     class MultiConnection2D: public virtual NumericalFunctor{
00285     public:
00286       virtual double GetValue( long theElementId );
00287       virtual double GetValue( const TSequenceOfXYZ& thePoints );
00288       virtual double GetBadRate( double Value, int nbNodes ) const;
00289       virtual SMDSAbs_ElementType GetType() const;
00290       struct Value{
00291      long myPntId[2];
00292      Value(long thePntId1, long thePntId2);
00293      bool operator<(const Value& x) const;
00294       };
00295       typedef std::map<Value,int> MValues;
00296 
00297       void GetValues(MValues& theValues);
00298     };
00299     typedef boost::shared_ptr<MultiConnection2D> MultiConnection2DPtr;
00300     /*
00301       PREDICATES
00302     */
00303     /*
00304       Class       : Predicate
00305       Description : Base class for all predicates
00306     */
00307     class Predicate: public virtual Functor{
00308     public:
00309       virtual bool IsSatisfy( long theElementId ) = 0;
00310       virtual SMDSAbs_ElementType GetType() const = 0;
00311     };
00312     
00313   
00314   
00315     /*
00316       Class       : FreeBorders
00317       Description : Predicate for free borders
00318     */
00319     class FreeBorders: public virtual Predicate{
00320     public:
00321       FreeBorders();
00322       virtual void SetMesh( const SMDS_Mesh* theMesh );
00323       virtual bool IsSatisfy( long theElementId );
00324       virtual SMDSAbs_ElementType GetType() const;
00325             
00326     protected:
00327       const SMDS_Mesh* myMesh;
00328     };
00329    
00330 
00331     /*
00332       Class       : BadOrientedVolume
00333       Description : Predicate bad oriented volumes
00334     */
00335     class BadOrientedVolume: public virtual Predicate{
00336     public:
00337       BadOrientedVolume();
00338       virtual void SetMesh( const SMDS_Mesh* theMesh );
00339       virtual bool IsSatisfy( long theElementId );
00340       virtual SMDSAbs_ElementType GetType() const;
00341             
00342     protected:
00343       const SMDS_Mesh* myMesh;
00344     };
00345    
00346 
00347     /*
00348       Class       : FreeEdges
00349       Description : Predicate for free Edges
00350     */
00351     class FreeEdges: public virtual Predicate{
00352     public:
00353       FreeEdges();
00354       virtual void SetMesh( const SMDS_Mesh* theMesh );
00355       virtual bool IsSatisfy( long theElementId );
00356       virtual SMDSAbs_ElementType GetType() const;
00357       static bool IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId  );
00358       typedef long TElemId;
00359       struct Border{
00360      TElemId myElemId;
00361      TElemId myPntId[2];
00362      Border(long theElemId, long thePntId1, long thePntId2);
00363      bool operator<(const Border& x) const;
00364       };
00365       typedef std::set<Border> TBorders;
00366       void GetBoreders(TBorders& theBorders);
00367       
00368     protected:
00369       const SMDS_Mesh* myMesh;
00370     };
00371     typedef boost::shared_ptr<FreeEdges> FreeEdgesPtr;
00372 
00373 
00374     /*
00375       Class       : RangeOfIds
00376       Description : Predicate for Range of Ids.
00377                     Range may be specified with two ways.
00378                     1. Using AddToRange method
00379                     2. With SetRangeStr method. Parameter of this method is a string
00380                        like as "1,2,3,50-60,63,67,70-"
00381     */
00382     class RangeOfIds: public virtual Predicate
00383     {
00384     public:
00385                                     RangeOfIds();
00386       virtual void                  SetMesh( const SMDS_Mesh* theMesh );
00387       virtual bool                  IsSatisfy( long theNodeId );
00388       virtual SMDSAbs_ElementType   GetType() const;
00389       virtual void                  SetType( SMDSAbs_ElementType theType );
00390 
00391       bool                          AddToRange( long theEntityId );
00392       void                          GetRangeStr( TCollection_AsciiString& );
00393       bool                          SetRangeStr( const TCollection_AsciiString& );
00394 
00395     protected:
00396       const SMDS_Mesh*              myMesh;
00397 
00398       TColStd_SequenceOfInteger     myMin;
00399       TColStd_SequenceOfInteger     myMax;
00400       TColStd_MapOfInteger          myIds;
00401 
00402       SMDSAbs_ElementType           myType;
00403     };
00404     
00405     typedef boost::shared_ptr<RangeOfIds> RangeOfIdsPtr;
00406    
00407     
00408     /*
00409       Class       : Comparator
00410       Description : Base class for comparators
00411     */
00412     class Comparator: public virtual Predicate{
00413     public:
00414       Comparator();
00415       virtual ~Comparator();
00416       virtual void SetMesh( const SMDS_Mesh* theMesh );
00417       virtual void SetMargin(double theValue);
00418       virtual void SetNumFunctor(NumericalFunctorPtr theFunct);
00419       virtual bool IsSatisfy( long theElementId ) = 0;
00420       virtual SMDSAbs_ElementType GetType() const;
00421       double  GetMargin();
00422   
00423     protected:
00424       double myMargin;
00425       NumericalFunctorPtr myFunctor;
00426     };
00427     typedef boost::shared_ptr<Comparator> ComparatorPtr;
00428   
00429   
00430     /*
00431       Class       : LessThan
00432       Description : Comparator "<"
00433     */
00434     class LessThan: public virtual Comparator{
00435     public:
00436       virtual bool IsSatisfy( long theElementId );
00437     };
00438   
00439   
00440     /*
00441       Class       : MoreThan
00442       Description : Comparator ">"
00443     */
00444     class MoreThan: public virtual Comparator{
00445     public:
00446       virtual bool IsSatisfy( long theElementId );
00447     };
00448   
00449   
00450     /*
00451       Class       : EqualTo
00452       Description : Comparator "="
00453     */
00454     class EqualTo: public virtual Comparator{
00455     public:
00456       EqualTo();
00457       virtual bool IsSatisfy( long theElementId );
00458       virtual void SetTolerance( double theTol );
00459       virtual double GetTolerance();
00460   
00461     private:
00462       double myToler;
00463     };
00464     typedef boost::shared_ptr<EqualTo> EqualToPtr;
00465   
00466     
00467     /*
00468       Class       : LogicalNOT
00469       Description : Logical NOT predicate
00470     */
00471     class LogicalNOT: public virtual Predicate{
00472     public:
00473       LogicalNOT();
00474       virtual ~LogicalNOT();
00475       virtual bool IsSatisfy( long theElementId );
00476       virtual void SetMesh( const SMDS_Mesh* theMesh );
00477       virtual void SetPredicate(PredicatePtr thePred);
00478       virtual SMDSAbs_ElementType GetType() const;
00479   
00480     private:
00481       PredicatePtr myPredicate;
00482     };
00483     typedef boost::shared_ptr<LogicalNOT> LogicalNOTPtr;
00484     
00485   
00486     /*
00487       Class       : LogicalBinary
00488       Description : Base class for binary logical predicate
00489     */
00490     class LogicalBinary: public virtual Predicate{
00491     public:
00492       LogicalBinary();
00493       virtual ~LogicalBinary();
00494       virtual void SetMesh( const SMDS_Mesh* theMesh );
00495       virtual void SetPredicate1(PredicatePtr thePred);
00496       virtual void SetPredicate2(PredicatePtr thePred);
00497       virtual SMDSAbs_ElementType GetType() const;
00498   
00499     protected:
00500       PredicatePtr myPredicate1;
00501       PredicatePtr myPredicate2;
00502     };
00503     typedef boost::shared_ptr<LogicalBinary> LogicalBinaryPtr;
00504   
00505   
00506     /*
00507       Class       : LogicalAND
00508       Description : Logical AND
00509     */
00510     class LogicalAND: public virtual LogicalBinary{
00511     public:
00512       virtual bool IsSatisfy( long theElementId );
00513     };
00514   
00515   
00516     /*
00517       Class       : LogicalOR
00518       Description : Logical OR
00519     */
00520     class LogicalOR: public virtual LogicalBinary{
00521     public:
00522       virtual bool IsSatisfy( long theElementId );
00523     };
00524   
00525   
00526     /*
00527       Class       : ManifoldPart
00528       Description : Predicate for manifold part of mesh
00529     */
00530     class ManifoldPart: public virtual Predicate{
00531     public:
00532 
00533       /* internal class for algorithm uses */
00534       class Link
00535       {
00536       public:
00537         Link( SMDS_MeshNode* theNode1,
00538               SMDS_MeshNode* theNode2 );
00539         ~Link();
00540         
00541         bool IsEqual( const ManifoldPart::Link& theLink ) const;
00542         bool operator<(const ManifoldPart::Link& x) const;
00543         
00544         SMDS_MeshNode* myNode1;
00545         SMDS_MeshNode* myNode2;
00546       };
00547 
00548       bool IsEqual( const ManifoldPart::Link& theLink1,
00549                     const ManifoldPart::Link& theLink2 );
00550       
00551       typedef std::set<ManifoldPart::Link>                TMapOfLink;
00552       typedef std::vector<SMDS_MeshFace*>                 TVectorOfFacePtr;
00553       typedef std::vector<ManifoldPart::Link>             TVectorOfLink;
00554       typedef std::map<SMDS_MeshFace*,int>                TDataMapFacePtrInt;
00555       typedef std::map<ManifoldPart::Link,SMDS_MeshFace*> TDataMapOfLinkFacePtr;
00556       
00557       ManifoldPart();
00558       ~ManifoldPart();
00559       virtual void SetMesh( const SMDS_Mesh* theMesh );
00560       // inoke when all parameters already set
00561       virtual bool IsSatisfy( long theElementId );
00562       virtual      SMDSAbs_ElementType GetType() const;
00563 
00564       void    SetAngleTolerance( const double theAngToler );
00565       double  GetAngleTolerance() const;
00566       void    SetIsOnlyManifold( const bool theIsOnly );
00567       void    SetStartElem( const long  theStartElemId );
00568 
00569     private:
00570       bool    process();
00571       bool    findConnected( const TDataMapFacePtrInt& theAllFacePtrInt,
00572                              SMDS_MeshFace*            theStartFace,
00573                              TMapOfLink&               theNonManifold,
00574                              TColStd_MapOfInteger&     theResFaces );
00575       bool    isInPlane( const SMDS_MeshFace* theFace1,
00576                           const SMDS_MeshFace* theFace2 );
00577       void    expandBoundary( TMapOfLink&            theMapOfBoundary,
00578                               TVectorOfLink&         theSeqOfBoundary,
00579                               TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
00580                               TMapOfLink&            theNonManifold,
00581                               SMDS_MeshFace*         theNextFace ) const;
00582 
00583      void     getFacesByLink( const Link& theLink,
00584                               TVectorOfFacePtr& theFaces ) const;
00585 
00586     private:
00587       const SMDS_Mesh*      myMesh;
00588       TColStd_MapOfInteger  myMapIds;
00589       TColStd_MapOfInteger  myMapBadGeomIds;
00590       TVectorOfFacePtr      myAllFacePtr;
00591       TDataMapFacePtrInt    myAllFacePtrIntDMap;
00592       double                myAngToler;
00593       bool                  myIsOnlyManifold;
00594       long                  myStartElemId;
00595 
00596     };
00597     typedef boost::shared_ptr<ManifoldPart> ManifoldPartPtr;
00598                          
00599 
00600     /*
00601       Class       : ElementsOnSurface
00602       Description : Predicate elements that lying on indicated surface
00603                     (plane or cylinder)
00604     */
00605     class ElementsOnSurface : public virtual Predicate {
00606     public:
00607       ElementsOnSurface();
00608       ~ElementsOnSurface();
00609       virtual void SetMesh( const SMDS_Mesh* theMesh );
00610       virtual bool IsSatisfy( long theElementId );
00611       virtual      SMDSAbs_ElementType GetType() const;
00612 
00613       void    SetTolerance( const double theToler );
00614       double  GetTolerance() const;
00615       void    SetSurface( const TopoDS_Shape& theShape,
00616                           const SMDSAbs_ElementType theType );
00617       void    SetUseBoundaries( bool theUse );
00618       bool    GetUseBoundaries() const { return myUseBoundaries; }
00619 
00620     private:
00621       void    process();
00622       void    process( const SMDS_MeshElement* theElem  );
00623       bool    isOnSurface( const SMDS_MeshNode* theNode );
00624 
00625     private:
00626       const SMDS_Mesh*      myMesh;
00627       TColStd_MapOfInteger  myIds;
00628       SMDSAbs_ElementType   myType;
00629       //Handle(Geom_Surface)  mySurf;
00630       TopoDS_Face           mySurf;
00631       double                myToler;
00632       bool                  myUseBoundaries;
00633       GeomAPI_ProjectPointOnSurf myProjector;
00634     };
00635     
00636     typedef boost::shared_ptr<ElementsOnSurface> ElementsOnSurfacePtr;
00637       
00638 
00639     /*
00640       FILTER
00641     */
00642     class Filter{
00643     public:
00644       Filter();
00645       virtual ~Filter();
00646       virtual void SetPredicate(PredicatePtr thePred);
00647 
00648       typedef std::vector<long> TIdSequence;
00649 
00650       virtual 
00651       void
00652       GetElementsId( const SMDS_Mesh* theMesh,
00653                TIdSequence& theSequence );
00654 
00655       static
00656       void
00657       GetElementsId( const SMDS_Mesh* theMesh, 
00658                PredicatePtr thePredicate,
00659                TIdSequence& theSequence );
00660       
00661     protected:
00662       PredicatePtr myPredicate;
00663     };
00664   };  
00665 };
00666 
00667 
00668 #endif