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_
28 #include <boost/shared_ptr.hpp>
30 //#include <Geom_Surface.hxx>
31 #include <GeomAPI_ProjectPointOnSurf.hxx>
32 #include <GeomAPI_ProjectPointOnCurve.hxx>
33 #include <TColStd_SequenceOfInteger.hxx>
34 #include <TColStd_MapOfInteger.hxx>
35 #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;
69 class SMESHCONTROLS_EXPORT TSequenceOfXYZ
71 typedef std::vector<gp_XYZ>::size_type size_type;
76 TSequenceOfXYZ(size_type n);
78 TSequenceOfXYZ(size_type n, const gp_XYZ& t);
80 TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ);
82 template <class InputIterator>
83 TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd);
87 TSequenceOfXYZ& operator=(const TSequenceOfXYZ& theSequenceOfXYZ);
89 gp_XYZ& operator()(size_type n);
91 const gp_XYZ& operator()(size_type n) const;
95 void reserve(size_type n);
97 void push_back(const gp_XYZ& v);
99 size_type size() const;
102 std::vector<gp_XYZ> myArray;
107 Description : Root of all Functors
109 class SMESHCONTROLS_EXPORT Functor
113 virtual void SetMesh( const SMDS_Mesh* theMesh ) = 0;
114 virtual SMDSAbs_ElementType GetType() const = 0;
118 Class : NumericalFunctor
119 Description : Root of all Functors returning numeric value
121 class SMESHCONTROLS_EXPORT NumericalFunctor: public virtual Functor{
124 virtual void SetMesh( const SMDS_Mesh* theMesh );
125 virtual double GetValue( long theElementId );
126 virtual double GetValue(const TSequenceOfXYZ& thePoints) { return -1.0;};
127 virtual SMDSAbs_ElementType GetType() const = 0;
128 virtual double GetBadRate( double Value, int nbNodes ) const = 0;
129 long GetPrecision() const;
130 void SetPrecision( const long thePrecision );
132 bool GetPoints(const int theId,
133 TSequenceOfXYZ& theRes) const;
134 static bool GetPoints(const SMDS_MeshElement* theElem,
135 TSequenceOfXYZ& theRes);
137 const SMDS_Mesh* myMesh;
138 const SMDS_MeshElement* myCurrElement;
145 Description : Functor calculating volume of 3D mesh element
147 class SMESHCONTROLS_EXPORT Volume: public virtual NumericalFunctor{
149 virtual double GetValue( long theElementId );
150 //virtual double GetValue( const TSequenceOfXYZ& thePoints );
151 virtual double GetBadRate( double Value, int nbNodes ) const;
152 virtual SMDSAbs_ElementType GetType() const;
157 Class : SMESH_MinimumAngle
158 Description : Functor for calculation of minimum angle
160 class SMESHCONTROLS_EXPORT MinimumAngle: public virtual NumericalFunctor{
162 virtual double GetValue( const TSequenceOfXYZ& thePoints );
163 virtual double GetBadRate( double Value, int nbNodes ) const;
164 virtual SMDSAbs_ElementType GetType() const;
170 Description : Functor for calculating aspect ratio
172 class SMESHCONTROLS_EXPORT AspectRatio: public virtual NumericalFunctor{
174 virtual double GetValue( const TSequenceOfXYZ& thePoints );
175 virtual double GetBadRate( double Value, int nbNodes ) const;
176 virtual SMDSAbs_ElementType GetType() const;
181 Class : AspectRatio3D
182 Description : Functor for calculating aspect ratio of 3D elems.
184 class SMESHCONTROLS_EXPORT AspectRatio3D: public virtual NumericalFunctor{
186 virtual double GetValue( const TSequenceOfXYZ& thePoints );
187 virtual double GetBadRate( double Value, int nbNodes ) const;
188 virtual SMDSAbs_ElementType GetType() const;
194 Description : Functor for calculating warping
196 class SMESHCONTROLS_EXPORT Warping: public virtual NumericalFunctor{
198 virtual double GetValue( const TSequenceOfXYZ& thePoints );
199 virtual double GetBadRate( double Value, int nbNodes ) const;
200 virtual SMDSAbs_ElementType GetType() const;
203 double ComputeA( const gp_XYZ&, const gp_XYZ&, const gp_XYZ&, const gp_XYZ& ) const;
209 Description : Functor for calculating taper
211 class SMESHCONTROLS_EXPORT Taper: public virtual NumericalFunctor{
213 virtual double GetValue( const TSequenceOfXYZ& thePoints );
214 virtual double GetBadRate( double Value, int nbNodes ) const;
215 virtual SMDSAbs_ElementType GetType() const;
221 Description : Functor for calculating skew in degrees
223 class SMESHCONTROLS_EXPORT Skew: public virtual NumericalFunctor{
225 virtual double GetValue( const TSequenceOfXYZ& thePoints );
226 virtual double GetBadRate( double Value, int nbNodes ) const;
227 virtual SMDSAbs_ElementType GetType() const;
233 Description : Functor for calculating area
235 class SMESHCONTROLS_EXPORT Area: public virtual NumericalFunctor{
237 virtual double GetValue( const TSequenceOfXYZ& thePoints );
238 virtual double GetBadRate( double Value, int nbNodes ) const;
239 virtual SMDSAbs_ElementType GetType() const;
245 Description : Functor for calculating length of edge
247 class SMESHCONTROLS_EXPORT Length: public virtual NumericalFunctor{
249 virtual double GetValue( const TSequenceOfXYZ& thePoints );
250 virtual double GetBadRate( double Value, int nbNodes ) const;
251 virtual SMDSAbs_ElementType GetType() const;
256 Description : Functor for calculating length of edge
258 class SMESHCONTROLS_EXPORT Length2D: public virtual NumericalFunctor{
260 virtual double GetValue( long theElementId );
261 virtual double GetBadRate( double Value, int nbNodes ) const;
262 virtual SMDSAbs_ElementType GetType() const;
266 Value(double theLength, long thePntId1, long thePntId2);
267 bool operator<(const Value& x) const;
269 typedef std::set<Value> TValues;
270 void GetValues(TValues& theValues);
273 typedef boost::shared_ptr<Length2D> Length2DPtr;
276 Class : MultiConnection
277 Description : Functor for calculating number of faces conneted to the edge
279 class SMESHCONTROLS_EXPORT MultiConnection: public virtual NumericalFunctor{
281 virtual double GetValue( long theElementId );
282 virtual double GetValue( const TSequenceOfXYZ& thePoints );
283 virtual double GetBadRate( double Value, int nbNodes ) const;
284 virtual SMDSAbs_ElementType GetType() const;
288 Class : MultiConnection2D
289 Description : Functor for calculating number of faces conneted to the edge
291 class SMESHCONTROLS_EXPORT MultiConnection2D: public virtual NumericalFunctor{
293 virtual double GetValue( long theElementId );
294 virtual double GetValue( const TSequenceOfXYZ& thePoints );
295 virtual double GetBadRate( double Value, int nbNodes ) const;
296 virtual SMDSAbs_ElementType GetType() const;
299 Value(long thePntId1, long thePntId2);
300 bool operator<(const Value& x) const;
302 typedef std::map<Value,int> MValues;
304 void GetValues(MValues& theValues);
306 typedef boost::shared_ptr<MultiConnection2D> MultiConnection2DPtr;
312 Description : Base class for all predicates
314 class SMESHCONTROLS_EXPORT Predicate: public virtual Functor{
316 virtual bool IsSatisfy( long theElementId ) = 0;
317 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 Range of Ids.
384 Range may be specified with two ways.
385 1. Using AddToRange method
386 2. With SetRangeStr method. Parameter of this method is a string
387 like as "1,2,3,50-60,63,67,70-"
389 class SMESHCONTROLS_EXPORT RangeOfIds: public virtual Predicate
393 virtual void SetMesh( const SMDS_Mesh* theMesh );
394 virtual bool IsSatisfy( long theNodeId );
395 virtual SMDSAbs_ElementType GetType() const;
396 virtual void SetType( SMDSAbs_ElementType theType );
398 bool AddToRange( long theEntityId );
399 void GetRangeStr( TCollection_AsciiString& );
400 bool SetRangeStr( const TCollection_AsciiString& );
403 const SMDS_Mesh* myMesh;
405 TColStd_SequenceOfInteger myMin;
406 TColStd_SequenceOfInteger myMax;
407 TColStd_MapOfInteger myIds;
409 SMDSAbs_ElementType myType;
412 typedef boost::shared_ptr<RangeOfIds> RangeOfIdsPtr;
417 Description : Base class for comparators
419 class SMESHCONTROLS_EXPORT Comparator: public virtual Predicate{
422 virtual ~Comparator();
423 virtual void SetMesh( const SMDS_Mesh* theMesh );
424 virtual void SetMargin(double theValue);
425 virtual void SetNumFunctor(NumericalFunctorPtr theFunct);
426 virtual bool IsSatisfy( long theElementId ) = 0;
427 virtual SMDSAbs_ElementType GetType() const;
432 NumericalFunctorPtr myFunctor;
434 typedef boost::shared_ptr<Comparator> ComparatorPtr;
439 Description : Comparator "<"
441 class SMESHCONTROLS_EXPORT LessThan: public virtual Comparator{
443 virtual bool IsSatisfy( long theElementId );
449 Description : Comparator ">"
451 class SMESHCONTROLS_EXPORT MoreThan: public virtual Comparator{
453 virtual bool IsSatisfy( long theElementId );
459 Description : Comparator "="
461 class SMESHCONTROLS_EXPORT EqualTo: public virtual Comparator{
464 virtual bool IsSatisfy( long theElementId );
465 virtual void SetTolerance( double theTol );
466 virtual double GetTolerance();
471 typedef boost::shared_ptr<EqualTo> EqualToPtr;
476 Description : Logical NOT predicate
478 class SMESHCONTROLS_EXPORT LogicalNOT: public virtual Predicate{
481 virtual ~LogicalNOT();
482 virtual bool IsSatisfy( long theElementId );
483 virtual void SetMesh( const SMDS_Mesh* theMesh );
484 virtual void SetPredicate(PredicatePtr thePred);
485 virtual SMDSAbs_ElementType GetType() const;
488 PredicatePtr myPredicate;
490 typedef boost::shared_ptr<LogicalNOT> LogicalNOTPtr;
494 Class : LogicalBinary
495 Description : Base class for binary logical predicate
497 class SMESHCONTROLS_EXPORT LogicalBinary: public virtual Predicate{
500 virtual ~LogicalBinary();
501 virtual void SetMesh( const SMDS_Mesh* theMesh );
502 virtual void SetPredicate1(PredicatePtr thePred);
503 virtual void SetPredicate2(PredicatePtr thePred);
504 virtual SMDSAbs_ElementType GetType() const;
507 PredicatePtr myPredicate1;
508 PredicatePtr myPredicate2;
510 typedef boost::shared_ptr<LogicalBinary> LogicalBinaryPtr;
515 Description : Logical AND
517 class SMESHCONTROLS_EXPORT LogicalAND: public virtual LogicalBinary{
519 virtual bool IsSatisfy( long theElementId );
525 Description : Logical OR
527 class SMESHCONTROLS_EXPORT LogicalOR: public virtual LogicalBinary{
529 virtual bool IsSatisfy( long theElementId );
535 Description : Predicate for manifold part of mesh
537 class SMESHCONTROLS_EXPORT ManifoldPart: public virtual Predicate{
540 /* internal class for algorithm uses */
544 Link( SMDS_MeshNode* theNode1,
545 SMDS_MeshNode* theNode2 );
548 bool IsEqual( const ManifoldPart::Link& theLink ) const;
549 bool operator<(const ManifoldPart::Link& x) const;
551 SMDS_MeshNode* myNode1;
552 SMDS_MeshNode* myNode2;
555 bool IsEqual( const ManifoldPart::Link& theLink1,
556 const ManifoldPart::Link& theLink2 );
558 typedef std::set<ManifoldPart::Link> TMapOfLink;
559 typedef std::vector<SMDS_MeshFace*> TVectorOfFacePtr;
560 typedef std::vector<ManifoldPart::Link> TVectorOfLink;
561 typedef std::map<SMDS_MeshFace*,int> TDataMapFacePtrInt;
562 typedef std::map<ManifoldPart::Link,SMDS_MeshFace*> TDataMapOfLinkFacePtr;
566 virtual void SetMesh( const SMDS_Mesh* theMesh );
567 // inoke when all parameters already set
568 virtual bool IsSatisfy( long theElementId );
569 virtual SMDSAbs_ElementType GetType() const;
571 void SetAngleTolerance( const double theAngToler );
572 double GetAngleTolerance() const;
573 void SetIsOnlyManifold( const bool theIsOnly );
574 void SetStartElem( const long theStartElemId );
578 bool findConnected( const TDataMapFacePtrInt& theAllFacePtrInt,
579 SMDS_MeshFace* theStartFace,
580 TMapOfLink& theNonManifold,
581 TColStd_MapOfInteger& theResFaces );
582 bool isInPlane( const SMDS_MeshFace* theFace1,
583 const SMDS_MeshFace* theFace2 );
584 void expandBoundary( TMapOfLink& theMapOfBoundary,
585 TVectorOfLink& theSeqOfBoundary,
586 TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
587 TMapOfLink& theNonManifold,
588 SMDS_MeshFace* theNextFace ) const;
590 void getFacesByLink( const Link& theLink,
591 TVectorOfFacePtr& theFaces ) const;
594 const SMDS_Mesh* myMesh;
595 TColStd_MapOfInteger myMapIds;
596 TColStd_MapOfInteger myMapBadGeomIds;
597 TVectorOfFacePtr myAllFacePtr;
598 TDataMapFacePtrInt myAllFacePtrIntDMap;
600 bool myIsOnlyManifold;
604 typedef boost::shared_ptr<ManifoldPart> ManifoldPartPtr;
608 Class : ElementsOnSurface
609 Description : Predicate elements that lying on indicated surface
612 class SMESHCONTROLS_EXPORT ElementsOnSurface : public virtual Predicate {
615 ~ElementsOnSurface();
616 virtual void SetMesh( const SMDS_Mesh* theMesh );
617 virtual bool IsSatisfy( long theElementId );
618 virtual SMDSAbs_ElementType GetType() const;
620 void SetTolerance( const double theToler );
621 double GetTolerance() const;
622 void SetSurface( const TopoDS_Shape& theShape,
623 const SMDSAbs_ElementType theType );
624 void SetUseBoundaries( bool theUse );
625 bool GetUseBoundaries() const { return myUseBoundaries; }
629 void process( const SMDS_MeshElement* theElem );
630 bool isOnSurface( const SMDS_MeshNode* theNode );
633 const SMDS_Mesh* myMesh;
634 TColStd_MapOfInteger myIds;
635 SMDSAbs_ElementType myType;
636 //Handle(Geom_Surface) mySurf;
639 bool myUseBoundaries;
640 GeomAPI_ProjectPointOnSurf myProjector;
643 typedef boost::shared_ptr<ElementsOnSurface> ElementsOnSurfacePtr;
646 Class : ElementsOnShape
647 Description : Predicate elements that lying on indicated shape
650 class SMESHCONTROLS_EXPORT ElementsOnShape : public virtual Predicate
656 virtual void SetMesh (const SMDS_Mesh* theMesh);
657 virtual bool IsSatisfy (long theElementId);
658 virtual SMDSAbs_ElementType GetType() const;
660 void SetTolerance (const double theToler);
661 double GetTolerance() const;
662 void SetAllNodes (bool theAllNodes);
663 bool GetAllNodes() const { return myAllNodesFlag; }
664 void SetShape (const TopoDS_Shape& theShape,
665 const SMDSAbs_ElementType theType);
668 void addShape (const TopoDS_Shape& theShape);
670 void process (const SMDS_MeshElement* theElem);
673 const SMDS_Mesh* myMesh;
674 TColStd_MapOfInteger myIds;
675 SMDSAbs_ElementType myType;
676 TopoDS_Shape myShape;
680 TopTools_MapOfShape myShapesMap;
681 TopAbs_ShapeEnum myCurShapeType; // type of current sub-shape
682 BRepClass3d_SolidClassifier myCurSC; // current SOLID
683 GeomAPI_ProjectPointOnSurf myCurProjFace; // current FACE
684 TopoDS_Face myCurFace; // current FACE
685 GeomAPI_ProjectPointOnCurve myCurProjEdge; // current EDGE
686 gp_Pnt myCurPnt; // current VERTEX
689 typedef boost::shared_ptr<ElementsOnShape> ElementsOnShapePtr;
695 class SMESHCONTROLS_EXPORT Filter{
699 virtual void SetPredicate(PredicatePtr thePred);
701 typedef std::vector<long> TIdSequence;
705 GetElementsId( const SMDS_Mesh* theMesh,
706 TIdSequence& theSequence );
710 GetElementsId( const SMDS_Mesh* theMesh,
711 PredicatePtr thePredicate,
712 TIdSequence& theSequence );
715 PredicatePtr myPredicate;