1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "SMESH_ControlsDef.hxx"
26 #include <BRepAdaptor_Surface.hxx>
27 #include <BRep_Tool.hxx>
28 #include <Geom_CylindricalSurface.hxx>
29 #include <Geom_Plane.hxx>
30 #include <Geom_Surface.hxx>
31 #include <Precision.hxx>
32 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
33 #include <TColStd_MapOfInteger.hxx>
34 #include <TColStd_SequenceOfAsciiString.hxx>
35 #include <TColgp_Array1OfXYZ.hxx>
38 #include <TopoDS_Face.hxx>
39 #include <TopoDS_Shape.hxx>
41 #include <gp_Cylinder.hxx>
48 #include "SMDS_Mesh.hxx"
49 #include "SMDS_Iterator.hxx"
50 #include "SMDS_MeshElement.hxx"
51 #include "SMDS_MeshNode.hxx"
52 #include "SMDS_VolumeTool.hxx"
53 #include "SMDS_QuadraticFaceOfNodes.hxx"
54 #include "SMDS_QuadraticEdge.hxx"
64 inline double getAngle( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
66 gp_Vec v1( P1 - P2 ), v2( P3 - P2 );
68 return v1.Magnitude() < gp::Resolution() ||
69 v2.Magnitude() < gp::Resolution() ? 0 : v1.Angle( v2 );
72 inline double getArea( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
74 gp_Vec aVec1( P2 - P1 );
75 gp_Vec aVec2( P3 - P1 );
76 return ( aVec1 ^ aVec2 ).Magnitude() * 0.5;
79 inline double getArea( const gp_Pnt& P1, const gp_Pnt& P2, const gp_Pnt& P3 )
81 return getArea( P1.XYZ(), P2.XYZ(), P3.XYZ() );
86 inline double getDistance( const gp_XYZ& P1, const gp_XYZ& P2 )
88 double aDist = gp_Pnt( P1 ).Distance( gp_Pnt( P2 ) );
92 int getNbMultiConnection( const SMDS_Mesh* theMesh, const int theId )
97 const SMDS_MeshElement* anEdge = theMesh->FindElement( theId );
98 if ( anEdge == 0 || anEdge->GetType() != SMDSAbs_Edge/* || anEdge->NbNodes() != 2 */)
101 // for each pair of nodes in anEdge (there are 2 pairs in a quadratic edge)
102 // count elements containing both nodes of the pair.
103 // Note that there may be such cases for a quadratic edge (a horizontal line):
108 // +-----+------+ +-----+------+
111 // result sould be 2 in both cases
113 int aResult0 = 0, aResult1 = 0;
114 // last node, it is a medium one in a quadratic edge
115 const SMDS_MeshNode* aLastNode = anEdge->GetNode( anEdge->NbNodes() - 1 );
116 const SMDS_MeshNode* aNode0 = anEdge->GetNode( 0 );
117 const SMDS_MeshNode* aNode1 = anEdge->GetNode( 1 );
118 if ( aNode1 == aLastNode ) aNode1 = 0;
120 SMDS_ElemIteratorPtr anElemIter = aLastNode->GetInverseElementIterator();
121 while( anElemIter->more() ) {
122 const SMDS_MeshElement* anElem = anElemIter->next();
123 if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) {
124 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
125 while ( anIter->more() ) {
126 if ( const SMDS_MeshElement* anElemNode = anIter->next() ) {
127 if ( anElemNode == aNode0 ) {
129 if ( !aNode1 ) break; // not a quadratic edge
131 else if ( anElemNode == aNode1 )
137 int aResult = max ( aResult0, aResult1 );
139 // TColStd_MapOfInteger aMap;
141 // SMDS_ElemIteratorPtr anIter = anEdge->nodesIterator();
142 // if ( anIter != 0 ) {
143 // while( anIter->more() ) {
144 // const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next();
147 // SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator();
148 // while( anElemIter->more() ) {
149 // const SMDS_MeshElement* anElem = anElemIter->next();
150 // if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) {
151 // int anId = anElem->GetID();
153 // if ( anIter->more() ) // i.e. first node
155 // else if ( aMap.Contains( anId ) )
169 using namespace SMESH::Controls;
176 Class : NumericalFunctor
177 Description : Base class for numerical functors
179 NumericalFunctor::NumericalFunctor():
185 void NumericalFunctor::SetMesh( const SMDS_Mesh* theMesh )
190 bool NumericalFunctor::GetPoints(const int theId,
191 TSequenceOfXYZ& theRes ) const
198 return GetPoints( myMesh->FindElement( theId ), theRes );
201 bool NumericalFunctor::GetPoints(const SMDS_MeshElement* anElem,
202 TSequenceOfXYZ& theRes )
209 theRes.reserve( anElem->NbNodes() );
211 // Get nodes of the element
212 SMDS_ElemIteratorPtr anIter;
214 if ( anElem->IsQuadratic() ) {
215 switch ( anElem->GetType() ) {
217 anIter = static_cast<const SMDS_QuadraticEdge*>
218 (anElem)->interlacedNodesElemIterator();
221 anIter = static_cast<const SMDS_QuadraticFaceOfNodes*>
222 (anElem)->interlacedNodesElemIterator();
225 anIter = anElem->nodesIterator();
230 anIter = anElem->nodesIterator();
234 while( anIter->more() ) {
235 if ( const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>( anIter->next() ))
236 theRes.push_back( gp_XYZ( aNode->X(), aNode->Y(), aNode->Z() ) );
243 long NumericalFunctor::GetPrecision() const
248 void NumericalFunctor::SetPrecision( const long thePrecision )
250 myPrecision = thePrecision;
253 double NumericalFunctor::GetValue( long theId )
255 myCurrElement = myMesh->FindElement( theId );
257 if ( GetPoints( theId, P ))
259 double aVal = GetValue( P );
260 if ( myPrecision >= 0 )
262 double prec = pow( 10., (double)( myPrecision ) );
263 aVal = floor( aVal * prec + 0.5 ) / prec;
271 //=======================================================================
272 //function : GetValue
274 //=======================================================================
276 double Volume::GetValue( long theElementId )
278 if ( theElementId && myMesh ) {
279 SMDS_VolumeTool aVolumeTool;
280 if ( aVolumeTool.Set( myMesh->FindElement( theElementId )))
281 return aVolumeTool.GetSize();
286 //=======================================================================
287 //function : GetBadRate
288 //purpose : meaningless as it is not quality control functor
289 //=======================================================================
291 double Volume::GetBadRate( double Value, int /*nbNodes*/ ) const
296 //=======================================================================
299 //=======================================================================
301 SMDSAbs_ElementType Volume::GetType() const
303 return SMDSAbs_Volume;
309 Description : Functor for calculation of minimum angle
312 double MinimumAngle::GetValue( const TSequenceOfXYZ& P )
319 aMin = getAngle(P( P.size() ), P( 1 ), P( 2 ));
320 aMin = Min(aMin,getAngle(P( P.size()-1 ), P( P.size() ), P( 1 )));
322 for (int i=2; i<P.size();i++){
323 double A0 = getAngle( P( i-1 ), P( i ), P( i+1 ) );
327 return aMin * 180.0 / PI;
330 double MinimumAngle::GetBadRate( double Value, int nbNodes ) const
332 //const double aBestAngle = PI / nbNodes;
333 const double aBestAngle = 180.0 - ( 360.0 / double(nbNodes) );
334 return ( fabs( aBestAngle - Value ));
337 SMDSAbs_ElementType MinimumAngle::GetType() const
345 Description : Functor for calculating aspect ratio
347 double AspectRatio::GetValue( const TSequenceOfXYZ& P )
349 // According to "Mesh quality control" by Nadir Bouhamau referring to
350 // Pascal Jean Frey and Paul-Louis George. Maillages, applications aux elements finis.
351 // Hermes Science publications, Paris 1999 ISBN 2-7462-0024-4
354 int nbNodes = P.size();
359 // Compute aspect ratio
361 if ( nbNodes == 3 ) {
362 // Compute lengths of the sides
363 vector< double > aLen (nbNodes);
364 for ( int i = 0; i < nbNodes - 1; i++ )
365 aLen[ i ] = getDistance( P( i + 1 ), P( i + 2 ) );
366 aLen[ nbNodes - 1 ] = getDistance( P( 1 ), P( nbNodes ) );
367 // Q = alfa * h * p / S, where
369 // alfa = sqrt( 3 ) / 6
370 // h - length of the longest edge
371 // p - half perimeter
372 // S - triangle surface
373 const double alfa = sqrt( 3. ) / 6.;
374 double maxLen = Max( aLen[ 0 ], Max( aLen[ 1 ], aLen[ 2 ] ) );
375 double half_perimeter = ( aLen[0] + aLen[1] + aLen[2] ) / 2.;
376 double anArea = getArea( P( 1 ), P( 2 ), P( 3 ) );
377 if ( anArea <= Precision::Confusion() )
379 return alfa * maxLen * half_perimeter / anArea;
381 else if ( nbNodes == 6 ) { // quadratic triangles
382 // Compute lengths of the sides
383 vector< double > aLen (3);
384 aLen[0] = getDistance( P(1), P(3) );
385 aLen[1] = getDistance( P(3), P(5) );
386 aLen[2] = getDistance( P(5), P(1) );
387 // Q = alfa * h * p / S, where
389 // alfa = sqrt( 3 ) / 6
390 // h - length of the longest edge
391 // p - half perimeter
392 // S - triangle surface
393 const double alfa = sqrt( 3. ) / 6.;
394 double maxLen = Max( aLen[ 0 ], Max( aLen[ 1 ], aLen[ 2 ] ) );
395 double half_perimeter = ( aLen[0] + aLen[1] + aLen[2] ) / 2.;
396 double anArea = getArea( P(1), P(3), P(5) );
397 if ( anArea <= Precision::Confusion() )
399 return alfa * maxLen * half_perimeter / anArea;
401 else if( nbNodes == 4 ) { // quadrangle
402 // return aspect ratio of the worst triange which can be built
403 // taking three nodes of the quadrangle
404 TSequenceOfXYZ triaPnts(3);
405 // triangle on nodes 1 3 2
409 double ar = GetValue( triaPnts );
410 // triangle on nodes 1 3 4
412 ar = Max ( ar, GetValue( triaPnts ));
413 // triangle on nodes 1 2 4
415 ar = Max ( ar, GetValue( triaPnts ));
416 // triangle on nodes 3 2 4
418 ar = Max ( ar, GetValue( triaPnts ));
422 else { // nbNodes==8 - quadratic quadrangle
423 // return aspect ratio of the worst triange which can be built
424 // taking three nodes of the quadrangle
425 TSequenceOfXYZ triaPnts(3);
426 // triangle on nodes 1 3 2
430 double ar = GetValue( triaPnts );
431 // triangle on nodes 1 3 4
433 ar = Max ( ar, GetValue( triaPnts ));
434 // triangle on nodes 1 2 4
436 ar = Max ( ar, GetValue( triaPnts ));
437 // triangle on nodes 3 2 4
439 ar = Max ( ar, GetValue( triaPnts ));
445 double AspectRatio::GetBadRate( double Value, int /*nbNodes*/ ) const
447 // the aspect ratio is in the range [1.0,infinity]
450 return Value / 1000.;
453 SMDSAbs_ElementType AspectRatio::GetType() const
460 Class : AspectRatio3D
461 Description : Functor for calculating aspect ratio
465 inline double getHalfPerimeter(double theTria[3]){
466 return (theTria[0] + theTria[1] + theTria[2])/2.0;
469 inline double getArea(double theHalfPerim, double theTria[3]){
470 return sqrt(theHalfPerim*
471 (theHalfPerim-theTria[0])*
472 (theHalfPerim-theTria[1])*
473 (theHalfPerim-theTria[2]));
476 inline double getVolume(double theLen[6]){
477 double a2 = theLen[0]*theLen[0];
478 double b2 = theLen[1]*theLen[1];
479 double c2 = theLen[2]*theLen[2];
480 double d2 = theLen[3]*theLen[3];
481 double e2 = theLen[4]*theLen[4];
482 double f2 = theLen[5]*theLen[5];
483 double P = 4.0*a2*b2*d2;
484 double Q = a2*(b2+d2-e2)-b2*(a2+d2-f2)-d2*(a2+b2-c2);
485 double R = (b2+d2-e2)*(a2+d2-f2)*(a2+d2-f2);
486 return sqrt(P-Q+R)/12.0;
489 inline double getVolume2(double theLen[6]){
490 double a2 = theLen[0]*theLen[0];
491 double b2 = theLen[1]*theLen[1];
492 double c2 = theLen[2]*theLen[2];
493 double d2 = theLen[3]*theLen[3];
494 double e2 = theLen[4]*theLen[4];
495 double f2 = theLen[5]*theLen[5];
497 double P = a2*e2*(b2+c2+d2+f2-a2-e2);
498 double Q = b2*f2*(a2+c2+d2+e2-b2-f2);
499 double R = c2*d2*(a2+b2+e2+f2-c2-d2);
500 double S = a2*b2*d2+b2*c2*e2+a2*c2*f2+d2*e2*f2;
502 return sqrt(P+Q+R-S)/12.0;
505 inline double getVolume(const TSequenceOfXYZ& P){
506 gp_Vec aVec1( P( 2 ) - P( 1 ) );
507 gp_Vec aVec2( P( 3 ) - P( 1 ) );
508 gp_Vec aVec3( P( 4 ) - P( 1 ) );
509 gp_Vec anAreaVec( aVec1 ^ aVec2 );
510 return fabs(aVec3 * anAreaVec) / 6.0;
513 inline double getMaxHeight(double theLen[6])
515 double aHeight = max(theLen[0],theLen[1]);
516 aHeight = max(aHeight,theLen[2]);
517 aHeight = max(aHeight,theLen[3]);
518 aHeight = max(aHeight,theLen[4]);
519 aHeight = max(aHeight,theLen[5]);
525 double AspectRatio3D::GetValue( const TSequenceOfXYZ& P )
527 double aQuality = 0.0;
528 if(myCurrElement->IsPoly()) return aQuality;
530 int nbNodes = P.size();
532 if(myCurrElement->IsQuadratic()) {
533 if(nbNodes==10) nbNodes=4; // quadratic tetrahedron
534 else if(nbNodes==13) nbNodes=5; // quadratic pyramid
535 else if(nbNodes==15) nbNodes=6; // quadratic pentahedron
536 else if(nbNodes==20) nbNodes=8; // quadratic hexahedron
537 else return aQuality;
543 getDistance(P( 1 ),P( 2 )), // a
544 getDistance(P( 2 ),P( 3 )), // b
545 getDistance(P( 3 ),P( 1 )), // c
546 getDistance(P( 2 ),P( 4 )), // d
547 getDistance(P( 3 ),P( 4 )), // e
548 getDistance(P( 1 ),P( 4 )) // f
550 double aTria[4][3] = {
551 {aLen[0],aLen[1],aLen[2]}, // abc
552 {aLen[0],aLen[3],aLen[5]}, // adf
553 {aLen[1],aLen[3],aLen[4]}, // bde
554 {aLen[2],aLen[4],aLen[5]} // cef
556 double aSumArea = 0.0;
557 double aHalfPerimeter = getHalfPerimeter(aTria[0]);
558 double anArea = getArea(aHalfPerimeter,aTria[0]);
560 aHalfPerimeter = getHalfPerimeter(aTria[1]);
561 anArea = getArea(aHalfPerimeter,aTria[1]);
563 aHalfPerimeter = getHalfPerimeter(aTria[2]);
564 anArea = getArea(aHalfPerimeter,aTria[2]);
566 aHalfPerimeter = getHalfPerimeter(aTria[3]);
567 anArea = getArea(aHalfPerimeter,aTria[3]);
569 double aVolume = getVolume(P);
570 //double aVolume = getVolume(aLen);
571 double aHeight = getMaxHeight(aLen);
572 static double aCoeff = sqrt(2.0)/12.0;
573 if ( aVolume > DBL_MIN )
574 aQuality = aCoeff*aHeight*aSumArea/aVolume;
579 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 3 ),P( 5 )};
580 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
583 gp_XYZ aXYZ[4] = {P( 1 ),P( 3 ),P( 4 ),P( 5 )};
584 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
587 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 5 )};
588 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
591 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 4 ),P( 5 )};
592 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
598 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 6 )};
599 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
602 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 3 )};
603 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
606 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 6 )};
607 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
610 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
611 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
614 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 6 )};
615 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
618 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 3 )};
619 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
625 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
626 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
629 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 4 )};
630 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
633 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 7 )};
634 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
637 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 8 )};
638 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
641 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 3 )};
642 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
645 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 4 )};
646 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
649 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 7 )};
650 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
653 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 8 )};
654 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
657 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 3 )};
658 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
661 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 4 )};
662 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
665 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 7 )};
666 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
669 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 8 )};
670 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
673 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 1 )};
674 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
677 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 2 )};
678 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
681 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 5 )};
682 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
685 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 6 )};
686 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
689 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 1 )};
690 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
693 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 2 )};
694 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
697 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 5 )};
698 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
701 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 6 )};
702 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
705 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 1 )};
706 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
709 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
710 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
713 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 5 )};
714 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
717 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 6 )};
718 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
721 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
722 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
725 gp_XYZ aXYZ[4] = {P( 4 ),P( 5 ),P( 8 ),P( 2 )};
726 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
729 gp_XYZ aXYZ[4] = {P( 1 ),P( 4 ),P( 5 ),P( 3 )};
730 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
733 gp_XYZ aXYZ[4] = {P( 3 ),P( 6 ),P( 7 ),P( 1 )};
734 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
737 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 6 ),P( 4 )};
738 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
741 gp_XYZ aXYZ[4] = {P( 5 ),P( 6 ),P( 8 ),P( 3 )};
742 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
745 gp_XYZ aXYZ[4] = {P( 7 ),P( 8 ),P( 6 ),P( 1 )};
746 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
749 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 7 )};
750 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
753 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 2 ),P( 5 )};
754 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
760 // avaluate aspect ratio of quadranle faces
761 AspectRatio aspect2D;
762 SMDS_VolumeTool::VolumeType type = SMDS_VolumeTool::GetType( nbNodes );
763 int nbFaces = SMDS_VolumeTool::NbFaces( type );
764 TSequenceOfXYZ points(4);
765 for ( int i = 0; i < nbFaces; ++i ) { // loop on faces of a volume
766 if ( SMDS_VolumeTool::NbFaceNodes( type, i ) != 4 )
768 const int* pInd = SMDS_VolumeTool::GetFaceNodesIndices( type, i, true );
769 for ( int p = 0; p < 4; ++p ) // loop on nodes of a quadranle face
770 points( p + 1 ) = P( pInd[ p ] + 1 );
771 aQuality = max( aQuality, aspect2D.GetValue( points ));
777 double AspectRatio3D::GetBadRate( double Value, int /*nbNodes*/ ) const
779 // the aspect ratio is in the range [1.0,infinity]
782 return Value / 1000.;
785 SMDSAbs_ElementType AspectRatio3D::GetType() const
787 return SMDSAbs_Volume;
793 Description : Functor for calculating warping
795 double Warping::GetValue( const TSequenceOfXYZ& P )
800 gp_XYZ G = ( P( 1 ) + P( 2 ) + P( 3 ) + P( 4 ) ) / 4.;
802 double A1 = ComputeA( P( 1 ), P( 2 ), P( 3 ), G );
803 double A2 = ComputeA( P( 2 ), P( 3 ), P( 4 ), G );
804 double A3 = ComputeA( P( 3 ), P( 4 ), P( 1 ), G );
805 double A4 = ComputeA( P( 4 ), P( 1 ), P( 2 ), G );
807 return Max( Max( A1, A2 ), Max( A3, A4 ) );
810 double Warping::ComputeA( const gp_XYZ& thePnt1,
811 const gp_XYZ& thePnt2,
812 const gp_XYZ& thePnt3,
813 const gp_XYZ& theG ) const
815 double aLen1 = gp_Pnt( thePnt1 ).Distance( gp_Pnt( thePnt2 ) );
816 double aLen2 = gp_Pnt( thePnt2 ).Distance( gp_Pnt( thePnt3 ) );
817 double L = Min( aLen1, aLen2 ) * 0.5;
818 if ( L < Precision::Confusion())
821 gp_XYZ GI = ( thePnt2 + thePnt1 ) / 2. - theG;
822 gp_XYZ GJ = ( thePnt3 + thePnt2 ) / 2. - theG;
823 gp_XYZ N = GI.Crossed( GJ );
825 if ( N.Modulus() < gp::Resolution() )
830 double H = ( thePnt2 - theG ).Dot( N );
831 return asin( fabs( H / L ) ) * 180. / PI;
834 double Warping::GetBadRate( double Value, int /*nbNodes*/ ) const
836 // the warp is in the range [0.0,PI/2]
837 // 0.0 = good (no warp)
838 // PI/2 = bad (face pliee)
842 SMDSAbs_ElementType Warping::GetType() const
850 Description : Functor for calculating taper
852 double Taper::GetValue( const TSequenceOfXYZ& P )
858 double J1 = getArea( P( 4 ), P( 1 ), P( 2 ) ) / 2.;
859 double J2 = getArea( P( 3 ), P( 1 ), P( 2 ) ) / 2.;
860 double J3 = getArea( P( 2 ), P( 3 ), P( 4 ) ) / 2.;
861 double J4 = getArea( P( 3 ), P( 4 ), P( 1 ) ) / 2.;
863 double JA = 0.25 * ( J1 + J2 + J3 + J4 );
864 if ( JA <= Precision::Confusion() )
867 double T1 = fabs( ( J1 - JA ) / JA );
868 double T2 = fabs( ( J2 - JA ) / JA );
869 double T3 = fabs( ( J3 - JA ) / JA );
870 double T4 = fabs( ( J4 - JA ) / JA );
872 return Max( Max( T1, T2 ), Max( T3, T4 ) );
875 double Taper::GetBadRate( double Value, int /*nbNodes*/ ) const
877 // the taper is in the range [0.0,1.0]
878 // 0.0 = good (no taper)
879 // 1.0 = bad (les cotes opposes sont allignes)
883 SMDSAbs_ElementType Taper::GetType() const
891 Description : Functor for calculating skew in degrees
893 static inline double skewAngle( const gp_XYZ& p1, const gp_XYZ& p2, const gp_XYZ& p3 )
895 gp_XYZ p12 = ( p2 + p1 ) / 2.;
896 gp_XYZ p23 = ( p3 + p2 ) / 2.;
897 gp_XYZ p31 = ( p3 + p1 ) / 2.;
899 gp_Vec v1( p31 - p2 ), v2( p12 - p23 );
901 return v1.Magnitude() < gp::Resolution() || v2.Magnitude() < gp::Resolution() ? 0. : v1.Angle( v2 );
904 double Skew::GetValue( const TSequenceOfXYZ& P )
906 if ( P.size() != 3 && P.size() != 4 )
910 static double PI2 = PI / 2.;
913 double A0 = fabs( PI2 - skewAngle( P( 3 ), P( 1 ), P( 2 ) ) );
914 double A1 = fabs( PI2 - skewAngle( P( 1 ), P( 2 ), P( 3 ) ) );
915 double A2 = fabs( PI2 - skewAngle( P( 2 ), P( 3 ), P( 1 ) ) );
917 return Max( A0, Max( A1, A2 ) ) * 180. / PI;
921 gp_XYZ p12 = ( P( 1 ) + P( 2 ) ) / 2.;
922 gp_XYZ p23 = ( P( 2 ) + P( 3 ) ) / 2.;
923 gp_XYZ p34 = ( P( 3 ) + P( 4 ) ) / 2.;
924 gp_XYZ p41 = ( P( 4 ) + P( 1 ) ) / 2.;
926 gp_Vec v1( p34 - p12 ), v2( p23 - p41 );
927 double A = v1.Magnitude() <= gp::Resolution() || v2.Magnitude() <= gp::Resolution()
928 ? 0. : fabs( PI2 - v1.Angle( v2 ) );
931 if ( A < Precision::Angular() )
934 return A * 180. / PI;
938 double Skew::GetBadRate( double Value, int /*nbNodes*/ ) const
940 // the skew is in the range [0.0,PI/2].
946 SMDSAbs_ElementType Skew::GetType() const
954 Description : Functor for calculating area
956 double Area::GetValue( const TSequenceOfXYZ& P )
958 gp_Vec aVec1( P(2) - P(1) );
959 gp_Vec aVec2( P(3) - P(1) );
960 gp_Vec SumVec = aVec1 ^ aVec2;
961 for (int i=4; i<=P.size(); i++) {
962 gp_Vec aVec1( P(i-1) - P(1) );
963 gp_Vec aVec2( P(i) - P(1) );
964 gp_Vec tmp = aVec1 ^ aVec2;
967 return SumVec.Magnitude() * 0.5;
970 double Area::GetBadRate( double Value, int /*nbNodes*/ ) const
972 // meaningless as it is not a quality control functor
976 SMDSAbs_ElementType Area::GetType() const
984 Description : Functor for calculating length off edge
986 double Length::GetValue( const TSequenceOfXYZ& P )
988 switch ( P.size() ) {
989 case 2: return getDistance( P( 1 ), P( 2 ) );
990 case 3: return getDistance( P( 1 ), P( 2 ) ) + getDistance( P( 2 ), P( 3 ) );
995 double Length::GetBadRate( double Value, int /*nbNodes*/ ) const
997 // meaningless as it is not quality control functor
1001 SMDSAbs_ElementType Length::GetType() const
1003 return SMDSAbs_Edge;
1008 Description : Functor for calculating length of edge
1011 double Length2D::GetValue( long theElementId)
1015 //cout<<"Length2D::GetValue"<<endl;
1016 if (GetPoints(theElementId,P)){
1017 //for(int jj=1; jj<=P.size(); jj++)
1018 // cout<<"jj="<<jj<<" P("<<P(jj).X()<<","<<P(jj).Y()<<","<<P(jj).Z()<<")"<<endl;
1020 double aVal;// = GetValue( P );
1021 const SMDS_MeshElement* aElem = myMesh->FindElement( theElementId );
1022 SMDSAbs_ElementType aType = aElem->GetType();
1031 aVal = getDistance( P( 1 ), P( 2 ) );
1034 else if (len == 3){ // quadratic edge
1035 aVal = getDistance(P( 1 ),P( 3 )) + getDistance(P( 3 ),P( 2 ));
1039 if (len == 3){ // triangles
1040 double L1 = getDistance(P( 1 ),P( 2 ));
1041 double L2 = getDistance(P( 2 ),P( 3 ));
1042 double L3 = getDistance(P( 3 ),P( 1 ));
1043 aVal = Max(L1,Max(L2,L3));
1046 else if (len == 4){ // quadrangles
1047 double L1 = getDistance(P( 1 ),P( 2 ));
1048 double L2 = getDistance(P( 2 ),P( 3 ));
1049 double L3 = getDistance(P( 3 ),P( 4 ));
1050 double L4 = getDistance(P( 4 ),P( 1 ));
1051 aVal = Max(Max(L1,L2),Max(L3,L4));
1054 if (len == 6){ // quadratic triangles
1055 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1056 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1057 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 1 ));
1058 aVal = Max(L1,Max(L2,L3));
1059 //cout<<"L1="<<L1<<" L2="<<L2<<"L3="<<L3<<" aVal="<<aVal<<endl;
1062 else if (len == 8){ // quadratic quadrangles
1063 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1064 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1065 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 7 ));
1066 double L4 = getDistance(P( 7 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
1067 aVal = Max(Max(L1,L2),Max(L3,L4));
1070 case SMDSAbs_Volume:
1071 if (len == 4){ // tetraidrs
1072 double L1 = getDistance(P( 1 ),P( 2 ));
1073 double L2 = getDistance(P( 2 ),P( 3 ));
1074 double L3 = getDistance(P( 3 ),P( 1 ));
1075 double L4 = getDistance(P( 1 ),P( 4 ));
1076 double L5 = getDistance(P( 2 ),P( 4 ));
1077 double L6 = getDistance(P( 3 ),P( 4 ));
1078 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1081 else if (len == 5){ // piramids
1082 double L1 = getDistance(P( 1 ),P( 2 ));
1083 double L2 = getDistance(P( 2 ),P( 3 ));
1084 double L3 = getDistance(P( 3 ),P( 1 ));
1085 double L4 = getDistance(P( 4 ),P( 1 ));
1086 double L5 = getDistance(P( 1 ),P( 5 ));
1087 double L6 = getDistance(P( 2 ),P( 5 ));
1088 double L7 = getDistance(P( 3 ),P( 5 ));
1089 double L8 = getDistance(P( 4 ),P( 5 ));
1091 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1092 aVal = Max(aVal,Max(L7,L8));
1095 else if (len == 6){ // pentaidres
1096 double L1 = getDistance(P( 1 ),P( 2 ));
1097 double L2 = getDistance(P( 2 ),P( 3 ));
1098 double L3 = getDistance(P( 3 ),P( 1 ));
1099 double L4 = getDistance(P( 4 ),P( 5 ));
1100 double L5 = getDistance(P( 5 ),P( 6 ));
1101 double L6 = getDistance(P( 6 ),P( 4 ));
1102 double L7 = getDistance(P( 1 ),P( 4 ));
1103 double L8 = getDistance(P( 2 ),P( 5 ));
1104 double L9 = getDistance(P( 3 ),P( 6 ));
1106 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1107 aVal = Max(aVal,Max(Max(L7,L8),L9));
1110 else if (len == 8){ // hexaider
1111 double L1 = getDistance(P( 1 ),P( 2 ));
1112 double L2 = getDistance(P( 2 ),P( 3 ));
1113 double L3 = getDistance(P( 3 ),P( 4 ));
1114 double L4 = getDistance(P( 4 ),P( 1 ));
1115 double L5 = getDistance(P( 5 ),P( 6 ));
1116 double L6 = getDistance(P( 6 ),P( 7 ));
1117 double L7 = getDistance(P( 7 ),P( 8 ));
1118 double L8 = getDistance(P( 8 ),P( 5 ));
1119 double L9 = getDistance(P( 1 ),P( 5 ));
1120 double L10= getDistance(P( 2 ),P( 6 ));
1121 double L11= getDistance(P( 3 ),P( 7 ));
1122 double L12= getDistance(P( 4 ),P( 8 ));
1124 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1125 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
1126 aVal = Max(aVal,Max(L11,L12));
1131 if (len == 10){ // quadratic tetraidrs
1132 double L1 = getDistance(P( 1 ),P( 5 )) + getDistance(P( 5 ),P( 2 ));
1133 double L2 = getDistance(P( 2 ),P( 6 )) + getDistance(P( 6 ),P( 3 ));
1134 double L3 = getDistance(P( 3 ),P( 7 )) + getDistance(P( 7 ),P( 1 ));
1135 double L4 = getDistance(P( 1 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
1136 double L5 = getDistance(P( 2 ),P( 9 )) + getDistance(P( 9 ),P( 4 ));
1137 double L6 = getDistance(P( 3 ),P( 10 )) + getDistance(P( 10 ),P( 4 ));
1138 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1141 else if (len == 13){ // quadratic piramids
1142 double L1 = getDistance(P( 1 ),P( 6 )) + getDistance(P( 6 ),P( 2 ));
1143 double L2 = getDistance(P( 2 ),P( 7 )) + getDistance(P( 7 ),P( 3 ));
1144 double L3 = getDistance(P( 3 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
1145 double L4 = getDistance(P( 4 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1146 double L5 = getDistance(P( 1 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1147 double L6 = getDistance(P( 2 ),P( 11 )) + getDistance(P( 11 ),P( 5 ));
1148 double L7 = getDistance(P( 3 ),P( 12 )) + getDistance(P( 12 ),P( 5 ));
1149 double L8 = getDistance(P( 4 ),P( 13 )) + getDistance(P( 13 ),P( 5 ));
1150 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1151 aVal = Max(aVal,Max(L7,L8));
1154 else if (len == 15){ // quadratic pentaidres
1155 double L1 = getDistance(P( 1 ),P( 7 )) + getDistance(P( 7 ),P( 2 ));
1156 double L2 = getDistance(P( 2 ),P( 8 )) + getDistance(P( 8 ),P( 3 ));
1157 double L3 = getDistance(P( 3 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1158 double L4 = getDistance(P( 4 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1159 double L5 = getDistance(P( 5 ),P( 11 )) + getDistance(P( 11 ),P( 6 ));
1160 double L6 = getDistance(P( 6 ),P( 12 )) + getDistance(P( 12 ),P( 4 ));
1161 double L7 = getDistance(P( 1 ),P( 13 )) + getDistance(P( 13 ),P( 4 ));
1162 double L8 = getDistance(P( 2 ),P( 14 )) + getDistance(P( 14 ),P( 5 ));
1163 double L9 = getDistance(P( 3 ),P( 15 )) + getDistance(P( 15 ),P( 6 ));
1164 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1165 aVal = Max(aVal,Max(Max(L7,L8),L9));
1168 else if (len == 20){ // quadratic hexaider
1169 double L1 = getDistance(P( 1 ),P( 9 )) + getDistance(P( 9 ),P( 2 ));
1170 double L2 = getDistance(P( 2 ),P( 10 )) + getDistance(P( 10 ),P( 3 ));
1171 double L3 = getDistance(P( 3 ),P( 11 )) + getDistance(P( 11 ),P( 4 ));
1172 double L4 = getDistance(P( 4 ),P( 12 )) + getDistance(P( 12 ),P( 1 ));
1173 double L5 = getDistance(P( 5 ),P( 13 )) + getDistance(P( 13 ),P( 6 ));
1174 double L6 = getDistance(P( 6 ),P( 14 )) + getDistance(P( 14 ),P( 7 ));
1175 double L7 = getDistance(P( 7 ),P( 15 )) + getDistance(P( 15 ),P( 8 ));
1176 double L8 = getDistance(P( 8 ),P( 16 )) + getDistance(P( 16 ),P( 5 ));
1177 double L9 = getDistance(P( 1 ),P( 17 )) + getDistance(P( 17 ),P( 5 ));
1178 double L10= getDistance(P( 2 ),P( 18 )) + getDistance(P( 18 ),P( 6 ));
1179 double L11= getDistance(P( 3 ),P( 19 )) + getDistance(P( 19 ),P( 7 ));
1180 double L12= getDistance(P( 4 ),P( 20 )) + getDistance(P( 20 ),P( 8 ));
1181 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1182 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
1183 aVal = Max(aVal,Max(L11,L12));
1195 if ( myPrecision >= 0 )
1197 double prec = pow( 10., (double)( myPrecision ) );
1198 aVal = floor( aVal * prec + 0.5 ) / prec;
1207 double Length2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1209 // meaningless as it is not quality control functor
1213 SMDSAbs_ElementType Length2D::GetType() const
1215 return SMDSAbs_Face;
1218 Length2D::Value::Value(double theLength,long thePntId1, long thePntId2):
1221 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1222 if(thePntId1 > thePntId2){
1223 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1227 bool Length2D::Value::operator<(const Length2D::Value& x) const{
1228 if(myPntId[0] < x.myPntId[0]) return true;
1229 if(myPntId[0] == x.myPntId[0])
1230 if(myPntId[1] < x.myPntId[1]) return true;
1234 void Length2D::GetValues(TValues& theValues){
1236 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1237 for(; anIter->more(); ){
1238 const SMDS_MeshFace* anElem = anIter->next();
1240 if(anElem->IsQuadratic()) {
1241 const SMDS_QuadraticFaceOfNodes* F =
1242 static_cast<const SMDS_QuadraticFaceOfNodes*>(anElem);
1243 // use special nodes iterator
1244 SMDS_NodeIteratorPtr anIter = F->interlacedNodesIterator();
1249 const SMDS_MeshElement* aNode;
1251 aNode = anIter->next();
1252 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1253 P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1254 aNodeId[0] = aNodeId[1] = aNode->GetID();
1257 for(; anIter->more(); ){
1258 const SMDS_MeshNode* N1 = static_cast<const SMDS_MeshNode*> (anIter->next());
1259 P[2] = gp_Pnt(N1->X(),N1->Y(),N1->Z());
1260 aNodeId[2] = N1->GetID();
1261 aLength = P[1].Distance(P[2]);
1262 if(!anIter->more()) break;
1263 const SMDS_MeshNode* N2 = static_cast<const SMDS_MeshNode*> (anIter->next());
1264 P[3] = gp_Pnt(N2->X(),N2->Y(),N2->Z());
1265 aNodeId[3] = N2->GetID();
1266 aLength += P[2].Distance(P[3]);
1267 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1268 Value aValue2(aLength,aNodeId[2],aNodeId[3]);
1270 aNodeId[1] = aNodeId[3];
1271 theValues.insert(aValue1);
1272 theValues.insert(aValue2);
1274 aLength += P[2].Distance(P[0]);
1275 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1276 Value aValue2(aLength,aNodeId[2],aNodeId[0]);
1277 theValues.insert(aValue1);
1278 theValues.insert(aValue2);
1281 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
1286 const SMDS_MeshElement* aNode;
1287 if(aNodesIter->more()){
1288 aNode = aNodesIter->next();
1289 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1290 P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1291 aNodeId[0] = aNodeId[1] = aNode->GetID();
1294 for(; aNodesIter->more(); ){
1295 aNode = aNodesIter->next();
1296 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1297 long anId = aNode->GetID();
1299 P[2] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1301 aLength = P[1].Distance(P[2]);
1303 Value aValue(aLength,aNodeId[1],anId);
1306 theValues.insert(aValue);
1309 aLength = P[0].Distance(P[1]);
1311 Value aValue(aLength,aNodeId[0],aNodeId[1]);
1312 theValues.insert(aValue);
1318 Class : MultiConnection
1319 Description : Functor for calculating number of faces conneted to the edge
1321 double MultiConnection::GetValue( const TSequenceOfXYZ& P )
1325 double MultiConnection::GetValue( long theId )
1327 return getNbMultiConnection( myMesh, theId );
1330 double MultiConnection::GetBadRate( double Value, int /*nbNodes*/ ) const
1332 // meaningless as it is not quality control functor
1336 SMDSAbs_ElementType MultiConnection::GetType() const
1338 return SMDSAbs_Edge;
1342 Class : MultiConnection2D
1343 Description : Functor for calculating number of faces conneted to the edge
1345 double MultiConnection2D::GetValue( const TSequenceOfXYZ& P )
1350 double MultiConnection2D::GetValue( long theElementId )
1354 const SMDS_MeshElement* aFaceElem = myMesh->FindElement(theElementId);
1355 SMDSAbs_ElementType aType = aFaceElem->GetType();
1360 int i = 0, len = aFaceElem->NbNodes();
1361 SMDS_ElemIteratorPtr anIter = aFaceElem->nodesIterator();
1364 const SMDS_MeshNode *aNode, *aNode0;
1365 TColStd_MapOfInteger aMap, aMapPrev;
1367 for (i = 0; i <= len; i++) {
1372 if (anIter->more()) {
1373 aNode = (SMDS_MeshNode*)anIter->next();
1381 if (i == 0) aNode0 = aNode;
1383 SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator();
1384 while (anElemIter->more()) {
1385 const SMDS_MeshElement* anElem = anElemIter->next();
1386 if (anElem != 0 && anElem->GetType() == SMDSAbs_Face) {
1387 int anId = anElem->GetID();
1390 if (aMapPrev.Contains(anId)) {
1395 aResult = Max(aResult, aNb);
1406 double MultiConnection2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1408 // meaningless as it is not quality control functor
1412 SMDSAbs_ElementType MultiConnection2D::GetType() const
1414 return SMDSAbs_Face;
1417 MultiConnection2D::Value::Value(long thePntId1, long thePntId2)
1419 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1420 if(thePntId1 > thePntId2){
1421 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1425 bool MultiConnection2D::Value::operator<(const MultiConnection2D::Value& x) const{
1426 if(myPntId[0] < x.myPntId[0]) return true;
1427 if(myPntId[0] == x.myPntId[0])
1428 if(myPntId[1] < x.myPntId[1]) return true;
1432 void MultiConnection2D::GetValues(MValues& theValues){
1433 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1434 for(; anIter->more(); ){
1435 const SMDS_MeshFace* anElem = anIter->next();
1436 SMDS_ElemIteratorPtr aNodesIter;
1437 if ( anElem->IsQuadratic() )
1438 aNodesIter = static_cast<const SMDS_QuadraticFaceOfNodes*>
1439 (anElem)->interlacedNodesElemIterator();
1441 aNodesIter = anElem->nodesIterator();
1444 //int aNbConnects=0;
1445 const SMDS_MeshNode* aNode0;
1446 const SMDS_MeshNode* aNode1;
1447 const SMDS_MeshNode* aNode2;
1448 if(aNodesIter->more()){
1449 aNode0 = (SMDS_MeshNode*) aNodesIter->next();
1451 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode1;
1452 aNodeId[0] = aNodeId[1] = aNodes->GetID();
1454 for(; aNodesIter->more(); ) {
1455 aNode2 = (SMDS_MeshNode*) aNodesIter->next();
1456 long anId = aNode2->GetID();
1459 Value aValue(aNodeId[1],aNodeId[2]);
1460 MValues::iterator aItr = theValues.find(aValue);
1461 if (aItr != theValues.end()){
1466 theValues[aValue] = 1;
1469 //cout << "NodeIds: "<<aNodeId[1]<<","<<aNodeId[2]<<" nbconn="<<aNbConnects<<endl;
1470 aNodeId[1] = aNodeId[2];
1473 Value aValue(aNodeId[0],aNodeId[2]);
1474 MValues::iterator aItr = theValues.find(aValue);
1475 if (aItr != theValues.end()) {
1480 theValues[aValue] = 1;
1483 //cout << "NodeIds: "<<aNodeId[0]<<","<<aNodeId[2]<<" nbconn="<<aNbConnects<<endl;
1493 Class : BadOrientedVolume
1494 Description : Predicate bad oriented volumes
1497 BadOrientedVolume::BadOrientedVolume()
1502 void BadOrientedVolume::SetMesh( const SMDS_Mesh* theMesh )
1507 bool BadOrientedVolume::IsSatisfy( long theId )
1512 SMDS_VolumeTool vTool( myMesh->FindElement( theId ));
1513 return !vTool.IsForward();
1516 SMDSAbs_ElementType BadOrientedVolume::GetType() const
1518 return SMDSAbs_Volume;
1525 Description : Predicate for free borders
1528 FreeBorders::FreeBorders()
1533 void FreeBorders::SetMesh( const SMDS_Mesh* theMesh )
1538 bool FreeBorders::IsSatisfy( long theId )
1540 return getNbMultiConnection( myMesh, theId ) == 1;
1543 SMDSAbs_ElementType FreeBorders::GetType() const
1545 return SMDSAbs_Edge;
1551 Description : Predicate for free Edges
1553 FreeEdges::FreeEdges()
1558 void FreeEdges::SetMesh( const SMDS_Mesh* theMesh )
1563 bool FreeEdges::IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId )
1565 TColStd_MapOfInteger aMap;
1566 for ( int i = 0; i < 2; i++ )
1568 SMDS_ElemIteratorPtr anElemIter = theNodes[ i ]->GetInverseElementIterator();
1569 while( anElemIter->more() )
1571 const SMDS_MeshElement* anElem = anElemIter->next();
1572 if ( anElem != 0 && anElem->GetType() == SMDSAbs_Face )
1574 int anId = anElem->GetID();
1578 else if ( aMap.Contains( anId ) && anId != theFaceId )
1586 bool FreeEdges::IsSatisfy( long theId )
1591 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
1592 if ( aFace == 0 || aFace->GetType() != SMDSAbs_Face || aFace->NbNodes() < 3 )
1595 SMDS_ElemIteratorPtr anIter;
1596 if ( aFace->IsQuadratic() ) {
1597 anIter = static_cast<const SMDS_QuadraticFaceOfNodes*>
1598 (aFace)->interlacedNodesElemIterator();
1601 anIter = aFace->nodesIterator();
1606 int i = 0, nbNodes = aFace->NbNodes();
1607 vector <const SMDS_MeshNode*> aNodes( nbNodes+1 );
1608 while( anIter->more() )
1610 const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next();
1613 aNodes[ i++ ] = aNode;
1615 aNodes[ nbNodes ] = aNodes[ 0 ];
1617 for ( i = 0; i < nbNodes; i++ )
1618 if ( IsFreeEdge( &aNodes[ i ], theId ) )
1624 SMDSAbs_ElementType FreeEdges::GetType() const
1626 return SMDSAbs_Face;
1629 FreeEdges::Border::Border(long theElemId, long thePntId1, long thePntId2):
1632 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1633 if(thePntId1 > thePntId2){
1634 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1638 bool FreeEdges::Border::operator<(const FreeEdges::Border& x) const{
1639 if(myPntId[0] < x.myPntId[0]) return true;
1640 if(myPntId[0] == x.myPntId[0])
1641 if(myPntId[1] < x.myPntId[1]) return true;
1645 inline void UpdateBorders(const FreeEdges::Border& theBorder,
1646 FreeEdges::TBorders& theRegistry,
1647 FreeEdges::TBorders& theContainer)
1649 if(theRegistry.find(theBorder) == theRegistry.end()){
1650 theRegistry.insert(theBorder);
1651 theContainer.insert(theBorder);
1653 theContainer.erase(theBorder);
1657 void FreeEdges::GetBoreders(TBorders& theBorders)
1660 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1661 for(; anIter->more(); ){
1662 const SMDS_MeshFace* anElem = anIter->next();
1663 long anElemId = anElem->GetID();
1664 SMDS_ElemIteratorPtr aNodesIter;
1665 if ( anElem->IsQuadratic() )
1666 aNodesIter = static_cast<const SMDS_QuadraticFaceOfNodes*>(anElem)->
1667 interlacedNodesElemIterator();
1669 aNodesIter = anElem->nodesIterator();
1671 const SMDS_MeshElement* aNode;
1672 if(aNodesIter->more()){
1673 aNode = aNodesIter->next();
1674 aNodeId[0] = aNodeId[1] = aNode->GetID();
1676 for(; aNodesIter->more(); ){
1677 aNode = aNodesIter->next();
1678 long anId = aNode->GetID();
1679 Border aBorder(anElemId,aNodeId[1],anId);
1681 //std::cout<<aBorder.myPntId[0]<<"; "<<aBorder.myPntId[1]<<"; "<<aBorder.myElemId<<endl;
1682 UpdateBorders(aBorder,aRegistry,theBorders);
1684 Border aBorder(anElemId,aNodeId[0],aNodeId[1]);
1685 //std::cout<<aBorder.myPntId[0]<<"; "<<aBorder.myPntId[1]<<"; "<<aBorder.myElemId<<endl;
1686 UpdateBorders(aBorder,aRegistry,theBorders);
1688 //std::cout<<"theBorders.size() = "<<theBorders.size()<<endl;
1693 Description : Predicate for Range of Ids.
1694 Range may be specified with two ways.
1695 1. Using AddToRange method
1696 2. With SetRangeStr method. Parameter of this method is a string
1697 like as "1,2,3,50-60,63,67,70-"
1700 //=======================================================================
1701 // name : RangeOfIds
1702 // Purpose : Constructor
1703 //=======================================================================
1704 RangeOfIds::RangeOfIds()
1707 myType = SMDSAbs_All;
1710 //=======================================================================
1712 // Purpose : Set mesh
1713 //=======================================================================
1714 void RangeOfIds::SetMesh( const SMDS_Mesh* theMesh )
1719 //=======================================================================
1720 // name : AddToRange
1721 // Purpose : Add ID to the range
1722 //=======================================================================
1723 bool RangeOfIds::AddToRange( long theEntityId )
1725 myIds.Add( theEntityId );
1729 //=======================================================================
1730 // name : GetRangeStr
1731 // Purpose : Get range as a string.
1732 // Example: "1,2,3,50-60,63,67,70-"
1733 //=======================================================================
1734 void RangeOfIds::GetRangeStr( TCollection_AsciiString& theResStr )
1738 TColStd_SequenceOfInteger anIntSeq;
1739 TColStd_SequenceOfAsciiString aStrSeq;
1741 TColStd_MapIteratorOfMapOfInteger anIter( myIds );
1742 for ( ; anIter.More(); anIter.Next() )
1744 int anId = anIter.Key();
1745 TCollection_AsciiString aStr( anId );
1746 anIntSeq.Append( anId );
1747 aStrSeq.Append( aStr );
1750 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
1752 int aMinId = myMin( i );
1753 int aMaxId = myMax( i );
1755 TCollection_AsciiString aStr;
1756 if ( aMinId != IntegerFirst() )
1761 if ( aMaxId != IntegerLast() )
1764 // find position of the string in result sequence and insert string in it
1765 if ( anIntSeq.Length() == 0 )
1767 anIntSeq.Append( aMinId );
1768 aStrSeq.Append( aStr );
1772 if ( aMinId < anIntSeq.First() )
1774 anIntSeq.Prepend( aMinId );
1775 aStrSeq.Prepend( aStr );
1777 else if ( aMinId > anIntSeq.Last() )
1779 anIntSeq.Append( aMinId );
1780 aStrSeq.Append( aStr );
1783 for ( int j = 1, k = anIntSeq.Length(); j <= k; j++ )
1784 if ( aMinId < anIntSeq( j ) )
1786 anIntSeq.InsertBefore( j, aMinId );
1787 aStrSeq.InsertBefore( j, aStr );
1793 if ( aStrSeq.Length() == 0 )
1796 theResStr = aStrSeq( 1 );
1797 for ( int j = 2, k = aStrSeq.Length(); j <= k; j++ )
1800 theResStr += aStrSeq( j );
1804 //=======================================================================
1805 // name : SetRangeStr
1806 // Purpose : Define range with string
1807 // Example of entry string: "1,2,3,50-60,63,67,70-"
1808 //=======================================================================
1809 bool RangeOfIds::SetRangeStr( const TCollection_AsciiString& theStr )
1815 TCollection_AsciiString aStr = theStr;
1816 aStr.RemoveAll( ' ' );
1817 aStr.RemoveAll( '\t' );
1819 for ( int aPos = aStr.Search( ",," ); aPos != -1; aPos = aStr.Search( ",," ) )
1820 aStr.Remove( aPos, 2 );
1822 TCollection_AsciiString tmpStr = aStr.Token( ",", 1 );
1824 while ( tmpStr != "" )
1826 tmpStr = aStr.Token( ",", i++ );
1827 int aPos = tmpStr.Search( '-' );
1831 if ( tmpStr.IsIntegerValue() )
1832 myIds.Add( tmpStr.IntegerValue() );
1838 TCollection_AsciiString aMaxStr = tmpStr.Split( aPos );
1839 TCollection_AsciiString aMinStr = tmpStr;
1841 while ( aMinStr.Search( "-" ) != -1 ) aMinStr.RemoveAll( '-' );
1842 while ( aMaxStr.Search( "-" ) != -1 ) aMaxStr.RemoveAll( '-' );
1844 if ( !aMinStr.IsEmpty() && !aMinStr.IsIntegerValue() ||
1845 !aMaxStr.IsEmpty() && !aMaxStr.IsIntegerValue() )
1848 myMin.Append( aMinStr.IsEmpty() ? IntegerFirst() : aMinStr.IntegerValue() );
1849 myMax.Append( aMaxStr.IsEmpty() ? IntegerLast() : aMaxStr.IntegerValue() );
1856 //=======================================================================
1858 // Purpose : Get type of supported entities
1859 //=======================================================================
1860 SMDSAbs_ElementType RangeOfIds::GetType() const
1865 //=======================================================================
1867 // Purpose : Set type of supported entities
1868 //=======================================================================
1869 void RangeOfIds::SetType( SMDSAbs_ElementType theType )
1874 //=======================================================================
1876 // Purpose : Verify whether entity satisfies to this rpedicate
1877 //=======================================================================
1878 bool RangeOfIds::IsSatisfy( long theId )
1883 if ( myType == SMDSAbs_Node )
1885 if ( myMesh->FindNode( theId ) == 0 )
1890 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
1891 if ( anElem == 0 || myType != anElem->GetType() && myType != SMDSAbs_All )
1895 if ( myIds.Contains( theId ) )
1898 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
1899 if ( theId >= myMin( i ) && theId <= myMax( i ) )
1907 Description : Base class for comparators
1909 Comparator::Comparator():
1913 Comparator::~Comparator()
1916 void Comparator::SetMesh( const SMDS_Mesh* theMesh )
1919 myFunctor->SetMesh( theMesh );
1922 void Comparator::SetMargin( double theValue )
1924 myMargin = theValue;
1927 void Comparator::SetNumFunctor( NumericalFunctorPtr theFunct )
1929 myFunctor = theFunct;
1932 SMDSAbs_ElementType Comparator::GetType() const
1934 return myFunctor ? myFunctor->GetType() : SMDSAbs_All;
1937 double Comparator::GetMargin()
1945 Description : Comparator "<"
1947 bool LessThan::IsSatisfy( long theId )
1949 return myFunctor && myFunctor->GetValue( theId ) < myMargin;
1955 Description : Comparator ">"
1957 bool MoreThan::IsSatisfy( long theId )
1959 return myFunctor && myFunctor->GetValue( theId ) > myMargin;
1965 Description : Comparator "="
1968 myToler(Precision::Confusion())
1971 bool EqualTo::IsSatisfy( long theId )
1973 return myFunctor && fabs( myFunctor->GetValue( theId ) - myMargin ) < myToler;
1976 void EqualTo::SetTolerance( double theToler )
1981 double EqualTo::GetTolerance()
1988 Description : Logical NOT predicate
1990 LogicalNOT::LogicalNOT()
1993 LogicalNOT::~LogicalNOT()
1996 bool LogicalNOT::IsSatisfy( long theId )
1998 return myPredicate && !myPredicate->IsSatisfy( theId );
2001 void LogicalNOT::SetMesh( const SMDS_Mesh* theMesh )
2004 myPredicate->SetMesh( theMesh );
2007 void LogicalNOT::SetPredicate( PredicatePtr thePred )
2009 myPredicate = thePred;
2012 SMDSAbs_ElementType LogicalNOT::GetType() const
2014 return myPredicate ? myPredicate->GetType() : SMDSAbs_All;
2019 Class : LogicalBinary
2020 Description : Base class for binary logical predicate
2022 LogicalBinary::LogicalBinary()
2025 LogicalBinary::~LogicalBinary()
2028 void LogicalBinary::SetMesh( const SMDS_Mesh* theMesh )
2031 myPredicate1->SetMesh( theMesh );
2034 myPredicate2->SetMesh( theMesh );
2037 void LogicalBinary::SetPredicate1( PredicatePtr thePredicate )
2039 myPredicate1 = thePredicate;
2042 void LogicalBinary::SetPredicate2( PredicatePtr thePredicate )
2044 myPredicate2 = thePredicate;
2047 SMDSAbs_ElementType LogicalBinary::GetType() const
2049 if ( !myPredicate1 || !myPredicate2 )
2052 SMDSAbs_ElementType aType1 = myPredicate1->GetType();
2053 SMDSAbs_ElementType aType2 = myPredicate2->GetType();
2055 return aType1 == aType2 ? aType1 : SMDSAbs_All;
2061 Description : Logical AND
2063 bool LogicalAND::IsSatisfy( long theId )
2068 myPredicate1->IsSatisfy( theId ) &&
2069 myPredicate2->IsSatisfy( theId );
2075 Description : Logical OR
2077 bool LogicalOR::IsSatisfy( long theId )
2082 myPredicate1->IsSatisfy( theId ) ||
2083 myPredicate2->IsSatisfy( theId );
2097 void Filter::SetPredicate( PredicatePtr thePredicate )
2099 myPredicate = thePredicate;
2102 template<class TElement, class TIterator, class TPredicate>
2103 inline void FillSequence(const TIterator& theIterator,
2104 TPredicate& thePredicate,
2105 Filter::TIdSequence& theSequence)
2107 if ( theIterator ) {
2108 while( theIterator->more() ) {
2109 TElement anElem = theIterator->next();
2110 long anId = anElem->GetID();
2111 if ( thePredicate->IsSatisfy( anId ) )
2112 theSequence.push_back( anId );
2119 GetElementsId( const SMDS_Mesh* theMesh,
2120 PredicatePtr thePredicate,
2121 TIdSequence& theSequence )
2123 theSequence.clear();
2125 if ( !theMesh || !thePredicate )
2128 thePredicate->SetMesh( theMesh );
2130 SMDSAbs_ElementType aType = thePredicate->GetType();
2133 FillSequence<const SMDS_MeshNode*>(theMesh->nodesIterator(),thePredicate,theSequence);
2136 FillSequence<const SMDS_MeshElement*>(theMesh->edgesIterator(),thePredicate,theSequence);
2139 FillSequence<const SMDS_MeshElement*>(theMesh->facesIterator(),thePredicate,theSequence);
2141 case SMDSAbs_Volume:
2142 FillSequence<const SMDS_MeshElement*>(theMesh->volumesIterator(),thePredicate,theSequence);
2145 FillSequence<const SMDS_MeshElement*>(theMesh->edgesIterator(),thePredicate,theSequence);
2146 FillSequence<const SMDS_MeshElement*>(theMesh->facesIterator(),thePredicate,theSequence);
2147 FillSequence<const SMDS_MeshElement*>(theMesh->volumesIterator(),thePredicate,theSequence);
2153 Filter::GetElementsId( const SMDS_Mesh* theMesh,
2154 Filter::TIdSequence& theSequence )
2156 GetElementsId(theMesh,myPredicate,theSequence);
2163 typedef std::set<SMDS_MeshFace*> TMapOfFacePtr;
2169 ManifoldPart::Link::Link( SMDS_MeshNode* theNode1,
2170 SMDS_MeshNode* theNode2 )
2176 ManifoldPart::Link::~Link()
2182 bool ManifoldPart::Link::IsEqual( const ManifoldPart::Link& theLink ) const
2184 if ( myNode1 == theLink.myNode1 &&
2185 myNode2 == theLink.myNode2 )
2187 else if ( myNode1 == theLink.myNode2 &&
2188 myNode2 == theLink.myNode1 )
2194 bool ManifoldPart::Link::operator<( const ManifoldPart::Link& x ) const
2196 if(myNode1 < x.myNode1) return true;
2197 if(myNode1 == x.myNode1)
2198 if(myNode2 < x.myNode2) return true;
2202 bool ManifoldPart::IsEqual( const ManifoldPart::Link& theLink1,
2203 const ManifoldPart::Link& theLink2 )
2205 return theLink1.IsEqual( theLink2 );
2208 ManifoldPart::ManifoldPart()
2211 myAngToler = Precision::Angular();
2212 myIsOnlyManifold = true;
2215 ManifoldPart::~ManifoldPart()
2220 void ManifoldPart::SetMesh( const SMDS_Mesh* theMesh )
2226 SMDSAbs_ElementType ManifoldPart::GetType() const
2227 { return SMDSAbs_Face; }
2229 bool ManifoldPart::IsSatisfy( long theElementId )
2231 return myMapIds.Contains( theElementId );
2234 void ManifoldPart::SetAngleTolerance( const double theAngToler )
2235 { myAngToler = theAngToler; }
2237 double ManifoldPart::GetAngleTolerance() const
2238 { return myAngToler; }
2240 void ManifoldPart::SetIsOnlyManifold( const bool theIsOnly )
2241 { myIsOnlyManifold = theIsOnly; }
2243 void ManifoldPart::SetStartElem( const long theStartId )
2244 { myStartElemId = theStartId; }
2246 bool ManifoldPart::process()
2249 myMapBadGeomIds.Clear();
2251 myAllFacePtr.clear();
2252 myAllFacePtrIntDMap.clear();
2256 // collect all faces into own map
2257 SMDS_FaceIteratorPtr anFaceItr = myMesh->facesIterator();
2258 for (; anFaceItr->more(); )
2260 SMDS_MeshFace* aFacePtr = (SMDS_MeshFace*)anFaceItr->next();
2261 myAllFacePtr.push_back( aFacePtr );
2262 myAllFacePtrIntDMap[aFacePtr] = myAllFacePtr.size()-1;
2265 SMDS_MeshFace* aStartFace = (SMDS_MeshFace*)myMesh->FindElement( myStartElemId );
2269 // the map of non manifold links and bad geometry
2270 TMapOfLink aMapOfNonManifold;
2271 TColStd_MapOfInteger aMapOfTreated;
2273 // begin cycle on faces from start index and run on vector till the end
2274 // and from begin to start index to cover whole vector
2275 const int aStartIndx = myAllFacePtrIntDMap[aStartFace];
2276 bool isStartTreat = false;
2277 for ( int fi = aStartIndx; !isStartTreat || fi != aStartIndx ; fi++ )
2279 if ( fi == aStartIndx )
2280 isStartTreat = true;
2281 // as result next time when fi will be equal to aStartIndx
2283 SMDS_MeshFace* aFacePtr = myAllFacePtr[ fi ];
2284 if ( aMapOfTreated.Contains( aFacePtr->GetID() ) )
2287 aMapOfTreated.Add( aFacePtr->GetID() );
2288 TColStd_MapOfInteger aResFaces;
2289 if ( !findConnected( myAllFacePtrIntDMap, aFacePtr,
2290 aMapOfNonManifold, aResFaces ) )
2292 TColStd_MapIteratorOfMapOfInteger anItr( aResFaces );
2293 for ( ; anItr.More(); anItr.Next() )
2295 int aFaceId = anItr.Key();
2296 aMapOfTreated.Add( aFaceId );
2297 myMapIds.Add( aFaceId );
2300 if ( fi == ( myAllFacePtr.size() - 1 ) )
2302 } // end run on vector of faces
2303 return !myMapIds.IsEmpty();
2306 static void getLinks( const SMDS_MeshFace* theFace,
2307 ManifoldPart::TVectorOfLink& theLinks )
2309 int aNbNode = theFace->NbNodes();
2310 SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
2312 SMDS_MeshNode* aNode = 0;
2313 for ( ; aNodeItr->more() && i <= aNbNode; )
2316 SMDS_MeshNode* aN1 = (SMDS_MeshNode*)aNodeItr->next();
2320 SMDS_MeshNode* aN2 = ( i >= aNbNode ) ? aNode : (SMDS_MeshNode*)aNodeItr->next();
2322 ManifoldPart::Link aLink( aN1, aN2 );
2323 theLinks.push_back( aLink );
2327 static gp_XYZ getNormale( const SMDS_MeshFace* theFace )
2330 int aNbNode = theFace->NbNodes();
2331 TColgp_Array1OfXYZ anArrOfXYZ(1,4);
2332 SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
2334 for ( ; aNodeItr->more() && i <= 4; i++ ) {
2335 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
2336 anArrOfXYZ.SetValue(i, gp_XYZ( aNode->X(), aNode->Y(), aNode->Z() ) );
2339 gp_XYZ q1 = anArrOfXYZ.Value(2) - anArrOfXYZ.Value(1);
2340 gp_XYZ q2 = anArrOfXYZ.Value(3) - anArrOfXYZ.Value(1);
2342 if ( aNbNode > 3 ) {
2343 gp_XYZ q3 = anArrOfXYZ.Value(4) - anArrOfXYZ.Value(1);
2346 double len = n.Modulus();
2353 bool ManifoldPart::findConnected
2354 ( const ManifoldPart::TDataMapFacePtrInt& theAllFacePtrInt,
2355 SMDS_MeshFace* theStartFace,
2356 ManifoldPart::TMapOfLink& theNonManifold,
2357 TColStd_MapOfInteger& theResFaces )
2359 theResFaces.Clear();
2360 if ( !theAllFacePtrInt.size() )
2363 if ( getNormale( theStartFace ).SquareModulus() <= gp::Resolution() )
2365 myMapBadGeomIds.Add( theStartFace->GetID() );
2369 ManifoldPart::TMapOfLink aMapOfBoundary, aMapToSkip;
2370 ManifoldPart::TVectorOfLink aSeqOfBoundary;
2371 theResFaces.Add( theStartFace->GetID() );
2372 ManifoldPart::TDataMapOfLinkFacePtr aDMapLinkFace;
2374 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
2375 aDMapLinkFace, theNonManifold, theStartFace );
2377 bool isDone = false;
2378 while ( !isDone && aMapOfBoundary.size() != 0 )
2380 bool isToReset = false;
2381 ManifoldPart::TVectorOfLink::iterator pLink = aSeqOfBoundary.begin();
2382 for ( ; !isToReset && pLink != aSeqOfBoundary.end(); ++pLink )
2384 ManifoldPart::Link aLink = *pLink;
2385 if ( aMapToSkip.find( aLink ) != aMapToSkip.end() )
2387 // each link could be treated only once
2388 aMapToSkip.insert( aLink );
2390 ManifoldPart::TVectorOfFacePtr aFaces;
2392 if ( myIsOnlyManifold &&
2393 (theNonManifold.find( aLink ) != theNonManifold.end()) )
2397 getFacesByLink( aLink, aFaces );
2398 // filter the element to keep only indicated elements
2399 ManifoldPart::TVectorOfFacePtr aFiltered;
2400 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
2401 for ( ; pFace != aFaces.end(); ++pFace )
2403 SMDS_MeshFace* aFace = *pFace;
2404 if ( myAllFacePtrIntDMap.find( aFace ) != myAllFacePtrIntDMap.end() )
2405 aFiltered.push_back( aFace );
2408 if ( aFaces.size() < 2 ) // no neihgbour faces
2410 else if ( myIsOnlyManifold && aFaces.size() > 2 ) // non manifold case
2412 theNonManifold.insert( aLink );
2417 // compare normal with normals of neighbor element
2418 SMDS_MeshFace* aPrevFace = aDMapLinkFace[ aLink ];
2419 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
2420 for ( ; pFace != aFaces.end(); ++pFace )
2422 SMDS_MeshFace* aNextFace = *pFace;
2423 if ( aPrevFace == aNextFace )
2425 int anNextFaceID = aNextFace->GetID();
2426 if ( myIsOnlyManifold && theResFaces.Contains( anNextFaceID ) )
2427 // should not be with non manifold restriction. probably bad topology
2429 // check if face was treated and skipped
2430 if ( myMapBadGeomIds.Contains( anNextFaceID ) ||
2431 !isInPlane( aPrevFace, aNextFace ) )
2433 // add new element to connected and extend the boundaries.
2434 theResFaces.Add( anNextFaceID );
2435 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
2436 aDMapLinkFace, theNonManifold, aNextFace );
2440 isDone = !isToReset;
2443 return !theResFaces.IsEmpty();
2446 bool ManifoldPart::isInPlane( const SMDS_MeshFace* theFace1,
2447 const SMDS_MeshFace* theFace2 )
2449 gp_Dir aNorm1 = gp_Dir( getNormale( theFace1 ) );
2450 gp_XYZ aNorm2XYZ = getNormale( theFace2 );
2451 if ( aNorm2XYZ.SquareModulus() <= gp::Resolution() )
2453 myMapBadGeomIds.Add( theFace2->GetID() );
2456 if ( aNorm1.IsParallel( gp_Dir( aNorm2XYZ ), myAngToler ) )
2462 void ManifoldPart::expandBoundary
2463 ( ManifoldPart::TMapOfLink& theMapOfBoundary,
2464 ManifoldPart::TVectorOfLink& theSeqOfBoundary,
2465 ManifoldPart::TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
2466 ManifoldPart::TMapOfLink& theNonManifold,
2467 SMDS_MeshFace* theNextFace ) const
2469 ManifoldPart::TVectorOfLink aLinks;
2470 getLinks( theNextFace, aLinks );
2471 int aNbLink = (int)aLinks.size();
2472 for ( int i = 0; i < aNbLink; i++ )
2474 ManifoldPart::Link aLink = aLinks[ i ];
2475 if ( myIsOnlyManifold && (theNonManifold.find( aLink ) != theNonManifold.end()) )
2477 if ( theMapOfBoundary.find( aLink ) != theMapOfBoundary.end() )
2479 if ( myIsOnlyManifold )
2481 // remove from boundary
2482 theMapOfBoundary.erase( aLink );
2483 ManifoldPart::TVectorOfLink::iterator pLink = theSeqOfBoundary.begin();
2484 for ( ; pLink != theSeqOfBoundary.end(); ++pLink )
2486 ManifoldPart::Link aBoundLink = *pLink;
2487 if ( aBoundLink.IsEqual( aLink ) )
2489 theSeqOfBoundary.erase( pLink );
2497 theMapOfBoundary.insert( aLink );
2498 theSeqOfBoundary.push_back( aLink );
2499 theDMapLinkFacePtr[ aLink ] = theNextFace;
2504 void ManifoldPart::getFacesByLink( const ManifoldPart::Link& theLink,
2505 ManifoldPart::TVectorOfFacePtr& theFaces ) const
2507 SMDS_Mesh::SetOfFaces aSetOfFaces;
2508 // take all faces that shared first node
2509 SMDS_ElemIteratorPtr anItr = theLink.myNode1->facesIterator();
2510 for ( ; anItr->more(); )
2512 SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
2515 aSetOfFaces.Add( aFace );
2517 // take all faces that shared second node
2518 anItr = theLink.myNode2->facesIterator();
2519 // find the common part of two sets
2520 for ( ; anItr->more(); )
2522 SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
2523 if ( aSetOfFaces.Contains( aFace ) )
2524 theFaces.push_back( aFace );
2533 ElementsOnSurface::ElementsOnSurface()
2537 myType = SMDSAbs_All;
2539 myToler = Precision::Confusion();
2540 myUseBoundaries = false;
2543 ElementsOnSurface::~ElementsOnSurface()
2548 void ElementsOnSurface::SetMesh( const SMDS_Mesh* theMesh )
2550 if ( myMesh == theMesh )
2556 bool ElementsOnSurface::IsSatisfy( long theElementId )
2558 return myIds.Contains( theElementId );
2561 SMDSAbs_ElementType ElementsOnSurface::GetType() const
2564 void ElementsOnSurface::SetTolerance( const double theToler )
2566 if ( myToler != theToler )
2571 double ElementsOnSurface::GetTolerance() const
2574 void ElementsOnSurface::SetUseBoundaries( bool theUse )
2576 if ( myUseBoundaries != theUse ) {
2577 myUseBoundaries = theUse;
2578 SetSurface( mySurf, myType );
2582 void ElementsOnSurface::SetSurface( const TopoDS_Shape& theShape,
2583 const SMDSAbs_ElementType theType )
2588 if ( theShape.IsNull() || theShape.ShapeType() != TopAbs_FACE )
2590 mySurf = TopoDS::Face( theShape );
2591 BRepAdaptor_Surface SA( mySurf, myUseBoundaries );
2593 u1 = SA.FirstUParameter(),
2594 u2 = SA.LastUParameter(),
2595 v1 = SA.FirstVParameter(),
2596 v2 = SA.LastVParameter();
2597 Handle(Geom_Surface) surf = BRep_Tool::Surface( mySurf );
2598 myProjector.Init( surf, u1,u2, v1,v2 );
2602 void ElementsOnSurface::process()
2605 if ( mySurf.IsNull() )
2611 if ( myType == SMDSAbs_Face || myType == SMDSAbs_All )
2613 myIds.ReSize( myMesh->NbFaces() );
2614 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
2615 for(; anIter->more(); )
2616 process( anIter->next() );
2619 if ( myType == SMDSAbs_Edge || myType == SMDSAbs_All )
2621 myIds.ReSize( myMesh->NbEdges() );
2622 SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
2623 for(; anIter->more(); )
2624 process( anIter->next() );
2627 if ( myType == SMDSAbs_Node )
2629 myIds.ReSize( myMesh->NbNodes() );
2630 SMDS_NodeIteratorPtr anIter = myMesh->nodesIterator();
2631 for(; anIter->more(); )
2632 process( anIter->next() );
2636 void ElementsOnSurface::process( const SMDS_MeshElement* theElemPtr )
2638 SMDS_ElemIteratorPtr aNodeItr = theElemPtr->nodesIterator();
2639 bool isSatisfy = true;
2640 for ( ; aNodeItr->more(); )
2642 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
2643 if ( !isOnSurface( aNode ) )
2650 myIds.Add( theElemPtr->GetID() );
2653 bool ElementsOnSurface::isOnSurface( const SMDS_MeshNode* theNode )
2655 if ( mySurf.IsNull() )
2658 gp_Pnt aPnt( theNode->X(), theNode->Y(), theNode->Z() );
2659 // double aToler2 = myToler * myToler;
2660 // if ( mySurf->IsKind(STANDARD_TYPE(Geom_Plane)))
2662 // gp_Pln aPln = Handle(Geom_Plane)::DownCast(mySurf)->Pln();
2663 // if ( aPln.SquareDistance( aPnt ) > aToler2 )
2666 // else if ( mySurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)))
2668 // gp_Cylinder aCyl = Handle(Geom_CylindricalSurface)::DownCast(mySurf)->Cylinder();
2669 // double aRad = aCyl.Radius();
2670 // gp_Ax3 anAxis = aCyl.Position();
2671 // gp_XYZ aLoc = aCyl.Location().XYZ();
2672 // double aXDist = anAxis.XDirection().XYZ() * ( aPnt.XYZ() - aLoc );
2673 // double aYDist = anAxis.YDirection().XYZ() * ( aPnt.XYZ() - aLoc );
2674 // if ( fabs(aXDist*aXDist + aYDist*aYDist - aRad*aRad) > aToler2 )
2679 myProjector.Perform( aPnt );
2680 bool isOn = ( myProjector.IsDone() && myProjector.LowerDistance() <= myToler );