1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef _SMESH_CONTROLSDEF_HXX_
21 #define _SMESH_CONTROLSDEF_HXX_
27 #include <boost/shared_ptr.hpp>
30 #include <GeomAPI_ProjectPointOnSurf.hxx>
31 #include <GeomAPI_ProjectPointOnCurve.hxx>
32 #include <TColStd_SequenceOfInteger.hxx>
33 #include <TColStd_MapOfInteger.hxx>
34 #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;
68 class SMESHCONTROLS_EXPORT TSequenceOfXYZ: public std::vector<gp_XYZ>
71 typedef std::vector<gp_XYZ> TSuperClass;
75 TSequenceOfXYZ(size_type n):
79 TSequenceOfXYZ(size_type n, const value_type& t):
83 TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ):
84 TSuperClass(theSequenceOfXYZ)
87 template <class InputIterator>
88 TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd):
89 TSuperClass(theBegin,theEnd)
92 TSequenceOfXYZ& operator=(const TSequenceOfXYZ& theSequenceOfXYZ){
93 TSuperClass::operator=(theSequenceOfXYZ);
97 reference operator()(size_type n){
98 return TSuperClass::operator[](n-1);
101 const_reference operator()(size_type n) const{
102 return TSuperClass::operator[](n-1);
106 reference operator[](size_type n);
108 const_reference operator[](size_type n) const;
113 Description : Root of all Functors
115 class SMESHCONTROLS_EXPORT Functor
119 virtual void SetMesh( const SMDS_Mesh* theMesh ) = 0;
120 virtual SMDSAbs_ElementType GetType() const = 0;
124 Class : NumericalFunctor
125 Description : Root of all Functors returning numeric value
127 class SMESHCONTROLS_EXPORT NumericalFunctor: public virtual Functor{
130 virtual void SetMesh( const SMDS_Mesh* theMesh );
131 virtual double GetValue( long theElementId );
132 virtual double GetValue(const TSequenceOfXYZ& thePoints) { return -1.0;};
133 virtual SMDSAbs_ElementType GetType() const = 0;
134 virtual double GetBadRate( double Value, int nbNodes ) const = 0;
135 long GetPrecision() const;
136 void SetPrecision( const long thePrecision );
138 bool GetPoints(const int theId,
139 TSequenceOfXYZ& theRes) const;
140 static bool GetPoints(const SMDS_MeshElement* theElem,
141 TSequenceOfXYZ& theRes);
143 const SMDS_Mesh* myMesh;
144 const SMDS_MeshElement* myCurrElement;
151 Description : Functor calculating volume of 3D mesh element
153 class SMESHCONTROLS_EXPORT Volume: public virtual NumericalFunctor{
155 virtual double GetValue( long theElementId );
156 //virtual double GetValue( const TSequenceOfXYZ& thePoints );
157 virtual double GetBadRate( double Value, int nbNodes ) const;
158 virtual SMDSAbs_ElementType GetType() const;
163 Class : SMESH_MinimumAngle
164 Description : Functor for calculation of minimum angle
166 class SMESHCONTROLS_EXPORT MinimumAngle: public virtual NumericalFunctor{
168 virtual double GetValue( const TSequenceOfXYZ& thePoints );
169 virtual double GetBadRate( double Value, int nbNodes ) const;
170 virtual SMDSAbs_ElementType GetType() const;
176 Description : Functor for calculating aspect ratio
178 class SMESHCONTROLS_EXPORT AspectRatio: public virtual NumericalFunctor{
180 virtual double GetValue( const TSequenceOfXYZ& thePoints );
181 virtual double GetBadRate( double Value, int nbNodes ) const;
182 virtual SMDSAbs_ElementType GetType() const;
187 Class : AspectRatio3D
188 Description : Functor for calculating aspect ratio of 3D elems.
190 class SMESHCONTROLS_EXPORT AspectRatio3D: public virtual NumericalFunctor{
192 virtual double GetValue( const TSequenceOfXYZ& thePoints );
193 virtual double GetBadRate( double Value, int nbNodes ) const;
194 virtual SMDSAbs_ElementType GetType() const;
200 Description : Functor for calculating warping
202 class SMESHCONTROLS_EXPORT Warping: public virtual NumericalFunctor{
204 virtual double GetValue( const TSequenceOfXYZ& thePoints );
205 virtual double GetBadRate( double Value, int nbNodes ) const;
206 virtual SMDSAbs_ElementType GetType() const;
209 double ComputeA( const gp_XYZ&, const gp_XYZ&, const gp_XYZ&, const gp_XYZ& ) const;
215 Description : Functor for calculating taper
217 class SMESHCONTROLS_EXPORT Taper: public virtual NumericalFunctor{
219 virtual double GetValue( const TSequenceOfXYZ& thePoints );
220 virtual double GetBadRate( double Value, int nbNodes ) const;
221 virtual SMDSAbs_ElementType GetType() const;
227 Description : Functor for calculating skew in degrees
229 class SMESHCONTROLS_EXPORT Skew: public virtual NumericalFunctor{
231 virtual double GetValue( const TSequenceOfXYZ& thePoints );
232 virtual double GetBadRate( double Value, int nbNodes ) const;
233 virtual SMDSAbs_ElementType GetType() const;
239 Description : Functor for calculating area
241 class SMESHCONTROLS_EXPORT Area: public virtual NumericalFunctor{
243 virtual double GetValue( const TSequenceOfXYZ& thePoints );
244 virtual double GetBadRate( double Value, int nbNodes ) const;
245 virtual SMDSAbs_ElementType GetType() const;
251 Description : Functor for calculating length of edge
253 class SMESHCONTROLS_EXPORT Length: public virtual NumericalFunctor{
255 virtual double GetValue( const TSequenceOfXYZ& thePoints );
256 virtual double GetBadRate( double Value, int nbNodes ) const;
257 virtual SMDSAbs_ElementType GetType() const;
262 Description : Functor for calculating length of edge
264 class SMESHCONTROLS_EXPORT Length2D: public virtual NumericalFunctor{
266 virtual double GetValue( long theElementId );
267 virtual double GetBadRate( double Value, int nbNodes ) const;
268 virtual SMDSAbs_ElementType GetType() const;
272 Value(double theLength, long thePntId1, long thePntId2);
273 bool operator<(const Value& x) const;
275 typedef std::set<Value> TValues;
276 void GetValues(TValues& theValues);
278 typedef boost::shared_ptr<Length2D> Length2DPtr;
281 Class : MultiConnection
282 Description : Functor for calculating number of faces conneted to the edge
284 class SMESHCONTROLS_EXPORT MultiConnection: public virtual NumericalFunctor{
286 virtual double GetValue( long theElementId );
287 virtual double GetValue( const TSequenceOfXYZ& thePoints );
288 virtual double GetBadRate( double Value, int nbNodes ) const;
289 virtual SMDSAbs_ElementType GetType() const;
293 Class : MultiConnection2D
294 Description : Functor for calculating number of faces conneted to the edge
296 class SMESHCONTROLS_EXPORT MultiConnection2D: public virtual NumericalFunctor{
298 virtual double GetValue( long theElementId );
299 virtual double GetValue( const TSequenceOfXYZ& thePoints );
300 virtual double GetBadRate( double Value, int nbNodes ) const;
301 virtual SMDSAbs_ElementType GetType() const;
304 Value(long thePntId1, long thePntId2);
305 bool operator<(const Value& x) const;
307 typedef std::map<Value,int> MValues;
309 void GetValues(MValues& theValues);
311 typedef boost::shared_ptr<MultiConnection2D> MultiConnection2DPtr;
317 Description : Base class for all predicates
319 class SMESHCONTROLS_EXPORT Predicate: public virtual Functor{
321 virtual bool IsSatisfy( long theElementId ) = 0;
322 virtual SMDSAbs_ElementType GetType() const = 0;
328 Description : Predicate for free borders
330 class SMESHCONTROLS_EXPORT FreeBorders: public virtual Predicate{
333 virtual void SetMesh( const SMDS_Mesh* theMesh );
334 virtual bool IsSatisfy( long theElementId );
335 virtual SMDSAbs_ElementType GetType() const;
338 const SMDS_Mesh* myMesh;
343 Class : BadOrientedVolume
344 Description : Predicate bad oriented volumes
346 class SMESHCONTROLS_EXPORT BadOrientedVolume: public virtual Predicate{
349 virtual void SetMesh( const SMDS_Mesh* theMesh );
350 virtual bool IsSatisfy( long theElementId );
351 virtual SMDSAbs_ElementType GetType() const;
354 const SMDS_Mesh* myMesh;
360 Description : Predicate for free Edges
362 class SMESHCONTROLS_EXPORT FreeEdges: public virtual Predicate{
365 virtual void SetMesh( const SMDS_Mesh* theMesh );
366 virtual bool IsSatisfy( long theElementId );
367 virtual SMDSAbs_ElementType GetType() const;
368 static bool IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId );
369 typedef long TElemId;
373 Border(long theElemId, long thePntId1, long thePntId2);
374 bool operator<(const Border& x) const;
376 typedef std::set<Border> TBorders;
377 void GetBoreders(TBorders& theBorders);
380 const SMDS_Mesh* myMesh;
382 typedef boost::shared_ptr<FreeEdges> FreeEdgesPtr;
387 Description : Predicate for Range of Ids.
388 Range may be specified with two ways.
389 1. Using AddToRange method
390 2. With SetRangeStr method. Parameter of this method is a string
391 like as "1,2,3,50-60,63,67,70-"
393 class SMESHCONTROLS_EXPORT RangeOfIds: public virtual Predicate
397 virtual void SetMesh( const SMDS_Mesh* theMesh );
398 virtual bool IsSatisfy( long theNodeId );
399 virtual SMDSAbs_ElementType GetType() const;
400 virtual void SetType( SMDSAbs_ElementType theType );
402 bool AddToRange( long theEntityId );
403 void GetRangeStr( TCollection_AsciiString& );
404 bool SetRangeStr( const TCollection_AsciiString& );
407 const SMDS_Mesh* myMesh;
409 TColStd_SequenceOfInteger myMin;
410 TColStd_SequenceOfInteger myMax;
411 TColStd_MapOfInteger myIds;
413 SMDSAbs_ElementType myType;
416 typedef boost::shared_ptr<RangeOfIds> RangeOfIdsPtr;
421 Description : Base class for comparators
423 class SMESHCONTROLS_EXPORT Comparator: public virtual Predicate{
426 virtual ~Comparator();
427 virtual void SetMesh( const SMDS_Mesh* theMesh );
428 virtual void SetMargin(double theValue);
429 virtual void SetNumFunctor(NumericalFunctorPtr theFunct);
430 virtual bool IsSatisfy( long theElementId ) = 0;
431 virtual SMDSAbs_ElementType GetType() const;
436 NumericalFunctorPtr myFunctor;
438 typedef boost::shared_ptr<Comparator> ComparatorPtr;
443 Description : Comparator "<"
445 class SMESHCONTROLS_EXPORT LessThan: public virtual Comparator{
447 virtual bool IsSatisfy( long theElementId );
453 Description : Comparator ">"
455 class SMESHCONTROLS_EXPORT MoreThan: public virtual Comparator{
457 virtual bool IsSatisfy( long theElementId );
463 Description : Comparator "="
465 class SMESHCONTROLS_EXPORT EqualTo: public virtual Comparator{
468 virtual bool IsSatisfy( long theElementId );
469 virtual void SetTolerance( double theTol );
470 virtual double GetTolerance();
475 typedef boost::shared_ptr<EqualTo> EqualToPtr;
480 Description : Logical NOT predicate
482 class SMESHCONTROLS_EXPORT LogicalNOT: public virtual Predicate{
485 virtual ~LogicalNOT();
486 virtual bool IsSatisfy( long theElementId );
487 virtual void SetMesh( const SMDS_Mesh* theMesh );
488 virtual void SetPredicate(PredicatePtr thePred);
489 virtual SMDSAbs_ElementType GetType() const;
492 PredicatePtr myPredicate;
494 typedef boost::shared_ptr<LogicalNOT> LogicalNOTPtr;
498 Class : LogicalBinary
499 Description : Base class for binary logical predicate
501 class SMESHCONTROLS_EXPORT LogicalBinary: public virtual Predicate{
504 virtual ~LogicalBinary();
505 virtual void SetMesh( const SMDS_Mesh* theMesh );
506 virtual void SetPredicate1(PredicatePtr thePred);
507 virtual void SetPredicate2(PredicatePtr thePred);
508 virtual SMDSAbs_ElementType GetType() const;
511 PredicatePtr myPredicate1;
512 PredicatePtr myPredicate2;
514 typedef boost::shared_ptr<LogicalBinary> LogicalBinaryPtr;
519 Description : Logical AND
521 class SMESHCONTROLS_EXPORT LogicalAND: public virtual LogicalBinary{
523 virtual bool IsSatisfy( long theElementId );
529 Description : Logical OR
531 class SMESHCONTROLS_EXPORT LogicalOR: public virtual LogicalBinary{
533 virtual bool IsSatisfy( long theElementId );
539 Description : Predicate for manifold part of mesh
541 class SMESHCONTROLS_EXPORT ManifoldPart: public virtual Predicate{
544 /* internal class for algorithm uses */
548 Link( SMDS_MeshNode* theNode1,
549 SMDS_MeshNode* theNode2 );
552 bool IsEqual( const ManifoldPart::Link& theLink ) const;
553 bool operator<(const ManifoldPart::Link& x) const;
555 SMDS_MeshNode* myNode1;
556 SMDS_MeshNode* myNode2;
559 bool IsEqual( const ManifoldPart::Link& theLink1,
560 const ManifoldPart::Link& theLink2 );
562 typedef std::set<ManifoldPart::Link> TMapOfLink;
563 typedef std::vector<SMDS_MeshFace*> TVectorOfFacePtr;
564 typedef std::vector<ManifoldPart::Link> TVectorOfLink;
565 typedef std::map<SMDS_MeshFace*,int> TDataMapFacePtrInt;
566 typedef std::map<ManifoldPart::Link,SMDS_MeshFace*> TDataMapOfLinkFacePtr;
570 virtual void SetMesh( const SMDS_Mesh* theMesh );
571 // inoke when all parameters already set
572 virtual bool IsSatisfy( long theElementId );
573 virtual SMDSAbs_ElementType GetType() const;
575 void SetAngleTolerance( const double theAngToler );
576 double GetAngleTolerance() const;
577 void SetIsOnlyManifold( const bool theIsOnly );
578 void SetStartElem( const long theStartElemId );
582 bool findConnected( const TDataMapFacePtrInt& theAllFacePtrInt,
583 SMDS_MeshFace* theStartFace,
584 TMapOfLink& theNonManifold,
585 TColStd_MapOfInteger& theResFaces );
586 bool isInPlane( const SMDS_MeshFace* theFace1,
587 const SMDS_MeshFace* theFace2 );
588 void expandBoundary( TMapOfLink& theMapOfBoundary,
589 TVectorOfLink& theSeqOfBoundary,
590 TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
591 TMapOfLink& theNonManifold,
592 SMDS_MeshFace* theNextFace ) const;
594 void getFacesByLink( const Link& theLink,
595 TVectorOfFacePtr& theFaces ) const;
598 const SMDS_Mesh* myMesh;
599 TColStd_MapOfInteger myMapIds;
600 TColStd_MapOfInteger myMapBadGeomIds;
601 TVectorOfFacePtr myAllFacePtr;
602 TDataMapFacePtrInt myAllFacePtrIntDMap;
604 bool myIsOnlyManifold;
608 typedef boost::shared_ptr<ManifoldPart> ManifoldPartPtr;
612 Class : ElementsOnSurface
613 Description : Predicate elements that lying on indicated surface
616 class SMESHCONTROLS_EXPORT ElementsOnSurface : public virtual Predicate {
619 ~ElementsOnSurface();
620 virtual void SetMesh( const SMDS_Mesh* theMesh );
621 virtual bool IsSatisfy( long theElementId );
622 virtual SMDSAbs_ElementType GetType() const;
624 void SetTolerance( const double theToler );
625 double GetTolerance() const;
626 void SetSurface( const TopoDS_Shape& theShape,
627 const SMDSAbs_ElementType theType );
628 void SetUseBoundaries( bool theUse );
629 bool GetUseBoundaries() const { return myUseBoundaries; }
633 void process( const SMDS_MeshElement* theElem );
634 bool isOnSurface( const SMDS_MeshNode* theNode );
637 const SMDS_Mesh* myMesh;
638 TColStd_MapOfInteger myIds;
639 SMDSAbs_ElementType myType;
640 //Handle(Geom_Surface) mySurf;
643 bool myUseBoundaries;
644 GeomAPI_ProjectPointOnSurf myProjector;
647 typedef boost::shared_ptr<ElementsOnSurface> ElementsOnSurfacePtr;
651 Class : ElementsOnShape
652 Description : Predicate elements that lying on indicated shape
655 class SMESHCONTROLS_EXPORT ElementsOnShape : public virtual Predicate
661 virtual void SetMesh (const SMDS_Mesh* theMesh);
662 virtual bool IsSatisfy (long theElementId);
663 virtual SMDSAbs_ElementType GetType() const;
665 void SetTolerance (const double theToler);
666 double GetTolerance() const;
667 void SetAllNodes (bool theAllNodes);
668 bool GetAllNodes() const { return myAllNodesFlag; }
669 void SetShape (const TopoDS_Shape& theShape,
670 const SMDSAbs_ElementType theType);
673 void addShape (const TopoDS_Shape& theShape);
675 void process (const SMDS_MeshElement* theElem);
678 const SMDS_Mesh* myMesh;
679 TColStd_MapOfInteger myIds;
680 SMDSAbs_ElementType myType;
681 TopoDS_Shape myShape;
685 TopTools_MapOfShape myShapesMap;
686 TopAbs_ShapeEnum myCurShapeType; // type of current sub-shape
687 BRepClass3d_SolidClassifier myCurSC; // current SOLID
688 GeomAPI_ProjectPointOnSurf myCurProjFace; // current FACE
689 TopoDS_Face myCurFace; // current FACE
690 GeomAPI_ProjectPointOnCurve myCurProjEdge; // current EDGE
691 gp_Pnt myCurPnt; // current VERTEX
694 typedef boost::shared_ptr<ElementsOnShape> ElementsOnShapePtr;
700 class SMESHCONTROLS_EXPORT Filter{
704 virtual void SetPredicate(PredicatePtr thePred);
706 typedef std::vector<long> TIdSequence;
710 GetElementsId( const SMDS_Mesh* theMesh,
711 TIdSequence& theSequence );
715 GetElementsId( const SMDS_Mesh* theMesh,
716 PredicatePtr thePredicate,
717 TIdSequence& theSequence );
720 PredicatePtr myPredicate;