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