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_CONTROLS_HXX_
21 #define _SMESH_CONTROLS_HXX_
26 #include <boost/shared_ptr.hpp>
27 #include "SMDSAbs_ElementType.hxx"
28 #include "SMDS_MeshNode.hxx"
29 #include <Geom_Surface.hxx>
30 #include <TColStd_SequenceOfInteger.hxx>
31 #include <TColStd_MapOfInteger.hxx>
32 #include <TCollection_AsciiString.hxx>
36 class SMESHDS_SubMesh;
39 class TColgp_SequenceOfXYZ;
41 class SMDS_MeshElement;
51 virtual void SetMesh( SMDS_Mesh* theMesh ) = 0;
52 virtual SMDSAbs_ElementType GetType() const = 0;
54 typedef boost::shared_ptr<Functor> FunctorPtr;
56 class NumericalFunctor: public virtual Functor{
59 virtual void SetMesh( SMDS_Mesh* theMesh );
60 virtual double GetValue( long theElementId );
61 virtual double GetValue( const TColgp_SequenceOfXYZ& thePoints ) = 0;
62 virtual SMDSAbs_ElementType GetType() const = 0;
63 virtual double GetBadRate( double Value, int nbNodes ) const = 0;
64 long GetPrecision() const;
65 void SetPrecision( const long thePrecision );
67 bool GetPoints (const int theId,
68 TColgp_SequenceOfXYZ& theRes ) const;
69 static bool GetPoints (const SMDS_MeshElement* theElem,
70 TColgp_SequenceOfXYZ& theRes );
75 typedef boost::shared_ptr<NumericalFunctor> NumericalFunctorPtr;
79 Class : SMESH_MinimumAngle
80 Description : Functor for calculation of minimum angle
82 class MinimumAngle: public virtual NumericalFunctor{
84 virtual double GetValue( const TColgp_SequenceOfXYZ& thePoints );
85 virtual double GetBadRate( double Value, int nbNodes ) const;
86 virtual SMDSAbs_ElementType GetType() const;
92 Description : Functor for calculating aspect ratio
94 class AspectRatio: public virtual NumericalFunctor{
96 virtual double GetValue( const TColgp_SequenceOfXYZ& thePoints );
97 virtual double GetBadRate( double Value, int nbNodes ) const;
98 virtual SMDSAbs_ElementType GetType() const;
103 Class : AspectRatio3D
104 Description : Functor for calculating aspect ratio of 3D elems.
106 class AspectRatio3D: public virtual NumericalFunctor{
108 virtual double GetValue( const TColgp_SequenceOfXYZ& thePoints );
109 virtual double GetBadRate( double Value, int nbNodes ) const;
110 virtual SMDSAbs_ElementType GetType() const;
116 Description : Functor for calculating warping
118 class Warping: public virtual NumericalFunctor{
120 virtual double GetValue( const TColgp_SequenceOfXYZ& thePoints );
121 virtual double GetBadRate( double Value, int nbNodes ) const;
122 virtual SMDSAbs_ElementType GetType() const;
125 double ComputeA( const gp_XYZ&, const gp_XYZ&, const gp_XYZ&, const gp_XYZ& ) const;
131 Description : Functor for calculating taper
133 class Taper: public virtual NumericalFunctor{
135 virtual double GetValue( const TColgp_SequenceOfXYZ& thePoints );
136 virtual double GetBadRate( double Value, int nbNodes ) const;
137 virtual SMDSAbs_ElementType GetType() const;
143 Description : Functor for calculating skew in degrees
145 class Skew: public virtual NumericalFunctor{
147 virtual double GetValue( const TColgp_SequenceOfXYZ& thePoints );
148 virtual double GetBadRate( double Value, int nbNodes ) const;
149 virtual SMDSAbs_ElementType GetType() const;
155 Description : Functor for calculating area
157 class Area: public virtual NumericalFunctor{
159 virtual double GetValue( const TColgp_SequenceOfXYZ& thePoints );
160 virtual double GetBadRate( double Value, int nbNodes ) const;
161 virtual SMDSAbs_ElementType GetType() const;
167 Description : Functor for calculating length of edge
169 class Length: public virtual NumericalFunctor{
171 virtual double GetValue( const TColgp_SequenceOfXYZ& thePoints );
172 virtual double GetBadRate( double Value, int nbNodes ) const;
173 virtual SMDSAbs_ElementType GetType() const;
178 Class : MultiConnection
179 Description : Functor for calculating number of faces conneted to the edge
181 class MultiConnection: public virtual NumericalFunctor{
183 virtual double GetValue( long theElementId );
184 virtual double GetValue( const TColgp_SequenceOfXYZ& thePoints );
185 virtual double GetBadRate( double Value, int nbNodes ) const;
186 virtual SMDSAbs_ElementType GetType() const;
195 Description : Base class for all predicates
197 class Predicate: public virtual Functor{
199 virtual bool IsSatisfy( long theElementId ) = 0;
200 virtual SMDSAbs_ElementType GetType() const = 0;
202 typedef boost::shared_ptr<Predicate> PredicatePtr;
208 Description : Predicate for free borders
210 class FreeBorders: public virtual Predicate{
213 virtual void SetMesh( SMDS_Mesh* theMesh );
214 virtual bool IsSatisfy( long theElementId );
215 virtual SMDSAbs_ElementType GetType() const;
224 Description : Predicate for free Edges
226 class FreeEdges: public virtual Predicate{
229 virtual void SetMesh( SMDS_Mesh* theMesh );
230 virtual bool IsSatisfy( long theElementId );
231 virtual SMDSAbs_ElementType GetType() const;
232 static bool IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId );
233 typedef long TElemId;
237 Border(long theElemId, long thePntId1, long thePntId2);
238 bool operator<(const Border& x) const;
240 typedef std::set<Border> TBorders;
241 void GetBoreders(TBorders& theBorders);
246 typedef boost::shared_ptr<FreeEdges> FreeEdgesPtr;
251 Description : Predicate for Range of Ids.
252 Range may be specified with two ways.
253 1. Using AddToRange method
254 2. With SetRangeStr method. Parameter of this method is a string
255 like as "1,2,3,50-60,63,67,70-"
257 class RangeOfIds: public virtual Predicate
261 virtual void SetMesh( SMDS_Mesh* theMesh );
262 virtual bool IsSatisfy( long theNodeId );
263 virtual SMDSAbs_ElementType GetType() const;
264 virtual void SetType( SMDSAbs_ElementType theType );
266 bool AddToRange( long theEntityId );
267 void GetRangeStr( TCollection_AsciiString& );
268 bool SetRangeStr( const TCollection_AsciiString& );
273 TColStd_SequenceOfInteger myMin;
274 TColStd_SequenceOfInteger myMax;
275 TColStd_MapOfInteger myIds;
277 SMDSAbs_ElementType myType;
280 typedef boost::shared_ptr<RangeOfIds> RangeOfIdsPtr;
285 Description : Base class for comparators
287 class Comparator: public virtual Predicate{
290 virtual ~Comparator();
291 virtual void SetMesh( SMDS_Mesh* theMesh );
292 virtual void SetMargin(double theValue);
293 virtual void SetNumFunctor(NumericalFunctorPtr theFunct);
294 virtual bool IsSatisfy( long theElementId ) = 0;
295 virtual SMDSAbs_ElementType GetType() const;
300 NumericalFunctorPtr myFunctor;
302 typedef boost::shared_ptr<Comparator> ComparatorPtr;
307 Description : Comparator "<"
309 class LessThan: public virtual Comparator{
311 virtual bool IsSatisfy( long theElementId );
317 Description : Comparator ">"
319 class MoreThan: public virtual Comparator{
321 virtual bool IsSatisfy( long theElementId );
327 Description : Comparator "="
329 class EqualTo: public virtual Comparator{
332 virtual bool IsSatisfy( long theElementId );
333 virtual void SetTolerance( double theTol );
334 virtual double GetTolerance();
339 typedef boost::shared_ptr<EqualTo> EqualToPtr;
344 Description : Logical NOT predicate
346 class LogicalNOT: public virtual Predicate{
349 virtual ~LogicalNOT();
350 virtual bool IsSatisfy( long theElementId );
351 virtual void SetMesh( SMDS_Mesh* theMesh );
352 virtual void SetPredicate(PredicatePtr thePred);
353 virtual SMDSAbs_ElementType GetType() const;
356 PredicatePtr myPredicate;
358 typedef boost::shared_ptr<LogicalNOT> LogicalNOTPtr;
362 Class : LogicalBinary
363 Description : Base class for binary logical predicate
365 class LogicalBinary: public virtual Predicate{
368 virtual ~LogicalBinary();
369 virtual void SetMesh( SMDS_Mesh* theMesh );
370 virtual void SetPredicate1(PredicatePtr thePred);
371 virtual void SetPredicate2(PredicatePtr thePred);
372 virtual SMDSAbs_ElementType GetType() const;
375 PredicatePtr myPredicate1;
376 PredicatePtr myPredicate2;
378 typedef boost::shared_ptr<LogicalBinary> LogicalBinaryPtr;
383 Description : Logical AND
385 class LogicalAND: public virtual LogicalBinary{
387 virtual bool IsSatisfy( long theElementId );
393 Description : Logical OR
395 class LogicalOR: public virtual LogicalBinary{
397 virtual bool IsSatisfy( long theElementId );
403 Description : Predicate for manifold part of mesh
405 class ManifoldPart: public virtual Predicate{
408 /* internal class for algorithm uses */
412 Link( SMDS_MeshNode* theNode1,
413 SMDS_MeshNode* theNode2 );
416 bool IsEqual( const ManifoldPart::Link& theLink ) const;
417 bool operator<(const ManifoldPart::Link& x) const;
419 SMDS_MeshNode* myNode1;
420 SMDS_MeshNode* myNode2;
423 bool IsEqual( const ManifoldPart::Link& theLink1,
424 const ManifoldPart::Link& theLink2 );
426 typedef std::set<ManifoldPart::Link> TMapOfLink;
427 typedef std::vector<SMDS_MeshFace*> TVectorOfFacePtr;
428 typedef std::vector<ManifoldPart::Link> TVectorOfLink;
429 typedef std::map<SMDS_MeshFace*,int> TDataMapFacePtrInt;
430 typedef std::map<ManifoldPart::Link,SMDS_MeshFace*> TDataMapOfLinkFacePtr;
434 virtual void SetMesh( SMDS_Mesh* theMesh );
435 // inoke when all parameters already set
436 virtual bool IsSatisfy( long theElementId );
437 virtual SMDSAbs_ElementType GetType() const;
439 void SetAngleTolerance( const double theAngToler );
440 double GetAngleTolerance() const;
441 void SetIsOnlyManifold( const bool theIsOnly );
442 void SetStartElem( const long theStartElemId );
446 bool findConnected( const TDataMapFacePtrInt& theAllFacePtrInt,
447 SMDS_MeshFace* theStartFace,
448 TMapOfLink& theNonManifold,
449 TColStd_MapOfInteger& theResFaces );
450 bool isInPlane( const SMDS_MeshFace* theFace1,
451 const SMDS_MeshFace* theFace2 );
452 void expandBoundary( TMapOfLink& theMapOfBoundary,
453 TVectorOfLink& theSeqOfBoundary,
454 TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
455 TMapOfLink& theNonManifold,
456 SMDS_MeshFace* theNextFace ) const;
458 void getFacesByLink( const Link& theLink,
459 TVectorOfFacePtr& theFaces ) const;
463 TColStd_MapOfInteger myMapIds;
464 TColStd_MapOfInteger myMapBadGeomIds;
465 TVectorOfFacePtr myAllFacePtr;
466 TDataMapFacePtrInt myAllFacePtrIntDMap;
468 bool myIsOnlyManifold;
472 typedef boost::shared_ptr<ManifoldPart> ManifoldPartPtr;
476 Class : ElementsOnSurface
477 Description : Predicate elements that lying on indicated surface
480 class ElementsOnSurface : public virtual Predicate {
483 ~ElementsOnSurface();
484 virtual void SetMesh( SMDS_Mesh* theMesh );
485 virtual bool IsSatisfy( long theElementId );
486 virtual SMDSAbs_ElementType GetType() const;
488 void SetTolerance( const double theToler );
489 double GetTolerance() const;
490 void SetSurface( const TopoDS_Shape& theShape,
491 const SMDSAbs_ElementType theType );
495 void process( const SMDS_MeshElement* theElem );
496 bool isOnSurface( const SMDS_MeshNode* theNode ) const;
500 TColStd_MapOfInteger myIds;
501 SMDSAbs_ElementType myType;
502 Handle(Geom_Surface) mySurf;
506 typedef boost::shared_ptr<ElementsOnSurface> ElementsOnSurfacePtr;
516 virtual void SetPredicate(PredicatePtr thePred);
517 typedef std::vector<long> TIdSequence;
518 virtual TIdSequence GetElementsId( SMDS_Mesh* theMesh );
521 PredicatePtr myPredicate;