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>
76 TSequenceOfXYZ(size_type n);
78 TSequenceOfXYZ(size_type n, const value_type& t);
80 TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ);
82 template <class InputIterator>
83 TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd);
85 TSequenceOfXYZ& operator=(const TSequenceOfXYZ& theSequenceOfXYZ);
87 reference operator()(size_type n);
89 const_reference operator()(size_type n) const;
92 reference operator[](size_type n);
94 const_reference operator[](size_type n) const;
99 Description : Root of all Functors
101 class SMESHCONTROLS_EXPORT Functor
105 virtual void SetMesh( const SMDS_Mesh* theMesh ) = 0;
106 virtual SMDSAbs_ElementType GetType() const = 0;
110 Class : NumericalFunctor
111 Description : Root of all Functors returning numeric value
113 class SMESHCONTROLS_EXPORT NumericalFunctor: public virtual Functor{
116 virtual void SetMesh( const SMDS_Mesh* theMesh );
117 virtual double GetValue( long theElementId );
118 virtual double GetValue(const TSequenceOfXYZ& thePoints) { return -1.0;};
119 virtual SMDSAbs_ElementType GetType() const = 0;
120 virtual double GetBadRate( double Value, int nbNodes ) const = 0;
121 long GetPrecision() const;
122 void SetPrecision( const long thePrecision );
124 bool GetPoints(const int theId,
125 TSequenceOfXYZ& theRes) const;
126 static bool GetPoints(const SMDS_MeshElement* theElem,
127 TSequenceOfXYZ& theRes);
129 const SMDS_Mesh* myMesh;
130 const SMDS_MeshElement* myCurrElement;
137 Description : Functor calculating volume of 3D mesh element
139 class SMESHCONTROLS_EXPORT Volume: public virtual NumericalFunctor{
141 virtual double GetValue( long theElementId );
142 //virtual double GetValue( const TSequenceOfXYZ& thePoints );
143 virtual double GetBadRate( double Value, int nbNodes ) const;
144 virtual SMDSAbs_ElementType GetType() const;
149 Class : SMESH_MinimumAngle
150 Description : Functor for calculation of minimum angle
152 class SMESHCONTROLS_EXPORT MinimumAngle: public virtual NumericalFunctor{
154 virtual double GetValue( const TSequenceOfXYZ& thePoints );
155 virtual double GetBadRate( double Value, int nbNodes ) const;
156 virtual SMDSAbs_ElementType GetType() const;
162 Description : Functor for calculating aspect ratio
164 class SMESHCONTROLS_EXPORT AspectRatio: public virtual NumericalFunctor{
166 virtual double GetValue( const TSequenceOfXYZ& thePoints );
167 virtual double GetBadRate( double Value, int nbNodes ) const;
168 virtual SMDSAbs_ElementType GetType() const;
173 Class : AspectRatio3D
174 Description : Functor for calculating aspect ratio of 3D elems.
176 class SMESHCONTROLS_EXPORT AspectRatio3D: public virtual NumericalFunctor{
178 virtual double GetValue( const TSequenceOfXYZ& thePoints );
179 virtual double GetBadRate( double Value, int nbNodes ) const;
180 virtual SMDSAbs_ElementType GetType() const;
186 Description : Functor for calculating warping
188 class SMESHCONTROLS_EXPORT Warping: public virtual NumericalFunctor{
190 virtual double GetValue( const TSequenceOfXYZ& thePoints );
191 virtual double GetBadRate( double Value, int nbNodes ) const;
192 virtual SMDSAbs_ElementType GetType() const;
195 double ComputeA( const gp_XYZ&, const gp_XYZ&, const gp_XYZ&, const gp_XYZ& ) const;
201 Description : Functor for calculating taper
203 class SMESHCONTROLS_EXPORT Taper: 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;
213 Description : Functor for calculating skew in degrees
215 class SMESHCONTROLS_EXPORT Skew: public virtual NumericalFunctor{
217 virtual double GetValue( const TSequenceOfXYZ& thePoints );
218 virtual double GetBadRate( double Value, int nbNodes ) const;
219 virtual SMDSAbs_ElementType GetType() const;
225 Description : Functor for calculating area
227 class SMESHCONTROLS_EXPORT Area: public virtual NumericalFunctor{
229 virtual double GetValue( const TSequenceOfXYZ& thePoints );
230 virtual double GetBadRate( double Value, int nbNodes ) const;
231 virtual SMDSAbs_ElementType GetType() const;
237 Description : Functor for calculating length of edge
239 class SMESHCONTROLS_EXPORT Length: public virtual NumericalFunctor{
241 virtual double GetValue( const TSequenceOfXYZ& thePoints );
242 virtual double GetBadRate( double Value, int nbNodes ) const;
243 virtual SMDSAbs_ElementType GetType() const;
248 Description : Functor for calculating length of edge
250 class SMESHCONTROLS_EXPORT Length2D: public virtual NumericalFunctor{
252 virtual double GetValue( long theElementId );
253 virtual double GetBadRate( double Value, int nbNodes ) const;
254 virtual SMDSAbs_ElementType GetType() const;
258 Value(double theLength, long thePntId1, long thePntId2);
259 bool operator<(const Value& x) const;
261 typedef std::set<Value> TValues;
262 void GetValues(TValues& theValues);
264 typedef boost::shared_ptr<Length2D> Length2DPtr;
267 Class : MultiConnection
268 Description : Functor for calculating number of faces conneted to the edge
270 class SMESHCONTROLS_EXPORT MultiConnection: public virtual NumericalFunctor{
272 virtual double GetValue( long theElementId );
273 virtual double GetValue( const TSequenceOfXYZ& thePoints );
274 virtual double GetBadRate( double Value, int nbNodes ) const;
275 virtual SMDSAbs_ElementType GetType() const;
279 Class : MultiConnection2D
280 Description : Functor for calculating number of faces conneted to the edge
282 class SMESHCONTROLS_EXPORT MultiConnection2D: public virtual NumericalFunctor{
284 virtual double GetValue( long theElementId );
285 virtual double GetValue( const TSequenceOfXYZ& thePoints );
286 virtual double GetBadRate( double Value, int nbNodes ) const;
287 virtual SMDSAbs_ElementType GetType() const;
290 Value(long thePntId1, long thePntId2);
291 bool operator<(const Value& x) const;
293 typedef std::map<Value,int> MValues;
295 void GetValues(MValues& theValues);
297 typedef boost::shared_ptr<MultiConnection2D> MultiConnection2DPtr;
303 Description : Base class for all predicates
305 class SMESHCONTROLS_EXPORT Predicate: public virtual Functor{
307 virtual bool IsSatisfy( long theElementId ) = 0;
308 virtual SMDSAbs_ElementType GetType() const = 0;
314 Description : Predicate for free borders
316 class SMESHCONTROLS_EXPORT FreeBorders: public virtual Predicate{
319 virtual void SetMesh( const SMDS_Mesh* theMesh );
320 virtual bool IsSatisfy( long theElementId );
321 virtual SMDSAbs_ElementType GetType() const;
324 const SMDS_Mesh* myMesh;
329 Class : BadOrientedVolume
330 Description : Predicate bad oriented volumes
332 class SMESHCONTROLS_EXPORT BadOrientedVolume: public virtual Predicate{
335 virtual void SetMesh( const SMDS_Mesh* theMesh );
336 virtual bool IsSatisfy( long theElementId );
337 virtual SMDSAbs_ElementType GetType() const;
340 const SMDS_Mesh* myMesh;
346 Description : Predicate for free Edges
348 class SMESHCONTROLS_EXPORT FreeEdges: public virtual Predicate{
351 virtual void SetMesh( const SMDS_Mesh* theMesh );
352 virtual bool IsSatisfy( long theElementId );
353 virtual SMDSAbs_ElementType GetType() const;
354 static bool IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId );
355 typedef long TElemId;
359 Border(long theElemId, long thePntId1, long thePntId2);
360 bool operator<(const Border& x) const;
362 typedef std::set<Border> TBorders;
363 void GetBoreders(TBorders& theBorders);
366 const SMDS_Mesh* myMesh;
368 typedef boost::shared_ptr<FreeEdges> FreeEdgesPtr;
373 Description : Predicate for free nodes
375 class SMESHCONTROLS_EXPORT FreeNodes: public virtual Predicate{
378 virtual void SetMesh( const SMDS_Mesh* theMesh );
379 virtual bool IsSatisfy( long theNodeId );
380 virtual SMDSAbs_ElementType GetType() const;
383 const SMDS_Mesh* myMesh;
389 Description : Predicate for Range of Ids.
390 Range may be specified with two ways.
391 1. Using AddToRange method
392 2. With SetRangeStr method. Parameter of this method is a string
393 like as "1,2,3,50-60,63,67,70-"
395 class SMESHCONTROLS_EXPORT RangeOfIds: public virtual Predicate
399 virtual void SetMesh( const SMDS_Mesh* theMesh );
400 virtual bool IsSatisfy( long theNodeId );
401 virtual SMDSAbs_ElementType GetType() const;
402 virtual void SetType( SMDSAbs_ElementType theType );
404 bool AddToRange( long theEntityId );
405 void GetRangeStr( TCollection_AsciiString& );
406 bool SetRangeStr( const TCollection_AsciiString& );
409 const SMDS_Mesh* myMesh;
411 TColStd_SequenceOfInteger myMin;
412 TColStd_SequenceOfInteger myMax;
413 TColStd_MapOfInteger myIds;
415 SMDSAbs_ElementType myType;
418 typedef boost::shared_ptr<RangeOfIds> RangeOfIdsPtr;
423 Description : Base class for comparators
425 class SMESHCONTROLS_EXPORT Comparator: public virtual Predicate{
428 virtual ~Comparator();
429 virtual void SetMesh( const SMDS_Mesh* theMesh );
430 virtual void SetMargin(double theValue);
431 virtual void SetNumFunctor(NumericalFunctorPtr theFunct);
432 virtual bool IsSatisfy( long theElementId ) = 0;
433 virtual SMDSAbs_ElementType GetType() const;
438 NumericalFunctorPtr myFunctor;
440 typedef boost::shared_ptr<Comparator> ComparatorPtr;
445 Description : Comparator "<"
447 class SMESHCONTROLS_EXPORT LessThan: public virtual Comparator{
449 virtual bool IsSatisfy( long theElementId );
455 Description : Comparator ">"
457 class SMESHCONTROLS_EXPORT MoreThan: public virtual Comparator{
459 virtual bool IsSatisfy( long theElementId );
465 Description : Comparator "="
467 class SMESHCONTROLS_EXPORT EqualTo: public virtual Comparator{
470 virtual bool IsSatisfy( long theElementId );
471 virtual void SetTolerance( double theTol );
472 virtual double GetTolerance();
477 typedef boost::shared_ptr<EqualTo> EqualToPtr;
482 Description : Logical NOT predicate
484 class SMESHCONTROLS_EXPORT LogicalNOT: public virtual Predicate{
487 virtual ~LogicalNOT();
488 virtual bool IsSatisfy( long theElementId );
489 virtual void SetMesh( const SMDS_Mesh* theMesh );
490 virtual void SetPredicate(PredicatePtr thePred);
491 virtual SMDSAbs_ElementType GetType() const;
494 PredicatePtr myPredicate;
496 typedef boost::shared_ptr<LogicalNOT> LogicalNOTPtr;
500 Class : LogicalBinary
501 Description : Base class for binary logical predicate
503 class SMESHCONTROLS_EXPORT LogicalBinary: public virtual Predicate{
506 virtual ~LogicalBinary();
507 virtual void SetMesh( const SMDS_Mesh* theMesh );
508 virtual void SetPredicate1(PredicatePtr thePred);
509 virtual void SetPredicate2(PredicatePtr thePred);
510 virtual SMDSAbs_ElementType GetType() const;
513 PredicatePtr myPredicate1;
514 PredicatePtr myPredicate2;
516 typedef boost::shared_ptr<LogicalBinary> LogicalBinaryPtr;
521 Description : Logical AND
523 class SMESHCONTROLS_EXPORT LogicalAND: public virtual LogicalBinary{
525 virtual bool IsSatisfy( long theElementId );
531 Description : Logical OR
533 class SMESHCONTROLS_EXPORT LogicalOR: public virtual LogicalBinary{
535 virtual bool IsSatisfy( long theElementId );
541 Description : Predicate for manifold part of mesh
543 class SMESHCONTROLS_EXPORT ManifoldPart: public virtual Predicate{
546 /* internal class for algorithm uses */
550 Link( SMDS_MeshNode* theNode1,
551 SMDS_MeshNode* theNode2 );
554 bool IsEqual( const ManifoldPart::Link& theLink ) const;
555 bool operator<(const ManifoldPart::Link& x) const;
557 SMDS_MeshNode* myNode1;
558 SMDS_MeshNode* myNode2;
561 bool IsEqual( const ManifoldPart::Link& theLink1,
562 const ManifoldPart::Link& theLink2 );
564 typedef std::set<ManifoldPart::Link> TMapOfLink;
565 typedef std::vector<SMDS_MeshFace*> TVectorOfFacePtr;
566 typedef std::vector<ManifoldPart::Link> TVectorOfLink;
567 typedef std::map<SMDS_MeshFace*,int> TDataMapFacePtrInt;
568 typedef std::map<ManifoldPart::Link,SMDS_MeshFace*> TDataMapOfLinkFacePtr;
572 virtual void SetMesh( const SMDS_Mesh* theMesh );
573 // inoke when all parameters already set
574 virtual bool IsSatisfy( long theElementId );
575 virtual SMDSAbs_ElementType GetType() const;
577 void SetAngleTolerance( const double theAngToler );
578 double GetAngleTolerance() const;
579 void SetIsOnlyManifold( const bool theIsOnly );
580 void SetStartElem( const long theStartElemId );
584 bool findConnected( const TDataMapFacePtrInt& theAllFacePtrInt,
585 SMDS_MeshFace* theStartFace,
586 TMapOfLink& theNonManifold,
587 TColStd_MapOfInteger& theResFaces );
588 bool isInPlane( const SMDS_MeshFace* theFace1,
589 const SMDS_MeshFace* theFace2 );
590 void expandBoundary( TMapOfLink& theMapOfBoundary,
591 TVectorOfLink& theSeqOfBoundary,
592 TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
593 TMapOfLink& theNonManifold,
594 SMDS_MeshFace* theNextFace ) const;
596 void getFacesByLink( const Link& theLink,
597 TVectorOfFacePtr& theFaces ) const;
600 const SMDS_Mesh* myMesh;
601 TColStd_MapOfInteger myMapIds;
602 TColStd_MapOfInteger myMapBadGeomIds;
603 TVectorOfFacePtr myAllFacePtr;
604 TDataMapFacePtrInt myAllFacePtrIntDMap;
606 bool myIsOnlyManifold;
610 typedef boost::shared_ptr<ManifoldPart> ManifoldPartPtr;
614 Class : ElementsOnSurface
615 Description : Predicate elements that lying on indicated surface
618 class SMESHCONTROLS_EXPORT ElementsOnSurface : public virtual Predicate {
621 ~ElementsOnSurface();
622 virtual void SetMesh( const SMDS_Mesh* theMesh );
623 virtual bool IsSatisfy( long theElementId );
624 virtual SMDSAbs_ElementType GetType() const;
626 void SetTolerance( const double theToler );
627 double GetTolerance() const;
628 void SetSurface( const TopoDS_Shape& theShape,
629 const SMDSAbs_ElementType theType );
630 void SetUseBoundaries( bool theUse );
631 bool GetUseBoundaries() const { return myUseBoundaries; }
635 void process( const SMDS_MeshElement* theElem );
636 bool isOnSurface( const SMDS_MeshNode* theNode );
639 const SMDS_Mesh* myMesh;
640 TColStd_MapOfInteger myIds;
641 SMDSAbs_ElementType myType;
642 //Handle(Geom_Surface) mySurf;
645 bool myUseBoundaries;
646 GeomAPI_ProjectPointOnSurf myProjector;
649 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;
701 Description : Predicate for free faces
703 class SMESHCONTROLS_EXPORT FreeFaces: public virtual Predicate{
706 virtual void SetMesh( const SMDS_Mesh* theMesh );
707 virtual bool IsSatisfy( long theElementId );
708 virtual SMDSAbs_ElementType GetType() const;
711 const SMDS_Mesh* myMesh;
715 Class : LinearOrQuadratic
716 Description : Predicate for free faces
718 class SMESHCONTROLS_EXPORT LinearOrQuadratic: public virtual Predicate{
721 virtual void SetMesh( const SMDS_Mesh* theMesh );
722 virtual bool IsSatisfy( long theElementId );
723 void SetType( SMDSAbs_ElementType theType );
724 virtual SMDSAbs_ElementType GetType() const;
727 const SMDS_Mesh* myMesh;
728 SMDSAbs_ElementType myType;
730 typedef boost::shared_ptr<LinearOrQuadratic> LinearOrQuadraticPtr;
734 Description : Functor for check color of group to whic mesh element belongs to
736 class SMESHCONTROLS_EXPORT GroupColor: public virtual Predicate{
739 virtual void SetMesh( const SMDS_Mesh* theMesh );
740 virtual bool IsSatisfy( long theElementId );
741 void SetType( SMDSAbs_ElementType theType );
742 virtual SMDSAbs_ElementType GetType() const;
743 void SetColorStr( const TCollection_AsciiString& );
744 void GetColorStr( TCollection_AsciiString& ) const;
747 typedef std::set< long > TIDs;
749 Quantity_Color myColor;
750 SMDSAbs_ElementType myType;
753 typedef boost::shared_ptr<GroupColor> GroupColorPtr;
757 Description : Predicate to check element geometry type
759 class SMESHCONTROLS_EXPORT ElemGeomType: public virtual Predicate{
762 virtual void SetMesh( const SMDS_Mesh* theMesh );
763 virtual bool IsSatisfy( long theElementId );
764 void SetType( SMDSAbs_ElementType theType );
765 virtual SMDSAbs_ElementType GetType() const;
766 void SetGeomType( SMDSAbs_GeometryType theType );
767 virtual SMDSAbs_GeometryType GetGeomType() const;
770 const SMDS_Mesh* myMesh;
771 SMDSAbs_ElementType myType;
772 SMDSAbs_GeometryType myGeomType;
774 typedef boost::shared_ptr<ElemGeomType> ElemGeomTypePtr;
779 class SMESHCONTROLS_EXPORT Filter{
783 virtual void SetPredicate(PredicatePtr thePred);
785 typedef std::vector<long> TIdSequence;
789 GetElementsId( const SMDS_Mesh* theMesh,
790 TIdSequence& theSequence );
794 GetElementsId( const SMDS_Mesh* theMesh,
795 PredicatePtr thePredicate,
796 TIdSequence& theSequence );
799 PredicatePtr myPredicate;