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