]> SALOME platform Git repositories - modules/smesh.git/blob - src/Controls/SMESH_ControlsDef.hxx
Salome HOME
Fix on - Bug PAL7220: DEVELOPMENT : 3D Aspect Ratio
[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) = 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     /*
225       Class       : MultiConnection
226       Description : Functor for calculating number of faces conneted to the edge
227     */
228     class MultiConnection: public virtual NumericalFunctor{
229     public:
230       virtual double GetValue( long theElementId );
231       virtual double GetValue( const TSequenceOfXYZ& thePoints );
232       virtual double GetBadRate( double Value, int nbNodes ) const;
233       virtual SMDSAbs_ElementType GetType() const;
234     };
235     
236   
237     /*
238       PREDICATES
239     */
240     /*
241       Class       : Predicate
242       Description : Base class for all predicates
243     */
244     class Predicate: public virtual Functor{
245     public:
246       virtual bool IsSatisfy( long theElementId ) = 0;
247       virtual SMDSAbs_ElementType GetType() const = 0;
248     };
249     
250   
251   
252     /*
253       Class       : FreeBorders
254       Description : Predicate for free borders
255     */
256     class FreeBorders: public virtual Predicate{
257     public:
258       FreeBorders();
259       virtual void SetMesh( SMDS_Mesh* theMesh );
260       virtual bool IsSatisfy( long theElementId );
261       virtual SMDSAbs_ElementType GetType() const;
262             
263     protected:
264       SMDS_Mesh* myMesh;
265     };
266    
267
268     /*
269       Class       : FreeEdges
270       Description : Predicate for free Edges
271     */
272     class FreeEdges: public virtual Predicate{
273     public:
274       FreeEdges();
275       virtual void SetMesh( SMDS_Mesh* theMesh );
276       virtual bool IsSatisfy( long theElementId );
277       virtual SMDSAbs_ElementType GetType() const;
278       static bool IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId  );
279       typedef long TElemId;
280       struct Border{
281         TElemId myElemId;
282         TElemId myPntId[2];
283         Border(long theElemId, long thePntId1, long thePntId2);
284         bool operator<(const Border& x) const;
285       };
286       typedef std::set<Border> TBorders;
287       void GetBoreders(TBorders& theBorders);
288       
289     protected:
290       SMDS_Mesh* myMesh;
291     };
292     typedef boost::shared_ptr<FreeEdges> FreeEdgesPtr;
293
294
295     /*
296       Class       : RangeOfIds
297       Description : Predicate for Range of Ids.
298                     Range may be specified with two ways.
299                     1. Using AddToRange method
300                     2. With SetRangeStr method. Parameter of this method is a string
301                        like as "1,2,3,50-60,63,67,70-"
302     */
303     class RangeOfIds: public virtual Predicate
304     {
305     public:
306                                     RangeOfIds();
307       virtual void                  SetMesh( SMDS_Mesh* theMesh );
308       virtual bool                  IsSatisfy( long theNodeId );
309       virtual SMDSAbs_ElementType   GetType() const;
310       virtual void                  SetType( SMDSAbs_ElementType theType );
311
312       bool                          AddToRange( long theEntityId );
313       void                          GetRangeStr( TCollection_AsciiString& );
314       bool                          SetRangeStr( const TCollection_AsciiString& );
315
316     protected:
317       SMDS_Mesh*                    myMesh;
318
319       TColStd_SequenceOfInteger     myMin;
320       TColStd_SequenceOfInteger     myMax;
321       TColStd_MapOfInteger          myIds;
322
323       SMDSAbs_ElementType           myType;
324     };
325     
326     typedef boost::shared_ptr<RangeOfIds> RangeOfIdsPtr;
327    
328     
329     /*
330       Class       : Comparator
331       Description : Base class for comparators
332     */
333     class Comparator: public virtual Predicate{
334     public:
335       Comparator();
336       virtual ~Comparator();
337       virtual void SetMesh( SMDS_Mesh* theMesh );
338       virtual void SetMargin(double theValue);
339       virtual void SetNumFunctor(NumericalFunctorPtr theFunct);
340       virtual bool IsSatisfy( long theElementId ) = 0;
341       virtual SMDSAbs_ElementType GetType() const;
342       double  GetMargin();
343   
344     protected:
345       double myMargin;
346       NumericalFunctorPtr myFunctor;
347     };
348     typedef boost::shared_ptr<Comparator> ComparatorPtr;
349   
350   
351     /*
352       Class       : LessThan
353       Description : Comparator "<"
354     */
355     class LessThan: public virtual Comparator{
356     public:
357       virtual bool IsSatisfy( long theElementId );
358     };
359   
360   
361     /*
362       Class       : MoreThan
363       Description : Comparator ">"
364     */
365     class MoreThan: public virtual Comparator{
366     public:
367       virtual bool IsSatisfy( long theElementId );
368     };
369   
370   
371     /*
372       Class       : EqualTo
373       Description : Comparator "="
374     */
375     class EqualTo: public virtual Comparator{
376     public:
377       EqualTo();
378       virtual bool IsSatisfy( long theElementId );
379       virtual void SetTolerance( double theTol );
380       virtual double GetTolerance();
381   
382     private:
383       double myToler;
384     };
385     typedef boost::shared_ptr<EqualTo> EqualToPtr;
386   
387     
388     /*
389       Class       : LogicalNOT
390       Description : Logical NOT predicate
391     */
392     class LogicalNOT: public virtual Predicate{
393     public:
394       LogicalNOT();
395       virtual ~LogicalNOT();
396       virtual bool IsSatisfy( long theElementId );
397       virtual void SetMesh( SMDS_Mesh* theMesh );
398       virtual void SetPredicate(PredicatePtr thePred);
399       virtual SMDSAbs_ElementType GetType() const;
400   
401     private:
402       PredicatePtr myPredicate;
403     };
404     typedef boost::shared_ptr<LogicalNOT> LogicalNOTPtr;
405     
406   
407     /*
408       Class       : LogicalBinary
409       Description : Base class for binary logical predicate
410     */
411     class LogicalBinary: public virtual Predicate{
412     public:
413       LogicalBinary();
414       virtual ~LogicalBinary();
415       virtual void SetMesh( SMDS_Mesh* theMesh );
416       virtual void SetPredicate1(PredicatePtr thePred);
417       virtual void SetPredicate2(PredicatePtr thePred);
418       virtual SMDSAbs_ElementType GetType() const;
419   
420     protected:
421       PredicatePtr myPredicate1;
422       PredicatePtr myPredicate2;
423     };
424     typedef boost::shared_ptr<LogicalBinary> LogicalBinaryPtr;
425   
426   
427     /*
428       Class       : LogicalAND
429       Description : Logical AND
430     */
431     class LogicalAND: public virtual LogicalBinary{
432     public:
433       virtual bool IsSatisfy( long theElementId );
434     };
435   
436   
437     /*
438       Class       : LogicalOR
439       Description : Logical OR
440     */
441     class LogicalOR: public virtual LogicalBinary{
442     public:
443       virtual bool IsSatisfy( long theElementId );
444     };
445   
446   
447     /*
448       Class       : ManifoldPart
449       Description : Predicate for manifold part of mesh
450     */
451     class ManifoldPart: public virtual Predicate{
452     public:
453
454       /* internal class for algorithm uses */
455       class Link
456       {
457       public:
458         Link( SMDS_MeshNode* theNode1,
459               SMDS_MeshNode* theNode2 );
460         ~Link();
461         
462         bool IsEqual( const ManifoldPart::Link& theLink ) const;
463         bool operator<(const ManifoldPart::Link& x) const;
464         
465         SMDS_MeshNode* myNode1;
466         SMDS_MeshNode* myNode2;
467       };
468
469       bool IsEqual( const ManifoldPart::Link& theLink1,
470                     const ManifoldPart::Link& theLink2 );
471       
472       typedef std::set<ManifoldPart::Link>                TMapOfLink;
473       typedef std::vector<SMDS_MeshFace*>                 TVectorOfFacePtr;
474       typedef std::vector<ManifoldPart::Link>             TVectorOfLink;
475       typedef std::map<SMDS_MeshFace*,int>                TDataMapFacePtrInt;
476       typedef std::map<ManifoldPart::Link,SMDS_MeshFace*> TDataMapOfLinkFacePtr;
477       
478       ManifoldPart();
479       ~ManifoldPart();
480       virtual void SetMesh( SMDS_Mesh* theMesh );
481       // inoke when all parameters already set
482       virtual bool IsSatisfy( long theElementId );
483       virtual      SMDSAbs_ElementType GetType() const;
484
485       void    SetAngleTolerance( const double theAngToler );
486       double  GetAngleTolerance() const;
487       void    SetIsOnlyManifold( const bool theIsOnly );
488       void    SetStartElem( const long  theStartElemId );
489
490     private:
491       bool    process();
492       bool    findConnected( const TDataMapFacePtrInt& theAllFacePtrInt,
493                              SMDS_MeshFace*            theStartFace,
494                              TMapOfLink&               theNonManifold,
495                              TColStd_MapOfInteger&     theResFaces );
496       bool    isInPlane( const SMDS_MeshFace* theFace1,
497                           const SMDS_MeshFace* theFace2 );
498       void    expandBoundary( TMapOfLink&            theMapOfBoundary,
499                               TVectorOfLink&         theSeqOfBoundary,
500                               TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
501                               TMapOfLink&            theNonManifold,
502                               SMDS_MeshFace*         theNextFace ) const;
503
504      void     getFacesByLink( const Link& theLink,
505                               TVectorOfFacePtr& theFaces ) const;
506
507     private:
508       SMDS_Mesh*            myMesh;
509       TColStd_MapOfInteger  myMapIds;
510       TColStd_MapOfInteger  myMapBadGeomIds;
511       TVectorOfFacePtr      myAllFacePtr;
512       TDataMapFacePtrInt    myAllFacePtrIntDMap;
513       double                myAngToler;
514       bool                  myIsOnlyManifold;
515       long                  myStartElemId;
516
517     };
518     typedef boost::shared_ptr<ManifoldPart> ManifoldPartPtr;
519                          
520
521     /*
522       Class       : ElementsOnSurface
523       Description : Predicate elements that lying on indicated surface
524                     (plane or cylinder)
525     */
526     class ElementsOnSurface : public virtual Predicate {
527     public:
528       ElementsOnSurface();
529       ~ElementsOnSurface();
530       virtual void SetMesh( SMDS_Mesh* theMesh );
531       virtual bool IsSatisfy( long theElementId );
532       virtual      SMDSAbs_ElementType GetType() const;
533
534       void    SetTolerance( const double theToler );
535       double  GetTolerance() const;
536       void    SetSurface( const TopoDS_Shape& theShape,
537                           const SMDSAbs_ElementType theType );
538
539     private:
540       void    process();
541       void    process( const SMDS_MeshElement* theElem  );
542       bool    isOnSurface( const SMDS_MeshNode* theNode ) const;
543
544     private:
545       SMDS_Mesh*            myMesh;
546       TColStd_MapOfInteger  myIds;
547       SMDSAbs_ElementType   myType;
548       Handle(Geom_Surface)  mySurf;
549       double                myToler;
550     };
551     
552     typedef boost::shared_ptr<ElementsOnSurface> ElementsOnSurfacePtr;
553       
554
555     /*
556       FILTER
557     */
558     class Filter{
559     public:
560       Filter();
561       virtual ~Filter();
562       virtual void SetPredicate(PredicatePtr thePred);
563       typedef std::vector<long> TIdSequence;
564       virtual TIdSequence GetElementsId( SMDS_Mesh* theMesh );
565   
566     protected:
567       PredicatePtr myPredicate;
568     };
569   };  
570 };
571
572
573 #endif