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( const 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( const 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;
207 //=======================================================================
208 //function : GetValue
210 //=======================================================================
212 double Volume::GetValue( long theElementId )
214 if ( theElementId && myMesh ) {
215 SMDS_VolumeTool aVolumeTool;
216 if ( aVolumeTool.Set( myMesh->FindElement( theElementId )))
217 return aVolumeTool.GetSize();
222 //=======================================================================
223 //function : GetBadRate
224 //purpose : meaningless as it is not quality control functor
225 //=======================================================================
227 double Volume::GetBadRate( double Value, int /*nbNodes*/ ) const
232 //=======================================================================
235 //=======================================================================
237 SMDSAbs_ElementType Volume::GetType() const
239 return SMDSAbs_Volume;
245 Description : Functor for calculation of minimum angle
248 double MinimumAngle::GetValue( const TSequenceOfXYZ& P )
255 aMin = getAngle(P( P.size() ), P( 1 ), P( 2 ));
256 aMin = Min(aMin,getAngle(P( P.size()-1 ), P( P.size() ), P( 1 )));
258 for (int i=2; i<P.size();i++){
259 double A0 = getAngle( P( i-1 ), P( i ), P( i+1 ) );
263 return aMin * 180.0 / PI;
266 double MinimumAngle::GetBadRate( double Value, int nbNodes ) const
268 //const double aBestAngle = PI / nbNodes;
269 const double aBestAngle = 180.0 - ( 360.0 / double(nbNodes) );
270 return ( fabs( aBestAngle - Value ));
273 SMDSAbs_ElementType MinimumAngle::GetType() const
281 Description : Functor for calculating aspect ratio
283 double AspectRatio::GetValue( const TSequenceOfXYZ& P )
285 // According to "Mesh quality control" by Nadir Bouhamau referring to
286 // Pascal Jean Frey and Paul-Louis George. Maillages, applications aux elements finis.
287 // Hermes Science publications, Paris 1999 ISBN 2-7462-0024-4
289 int nbNodes = P.size();
294 // Compute lengths of the sides
296 vector< double > aLen (nbNodes);
298 for ( int i = 0; i < nbNodes - 1; i++ )
299 aLen[ i ] = getDistance( P( i + 1 ), P( i + 2 ) );
300 aLen[ nbNodes - 1 ] = getDistance( P( 1 ), P( nbNodes ) );
302 // Compute aspect ratio
306 // Q = alfa * h * p / S, where
308 // alfa = sqrt( 3 ) / 6
309 // h - length of the longest edge
310 // p - half perimeter
311 // S - triangle surface
313 const double alfa = sqrt( 3. ) / 6.;
314 double maxLen = Max( aLen[ 0 ], Max( aLen[ 1 ], aLen[ 2 ] ) );
315 double half_perimeter = ( aLen[0] + aLen[1] + aLen[2] ) / 2.;
316 double anArea = getArea( P( 1 ), P( 2 ), P( 3 ) );
317 if ( anArea <= Precision::Confusion() )
320 return alfa * maxLen * half_perimeter / anArea;
324 // return aspect ratio of the worst triange which can be built
325 // taking three nodes of the quadrangle
326 TSequenceOfXYZ triaPnts(3);
327 // triangle on nodes 1 3 2
331 double ar = GetValue( triaPnts );
332 // triangle on nodes 1 3 4
334 ar = Max ( ar, GetValue( triaPnts ));
335 // triangle on nodes 1 2 4
337 ar = Max ( ar, GetValue( triaPnts ));
338 // triangle on nodes 3 2 4
340 ar = Max ( ar, GetValue( triaPnts ));
346 double AspectRatio::GetBadRate( double Value, int /*nbNodes*/ ) const
348 // the aspect ratio is in the range [1.0,infinity]
351 return Value / 1000.;
354 SMDSAbs_ElementType AspectRatio::GetType() const
361 Class : AspectRatio3D
362 Description : Functor for calculating aspect ratio
366 inline double getHalfPerimeter(double theTria[3]){
367 return (theTria[0] + theTria[1] + theTria[2])/2.0;
370 inline double getArea(double theHalfPerim, double theTria[3]){
371 return sqrt(theHalfPerim*
372 (theHalfPerim-theTria[0])*
373 (theHalfPerim-theTria[1])*
374 (theHalfPerim-theTria[2]));
377 inline double getVolume(double theLen[6]){
378 double a2 = theLen[0]*theLen[0];
379 double b2 = theLen[1]*theLen[1];
380 double c2 = theLen[2]*theLen[2];
381 double d2 = theLen[3]*theLen[3];
382 double e2 = theLen[4]*theLen[4];
383 double f2 = theLen[5]*theLen[5];
384 double P = 4.0*a2*b2*d2;
385 double Q = a2*(b2+d2-e2)-b2*(a2+d2-f2)-d2*(a2+b2-c2);
386 double R = (b2+d2-e2)*(a2+d2-f2)*(a2+d2-f2);
387 return sqrt(P-Q+R)/12.0;
390 inline double getVolume2(double theLen[6]){
391 double a2 = theLen[0]*theLen[0];
392 double b2 = theLen[1]*theLen[1];
393 double c2 = theLen[2]*theLen[2];
394 double d2 = theLen[3]*theLen[3];
395 double e2 = theLen[4]*theLen[4];
396 double f2 = theLen[5]*theLen[5];
398 double P = a2*e2*(b2+c2+d2+f2-a2-e2);
399 double Q = b2*f2*(a2+c2+d2+e2-b2-f2);
400 double R = c2*d2*(a2+b2+e2+f2-c2-d2);
401 double S = a2*b2*d2+b2*c2*e2+a2*c2*f2+d2*e2*f2;
403 return sqrt(P+Q+R-S)/12.0;
406 inline double getVolume(const TSequenceOfXYZ& P){
407 gp_Vec aVec1( P( 2 ) - P( 1 ) );
408 gp_Vec aVec2( P( 3 ) - P( 1 ) );
409 gp_Vec aVec3( P( 4 ) - P( 1 ) );
410 gp_Vec anAreaVec( aVec1 ^ aVec2 );
411 return fabs(aVec3 * anAreaVec) / 6.0;
414 inline double getMaxHeight(double theLen[6])
416 double aHeight = max(theLen[0],theLen[1]);
417 aHeight = max(aHeight,theLen[2]);
418 aHeight = max(aHeight,theLen[3]);
419 aHeight = max(aHeight,theLen[4]);
420 aHeight = max(aHeight,theLen[5]);
426 double AspectRatio3D::GetValue( const TSequenceOfXYZ& P )
428 double aQuality = 0.0;
429 int nbNodes = P.size();
433 getDistance(P( 1 ),P( 2 )), // a
434 getDistance(P( 2 ),P( 3 )), // b
435 getDistance(P( 3 ),P( 1 )), // c
436 getDistance(P( 2 ),P( 4 )), // d
437 getDistance(P( 3 ),P( 4 )), // e
438 getDistance(P( 1 ),P( 4 )) // f
440 double aTria[4][3] = {
441 {aLen[0],aLen[1],aLen[2]}, // abc
442 {aLen[0],aLen[3],aLen[5]}, // adf
443 {aLen[1],aLen[3],aLen[4]}, // bde
444 {aLen[2],aLen[4],aLen[5]} // cef
446 double aSumArea = 0.0;
447 double aHalfPerimeter = getHalfPerimeter(aTria[0]);
448 double anArea = getArea(aHalfPerimeter,aTria[0]);
450 aHalfPerimeter = getHalfPerimeter(aTria[1]);
451 anArea = getArea(aHalfPerimeter,aTria[1]);
453 aHalfPerimeter = getHalfPerimeter(aTria[2]);
454 anArea = getArea(aHalfPerimeter,aTria[2]);
456 aHalfPerimeter = getHalfPerimeter(aTria[3]);
457 anArea = getArea(aHalfPerimeter,aTria[3]);
459 double aVolume = getVolume(P);
460 //double aVolume = getVolume(aLen);
461 double aHeight = getMaxHeight(aLen);
462 static double aCoeff = sqrt(2.0)/12.0;
463 aQuality = aCoeff*aHeight*aSumArea/aVolume;
468 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 3 ),P( 5 )};
469 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
472 gp_XYZ aXYZ[4] = {P( 1 ),P( 3 ),P( 4 ),P( 5 )};
473 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
476 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 5 )};
477 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
480 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 4 ),P( 5 )};
481 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
487 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 6 )};
488 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
491 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 3 )};
492 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
495 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 6 )};
496 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
499 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
500 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
503 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 6 )};
504 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
507 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 3 )};
508 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
514 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
515 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
518 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 4 )};
519 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
522 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 7 )};
523 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
526 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 8 )};
527 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
530 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 3 )};
531 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
534 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 4 )};
535 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
538 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 7 )};
539 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
542 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 8 )};
543 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
546 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 3 )};
547 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
550 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 4 )};
551 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
554 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 7 )};
555 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
558 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 8 )};
559 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
562 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 1 )};
563 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
566 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 2 )};
567 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
570 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 5 )};
571 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
574 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 6 )};
575 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
578 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 1 )};
579 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
582 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 2 )};
583 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
586 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 5 )};
587 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
590 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 6 )};
591 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
594 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 1 )};
595 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
598 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
599 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
602 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 5 )};
603 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
606 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 6 )};
607 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
610 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
611 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
614 gp_XYZ aXYZ[4] = {P( 4 ),P( 5 ),P( 8 ),P( 2 )};
615 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
618 gp_XYZ aXYZ[4] = {P( 1 ),P( 4 ),P( 5 ),P( 3 )};
619 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
622 gp_XYZ aXYZ[4] = {P( 3 ),P( 6 ),P( 7 ),P( 1 )};
623 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
626 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 6 ),P( 4 )};
627 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
630 gp_XYZ aXYZ[4] = {P( 5 ),P( 6 ),P( 8 ),P( 3 )};
631 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
634 gp_XYZ aXYZ[4] = {P( 7 ),P( 8 ),P( 6 ),P( 1 )};
635 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
638 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 7 )};
639 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
642 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 2 ),P( 5 )};
643 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
651 double AspectRatio3D::GetBadRate( double Value, int /*nbNodes*/ ) const
653 // the aspect ratio is in the range [1.0,infinity]
656 return Value / 1000.;
659 SMDSAbs_ElementType AspectRatio3D::GetType() const
661 return SMDSAbs_Volume;
667 Description : Functor for calculating warping
669 double Warping::GetValue( const TSequenceOfXYZ& P )
674 gp_XYZ G = ( P( 1 ) + P( 2 ) + P( 3 ) + P( 4 ) ) / 4;
676 double A1 = ComputeA( P( 1 ), P( 2 ), P( 3 ), G );
677 double A2 = ComputeA( P( 2 ), P( 3 ), P( 4 ), G );
678 double A3 = ComputeA( P( 3 ), P( 4 ), P( 1 ), G );
679 double A4 = ComputeA( P( 4 ), P( 1 ), P( 2 ), G );
681 return Max( Max( A1, A2 ), Max( A3, A4 ) );
684 double Warping::ComputeA( const gp_XYZ& thePnt1,
685 const gp_XYZ& thePnt2,
686 const gp_XYZ& thePnt3,
687 const gp_XYZ& theG ) const
689 double aLen1 = gp_Pnt( thePnt1 ).Distance( gp_Pnt( thePnt2 ) );
690 double aLen2 = gp_Pnt( thePnt2 ).Distance( gp_Pnt( thePnt3 ) );
691 double L = Min( aLen1, aLen2 ) * 0.5;
692 if ( L < Precision::Confusion())
695 gp_XYZ GI = ( thePnt2 + thePnt1 ) / 2. - theG;
696 gp_XYZ GJ = ( thePnt3 + thePnt2 ) / 2. - theG;
697 gp_XYZ N = GI.Crossed( GJ );
699 if ( N.Modulus() < gp::Resolution() )
704 double H = ( thePnt2 - theG ).Dot( N );
705 return asin( fabs( H / L ) ) * 180 / PI;
708 double Warping::GetBadRate( double Value, int /*nbNodes*/ ) const
710 // the warp is in the range [0.0,PI/2]
711 // 0.0 = good (no warp)
712 // PI/2 = bad (face pliee)
716 SMDSAbs_ElementType Warping::GetType() const
724 Description : Functor for calculating taper
726 double Taper::GetValue( const TSequenceOfXYZ& P )
732 double J1 = getArea( P( 4 ), P( 1 ), P( 2 ) ) / 2;
733 double J2 = getArea( P( 3 ), P( 1 ), P( 2 ) ) / 2;
734 double J3 = getArea( P( 2 ), P( 3 ), P( 4 ) ) / 2;
735 double J4 = getArea( P( 3 ), P( 4 ), P( 1 ) ) / 2;
737 double JA = 0.25 * ( J1 + J2 + J3 + J4 );
738 if ( JA <= Precision::Confusion() )
741 double T1 = fabs( ( J1 - JA ) / JA );
742 double T2 = fabs( ( J2 - JA ) / JA );
743 double T3 = fabs( ( J3 - JA ) / JA );
744 double T4 = fabs( ( J4 - JA ) / JA );
746 return Max( Max( T1, T2 ), Max( T3, T4 ) );
749 double Taper::GetBadRate( double Value, int /*nbNodes*/ ) const
751 // the taper is in the range [0.0,1.0]
752 // 0.0 = good (no taper)
753 // 1.0 = bad (les cotes opposes sont allignes)
757 SMDSAbs_ElementType Taper::GetType() const
765 Description : Functor for calculating skew in degrees
767 static inline double skewAngle( const gp_XYZ& p1, const gp_XYZ& p2, const gp_XYZ& p3 )
769 gp_XYZ p12 = ( p2 + p1 ) / 2;
770 gp_XYZ p23 = ( p3 + p2 ) / 2;
771 gp_XYZ p31 = ( p3 + p1 ) / 2;
773 gp_Vec v1( p31 - p2 ), v2( p12 - p23 );
775 return v1.Magnitude() < gp::Resolution() || v2.Magnitude() < gp::Resolution() ? 0 : v1.Angle( v2 );
778 double Skew::GetValue( const TSequenceOfXYZ& P )
780 if ( P.size() != 3 && P.size() != 4 )
784 static double PI2 = PI / 2;
787 double A0 = fabs( PI2 - skewAngle( P( 3 ), P( 1 ), P( 2 ) ) );
788 double A1 = fabs( PI2 - skewAngle( P( 1 ), P( 2 ), P( 3 ) ) );
789 double A2 = fabs( PI2 - skewAngle( P( 2 ), P( 3 ), P( 1 ) ) );
791 return Max( A0, Max( A1, A2 ) ) * 180 / PI;
795 gp_XYZ p12 = ( P( 1 ) + P( 2 ) ) / 2;
796 gp_XYZ p23 = ( P( 2 ) + P( 3 ) ) / 2;
797 gp_XYZ p34 = ( P( 3 ) + P( 4 ) ) / 2;
798 gp_XYZ p41 = ( P( 4 ) + P( 1 ) ) / 2;
800 gp_Vec v1( p34 - p12 ), v2( p23 - p41 );
801 double A = v1.Magnitude() <= gp::Resolution() || v2.Magnitude() <= gp::Resolution()
802 ? 0 : fabs( PI2 - v1.Angle( v2 ) );
808 double Skew::GetBadRate( double Value, int /*nbNodes*/ ) const
810 // the skew is in the range [0.0,PI/2].
816 SMDSAbs_ElementType Skew::GetType() const
824 Description : Functor for calculating area
826 double Area::GetValue( const TSequenceOfXYZ& P )
830 return getArea( P( 1 ), P( 2 ), P( 3 ) );
831 else if (P.size() > 3)
832 aArea = getArea( P( 1 ), P( 2 ), P( 3 ) );
836 for (int i=4; i<=P.size(); i++)
837 aArea += getArea(P(1),P(i-1),P(i));
841 double Area::GetBadRate( double Value, int /*nbNodes*/ ) const
843 // meaningless as it is not quality control functor
847 SMDSAbs_ElementType Area::GetType() const
855 Description : Functor for calculating length off edge
857 double Length::GetValue( const TSequenceOfXYZ& P )
859 return ( P.size() == 2 ? getDistance( P( 1 ), P( 2 ) ) : 0 );
862 double Length::GetBadRate( double Value, int /*nbNodes*/ ) const
864 // meaningless as it is not quality control functor
868 SMDSAbs_ElementType Length::GetType() const
875 Description : Functor for calculating length of edge
878 double Length2D::GetValue( long theElementId)
882 if (GetPoints(theElementId,P)){
884 double aVal;// = GetValue( P );
885 const SMDS_MeshElement* aElem = myMesh->FindElement( theElementId );
886 SMDSAbs_ElementType aType = aElem->GetType();
895 aVal = getDistance( P( 1 ), P( 2 ) );
899 if (len == 3){ // triangles
900 double L1 = getDistance(P( 1 ),P( 2 ));
901 double L2 = getDistance(P( 2 ),P( 3 ));
902 double L3 = getDistance(P( 3 ),P( 1 ));
903 aVal = Max(L1,Max(L2,L3));
906 else if (len == 4){ // quadrangles
907 double L1 = getDistance(P( 1 ),P( 2 ));
908 double L2 = getDistance(P( 2 ),P( 3 ));
909 double L3 = getDistance(P( 3 ),P( 4 ));
910 double L4 = getDistance(P( 4 ),P( 1 ));
911 aVal = Max(Max(L1,L2),Max(L3,L4));
915 if (len == 4){ // tetraidrs
916 double L1 = getDistance(P( 1 ),P( 2 ));
917 double L2 = getDistance(P( 2 ),P( 3 ));
918 double L3 = getDistance(P( 3 ),P( 1 ));
919 double L4 = getDistance(P( 1 ),P( 4 ));
920 double L5 = getDistance(P( 2 ),P( 4 ));
921 double L6 = getDistance(P( 3 ),P( 4 ));
922 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
925 else if (len == 5){ // piramids
926 double L1 = getDistance(P( 1 ),P( 2 ));
927 double L2 = getDistance(P( 2 ),P( 3 ));
928 double L3 = getDistance(P( 3 ),P( 1 ));
929 double L4 = getDistance(P( 4 ),P( 1 ));
930 double L5 = getDistance(P( 1 ),P( 5 ));
931 double L6 = getDistance(P( 2 ),P( 5 ));
932 double L7 = getDistance(P( 3 ),P( 5 ));
933 double L8 = getDistance(P( 4 ),P( 5 ));
935 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
936 aVal = Max(aVal,Max(L7,L8));
939 else if (len == 6){ // pentaidres
940 double L1 = getDistance(P( 1 ),P( 2 ));
941 double L2 = getDistance(P( 2 ),P( 3 ));
942 double L3 = getDistance(P( 3 ),P( 1 ));
943 double L4 = getDistance(P( 4 ),P( 5 ));
944 double L5 = getDistance(P( 5 ),P( 6 ));
945 double L6 = getDistance(P( 6 ),P( 4 ));
946 double L7 = getDistance(P( 1 ),P( 4 ));
947 double L8 = getDistance(P( 2 ),P( 5 ));
948 double L9 = getDistance(P( 3 ),P( 6 ));
950 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
951 aVal = Max(aVal,Max(Max(L7,L8),L9));
954 else if (len == 8){ // hexaider
955 double L1 = getDistance(P( 1 ),P( 2 ));
956 double L2 = getDistance(P( 2 ),P( 3 ));
957 double L3 = getDistance(P( 3 ),P( 4 ));
958 double L4 = getDistance(P( 4 ),P( 1 ));
959 double L5 = getDistance(P( 5 ),P( 6 ));
960 double L6 = getDistance(P( 6 ),P( 7 ));
961 double L7 = getDistance(P( 7 ),P( 8 ));
962 double L8 = getDistance(P( 8 ),P( 5 ));
963 double L9 = getDistance(P( 1 ),P( 5 ));
964 double L10= getDistance(P( 2 ),P( 6 ));
965 double L11= getDistance(P( 3 ),P( 7 ));
966 double L12= getDistance(P( 4 ),P( 8 ));
968 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
969 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
970 aVal = Max(aVal,Max(L11,L12));
982 if ( myPrecision >= 0 )
984 double prec = pow( 10., (double)( myPrecision ) );
985 aVal = floor( aVal * prec + 0.5 ) / prec;
994 double Length2D::GetBadRate( double Value, int /*nbNodes*/ ) const
996 // meaningless as it is not quality control functor
1000 SMDSAbs_ElementType Length2D::GetType() const
1002 return SMDSAbs_Face;
1005 Length2D::Value::Value(double theLength,long thePntId1, long thePntId2):
1008 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1009 if(thePntId1 > thePntId2){
1010 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1014 bool Length2D::Value::operator<(const Length2D::Value& x) const{
1015 if(myPntId[0] < x.myPntId[0]) return true;
1016 if(myPntId[0] == x.myPntId[0])
1017 if(myPntId[1] < x.myPntId[1]) return true;
1021 void Length2D::GetValues(TValues& theValues){
1023 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1024 for(; anIter->more(); ){
1025 const SMDS_MeshFace* anElem = anIter->next();
1026 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
1031 const SMDS_MeshElement* aNode;
1032 if(aNodesIter->more()){
1033 aNode = aNodesIter->next();
1034 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1035 P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1036 aNodeId[0] = aNodeId[1] = aNode->GetID();
1039 for(; aNodesIter->more(); ){
1040 aNode = aNodesIter->next();
1041 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1042 long anId = aNode->GetID();
1044 P[2] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1046 aLength = P[1].Distance(P[2]);
1048 Value aValue(aLength,aNodeId[1],anId);
1051 theValues.insert(aValue);
1054 aLength = P[0].Distance(P[1]);
1056 Value aValue(aLength,aNodeId[0],aNodeId[1]);
1057 theValues.insert(aValue);
1062 Class : MultiConnection
1063 Description : Functor for calculating number of faces conneted to the edge
1065 double MultiConnection::GetValue( const TSequenceOfXYZ& P )
1069 double MultiConnection::GetValue( long theId )
1071 return getNbMultiConnection( myMesh, theId );
1074 double MultiConnection::GetBadRate( double Value, int /*nbNodes*/ ) const
1076 // meaningless as it is not quality control functor
1080 SMDSAbs_ElementType MultiConnection::GetType() const
1082 return SMDSAbs_Edge;
1086 Class : MultiConnection2D
1087 Description : Functor for calculating number of faces conneted to the edge
1089 double MultiConnection2D::GetValue( const TSequenceOfXYZ& P )
1094 double MultiConnection2D::GetValue( long theElementId )
1099 if (GetPoints(theElementId,P)){
1100 const SMDS_MeshElement* anFaceElem = myMesh->FindElement( theElementId );
1101 SMDSAbs_ElementType aType = anFaceElem->GetType();
1105 TColStd_MapOfInteger aMap;
1113 if (len == 3){ // triangles
1114 int Nb[3] = {0,0,0};
1117 SMDS_ElemIteratorPtr anIter = anFaceElem->nodesIterator();
1118 if ( anIter != 0 ) {
1119 while( anIter->more() ) {
1120 const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next();
1124 SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator();
1125 while( anElemIter->more() ) {
1126 const SMDS_MeshElement* anElem = anElemIter->next();
1127 if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) {
1128 int anId = anElem->GetID();
1130 if ( anIter->more() ) // i.e. first node
1132 else if ( aMap.Contains( anId ) ){
1136 else if ( anElem != 0 && anElem->GetType() == SMDSAbs_Edge ) i++;
1141 aResult = Max(Max(Nb[0],Nb[1]),Nb[2]);
1144 case SMDSAbs_Volume:
1149 return aResult;//getNbMultiConnection( myMesh, theId );
1152 double MultiConnection2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1154 // meaningless as it is not quality control functor
1158 SMDSAbs_ElementType MultiConnection2D::GetType() const
1160 return SMDSAbs_Face;
1163 MultiConnection2D::Value::Value(long thePntId1, long thePntId2)
1165 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1166 if(thePntId1 > thePntId2){
1167 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1171 bool MultiConnection2D::Value::operator<(const MultiConnection2D::Value& x) const{
1172 if(myPntId[0] < x.myPntId[0]) return true;
1173 if(myPntId[0] == x.myPntId[0])
1174 if(myPntId[1] < x.myPntId[1]) return true;
1178 void MultiConnection2D::GetValues(MValues& theValues){
1179 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1180 for(; anIter->more(); ){
1181 const SMDS_MeshFace* anElem = anIter->next();
1182 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
1185 //int aNbConnects=0;
1186 const SMDS_MeshNode* aNode0;
1187 const SMDS_MeshNode* aNode1;
1188 const SMDS_MeshNode* aNode2;
1189 if(aNodesIter->more()){
1190 aNode0 = (SMDS_MeshNode*) aNodesIter->next();
1192 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode1;
1193 aNodeId[0] = aNodeId[1] = aNodes->GetID();
1195 for(; aNodesIter->more(); ){
1196 aNode2 = (SMDS_MeshNode*) aNodesIter->next();
1197 long anId = aNode2->GetID();
1200 Value aValue(aNodeId[1],aNodeId[2]);
1201 MValues::iterator aItr = theValues.find(aValue);
1202 if (aItr != theValues.end()){
1206 theValues[aValue] = 1;
1209 //cout << "NodeIds: "<<aNodeId[1]<<","<<aNodeId[2]<<" nbconn="<<aNbConnects<<endl;
1210 aNodeId[1] = aNodeId[2];
1213 Value aValue(aNodeId[0],aNodeId[2]);
1214 MValues::iterator aItr = theValues.find(aValue);
1215 if (aItr != theValues.end()){
1219 theValues[aValue] = 1;
1222 //cout << "NodeIds: "<<aNodeId[0]<<","<<aNodeId[2]<<" nbconn="<<aNbConnects<<endl;
1232 Class : BadOrientedVolume
1233 Description : Predicate bad oriented volumes
1236 BadOrientedVolume::BadOrientedVolume()
1241 void BadOrientedVolume::SetMesh( const SMDS_Mesh* theMesh )
1246 bool BadOrientedVolume::IsSatisfy( long theId )
1251 SMDS_VolumeTool vTool( myMesh->FindElement( theId ));
1252 return !vTool.IsForward();
1255 SMDSAbs_ElementType BadOrientedVolume::GetType() const
1257 return SMDSAbs_Volume;
1264 Description : Predicate for free borders
1267 FreeBorders::FreeBorders()
1272 void FreeBorders::SetMesh( const SMDS_Mesh* theMesh )
1277 bool FreeBorders::IsSatisfy( long theId )
1279 return getNbMultiConnection( myMesh, theId ) == 1;
1282 SMDSAbs_ElementType FreeBorders::GetType() const
1284 return SMDSAbs_Edge;
1290 Description : Predicate for free Edges
1292 FreeEdges::FreeEdges()
1297 void FreeEdges::SetMesh( const SMDS_Mesh* theMesh )
1302 bool FreeEdges::IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId )
1304 TColStd_MapOfInteger aMap;
1305 for ( int i = 0; i < 2; i++ )
1307 SMDS_ElemIteratorPtr anElemIter = theNodes[ i ]->GetInverseElementIterator();
1308 while( anElemIter->more() )
1310 const SMDS_MeshElement* anElem = anElemIter->next();
1311 if ( anElem != 0 && anElem->GetType() == SMDSAbs_Face )
1313 int anId = anElem->GetID();
1317 else if ( aMap.Contains( anId ) && anId != theFaceId )
1325 bool FreeEdges::IsSatisfy( long theId )
1330 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
1331 if ( aFace == 0 || aFace->GetType() != SMDSAbs_Face || aFace->NbNodes() < 3 )
1334 int nbNodes = aFace->NbNodes();
1335 //const SMDS_MeshNode* aNodes[ nbNodes ];
1337 const SMDS_MeshNode* aNodes [nbNodes];
1339 const SMDS_MeshNode** aNodes = (const SMDS_MeshNode **)new SMDS_MeshNode*[nbNodes];
1342 SMDS_ElemIteratorPtr anIter = aFace->nodesIterator();
1345 while( anIter->more() )
1347 const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next();
1350 aNodes[ i++ ] = aNode;
1354 for ( int i = 0; i < nbNodes - 1; i++ )
1355 if ( IsFreeEdge( &aNodes[ i ], theId ) ) {
1362 aNodes[ 1 ] = aNodes[ nbNodes - 1 ];
1363 const Standard_Boolean isFree = IsFreeEdge( &aNodes[ 0 ], theId );
1371 SMDSAbs_ElementType FreeEdges::GetType() const
1373 return SMDSAbs_Face;
1376 FreeEdges::Border::Border(long theElemId, long thePntId1, long thePntId2):
1379 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1380 if(thePntId1 > thePntId2){
1381 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1385 bool FreeEdges::Border::operator<(const FreeEdges::Border& x) const{
1386 if(myPntId[0] < x.myPntId[0]) return true;
1387 if(myPntId[0] == x.myPntId[0])
1388 if(myPntId[1] < x.myPntId[1]) return true;
1392 inline void UpdateBorders(const FreeEdges::Border& theBorder,
1393 FreeEdges::TBorders& theRegistry,
1394 FreeEdges::TBorders& theContainer)
1396 if(theRegistry.find(theBorder) == theRegistry.end()){
1397 theRegistry.insert(theBorder);
1398 theContainer.insert(theBorder);
1400 theContainer.erase(theBorder);
1404 void FreeEdges::GetBoreders(TBorders& theBorders)
1407 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1408 for(; anIter->more(); ){
1409 const SMDS_MeshFace* anElem = anIter->next();
1410 long anElemId = anElem->GetID();
1411 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
1413 const SMDS_MeshElement* aNode;
1414 if(aNodesIter->more()){
1415 aNode = aNodesIter->next();
1416 aNodeId[0] = aNodeId[1] = aNode->GetID();
1418 for(; aNodesIter->more(); ){
1419 aNode = aNodesIter->next();
1420 long anId = aNode->GetID();
1421 Border aBorder(anElemId,aNodeId[1],anId);
1423 //std::cout<<aBorder.myPntId[0]<<"; "<<aBorder.myPntId[1]<<"; "<<aBorder.myElemId<<endl;
1424 UpdateBorders(aBorder,aRegistry,theBorders);
1426 Border aBorder(anElemId,aNodeId[0],aNodeId[1]);
1427 //std::cout<<aBorder.myPntId[0]<<"; "<<aBorder.myPntId[1]<<"; "<<aBorder.myElemId<<endl;
1428 UpdateBorders(aBorder,aRegistry,theBorders);
1430 //std::cout<<"theBorders.size() = "<<theBorders.size()<<endl;
1435 Description : Predicate for Range of Ids.
1436 Range may be specified with two ways.
1437 1. Using AddToRange method
1438 2. With SetRangeStr method. Parameter of this method is a string
1439 like as "1,2,3,50-60,63,67,70-"
1442 //=======================================================================
1443 // name : RangeOfIds
1444 // Purpose : Constructor
1445 //=======================================================================
1446 RangeOfIds::RangeOfIds()
1449 myType = SMDSAbs_All;
1452 //=======================================================================
1454 // Purpose : Set mesh
1455 //=======================================================================
1456 void RangeOfIds::SetMesh( const SMDS_Mesh* theMesh )
1461 //=======================================================================
1462 // name : AddToRange
1463 // Purpose : Add ID to the range
1464 //=======================================================================
1465 bool RangeOfIds::AddToRange( long theEntityId )
1467 myIds.Add( theEntityId );
1471 //=======================================================================
1472 // name : GetRangeStr
1473 // Purpose : Get range as a string.
1474 // Example: "1,2,3,50-60,63,67,70-"
1475 //=======================================================================
1476 void RangeOfIds::GetRangeStr( TCollection_AsciiString& theResStr )
1480 TColStd_SequenceOfInteger anIntSeq;
1481 TColStd_SequenceOfAsciiString aStrSeq;
1483 TColStd_MapIteratorOfMapOfInteger anIter( myIds );
1484 for ( ; anIter.More(); anIter.Next() )
1486 int anId = anIter.Key();
1487 TCollection_AsciiString aStr( anId );
1488 anIntSeq.Append( anId );
1489 aStrSeq.Append( aStr );
1492 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
1494 int aMinId = myMin( i );
1495 int aMaxId = myMax( i );
1497 TCollection_AsciiString aStr;
1498 if ( aMinId != IntegerFirst() )
1503 if ( aMaxId != IntegerLast() )
1506 // find position of the string in result sequence and insert string in it
1507 if ( anIntSeq.Length() == 0 )
1509 anIntSeq.Append( aMinId );
1510 aStrSeq.Append( aStr );
1514 if ( aMinId < anIntSeq.First() )
1516 anIntSeq.Prepend( aMinId );
1517 aStrSeq.Prepend( aStr );
1519 else if ( aMinId > anIntSeq.Last() )
1521 anIntSeq.Append( aMinId );
1522 aStrSeq.Append( aStr );
1525 for ( int j = 1, k = anIntSeq.Length(); j <= k; j++ )
1526 if ( aMinId < anIntSeq( j ) )
1528 anIntSeq.InsertBefore( j, aMinId );
1529 aStrSeq.InsertBefore( j, aStr );
1535 if ( aStrSeq.Length() == 0 )
1538 theResStr = aStrSeq( 1 );
1539 for ( int j = 2, k = aStrSeq.Length(); j <= k; j++ )
1542 theResStr += aStrSeq( j );
1546 //=======================================================================
1547 // name : SetRangeStr
1548 // Purpose : Define range with string
1549 // Example of entry string: "1,2,3,50-60,63,67,70-"
1550 //=======================================================================
1551 bool RangeOfIds::SetRangeStr( const TCollection_AsciiString& theStr )
1557 TCollection_AsciiString aStr = theStr;
1558 aStr.RemoveAll( ' ' );
1559 aStr.RemoveAll( '\t' );
1561 for ( int aPos = aStr.Search( ",," ); aPos != -1; aPos = aStr.Search( ",," ) )
1562 aStr.Remove( aPos, 2 );
1564 TCollection_AsciiString tmpStr = aStr.Token( ",", 1 );
1566 while ( tmpStr != "" )
1568 tmpStr = aStr.Token( ",", i++ );
1569 int aPos = tmpStr.Search( '-' );
1573 if ( tmpStr.IsIntegerValue() )
1574 myIds.Add( tmpStr.IntegerValue() );
1580 TCollection_AsciiString aMaxStr = tmpStr.Split( aPos );
1581 TCollection_AsciiString aMinStr = tmpStr;
1583 while ( aMinStr.Search( "-" ) != -1 ) aMinStr.RemoveAll( '-' );
1584 while ( aMaxStr.Search( "-" ) != -1 ) aMaxStr.RemoveAll( '-' );
1586 if ( !aMinStr.IsEmpty() && !aMinStr.IsIntegerValue() ||
1587 !aMaxStr.IsEmpty() && !aMaxStr.IsIntegerValue() )
1590 myMin.Append( aMinStr.IsEmpty() ? IntegerFirst() : aMinStr.IntegerValue() );
1591 myMax.Append( aMaxStr.IsEmpty() ? IntegerLast() : aMaxStr.IntegerValue() );
1598 //=======================================================================
1600 // Purpose : Get type of supported entities
1601 //=======================================================================
1602 SMDSAbs_ElementType RangeOfIds::GetType() const
1607 //=======================================================================
1609 // Purpose : Set type of supported entities
1610 //=======================================================================
1611 void RangeOfIds::SetType( SMDSAbs_ElementType theType )
1616 //=======================================================================
1618 // Purpose : Verify whether entity satisfies to this rpedicate
1619 //=======================================================================
1620 bool RangeOfIds::IsSatisfy( long theId )
1625 if ( myType == SMDSAbs_Node )
1627 if ( myMesh->FindNode( theId ) == 0 )
1632 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
1633 if ( anElem == 0 || myType != anElem->GetType() && myType != SMDSAbs_All )
1637 if ( myIds.Contains( theId ) )
1640 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
1641 if ( theId >= myMin( i ) && theId <= myMax( i ) )
1649 Description : Base class for comparators
1651 Comparator::Comparator():
1655 Comparator::~Comparator()
1658 void Comparator::SetMesh( const SMDS_Mesh* theMesh )
1661 myFunctor->SetMesh( theMesh );
1664 void Comparator::SetMargin( double theValue )
1666 myMargin = theValue;
1669 void Comparator::SetNumFunctor( NumericalFunctorPtr theFunct )
1671 myFunctor = theFunct;
1674 SMDSAbs_ElementType Comparator::GetType() const
1676 return myFunctor ? myFunctor->GetType() : SMDSAbs_All;
1679 double Comparator::GetMargin()
1687 Description : Comparator "<"
1689 bool LessThan::IsSatisfy( long theId )
1691 return myFunctor && myFunctor->GetValue( theId ) < myMargin;
1697 Description : Comparator ">"
1699 bool MoreThan::IsSatisfy( long theId )
1701 return myFunctor && myFunctor->GetValue( theId ) > myMargin;
1707 Description : Comparator "="
1710 myToler(Precision::Confusion())
1713 bool EqualTo::IsSatisfy( long theId )
1715 return myFunctor && fabs( myFunctor->GetValue( theId ) - myMargin ) < myToler;
1718 void EqualTo::SetTolerance( double theToler )
1723 double EqualTo::GetTolerance()
1730 Description : Logical NOT predicate
1732 LogicalNOT::LogicalNOT()
1735 LogicalNOT::~LogicalNOT()
1738 bool LogicalNOT::IsSatisfy( long theId )
1740 return myPredicate && !myPredicate->IsSatisfy( theId );
1743 void LogicalNOT::SetMesh( const SMDS_Mesh* theMesh )
1746 myPredicate->SetMesh( theMesh );
1749 void LogicalNOT::SetPredicate( PredicatePtr thePred )
1751 myPredicate = thePred;
1754 SMDSAbs_ElementType LogicalNOT::GetType() const
1756 return myPredicate ? myPredicate->GetType() : SMDSAbs_All;
1761 Class : LogicalBinary
1762 Description : Base class for binary logical predicate
1764 LogicalBinary::LogicalBinary()
1767 LogicalBinary::~LogicalBinary()
1770 void LogicalBinary::SetMesh( const SMDS_Mesh* theMesh )
1773 myPredicate1->SetMesh( theMesh );
1776 myPredicate2->SetMesh( theMesh );
1779 void LogicalBinary::SetPredicate1( PredicatePtr thePredicate )
1781 myPredicate1 = thePredicate;
1784 void LogicalBinary::SetPredicate2( PredicatePtr thePredicate )
1786 myPredicate2 = thePredicate;
1789 SMDSAbs_ElementType LogicalBinary::GetType() const
1791 if ( !myPredicate1 || !myPredicate2 )
1794 SMDSAbs_ElementType aType1 = myPredicate1->GetType();
1795 SMDSAbs_ElementType aType2 = myPredicate2->GetType();
1797 return aType1 == aType2 ? aType1 : SMDSAbs_All;
1803 Description : Logical AND
1805 bool LogicalAND::IsSatisfy( long theId )
1810 myPredicate1->IsSatisfy( theId ) &&
1811 myPredicate2->IsSatisfy( theId );
1817 Description : Logical OR
1819 bool LogicalOR::IsSatisfy( long theId )
1824 myPredicate1->IsSatisfy( theId ) ||
1825 myPredicate2->IsSatisfy( theId );
1839 void Filter::SetPredicate( PredicatePtr thePredicate )
1841 myPredicate = thePredicate;
1844 template<class TElement, class TIterator, class TPredicate>
1845 inline void FillSequence(const TIterator& theIterator,
1846 TPredicate& thePredicate,
1847 Filter::TIdSequence& theSequence)
1849 if ( theIterator ) {
1850 while( theIterator->more() ) {
1851 TElement anElem = theIterator->next();
1852 long anId = anElem->GetID();
1853 if ( thePredicate->IsSatisfy( anId ) )
1854 theSequence.push_back( anId );
1861 GetElementsId( const SMDS_Mesh* theMesh,
1862 PredicatePtr thePredicate,
1863 TIdSequence& theSequence )
1865 theSequence.clear();
1867 if ( !theMesh || !thePredicate )
1870 thePredicate->SetMesh( theMesh );
1872 SMDSAbs_ElementType aType = thePredicate->GetType();
1875 FillSequence<const SMDS_MeshNode*>(theMesh->nodesIterator(),thePredicate,theSequence);
1878 FillSequence<const SMDS_MeshElement*>(theMesh->edgesIterator(),thePredicate,theSequence);
1881 FillSequence<const SMDS_MeshElement*>(theMesh->facesIterator(),thePredicate,theSequence);
1883 case SMDSAbs_Volume:
1884 FillSequence<const SMDS_MeshElement*>(theMesh->volumesIterator(),thePredicate,theSequence);
1887 FillSequence<const SMDS_MeshElement*>(theMesh->edgesIterator(),thePredicate,theSequence);
1888 FillSequence<const SMDS_MeshElement*>(theMesh->facesIterator(),thePredicate,theSequence);
1889 FillSequence<const SMDS_MeshElement*>(theMesh->volumesIterator(),thePredicate,theSequence);
1895 Filter::GetElementsId( const SMDS_Mesh* theMesh,
1896 Filter::TIdSequence& theSequence )
1898 GetElementsId(theMesh,myPredicate,theSequence);
1905 typedef std::set<SMDS_MeshFace*> TMapOfFacePtr;
1911 ManifoldPart::Link::Link( SMDS_MeshNode* theNode1,
1912 SMDS_MeshNode* theNode2 )
1918 ManifoldPart::Link::~Link()
1924 bool ManifoldPart::Link::IsEqual( const ManifoldPart::Link& theLink ) const
1926 if ( myNode1 == theLink.myNode1 &&
1927 myNode2 == theLink.myNode2 )
1929 else if ( myNode1 == theLink.myNode2 &&
1930 myNode2 == theLink.myNode1 )
1936 bool ManifoldPart::Link::operator<( const ManifoldPart::Link& x ) const
1938 if(myNode1 < x.myNode1) return true;
1939 if(myNode1 == x.myNode1)
1940 if(myNode2 < x.myNode2) return true;
1944 bool ManifoldPart::IsEqual( const ManifoldPart::Link& theLink1,
1945 const ManifoldPart::Link& theLink2 )
1947 return theLink1.IsEqual( theLink2 );
1950 ManifoldPart::ManifoldPart()
1953 myAngToler = Precision::Angular();
1954 myIsOnlyManifold = true;
1957 ManifoldPart::~ManifoldPart()
1962 void ManifoldPart::SetMesh( const SMDS_Mesh* theMesh )
1968 SMDSAbs_ElementType ManifoldPart::GetType() const
1969 { return SMDSAbs_Face; }
1971 bool ManifoldPart::IsSatisfy( long theElementId )
1973 return myMapIds.Contains( theElementId );
1976 void ManifoldPart::SetAngleTolerance( const double theAngToler )
1977 { myAngToler = theAngToler; }
1979 double ManifoldPart::GetAngleTolerance() const
1980 { return myAngToler; }
1982 void ManifoldPart::SetIsOnlyManifold( const bool theIsOnly )
1983 { myIsOnlyManifold = theIsOnly; }
1985 void ManifoldPart::SetStartElem( const long theStartId )
1986 { myStartElemId = theStartId; }
1988 bool ManifoldPart::process()
1991 myMapBadGeomIds.Clear();
1993 myAllFacePtr.clear();
1994 myAllFacePtrIntDMap.clear();
1998 // collect all faces into own map
1999 SMDS_FaceIteratorPtr anFaceItr = myMesh->facesIterator();
2000 for (; anFaceItr->more(); )
2002 SMDS_MeshFace* aFacePtr = (SMDS_MeshFace*)anFaceItr->next();
2003 myAllFacePtr.push_back( aFacePtr );
2004 myAllFacePtrIntDMap[aFacePtr] = myAllFacePtr.size()-1;
2007 SMDS_MeshFace* aStartFace = (SMDS_MeshFace*)myMesh->FindElement( myStartElemId );
2011 // the map of non manifold links and bad geometry
2012 TMapOfLink aMapOfNonManifold;
2013 TColStd_MapOfInteger aMapOfTreated;
2015 // begin cycle on faces from start index and run on vector till the end
2016 // and from begin to start index to cover whole vector
2017 const int aStartIndx = myAllFacePtrIntDMap[aStartFace];
2018 bool isStartTreat = false;
2019 for ( int fi = aStartIndx; !isStartTreat || fi != aStartIndx ; fi++ )
2021 if ( fi == aStartIndx )
2022 isStartTreat = true;
2023 // as result next time when fi will be equal to aStartIndx
2025 SMDS_MeshFace* aFacePtr = myAllFacePtr[ fi ];
2026 if ( aMapOfTreated.Contains( aFacePtr->GetID() ) )
2029 aMapOfTreated.Add( aFacePtr->GetID() );
2030 TColStd_MapOfInteger aResFaces;
2031 if ( !findConnected( myAllFacePtrIntDMap, aFacePtr,
2032 aMapOfNonManifold, aResFaces ) )
2034 TColStd_MapIteratorOfMapOfInteger anItr( aResFaces );
2035 for ( ; anItr.More(); anItr.Next() )
2037 int aFaceId = anItr.Key();
2038 aMapOfTreated.Add( aFaceId );
2039 myMapIds.Add( aFaceId );
2042 if ( fi == ( myAllFacePtr.size() - 1 ) )
2044 } // end run on vector of faces
2045 return !myMapIds.IsEmpty();
2048 static void getLinks( const SMDS_MeshFace* theFace,
2049 ManifoldPart::TVectorOfLink& theLinks )
2051 int aNbNode = theFace->NbNodes();
2052 SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
2054 SMDS_MeshNode* aNode = 0;
2055 for ( ; aNodeItr->more() && i <= aNbNode; )
2058 SMDS_MeshNode* aN1 = (SMDS_MeshNode*)aNodeItr->next();
2062 SMDS_MeshNode* aN2 = ( i >= aNbNode ) ? aNode : (SMDS_MeshNode*)aNodeItr->next();
2064 ManifoldPart::Link aLink( aN1, aN2 );
2065 theLinks.push_back( aLink );
2069 static gp_XYZ getNormale( const SMDS_MeshFace* theFace )
2072 int aNbNode = theFace->NbNodes();
2073 TColgp_Array1OfXYZ anArrOfXYZ(1,4);
2074 SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
2076 for ( ; aNodeItr->more() && i <= 4; i++ )
2078 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
2079 anArrOfXYZ.SetValue(i, gp_XYZ( aNode->X(), aNode->Y(), aNode->Z() ) );
2082 gp_XYZ q1 = anArrOfXYZ.Value(2) - anArrOfXYZ.Value(1);
2083 gp_XYZ q2 = anArrOfXYZ.Value(3) - anArrOfXYZ.Value(1);
2087 gp_XYZ q3 = anArrOfXYZ.Value(4) - anArrOfXYZ.Value(1);
2090 double len = n.Modulus();
2097 bool ManifoldPart::findConnected
2098 ( const ManifoldPart::TDataMapFacePtrInt& theAllFacePtrInt,
2099 SMDS_MeshFace* theStartFace,
2100 ManifoldPart::TMapOfLink& theNonManifold,
2101 TColStd_MapOfInteger& theResFaces )
2103 theResFaces.Clear();
2104 if ( !theAllFacePtrInt.size() )
2107 if ( getNormale( theStartFace ).SquareModulus() <= gp::Resolution() )
2109 myMapBadGeomIds.Add( theStartFace->GetID() );
2113 ManifoldPart::TMapOfLink aMapOfBoundary, aMapToSkip;
2114 ManifoldPart::TVectorOfLink aSeqOfBoundary;
2115 theResFaces.Add( theStartFace->GetID() );
2116 ManifoldPart::TDataMapOfLinkFacePtr aDMapLinkFace;
2118 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
2119 aDMapLinkFace, theNonManifold, theStartFace );
2121 bool isDone = false;
2122 while ( !isDone && aMapOfBoundary.size() != 0 )
2124 bool isToReset = false;
2125 ManifoldPart::TVectorOfLink::iterator pLink = aSeqOfBoundary.begin();
2126 for ( ; !isToReset && pLink != aSeqOfBoundary.end(); ++pLink )
2128 ManifoldPart::Link aLink = *pLink;
2129 if ( aMapToSkip.find( aLink ) != aMapToSkip.end() )
2131 // each link could be treated only once
2132 aMapToSkip.insert( aLink );
2134 ManifoldPart::TVectorOfFacePtr aFaces;
2136 if ( myIsOnlyManifold &&
2137 (theNonManifold.find( aLink ) != theNonManifold.end()) )
2141 getFacesByLink( aLink, aFaces );
2142 // filter the element to keep only indicated elements
2143 ManifoldPart::TVectorOfFacePtr aFiltered;
2144 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
2145 for ( ; pFace != aFaces.end(); ++pFace )
2147 SMDS_MeshFace* aFace = *pFace;
2148 if ( myAllFacePtrIntDMap.find( aFace ) != myAllFacePtrIntDMap.end() )
2149 aFiltered.push_back( aFace );
2152 if ( aFaces.size() < 2 ) // no neihgbour faces
2154 else if ( myIsOnlyManifold && aFaces.size() > 2 ) // non manifold case
2156 theNonManifold.insert( aLink );
2161 // compare normal with normals of neighbor element
2162 SMDS_MeshFace* aPrevFace = aDMapLinkFace[ aLink ];
2163 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
2164 for ( ; pFace != aFaces.end(); ++pFace )
2166 SMDS_MeshFace* aNextFace = *pFace;
2167 if ( aPrevFace == aNextFace )
2169 int anNextFaceID = aNextFace->GetID();
2170 if ( myIsOnlyManifold && theResFaces.Contains( anNextFaceID ) )
2171 // should not be with non manifold restriction. probably bad topology
2173 // check if face was treated and skipped
2174 if ( myMapBadGeomIds.Contains( anNextFaceID ) ||
2175 !isInPlane( aPrevFace, aNextFace ) )
2177 // add new element to connected and extend the boundaries.
2178 theResFaces.Add( anNextFaceID );
2179 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
2180 aDMapLinkFace, theNonManifold, aNextFace );
2184 isDone = !isToReset;
2187 return !theResFaces.IsEmpty();
2190 bool ManifoldPart::isInPlane( const SMDS_MeshFace* theFace1,
2191 const SMDS_MeshFace* theFace2 )
2193 gp_Dir aNorm1 = gp_Dir( getNormale( theFace1 ) );
2194 gp_XYZ aNorm2XYZ = getNormale( theFace2 );
2195 if ( aNorm2XYZ.SquareModulus() <= gp::Resolution() )
2197 myMapBadGeomIds.Add( theFace2->GetID() );
2200 if ( aNorm1.IsParallel( gp_Dir( aNorm2XYZ ), myAngToler ) )
2206 void ManifoldPart::expandBoundary
2207 ( ManifoldPart::TMapOfLink& theMapOfBoundary,
2208 ManifoldPart::TVectorOfLink& theSeqOfBoundary,
2209 ManifoldPart::TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
2210 ManifoldPart::TMapOfLink& theNonManifold,
2211 SMDS_MeshFace* theNextFace ) const
2213 ManifoldPart::TVectorOfLink aLinks;
2214 getLinks( theNextFace, aLinks );
2215 int aNbLink = (int)aLinks.size();
2216 for ( int i = 0; i < aNbLink; i++ )
2218 ManifoldPart::Link aLink = aLinks[ i ];
2219 if ( myIsOnlyManifold && (theNonManifold.find( aLink ) != theNonManifold.end()) )
2221 if ( theMapOfBoundary.find( aLink ) != theMapOfBoundary.end() )
2223 if ( myIsOnlyManifold )
2225 // remove from boundary
2226 theMapOfBoundary.erase( aLink );
2227 ManifoldPart::TVectorOfLink::iterator pLink = theSeqOfBoundary.begin();
2228 for ( ; pLink != theSeqOfBoundary.end(); ++pLink )
2230 ManifoldPart::Link aBoundLink = *pLink;
2231 if ( aBoundLink.IsEqual( aLink ) )
2233 theSeqOfBoundary.erase( pLink );
2241 theMapOfBoundary.insert( aLink );
2242 theSeqOfBoundary.push_back( aLink );
2243 theDMapLinkFacePtr[ aLink ] = theNextFace;
2248 void ManifoldPart::getFacesByLink( const ManifoldPart::Link& theLink,
2249 ManifoldPart::TVectorOfFacePtr& theFaces ) const
2251 SMDS_Mesh::SetOfFaces aSetOfFaces;
2252 // take all faces that shared first node
2253 SMDS_ElemIteratorPtr anItr = theLink.myNode1->facesIterator();
2254 for ( ; anItr->more(); )
2256 SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
2259 aSetOfFaces.Add( aFace );
2261 // take all faces that shared second node
2262 anItr = theLink.myNode2->facesIterator();
2263 // find the common part of two sets
2264 for ( ; anItr->more(); )
2266 SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
2267 if ( aSetOfFaces.Contains( aFace ) )
2268 theFaces.push_back( aFace );
2277 ElementsOnSurface::ElementsOnSurface()
2281 myType = SMDSAbs_All;
2283 myToler = Precision::Confusion();
2286 ElementsOnSurface::~ElementsOnSurface()
2291 void ElementsOnSurface::SetMesh( const SMDS_Mesh* theMesh )
2293 if ( myMesh == theMesh )
2300 bool ElementsOnSurface::IsSatisfy( long theElementId )
2302 return myIds.Contains( theElementId );
2305 SMDSAbs_ElementType ElementsOnSurface::GetType() const
2308 void ElementsOnSurface::SetTolerance( const double theToler )
2309 { myToler = theToler; }
2311 double ElementsOnSurface::GetTolerance() const
2316 void ElementsOnSurface::SetSurface( const TopoDS_Shape& theShape,
2317 const SMDSAbs_ElementType theType )
2321 if ( theShape.IsNull() || theShape.ShapeType() != TopAbs_FACE )
2326 TopoDS_Face aFace = TopoDS::Face( theShape );
2327 mySurf = BRep_Tool::Surface( aFace );
2330 void ElementsOnSurface::process()
2333 if ( mySurf.IsNull() )
2339 if ( myType == SMDSAbs_Face || myType == SMDSAbs_All )
2341 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
2342 for(; anIter->more(); )
2343 process( anIter->next() );
2346 if ( myType == SMDSAbs_Edge || myType == SMDSAbs_All )
2348 SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
2349 for(; anIter->more(); )
2350 process( anIter->next() );
2353 if ( myType == SMDSAbs_Node )
2355 SMDS_NodeIteratorPtr anIter = myMesh->nodesIterator();
2356 for(; anIter->more(); )
2357 process( anIter->next() );
2361 void ElementsOnSurface::process( const SMDS_MeshElement* theElemPtr )
2363 SMDS_ElemIteratorPtr aNodeItr = theElemPtr->nodesIterator();
2364 bool isSatisfy = true;
2365 for ( ; aNodeItr->more(); )
2367 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
2368 if ( !isOnSurface( aNode ) )
2375 myIds.Add( theElemPtr->GetID() );
2378 bool ElementsOnSurface::isOnSurface( const SMDS_MeshNode* theNode ) const
2380 if ( mySurf.IsNull() )
2383 gp_Pnt aPnt( theNode->X(), theNode->Y(), theNode->Z() );
2384 double aToler2 = myToler * myToler;
2385 if ( mySurf->IsKind(STANDARD_TYPE(Geom_Plane)))
2387 gp_Pln aPln = Handle(Geom_Plane)::DownCast(mySurf)->Pln();
2388 if ( aPln.SquareDistance( aPnt ) > aToler2 )
2391 else if ( mySurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)))
2393 gp_Cylinder aCyl = Handle(Geom_CylindricalSurface)::DownCast(mySurf)->Cylinder();
2394 double aRad = aCyl.Radius();
2395 gp_Ax3 anAxis = aCyl.Position();
2396 gp_XYZ aLoc = aCyl.Location().XYZ();
2397 double aXDist = anAxis.XDirection().XYZ() * ( aPnt.XYZ() - aLoc );
2398 double aYDist = anAxis.YDirection().XYZ() * ( aPnt.XYZ() - aLoc );
2399 if ( fabs(aXDist*aXDist + aYDist*aYDist - aRad*aRad) > aToler2 )