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