1 // Copyright (C) 2007-2010 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
23 #ifndef _SMESH_CONTROLSDEF_HXX_
24 #define _SMESH_CONTROLSDEF_HXX_
30 #include <boost/shared_ptr.hpp>
33 #include <GeomAPI_ProjectPointOnSurf.hxx>
34 #include <GeomAPI_ProjectPointOnCurve.hxx>
35 #include <TColStd_SequenceOfInteger.hxx>
36 #include <TColStd_MapOfInteger.hxx>
37 #include <TCollection_AsciiString.hxx>
39 #include <TopoDS_Face.hxx>
40 #include <TopTools_MapOfShape.hxx>
41 #include <BRepClass3d_SolidClassifier.hxx>
42 #include <Quantity_Color.hxx>
44 #include "SMDSAbs_ElementType.hxx"
45 #include "SMDS_MeshNode.hxx"
47 #include "SMESH_Controls.hxx"
50 #if defined SMESHCONTROLS_EXPORTS || defined SMESHControls_EXPORTS
51 #define SMESHCONTROLS_EXPORT __declspec( dllexport )
53 #define SMESHCONTROLS_EXPORT __declspec( dllimport )
56 #define SMESHCONTROLS_EXPORT
59 class SMDS_MeshElement;
65 class SMESHDS_SubMesh;
72 class SMESHCONTROLS_EXPORT TSequenceOfXYZ
74 typedef std::vector<gp_XYZ>::size_type size_type;
79 TSequenceOfXYZ(size_type n);
81 TSequenceOfXYZ(size_type n, const gp_XYZ& t);
83 TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ);
85 template <class InputIterator>
86 TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd);
90 TSequenceOfXYZ& operator=(const TSequenceOfXYZ& theSequenceOfXYZ);
92 gp_XYZ& operator()(size_type n);
94 const gp_XYZ& operator()(size_type n) const;
98 void reserve(size_type n);
100 void push_back(const gp_XYZ& v);
102 size_type size() const;
105 std::vector<gp_XYZ> myArray;
110 Description : Root of all Functors
112 class SMESHCONTROLS_EXPORT Functor
116 virtual void SetMesh( const SMDS_Mesh* theMesh ) = 0;
117 virtual SMDSAbs_ElementType GetType() const = 0;
121 Class : NumericalFunctor
122 Description : Root of all Functors returning numeric value
124 class SMESHCONTROLS_EXPORT NumericalFunctor: public virtual Functor{
127 virtual void SetMesh( const SMDS_Mesh* theMesh );
128 virtual double GetValue( long theElementId );
129 virtual double GetValue(const TSequenceOfXYZ& thePoints) { return -1.0;};
130 virtual SMDSAbs_ElementType GetType() const = 0;
131 virtual double GetBadRate( double Value, int nbNodes ) const = 0;
132 long GetPrecision() const;
133 void SetPrecision( const long thePrecision );
135 bool GetPoints(const int theId,
136 TSequenceOfXYZ& theRes) const;
137 static bool GetPoints(const SMDS_MeshElement* theElem,
138 TSequenceOfXYZ& theRes);
140 const SMDS_Mesh* myMesh;
141 const SMDS_MeshElement* myCurrElement;
148 Description : Functor calculating volume of 3D mesh element
150 class SMESHCONTROLS_EXPORT Volume: public virtual NumericalFunctor{
152 virtual double GetValue( long theElementId );
153 //virtual double GetValue( const TSequenceOfXYZ& thePoints );
154 virtual double GetBadRate( double Value, int nbNodes ) const;
155 virtual SMDSAbs_ElementType GetType() const;
160 Class : SMESH_MinimumAngle
161 Description : Functor for calculation of minimum angle
163 class SMESHCONTROLS_EXPORT MinimumAngle: public virtual NumericalFunctor{
165 virtual double GetValue( const TSequenceOfXYZ& thePoints );
166 virtual double GetBadRate( double Value, int nbNodes ) const;
167 virtual SMDSAbs_ElementType GetType() const;
173 Description : Functor for calculating aspect ratio
175 class SMESHCONTROLS_EXPORT AspectRatio: public virtual NumericalFunctor{
177 virtual double GetValue( const TSequenceOfXYZ& thePoints );
178 virtual double GetBadRate( double Value, int nbNodes ) const;
179 virtual SMDSAbs_ElementType GetType() const;
184 Class : AspectRatio3D
185 Description : Functor for calculating aspect ratio of 3D elems.
187 class SMESHCONTROLS_EXPORT AspectRatio3D: public virtual NumericalFunctor{
189 virtual double GetValue( const TSequenceOfXYZ& thePoints );
190 virtual double GetBadRate( double Value, int nbNodes ) const;
191 virtual SMDSAbs_ElementType GetType() const;
197 Description : Functor for calculating warping
199 class SMESHCONTROLS_EXPORT Warping: public virtual NumericalFunctor{
201 virtual double GetValue( const TSequenceOfXYZ& thePoints );
202 virtual double GetBadRate( double Value, int nbNodes ) const;
203 virtual SMDSAbs_ElementType GetType() const;
206 double ComputeA( const gp_XYZ&, const gp_XYZ&, const gp_XYZ&, const gp_XYZ& ) const;
212 Description : Functor for calculating taper
214 class SMESHCONTROLS_EXPORT Taper: public virtual NumericalFunctor{
216 virtual double GetValue( const TSequenceOfXYZ& thePoints );
217 virtual double GetBadRate( double Value, int nbNodes ) const;
218 virtual SMDSAbs_ElementType GetType() const;
224 Description : Functor for calculating skew in degrees
226 class SMESHCONTROLS_EXPORT Skew: public virtual NumericalFunctor{
228 virtual double GetValue( const TSequenceOfXYZ& thePoints );
229 virtual double GetBadRate( double Value, int nbNodes ) const;
230 virtual SMDSAbs_ElementType GetType() const;
236 Description : Functor for calculating area
238 class SMESHCONTROLS_EXPORT Area: public virtual NumericalFunctor{
240 virtual double GetValue( const TSequenceOfXYZ& thePoints );
241 virtual double GetBadRate( double Value, int nbNodes ) const;
242 virtual SMDSAbs_ElementType GetType() const;
248 Description : Functor for calculating length of edge
250 class SMESHCONTROLS_EXPORT Length: public virtual NumericalFunctor{
252 virtual double GetValue( const TSequenceOfXYZ& thePoints );
253 virtual double GetBadRate( double Value, int nbNodes ) const;
254 virtual SMDSAbs_ElementType GetType() const;
259 Description : Functor for calculating length of edge
261 class SMESHCONTROLS_EXPORT Length2D: public virtual NumericalFunctor{
263 virtual double GetValue( long theElementId );
264 virtual double GetBadRate( double Value, int nbNodes ) const;
265 virtual SMDSAbs_ElementType GetType() const;
269 Value(double theLength, long thePntId1, long thePntId2);
270 bool operator<(const Value& x) const;
272 typedef std::set<Value> TValues;
273 void GetValues(TValues& theValues);
275 typedef boost::shared_ptr<Length2D> Length2DPtr;
278 Class : MultiConnection
279 Description : Functor for calculating number of faces conneted to the edge
281 class SMESHCONTROLS_EXPORT MultiConnection: public virtual NumericalFunctor{
283 virtual double GetValue( long theElementId );
284 virtual double GetValue( const TSequenceOfXYZ& thePoints );
285 virtual double GetBadRate( double Value, int nbNodes ) const;
286 virtual SMDSAbs_ElementType GetType() const;
290 Class : MultiConnection2D
291 Description : Functor for calculating number of faces conneted to the edge
293 class SMESHCONTROLS_EXPORT MultiConnection2D: public virtual NumericalFunctor{
295 virtual double GetValue( long theElementId );
296 virtual double GetValue( const TSequenceOfXYZ& thePoints );
297 virtual double GetBadRate( double Value, int nbNodes ) const;
298 virtual SMDSAbs_ElementType GetType() const;
301 Value(long thePntId1, long thePntId2);
302 bool operator<(const Value& x) const;
304 typedef std::map<Value,int> MValues;
306 void GetValues(MValues& theValues);
308 typedef boost::shared_ptr<MultiConnection2D> MultiConnection2DPtr;
314 Description : Base class for all predicates
316 class SMESHCONTROLS_EXPORT Predicate: public virtual Functor{
318 virtual bool IsSatisfy( long theElementId ) = 0;
319 virtual SMDSAbs_ElementType GetType() const = 0;
325 Description : Predicate for free borders
327 class SMESHCONTROLS_EXPORT FreeBorders: public virtual Predicate{
330 virtual void SetMesh( const SMDS_Mesh* theMesh );
331 virtual bool IsSatisfy( long theElementId );
332 virtual SMDSAbs_ElementType GetType() const;
335 const SMDS_Mesh* myMesh;
340 Class : BadOrientedVolume
341 Description : Predicate bad oriented volumes
343 class SMESHCONTROLS_EXPORT BadOrientedVolume: public virtual Predicate{
346 virtual void SetMesh( const SMDS_Mesh* theMesh );
347 virtual bool IsSatisfy( long theElementId );
348 virtual SMDSAbs_ElementType GetType() const;
351 const SMDS_Mesh* myMesh;
357 Description : Predicate for free Edges
359 class SMESHCONTROLS_EXPORT FreeEdges: public virtual Predicate{
362 virtual void SetMesh( const SMDS_Mesh* theMesh );
363 virtual bool IsSatisfy( long theElementId );
364 virtual SMDSAbs_ElementType GetType() const;
365 static bool IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId );
366 typedef long TElemId;
370 Border(long theElemId, long thePntId1, long thePntId2);
371 bool operator<(const Border& x) const;
373 typedef std::set<Border> TBorders;
374 void GetBoreders(TBorders& theBorders);
377 const SMDS_Mesh* myMesh;
379 typedef boost::shared_ptr<FreeEdges> FreeEdgesPtr;
384 Description : Predicate for free nodes
386 class SMESHCONTROLS_EXPORT FreeNodes: public virtual Predicate{
389 virtual void SetMesh( const SMDS_Mesh* theMesh );
390 virtual bool IsSatisfy( long theNodeId );
391 virtual SMDSAbs_ElementType GetType() const;
394 const SMDS_Mesh* myMesh;
400 Description : Predicate for Range of Ids.
401 Range may be specified with two ways.
402 1. Using AddToRange method
403 2. With SetRangeStr method. Parameter of this method is a string
404 like as "1,2,3,50-60,63,67,70-"
406 class SMESHCONTROLS_EXPORT RangeOfIds: public virtual Predicate
410 virtual void SetMesh( const SMDS_Mesh* theMesh );
411 virtual bool IsSatisfy( long theNodeId );
412 virtual SMDSAbs_ElementType GetType() const;
413 virtual void SetType( SMDSAbs_ElementType theType );
415 bool AddToRange( long theEntityId );
416 void GetRangeStr( TCollection_AsciiString& );
417 bool SetRangeStr( const TCollection_AsciiString& );
420 const SMDS_Mesh* myMesh;
422 TColStd_SequenceOfInteger myMin;
423 TColStd_SequenceOfInteger myMax;
424 TColStd_MapOfInteger myIds;
426 SMDSAbs_ElementType myType;
429 typedef boost::shared_ptr<RangeOfIds> RangeOfIdsPtr;
434 Description : Base class for comparators
436 class SMESHCONTROLS_EXPORT Comparator: public virtual Predicate{
439 virtual ~Comparator();
440 virtual void SetMesh( const SMDS_Mesh* theMesh );
441 virtual void SetMargin(double theValue);
442 virtual void SetNumFunctor(NumericalFunctorPtr theFunct);
443 virtual bool IsSatisfy( long theElementId ) = 0;
444 virtual SMDSAbs_ElementType GetType() const;
449 NumericalFunctorPtr myFunctor;
451 typedef boost::shared_ptr<Comparator> ComparatorPtr;
456 Description : Comparator "<"
458 class SMESHCONTROLS_EXPORT LessThan: public virtual Comparator{
460 virtual bool IsSatisfy( long theElementId );
466 Description : Comparator ">"
468 class SMESHCONTROLS_EXPORT MoreThan: public virtual Comparator{
470 virtual bool IsSatisfy( long theElementId );
476 Description : Comparator "="
478 class SMESHCONTROLS_EXPORT EqualTo: public virtual Comparator{
481 virtual bool IsSatisfy( long theElementId );
482 virtual void SetTolerance( double theTol );
483 virtual double GetTolerance();
488 typedef boost::shared_ptr<EqualTo> EqualToPtr;
493 Description : Logical NOT predicate
495 class SMESHCONTROLS_EXPORT LogicalNOT: public virtual Predicate{
498 virtual ~LogicalNOT();
499 virtual bool IsSatisfy( long theElementId );
500 virtual void SetMesh( const SMDS_Mesh* theMesh );
501 virtual void SetPredicate(PredicatePtr thePred);
502 virtual SMDSAbs_ElementType GetType() const;
505 PredicatePtr myPredicate;
507 typedef boost::shared_ptr<LogicalNOT> LogicalNOTPtr;
511 Class : LogicalBinary
512 Description : Base class for binary logical predicate
514 class SMESHCONTROLS_EXPORT LogicalBinary: public virtual Predicate{
517 virtual ~LogicalBinary();
518 virtual void SetMesh( const SMDS_Mesh* theMesh );
519 virtual void SetPredicate1(PredicatePtr thePred);
520 virtual void SetPredicate2(PredicatePtr thePred);
521 virtual SMDSAbs_ElementType GetType() const;
524 PredicatePtr myPredicate1;
525 PredicatePtr myPredicate2;
527 typedef boost::shared_ptr<LogicalBinary> LogicalBinaryPtr;
532 Description : Logical AND
534 class SMESHCONTROLS_EXPORT LogicalAND: public virtual LogicalBinary{
536 virtual bool IsSatisfy( long theElementId );
542 Description : Logical OR
544 class SMESHCONTROLS_EXPORT LogicalOR: public virtual LogicalBinary{
546 virtual bool IsSatisfy( long theElementId );
552 Description : Predicate for manifold part of mesh
554 class SMESHCONTROLS_EXPORT ManifoldPart: public virtual Predicate{
557 /* internal class for algorithm uses */
561 Link( SMDS_MeshNode* theNode1,
562 SMDS_MeshNode* theNode2 );
565 bool IsEqual( const ManifoldPart::Link& theLink ) const;
566 bool operator<(const ManifoldPart::Link& x) const;
568 SMDS_MeshNode* myNode1;
569 SMDS_MeshNode* myNode2;
572 bool IsEqual( const ManifoldPart::Link& theLink1,
573 const ManifoldPart::Link& theLink2 );
575 typedef std::set<ManifoldPart::Link> TMapOfLink;
576 typedef std::vector<SMDS_MeshFace*> TVectorOfFacePtr;
577 typedef std::vector<ManifoldPart::Link> TVectorOfLink;
578 typedef std::map<SMDS_MeshFace*,int> TDataMapFacePtrInt;
579 typedef std::map<ManifoldPart::Link,SMDS_MeshFace*> TDataMapOfLinkFacePtr;
583 virtual void SetMesh( const SMDS_Mesh* theMesh );
584 // inoke when all parameters already set
585 virtual bool IsSatisfy( long theElementId );
586 virtual SMDSAbs_ElementType GetType() const;
588 void SetAngleTolerance( const double theAngToler );
589 double GetAngleTolerance() const;
590 void SetIsOnlyManifold( const bool theIsOnly );
591 void SetStartElem( const long theStartElemId );
595 bool findConnected( const TDataMapFacePtrInt& theAllFacePtrInt,
596 SMDS_MeshFace* theStartFace,
597 TMapOfLink& theNonManifold,
598 TColStd_MapOfInteger& theResFaces );
599 bool isInPlane( const SMDS_MeshFace* theFace1,
600 const SMDS_MeshFace* theFace2 );
601 void expandBoundary( TMapOfLink& theMapOfBoundary,
602 TVectorOfLink& theSeqOfBoundary,
603 TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
604 TMapOfLink& theNonManifold,
605 SMDS_MeshFace* theNextFace ) const;
607 void getFacesByLink( const Link& theLink,
608 TVectorOfFacePtr& theFaces ) const;
611 const SMDS_Mesh* myMesh;
612 TColStd_MapOfInteger myMapIds;
613 TColStd_MapOfInteger myMapBadGeomIds;
614 TVectorOfFacePtr myAllFacePtr;
615 TDataMapFacePtrInt myAllFacePtrIntDMap;
617 bool myIsOnlyManifold;
621 typedef boost::shared_ptr<ManifoldPart> ManifoldPartPtr;
625 Class : ElementsOnSurface
626 Description : Predicate elements that lying on indicated surface
629 class SMESHCONTROLS_EXPORT ElementsOnSurface : public virtual Predicate {
632 ~ElementsOnSurface();
633 virtual void SetMesh( const SMDS_Mesh* theMesh );
634 virtual bool IsSatisfy( long theElementId );
635 virtual SMDSAbs_ElementType GetType() const;
637 void SetTolerance( const double theToler );
638 double GetTolerance() const;
639 void SetSurface( const TopoDS_Shape& theShape,
640 const SMDSAbs_ElementType theType );
641 void SetUseBoundaries( bool theUse );
642 bool GetUseBoundaries() const { return myUseBoundaries; }
646 void process( const SMDS_MeshElement* theElem );
647 bool isOnSurface( const SMDS_MeshNode* theNode );
650 const SMDS_Mesh* myMesh;
651 TColStd_MapOfInteger myIds;
652 SMDSAbs_ElementType myType;
653 //Handle(Geom_Surface) mySurf;
656 bool myUseBoundaries;
657 GeomAPI_ProjectPointOnSurf myProjector;
660 typedef boost::shared_ptr<ElementsOnSurface> ElementsOnSurfacePtr;
664 Class : ElementsOnShape
665 Description : Predicate elements that lying on indicated shape
668 class SMESHCONTROLS_EXPORT ElementsOnShape : public virtual Predicate
674 virtual void SetMesh (const SMDS_Mesh* theMesh);
675 virtual bool IsSatisfy (long theElementId);
676 virtual SMDSAbs_ElementType GetType() const;
678 void SetTolerance (const double theToler);
679 double GetTolerance() const;
680 void SetAllNodes (bool theAllNodes);
681 bool GetAllNodes() const { return myAllNodesFlag; }
682 void SetShape (const TopoDS_Shape& theShape,
683 const SMDSAbs_ElementType theType);
686 void addShape (const TopoDS_Shape& theShape);
688 void process (const SMDS_MeshElement* theElem);
691 const SMDS_Mesh* myMesh;
692 TColStd_MapOfInteger myIds;
693 SMDSAbs_ElementType myType;
694 TopoDS_Shape myShape;
698 TopTools_MapOfShape myShapesMap;
699 TopAbs_ShapeEnum myCurShapeType; // type of current sub-shape
700 BRepClass3d_SolidClassifier myCurSC; // current SOLID
701 GeomAPI_ProjectPointOnSurf myCurProjFace; // current FACE
702 TopoDS_Face myCurFace; // current FACE
703 GeomAPI_ProjectPointOnCurve myCurProjEdge; // current EDGE
704 gp_Pnt myCurPnt; // current VERTEX
707 typedef boost::shared_ptr<ElementsOnShape> ElementsOnShapePtr;
712 Description : Predicate for free faces
714 class SMESHCONTROLS_EXPORT FreeFaces: public virtual Predicate{
717 virtual void SetMesh( const SMDS_Mesh* theMesh );
718 virtual bool IsSatisfy( long theElementId );
719 virtual SMDSAbs_ElementType GetType() const;
722 const SMDS_Mesh* myMesh;
726 Class : LinearOrQuadratic
727 Description : Predicate for free faces
729 class SMESHCONTROLS_EXPORT LinearOrQuadratic: public virtual Predicate{
732 virtual void SetMesh( const SMDS_Mesh* theMesh );
733 virtual bool IsSatisfy( long theElementId );
734 void SetType( SMDSAbs_ElementType theType );
735 virtual SMDSAbs_ElementType GetType() const;
738 const SMDS_Mesh* myMesh;
739 SMDSAbs_ElementType myType;
741 typedef boost::shared_ptr<LinearOrQuadratic> LinearOrQuadraticPtr;
745 Description : Functor for check color of group to whic mesh element belongs to
747 class SMESHCONTROLS_EXPORT GroupColor: public virtual Predicate{
750 virtual void SetMesh( const SMDS_Mesh* theMesh );
751 virtual bool IsSatisfy( long theElementId );
752 void SetType( SMDSAbs_ElementType theType );
753 virtual SMDSAbs_ElementType GetType() const;
754 void SetColorStr( const TCollection_AsciiString& );
755 void GetColorStr( TCollection_AsciiString& ) const;
758 typedef std::set< long > TIDs;
760 Quantity_Color myColor;
761 SMDSAbs_ElementType myType;
764 typedef boost::shared_ptr<GroupColor> GroupColorPtr;
768 Description : Predicate to check element geometry type
770 class SMESHCONTROLS_EXPORT ElemGeomType: public virtual Predicate{
773 virtual void SetMesh( const SMDS_Mesh* theMesh );
774 virtual bool IsSatisfy( long theElementId );
775 void SetType( SMDSAbs_ElementType theType );
776 virtual SMDSAbs_ElementType GetType() const;
777 void SetGeomType( SMDSAbs_GeometryType theType );
778 virtual SMDSAbs_GeometryType GetGeomType() const;
781 const SMDS_Mesh* myMesh;
782 SMDSAbs_ElementType myType;
783 SMDSAbs_GeometryType myGeomType;
785 typedef boost::shared_ptr<ElemGeomType> ElemGeomTypePtr;
790 class SMESHCONTROLS_EXPORT Filter{
794 virtual void SetPredicate(PredicatePtr thePred);
796 typedef std::vector<long> TIdSequence;
800 GetElementsId( const SMDS_Mesh* theMesh,
801 TIdSequence& theSequence );
805 GetElementsId( const SMDS_Mesh* theMesh,
806 PredicatePtr thePredicate,
807 TIdSequence& theSequence );
810 PredicatePtr myPredicate;