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"
60 inline double getAngle( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
62 gp_Vec v1( P1 - P2 ), v2( P3 - P2 );
64 return v1.Magnitude() < gp::Resolution() ||
65 v2.Magnitude() < gp::Resolution() ? 0 : v1.Angle( v2 );
68 inline double getArea( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
70 gp_Vec aVec1( P2 - P1 );
71 gp_Vec aVec2( P3 - P1 );
72 return ( aVec1 ^ aVec2 ).Magnitude() * 0.5;
75 inline double getArea( const gp_Pnt& P1, const gp_Pnt& P2, const gp_Pnt& P3 )
77 return getArea( P1.XYZ(), P2.XYZ(), P3.XYZ() );
82 inline double getDistance( const gp_XYZ& P1, const gp_XYZ& P2 )
84 double aDist = gp_Pnt( P1 ).Distance( gp_Pnt( P2 ) );
88 int getNbMultiConnection( const SMDS_Mesh* theMesh, const int theId )
93 const SMDS_MeshElement* anEdge = theMesh->FindElement( theId );
94 if ( anEdge == 0 || anEdge->GetType() != SMDSAbs_Edge/* || anEdge->NbNodes() != 2 */)
97 // for each pair of nodes in anEdge (there are 2 pairs in a quadratic edge)
98 // count elements containing both nodes of the pair.
99 // Note that there may be such cases for a quadratic edge (a horizontal line):
104 // +-----+------+ +-----+------+
107 // result sould be 2 in both cases
109 int aResult0 = 0, aResult1 = 0;
110 // last node, it is a medium one in a quadratic edge
111 const SMDS_MeshNode* aLastNode = anEdge->GetNode( anEdge->NbNodes() - 1 );
112 const SMDS_MeshNode* aNode0 = anEdge->GetNode( 0 );
113 const SMDS_MeshNode* aNode1 = anEdge->GetNode( 1 );
114 if ( aNode1 == aLastNode ) aNode1 = 0;
116 SMDS_ElemIteratorPtr anElemIter = aLastNode->GetInverseElementIterator();
117 while( anElemIter->more() ) {
118 const SMDS_MeshElement* anElem = anElemIter->next();
119 if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) {
120 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
121 while ( anIter->more() ) {
122 if ( const SMDS_MeshElement* anElemNode = anIter->next() ) {
123 if ( anElemNode == aNode0 ) {
125 if ( !aNode1 ) break; // not a quadratic edge
127 else if ( anElemNode == aNode1 )
133 int aResult = max ( aResult0, aResult1 );
135 // TColStd_MapOfInteger aMap;
137 // SMDS_ElemIteratorPtr anIter = anEdge->nodesIterator();
138 // if ( anIter != 0 ) {
139 // while( anIter->more() ) {
140 // const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next();
143 // SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator();
144 // while( anElemIter->more() ) {
145 // const SMDS_MeshElement* anElem = anElemIter->next();
146 // if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) {
147 // int anId = anElem->GetID();
149 // if ( anIter->more() ) // i.e. first node
151 // else if ( aMap.Contains( anId ) )
165 using namespace SMESH::Controls;
172 Class : NumericalFunctor
173 Description : Base class for numerical functors
175 NumericalFunctor::NumericalFunctor():
181 void NumericalFunctor::SetMesh( const SMDS_Mesh* theMesh )
186 bool NumericalFunctor::GetPoints(const int theId,
187 TSequenceOfXYZ& theRes ) const
194 return GetPoints( myMesh->FindElement( theId ), theRes );
197 bool NumericalFunctor::GetPoints(const SMDS_MeshElement* anElem,
198 TSequenceOfXYZ& theRes )
205 theRes.reserve( anElem->NbNodes() );
207 // Get nodes of the element
208 SMDS_ElemIteratorPtr anIter;
210 if ( anElem->IsQuadratic() ) {
211 switch ( anElem->GetType() ) {
213 anIter = static_cast<const SMDS_QuadraticEdge*>
214 (anElem)->interlacedNodesElemIterator();
217 anIter = static_cast<const SMDS_QuadraticFaceOfNodes*>
218 (anElem)->interlacedNodesElemIterator();
221 anIter = anElem->nodesIterator();
226 anIter = anElem->nodesIterator();
230 while( anIter->more() ) {
231 if ( const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>( anIter->next() ))
232 theRes.push_back( gp_XYZ( aNode->X(), aNode->Y(), aNode->Z() ) );
239 long NumericalFunctor::GetPrecision() const
244 void NumericalFunctor::SetPrecision( const long thePrecision )
246 myPrecision = thePrecision;
249 double NumericalFunctor::GetValue( long theId )
251 myCurrElement = myMesh->FindElement( theId );
253 if ( GetPoints( theId, P ))
255 double aVal = GetValue( P );
256 if ( myPrecision >= 0 )
258 double prec = pow( 10., (double)( myPrecision ) );
259 aVal = floor( aVal * prec + 0.5 ) / prec;
267 //=======================================================================
268 //function : GetValue
270 //=======================================================================
272 double Volume::GetValue( long theElementId )
274 if ( theElementId && myMesh ) {
275 SMDS_VolumeTool aVolumeTool;
276 if ( aVolumeTool.Set( myMesh->FindElement( theElementId )))
277 return aVolumeTool.GetSize();
282 //=======================================================================
283 //function : GetBadRate
284 //purpose : meaningless as it is not quality control functor
285 //=======================================================================
287 double Volume::GetBadRate( double Value, int /*nbNodes*/ ) const
292 //=======================================================================
295 //=======================================================================
297 SMDSAbs_ElementType Volume::GetType() const
299 return SMDSAbs_Volume;
305 Description : Functor for calculation of minimum angle
308 double MinimumAngle::GetValue( const TSequenceOfXYZ& P )
315 aMin = getAngle(P( P.size() ), P( 1 ), P( 2 ));
316 aMin = Min(aMin,getAngle(P( P.size()-1 ), P( P.size() ), P( 1 )));
318 for (int i=2; i<P.size();i++){
319 double A0 = getAngle( P( i-1 ), P( i ), P( i+1 ) );
323 return aMin * 180.0 / PI;
326 double MinimumAngle::GetBadRate( double Value, int nbNodes ) const
328 //const double aBestAngle = PI / nbNodes;
329 const double aBestAngle = 180.0 - ( 360.0 / double(nbNodes) );
330 return ( fabs( aBestAngle - Value ));
333 SMDSAbs_ElementType MinimumAngle::GetType() const
341 Description : Functor for calculating aspect ratio
343 double AspectRatio::GetValue( const TSequenceOfXYZ& P )
345 // According to "Mesh quality control" by Nadir Bouhamau referring to
346 // Pascal Jean Frey and Paul-Louis George. Maillages, applications aux elements finis.
347 // Hermes Science publications, Paris 1999 ISBN 2-7462-0024-4
350 int nbNodes = P.size();
355 // Compute aspect ratio
357 if ( nbNodes == 3 ) {
358 // Compute lengths of the sides
359 vector< double > aLen (nbNodes);
360 for ( int i = 0; i < nbNodes - 1; i++ )
361 aLen[ i ] = getDistance( P( i + 1 ), P( i + 2 ) );
362 aLen[ nbNodes - 1 ] = getDistance( P( 1 ), P( nbNodes ) );
363 // Q = alfa * h * p / S, where
365 // alfa = sqrt( 3 ) / 6
366 // h - length of the longest edge
367 // p - half perimeter
368 // S - triangle surface
369 const double alfa = sqrt( 3. ) / 6.;
370 double maxLen = Max( aLen[ 0 ], Max( aLen[ 1 ], aLen[ 2 ] ) );
371 double half_perimeter = ( aLen[0] + aLen[1] + aLen[2] ) / 2.;
372 double anArea = getArea( P( 1 ), P( 2 ), P( 3 ) );
373 if ( anArea <= Precision::Confusion() )
375 return alfa * maxLen * half_perimeter / anArea;
377 else if ( nbNodes == 6 ) { // quadratic triangles
378 // Compute lengths of the sides
379 vector< double > aLen (3);
380 aLen[0] = getDistance( P(1), P(3) );
381 aLen[1] = getDistance( P(3), P(5) );
382 aLen[2] = getDistance( P(5), P(1) );
383 // Q = alfa * h * p / S, where
385 // alfa = sqrt( 3 ) / 6
386 // h - length of the longest edge
387 // p - half perimeter
388 // S - triangle surface
389 const double alfa = sqrt( 3. ) / 6.;
390 double maxLen = Max( aLen[ 0 ], Max( aLen[ 1 ], aLen[ 2 ] ) );
391 double half_perimeter = ( aLen[0] + aLen[1] + aLen[2] ) / 2.;
392 double anArea = getArea( P(1), P(3), P(5) );
393 if ( anArea <= Precision::Confusion() )
395 return alfa * maxLen * half_perimeter / anArea;
397 else if( nbNodes == 4 ) { // quadrangle
398 // return aspect ratio of the worst triange which can be built
399 // taking three nodes of the quadrangle
400 TSequenceOfXYZ triaPnts(3);
401 // triangle on nodes 1 3 2
405 double ar = GetValue( triaPnts );
406 // triangle on nodes 1 3 4
408 ar = Max ( ar, GetValue( triaPnts ));
409 // triangle on nodes 1 2 4
411 ar = Max ( ar, GetValue( triaPnts ));
412 // triangle on nodes 3 2 4
414 ar = Max ( ar, GetValue( triaPnts ));
418 else { // nbNodes==8 - quadratic quadrangle
419 // return aspect ratio of the worst triange which can be built
420 // taking three nodes of the quadrangle
421 TSequenceOfXYZ triaPnts(3);
422 // triangle on nodes 1 3 2
426 double ar = GetValue( triaPnts );
427 // triangle on nodes 1 3 4
429 ar = Max ( ar, GetValue( triaPnts ));
430 // triangle on nodes 1 2 4
432 ar = Max ( ar, GetValue( triaPnts ));
433 // triangle on nodes 3 2 4
435 ar = Max ( ar, GetValue( triaPnts ));
441 double AspectRatio::GetBadRate( double Value, int /*nbNodes*/ ) const
443 // the aspect ratio is in the range [1.0,infinity]
446 return Value / 1000.;
449 SMDSAbs_ElementType AspectRatio::GetType() const
456 Class : AspectRatio3D
457 Description : Functor for calculating aspect ratio
461 inline double getHalfPerimeter(double theTria[3]){
462 return (theTria[0] + theTria[1] + theTria[2])/2.0;
465 inline double getArea(double theHalfPerim, double theTria[3]){
466 return sqrt(theHalfPerim*
467 (theHalfPerim-theTria[0])*
468 (theHalfPerim-theTria[1])*
469 (theHalfPerim-theTria[2]));
472 inline double getVolume(double theLen[6]){
473 double a2 = theLen[0]*theLen[0];
474 double b2 = theLen[1]*theLen[1];
475 double c2 = theLen[2]*theLen[2];
476 double d2 = theLen[3]*theLen[3];
477 double e2 = theLen[4]*theLen[4];
478 double f2 = theLen[5]*theLen[5];
479 double P = 4.0*a2*b2*d2;
480 double Q = a2*(b2+d2-e2)-b2*(a2+d2-f2)-d2*(a2+b2-c2);
481 double R = (b2+d2-e2)*(a2+d2-f2)*(a2+d2-f2);
482 return sqrt(P-Q+R)/12.0;
485 inline double getVolume2(double theLen[6]){
486 double a2 = theLen[0]*theLen[0];
487 double b2 = theLen[1]*theLen[1];
488 double c2 = theLen[2]*theLen[2];
489 double d2 = theLen[3]*theLen[3];
490 double e2 = theLen[4]*theLen[4];
491 double f2 = theLen[5]*theLen[5];
493 double P = a2*e2*(b2+c2+d2+f2-a2-e2);
494 double Q = b2*f2*(a2+c2+d2+e2-b2-f2);
495 double R = c2*d2*(a2+b2+e2+f2-c2-d2);
496 double S = a2*b2*d2+b2*c2*e2+a2*c2*f2+d2*e2*f2;
498 return sqrt(P+Q+R-S)/12.0;
501 inline double getVolume(const TSequenceOfXYZ& P){
502 gp_Vec aVec1( P( 2 ) - P( 1 ) );
503 gp_Vec aVec2( P( 3 ) - P( 1 ) );
504 gp_Vec aVec3( P( 4 ) - P( 1 ) );
505 gp_Vec anAreaVec( aVec1 ^ aVec2 );
506 return fabs(aVec3 * anAreaVec) / 6.0;
509 inline double getMaxHeight(double theLen[6])
511 double aHeight = max(theLen[0],theLen[1]);
512 aHeight = max(aHeight,theLen[2]);
513 aHeight = max(aHeight,theLen[3]);
514 aHeight = max(aHeight,theLen[4]);
515 aHeight = max(aHeight,theLen[5]);
521 double AspectRatio3D::GetValue( const TSequenceOfXYZ& P )
523 double aQuality = 0.0;
524 if(myCurrElement->IsPoly()) return aQuality;
526 int nbNodes = P.size();
528 if(myCurrElement->IsQuadratic()) {
529 if(nbNodes==10) nbNodes=4; // quadratic tetrahedron
530 else if(nbNodes==13) nbNodes=5; // quadratic pyramid
531 else if(nbNodes==15) nbNodes=6; // quadratic pentahedron
532 else if(nbNodes==20) nbNodes=8; // quadratic hexahedron
533 else return aQuality;
539 getDistance(P( 1 ),P( 2 )), // a
540 getDistance(P( 2 ),P( 3 )), // b
541 getDistance(P( 3 ),P( 1 )), // c
542 getDistance(P( 2 ),P( 4 )), // d
543 getDistance(P( 3 ),P( 4 )), // e
544 getDistance(P( 1 ),P( 4 )) // f
546 double aTria[4][3] = {
547 {aLen[0],aLen[1],aLen[2]}, // abc
548 {aLen[0],aLen[3],aLen[5]}, // adf
549 {aLen[1],aLen[3],aLen[4]}, // bde
550 {aLen[2],aLen[4],aLen[5]} // cef
552 double aSumArea = 0.0;
553 double aHalfPerimeter = getHalfPerimeter(aTria[0]);
554 double anArea = getArea(aHalfPerimeter,aTria[0]);
556 aHalfPerimeter = getHalfPerimeter(aTria[1]);
557 anArea = getArea(aHalfPerimeter,aTria[1]);
559 aHalfPerimeter = getHalfPerimeter(aTria[2]);
560 anArea = getArea(aHalfPerimeter,aTria[2]);
562 aHalfPerimeter = getHalfPerimeter(aTria[3]);
563 anArea = getArea(aHalfPerimeter,aTria[3]);
565 double aVolume = getVolume(P);
566 //double aVolume = getVolume(aLen);
567 double aHeight = getMaxHeight(aLen);
568 static double aCoeff = sqrt(2.0)/12.0;
569 if ( aVolume > DBL_MIN )
570 aQuality = aCoeff*aHeight*aSumArea/aVolume;
575 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 3 ),P( 5 )};
576 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
579 gp_XYZ aXYZ[4] = {P( 1 ),P( 3 ),P( 4 ),P( 5 )};
580 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
583 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 5 )};
584 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
587 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 4 ),P( 5 )};
588 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
594 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 6 )};
595 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
598 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 3 )};
599 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
602 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 6 )};
603 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
606 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
607 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
610 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 6 )};
611 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
614 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 3 )};
615 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
621 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
622 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
625 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 4 )};
626 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
629 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 7 )};
630 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
633 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 8 )};
634 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
637 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 3 )};
638 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
641 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 4 )};
642 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
645 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 7 )};
646 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
649 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 8 )};
650 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
653 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 3 )};
654 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
657 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 4 )};
658 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
661 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 7 )};
662 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
665 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 8 )};
666 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
669 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 1 )};
670 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
673 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 2 )};
674 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
677 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 5 )};
678 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
681 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 6 )};
682 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
685 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 1 )};
686 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
689 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 2 )};
690 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
693 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 5 )};
694 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
697 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 6 )};
698 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
701 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 1 )};
702 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
705 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
706 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
709 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 5 )};
710 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
713 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 6 )};
714 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
717 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
718 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
721 gp_XYZ aXYZ[4] = {P( 4 ),P( 5 ),P( 8 ),P( 2 )};
722 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
725 gp_XYZ aXYZ[4] = {P( 1 ),P( 4 ),P( 5 ),P( 3 )};
726 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
729 gp_XYZ aXYZ[4] = {P( 3 ),P( 6 ),P( 7 ),P( 1 )};
730 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
733 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 6 ),P( 4 )};
734 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
737 gp_XYZ aXYZ[4] = {P( 5 ),P( 6 ),P( 8 ),P( 3 )};
738 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
741 gp_XYZ aXYZ[4] = {P( 7 ),P( 8 ),P( 6 ),P( 1 )};
742 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
745 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 7 )};
746 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
749 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 2 ),P( 5 )};
750 aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
756 // avaluate aspect ratio of quadranle faces
757 AspectRatio aspect2D;
758 SMDS_VolumeTool::VolumeType type = SMDS_VolumeTool::GetType( nbNodes );
759 int nbFaces = SMDS_VolumeTool::NbFaces( type );
760 TSequenceOfXYZ points(4);
761 for ( int i = 0; i < nbFaces; ++i ) { // loop on faces of a volume
762 if ( SMDS_VolumeTool::NbFaceNodes( type, i ) != 4 )
764 const int* pInd = SMDS_VolumeTool::GetFaceNodesIndices( type, i, true );
765 for ( int p = 0; p < 4; ++p ) // loop on nodes of a quadranle face
766 points( p + 1 ) = P( pInd[ p ] + 1 );
767 aQuality = max( aQuality, aspect2D.GetValue( points ));
773 double AspectRatio3D::GetBadRate( double Value, int /*nbNodes*/ ) const
775 // the aspect ratio is in the range [1.0,infinity]
778 return Value / 1000.;
781 SMDSAbs_ElementType AspectRatio3D::GetType() const
783 return SMDSAbs_Volume;
789 Description : Functor for calculating warping
791 double Warping::GetValue( const TSequenceOfXYZ& P )
796 gp_XYZ G = ( P( 1 ) + P( 2 ) + P( 3 ) + P( 4 ) ) / 4;
798 double A1 = ComputeA( P( 1 ), P( 2 ), P( 3 ), G );
799 double A2 = ComputeA( P( 2 ), P( 3 ), P( 4 ), G );
800 double A3 = ComputeA( P( 3 ), P( 4 ), P( 1 ), G );
801 double A4 = ComputeA( P( 4 ), P( 1 ), P( 2 ), G );
803 return Max( Max( A1, A2 ), Max( A3, A4 ) );
806 double Warping::ComputeA( const gp_XYZ& thePnt1,
807 const gp_XYZ& thePnt2,
808 const gp_XYZ& thePnt3,
809 const gp_XYZ& theG ) const
811 double aLen1 = gp_Pnt( thePnt1 ).Distance( gp_Pnt( thePnt2 ) );
812 double aLen2 = gp_Pnt( thePnt2 ).Distance( gp_Pnt( thePnt3 ) );
813 double L = Min( aLen1, aLen2 ) * 0.5;
814 if ( L < Precision::Confusion())
817 gp_XYZ GI = ( thePnt2 + thePnt1 ) / 2. - theG;
818 gp_XYZ GJ = ( thePnt3 + thePnt2 ) / 2. - theG;
819 gp_XYZ N = GI.Crossed( GJ );
821 if ( N.Modulus() < gp::Resolution() )
826 double H = ( thePnt2 - theG ).Dot( N );
827 return asin( fabs( H / L ) ) * 180 / PI;
830 double Warping::GetBadRate( double Value, int /*nbNodes*/ ) const
832 // the warp is in the range [0.0,PI/2]
833 // 0.0 = good (no warp)
834 // PI/2 = bad (face pliee)
838 SMDSAbs_ElementType Warping::GetType() const
846 Description : Functor for calculating taper
848 double Taper::GetValue( const TSequenceOfXYZ& P )
854 double J1 = getArea( P( 4 ), P( 1 ), P( 2 ) ) / 2;
855 double J2 = getArea( P( 3 ), P( 1 ), P( 2 ) ) / 2;
856 double J3 = getArea( P( 2 ), P( 3 ), P( 4 ) ) / 2;
857 double J4 = getArea( P( 3 ), P( 4 ), P( 1 ) ) / 2;
859 double JA = 0.25 * ( J1 + J2 + J3 + J4 );
860 if ( JA <= Precision::Confusion() )
863 double T1 = fabs( ( J1 - JA ) / JA );
864 double T2 = fabs( ( J2 - JA ) / JA );
865 double T3 = fabs( ( J3 - JA ) / JA );
866 double T4 = fabs( ( J4 - JA ) / JA );
868 return Max( Max( T1, T2 ), Max( T3, T4 ) );
871 double Taper::GetBadRate( double Value, int /*nbNodes*/ ) const
873 // the taper is in the range [0.0,1.0]
874 // 0.0 = good (no taper)
875 // 1.0 = bad (les cotes opposes sont allignes)
879 SMDSAbs_ElementType Taper::GetType() const
887 Description : Functor for calculating skew in degrees
889 static inline double skewAngle( const gp_XYZ& p1, const gp_XYZ& p2, const gp_XYZ& p3 )
891 gp_XYZ p12 = ( p2 + p1 ) / 2;
892 gp_XYZ p23 = ( p3 + p2 ) / 2;
893 gp_XYZ p31 = ( p3 + p1 ) / 2;
895 gp_Vec v1( p31 - p2 ), v2( p12 - p23 );
897 return v1.Magnitude() < gp::Resolution() || v2.Magnitude() < gp::Resolution() ? 0 : v1.Angle( v2 );
900 double Skew::GetValue( const TSequenceOfXYZ& P )
902 if ( P.size() != 3 && P.size() != 4 )
906 static double PI2 = PI / 2;
909 double A0 = fabs( PI2 - skewAngle( P( 3 ), P( 1 ), P( 2 ) ) );
910 double A1 = fabs( PI2 - skewAngle( P( 1 ), P( 2 ), P( 3 ) ) );
911 double A2 = fabs( PI2 - skewAngle( P( 2 ), P( 3 ), P( 1 ) ) );
913 return Max( A0, Max( A1, A2 ) ) * 180 / PI;
917 gp_XYZ p12 = ( P( 1 ) + P( 2 ) ) / 2;
918 gp_XYZ p23 = ( P( 2 ) + P( 3 ) ) / 2;
919 gp_XYZ p34 = ( P( 3 ) + P( 4 ) ) / 2;
920 gp_XYZ p41 = ( P( 4 ) + P( 1 ) ) / 2;
922 gp_Vec v1( p34 - p12 ), v2( p23 - p41 );
923 double A = v1.Magnitude() <= gp::Resolution() || v2.Magnitude() <= gp::Resolution()
924 ? 0 : fabs( PI2 - v1.Angle( v2 ) );
930 double Skew::GetBadRate( double Value, int /*nbNodes*/ ) const
932 // the skew is in the range [0.0,PI/2].
938 SMDSAbs_ElementType Skew::GetType() const
946 Description : Functor for calculating area
948 double Area::GetValue( const TSequenceOfXYZ& P )
950 gp_Vec aVec1( P(2) - P(1) );
951 gp_Vec aVec2( P(3) - P(1) );
952 gp_Vec SumVec = aVec1 ^ aVec2;
953 for (int i=4; i<=P.size(); i++) {
954 gp_Vec aVec1( P(i-1) - P(1) );
955 gp_Vec aVec2( P(i) - P(1) );
956 gp_Vec tmp = aVec1 ^ aVec2;
959 return SumVec.Magnitude() * 0.5;
962 double Area::GetBadRate( double Value, int /*nbNodes*/ ) const
964 // meaningless as it is not a quality control functor
968 SMDSAbs_ElementType Area::GetType() const
976 Description : Functor for calculating length off edge
978 double Length::GetValue( const TSequenceOfXYZ& P )
980 switch ( P.size() ) {
981 case 2: return getDistance( P( 1 ), P( 2 ) );
982 case 3: return getDistance( P( 1 ), P( 2 ) ) + getDistance( P( 2 ), P( 3 ) );
987 double Length::GetBadRate( double Value, int /*nbNodes*/ ) const
989 // meaningless as it is not quality control functor
993 SMDSAbs_ElementType Length::GetType() const
1000 Description : Functor for calculating length of edge
1003 double Length2D::GetValue( long theElementId)
1007 //cout<<"Length2D::GetValue"<<endl;
1008 if (GetPoints(theElementId,P)){
1009 //for(int jj=1; jj<=P.size(); jj++)
1010 // cout<<"jj="<<jj<<" P("<<P(jj).X()<<","<<P(jj).Y()<<","<<P(jj).Z()<<")"<<endl;
1012 double aVal;// = GetValue( P );
1013 const SMDS_MeshElement* aElem = myMesh->FindElement( theElementId );
1014 SMDSAbs_ElementType aType = aElem->GetType();
1023 aVal = getDistance( P( 1 ), P( 2 ) );
1026 else if (len == 3){ // quadratic edge
1027 aVal = getDistance(P( 1 ),P( 3 )) + getDistance(P( 3 ),P( 2 ));
1031 if (len == 3){ // triangles
1032 double L1 = getDistance(P( 1 ),P( 2 ));
1033 double L2 = getDistance(P( 2 ),P( 3 ));
1034 double L3 = getDistance(P( 3 ),P( 1 ));
1035 aVal = Max(L1,Max(L2,L3));
1038 else if (len == 4){ // quadrangles
1039 double L1 = getDistance(P( 1 ),P( 2 ));
1040 double L2 = getDistance(P( 2 ),P( 3 ));
1041 double L3 = getDistance(P( 3 ),P( 4 ));
1042 double L4 = getDistance(P( 4 ),P( 1 ));
1043 aVal = Max(Max(L1,L2),Max(L3,L4));
1046 if (len == 6){ // quadratic triangles
1047 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1048 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1049 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 1 ));
1050 aVal = Max(L1,Max(L2,L3));
1051 //cout<<"L1="<<L1<<" L2="<<L2<<"L3="<<L3<<" aVal="<<aVal<<endl;
1054 else if (len == 8){ // quadratic quadrangles
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( 7 ));
1058 double L4 = getDistance(P( 7 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
1059 aVal = Max(Max(L1,L2),Max(L3,L4));
1062 case SMDSAbs_Volume:
1063 if (len == 4){ // tetraidrs
1064 double L1 = getDistance(P( 1 ),P( 2 ));
1065 double L2 = getDistance(P( 2 ),P( 3 ));
1066 double L3 = getDistance(P( 3 ),P( 1 ));
1067 double L4 = getDistance(P( 1 ),P( 4 ));
1068 double L5 = getDistance(P( 2 ),P( 4 ));
1069 double L6 = getDistance(P( 3 ),P( 4 ));
1070 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1073 else if (len == 5){ // piramids
1074 double L1 = getDistance(P( 1 ),P( 2 ));
1075 double L2 = getDistance(P( 2 ),P( 3 ));
1076 double L3 = getDistance(P( 3 ),P( 1 ));
1077 double L4 = getDistance(P( 4 ),P( 1 ));
1078 double L5 = getDistance(P( 1 ),P( 5 ));
1079 double L6 = getDistance(P( 2 ),P( 5 ));
1080 double L7 = getDistance(P( 3 ),P( 5 ));
1081 double L8 = getDistance(P( 4 ),P( 5 ));
1083 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1084 aVal = Max(aVal,Max(L7,L8));
1087 else if (len == 6){ // pentaidres
1088 double L1 = getDistance(P( 1 ),P( 2 ));
1089 double L2 = getDistance(P( 2 ),P( 3 ));
1090 double L3 = getDistance(P( 3 ),P( 1 ));
1091 double L4 = getDistance(P( 4 ),P( 5 ));
1092 double L5 = getDistance(P( 5 ),P( 6 ));
1093 double L6 = getDistance(P( 6 ),P( 4 ));
1094 double L7 = getDistance(P( 1 ),P( 4 ));
1095 double L8 = getDistance(P( 2 ),P( 5 ));
1096 double L9 = getDistance(P( 3 ),P( 6 ));
1098 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1099 aVal = Max(aVal,Max(Max(L7,L8),L9));
1102 else if (len == 8){ // hexaider
1103 double L1 = getDistance(P( 1 ),P( 2 ));
1104 double L2 = getDistance(P( 2 ),P( 3 ));
1105 double L3 = getDistance(P( 3 ),P( 4 ));
1106 double L4 = getDistance(P( 4 ),P( 1 ));
1107 double L5 = getDistance(P( 5 ),P( 6 ));
1108 double L6 = getDistance(P( 6 ),P( 7 ));
1109 double L7 = getDistance(P( 7 ),P( 8 ));
1110 double L8 = getDistance(P( 8 ),P( 5 ));
1111 double L9 = getDistance(P( 1 ),P( 5 ));
1112 double L10= getDistance(P( 2 ),P( 6 ));
1113 double L11= getDistance(P( 3 ),P( 7 ));
1114 double L12= getDistance(P( 4 ),P( 8 ));
1116 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1117 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
1118 aVal = Max(aVal,Max(L11,L12));
1123 if (len == 10){ // quadratic tetraidrs
1124 double L1 = getDistance(P( 1 ),P( 5 )) + getDistance(P( 5 ),P( 2 ));
1125 double L2 = getDistance(P( 2 ),P( 6 )) + getDistance(P( 6 ),P( 3 ));
1126 double L3 = getDistance(P( 3 ),P( 7 )) + getDistance(P( 7 ),P( 1 ));
1127 double L4 = getDistance(P( 1 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
1128 double L5 = getDistance(P( 2 ),P( 9 )) + getDistance(P( 9 ),P( 4 ));
1129 double L6 = getDistance(P( 3 ),P( 10 )) + getDistance(P( 10 ),P( 4 ));
1130 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1133 else if (len == 13){ // quadratic piramids
1134 double L1 = getDistance(P( 1 ),P( 6 )) + getDistance(P( 6 ),P( 2 ));
1135 double L2 = getDistance(P( 2 ),P( 7 )) + getDistance(P( 7 ),P( 3 ));
1136 double L3 = getDistance(P( 3 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
1137 double L4 = getDistance(P( 4 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1138 double L5 = getDistance(P( 1 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1139 double L6 = getDistance(P( 2 ),P( 11 )) + getDistance(P( 11 ),P( 5 ));
1140 double L7 = getDistance(P( 3 ),P( 12 )) + getDistance(P( 12 ),P( 5 ));
1141 double L8 = getDistance(P( 4 ),P( 13 )) + getDistance(P( 13 ),P( 5 ));
1142 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1143 aVal = Max(aVal,Max(L7,L8));
1146 else if (len == 15){ // quadratic pentaidres
1147 double L1 = getDistance(P( 1 ),P( 7 )) + getDistance(P( 7 ),P( 2 ));
1148 double L2 = getDistance(P( 2 ),P( 8 )) + getDistance(P( 8 ),P( 3 ));
1149 double L3 = getDistance(P( 3 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1150 double L4 = getDistance(P( 4 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1151 double L5 = getDistance(P( 5 ),P( 11 )) + getDistance(P( 11 ),P( 6 ));
1152 double L6 = getDistance(P( 6 ),P( 12 )) + getDistance(P( 12 ),P( 4 ));
1153 double L7 = getDistance(P( 1 ),P( 13 )) + getDistance(P( 13 ),P( 4 ));
1154 double L8 = getDistance(P( 2 ),P( 14 )) + getDistance(P( 14 ),P( 5 ));
1155 double L9 = getDistance(P( 3 ),P( 15 )) + getDistance(P( 15 ),P( 6 ));
1156 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1157 aVal = Max(aVal,Max(Max(L7,L8),L9));
1160 else if (len == 20){ // quadratic hexaider
1161 double L1 = getDistance(P( 1 ),P( 9 )) + getDistance(P( 9 ),P( 2 ));
1162 double L2 = getDistance(P( 2 ),P( 10 )) + getDistance(P( 10 ),P( 3 ));
1163 double L3 = getDistance(P( 3 ),P( 11 )) + getDistance(P( 11 ),P( 4 ));
1164 double L4 = getDistance(P( 4 ),P( 12 )) + getDistance(P( 12 ),P( 1 ));
1165 double L5 = getDistance(P( 5 ),P( 13 )) + getDistance(P( 13 ),P( 6 ));
1166 double L6 = getDistance(P( 6 ),P( 14 )) + getDistance(P( 14 ),P( 7 ));
1167 double L7 = getDistance(P( 7 ),P( 15 )) + getDistance(P( 15 ),P( 8 ));
1168 double L8 = getDistance(P( 8 ),P( 16 )) + getDistance(P( 16 ),P( 5 ));
1169 double L9 = getDistance(P( 1 ),P( 17 )) + getDistance(P( 17 ),P( 5 ));
1170 double L10= getDistance(P( 2 ),P( 18 )) + getDistance(P( 18 ),P( 6 ));
1171 double L11= getDistance(P( 3 ),P( 19 )) + getDistance(P( 19 ),P( 7 ));
1172 double L12= getDistance(P( 4 ),P( 20 )) + getDistance(P( 20 ),P( 8 ));
1173 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1174 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
1175 aVal = Max(aVal,Max(L11,L12));
1187 if ( myPrecision >= 0 )
1189 double prec = pow( 10., (double)( myPrecision ) );
1190 aVal = floor( aVal * prec + 0.5 ) / prec;
1199 double Length2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1201 // meaningless as it is not quality control functor
1205 SMDSAbs_ElementType Length2D::GetType() const
1207 return SMDSAbs_Face;
1210 Length2D::Value::Value(double theLength,long thePntId1, long thePntId2):
1213 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1214 if(thePntId1 > thePntId2){
1215 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1219 bool Length2D::Value::operator<(const Length2D::Value& x) const{
1220 if(myPntId[0] < x.myPntId[0]) return true;
1221 if(myPntId[0] == x.myPntId[0])
1222 if(myPntId[1] < x.myPntId[1]) return true;
1226 void Length2D::GetValues(TValues& theValues){
1228 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1229 for(; anIter->more(); ){
1230 const SMDS_MeshFace* anElem = anIter->next();
1232 if(anElem->IsQuadratic()) {
1233 const SMDS_QuadraticFaceOfNodes* F =
1234 static_cast<const SMDS_QuadraticFaceOfNodes*>(anElem);
1235 // use special nodes iterator
1236 SMDS_NodeIteratorPtr anIter = F->interlacedNodesIterator();
1241 const SMDS_MeshElement* aNode;
1243 aNode = anIter->next();
1244 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1245 P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1246 aNodeId[0] = aNodeId[1] = aNode->GetID();
1249 for(; anIter->more(); ){
1250 const SMDS_MeshNode* N1 = static_cast<const SMDS_MeshNode*> (anIter->next());
1251 P[2] = gp_Pnt(N1->X(),N1->Y(),N1->Z());
1252 aNodeId[2] = N1->GetID();
1253 aLength = P[1].Distance(P[2]);
1254 if(!anIter->more()) break;
1255 const SMDS_MeshNode* N2 = static_cast<const SMDS_MeshNode*> (anIter->next());
1256 P[3] = gp_Pnt(N2->X(),N2->Y(),N2->Z());
1257 aNodeId[3] = N2->GetID();
1258 aLength += P[2].Distance(P[3]);
1259 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1260 Value aValue2(aLength,aNodeId[2],aNodeId[3]);
1262 aNodeId[1] = aNodeId[3];
1263 theValues.insert(aValue1);
1264 theValues.insert(aValue2);
1266 aLength += P[2].Distance(P[0]);
1267 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1268 Value aValue2(aLength,aNodeId[2],aNodeId[0]);
1269 theValues.insert(aValue1);
1270 theValues.insert(aValue2);
1273 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
1278 const SMDS_MeshElement* aNode;
1279 if(aNodesIter->more()){
1280 aNode = aNodesIter->next();
1281 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1282 P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1283 aNodeId[0] = aNodeId[1] = aNode->GetID();
1286 for(; aNodesIter->more(); ){
1287 aNode = aNodesIter->next();
1288 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1289 long anId = aNode->GetID();
1291 P[2] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1293 aLength = P[1].Distance(P[2]);
1295 Value aValue(aLength,aNodeId[1],anId);
1298 theValues.insert(aValue);
1301 aLength = P[0].Distance(P[1]);
1303 Value aValue(aLength,aNodeId[0],aNodeId[1]);
1304 theValues.insert(aValue);
1310 Class : MultiConnection
1311 Description : Functor for calculating number of faces conneted to the edge
1313 double MultiConnection::GetValue( const TSequenceOfXYZ& P )
1317 double MultiConnection::GetValue( long theId )
1319 return getNbMultiConnection( myMesh, theId );
1322 double MultiConnection::GetBadRate( double Value, int /*nbNodes*/ ) const
1324 // meaningless as it is not quality control functor
1328 SMDSAbs_ElementType MultiConnection::GetType() const
1330 return SMDSAbs_Edge;
1334 Class : MultiConnection2D
1335 Description : Functor for calculating number of faces conneted to the edge
1337 double MultiConnection2D::GetValue( const TSequenceOfXYZ& P )
1342 double MultiConnection2D::GetValue( long theElementId )
1346 const SMDS_MeshElement* aFaceElem = myMesh->FindElement(theElementId);
1347 SMDSAbs_ElementType aType = aFaceElem->GetType();
1352 int i = 0, len = aFaceElem->NbNodes();
1353 SMDS_ElemIteratorPtr anIter = aFaceElem->nodesIterator();
1356 const SMDS_MeshNode *aNode, *aNode0;
1357 TColStd_MapOfInteger aMap, aMapPrev;
1359 for (i = 0; i <= len; i++) {
1364 if (anIter->more()) {
1365 aNode = (SMDS_MeshNode*)anIter->next();
1373 if (i == 0) aNode0 = aNode;
1375 SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator();
1376 while (anElemIter->more()) {
1377 const SMDS_MeshElement* anElem = anElemIter->next();
1378 if (anElem != 0 && anElem->GetType() == SMDSAbs_Face) {
1379 int anId = anElem->GetID();
1382 if (aMapPrev.Contains(anId)) {
1387 aResult = Max(aResult, aNb);
1398 double MultiConnection2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1400 // meaningless as it is not quality control functor
1404 SMDSAbs_ElementType MultiConnection2D::GetType() const
1406 return SMDSAbs_Face;
1409 MultiConnection2D::Value::Value(long thePntId1, long thePntId2)
1411 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1412 if(thePntId1 > thePntId2){
1413 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1417 bool MultiConnection2D::Value::operator<(const MultiConnection2D::Value& x) const{
1418 if(myPntId[0] < x.myPntId[0]) return true;
1419 if(myPntId[0] == x.myPntId[0])
1420 if(myPntId[1] < x.myPntId[1]) return true;
1424 void MultiConnection2D::GetValues(MValues& theValues){
1425 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1426 for(; anIter->more(); ){
1427 const SMDS_MeshFace* anElem = anIter->next();
1428 SMDS_ElemIteratorPtr aNodesIter;
1429 if ( anElem->IsQuadratic() )
1430 aNodesIter = static_cast<const SMDS_QuadraticFaceOfNodes*>
1431 (anElem)->interlacedNodesElemIterator();
1433 aNodesIter = anElem->nodesIterator();
1436 //int aNbConnects=0;
1437 const SMDS_MeshNode* aNode0;
1438 const SMDS_MeshNode* aNode1;
1439 const SMDS_MeshNode* aNode2;
1440 if(aNodesIter->more()){
1441 aNode0 = (SMDS_MeshNode*) aNodesIter->next();
1443 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode1;
1444 aNodeId[0] = aNodeId[1] = aNodes->GetID();
1446 for(; aNodesIter->more(); ) {
1447 aNode2 = (SMDS_MeshNode*) aNodesIter->next();
1448 long anId = aNode2->GetID();
1451 Value aValue(aNodeId[1],aNodeId[2]);
1452 MValues::iterator aItr = theValues.find(aValue);
1453 if (aItr != theValues.end()){
1458 theValues[aValue] = 1;
1461 //cout << "NodeIds: "<<aNodeId[1]<<","<<aNodeId[2]<<" nbconn="<<aNbConnects<<endl;
1462 aNodeId[1] = aNodeId[2];
1465 Value aValue(aNodeId[0],aNodeId[2]);
1466 MValues::iterator aItr = theValues.find(aValue);
1467 if (aItr != theValues.end()) {
1472 theValues[aValue] = 1;
1475 //cout << "NodeIds: "<<aNodeId[0]<<","<<aNodeId[2]<<" nbconn="<<aNbConnects<<endl;
1485 Class : BadOrientedVolume
1486 Description : Predicate bad oriented volumes
1489 BadOrientedVolume::BadOrientedVolume()
1494 void BadOrientedVolume::SetMesh( const SMDS_Mesh* theMesh )
1499 bool BadOrientedVolume::IsSatisfy( long theId )
1504 SMDS_VolumeTool vTool( myMesh->FindElement( theId ));
1505 return !vTool.IsForward();
1508 SMDSAbs_ElementType BadOrientedVolume::GetType() const
1510 return SMDSAbs_Volume;
1517 Description : Predicate for free borders
1520 FreeBorders::FreeBorders()
1525 void FreeBorders::SetMesh( const SMDS_Mesh* theMesh )
1530 bool FreeBorders::IsSatisfy( long theId )
1532 return getNbMultiConnection( myMesh, theId ) == 1;
1535 SMDSAbs_ElementType FreeBorders::GetType() const
1537 return SMDSAbs_Edge;
1543 Description : Predicate for free Edges
1545 FreeEdges::FreeEdges()
1550 void FreeEdges::SetMesh( const SMDS_Mesh* theMesh )
1555 bool FreeEdges::IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId )
1557 TColStd_MapOfInteger aMap;
1558 for ( int i = 0; i < 2; i++ )
1560 SMDS_ElemIteratorPtr anElemIter = theNodes[ i ]->GetInverseElementIterator();
1561 while( anElemIter->more() )
1563 const SMDS_MeshElement* anElem = anElemIter->next();
1564 if ( anElem != 0 && anElem->GetType() == SMDSAbs_Face )
1566 int anId = anElem->GetID();
1570 else if ( aMap.Contains( anId ) && anId != theFaceId )
1578 bool FreeEdges::IsSatisfy( long theId )
1583 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
1584 if ( aFace == 0 || aFace->GetType() != SMDSAbs_Face || aFace->NbNodes() < 3 )
1587 SMDS_ElemIteratorPtr anIter;
1588 if ( aFace->IsQuadratic() ) {
1589 anIter = static_cast<const SMDS_QuadraticFaceOfNodes*>
1590 (aFace)->interlacedNodesElemIterator();
1593 anIter = aFace->nodesIterator();
1598 int i = 0, nbNodes = aFace->NbNodes();
1599 vector <const SMDS_MeshNode*> aNodes( nbNodes+1 );
1600 while( anIter->more() )
1602 const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next();
1605 aNodes[ i++ ] = aNode;
1607 aNodes[ nbNodes ] = aNodes[ 0 ];
1609 for ( i = 0; i < nbNodes; i++ )
1610 if ( IsFreeEdge( &aNodes[ i ], theId ) )
1616 SMDSAbs_ElementType FreeEdges::GetType() const
1618 return SMDSAbs_Face;
1621 FreeEdges::Border::Border(long theElemId, long thePntId1, long thePntId2):
1624 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1625 if(thePntId1 > thePntId2){
1626 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1630 bool FreeEdges::Border::operator<(const FreeEdges::Border& x) const{
1631 if(myPntId[0] < x.myPntId[0]) return true;
1632 if(myPntId[0] == x.myPntId[0])
1633 if(myPntId[1] < x.myPntId[1]) return true;
1637 inline void UpdateBorders(const FreeEdges::Border& theBorder,
1638 FreeEdges::TBorders& theRegistry,
1639 FreeEdges::TBorders& theContainer)
1641 if(theRegistry.find(theBorder) == theRegistry.end()){
1642 theRegistry.insert(theBorder);
1643 theContainer.insert(theBorder);
1645 theContainer.erase(theBorder);
1649 void FreeEdges::GetBoreders(TBorders& theBorders)
1652 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1653 for(; anIter->more(); ){
1654 const SMDS_MeshFace* anElem = anIter->next();
1655 long anElemId = anElem->GetID();
1656 SMDS_ElemIteratorPtr aNodesIter;
1657 if ( anElem->IsQuadratic() )
1658 aNodesIter = static_cast<const SMDS_QuadraticFaceOfNodes*>(anElem)->
1659 interlacedNodesElemIterator();
1661 aNodesIter = anElem->nodesIterator();
1663 const SMDS_MeshElement* aNode;
1664 if(aNodesIter->more()){
1665 aNode = aNodesIter->next();
1666 aNodeId[0] = aNodeId[1] = aNode->GetID();
1668 for(; aNodesIter->more(); ){
1669 aNode = aNodesIter->next();
1670 long anId = aNode->GetID();
1671 Border aBorder(anElemId,aNodeId[1],anId);
1673 //std::cout<<aBorder.myPntId[0]<<"; "<<aBorder.myPntId[1]<<"; "<<aBorder.myElemId<<endl;
1674 UpdateBorders(aBorder,aRegistry,theBorders);
1676 Border aBorder(anElemId,aNodeId[0],aNodeId[1]);
1677 //std::cout<<aBorder.myPntId[0]<<"; "<<aBorder.myPntId[1]<<"; "<<aBorder.myElemId<<endl;
1678 UpdateBorders(aBorder,aRegistry,theBorders);
1680 //std::cout<<"theBorders.size() = "<<theBorders.size()<<endl;
1685 Description : Predicate for Range of Ids.
1686 Range may be specified with two ways.
1687 1. Using AddToRange method
1688 2. With SetRangeStr method. Parameter of this method is a string
1689 like as "1,2,3,50-60,63,67,70-"
1692 //=======================================================================
1693 // name : RangeOfIds
1694 // Purpose : Constructor
1695 //=======================================================================
1696 RangeOfIds::RangeOfIds()
1699 myType = SMDSAbs_All;
1702 //=======================================================================
1704 // Purpose : Set mesh
1705 //=======================================================================
1706 void RangeOfIds::SetMesh( const SMDS_Mesh* theMesh )
1711 //=======================================================================
1712 // name : AddToRange
1713 // Purpose : Add ID to the range
1714 //=======================================================================
1715 bool RangeOfIds::AddToRange( long theEntityId )
1717 myIds.Add( theEntityId );
1721 //=======================================================================
1722 // name : GetRangeStr
1723 // Purpose : Get range as a string.
1724 // Example: "1,2,3,50-60,63,67,70-"
1725 //=======================================================================
1726 void RangeOfIds::GetRangeStr( TCollection_AsciiString& theResStr )
1730 TColStd_SequenceOfInteger anIntSeq;
1731 TColStd_SequenceOfAsciiString aStrSeq;
1733 TColStd_MapIteratorOfMapOfInteger anIter( myIds );
1734 for ( ; anIter.More(); anIter.Next() )
1736 int anId = anIter.Key();
1737 TCollection_AsciiString aStr( anId );
1738 anIntSeq.Append( anId );
1739 aStrSeq.Append( aStr );
1742 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
1744 int aMinId = myMin( i );
1745 int aMaxId = myMax( i );
1747 TCollection_AsciiString aStr;
1748 if ( aMinId != IntegerFirst() )
1753 if ( aMaxId != IntegerLast() )
1756 // find position of the string in result sequence and insert string in it
1757 if ( anIntSeq.Length() == 0 )
1759 anIntSeq.Append( aMinId );
1760 aStrSeq.Append( aStr );
1764 if ( aMinId < anIntSeq.First() )
1766 anIntSeq.Prepend( aMinId );
1767 aStrSeq.Prepend( aStr );
1769 else if ( aMinId > anIntSeq.Last() )
1771 anIntSeq.Append( aMinId );
1772 aStrSeq.Append( aStr );
1775 for ( int j = 1, k = anIntSeq.Length(); j <= k; j++ )
1776 if ( aMinId < anIntSeq( j ) )
1778 anIntSeq.InsertBefore( j, aMinId );
1779 aStrSeq.InsertBefore( j, aStr );
1785 if ( aStrSeq.Length() == 0 )
1788 theResStr = aStrSeq( 1 );
1789 for ( int j = 2, k = aStrSeq.Length(); j <= k; j++ )
1792 theResStr += aStrSeq( j );
1796 //=======================================================================
1797 // name : SetRangeStr
1798 // Purpose : Define range with string
1799 // Example of entry string: "1,2,3,50-60,63,67,70-"
1800 //=======================================================================
1801 bool RangeOfIds::SetRangeStr( const TCollection_AsciiString& theStr )
1807 TCollection_AsciiString aStr = theStr;
1808 aStr.RemoveAll( ' ' );
1809 aStr.RemoveAll( '\t' );
1811 for ( int aPos = aStr.Search( ",," ); aPos != -1; aPos = aStr.Search( ",," ) )
1812 aStr.Remove( aPos, 2 );
1814 TCollection_AsciiString tmpStr = aStr.Token( ",", 1 );
1816 while ( tmpStr != "" )
1818 tmpStr = aStr.Token( ",", i++ );
1819 int aPos = tmpStr.Search( '-' );
1823 if ( tmpStr.IsIntegerValue() )
1824 myIds.Add( tmpStr.IntegerValue() );
1830 TCollection_AsciiString aMaxStr = tmpStr.Split( aPos );
1831 TCollection_AsciiString aMinStr = tmpStr;
1833 while ( aMinStr.Search( "-" ) != -1 ) aMinStr.RemoveAll( '-' );
1834 while ( aMaxStr.Search( "-" ) != -1 ) aMaxStr.RemoveAll( '-' );
1836 if ( !aMinStr.IsEmpty() && !aMinStr.IsIntegerValue() ||
1837 !aMaxStr.IsEmpty() && !aMaxStr.IsIntegerValue() )
1840 myMin.Append( aMinStr.IsEmpty() ? IntegerFirst() : aMinStr.IntegerValue() );
1841 myMax.Append( aMaxStr.IsEmpty() ? IntegerLast() : aMaxStr.IntegerValue() );
1848 //=======================================================================
1850 // Purpose : Get type of supported entities
1851 //=======================================================================
1852 SMDSAbs_ElementType RangeOfIds::GetType() const
1857 //=======================================================================
1859 // Purpose : Set type of supported entities
1860 //=======================================================================
1861 void RangeOfIds::SetType( SMDSAbs_ElementType theType )
1866 //=======================================================================
1868 // Purpose : Verify whether entity satisfies to this rpedicate
1869 //=======================================================================
1870 bool RangeOfIds::IsSatisfy( long theId )
1875 if ( myType == SMDSAbs_Node )
1877 if ( myMesh->FindNode( theId ) == 0 )
1882 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
1883 if ( anElem == 0 || myType != anElem->GetType() && myType != SMDSAbs_All )
1887 if ( myIds.Contains( theId ) )
1890 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
1891 if ( theId >= myMin( i ) && theId <= myMax( i ) )
1899 Description : Base class for comparators
1901 Comparator::Comparator():
1905 Comparator::~Comparator()
1908 void Comparator::SetMesh( const SMDS_Mesh* theMesh )
1911 myFunctor->SetMesh( theMesh );
1914 void Comparator::SetMargin( double theValue )
1916 myMargin = theValue;
1919 void Comparator::SetNumFunctor( NumericalFunctorPtr theFunct )
1921 myFunctor = theFunct;
1924 SMDSAbs_ElementType Comparator::GetType() const
1926 return myFunctor ? myFunctor->GetType() : SMDSAbs_All;
1929 double Comparator::GetMargin()
1937 Description : Comparator "<"
1939 bool LessThan::IsSatisfy( long theId )
1941 return myFunctor && myFunctor->GetValue( theId ) < myMargin;
1947 Description : Comparator ">"
1949 bool MoreThan::IsSatisfy( long theId )
1951 return myFunctor && myFunctor->GetValue( theId ) > myMargin;
1957 Description : Comparator "="
1960 myToler(Precision::Confusion())
1963 bool EqualTo::IsSatisfy( long theId )
1965 return myFunctor && fabs( myFunctor->GetValue( theId ) - myMargin ) < myToler;
1968 void EqualTo::SetTolerance( double theToler )
1973 double EqualTo::GetTolerance()
1980 Description : Logical NOT predicate
1982 LogicalNOT::LogicalNOT()
1985 LogicalNOT::~LogicalNOT()
1988 bool LogicalNOT::IsSatisfy( long theId )
1990 return myPredicate && !myPredicate->IsSatisfy( theId );
1993 void LogicalNOT::SetMesh( const SMDS_Mesh* theMesh )
1996 myPredicate->SetMesh( theMesh );
1999 void LogicalNOT::SetPredicate( PredicatePtr thePred )
2001 myPredicate = thePred;
2004 SMDSAbs_ElementType LogicalNOT::GetType() const
2006 return myPredicate ? myPredicate->GetType() : SMDSAbs_All;
2011 Class : LogicalBinary
2012 Description : Base class for binary logical predicate
2014 LogicalBinary::LogicalBinary()
2017 LogicalBinary::~LogicalBinary()
2020 void LogicalBinary::SetMesh( const SMDS_Mesh* theMesh )
2023 myPredicate1->SetMesh( theMesh );
2026 myPredicate2->SetMesh( theMesh );
2029 void LogicalBinary::SetPredicate1( PredicatePtr thePredicate )
2031 myPredicate1 = thePredicate;
2034 void LogicalBinary::SetPredicate2( PredicatePtr thePredicate )
2036 myPredicate2 = thePredicate;
2039 SMDSAbs_ElementType LogicalBinary::GetType() const
2041 if ( !myPredicate1 || !myPredicate2 )
2044 SMDSAbs_ElementType aType1 = myPredicate1->GetType();
2045 SMDSAbs_ElementType aType2 = myPredicate2->GetType();
2047 return aType1 == aType2 ? aType1 : SMDSAbs_All;
2053 Description : Logical AND
2055 bool LogicalAND::IsSatisfy( long theId )
2060 myPredicate1->IsSatisfy( theId ) &&
2061 myPredicate2->IsSatisfy( theId );
2067 Description : Logical OR
2069 bool LogicalOR::IsSatisfy( long theId )
2074 myPredicate1->IsSatisfy( theId ) ||
2075 myPredicate2->IsSatisfy( theId );
2089 void Filter::SetPredicate( PredicatePtr thePredicate )
2091 myPredicate = thePredicate;
2094 template<class TElement, class TIterator, class TPredicate>
2095 inline void FillSequence(const TIterator& theIterator,
2096 TPredicate& thePredicate,
2097 Filter::TIdSequence& theSequence)
2099 if ( theIterator ) {
2100 while( theIterator->more() ) {
2101 TElement anElem = theIterator->next();
2102 long anId = anElem->GetID();
2103 if ( thePredicate->IsSatisfy( anId ) )
2104 theSequence.push_back( anId );
2111 GetElementsId( const SMDS_Mesh* theMesh,
2112 PredicatePtr thePredicate,
2113 TIdSequence& theSequence )
2115 theSequence.clear();
2117 if ( !theMesh || !thePredicate )
2120 thePredicate->SetMesh( theMesh );
2122 SMDSAbs_ElementType aType = thePredicate->GetType();
2125 FillSequence<const SMDS_MeshNode*>(theMesh->nodesIterator(),thePredicate,theSequence);
2128 FillSequence<const SMDS_MeshElement*>(theMesh->edgesIterator(),thePredicate,theSequence);
2131 FillSequence<const SMDS_MeshElement*>(theMesh->facesIterator(),thePredicate,theSequence);
2133 case SMDSAbs_Volume:
2134 FillSequence<const SMDS_MeshElement*>(theMesh->volumesIterator(),thePredicate,theSequence);
2137 FillSequence<const SMDS_MeshElement*>(theMesh->edgesIterator(),thePredicate,theSequence);
2138 FillSequence<const SMDS_MeshElement*>(theMesh->facesIterator(),thePredicate,theSequence);
2139 FillSequence<const SMDS_MeshElement*>(theMesh->volumesIterator(),thePredicate,theSequence);
2145 Filter::GetElementsId( const SMDS_Mesh* theMesh,
2146 Filter::TIdSequence& theSequence )
2148 GetElementsId(theMesh,myPredicate,theSequence);
2155 typedef std::set<SMDS_MeshFace*> TMapOfFacePtr;
2161 ManifoldPart::Link::Link( SMDS_MeshNode* theNode1,
2162 SMDS_MeshNode* theNode2 )
2168 ManifoldPart::Link::~Link()
2174 bool ManifoldPart::Link::IsEqual( const ManifoldPart::Link& theLink ) const
2176 if ( myNode1 == theLink.myNode1 &&
2177 myNode2 == theLink.myNode2 )
2179 else if ( myNode1 == theLink.myNode2 &&
2180 myNode2 == theLink.myNode1 )
2186 bool ManifoldPart::Link::operator<( const ManifoldPart::Link& x ) const
2188 if(myNode1 < x.myNode1) return true;
2189 if(myNode1 == x.myNode1)
2190 if(myNode2 < x.myNode2) return true;
2194 bool ManifoldPart::IsEqual( const ManifoldPart::Link& theLink1,
2195 const ManifoldPart::Link& theLink2 )
2197 return theLink1.IsEqual( theLink2 );
2200 ManifoldPart::ManifoldPart()
2203 myAngToler = Precision::Angular();
2204 myIsOnlyManifold = true;
2207 ManifoldPart::~ManifoldPart()
2212 void ManifoldPart::SetMesh( const SMDS_Mesh* theMesh )
2218 SMDSAbs_ElementType ManifoldPart::GetType() const
2219 { return SMDSAbs_Face; }
2221 bool ManifoldPart::IsSatisfy( long theElementId )
2223 return myMapIds.Contains( theElementId );
2226 void ManifoldPart::SetAngleTolerance( const double theAngToler )
2227 { myAngToler = theAngToler; }
2229 double ManifoldPart::GetAngleTolerance() const
2230 { return myAngToler; }
2232 void ManifoldPart::SetIsOnlyManifold( const bool theIsOnly )
2233 { myIsOnlyManifold = theIsOnly; }
2235 void ManifoldPart::SetStartElem( const long theStartId )
2236 { myStartElemId = theStartId; }
2238 bool ManifoldPart::process()
2241 myMapBadGeomIds.Clear();
2243 myAllFacePtr.clear();
2244 myAllFacePtrIntDMap.clear();
2248 // collect all faces into own map
2249 SMDS_FaceIteratorPtr anFaceItr = myMesh->facesIterator();
2250 for (; anFaceItr->more(); )
2252 SMDS_MeshFace* aFacePtr = (SMDS_MeshFace*)anFaceItr->next();
2253 myAllFacePtr.push_back( aFacePtr );
2254 myAllFacePtrIntDMap[aFacePtr] = myAllFacePtr.size()-1;
2257 SMDS_MeshFace* aStartFace = (SMDS_MeshFace*)myMesh->FindElement( myStartElemId );
2261 // the map of non manifold links and bad geometry
2262 TMapOfLink aMapOfNonManifold;
2263 TColStd_MapOfInteger aMapOfTreated;
2265 // begin cycle on faces from start index and run on vector till the end
2266 // and from begin to start index to cover whole vector
2267 const int aStartIndx = myAllFacePtrIntDMap[aStartFace];
2268 bool isStartTreat = false;
2269 for ( int fi = aStartIndx; !isStartTreat || fi != aStartIndx ; fi++ )
2271 if ( fi == aStartIndx )
2272 isStartTreat = true;
2273 // as result next time when fi will be equal to aStartIndx
2275 SMDS_MeshFace* aFacePtr = myAllFacePtr[ fi ];
2276 if ( aMapOfTreated.Contains( aFacePtr->GetID() ) )
2279 aMapOfTreated.Add( aFacePtr->GetID() );
2280 TColStd_MapOfInteger aResFaces;
2281 if ( !findConnected( myAllFacePtrIntDMap, aFacePtr,
2282 aMapOfNonManifold, aResFaces ) )
2284 TColStd_MapIteratorOfMapOfInteger anItr( aResFaces );
2285 for ( ; anItr.More(); anItr.Next() )
2287 int aFaceId = anItr.Key();
2288 aMapOfTreated.Add( aFaceId );
2289 myMapIds.Add( aFaceId );
2292 if ( fi == ( myAllFacePtr.size() - 1 ) )
2294 } // end run on vector of faces
2295 return !myMapIds.IsEmpty();
2298 static void getLinks( const SMDS_MeshFace* theFace,
2299 ManifoldPart::TVectorOfLink& theLinks )
2301 int aNbNode = theFace->NbNodes();
2302 SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
2304 SMDS_MeshNode* aNode = 0;
2305 for ( ; aNodeItr->more() && i <= aNbNode; )
2308 SMDS_MeshNode* aN1 = (SMDS_MeshNode*)aNodeItr->next();
2312 SMDS_MeshNode* aN2 = ( i >= aNbNode ) ? aNode : (SMDS_MeshNode*)aNodeItr->next();
2314 ManifoldPart::Link aLink( aN1, aN2 );
2315 theLinks.push_back( aLink );
2319 static gp_XYZ getNormale( const SMDS_MeshFace* theFace )
2322 int aNbNode = theFace->NbNodes();
2323 TColgp_Array1OfXYZ anArrOfXYZ(1,4);
2324 SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
2326 for ( ; aNodeItr->more() && i <= 4; i++ ) {
2327 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
2328 anArrOfXYZ.SetValue(i, gp_XYZ( aNode->X(), aNode->Y(), aNode->Z() ) );
2331 gp_XYZ q1 = anArrOfXYZ.Value(2) - anArrOfXYZ.Value(1);
2332 gp_XYZ q2 = anArrOfXYZ.Value(3) - anArrOfXYZ.Value(1);
2334 if ( aNbNode > 3 ) {
2335 gp_XYZ q3 = anArrOfXYZ.Value(4) - anArrOfXYZ.Value(1);
2338 double len = n.Modulus();
2345 bool ManifoldPart::findConnected
2346 ( const ManifoldPart::TDataMapFacePtrInt& theAllFacePtrInt,
2347 SMDS_MeshFace* theStartFace,
2348 ManifoldPart::TMapOfLink& theNonManifold,
2349 TColStd_MapOfInteger& theResFaces )
2351 theResFaces.Clear();
2352 if ( !theAllFacePtrInt.size() )
2355 if ( getNormale( theStartFace ).SquareModulus() <= gp::Resolution() )
2357 myMapBadGeomIds.Add( theStartFace->GetID() );
2361 ManifoldPart::TMapOfLink aMapOfBoundary, aMapToSkip;
2362 ManifoldPart::TVectorOfLink aSeqOfBoundary;
2363 theResFaces.Add( theStartFace->GetID() );
2364 ManifoldPart::TDataMapOfLinkFacePtr aDMapLinkFace;
2366 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
2367 aDMapLinkFace, theNonManifold, theStartFace );
2369 bool isDone = false;
2370 while ( !isDone && aMapOfBoundary.size() != 0 )
2372 bool isToReset = false;
2373 ManifoldPart::TVectorOfLink::iterator pLink = aSeqOfBoundary.begin();
2374 for ( ; !isToReset && pLink != aSeqOfBoundary.end(); ++pLink )
2376 ManifoldPart::Link aLink = *pLink;
2377 if ( aMapToSkip.find( aLink ) != aMapToSkip.end() )
2379 // each link could be treated only once
2380 aMapToSkip.insert( aLink );
2382 ManifoldPart::TVectorOfFacePtr aFaces;
2384 if ( myIsOnlyManifold &&
2385 (theNonManifold.find( aLink ) != theNonManifold.end()) )
2389 getFacesByLink( aLink, aFaces );
2390 // filter the element to keep only indicated elements
2391 ManifoldPart::TVectorOfFacePtr aFiltered;
2392 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
2393 for ( ; pFace != aFaces.end(); ++pFace )
2395 SMDS_MeshFace* aFace = *pFace;
2396 if ( myAllFacePtrIntDMap.find( aFace ) != myAllFacePtrIntDMap.end() )
2397 aFiltered.push_back( aFace );
2400 if ( aFaces.size() < 2 ) // no neihgbour faces
2402 else if ( myIsOnlyManifold && aFaces.size() > 2 ) // non manifold case
2404 theNonManifold.insert( aLink );
2409 // compare normal with normals of neighbor element
2410 SMDS_MeshFace* aPrevFace = aDMapLinkFace[ aLink ];
2411 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
2412 for ( ; pFace != aFaces.end(); ++pFace )
2414 SMDS_MeshFace* aNextFace = *pFace;
2415 if ( aPrevFace == aNextFace )
2417 int anNextFaceID = aNextFace->GetID();
2418 if ( myIsOnlyManifold && theResFaces.Contains( anNextFaceID ) )
2419 // should not be with non manifold restriction. probably bad topology
2421 // check if face was treated and skipped
2422 if ( myMapBadGeomIds.Contains( anNextFaceID ) ||
2423 !isInPlane( aPrevFace, aNextFace ) )
2425 // add new element to connected and extend the boundaries.
2426 theResFaces.Add( anNextFaceID );
2427 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
2428 aDMapLinkFace, theNonManifold, aNextFace );
2432 isDone = !isToReset;
2435 return !theResFaces.IsEmpty();
2438 bool ManifoldPart::isInPlane( const SMDS_MeshFace* theFace1,
2439 const SMDS_MeshFace* theFace2 )
2441 gp_Dir aNorm1 = gp_Dir( getNormale( theFace1 ) );
2442 gp_XYZ aNorm2XYZ = getNormale( theFace2 );
2443 if ( aNorm2XYZ.SquareModulus() <= gp::Resolution() )
2445 myMapBadGeomIds.Add( theFace2->GetID() );
2448 if ( aNorm1.IsParallel( gp_Dir( aNorm2XYZ ), myAngToler ) )
2454 void ManifoldPart::expandBoundary
2455 ( ManifoldPart::TMapOfLink& theMapOfBoundary,
2456 ManifoldPart::TVectorOfLink& theSeqOfBoundary,
2457 ManifoldPart::TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
2458 ManifoldPart::TMapOfLink& theNonManifold,
2459 SMDS_MeshFace* theNextFace ) const
2461 ManifoldPart::TVectorOfLink aLinks;
2462 getLinks( theNextFace, aLinks );
2463 int aNbLink = (int)aLinks.size();
2464 for ( int i = 0; i < aNbLink; i++ )
2466 ManifoldPart::Link aLink = aLinks[ i ];
2467 if ( myIsOnlyManifold && (theNonManifold.find( aLink ) != theNonManifold.end()) )
2469 if ( theMapOfBoundary.find( aLink ) != theMapOfBoundary.end() )
2471 if ( myIsOnlyManifold )
2473 // remove from boundary
2474 theMapOfBoundary.erase( aLink );
2475 ManifoldPart::TVectorOfLink::iterator pLink = theSeqOfBoundary.begin();
2476 for ( ; pLink != theSeqOfBoundary.end(); ++pLink )
2478 ManifoldPart::Link aBoundLink = *pLink;
2479 if ( aBoundLink.IsEqual( aLink ) )
2481 theSeqOfBoundary.erase( pLink );
2489 theMapOfBoundary.insert( aLink );
2490 theSeqOfBoundary.push_back( aLink );
2491 theDMapLinkFacePtr[ aLink ] = theNextFace;
2496 void ManifoldPart::getFacesByLink( const ManifoldPart::Link& theLink,
2497 ManifoldPart::TVectorOfFacePtr& theFaces ) const
2499 SMDS_Mesh::SetOfFaces aSetOfFaces;
2500 // take all faces that shared first node
2501 SMDS_ElemIteratorPtr anItr = theLink.myNode1->facesIterator();
2502 for ( ; anItr->more(); )
2504 SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
2507 aSetOfFaces.Add( aFace );
2509 // take all faces that shared second node
2510 anItr = theLink.myNode2->facesIterator();
2511 // find the common part of two sets
2512 for ( ; anItr->more(); )
2514 SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
2515 if ( aSetOfFaces.Contains( aFace ) )
2516 theFaces.push_back( aFace );
2525 ElementsOnSurface::ElementsOnSurface()
2529 myType = SMDSAbs_All;
2531 myToler = Precision::Confusion();
2532 myUseBoundaries = false;
2535 ElementsOnSurface::~ElementsOnSurface()
2540 void ElementsOnSurface::SetMesh( const SMDS_Mesh* theMesh )
2542 if ( myMesh == theMesh )
2548 bool ElementsOnSurface::IsSatisfy( long theElementId )
2550 return myIds.Contains( theElementId );
2553 SMDSAbs_ElementType ElementsOnSurface::GetType() const
2556 void ElementsOnSurface::SetTolerance( const double theToler )
2558 if ( myToler != theToler )
2563 double ElementsOnSurface::GetTolerance() const
2566 void ElementsOnSurface::SetUseBoundaries( bool theUse )
2568 if ( myUseBoundaries != theUse ) {
2569 myUseBoundaries = theUse;
2570 SetSurface( mySurf, myType );
2574 void ElementsOnSurface::SetSurface( const TopoDS_Shape& theShape,
2575 const SMDSAbs_ElementType theType )
2580 if ( theShape.IsNull() || theShape.ShapeType() != TopAbs_FACE )
2582 mySurf = TopoDS::Face( theShape );
2583 BRepAdaptor_Surface SA( mySurf, myUseBoundaries );
2585 u1 = SA.FirstUParameter(),
2586 u2 = SA.LastUParameter(),
2587 v1 = SA.FirstVParameter(),
2588 v2 = SA.LastVParameter();
2589 Handle(Geom_Surface) surf = BRep_Tool::Surface( mySurf );
2590 myProjector.Init( surf, u1,u2, v1,v2 );
2594 void ElementsOnSurface::process()
2597 if ( mySurf.IsNull() )
2603 if ( myType == SMDSAbs_Face || myType == SMDSAbs_All )
2605 myIds.ReSize( myMesh->NbFaces() );
2606 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
2607 for(; anIter->more(); )
2608 process( anIter->next() );
2611 if ( myType == SMDSAbs_Edge || myType == SMDSAbs_All )
2613 myIds.ReSize( myMesh->NbEdges() );
2614 SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
2615 for(; anIter->more(); )
2616 process( anIter->next() );
2619 if ( myType == SMDSAbs_Node )
2621 myIds.ReSize( myMesh->NbNodes() );
2622 SMDS_NodeIteratorPtr anIter = myMesh->nodesIterator();
2623 for(; anIter->more(); )
2624 process( anIter->next() );
2628 void ElementsOnSurface::process( const SMDS_MeshElement* theElemPtr )
2630 SMDS_ElemIteratorPtr aNodeItr = theElemPtr->nodesIterator();
2631 bool isSatisfy = true;
2632 for ( ; aNodeItr->more(); )
2634 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
2635 if ( !isOnSurface( aNode ) )
2642 myIds.Add( theElemPtr->GetID() );
2645 bool ElementsOnSurface::isOnSurface( const SMDS_MeshNode* theNode )
2647 if ( mySurf.IsNull() )
2650 gp_Pnt aPnt( theNode->X(), theNode->Y(), theNode->Z() );
2651 // double aToler2 = myToler * myToler;
2652 // if ( mySurf->IsKind(STANDARD_TYPE(Geom_Plane)))
2654 // gp_Pln aPln = Handle(Geom_Plane)::DownCast(mySurf)->Pln();
2655 // if ( aPln.SquareDistance( aPnt ) > aToler2 )
2658 // else if ( mySurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)))
2660 // gp_Cylinder aCyl = Handle(Geom_CylindricalSurface)::DownCast(mySurf)->Cylinder();
2661 // double aRad = aCyl.Radius();
2662 // gp_Ax3 anAxis = aCyl.Position();
2663 // gp_XYZ aLoc = aCyl.Location().XYZ();
2664 // double aXDist = anAxis.XDirection().XYZ() * ( aPnt.XYZ() - aLoc );
2665 // double aYDist = anAxis.YDirection().XYZ() * ( aPnt.XYZ() - aLoc );
2666 // if ( fabs(aXDist*aXDist + aYDist*aYDist - aRad*aRad) > aToler2 )
2671 myProjector.Perform( aPnt );
2672 bool isOn = ( myProjector.IsDone() && myProjector.LowerDistance() <= myToler );