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
73 typedef std::vector<gp_XYZ>::size_type size_type;
78 TSequenceOfXYZ(size_type n);
80 TSequenceOfXYZ(size_type n, const gp_XYZ& t);
82 TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ);
84 template <class InputIterator>
85 TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd);
89 TSequenceOfXYZ& operator=(const TSequenceOfXYZ& theSequenceOfXYZ);
91 gp_XYZ& operator()(size_type n);
93 const gp_XYZ& operator()(size_type n) const;
97 void reserve(size_type n);
99 void push_back(const gp_XYZ& v);
101 size_type size() const;
104 std::vector<gp_XYZ> myArray;
109 Description : Root of all Functors
111 class SMESHCONTROLS_EXPORT Functor
115 virtual void SetMesh( const SMDS_Mesh* theMesh ) = 0;
116 virtual SMDSAbs_ElementType GetType() const = 0;
120 Class : NumericalFunctor
121 Description : Root of all Functors returning numeric value
123 class SMESHCONTROLS_EXPORT NumericalFunctor: public virtual Functor{
126 virtual void SetMesh( const SMDS_Mesh* theMesh );
127 virtual double GetValue( long theElementId );
128 virtual double GetValue(const TSequenceOfXYZ& thePoints) { return -1.0;};
129 virtual SMDSAbs_ElementType GetType() const = 0;
130 virtual double GetBadRate( double Value, int nbNodes ) const = 0;
131 long GetPrecision() const;
132 void SetPrecision( const long thePrecision );
134 bool GetPoints(const int theId,
135 TSequenceOfXYZ& theRes) const;
136 static bool GetPoints(const SMDS_MeshElement* theElem,
137 TSequenceOfXYZ& theRes);
139 const SMDS_Mesh* myMesh;
140 const SMDS_MeshElement* myCurrElement;
147 Description : Functor calculating volume of 3D mesh element
149 class SMESHCONTROLS_EXPORT Volume: public virtual NumericalFunctor{
151 virtual double GetValue( long theElementId );
152 //virtual double GetValue( const TSequenceOfXYZ& thePoints );
153 virtual double GetBadRate( double Value, int nbNodes ) const;
154 virtual SMDSAbs_ElementType GetType() const;
159 Class : SMESH_MinimumAngle
160 Description : Functor for calculation of minimum angle
162 class SMESHCONTROLS_EXPORT MinimumAngle: public virtual NumericalFunctor{
164 virtual double GetValue( const TSequenceOfXYZ& thePoints );
165 virtual double GetBadRate( double Value, int nbNodes ) const;
166 virtual SMDSAbs_ElementType GetType() const;
172 Description : Functor for calculating aspect ratio
174 class SMESHCONTROLS_EXPORT AspectRatio: public virtual NumericalFunctor{
176 virtual double GetValue( const TSequenceOfXYZ& thePoints );
177 virtual double GetBadRate( double Value, int nbNodes ) const;
178 virtual SMDSAbs_ElementType GetType() const;
183 Class : AspectRatio3D
184 Description : Functor for calculating aspect ratio of 3D elems.
186 class SMESHCONTROLS_EXPORT AspectRatio3D: public virtual NumericalFunctor{
188 virtual double GetValue( const TSequenceOfXYZ& thePoints );
189 virtual double GetBadRate( double Value, int nbNodes ) const;
190 virtual SMDSAbs_ElementType GetType() const;
196 Description : Functor for calculating warping
198 class SMESHCONTROLS_EXPORT Warping: public virtual NumericalFunctor{
200 virtual double GetValue( const TSequenceOfXYZ& thePoints );
201 virtual double GetBadRate( double Value, int nbNodes ) const;
202 virtual SMDSAbs_ElementType GetType() const;
205 double ComputeA( const gp_XYZ&, const gp_XYZ&, const gp_XYZ&, const gp_XYZ& ) const;
211 Description : Functor for calculating taper
213 class SMESHCONTROLS_EXPORT Taper: public virtual NumericalFunctor{
215 virtual double GetValue( const TSequenceOfXYZ& thePoints );
216 virtual double GetBadRate( double Value, int nbNodes ) const;
217 virtual SMDSAbs_ElementType GetType() const;
223 Description : Functor for calculating skew in degrees
225 class SMESHCONTROLS_EXPORT Skew: public virtual NumericalFunctor{
227 virtual double GetValue( const TSequenceOfXYZ& thePoints );
228 virtual double GetBadRate( double Value, int nbNodes ) const;
229 virtual SMDSAbs_ElementType GetType() const;
235 Description : Functor for calculating area
237 class SMESHCONTROLS_EXPORT Area: public virtual NumericalFunctor{
239 virtual double GetValue( const TSequenceOfXYZ& thePoints );
240 virtual double GetBadRate( double Value, int nbNodes ) const;
241 virtual SMDSAbs_ElementType GetType() const;
247 Description : Functor for calculating length of edge
249 class SMESHCONTROLS_EXPORT Length: public virtual NumericalFunctor{
251 virtual double GetValue( const TSequenceOfXYZ& thePoints );
252 virtual double GetBadRate( double Value, int nbNodes ) const;
253 virtual SMDSAbs_ElementType GetType() const;
258 Description : Functor for calculating length of edge
260 class SMESHCONTROLS_EXPORT Length2D: public virtual NumericalFunctor{
262 virtual double GetValue( long theElementId );
263 virtual double GetBadRate( double Value, int nbNodes ) const;
264 virtual SMDSAbs_ElementType GetType() const;
268 Value(double theLength, long thePntId1, long thePntId2);
269 bool operator<(const Value& x) const;
271 typedef std::set<Value> TValues;
272 void GetValues(TValues& theValues);
274 typedef boost::shared_ptr<Length2D> Length2DPtr;
277 Class : MultiConnection
278 Description : Functor for calculating number of faces conneted to the edge
280 class SMESHCONTROLS_EXPORT MultiConnection: public virtual NumericalFunctor{
282 virtual double GetValue( long theElementId );
283 virtual double GetValue( const TSequenceOfXYZ& thePoints );
284 virtual double GetBadRate( double Value, int nbNodes ) const;
285 virtual SMDSAbs_ElementType GetType() const;
289 Class : MultiConnection2D
290 Description : Functor for calculating number of faces conneted to the edge
292 class SMESHCONTROLS_EXPORT MultiConnection2D: public virtual NumericalFunctor{
294 virtual double GetValue( long theElementId );
295 virtual double GetValue( const TSequenceOfXYZ& thePoints );
296 virtual double GetBadRate( double Value, int nbNodes ) const;
297 virtual SMDSAbs_ElementType GetType() const;
300 Value(long thePntId1, long thePntId2);
301 bool operator<(const Value& x) const;
303 typedef std::map<Value,int> MValues;
305 void GetValues(MValues& theValues);
307 typedef boost::shared_ptr<MultiConnection2D> MultiConnection2DPtr;
313 Description : Base class for all predicates
315 class SMESHCONTROLS_EXPORT Predicate: public virtual Functor{
317 virtual bool IsSatisfy( long theElementId ) = 0;
318 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 free nodes
385 class SMESHCONTROLS_EXPORT FreeNodes: public virtual Predicate{
388 virtual void SetMesh( const SMDS_Mesh* theMesh );
389 virtual bool IsSatisfy( long theNodeId );
390 virtual SMDSAbs_ElementType GetType() const;
393 const SMDS_Mesh* myMesh;
399 Description : Predicate for Range of Ids.
400 Range may be specified with two ways.
401 1. Using AddToRange method
402 2. With SetRangeStr method. Parameter of this method is a string
403 like as "1,2,3,50-60,63,67,70-"
405 class SMESHCONTROLS_EXPORT RangeOfIds: public virtual Predicate
409 virtual void SetMesh( const SMDS_Mesh* theMesh );
410 virtual bool IsSatisfy( long theNodeId );
411 virtual SMDSAbs_ElementType GetType() const;
412 virtual void SetType( SMDSAbs_ElementType theType );
414 bool AddToRange( long theEntityId );
415 void GetRangeStr( TCollection_AsciiString& );
416 bool SetRangeStr( const TCollection_AsciiString& );
419 const SMDS_Mesh* myMesh;
421 TColStd_SequenceOfInteger myMin;
422 TColStd_SequenceOfInteger myMax;
423 TColStd_MapOfInteger myIds;
425 SMDSAbs_ElementType myType;
428 typedef boost::shared_ptr<RangeOfIds> RangeOfIdsPtr;
433 Description : Base class for comparators
435 class SMESHCONTROLS_EXPORT Comparator: public virtual Predicate{
438 virtual ~Comparator();
439 virtual void SetMesh( const SMDS_Mesh* theMesh );
440 virtual void SetMargin(double theValue);
441 virtual void SetNumFunctor(NumericalFunctorPtr theFunct);
442 virtual bool IsSatisfy( long theElementId ) = 0;
443 virtual SMDSAbs_ElementType GetType() const;
448 NumericalFunctorPtr myFunctor;
450 typedef boost::shared_ptr<Comparator> ComparatorPtr;
455 Description : Comparator "<"
457 class SMESHCONTROLS_EXPORT LessThan: public virtual Comparator{
459 virtual bool IsSatisfy( long theElementId );
465 Description : Comparator ">"
467 class SMESHCONTROLS_EXPORT MoreThan: public virtual Comparator{
469 virtual bool IsSatisfy( long theElementId );
475 Description : Comparator "="
477 class SMESHCONTROLS_EXPORT EqualTo: public virtual Comparator{
480 virtual bool IsSatisfy( long theElementId );
481 virtual void SetTolerance( double theTol );
482 virtual double GetTolerance();
487 typedef boost::shared_ptr<EqualTo> EqualToPtr;
492 Description : Logical NOT predicate
494 class SMESHCONTROLS_EXPORT LogicalNOT: public virtual Predicate{
497 virtual ~LogicalNOT();
498 virtual bool IsSatisfy( long theElementId );
499 virtual void SetMesh( const SMDS_Mesh* theMesh );
500 virtual void SetPredicate(PredicatePtr thePred);
501 virtual SMDSAbs_ElementType GetType() const;
504 PredicatePtr myPredicate;
506 typedef boost::shared_ptr<LogicalNOT> LogicalNOTPtr;
510 Class : LogicalBinary
511 Description : Base class for binary logical predicate
513 class SMESHCONTROLS_EXPORT LogicalBinary: public virtual Predicate{
516 virtual ~LogicalBinary();
517 virtual void SetMesh( const SMDS_Mesh* theMesh );
518 virtual void SetPredicate1(PredicatePtr thePred);
519 virtual void SetPredicate2(PredicatePtr thePred);
520 virtual SMDSAbs_ElementType GetType() const;
523 PredicatePtr myPredicate1;
524 PredicatePtr myPredicate2;
526 typedef boost::shared_ptr<LogicalBinary> LogicalBinaryPtr;
531 Description : Logical AND
533 class SMESHCONTROLS_EXPORT LogicalAND: public virtual LogicalBinary{
535 virtual bool IsSatisfy( long theElementId );
541 Description : Logical OR
543 class SMESHCONTROLS_EXPORT LogicalOR: public virtual LogicalBinary{
545 virtual bool IsSatisfy( long theElementId );
551 Description : Predicate for manifold part of mesh
553 class SMESHCONTROLS_EXPORT ManifoldPart: public virtual Predicate{
556 /* internal class for algorithm uses */
560 Link( SMDS_MeshNode* theNode1,
561 SMDS_MeshNode* theNode2 );
564 bool IsEqual( const ManifoldPart::Link& theLink ) const;
565 bool operator<(const ManifoldPart::Link& x) const;
567 SMDS_MeshNode* myNode1;
568 SMDS_MeshNode* myNode2;
571 bool IsEqual( const ManifoldPart::Link& theLink1,
572 const ManifoldPart::Link& theLink2 );
574 typedef std::set<ManifoldPart::Link> TMapOfLink;
575 typedef std::vector<SMDS_MeshFace*> TVectorOfFacePtr;
576 typedef std::vector<ManifoldPart::Link> TVectorOfLink;
577 typedef std::map<SMDS_MeshFace*,int> TDataMapFacePtrInt;
578 typedef std::map<ManifoldPart::Link,SMDS_MeshFace*> TDataMapOfLinkFacePtr;
582 virtual void SetMesh( const SMDS_Mesh* theMesh );
583 // inoke when all parameters already set
584 virtual bool IsSatisfy( long theElementId );
585 virtual SMDSAbs_ElementType GetType() const;
587 void SetAngleTolerance( const double theAngToler );
588 double GetAngleTolerance() const;
589 void SetIsOnlyManifold( const bool theIsOnly );
590 void SetStartElem( const long theStartElemId );
594 bool findConnected( const TDataMapFacePtrInt& theAllFacePtrInt,
595 SMDS_MeshFace* theStartFace,
596 TMapOfLink& theNonManifold,
597 TColStd_MapOfInteger& theResFaces );
598 bool isInPlane( const SMDS_MeshFace* theFace1,
599 const SMDS_MeshFace* theFace2 );
600 void expandBoundary( TMapOfLink& theMapOfBoundary,
601 TVectorOfLink& theSeqOfBoundary,
602 TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
603 TMapOfLink& theNonManifold,
604 SMDS_MeshFace* theNextFace ) const;
606 void getFacesByLink( const Link& theLink,
607 TVectorOfFacePtr& theFaces ) const;
610 const SMDS_Mesh* myMesh;
611 TColStd_MapOfInteger myMapIds;
612 TColStd_MapOfInteger myMapBadGeomIds;
613 TVectorOfFacePtr myAllFacePtr;
614 TDataMapFacePtrInt myAllFacePtrIntDMap;
616 bool myIsOnlyManifold;
620 typedef boost::shared_ptr<ManifoldPart> ManifoldPartPtr;
624 Class : ElementsOnSurface
625 Description : Predicate elements that lying on indicated surface
628 class SMESHCONTROLS_EXPORT ElementsOnSurface : public virtual Predicate {
631 ~ElementsOnSurface();
632 virtual void SetMesh( const SMDS_Mesh* theMesh );
633 virtual bool IsSatisfy( long theElementId );
634 virtual SMDSAbs_ElementType GetType() const;
636 void SetTolerance( const double theToler );
637 double GetTolerance() const;
638 void SetSurface( const TopoDS_Shape& theShape,
639 const SMDSAbs_ElementType theType );
640 void SetUseBoundaries( bool theUse );
641 bool GetUseBoundaries() const { return myUseBoundaries; }
645 void process( const SMDS_MeshElement* theElem );
646 bool isOnSurface( const SMDS_MeshNode* theNode );
649 const SMDS_Mesh* myMesh;
650 TColStd_MapOfInteger myIds;
651 SMDSAbs_ElementType myType;
652 //Handle(Geom_Surface) mySurf;
655 bool myUseBoundaries;
656 GeomAPI_ProjectPointOnSurf myProjector;
659 typedef boost::shared_ptr<ElementsOnSurface> ElementsOnSurfacePtr;
663 Class : ElementsOnShape
664 Description : Predicate elements that lying on indicated shape
667 class SMESHCONTROLS_EXPORT ElementsOnShape : public virtual Predicate
673 virtual void SetMesh (const SMDS_Mesh* theMesh);
674 virtual bool IsSatisfy (long theElementId);
675 virtual SMDSAbs_ElementType GetType() const;
677 void SetTolerance (const double theToler);
678 double GetTolerance() const;
679 void SetAllNodes (bool theAllNodes);
680 bool GetAllNodes() const { return myAllNodesFlag; }
681 void SetShape (const TopoDS_Shape& theShape,
682 const SMDSAbs_ElementType theType);
685 void addShape (const TopoDS_Shape& theShape);
687 void process (const SMDS_MeshElement* theElem);
690 const SMDS_Mesh* myMesh;
691 TColStd_MapOfInteger myIds;
692 SMDSAbs_ElementType myType;
693 TopoDS_Shape myShape;
697 TopTools_MapOfShape myShapesMap;
698 TopAbs_ShapeEnum myCurShapeType; // type of current sub-shape
699 BRepClass3d_SolidClassifier myCurSC; // current SOLID
700 GeomAPI_ProjectPointOnSurf myCurProjFace; // current FACE
701 TopoDS_Face myCurFace; // current FACE
702 GeomAPI_ProjectPointOnCurve myCurProjEdge; // current EDGE
703 gp_Pnt myCurPnt; // current VERTEX
706 typedef boost::shared_ptr<ElementsOnShape> ElementsOnShapePtr;
711 Description : Predicate for free faces
713 class SMESHCONTROLS_EXPORT FreeFaces: public virtual Predicate{
716 virtual void SetMesh( const SMDS_Mesh* theMesh );
717 virtual bool IsSatisfy( long theElementId );
718 virtual SMDSAbs_ElementType GetType() const;
721 const SMDS_Mesh* myMesh;
725 Class : LinearOrQuadratic
726 Description : Predicate for free faces
728 class SMESHCONTROLS_EXPORT LinearOrQuadratic: public virtual Predicate{
731 virtual void SetMesh( const SMDS_Mesh* theMesh );
732 virtual bool IsSatisfy( long theElementId );
733 void SetType( SMDSAbs_ElementType theType );
734 virtual SMDSAbs_ElementType GetType() const;
737 const SMDS_Mesh* myMesh;
738 SMDSAbs_ElementType myType;
740 typedef boost::shared_ptr<LinearOrQuadratic> LinearOrQuadraticPtr;
744 Description : Functor for check color of group to whic mesh element belongs to
746 class SMESHCONTROLS_EXPORT GroupColor: public virtual Predicate{
749 virtual void SetMesh( const SMDS_Mesh* theMesh );
750 virtual bool IsSatisfy( long theElementId );
751 void SetType( SMDSAbs_ElementType theType );
752 virtual SMDSAbs_ElementType GetType() const;
753 void SetColorStr( const TCollection_AsciiString& );
754 void GetColorStr( TCollection_AsciiString& ) const;
757 typedef std::set< long > TIDs;
759 Quantity_Color myColor;
760 SMDSAbs_ElementType myType;
763 typedef boost::shared_ptr<GroupColor> GroupColorPtr;
767 Description : Predicate to check element geometry type
769 class SMESHCONTROLS_EXPORT ElemGeomType: public virtual Predicate{
772 virtual void SetMesh( const SMDS_Mesh* theMesh );
773 virtual bool IsSatisfy( long theElementId );
774 void SetType( SMDSAbs_ElementType theType );
775 virtual SMDSAbs_ElementType GetType() const;
776 void SetGeomType( SMDSAbs_GeometryType theType );
777 virtual SMDSAbs_GeometryType GetGeomType() const;
780 const SMDS_Mesh* myMesh;
781 SMDSAbs_ElementType myType;
782 SMDSAbs_GeometryType myGeomType;
784 typedef boost::shared_ptr<ElemGeomType> ElemGeomTypePtr;
789 class SMESHCONTROLS_EXPORT Filter{
793 virtual void SetPredicate(PredicatePtr thePred);
795 typedef std::vector<long> TIdSequence;
799 GetElementsId( const SMDS_Mesh* theMesh,
800 TIdSequence& theSequence );
804 GetElementsId( const SMDS_Mesh* theMesh,
805 PredicatePtr thePredicate,
806 TIdSequence& theSequence );
809 PredicatePtr myPredicate;