1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #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"
49 #include "SMDS_QuadraticFaceOfNodes.hxx"
50 #include "SMDS_QuadraticEdge.hxx"
58 inline double getAngle( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
60 gp_Vec v1( P1 - P2 ), v2( P3 - P2 );
62 return v1.Magnitude() < gp::Resolution() ||
63 v2.Magnitude() < gp::Resolution() ? 0 : v1.Angle( v2 );
66 inline double getArea( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
68 gp_Vec aVec1( P2 - P1 );
69 gp_Vec aVec2( P3 - P1 );
70 return ( aVec1 ^ aVec2 ).Magnitude() * 0.5;
73 inline double getArea( const gp_Pnt& P1, const gp_Pnt& P2, const gp_Pnt& P3 )
75 return getArea( P1.XYZ(), P2.XYZ(), P3.XYZ() );
80 inline double getDistance( const gp_XYZ& P1, const gp_XYZ& P2 )
82 double aDist = gp_Pnt( P1 ).Distance( gp_Pnt( P2 ) );
86 int getNbMultiConnection( const SMDS_Mesh* theMesh, const int theId )
91 const SMDS_MeshElement* anEdge = theMesh->FindElement( theId );
92 if ( anEdge == 0 || anEdge->GetType() != SMDSAbs_Edge/* || anEdge->NbNodes() != 2 */)
95 // for each pair of nodes in anEdge (there are 2 pairs in a quadratic edge)
96 // count elements containing both nodes of the pair.
97 // Note that there may be such cases for a quadratic edge (a horizontal line):
102 // +-----+------+ +-----+------+
105 // result sould be 2 in both cases
107 int aResult0 = 0, aResult1 = 0;
108 // last node, it is a medium one in a quadratic edge
109 const SMDS_MeshNode* aLastNode = anEdge->GetNode( anEdge->NbNodes() - 1 );
110 const SMDS_MeshNode* aNode0 = anEdge->GetNode( 0 );
111 const SMDS_MeshNode* aNode1 = anEdge->GetNode( 1 );
112 if ( aNode1 == aLastNode ) aNode1 = 0;
114 SMDS_ElemIteratorPtr anElemIter = aLastNode->GetInverseElementIterator();
115 while( anElemIter->more() ) {
116 const SMDS_MeshElement* anElem = anElemIter->next();
117 if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) {
118 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
119 while ( anIter->more() ) {
120 if ( const SMDS_MeshElement* anElemNode = anIter->next() ) {
121 if ( anElemNode == aNode0 ) {
123 if ( !aNode1 ) break; // not a quadratic edge
125 else if ( anElemNode == aNode1 )
131 int aResult = max ( aResult0, aResult1 );
133 // TColStd_MapOfInteger aMap;
135 // SMDS_ElemIteratorPtr anIter = anEdge->nodesIterator();
136 // if ( anIter != 0 ) {
137 // while( anIter->more() ) {
138 // const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next();
141 // SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator();
142 // while( anElemIter->more() ) {
143 // const SMDS_MeshElement* anElem = anElemIter->next();
144 // if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) {
145 // int anId = anElem->GetID();
147 // if ( anIter->more() ) // i.e. first node
149 // else if ( aMap.Contains( anId ) )
163 using namespace SMESH::Controls;
170 Class : NumericalFunctor
171 Description : Base class for numerical functors
173 NumericalFunctor::NumericalFunctor():
179 void NumericalFunctor::SetMesh( const SMDS_Mesh* theMesh )
184 bool NumericalFunctor::GetPoints(const int theId,
185 TSequenceOfXYZ& theRes ) const
192 return GetPoints( myMesh->FindElement( theId ), theRes );
195 bool NumericalFunctor::GetPoints(const SMDS_MeshElement* anElem,
196 TSequenceOfXYZ& theRes )
203 theRes.reserve( anElem->NbNodes() );
205 // Get nodes of the element
206 SMDS_ElemIteratorPtr anIter;
208 if ( anElem->IsQuadratic() ) {
209 switch ( anElem->GetType() ) {
211 anIter = static_cast<const SMDS_QuadraticEdge*>
212 (anElem)->interlacedNodesElemIterator();
215 anIter = static_cast<const SMDS_QuadraticFaceOfNodes*>
216 (anElem)->interlacedNodesElemIterator();
219 anIter = anElem->nodesIterator();
224 anIter = anElem->nodesIterator();
228 while( anIter->more() ) {
229 if ( const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>( anIter->next() ))
230 theRes.push_back( gp_XYZ( aNode->X(), aNode->Y(), aNode->Z() ) );
237 long NumericalFunctor::GetPrecision() const
242 void NumericalFunctor::SetPrecision( const long thePrecision )
244 myPrecision = thePrecision;
247 double NumericalFunctor::GetValue( long theId )
249 myCurrElement = myMesh->FindElement( theId );
251 if ( GetPoints( theId, P ))
253 double aVal = GetValue( P );
254 if ( myPrecision >= 0 )
256 double prec = pow( 10., (double)( myPrecision ) );
257 aVal = floor( aVal * prec + 0.5 ) / prec;
265 //=======================================================================
266 //function : GetValue
268 //=======================================================================
270 double Volume::GetValue( long theElementId )
272 if ( theElementId && myMesh ) {
273 SMDS_VolumeTool aVolumeTool;
274 if ( aVolumeTool.Set( myMesh->FindElement( theElementId )))
275 return aVolumeTool.GetSize();
280 //=======================================================================
281 //function : GetBadRate
282 //purpose : meaningless as it is not quality control functor
283 //=======================================================================
285 double Volume::GetBadRate( double Value, int /*nbNodes*/ ) const
290 //=======================================================================
293 //=======================================================================
295 SMDSAbs_ElementType Volume::GetType() const
297 return SMDSAbs_Volume;
303 Description : Functor for calculation of minimum angle
306 double MinimumAngle::GetValue( const TSequenceOfXYZ& P )
313 aMin = getAngle(P( P.size() ), P( 1 ), P( 2 ));
314 aMin = Min(aMin,getAngle(P( P.size()-1 ), P( P.size() ), P( 1 )));
316 for (int i=2; i<P.size();i++){
317 double A0 = getAngle( P( i-1 ), P( i ), P( i+1 ) );
321 return aMin * 180.0 / PI;
324 double MinimumAngle::GetBadRate( double Value, int nbNodes ) const
326 //const double aBestAngle = PI / nbNodes;
327 const double aBestAngle = 180.0 - ( 360.0 / double(nbNodes) );
328 return ( fabs( aBestAngle - Value ));
331 SMDSAbs_ElementType MinimumAngle::GetType() const
339 Description : Functor for calculating aspect ratio
341 double AspectRatio::GetValue( const TSequenceOfXYZ& P )
343 // According to "Mesh quality control" by Nadir Bouhamau referring to
344 // Pascal Jean Frey and Paul-Louis George. Maillages, applications aux elements finis.
345 // Hermes Science publications, Paris 1999 ISBN 2-7462-0024-4
348 int nbNodes = P.size();
353 // Compute aspect ratio
355 if ( nbNodes == 3 ) {
356 // Compute lengths of the sides
357 vector< double > aLen (nbNodes);
358 for ( int i = 0; i < nbNodes - 1; i++ )
359 aLen[ i ] = getDistance( P( i + 1 ), P( i + 2 ) );
360 aLen[ nbNodes - 1 ] = getDistance( P( 1 ), P( nbNodes ) );
361 // Q = alfa * h * p / S, where
363 // alfa = sqrt( 3 ) / 6
364 // h - length of the longest edge
365 // p - half perimeter
366 // S - triangle surface
367 const double alfa = sqrt( 3. ) / 6.;
368 double maxLen = Max( aLen[ 0 ], Max( aLen[ 1 ], aLen[ 2 ] ) );
369 double half_perimeter = ( aLen[0] + aLen[1] + aLen[2] ) / 2.;
370 double anArea = getArea( P( 1 ), P( 2 ), P( 3 ) );
371 if ( anArea <= Precision::Confusion() )
373 return alfa * maxLen * half_perimeter / anArea;
375 else if ( nbNodes == 6 ) { // quadratic triangles
376 // Compute lengths of the sides
377 vector< double > aLen (3);
378 aLen[0] = getDistance( P(1), P(3) );
379 aLen[1] = getDistance( P(3), P(5) );
380 aLen[2] = getDistance( P(5), P(1) );
381 // Q = alfa * h * p / S, where
383 // alfa = sqrt( 3 ) / 6
384 // h - length of the longest edge
385 // p - half perimeter
386 // S - triangle surface
387 const double alfa = sqrt( 3. ) / 6.;
388 double maxLen = Max( aLen[ 0 ], Max( aLen[ 1 ], aLen[ 2 ] ) );
389 double half_perimeter = ( aLen[0] + aLen[1] + aLen[2] ) / 2.;
390 double anArea = getArea( P(1), P(3), P(5) );
391 if ( anArea <= Precision::Confusion() )
393 return alfa * maxLen * half_perimeter / anArea;
395 else if( nbNodes == 4 ) { // quadrangle
396 // return aspect ratio of the worst triange which can be built
397 // taking three nodes of the quadrangle
398 TSequenceOfXYZ triaPnts(3);
399 // triangle on nodes 1 3 2
403 double ar = GetValue( triaPnts );
404 // triangle on nodes 1 3 4
406 ar = Max ( ar, GetValue( triaPnts ));
407 // triangle on nodes 1 2 4
409 ar = Max ( ar, GetValue( triaPnts ));
410 // triangle on nodes 3 2 4
412 ar = Max ( ar, GetValue( triaPnts ));
416 else { // nbNodes==8 - quadratic quadrangle
417 // return aspect ratio of the worst triange which can be built
418 // taking three nodes of the quadrangle
419 TSequenceOfXYZ triaPnts(3);
420 // triangle on nodes 1 3 2
424 double ar = GetValue( triaPnts );
425 // triangle on nodes 1 3 4
427 ar = Max ( ar, GetValue( triaPnts ));
428 // triangle on nodes 1 2 4
430 ar = Max ( ar, GetValue( triaPnts ));
431 // triangle on nodes 3 2 4
433 ar = Max ( ar, GetValue( triaPnts ));
439 double AspectRatio::GetBadRate( double Value, int /*nbNodes*/ ) const
441 // the aspect ratio is in the range [1.0,infinity]
444 return Value / 1000.;
447 SMDSAbs_ElementType AspectRatio::GetType() const
454 Class : AspectRatio3D
455 Description : Functor for calculating aspect ratio
459 inline double getHalfPerimeter(double theTria[3]){
460 return (theTria[0] + theTria[1] + theTria[2])/2.0;
463 inline double getArea(double theHalfPerim, double theTria[3]){
464 return sqrt(theHalfPerim*
465 (theHalfPerim-theTria[0])*
466 (theHalfPerim-theTria[1])*
467 (theHalfPerim-theTria[2]));
470 inline double getVolume(double theLen[6]){
471 double a2 = theLen[0]*theLen[0];
472 double b2 = theLen[1]*theLen[1];
473 double c2 = theLen[2]*theLen[2];
474 double d2 = theLen[3]*theLen[3];
475 double e2 = theLen[4]*theLen[4];
476 double f2 = theLen[5]*theLen[5];
477 double P = 4.0*a2*b2*d2;
478 double Q = a2*(b2+d2-e2)-b2*(a2+d2-f2)-d2*(a2+b2-c2);
479 double R = (b2+d2-e2)*(a2+d2-f2)*(a2+d2-f2);
480 return sqrt(P-Q+R)/12.0;
483 inline double getVolume2(double theLen[6]){
484 double a2 = theLen[0]*theLen[0];
485 double b2 = theLen[1]*theLen[1];
486 double c2 = theLen[2]*theLen[2];
487 double d2 = theLen[3]*theLen[3];
488 double e2 = theLen[4]*theLen[4];
489 double f2 = theLen[5]*theLen[5];
491 double P = a2*e2*(b2+c2+d2+f2-a2-e2);
492 double Q = b2*f2*(a2+c2+d2+e2-b2-f2);
493 double R = c2*d2*(a2+b2+e2+f2-c2-d2);
494 double S = a2*b2*d2+b2*c2*e2+a2*c2*f2+d2*e2*f2;
496 return sqrt(P+Q+R-S)/12.0;
499 inline double getVolume(const TSequenceOfXYZ& P){
500 gp_Vec aVec1( P( 2 ) - P( 1 ) );
501 gp_Vec aVec2( P( 3 ) - P( 1 ) );
502 gp_Vec aVec3( P( 4 ) - P( 1 ) );
503 gp_Vec anAreaVec( aVec1 ^ aVec2 );
504 return fabs(aVec3 * anAreaVec) / 6.0;
507 inline double getMaxHeight(double theLen[6])
509 double aHeight = max(theLen[0],theLen[1]);
510 aHeight = max(aHeight,theLen[2]);
511 aHeight = max(aHeight,theLen[3]);
512 aHeight = max(aHeight,theLen[4]);
513 aHeight = max(aHeight,theLen[5]);
519 double AspectRatio3D::GetValue( const TSequenceOfXYZ& P )
521 double aQuality = 0.0;
522 if(myCurrElement->IsPoly()) return aQuality;
523 int nbNodes = P.size();
527 getDistance(P( 1 ),P( 2 )), // a
528 getDistance(P( 2 ),P( 3 )), // b
529 getDistance(P( 3 ),P( 1 )), // c
530 getDistance(P( 2 ),P( 4 )), // d
531 getDistance(P( 3 ),P( 4 )), // e
532 getDistance(P( 1 ),P( 4 )) // f
534 double aTria[4][3] = {
535 {aLen[0],aLen[1],aLen[2]}, // abc
536 {aLen[0],aLen[3],aLen[5]}, // adf
537 {aLen[1],aLen[3],aLen[4]}, // bde
538 {aLen[2],aLen[4],aLen[5]} // cef
540 double aSumArea = 0.0;
541 double aHalfPerimeter = getHalfPerimeter(aTria[0]);
542 double anArea = getArea(aHalfPerimeter,aTria[0]);
544 aHalfPerimeter = getHalfPerimeter(aTria[1]);
545 anArea = getArea(aHalfPerimeter,aTria[1]);
547 aHalfPerimeter = getHalfPerimeter(aTria[2]);
548 anArea = getArea(aHalfPerimeter,aTria[2]);
550 aHalfPerimeter = getHalfPerimeter(aTria[3]);
551 anArea = getArea(aHalfPerimeter,aTria[3]);
553 double aVolume = getVolume(P);
554 //double aVolume = getVolume(aLen);
555 double aHeight = getMaxHeight(aLen);
556 static double aCoeff = sqrt(2.0)/12.0;
557 aQuality = aCoeff*aHeight*aSumArea/aVolume;
562 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 3 ),P( 5 )};
563 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
566 gp_XYZ aXYZ[4] = {P( 1 ),P( 3 ),P( 4 ),P( 5 )};
567 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
570 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 5 )};
571 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
574 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 4 ),P( 5 )};
575 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
581 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 6 )};
582 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
585 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 3 )};
586 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
589 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 6 )};
590 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
593 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
594 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
597 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 6 )};
598 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
601 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 3 )};
602 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
608 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
609 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
612 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 4 )};
613 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
616 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 7 )};
617 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
620 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 8 )};
621 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
624 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 3 )};
625 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
628 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 4 )};
629 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
632 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 7 )};
633 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
636 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 8 )};
637 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
640 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 3 )};
641 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
644 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 4 )};
645 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
648 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 7 )};
649 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
652 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 8 )};
653 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
656 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 1 )};
657 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
660 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 2 )};
661 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
664 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 5 )};
665 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
668 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 6 )};
669 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
672 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 1 )};
673 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
676 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 2 )};
677 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
680 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 5 )};
681 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
684 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 6 )};
685 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
688 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 1 )};
689 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
692 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
693 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
696 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 5 )};
697 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
700 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 6 )};
701 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
704 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
705 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
708 gp_XYZ aXYZ[4] = {P( 4 ),P( 5 ),P( 8 ),P( 2 )};
709 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
712 gp_XYZ aXYZ[4] = {P( 1 ),P( 4 ),P( 5 ),P( 3 )};
713 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
716 gp_XYZ aXYZ[4] = {P( 3 ),P( 6 ),P( 7 ),P( 1 )};
717 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
720 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 6 ),P( 4 )};
721 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
724 gp_XYZ aXYZ[4] = {P( 5 ),P( 6 ),P( 8 ),P( 3 )};
725 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
728 gp_XYZ aXYZ[4] = {P( 7 ),P( 8 ),P( 6 ),P( 1 )};
729 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
732 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 7 )};
733 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
736 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 2 ),P( 5 )};
737 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
743 // avaluate aspect ratio of quadranle faces
744 AspectRatio aspect2D;
745 SMDS_VolumeTool::VolumeType type = SMDS_VolumeTool::GetType( nbNodes );
746 int nbFaces = SMDS_VolumeTool::NbFaces( type );
747 TSequenceOfXYZ points(4);
748 for ( int i = 0; i < nbFaces; ++i ) { // loop on faces of a volume
749 if ( SMDS_VolumeTool::NbFaceNodes( type, i ) != 4 )
751 const int* pInd = SMDS_VolumeTool::GetFaceNodesIndices( type, i, true );
752 for ( int p = 0; p < 4; ++p ) // loop on nodes of a quadranle face
753 points( p + 1 ) = P( pInd[ p ] + 1 );
754 aQuality = max( aQuality, aspect2D.GetValue( points ));
760 double AspectRatio3D::GetBadRate( double Value, int /*nbNodes*/ ) const
762 // the aspect ratio is in the range [1.0,infinity]
765 return Value / 1000.;
768 SMDSAbs_ElementType AspectRatio3D::GetType() const
770 return SMDSAbs_Volume;
776 Description : Functor for calculating warping
778 double Warping::GetValue( const TSequenceOfXYZ& P )
783 gp_XYZ G = ( P( 1 ) + P( 2 ) + P( 3 ) + P( 4 ) ) / 4;
785 double A1 = ComputeA( P( 1 ), P( 2 ), P( 3 ), G );
786 double A2 = ComputeA( P( 2 ), P( 3 ), P( 4 ), G );
787 double A3 = ComputeA( P( 3 ), P( 4 ), P( 1 ), G );
788 double A4 = ComputeA( P( 4 ), P( 1 ), P( 2 ), G );
790 return Max( Max( A1, A2 ), Max( A3, A4 ) );
793 double Warping::ComputeA( const gp_XYZ& thePnt1,
794 const gp_XYZ& thePnt2,
795 const gp_XYZ& thePnt3,
796 const gp_XYZ& theG ) const
798 double aLen1 = gp_Pnt( thePnt1 ).Distance( gp_Pnt( thePnt2 ) );
799 double aLen2 = gp_Pnt( thePnt2 ).Distance( gp_Pnt( thePnt3 ) );
800 double L = Min( aLen1, aLen2 ) * 0.5;
801 if ( L < Precision::Confusion())
804 gp_XYZ GI = ( thePnt2 + thePnt1 ) / 2. - theG;
805 gp_XYZ GJ = ( thePnt3 + thePnt2 ) / 2. - theG;
806 gp_XYZ N = GI.Crossed( GJ );
808 if ( N.Modulus() < gp::Resolution() )
813 double H = ( thePnt2 - theG ).Dot( N );
814 return asin( fabs( H / L ) ) * 180 / PI;
817 double Warping::GetBadRate( double Value, int /*nbNodes*/ ) const
819 // the warp is in the range [0.0,PI/2]
820 // 0.0 = good (no warp)
821 // PI/2 = bad (face pliee)
825 SMDSAbs_ElementType Warping::GetType() const
833 Description : Functor for calculating taper
835 double Taper::GetValue( const TSequenceOfXYZ& P )
841 double J1 = getArea( P( 4 ), P( 1 ), P( 2 ) ) / 2;
842 double J2 = getArea( P( 3 ), P( 1 ), P( 2 ) ) / 2;
843 double J3 = getArea( P( 2 ), P( 3 ), P( 4 ) ) / 2;
844 double J4 = getArea( P( 3 ), P( 4 ), P( 1 ) ) / 2;
846 double JA = 0.25 * ( J1 + J2 + J3 + J4 );
847 if ( JA <= Precision::Confusion() )
850 double T1 = fabs( ( J1 - JA ) / JA );
851 double T2 = fabs( ( J2 - JA ) / JA );
852 double T3 = fabs( ( J3 - JA ) / JA );
853 double T4 = fabs( ( J4 - JA ) / JA );
855 return Max( Max( T1, T2 ), Max( T3, T4 ) );
858 double Taper::GetBadRate( double Value, int /*nbNodes*/ ) const
860 // the taper is in the range [0.0,1.0]
861 // 0.0 = good (no taper)
862 // 1.0 = bad (les cotes opposes sont allignes)
866 SMDSAbs_ElementType Taper::GetType() const
874 Description : Functor for calculating skew in degrees
876 static inline double skewAngle( const gp_XYZ& p1, const gp_XYZ& p2, const gp_XYZ& p3 )
878 gp_XYZ p12 = ( p2 + p1 ) / 2;
879 gp_XYZ p23 = ( p3 + p2 ) / 2;
880 gp_XYZ p31 = ( p3 + p1 ) / 2;
882 gp_Vec v1( p31 - p2 ), v2( p12 - p23 );
884 return v1.Magnitude() < gp::Resolution() || v2.Magnitude() < gp::Resolution() ? 0 : v1.Angle( v2 );
887 double Skew::GetValue( const TSequenceOfXYZ& P )
889 if ( P.size() != 3 && P.size() != 4 )
893 static double PI2 = PI / 2;
896 double A0 = fabs( PI2 - skewAngle( P( 3 ), P( 1 ), P( 2 ) ) );
897 double A1 = fabs( PI2 - skewAngle( P( 1 ), P( 2 ), P( 3 ) ) );
898 double A2 = fabs( PI2 - skewAngle( P( 2 ), P( 3 ), P( 1 ) ) );
900 return Max( A0, Max( A1, A2 ) ) * 180 / PI;
904 gp_XYZ p12 = ( P( 1 ) + P( 2 ) ) / 2;
905 gp_XYZ p23 = ( P( 2 ) + P( 3 ) ) / 2;
906 gp_XYZ p34 = ( P( 3 ) + P( 4 ) ) / 2;
907 gp_XYZ p41 = ( P( 4 ) + P( 1 ) ) / 2;
909 gp_Vec v1( p34 - p12 ), v2( p23 - p41 );
910 double A = v1.Magnitude() <= gp::Resolution() || v2.Magnitude() <= gp::Resolution()
911 ? 0 : fabs( PI2 - v1.Angle( v2 ) );
917 double Skew::GetBadRate( double Value, int /*nbNodes*/ ) const
919 // the skew is in the range [0.0,PI/2].
925 SMDSAbs_ElementType Skew::GetType() const
933 Description : Functor for calculating area
935 double Area::GetValue( const TSequenceOfXYZ& P )
937 gp_Vec aVec1( P(2) - P(1) );
938 gp_Vec aVec2( P(3) - P(1) );
939 gp_Vec SumVec = aVec1 ^ aVec2;
940 for (int i=4; i<=P.size(); i++) {
941 gp_Vec aVec1( P(i-1) - P(1) );
942 gp_Vec aVec2( P(i) - P(1) );
943 gp_Vec tmp = aVec1 ^ aVec2;
946 return SumVec.Magnitude() * 0.5;
949 double Area::GetBadRate( double Value, int /*nbNodes*/ ) const
951 // meaningless as it is not a quality control functor
955 SMDSAbs_ElementType Area::GetType() const
963 Description : Functor for calculating length off edge
965 double Length::GetValue( const TSequenceOfXYZ& P )
967 switch ( P.size() ) {
968 case 2: return getDistance( P( 1 ), P( 2 ) );
969 case 3: return getDistance( P( 1 ), P( 2 ) ) + getDistance( P( 2 ), P( 3 ) );
974 double Length::GetBadRate( double Value, int /*nbNodes*/ ) const
976 // meaningless as it is not quality control functor
980 SMDSAbs_ElementType Length::GetType() const
987 Description : Functor for calculating length of edge
990 double Length2D::GetValue( long theElementId)
994 //cout<<"Length2D::GetValue"<<endl;
995 if (GetPoints(theElementId,P)){
996 //for(int jj=1; jj<=P.size(); jj++)
997 // cout<<"jj="<<jj<<" P("<<P(jj).X()<<","<<P(jj).Y()<<","<<P(jj).Z()<<")"<<endl;
999 double aVal;// = GetValue( P );
1000 const SMDS_MeshElement* aElem = myMesh->FindElement( theElementId );
1001 SMDSAbs_ElementType aType = aElem->GetType();
1010 aVal = getDistance( P( 1 ), P( 2 ) );
1013 else if (len == 3){ // quadratic edge
1014 aVal = getDistance(P( 1 ),P( 3 )) + getDistance(P( 3 ),P( 2 ));
1018 if (len == 3){ // triangles
1019 double L1 = getDistance(P( 1 ),P( 2 ));
1020 double L2 = getDistance(P( 2 ),P( 3 ));
1021 double L3 = getDistance(P( 3 ),P( 1 ));
1022 aVal = Max(L1,Max(L2,L3));
1025 else if (len == 4){ // quadrangles
1026 double L1 = getDistance(P( 1 ),P( 2 ));
1027 double L2 = getDistance(P( 2 ),P( 3 ));
1028 double L3 = getDistance(P( 3 ),P( 4 ));
1029 double L4 = getDistance(P( 4 ),P( 1 ));
1030 aVal = Max(Max(L1,L2),Max(L3,L4));
1033 if (len == 6){ // quadratic triangles
1034 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1035 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1036 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 1 ));
1037 aVal = Max(L1,Max(L2,L3));
1038 //cout<<"L1="<<L1<<" L2="<<L2<<"L3="<<L3<<" aVal="<<aVal<<endl;
1041 else if (len == 8){ // quadratic quadrangles
1042 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1043 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1044 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 7 ));
1045 double L4 = getDistance(P( 7 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
1046 aVal = Max(Max(L1,L2),Max(L3,L4));
1049 case SMDSAbs_Volume:
1050 if (len == 4){ // tetraidrs
1051 double L1 = getDistance(P( 1 ),P( 2 ));
1052 double L2 = getDistance(P( 2 ),P( 3 ));
1053 double L3 = getDistance(P( 3 ),P( 1 ));
1054 double L4 = getDistance(P( 1 ),P( 4 ));
1055 double L5 = getDistance(P( 2 ),P( 4 ));
1056 double L6 = getDistance(P( 3 ),P( 4 ));
1057 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1060 else if (len == 5){ // piramids
1061 double L1 = getDistance(P( 1 ),P( 2 ));
1062 double L2 = getDistance(P( 2 ),P( 3 ));
1063 double L3 = getDistance(P( 3 ),P( 1 ));
1064 double L4 = getDistance(P( 4 ),P( 1 ));
1065 double L5 = getDistance(P( 1 ),P( 5 ));
1066 double L6 = getDistance(P( 2 ),P( 5 ));
1067 double L7 = getDistance(P( 3 ),P( 5 ));
1068 double L8 = getDistance(P( 4 ),P( 5 ));
1070 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1071 aVal = Max(aVal,Max(L7,L8));
1074 else if (len == 6){ // pentaidres
1075 double L1 = getDistance(P( 1 ),P( 2 ));
1076 double L2 = getDistance(P( 2 ),P( 3 ));
1077 double L3 = getDistance(P( 3 ),P( 1 ));
1078 double L4 = getDistance(P( 4 ),P( 5 ));
1079 double L5 = getDistance(P( 5 ),P( 6 ));
1080 double L6 = getDistance(P( 6 ),P( 4 ));
1081 double L7 = getDistance(P( 1 ),P( 4 ));
1082 double L8 = getDistance(P( 2 ),P( 5 ));
1083 double L9 = getDistance(P( 3 ),P( 6 ));
1085 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1086 aVal = Max(aVal,Max(Max(L7,L8),L9));
1089 else if (len == 8){ // hexaider
1090 double L1 = getDistance(P( 1 ),P( 2 ));
1091 double L2 = getDistance(P( 2 ),P( 3 ));
1092 double L3 = getDistance(P( 3 ),P( 4 ));
1093 double L4 = getDistance(P( 4 ),P( 1 ));
1094 double L5 = getDistance(P( 5 ),P( 6 ));
1095 double L6 = getDistance(P( 6 ),P( 7 ));
1096 double L7 = getDistance(P( 7 ),P( 8 ));
1097 double L8 = getDistance(P( 8 ),P( 5 ));
1098 double L9 = getDistance(P( 1 ),P( 5 ));
1099 double L10= getDistance(P( 2 ),P( 6 ));
1100 double L11= getDistance(P( 3 ),P( 7 ));
1101 double L12= getDistance(P( 4 ),P( 8 ));
1103 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1104 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
1105 aVal = Max(aVal,Max(L11,L12));
1110 if (len == 10){ // quadratic tetraidrs
1111 double L1 = getDistance(P( 1 ),P( 5 )) + getDistance(P( 5 ),P( 2 ));
1112 double L2 = getDistance(P( 2 ),P( 6 )) + getDistance(P( 6 ),P( 3 ));
1113 double L3 = getDistance(P( 3 ),P( 7 )) + getDistance(P( 7 ),P( 1 ));
1114 double L4 = getDistance(P( 1 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
1115 double L5 = getDistance(P( 2 ),P( 9 )) + getDistance(P( 9 ),P( 4 ));
1116 double L6 = getDistance(P( 3 ),P( 10 )) + getDistance(P( 10 ),P( 4 ));
1117 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1120 else if (len == 13){ // quadratic piramids
1121 double L1 = getDistance(P( 1 ),P( 6 )) + getDistance(P( 6 ),P( 2 ));
1122 double L2 = getDistance(P( 2 ),P( 7 )) + getDistance(P( 7 ),P( 3 ));
1123 double L3 = getDistance(P( 3 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
1124 double L4 = getDistance(P( 4 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1125 double L5 = getDistance(P( 1 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1126 double L6 = getDistance(P( 2 ),P( 11 )) + getDistance(P( 11 ),P( 5 ));
1127 double L7 = getDistance(P( 3 ),P( 12 )) + getDistance(P( 12 ),P( 5 ));
1128 double L8 = getDistance(P( 4 ),P( 13 )) + getDistance(P( 13 ),P( 5 ));
1129 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1130 aVal = Max(aVal,Max(L7,L8));
1133 else if (len == 15){ // quadratic pentaidres
1134 double L1 = getDistance(P( 1 ),P( 7 )) + getDistance(P( 7 ),P( 2 ));
1135 double L2 = getDistance(P( 2 ),P( 8 )) + getDistance(P( 8 ),P( 3 ));
1136 double L3 = getDistance(P( 3 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1137 double L4 = getDistance(P( 4 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1138 double L5 = getDistance(P( 5 ),P( 11 )) + getDistance(P( 11 ),P( 6 ));
1139 double L6 = getDistance(P( 6 ),P( 12 )) + getDistance(P( 12 ),P( 4 ));
1140 double L7 = getDistance(P( 1 ),P( 13 )) + getDistance(P( 13 ),P( 4 ));
1141 double L8 = getDistance(P( 2 ),P( 14 )) + getDistance(P( 14 ),P( 5 ));
1142 double L9 = getDistance(P( 3 ),P( 15 )) + getDistance(P( 15 ),P( 6 ));
1143 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1144 aVal = Max(aVal,Max(Max(L7,L8),L9));
1147 else if (len == 20){ // quadratic hexaider
1148 double L1 = getDistance(P( 1 ),P( 9 )) + getDistance(P( 9 ),P( 2 ));
1149 double L2 = getDistance(P( 2 ),P( 10 )) + getDistance(P( 10 ),P( 3 ));
1150 double L3 = getDistance(P( 3 ),P( 11 )) + getDistance(P( 11 ),P( 4 ));
1151 double L4 = getDistance(P( 4 ),P( 12 )) + getDistance(P( 12 ),P( 1 ));
1152 double L5 = getDistance(P( 5 ),P( 13 )) + getDistance(P( 13 ),P( 6 ));
1153 double L6 = getDistance(P( 6 ),P( 14 )) + getDistance(P( 14 ),P( 7 ));
1154 double L7 = getDistance(P( 7 ),P( 15 )) + getDistance(P( 15 ),P( 8 ));
1155 double L8 = getDistance(P( 8 ),P( 16 )) + getDistance(P( 16 ),P( 5 ));
1156 double L9 = getDistance(P( 1 ),P( 17 )) + getDistance(P( 17 ),P( 5 ));
1157 double L10= getDistance(P( 2 ),P( 18 )) + getDistance(P( 18 ),P( 6 ));
1158 double L11= getDistance(P( 3 ),P( 19 )) + getDistance(P( 19 ),P( 7 ));
1159 double L12= getDistance(P( 4 ),P( 20 )) + getDistance(P( 20 ),P( 8 ));
1160 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1161 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
1162 aVal = Max(aVal,Max(L11,L12));
1174 if ( myPrecision >= 0 )
1176 double prec = pow( 10., (double)( myPrecision ) );
1177 aVal = floor( aVal * prec + 0.5 ) / prec;
1186 double Length2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1188 // meaningless as it is not quality control functor
1192 SMDSAbs_ElementType Length2D::GetType() const
1194 return SMDSAbs_Face;
1197 Length2D::Value::Value(double theLength,long thePntId1, long thePntId2):
1200 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1201 if(thePntId1 > thePntId2){
1202 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1206 bool Length2D::Value::operator<(const Length2D::Value& x) const{
1207 if(myPntId[0] < x.myPntId[0]) return true;
1208 if(myPntId[0] == x.myPntId[0])
1209 if(myPntId[1] < x.myPntId[1]) return true;
1213 void Length2D::GetValues(TValues& theValues){
1215 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1216 for(; anIter->more(); ){
1217 const SMDS_MeshFace* anElem = anIter->next();
1219 if(anElem->IsQuadratic()) {
1220 const SMDS_QuadraticFaceOfNodes* F =
1221 static_cast<const SMDS_QuadraticFaceOfNodes*>(anElem);
1222 // use special nodes iterator
1223 SMDS_NodeIteratorPtr anIter = F->interlacedNodesIterator();
1228 const SMDS_MeshElement* aNode;
1230 aNode = anIter->next();
1231 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1232 P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1233 aNodeId[0] = aNodeId[1] = aNode->GetID();
1236 for(; anIter->more(); ){
1237 const SMDS_MeshNode* N1 = static_cast<const SMDS_MeshNode*> (anIter->next());
1238 P[2] = gp_Pnt(N1->X(),N1->Y(),N1->Z());
1239 aNodeId[2] = N1->GetID();
1240 aLength = P[1].Distance(P[2]);
1241 if(!anIter->more()) break;
1242 const SMDS_MeshNode* N2 = static_cast<const SMDS_MeshNode*> (anIter->next());
1243 P[3] = gp_Pnt(N2->X(),N2->Y(),N2->Z());
1244 aNodeId[3] = N2->GetID();
1245 aLength += P[2].Distance(P[3]);
1246 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1247 Value aValue2(aLength,aNodeId[2],aNodeId[3]);
1249 aNodeId[1] = aNodeId[3];
1250 theValues.insert(aValue1);
1251 theValues.insert(aValue2);
1253 aLength += P[2].Distance(P[0]);
1254 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1255 Value aValue2(aLength,aNodeId[2],aNodeId[0]);
1256 theValues.insert(aValue1);
1257 theValues.insert(aValue2);
1260 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
1265 const SMDS_MeshElement* aNode;
1266 if(aNodesIter->more()){
1267 aNode = aNodesIter->next();
1268 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1269 P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1270 aNodeId[0] = aNodeId[1] = aNode->GetID();
1273 for(; aNodesIter->more(); ){
1274 aNode = aNodesIter->next();
1275 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1276 long anId = aNode->GetID();
1278 P[2] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1280 aLength = P[1].Distance(P[2]);
1282 Value aValue(aLength,aNodeId[1],anId);
1285 theValues.insert(aValue);
1288 aLength = P[0].Distance(P[1]);
1290 Value aValue(aLength,aNodeId[0],aNodeId[1]);
1291 theValues.insert(aValue);
1297 Class : MultiConnection
1298 Description : Functor for calculating number of faces conneted to the edge
1300 double MultiConnection::GetValue( const TSequenceOfXYZ& P )
1304 double MultiConnection::GetValue( long theId )
1306 return getNbMultiConnection( myMesh, theId );
1309 double MultiConnection::GetBadRate( double Value, int /*nbNodes*/ ) const
1311 // meaningless as it is not quality control functor
1315 SMDSAbs_ElementType MultiConnection::GetType() const
1317 return SMDSAbs_Edge;
1321 Class : MultiConnection2D
1322 Description : Functor for calculating number of faces conneted to the edge
1324 double MultiConnection2D::GetValue( const TSequenceOfXYZ& P )
1329 double MultiConnection2D::GetValue( long theElementId )
1333 const SMDS_MeshElement* aFaceElem = myMesh->FindElement(theElementId);
1334 SMDSAbs_ElementType aType = aFaceElem->GetType();
1339 int i = 0, len = aFaceElem->NbNodes();
1340 SMDS_ElemIteratorPtr anIter = aFaceElem->nodesIterator();
1343 const SMDS_MeshNode *aNode, *aNode0;
1344 TColStd_MapOfInteger aMap, aMapPrev;
1346 for (i = 0; i <= len; i++) {
1351 if (anIter->more()) {
1352 aNode = (SMDS_MeshNode*)anIter->next();
1360 if (i == 0) aNode0 = aNode;
1362 SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator();
1363 while (anElemIter->more()) {
1364 const SMDS_MeshElement* anElem = anElemIter->next();
1365 if (anElem != 0 && anElem->GetType() == SMDSAbs_Face) {
1366 int anId = anElem->GetID();
1369 if (aMapPrev.Contains(anId)) {
1374 aResult = Max(aResult, aNb);
1385 double MultiConnection2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1387 // meaningless as it is not quality control functor
1391 SMDSAbs_ElementType MultiConnection2D::GetType() const
1393 return SMDSAbs_Face;
1396 MultiConnection2D::Value::Value(long thePntId1, long thePntId2)
1398 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1399 if(thePntId1 > thePntId2){
1400 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1404 bool MultiConnection2D::Value::operator<(const MultiConnection2D::Value& x) const{
1405 if(myPntId[0] < x.myPntId[0]) return true;
1406 if(myPntId[0] == x.myPntId[0])
1407 if(myPntId[1] < x.myPntId[1]) return true;
1411 void MultiConnection2D::GetValues(MValues& theValues){
1412 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1413 for(; anIter->more(); ){
1414 const SMDS_MeshFace* anElem = anIter->next();
1415 SMDS_ElemIteratorPtr aNodesIter;
1416 if ( anElem->IsQuadratic() )
1417 aNodesIter = static_cast<const SMDS_QuadraticFaceOfNodes*>
1418 (anElem)->interlacedNodesElemIterator();
1420 aNodesIter = anElem->nodesIterator();
1423 //int aNbConnects=0;
1424 const SMDS_MeshNode* aNode0;
1425 const SMDS_MeshNode* aNode1;
1426 const SMDS_MeshNode* aNode2;
1427 if(aNodesIter->more()){
1428 aNode0 = (SMDS_MeshNode*) aNodesIter->next();
1430 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode1;
1431 aNodeId[0] = aNodeId[1] = aNodes->GetID();
1433 for(; aNodesIter->more(); ) {
1434 aNode2 = (SMDS_MeshNode*) aNodesIter->next();
1435 long anId = aNode2->GetID();
1438 Value aValue(aNodeId[1],aNodeId[2]);
1439 MValues::iterator aItr = theValues.find(aValue);
1440 if (aItr != theValues.end()){
1445 theValues[aValue] = 1;
1448 //cout << "NodeIds: "<<aNodeId[1]<<","<<aNodeId[2]<<" nbconn="<<aNbConnects<<endl;
1449 aNodeId[1] = aNodeId[2];
1452 Value aValue(aNodeId[0],aNodeId[2]);
1453 MValues::iterator aItr = theValues.find(aValue);
1454 if (aItr != theValues.end()) {
1459 theValues[aValue] = 1;
1462 //cout << "NodeIds: "<<aNodeId[0]<<","<<aNodeId[2]<<" nbconn="<<aNbConnects<<endl;
1472 Class : BadOrientedVolume
1473 Description : Predicate bad oriented volumes
1476 BadOrientedVolume::BadOrientedVolume()
1481 void BadOrientedVolume::SetMesh( const SMDS_Mesh* theMesh )
1486 bool BadOrientedVolume::IsSatisfy( long theId )
1491 SMDS_VolumeTool vTool( myMesh->FindElement( theId ));
1492 return !vTool.IsForward();
1495 SMDSAbs_ElementType BadOrientedVolume::GetType() const
1497 return SMDSAbs_Volume;
1504 Description : Predicate for free borders
1507 FreeBorders::FreeBorders()
1512 void FreeBorders::SetMesh( const SMDS_Mesh* theMesh )
1517 bool FreeBorders::IsSatisfy( long theId )
1519 return getNbMultiConnection( myMesh, theId ) == 1;
1522 SMDSAbs_ElementType FreeBorders::GetType() const
1524 return SMDSAbs_Edge;
1530 Description : Predicate for free Edges
1532 FreeEdges::FreeEdges()
1537 void FreeEdges::SetMesh( const SMDS_Mesh* theMesh )
1542 bool FreeEdges::IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId )
1544 TColStd_MapOfInteger aMap;
1545 for ( int i = 0; i < 2; i++ )
1547 SMDS_ElemIteratorPtr anElemIter = theNodes[ i ]->GetInverseElementIterator();
1548 while( anElemIter->more() )
1550 const SMDS_MeshElement* anElem = anElemIter->next();
1551 if ( anElem != 0 && anElem->GetType() == SMDSAbs_Face )
1553 int anId = anElem->GetID();
1557 else if ( aMap.Contains( anId ) && anId != theFaceId )
1565 bool FreeEdges::IsSatisfy( long theId )
1570 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
1571 if ( aFace == 0 || aFace->GetType() != SMDSAbs_Face || aFace->NbNodes() < 3 )
1574 SMDS_ElemIteratorPtr anIter;
1575 if ( aFace->IsQuadratic() ) {
1576 anIter = static_cast<const SMDS_QuadraticFaceOfNodes*>
1577 (aFace)->interlacedNodesElemIterator();
1580 anIter = aFace->nodesIterator();
1585 int i = 0, nbNodes = aFace->NbNodes();
1586 vector <const SMDS_MeshNode*> aNodes( nbNodes+1 );
1587 while( anIter->more() )
1589 const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next();
1592 aNodes[ i++ ] = aNode;
1594 aNodes[ nbNodes ] = aNodes[ 0 ];
1596 for ( i = 0; i < nbNodes; i++ )
1597 if ( IsFreeEdge( &aNodes[ i ], theId ) )
1603 SMDSAbs_ElementType FreeEdges::GetType() const
1605 return SMDSAbs_Face;
1608 FreeEdges::Border::Border(long theElemId, long thePntId1, long thePntId2):
1611 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1612 if(thePntId1 > thePntId2){
1613 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1617 bool FreeEdges::Border::operator<(const FreeEdges::Border& x) const{
1618 if(myPntId[0] < x.myPntId[0]) return true;
1619 if(myPntId[0] == x.myPntId[0])
1620 if(myPntId[1] < x.myPntId[1]) return true;
1624 inline void UpdateBorders(const FreeEdges::Border& theBorder,
1625 FreeEdges::TBorders& theRegistry,
1626 FreeEdges::TBorders& theContainer)
1628 if(theRegistry.find(theBorder) == theRegistry.end()){
1629 theRegistry.insert(theBorder);
1630 theContainer.insert(theBorder);
1632 theContainer.erase(theBorder);
1636 void FreeEdges::GetBoreders(TBorders& theBorders)
1639 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1640 for(; anIter->more(); ){
1641 const SMDS_MeshFace* anElem = anIter->next();
1642 long anElemId = anElem->GetID();
1643 SMDS_ElemIteratorPtr aNodesIter;
1644 if ( anElem->IsQuadratic() )
1645 aNodesIter = static_cast<const SMDS_QuadraticFaceOfNodes*>(anElem)->
1646 interlacedNodesElemIterator();
1648 aNodesIter = anElem->nodesIterator();
1650 const SMDS_MeshElement* aNode;
1651 if(aNodesIter->more()){
1652 aNode = aNodesIter->next();
1653 aNodeId[0] = aNodeId[1] = aNode->GetID();
1655 for(; aNodesIter->more(); ){
1656 aNode = aNodesIter->next();
1657 long anId = aNode->GetID();
1658 Border aBorder(anElemId,aNodeId[1],anId);
1660 //std::cout<<aBorder.myPntId[0]<<"; "<<aBorder.myPntId[1]<<"; "<<aBorder.myElemId<<endl;
1661 UpdateBorders(aBorder,aRegistry,theBorders);
1663 Border aBorder(anElemId,aNodeId[0],aNodeId[1]);
1664 //std::cout<<aBorder.myPntId[0]<<"; "<<aBorder.myPntId[1]<<"; "<<aBorder.myElemId<<endl;
1665 UpdateBorders(aBorder,aRegistry,theBorders);
1667 //std::cout<<"theBorders.size() = "<<theBorders.size()<<endl;
1672 Description : Predicate for Range of Ids.
1673 Range may be specified with two ways.
1674 1. Using AddToRange method
1675 2. With SetRangeStr method. Parameter of this method is a string
1676 like as "1,2,3,50-60,63,67,70-"
1679 //=======================================================================
1680 // name : RangeOfIds
1681 // Purpose : Constructor
1682 //=======================================================================
1683 RangeOfIds::RangeOfIds()
1686 myType = SMDSAbs_All;
1689 //=======================================================================
1691 // Purpose : Set mesh
1692 //=======================================================================
1693 void RangeOfIds::SetMesh( const SMDS_Mesh* theMesh )
1698 //=======================================================================
1699 // name : AddToRange
1700 // Purpose : Add ID to the range
1701 //=======================================================================
1702 bool RangeOfIds::AddToRange( long theEntityId )
1704 myIds.Add( theEntityId );
1708 //=======================================================================
1709 // name : GetRangeStr
1710 // Purpose : Get range as a string.
1711 // Example: "1,2,3,50-60,63,67,70-"
1712 //=======================================================================
1713 void RangeOfIds::GetRangeStr( TCollection_AsciiString& theResStr )
1717 TColStd_SequenceOfInteger anIntSeq;
1718 TColStd_SequenceOfAsciiString aStrSeq;
1720 TColStd_MapIteratorOfMapOfInteger anIter( myIds );
1721 for ( ; anIter.More(); anIter.Next() )
1723 int anId = anIter.Key();
1724 TCollection_AsciiString aStr( anId );
1725 anIntSeq.Append( anId );
1726 aStrSeq.Append( aStr );
1729 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
1731 int aMinId = myMin( i );
1732 int aMaxId = myMax( i );
1734 TCollection_AsciiString aStr;
1735 if ( aMinId != IntegerFirst() )
1740 if ( aMaxId != IntegerLast() )
1743 // find position of the string in result sequence and insert string in it
1744 if ( anIntSeq.Length() == 0 )
1746 anIntSeq.Append( aMinId );
1747 aStrSeq.Append( aStr );
1751 if ( aMinId < anIntSeq.First() )
1753 anIntSeq.Prepend( aMinId );
1754 aStrSeq.Prepend( aStr );
1756 else if ( aMinId > anIntSeq.Last() )
1758 anIntSeq.Append( aMinId );
1759 aStrSeq.Append( aStr );
1762 for ( int j = 1, k = anIntSeq.Length(); j <= k; j++ )
1763 if ( aMinId < anIntSeq( j ) )
1765 anIntSeq.InsertBefore( j, aMinId );
1766 aStrSeq.InsertBefore( j, aStr );
1772 if ( aStrSeq.Length() == 0 )
1775 theResStr = aStrSeq( 1 );
1776 for ( int j = 2, k = aStrSeq.Length(); j <= k; j++ )
1779 theResStr += aStrSeq( j );
1783 //=======================================================================
1784 // name : SetRangeStr
1785 // Purpose : Define range with string
1786 // Example of entry string: "1,2,3,50-60,63,67,70-"
1787 //=======================================================================
1788 bool RangeOfIds::SetRangeStr( const TCollection_AsciiString& theStr )
1794 TCollection_AsciiString aStr = theStr;
1795 aStr.RemoveAll( ' ' );
1796 aStr.RemoveAll( '\t' );
1798 for ( int aPos = aStr.Search( ",," ); aPos != -1; aPos = aStr.Search( ",," ) )
1799 aStr.Remove( aPos, 2 );
1801 TCollection_AsciiString tmpStr = aStr.Token( ",", 1 );
1803 while ( tmpStr != "" )
1805 tmpStr = aStr.Token( ",", i++ );
1806 int aPos = tmpStr.Search( '-' );
1810 if ( tmpStr.IsIntegerValue() )
1811 myIds.Add( tmpStr.IntegerValue() );
1817 TCollection_AsciiString aMaxStr = tmpStr.Split( aPos );
1818 TCollection_AsciiString aMinStr = tmpStr;
1820 while ( aMinStr.Search( "-" ) != -1 ) aMinStr.RemoveAll( '-' );
1821 while ( aMaxStr.Search( "-" ) != -1 ) aMaxStr.RemoveAll( '-' );
1823 if ( !aMinStr.IsEmpty() && !aMinStr.IsIntegerValue() ||
1824 !aMaxStr.IsEmpty() && !aMaxStr.IsIntegerValue() )
1827 myMin.Append( aMinStr.IsEmpty() ? IntegerFirst() : aMinStr.IntegerValue() );
1828 myMax.Append( aMaxStr.IsEmpty() ? IntegerLast() : aMaxStr.IntegerValue() );
1835 //=======================================================================
1837 // Purpose : Get type of supported entities
1838 //=======================================================================
1839 SMDSAbs_ElementType RangeOfIds::GetType() const
1844 //=======================================================================
1846 // Purpose : Set type of supported entities
1847 //=======================================================================
1848 void RangeOfIds::SetType( SMDSAbs_ElementType theType )
1853 //=======================================================================
1855 // Purpose : Verify whether entity satisfies to this rpedicate
1856 //=======================================================================
1857 bool RangeOfIds::IsSatisfy( long theId )
1862 if ( myType == SMDSAbs_Node )
1864 if ( myMesh->FindNode( theId ) == 0 )
1869 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
1870 if ( anElem == 0 || myType != anElem->GetType() && myType != SMDSAbs_All )
1874 if ( myIds.Contains( theId ) )
1877 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
1878 if ( theId >= myMin( i ) && theId <= myMax( i ) )
1886 Description : Base class for comparators
1888 Comparator::Comparator():
1892 Comparator::~Comparator()
1895 void Comparator::SetMesh( const SMDS_Mesh* theMesh )
1898 myFunctor->SetMesh( theMesh );
1901 void Comparator::SetMargin( double theValue )
1903 myMargin = theValue;
1906 void Comparator::SetNumFunctor( NumericalFunctorPtr theFunct )
1908 myFunctor = theFunct;
1911 SMDSAbs_ElementType Comparator::GetType() const
1913 return myFunctor ? myFunctor->GetType() : SMDSAbs_All;
1916 double Comparator::GetMargin()
1924 Description : Comparator "<"
1926 bool LessThan::IsSatisfy( long theId )
1928 return myFunctor && myFunctor->GetValue( theId ) < myMargin;
1934 Description : Comparator ">"
1936 bool MoreThan::IsSatisfy( long theId )
1938 return myFunctor && myFunctor->GetValue( theId ) > myMargin;
1944 Description : Comparator "="
1947 myToler(Precision::Confusion())
1950 bool EqualTo::IsSatisfy( long theId )
1952 return myFunctor && fabs( myFunctor->GetValue( theId ) - myMargin ) < myToler;
1955 void EqualTo::SetTolerance( double theToler )
1960 double EqualTo::GetTolerance()
1967 Description : Logical NOT predicate
1969 LogicalNOT::LogicalNOT()
1972 LogicalNOT::~LogicalNOT()
1975 bool LogicalNOT::IsSatisfy( long theId )
1977 return myPredicate && !myPredicate->IsSatisfy( theId );
1980 void LogicalNOT::SetMesh( const SMDS_Mesh* theMesh )
1983 myPredicate->SetMesh( theMesh );
1986 void LogicalNOT::SetPredicate( PredicatePtr thePred )
1988 myPredicate = thePred;
1991 SMDSAbs_ElementType LogicalNOT::GetType() const
1993 return myPredicate ? myPredicate->GetType() : SMDSAbs_All;
1998 Class : LogicalBinary
1999 Description : Base class for binary logical predicate
2001 LogicalBinary::LogicalBinary()
2004 LogicalBinary::~LogicalBinary()
2007 void LogicalBinary::SetMesh( const SMDS_Mesh* theMesh )
2010 myPredicate1->SetMesh( theMesh );
2013 myPredicate2->SetMesh( theMesh );
2016 void LogicalBinary::SetPredicate1( PredicatePtr thePredicate )
2018 myPredicate1 = thePredicate;
2021 void LogicalBinary::SetPredicate2( PredicatePtr thePredicate )
2023 myPredicate2 = thePredicate;
2026 SMDSAbs_ElementType LogicalBinary::GetType() const
2028 if ( !myPredicate1 || !myPredicate2 )
2031 SMDSAbs_ElementType aType1 = myPredicate1->GetType();
2032 SMDSAbs_ElementType aType2 = myPredicate2->GetType();
2034 return aType1 == aType2 ? aType1 : SMDSAbs_All;
2040 Description : Logical AND
2042 bool LogicalAND::IsSatisfy( long theId )
2047 myPredicate1->IsSatisfy( theId ) &&
2048 myPredicate2->IsSatisfy( theId );
2054 Description : Logical OR
2056 bool LogicalOR::IsSatisfy( long theId )
2061 myPredicate1->IsSatisfy( theId ) ||
2062 myPredicate2->IsSatisfy( theId );
2076 void Filter::SetPredicate( PredicatePtr thePredicate )
2078 myPredicate = thePredicate;
2081 template<class TElement, class TIterator, class TPredicate>
2082 inline void FillSequence(const TIterator& theIterator,
2083 TPredicate& thePredicate,
2084 Filter::TIdSequence& theSequence)
2086 if ( theIterator ) {
2087 while( theIterator->more() ) {
2088 TElement anElem = theIterator->next();
2089 long anId = anElem->GetID();
2090 if ( thePredicate->IsSatisfy( anId ) )
2091 theSequence.push_back( anId );
2098 GetElementsId( const SMDS_Mesh* theMesh,
2099 PredicatePtr thePredicate,
2100 TIdSequence& theSequence )
2102 theSequence.clear();
2104 if ( !theMesh || !thePredicate )
2107 thePredicate->SetMesh( theMesh );
2109 SMDSAbs_ElementType aType = thePredicate->GetType();
2112 FillSequence<const SMDS_MeshNode*>(theMesh->nodesIterator(),thePredicate,theSequence);
2115 FillSequence<const SMDS_MeshElement*>(theMesh->edgesIterator(),thePredicate,theSequence);
2118 FillSequence<const SMDS_MeshElement*>(theMesh->facesIterator(),thePredicate,theSequence);
2120 case SMDSAbs_Volume:
2121 FillSequence<const SMDS_MeshElement*>(theMesh->volumesIterator(),thePredicate,theSequence);
2124 FillSequence<const SMDS_MeshElement*>(theMesh->edgesIterator(),thePredicate,theSequence);
2125 FillSequence<const SMDS_MeshElement*>(theMesh->facesIterator(),thePredicate,theSequence);
2126 FillSequence<const SMDS_MeshElement*>(theMesh->volumesIterator(),thePredicate,theSequence);
2132 Filter::GetElementsId( const SMDS_Mesh* theMesh,
2133 Filter::TIdSequence& theSequence )
2135 GetElementsId(theMesh,myPredicate,theSequence);
2142 typedef std::set<SMDS_MeshFace*> TMapOfFacePtr;
2148 ManifoldPart::Link::Link( SMDS_MeshNode* theNode1,
2149 SMDS_MeshNode* theNode2 )
2155 ManifoldPart::Link::~Link()
2161 bool ManifoldPart::Link::IsEqual( const ManifoldPart::Link& theLink ) const
2163 if ( myNode1 == theLink.myNode1 &&
2164 myNode2 == theLink.myNode2 )
2166 else if ( myNode1 == theLink.myNode2 &&
2167 myNode2 == theLink.myNode1 )
2173 bool ManifoldPart::Link::operator<( const ManifoldPart::Link& x ) const
2175 if(myNode1 < x.myNode1) return true;
2176 if(myNode1 == x.myNode1)
2177 if(myNode2 < x.myNode2) return true;
2181 bool ManifoldPart::IsEqual( const ManifoldPart::Link& theLink1,
2182 const ManifoldPart::Link& theLink2 )
2184 return theLink1.IsEqual( theLink2 );
2187 ManifoldPart::ManifoldPart()
2190 myAngToler = Precision::Angular();
2191 myIsOnlyManifold = true;
2194 ManifoldPart::~ManifoldPart()
2199 void ManifoldPart::SetMesh( const SMDS_Mesh* theMesh )
2205 SMDSAbs_ElementType ManifoldPart::GetType() const
2206 { return SMDSAbs_Face; }
2208 bool ManifoldPart::IsSatisfy( long theElementId )
2210 return myMapIds.Contains( theElementId );
2213 void ManifoldPart::SetAngleTolerance( const double theAngToler )
2214 { myAngToler = theAngToler; }
2216 double ManifoldPart::GetAngleTolerance() const
2217 { return myAngToler; }
2219 void ManifoldPart::SetIsOnlyManifold( const bool theIsOnly )
2220 { myIsOnlyManifold = theIsOnly; }
2222 void ManifoldPart::SetStartElem( const long theStartId )
2223 { myStartElemId = theStartId; }
2225 bool ManifoldPart::process()
2228 myMapBadGeomIds.Clear();
2230 myAllFacePtr.clear();
2231 myAllFacePtrIntDMap.clear();
2235 // collect all faces into own map
2236 SMDS_FaceIteratorPtr anFaceItr = myMesh->facesIterator();
2237 for (; anFaceItr->more(); )
2239 SMDS_MeshFace* aFacePtr = (SMDS_MeshFace*)anFaceItr->next();
2240 myAllFacePtr.push_back( aFacePtr );
2241 myAllFacePtrIntDMap[aFacePtr] = myAllFacePtr.size()-1;
2244 SMDS_MeshFace* aStartFace = (SMDS_MeshFace*)myMesh->FindElement( myStartElemId );
2248 // the map of non manifold links and bad geometry
2249 TMapOfLink aMapOfNonManifold;
2250 TColStd_MapOfInteger aMapOfTreated;
2252 // begin cycle on faces from start index and run on vector till the end
2253 // and from begin to start index to cover whole vector
2254 const int aStartIndx = myAllFacePtrIntDMap[aStartFace];
2255 bool isStartTreat = false;
2256 for ( int fi = aStartIndx; !isStartTreat || fi != aStartIndx ; fi++ )
2258 if ( fi == aStartIndx )
2259 isStartTreat = true;
2260 // as result next time when fi will be equal to aStartIndx
2262 SMDS_MeshFace* aFacePtr = myAllFacePtr[ fi ];
2263 if ( aMapOfTreated.Contains( aFacePtr->GetID() ) )
2266 aMapOfTreated.Add( aFacePtr->GetID() );
2267 TColStd_MapOfInteger aResFaces;
2268 if ( !findConnected( myAllFacePtrIntDMap, aFacePtr,
2269 aMapOfNonManifold, aResFaces ) )
2271 TColStd_MapIteratorOfMapOfInteger anItr( aResFaces );
2272 for ( ; anItr.More(); anItr.Next() )
2274 int aFaceId = anItr.Key();
2275 aMapOfTreated.Add( aFaceId );
2276 myMapIds.Add( aFaceId );
2279 if ( fi == ( myAllFacePtr.size() - 1 ) )
2281 } // end run on vector of faces
2282 return !myMapIds.IsEmpty();
2285 static void getLinks( const SMDS_MeshFace* theFace,
2286 ManifoldPart::TVectorOfLink& theLinks )
2288 int aNbNode = theFace->NbNodes();
2289 SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
2291 SMDS_MeshNode* aNode = 0;
2292 for ( ; aNodeItr->more() && i <= aNbNode; )
2295 SMDS_MeshNode* aN1 = (SMDS_MeshNode*)aNodeItr->next();
2299 SMDS_MeshNode* aN2 = ( i >= aNbNode ) ? aNode : (SMDS_MeshNode*)aNodeItr->next();
2301 ManifoldPart::Link aLink( aN1, aN2 );
2302 theLinks.push_back( aLink );
2306 static gp_XYZ getNormale( const SMDS_MeshFace* theFace )
2309 int aNbNode = theFace->NbNodes();
2310 TColgp_Array1OfXYZ anArrOfXYZ(1,4);
2311 SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
2313 for ( ; aNodeItr->more() && i <= 4; i++ ) {
2314 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
2315 anArrOfXYZ.SetValue(i, gp_XYZ( aNode->X(), aNode->Y(), aNode->Z() ) );
2318 gp_XYZ q1 = anArrOfXYZ.Value(2) - anArrOfXYZ.Value(1);
2319 gp_XYZ q2 = anArrOfXYZ.Value(3) - anArrOfXYZ.Value(1);
2321 if ( aNbNode > 3 ) {
2322 gp_XYZ q3 = anArrOfXYZ.Value(4) - anArrOfXYZ.Value(1);
2325 double len = n.Modulus();
2332 bool ManifoldPart::findConnected
2333 ( const ManifoldPart::TDataMapFacePtrInt& theAllFacePtrInt,
2334 SMDS_MeshFace* theStartFace,
2335 ManifoldPart::TMapOfLink& theNonManifold,
2336 TColStd_MapOfInteger& theResFaces )
2338 theResFaces.Clear();
2339 if ( !theAllFacePtrInt.size() )
2342 if ( getNormale( theStartFace ).SquareModulus() <= gp::Resolution() )
2344 myMapBadGeomIds.Add( theStartFace->GetID() );
2348 ManifoldPart::TMapOfLink aMapOfBoundary, aMapToSkip;
2349 ManifoldPart::TVectorOfLink aSeqOfBoundary;
2350 theResFaces.Add( theStartFace->GetID() );
2351 ManifoldPart::TDataMapOfLinkFacePtr aDMapLinkFace;
2353 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
2354 aDMapLinkFace, theNonManifold, theStartFace );
2356 bool isDone = false;
2357 while ( !isDone && aMapOfBoundary.size() != 0 )
2359 bool isToReset = false;
2360 ManifoldPart::TVectorOfLink::iterator pLink = aSeqOfBoundary.begin();
2361 for ( ; !isToReset && pLink != aSeqOfBoundary.end(); ++pLink )
2363 ManifoldPart::Link aLink = *pLink;
2364 if ( aMapToSkip.find( aLink ) != aMapToSkip.end() )
2366 // each link could be treated only once
2367 aMapToSkip.insert( aLink );
2369 ManifoldPart::TVectorOfFacePtr aFaces;
2371 if ( myIsOnlyManifold &&
2372 (theNonManifold.find( aLink ) != theNonManifold.end()) )
2376 getFacesByLink( aLink, aFaces );
2377 // filter the element to keep only indicated elements
2378 ManifoldPart::TVectorOfFacePtr aFiltered;
2379 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
2380 for ( ; pFace != aFaces.end(); ++pFace )
2382 SMDS_MeshFace* aFace = *pFace;
2383 if ( myAllFacePtrIntDMap.find( aFace ) != myAllFacePtrIntDMap.end() )
2384 aFiltered.push_back( aFace );
2387 if ( aFaces.size() < 2 ) // no neihgbour faces
2389 else if ( myIsOnlyManifold && aFaces.size() > 2 ) // non manifold case
2391 theNonManifold.insert( aLink );
2396 // compare normal with normals of neighbor element
2397 SMDS_MeshFace* aPrevFace = aDMapLinkFace[ aLink ];
2398 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
2399 for ( ; pFace != aFaces.end(); ++pFace )
2401 SMDS_MeshFace* aNextFace = *pFace;
2402 if ( aPrevFace == aNextFace )
2404 int anNextFaceID = aNextFace->GetID();
2405 if ( myIsOnlyManifold && theResFaces.Contains( anNextFaceID ) )
2406 // should not be with non manifold restriction. probably bad topology
2408 // check if face was treated and skipped
2409 if ( myMapBadGeomIds.Contains( anNextFaceID ) ||
2410 !isInPlane( aPrevFace, aNextFace ) )
2412 // add new element to connected and extend the boundaries.
2413 theResFaces.Add( anNextFaceID );
2414 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
2415 aDMapLinkFace, theNonManifold, aNextFace );
2419 isDone = !isToReset;
2422 return !theResFaces.IsEmpty();
2425 bool ManifoldPart::isInPlane( const SMDS_MeshFace* theFace1,
2426 const SMDS_MeshFace* theFace2 )
2428 gp_Dir aNorm1 = gp_Dir( getNormale( theFace1 ) );
2429 gp_XYZ aNorm2XYZ = getNormale( theFace2 );
2430 if ( aNorm2XYZ.SquareModulus() <= gp::Resolution() )
2432 myMapBadGeomIds.Add( theFace2->GetID() );
2435 if ( aNorm1.IsParallel( gp_Dir( aNorm2XYZ ), myAngToler ) )
2441 void ManifoldPart::expandBoundary
2442 ( ManifoldPart::TMapOfLink& theMapOfBoundary,
2443 ManifoldPart::TVectorOfLink& theSeqOfBoundary,
2444 ManifoldPart::TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
2445 ManifoldPart::TMapOfLink& theNonManifold,
2446 SMDS_MeshFace* theNextFace ) const
2448 ManifoldPart::TVectorOfLink aLinks;
2449 getLinks( theNextFace, aLinks );
2450 int aNbLink = (int)aLinks.size();
2451 for ( int i = 0; i < aNbLink; i++ )
2453 ManifoldPart::Link aLink = aLinks[ i ];
2454 if ( myIsOnlyManifold && (theNonManifold.find( aLink ) != theNonManifold.end()) )
2456 if ( theMapOfBoundary.find( aLink ) != theMapOfBoundary.end() )
2458 if ( myIsOnlyManifold )
2460 // remove from boundary
2461 theMapOfBoundary.erase( aLink );
2462 ManifoldPart::TVectorOfLink::iterator pLink = theSeqOfBoundary.begin();
2463 for ( ; pLink != theSeqOfBoundary.end(); ++pLink )
2465 ManifoldPart::Link aBoundLink = *pLink;
2466 if ( aBoundLink.IsEqual( aLink ) )
2468 theSeqOfBoundary.erase( pLink );
2476 theMapOfBoundary.insert( aLink );
2477 theSeqOfBoundary.push_back( aLink );
2478 theDMapLinkFacePtr[ aLink ] = theNextFace;
2483 void ManifoldPart::getFacesByLink( const ManifoldPart::Link& theLink,
2484 ManifoldPart::TVectorOfFacePtr& theFaces ) const
2486 SMDS_Mesh::SetOfFaces aSetOfFaces;
2487 // take all faces that shared first node
2488 SMDS_ElemIteratorPtr anItr = theLink.myNode1->facesIterator();
2489 for ( ; anItr->more(); )
2491 SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
2494 aSetOfFaces.Add( aFace );
2496 // take all faces that shared second node
2497 anItr = theLink.myNode2->facesIterator();
2498 // find the common part of two sets
2499 for ( ; anItr->more(); )
2501 SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
2502 if ( aSetOfFaces.Contains( aFace ) )
2503 theFaces.push_back( aFace );
2512 ElementsOnSurface::ElementsOnSurface()
2516 myType = SMDSAbs_All;
2518 myToler = Precision::Confusion();
2521 ElementsOnSurface::~ElementsOnSurface()
2526 void ElementsOnSurface::SetMesh( const SMDS_Mesh* theMesh )
2528 if ( myMesh == theMesh )
2535 bool ElementsOnSurface::IsSatisfy( long theElementId )
2537 return myIds.Contains( theElementId );
2540 SMDSAbs_ElementType ElementsOnSurface::GetType() const
2543 void ElementsOnSurface::SetTolerance( const double theToler )
2544 { myToler = theToler; }
2546 double ElementsOnSurface::GetTolerance() const
2551 void ElementsOnSurface::SetSurface( const TopoDS_Shape& theShape,
2552 const SMDSAbs_ElementType theType )
2556 if ( theShape.IsNull() || theShape.ShapeType() != TopAbs_FACE )
2561 TopoDS_Face aFace = TopoDS::Face( theShape );
2562 mySurf = BRep_Tool::Surface( aFace );
2565 void ElementsOnSurface::process()
2568 if ( mySurf.IsNull() )
2574 if ( myType == SMDSAbs_Face || myType == SMDSAbs_All )
2576 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
2577 for(; anIter->more(); )
2578 process( anIter->next() );
2581 if ( myType == SMDSAbs_Edge || myType == SMDSAbs_All )
2583 SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
2584 for(; anIter->more(); )
2585 process( anIter->next() );
2588 if ( myType == SMDSAbs_Node )
2590 SMDS_NodeIteratorPtr anIter = myMesh->nodesIterator();
2591 for(; anIter->more(); )
2592 process( anIter->next() );
2596 void ElementsOnSurface::process( const SMDS_MeshElement* theElemPtr )
2598 SMDS_ElemIteratorPtr aNodeItr = theElemPtr->nodesIterator();
2599 bool isSatisfy = true;
2600 for ( ; aNodeItr->more(); )
2602 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
2603 if ( !isOnSurface( aNode ) )
2610 myIds.Add( theElemPtr->GetID() );
2613 bool ElementsOnSurface::isOnSurface( const SMDS_MeshNode* theNode ) const
2615 if ( mySurf.IsNull() )
2618 gp_Pnt aPnt( theNode->X(), theNode->Y(), theNode->Z() );
2619 double aToler2 = myToler * myToler;
2620 if ( mySurf->IsKind(STANDARD_TYPE(Geom_Plane)))
2622 gp_Pln aPln = Handle(Geom_Plane)::DownCast(mySurf)->Pln();
2623 if ( aPln.SquareDistance( aPnt ) > aToler2 )
2626 else if ( mySurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)))
2628 gp_Cylinder aCyl = Handle(Geom_CylindricalSurface)::DownCast(mySurf)->Cylinder();
2629 double aRad = aCyl.Radius();
2630 gp_Ax3 anAxis = aCyl.Position();
2631 gp_XYZ aLoc = aCyl.Location().XYZ();
2632 double aXDist = anAxis.XDirection().XYZ() * ( aPnt.XYZ() - aLoc );
2633 double aYDist = anAxis.YDirection().XYZ() * ( aPnt.XYZ() - aLoc );
2634 if ( fabs(aXDist*aXDist + aYDist*aYDist - aRad*aRad) > aToler2 )