1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #ifndef _SMESH_CONTROLSDEF_HXX_
23 #define _SMESH_CONTROLSDEF_HXX_
28 #include <boost/shared_ptr.hpp>
30 //#include <Geom_Surface.hxx>
31 #include <GeomAPI_ProjectPointOnSurf.hxx>
32 #include <GeomAPI_ProjectPointOnCurve.hxx>
33 #include <TColStd_SequenceOfInteger.hxx>
34 #include <TColStd_MapOfInteger.hxx>
35 #include <TCollection_AsciiString.hxx>
36 #include <TopoDS_Face.hxx>
37 #include <TopTools_MapOfShape.hxx>
38 #include <BRepClass3d_SolidClassifier.hxx>
40 #include "SMDSAbs_ElementType.hxx"
41 #include "SMDS_MeshNode.hxx"
43 #include "SMESH_Controls.hxx"
46 #if defined SMESHCONTROLS_EXPORTS
47 #define SMESHCONTROLS_EXPORT __declspec( dllexport )
49 #define SMESHCONTROLS_EXPORT __declspec( dllimport )
52 #define SMESHCONTROLS_EXPORT
55 class SMDS_MeshElement;
61 class SMESHDS_SubMesh;
69 class SMESHCONTROLS_EXPORT TSequenceOfXYZ: public std::vector<gp_XYZ>
72 typedef std::vector<gp_XYZ> TSuperClass;
76 TSequenceOfXYZ(size_type n):
80 TSequenceOfXYZ(size_type n, const value_type& t):
84 TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ):
85 TSuperClass(theSequenceOfXYZ)
88 template <class InputIterator>
89 TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd):
90 TSuperClass(theBegin,theEnd)
93 TSequenceOfXYZ& operator=(const TSequenceOfXYZ& theSequenceOfXYZ){
94 TSuperClass::operator=(theSequenceOfXYZ);
98 reference operator()(size_type n){
99 return TSuperClass::operator[](n-1);
102 const_reference operator()(size_type n) const{
103 return TSuperClass::operator[](n-1);
107 reference operator[](size_type n);
109 const_reference operator[](size_type n) const;
114 Description : Root of all Functors
116 class SMESHCONTROLS_EXPORT Functor
120 virtual void SetMesh( const SMDS_Mesh* theMesh ) = 0;
121 virtual SMDSAbs_ElementType GetType() const = 0;
125 Class : NumericalFunctor
126 Description : Root of all Functors returning numeric value
128 class SMESHCONTROLS_EXPORT NumericalFunctor: public virtual Functor{
131 virtual void SetMesh( const SMDS_Mesh* theMesh );
132 virtual double GetValue( long theElementId );
133 virtual double GetValue(const TSequenceOfXYZ& thePoints) { return -1.0;};
134 virtual SMDSAbs_ElementType GetType() const = 0;
135 virtual double GetBadRate( double Value, int nbNodes ) const = 0;
136 long GetPrecision() const;
137 void SetPrecision( const long thePrecision );
139 bool GetPoints(const int theId,
140 TSequenceOfXYZ& theRes) const;
141 static bool GetPoints(const SMDS_MeshElement* theElem,
142 TSequenceOfXYZ& theRes);
144 const SMDS_Mesh* myMesh;
145 const SMDS_MeshElement* myCurrElement;
152 Description : Functor calculating volume of 3D mesh element
154 class SMESHCONTROLS_EXPORT Volume: public virtual NumericalFunctor{
156 virtual double GetValue( long theElementId );
157 //virtual double GetValue( const TSequenceOfXYZ& thePoints );
158 virtual double GetBadRate( double Value, int nbNodes ) const;
159 virtual SMDSAbs_ElementType GetType() const;
164 Class : SMESH_MinimumAngle
165 Description : Functor for calculation of minimum angle
167 class SMESHCONTROLS_EXPORT MinimumAngle: public virtual NumericalFunctor{
169 virtual double GetValue( const TSequenceOfXYZ& thePoints );
170 virtual double GetBadRate( double Value, int nbNodes ) const;
171 virtual SMDSAbs_ElementType GetType() const;
177 Description : Functor for calculating aspect ratio
179 class SMESHCONTROLS_EXPORT AspectRatio: public virtual NumericalFunctor{
181 virtual double GetValue( const TSequenceOfXYZ& thePoints );
182 virtual double GetBadRate( double Value, int nbNodes ) const;
183 virtual SMDSAbs_ElementType GetType() const;
188 Class : AspectRatio3D
189 Description : Functor for calculating aspect ratio of 3D elems.
191 class SMESHCONTROLS_EXPORT AspectRatio3D: public virtual NumericalFunctor{
193 virtual double GetValue( const TSequenceOfXYZ& thePoints );
194 virtual double GetBadRate( double Value, int nbNodes ) const;
195 virtual SMDSAbs_ElementType GetType() const;
201 Description : Functor for calculating warping
203 class SMESHCONTROLS_EXPORT Warping: public virtual NumericalFunctor{
205 virtual double GetValue( const TSequenceOfXYZ& thePoints );
206 virtual double GetBadRate( double Value, int nbNodes ) const;
207 virtual SMDSAbs_ElementType GetType() const;
210 double ComputeA( const gp_XYZ&, const gp_XYZ&, const gp_XYZ&, const gp_XYZ& ) const;
216 Description : Functor for calculating taper
218 class SMESHCONTROLS_EXPORT Taper: public virtual NumericalFunctor{
220 virtual double GetValue( const TSequenceOfXYZ& thePoints );
221 virtual double GetBadRate( double Value, int nbNodes ) const;
222 virtual SMDSAbs_ElementType GetType() const;
228 Description : Functor for calculating skew in degrees
230 class SMESHCONTROLS_EXPORT Skew: public virtual NumericalFunctor{
232 virtual double GetValue( const TSequenceOfXYZ& thePoints );
233 virtual double GetBadRate( double Value, int nbNodes ) const;
234 virtual SMDSAbs_ElementType GetType() const;
240 Description : Functor for calculating area
242 class SMESHCONTROLS_EXPORT Area: public virtual NumericalFunctor{
244 virtual double GetValue( const TSequenceOfXYZ& thePoints );
245 virtual double GetBadRate( double Value, int nbNodes ) const;
246 virtual SMDSAbs_ElementType GetType() const;
252 Description : Functor for calculating length of edge
254 class SMESHCONTROLS_EXPORT Length: public virtual NumericalFunctor{
256 virtual double GetValue( const TSequenceOfXYZ& thePoints );
257 virtual double GetBadRate( double Value, int nbNodes ) const;
258 virtual SMDSAbs_ElementType GetType() const;
263 Description : Functor for calculating length of edge
265 class SMESHCONTROLS_EXPORT Length2D: public virtual NumericalFunctor{
267 virtual double GetValue( long theElementId );
268 virtual double GetBadRate( double Value, int nbNodes ) const;
269 virtual SMDSAbs_ElementType GetType() const;
273 Value(double theLength, long thePntId1, long thePntId2);
274 bool operator<(const Value& x) const;
276 typedef std::set<Value> TValues;
277 void GetValues(TValues& theValues);
280 typedef boost::shared_ptr<Length2D> Length2DPtr;
283 Class : MultiConnection
284 Description : Functor for calculating number of faces conneted to the edge
286 class SMESHCONTROLS_EXPORT MultiConnection: public virtual NumericalFunctor{
288 virtual double GetValue( long theElementId );
289 virtual double GetValue( const TSequenceOfXYZ& thePoints );
290 virtual double GetBadRate( double Value, int nbNodes ) const;
291 virtual SMDSAbs_ElementType GetType() const;
295 Class : MultiConnection2D
296 Description : Functor for calculating number of faces conneted to the edge
298 class SMESHCONTROLS_EXPORT MultiConnection2D: public virtual NumericalFunctor{
300 virtual double GetValue( long theElementId );
301 virtual double GetValue( const TSequenceOfXYZ& thePoints );
302 virtual double GetBadRate( double Value, int nbNodes ) const;
303 virtual SMDSAbs_ElementType GetType() const;
306 Value(long thePntId1, long thePntId2);
307 bool operator<(const Value& x) const;
309 typedef std::map<Value,int> MValues;
311 void GetValues(MValues& theValues);
313 typedef boost::shared_ptr<MultiConnection2D> MultiConnection2DPtr;
319 Description : Base class for all predicates
321 class SMESHCONTROLS_EXPORT Predicate: public virtual Functor{
323 virtual bool IsSatisfy( long theElementId ) = 0;
324 virtual SMDSAbs_ElementType GetType() const = 0;
331 Description : Predicate for free borders
333 class SMESHCONTROLS_EXPORT FreeBorders: public virtual Predicate{
336 virtual void SetMesh( const SMDS_Mesh* theMesh );
337 virtual bool IsSatisfy( long theElementId );
338 virtual SMDSAbs_ElementType GetType() const;
341 const SMDS_Mesh* myMesh;
346 Class : BadOrientedVolume
347 Description : Predicate bad oriented volumes
349 class SMESHCONTROLS_EXPORT BadOrientedVolume: public virtual Predicate{
352 virtual void SetMesh( const SMDS_Mesh* theMesh );
353 virtual bool IsSatisfy( long theElementId );
354 virtual SMDSAbs_ElementType GetType() const;
357 const SMDS_Mesh* myMesh;
363 Description : Predicate for free Edges
365 class SMESHCONTROLS_EXPORT FreeEdges: public virtual Predicate{
368 virtual void SetMesh( const SMDS_Mesh* theMesh );
369 virtual bool IsSatisfy( long theElementId );
370 virtual SMDSAbs_ElementType GetType() const;
371 static bool IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId );
372 typedef long TElemId;
376 Border(long theElemId, long thePntId1, long thePntId2);
377 bool operator<(const Border& x) const;
379 typedef std::set<Border> TBorders;
380 void GetBoreders(TBorders& theBorders);
383 const SMDS_Mesh* myMesh;
385 typedef boost::shared_ptr<FreeEdges> FreeEdgesPtr;
390 Description : Predicate for Range of Ids.
391 Range may be specified with two ways.
392 1. Using AddToRange method
393 2. With SetRangeStr method. Parameter of this method is a string
394 like as "1,2,3,50-60,63,67,70-"
396 class SMESHCONTROLS_EXPORT RangeOfIds: public virtual Predicate
400 virtual void SetMesh( const SMDS_Mesh* theMesh );
401 virtual bool IsSatisfy( long theNodeId );
402 virtual SMDSAbs_ElementType GetType() const;
403 virtual void SetType( SMDSAbs_ElementType theType );
405 bool AddToRange( long theEntityId );
406 void GetRangeStr( TCollection_AsciiString& );
407 bool SetRangeStr( const TCollection_AsciiString& );
410 const SMDS_Mesh* myMesh;
412 TColStd_SequenceOfInteger myMin;
413 TColStd_SequenceOfInteger myMax;
414 TColStd_MapOfInteger myIds;
416 SMDSAbs_ElementType myType;
419 typedef boost::shared_ptr<RangeOfIds> RangeOfIdsPtr;
424 Description : Base class for comparators
426 class SMESHCONTROLS_EXPORT Comparator: public virtual Predicate{
429 virtual ~Comparator();
430 virtual void SetMesh( const SMDS_Mesh* theMesh );
431 virtual void SetMargin(double theValue);
432 virtual void SetNumFunctor(NumericalFunctorPtr theFunct);
433 virtual bool IsSatisfy( long theElementId ) = 0;
434 virtual SMDSAbs_ElementType GetType() const;
439 NumericalFunctorPtr myFunctor;
441 typedef boost::shared_ptr<Comparator> ComparatorPtr;
446 Description : Comparator "<"
448 class SMESHCONTROLS_EXPORT LessThan: public virtual Comparator{
450 virtual bool IsSatisfy( long theElementId );
456 Description : Comparator ">"
458 class SMESHCONTROLS_EXPORT MoreThan: public virtual Comparator{
460 virtual bool IsSatisfy( long theElementId );
466 Description : Comparator "="
468 class SMESHCONTROLS_EXPORT EqualTo: public virtual Comparator{
471 virtual bool IsSatisfy( long theElementId );
472 virtual void SetTolerance( double theTol );
473 virtual double GetTolerance();
478 typedef boost::shared_ptr<EqualTo> EqualToPtr;
483 Description : Logical NOT predicate
485 class SMESHCONTROLS_EXPORT LogicalNOT: public virtual Predicate{
488 virtual ~LogicalNOT();
489 virtual bool IsSatisfy( long theElementId );
490 virtual void SetMesh( const SMDS_Mesh* theMesh );
491 virtual void SetPredicate(PredicatePtr thePred);
492 virtual SMDSAbs_ElementType GetType() const;
495 PredicatePtr myPredicate;
497 typedef boost::shared_ptr<LogicalNOT> LogicalNOTPtr;
501 Class : LogicalBinary
502 Description : Base class for binary logical predicate
504 class SMESHCONTROLS_EXPORT LogicalBinary: public virtual Predicate{
507 virtual ~LogicalBinary();
508 virtual void SetMesh( const SMDS_Mesh* theMesh );
509 virtual void SetPredicate1(PredicatePtr thePred);
510 virtual void SetPredicate2(PredicatePtr thePred);
511 virtual SMDSAbs_ElementType GetType() const;
514 PredicatePtr myPredicate1;
515 PredicatePtr myPredicate2;
517 typedef boost::shared_ptr<LogicalBinary> LogicalBinaryPtr;
522 Description : Logical AND
524 class SMESHCONTROLS_EXPORT LogicalAND: public virtual LogicalBinary{
526 virtual bool IsSatisfy( long theElementId );
532 Description : Logical OR
534 class SMESHCONTROLS_EXPORT LogicalOR: public virtual LogicalBinary{
536 virtual bool IsSatisfy( long theElementId );
542 Description : Predicate for manifold part of mesh
544 class SMESHCONTROLS_EXPORT ManifoldPart: public virtual Predicate{
547 /* internal class for algorithm uses */
551 Link( SMDS_MeshNode* theNode1,
552 SMDS_MeshNode* theNode2 );
555 bool IsEqual( const ManifoldPart::Link& theLink ) const;
556 bool operator<(const ManifoldPart::Link& x) const;
558 SMDS_MeshNode* myNode1;
559 SMDS_MeshNode* myNode2;
562 bool IsEqual( const ManifoldPart::Link& theLink1,
563 const ManifoldPart::Link& theLink2 );
565 typedef std::set<ManifoldPart::Link> TMapOfLink;
566 typedef std::vector<SMDS_MeshFace*> TVectorOfFacePtr;
567 typedef std::vector<ManifoldPart::Link> TVectorOfLink;
568 typedef std::map<SMDS_MeshFace*,int> TDataMapFacePtrInt;
569 typedef std::map<ManifoldPart::Link,SMDS_MeshFace*> TDataMapOfLinkFacePtr;
573 virtual void SetMesh( const SMDS_Mesh* theMesh );
574 // inoke when all parameters already set
575 virtual bool IsSatisfy( long theElementId );
576 virtual SMDSAbs_ElementType GetType() const;
578 void SetAngleTolerance( const double theAngToler );
579 double GetAngleTolerance() const;
580 void SetIsOnlyManifold( const bool theIsOnly );
581 void SetStartElem( const long theStartElemId );
585 bool findConnected( const TDataMapFacePtrInt& theAllFacePtrInt,
586 SMDS_MeshFace* theStartFace,
587 TMapOfLink& theNonManifold,
588 TColStd_MapOfInteger& theResFaces );
589 bool isInPlane( const SMDS_MeshFace* theFace1,
590 const SMDS_MeshFace* theFace2 );
591 void expandBoundary( TMapOfLink& theMapOfBoundary,
592 TVectorOfLink& theSeqOfBoundary,
593 TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
594 TMapOfLink& theNonManifold,
595 SMDS_MeshFace* theNextFace ) const;
597 void getFacesByLink( const Link& theLink,
598 TVectorOfFacePtr& theFaces ) const;
601 const SMDS_Mesh* myMesh;
602 TColStd_MapOfInteger myMapIds;
603 TColStd_MapOfInteger myMapBadGeomIds;
604 TVectorOfFacePtr myAllFacePtr;
605 TDataMapFacePtrInt myAllFacePtrIntDMap;
607 bool myIsOnlyManifold;
611 typedef boost::shared_ptr<ManifoldPart> ManifoldPartPtr;
615 Class : ElementsOnSurface
616 Description : Predicate elements that lying on indicated surface
619 class SMESHCONTROLS_EXPORT ElementsOnSurface : public virtual Predicate {
622 ~ElementsOnSurface();
623 virtual void SetMesh( const SMDS_Mesh* theMesh );
624 virtual bool IsSatisfy( long theElementId );
625 virtual SMDSAbs_ElementType GetType() const;
627 void SetTolerance( const double theToler );
628 double GetTolerance() const;
629 void SetSurface( const TopoDS_Shape& theShape,
630 const SMDSAbs_ElementType theType );
631 void SetUseBoundaries( bool theUse );
632 bool GetUseBoundaries() const { return myUseBoundaries; }
636 void process( const SMDS_MeshElement* theElem );
637 bool isOnSurface( const SMDS_MeshNode* theNode );
640 const SMDS_Mesh* myMesh;
641 TColStd_MapOfInteger myIds;
642 SMDSAbs_ElementType myType;
643 //Handle(Geom_Surface) mySurf;
646 bool myUseBoundaries;
647 GeomAPI_ProjectPointOnSurf myProjector;
650 typedef boost::shared_ptr<ElementsOnSurface> ElementsOnSurfacePtr;
653 Class : ElementsOnShape
654 Description : Predicate elements that lying on indicated shape
657 class SMESHCONTROLS_EXPORT ElementsOnShape : public virtual Predicate
663 virtual void SetMesh (const SMDS_Mesh* theMesh);
664 virtual bool IsSatisfy (long theElementId);
665 virtual SMDSAbs_ElementType GetType() const;
667 void SetTolerance (const double theToler);
668 double GetTolerance() const;
669 void SetAllNodes (bool theAllNodes);
670 bool GetAllNodes() const { return myAllNodesFlag; }
671 void SetShape (const TopoDS_Shape& theShape,
672 const SMDSAbs_ElementType theType);
675 void addShape (const TopoDS_Shape& theShape);
677 void process (const SMDS_MeshElement* theElem);
680 const SMDS_Mesh* myMesh;
681 TColStd_MapOfInteger myIds;
682 SMDSAbs_ElementType myType;
683 TopoDS_Shape myShape;
687 TopTools_MapOfShape myShapesMap;
688 TopAbs_ShapeEnum myCurShapeType; // type of current sub-shape
689 BRepClass3d_SolidClassifier myCurSC; // current SOLID
690 GeomAPI_ProjectPointOnSurf myCurProjFace; // current FACE
691 TopoDS_Face myCurFace; // current FACE
692 GeomAPI_ProjectPointOnCurve myCurProjEdge; // current EDGE
693 gp_Pnt myCurPnt; // current VERTEX
696 typedef boost::shared_ptr<ElementsOnShape> ElementsOnShapePtr;
702 class SMESHCONTROLS_EXPORT Filter{
706 virtual void SetPredicate(PredicatePtr thePred);
708 typedef std::vector<long> TIdSequence;
712 GetElementsId( const SMDS_Mesh* theMesh,
713 TIdSequence& theSequence );
717 GetElementsId( const SMDS_Mesh* theMesh,
718 PredicatePtr thePredicate,
719 TIdSequence& theSequence );
722 PredicatePtr myPredicate;