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_
26 #include <boost/shared_ptr.hpp>
28 //#include <Geom_Surface.hxx>
29 #include <GeomAPI_ProjectPointOnSurf.hxx>
30 #include <TColStd_SequenceOfInteger.hxx>
31 #include <TColStd_MapOfInteger.hxx>
32 #include <TCollection_AsciiString.hxx>
33 #include <TopoDS_Face.hxx>
35 #include "SMDSAbs_ElementType.hxx"
36 #include "SMDS_MeshNode.hxx"
38 #include "SMESH_Controls.hxx"
41 #if defined SMESHCONTROLS_EXPORTS
42 #define SMESHCONTROLS_EXPORT __declspec( dllexport )
44 #define SMESHCONTROLS_EXPORT __declspec( dllimport )
47 #define SMESHCONTROLS_EXPORT
50 class SMDS_MeshElement;
56 class SMESHDS_SubMesh;
64 class SMESHCONTROLS_EXPORT TSequenceOfXYZ: public std::vector<gp_XYZ>
67 typedef std::vector<gp_XYZ> TSuperClass;
71 TSequenceOfXYZ(size_type n):
75 TSequenceOfXYZ(size_type n, const value_type& t):
79 TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ):
80 TSuperClass(theSequenceOfXYZ)
83 template <class InputIterator>
84 TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd):
85 TSuperClass(theBegin,theEnd)
88 TSequenceOfXYZ& operator=(const TSequenceOfXYZ& theSequenceOfXYZ){
89 TSuperClass::operator=(theSequenceOfXYZ);
93 reference operator()(size_type n){
94 return TSuperClass::operator[](n-1);
97 const_reference operator()(size_type n) const{
98 return TSuperClass::operator[](n-1);
102 reference operator[](size_type n);
104 const_reference operator[](size_type n) const;
109 Description : Root of all Functors
111 class SMESHCONTROLS_EXPORT Functor
115 virtual void SetMesh( const SMDS_Mesh* theMesh ) = 0;
116 virtual SMDSAbs_ElementType GetType() const = 0;
120 Class : NumericalFunctor
121 Description : Root of all Functors returning numeric value
123 class SMESHCONTROLS_EXPORT NumericalFunctor: public virtual Functor{
126 virtual void SetMesh( const SMDS_Mesh* theMesh );
127 virtual double GetValue( long theElementId );
128 virtual double GetValue(const TSequenceOfXYZ& thePoints) { return -1.0;};
129 virtual SMDSAbs_ElementType GetType() const = 0;
130 virtual double GetBadRate( double Value, int nbNodes ) const = 0;
131 long GetPrecision() const;
132 void SetPrecision( const long thePrecision );
134 bool GetPoints(const int theId,
135 TSequenceOfXYZ& theRes) const;
136 static bool GetPoints(const SMDS_MeshElement* theElem,
137 TSequenceOfXYZ& theRes);
139 const SMDS_Mesh* myMesh;
140 const SMDS_MeshElement* myCurrElement;
147 Description : Functor calculating volume of 3D mesh element
149 class SMESHCONTROLS_EXPORT Volume: public virtual NumericalFunctor{
151 virtual double GetValue( long theElementId );
152 //virtual double GetValue( const TSequenceOfXYZ& thePoints );
153 virtual double GetBadRate( double Value, int nbNodes ) const;
154 virtual SMDSAbs_ElementType GetType() const;
159 Class : SMESH_MinimumAngle
160 Description : Functor for calculation of minimum angle
162 class SMESHCONTROLS_EXPORT MinimumAngle: 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;
172 Description : Functor for calculating aspect ratio
174 class SMESHCONTROLS_EXPORT AspectRatio: 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;
183 Class : AspectRatio3D
184 Description : Functor for calculating aspect ratio of 3D elems.
186 class SMESHCONTROLS_EXPORT AspectRatio3D: 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;
196 Description : Functor for calculating warping
198 class SMESHCONTROLS_EXPORT Warping: public virtual NumericalFunctor{
200 virtual double GetValue( const TSequenceOfXYZ& thePoints );
201 virtual double GetBadRate( double Value, int nbNodes ) const;
202 virtual SMDSAbs_ElementType GetType() const;
205 double ComputeA( const gp_XYZ&, const gp_XYZ&, const gp_XYZ&, const gp_XYZ& ) const;
211 Description : Functor for calculating taper
213 class SMESHCONTROLS_EXPORT Taper: 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 skew in degrees
225 class SMESHCONTROLS_EXPORT Skew: 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 area
237 class SMESHCONTROLS_EXPORT Area: 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;
247 Description : Functor for calculating length of edge
249 class SMESHCONTROLS_EXPORT Length: public virtual NumericalFunctor{
251 virtual double GetValue( const TSequenceOfXYZ& thePoints );
252 virtual double GetBadRate( double Value, int nbNodes ) const;
253 virtual SMDSAbs_ElementType GetType() const;
258 Description : Functor for calculating length of edge
260 class SMESHCONTROLS_EXPORT Length2D: public virtual NumericalFunctor{
262 virtual double GetValue( long theElementId );
263 virtual double GetBadRate( double Value, int nbNodes ) const;
264 virtual SMDSAbs_ElementType GetType() const;
268 Value(double theLength, long thePntId1, long thePntId2);
269 bool operator<(const Value& x) const;
271 typedef std::set<Value> TValues;
272 void GetValues(TValues& theValues);
275 typedef boost::shared_ptr<Length2D> Length2DPtr;
278 Class : MultiConnection
279 Description : Functor for calculating number of faces conneted to the edge
281 class SMESHCONTROLS_EXPORT MultiConnection: 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;
290 Class : MultiConnection2D
291 Description : Functor for calculating number of faces conneted to the edge
293 class SMESHCONTROLS_EXPORT MultiConnection2D: public virtual NumericalFunctor{
295 virtual double GetValue( long theElementId );
296 virtual double GetValue( const TSequenceOfXYZ& thePoints );
297 virtual double GetBadRate( double Value, int nbNodes ) const;
298 virtual SMDSAbs_ElementType GetType() const;
301 Value(long thePntId1, long thePntId2);
302 bool operator<(const Value& x) const;
304 typedef std::map<Value,int> MValues;
306 void GetValues(MValues& theValues);
308 typedef boost::shared_ptr<MultiConnection2D> MultiConnection2DPtr;
314 Description : Base class for all predicates
316 class SMESHCONTROLS_EXPORT Predicate: public virtual Functor{
318 virtual bool IsSatisfy( long theElementId ) = 0;
319 virtual SMDSAbs_ElementType GetType() const = 0;
326 Description : Predicate for free borders
328 class SMESHCONTROLS_EXPORT FreeBorders: public virtual Predicate{
331 virtual void SetMesh( const SMDS_Mesh* theMesh );
332 virtual bool IsSatisfy( long theElementId );
333 virtual SMDSAbs_ElementType GetType() const;
336 const SMDS_Mesh* myMesh;
341 Class : BadOrientedVolume
342 Description : Predicate bad oriented volumes
344 class SMESHCONTROLS_EXPORT BadOrientedVolume: public virtual Predicate{
347 virtual void SetMesh( const SMDS_Mesh* theMesh );
348 virtual bool IsSatisfy( long theElementId );
349 virtual SMDSAbs_ElementType GetType() const;
352 const SMDS_Mesh* myMesh;
358 Description : Predicate for free Edges
360 class SMESHCONTROLS_EXPORT FreeEdges: public virtual Predicate{
363 virtual void SetMesh( const SMDS_Mesh* theMesh );
364 virtual bool IsSatisfy( long theElementId );
365 virtual SMDSAbs_ElementType GetType() const;
366 static bool IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId );
367 typedef long TElemId;
371 Border(long theElemId, long thePntId1, long thePntId2);
372 bool operator<(const Border& x) const;
374 typedef std::set<Border> TBorders;
375 void GetBoreders(TBorders& theBorders);
378 const SMDS_Mesh* myMesh;
380 typedef boost::shared_ptr<FreeEdges> FreeEdgesPtr;
385 Description : Predicate for Range of Ids.
386 Range may be specified with two ways.
387 1. Using AddToRange method
388 2. With SetRangeStr method. Parameter of this method is a string
389 like as "1,2,3,50-60,63,67,70-"
391 class SMESHCONTROLS_EXPORT RangeOfIds: public virtual Predicate
395 virtual void SetMesh( const SMDS_Mesh* theMesh );
396 virtual bool IsSatisfy( long theNodeId );
397 virtual SMDSAbs_ElementType GetType() const;
398 virtual void SetType( SMDSAbs_ElementType theType );
400 bool AddToRange( long theEntityId );
401 void GetRangeStr( TCollection_AsciiString& );
402 bool SetRangeStr( const TCollection_AsciiString& );
405 const SMDS_Mesh* myMesh;
407 TColStd_SequenceOfInteger myMin;
408 TColStd_SequenceOfInteger myMax;
409 TColStd_MapOfInteger myIds;
411 SMDSAbs_ElementType myType;
414 typedef boost::shared_ptr<RangeOfIds> RangeOfIdsPtr;
419 Description : Base class for comparators
421 class SMESHCONTROLS_EXPORT Comparator: public virtual Predicate{
424 virtual ~Comparator();
425 virtual void SetMesh( const SMDS_Mesh* theMesh );
426 virtual void SetMargin(double theValue);
427 virtual void SetNumFunctor(NumericalFunctorPtr theFunct);
428 virtual bool IsSatisfy( long theElementId ) = 0;
429 virtual SMDSAbs_ElementType GetType() const;
434 NumericalFunctorPtr myFunctor;
436 typedef boost::shared_ptr<Comparator> ComparatorPtr;
441 Description : Comparator "<"
443 class SMESHCONTROLS_EXPORT LessThan: public virtual Comparator{
445 virtual bool IsSatisfy( long theElementId );
451 Description : Comparator ">"
453 class SMESHCONTROLS_EXPORT MoreThan: public virtual Comparator{
455 virtual bool IsSatisfy( long theElementId );
461 Description : Comparator "="
463 class SMESHCONTROLS_EXPORT EqualTo: public virtual Comparator{
466 virtual bool IsSatisfy( long theElementId );
467 virtual void SetTolerance( double theTol );
468 virtual double GetTolerance();
473 typedef boost::shared_ptr<EqualTo> EqualToPtr;
478 Description : Logical NOT predicate
480 class SMESHCONTROLS_EXPORT LogicalNOT: public virtual Predicate{
483 virtual ~LogicalNOT();
484 virtual bool IsSatisfy( long theElementId );
485 virtual void SetMesh( const SMDS_Mesh* theMesh );
486 virtual void SetPredicate(PredicatePtr thePred);
487 virtual SMDSAbs_ElementType GetType() const;
490 PredicatePtr myPredicate;
492 typedef boost::shared_ptr<LogicalNOT> LogicalNOTPtr;
496 Class : LogicalBinary
497 Description : Base class for binary logical predicate
499 class SMESHCONTROLS_EXPORT LogicalBinary: public virtual Predicate{
502 virtual ~LogicalBinary();
503 virtual void SetMesh( const SMDS_Mesh* theMesh );
504 virtual void SetPredicate1(PredicatePtr thePred);
505 virtual void SetPredicate2(PredicatePtr thePred);
506 virtual SMDSAbs_ElementType GetType() const;
509 PredicatePtr myPredicate1;
510 PredicatePtr myPredicate2;
512 typedef boost::shared_ptr<LogicalBinary> LogicalBinaryPtr;
517 Description : Logical AND
519 class SMESHCONTROLS_EXPORT LogicalAND: public virtual LogicalBinary{
521 virtual bool IsSatisfy( long theElementId );
527 Description : Logical OR
529 class SMESHCONTROLS_EXPORT LogicalOR: public virtual LogicalBinary{
531 virtual bool IsSatisfy( long theElementId );
537 Description : Predicate for manifold part of mesh
539 class SMESHCONTROLS_EXPORT ManifoldPart: public virtual Predicate{
542 /* internal class for algorithm uses */
546 Link( SMDS_MeshNode* theNode1,
547 SMDS_MeshNode* theNode2 );
550 bool IsEqual( const ManifoldPart::Link& theLink ) const;
551 bool operator<(const ManifoldPart::Link& x) const;
553 SMDS_MeshNode* myNode1;
554 SMDS_MeshNode* myNode2;
557 bool IsEqual( const ManifoldPart::Link& theLink1,
558 const ManifoldPart::Link& theLink2 );
560 typedef std::set<ManifoldPart::Link> TMapOfLink;
561 typedef std::vector<SMDS_MeshFace*> TVectorOfFacePtr;
562 typedef std::vector<ManifoldPart::Link> TVectorOfLink;
563 typedef std::map<SMDS_MeshFace*,int> TDataMapFacePtrInt;
564 typedef std::map<ManifoldPart::Link,SMDS_MeshFace*> TDataMapOfLinkFacePtr;
568 virtual void SetMesh( const SMDS_Mesh* theMesh );
569 // inoke when all parameters already set
570 virtual bool IsSatisfy( long theElementId );
571 virtual SMDSAbs_ElementType GetType() const;
573 void SetAngleTolerance( const double theAngToler );
574 double GetAngleTolerance() const;
575 void SetIsOnlyManifold( const bool theIsOnly );
576 void SetStartElem( const long theStartElemId );
580 bool findConnected( const TDataMapFacePtrInt& theAllFacePtrInt,
581 SMDS_MeshFace* theStartFace,
582 TMapOfLink& theNonManifold,
583 TColStd_MapOfInteger& theResFaces );
584 bool isInPlane( const SMDS_MeshFace* theFace1,
585 const SMDS_MeshFace* theFace2 );
586 void expandBoundary( TMapOfLink& theMapOfBoundary,
587 TVectorOfLink& theSeqOfBoundary,
588 TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
589 TMapOfLink& theNonManifold,
590 SMDS_MeshFace* theNextFace ) const;
592 void getFacesByLink( const Link& theLink,
593 TVectorOfFacePtr& theFaces ) const;
596 const SMDS_Mesh* myMesh;
597 TColStd_MapOfInteger myMapIds;
598 TColStd_MapOfInteger myMapBadGeomIds;
599 TVectorOfFacePtr myAllFacePtr;
600 TDataMapFacePtrInt myAllFacePtrIntDMap;
602 bool myIsOnlyManifold;
606 typedef boost::shared_ptr<ManifoldPart> ManifoldPartPtr;
610 Class : ElementsOnSurface
611 Description : Predicate elements that lying on indicated surface
614 class SMESHCONTROLS_EXPORT ElementsOnSurface : public virtual Predicate {
617 ~ElementsOnSurface();
618 virtual void SetMesh( const SMDS_Mesh* theMesh );
619 virtual bool IsSatisfy( long theElementId );
620 virtual SMDSAbs_ElementType GetType() const;
622 void SetTolerance( const double theToler );
623 double GetTolerance() const;
624 void SetSurface( const TopoDS_Shape& theShape,
625 const SMDSAbs_ElementType theType );
626 void SetUseBoundaries( bool theUse );
627 bool GetUseBoundaries() const { return myUseBoundaries; }
631 void process( const SMDS_MeshElement* theElem );
632 bool isOnSurface( const SMDS_MeshNode* theNode );
635 const SMDS_Mesh* myMesh;
636 TColStd_MapOfInteger myIds;
637 SMDSAbs_ElementType myType;
638 //Handle(Geom_Surface) mySurf;
641 bool myUseBoundaries;
642 GeomAPI_ProjectPointOnSurf myProjector;
645 typedef boost::shared_ptr<ElementsOnSurface> ElementsOnSurfacePtr;
651 class SMESHCONTROLS_EXPORT Filter{
655 virtual void SetPredicate(PredicatePtr thePred);
657 typedef std::vector<long> TIdSequence;
661 GetElementsId( const SMDS_Mesh* theMesh,
662 TIdSequence& theSequence );
666 GetElementsId( const SMDS_Mesh* theMesh,
667 PredicatePtr thePredicate,
668 TIdSequence& theSequence );
671 PredicatePtr myPredicate;