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 #include "SMESH_ControlsDef.hxx"
24 #include <BRep_Tool.hxx>
26 #include <gp_Cylinder.hxx>
32 #include <Geom_Plane.hxx>
33 #include <Geom_CylindricalSurface.hxx>
34 #include <Precision.hxx>
35 #include <TColgp_Array1OfXYZ.hxx>
36 #include <TColStd_MapOfInteger.hxx>
37 #include <TColStd_SequenceOfAsciiString.hxx>
38 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
41 #include <TopoDS_Face.hxx>
42 #include <TopoDS_Shape.hxx>
44 #include "SMDS_Mesh.hxx"
45 #include "SMDS_Iterator.hxx"
46 #include "SMDS_MeshElement.hxx"
47 #include "SMDS_MeshNode.hxx"
48 #include "SMDS_VolumeTool.hxx"
56 inline double getAngle( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
58 gp_Vec v1( P1 - P2 ), v2( P3 - P2 );
60 return v1.Magnitude() < gp::Resolution() ||
61 v2.Magnitude() < gp::Resolution() ? 0 : v1.Angle( v2 );
64 inline double getArea( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
66 gp_Vec aVec1( P2 - P1 );
67 gp_Vec aVec2( P3 - P1 );
68 return ( aVec1 ^ aVec2 ).Magnitude() * 0.5;
71 inline double getArea( const gp_Pnt& P1, const gp_Pnt& P2, const gp_Pnt& P3 )
73 return getArea( P1.XYZ(), P2.XYZ(), P3.XYZ() );
78 inline double getDistance( const gp_XYZ& P1, const gp_XYZ& P2 )
80 double aDist = gp_Pnt( P1 ).Distance( gp_Pnt( P2 ) );
84 int getNbMultiConnection( SMDS_Mesh* theMesh, const int theId )
89 const SMDS_MeshElement* anEdge = theMesh->FindElement( theId );
90 if ( anEdge == 0 || anEdge->GetType() != SMDSAbs_Edge || anEdge->NbNodes() != 2 )
93 TColStd_MapOfInteger aMap;
96 SMDS_ElemIteratorPtr anIter = anEdge->nodesIterator();
98 while( anIter->more() ) {
99 const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next();
102 SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator();
103 while( anElemIter->more() ) {
104 const SMDS_MeshElement* anElem = anElemIter->next();
105 if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) {
106 int anId = anElem->GetID();
108 if ( anIter->more() ) // i.e. first node
110 else if ( aMap.Contains( anId ) )
124 using namespace SMESH::Controls;
131 Class : NumericalFunctor
132 Description : Base class for numerical functors
134 NumericalFunctor::NumericalFunctor():
140 void NumericalFunctor::SetMesh( SMDS_Mesh* theMesh )
145 bool NumericalFunctor::GetPoints(const int theId,
146 TSequenceOfXYZ& theRes ) const
153 return GetPoints( myMesh->FindElement( theId ), theRes );
156 bool NumericalFunctor::GetPoints(const SMDS_MeshElement* anElem,
157 TSequenceOfXYZ& theRes )
164 // Get nodes of the element
165 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
168 while( anIter->more() )
170 const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next();
172 theRes.push_back( gp_XYZ( aNode->X(), aNode->Y(), aNode->Z() ) );
180 long NumericalFunctor::GetPrecision() const
185 void NumericalFunctor::SetPrecision( const long thePrecision )
187 myPrecision = thePrecision;
190 double NumericalFunctor::GetValue( long theId )
193 if ( GetPoints( theId, P ))
195 double aVal = GetValue( P );
196 if ( myPrecision >= 0 )
198 double prec = pow( 10., (double)( myPrecision ) );
199 aVal = floor( aVal * prec + 0.5 ) / prec;
209 Description : Functor for calculation of minimum angle
212 double MinimumAngle::GetValue( const TSequenceOfXYZ& P )
218 double A0 = getAngle( P( 3 ), P( 1 ), P( 2 ) );
219 double A1 = getAngle( P( 1 ), P( 2 ), P( 3 ) );
220 double A2 = getAngle( P( 2 ), P( 3 ), P( 1 ) );
222 aMin = Min( A0, Min( A1, A2 ) );
224 else if ( P.size() == 4 )
226 double A0 = getAngle( P( 4 ), P( 1 ), P( 2 ) );
227 double A1 = getAngle( P( 1 ), P( 2 ), P( 3 ) );
228 double A2 = getAngle( P( 2 ), P( 3 ), P( 4 ) );
229 double A3 = getAngle( P( 3 ), P( 4 ), P( 1 ) );
231 aMin = Min( Min( A0, A1 ), Min( A2, A3 ) );
236 return aMin * 180 / PI;
239 double MinimumAngle::GetBadRate( double Value, int nbNodes ) const
241 const double aBestAngle = PI / nbNodes;
242 return ( fabs( aBestAngle - Value ));
245 SMDSAbs_ElementType MinimumAngle::GetType() const
253 Description : Functor for calculating aspect ratio
255 double AspectRatio::GetValue( const TSequenceOfXYZ& P )
257 // According to "Mesh quality control" by Nadir Bouhamau referring to
258 // Pascal Jean Frey and Paul-Louis George. Maillages, applications aux elements finis.
259 // Hermes Science publications, Paris 1999 ISBN 2-7462-0024-4
262 int nbNodes = P.size();
267 // Compute lengths of the sides
269 vector< double > aLen (nbNodes);
271 for ( int i = 0; i < nbNodes - 1; i++ )
272 aLen[ i ] = getDistance( P( i + 1 ), P( i + 2 ) );
273 aLen[ nbNodes - 1 ] = getDistance( P( 1 ), P( nbNodes ) );
275 // Compute aspect ratio
279 // Q = alfa * h * p / S, where
281 // alfa = sqrt( 3 ) / 6
282 // h - length of the longest edge
283 // p - half perimeter
284 // S - triangle surface
286 const double alfa = sqrt( 3. ) / 6.;
287 double maxLen = Max( aLen[ 0 ], Max( aLen[ 1 ], aLen[ 2 ] ) );
288 double half_perimeter = ( aLen[0] + aLen[1] + aLen[2] ) / 2.;
289 double anArea = getArea( P( 1 ), P( 2 ), P( 3 ) );
290 if ( anArea <= Precision::Confusion() )
293 return alfa * maxLen * half_perimeter / anArea;
297 // return aspect ratio of the worst triange which can be built
298 // taking three nodes of the quadrangle
299 TSequenceOfXYZ triaPnts(3);
300 // triangle on nodes 1 3 2
304 double ar = GetValue( triaPnts );
305 // triangle on nodes 1 3 4
307 ar = Max ( ar, GetValue( triaPnts ));
308 // triangle on nodes 1 2 4
310 ar = Max ( ar, GetValue( triaPnts ));
311 // triangle on nodes 3 2 4
313 ar = Max ( ar, GetValue( triaPnts ));
319 double AspectRatio::GetBadRate( double Value, int /*nbNodes*/ ) const
321 // the aspect ratio is in the range [1.0,infinity]
324 return Value / 1000.;
327 SMDSAbs_ElementType AspectRatio::GetType() const
334 Class : AspectRatio3D
335 Description : Functor for calculating aspect ratio
339 inline double getHalfPerimeter(double theTria[3]){
340 return (theTria[0] + theTria[1] + theTria[2])/2.0;
343 inline double getArea(double theHalfPerim, double theTria[3]){
344 return sqrt(theHalfPerim*
345 (theHalfPerim-theTria[0])*
346 (theHalfPerim-theTria[1])*
347 (theHalfPerim-theTria[2]));
350 inline double getVolume(double theLen[6]){
351 double a2 = theLen[0]*theLen[0];
352 double b2 = theLen[1]*theLen[1];
353 double c2 = theLen[2]*theLen[2];
354 double d2 = theLen[3]*theLen[3];
355 double e2 = theLen[4]*theLen[4];
356 double f2 = theLen[5]*theLen[5];
357 double P = 4.0*a2*b2*d2;
358 double Q = a2*(b2+d2-e2)-b2*(a2+d2-f2)-d2*(a2+b2-c2);
359 double R = (b2+d2-e2)*(a2+d2-f2)*(a2+d2-f2);
360 return sqrt(P-Q+R)/12.0;
363 inline double getVolume2(double theLen[6]){
364 double a2 = theLen[0]*theLen[0];
365 double b2 = theLen[1]*theLen[1];
366 double c2 = theLen[2]*theLen[2];
367 double d2 = theLen[3]*theLen[3];
368 double e2 = theLen[4]*theLen[4];
369 double f2 = theLen[5]*theLen[5];
371 double P = a2*e2*(b2+c2+d2+f2-a2-e2);
372 double Q = b2*f2*(a2+c2+d2+e2-b2-f2);
373 double R = c2*d2*(a2+b2+e2+f2-c2-d2);
374 double S = a2*b2*d2+b2*c2*e2+a2*c2*f2+d2*e2*f2;
376 return sqrt(P+Q+R-S)/12.0;
379 inline double getVolume(const TSequenceOfXYZ& P){
380 gp_Vec aVec1( P( 2 ) - P( 1 ) );
381 gp_Vec aVec2( P( 3 ) - P( 1 ) );
382 gp_Vec aVec3( P( 4 ) - P( 1 ) );
383 gp_Vec anAreaVec( aVec1 ^ aVec2 );
384 return Abs(aVec3 * anAreaVec) / 6.0;
387 inline double getMaxHeight(double theLen[6])
389 double aHeight = max(theLen[0],theLen[1]);
390 aHeight = max(aHeight,theLen[2]);
391 aHeight = max(aHeight,theLen[3]);
392 aHeight = max(aHeight,theLen[4]);
393 aHeight = max(aHeight,theLen[5]);
399 double AspectRatio3D::GetValue( const TSequenceOfXYZ& P )
401 double aQuality = 0.0;
402 int nbNodes = P.size();
406 getDistance(P( 1 ),P( 2 )), // a
407 getDistance(P( 2 ),P( 3 )), // b
408 getDistance(P( 3 ),P( 1 )), // c
409 getDistance(P( 2 ),P( 4 )), // d
410 getDistance(P( 3 ),P( 4 )), // e
411 getDistance(P( 1 ),P( 4 )) // f
413 double aTria[4][3] = {
414 {aLen[0],aLen[1],aLen[2]}, // abc
415 {aLen[0],aLen[3],aLen[5]}, // adf
416 {aLen[1],aLen[3],aLen[4]}, // bde
417 {aLen[2],aLen[4],aLen[5]} // cef
419 double aSumArea = 0.0;
420 double aHalfPerimeter = getHalfPerimeter(aTria[0]);
421 double anArea = getArea(aHalfPerimeter,aTria[0]);
423 aHalfPerimeter = getHalfPerimeter(aTria[1]);
424 anArea = getArea(aHalfPerimeter,aTria[1]);
426 aHalfPerimeter = getHalfPerimeter(aTria[2]);
427 anArea = getArea(aHalfPerimeter,aTria[2]);
429 aHalfPerimeter = getHalfPerimeter(aTria[3]);
430 anArea = getArea(aHalfPerimeter,aTria[3]);
432 double aVolume = getVolume(P);
433 //double aVolume = getVolume(aLen);
434 double aHeight = getMaxHeight(aLen);
435 static double aCoeff = sqrt(6.0)/36.0;
436 aQuality = aCoeff*aHeight*aSumArea/aVolume;
441 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 3 ),P( 5 )};
442 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
445 gp_XYZ aXYZ[4] = {P( 1 ),P( 3 ),P( 4 ),P( 5 )};
446 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
449 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 5 )};
450 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
453 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 4 ),P( 5 )};
454 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
460 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 6 )};
461 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
464 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 3 )};
465 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
468 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 6 )};
469 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
472 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
473 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
476 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 6 )};
477 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
480 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 3 )};
481 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
487 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
488 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
491 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 4 )};
492 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
495 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 7 )};
496 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
499 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 8 )};
500 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
503 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 3 )};
504 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
507 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 4 )};
508 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
511 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 7 )};
512 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
515 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 8 )};
516 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
519 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 3 )};
520 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
523 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 4 )};
524 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
527 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 7 )};
528 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
531 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 8 )};
532 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
535 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 1 )};
536 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
539 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 2 )};
540 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
543 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 5 )};
544 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
547 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 6 )};
548 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
551 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 1 )};
552 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
555 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 2 )};
556 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
559 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 5 )};
560 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
563 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 6 )};
564 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
567 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 1 )};
568 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
571 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
572 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
575 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 5 )};
576 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
579 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 6 )};
580 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
583 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
584 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
587 gp_XYZ aXYZ[4] = {P( 4 ),P( 5 ),P( 8 ),P( 2 )};
588 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
591 gp_XYZ aXYZ[4] = {P( 1 ),P( 4 ),P( 5 ),P( 3 )};
592 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
595 gp_XYZ aXYZ[4] = {P( 3 ),P( 6 ),P( 7 ),P( 1 )};
596 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
599 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 6 ),P( 4 )};
600 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
603 gp_XYZ aXYZ[4] = {P( 5 ),P( 6 ),P( 8 ),P( 3 )};
604 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
607 gp_XYZ aXYZ[4] = {P( 7 ),P( 8 ),P( 6 ),P( 1 )};
608 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
611 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 7 )};
612 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
615 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 2 ),P( 5 )};
616 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
624 double AspectRatio3D::GetBadRate( double Value, int /*nbNodes*/ ) const
626 // the aspect ratio is in the range [1.0,infinity]
629 return Value / 1000.;
632 SMDSAbs_ElementType AspectRatio3D::GetType() const
634 return SMDSAbs_Volume;
640 Description : Functor for calculating warping
642 double Warping::GetValue( const TSequenceOfXYZ& P )
647 gp_XYZ G = ( P( 1 ) + P( 2 ) + P( 3 ) + P( 4 ) ) / 4;
649 double A1 = ComputeA( P( 1 ), P( 2 ), P( 3 ), G );
650 double A2 = ComputeA( P( 2 ), P( 3 ), P( 4 ), G );
651 double A3 = ComputeA( P( 3 ), P( 4 ), P( 1 ), G );
652 double A4 = ComputeA( P( 4 ), P( 1 ), P( 2 ), G );
654 return Max( Max( A1, A2 ), Max( A3, A4 ) );
657 double Warping::ComputeA( const gp_XYZ& thePnt1,
658 const gp_XYZ& thePnt2,
659 const gp_XYZ& thePnt3,
660 const gp_XYZ& theG ) const
662 double aLen1 = gp_Pnt( thePnt1 ).Distance( gp_Pnt( thePnt2 ) );
663 double aLen2 = gp_Pnt( thePnt2 ).Distance( gp_Pnt( thePnt3 ) );
664 double L = Min( aLen1, aLen2 ) * 0.5;
665 if ( L < Precision::Confusion())
668 gp_XYZ GI = ( thePnt2 + thePnt1 ) / 2. - theG;
669 gp_XYZ GJ = ( thePnt3 + thePnt2 ) / 2. - theG;
670 gp_XYZ N = GI.Crossed( GJ );
672 if ( N.Modulus() < gp::Resolution() )
677 double H = ( thePnt2 - theG ).Dot( N );
678 return asin( fabs( H / L ) ) * 180 / PI;
681 double Warping::GetBadRate( double Value, int /*nbNodes*/ ) const
683 // the warp is in the range [0.0,PI/2]
684 // 0.0 = good (no warp)
685 // PI/2 = bad (face pliee)
689 SMDSAbs_ElementType Warping::GetType() const
697 Description : Functor for calculating taper
699 double Taper::GetValue( const TSequenceOfXYZ& P )
705 double J1 = getArea( P( 4 ), P( 1 ), P( 2 ) ) / 2;
706 double J2 = getArea( P( 3 ), P( 1 ), P( 2 ) ) / 2;
707 double J3 = getArea( P( 2 ), P( 3 ), P( 4 ) ) / 2;
708 double J4 = getArea( P( 3 ), P( 4 ), P( 1 ) ) / 2;
710 double JA = 0.25 * ( J1 + J2 + J3 + J4 );
711 if ( JA <= Precision::Confusion() )
714 double T1 = fabs( ( J1 - JA ) / JA );
715 double T2 = fabs( ( J2 - JA ) / JA );
716 double T3 = fabs( ( J3 - JA ) / JA );
717 double T4 = fabs( ( J4 - JA ) / JA );
719 return Max( Max( T1, T2 ), Max( T3, T4 ) );
722 double Taper::GetBadRate( double Value, int /*nbNodes*/ ) const
724 // the taper is in the range [0.0,1.0]
725 // 0.0 = good (no taper)
726 // 1.0 = bad (les cotes opposes sont allignes)
730 SMDSAbs_ElementType Taper::GetType() const
738 Description : Functor for calculating skew in degrees
740 static inline double skewAngle( const gp_XYZ& p1, const gp_XYZ& p2, const gp_XYZ& p3 )
742 gp_XYZ p12 = ( p2 + p1 ) / 2;
743 gp_XYZ p23 = ( p3 + p2 ) / 2;
744 gp_XYZ p31 = ( p3 + p1 ) / 2;
746 gp_Vec v1( p31 - p2 ), v2( p12 - p23 );
748 return v1.Magnitude() < gp::Resolution() || v2.Magnitude() < gp::Resolution() ? 0 : v1.Angle( v2 );
751 double Skew::GetValue( const TSequenceOfXYZ& P )
753 if ( P.size() != 3 && P.size() != 4 )
757 static double PI2 = PI / 2;
760 double A0 = fabs( PI2 - skewAngle( P( 3 ), P( 1 ), P( 2 ) ) );
761 double A1 = fabs( PI2 - skewAngle( P( 1 ), P( 2 ), P( 3 ) ) );
762 double A2 = fabs( PI2 - skewAngle( P( 2 ), P( 3 ), P( 1 ) ) );
764 return Max( A0, Max( A1, A2 ) ) * 180 / PI;
768 gp_XYZ p12 = ( P( 1 ) + P( 2 ) ) / 2;
769 gp_XYZ p23 = ( P( 2 ) + P( 3 ) ) / 2;
770 gp_XYZ p34 = ( P( 3 ) + P( 4 ) ) / 2;
771 gp_XYZ p41 = ( P( 4 ) + P( 1 ) ) / 2;
773 gp_Vec v1( p34 - p12 ), v2( p23 - p41 );
774 double A = v1.Magnitude() <= gp::Resolution() || v2.Magnitude() <= gp::Resolution()
775 ? 0 : fabs( PI2 - v1.Angle( v2 ) );
781 double Skew::GetBadRate( double Value, int /*nbNodes*/ ) const
783 // the skew is in the range [0.0,PI/2].
789 SMDSAbs_ElementType Skew::GetType() const
797 Description : Functor for calculating area
799 double Area::GetValue( const TSequenceOfXYZ& P )
802 return getArea( P( 1 ), P( 2 ), P( 3 ) );
803 else if ( P.size() == 4 )
804 return getArea( P( 1 ), P( 2 ), P( 3 ) ) + getArea( P( 1 ), P( 3 ), P( 4 ) );
809 double Area::GetBadRate( double Value, int /*nbNodes*/ ) const
814 SMDSAbs_ElementType Area::GetType() const
822 Description : Functor for calculating length off edge
824 double Length::GetValue( const TSequenceOfXYZ& P )
826 return ( P.size() == 2 ? getDistance( P( 1 ), P( 2 ) ) : 0 );
829 double Length::GetBadRate( double Value, int /*nbNodes*/ ) const
834 SMDSAbs_ElementType Length::GetType() const
841 Description : Functor for calculating length of edge
844 double Length2D::GetValue( long theElementId)
848 if (GetPoints(theElementId,P)){
850 double aVal;// = GetValue( P );
851 const SMDS_MeshElement* aElem = myMesh->FindElement( theElementId );
852 SMDSAbs_ElementType aType = aElem->GetType();
861 aVal = getDistance( P( 1 ), P( 2 ) );
865 if (len == 3){ // triangles
866 double L1 = getDistance(P( 1 ),P( 2 ));
867 double L2 = getDistance(P( 2 ),P( 3 ));
868 double L3 = getDistance(P( 3 ),P( 1 ));
869 aVal = Max(L1,Max(L2,L3));
872 else if (len == 4){ // quadrangles
873 double L1 = getDistance(P( 1 ),P( 2 ));
874 double L2 = getDistance(P( 2 ),P( 3 ));
875 double L3 = getDistance(P( 3 ),P( 4 ));
876 double L4 = getDistance(P( 4 ),P( 1 ));
877 aVal = Max(Max(L1,L2),Max(L3,L4));
881 if (len == 4){ // tetraidrs
882 double L1 = getDistance(P( 1 ),P( 2 ));
883 double L2 = getDistance(P( 2 ),P( 3 ));
884 double L3 = getDistance(P( 3 ),P( 1 ));
885 double L4 = getDistance(P( 1 ),P( 4 ));
886 double L5 = getDistance(P( 2 ),P( 4 ));
887 double L6 = getDistance(P( 3 ),P( 4 ));
888 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
891 else if (len == 5){ // piramids
892 double L1 = getDistance(P( 1 ),P( 2 ));
893 double L2 = getDistance(P( 2 ),P( 3 ));
894 double L3 = getDistance(P( 3 ),P( 1 ));
895 double L4 = getDistance(P( 4 ),P( 1 ));
896 double L5 = getDistance(P( 1 ),P( 5 ));
897 double L6 = getDistance(P( 2 ),P( 5 ));
898 double L7 = getDistance(P( 3 ),P( 5 ));
899 double L8 = getDistance(P( 4 ),P( 5 ));
901 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
902 aVal = Max(aVal,Max(L7,L8));
905 else if (len == 6){ // pentaidres
906 double L1 = getDistance(P( 1 ),P( 2 ));
907 double L2 = getDistance(P( 2 ),P( 3 ));
908 double L3 = getDistance(P( 3 ),P( 1 ));
909 double L4 = getDistance(P( 4 ),P( 5 ));
910 double L5 = getDistance(P( 5 ),P( 6 ));
911 double L6 = getDistance(P( 6 ),P( 4 ));
912 double L7 = getDistance(P( 1 ),P( 4 ));
913 double L8 = getDistance(P( 2 ),P( 5 ));
914 double L9 = getDistance(P( 3 ),P( 6 ));
916 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
917 aVal = Max(aVal,Max(Max(L7,L8),L9));
920 else if (len == 8){ // hexaider
921 double L1 = getDistance(P( 1 ),P( 2 ));
922 double L2 = getDistance(P( 2 ),P( 3 ));
923 double L3 = getDistance(P( 3 ),P( 4 ));
924 double L4 = getDistance(P( 4 ),P( 1 ));
925 double L5 = getDistance(P( 5 ),P( 6 ));
926 double L6 = getDistance(P( 6 ),P( 7 ));
927 double L7 = getDistance(P( 7 ),P( 8 ));
928 double L8 = getDistance(P( 8 ),P( 5 ));
929 double L9 = getDistance(P( 1 ),P( 5 ));
930 double L10= getDistance(P( 2 ),P( 6 ));
931 double L11= getDistance(P( 3 ),P( 7 ));
932 double L12= getDistance(P( 4 ),P( 8 ));
934 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
935 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
936 aVal = Max(aVal,Max(L11,L12));
948 if ( myPrecision >= 0 )
950 double prec = pow( 10., (double)( myPrecision ) );
951 aVal = floor( aVal * prec + 0.5 ) / prec;
960 double Length2D::GetBadRate( double Value, int /*nbNodes*/ ) const
965 SMDSAbs_ElementType Length2D::GetType() const
970 Length2D::Value::Value(double theLength,long thePntId1, long thePntId2):
973 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
974 if(thePntId1 > thePntId2){
975 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
979 bool Length2D::Value::operator<(const Length2D::Value& x) const{
980 if(myPntId[0] < x.myPntId[0]) return true;
981 if(myPntId[0] == x.myPntId[0])
982 if(myPntId[1] < x.myPntId[1]) return true;
986 void Length2D::GetValues(TValues& theValues){
988 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
989 for(; anIter->more(); ){
990 const SMDS_MeshFace* anElem = anIter->next();
991 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
996 const SMDS_MeshElement* aNode;
997 if(aNodesIter->more()){
998 aNode = aNodesIter->next();
999 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1000 P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1001 aNodeId[0] = aNodeId[1] = aNode->GetID();
1004 for(; aNodesIter->more(); ){
1005 aNode = aNodesIter->next();
1006 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1007 long anId = aNode->GetID();
1009 P[2] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1011 aLength = P[1].Distance(P[2]);
1013 Value aValue(aLength,aNodeId[1],anId);
1016 theValues.insert(aValue);
1019 aLength = P[0].Distance(P[1]);
1021 Value aValue(aLength,aNodeId[0],aNodeId[1]);
1022 theValues.insert(aValue);
1027 Class : MultiConnection
1028 Description : Functor for calculating number of faces conneted to the edge
1030 double MultiConnection::GetValue( const TSequenceOfXYZ& P )
1034 double MultiConnection::GetValue( long theId )
1036 return getNbMultiConnection( myMesh, theId );
1039 double MultiConnection::GetBadRate( double Value, int /*nbNodes*/ ) const
1044 SMDSAbs_ElementType MultiConnection::GetType() const
1046 return SMDSAbs_Edge;
1050 Class : MultiConnection2D
1051 Description : Functor for calculating number of faces conneted to the edge
1053 double MultiConnection2D::GetValue( const TSequenceOfXYZ& P )
1058 double MultiConnection2D::GetValue( long theElementId )
1063 if (GetPoints(theElementId,P)){
1065 const SMDS_MeshElement* anFaceElem = myMesh->FindElement( theElementId );
1066 SMDSAbs_ElementType aType = anFaceElem->GetType();
1070 TColStd_MapOfInteger aMap;
1078 if (len == 3){ // triangles
1079 int Nb[3] = {0,0,0};
1082 SMDS_ElemIteratorPtr anIter = anFaceElem->nodesIterator();
1083 if ( anIter != 0 ) {
1084 while( anIter->more() ) {
1085 const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next();
1089 SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator();
1090 while( anElemIter->more() ) {
1091 const SMDS_MeshElement* anElem = anElemIter->next();
1092 if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) {
1093 int anId = anElem->GetID();
1095 if ( anIter->more() ) // i.e. first node
1097 else if ( aMap.Contains( anId ) ){
1101 else if ( anElem != 0 && anElem->GetType() == SMDSAbs_Edge ) i++;
1106 aResult = Max(Max(Nb[0],Nb[1]),Nb[2]);
1109 case SMDSAbs_Volume:
1114 return aResult;//getNbMultiConnection( myMesh, theId );
1117 double MultiConnection2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1122 SMDSAbs_ElementType MultiConnection2D::GetType() const
1124 return SMDSAbs_Face;
1127 MultiConnection2D::Value::Value(long thePntId1, long thePntId2)
1129 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1130 if(thePntId1 > thePntId2){
1131 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1135 bool MultiConnection2D::Value::operator<(const MultiConnection2D::Value& x) const{
1136 if(myPntId[0] < x.myPntId[0]) return true;
1137 if(myPntId[0] == x.myPntId[0])
1138 if(myPntId[1] < x.myPntId[1]) return true;
1142 void MultiConnection2D::GetValues(MValues& theValues){
1143 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1144 for(; anIter->more(); ){
1145 const SMDS_MeshFace* anElem = anIter->next();
1146 //long anElemId = anElem->GetID();
1147 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
1150 //int aNbConnects=0;
1151 const SMDS_MeshNode* aNode0;
1152 const SMDS_MeshNode* aNode1;
1153 const SMDS_MeshNode* aNode2;
1154 if(aNodesIter->more()){
1155 aNode0 = (SMDS_MeshNode*) aNodesIter->next();
1157 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode1;
1158 aNodeId[0] = aNodeId[1] = aNodes->GetID();
1160 for(; aNodesIter->more(); ){
1161 aNode2 = (SMDS_MeshNode*) aNodesIter->next();
1162 long anId = aNode2->GetID();
1165 Value aValue(aNodeId[1],aNodeId[2]);
1166 MValues::iterator aItr = theValues.find(aValue);
1167 if (aItr != theValues.end()){
1171 theValues[aValue] = 1;
1174 //cout << "NodeIds: "<<aNodeId[1]<<","<<aNodeId[2]<<" nbconn="<<aNbConnects<<endl;
1175 aNodeId[1] = aNodeId[2];
1178 Value aValue(aNodeId[0],aNodeId[2]);
1179 MValues::iterator aItr = theValues.find(aValue);
1180 if (aItr != theValues.end()){
1184 theValues[aValue] = 1;
1187 //cout << "NodeIds: "<<aNodeId[0]<<","<<aNodeId[2]<<" nbconn="<<aNbConnects<<endl;
1197 Class : BadOrientedVolume
1198 Description : Predicate bad oriented volumes
1201 BadOrientedVolume::BadOrientedVolume()
1206 void BadOrientedVolume::SetMesh( SMDS_Mesh* theMesh )
1211 bool BadOrientedVolume::IsSatisfy( long theId )
1216 SMDS_VolumeTool vTool( myMesh->FindElement( theId ));
1217 return !vTool.IsForward();
1220 SMDSAbs_ElementType BadOrientedVolume::GetType() const
1222 return SMDSAbs_Volume;
1229 Description : Predicate for free borders
1232 FreeBorders::FreeBorders()
1237 void FreeBorders::SetMesh( SMDS_Mesh* theMesh )
1242 bool FreeBorders::IsSatisfy( long theId )
1244 return getNbMultiConnection( myMesh, theId ) == 1;
1247 SMDSAbs_ElementType FreeBorders::GetType() const
1249 return SMDSAbs_Edge;
1255 Description : Predicate for free Edges
1257 FreeEdges::FreeEdges()
1262 void FreeEdges::SetMesh( SMDS_Mesh* theMesh )
1267 bool FreeEdges::IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId )
1269 TColStd_MapOfInteger aMap;
1270 for ( int i = 0; i < 2; i++ )
1272 SMDS_ElemIteratorPtr anElemIter = theNodes[ i ]->GetInverseElementIterator();
1273 while( anElemIter->more() )
1275 const SMDS_MeshElement* anElem = anElemIter->next();
1276 if ( anElem != 0 && anElem->GetType() == SMDSAbs_Face )
1278 int anId = anElem->GetID();
1282 else if ( aMap.Contains( anId ) && anId != theFaceId )
1290 bool FreeEdges::IsSatisfy( long theId )
1295 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
1296 if ( aFace == 0 || aFace->GetType() != SMDSAbs_Face || aFace->NbNodes() < 3 )
1299 int nbNodes = aFace->NbNodes();
1300 const SMDS_MeshNode* aNodes[ nbNodes ];
1302 SMDS_ElemIteratorPtr anIter = aFace->nodesIterator();
1305 while( anIter->more() )
1307 const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next();
1310 aNodes[ i++ ] = aNode;
1314 for ( int i = 0; i < nbNodes - 1; i++ )
1315 if ( IsFreeEdge( &aNodes[ i ], theId ) )
1318 aNodes[ 1 ] = aNodes[ nbNodes - 1 ];
1320 return IsFreeEdge( &aNodes[ 0 ], theId );
1324 SMDSAbs_ElementType FreeEdges::GetType() const
1326 return SMDSAbs_Face;
1329 FreeEdges::Border::Border(long theElemId, long thePntId1, long thePntId2):
1332 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1333 if(thePntId1 > thePntId2){
1334 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1338 bool FreeEdges::Border::operator<(const FreeEdges::Border& x) const{
1339 if(myPntId[0] < x.myPntId[0]) return true;
1340 if(myPntId[0] == x.myPntId[0])
1341 if(myPntId[1] < x.myPntId[1]) return true;
1345 inline void UpdateBorders(const FreeEdges::Border& theBorder,
1346 FreeEdges::TBorders& theRegistry,
1347 FreeEdges::TBorders& theContainer)
1349 if(theRegistry.find(theBorder) == theRegistry.end()){
1350 theRegistry.insert(theBorder);
1351 theContainer.insert(theBorder);
1353 theContainer.erase(theBorder);
1357 void FreeEdges::GetBoreders(TBorders& theBorders)
1360 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1361 for(; anIter->more(); ){
1362 const SMDS_MeshFace* anElem = anIter->next();
1363 long anElemId = anElem->GetID();
1364 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
1366 const SMDS_MeshElement* aNode;
1367 if(aNodesIter->more()){
1368 aNode = aNodesIter->next();
1369 aNodeId[0] = aNodeId[1] = aNode->GetID();
1371 for(; aNodesIter->more(); ){
1372 aNode = aNodesIter->next();
1373 long anId = aNode->GetID();
1374 Border aBorder(anElemId,aNodeId[1],anId);
1376 //std::cout<<aBorder.myPntId[0]<<"; "<<aBorder.myPntId[1]<<"; "<<aBorder.myElemId<<endl;
1377 UpdateBorders(aBorder,aRegistry,theBorders);
1379 Border aBorder(anElemId,aNodeId[0],aNodeId[1]);
1380 //std::cout<<aBorder.myPntId[0]<<"; "<<aBorder.myPntId[1]<<"; "<<aBorder.myElemId<<endl;
1381 UpdateBorders(aBorder,aRegistry,theBorders);
1383 //std::cout<<"theBorders.size() = "<<theBorders.size()<<endl;
1388 Description : Predicate for Range of Ids.
1389 Range may be specified with two ways.
1390 1. Using AddToRange method
1391 2. With SetRangeStr method. Parameter of this method is a string
1392 like as "1,2,3,50-60,63,67,70-"
1395 //=======================================================================
1396 // name : RangeOfIds
1397 // Purpose : Constructor
1398 //=======================================================================
1399 RangeOfIds::RangeOfIds()
1402 myType = SMDSAbs_All;
1405 //=======================================================================
1407 // Purpose : Set mesh
1408 //=======================================================================
1409 void RangeOfIds::SetMesh( SMDS_Mesh* theMesh )
1414 //=======================================================================
1415 // name : AddToRange
1416 // Purpose : Add ID to the range
1417 //=======================================================================
1418 bool RangeOfIds::AddToRange( long theEntityId )
1420 myIds.Add( theEntityId );
1424 //=======================================================================
1425 // name : GetRangeStr
1426 // Purpose : Get range as a string.
1427 // Example: "1,2,3,50-60,63,67,70-"
1428 //=======================================================================
1429 void RangeOfIds::GetRangeStr( TCollection_AsciiString& theResStr )
1433 TColStd_SequenceOfInteger anIntSeq;
1434 TColStd_SequenceOfAsciiString aStrSeq;
1436 TColStd_MapIteratorOfMapOfInteger anIter( myIds );
1437 for ( ; anIter.More(); anIter.Next() )
1439 int anId = anIter.Key();
1440 TCollection_AsciiString aStr( anId );
1441 anIntSeq.Append( anId );
1442 aStrSeq.Append( aStr );
1445 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
1447 int aMinId = myMin( i );
1448 int aMaxId = myMax( i );
1450 TCollection_AsciiString aStr;
1451 if ( aMinId != IntegerFirst() )
1456 if ( aMaxId != IntegerLast() )
1459 // find position of the string in result sequence and insert string in it
1460 if ( anIntSeq.Length() == 0 )
1462 anIntSeq.Append( aMinId );
1463 aStrSeq.Append( aStr );
1467 if ( aMinId < anIntSeq.First() )
1469 anIntSeq.Prepend( aMinId );
1470 aStrSeq.Prepend( aStr );
1472 else if ( aMinId > anIntSeq.Last() )
1474 anIntSeq.Append( aMinId );
1475 aStrSeq.Append( aStr );
1478 for ( int j = 1, k = anIntSeq.Length(); j <= k; j++ )
1479 if ( aMinId < anIntSeq( j ) )
1481 anIntSeq.InsertBefore( j, aMinId );
1482 aStrSeq.InsertBefore( j, aStr );
1488 if ( aStrSeq.Length() == 0 )
1491 theResStr = aStrSeq( 1 );
1492 for ( int j = 2, k = aStrSeq.Length(); j <= k; j++ )
1495 theResStr += aStrSeq( j );
1499 //=======================================================================
1500 // name : SetRangeStr
1501 // Purpose : Define range with string
1502 // Example of entry string: "1,2,3,50-60,63,67,70-"
1503 //=======================================================================
1504 bool RangeOfIds::SetRangeStr( const TCollection_AsciiString& theStr )
1510 TCollection_AsciiString aStr = theStr;
1511 aStr.RemoveAll( ' ' );
1512 aStr.RemoveAll( '\t' );
1514 for ( int aPos = aStr.Search( ",," ); aPos != -1; aPos = aStr.Search( ",," ) )
1515 aStr.Remove( aPos, 2 );
1517 TCollection_AsciiString tmpStr = aStr.Token( ",", 1 );
1519 while ( tmpStr != "" )
1521 tmpStr = aStr.Token( ",", i++ );
1522 int aPos = tmpStr.Search( '-' );
1526 if ( tmpStr.IsIntegerValue() )
1527 myIds.Add( tmpStr.IntegerValue() );
1533 TCollection_AsciiString aMaxStr = tmpStr.Split( aPos );
1534 TCollection_AsciiString aMinStr = tmpStr;
1536 while ( aMinStr.Search( "-" ) != -1 ) aMinStr.RemoveAll( '-' );
1537 while ( aMaxStr.Search( "-" ) != -1 ) aMaxStr.RemoveAll( '-' );
1539 if ( !aMinStr.IsEmpty() && !aMinStr.IsIntegerValue() ||
1540 !aMaxStr.IsEmpty() && !aMaxStr.IsIntegerValue() )
1543 myMin.Append( aMinStr.IsEmpty() ? IntegerFirst() : aMinStr.IntegerValue() );
1544 myMax.Append( aMaxStr.IsEmpty() ? IntegerLast() : aMaxStr.IntegerValue() );
1551 //=======================================================================
1553 // Purpose : Get type of supported entities
1554 //=======================================================================
1555 SMDSAbs_ElementType RangeOfIds::GetType() const
1560 //=======================================================================
1562 // Purpose : Set type of supported entities
1563 //=======================================================================
1564 void RangeOfIds::SetType( SMDSAbs_ElementType theType )
1569 //=======================================================================
1571 // Purpose : Verify whether entity satisfies to this rpedicate
1572 //=======================================================================
1573 bool RangeOfIds::IsSatisfy( long theId )
1578 if ( myType == SMDSAbs_Node )
1580 if ( myMesh->FindNode( theId ) == 0 )
1585 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
1586 if ( anElem == 0 || myType != anElem->GetType() && myType != SMDSAbs_All )
1590 if ( myIds.Contains( theId ) )
1593 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
1594 if ( theId >= myMin( i ) && theId <= myMax( i ) )
1602 Description : Base class for comparators
1604 Comparator::Comparator():
1608 Comparator::~Comparator()
1611 void Comparator::SetMesh( SMDS_Mesh* theMesh )
1614 myFunctor->SetMesh( theMesh );
1617 void Comparator::SetMargin( double theValue )
1619 myMargin = theValue;
1622 void Comparator::SetNumFunctor( NumericalFunctorPtr theFunct )
1624 myFunctor = theFunct;
1627 SMDSAbs_ElementType Comparator::GetType() const
1629 return myFunctor ? myFunctor->GetType() : SMDSAbs_All;
1632 double Comparator::GetMargin()
1640 Description : Comparator "<"
1642 bool LessThan::IsSatisfy( long theId )
1644 return myFunctor && myFunctor->GetValue( theId ) < myMargin;
1650 Description : Comparator ">"
1652 bool MoreThan::IsSatisfy( long theId )
1654 return myFunctor && myFunctor->GetValue( theId ) > myMargin;
1660 Description : Comparator "="
1663 myToler(Precision::Confusion())
1666 bool EqualTo::IsSatisfy( long theId )
1668 return myFunctor && fabs( myFunctor->GetValue( theId ) - myMargin ) < myToler;
1671 void EqualTo::SetTolerance( double theToler )
1676 double EqualTo::GetTolerance()
1683 Description : Logical NOT predicate
1685 LogicalNOT::LogicalNOT()
1688 LogicalNOT::~LogicalNOT()
1691 bool LogicalNOT::IsSatisfy( long theId )
1693 return myPredicate && !myPredicate->IsSatisfy( theId );
1696 void LogicalNOT::SetMesh( SMDS_Mesh* theMesh )
1699 myPredicate->SetMesh( theMesh );
1702 void LogicalNOT::SetPredicate( PredicatePtr thePred )
1704 myPredicate = thePred;
1707 SMDSAbs_ElementType LogicalNOT::GetType() const
1709 return myPredicate ? myPredicate->GetType() : SMDSAbs_All;
1714 Class : LogicalBinary
1715 Description : Base class for binary logical predicate
1717 LogicalBinary::LogicalBinary()
1720 LogicalBinary::~LogicalBinary()
1723 void LogicalBinary::SetMesh( SMDS_Mesh* theMesh )
1726 myPredicate1->SetMesh( theMesh );
1729 myPredicate2->SetMesh( theMesh );
1732 void LogicalBinary::SetPredicate1( PredicatePtr thePredicate )
1734 myPredicate1 = thePredicate;
1737 void LogicalBinary::SetPredicate2( PredicatePtr thePredicate )
1739 myPredicate2 = thePredicate;
1742 SMDSAbs_ElementType LogicalBinary::GetType() const
1744 if ( !myPredicate1 || !myPredicate2 )
1747 SMDSAbs_ElementType aType1 = myPredicate1->GetType();
1748 SMDSAbs_ElementType aType2 = myPredicate2->GetType();
1750 return aType1 == aType2 ? aType1 : SMDSAbs_All;
1756 Description : Logical AND
1758 bool LogicalAND::IsSatisfy( long theId )
1763 myPredicate1->IsSatisfy( theId ) &&
1764 myPredicate2->IsSatisfy( theId );
1770 Description : Logical OR
1772 bool LogicalOR::IsSatisfy( long theId )
1777 myPredicate1->IsSatisfy( theId ) ||
1778 myPredicate2->IsSatisfy( theId );
1792 void Filter::SetPredicate( PredicatePtr thePredicate )
1794 myPredicate = thePredicate;
1798 template<class TElement, class TIterator, class TPredicate>
1799 void FillSequence(const TIterator& theIterator,
1800 TPredicate& thePredicate,
1801 Filter::TIdSequence& theSequence)
1803 if ( theIterator ) {
1804 while( theIterator->more() ) {
1805 TElement anElem = theIterator->next();
1806 long anId = anElem->GetID();
1807 if ( thePredicate->IsSatisfy( anId ) )
1808 theSequence.push_back( anId );
1814 Filter::GetElementsId( SMDS_Mesh* theMesh )
1816 TIdSequence aSequence;
1817 if ( !theMesh || !myPredicate ) return aSequence;
1819 myPredicate->SetMesh( theMesh );
1821 SMDSAbs_ElementType aType = myPredicate->GetType();
1824 FillSequence<const SMDS_MeshNode*>(theMesh->nodesIterator(),myPredicate,aSequence);
1828 FillSequence<const SMDS_MeshElement*>(theMesh->edgesIterator(),myPredicate,aSequence);
1832 FillSequence<const SMDS_MeshElement*>(theMesh->facesIterator(),myPredicate,aSequence);
1835 case SMDSAbs_Volume:{
1836 FillSequence<const SMDS_MeshElement*>(theMesh->volumesIterator(),myPredicate,aSequence);
1840 FillSequence<const SMDS_MeshElement*>(theMesh->edgesIterator(),myPredicate,aSequence);
1841 FillSequence<const SMDS_MeshElement*>(theMesh->facesIterator(),myPredicate,aSequence);
1842 FillSequence<const SMDS_MeshElement*>(theMesh->volumesIterator(),myPredicate,aSequence);
1853 typedef std::set<SMDS_MeshFace*> TMapOfFacePtr;
1859 ManifoldPart::Link::Link( SMDS_MeshNode* theNode1,
1860 SMDS_MeshNode* theNode2 )
1866 ManifoldPart::Link::~Link()
1872 bool ManifoldPart::Link::IsEqual( const ManifoldPart::Link& theLink ) const
1874 if ( myNode1 == theLink.myNode1 &&
1875 myNode2 == theLink.myNode2 )
1877 else if ( myNode1 == theLink.myNode2 &&
1878 myNode2 == theLink.myNode1 )
1884 bool ManifoldPart::Link::operator<( const ManifoldPart::Link& x ) const
1886 if(myNode1 < x.myNode1) return true;
1887 if(myNode1 == x.myNode1)
1888 if(myNode2 < x.myNode2) return true;
1892 bool ManifoldPart::IsEqual( const ManifoldPart::Link& theLink1,
1893 const ManifoldPart::Link& theLink2 )
1895 return theLink1.IsEqual( theLink2 );
1898 ManifoldPart::ManifoldPart()
1901 myAngToler = Precision::Angular();
1902 myIsOnlyManifold = true;
1905 ManifoldPart::~ManifoldPart()
1910 void ManifoldPart::SetMesh( SMDS_Mesh* theMesh )
1916 SMDSAbs_ElementType ManifoldPart::GetType() const
1917 { return SMDSAbs_Face; }
1919 bool ManifoldPart::IsSatisfy( long theElementId )
1921 return myMapIds.Contains( theElementId );
1924 void ManifoldPart::SetAngleTolerance( const double theAngToler )
1925 { myAngToler = theAngToler; }
1927 double ManifoldPart::GetAngleTolerance() const
1928 { return myAngToler; }
1930 void ManifoldPart::SetIsOnlyManifold( const bool theIsOnly )
1931 { myIsOnlyManifold = theIsOnly; }
1933 void ManifoldPart::SetStartElem( const long theStartId )
1934 { myStartElemId = theStartId; }
1936 bool ManifoldPart::process()
1939 myMapBadGeomIds.Clear();
1941 myAllFacePtr.clear();
1942 myAllFacePtrIntDMap.clear();
1946 // collect all faces into own map
1947 SMDS_FaceIteratorPtr anFaceItr = myMesh->facesIterator();
1948 for (; anFaceItr->more(); )
1950 SMDS_MeshFace* aFacePtr = (SMDS_MeshFace*)anFaceItr->next();
1951 myAllFacePtr.push_back( aFacePtr );
1952 myAllFacePtrIntDMap[aFacePtr] = myAllFacePtr.size()-1;
1955 SMDS_MeshFace* aStartFace = (SMDS_MeshFace*)myMesh->FindElement( myStartElemId );
1959 // the map of non manifold links and bad geometry
1960 TMapOfLink aMapOfNonManifold;
1961 TColStd_MapOfInteger aMapOfTreated;
1963 // begin cycle on faces from start index and run on vector till the end
1964 // and from begin to start index to cover whole vector
1965 const int aStartIndx = myAllFacePtrIntDMap[aStartFace];
1966 bool isStartTreat = false;
1967 for ( int fi = aStartIndx; !isStartTreat || fi != aStartIndx ; fi++ )
1969 if ( fi == aStartIndx )
1970 isStartTreat = true;
1971 // as result next time when fi will be equal to aStartIndx
1973 SMDS_MeshFace* aFacePtr = myAllFacePtr[ fi ];
1974 if ( aMapOfTreated.Contains( aFacePtr->GetID() ) )
1977 aMapOfTreated.Add( aFacePtr->GetID() );
1978 TColStd_MapOfInteger aResFaces;
1979 if ( !findConnected( myAllFacePtrIntDMap, aFacePtr,
1980 aMapOfNonManifold, aResFaces ) )
1982 TColStd_MapIteratorOfMapOfInteger anItr( aResFaces );
1983 for ( ; anItr.More(); anItr.Next() )
1985 int aFaceId = anItr.Key();
1986 aMapOfTreated.Add( aFaceId );
1987 myMapIds.Add( aFaceId );
1990 if ( fi == ( myAllFacePtr.size() - 1 ) )
1992 } // end run on vector of faces
1993 return !myMapIds.IsEmpty();
1996 static void getLinks( const SMDS_MeshFace* theFace,
1997 ManifoldPart::TVectorOfLink& theLinks )
1999 int aNbNode = theFace->NbNodes();
2000 SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
2002 SMDS_MeshNode* aNode = 0;
2003 for ( ; aNodeItr->more() && i <= aNbNode; )
2006 SMDS_MeshNode* aN1 = (SMDS_MeshNode*)aNodeItr->next();
2010 SMDS_MeshNode* aN2 = ( i >= aNbNode ) ? aNode : (SMDS_MeshNode*)aNodeItr->next();
2012 ManifoldPart::Link aLink( aN1, aN2 );
2013 theLinks.push_back( aLink );
2017 static gp_XYZ getNormale( const SMDS_MeshFace* theFace )
2020 int aNbNode = theFace->NbNodes();
2021 TColgp_Array1OfXYZ anArrOfXYZ(1,4);
2022 SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
2024 for ( ; aNodeItr->more() && i <= 4; i++ )
2026 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
2027 anArrOfXYZ.SetValue(i, gp_XYZ( aNode->X(), aNode->Y(), aNode->Z() ) );
2030 gp_XYZ q1 = anArrOfXYZ.Value(2) - anArrOfXYZ.Value(1);
2031 gp_XYZ q2 = anArrOfXYZ.Value(3) - anArrOfXYZ.Value(1);
2035 gp_XYZ q3 = anArrOfXYZ.Value(4) - anArrOfXYZ.Value(1);
2038 double len = n.Modulus();
2045 bool ManifoldPart::findConnected
2046 ( const ManifoldPart::TDataMapFacePtrInt& theAllFacePtrInt,
2047 SMDS_MeshFace* theStartFace,
2048 ManifoldPart::TMapOfLink& theNonManifold,
2049 TColStd_MapOfInteger& theResFaces )
2051 theResFaces.Clear();
2052 if ( !theAllFacePtrInt.size() )
2055 if ( getNormale( theStartFace ).SquareModulus() <= gp::Resolution() )
2057 myMapBadGeomIds.Add( theStartFace->GetID() );
2061 ManifoldPart::TMapOfLink aMapOfBoundary, aMapToSkip;
2062 ManifoldPart::TVectorOfLink aSeqOfBoundary;
2063 theResFaces.Add( theStartFace->GetID() );
2064 ManifoldPart::TDataMapOfLinkFacePtr aDMapLinkFace;
2066 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
2067 aDMapLinkFace, theNonManifold, theStartFace );
2069 bool isDone = false;
2070 while ( !isDone && aMapOfBoundary.size() != 0 )
2072 bool isToReset = false;
2073 ManifoldPart::TVectorOfLink::iterator pLink = aSeqOfBoundary.begin();
2074 for ( ; !isToReset && pLink != aSeqOfBoundary.end(); ++pLink )
2076 ManifoldPart::Link aLink = *pLink;
2077 if ( aMapToSkip.find( aLink ) != aMapToSkip.end() )
2079 // each link could be treated only once
2080 aMapToSkip.insert( aLink );
2082 ManifoldPart::TVectorOfFacePtr aFaces;
2084 if ( myIsOnlyManifold &&
2085 (theNonManifold.find( aLink ) != theNonManifold.end()) )
2089 getFacesByLink( aLink, aFaces );
2090 // filter the element to keep only indicated elements
2091 ManifoldPart::TVectorOfFacePtr aFiltered;
2092 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
2093 for ( ; pFace != aFaces.end(); ++pFace )
2095 SMDS_MeshFace* aFace = *pFace;
2096 if ( myAllFacePtrIntDMap.find( aFace ) != myAllFacePtrIntDMap.end() )
2097 aFiltered.push_back( aFace );
2100 if ( aFaces.size() < 2 ) // no neihgbour faces
2102 else if ( myIsOnlyManifold && aFaces.size() > 2 ) // non manifold case
2104 theNonManifold.insert( aLink );
2109 // compare normal with normals of neighbor element
2110 SMDS_MeshFace* aPrevFace = aDMapLinkFace[ aLink ];
2111 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
2112 for ( ; pFace != aFaces.end(); ++pFace )
2114 SMDS_MeshFace* aNextFace = *pFace;
2115 if ( aPrevFace == aNextFace )
2117 int anNextFaceID = aNextFace->GetID();
2118 if ( myIsOnlyManifold && theResFaces.Contains( anNextFaceID ) )
2119 // should not be with non manifold restriction. probably bad topology
2121 // check if face was treated and skipped
2122 if ( myMapBadGeomIds.Contains( anNextFaceID ) ||
2123 !isInPlane( aPrevFace, aNextFace ) )
2125 // add new element to connected and extend the boundaries.
2126 theResFaces.Add( anNextFaceID );
2127 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
2128 aDMapLinkFace, theNonManifold, aNextFace );
2132 isDone = !isToReset;
2135 return !theResFaces.IsEmpty();
2138 bool ManifoldPart::isInPlane( const SMDS_MeshFace* theFace1,
2139 const SMDS_MeshFace* theFace2 )
2141 gp_Dir aNorm1 = gp_Dir( getNormale( theFace1 ) );
2142 gp_XYZ aNorm2XYZ = getNormale( theFace2 );
2143 if ( aNorm2XYZ.SquareModulus() <= gp::Resolution() )
2145 myMapBadGeomIds.Add( theFace2->GetID() );
2148 if ( aNorm1.IsParallel( gp_Dir( aNorm2XYZ ), myAngToler ) )
2154 void ManifoldPart::expandBoundary
2155 ( ManifoldPart::TMapOfLink& theMapOfBoundary,
2156 ManifoldPart::TVectorOfLink& theSeqOfBoundary,
2157 ManifoldPart::TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
2158 ManifoldPart::TMapOfLink& theNonManifold,
2159 SMDS_MeshFace* theNextFace ) const
2161 ManifoldPart::TVectorOfLink aLinks;
2162 getLinks( theNextFace, aLinks );
2163 int aNbLink = aLinks.size();
2164 for ( int i = 0; i < aNbLink; i++ )
2166 ManifoldPart::Link aLink = aLinks[ i ];
2167 if ( myIsOnlyManifold && (theNonManifold.find( aLink ) != theNonManifold.end()) )
2169 if ( theMapOfBoundary.find( aLink ) != theMapOfBoundary.end() )
2171 if ( myIsOnlyManifold )
2173 // remove from boundary
2174 theMapOfBoundary.erase( aLink );
2175 ManifoldPart::TVectorOfLink::iterator pLink = theSeqOfBoundary.begin();
2176 for ( ; pLink != theSeqOfBoundary.end(); ++pLink )
2178 ManifoldPart::Link aBoundLink = *pLink;
2179 if ( aBoundLink.IsEqual( aLink ) )
2181 theSeqOfBoundary.erase( pLink );
2189 theMapOfBoundary.insert( aLink );
2190 theSeqOfBoundary.push_back( aLink );
2191 theDMapLinkFacePtr[ aLink ] = theNextFace;
2196 void ManifoldPart::getFacesByLink( const ManifoldPart::Link& theLink,
2197 ManifoldPart::TVectorOfFacePtr& theFaces ) const
2199 SMDS_Mesh::SetOfFaces aSetOfFaces;
2200 // take all faces that shared first node
2201 SMDS_ElemIteratorPtr anItr = theLink.myNode1->facesIterator();
2202 for ( ; anItr->more(); )
2204 SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
2207 aSetOfFaces.Add( aFace );
2209 // take all faces that shared second node
2210 anItr = theLink.myNode2->facesIterator();
2211 // find the common part of two sets
2212 for ( ; anItr->more(); )
2214 SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
2215 if ( aSetOfFaces.Contains( aFace ) )
2216 theFaces.push_back( aFace );
2225 ElementsOnSurface::ElementsOnSurface()
2229 myType = SMDSAbs_All;
2231 myToler = Precision::Confusion();
2234 ElementsOnSurface::~ElementsOnSurface()
2239 void ElementsOnSurface::SetMesh( SMDS_Mesh* theMesh )
2241 if ( myMesh == theMesh )
2248 bool ElementsOnSurface::IsSatisfy( long theElementId )
2250 return myIds.Contains( theElementId );
2253 SMDSAbs_ElementType ElementsOnSurface::GetType() const
2256 void ElementsOnSurface::SetTolerance( const double theToler )
2257 { myToler = theToler; }
2259 double ElementsOnSurface::GetTolerance() const
2264 void ElementsOnSurface::SetSurface( const TopoDS_Shape& theShape,
2265 const SMDSAbs_ElementType theType )
2269 if ( theShape.IsNull() || theShape.ShapeType() != TopAbs_FACE )
2274 TopoDS_Face aFace = TopoDS::Face( theShape );
2275 mySurf = BRep_Tool::Surface( aFace );
2278 void ElementsOnSurface::process()
2281 if ( mySurf.IsNull() )
2287 if ( myType == SMDSAbs_Face || myType == SMDSAbs_All )
2289 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
2290 for(; anIter->more(); )
2291 process( anIter->next() );
2294 if ( myType == SMDSAbs_Edge || myType == SMDSAbs_All )
2296 SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
2297 for(; anIter->more(); )
2298 process( anIter->next() );
2301 if ( myType == SMDSAbs_Node )
2303 SMDS_NodeIteratorPtr anIter = myMesh->nodesIterator();
2304 for(; anIter->more(); )
2305 process( anIter->next() );
2309 void ElementsOnSurface::process( const SMDS_MeshElement* theElemPtr )
2311 SMDS_ElemIteratorPtr aNodeItr = theElemPtr->nodesIterator();
2312 bool isSatisfy = true;
2313 for ( ; aNodeItr->more(); )
2315 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
2316 if ( !isOnSurface( aNode ) )
2323 myIds.Add( theElemPtr->GetID() );
2326 bool ElementsOnSurface::isOnSurface( const SMDS_MeshNode* theNode ) const
2328 if ( mySurf.IsNull() )
2331 gp_Pnt aPnt( theNode->X(), theNode->Y(), theNode->Z() );
2332 double aToler2 = myToler * myToler;
2333 if ( mySurf->IsKind(STANDARD_TYPE(Geom_Plane)))
2335 gp_Pln aPln = Handle(Geom_Plane)::DownCast(mySurf)->Pln();
2336 if ( aPln.SquareDistance( aPnt ) > aToler2 )
2339 else if ( mySurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)))
2341 gp_Cylinder aCyl = Handle(Geom_CylindricalSurface)::DownCast(mySurf)->Cylinder();
2342 double aRad = aCyl.Radius();
2343 gp_Ax3 anAxis = aCyl.Position();
2344 gp_XYZ aLoc = aCyl.Location().XYZ();
2345 double aXDist = anAxis.XDirection().XYZ() * ( aPnt.XYZ() - aLoc );
2346 double aYDist = anAxis.YDirection().XYZ() * ( aPnt.XYZ() - aLoc );
2347 if ( fabs(aXDist*aXDist + aYDist*aYDist - aRad*aRad) > aToler2 )