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"
40 class SMDS_MeshElement;
46 class SMESHDS_SubMesh;
55 class TSequenceOfXYZ: public std::vector<gp_XYZ>
58 typedef std::vector<gp_XYZ> TSuperClass;
62 TSequenceOfXYZ(size_type n):
66 TSequenceOfXYZ(size_type n, const value_type& t):
70 TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ):
71 TSuperClass(theSequenceOfXYZ)
74 template <class InputIterator>
75 TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd):
76 TSuperClass(theBegin,theEnd)
79 TSequenceOfXYZ& operator=(const TSequenceOfXYZ& theSequenceOfXYZ){
80 TSuperClass::operator=(theSequenceOfXYZ);
84 reference operator()(size_type n){
85 return TSuperClass::operator[](n-1);
88 const_reference operator()(size_type n) const{
89 return TSuperClass::operator[](n-1);
93 reference operator[](size_type n);
95 const_reference operator[](size_type n) const;
100 Description : Root of all Functors
106 virtual void SetMesh( const SMDS_Mesh* theMesh ) = 0;
107 virtual SMDSAbs_ElementType GetType() const = 0;
111 Class : NumericalFunctor
112 Description : Root of all Functors returning numeric value
114 class NumericalFunctor: public virtual Functor{
117 virtual void SetMesh( const SMDS_Mesh* theMesh );
118 virtual double GetValue( long theElementId );
119 virtual double GetValue(const TSequenceOfXYZ& thePoints) { return -1.0;};
120 virtual SMDSAbs_ElementType GetType() const = 0;
121 virtual double GetBadRate( double Value, int nbNodes ) const = 0;
122 long GetPrecision() const;
123 void SetPrecision( const long thePrecision );
125 bool GetPoints(const int theId,
126 TSequenceOfXYZ& theRes) const;
127 static bool GetPoints(const SMDS_MeshElement* theElem,
128 TSequenceOfXYZ& theRes);
130 const SMDS_Mesh* myMesh;
131 const SMDS_MeshElement* myCurrElement;
138 Description : Functor calculating volume of 3D mesh element
140 class Volume: public virtual NumericalFunctor{
142 virtual double GetValue( long theElementId );
143 //virtual double GetValue( const TSequenceOfXYZ& thePoints );
144 virtual double GetBadRate( double Value, int nbNodes ) const;
145 virtual SMDSAbs_ElementType GetType() const;
150 Class : SMESH_MinimumAngle
151 Description : Functor for calculation of minimum angle
153 class MinimumAngle: public virtual NumericalFunctor{
155 virtual double GetValue( const TSequenceOfXYZ& thePoints );
156 virtual double GetBadRate( double Value, int nbNodes ) const;
157 virtual SMDSAbs_ElementType GetType() const;
163 Description : Functor for calculating aspect ratio
165 class AspectRatio: public virtual NumericalFunctor{
167 virtual double GetValue( const TSequenceOfXYZ& thePoints );
168 virtual double GetBadRate( double Value, int nbNodes ) const;
169 virtual SMDSAbs_ElementType GetType() const;
174 Class : AspectRatio3D
175 Description : Functor for calculating aspect ratio of 3D elems.
177 class AspectRatio3D: public virtual NumericalFunctor{
179 virtual double GetValue( const TSequenceOfXYZ& thePoints );
180 virtual double GetBadRate( double Value, int nbNodes ) const;
181 virtual SMDSAbs_ElementType GetType() const;
187 Description : Functor for calculating warping
189 class Warping: public virtual NumericalFunctor{
191 virtual double GetValue( const TSequenceOfXYZ& thePoints );
192 virtual double GetBadRate( double Value, int nbNodes ) const;
193 virtual SMDSAbs_ElementType GetType() const;
196 double ComputeA( const gp_XYZ&, const gp_XYZ&, const gp_XYZ&, const gp_XYZ& ) const;
202 Description : Functor for calculating taper
204 class Taper: 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;
214 Description : Functor for calculating skew in degrees
216 class Skew: public virtual NumericalFunctor{
218 virtual double GetValue( const TSequenceOfXYZ& thePoints );
219 virtual double GetBadRate( double Value, int nbNodes ) const;
220 virtual SMDSAbs_ElementType GetType() const;
226 Description : Functor for calculating area
228 class Area: public virtual NumericalFunctor{
230 virtual double GetValue( const TSequenceOfXYZ& thePoints );
231 virtual double GetBadRate( double Value, int nbNodes ) const;
232 virtual SMDSAbs_ElementType GetType() const;
238 Description : Functor for calculating length of edge
240 class Length: public virtual NumericalFunctor{
242 virtual double GetValue( const TSequenceOfXYZ& thePoints );
243 virtual double GetBadRate( double Value, int nbNodes ) const;
244 virtual SMDSAbs_ElementType GetType() const;
249 Description : Functor for calculating length of edge
251 class Length2D: public virtual NumericalFunctor{
253 virtual double GetValue( long theElementId );
254 virtual double GetBadRate( double Value, int nbNodes ) const;
255 virtual SMDSAbs_ElementType GetType() const;
259 Value(double theLength, long thePntId1, long thePntId2);
260 bool operator<(const Value& x) const;
262 typedef std::set<Value> TValues;
263 void GetValues(TValues& theValues);
266 typedef boost::shared_ptr<Length2D> Length2DPtr;
269 Class : MultiConnection
270 Description : Functor for calculating number of faces conneted to the edge
272 class MultiConnection: public virtual NumericalFunctor{
274 virtual double GetValue( long theElementId );
275 virtual double GetValue( const TSequenceOfXYZ& thePoints );
276 virtual double GetBadRate( double Value, int nbNodes ) const;
277 virtual SMDSAbs_ElementType GetType() const;
281 Class : MultiConnection2D
282 Description : Functor for calculating number of faces conneted to the edge
284 class MultiConnection2D: public virtual NumericalFunctor{
286 virtual double GetValue( long theElementId );
287 virtual double GetValue( const TSequenceOfXYZ& thePoints );
288 virtual double GetBadRate( double Value, int nbNodes ) const;
289 virtual SMDSAbs_ElementType GetType() const;
292 Value(long thePntId1, long thePntId2);
293 bool operator<(const Value& x) const;
295 typedef std::map<Value,int> MValues;
297 void GetValues(MValues& theValues);
299 typedef boost::shared_ptr<MultiConnection2D> MultiConnection2DPtr;
305 Description : Base class for all predicates
307 class Predicate: public virtual Functor{
309 virtual bool IsSatisfy( long theElementId ) = 0;
310 virtual SMDSAbs_ElementType GetType() const = 0;
317 Description : Predicate for free borders
319 class FreeBorders: public virtual Predicate{
322 virtual void SetMesh( const SMDS_Mesh* theMesh );
323 virtual bool IsSatisfy( long theElementId );
324 virtual SMDSAbs_ElementType GetType() const;
327 const SMDS_Mesh* myMesh;
332 Class : BadOrientedVolume
333 Description : Predicate bad oriented volumes
335 class BadOrientedVolume: public virtual Predicate{
338 virtual void SetMesh( const SMDS_Mesh* theMesh );
339 virtual bool IsSatisfy( long theElementId );
340 virtual SMDSAbs_ElementType GetType() const;
343 const SMDS_Mesh* myMesh;
349 Description : Predicate for free Edges
351 class FreeEdges: public virtual Predicate{
354 virtual void SetMesh( const SMDS_Mesh* theMesh );
355 virtual bool IsSatisfy( long theElementId );
356 virtual SMDSAbs_ElementType GetType() const;
357 static bool IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId );
358 typedef long TElemId;
362 Border(long theElemId, long thePntId1, long thePntId2);
363 bool operator<(const Border& x) const;
365 typedef std::set<Border> TBorders;
366 void GetBoreders(TBorders& theBorders);
369 const SMDS_Mesh* myMesh;
371 typedef boost::shared_ptr<FreeEdges> FreeEdgesPtr;
376 Description : Predicate for Range of Ids.
377 Range may be specified with two ways.
378 1. Using AddToRange method
379 2. With SetRangeStr method. Parameter of this method is a string
380 like as "1,2,3,50-60,63,67,70-"
382 class RangeOfIds: public virtual Predicate
386 virtual void SetMesh( const SMDS_Mesh* theMesh );
387 virtual bool IsSatisfy( long theNodeId );
388 virtual SMDSAbs_ElementType GetType() const;
389 virtual void SetType( SMDSAbs_ElementType theType );
391 bool AddToRange( long theEntityId );
392 void GetRangeStr( TCollection_AsciiString& );
393 bool SetRangeStr( const TCollection_AsciiString& );
396 const SMDS_Mesh* myMesh;
398 TColStd_SequenceOfInteger myMin;
399 TColStd_SequenceOfInteger myMax;
400 TColStd_MapOfInteger myIds;
402 SMDSAbs_ElementType myType;
405 typedef boost::shared_ptr<RangeOfIds> RangeOfIdsPtr;
410 Description : Base class for comparators
412 class Comparator: public virtual Predicate{
415 virtual ~Comparator();
416 virtual void SetMesh( const SMDS_Mesh* theMesh );
417 virtual void SetMargin(double theValue);
418 virtual void SetNumFunctor(NumericalFunctorPtr theFunct);
419 virtual bool IsSatisfy( long theElementId ) = 0;
420 virtual SMDSAbs_ElementType GetType() const;
425 NumericalFunctorPtr myFunctor;
427 typedef boost::shared_ptr<Comparator> ComparatorPtr;
432 Description : Comparator "<"
434 class LessThan: public virtual Comparator{
436 virtual bool IsSatisfy( long theElementId );
442 Description : Comparator ">"
444 class MoreThan: public virtual Comparator{
446 virtual bool IsSatisfy( long theElementId );
452 Description : Comparator "="
454 class EqualTo: public virtual Comparator{
457 virtual bool IsSatisfy( long theElementId );
458 virtual void SetTolerance( double theTol );
459 virtual double GetTolerance();
464 typedef boost::shared_ptr<EqualTo> EqualToPtr;
469 Description : Logical NOT predicate
471 class LogicalNOT: public virtual Predicate{
474 virtual ~LogicalNOT();
475 virtual bool IsSatisfy( long theElementId );
476 virtual void SetMesh( const SMDS_Mesh* theMesh );
477 virtual void SetPredicate(PredicatePtr thePred);
478 virtual SMDSAbs_ElementType GetType() const;
481 PredicatePtr myPredicate;
483 typedef boost::shared_ptr<LogicalNOT> LogicalNOTPtr;
487 Class : LogicalBinary
488 Description : Base class for binary logical predicate
490 class LogicalBinary: public virtual Predicate{
493 virtual ~LogicalBinary();
494 virtual void SetMesh( const SMDS_Mesh* theMesh );
495 virtual void SetPredicate1(PredicatePtr thePred);
496 virtual void SetPredicate2(PredicatePtr thePred);
497 virtual SMDSAbs_ElementType GetType() const;
500 PredicatePtr myPredicate1;
501 PredicatePtr myPredicate2;
503 typedef boost::shared_ptr<LogicalBinary> LogicalBinaryPtr;
508 Description : Logical AND
510 class LogicalAND: public virtual LogicalBinary{
512 virtual bool IsSatisfy( long theElementId );
518 Description : Logical OR
520 class LogicalOR: public virtual LogicalBinary{
522 virtual bool IsSatisfy( long theElementId );
528 Description : Predicate for manifold part of mesh
530 class ManifoldPart: public virtual Predicate{
533 /* internal class for algorithm uses */
537 Link( SMDS_MeshNode* theNode1,
538 SMDS_MeshNode* theNode2 );
541 bool IsEqual( const ManifoldPart::Link& theLink ) const;
542 bool operator<(const ManifoldPart::Link& x) const;
544 SMDS_MeshNode* myNode1;
545 SMDS_MeshNode* myNode2;
548 bool IsEqual( const ManifoldPart::Link& theLink1,
549 const ManifoldPart::Link& theLink2 );
551 typedef std::set<ManifoldPart::Link> TMapOfLink;
552 typedef std::vector<SMDS_MeshFace*> TVectorOfFacePtr;
553 typedef std::vector<ManifoldPart::Link> TVectorOfLink;
554 typedef std::map<SMDS_MeshFace*,int> TDataMapFacePtrInt;
555 typedef std::map<ManifoldPart::Link,SMDS_MeshFace*> TDataMapOfLinkFacePtr;
559 virtual void SetMesh( const SMDS_Mesh* theMesh );
560 // inoke when all parameters already set
561 virtual bool IsSatisfy( long theElementId );
562 virtual SMDSAbs_ElementType GetType() const;
564 void SetAngleTolerance( const double theAngToler );
565 double GetAngleTolerance() const;
566 void SetIsOnlyManifold( const bool theIsOnly );
567 void SetStartElem( const long theStartElemId );
571 bool findConnected( const TDataMapFacePtrInt& theAllFacePtrInt,
572 SMDS_MeshFace* theStartFace,
573 TMapOfLink& theNonManifold,
574 TColStd_MapOfInteger& theResFaces );
575 bool isInPlane( const SMDS_MeshFace* theFace1,
576 const SMDS_MeshFace* theFace2 );
577 void expandBoundary( TMapOfLink& theMapOfBoundary,
578 TVectorOfLink& theSeqOfBoundary,
579 TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
580 TMapOfLink& theNonManifold,
581 SMDS_MeshFace* theNextFace ) const;
583 void getFacesByLink( const Link& theLink,
584 TVectorOfFacePtr& theFaces ) const;
587 const SMDS_Mesh* myMesh;
588 TColStd_MapOfInteger myMapIds;
589 TColStd_MapOfInteger myMapBadGeomIds;
590 TVectorOfFacePtr myAllFacePtr;
591 TDataMapFacePtrInt myAllFacePtrIntDMap;
593 bool myIsOnlyManifold;
597 typedef boost::shared_ptr<ManifoldPart> ManifoldPartPtr;
601 Class : ElementsOnSurface
602 Description : Predicate elements that lying on indicated surface
605 class ElementsOnSurface : public virtual Predicate {
608 ~ElementsOnSurface();
609 virtual void SetMesh( const SMDS_Mesh* theMesh );
610 virtual bool IsSatisfy( long theElementId );
611 virtual SMDSAbs_ElementType GetType() const;
613 void SetTolerance( const double theToler );
614 double GetTolerance() const;
615 void SetSurface( const TopoDS_Shape& theShape,
616 const SMDSAbs_ElementType theType );
617 void SetUseBoundaries( bool theUse );
618 bool GetUseBoundaries() const { return myUseBoundaries; }
622 void process( const SMDS_MeshElement* theElem );
623 bool isOnSurface( const SMDS_MeshNode* theNode );
626 const SMDS_Mesh* myMesh;
627 TColStd_MapOfInteger myIds;
628 SMDSAbs_ElementType myType;
629 //Handle(Geom_Surface) mySurf;
632 bool myUseBoundaries;
633 GeomAPI_ProjectPointOnSurf myProjector;
636 typedef boost::shared_ptr<ElementsOnSurface> ElementsOnSurfacePtr;
646 virtual void SetPredicate(PredicatePtr thePred);
648 typedef std::vector<long> TIdSequence;
652 GetElementsId( const SMDS_Mesh* theMesh,
653 TIdSequence& theSequence );
657 GetElementsId( const SMDS_Mesh* theMesh,
658 PredicatePtr thePredicate,
659 TIdSequence& theSequence );
662 PredicatePtr myPredicate;