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;
100 virtual void SetMesh( SMDS_Mesh* theMesh ) = 0;
101 virtual SMDSAbs_ElementType GetType() const = 0;
104 class NumericalFunctor: public virtual Functor{
107 virtual void SetMesh( SMDS_Mesh* theMesh );
108 virtual double GetValue( long theElementId );
109 virtual double GetValue(const TSequenceOfXYZ& thePoints) { return -1.0;};
110 virtual SMDSAbs_ElementType GetType() const = 0;
111 virtual double GetBadRate( double Value, int nbNodes ) const = 0;
112 long GetPrecision() const;
113 void SetPrecision( const long thePrecision );
115 bool GetPoints(const int theId,
116 TSequenceOfXYZ& theRes) const;
117 static bool GetPoints(const SMDS_MeshElement* theElem,
118 TSequenceOfXYZ& theRes);
126 Class : SMESH_MinimumAngle
127 Description : Functor for calculation of minimum angle
129 class MinimumAngle: public virtual NumericalFunctor{
131 virtual double GetValue( const TSequenceOfXYZ& thePoints );
132 virtual double GetBadRate( double Value, int nbNodes ) const;
133 virtual SMDSAbs_ElementType GetType() const;
139 Description : Functor for calculating aspect ratio
141 class AspectRatio: public virtual NumericalFunctor{
143 virtual double GetValue( const TSequenceOfXYZ& thePoints );
144 virtual double GetBadRate( double Value, int nbNodes ) const;
145 virtual SMDSAbs_ElementType GetType() const;
150 Class : AspectRatio3D
151 Description : Functor for calculating aspect ratio of 3D elems.
153 class AspectRatio3D: 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 warping
165 class Warping: 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;
172 double ComputeA( const gp_XYZ&, const gp_XYZ&, const gp_XYZ&, const gp_XYZ& ) const;
178 Description : Functor for calculating taper
180 class Taper: 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;
190 Description : Functor for calculating skew in degrees
192 class Skew: 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 area
204 class Area: 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 length of edge
216 class Length: 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;
225 Description : Functor for calculating length of edge
227 class Length2D: public virtual NumericalFunctor{
229 virtual double GetValue( long theElementId );
230 virtual double GetBadRate( double Value, int nbNodes ) const;
231 virtual SMDSAbs_ElementType GetType() const;
235 Value(double theLength, long thePntId1, long thePntId2);
236 bool operator<(const Value& x) const;
238 typedef std::set<Value> TValues;
239 void GetValues(TValues& theValues);
242 typedef boost::shared_ptr<Length2D> Length2DPtr;
245 Class : MultiConnection
246 Description : Functor for calculating number of faces conneted to the edge
248 class MultiConnection: public virtual NumericalFunctor{
250 virtual double GetValue( long theElementId );
251 virtual double GetValue( const TSequenceOfXYZ& thePoints );
252 virtual double GetBadRate( double Value, int nbNodes ) const;
253 virtual SMDSAbs_ElementType GetType() const;
257 Class : MultiConnection2D
258 Description : Functor for calculating number of faces conneted to the edge
260 class MultiConnection2D: public virtual NumericalFunctor{
262 virtual double GetValue( long theElementId );
263 virtual double GetValue( const TSequenceOfXYZ& thePoints );
264 virtual double GetBadRate( double Value, int nbNodes ) const;
265 virtual SMDSAbs_ElementType GetType() const;
268 Value(long thePntId1, long thePntId2);
269 bool operator<(const Value& x) const;
271 typedef std::map<Value,int> MValues;
273 void GetValues(MValues& theValues);
275 typedef boost::shared_ptr<MultiConnection2D> MultiConnection2DPtr;
281 Description : Base class for all predicates
283 class Predicate: public virtual Functor{
285 virtual bool IsSatisfy( long theElementId ) = 0;
286 virtual SMDSAbs_ElementType GetType() const = 0;
293 Description : Predicate for free borders
295 class FreeBorders: public virtual Predicate{
298 virtual void SetMesh( SMDS_Mesh* theMesh );
299 virtual bool IsSatisfy( long theElementId );
300 virtual SMDSAbs_ElementType GetType() const;
309 Description : Predicate for free Edges
311 class FreeEdges: public virtual Predicate{
314 virtual void SetMesh( SMDS_Mesh* theMesh );
315 virtual bool IsSatisfy( long theElementId );
316 virtual SMDSAbs_ElementType GetType() const;
317 static bool IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId );
318 typedef long TElemId;
322 Border(long theElemId, long thePntId1, long thePntId2);
323 bool operator<(const Border& x) const;
325 typedef std::set<Border> TBorders;
326 void GetBoreders(TBorders& theBorders);
331 typedef boost::shared_ptr<FreeEdges> FreeEdgesPtr;
336 Description : Predicate for Range of Ids.
337 Range may be specified with two ways.
338 1. Using AddToRange method
339 2. With SetRangeStr method. Parameter of this method is a string
340 like as "1,2,3,50-60,63,67,70-"
342 class RangeOfIds: public virtual Predicate
346 virtual void SetMesh( SMDS_Mesh* theMesh );
347 virtual bool IsSatisfy( long theNodeId );
348 virtual SMDSAbs_ElementType GetType() const;
349 virtual void SetType( SMDSAbs_ElementType theType );
351 bool AddToRange( long theEntityId );
352 void GetRangeStr( TCollection_AsciiString& );
353 bool SetRangeStr( const TCollection_AsciiString& );
358 TColStd_SequenceOfInteger myMin;
359 TColStd_SequenceOfInteger myMax;
360 TColStd_MapOfInteger myIds;
362 SMDSAbs_ElementType myType;
365 typedef boost::shared_ptr<RangeOfIds> RangeOfIdsPtr;
370 Description : Base class for comparators
372 class Comparator: public virtual Predicate{
375 virtual ~Comparator();
376 virtual void SetMesh( SMDS_Mesh* theMesh );
377 virtual void SetMargin(double theValue);
378 virtual void SetNumFunctor(NumericalFunctorPtr theFunct);
379 virtual bool IsSatisfy( long theElementId ) = 0;
380 virtual SMDSAbs_ElementType GetType() const;
385 NumericalFunctorPtr myFunctor;
387 typedef boost::shared_ptr<Comparator> ComparatorPtr;
392 Description : Comparator "<"
394 class LessThan: public virtual Comparator{
396 virtual bool IsSatisfy( long theElementId );
402 Description : Comparator ">"
404 class MoreThan: public virtual Comparator{
406 virtual bool IsSatisfy( long theElementId );
412 Description : Comparator "="
414 class EqualTo: public virtual Comparator{
417 virtual bool IsSatisfy( long theElementId );
418 virtual void SetTolerance( double theTol );
419 virtual double GetTolerance();
424 typedef boost::shared_ptr<EqualTo> EqualToPtr;
429 Description : Logical NOT predicate
431 class LogicalNOT: public virtual Predicate{
434 virtual ~LogicalNOT();
435 virtual bool IsSatisfy( long theElementId );
436 virtual void SetMesh( SMDS_Mesh* theMesh );
437 virtual void SetPredicate(PredicatePtr thePred);
438 virtual SMDSAbs_ElementType GetType() const;
441 PredicatePtr myPredicate;
443 typedef boost::shared_ptr<LogicalNOT> LogicalNOTPtr;
447 Class : LogicalBinary
448 Description : Base class for binary logical predicate
450 class LogicalBinary: public virtual Predicate{
453 virtual ~LogicalBinary();
454 virtual void SetMesh( SMDS_Mesh* theMesh );
455 virtual void SetPredicate1(PredicatePtr thePred);
456 virtual void SetPredicate2(PredicatePtr thePred);
457 virtual SMDSAbs_ElementType GetType() const;
460 PredicatePtr myPredicate1;
461 PredicatePtr myPredicate2;
463 typedef boost::shared_ptr<LogicalBinary> LogicalBinaryPtr;
468 Description : Logical AND
470 class LogicalAND: public virtual LogicalBinary{
472 virtual bool IsSatisfy( long theElementId );
478 Description : Logical OR
480 class LogicalOR: public virtual LogicalBinary{
482 virtual bool IsSatisfy( long theElementId );
488 Description : Predicate for manifold part of mesh
490 class ManifoldPart: public virtual Predicate{
493 /* internal class for algorithm uses */
497 Link( SMDS_MeshNode* theNode1,
498 SMDS_MeshNode* theNode2 );
501 bool IsEqual( const ManifoldPart::Link& theLink ) const;
502 bool operator<(const ManifoldPart::Link& x) const;
504 SMDS_MeshNode* myNode1;
505 SMDS_MeshNode* myNode2;
508 bool IsEqual( const ManifoldPart::Link& theLink1,
509 const ManifoldPart::Link& theLink2 );
511 typedef std::set<ManifoldPart::Link> TMapOfLink;
512 typedef std::vector<SMDS_MeshFace*> TVectorOfFacePtr;
513 typedef std::vector<ManifoldPart::Link> TVectorOfLink;
514 typedef std::map<SMDS_MeshFace*,int> TDataMapFacePtrInt;
515 typedef std::map<ManifoldPart::Link,SMDS_MeshFace*> TDataMapOfLinkFacePtr;
519 virtual void SetMesh( SMDS_Mesh* theMesh );
520 // inoke when all parameters already set
521 virtual bool IsSatisfy( long theElementId );
522 virtual SMDSAbs_ElementType GetType() const;
524 void SetAngleTolerance( const double theAngToler );
525 double GetAngleTolerance() const;
526 void SetIsOnlyManifold( const bool theIsOnly );
527 void SetStartElem( const long theStartElemId );
531 bool findConnected( const TDataMapFacePtrInt& theAllFacePtrInt,
532 SMDS_MeshFace* theStartFace,
533 TMapOfLink& theNonManifold,
534 TColStd_MapOfInteger& theResFaces );
535 bool isInPlane( const SMDS_MeshFace* theFace1,
536 const SMDS_MeshFace* theFace2 );
537 void expandBoundary( TMapOfLink& theMapOfBoundary,
538 TVectorOfLink& theSeqOfBoundary,
539 TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
540 TMapOfLink& theNonManifold,
541 SMDS_MeshFace* theNextFace ) const;
543 void getFacesByLink( const Link& theLink,
544 TVectorOfFacePtr& theFaces ) const;
548 TColStd_MapOfInteger myMapIds;
549 TColStd_MapOfInteger myMapBadGeomIds;
550 TVectorOfFacePtr myAllFacePtr;
551 TDataMapFacePtrInt myAllFacePtrIntDMap;
553 bool myIsOnlyManifold;
557 typedef boost::shared_ptr<ManifoldPart> ManifoldPartPtr;
561 Class : ElementsOnSurface
562 Description : Predicate elements that lying on indicated surface
565 class ElementsOnSurface : public virtual Predicate {
568 ~ElementsOnSurface();
569 virtual void SetMesh( SMDS_Mesh* theMesh );
570 virtual bool IsSatisfy( long theElementId );
571 virtual SMDSAbs_ElementType GetType() const;
573 void SetTolerance( const double theToler );
574 double GetTolerance() const;
575 void SetSurface( const TopoDS_Shape& theShape,
576 const SMDSAbs_ElementType theType );
580 void process( const SMDS_MeshElement* theElem );
581 bool isOnSurface( const SMDS_MeshNode* theNode ) const;
585 TColStd_MapOfInteger myIds;
586 SMDSAbs_ElementType myType;
587 Handle(Geom_Surface) mySurf;
591 typedef boost::shared_ptr<ElementsOnSurface> ElementsOnSurfacePtr;
601 virtual void SetPredicate(PredicatePtr thePred);
602 typedef std::vector<long> TIdSequence;
603 virtual TIdSequence GetElementsId( SMDS_Mesh* theMesh );
606 PredicatePtr myPredicate;