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: public std::vector<gp_XYZ>
74 TSequenceOfXYZ(size_type n);
76 TSequenceOfXYZ(size_type n, const value_type& t);
78 TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ);
80 template <class InputIterator>
81 TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd);
83 TSequenceOfXYZ& operator=(const TSequenceOfXYZ& theSequenceOfXYZ);
85 reference operator()(size_type n);
87 const_reference operator()(size_type n) const;
90 reference operator[](size_type n);
92 const_reference operator[](size_type n) const;
97 Description : Root of all Functors
99 class SMESHCONTROLS_EXPORT Functor
103 virtual void SetMesh( const SMDS_Mesh* theMesh ) = 0;
104 virtual SMDSAbs_ElementType GetType() const = 0;
108 Class : NumericalFunctor
109 Description : Root of all Functors returning numeric value
111 class SMESHCONTROLS_EXPORT NumericalFunctor: public virtual Functor{
114 virtual void SetMesh( const SMDS_Mesh* theMesh );
115 virtual double GetValue( long theElementId );
116 virtual double GetValue(const TSequenceOfXYZ& thePoints) { return -1.0;};
117 virtual SMDSAbs_ElementType GetType() const = 0;
118 virtual double GetBadRate( double Value, int nbNodes ) const = 0;
119 long GetPrecision() const;
120 void SetPrecision( const long thePrecision );
122 bool GetPoints(const int theId,
123 TSequenceOfXYZ& theRes) const;
124 static bool GetPoints(const SMDS_MeshElement* theElem,
125 TSequenceOfXYZ& theRes);
127 const SMDS_Mesh* myMesh;
128 const SMDS_MeshElement* myCurrElement;
135 Description : Functor calculating volume of 3D mesh element
137 class SMESHCONTROLS_EXPORT Volume: public virtual NumericalFunctor{
139 virtual double GetValue( long theElementId );
140 //virtual double GetValue( const TSequenceOfXYZ& thePoints );
141 virtual double GetBadRate( double Value, int nbNodes ) const;
142 virtual SMDSAbs_ElementType GetType() const;
147 Class : SMESH_MinimumAngle
148 Description : Functor for calculation of minimum angle
150 class SMESHCONTROLS_EXPORT MinimumAngle: public virtual NumericalFunctor{
152 virtual double GetValue( const TSequenceOfXYZ& thePoints );
153 virtual double GetBadRate( double Value, int nbNodes ) const;
154 virtual SMDSAbs_ElementType GetType() const;
160 Description : Functor for calculating aspect ratio
162 class SMESHCONTROLS_EXPORT AspectRatio: 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;
171 Class : AspectRatio3D
172 Description : Functor for calculating aspect ratio of 3D elems.
174 class SMESHCONTROLS_EXPORT AspectRatio3D: 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;
184 Description : Functor for calculating warping
186 class SMESHCONTROLS_EXPORT Warping: 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;
193 double ComputeA( const gp_XYZ&, const gp_XYZ&, const gp_XYZ&, const gp_XYZ& ) const;
199 Description : Functor for calculating taper
201 class SMESHCONTROLS_EXPORT Taper: public virtual NumericalFunctor{
203 virtual double GetValue( const TSequenceOfXYZ& thePoints );
204 virtual double GetBadRate( double Value, int nbNodes ) const;
205 virtual SMDSAbs_ElementType GetType() const;
211 Description : Functor for calculating skew in degrees
213 class SMESHCONTROLS_EXPORT Skew: 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 area
225 class SMESHCONTROLS_EXPORT Area: 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 length of edge
237 class SMESHCONTROLS_EXPORT Length: 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;
246 Description : Functor for calculating length of edge
248 class SMESHCONTROLS_EXPORT Length2D: public virtual NumericalFunctor{
250 virtual double GetValue( long theElementId );
251 virtual double GetBadRate( double Value, int nbNodes ) const;
252 virtual SMDSAbs_ElementType GetType() const;
256 Value(double theLength, long thePntId1, long thePntId2);
257 bool operator<(const Value& x) const;
259 typedef std::set<Value> TValues;
260 void GetValues(TValues& theValues);
263 typedef boost::shared_ptr<Length2D> Length2DPtr;
266 Class : MultiConnection
267 Description : Functor for calculating number of faces conneted to the edge
269 class SMESHCONTROLS_EXPORT MultiConnection: public virtual NumericalFunctor{
271 virtual double GetValue( long theElementId );
272 virtual double GetValue( const TSequenceOfXYZ& thePoints );
273 virtual double GetBadRate( double Value, int nbNodes ) const;
274 virtual SMDSAbs_ElementType GetType() const;
278 Class : MultiConnection2D
279 Description : Functor for calculating number of faces conneted to the edge
281 class SMESHCONTROLS_EXPORT MultiConnection2D: 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;
289 Value(long thePntId1, long thePntId2);
290 bool operator<(const Value& x) const;
292 typedef std::map<Value,int> MValues;
294 void GetValues(MValues& theValues);
296 typedef boost::shared_ptr<MultiConnection2D> MultiConnection2DPtr;
302 Description : Base class for all predicates
304 class SMESHCONTROLS_EXPORT Predicate: public virtual Functor{
306 virtual bool IsSatisfy( long theElementId ) = 0;
307 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 Range of Ids.
374 Range may be specified with two ways.
375 1. Using AddToRange method
376 2. With SetRangeStr method. Parameter of this method is a string
377 like as "1,2,3,50-60,63,67,70-"
379 class SMESHCONTROLS_EXPORT RangeOfIds: public virtual Predicate
383 virtual void SetMesh( const SMDS_Mesh* theMesh );
384 virtual bool IsSatisfy( long theNodeId );
385 virtual SMDSAbs_ElementType GetType() const;
386 virtual void SetType( SMDSAbs_ElementType theType );
388 bool AddToRange( long theEntityId );
389 void GetRangeStr( TCollection_AsciiString& );
390 bool SetRangeStr( const TCollection_AsciiString& );
393 const SMDS_Mesh* myMesh;
395 TColStd_SequenceOfInteger myMin;
396 TColStd_SequenceOfInteger myMax;
397 TColStd_MapOfInteger myIds;
399 SMDSAbs_ElementType myType;
402 typedef boost::shared_ptr<RangeOfIds> RangeOfIdsPtr;
407 Description : Base class for comparators
409 class SMESHCONTROLS_EXPORT Comparator: public virtual Predicate{
412 virtual ~Comparator();
413 virtual void SetMesh( const SMDS_Mesh* theMesh );
414 virtual void SetMargin(double theValue);
415 virtual void SetNumFunctor(NumericalFunctorPtr theFunct);
416 virtual bool IsSatisfy( long theElementId ) = 0;
417 virtual SMDSAbs_ElementType GetType() const;
422 NumericalFunctorPtr myFunctor;
424 typedef boost::shared_ptr<Comparator> ComparatorPtr;
429 Description : Comparator "<"
431 class SMESHCONTROLS_EXPORT LessThan: public virtual Comparator{
433 virtual bool IsSatisfy( long theElementId );
439 Description : Comparator ">"
441 class SMESHCONTROLS_EXPORT MoreThan: public virtual Comparator{
443 virtual bool IsSatisfy( long theElementId );
449 Description : Comparator "="
451 class SMESHCONTROLS_EXPORT EqualTo: public virtual Comparator{
454 virtual bool IsSatisfy( long theElementId );
455 virtual void SetTolerance( double theTol );
456 virtual double GetTolerance();
461 typedef boost::shared_ptr<EqualTo> EqualToPtr;
466 Description : Logical NOT predicate
468 class SMESHCONTROLS_EXPORT LogicalNOT: public virtual Predicate{
471 virtual ~LogicalNOT();
472 virtual bool IsSatisfy( long theElementId );
473 virtual void SetMesh( const SMDS_Mesh* theMesh );
474 virtual void SetPredicate(PredicatePtr thePred);
475 virtual SMDSAbs_ElementType GetType() const;
478 PredicatePtr myPredicate;
480 typedef boost::shared_ptr<LogicalNOT> LogicalNOTPtr;
484 Class : LogicalBinary
485 Description : Base class for binary logical predicate
487 class SMESHCONTROLS_EXPORT LogicalBinary: public virtual Predicate{
490 virtual ~LogicalBinary();
491 virtual void SetMesh( const SMDS_Mesh* theMesh );
492 virtual void SetPredicate1(PredicatePtr thePred);
493 virtual void SetPredicate2(PredicatePtr thePred);
494 virtual SMDSAbs_ElementType GetType() const;
497 PredicatePtr myPredicate1;
498 PredicatePtr myPredicate2;
500 typedef boost::shared_ptr<LogicalBinary> LogicalBinaryPtr;
505 Description : Logical AND
507 class SMESHCONTROLS_EXPORT LogicalAND: public virtual LogicalBinary{
509 virtual bool IsSatisfy( long theElementId );
515 Description : Logical OR
517 class SMESHCONTROLS_EXPORT LogicalOR: public virtual LogicalBinary{
519 virtual bool IsSatisfy( long theElementId );
525 Description : Predicate for manifold part of mesh
527 class SMESHCONTROLS_EXPORT ManifoldPart: public virtual Predicate{
530 /* internal class for algorithm uses */
534 Link( SMDS_MeshNode* theNode1,
535 SMDS_MeshNode* theNode2 );
538 bool IsEqual( const ManifoldPart::Link& theLink ) const;
539 bool operator<(const ManifoldPart::Link& x) const;
541 SMDS_MeshNode* myNode1;
542 SMDS_MeshNode* myNode2;
545 bool IsEqual( const ManifoldPart::Link& theLink1,
546 const ManifoldPart::Link& theLink2 );
548 typedef std::set<ManifoldPart::Link> TMapOfLink;
549 typedef std::vector<SMDS_MeshFace*> TVectorOfFacePtr;
550 typedef std::vector<ManifoldPart::Link> TVectorOfLink;
551 typedef std::map<SMDS_MeshFace*,int> TDataMapFacePtrInt;
552 typedef std::map<ManifoldPart::Link,SMDS_MeshFace*> TDataMapOfLinkFacePtr;
556 virtual void SetMesh( const SMDS_Mesh* theMesh );
557 // inoke when all parameters already set
558 virtual bool IsSatisfy( long theElementId );
559 virtual SMDSAbs_ElementType GetType() const;
561 void SetAngleTolerance( const double theAngToler );
562 double GetAngleTolerance() const;
563 void SetIsOnlyManifold( const bool theIsOnly );
564 void SetStartElem( const long theStartElemId );
568 bool findConnected( const TDataMapFacePtrInt& theAllFacePtrInt,
569 SMDS_MeshFace* theStartFace,
570 TMapOfLink& theNonManifold,
571 TColStd_MapOfInteger& theResFaces );
572 bool isInPlane( const SMDS_MeshFace* theFace1,
573 const SMDS_MeshFace* theFace2 );
574 void expandBoundary( TMapOfLink& theMapOfBoundary,
575 TVectorOfLink& theSeqOfBoundary,
576 TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
577 TMapOfLink& theNonManifold,
578 SMDS_MeshFace* theNextFace ) const;
580 void getFacesByLink( const Link& theLink,
581 TVectorOfFacePtr& theFaces ) const;
584 const SMDS_Mesh* myMesh;
585 TColStd_MapOfInteger myMapIds;
586 TColStd_MapOfInteger myMapBadGeomIds;
587 TVectorOfFacePtr myAllFacePtr;
588 TDataMapFacePtrInt myAllFacePtrIntDMap;
590 bool myIsOnlyManifold;
594 typedef boost::shared_ptr<ManifoldPart> ManifoldPartPtr;
598 Class : ElementsOnSurface
599 Description : Predicate elements that lying on indicated surface
602 class SMESHCONTROLS_EXPORT ElementsOnSurface : public virtual Predicate {
605 ~ElementsOnSurface();
606 virtual void SetMesh( const SMDS_Mesh* theMesh );
607 virtual bool IsSatisfy( long theElementId );
608 virtual SMDSAbs_ElementType GetType() const;
610 void SetTolerance( const double theToler );
611 double GetTolerance() const;
612 void SetSurface( const TopoDS_Shape& theShape,
613 const SMDSAbs_ElementType theType );
614 void SetUseBoundaries( bool theUse );
615 bool GetUseBoundaries() const { return myUseBoundaries; }
619 void process( const SMDS_MeshElement* theElem );
620 bool isOnSurface( const SMDS_MeshNode* theNode );
623 const SMDS_Mesh* myMesh;
624 TColStd_MapOfInteger myIds;
625 SMDSAbs_ElementType myType;
626 //Handle(Geom_Surface) mySurf;
629 bool myUseBoundaries;
630 GeomAPI_ProjectPointOnSurf myProjector;
633 typedef boost::shared_ptr<ElementsOnSurface> ElementsOnSurfacePtr;
636 Class : ElementsOnShape
637 Description : Predicate elements that lying on indicated shape
640 class SMESHCONTROLS_EXPORT ElementsOnShape : public virtual Predicate
646 virtual void SetMesh (const SMDS_Mesh* theMesh);
647 virtual bool IsSatisfy (long theElementId);
648 virtual SMDSAbs_ElementType GetType() const;
650 void SetTolerance (const double theToler);
651 double GetTolerance() const;
652 void SetAllNodes (bool theAllNodes);
653 bool GetAllNodes() const { return myAllNodesFlag; }
654 void SetShape (const TopoDS_Shape& theShape,
655 const SMDSAbs_ElementType theType);
658 void addShape (const TopoDS_Shape& theShape);
660 void process (const SMDS_MeshElement* theElem);
663 const SMDS_Mesh* myMesh;
664 TColStd_MapOfInteger myIds;
665 SMDSAbs_ElementType myType;
666 TopoDS_Shape myShape;
670 TopTools_MapOfShape myShapesMap;
671 TopAbs_ShapeEnum myCurShapeType; // type of current sub-shape
672 BRepClass3d_SolidClassifier myCurSC; // current SOLID
673 GeomAPI_ProjectPointOnSurf myCurProjFace; // current FACE
674 TopoDS_Face myCurFace; // current FACE
675 GeomAPI_ProjectPointOnCurve myCurProjEdge; // current EDGE
676 gp_Pnt myCurPnt; // current VERTEX
679 typedef boost::shared_ptr<ElementsOnShape> ElementsOnShapePtr;
685 class SMESHCONTROLS_EXPORT Filter{
689 virtual void SetPredicate(PredicatePtr thePred);
691 typedef std::vector<long> TIdSequence;
695 GetElementsId( const SMDS_Mesh* theMesh,
696 TIdSequence& theSequence );
700 GetElementsId( const SMDS_Mesh* theMesh,
701 PredicatePtr thePredicate,
702 TIdSequence& theSequence );
705 PredicatePtr myPredicate;