Salome HOME
Integration of PAL/SALOME V2.1.0c from OCC
[modules/smesh.git] / src / Controls / SMESH_Controls.hxx
1 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
3 // 
4 //  This library is free software; you can redistribute it and/or 
5 //  modify it under the terms of the GNU Lesser General Public 
6 //  License as published by the Free Software Foundation; either 
7 //  version 2.1 of the License. 
8 // 
9 //  This library is distributed in the hope that it will be useful, 
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 //  Lesser General Public License for more details. 
13 // 
14 //  You should have received a copy of the GNU Lesser General Public 
15 //  License along with this library; if not, write to the Free Software 
16 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
17 // 
18 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
19
20 #ifndef _SMESH_CONTROLS_HXX_
21 #define _SMESH_CONTROLS_HXX_
22
23 #include <set>
24 #include <map>
25 #include <vector>
26 #include <boost/shared_ptr.hpp>
27 #include "SMDSAbs_ElementType.hxx"
28 #include "SMDS_MeshNode.hxx"
29 #include <Geom_Surface.hxx>
30 #include <TColStd_SequenceOfInteger.hxx>
31 #include <TColStd_MapOfInteger.hxx>
32 #include <TCollection_AsciiString.hxx>
33
34 class SMDS_Mesh;
35 class SMESHDS_Mesh;
36 class SMESHDS_SubMesh;
37 class gp_Pnt;
38 class gp_XYZ;
39 class TColgp_SequenceOfXYZ;
40 class TopoDS_Shape;
41 class SMDS_MeshElement;
42 class SMDS_MeshFace;
43 class SMDS_MeshNode;
44
45 namespace SMESH{
46   namespace Controls{
47     class Functor
48     {
49     public:
50       ~Functor(){}
51       virtual void SetMesh( SMDS_Mesh* theMesh ) = 0;
52       virtual SMDSAbs_ElementType GetType() const = 0;
53     };
54     typedef boost::shared_ptr<Functor> FunctorPtr;
55
56     class NumericalFunctor: public virtual Functor{
57     public:
58       NumericalFunctor();
59       virtual void SetMesh( SMDS_Mesh* theMesh );
60       virtual double GetValue( long theElementId );
61       virtual double GetValue( const TColgp_SequenceOfXYZ& thePoints ) = 0;
62       virtual SMDSAbs_ElementType GetType() const = 0;
63       virtual double GetBadRate( double Value, int nbNodes ) const = 0;
64       long  GetPrecision() const;
65       void  SetPrecision( const long thePrecision );
66       
67       bool GetPoints (const int             theId, 
68                       TColgp_SequenceOfXYZ& theRes ) const;
69       static bool GetPoints (const SMDS_MeshElement* theElem, 
70                              TColgp_SequenceOfXYZ&    theRes );
71     protected:
72       SMDS_Mesh* myMesh;
73       long       myPrecision;
74     };
75     typedef boost::shared_ptr<NumericalFunctor> NumericalFunctorPtr;
76   
77   
78     /*
79       Class       : SMESH_MinimumAngle
80       Description : Functor for calculation of minimum angle
81     */
82     class MinimumAngle: public virtual NumericalFunctor{
83     public:
84       virtual double GetValue( const TColgp_SequenceOfXYZ& thePoints );
85       virtual double GetBadRate( double Value, int nbNodes ) const;
86       virtual SMDSAbs_ElementType GetType() const;
87     };
88   
89   
90     /*
91       Class       : AspectRatio
92       Description : Functor for calculating aspect ratio
93     */
94     class AspectRatio: public virtual NumericalFunctor{
95     public:
96       virtual double GetValue( const TColgp_SequenceOfXYZ& thePoints );
97       virtual double GetBadRate( double Value, int nbNodes ) const;
98       virtual SMDSAbs_ElementType GetType() const;
99     };
100   
101   
102     /*
103       Class       : AspectRatio3D
104       Description : Functor for calculating aspect ratio of 3D elems.
105     */
106     class AspectRatio3D: public virtual NumericalFunctor{
107     public:
108       virtual double GetValue( const TColgp_SequenceOfXYZ& thePoints );
109       virtual double GetBadRate( double Value, int nbNodes ) const;
110       virtual SMDSAbs_ElementType GetType() const;
111     };
112   
113   
114     /*
115       Class       : Warping
116       Description : Functor for calculating warping
117     */
118     class Warping: public virtual NumericalFunctor{
119     public:
120       virtual double GetValue( const TColgp_SequenceOfXYZ& thePoints );
121       virtual double GetBadRate( double Value, int nbNodes ) const;
122       virtual SMDSAbs_ElementType GetType() const;
123       
124     private:
125       double ComputeA( const gp_XYZ&, const gp_XYZ&, const gp_XYZ&, const gp_XYZ& ) const;
126     };
127   
128   
129     /*
130       Class       : Taper
131       Description : Functor for calculating taper
132     */
133     class Taper: public virtual NumericalFunctor{
134     public:
135       virtual double GetValue( const TColgp_SequenceOfXYZ& thePoints );
136       virtual double GetBadRate( double Value, int nbNodes ) const;
137       virtual SMDSAbs_ElementType GetType() const;
138     };
139     
140   
141     /*
142       Class       : Skew
143       Description : Functor for calculating skew in degrees
144     */
145     class Skew: public virtual NumericalFunctor{
146     public:
147       virtual double GetValue( const TColgp_SequenceOfXYZ& thePoints );
148       virtual double GetBadRate( double Value, int nbNodes ) const;
149       virtual SMDSAbs_ElementType GetType() const;
150     };
151   
152     
153     /*
154       Class       : Area
155       Description : Functor for calculating area
156     */
157     class Area: public virtual NumericalFunctor{
158     public:
159       virtual double GetValue( const TColgp_SequenceOfXYZ& thePoints );
160       virtual double GetBadRate( double Value, int nbNodes ) const;
161       virtual SMDSAbs_ElementType GetType() const;
162     };
163   
164   
165     /*
166       Class       : Length
167       Description : Functor for calculating length of edge
168     */
169     class Length: public virtual NumericalFunctor{
170     public:
171       virtual double GetValue( const TColgp_SequenceOfXYZ& thePoints );
172       virtual double GetBadRate( double Value, int nbNodes ) const;
173       virtual SMDSAbs_ElementType GetType() const;
174     };
175   
176   
177     /*
178       Class       : MultiConnection
179       Description : Functor for calculating number of faces conneted to the edge
180     */
181     class MultiConnection: public virtual NumericalFunctor{
182     public:
183       virtual double GetValue( long theElementId );
184       virtual double GetValue( const TColgp_SequenceOfXYZ& thePoints );
185       virtual double GetBadRate( double Value, int nbNodes ) const;
186       virtual SMDSAbs_ElementType GetType() const;
187     };
188     
189   
190     /*
191       PREDICATES
192     */
193     /*
194       Class       : Predicate
195       Description : Base class for all predicates
196     */
197     class Predicate: public virtual Functor{
198     public:
199       virtual bool IsSatisfy( long theElementId ) = 0;
200       virtual SMDSAbs_ElementType GetType() const = 0;
201     };
202     typedef boost::shared_ptr<Predicate> PredicatePtr;
203     
204   
205   
206     /*
207       Class       : FreeBorders
208       Description : Predicate for free borders
209     */
210     class FreeBorders: public virtual Predicate{
211     public:
212       FreeBorders();
213       virtual void SetMesh( SMDS_Mesh* theMesh );
214       virtual bool IsSatisfy( long theElementId );
215       virtual SMDSAbs_ElementType GetType() const;
216             
217     protected:
218       SMDS_Mesh* myMesh;
219     };
220    
221
222     /*
223       Class       : FreeEdges
224       Description : Predicate for free Edges
225     */
226     class FreeEdges: public virtual Predicate{
227     public:
228       FreeEdges();
229       virtual void SetMesh( SMDS_Mesh* theMesh );
230       virtual bool IsSatisfy( long theElementId );
231       virtual SMDSAbs_ElementType GetType() const;
232       static bool IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId  );
233       typedef long TElemId;
234       struct Border{
235         TElemId myElemId;
236         TElemId myPntId[2];
237         Border(long theElemId, long thePntId1, long thePntId2);
238         bool operator<(const Border& x) const;
239       };
240       typedef std::set<Border> TBorders;
241       void GetBoreders(TBorders& theBorders);
242       
243     protected:
244       SMDS_Mesh* myMesh;
245     };
246     typedef boost::shared_ptr<FreeEdges> FreeEdgesPtr;
247
248
249     /*
250       Class       : RangeOfIds
251       Description : Predicate for Range of Ids.
252                     Range may be specified with two ways.
253                     1. Using AddToRange method
254                     2. With SetRangeStr method. Parameter of this method is a string
255                        like as "1,2,3,50-60,63,67,70-"
256     */
257     class RangeOfIds: public virtual Predicate
258     {
259     public:
260                                     RangeOfIds();
261       virtual void                  SetMesh( SMDS_Mesh* theMesh );
262       virtual bool                  IsSatisfy( long theNodeId );
263       virtual SMDSAbs_ElementType   GetType() const;
264       virtual void                  SetType( SMDSAbs_ElementType theType );
265
266       bool                          AddToRange( long theEntityId );
267       void                          GetRangeStr( TCollection_AsciiString& );
268       bool                          SetRangeStr( const TCollection_AsciiString& );
269
270     protected:
271       SMDS_Mesh*                    myMesh;
272
273       TColStd_SequenceOfInteger     myMin;
274       TColStd_SequenceOfInteger     myMax;
275       TColStd_MapOfInteger          myIds;
276
277       SMDSAbs_ElementType           myType;
278     };
279     
280     typedef boost::shared_ptr<RangeOfIds> RangeOfIdsPtr;
281    
282     
283     /*
284       Class       : Comparator
285       Description : Base class for comparators
286     */
287     class Comparator: public virtual Predicate{
288     public:
289       Comparator();
290       virtual ~Comparator();
291       virtual void SetMesh( SMDS_Mesh* theMesh );
292       virtual void SetMargin(double theValue);
293       virtual void SetNumFunctor(NumericalFunctorPtr theFunct);
294       virtual bool IsSatisfy( long theElementId ) = 0;
295       virtual SMDSAbs_ElementType GetType() const;
296       double  GetMargin();
297   
298     protected:
299       double myMargin;
300       NumericalFunctorPtr myFunctor;
301     };
302     typedef boost::shared_ptr<Comparator> ComparatorPtr;
303   
304   
305     /*
306       Class       : LessThan
307       Description : Comparator "<"
308     */
309     class LessThan: public virtual Comparator{
310     public:
311       virtual bool IsSatisfy( long theElementId );
312     };
313   
314   
315     /*
316       Class       : MoreThan
317       Description : Comparator ">"
318     */
319     class MoreThan: public virtual Comparator{
320     public:
321       virtual bool IsSatisfy( long theElementId );
322     };
323   
324   
325     /*
326       Class       : EqualTo
327       Description : Comparator "="
328     */
329     class EqualTo: public virtual Comparator{
330     public:
331       EqualTo();
332       virtual bool IsSatisfy( long theElementId );
333       virtual void SetTolerance( double theTol );
334       virtual double GetTolerance();
335   
336     private:
337       double myToler;
338     };
339     typedef boost::shared_ptr<EqualTo> EqualToPtr;
340   
341     
342     /*
343       Class       : LogicalNOT
344       Description : Logical NOT predicate
345     */
346     class LogicalNOT: public virtual Predicate{
347     public:
348       LogicalNOT();
349       virtual ~LogicalNOT();
350       virtual bool IsSatisfy( long theElementId );
351       virtual void SetMesh( SMDS_Mesh* theMesh );
352       virtual void SetPredicate(PredicatePtr thePred);
353       virtual SMDSAbs_ElementType GetType() const;
354   
355     private:
356       PredicatePtr myPredicate;
357     };
358     typedef boost::shared_ptr<LogicalNOT> LogicalNOTPtr;
359     
360   
361     /*
362       Class       : LogicalBinary
363       Description : Base class for binary logical predicate
364     */
365     class LogicalBinary: public virtual Predicate{
366     public:
367       LogicalBinary();
368       virtual ~LogicalBinary();
369       virtual void SetMesh( SMDS_Mesh* theMesh );
370       virtual void SetPredicate1(PredicatePtr thePred);
371       virtual void SetPredicate2(PredicatePtr thePred);
372       virtual SMDSAbs_ElementType GetType() const;
373   
374     protected:
375       PredicatePtr myPredicate1;
376       PredicatePtr myPredicate2;
377     };
378     typedef boost::shared_ptr<LogicalBinary> LogicalBinaryPtr;
379   
380   
381     /*
382       Class       : LogicalAND
383       Description : Logical AND
384     */
385     class LogicalAND: public virtual LogicalBinary{
386     public:
387       virtual bool IsSatisfy( long theElementId );
388     };
389   
390   
391     /*
392       Class       : LogicalOR
393       Description : Logical OR
394     */
395     class LogicalOR: public virtual LogicalBinary{
396     public:
397       virtual bool IsSatisfy( long theElementId );
398     };
399   
400   
401     /*
402       Class       : ManifoldPart
403       Description : Predicate for manifold part of mesh
404     */
405     class ManifoldPart: public virtual Predicate{
406     public:
407
408       /* internal class for algorithm uses */
409       class Link
410       {
411       public:
412         Link( SMDS_MeshNode* theNode1,
413               SMDS_MeshNode* theNode2 );
414         ~Link();
415         
416         bool IsEqual( const ManifoldPart::Link& theLink ) const;
417         bool operator<(const ManifoldPart::Link& x) const;
418         
419         SMDS_MeshNode* myNode1;
420         SMDS_MeshNode* myNode2;
421       };
422
423       bool IsEqual( const ManifoldPart::Link& theLink1,
424                     const ManifoldPart::Link& theLink2 );
425       
426       typedef std::set<ManifoldPart::Link>                TMapOfLink;
427       typedef std::vector<SMDS_MeshFace*>                 TVectorOfFacePtr;
428       typedef std::vector<ManifoldPart::Link>             TVectorOfLink;
429       typedef std::map<SMDS_MeshFace*,int>                TDataMapFacePtrInt;
430       typedef std::map<ManifoldPart::Link,SMDS_MeshFace*> TDataMapOfLinkFacePtr;
431       
432       ManifoldPart();
433       ~ManifoldPart();
434       virtual void SetMesh( SMDS_Mesh* theMesh );
435       // inoke when all parameters already set
436       virtual bool IsSatisfy( long theElementId );
437       virtual      SMDSAbs_ElementType GetType() const;
438
439       void    SetAngleTolerance( const double theAngToler );
440       double  GetAngleTolerance() const;
441       void    SetIsOnlyManifold( const bool theIsOnly );
442       void    SetStartElem( const long  theStartElemId );
443
444     private:
445       bool    process();
446       bool    findConnected( const TDataMapFacePtrInt& theAllFacePtrInt,
447                              SMDS_MeshFace*            theStartFace,
448                              TMapOfLink&               theNonManifold,
449                              TColStd_MapOfInteger&     theResFaces );
450       bool    isInPlane( const SMDS_MeshFace* theFace1,
451                           const SMDS_MeshFace* theFace2 );
452       void    expandBoundary( TMapOfLink&            theMapOfBoundary,
453                               TVectorOfLink&         theSeqOfBoundary,
454                               TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
455                               TMapOfLink&            theNonManifold,
456                               SMDS_MeshFace*         theNextFace ) const;
457
458      void     getFacesByLink( const Link& theLink,
459                               TVectorOfFacePtr& theFaces ) const;
460
461     private:
462       SMDS_Mesh*            myMesh;
463       TColStd_MapOfInteger  myMapIds;
464       TColStd_MapOfInteger  myMapBadGeomIds;
465       TVectorOfFacePtr      myAllFacePtr;
466       TDataMapFacePtrInt    myAllFacePtrIntDMap;
467       double                myAngToler;
468       bool                  myIsOnlyManifold;
469       long                  myStartElemId;
470
471     };
472     typedef boost::shared_ptr<ManifoldPart> ManifoldPartPtr;
473                          
474
475     /*
476       Class       : ElementsOnSurface
477       Description : Predicate elements that lying on indicated surface
478                     (plane or cylinder)
479     */
480     class ElementsOnSurface : public virtual Predicate {
481     public:
482       ElementsOnSurface();
483       ~ElementsOnSurface();
484       virtual void SetMesh( SMDS_Mesh* theMesh );
485       virtual bool IsSatisfy( long theElementId );
486       virtual      SMDSAbs_ElementType GetType() const;
487
488       void    SetTolerance( const double theToler );
489       double  GetTolerance() const;
490       void    SetSurface( const TopoDS_Shape& theShape,
491                           const SMDSAbs_ElementType theType );
492
493     private:
494       void    process();
495       void    process( const SMDS_MeshElement* theElem  );
496       bool    isOnSurface( const SMDS_MeshNode* theNode ) const;
497
498     private:
499       SMDS_Mesh*            myMesh;
500       TColStd_MapOfInteger  myIds;
501       SMDSAbs_ElementType   myType;
502       Handle(Geom_Surface)  mySurf;
503       double                myToler;
504     };
505     
506     typedef boost::shared_ptr<ElementsOnSurface> ElementsOnSurfacePtr;
507       
508
509     /*
510       FILTER
511     */
512     class Filter{
513     public:
514       Filter();
515       virtual ~Filter();
516       virtual void SetPredicate(PredicatePtr thePred);
517       typedef std::vector<long> TIdSequence;
518       virtual TIdSequence GetElementsId( SMDS_Mesh* theMesh );
519   
520     protected:
521       PredicatePtr myPredicate;
522     };
523   };  
524 };
525
526
527 #endif