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_
29 #include <boost/shared_ptr.hpp>
32 #include <GeomAPI_ProjectPointOnSurf.hxx>
33 #include <GeomAPI_ProjectPointOnCurve.hxx>
34 #include <TColStd_SequenceOfInteger.hxx>
35 #include <TColStd_MapOfInteger.hxx>
36 #include <TCollection_AsciiString.hxx>
38 #include <TopoDS_Face.hxx>
39 #include <TopTools_MapOfShape.hxx>
40 #include <BRepClass3d_SolidClassifier.hxx>
41 #include <Quantity_Color.hxx>
43 #include "SMDSAbs_ElementType.hxx"
44 #include "SMDS_MeshNode.hxx"
46 #include "SMESH_Controls.hxx"
49 #if defined SMESHCONTROLS_EXPORTS || defined SMESHControls_EXPORTS
50 #define SMESHCONTROLS_EXPORT __declspec( dllexport )
52 #define SMESHCONTROLS_EXPORT __declspec( dllimport )
55 #define SMESHCONTROLS_EXPORT
58 class SMDS_MeshElement;
64 class SMESHDS_SubMesh;
71 class SMESHCONTROLS_EXPORT TSequenceOfXYZ: public std::vector<gp_XYZ>
74 typedef std::vector<gp_XYZ> TSuperClass;
78 TSequenceOfXYZ(size_type n):
82 TSequenceOfXYZ(size_type n, const value_type& t):
86 TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ):
87 TSuperClass(theSequenceOfXYZ)
90 template <class InputIterator>
91 TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd):
92 TSuperClass(theBegin,theEnd)
95 TSequenceOfXYZ& operator=(const TSequenceOfXYZ& theSequenceOfXYZ){
96 TSuperClass::operator=(theSequenceOfXYZ);
100 reference operator()(size_type n){
101 return TSuperClass::operator[](n-1);
104 const_reference operator()(size_type n) const{
105 return TSuperClass::operator[](n-1);
109 reference operator[](size_type n);
111 const_reference operator[](size_type n) const;
116 Description : Root of all Functors
118 class SMESHCONTROLS_EXPORT Functor
122 virtual void SetMesh( const SMDS_Mesh* theMesh ) = 0;
123 virtual SMDSAbs_ElementType GetType() const = 0;
127 Class : NumericalFunctor
128 Description : Root of all Functors returning numeric value
130 class SMESHCONTROLS_EXPORT NumericalFunctor: public virtual Functor{
133 virtual void SetMesh( const SMDS_Mesh* theMesh );
134 virtual double GetValue( long theElementId );
135 virtual double GetValue(const TSequenceOfXYZ& thePoints) { return -1.0;};
136 virtual SMDSAbs_ElementType GetType() const = 0;
137 virtual double GetBadRate( double Value, int nbNodes ) const = 0;
138 long GetPrecision() const;
139 void SetPrecision( const long thePrecision );
141 bool GetPoints(const int theId,
142 TSequenceOfXYZ& theRes) const;
143 static bool GetPoints(const SMDS_MeshElement* theElem,
144 TSequenceOfXYZ& theRes);
146 const SMDS_Mesh* myMesh;
147 const SMDS_MeshElement* myCurrElement;
154 Description : Functor calculating volume of 3D mesh element
156 class SMESHCONTROLS_EXPORT Volume: public virtual NumericalFunctor{
158 virtual double GetValue( long theElementId );
159 //virtual double GetValue( const TSequenceOfXYZ& thePoints );
160 virtual double GetBadRate( double Value, int nbNodes ) const;
161 virtual SMDSAbs_ElementType GetType() const;
166 Class : SMESH_MinimumAngle
167 Description : Functor for calculation of minimum angle
169 class SMESHCONTROLS_EXPORT MinimumAngle: public virtual NumericalFunctor{
171 virtual double GetValue( const TSequenceOfXYZ& thePoints );
172 virtual double GetBadRate( double Value, int nbNodes ) const;
173 virtual SMDSAbs_ElementType GetType() const;
179 Description : Functor for calculating aspect ratio
181 class SMESHCONTROLS_EXPORT AspectRatio: public virtual NumericalFunctor{
183 virtual double GetValue( const TSequenceOfXYZ& thePoints );
184 virtual double GetBadRate( double Value, int nbNodes ) const;
185 virtual SMDSAbs_ElementType GetType() const;
190 Class : AspectRatio3D
191 Description : Functor for calculating aspect ratio of 3D elems.
193 class SMESHCONTROLS_EXPORT AspectRatio3D: public virtual NumericalFunctor{
195 virtual double GetValue( const TSequenceOfXYZ& thePoints );
196 virtual double GetBadRate( double Value, int nbNodes ) const;
197 virtual SMDSAbs_ElementType GetType() const;
203 Description : Functor for calculating warping
205 class SMESHCONTROLS_EXPORT Warping: public virtual NumericalFunctor{
207 virtual double GetValue( const TSequenceOfXYZ& thePoints );
208 virtual double GetBadRate( double Value, int nbNodes ) const;
209 virtual SMDSAbs_ElementType GetType() const;
212 double ComputeA( const gp_XYZ&, const gp_XYZ&, const gp_XYZ&, const gp_XYZ& ) const;
218 Description : Functor for calculating taper
220 class SMESHCONTROLS_EXPORT Taper: public virtual NumericalFunctor{
222 virtual double GetValue( const TSequenceOfXYZ& thePoints );
223 virtual double GetBadRate( double Value, int nbNodes ) const;
224 virtual SMDSAbs_ElementType GetType() const;
230 Description : Functor for calculating skew in degrees
232 class SMESHCONTROLS_EXPORT Skew: public virtual NumericalFunctor{
234 virtual double GetValue( const TSequenceOfXYZ& thePoints );
235 virtual double GetBadRate( double Value, int nbNodes ) const;
236 virtual SMDSAbs_ElementType GetType() const;
242 Description : Functor for calculating area
244 class SMESHCONTROLS_EXPORT Area: public virtual NumericalFunctor{
246 virtual double GetValue( const TSequenceOfXYZ& thePoints );
247 virtual double GetBadRate( double Value, int nbNodes ) const;
248 virtual SMDSAbs_ElementType GetType() const;
254 Description : Functor for calculating length of edge
256 class SMESHCONTROLS_EXPORT Length: public virtual NumericalFunctor{
258 virtual double GetValue( const TSequenceOfXYZ& thePoints );
259 virtual double GetBadRate( double Value, int nbNodes ) const;
260 virtual SMDSAbs_ElementType GetType() const;
265 Description : Functor for calculating length of edge
267 class SMESHCONTROLS_EXPORT Length2D: public virtual NumericalFunctor{
269 virtual double GetValue( long theElementId );
270 virtual double GetBadRate( double Value, int nbNodes ) const;
271 virtual SMDSAbs_ElementType GetType() const;
275 Value(double theLength, long thePntId1, long thePntId2);
276 bool operator<(const Value& x) const;
278 typedef std::set<Value> TValues;
279 void GetValues(TValues& theValues);
281 typedef boost::shared_ptr<Length2D> Length2DPtr;
284 Class : MultiConnection
285 Description : Functor for calculating number of faces conneted to the edge
287 class SMESHCONTROLS_EXPORT MultiConnection: public virtual NumericalFunctor{
289 virtual double GetValue( long theElementId );
290 virtual double GetValue( const TSequenceOfXYZ& thePoints );
291 virtual double GetBadRate( double Value, int nbNodes ) const;
292 virtual SMDSAbs_ElementType GetType() const;
296 Class : MultiConnection2D
297 Description : Functor for calculating number of faces conneted to the edge
299 class SMESHCONTROLS_EXPORT MultiConnection2D: public virtual NumericalFunctor{
301 virtual double GetValue( long theElementId );
302 virtual double GetValue( const TSequenceOfXYZ& thePoints );
303 virtual double GetBadRate( double Value, int nbNodes ) const;
304 virtual SMDSAbs_ElementType GetType() const;
307 Value(long thePntId1, long thePntId2);
308 bool operator<(const Value& x) const;
310 typedef std::map<Value,int> MValues;
312 void GetValues(MValues& theValues);
314 typedef boost::shared_ptr<MultiConnection2D> MultiConnection2DPtr;
320 Description : Base class for all predicates
322 class SMESHCONTROLS_EXPORT Predicate: public virtual Functor{
324 virtual bool IsSatisfy( long theElementId ) = 0;
325 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 free nodes
392 class SMESHCONTROLS_EXPORT FreeNodes: public virtual Predicate{
395 virtual void SetMesh( const SMDS_Mesh* theMesh );
396 virtual bool IsSatisfy( long theNodeId );
397 virtual SMDSAbs_ElementType GetType() const;
400 const SMDS_Mesh* myMesh;
406 Description : Predicate for Range of Ids.
407 Range may be specified with two ways.
408 1. Using AddToRange method
409 2. With SetRangeStr method. Parameter of this method is a string
410 like as "1,2,3,50-60,63,67,70-"
412 class SMESHCONTROLS_EXPORT RangeOfIds: public virtual Predicate
416 virtual void SetMesh( const SMDS_Mesh* theMesh );
417 virtual bool IsSatisfy( long theNodeId );
418 virtual SMDSAbs_ElementType GetType() const;
419 virtual void SetType( SMDSAbs_ElementType theType );
421 bool AddToRange( long theEntityId );
422 void GetRangeStr( TCollection_AsciiString& );
423 bool SetRangeStr( const TCollection_AsciiString& );
426 const SMDS_Mesh* myMesh;
428 TColStd_SequenceOfInteger myMin;
429 TColStd_SequenceOfInteger myMax;
430 TColStd_MapOfInteger myIds;
432 SMDSAbs_ElementType myType;
435 typedef boost::shared_ptr<RangeOfIds> RangeOfIdsPtr;
440 Description : Base class for comparators
442 class SMESHCONTROLS_EXPORT Comparator: public virtual Predicate{
445 virtual ~Comparator();
446 virtual void SetMesh( const SMDS_Mesh* theMesh );
447 virtual void SetMargin(double theValue);
448 virtual void SetNumFunctor(NumericalFunctorPtr theFunct);
449 virtual bool IsSatisfy( long theElementId ) = 0;
450 virtual SMDSAbs_ElementType GetType() const;
455 NumericalFunctorPtr myFunctor;
457 typedef boost::shared_ptr<Comparator> ComparatorPtr;
462 Description : Comparator "<"
464 class SMESHCONTROLS_EXPORT LessThan: public virtual Comparator{
466 virtual bool IsSatisfy( long theElementId );
472 Description : Comparator ">"
474 class SMESHCONTROLS_EXPORT MoreThan: public virtual Comparator{
476 virtual bool IsSatisfy( long theElementId );
482 Description : Comparator "="
484 class SMESHCONTROLS_EXPORT EqualTo: public virtual Comparator{
487 virtual bool IsSatisfy( long theElementId );
488 virtual void SetTolerance( double theTol );
489 virtual double GetTolerance();
494 typedef boost::shared_ptr<EqualTo> EqualToPtr;
499 Description : Logical NOT predicate
501 class SMESHCONTROLS_EXPORT LogicalNOT: public virtual Predicate{
504 virtual ~LogicalNOT();
505 virtual bool IsSatisfy( long theElementId );
506 virtual void SetMesh( const SMDS_Mesh* theMesh );
507 virtual void SetPredicate(PredicatePtr thePred);
508 virtual SMDSAbs_ElementType GetType() const;
511 PredicatePtr myPredicate;
513 typedef boost::shared_ptr<LogicalNOT> LogicalNOTPtr;
517 Class : LogicalBinary
518 Description : Base class for binary logical predicate
520 class SMESHCONTROLS_EXPORT LogicalBinary: public virtual Predicate{
523 virtual ~LogicalBinary();
524 virtual void SetMesh( const SMDS_Mesh* theMesh );
525 virtual void SetPredicate1(PredicatePtr thePred);
526 virtual void SetPredicate2(PredicatePtr thePred);
527 virtual SMDSAbs_ElementType GetType() const;
530 PredicatePtr myPredicate1;
531 PredicatePtr myPredicate2;
533 typedef boost::shared_ptr<LogicalBinary> LogicalBinaryPtr;
538 Description : Logical AND
540 class SMESHCONTROLS_EXPORT LogicalAND: public virtual LogicalBinary{
542 virtual bool IsSatisfy( long theElementId );
548 Description : Logical OR
550 class SMESHCONTROLS_EXPORT LogicalOR: public virtual LogicalBinary{
552 virtual bool IsSatisfy( long theElementId );
558 Description : Predicate for manifold part of mesh
560 class SMESHCONTROLS_EXPORT ManifoldPart: public virtual Predicate{
563 /* internal class for algorithm uses */
567 Link( SMDS_MeshNode* theNode1,
568 SMDS_MeshNode* theNode2 );
571 bool IsEqual( const ManifoldPart::Link& theLink ) const;
572 bool operator<(const ManifoldPart::Link& x) const;
574 SMDS_MeshNode* myNode1;
575 SMDS_MeshNode* myNode2;
578 bool IsEqual( const ManifoldPart::Link& theLink1,
579 const ManifoldPart::Link& theLink2 );
581 typedef std::set<ManifoldPart::Link> TMapOfLink;
582 typedef std::vector<SMDS_MeshFace*> TVectorOfFacePtr;
583 typedef std::vector<ManifoldPart::Link> TVectorOfLink;
584 typedef std::map<SMDS_MeshFace*,int> TDataMapFacePtrInt;
585 typedef std::map<ManifoldPart::Link,SMDS_MeshFace*> TDataMapOfLinkFacePtr;
589 virtual void SetMesh( const SMDS_Mesh* theMesh );
590 // inoke when all parameters already set
591 virtual bool IsSatisfy( long theElementId );
592 virtual SMDSAbs_ElementType GetType() const;
594 void SetAngleTolerance( const double theAngToler );
595 double GetAngleTolerance() const;
596 void SetIsOnlyManifold( const bool theIsOnly );
597 void SetStartElem( const long theStartElemId );
601 bool findConnected( const TDataMapFacePtrInt& theAllFacePtrInt,
602 SMDS_MeshFace* theStartFace,
603 TMapOfLink& theNonManifold,
604 TColStd_MapOfInteger& theResFaces );
605 bool isInPlane( const SMDS_MeshFace* theFace1,
606 const SMDS_MeshFace* theFace2 );
607 void expandBoundary( TMapOfLink& theMapOfBoundary,
608 TVectorOfLink& theSeqOfBoundary,
609 TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
610 TMapOfLink& theNonManifold,
611 SMDS_MeshFace* theNextFace ) const;
613 void getFacesByLink( const Link& theLink,
614 TVectorOfFacePtr& theFaces ) const;
617 const SMDS_Mesh* myMesh;
618 TColStd_MapOfInteger myMapIds;
619 TColStd_MapOfInteger myMapBadGeomIds;
620 TVectorOfFacePtr myAllFacePtr;
621 TDataMapFacePtrInt myAllFacePtrIntDMap;
623 bool myIsOnlyManifold;
627 typedef boost::shared_ptr<ManifoldPart> ManifoldPartPtr;
631 Class : ElementsOnSurface
632 Description : Predicate elements that lying on indicated surface
635 class SMESHCONTROLS_EXPORT ElementsOnSurface : public virtual Predicate {
638 ~ElementsOnSurface();
639 virtual void SetMesh( const SMDS_Mesh* theMesh );
640 virtual bool IsSatisfy( long theElementId );
641 virtual SMDSAbs_ElementType GetType() const;
643 void SetTolerance( const double theToler );
644 double GetTolerance() const;
645 void SetSurface( const TopoDS_Shape& theShape,
646 const SMDSAbs_ElementType theType );
647 void SetUseBoundaries( bool theUse );
648 bool GetUseBoundaries() const { return myUseBoundaries; }
652 void process( const SMDS_MeshElement* theElem );
653 bool isOnSurface( const SMDS_MeshNode* theNode );
656 const SMDS_Mesh* myMesh;
657 TColStd_MapOfInteger myIds;
658 SMDSAbs_ElementType myType;
659 //Handle(Geom_Surface) mySurf;
662 bool myUseBoundaries;
663 GeomAPI_ProjectPointOnSurf myProjector;
666 typedef boost::shared_ptr<ElementsOnSurface> ElementsOnSurfacePtr;
670 Class : ElementsOnShape
671 Description : Predicate elements that lying on indicated shape
674 class SMESHCONTROLS_EXPORT ElementsOnShape : public virtual Predicate
680 virtual void SetMesh (const SMDS_Mesh* theMesh);
681 virtual bool IsSatisfy (long theElementId);
682 virtual SMDSAbs_ElementType GetType() const;
684 void SetTolerance (const double theToler);
685 double GetTolerance() const;
686 void SetAllNodes (bool theAllNodes);
687 bool GetAllNodes() const { return myAllNodesFlag; }
688 void SetShape (const TopoDS_Shape& theShape,
689 const SMDSAbs_ElementType theType);
692 void addShape (const TopoDS_Shape& theShape);
694 void process (const SMDS_MeshElement* theElem);
697 const SMDS_Mesh* myMesh;
698 TColStd_MapOfInteger myIds;
699 SMDSAbs_ElementType myType;
700 TopoDS_Shape myShape;
704 TopTools_MapOfShape myShapesMap;
705 TopAbs_ShapeEnum myCurShapeType; // type of current sub-shape
706 BRepClass3d_SolidClassifier myCurSC; // current SOLID
707 GeomAPI_ProjectPointOnSurf myCurProjFace; // current FACE
708 TopoDS_Face myCurFace; // current FACE
709 GeomAPI_ProjectPointOnCurve myCurProjEdge; // current EDGE
710 gp_Pnt myCurPnt; // current VERTEX
713 typedef boost::shared_ptr<ElementsOnShape> ElementsOnShapePtr;
718 Description : Predicate for free faces
720 class SMESHCONTROLS_EXPORT FreeFaces: public virtual Predicate{
723 virtual void SetMesh( const SMDS_Mesh* theMesh );
724 virtual bool IsSatisfy( long theElementId );
725 virtual SMDSAbs_ElementType GetType() const;
728 const SMDS_Mesh* myMesh;
732 Class : LinearOrQuadratic
733 Description : Predicate for free faces
735 class SMESHCONTROLS_EXPORT LinearOrQuadratic: public virtual Predicate{
738 virtual void SetMesh( const SMDS_Mesh* theMesh );
739 virtual bool IsSatisfy( long theElementId );
740 void SetType( SMDSAbs_ElementType theType );
741 virtual SMDSAbs_ElementType GetType() const;
744 const SMDS_Mesh* myMesh;
745 SMDSAbs_ElementType myType;
747 typedef boost::shared_ptr<LinearOrQuadratic> LinearOrQuadraticPtr;
751 Description : Functor for check color of group to whic mesh element belongs to
753 class SMESHCONTROLS_EXPORT GroupColor: public virtual Predicate{
756 virtual void SetMesh( const SMDS_Mesh* theMesh );
757 virtual bool IsSatisfy( long theElementId );
758 void SetType( SMDSAbs_ElementType theType );
759 virtual SMDSAbs_ElementType GetType() const;
760 void SetColorStr( const TCollection_AsciiString& );
761 void GetColorStr( TCollection_AsciiString& ) const;
764 typedef std::set< long > TIDs;
766 Quantity_Color myColor;
767 SMDSAbs_ElementType myType;
770 typedef boost::shared_ptr<GroupColor> GroupColorPtr;
774 Description : Predicate to check element geometry type
776 class SMESHCONTROLS_EXPORT ElemGeomType: public virtual Predicate{
779 virtual void SetMesh( const SMDS_Mesh* theMesh );
780 virtual bool IsSatisfy( long theElementId );
781 void SetType( SMDSAbs_ElementType theType );
782 virtual SMDSAbs_ElementType GetType() const;
783 void SetGeomType( SMDSAbs_GeometryType theType );
784 virtual SMDSAbs_GeometryType GetGeomType() const;
787 const SMDS_Mesh* myMesh;
788 SMDSAbs_ElementType myType;
789 SMDSAbs_GeometryType myGeomType;
791 typedef boost::shared_ptr<ElemGeomType> ElemGeomTypePtr;
796 class SMESHCONTROLS_EXPORT Filter{
800 virtual void SetPredicate(PredicatePtr thePred);
802 typedef std::vector<long> TIdSequence;
806 GetElementsId( const SMDS_Mesh* theMesh,
807 TIdSequence& theSequence );
811 GetElementsId( const SMDS_Mesh* theMesh,
812 PredicatePtr thePredicate,
813 TIdSequence& theSequence );
816 PredicatePtr myPredicate;