1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef _SMESH_CONTROLSDEF_HXX_
21 #define _SMESH_CONTROLSDEF_HXX_
26 #include <boost/shared_ptr.hpp>
28 #include <Geom_Surface.hxx>
29 #include <TColStd_SequenceOfInteger.hxx>
30 #include <TColStd_MapOfInteger.hxx>
31 #include <TCollection_AsciiString.hxx>
33 #include "SMDSAbs_ElementType.hxx"
34 #include "SMDS_MeshNode.hxx"
36 #include "SMESH_Controls.hxx"
39 #if defined SMESHCONTROLS_EXPORTS
40 #define SMESHCONTROLS_EXPORT __declspec( dllexport )
42 #define SMESHCONTROLS_EXPORT __declspec( dllimport )
45 #define SMESHCONTROLS_EXPORT
48 class SMDS_MeshElement;
54 class SMESHDS_SubMesh;
62 class SMESHCONTROLS_EXPORT TSequenceOfXYZ: public std::vector<gp_XYZ>
65 typedef std::vector<gp_XYZ> TSuperClass;
69 TSequenceOfXYZ(size_type n):
73 TSequenceOfXYZ(size_type n, const value_type& t):
77 TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ):
78 TSuperClass(theSequenceOfXYZ)
81 template <class InputIterator>
82 TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd):
83 TSuperClass(theBegin,theEnd)
86 TSequenceOfXYZ& operator=(const TSequenceOfXYZ& theSequenceOfXYZ){
87 TSuperClass::operator=(theSequenceOfXYZ);
91 reference operator()(size_type n){
92 return TSuperClass::operator[](n-1);
95 const_reference operator()(size_type n) const{
96 return TSuperClass::operator[](n-1);
100 reference operator[](size_type n);
102 const_reference operator[](size_type n) const;
107 Description : Root of all Functors
109 class SMESHCONTROLS_EXPORT Functor
113 virtual void SetMesh( const SMDS_Mesh* theMesh ) = 0;
114 virtual SMDSAbs_ElementType GetType() const = 0;
118 Class : NumericalFunctor
119 Description : Root of all Functors returning numeric value
121 class SMESHCONTROLS_EXPORT NumericalFunctor: public virtual Functor{
124 virtual void SetMesh( const SMDS_Mesh* theMesh );
125 virtual double GetValue( long theElementId );
126 virtual double GetValue(const TSequenceOfXYZ& thePoints) { return -1.0;};
127 virtual SMDSAbs_ElementType GetType() const = 0;
128 virtual double GetBadRate( double Value, int nbNodes ) const = 0;
129 long GetPrecision() const;
130 void SetPrecision( const long thePrecision );
132 bool GetPoints(const int theId,
133 TSequenceOfXYZ& theRes) const;
134 static bool GetPoints(const SMDS_MeshElement* theElem,
135 TSequenceOfXYZ& theRes);
137 const SMDS_Mesh* myMesh;
138 const SMDS_MeshElement* myCurrElement;
145 Description : Functor calculating volume of 3D mesh element
147 class SMESHCONTROLS_EXPORT Volume: public virtual NumericalFunctor{
149 virtual double GetValue( long theElementId );
150 //virtual double GetValue( const TSequenceOfXYZ& thePoints );
151 virtual double GetBadRate( double Value, int nbNodes ) const;
152 virtual SMDSAbs_ElementType GetType() const;
157 Class : SMESH_MinimumAngle
158 Description : Functor for calculation of minimum angle
160 class SMESHCONTROLS_EXPORT MinimumAngle: public virtual NumericalFunctor{
162 virtual double GetValue( const TSequenceOfXYZ& thePoints );
163 virtual double GetBadRate( double Value, int nbNodes ) const;
164 virtual SMDSAbs_ElementType GetType() const;
170 Description : Functor for calculating aspect ratio
172 class SMESHCONTROLS_EXPORT AspectRatio: public virtual NumericalFunctor{
174 virtual double GetValue( const TSequenceOfXYZ& thePoints );
175 virtual double GetBadRate( double Value, int nbNodes ) const;
176 virtual SMDSAbs_ElementType GetType() const;
181 Class : AspectRatio3D
182 Description : Functor for calculating aspect ratio of 3D elems.
184 class SMESHCONTROLS_EXPORT AspectRatio3D: public virtual NumericalFunctor{
186 virtual double GetValue( const TSequenceOfXYZ& thePoints );
187 virtual double GetBadRate( double Value, int nbNodes ) const;
188 virtual SMDSAbs_ElementType GetType() const;
194 Description : Functor for calculating warping
196 class SMESHCONTROLS_EXPORT Warping: public virtual NumericalFunctor{
198 virtual double GetValue( const TSequenceOfXYZ& thePoints );
199 virtual double GetBadRate( double Value, int nbNodes ) const;
200 virtual SMDSAbs_ElementType GetType() const;
203 double ComputeA( const gp_XYZ&, const gp_XYZ&, const gp_XYZ&, const gp_XYZ& ) const;
209 Description : Functor for calculating taper
211 class SMESHCONTROLS_EXPORT Taper: public virtual NumericalFunctor{
213 virtual double GetValue( const TSequenceOfXYZ& thePoints );
214 virtual double GetBadRate( double Value, int nbNodes ) const;
215 virtual SMDSAbs_ElementType GetType() const;
221 Description : Functor for calculating skew in degrees
223 class SMESHCONTROLS_EXPORT Skew: public virtual NumericalFunctor{
225 virtual double GetValue( const TSequenceOfXYZ& thePoints );
226 virtual double GetBadRate( double Value, int nbNodes ) const;
227 virtual SMDSAbs_ElementType GetType() const;
233 Description : Functor for calculating area
235 class SMESHCONTROLS_EXPORT Area: public virtual NumericalFunctor{
237 virtual double GetValue( const TSequenceOfXYZ& thePoints );
238 virtual double GetBadRate( double Value, int nbNodes ) const;
239 virtual SMDSAbs_ElementType GetType() const;
245 Description : Functor for calculating length of edge
247 class SMESHCONTROLS_EXPORT Length: public virtual NumericalFunctor{
249 virtual double GetValue( const TSequenceOfXYZ& thePoints );
250 virtual double GetBadRate( double Value, int nbNodes ) const;
251 virtual SMDSAbs_ElementType GetType() const;
256 Description : Functor for calculating length of edge
258 class SMESHCONTROLS_EXPORT Length2D: public virtual NumericalFunctor{
260 virtual double GetValue( long theElementId );
261 virtual double GetBadRate( double Value, int nbNodes ) const;
262 virtual SMDSAbs_ElementType GetType() const;
266 Value(double theLength, long thePntId1, long thePntId2);
267 bool operator<(const Value& x) const;
269 typedef std::set<Value> TValues;
270 void GetValues(TValues& theValues);
273 typedef boost::shared_ptr<Length2D> Length2DPtr;
276 Class : MultiConnection
277 Description : Functor for calculating number of faces conneted to the edge
279 class SMESHCONTROLS_EXPORT MultiConnection: public virtual NumericalFunctor{
281 virtual double GetValue( long theElementId );
282 virtual double GetValue( const TSequenceOfXYZ& thePoints );
283 virtual double GetBadRate( double Value, int nbNodes ) const;
284 virtual SMDSAbs_ElementType GetType() const;
288 Class : MultiConnection2D
289 Description : Functor for calculating number of faces conneted to the edge
291 class SMESHCONTROLS_EXPORT MultiConnection2D: public virtual NumericalFunctor{
293 virtual double GetValue( long theElementId );
294 virtual double GetValue( const TSequenceOfXYZ& thePoints );
295 virtual double GetBadRate( double Value, int nbNodes ) const;
296 virtual SMDSAbs_ElementType GetType() const;
299 Value(long thePntId1, long thePntId2);
300 bool operator<(const Value& x) const;
302 typedef std::map<Value,int> MValues;
304 void GetValues(MValues& theValues);
306 typedef boost::shared_ptr<MultiConnection2D> MultiConnection2DPtr;
312 Description : Base class for all predicates
314 class SMESHCONTROLS_EXPORT Predicate: public virtual Functor{
316 virtual bool IsSatisfy( long theElementId ) = 0;
317 virtual SMDSAbs_ElementType GetType() const = 0;
324 Description : Predicate for free borders
326 class SMESHCONTROLS_EXPORT FreeBorders: public virtual Predicate{
329 virtual void SetMesh( const SMDS_Mesh* theMesh );
330 virtual bool IsSatisfy( long theElementId );
331 virtual SMDSAbs_ElementType GetType() const;
334 const SMDS_Mesh* myMesh;
339 Class : BadOrientedVolume
340 Description : Predicate bad oriented volumes
342 class SMESHCONTROLS_EXPORT BadOrientedVolume: public virtual Predicate{
345 virtual void SetMesh( const SMDS_Mesh* theMesh );
346 virtual bool IsSatisfy( long theElementId );
347 virtual SMDSAbs_ElementType GetType() const;
350 const SMDS_Mesh* myMesh;
356 Description : Predicate for free Edges
358 class SMESHCONTROLS_EXPORT FreeEdges: public virtual Predicate{
361 virtual void SetMesh( const SMDS_Mesh* theMesh );
362 virtual bool IsSatisfy( long theElementId );
363 virtual SMDSAbs_ElementType GetType() const;
364 static bool IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId );
365 typedef long TElemId;
369 Border(long theElemId, long thePntId1, long thePntId2);
370 bool operator<(const Border& x) const;
372 typedef std::set<Border> TBorders;
373 void GetBoreders(TBorders& theBorders);
376 const SMDS_Mesh* myMesh;
378 typedef boost::shared_ptr<FreeEdges> FreeEdgesPtr;
383 Description : Predicate for Range of Ids.
384 Range may be specified with two ways.
385 1. Using AddToRange method
386 2. With SetRangeStr method. Parameter of this method is a string
387 like as "1,2,3,50-60,63,67,70-"
389 class SMESHCONTROLS_EXPORT RangeOfIds: public virtual Predicate
393 virtual void SetMesh( const SMDS_Mesh* theMesh );
394 virtual bool IsSatisfy( long theNodeId );
395 virtual SMDSAbs_ElementType GetType() const;
396 virtual void SetType( SMDSAbs_ElementType theType );
398 bool AddToRange( long theEntityId );
399 void GetRangeStr( TCollection_AsciiString& );
400 bool SetRangeStr( const TCollection_AsciiString& );
403 const SMDS_Mesh* myMesh;
405 TColStd_SequenceOfInteger myMin;
406 TColStd_SequenceOfInteger myMax;
407 TColStd_MapOfInteger myIds;
409 SMDSAbs_ElementType myType;
412 typedef boost::shared_ptr<RangeOfIds> RangeOfIdsPtr;
417 Description : Base class for comparators
419 class SMESHCONTROLS_EXPORT Comparator: public virtual Predicate{
422 virtual ~Comparator();
423 virtual void SetMesh( const SMDS_Mesh* theMesh );
424 virtual void SetMargin(double theValue);
425 virtual void SetNumFunctor(NumericalFunctorPtr theFunct);
426 virtual bool IsSatisfy( long theElementId ) = 0;
427 virtual SMDSAbs_ElementType GetType() const;
432 NumericalFunctorPtr myFunctor;
434 typedef boost::shared_ptr<Comparator> ComparatorPtr;
439 Description : Comparator "<"
441 class SMESHCONTROLS_EXPORT LessThan: public virtual Comparator{
443 virtual bool IsSatisfy( long theElementId );
449 Description : Comparator ">"
451 class SMESHCONTROLS_EXPORT MoreThan: public virtual Comparator{
453 virtual bool IsSatisfy( long theElementId );
459 Description : Comparator "="
461 class SMESHCONTROLS_EXPORT EqualTo: public virtual Comparator{
464 virtual bool IsSatisfy( long theElementId );
465 virtual void SetTolerance( double theTol );
466 virtual double GetTolerance();
471 typedef boost::shared_ptr<EqualTo> EqualToPtr;
476 Description : Logical NOT predicate
478 class SMESHCONTROLS_EXPORT LogicalNOT: public virtual Predicate{
481 virtual ~LogicalNOT();
482 virtual bool IsSatisfy( long theElementId );
483 virtual void SetMesh( const SMDS_Mesh* theMesh );
484 virtual void SetPredicate(PredicatePtr thePred);
485 virtual SMDSAbs_ElementType GetType() const;
488 PredicatePtr myPredicate;
490 typedef boost::shared_ptr<LogicalNOT> LogicalNOTPtr;
494 Class : LogicalBinary
495 Description : Base class for binary logical predicate
497 class SMESHCONTROLS_EXPORT LogicalBinary: public virtual Predicate{
500 virtual ~LogicalBinary();
501 virtual void SetMesh( const SMDS_Mesh* theMesh );
502 virtual void SetPredicate1(PredicatePtr thePred);
503 virtual void SetPredicate2(PredicatePtr thePred);
504 virtual SMDSAbs_ElementType GetType() const;
507 PredicatePtr myPredicate1;
508 PredicatePtr myPredicate2;
510 typedef boost::shared_ptr<LogicalBinary> LogicalBinaryPtr;
515 Description : Logical AND
517 class SMESHCONTROLS_EXPORT LogicalAND: public virtual LogicalBinary{
519 virtual bool IsSatisfy( long theElementId );
525 Description : Logical OR
527 class SMESHCONTROLS_EXPORT LogicalOR: public virtual LogicalBinary{
529 virtual bool IsSatisfy( long theElementId );
535 Description : Predicate for manifold part of mesh
537 class SMESHCONTROLS_EXPORT ManifoldPart: public virtual Predicate{
540 /* internal class for algorithm uses */
544 Link( SMDS_MeshNode* theNode1,
545 SMDS_MeshNode* theNode2 );
548 bool IsEqual( const ManifoldPart::Link& theLink ) const;
549 bool operator<(const ManifoldPart::Link& x) const;
551 SMDS_MeshNode* myNode1;
552 SMDS_MeshNode* myNode2;
555 bool IsEqual( const ManifoldPart::Link& theLink1,
556 const ManifoldPart::Link& theLink2 );
558 typedef std::set<ManifoldPart::Link> TMapOfLink;
559 typedef std::vector<SMDS_MeshFace*> TVectorOfFacePtr;
560 typedef std::vector<ManifoldPart::Link> TVectorOfLink;
561 typedef std::map<SMDS_MeshFace*,int> TDataMapFacePtrInt;
562 typedef std::map<ManifoldPart::Link,SMDS_MeshFace*> TDataMapOfLinkFacePtr;
566 virtual void SetMesh( const SMDS_Mesh* theMesh );
567 // inoke when all parameters already set
568 virtual bool IsSatisfy( long theElementId );
569 virtual SMDSAbs_ElementType GetType() const;
571 void SetAngleTolerance( const double theAngToler );
572 double GetAngleTolerance() const;
573 void SetIsOnlyManifold( const bool theIsOnly );
574 void SetStartElem( const long theStartElemId );
578 bool findConnected( const TDataMapFacePtrInt& theAllFacePtrInt,
579 SMDS_MeshFace* theStartFace,
580 TMapOfLink& theNonManifold,
581 TColStd_MapOfInteger& theResFaces );
582 bool isInPlane( const SMDS_MeshFace* theFace1,
583 const SMDS_MeshFace* theFace2 );
584 void expandBoundary( TMapOfLink& theMapOfBoundary,
585 TVectorOfLink& theSeqOfBoundary,
586 TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
587 TMapOfLink& theNonManifold,
588 SMDS_MeshFace* theNextFace ) const;
590 void getFacesByLink( const Link& theLink,
591 TVectorOfFacePtr& theFaces ) const;
594 const SMDS_Mesh* myMesh;
595 TColStd_MapOfInteger myMapIds;
596 TColStd_MapOfInteger myMapBadGeomIds;
597 TVectorOfFacePtr myAllFacePtr;
598 TDataMapFacePtrInt myAllFacePtrIntDMap;
600 bool myIsOnlyManifold;
604 typedef boost::shared_ptr<ManifoldPart> ManifoldPartPtr;
608 Class : ElementsOnSurface
609 Description : Predicate elements that lying on indicated surface
612 class SMESHCONTROLS_EXPORT ElementsOnSurface : public virtual Predicate {
615 ~ElementsOnSurface();
616 virtual void SetMesh( const SMDS_Mesh* theMesh );
617 virtual bool IsSatisfy( long theElementId );
618 virtual SMDSAbs_ElementType GetType() const;
620 void SetTolerance( const double theToler );
621 double GetTolerance() const;
622 void SetSurface( const TopoDS_Shape& theShape,
623 const SMDSAbs_ElementType theType );
627 void process( const SMDS_MeshElement* theElem );
628 bool isOnSurface( const SMDS_MeshNode* theNode ) const;
631 const SMDS_Mesh* myMesh;
632 TColStd_MapOfInteger myIds;
633 SMDSAbs_ElementType myType;
634 Handle(Geom_Surface) mySurf;
638 typedef boost::shared_ptr<ElementsOnSurface> ElementsOnSurfacePtr;
644 class SMESHCONTROLS_EXPORT Filter{
648 virtual void SetPredicate(PredicatePtr thePred);
650 typedef std::vector<long> TIdSequence;
654 GetElementsId( const SMDS_Mesh* theMesh,
655 TIdSequence& theSequence );
659 GetElementsId( const SMDS_Mesh* theMesh,
660 PredicatePtr thePredicate,
661 TIdSequence& theSequence );
664 PredicatePtr myPredicate;