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 <BRepAdaptor_Surface.hxx>
25 #include <BRep_Tool.hxx>
26 #include <Geom_CylindricalSurface.hxx>
27 #include <Geom_Plane.hxx>
28 #include <Geom_Surface.hxx>
29 #include <Precision.hxx>
30 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
31 #include <TColStd_MapOfInteger.hxx>
32 #include <TColStd_SequenceOfAsciiString.hxx>
33 #include <TColgp_Array1OfXYZ.hxx>
36 #include <TopoDS_Face.hxx>
37 #include <TopoDS_Shape.hxx>
39 #include <gp_Cylinder.hxx>
46 #include "SMDS_Mesh.hxx"
47 #include "SMDS_Iterator.hxx"
48 #include "SMDS_MeshElement.hxx"
49 #include "SMDS_MeshNode.hxx"
50 #include "SMDS_VolumeTool.hxx"
51 #include "SMDS_QuadraticFaceOfNodes.hxx"
52 #include "SMDS_QuadraticEdge.hxx"
62 inline double getAngle( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
64 gp_Vec v1( P1 - P2 ), v2( P3 - P2 );
66 return v1.Magnitude() < gp::Resolution() ||
67 v2.Magnitude() < gp::Resolution() ? 0 : v1.Angle( v2 );
70 inline double getArea( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
72 gp_Vec aVec1( P2 - P1 );
73 gp_Vec aVec2( P3 - P1 );
74 return ( aVec1 ^ aVec2 ).Magnitude() * 0.5;
77 inline double getArea( const gp_Pnt& P1, const gp_Pnt& P2, const gp_Pnt& P3 )
79 return getArea( P1.XYZ(), P2.XYZ(), P3.XYZ() );
84 inline double getDistance( const gp_XYZ& P1, const gp_XYZ& P2 )
86 double aDist = gp_Pnt( P1 ).Distance( gp_Pnt( P2 ) );
90 int getNbMultiConnection( const SMDS_Mesh* theMesh, const int theId )
95 const SMDS_MeshElement* anEdge = theMesh->FindElement( theId );
96 if ( anEdge == 0 || anEdge->GetType() != SMDSAbs_Edge/* || anEdge->NbNodes() != 2 */)
99 // for each pair of nodes in anEdge (there are 2 pairs in a quadratic edge)
100 // count elements containing both nodes of the pair.
101 // Note that there may be such cases for a quadratic edge (a horizontal line):
106 // +-----+------+ +-----+------+
109 // result sould be 2 in both cases
111 int aResult0 = 0, aResult1 = 0;
112 // last node, it is a medium one in a quadratic edge
113 const SMDS_MeshNode* aLastNode = anEdge->GetNode( anEdge->NbNodes() - 1 );
114 const SMDS_MeshNode* aNode0 = anEdge->GetNode( 0 );
115 const SMDS_MeshNode* aNode1 = anEdge->GetNode( 1 );
116 if ( aNode1 == aLastNode ) aNode1 = 0;
118 SMDS_ElemIteratorPtr anElemIter = aLastNode->GetInverseElementIterator();
119 while( anElemIter->more() ) {
120 const SMDS_MeshElement* anElem = anElemIter->next();
121 if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) {
122 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
123 while ( anIter->more() ) {
124 if ( const SMDS_MeshElement* anElemNode = anIter->next() ) {
125 if ( anElemNode == aNode0 ) {
127 if ( !aNode1 ) break; // not a quadratic edge
129 else if ( anElemNode == aNode1 )
135 int aResult = max ( aResult0, aResult1 );
137 // TColStd_MapOfInteger aMap;
139 // SMDS_ElemIteratorPtr anIter = anEdge->nodesIterator();
140 // if ( anIter != 0 ) {
141 // while( anIter->more() ) {
142 // const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next();
145 // SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator();
146 // while( anElemIter->more() ) {
147 // const SMDS_MeshElement* anElem = anElemIter->next();
148 // if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) {
149 // int anId = anElem->GetID();
151 // if ( anIter->more() ) // i.e. first node
153 // else if ( aMap.Contains( anId ) )
167 using namespace SMESH::Controls;
174 Class : NumericalFunctor
175 Description : Base class for numerical functors
177 NumericalFunctor::NumericalFunctor():
183 void NumericalFunctor::SetMesh( const SMDS_Mesh* theMesh )
188 bool NumericalFunctor::GetPoints(const int theId,
189 TSequenceOfXYZ& theRes ) const
196 return GetPoints( myMesh->FindElement( theId ), theRes );
199 bool NumericalFunctor::GetPoints(const SMDS_MeshElement* anElem,
200 TSequenceOfXYZ& theRes )
207 theRes.reserve( anElem->NbNodes() );
209 // Get nodes of the element
210 SMDS_ElemIteratorPtr anIter;
212 if ( anElem->IsQuadratic() ) {
213 switch ( anElem->GetType() ) {
215 anIter = static_cast<const SMDS_QuadraticEdge*>
216 (anElem)->interlacedNodesElemIterator();
219 anIter = static_cast<const SMDS_QuadraticFaceOfNodes*>
220 (anElem)->interlacedNodesElemIterator();
223 anIter = anElem->nodesIterator();
228 anIter = anElem->nodesIterator();
232 while( anIter->more() ) {
233 if ( const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>( anIter->next() ))
234 theRes.push_back( gp_XYZ( aNode->X(), aNode->Y(), aNode->Z() ) );
241 long NumericalFunctor::GetPrecision() const
246 void NumericalFunctor::SetPrecision( const long thePrecision )
248 myPrecision = thePrecision;
251 double NumericalFunctor::GetValue( long theId )
253 myCurrElement = myMesh->FindElement( theId );
255 if ( GetPoints( theId, P ))
257 double aVal = GetValue( P );
258 if ( myPrecision >= 0 )
260 double prec = pow( 10., (double)( myPrecision ) );
261 aVal = floor( aVal * prec + 0.5 ) / prec;
269 //=======================================================================
270 //function : GetValue
272 //=======================================================================
274 double Volume::GetValue( long theElementId )
276 if ( theElementId && myMesh ) {
277 SMDS_VolumeTool aVolumeTool;
278 if ( aVolumeTool.Set( myMesh->FindElement( theElementId )))
279 return aVolumeTool.GetSize();
284 //=======================================================================
285 //function : GetBadRate
286 //purpose : meaningless as it is not quality control functor
287 //=======================================================================
289 double Volume::GetBadRate( double Value, int /*nbNodes*/ ) const
294 //=======================================================================
297 //=======================================================================
299 SMDSAbs_ElementType Volume::GetType() const
301 return SMDSAbs_Volume;
307 Description : Functor for calculation of minimum angle
310 double MinimumAngle::GetValue( const TSequenceOfXYZ& P )
317 aMin = getAngle(P( P.size() ), P( 1 ), P( 2 ));
318 aMin = Min(aMin,getAngle(P( P.size()-1 ), P( P.size() ), P( 1 )));
320 for (int i=2; i<P.size();i++){
321 double A0 = getAngle( P( i-1 ), P( i ), P( i+1 ) );
325 return aMin * 180.0 / PI;
328 double MinimumAngle::GetBadRate( double Value, int nbNodes ) const
330 //const double aBestAngle = PI / nbNodes;
331 const double aBestAngle = 180.0 - ( 360.0 / double(nbNodes) );
332 return ( fabs( aBestAngle - Value ));
335 SMDSAbs_ElementType MinimumAngle::GetType() const
343 Description : Functor for calculating aspect ratio
345 double AspectRatio::GetValue( const TSequenceOfXYZ& P )
347 // According to "Mesh quality control" by Nadir Bouhamau referring to
348 // Pascal Jean Frey and Paul-Louis George. Maillages, applications aux elements finis.
349 // Hermes Science publications, Paris 1999 ISBN 2-7462-0024-4
352 int nbNodes = P.size();
357 // Compute aspect ratio
359 if ( nbNodes == 3 ) {
360 // Compute lengths of the sides
361 vector< double > aLen (nbNodes);
362 for ( int i = 0; i < nbNodes - 1; i++ )
363 aLen[ i ] = getDistance( P( i + 1 ), P( i + 2 ) );
364 aLen[ nbNodes - 1 ] = getDistance( P( 1 ), P( nbNodes ) );
365 // Q = alfa * h * p / S, where
367 // alfa = sqrt( 3 ) / 6
368 // h - length of the longest edge
369 // p - half perimeter
370 // S - triangle surface
371 const double alfa = sqrt( 3. ) / 6.;
372 double maxLen = Max( aLen[ 0 ], Max( aLen[ 1 ], aLen[ 2 ] ) );
373 double half_perimeter = ( aLen[0] + aLen[1] + aLen[2] ) / 2.;
374 double anArea = getArea( P( 1 ), P( 2 ), P( 3 ) );
375 if ( anArea <= Precision::Confusion() )
377 return alfa * maxLen * half_perimeter / anArea;
379 else if ( nbNodes == 6 ) { // quadratic triangles
380 // Compute lengths of the sides
381 vector< double > aLen (3);
382 aLen[0] = getDistance( P(1), P(3) );
383 aLen[1] = getDistance( P(3), P(5) );
384 aLen[2] = getDistance( P(5), P(1) );
385 // Q = alfa * h * p / S, where
387 // alfa = sqrt( 3 ) / 6
388 // h - length of the longest edge
389 // p - half perimeter
390 // S - triangle surface
391 const double alfa = sqrt( 3. ) / 6.;
392 double maxLen = Max( aLen[ 0 ], Max( aLen[ 1 ], aLen[ 2 ] ) );
393 double half_perimeter = ( aLen[0] + aLen[1] + aLen[2] ) / 2.;
394 double anArea = getArea( P(1), P(3), P(5) );
395 if ( anArea <= Precision::Confusion() )
397 return alfa * maxLen * half_perimeter / anArea;
399 else if( nbNodes == 4 ) { // quadrangle
400 // return aspect ratio of the worst triange which can be built
401 // taking three nodes of the quadrangle
402 TSequenceOfXYZ triaPnts(3);
403 // triangle on nodes 1 3 2
407 double ar = GetValue( triaPnts );
408 // triangle on nodes 1 3 4
410 ar = Max ( ar, GetValue( triaPnts ));
411 // triangle on nodes 1 2 4
413 ar = Max ( ar, GetValue( triaPnts ));
414 // triangle on nodes 3 2 4
416 ar = Max ( ar, GetValue( triaPnts ));
420 else { // nbNodes==8 - quadratic quadrangle
421 // return aspect ratio of the worst triange which can be built
422 // taking three nodes of the quadrangle
423 TSequenceOfXYZ triaPnts(3);
424 // triangle on nodes 1 3 2
428 double ar = GetValue( triaPnts );
429 // triangle on nodes 1 3 4
431 ar = Max ( ar, GetValue( triaPnts ));
432 // triangle on nodes 1 2 4
434 ar = Max ( ar, GetValue( triaPnts ));
435 // triangle on nodes 3 2 4
437 ar = Max ( ar, GetValue( triaPnts ));
443 double AspectRatio::GetBadRate( double Value, int /*nbNodes*/ ) const
445 // the aspect ratio is in the range [1.0,infinity]
448 return Value / 1000.;
451 SMDSAbs_ElementType AspectRatio::GetType() const
458 Class : AspectRatio3D
459 Description : Functor for calculating aspect ratio
463 inline double getHalfPerimeter(double theTria[3]){
464 return (theTria[0] + theTria[1] + theTria[2])/2.0;
467 inline double getArea(double theHalfPerim, double theTria[3]){
468 return sqrt(theHalfPerim*
469 (theHalfPerim-theTria[0])*
470 (theHalfPerim-theTria[1])*
471 (theHalfPerim-theTria[2]));
474 inline double getVolume(double theLen[6]){
475 double a2 = theLen[0]*theLen[0];
476 double b2 = theLen[1]*theLen[1];
477 double c2 = theLen[2]*theLen[2];
478 double d2 = theLen[3]*theLen[3];
479 double e2 = theLen[4]*theLen[4];
480 double f2 = theLen[5]*theLen[5];
481 double P = 4.0*a2*b2*d2;
482 double Q = a2*(b2+d2-e2)-b2*(a2+d2-f2)-d2*(a2+b2-c2);
483 double R = (b2+d2-e2)*(a2+d2-f2)*(a2+d2-f2);
484 return sqrt(P-Q+R)/12.0;
487 inline double getVolume2(double theLen[6]){
488 double a2 = theLen[0]*theLen[0];
489 double b2 = theLen[1]*theLen[1];
490 double c2 = theLen[2]*theLen[2];
491 double d2 = theLen[3]*theLen[3];
492 double e2 = theLen[4]*theLen[4];
493 double f2 = theLen[5]*theLen[5];
495 double P = a2*e2*(b2+c2+d2+f2-a2-e2);
496 double Q = b2*f2*(a2+c2+d2+e2-b2-f2);
497 double R = c2*d2*(a2+b2+e2+f2-c2-d2);
498 double S = a2*b2*d2+b2*c2*e2+a2*c2*f2+d2*e2*f2;
500 return sqrt(P+Q+R-S)/12.0;
503 inline double getVolume(const TSequenceOfXYZ& P){
504 gp_Vec aVec1( P( 2 ) - P( 1 ) );
505 gp_Vec aVec2( P( 3 ) - P( 1 ) );
506 gp_Vec aVec3( P( 4 ) - P( 1 ) );
507 gp_Vec anAreaVec( aVec1 ^ aVec2 );
508 return fabs(aVec3 * anAreaVec) / 6.0;
511 inline double getMaxHeight(double theLen[6])
513 double aHeight = max(theLen[0],theLen[1]);
514 aHeight = max(aHeight,theLen[2]);
515 aHeight = max(aHeight,theLen[3]);
516 aHeight = max(aHeight,theLen[4]);
517 aHeight = max(aHeight,theLen[5]);
523 double AspectRatio3D::GetValue( const TSequenceOfXYZ& P )
525 double aQuality = 0.0;
526 if(myCurrElement->IsPoly()) return aQuality;
528 int nbNodes = P.size();
530 if(myCurrElement->IsQuadratic()) {
531 if(nbNodes==10) nbNodes=4; // quadratic tetrahedron
532 else if(nbNodes==13) nbNodes=5; // quadratic pyramid
533 else if(nbNodes==15) nbNodes=6; // quadratic pentahedron
534 else if(nbNodes==20) nbNodes=8; // quadratic hexahedron
535 else return aQuality;
541 getDistance(P( 1 ),P( 2 )), // a
542 getDistance(P( 2 ),P( 3 )), // b
543 getDistance(P( 3 ),P( 1 )), // c
544 getDistance(P( 2 ),P( 4 )), // d
545 getDistance(P( 3 ),P( 4 )), // e
546 getDistance(P( 1 ),P( 4 )) // f
548 double aTria[4][3] = {
549 {aLen[0],aLen[1],aLen[2]}, // abc
550 {aLen[0],aLen[3],aLen[5]}, // adf
551 {aLen[1],aLen[3],aLen[4]}, // bde
552 {aLen[2],aLen[4],aLen[5]} // cef
554 double aSumArea = 0.0;
555 double aHalfPerimeter = getHalfPerimeter(aTria[0]);
556 double anArea = getArea(aHalfPerimeter,aTria[0]);
558 aHalfPerimeter = getHalfPerimeter(aTria[1]);
559 anArea = getArea(aHalfPerimeter,aTria[1]);
561 aHalfPerimeter = getHalfPerimeter(aTria[2]);
562 anArea = getArea(aHalfPerimeter,aTria[2]);
564 aHalfPerimeter = getHalfPerimeter(aTria[3]);
565 anArea = getArea(aHalfPerimeter,aTria[3]);
567 double aVolume = getVolume(P);
568 //double aVolume = getVolume(aLen);
569 double aHeight = getMaxHeight(aLen);
570 static double aCoeff = sqrt(2.0)/12.0;
571 if ( aVolume > DBL_MIN )
572 aQuality = aCoeff*aHeight*aSumArea/aVolume;
577 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 3 ),P( 5 )};
578 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
581 gp_XYZ aXYZ[4] = {P( 1 ),P( 3 ),P( 4 ),P( 5 )};
582 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
585 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 5 )};
586 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
589 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 4 ),P( 5 )};
590 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
596 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 6 )};
597 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
600 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 3 )};
601 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
604 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 6 )};
605 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( 2 ),P( 5 ),P( 4 ),P( 6 )};
613 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
616 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 3 )};
617 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
623 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
624 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
627 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 4 )};
628 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
631 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 7 )};
632 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
635 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 8 )};
636 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
639 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 3 )};
640 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
643 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 4 )};
644 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
647 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 7 )};
648 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
651 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 8 )};
652 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
655 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 3 )};
656 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
659 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 4 )};
660 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
663 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 7 )};
664 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
667 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 8 )};
668 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
671 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 1 )};
672 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
675 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 2 )};
676 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
679 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 5 )};
680 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
683 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 6 )};
684 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
687 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 1 )};
688 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
691 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 2 )};
692 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
695 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 5 )};
696 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
699 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 6 )};
700 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
703 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 1 )};
704 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
707 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
708 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
711 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 5 )};
712 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
715 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 6 )};
716 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
719 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
720 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
723 gp_XYZ aXYZ[4] = {P( 4 ),P( 5 ),P( 8 ),P( 2 )};
724 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
727 gp_XYZ aXYZ[4] = {P( 1 ),P( 4 ),P( 5 ),P( 3 )};
728 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
731 gp_XYZ aXYZ[4] = {P( 3 ),P( 6 ),P( 7 ),P( 1 )};
732 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
735 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 6 ),P( 4 )};
736 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
739 gp_XYZ aXYZ[4] = {P( 5 ),P( 6 ),P( 8 ),P( 3 )};
740 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
743 gp_XYZ aXYZ[4] = {P( 7 ),P( 8 ),P( 6 ),P( 1 )};
744 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
747 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 7 )};
748 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
751 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 2 ),P( 5 )};
752 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
758 // avaluate aspect ratio of quadranle faces
759 AspectRatio aspect2D;
760 SMDS_VolumeTool::VolumeType type = SMDS_VolumeTool::GetType( nbNodes );
761 int nbFaces = SMDS_VolumeTool::NbFaces( type );
762 TSequenceOfXYZ points(4);
763 for ( int i = 0; i < nbFaces; ++i ) { // loop on faces of a volume
764 if ( SMDS_VolumeTool::NbFaceNodes( type, i ) != 4 )
766 const int* pInd = SMDS_VolumeTool::GetFaceNodesIndices( type, i, true );
767 for ( int p = 0; p < 4; ++p ) // loop on nodes of a quadranle face
768 points( p + 1 ) = P( pInd[ p ] + 1 );
769 aQuality = max( aQuality, aspect2D.GetValue( points ));
775 double AspectRatio3D::GetBadRate( double Value, int /*nbNodes*/ ) const
777 // the aspect ratio is in the range [1.0,infinity]
780 return Value / 1000.;
783 SMDSAbs_ElementType AspectRatio3D::GetType() const
785 return SMDSAbs_Volume;
791 Description : Functor for calculating warping
793 double Warping::GetValue( const TSequenceOfXYZ& P )
798 gp_XYZ G = ( P( 1 ) + P( 2 ) + P( 3 ) + P( 4 ) ) / 4.;
800 double A1 = ComputeA( P( 1 ), P( 2 ), P( 3 ), G );
801 double A2 = ComputeA( P( 2 ), P( 3 ), P( 4 ), G );
802 double A3 = ComputeA( P( 3 ), P( 4 ), P( 1 ), G );
803 double A4 = ComputeA( P( 4 ), P( 1 ), P( 2 ), G );
805 return Max( Max( A1, A2 ), Max( A3, A4 ) );
808 double Warping::ComputeA( const gp_XYZ& thePnt1,
809 const gp_XYZ& thePnt2,
810 const gp_XYZ& thePnt3,
811 const gp_XYZ& theG ) const
813 double aLen1 = gp_Pnt( thePnt1 ).Distance( gp_Pnt( thePnt2 ) );
814 double aLen2 = gp_Pnt( thePnt2 ).Distance( gp_Pnt( thePnt3 ) );
815 double L = Min( aLen1, aLen2 ) * 0.5;
816 if ( L < Precision::Confusion())
819 gp_XYZ GI = ( thePnt2 + thePnt1 ) / 2. - theG;
820 gp_XYZ GJ = ( thePnt3 + thePnt2 ) / 2. - theG;
821 gp_XYZ N = GI.Crossed( GJ );
823 if ( N.Modulus() < gp::Resolution() )
828 double H = ( thePnt2 - theG ).Dot( N );
829 return asin( fabs( H / L ) ) * 180. / PI;
832 double Warping::GetBadRate( double Value, int /*nbNodes*/ ) const
834 // the warp is in the range [0.0,PI/2]
835 // 0.0 = good (no warp)
836 // PI/2 = bad (face pliee)
840 SMDSAbs_ElementType Warping::GetType() const
848 Description : Functor for calculating taper
850 double Taper::GetValue( const TSequenceOfXYZ& P )
856 double J1 = getArea( P( 4 ), P( 1 ), P( 2 ) ) / 2.;
857 double J2 = getArea( P( 3 ), P( 1 ), P( 2 ) ) / 2.;
858 double J3 = getArea( P( 2 ), P( 3 ), P( 4 ) ) / 2.;
859 double J4 = getArea( P( 3 ), P( 4 ), P( 1 ) ) / 2.;
861 double JA = 0.25 * ( J1 + J2 + J3 + J4 );
862 if ( JA <= Precision::Confusion() )
865 double T1 = fabs( ( J1 - JA ) / JA );
866 double T2 = fabs( ( J2 - JA ) / JA );
867 double T3 = fabs( ( J3 - JA ) / JA );
868 double T4 = fabs( ( J4 - JA ) / JA );
870 return Max( Max( T1, T2 ), Max( T3, T4 ) );
873 double Taper::GetBadRate( double Value, int /*nbNodes*/ ) const
875 // the taper is in the range [0.0,1.0]
876 // 0.0 = good (no taper)
877 // 1.0 = bad (les cotes opposes sont allignes)
881 SMDSAbs_ElementType Taper::GetType() const
889 Description : Functor for calculating skew in degrees
891 static inline double skewAngle( const gp_XYZ& p1, const gp_XYZ& p2, const gp_XYZ& p3 )
893 gp_XYZ p12 = ( p2 + p1 ) / 2.;
894 gp_XYZ p23 = ( p3 + p2 ) / 2.;
895 gp_XYZ p31 = ( p3 + p1 ) / 2.;
897 gp_Vec v1( p31 - p2 ), v2( p12 - p23 );
899 return v1.Magnitude() < gp::Resolution() || v2.Magnitude() < gp::Resolution() ? 0. : v1.Angle( v2 );
902 double Skew::GetValue( const TSequenceOfXYZ& P )
904 if ( P.size() != 3 && P.size() != 4 )
908 static double PI2 = PI / 2.;
911 double A0 = fabs( PI2 - skewAngle( P( 3 ), P( 1 ), P( 2 ) ) );
912 double A1 = fabs( PI2 - skewAngle( P( 1 ), P( 2 ), P( 3 ) ) );
913 double A2 = fabs( PI2 - skewAngle( P( 2 ), P( 3 ), P( 1 ) ) );
915 return Max( A0, Max( A1, A2 ) ) * 180. / PI;
919 gp_XYZ p12 = ( P( 1 ) + P( 2 ) ) / 2.;
920 gp_XYZ p23 = ( P( 2 ) + P( 3 ) ) / 2.;
921 gp_XYZ p34 = ( P( 3 ) + P( 4 ) ) / 2.;
922 gp_XYZ p41 = ( P( 4 ) + P( 1 ) ) / 2.;
924 gp_Vec v1( p34 - p12 ), v2( p23 - p41 );
925 double A = v1.Magnitude() <= gp::Resolution() || v2.Magnitude() <= gp::Resolution()
926 ? 0. : fabs( PI2 - v1.Angle( v2 ) );
929 if ( A < Precision::Angular() )
932 return A * 180. / PI;
936 double Skew::GetBadRate( double Value, int /*nbNodes*/ ) const
938 // the skew is in the range [0.0,PI/2].
944 SMDSAbs_ElementType Skew::GetType() const
952 Description : Functor for calculating area
954 double Area::GetValue( const TSequenceOfXYZ& P )
956 gp_Vec aVec1( P(2) - P(1) );
957 gp_Vec aVec2( P(3) - P(1) );
958 gp_Vec SumVec = aVec1 ^ aVec2;
959 for (int i=4; i<=P.size(); i++) {
960 gp_Vec aVec1( P(i-1) - P(1) );
961 gp_Vec aVec2( P(i) - P(1) );
962 gp_Vec tmp = aVec1 ^ aVec2;
965 return SumVec.Magnitude() * 0.5;
968 double Area::GetBadRate( double Value, int /*nbNodes*/ ) const
970 // meaningless as it is not a quality control functor
974 SMDSAbs_ElementType Area::GetType() const
982 Description : Functor for calculating length off edge
984 double Length::GetValue( const TSequenceOfXYZ& P )
986 switch ( P.size() ) {
987 case 2: return getDistance( P( 1 ), P( 2 ) );
988 case 3: return getDistance( P( 1 ), P( 2 ) ) + getDistance( P( 2 ), P( 3 ) );
993 double Length::GetBadRate( double Value, int /*nbNodes*/ ) const
995 // meaningless as it is not quality control functor
999 SMDSAbs_ElementType Length::GetType() const
1001 return SMDSAbs_Edge;
1006 Description : Functor for calculating length of edge
1009 double Length2D::GetValue( long theElementId)
1013 //cout<<"Length2D::GetValue"<<endl;
1014 if (GetPoints(theElementId,P)){
1015 //for(int jj=1; jj<=P.size(); jj++)
1016 // cout<<"jj="<<jj<<" P("<<P(jj).X()<<","<<P(jj).Y()<<","<<P(jj).Z()<<")"<<endl;
1018 double aVal;// = GetValue( P );
1019 const SMDS_MeshElement* aElem = myMesh->FindElement( theElementId );
1020 SMDSAbs_ElementType aType = aElem->GetType();
1029 aVal = getDistance( P( 1 ), P( 2 ) );
1032 else if (len == 3){ // quadratic edge
1033 aVal = getDistance(P( 1 ),P( 3 )) + getDistance(P( 3 ),P( 2 ));
1037 if (len == 3){ // triangles
1038 double L1 = getDistance(P( 1 ),P( 2 ));
1039 double L2 = getDistance(P( 2 ),P( 3 ));
1040 double L3 = getDistance(P( 3 ),P( 1 ));
1041 aVal = Max(L1,Max(L2,L3));
1044 else if (len == 4){ // quadrangles
1045 double L1 = getDistance(P( 1 ),P( 2 ));
1046 double L2 = getDistance(P( 2 ),P( 3 ));
1047 double L3 = getDistance(P( 3 ),P( 4 ));
1048 double L4 = getDistance(P( 4 ),P( 1 ));
1049 aVal = Max(Max(L1,L2),Max(L3,L4));
1052 if (len == 6){ // quadratic triangles
1053 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1054 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1055 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 1 ));
1056 aVal = Max(L1,Max(L2,L3));
1057 //cout<<"L1="<<L1<<" L2="<<L2<<"L3="<<L3<<" aVal="<<aVal<<endl;
1060 else if (len == 8){ // quadratic quadrangles
1061 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1062 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1063 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 7 ));
1064 double L4 = getDistance(P( 7 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
1065 aVal = Max(Max(L1,L2),Max(L3,L4));
1068 case SMDSAbs_Volume:
1069 if (len == 4){ // tetraidrs
1070 double L1 = getDistance(P( 1 ),P( 2 ));
1071 double L2 = getDistance(P( 2 ),P( 3 ));
1072 double L3 = getDistance(P( 3 ),P( 1 ));
1073 double L4 = getDistance(P( 1 ),P( 4 ));
1074 double L5 = getDistance(P( 2 ),P( 4 ));
1075 double L6 = getDistance(P( 3 ),P( 4 ));
1076 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1079 else if (len == 5){ // piramids
1080 double L1 = getDistance(P( 1 ),P( 2 ));
1081 double L2 = getDistance(P( 2 ),P( 3 ));
1082 double L3 = getDistance(P( 3 ),P( 1 ));
1083 double L4 = getDistance(P( 4 ),P( 1 ));
1084 double L5 = getDistance(P( 1 ),P( 5 ));
1085 double L6 = getDistance(P( 2 ),P( 5 ));
1086 double L7 = getDistance(P( 3 ),P( 5 ));
1087 double L8 = getDistance(P( 4 ),P( 5 ));
1089 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1090 aVal = Max(aVal,Max(L7,L8));
1093 else if (len == 6){ // pentaidres
1094 double L1 = getDistance(P( 1 ),P( 2 ));
1095 double L2 = getDistance(P( 2 ),P( 3 ));
1096 double L3 = getDistance(P( 3 ),P( 1 ));
1097 double L4 = getDistance(P( 4 ),P( 5 ));
1098 double L5 = getDistance(P( 5 ),P( 6 ));
1099 double L6 = getDistance(P( 6 ),P( 4 ));
1100 double L7 = getDistance(P( 1 ),P( 4 ));
1101 double L8 = getDistance(P( 2 ),P( 5 ));
1102 double L9 = getDistance(P( 3 ),P( 6 ));
1104 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1105 aVal = Max(aVal,Max(Max(L7,L8),L9));
1108 else if (len == 8){ // hexaider
1109 double L1 = getDistance(P( 1 ),P( 2 ));
1110 double L2 = getDistance(P( 2 ),P( 3 ));
1111 double L3 = getDistance(P( 3 ),P( 4 ));
1112 double L4 = getDistance(P( 4 ),P( 1 ));
1113 double L5 = getDistance(P( 5 ),P( 6 ));
1114 double L6 = getDistance(P( 6 ),P( 7 ));
1115 double L7 = getDistance(P( 7 ),P( 8 ));
1116 double L8 = getDistance(P( 8 ),P( 5 ));
1117 double L9 = getDistance(P( 1 ),P( 5 ));
1118 double L10= getDistance(P( 2 ),P( 6 ));
1119 double L11= getDistance(P( 3 ),P( 7 ));
1120 double L12= getDistance(P( 4 ),P( 8 ));
1122 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1123 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
1124 aVal = Max(aVal,Max(L11,L12));
1129 if (len == 10){ // quadratic tetraidrs
1130 double L1 = getDistance(P( 1 ),P( 5 )) + getDistance(P( 5 ),P( 2 ));
1131 double L2 = getDistance(P( 2 ),P( 6 )) + getDistance(P( 6 ),P( 3 ));
1132 double L3 = getDistance(P( 3 ),P( 7 )) + getDistance(P( 7 ),P( 1 ));
1133 double L4 = getDistance(P( 1 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
1134 double L5 = getDistance(P( 2 ),P( 9 )) + getDistance(P( 9 ),P( 4 ));
1135 double L6 = getDistance(P( 3 ),P( 10 )) + getDistance(P( 10 ),P( 4 ));
1136 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1139 else if (len == 13){ // quadratic piramids
1140 double L1 = getDistance(P( 1 ),P( 6 )) + getDistance(P( 6 ),P( 2 ));
1141 double L2 = getDistance(P( 2 ),P( 7 )) + getDistance(P( 7 ),P( 3 ));
1142 double L3 = getDistance(P( 3 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
1143 double L4 = getDistance(P( 4 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1144 double L5 = getDistance(P( 1 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1145 double L6 = getDistance(P( 2 ),P( 11 )) + getDistance(P( 11 ),P( 5 ));
1146 double L7 = getDistance(P( 3 ),P( 12 )) + getDistance(P( 12 ),P( 5 ));
1147 double L8 = getDistance(P( 4 ),P( 13 )) + getDistance(P( 13 ),P( 5 ));
1148 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1149 aVal = Max(aVal,Max(L7,L8));
1152 else if (len == 15){ // quadratic pentaidres
1153 double L1 = getDistance(P( 1 ),P( 7 )) + getDistance(P( 7 ),P( 2 ));
1154 double L2 = getDistance(P( 2 ),P( 8 )) + getDistance(P( 8 ),P( 3 ));
1155 double L3 = getDistance(P( 3 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1156 double L4 = getDistance(P( 4 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1157 double L5 = getDistance(P( 5 ),P( 11 )) + getDistance(P( 11 ),P( 6 ));
1158 double L6 = getDistance(P( 6 ),P( 12 )) + getDistance(P( 12 ),P( 4 ));
1159 double L7 = getDistance(P( 1 ),P( 13 )) + getDistance(P( 13 ),P( 4 ));
1160 double L8 = getDistance(P( 2 ),P( 14 )) + getDistance(P( 14 ),P( 5 ));
1161 double L9 = getDistance(P( 3 ),P( 15 )) + getDistance(P( 15 ),P( 6 ));
1162 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1163 aVal = Max(aVal,Max(Max(L7,L8),L9));
1166 else if (len == 20){ // quadratic hexaider
1167 double L1 = getDistance(P( 1 ),P( 9 )) + getDistance(P( 9 ),P( 2 ));
1168 double L2 = getDistance(P( 2 ),P( 10 )) + getDistance(P( 10 ),P( 3 ));
1169 double L3 = getDistance(P( 3 ),P( 11 )) + getDistance(P( 11 ),P( 4 ));
1170 double L4 = getDistance(P( 4 ),P( 12 )) + getDistance(P( 12 ),P( 1 ));
1171 double L5 = getDistance(P( 5 ),P( 13 )) + getDistance(P( 13 ),P( 6 ));
1172 double L6 = getDistance(P( 6 ),P( 14 )) + getDistance(P( 14 ),P( 7 ));
1173 double L7 = getDistance(P( 7 ),P( 15 )) + getDistance(P( 15 ),P( 8 ));
1174 double L8 = getDistance(P( 8 ),P( 16 )) + getDistance(P( 16 ),P( 5 ));
1175 double L9 = getDistance(P( 1 ),P( 17 )) + getDistance(P( 17 ),P( 5 ));
1176 double L10= getDistance(P( 2 ),P( 18 )) + getDistance(P( 18 ),P( 6 ));
1177 double L11= getDistance(P( 3 ),P( 19 )) + getDistance(P( 19 ),P( 7 ));
1178 double L12= getDistance(P( 4 ),P( 20 )) + getDistance(P( 20 ),P( 8 ));
1179 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1180 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
1181 aVal = Max(aVal,Max(L11,L12));
1193 if ( myPrecision >= 0 )
1195 double prec = pow( 10., (double)( myPrecision ) );
1196 aVal = floor( aVal * prec + 0.5 ) / prec;
1205 double Length2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1207 // meaningless as it is not quality control functor
1211 SMDSAbs_ElementType Length2D::GetType() const
1213 return SMDSAbs_Face;
1216 Length2D::Value::Value(double theLength,long thePntId1, long thePntId2):
1219 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1220 if(thePntId1 > thePntId2){
1221 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1225 bool Length2D::Value::operator<(const Length2D::Value& x) const{
1226 if(myPntId[0] < x.myPntId[0]) return true;
1227 if(myPntId[0] == x.myPntId[0])
1228 if(myPntId[1] < x.myPntId[1]) return true;
1232 void Length2D::GetValues(TValues& theValues){
1234 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1235 for(; anIter->more(); ){
1236 const SMDS_MeshFace* anElem = anIter->next();
1238 if(anElem->IsQuadratic()) {
1239 const SMDS_QuadraticFaceOfNodes* F =
1240 static_cast<const SMDS_QuadraticFaceOfNodes*>(anElem);
1241 // use special nodes iterator
1242 SMDS_NodeIteratorPtr anIter = F->interlacedNodesIterator();
1247 const SMDS_MeshElement* aNode;
1249 aNode = anIter->next();
1250 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1251 P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1252 aNodeId[0] = aNodeId[1] = aNode->GetID();
1255 for(; anIter->more(); ){
1256 const SMDS_MeshNode* N1 = static_cast<const SMDS_MeshNode*> (anIter->next());
1257 P[2] = gp_Pnt(N1->X(),N1->Y(),N1->Z());
1258 aNodeId[2] = N1->GetID();
1259 aLength = P[1].Distance(P[2]);
1260 if(!anIter->more()) break;
1261 const SMDS_MeshNode* N2 = static_cast<const SMDS_MeshNode*> (anIter->next());
1262 P[3] = gp_Pnt(N2->X(),N2->Y(),N2->Z());
1263 aNodeId[3] = N2->GetID();
1264 aLength += P[2].Distance(P[3]);
1265 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1266 Value aValue2(aLength,aNodeId[2],aNodeId[3]);
1268 aNodeId[1] = aNodeId[3];
1269 theValues.insert(aValue1);
1270 theValues.insert(aValue2);
1272 aLength += P[2].Distance(P[0]);
1273 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1274 Value aValue2(aLength,aNodeId[2],aNodeId[0]);
1275 theValues.insert(aValue1);
1276 theValues.insert(aValue2);
1279 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
1284 const SMDS_MeshElement* aNode;
1285 if(aNodesIter->more()){
1286 aNode = aNodesIter->next();
1287 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1288 P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1289 aNodeId[0] = aNodeId[1] = aNode->GetID();
1292 for(; aNodesIter->more(); ){
1293 aNode = aNodesIter->next();
1294 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1295 long anId = aNode->GetID();
1297 P[2] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1299 aLength = P[1].Distance(P[2]);
1301 Value aValue(aLength,aNodeId[1],anId);
1304 theValues.insert(aValue);
1307 aLength = P[0].Distance(P[1]);
1309 Value aValue(aLength,aNodeId[0],aNodeId[1]);
1310 theValues.insert(aValue);
1316 Class : MultiConnection
1317 Description : Functor for calculating number of faces conneted to the edge
1319 double MultiConnection::GetValue( const TSequenceOfXYZ& P )
1323 double MultiConnection::GetValue( long theId )
1325 return getNbMultiConnection( myMesh, theId );
1328 double MultiConnection::GetBadRate( double Value, int /*nbNodes*/ ) const
1330 // meaningless as it is not quality control functor
1334 SMDSAbs_ElementType MultiConnection::GetType() const
1336 return SMDSAbs_Edge;
1340 Class : MultiConnection2D
1341 Description : Functor for calculating number of faces conneted to the edge
1343 double MultiConnection2D::GetValue( const TSequenceOfXYZ& P )
1348 double MultiConnection2D::GetValue( long theElementId )
1352 const SMDS_MeshElement* aFaceElem = myMesh->FindElement(theElementId);
1353 SMDSAbs_ElementType aType = aFaceElem->GetType();
1358 int i = 0, len = aFaceElem->NbNodes();
1359 SMDS_ElemIteratorPtr anIter = aFaceElem->nodesIterator();
1362 const SMDS_MeshNode *aNode, *aNode0;
1363 TColStd_MapOfInteger aMap, aMapPrev;
1365 for (i = 0; i <= len; i++) {
1370 if (anIter->more()) {
1371 aNode = (SMDS_MeshNode*)anIter->next();
1379 if (i == 0) aNode0 = aNode;
1381 SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator();
1382 while (anElemIter->more()) {
1383 const SMDS_MeshElement* anElem = anElemIter->next();
1384 if (anElem != 0 && anElem->GetType() == SMDSAbs_Face) {
1385 int anId = anElem->GetID();
1388 if (aMapPrev.Contains(anId)) {
1393 aResult = Max(aResult, aNb);
1404 double MultiConnection2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1406 // meaningless as it is not quality control functor
1410 SMDSAbs_ElementType MultiConnection2D::GetType() const
1412 return SMDSAbs_Face;
1415 MultiConnection2D::Value::Value(long thePntId1, long thePntId2)
1417 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1418 if(thePntId1 > thePntId2){
1419 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1423 bool MultiConnection2D::Value::operator<(const MultiConnection2D::Value& x) const{
1424 if(myPntId[0] < x.myPntId[0]) return true;
1425 if(myPntId[0] == x.myPntId[0])
1426 if(myPntId[1] < x.myPntId[1]) return true;
1430 void MultiConnection2D::GetValues(MValues& theValues){
1431 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1432 for(; anIter->more(); ){
1433 const SMDS_MeshFace* anElem = anIter->next();
1434 SMDS_ElemIteratorPtr aNodesIter;
1435 if ( anElem->IsQuadratic() )
1436 aNodesIter = static_cast<const SMDS_QuadraticFaceOfNodes*>
1437 (anElem)->interlacedNodesElemIterator();
1439 aNodesIter = anElem->nodesIterator();
1442 //int aNbConnects=0;
1443 const SMDS_MeshNode* aNode0;
1444 const SMDS_MeshNode* aNode1;
1445 const SMDS_MeshNode* aNode2;
1446 if(aNodesIter->more()){
1447 aNode0 = (SMDS_MeshNode*) aNodesIter->next();
1449 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode1;
1450 aNodeId[0] = aNodeId[1] = aNodes->GetID();
1452 for(; aNodesIter->more(); ) {
1453 aNode2 = (SMDS_MeshNode*) aNodesIter->next();
1454 long anId = aNode2->GetID();
1457 Value aValue(aNodeId[1],aNodeId[2]);
1458 MValues::iterator aItr = theValues.find(aValue);
1459 if (aItr != theValues.end()){
1464 theValues[aValue] = 1;
1467 //cout << "NodeIds: "<<aNodeId[1]<<","<<aNodeId[2]<<" nbconn="<<aNbConnects<<endl;
1468 aNodeId[1] = aNodeId[2];
1471 Value aValue(aNodeId[0],aNodeId[2]);
1472 MValues::iterator aItr = theValues.find(aValue);
1473 if (aItr != theValues.end()) {
1478 theValues[aValue] = 1;
1481 //cout << "NodeIds: "<<aNodeId[0]<<","<<aNodeId[2]<<" nbconn="<<aNbConnects<<endl;
1491 Class : BadOrientedVolume
1492 Description : Predicate bad oriented volumes
1495 BadOrientedVolume::BadOrientedVolume()
1500 void BadOrientedVolume::SetMesh( const SMDS_Mesh* theMesh )
1505 bool BadOrientedVolume::IsSatisfy( long theId )
1510 SMDS_VolumeTool vTool( myMesh->FindElement( theId ));
1511 return !vTool.IsForward();
1514 SMDSAbs_ElementType BadOrientedVolume::GetType() const
1516 return SMDSAbs_Volume;
1523 Description : Predicate for free borders
1526 FreeBorders::FreeBorders()
1531 void FreeBorders::SetMesh( const SMDS_Mesh* theMesh )
1536 bool FreeBorders::IsSatisfy( long theId )
1538 return getNbMultiConnection( myMesh, theId ) == 1;
1541 SMDSAbs_ElementType FreeBorders::GetType() const
1543 return SMDSAbs_Edge;
1549 Description : Predicate for free Edges
1551 FreeEdges::FreeEdges()
1556 void FreeEdges::SetMesh( const SMDS_Mesh* theMesh )
1561 bool FreeEdges::IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId )
1563 TColStd_MapOfInteger aMap;
1564 for ( int i = 0; i < 2; i++ )
1566 SMDS_ElemIteratorPtr anElemIter = theNodes[ i ]->GetInverseElementIterator();
1567 while( anElemIter->more() )
1569 const SMDS_MeshElement* anElem = anElemIter->next();
1570 if ( anElem != 0 && anElem->GetType() == SMDSAbs_Face )
1572 int anId = anElem->GetID();
1576 else if ( aMap.Contains( anId ) && anId != theFaceId )
1584 bool FreeEdges::IsSatisfy( long theId )
1589 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
1590 if ( aFace == 0 || aFace->GetType() != SMDSAbs_Face || aFace->NbNodes() < 3 )
1593 SMDS_ElemIteratorPtr anIter;
1594 if ( aFace->IsQuadratic() ) {
1595 anIter = static_cast<const SMDS_QuadraticFaceOfNodes*>
1596 (aFace)->interlacedNodesElemIterator();
1599 anIter = aFace->nodesIterator();
1604 int i = 0, nbNodes = aFace->NbNodes();
1605 vector <const SMDS_MeshNode*> aNodes( nbNodes+1 );
1606 while( anIter->more() )
1608 const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next();
1611 aNodes[ i++ ] = aNode;
1613 aNodes[ nbNodes ] = aNodes[ 0 ];
1615 for ( i = 0; i < nbNodes; i++ )
1616 if ( IsFreeEdge( &aNodes[ i ], theId ) )
1622 SMDSAbs_ElementType FreeEdges::GetType() const
1624 return SMDSAbs_Face;
1627 FreeEdges::Border::Border(long theElemId, long thePntId1, long thePntId2):
1630 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1631 if(thePntId1 > thePntId2){
1632 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1636 bool FreeEdges::Border::operator<(const FreeEdges::Border& x) const{
1637 if(myPntId[0] < x.myPntId[0]) return true;
1638 if(myPntId[0] == x.myPntId[0])
1639 if(myPntId[1] < x.myPntId[1]) return true;
1643 inline void UpdateBorders(const FreeEdges::Border& theBorder,
1644 FreeEdges::TBorders& theRegistry,
1645 FreeEdges::TBorders& theContainer)
1647 if(theRegistry.find(theBorder) == theRegistry.end()){
1648 theRegistry.insert(theBorder);
1649 theContainer.insert(theBorder);
1651 theContainer.erase(theBorder);
1655 void FreeEdges::GetBoreders(TBorders& theBorders)
1658 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1659 for(; anIter->more(); ){
1660 const SMDS_MeshFace* anElem = anIter->next();
1661 long anElemId = anElem->GetID();
1662 SMDS_ElemIteratorPtr aNodesIter;
1663 if ( anElem->IsQuadratic() )
1664 aNodesIter = static_cast<const SMDS_QuadraticFaceOfNodes*>(anElem)->
1665 interlacedNodesElemIterator();
1667 aNodesIter = anElem->nodesIterator();
1669 const SMDS_MeshElement* aNode;
1670 if(aNodesIter->more()){
1671 aNode = aNodesIter->next();
1672 aNodeId[0] = aNodeId[1] = aNode->GetID();
1674 for(; aNodesIter->more(); ){
1675 aNode = aNodesIter->next();
1676 long anId = aNode->GetID();
1677 Border aBorder(anElemId,aNodeId[1],anId);
1679 //std::cout<<aBorder.myPntId[0]<<"; "<<aBorder.myPntId[1]<<"; "<<aBorder.myElemId<<endl;
1680 UpdateBorders(aBorder,aRegistry,theBorders);
1682 Border aBorder(anElemId,aNodeId[0],aNodeId[1]);
1683 //std::cout<<aBorder.myPntId[0]<<"; "<<aBorder.myPntId[1]<<"; "<<aBorder.myElemId<<endl;
1684 UpdateBorders(aBorder,aRegistry,theBorders);
1686 //std::cout<<"theBorders.size() = "<<theBorders.size()<<endl;
1691 Description : Predicate for Range of Ids.
1692 Range may be specified with two ways.
1693 1. Using AddToRange method
1694 2. With SetRangeStr method. Parameter of this method is a string
1695 like as "1,2,3,50-60,63,67,70-"
1698 //=======================================================================
1699 // name : RangeOfIds
1700 // Purpose : Constructor
1701 //=======================================================================
1702 RangeOfIds::RangeOfIds()
1705 myType = SMDSAbs_All;
1708 //=======================================================================
1710 // Purpose : Set mesh
1711 //=======================================================================
1712 void RangeOfIds::SetMesh( const SMDS_Mesh* theMesh )
1717 //=======================================================================
1718 // name : AddToRange
1719 // Purpose : Add ID to the range
1720 //=======================================================================
1721 bool RangeOfIds::AddToRange( long theEntityId )
1723 myIds.Add( theEntityId );
1727 //=======================================================================
1728 // name : GetRangeStr
1729 // Purpose : Get range as a string.
1730 // Example: "1,2,3,50-60,63,67,70-"
1731 //=======================================================================
1732 void RangeOfIds::GetRangeStr( TCollection_AsciiString& theResStr )
1736 TColStd_SequenceOfInteger anIntSeq;
1737 TColStd_SequenceOfAsciiString aStrSeq;
1739 TColStd_MapIteratorOfMapOfInteger anIter( myIds );
1740 for ( ; anIter.More(); anIter.Next() )
1742 int anId = anIter.Key();
1743 TCollection_AsciiString aStr( anId );
1744 anIntSeq.Append( anId );
1745 aStrSeq.Append( aStr );
1748 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
1750 int aMinId = myMin( i );
1751 int aMaxId = myMax( i );
1753 TCollection_AsciiString aStr;
1754 if ( aMinId != IntegerFirst() )
1759 if ( aMaxId != IntegerLast() )
1762 // find position of the string in result sequence and insert string in it
1763 if ( anIntSeq.Length() == 0 )
1765 anIntSeq.Append( aMinId );
1766 aStrSeq.Append( aStr );
1770 if ( aMinId < anIntSeq.First() )
1772 anIntSeq.Prepend( aMinId );
1773 aStrSeq.Prepend( aStr );
1775 else if ( aMinId > anIntSeq.Last() )
1777 anIntSeq.Append( aMinId );
1778 aStrSeq.Append( aStr );
1781 for ( int j = 1, k = anIntSeq.Length(); j <= k; j++ )
1782 if ( aMinId < anIntSeq( j ) )
1784 anIntSeq.InsertBefore( j, aMinId );
1785 aStrSeq.InsertBefore( j, aStr );
1791 if ( aStrSeq.Length() == 0 )
1794 theResStr = aStrSeq( 1 );
1795 for ( int j = 2, k = aStrSeq.Length(); j <= k; j++ )
1798 theResStr += aStrSeq( j );
1802 //=======================================================================
1803 // name : SetRangeStr
1804 // Purpose : Define range with string
1805 // Example of entry string: "1,2,3,50-60,63,67,70-"
1806 //=======================================================================
1807 bool RangeOfIds::SetRangeStr( const TCollection_AsciiString& theStr )
1813 TCollection_AsciiString aStr = theStr;
1814 aStr.RemoveAll( ' ' );
1815 aStr.RemoveAll( '\t' );
1817 for ( int aPos = aStr.Search( ",," ); aPos != -1; aPos = aStr.Search( ",," ) )
1818 aStr.Remove( aPos, 2 );
1820 TCollection_AsciiString tmpStr = aStr.Token( ",", 1 );
1822 while ( tmpStr != "" )
1824 tmpStr = aStr.Token( ",", i++ );
1825 int aPos = tmpStr.Search( '-' );
1829 if ( tmpStr.IsIntegerValue() )
1830 myIds.Add( tmpStr.IntegerValue() );
1836 TCollection_AsciiString aMaxStr = tmpStr.Split( aPos );
1837 TCollection_AsciiString aMinStr = tmpStr;
1839 while ( aMinStr.Search( "-" ) != -1 ) aMinStr.RemoveAll( '-' );
1840 while ( aMaxStr.Search( "-" ) != -1 ) aMaxStr.RemoveAll( '-' );
1842 if ( !aMinStr.IsEmpty() && !aMinStr.IsIntegerValue() ||
1843 !aMaxStr.IsEmpty() && !aMaxStr.IsIntegerValue() )
1846 myMin.Append( aMinStr.IsEmpty() ? IntegerFirst() : aMinStr.IntegerValue() );
1847 myMax.Append( aMaxStr.IsEmpty() ? IntegerLast() : aMaxStr.IntegerValue() );
1854 //=======================================================================
1856 // Purpose : Get type of supported entities
1857 //=======================================================================
1858 SMDSAbs_ElementType RangeOfIds::GetType() const
1863 //=======================================================================
1865 // Purpose : Set type of supported entities
1866 //=======================================================================
1867 void RangeOfIds::SetType( SMDSAbs_ElementType theType )
1872 //=======================================================================
1874 // Purpose : Verify whether entity satisfies to this rpedicate
1875 //=======================================================================
1876 bool RangeOfIds::IsSatisfy( long theId )
1881 if ( myType == SMDSAbs_Node )
1883 if ( myMesh->FindNode( theId ) == 0 )
1888 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
1889 if ( anElem == 0 || myType != anElem->GetType() && myType != SMDSAbs_All )
1893 if ( myIds.Contains( theId ) )
1896 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
1897 if ( theId >= myMin( i ) && theId <= myMax( i ) )
1905 Description : Base class for comparators
1907 Comparator::Comparator():
1911 Comparator::~Comparator()
1914 void Comparator::SetMesh( const SMDS_Mesh* theMesh )
1917 myFunctor->SetMesh( theMesh );
1920 void Comparator::SetMargin( double theValue )
1922 myMargin = theValue;
1925 void Comparator::SetNumFunctor( NumericalFunctorPtr theFunct )
1927 myFunctor = theFunct;
1930 SMDSAbs_ElementType Comparator::GetType() const
1932 return myFunctor ? myFunctor->GetType() : SMDSAbs_All;
1935 double Comparator::GetMargin()
1943 Description : Comparator "<"
1945 bool LessThan::IsSatisfy( long theId )
1947 return myFunctor && myFunctor->GetValue( theId ) < myMargin;
1953 Description : Comparator ">"
1955 bool MoreThan::IsSatisfy( long theId )
1957 return myFunctor && myFunctor->GetValue( theId ) > myMargin;
1963 Description : Comparator "="
1966 myToler(Precision::Confusion())
1969 bool EqualTo::IsSatisfy( long theId )
1971 return myFunctor && fabs( myFunctor->GetValue( theId ) - myMargin ) < myToler;
1974 void EqualTo::SetTolerance( double theToler )
1979 double EqualTo::GetTolerance()
1986 Description : Logical NOT predicate
1988 LogicalNOT::LogicalNOT()
1991 LogicalNOT::~LogicalNOT()
1994 bool LogicalNOT::IsSatisfy( long theId )
1996 return myPredicate && !myPredicate->IsSatisfy( theId );
1999 void LogicalNOT::SetMesh( const SMDS_Mesh* theMesh )
2002 myPredicate->SetMesh( theMesh );
2005 void LogicalNOT::SetPredicate( PredicatePtr thePred )
2007 myPredicate = thePred;
2010 SMDSAbs_ElementType LogicalNOT::GetType() const
2012 return myPredicate ? myPredicate->GetType() : SMDSAbs_All;
2017 Class : LogicalBinary
2018 Description : Base class for binary logical predicate
2020 LogicalBinary::LogicalBinary()
2023 LogicalBinary::~LogicalBinary()
2026 void LogicalBinary::SetMesh( const SMDS_Mesh* theMesh )
2029 myPredicate1->SetMesh( theMesh );
2032 myPredicate2->SetMesh( theMesh );
2035 void LogicalBinary::SetPredicate1( PredicatePtr thePredicate )
2037 myPredicate1 = thePredicate;
2040 void LogicalBinary::SetPredicate2( PredicatePtr thePredicate )
2042 myPredicate2 = thePredicate;
2045 SMDSAbs_ElementType LogicalBinary::GetType() const
2047 if ( !myPredicate1 || !myPredicate2 )
2050 SMDSAbs_ElementType aType1 = myPredicate1->GetType();
2051 SMDSAbs_ElementType aType2 = myPredicate2->GetType();
2053 return aType1 == aType2 ? aType1 : SMDSAbs_All;
2059 Description : Logical AND
2061 bool LogicalAND::IsSatisfy( long theId )
2066 myPredicate1->IsSatisfy( theId ) &&
2067 myPredicate2->IsSatisfy( theId );
2073 Description : Logical OR
2075 bool LogicalOR::IsSatisfy( long theId )
2080 myPredicate1->IsSatisfy( theId ) ||
2081 myPredicate2->IsSatisfy( theId );
2095 void Filter::SetPredicate( PredicatePtr thePredicate )
2097 myPredicate = thePredicate;
2100 template<class TElement, class TIterator, class TPredicate>
2101 inline void FillSequence(const TIterator& theIterator,
2102 TPredicate& thePredicate,
2103 Filter::TIdSequence& theSequence)
2105 if ( theIterator ) {
2106 while( theIterator->more() ) {
2107 TElement anElem = theIterator->next();
2108 long anId = anElem->GetID();
2109 if ( thePredicate->IsSatisfy( anId ) )
2110 theSequence.push_back( anId );
2117 GetElementsId( const SMDS_Mesh* theMesh,
2118 PredicatePtr thePredicate,
2119 TIdSequence& theSequence )
2121 theSequence.clear();
2123 if ( !theMesh || !thePredicate )
2126 thePredicate->SetMesh( theMesh );
2128 SMDSAbs_ElementType aType = thePredicate->GetType();
2131 FillSequence<const SMDS_MeshNode*>(theMesh->nodesIterator(),thePredicate,theSequence);
2134 FillSequence<const SMDS_MeshElement*>(theMesh->edgesIterator(),thePredicate,theSequence);
2137 FillSequence<const SMDS_MeshElement*>(theMesh->facesIterator(),thePredicate,theSequence);
2139 case SMDSAbs_Volume:
2140 FillSequence<const SMDS_MeshElement*>(theMesh->volumesIterator(),thePredicate,theSequence);
2143 FillSequence<const SMDS_MeshElement*>(theMesh->edgesIterator(),thePredicate,theSequence);
2144 FillSequence<const SMDS_MeshElement*>(theMesh->facesIterator(),thePredicate,theSequence);
2145 FillSequence<const SMDS_MeshElement*>(theMesh->volumesIterator(),thePredicate,theSequence);
2151 Filter::GetElementsId( const SMDS_Mesh* theMesh,
2152 Filter::TIdSequence& theSequence )
2154 GetElementsId(theMesh,myPredicate,theSequence);
2161 typedef std::set<SMDS_MeshFace*> TMapOfFacePtr;
2167 ManifoldPart::Link::Link( SMDS_MeshNode* theNode1,
2168 SMDS_MeshNode* theNode2 )
2174 ManifoldPart::Link::~Link()
2180 bool ManifoldPart::Link::IsEqual( const ManifoldPart::Link& theLink ) const
2182 if ( myNode1 == theLink.myNode1 &&
2183 myNode2 == theLink.myNode2 )
2185 else if ( myNode1 == theLink.myNode2 &&
2186 myNode2 == theLink.myNode1 )
2192 bool ManifoldPart::Link::operator<( const ManifoldPart::Link& x ) const
2194 if(myNode1 < x.myNode1) return true;
2195 if(myNode1 == x.myNode1)
2196 if(myNode2 < x.myNode2) return true;
2200 bool ManifoldPart::IsEqual( const ManifoldPart::Link& theLink1,
2201 const ManifoldPart::Link& theLink2 )
2203 return theLink1.IsEqual( theLink2 );
2206 ManifoldPart::ManifoldPart()
2209 myAngToler = Precision::Angular();
2210 myIsOnlyManifold = true;
2213 ManifoldPart::~ManifoldPart()
2218 void ManifoldPart::SetMesh( const SMDS_Mesh* theMesh )
2224 SMDSAbs_ElementType ManifoldPart::GetType() const
2225 { return SMDSAbs_Face; }
2227 bool ManifoldPart::IsSatisfy( long theElementId )
2229 return myMapIds.Contains( theElementId );
2232 void ManifoldPart::SetAngleTolerance( const double theAngToler )
2233 { myAngToler = theAngToler; }
2235 double ManifoldPart::GetAngleTolerance() const
2236 { return myAngToler; }
2238 void ManifoldPart::SetIsOnlyManifold( const bool theIsOnly )
2239 { myIsOnlyManifold = theIsOnly; }
2241 void ManifoldPart::SetStartElem( const long theStartId )
2242 { myStartElemId = theStartId; }
2244 bool ManifoldPart::process()
2247 myMapBadGeomIds.Clear();
2249 myAllFacePtr.clear();
2250 myAllFacePtrIntDMap.clear();
2254 // collect all faces into own map
2255 SMDS_FaceIteratorPtr anFaceItr = myMesh->facesIterator();
2256 for (; anFaceItr->more(); )
2258 SMDS_MeshFace* aFacePtr = (SMDS_MeshFace*)anFaceItr->next();
2259 myAllFacePtr.push_back( aFacePtr );
2260 myAllFacePtrIntDMap[aFacePtr] = myAllFacePtr.size()-1;
2263 SMDS_MeshFace* aStartFace = (SMDS_MeshFace*)myMesh->FindElement( myStartElemId );
2267 // the map of non manifold links and bad geometry
2268 TMapOfLink aMapOfNonManifold;
2269 TColStd_MapOfInteger aMapOfTreated;
2271 // begin cycle on faces from start index and run on vector till the end
2272 // and from begin to start index to cover whole vector
2273 const int aStartIndx = myAllFacePtrIntDMap[aStartFace];
2274 bool isStartTreat = false;
2275 for ( int fi = aStartIndx; !isStartTreat || fi != aStartIndx ; fi++ )
2277 if ( fi == aStartIndx )
2278 isStartTreat = true;
2279 // as result next time when fi will be equal to aStartIndx
2281 SMDS_MeshFace* aFacePtr = myAllFacePtr[ fi ];
2282 if ( aMapOfTreated.Contains( aFacePtr->GetID() ) )
2285 aMapOfTreated.Add( aFacePtr->GetID() );
2286 TColStd_MapOfInteger aResFaces;
2287 if ( !findConnected( myAllFacePtrIntDMap, aFacePtr,
2288 aMapOfNonManifold, aResFaces ) )
2290 TColStd_MapIteratorOfMapOfInteger anItr( aResFaces );
2291 for ( ; anItr.More(); anItr.Next() )
2293 int aFaceId = anItr.Key();
2294 aMapOfTreated.Add( aFaceId );
2295 myMapIds.Add( aFaceId );
2298 if ( fi == ( myAllFacePtr.size() - 1 ) )
2300 } // end run on vector of faces
2301 return !myMapIds.IsEmpty();
2304 static void getLinks( const SMDS_MeshFace* theFace,
2305 ManifoldPart::TVectorOfLink& theLinks )
2307 int aNbNode = theFace->NbNodes();
2308 SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
2310 SMDS_MeshNode* aNode = 0;
2311 for ( ; aNodeItr->more() && i <= aNbNode; )
2314 SMDS_MeshNode* aN1 = (SMDS_MeshNode*)aNodeItr->next();
2318 SMDS_MeshNode* aN2 = ( i >= aNbNode ) ? aNode : (SMDS_MeshNode*)aNodeItr->next();
2320 ManifoldPart::Link aLink( aN1, aN2 );
2321 theLinks.push_back( aLink );
2325 static gp_XYZ getNormale( const SMDS_MeshFace* theFace )
2328 int aNbNode = theFace->NbNodes();
2329 TColgp_Array1OfXYZ anArrOfXYZ(1,4);
2330 SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
2332 for ( ; aNodeItr->more() && i <= 4; i++ ) {
2333 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
2334 anArrOfXYZ.SetValue(i, gp_XYZ( aNode->X(), aNode->Y(), aNode->Z() ) );
2337 gp_XYZ q1 = anArrOfXYZ.Value(2) - anArrOfXYZ.Value(1);
2338 gp_XYZ q2 = anArrOfXYZ.Value(3) - anArrOfXYZ.Value(1);
2340 if ( aNbNode > 3 ) {
2341 gp_XYZ q3 = anArrOfXYZ.Value(4) - anArrOfXYZ.Value(1);
2344 double len = n.Modulus();
2351 bool ManifoldPart::findConnected
2352 ( const ManifoldPart::TDataMapFacePtrInt& theAllFacePtrInt,
2353 SMDS_MeshFace* theStartFace,
2354 ManifoldPart::TMapOfLink& theNonManifold,
2355 TColStd_MapOfInteger& theResFaces )
2357 theResFaces.Clear();
2358 if ( !theAllFacePtrInt.size() )
2361 if ( getNormale( theStartFace ).SquareModulus() <= gp::Resolution() )
2363 myMapBadGeomIds.Add( theStartFace->GetID() );
2367 ManifoldPart::TMapOfLink aMapOfBoundary, aMapToSkip;
2368 ManifoldPart::TVectorOfLink aSeqOfBoundary;
2369 theResFaces.Add( theStartFace->GetID() );
2370 ManifoldPart::TDataMapOfLinkFacePtr aDMapLinkFace;
2372 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
2373 aDMapLinkFace, theNonManifold, theStartFace );
2375 bool isDone = false;
2376 while ( !isDone && aMapOfBoundary.size() != 0 )
2378 bool isToReset = false;
2379 ManifoldPart::TVectorOfLink::iterator pLink = aSeqOfBoundary.begin();
2380 for ( ; !isToReset && pLink != aSeqOfBoundary.end(); ++pLink )
2382 ManifoldPart::Link aLink = *pLink;
2383 if ( aMapToSkip.find( aLink ) != aMapToSkip.end() )
2385 // each link could be treated only once
2386 aMapToSkip.insert( aLink );
2388 ManifoldPart::TVectorOfFacePtr aFaces;
2390 if ( myIsOnlyManifold &&
2391 (theNonManifold.find( aLink ) != theNonManifold.end()) )
2395 getFacesByLink( aLink, aFaces );
2396 // filter the element to keep only indicated elements
2397 ManifoldPart::TVectorOfFacePtr aFiltered;
2398 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
2399 for ( ; pFace != aFaces.end(); ++pFace )
2401 SMDS_MeshFace* aFace = *pFace;
2402 if ( myAllFacePtrIntDMap.find( aFace ) != myAllFacePtrIntDMap.end() )
2403 aFiltered.push_back( aFace );
2406 if ( aFaces.size() < 2 ) // no neihgbour faces
2408 else if ( myIsOnlyManifold && aFaces.size() > 2 ) // non manifold case
2410 theNonManifold.insert( aLink );
2415 // compare normal with normals of neighbor element
2416 SMDS_MeshFace* aPrevFace = aDMapLinkFace[ aLink ];
2417 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
2418 for ( ; pFace != aFaces.end(); ++pFace )
2420 SMDS_MeshFace* aNextFace = *pFace;
2421 if ( aPrevFace == aNextFace )
2423 int anNextFaceID = aNextFace->GetID();
2424 if ( myIsOnlyManifold && theResFaces.Contains( anNextFaceID ) )
2425 // should not be with non manifold restriction. probably bad topology
2427 // check if face was treated and skipped
2428 if ( myMapBadGeomIds.Contains( anNextFaceID ) ||
2429 !isInPlane( aPrevFace, aNextFace ) )
2431 // add new element to connected and extend the boundaries.
2432 theResFaces.Add( anNextFaceID );
2433 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
2434 aDMapLinkFace, theNonManifold, aNextFace );
2438 isDone = !isToReset;
2441 return !theResFaces.IsEmpty();
2444 bool ManifoldPart::isInPlane( const SMDS_MeshFace* theFace1,
2445 const SMDS_MeshFace* theFace2 )
2447 gp_Dir aNorm1 = gp_Dir( getNormale( theFace1 ) );
2448 gp_XYZ aNorm2XYZ = getNormale( theFace2 );
2449 if ( aNorm2XYZ.SquareModulus() <= gp::Resolution() )
2451 myMapBadGeomIds.Add( theFace2->GetID() );
2454 if ( aNorm1.IsParallel( gp_Dir( aNorm2XYZ ), myAngToler ) )
2460 void ManifoldPart::expandBoundary
2461 ( ManifoldPart::TMapOfLink& theMapOfBoundary,
2462 ManifoldPart::TVectorOfLink& theSeqOfBoundary,
2463 ManifoldPart::TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
2464 ManifoldPart::TMapOfLink& theNonManifold,
2465 SMDS_MeshFace* theNextFace ) const
2467 ManifoldPart::TVectorOfLink aLinks;
2468 getLinks( theNextFace, aLinks );
2469 int aNbLink = (int)aLinks.size();
2470 for ( int i = 0; i < aNbLink; i++ )
2472 ManifoldPart::Link aLink = aLinks[ i ];
2473 if ( myIsOnlyManifold && (theNonManifold.find( aLink ) != theNonManifold.end()) )
2475 if ( theMapOfBoundary.find( aLink ) != theMapOfBoundary.end() )
2477 if ( myIsOnlyManifold )
2479 // remove from boundary
2480 theMapOfBoundary.erase( aLink );
2481 ManifoldPart::TVectorOfLink::iterator pLink = theSeqOfBoundary.begin();
2482 for ( ; pLink != theSeqOfBoundary.end(); ++pLink )
2484 ManifoldPart::Link aBoundLink = *pLink;
2485 if ( aBoundLink.IsEqual( aLink ) )
2487 theSeqOfBoundary.erase( pLink );
2495 theMapOfBoundary.insert( aLink );
2496 theSeqOfBoundary.push_back( aLink );
2497 theDMapLinkFacePtr[ aLink ] = theNextFace;
2502 void ManifoldPart::getFacesByLink( const ManifoldPart::Link& theLink,
2503 ManifoldPart::TVectorOfFacePtr& theFaces ) const
2505 SMDS_Mesh::SetOfFaces aSetOfFaces;
2506 // take all faces that shared first node
2507 SMDS_ElemIteratorPtr anItr = theLink.myNode1->facesIterator();
2508 for ( ; anItr->more(); )
2510 SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
2513 aSetOfFaces.Add( aFace );
2515 // take all faces that shared second node
2516 anItr = theLink.myNode2->facesIterator();
2517 // find the common part of two sets
2518 for ( ; anItr->more(); )
2520 SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
2521 if ( aSetOfFaces.Contains( aFace ) )
2522 theFaces.push_back( aFace );
2531 ElementsOnSurface::ElementsOnSurface()
2535 myType = SMDSAbs_All;
2537 myToler = Precision::Confusion();
2538 myUseBoundaries = false;
2541 ElementsOnSurface::~ElementsOnSurface()
2546 void ElementsOnSurface::SetMesh( const SMDS_Mesh* theMesh )
2548 if ( myMesh == theMesh )
2554 bool ElementsOnSurface::IsSatisfy( long theElementId )
2556 return myIds.Contains( theElementId );
2559 SMDSAbs_ElementType ElementsOnSurface::GetType() const
2562 void ElementsOnSurface::SetTolerance( const double theToler )
2564 if ( myToler != theToler )
2569 double ElementsOnSurface::GetTolerance() const
2572 void ElementsOnSurface::SetUseBoundaries( bool theUse )
2574 if ( myUseBoundaries != theUse ) {
2575 myUseBoundaries = theUse;
2576 SetSurface( mySurf, myType );
2580 void ElementsOnSurface::SetSurface( const TopoDS_Shape& theShape,
2581 const SMDSAbs_ElementType theType )
2586 if ( theShape.IsNull() || theShape.ShapeType() != TopAbs_FACE )
2588 mySurf = TopoDS::Face( theShape );
2589 BRepAdaptor_Surface SA( mySurf, myUseBoundaries );
2591 u1 = SA.FirstUParameter(),
2592 u2 = SA.LastUParameter(),
2593 v1 = SA.FirstVParameter(),
2594 v2 = SA.LastVParameter();
2595 Handle(Geom_Surface) surf = BRep_Tool::Surface( mySurf );
2596 myProjector.Init( surf, u1,u2, v1,v2 );
2600 void ElementsOnSurface::process()
2603 if ( mySurf.IsNull() )
2609 if ( myType == SMDSAbs_Face || myType == SMDSAbs_All )
2611 myIds.ReSize( myMesh->NbFaces() );
2612 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
2613 for(; anIter->more(); )
2614 process( anIter->next() );
2617 if ( myType == SMDSAbs_Edge || myType == SMDSAbs_All )
2619 myIds.ReSize( myMesh->NbEdges() );
2620 SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
2621 for(; anIter->more(); )
2622 process( anIter->next() );
2625 if ( myType == SMDSAbs_Node )
2627 myIds.ReSize( myMesh->NbNodes() );
2628 SMDS_NodeIteratorPtr anIter = myMesh->nodesIterator();
2629 for(; anIter->more(); )
2630 process( anIter->next() );
2634 void ElementsOnSurface::process( const SMDS_MeshElement* theElemPtr )
2636 SMDS_ElemIteratorPtr aNodeItr = theElemPtr->nodesIterator();
2637 bool isSatisfy = true;
2638 for ( ; aNodeItr->more(); )
2640 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
2641 if ( !isOnSurface( aNode ) )
2648 myIds.Add( theElemPtr->GetID() );
2651 bool ElementsOnSurface::isOnSurface( const SMDS_MeshNode* theNode )
2653 if ( mySurf.IsNull() )
2656 gp_Pnt aPnt( theNode->X(), theNode->Y(), theNode->Z() );
2657 // double aToler2 = myToler * myToler;
2658 // if ( mySurf->IsKind(STANDARD_TYPE(Geom_Plane)))
2660 // gp_Pln aPln = Handle(Geom_Plane)::DownCast(mySurf)->Pln();
2661 // if ( aPln.SquareDistance( aPnt ) > aToler2 )
2664 // else if ( mySurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)))
2666 // gp_Cylinder aCyl = Handle(Geom_CylindricalSurface)::DownCast(mySurf)->Cylinder();
2667 // double aRad = aCyl.Radius();
2668 // gp_Ax3 anAxis = aCyl.Position();
2669 // gp_XYZ aLoc = aCyl.Location().XYZ();
2670 // double aXDist = anAxis.XDirection().XYZ() * ( aPnt.XYZ() - aLoc );
2671 // double aYDist = anAxis.YDirection().XYZ() * ( aPnt.XYZ() - aLoc );
2672 // if ( fabs(aXDist*aXDist + aYDist*aYDist - aRad*aRad) > aToler2 )
2677 myProjector.Perform( aPnt );
2678 bool isOn = ( myProjector.IsDone() && myProjector.LowerDistance() <= myToler );