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>
42 #include "SMDSAbs_ElementType.hxx"
43 #include "SMDS_MeshNode.hxx"
45 #include "SMESH_Controls.hxx"
48 #if defined SMESHCONTROLS_EXPORTS
49 #define SMESHCONTROLS_EXPORT __declspec( dllexport )
51 #define SMESHCONTROLS_EXPORT __declspec( dllimport )
54 #define SMESHCONTROLS_EXPORT
57 class SMDS_MeshElement;
63 class SMESHDS_SubMesh;
70 class SMESHCONTROLS_EXPORT TSequenceOfXYZ: public std::vector<gp_XYZ>
73 typedef std::vector<gp_XYZ> TSuperClass;
77 TSequenceOfXYZ(size_type n):
81 TSequenceOfXYZ(size_type n, const value_type& t):
85 TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ):
86 TSuperClass(theSequenceOfXYZ)
89 template <class InputIterator>
90 TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd):
91 TSuperClass(theBegin,theEnd)
94 TSequenceOfXYZ& operator=(const TSequenceOfXYZ& theSequenceOfXYZ){
95 TSuperClass::operator=(theSequenceOfXYZ);
99 reference operator()(size_type n){
100 return TSuperClass::operator[](n-1);
103 const_reference operator()(size_type n) const{
104 return TSuperClass::operator[](n-1);
108 reference operator[](size_type n);
110 const_reference operator[](size_type n) const;
115 Description : Root of all Functors
117 class SMESHCONTROLS_EXPORT Functor
121 virtual void SetMesh( const SMDS_Mesh* theMesh ) = 0;
122 virtual SMDSAbs_ElementType GetType() const = 0;
126 Class : NumericalFunctor
127 Description : Root of all Functors returning numeric value
129 class SMESHCONTROLS_EXPORT NumericalFunctor: public virtual Functor{
132 virtual void SetMesh( const SMDS_Mesh* theMesh );
133 virtual double GetValue( long theElementId );
134 virtual double GetValue(const TSequenceOfXYZ& thePoints) { return -1.0;};
135 virtual SMDSAbs_ElementType GetType() const = 0;
136 virtual double GetBadRate( double Value, int nbNodes ) const = 0;
137 long GetPrecision() const;
138 void SetPrecision( const long thePrecision );
140 bool GetPoints(const int theId,
141 TSequenceOfXYZ& theRes) const;
142 static bool GetPoints(const SMDS_MeshElement* theElem,
143 TSequenceOfXYZ& theRes);
145 const SMDS_Mesh* myMesh;
146 const SMDS_MeshElement* myCurrElement;
153 Description : Functor calculating volume of 3D mesh element
155 class SMESHCONTROLS_EXPORT Volume: public virtual NumericalFunctor{
157 virtual double GetValue( long theElementId );
158 //virtual double GetValue( const TSequenceOfXYZ& thePoints );
159 virtual double GetBadRate( double Value, int nbNodes ) const;
160 virtual SMDSAbs_ElementType GetType() const;
165 Class : SMESH_MinimumAngle
166 Description : Functor for calculation of minimum angle
168 class SMESHCONTROLS_EXPORT MinimumAngle: public virtual NumericalFunctor{
170 virtual double GetValue( const TSequenceOfXYZ& thePoints );
171 virtual double GetBadRate( double Value, int nbNodes ) const;
172 virtual SMDSAbs_ElementType GetType() const;
178 Description : Functor for calculating aspect ratio
180 class SMESHCONTROLS_EXPORT AspectRatio: public virtual NumericalFunctor{
182 virtual double GetValue( const TSequenceOfXYZ& thePoints );
183 virtual double GetBadRate( double Value, int nbNodes ) const;
184 virtual SMDSAbs_ElementType GetType() const;
189 Class : AspectRatio3D
190 Description : Functor for calculating aspect ratio of 3D elems.
192 class SMESHCONTROLS_EXPORT AspectRatio3D: public virtual NumericalFunctor{
194 virtual double GetValue( const TSequenceOfXYZ& thePoints );
195 virtual double GetBadRate( double Value, int nbNodes ) const;
196 virtual SMDSAbs_ElementType GetType() const;
202 Description : Functor for calculating warping
204 class SMESHCONTROLS_EXPORT Warping: public virtual NumericalFunctor{
206 virtual double GetValue( const TSequenceOfXYZ& thePoints );
207 virtual double GetBadRate( double Value, int nbNodes ) const;
208 virtual SMDSAbs_ElementType GetType() const;
211 double ComputeA( const gp_XYZ&, const gp_XYZ&, const gp_XYZ&, const gp_XYZ& ) const;
217 Description : Functor for calculating taper
219 class SMESHCONTROLS_EXPORT Taper: public virtual NumericalFunctor{
221 virtual double GetValue( const TSequenceOfXYZ& thePoints );
222 virtual double GetBadRate( double Value, int nbNodes ) const;
223 virtual SMDSAbs_ElementType GetType() const;
229 Description : Functor for calculating skew in degrees
231 class SMESHCONTROLS_EXPORT Skew: public virtual NumericalFunctor{
233 virtual double GetValue( const TSequenceOfXYZ& thePoints );
234 virtual double GetBadRate( double Value, int nbNodes ) const;
235 virtual SMDSAbs_ElementType GetType() const;
241 Description : Functor for calculating area
243 class SMESHCONTROLS_EXPORT Area: public virtual NumericalFunctor{
245 virtual double GetValue( const TSequenceOfXYZ& thePoints );
246 virtual double GetBadRate( double Value, int nbNodes ) const;
247 virtual SMDSAbs_ElementType GetType() const;
253 Description : Functor for calculating length of edge
255 class SMESHCONTROLS_EXPORT Length: public virtual NumericalFunctor{
257 virtual double GetValue( const TSequenceOfXYZ& thePoints );
258 virtual double GetBadRate( double Value, int nbNodes ) const;
259 virtual SMDSAbs_ElementType GetType() const;
264 Description : Functor for calculating length of edge
266 class SMESHCONTROLS_EXPORT Length2D: public virtual NumericalFunctor{
268 virtual double GetValue( long theElementId );
269 virtual double GetBadRate( double Value, int nbNodes ) const;
270 virtual SMDSAbs_ElementType GetType() const;
274 Value(double theLength, long thePntId1, long thePntId2);
275 bool operator<(const Value& x) const;
277 typedef std::set<Value> TValues;
278 void GetValues(TValues& theValues);
280 typedef boost::shared_ptr<Length2D> Length2DPtr;
283 Class : MultiConnection
284 Description : Functor for calculating number of faces conneted to the edge
286 class SMESHCONTROLS_EXPORT MultiConnection: public virtual NumericalFunctor{
288 virtual double GetValue( long theElementId );
289 virtual double GetValue( const TSequenceOfXYZ& thePoints );
290 virtual double GetBadRate( double Value, int nbNodes ) const;
291 virtual SMDSAbs_ElementType GetType() const;
295 Class : MultiConnection2D
296 Description : Functor for calculating number of faces conneted to the edge
298 class SMESHCONTROLS_EXPORT MultiConnection2D: public virtual NumericalFunctor{
300 virtual double GetValue( long theElementId );
301 virtual double GetValue( const TSequenceOfXYZ& thePoints );
302 virtual double GetBadRate( double Value, int nbNodes ) const;
303 virtual SMDSAbs_ElementType GetType() const;
306 Value(long thePntId1, long thePntId2);
307 bool operator<(const Value& x) const;
309 typedef std::map<Value,int> MValues;
311 void GetValues(MValues& theValues);
313 typedef boost::shared_ptr<MultiConnection2D> MultiConnection2DPtr;
319 Description : Base class for all predicates
321 class SMESHCONTROLS_EXPORT Predicate: public virtual Functor{
323 virtual bool IsSatisfy( long theElementId ) = 0;
324 virtual SMDSAbs_ElementType GetType() const = 0;
330 Description : Predicate for free borders
332 class SMESHCONTROLS_EXPORT FreeBorders: 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;
345 Class : BadOrientedVolume
346 Description : Predicate bad oriented volumes
348 class SMESHCONTROLS_EXPORT BadOrientedVolume: public virtual Predicate{
351 virtual void SetMesh( const SMDS_Mesh* theMesh );
352 virtual bool IsSatisfy( long theElementId );
353 virtual SMDSAbs_ElementType GetType() const;
356 const SMDS_Mesh* myMesh;
362 Description : Predicate for free Edges
364 class SMESHCONTROLS_EXPORT FreeEdges: public virtual Predicate{
367 virtual void SetMesh( const SMDS_Mesh* theMesh );
368 virtual bool IsSatisfy( long theElementId );
369 virtual SMDSAbs_ElementType GetType() const;
370 static bool IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId );
371 typedef long TElemId;
375 Border(long theElemId, long thePntId1, long thePntId2);
376 bool operator<(const Border& x) const;
378 typedef std::set<Border> TBorders;
379 void GetBoreders(TBorders& theBorders);
382 const SMDS_Mesh* myMesh;
384 typedef boost::shared_ptr<FreeEdges> FreeEdgesPtr;
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;
702 class SMESHCONTROLS_EXPORT Filter{
706 virtual void SetPredicate(PredicatePtr thePred);
708 typedef std::vector<long> TIdSequence;
712 GetElementsId( const SMDS_Mesh* theMesh,
713 TIdSequence& theSequence );
717 GetElementsId( const SMDS_Mesh* theMesh,
718 PredicatePtr thePredicate,
719 TIdSequence& theSequence );
722 PredicatePtr myPredicate;