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