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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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;
144 Description : Functor calculating volume of 3D mesh element
146 class SMESHCONTROLS_EXPORT Volume: public virtual NumericalFunctor{
148 virtual double GetValue( long theElementId );
149 //virtual double GetValue( const TSequenceOfXYZ& thePoints );
150 virtual double GetBadRate( double Value, int nbNodes ) const;
151 virtual SMDSAbs_ElementType GetType() const;
156 Class : SMESH_MinimumAngle
157 Description : Functor for calculation of minimum angle
159 class SMESHCONTROLS_EXPORT MinimumAngle: public virtual NumericalFunctor{
161 virtual double GetValue( const TSequenceOfXYZ& thePoints );
162 virtual double GetBadRate( double Value, int nbNodes ) const;
163 virtual SMDSAbs_ElementType GetType() const;
169 Description : Functor for calculating aspect ratio
171 class SMESHCONTROLS_EXPORT AspectRatio: public virtual NumericalFunctor{
173 virtual double GetValue( const TSequenceOfXYZ& thePoints );
174 virtual double GetBadRate( double Value, int nbNodes ) const;
175 virtual SMDSAbs_ElementType GetType() const;
180 Class : AspectRatio3D
181 Description : Functor for calculating aspect ratio of 3D elems.
183 class SMESHCONTROLS_EXPORT AspectRatio3D: public virtual NumericalFunctor{
185 virtual double GetValue( const TSequenceOfXYZ& thePoints );
186 virtual double GetBadRate( double Value, int nbNodes ) const;
187 virtual SMDSAbs_ElementType GetType() const;
193 Description : Functor for calculating warping
195 class SMESHCONTROLS_EXPORT Warping: public virtual NumericalFunctor{
197 virtual double GetValue( const TSequenceOfXYZ& thePoints );
198 virtual double GetBadRate( double Value, int nbNodes ) const;
199 virtual SMDSAbs_ElementType GetType() const;
202 double ComputeA( const gp_XYZ&, const gp_XYZ&, const gp_XYZ&, const gp_XYZ& ) const;
208 Description : Functor for calculating taper
210 class SMESHCONTROLS_EXPORT Taper: public virtual NumericalFunctor{
212 virtual double GetValue( const TSequenceOfXYZ& thePoints );
213 virtual double GetBadRate( double Value, int nbNodes ) const;
214 virtual SMDSAbs_ElementType GetType() const;
220 Description : Functor for calculating skew in degrees
222 class SMESHCONTROLS_EXPORT Skew: public virtual NumericalFunctor{
224 virtual double GetValue( const TSequenceOfXYZ& thePoints );
225 virtual double GetBadRate( double Value, int nbNodes ) const;
226 virtual SMDSAbs_ElementType GetType() const;
232 Description : Functor for calculating area
234 class SMESHCONTROLS_EXPORT Area: public virtual NumericalFunctor{
236 virtual double GetValue( const TSequenceOfXYZ& thePoints );
237 virtual double GetBadRate( double Value, int nbNodes ) const;
238 virtual SMDSAbs_ElementType GetType() const;
244 Description : Functor for calculating length of edge
246 class SMESHCONTROLS_EXPORT Length: public virtual NumericalFunctor{
248 virtual double GetValue( const TSequenceOfXYZ& thePoints );
249 virtual double GetBadRate( double Value, int nbNodes ) const;
250 virtual SMDSAbs_ElementType GetType() const;
255 Description : Functor for calculating length of edge
257 class SMESHCONTROLS_EXPORT Length2D: public virtual NumericalFunctor{
259 virtual double GetValue( long theElementId );
260 virtual double GetBadRate( double Value, int nbNodes ) const;
261 virtual SMDSAbs_ElementType GetType() const;
265 Value(double theLength, long thePntId1, long thePntId2);
266 bool operator<(const Value& x) const;
268 typedef std::set<Value> TValues;
269 void GetValues(TValues& theValues);
272 typedef boost::shared_ptr<Length2D> Length2DPtr;
275 Class : MultiConnection
276 Description : Functor for calculating number of faces conneted to the edge
278 class SMESHCONTROLS_EXPORT MultiConnection: public virtual NumericalFunctor{
280 virtual double GetValue( long theElementId );
281 virtual double GetValue( const TSequenceOfXYZ& thePoints );
282 virtual double GetBadRate( double Value, int nbNodes ) const;
283 virtual SMDSAbs_ElementType GetType() const;
287 Class : MultiConnection2D
288 Description : Functor for calculating number of faces conneted to the edge
290 class SMESHCONTROLS_EXPORT MultiConnection2D: public virtual NumericalFunctor{
292 virtual double GetValue( long theElementId );
293 virtual double GetValue( const TSequenceOfXYZ& thePoints );
294 virtual double GetBadRate( double Value, int nbNodes ) const;
295 virtual SMDSAbs_ElementType GetType() const;
298 Value(long thePntId1, long thePntId2);
299 bool operator<(const Value& x) const;
301 typedef std::map<Value,int> MValues;
303 void GetValues(MValues& theValues);
305 typedef boost::shared_ptr<MultiConnection2D> MultiConnection2DPtr;
311 Description : Base class for all predicates
313 class SMESHCONTROLS_EXPORT Predicate: public virtual Functor{
315 virtual bool IsSatisfy( long theElementId ) = 0;
316 virtual SMDSAbs_ElementType GetType() const = 0;
323 Description : Predicate for free borders
325 class SMESHCONTROLS_EXPORT FreeBorders: public virtual Predicate{
328 virtual void SetMesh( const SMDS_Mesh* theMesh );
329 virtual bool IsSatisfy( long theElementId );
330 virtual SMDSAbs_ElementType GetType() const;
333 const SMDS_Mesh* myMesh;
338 Class : BadOrientedVolume
339 Description : Predicate bad oriented volumes
341 class SMESHCONTROLS_EXPORT BadOrientedVolume: public virtual Predicate{
344 virtual void SetMesh( const SMDS_Mesh* theMesh );
345 virtual bool IsSatisfy( long theElementId );
346 virtual SMDSAbs_ElementType GetType() const;
349 const SMDS_Mesh* myMesh;
355 Description : Predicate for free Edges
357 class SMESHCONTROLS_EXPORT FreeEdges: public virtual Predicate{
360 virtual void SetMesh( const SMDS_Mesh* theMesh );
361 virtual bool IsSatisfy( long theElementId );
362 virtual SMDSAbs_ElementType GetType() const;
363 static bool IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId );
364 typedef long TElemId;
368 Border(long theElemId, long thePntId1, long thePntId2);
369 bool operator<(const Border& x) const;
371 typedef std::set<Border> TBorders;
372 void GetBoreders(TBorders& theBorders);
375 const SMDS_Mesh* myMesh;
377 typedef boost::shared_ptr<FreeEdges> FreeEdgesPtr;
382 Description : Predicate for Range of Ids.
383 Range may be specified with two ways.
384 1. Using AddToRange method
385 2. With SetRangeStr method. Parameter of this method is a string
386 like as "1,2,3,50-60,63,67,70-"
388 class SMESHCONTROLS_EXPORT RangeOfIds: public virtual Predicate
392 virtual void SetMesh( const SMDS_Mesh* theMesh );
393 virtual bool IsSatisfy( long theNodeId );
394 virtual SMDSAbs_ElementType GetType() const;
395 virtual void SetType( SMDSAbs_ElementType theType );
397 bool AddToRange( long theEntityId );
398 void GetRangeStr( TCollection_AsciiString& );
399 bool SetRangeStr( const TCollection_AsciiString& );
402 const SMDS_Mesh* myMesh;
404 TColStd_SequenceOfInteger myMin;
405 TColStd_SequenceOfInteger myMax;
406 TColStd_MapOfInteger myIds;
408 SMDSAbs_ElementType myType;
411 typedef boost::shared_ptr<RangeOfIds> RangeOfIdsPtr;
416 Description : Base class for comparators
418 class SMESHCONTROLS_EXPORT Comparator: public virtual Predicate{
421 virtual ~Comparator();
422 virtual void SetMesh( const SMDS_Mesh* theMesh );
423 virtual void SetMargin(double theValue);
424 virtual void SetNumFunctor(NumericalFunctorPtr theFunct);
425 virtual bool IsSatisfy( long theElementId ) = 0;
426 virtual SMDSAbs_ElementType GetType() const;
431 NumericalFunctorPtr myFunctor;
433 typedef boost::shared_ptr<Comparator> ComparatorPtr;
438 Description : Comparator "<"
440 class SMESHCONTROLS_EXPORT LessThan: public virtual Comparator{
442 virtual bool IsSatisfy( long theElementId );
448 Description : Comparator ">"
450 class SMESHCONTROLS_EXPORT MoreThan: public virtual Comparator{
452 virtual bool IsSatisfy( long theElementId );
458 Description : Comparator "="
460 class SMESHCONTROLS_EXPORT EqualTo: public virtual Comparator{
463 virtual bool IsSatisfy( long theElementId );
464 virtual void SetTolerance( double theTol );
465 virtual double GetTolerance();
470 typedef boost::shared_ptr<EqualTo> EqualToPtr;
475 Description : Logical NOT predicate
477 class SMESHCONTROLS_EXPORT LogicalNOT: public virtual Predicate{
480 virtual ~LogicalNOT();
481 virtual bool IsSatisfy( long theElementId );
482 virtual void SetMesh( const SMDS_Mesh* theMesh );
483 virtual void SetPredicate(PredicatePtr thePred);
484 virtual SMDSAbs_ElementType GetType() const;
487 PredicatePtr myPredicate;
489 typedef boost::shared_ptr<LogicalNOT> LogicalNOTPtr;
493 Class : LogicalBinary
494 Description : Base class for binary logical predicate
496 class SMESHCONTROLS_EXPORT LogicalBinary: public virtual Predicate{
499 virtual ~LogicalBinary();
500 virtual void SetMesh( const SMDS_Mesh* theMesh );
501 virtual void SetPredicate1(PredicatePtr thePred);
502 virtual void SetPredicate2(PredicatePtr thePred);
503 virtual SMDSAbs_ElementType GetType() const;
506 PredicatePtr myPredicate1;
507 PredicatePtr myPredicate2;
509 typedef boost::shared_ptr<LogicalBinary> LogicalBinaryPtr;
514 Description : Logical AND
516 class SMESHCONTROLS_EXPORT LogicalAND: public virtual LogicalBinary{
518 virtual bool IsSatisfy( long theElementId );
524 Description : Logical OR
526 class SMESHCONTROLS_EXPORT LogicalOR: public virtual LogicalBinary{
528 virtual bool IsSatisfy( long theElementId );
534 Description : Predicate for manifold part of mesh
536 class SMESHCONTROLS_EXPORT ManifoldPart: public virtual Predicate{
539 /* internal class for algorithm uses */
543 Link( SMDS_MeshNode* theNode1,
544 SMDS_MeshNode* theNode2 );
547 bool IsEqual( const ManifoldPart::Link& theLink ) const;
548 bool operator<(const ManifoldPart::Link& x) const;
550 SMDS_MeshNode* myNode1;
551 SMDS_MeshNode* myNode2;
554 bool IsEqual( const ManifoldPart::Link& theLink1,
555 const ManifoldPart::Link& theLink2 );
557 typedef std::set<ManifoldPart::Link> TMapOfLink;
558 typedef std::vector<SMDS_MeshFace*> TVectorOfFacePtr;
559 typedef std::vector<ManifoldPart::Link> TVectorOfLink;
560 typedef std::map<SMDS_MeshFace*,int> TDataMapFacePtrInt;
561 typedef std::map<ManifoldPart::Link,SMDS_MeshFace*> TDataMapOfLinkFacePtr;
565 virtual void SetMesh( const SMDS_Mesh* theMesh );
566 // inoke when all parameters already set
567 virtual bool IsSatisfy( long theElementId );
568 virtual SMDSAbs_ElementType GetType() const;
570 void SetAngleTolerance( const double theAngToler );
571 double GetAngleTolerance() const;
572 void SetIsOnlyManifold( const bool theIsOnly );
573 void SetStartElem( const long theStartElemId );
577 bool findConnected( const TDataMapFacePtrInt& theAllFacePtrInt,
578 SMDS_MeshFace* theStartFace,
579 TMapOfLink& theNonManifold,
580 TColStd_MapOfInteger& theResFaces );
581 bool isInPlane( const SMDS_MeshFace* theFace1,
582 const SMDS_MeshFace* theFace2 );
583 void expandBoundary( TMapOfLink& theMapOfBoundary,
584 TVectorOfLink& theSeqOfBoundary,
585 TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
586 TMapOfLink& theNonManifold,
587 SMDS_MeshFace* theNextFace ) const;
589 void getFacesByLink( const Link& theLink,
590 TVectorOfFacePtr& theFaces ) const;
593 const SMDS_Mesh* myMesh;
594 TColStd_MapOfInteger myMapIds;
595 TColStd_MapOfInteger myMapBadGeomIds;
596 TVectorOfFacePtr myAllFacePtr;
597 TDataMapFacePtrInt myAllFacePtrIntDMap;
599 bool myIsOnlyManifold;
603 typedef boost::shared_ptr<ManifoldPart> ManifoldPartPtr;
607 Class : ElementsOnSurface
608 Description : Predicate elements that lying on indicated surface
611 class SMESHCONTROLS_EXPORT ElementsOnSurface : public virtual Predicate {
614 ~ElementsOnSurface();
615 virtual void SetMesh( const SMDS_Mesh* theMesh );
616 virtual bool IsSatisfy( long theElementId );
617 virtual SMDSAbs_ElementType GetType() const;
619 void SetTolerance( const double theToler );
620 double GetTolerance() const;
621 void SetSurface( const TopoDS_Shape& theShape,
622 const SMDSAbs_ElementType theType );
626 void process( const SMDS_MeshElement* theElem );
627 bool isOnSurface( const SMDS_MeshNode* theNode ) const;
630 const SMDS_Mesh* myMesh;
631 TColStd_MapOfInteger myIds;
632 SMDSAbs_ElementType myType;
633 Handle(Geom_Surface) mySurf;
637 typedef boost::shared_ptr<ElementsOnSurface> ElementsOnSurfacePtr;
643 class SMESHCONTROLS_EXPORT Filter{
647 virtual void SetPredicate(PredicatePtr thePred);
649 typedef std::vector<long> TIdSequence;
653 GetElementsId( const SMDS_Mesh* theMesh,
654 TIdSequence& theSequence );
658 GetElementsId( const SMDS_Mesh* theMesh,
659 PredicatePtr thePredicate,
660 TIdSequence& theSequence );
663 PredicatePtr myPredicate;