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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
20 #ifndef _SMESH_CONTROLSDEF_HXX_
21 #define _SMESH_CONTROLSDEF_HXX_
26 #include <boost/shared_ptr.hpp>
28 #include <Geom_Surface.hxx>
29 #include <TColStd_SequenceOfInteger.hxx>
30 #include <TColStd_MapOfInteger.hxx>
31 #include <TCollection_AsciiString.hxx>
33 #include "SMDSAbs_ElementType.hxx"
34 #include "SMDS_MeshNode.hxx"
36 #include "SMESH_Controls.hxx"
38 class SMDS_MeshElement;
44 class SMESHDS_SubMesh;
53 class TSequenceOfXYZ: public std::vector<gp_XYZ>
56 typedef std::vector<gp_XYZ> TSuperClass;
60 TSequenceOfXYZ(size_type n):
64 TSequenceOfXYZ(size_type n, const value_type& t):
68 TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ):
69 TSuperClass(theSequenceOfXYZ)
72 template <class InputIterator>
73 TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd):
74 TSuperClass(theBegin,theEnd)
77 TSequenceOfXYZ& operator=(const TSequenceOfXYZ& theSequenceOfXYZ){
78 TSuperClass::operator=(theSequenceOfXYZ);
82 reference operator()(size_type n){
83 return TSuperClass::operator[](n-1);
86 const_reference operator()(size_type n) const{
87 return TSuperClass::operator[](n-1);
91 reference operator[](size_type n);
93 const_reference operator[](size_type n) const;
98 Description : Root of all Functors
104 virtual void SetMesh( const SMDS_Mesh* theMesh ) = 0;
105 virtual SMDSAbs_ElementType GetType() const = 0;
109 Class : NumericalFunctor
110 Description : Root of all Functors returning numeric value
112 class NumericalFunctor: public virtual Functor{
115 virtual void SetMesh( const SMDS_Mesh* theMesh );
116 virtual double GetValue( long theElementId );
117 virtual double GetValue(const TSequenceOfXYZ& thePoints) { return -1.0;};
118 virtual SMDSAbs_ElementType GetType() const = 0;
119 virtual double GetBadRate( double Value, int nbNodes ) const = 0;
120 long GetPrecision() const;
121 void SetPrecision( const long thePrecision );
123 bool GetPoints(const int theId,
124 TSequenceOfXYZ& theRes) const;
125 static bool GetPoints(const SMDS_MeshElement* theElem,
126 TSequenceOfXYZ& theRes);
128 const SMDS_Mesh* myMesh;
129 const SMDS_MeshElement* myCurrElement;
136 Description : Functor calculating volume of 3D mesh element
138 class Volume: public virtual NumericalFunctor{
140 virtual double GetValue( long theElementId );
141 //virtual double GetValue( const TSequenceOfXYZ& thePoints );
142 virtual double GetBadRate( double Value, int nbNodes ) const;
143 virtual SMDSAbs_ElementType GetType() const;
148 Class : SMESH_MinimumAngle
149 Description : Functor for calculation of minimum angle
151 class MinimumAngle: public virtual NumericalFunctor{
153 virtual double GetValue( const TSequenceOfXYZ& thePoints );
154 virtual double GetBadRate( double Value, int nbNodes ) const;
155 virtual SMDSAbs_ElementType GetType() const;
161 Description : Functor for calculating aspect ratio
163 class AspectRatio: public virtual NumericalFunctor{
165 virtual double GetValue( const TSequenceOfXYZ& thePoints );
166 virtual double GetBadRate( double Value, int nbNodes ) const;
167 virtual SMDSAbs_ElementType GetType() const;
172 Class : AspectRatio3D
173 Description : Functor for calculating aspect ratio of 3D elems.
175 class AspectRatio3D: public virtual NumericalFunctor{
177 virtual double GetValue( const TSequenceOfXYZ& thePoints );
178 virtual double GetBadRate( double Value, int nbNodes ) const;
179 virtual SMDSAbs_ElementType GetType() const;
185 Description : Functor for calculating warping
187 class Warping: public virtual NumericalFunctor{
189 virtual double GetValue( const TSequenceOfXYZ& thePoints );
190 virtual double GetBadRate( double Value, int nbNodes ) const;
191 virtual SMDSAbs_ElementType GetType() const;
194 double ComputeA( const gp_XYZ&, const gp_XYZ&, const gp_XYZ&, const gp_XYZ& ) const;
200 Description : Functor for calculating taper
202 class Taper: public virtual NumericalFunctor{
204 virtual double GetValue( const TSequenceOfXYZ& thePoints );
205 virtual double GetBadRate( double Value, int nbNodes ) const;
206 virtual SMDSAbs_ElementType GetType() const;
212 Description : Functor for calculating skew in degrees
214 class Skew: public virtual NumericalFunctor{
216 virtual double GetValue( const TSequenceOfXYZ& thePoints );
217 virtual double GetBadRate( double Value, int nbNodes ) const;
218 virtual SMDSAbs_ElementType GetType() const;
224 Description : Functor for calculating area
226 class Area: public virtual NumericalFunctor{
228 virtual double GetValue( const TSequenceOfXYZ& thePoints );
229 virtual double GetBadRate( double Value, int nbNodes ) const;
230 virtual SMDSAbs_ElementType GetType() const;
236 Description : Functor for calculating length of edge
238 class Length: public virtual NumericalFunctor{
240 virtual double GetValue( const TSequenceOfXYZ& thePoints );
241 virtual double GetBadRate( double Value, int nbNodes ) const;
242 virtual SMDSAbs_ElementType GetType() const;
247 Description : Functor for calculating length of edge
249 class Length2D: public virtual NumericalFunctor{
251 virtual double GetValue( long theElementId );
252 virtual double GetBadRate( double Value, int nbNodes ) const;
253 virtual SMDSAbs_ElementType GetType() const;
257 Value(double theLength, long thePntId1, long thePntId2);
258 bool operator<(const Value& x) const;
260 typedef std::set<Value> TValues;
261 void GetValues(TValues& theValues);
264 typedef boost::shared_ptr<Length2D> Length2DPtr;
267 Class : MultiConnection
268 Description : Functor for calculating number of faces conneted to the edge
270 class MultiConnection: public virtual NumericalFunctor{
272 virtual double GetValue( long theElementId );
273 virtual double GetValue( const TSequenceOfXYZ& thePoints );
274 virtual double GetBadRate( double Value, int nbNodes ) const;
275 virtual SMDSAbs_ElementType GetType() const;
279 Class : MultiConnection2D
280 Description : Functor for calculating number of faces conneted to the edge
282 class MultiConnection2D: public virtual NumericalFunctor{
284 virtual double GetValue( long theElementId );
285 virtual double GetValue( const TSequenceOfXYZ& thePoints );
286 virtual double GetBadRate( double Value, int nbNodes ) const;
287 virtual SMDSAbs_ElementType GetType() const;
290 Value(long thePntId1, long thePntId2);
291 bool operator<(const Value& x) const;
293 typedef std::map<Value,int> MValues;
295 void GetValues(MValues& theValues);
297 typedef boost::shared_ptr<MultiConnection2D> MultiConnection2DPtr;
303 Description : Base class for all predicates
305 class Predicate: public virtual Functor{
307 virtual bool IsSatisfy( long theElementId ) = 0;
308 virtual SMDSAbs_ElementType GetType() const = 0;
315 Description : Predicate for free borders
317 class FreeBorders: public virtual Predicate{
320 virtual void SetMesh( const SMDS_Mesh* theMesh );
321 virtual bool IsSatisfy( long theElementId );
322 virtual SMDSAbs_ElementType GetType() const;
325 const SMDS_Mesh* myMesh;
330 Class : BadOrientedVolume
331 Description : Predicate bad oriented volumes
333 class BadOrientedVolume: public virtual Predicate{
336 virtual void SetMesh( const SMDS_Mesh* theMesh );
337 virtual bool IsSatisfy( long theElementId );
338 virtual SMDSAbs_ElementType GetType() const;
341 const SMDS_Mesh* myMesh;
347 Description : Predicate for free Edges
349 class FreeEdges: public virtual Predicate{
352 virtual void SetMesh( const SMDS_Mesh* theMesh );
353 virtual bool IsSatisfy( long theElementId );
354 virtual SMDSAbs_ElementType GetType() const;
355 static bool IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId );
356 typedef long TElemId;
360 Border(long theElemId, long thePntId1, long thePntId2);
361 bool operator<(const Border& x) const;
363 typedef std::set<Border> TBorders;
364 void GetBoreders(TBorders& theBorders);
367 const SMDS_Mesh* myMesh;
369 typedef boost::shared_ptr<FreeEdges> FreeEdgesPtr;
374 Description : Predicate for Range of Ids.
375 Range may be specified with two ways.
376 1. Using AddToRange method
377 2. With SetRangeStr method. Parameter of this method is a string
378 like as "1,2,3,50-60,63,67,70-"
380 class RangeOfIds: public virtual Predicate
384 virtual void SetMesh( const SMDS_Mesh* theMesh );
385 virtual bool IsSatisfy( long theNodeId );
386 virtual SMDSAbs_ElementType GetType() const;
387 virtual void SetType( SMDSAbs_ElementType theType );
389 bool AddToRange( long theEntityId );
390 void GetRangeStr( TCollection_AsciiString& );
391 bool SetRangeStr( const TCollection_AsciiString& );
394 const SMDS_Mesh* myMesh;
396 TColStd_SequenceOfInteger myMin;
397 TColStd_SequenceOfInteger myMax;
398 TColStd_MapOfInteger myIds;
400 SMDSAbs_ElementType myType;
403 typedef boost::shared_ptr<RangeOfIds> RangeOfIdsPtr;
408 Description : Base class for comparators
410 class Comparator: public virtual Predicate{
413 virtual ~Comparator();
414 virtual void SetMesh( const SMDS_Mesh* theMesh );
415 virtual void SetMargin(double theValue);
416 virtual void SetNumFunctor(NumericalFunctorPtr theFunct);
417 virtual bool IsSatisfy( long theElementId ) = 0;
418 virtual SMDSAbs_ElementType GetType() const;
423 NumericalFunctorPtr myFunctor;
425 typedef boost::shared_ptr<Comparator> ComparatorPtr;
430 Description : Comparator "<"
432 class LessThan: public virtual Comparator{
434 virtual bool IsSatisfy( long theElementId );
440 Description : Comparator ">"
442 class MoreThan: public virtual Comparator{
444 virtual bool IsSatisfy( long theElementId );
450 Description : Comparator "="
452 class EqualTo: public virtual Comparator{
455 virtual bool IsSatisfy( long theElementId );
456 virtual void SetTolerance( double theTol );
457 virtual double GetTolerance();
462 typedef boost::shared_ptr<EqualTo> EqualToPtr;
467 Description : Logical NOT predicate
469 class LogicalNOT: public virtual Predicate{
472 virtual ~LogicalNOT();
473 virtual bool IsSatisfy( long theElementId );
474 virtual void SetMesh( const SMDS_Mesh* theMesh );
475 virtual void SetPredicate(PredicatePtr thePred);
476 virtual SMDSAbs_ElementType GetType() const;
479 PredicatePtr myPredicate;
481 typedef boost::shared_ptr<LogicalNOT> LogicalNOTPtr;
485 Class : LogicalBinary
486 Description : Base class for binary logical predicate
488 class LogicalBinary: public virtual Predicate{
491 virtual ~LogicalBinary();
492 virtual void SetMesh( const SMDS_Mesh* theMesh );
493 virtual void SetPredicate1(PredicatePtr thePred);
494 virtual void SetPredicate2(PredicatePtr thePred);
495 virtual SMDSAbs_ElementType GetType() const;
498 PredicatePtr myPredicate1;
499 PredicatePtr myPredicate2;
501 typedef boost::shared_ptr<LogicalBinary> LogicalBinaryPtr;
506 Description : Logical AND
508 class LogicalAND: public virtual LogicalBinary{
510 virtual bool IsSatisfy( long theElementId );
516 Description : Logical OR
518 class LogicalOR: public virtual LogicalBinary{
520 virtual bool IsSatisfy( long theElementId );
526 Description : Predicate for manifold part of mesh
528 class ManifoldPart: public virtual Predicate{
531 /* internal class for algorithm uses */
535 Link( SMDS_MeshNode* theNode1,
536 SMDS_MeshNode* theNode2 );
539 bool IsEqual( const ManifoldPart::Link& theLink ) const;
540 bool operator<(const ManifoldPart::Link& x) const;
542 SMDS_MeshNode* myNode1;
543 SMDS_MeshNode* myNode2;
546 bool IsEqual( const ManifoldPart::Link& theLink1,
547 const ManifoldPart::Link& theLink2 );
549 typedef std::set<ManifoldPart::Link> TMapOfLink;
550 typedef std::vector<SMDS_MeshFace*> TVectorOfFacePtr;
551 typedef std::vector<ManifoldPart::Link> TVectorOfLink;
552 typedef std::map<SMDS_MeshFace*,int> TDataMapFacePtrInt;
553 typedef std::map<ManifoldPart::Link,SMDS_MeshFace*> TDataMapOfLinkFacePtr;
557 virtual void SetMesh( const SMDS_Mesh* theMesh );
558 // inoke when all parameters already set
559 virtual bool IsSatisfy( long theElementId );
560 virtual SMDSAbs_ElementType GetType() const;
562 void SetAngleTolerance( const double theAngToler );
563 double GetAngleTolerance() const;
564 void SetIsOnlyManifold( const bool theIsOnly );
565 void SetStartElem( const long theStartElemId );
569 bool findConnected( const TDataMapFacePtrInt& theAllFacePtrInt,
570 SMDS_MeshFace* theStartFace,
571 TMapOfLink& theNonManifold,
572 TColStd_MapOfInteger& theResFaces );
573 bool isInPlane( const SMDS_MeshFace* theFace1,
574 const SMDS_MeshFace* theFace2 );
575 void expandBoundary( TMapOfLink& theMapOfBoundary,
576 TVectorOfLink& theSeqOfBoundary,
577 TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
578 TMapOfLink& theNonManifold,
579 SMDS_MeshFace* theNextFace ) const;
581 void getFacesByLink( const Link& theLink,
582 TVectorOfFacePtr& theFaces ) const;
585 const SMDS_Mesh* myMesh;
586 TColStd_MapOfInteger myMapIds;
587 TColStd_MapOfInteger myMapBadGeomIds;
588 TVectorOfFacePtr myAllFacePtr;
589 TDataMapFacePtrInt myAllFacePtrIntDMap;
591 bool myIsOnlyManifold;
595 typedef boost::shared_ptr<ManifoldPart> ManifoldPartPtr;
599 Class : ElementsOnSurface
600 Description : Predicate elements that lying on indicated surface
603 class ElementsOnSurface : public virtual Predicate {
606 ~ElementsOnSurface();
607 virtual void SetMesh( const SMDS_Mesh* theMesh );
608 virtual bool IsSatisfy( long theElementId );
609 virtual SMDSAbs_ElementType GetType() const;
611 void SetTolerance( const double theToler );
612 double GetTolerance() const;
613 void SetSurface( const TopoDS_Shape& theShape,
614 const SMDSAbs_ElementType theType );
618 void process( const SMDS_MeshElement* theElem );
619 bool isOnSurface( const SMDS_MeshNode* theNode ) const;
622 const SMDS_Mesh* myMesh;
623 TColStd_MapOfInteger myIds;
624 SMDSAbs_ElementType myType;
625 Handle(Geom_Surface) mySurf;
629 typedef boost::shared_ptr<ElementsOnSurface> ElementsOnSurfacePtr;
639 virtual void SetPredicate(PredicatePtr thePred);
641 typedef std::vector<long> TIdSequence;
645 GetElementsId( const SMDS_Mesh* theMesh,
646 TIdSequence& theSequence );
650 GetElementsId( const SMDS_Mesh* theMesh,
651 PredicatePtr thePredicate,
652 TIdSequence& theSequence );
655 PredicatePtr myPredicate;