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