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