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 <TColStd_SequenceOfInteger.hxx>
33 #include <TColStd_MapOfInteger.hxx>
34 #include <TCollection_AsciiString.hxx>
35 #include <TopoDS_Face.hxx>
37 #include "SMDSAbs_ElementType.hxx"
38 #include "SMDS_MeshNode.hxx"
40 #include "SMESH_Controls.hxx"
43 #if defined SMESHCONTROLS_EXPORTS
44 #define SMESHCONTROLS_EXPORT __declspec( dllexport )
46 #define SMESHCONTROLS_EXPORT __declspec( dllimport )
49 #define SMESHCONTROLS_EXPORT
52 class SMDS_MeshElement;
58 class SMESHDS_SubMesh;
66 class SMESHCONTROLS_EXPORT TSequenceOfXYZ: public std::vector<gp_XYZ>
69 typedef std::vector<gp_XYZ> TSuperClass;
73 TSequenceOfXYZ(size_type n):
77 TSequenceOfXYZ(size_type n, const value_type& t):
81 TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ):
82 TSuperClass(theSequenceOfXYZ)
85 template <class InputIterator>
86 TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd):
87 TSuperClass(theBegin,theEnd)
90 TSequenceOfXYZ& operator=(const TSequenceOfXYZ& theSequenceOfXYZ){
91 TSuperClass::operator=(theSequenceOfXYZ);
95 reference operator()(size_type n){
96 return TSuperClass::operator[](n-1);
99 const_reference operator()(size_type n) const{
100 return TSuperClass::operator[](n-1);
104 reference operator[](size_type n);
106 const_reference operator[](size_type n) const;
111 Description : Root of all Functors
113 class SMESHCONTROLS_EXPORT Functor
117 virtual void SetMesh( const SMDS_Mesh* theMesh ) = 0;
118 virtual SMDSAbs_ElementType GetType() const = 0;
122 Class : NumericalFunctor
123 Description : Root of all Functors returning numeric value
125 class SMESHCONTROLS_EXPORT NumericalFunctor: public virtual Functor{
128 virtual void SetMesh( const SMDS_Mesh* theMesh );
129 virtual double GetValue( long theElementId );
130 virtual double GetValue(const TSequenceOfXYZ& thePoints) { return -1.0;};
131 virtual SMDSAbs_ElementType GetType() const = 0;
132 virtual double GetBadRate( double Value, int nbNodes ) const = 0;
133 long GetPrecision() const;
134 void SetPrecision( const long thePrecision );
136 bool GetPoints(const int theId,
137 TSequenceOfXYZ& theRes) const;
138 static bool GetPoints(const SMDS_MeshElement* theElem,
139 TSequenceOfXYZ& theRes);
141 const SMDS_Mesh* myMesh;
142 const SMDS_MeshElement* myCurrElement;
149 Description : Functor calculating volume of 3D mesh element
151 class SMESHCONTROLS_EXPORT Volume: public virtual NumericalFunctor{
153 virtual double GetValue( long theElementId );
154 //virtual double GetValue( const TSequenceOfXYZ& thePoints );
155 virtual double GetBadRate( double Value, int nbNodes ) const;
156 virtual SMDSAbs_ElementType GetType() const;
161 Class : SMESH_MinimumAngle
162 Description : Functor for calculation of minimum angle
164 class SMESHCONTROLS_EXPORT MinimumAngle: 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;
174 Description : Functor for calculating aspect ratio
176 class SMESHCONTROLS_EXPORT AspectRatio: 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;
185 Class : AspectRatio3D
186 Description : Functor for calculating aspect ratio of 3D elems.
188 class SMESHCONTROLS_EXPORT AspectRatio3D: 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;
198 Description : Functor for calculating warping
200 class SMESHCONTROLS_EXPORT Warping: public virtual NumericalFunctor{
202 virtual double GetValue( const TSequenceOfXYZ& thePoints );
203 virtual double GetBadRate( double Value, int nbNodes ) const;
204 virtual SMDSAbs_ElementType GetType() const;
207 double ComputeA( const gp_XYZ&, const gp_XYZ&, const gp_XYZ&, const gp_XYZ& ) const;
213 Description : Functor for calculating taper
215 class SMESHCONTROLS_EXPORT Taper: 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 skew in degrees
227 class SMESHCONTROLS_EXPORT Skew: 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 area
239 class SMESHCONTROLS_EXPORT Area: 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;
249 Description : Functor for calculating length of edge
251 class SMESHCONTROLS_EXPORT Length: public virtual NumericalFunctor{
253 virtual double GetValue( const TSequenceOfXYZ& thePoints );
254 virtual double GetBadRate( double Value, int nbNodes ) const;
255 virtual SMDSAbs_ElementType GetType() const;
260 Description : Functor for calculating length of edge
262 class SMESHCONTROLS_EXPORT Length2D: public virtual NumericalFunctor{
264 virtual double GetValue( long theElementId );
265 virtual double GetBadRate( double Value, int nbNodes ) const;
266 virtual SMDSAbs_ElementType GetType() const;
270 Value(double theLength, long thePntId1, long thePntId2);
271 bool operator<(const Value& x) const;
273 typedef std::set<Value> TValues;
274 void GetValues(TValues& theValues);
277 typedef boost::shared_ptr<Length2D> Length2DPtr;
280 Class : MultiConnection
281 Description : Functor for calculating number of faces conneted to the edge
283 class SMESHCONTROLS_EXPORT MultiConnection: public virtual NumericalFunctor{
285 virtual double GetValue( long theElementId );
286 virtual double GetValue( const TSequenceOfXYZ& thePoints );
287 virtual double GetBadRate( double Value, int nbNodes ) const;
288 virtual SMDSAbs_ElementType GetType() const;
292 Class : MultiConnection2D
293 Description : Functor for calculating number of faces conneted to the edge
295 class SMESHCONTROLS_EXPORT MultiConnection2D: public virtual NumericalFunctor{
297 virtual double GetValue( long theElementId );
298 virtual double GetValue( const TSequenceOfXYZ& thePoints );
299 virtual double GetBadRate( double Value, int nbNodes ) const;
300 virtual SMDSAbs_ElementType GetType() const;
303 Value(long thePntId1, long thePntId2);
304 bool operator<(const Value& x) const;
306 typedef std::map<Value,int> MValues;
308 void GetValues(MValues& theValues);
310 typedef boost::shared_ptr<MultiConnection2D> MultiConnection2DPtr;
316 Description : Base class for all predicates
318 class SMESHCONTROLS_EXPORT Predicate: public virtual Functor{
320 virtual bool IsSatisfy( long theElementId ) = 0;
321 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;
653 class SMESHCONTROLS_EXPORT Filter{
657 virtual void SetPredicate(PredicatePtr thePred);
659 typedef std::vector<long> TIdSequence;
663 GetElementsId( const SMDS_Mesh* theMesh,
664 TIdSequence& theSequence );
668 GetElementsId( const SMDS_Mesh* theMesh,
669 PredicatePtr thePredicate,
670 TIdSequence& theSequence );
673 PredicatePtr myPredicate;