Salome HOME
Merging with WPdev
[modules/smesh.git] / src / Controls / SMESH_ControlsDef.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.salome-platform.org/ or email : webmaster.salome@opencascade.com
19
20 #ifndef _SMESH_CONTROLSDEF_HXX_
21 #define _SMESH_CONTROLSDEF_HXX_
22
23 #include <set>
24 #include <map>
25 #include <vector>
26 #include <boost/shared_ptr.hpp>
27 #include <gp_XYZ.hxx>
28 #include <Geom_Surface.hxx>
29 #include <TColStd_SequenceOfInteger.hxx>
30 #include <TColStd_MapOfInteger.hxx>
31 #include <TCollection_AsciiString.hxx>
32
33 #include "SMDSAbs_ElementType.hxx"
34 #include "SMDS_MeshNode.hxx"
35
36 #include "SMESH_Controls.hxx"
37
38 #ifdef WNT
39  #if defined SMESHCONTROLS_EXPORTS
40   #define SMESHCONTROLS_EXPORT __declspec( dllexport )
41  #else
42   #define SMESHCONTROLS_EXPORT __declspec( dllimport )
43  #endif
44 #else
45  #define SMESHCONTROLS_EXPORT
46 #endif
47
48 class SMDS_MeshElement;
49 class SMDS_MeshFace;
50 class SMDS_MeshNode;
51 class SMDS_Mesh;
52
53 class SMESHDS_Mesh;
54 class SMESHDS_SubMesh;
55
56 class gp_Pnt;
57 class TopoDS_Shape;
58
59 namespace SMESH{
60   namespace Controls{
61
62     class SMESHCONTROLS_EXPORT TSequenceOfXYZ: public std::vector<gp_XYZ>
63     {
64     public:
65       typedef std::vector<gp_XYZ> TSuperClass;
66       TSequenceOfXYZ()
67       {}
68
69       TSequenceOfXYZ(size_type n):
70         TSuperClass(n)
71       {}
72
73       TSequenceOfXYZ(size_type n, const value_type& t):
74         TSuperClass(n,t)
75       {}
76
77       TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ):
78         TSuperClass(theSequenceOfXYZ)
79       {}
80
81       template <class InputIterator>
82       TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd):
83         TSuperClass(theBegin,theEnd)
84       {}
85
86       TSequenceOfXYZ& operator=(const TSequenceOfXYZ& theSequenceOfXYZ){
87         TSuperClass::operator=(theSequenceOfXYZ);
88         return *this;
89       }
90
91       reference operator()(size_type n){
92         return TSuperClass::operator[](n-1);
93       }
94
95       const_reference operator()(size_type n) const{
96         return TSuperClass::operator[](n-1);
97       }
98
99     private:
100       reference operator[](size_type n);
101
102       const_reference operator[](size_type n) const;
103     };
104
105     /*
106       Class       : Functor
107       Description : Root of all Functors
108     */
109     class SMESHCONTROLS_EXPORT Functor
110     {
111     public:
112       ~Functor(){}
113       virtual void SetMesh( const SMDS_Mesh* theMesh ) = 0;
114       virtual SMDSAbs_ElementType GetType() const = 0;
115     };
116
117     /*
118       Class       : NumericalFunctor
119       Description : Root of all Functors returning numeric value
120     */
121     class SMESHCONTROLS_EXPORT NumericalFunctor: public virtual Functor{
122     public:
123       NumericalFunctor();
124       virtual void SetMesh( const SMDS_Mesh* theMesh );
125       virtual double GetValue( long theElementId );
126       virtual double GetValue(const TSequenceOfXYZ& thePoints) { return -1.0;};
127       virtual SMDSAbs_ElementType GetType() const = 0;
128       virtual double GetBadRate( double Value, int nbNodes ) const = 0;
129       long  GetPrecision() const;
130       void  SetPrecision( const long thePrecision );
131       
132       bool GetPoints(const int theId, 
133                      TSequenceOfXYZ& theRes) const;
134       static bool GetPoints(const SMDS_MeshElement* theElem, 
135                             TSequenceOfXYZ& theRes);
136     protected:
137       const SMDS_Mesh* myMesh;
138       const SMDS_MeshElement* myCurrElement;
139       long       myPrecision;
140     };
141   
142   
143     /*
144       Class       : Volume
145       Description : Functor calculating volume of 3D mesh element
146     */
147     class SMESHCONTROLS_EXPORT Volume: public virtual NumericalFunctor{
148     public:
149       virtual double GetValue( long theElementId );
150       //virtual double GetValue( const TSequenceOfXYZ& thePoints );
151       virtual double GetBadRate( double Value, int nbNodes ) const;
152       virtual SMDSAbs_ElementType GetType() const;
153     };
154   
155   
156     /*
157       Class       : SMESH_MinimumAngle
158       Description : Functor for calculation of minimum angle
159     */
160     class SMESHCONTROLS_EXPORT MinimumAngle: public virtual NumericalFunctor{
161     public:
162       virtual double GetValue( const TSequenceOfXYZ& thePoints );
163       virtual double GetBadRate( double Value, int nbNodes ) const;
164       virtual SMDSAbs_ElementType GetType() const;
165     };
166   
167   
168     /*
169       Class       : AspectRatio
170       Description : Functor for calculating aspect ratio
171     */
172     class SMESHCONTROLS_EXPORT AspectRatio: public virtual NumericalFunctor{
173     public:
174       virtual double GetValue( const TSequenceOfXYZ& thePoints );
175       virtual double GetBadRate( double Value, int nbNodes ) const;
176       virtual SMDSAbs_ElementType GetType() const;
177     };
178   
179   
180     /*
181       Class       : AspectRatio3D
182       Description : Functor for calculating aspect ratio of 3D elems.
183     */
184     class SMESHCONTROLS_EXPORT AspectRatio3D: public virtual NumericalFunctor{
185     public:
186       virtual double GetValue( const TSequenceOfXYZ& thePoints );
187       virtual double GetBadRate( double Value, int nbNodes ) const;
188       virtual SMDSAbs_ElementType GetType() const;
189     };
190   
191   
192     /*
193       Class       : Warping
194       Description : Functor for calculating warping
195     */
196     class SMESHCONTROLS_EXPORT Warping: public virtual NumericalFunctor{
197     public:
198       virtual double GetValue( const TSequenceOfXYZ& thePoints );
199       virtual double GetBadRate( double Value, int nbNodes ) const;
200       virtual SMDSAbs_ElementType GetType() const;
201       
202     private:
203       double ComputeA( const gp_XYZ&, const gp_XYZ&, const gp_XYZ&, const gp_XYZ& ) const;
204     };
205   
206   
207     /*
208       Class       : Taper
209       Description : Functor for calculating taper
210     */
211     class SMESHCONTROLS_EXPORT Taper: public virtual NumericalFunctor{
212     public:
213       virtual double GetValue( const TSequenceOfXYZ& thePoints );
214       virtual double GetBadRate( double Value, int nbNodes ) const;
215       virtual SMDSAbs_ElementType GetType() const;
216     };
217     
218   
219     /*
220       Class       : Skew
221       Description : Functor for calculating skew in degrees
222     */
223     class SMESHCONTROLS_EXPORT Skew: public virtual NumericalFunctor{
224     public:
225       virtual double GetValue( const TSequenceOfXYZ& thePoints );
226       virtual double GetBadRate( double Value, int nbNodes ) const;
227       virtual SMDSAbs_ElementType GetType() const;
228     };
229   
230     
231     /*
232       Class       : Area
233       Description : Functor for calculating area
234     */
235     class SMESHCONTROLS_EXPORT Area: public virtual NumericalFunctor{
236     public:
237       virtual double GetValue( const TSequenceOfXYZ& thePoints );
238       virtual double GetBadRate( double Value, int nbNodes ) const;
239       virtual SMDSAbs_ElementType GetType() const;
240     };
241   
242   
243     /*
244       Class       : Length
245       Description : Functor for calculating length of edge
246     */
247     class SMESHCONTROLS_EXPORT Length: public virtual NumericalFunctor{
248     public:
249       virtual double GetValue( const TSequenceOfXYZ& thePoints );
250       virtual double GetBadRate( double Value, int nbNodes ) const;
251       virtual SMDSAbs_ElementType GetType() const;
252     };
253   
254     /*
255       Class       : Length2D
256       Description : Functor for calculating length of edge
257     */
258     class SMESHCONTROLS_EXPORT Length2D: public virtual NumericalFunctor{
259     public:
260       virtual double GetValue( long theElementId );
261       virtual double GetBadRate( double Value, int nbNodes ) const;
262       virtual SMDSAbs_ElementType GetType() const;
263       struct Value{
264         double myLength;
265         long myPntId[2];
266         Value(double theLength, long thePntId1, long thePntId2);
267         bool operator<(const Value& x) const;
268       };
269       typedef std::set<Value> TValues;
270       void GetValues(TValues& theValues);
271       
272     };
273     typedef boost::shared_ptr<Length2D> Length2DPtr;
274
275     /*
276       Class       : MultiConnection
277       Description : Functor for calculating number of faces conneted to the edge
278     */
279     class SMESHCONTROLS_EXPORT MultiConnection: public virtual NumericalFunctor{
280     public:
281       virtual double GetValue( long theElementId );
282       virtual double GetValue( const TSequenceOfXYZ& thePoints );
283       virtual double GetBadRate( double Value, int nbNodes ) const;
284       virtual SMDSAbs_ElementType GetType() const;
285     };
286     
287     /*
288       Class       : MultiConnection2D
289       Description : Functor for calculating number of faces conneted to the edge
290     */
291     class SMESHCONTROLS_EXPORT MultiConnection2D: public virtual NumericalFunctor{
292     public:
293       virtual double GetValue( long theElementId );
294       virtual double GetValue( const TSequenceOfXYZ& thePoints );
295       virtual double GetBadRate( double Value, int nbNodes ) const;
296       virtual SMDSAbs_ElementType GetType() const;
297       struct Value{
298         long myPntId[2];
299         Value(long thePntId1, long thePntId2);
300         bool operator<(const Value& x) const;
301       };
302       typedef std::map<Value,int> MValues;
303
304       void GetValues(MValues& theValues);
305     };
306     typedef boost::shared_ptr<MultiConnection2D> MultiConnection2DPtr;
307     /*
308       PREDICATES
309     */
310     /*
311       Class       : Predicate
312       Description : Base class for all predicates
313     */
314     class SMESHCONTROLS_EXPORT Predicate: public virtual Functor{
315     public:
316       virtual bool IsSatisfy( long theElementId ) = 0;
317       virtual SMDSAbs_ElementType GetType() const = 0;
318     };
319     
320   
321   
322     /*
323       Class       : FreeBorders
324       Description : Predicate for free borders
325     */
326     class SMESHCONTROLS_EXPORT FreeBorders: public virtual Predicate{
327     public:
328       FreeBorders();
329       virtual void SetMesh( const SMDS_Mesh* theMesh );
330       virtual bool IsSatisfy( long theElementId );
331       virtual SMDSAbs_ElementType GetType() const;
332             
333     protected:
334       const SMDS_Mesh* myMesh;
335     };
336    
337
338     /*
339       Class       : BadOrientedVolume
340       Description : Predicate bad oriented volumes
341     */
342     class SMESHCONTROLS_EXPORT BadOrientedVolume: public virtual Predicate{
343     public:
344       BadOrientedVolume();
345       virtual void SetMesh( const SMDS_Mesh* theMesh );
346       virtual bool IsSatisfy( long theElementId );
347       virtual SMDSAbs_ElementType GetType() const;
348             
349     protected:
350       const SMDS_Mesh* myMesh;
351     };
352    
353
354     /*
355       Class       : FreeEdges
356       Description : Predicate for free Edges
357     */
358     class SMESHCONTROLS_EXPORT FreeEdges: public virtual Predicate{
359     public:
360       FreeEdges();
361       virtual void SetMesh( const SMDS_Mesh* theMesh );
362       virtual bool IsSatisfy( long theElementId );
363       virtual SMDSAbs_ElementType GetType() const;
364       static bool IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId  );
365       typedef long TElemId;
366       struct Border{
367         TElemId myElemId;
368         TElemId myPntId[2];
369         Border(long theElemId, long thePntId1, long thePntId2);
370         bool operator<(const Border& x) const;
371       };
372       typedef std::set<Border> TBorders;
373       void GetBoreders(TBorders& theBorders);
374       
375     protected:
376       const SMDS_Mesh* myMesh;
377     };
378     typedef boost::shared_ptr<FreeEdges> FreeEdgesPtr;
379
380
381     /*
382       Class       : RangeOfIds
383       Description : Predicate for Range of Ids.
384                     Range may be specified with two ways.
385                     1. Using AddToRange method
386                     2. With SetRangeStr method. Parameter of this method is a string
387                        like as "1,2,3,50-60,63,67,70-"
388     */
389     class SMESHCONTROLS_EXPORT RangeOfIds: public virtual Predicate
390     {
391     public:
392                                     RangeOfIds();
393       virtual void                  SetMesh( const SMDS_Mesh* theMesh );
394       virtual bool                  IsSatisfy( long theNodeId );
395       virtual SMDSAbs_ElementType   GetType() const;
396       virtual void                  SetType( SMDSAbs_ElementType theType );
397
398       bool                          AddToRange( long theEntityId );
399       void                          GetRangeStr( TCollection_AsciiString& );
400       bool                          SetRangeStr( const TCollection_AsciiString& );
401
402     protected:
403       const SMDS_Mesh*              myMesh;
404
405       TColStd_SequenceOfInteger     myMin;
406       TColStd_SequenceOfInteger     myMax;
407       TColStd_MapOfInteger          myIds;
408
409       SMDSAbs_ElementType           myType;
410     };
411     
412     typedef boost::shared_ptr<RangeOfIds> RangeOfIdsPtr;
413    
414     
415     /*
416       Class       : Comparator
417       Description : Base class for comparators
418     */
419     class SMESHCONTROLS_EXPORT Comparator: public virtual Predicate{
420     public:
421       Comparator();
422       virtual ~Comparator();
423       virtual void SetMesh( const SMDS_Mesh* theMesh );
424       virtual void SetMargin(double theValue);
425       virtual void SetNumFunctor(NumericalFunctorPtr theFunct);
426       virtual bool IsSatisfy( long theElementId ) = 0;
427       virtual SMDSAbs_ElementType GetType() const;
428       double  GetMargin();
429   
430     protected:
431       double myMargin;
432       NumericalFunctorPtr myFunctor;
433     };
434     typedef boost::shared_ptr<Comparator> ComparatorPtr;
435   
436   
437     /*
438       Class       : LessThan
439       Description : Comparator "<"
440     */
441     class SMESHCONTROLS_EXPORT LessThan: public virtual Comparator{
442     public:
443       virtual bool IsSatisfy( long theElementId );
444     };
445   
446   
447     /*
448       Class       : MoreThan
449       Description : Comparator ">"
450     */
451     class SMESHCONTROLS_EXPORT MoreThan: public virtual Comparator{
452     public:
453       virtual bool IsSatisfy( long theElementId );
454     };
455   
456   
457     /*
458       Class       : EqualTo
459       Description : Comparator "="
460     */
461     class SMESHCONTROLS_EXPORT EqualTo: public virtual Comparator{
462     public:
463       EqualTo();
464       virtual bool IsSatisfy( long theElementId );
465       virtual void SetTolerance( double theTol );
466       virtual double GetTolerance();
467   
468     private:
469       double myToler;
470     };
471     typedef boost::shared_ptr<EqualTo> EqualToPtr;
472   
473     
474     /*
475       Class       : LogicalNOT
476       Description : Logical NOT predicate
477     */
478     class SMESHCONTROLS_EXPORT LogicalNOT: public virtual Predicate{
479     public:
480       LogicalNOT();
481       virtual ~LogicalNOT();
482       virtual bool IsSatisfy( long theElementId );
483       virtual void SetMesh( const SMDS_Mesh* theMesh );
484       virtual void SetPredicate(PredicatePtr thePred);
485       virtual SMDSAbs_ElementType GetType() const;
486   
487     private:
488       PredicatePtr myPredicate;
489     };
490     typedef boost::shared_ptr<LogicalNOT> LogicalNOTPtr;
491     
492   
493     /*
494       Class       : LogicalBinary
495       Description : Base class for binary logical predicate
496     */
497     class SMESHCONTROLS_EXPORT LogicalBinary: public virtual Predicate{
498     public:
499       LogicalBinary();
500       virtual ~LogicalBinary();
501       virtual void SetMesh( const SMDS_Mesh* theMesh );
502       virtual void SetPredicate1(PredicatePtr thePred);
503       virtual void SetPredicate2(PredicatePtr thePred);
504       virtual SMDSAbs_ElementType GetType() const;
505   
506     protected:
507       PredicatePtr myPredicate1;
508       PredicatePtr myPredicate2;
509     };
510     typedef boost::shared_ptr<LogicalBinary> LogicalBinaryPtr;
511   
512   
513     /*
514       Class       : LogicalAND
515       Description : Logical AND
516     */
517     class SMESHCONTROLS_EXPORT LogicalAND: public virtual LogicalBinary{
518     public:
519       virtual bool IsSatisfy( long theElementId );
520     };
521   
522   
523     /*
524       Class       : LogicalOR
525       Description : Logical OR
526     */
527     class SMESHCONTROLS_EXPORT LogicalOR: public virtual LogicalBinary{
528     public:
529       virtual bool IsSatisfy( long theElementId );
530     };
531   
532   
533     /*
534       Class       : ManifoldPart
535       Description : Predicate for manifold part of mesh
536     */
537     class SMESHCONTROLS_EXPORT ManifoldPart: public virtual Predicate{
538     public:
539
540       /* internal class for algorithm uses */
541       class Link
542       {
543       public:
544         Link( SMDS_MeshNode* theNode1,
545               SMDS_MeshNode* theNode2 );
546         ~Link();
547         
548         bool IsEqual( const ManifoldPart::Link& theLink ) const;
549         bool operator<(const ManifoldPart::Link& x) const;
550         
551         SMDS_MeshNode* myNode1;
552         SMDS_MeshNode* myNode2;
553       };
554
555       bool IsEqual( const ManifoldPart::Link& theLink1,
556                     const ManifoldPart::Link& theLink2 );
557       
558       typedef std::set<ManifoldPart::Link>                TMapOfLink;
559       typedef std::vector<SMDS_MeshFace*>                 TVectorOfFacePtr;
560       typedef std::vector<ManifoldPart::Link>             TVectorOfLink;
561       typedef std::map<SMDS_MeshFace*,int>                TDataMapFacePtrInt;
562       typedef std::map<ManifoldPart::Link,SMDS_MeshFace*> TDataMapOfLinkFacePtr;
563       
564       ManifoldPart();
565       ~ManifoldPart();
566       virtual void SetMesh( const SMDS_Mesh* theMesh );
567       // inoke when all parameters already set
568       virtual bool IsSatisfy( long theElementId );
569       virtual      SMDSAbs_ElementType GetType() const;
570
571       void    SetAngleTolerance( const double theAngToler );
572       double  GetAngleTolerance() const;
573       void    SetIsOnlyManifold( const bool theIsOnly );
574       void    SetStartElem( const long  theStartElemId );
575
576     private:
577       bool    process();
578       bool    findConnected( const TDataMapFacePtrInt& theAllFacePtrInt,
579                              SMDS_MeshFace*            theStartFace,
580                              TMapOfLink&               theNonManifold,
581                              TColStd_MapOfInteger&     theResFaces );
582       bool    isInPlane( const SMDS_MeshFace* theFace1,
583                           const SMDS_MeshFace* theFace2 );
584       void    expandBoundary( TMapOfLink&            theMapOfBoundary,
585                               TVectorOfLink&         theSeqOfBoundary,
586                               TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
587                               TMapOfLink&            theNonManifold,
588                               SMDS_MeshFace*         theNextFace ) const;
589
590      void     getFacesByLink( const Link& theLink,
591                               TVectorOfFacePtr& theFaces ) const;
592
593     private:
594       const SMDS_Mesh*      myMesh;
595       TColStd_MapOfInteger  myMapIds;
596       TColStd_MapOfInteger  myMapBadGeomIds;
597       TVectorOfFacePtr      myAllFacePtr;
598       TDataMapFacePtrInt    myAllFacePtrIntDMap;
599       double                myAngToler;
600       bool                  myIsOnlyManifold;
601       long                  myStartElemId;
602
603     };
604     typedef boost::shared_ptr<ManifoldPart> ManifoldPartPtr;
605                          
606
607     /*
608       Class       : ElementsOnSurface
609       Description : Predicate elements that lying on indicated surface
610                     (plane or cylinder)
611     */
612     class SMESHCONTROLS_EXPORT ElementsOnSurface : public virtual Predicate {
613     public:
614       ElementsOnSurface();
615       ~ElementsOnSurface();
616       virtual void SetMesh( const SMDS_Mesh* theMesh );
617       virtual bool IsSatisfy( long theElementId );
618       virtual      SMDSAbs_ElementType GetType() const;
619
620       void    SetTolerance( const double theToler );
621       double  GetTolerance() const;
622       void    SetSurface( const TopoDS_Shape& theShape,
623                           const SMDSAbs_ElementType theType );
624
625     private:
626       void    process();
627       void    process( const SMDS_MeshElement* theElem  );
628       bool    isOnSurface( const SMDS_MeshNode* theNode ) const;
629
630     private:
631       const SMDS_Mesh*      myMesh;
632       TColStd_MapOfInteger  myIds;
633       SMDSAbs_ElementType   myType;
634       Handle(Geom_Surface)  mySurf;
635       double                myToler;
636     };
637     
638     typedef boost::shared_ptr<ElementsOnSurface> ElementsOnSurfacePtr;
639       
640
641     /*
642       FILTER
643     */
644     class SMESHCONTROLS_EXPORT Filter{
645     public:
646       Filter();
647       virtual ~Filter();
648       virtual void SetPredicate(PredicatePtr thePred);
649
650       typedef std::vector<long> TIdSequence;
651
652       virtual 
653       void
654       GetElementsId( const SMDS_Mesh* theMesh,
655                      TIdSequence& theSequence );
656
657       static
658       void
659       GetElementsId( const SMDS_Mesh* theMesh, 
660                      PredicatePtr thePredicate,
661                      TIdSequence& theSequence );
662       
663     protected:
664       PredicatePtr myPredicate;
665     };
666   };  
667 };
668
669
670 #endif