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 <BRepClass_FaceClassifier.hxx>
28 #include <BRep_Tool.hxx>
32 #include <TopoDS_Edge.hxx>
33 #include <TopoDS_Face.hxx>
34 #include <TopoDS_Shape.hxx>
35 #include <TopoDS_Vertex.hxx>
36 #include <TopoDS_Iterator.hxx>
38 #include <Geom_CylindricalSurface.hxx>
39 #include <Geom_Plane.hxx>
40 #include <Geom_Surface.hxx>
42 #include <Precision.hxx>
43 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
44 #include <TColStd_MapOfInteger.hxx>
45 #include <TColStd_SequenceOfAsciiString.hxx>
46 #include <TColgp_Array1OfXYZ.hxx>
49 #include <gp_Cylinder.hxx>
56 #include "SMDS_Mesh.hxx"
57 #include "SMDS_Iterator.hxx"
58 #include "SMDS_MeshElement.hxx"
59 #include "SMDS_MeshNode.hxx"
60 #include "SMDS_VolumeTool.hxx"
61 #include "SMDS_QuadraticFaceOfNodes.hxx"
62 #include "SMDS_QuadraticEdge.hxx"
69 inline double getAngle( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
71 gp_Vec v1( P1 - P2 ), v2( P3 - P2 );
73 return v1.Magnitude() < gp::Resolution() ||
74 v2.Magnitude() < gp::Resolution() ? 0 : v1.Angle( v2 );
77 inline double getArea( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
79 gp_Vec aVec1( P2 - P1 );
80 gp_Vec aVec2( P3 - P1 );
81 return ( aVec1 ^ aVec2 ).Magnitude() * 0.5;
84 inline double getArea( const gp_Pnt& P1, const gp_Pnt& P2, const gp_Pnt& P3 )
86 return getArea( P1.XYZ(), P2.XYZ(), P3.XYZ() );
91 inline double getDistance( const gp_XYZ& P1, const gp_XYZ& P2 )
93 double aDist = gp_Pnt( P1 ).Distance( gp_Pnt( P2 ) );
97 int getNbMultiConnection( const SMDS_Mesh* theMesh, const int theId )
102 const SMDS_MeshElement* anEdge = theMesh->FindElement( theId );
103 if ( anEdge == 0 || anEdge->GetType() != SMDSAbs_Edge/* || anEdge->NbNodes() != 2 */)
106 // for each pair of nodes in anEdge (there are 2 pairs in a quadratic edge)
107 // count elements containing both nodes of the pair.
108 // Note that there may be such cases for a quadratic edge (a horizontal line):
113 // +-----+------+ +-----+------+
116 // result sould be 2 in both cases
118 int aResult0 = 0, aResult1 = 0;
119 // last node, it is a medium one in a quadratic edge
120 const SMDS_MeshNode* aLastNode = anEdge->GetNode( anEdge->NbNodes() - 1 );
121 const SMDS_MeshNode* aNode0 = anEdge->GetNode( 0 );
122 const SMDS_MeshNode* aNode1 = anEdge->GetNode( 1 );
123 if ( aNode1 == aLastNode ) aNode1 = 0;
125 SMDS_ElemIteratorPtr anElemIter = aLastNode->GetInverseElementIterator();
126 while( anElemIter->more() ) {
127 const SMDS_MeshElement* anElem = anElemIter->next();
128 if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) {
129 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
130 while ( anIter->more() ) {
131 if ( const SMDS_MeshElement* anElemNode = anIter->next() ) {
132 if ( anElemNode == aNode0 ) {
134 if ( !aNode1 ) break; // not a quadratic edge
136 else if ( anElemNode == aNode1 )
142 int aResult = std::max ( aResult0, aResult1 );
144 // TColStd_MapOfInteger aMap;
146 // SMDS_ElemIteratorPtr anIter = anEdge->nodesIterator();
147 // if ( anIter != 0 ) {
148 // while( anIter->more() ) {
149 // const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next();
152 // SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator();
153 // while( anElemIter->more() ) {
154 // const SMDS_MeshElement* anElem = anElemIter->next();
155 // if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) {
156 // int anId = anElem->GetID();
158 // if ( anIter->more() ) // i.e. first node
160 // else if ( aMap.Contains( anId ) )
174 using namespace SMESH::Controls;
181 Class : NumericalFunctor
182 Description : Base class for numerical functors
184 NumericalFunctor::NumericalFunctor():
190 void NumericalFunctor::SetMesh( const SMDS_Mesh* theMesh )
195 bool NumericalFunctor::GetPoints(const int theId,
196 TSequenceOfXYZ& theRes ) const
203 return GetPoints( myMesh->FindElement( theId ), theRes );
206 bool NumericalFunctor::GetPoints(const SMDS_MeshElement* anElem,
207 TSequenceOfXYZ& theRes )
214 theRes.reserve( anElem->NbNodes() );
216 // Get nodes of the element
217 SMDS_ElemIteratorPtr anIter;
219 if ( anElem->IsQuadratic() ) {
220 switch ( anElem->GetType() ) {
222 anIter = static_cast<const SMDS_QuadraticEdge*>
223 (anElem)->interlacedNodesElemIterator();
226 anIter = static_cast<const SMDS_QuadraticFaceOfNodes*>
227 (anElem)->interlacedNodesElemIterator();
230 anIter = anElem->nodesIterator();
235 anIter = anElem->nodesIterator();
239 while( anIter->more() ) {
240 if ( const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>( anIter->next() ))
241 theRes.push_back( gp_XYZ( aNode->X(), aNode->Y(), aNode->Z() ) );
248 long NumericalFunctor::GetPrecision() const
253 void NumericalFunctor::SetPrecision( const long thePrecision )
255 myPrecision = thePrecision;
258 double NumericalFunctor::GetValue( long theId )
260 myCurrElement = myMesh->FindElement( theId );
262 if ( GetPoints( theId, P ))
264 double aVal = GetValue( P );
265 if ( myPrecision >= 0 )
267 double prec = pow( 10., (double)( myPrecision ) );
268 aVal = floor( aVal * prec + 0.5 ) / prec;
276 //=======================================================================
277 //function : GetValue
279 //=======================================================================
281 double Volume::GetValue( long theElementId )
283 if ( theElementId && myMesh ) {
284 SMDS_VolumeTool aVolumeTool;
285 if ( aVolumeTool.Set( myMesh->FindElement( theElementId )))
286 return aVolumeTool.GetSize();
291 //=======================================================================
292 //function : GetBadRate
293 //purpose : meaningless as it is not quality control functor
294 //=======================================================================
296 double Volume::GetBadRate( double Value, int /*nbNodes*/ ) const
301 //=======================================================================
304 //=======================================================================
306 SMDSAbs_ElementType Volume::GetType() const
308 return SMDSAbs_Volume;
314 Description : Functor for calculation of minimum angle
317 double MinimumAngle::GetValue( const TSequenceOfXYZ& P )
324 aMin = getAngle(P( P.size() ), P( 1 ), P( 2 ));
325 aMin = Min(aMin,getAngle(P( P.size()-1 ), P( P.size() ), P( 1 )));
327 for (int i=2; i<P.size();i++){
328 double A0 = getAngle( P( i-1 ), P( i ), P( i+1 ) );
332 return aMin * 180.0 / PI;
335 double MinimumAngle::GetBadRate( double Value, int nbNodes ) const
337 //const double aBestAngle = PI / nbNodes;
338 const double aBestAngle = 180.0 - ( 360.0 / double(nbNodes) );
339 return ( fabs( aBestAngle - Value ));
342 SMDSAbs_ElementType MinimumAngle::GetType() const
350 Description : Functor for calculating aspect ratio
352 double AspectRatio::GetValue( const TSequenceOfXYZ& P )
354 // According to "Mesh quality control" by Nadir Bouhamau referring to
355 // Pascal Jean Frey and Paul-Louis George. Maillages, applications aux elements finis.
356 // Hermes Science publications, Paris 1999 ISBN 2-7462-0024-4
359 int nbNodes = P.size();
364 // Compute aspect ratio
366 if ( nbNodes == 3 ) {
367 // Compute lengths of the sides
368 std::vector< double > aLen (nbNodes);
369 for ( int i = 0; i < nbNodes - 1; i++ )
370 aLen[ i ] = getDistance( P( i + 1 ), P( i + 2 ) );
371 aLen[ nbNodes - 1 ] = getDistance( P( 1 ), P( nbNodes ) );
372 // Q = alfa * h * p / S, where
374 // alfa = sqrt( 3 ) / 6
375 // h - length of the longest edge
376 // p - half perimeter
377 // S - triangle surface
378 const double alfa = sqrt( 3. ) / 6.;
379 double maxLen = Max( aLen[ 0 ], Max( aLen[ 1 ], aLen[ 2 ] ) );
380 double half_perimeter = ( aLen[0] + aLen[1] + aLen[2] ) / 2.;
381 double anArea = getArea( P( 1 ), P( 2 ), P( 3 ) );
382 if ( anArea <= Precision::Confusion() )
384 return alfa * maxLen * half_perimeter / anArea;
386 else if ( nbNodes == 6 ) { // quadratic triangles
387 // Compute lengths of the sides
388 std::vector< double > aLen (3);
389 aLen[0] = getDistance( P(1), P(3) );
390 aLen[1] = getDistance( P(3), P(5) );
391 aLen[2] = getDistance( P(5), P(1) );
392 // Q = alfa * h * p / S, where
394 // alfa = sqrt( 3 ) / 6
395 // h - length of the longest edge
396 // p - half perimeter
397 // S - triangle surface
398 const double alfa = sqrt( 3. ) / 6.;
399 double maxLen = Max( aLen[ 0 ], Max( aLen[ 1 ], aLen[ 2 ] ) );
400 double half_perimeter = ( aLen[0] + aLen[1] + aLen[2] ) / 2.;
401 double anArea = getArea( P(1), P(3), P(5) );
402 if ( anArea <= Precision::Confusion() )
404 return alfa * maxLen * half_perimeter / anArea;
406 else if( nbNodes == 4 ) { // quadrangle
407 // return aspect ratio of the worst triange which can be built
408 // taking three nodes of the quadrangle
409 TSequenceOfXYZ triaPnts(3);
410 // triangle on nodes 1 3 2
414 double ar = GetValue( triaPnts );
415 // triangle on nodes 1 3 4
417 ar = Max ( ar, GetValue( triaPnts ));
418 // triangle on nodes 1 2 4
420 ar = Max ( ar, GetValue( triaPnts ));
421 // triangle on nodes 3 2 4
423 ar = Max ( ar, GetValue( triaPnts ));
427 else { // nbNodes==8 - quadratic quadrangle
428 // return aspect ratio of the worst triange which can be built
429 // taking three nodes of the quadrangle
430 TSequenceOfXYZ triaPnts(3);
431 // triangle on nodes 1 3 2
435 double ar = GetValue( triaPnts );
436 // triangle on nodes 1 3 4
438 ar = Max ( ar, GetValue( triaPnts ));
439 // triangle on nodes 1 2 4
441 ar = Max ( ar, GetValue( triaPnts ));
442 // triangle on nodes 3 2 4
444 ar = Max ( ar, GetValue( triaPnts ));
450 double AspectRatio::GetBadRate( double Value, int /*nbNodes*/ ) const
452 // the aspect ratio is in the range [1.0,infinity]
455 return Value / 1000.;
458 SMDSAbs_ElementType AspectRatio::GetType() const
465 Class : AspectRatio3D
466 Description : Functor for calculating aspect ratio
470 inline double getHalfPerimeter(double theTria[3]){
471 return (theTria[0] + theTria[1] + theTria[2])/2.0;
474 inline double getArea(double theHalfPerim, double theTria[3]){
475 return sqrt(theHalfPerim*
476 (theHalfPerim-theTria[0])*
477 (theHalfPerim-theTria[1])*
478 (theHalfPerim-theTria[2]));
481 inline double getVolume(double theLen[6]){
482 double a2 = theLen[0]*theLen[0];
483 double b2 = theLen[1]*theLen[1];
484 double c2 = theLen[2]*theLen[2];
485 double d2 = theLen[3]*theLen[3];
486 double e2 = theLen[4]*theLen[4];
487 double f2 = theLen[5]*theLen[5];
488 double P = 4.0*a2*b2*d2;
489 double Q = a2*(b2+d2-e2)-b2*(a2+d2-f2)-d2*(a2+b2-c2);
490 double R = (b2+d2-e2)*(a2+d2-f2)*(a2+d2-f2);
491 return sqrt(P-Q+R)/12.0;
494 inline double getVolume2(double theLen[6]){
495 double a2 = theLen[0]*theLen[0];
496 double b2 = theLen[1]*theLen[1];
497 double c2 = theLen[2]*theLen[2];
498 double d2 = theLen[3]*theLen[3];
499 double e2 = theLen[4]*theLen[4];
500 double f2 = theLen[5]*theLen[5];
502 double P = a2*e2*(b2+c2+d2+f2-a2-e2);
503 double Q = b2*f2*(a2+c2+d2+e2-b2-f2);
504 double R = c2*d2*(a2+b2+e2+f2-c2-d2);
505 double S = a2*b2*d2+b2*c2*e2+a2*c2*f2+d2*e2*f2;
507 return sqrt(P+Q+R-S)/12.0;
510 inline double getVolume(const TSequenceOfXYZ& P){
511 gp_Vec aVec1( P( 2 ) - P( 1 ) );
512 gp_Vec aVec2( P( 3 ) - P( 1 ) );
513 gp_Vec aVec3( P( 4 ) - P( 1 ) );
514 gp_Vec anAreaVec( aVec1 ^ aVec2 );
515 return fabs(aVec3 * anAreaVec) / 6.0;
518 inline double getMaxHeight(double theLen[6])
520 double aHeight = std::max(theLen[0],theLen[1]);
521 aHeight = std::max(aHeight,theLen[2]);
522 aHeight = std::max(aHeight,theLen[3]);
523 aHeight = std::max(aHeight,theLen[4]);
524 aHeight = std::max(aHeight,theLen[5]);
530 double AspectRatio3D::GetValue( const TSequenceOfXYZ& P )
532 double aQuality = 0.0;
533 if(myCurrElement->IsPoly()) return aQuality;
535 int nbNodes = P.size();
537 if(myCurrElement->IsQuadratic()) {
538 if(nbNodes==10) nbNodes=4; // quadratic tetrahedron
539 else if(nbNodes==13) nbNodes=5; // quadratic pyramid
540 else if(nbNodes==15) nbNodes=6; // quadratic pentahedron
541 else if(nbNodes==20) nbNodes=8; // quadratic hexahedron
542 else return aQuality;
548 getDistance(P( 1 ),P( 2 )), // a
549 getDistance(P( 2 ),P( 3 )), // b
550 getDistance(P( 3 ),P( 1 )), // c
551 getDistance(P( 2 ),P( 4 )), // d
552 getDistance(P( 3 ),P( 4 )), // e
553 getDistance(P( 1 ),P( 4 )) // f
555 double aTria[4][3] = {
556 {aLen[0],aLen[1],aLen[2]}, // abc
557 {aLen[0],aLen[3],aLen[5]}, // adf
558 {aLen[1],aLen[3],aLen[4]}, // bde
559 {aLen[2],aLen[4],aLen[5]} // cef
561 double aSumArea = 0.0;
562 double aHalfPerimeter = getHalfPerimeter(aTria[0]);
563 double anArea = getArea(aHalfPerimeter,aTria[0]);
565 aHalfPerimeter = getHalfPerimeter(aTria[1]);
566 anArea = getArea(aHalfPerimeter,aTria[1]);
568 aHalfPerimeter = getHalfPerimeter(aTria[2]);
569 anArea = getArea(aHalfPerimeter,aTria[2]);
571 aHalfPerimeter = getHalfPerimeter(aTria[3]);
572 anArea = getArea(aHalfPerimeter,aTria[3]);
574 double aVolume = getVolume(P);
575 //double aVolume = getVolume(aLen);
576 double aHeight = getMaxHeight(aLen);
577 static double aCoeff = sqrt(2.0)/12.0;
578 if ( aVolume > DBL_MIN )
579 aQuality = aCoeff*aHeight*aSumArea/aVolume;
584 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 3 ),P( 5 )};
585 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
588 gp_XYZ aXYZ[4] = {P( 1 ),P( 3 ),P( 4 ),P( 5 )};
589 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
592 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 5 )};
593 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
596 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 4 ),P( 5 )};
597 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
603 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 6 )};
604 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
607 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 3 )};
608 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
611 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 6 )};
612 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
615 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
616 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
619 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 6 )};
620 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
623 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 3 )};
624 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
630 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
631 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
634 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 4 )};
635 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
638 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 7 )};
639 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
642 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 8 )};
643 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
646 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 3 )};
647 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
650 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 4 )};
651 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
654 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 7 )};
655 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
658 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 8 )};
659 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
662 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 3 )};
663 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
666 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 4 )};
667 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
670 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 7 )};
671 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
674 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 8 )};
675 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
678 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 1 )};
679 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
682 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 2 )};
683 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
686 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 5 )};
687 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
690 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 6 )};
691 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
694 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 1 )};
695 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
698 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 2 )};
699 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
702 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 5 )};
703 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
706 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 6 )};
707 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
710 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 1 )};
711 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
714 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
715 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
718 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 5 )};
719 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
722 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 6 )};
723 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
726 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
727 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
730 gp_XYZ aXYZ[4] = {P( 4 ),P( 5 ),P( 8 ),P( 2 )};
731 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
734 gp_XYZ aXYZ[4] = {P( 1 ),P( 4 ),P( 5 ),P( 3 )};
735 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
738 gp_XYZ aXYZ[4] = {P( 3 ),P( 6 ),P( 7 ),P( 1 )};
739 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
742 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 6 ),P( 4 )};
743 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
746 gp_XYZ aXYZ[4] = {P( 5 ),P( 6 ),P( 8 ),P( 3 )};
747 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
750 gp_XYZ aXYZ[4] = {P( 7 ),P( 8 ),P( 6 ),P( 1 )};
751 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
754 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 7 )};
755 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
758 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 2 ),P( 5 )};
759 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
765 // avaluate aspect ratio of quadranle faces
766 AspectRatio aspect2D;
767 SMDS_VolumeTool::VolumeType type = SMDS_VolumeTool::GetType( nbNodes );
768 int nbFaces = SMDS_VolumeTool::NbFaces( type );
769 TSequenceOfXYZ points(4);
770 for ( int i = 0; i < nbFaces; ++i ) { // loop on faces of a volume
771 if ( SMDS_VolumeTool::NbFaceNodes( type, i ) != 4 )
773 const int* pInd = SMDS_VolumeTool::GetFaceNodesIndices( type, i, true );
774 for ( int p = 0; p < 4; ++p ) // loop on nodes of a quadranle face
775 points( p + 1 ) = P( pInd[ p ] + 1 );
776 aQuality = std::max( aQuality, aspect2D.GetValue( points ));
782 double AspectRatio3D::GetBadRate( double Value, int /*nbNodes*/ ) const
784 // the aspect ratio is in the range [1.0,infinity]
787 return Value / 1000.;
790 SMDSAbs_ElementType AspectRatio3D::GetType() const
792 return SMDSAbs_Volume;
798 Description : Functor for calculating warping
800 double Warping::GetValue( const TSequenceOfXYZ& P )
805 gp_XYZ G = ( P( 1 ) + P( 2 ) + P( 3 ) + P( 4 ) ) / 4.;
807 double A1 = ComputeA( P( 1 ), P( 2 ), P( 3 ), G );
808 double A2 = ComputeA( P( 2 ), P( 3 ), P( 4 ), G );
809 double A3 = ComputeA( P( 3 ), P( 4 ), P( 1 ), G );
810 double A4 = ComputeA( P( 4 ), P( 1 ), P( 2 ), G );
812 return Max( Max( A1, A2 ), Max( A3, A4 ) );
815 double Warping::ComputeA( const gp_XYZ& thePnt1,
816 const gp_XYZ& thePnt2,
817 const gp_XYZ& thePnt3,
818 const gp_XYZ& theG ) const
820 double aLen1 = gp_Pnt( thePnt1 ).Distance( gp_Pnt( thePnt2 ) );
821 double aLen2 = gp_Pnt( thePnt2 ).Distance( gp_Pnt( thePnt3 ) );
822 double L = Min( aLen1, aLen2 ) * 0.5;
823 if ( L < Precision::Confusion())
826 gp_XYZ GI = ( thePnt2 + thePnt1 ) / 2. - theG;
827 gp_XYZ GJ = ( thePnt3 + thePnt2 ) / 2. - theG;
828 gp_XYZ N = GI.Crossed( GJ );
830 if ( N.Modulus() < gp::Resolution() )
835 double H = ( thePnt2 - theG ).Dot( N );
836 return asin( fabs( H / L ) ) * 180. / PI;
839 double Warping::GetBadRate( double Value, int /*nbNodes*/ ) const
841 // the warp is in the range [0.0,PI/2]
842 // 0.0 = good (no warp)
843 // PI/2 = bad (face pliee)
847 SMDSAbs_ElementType Warping::GetType() const
855 Description : Functor for calculating taper
857 double Taper::GetValue( const TSequenceOfXYZ& P )
863 double J1 = getArea( P( 4 ), P( 1 ), P( 2 ) ) / 2.;
864 double J2 = getArea( P( 3 ), P( 1 ), P( 2 ) ) / 2.;
865 double J3 = getArea( P( 2 ), P( 3 ), P( 4 ) ) / 2.;
866 double J4 = getArea( P( 3 ), P( 4 ), P( 1 ) ) / 2.;
868 double JA = 0.25 * ( J1 + J2 + J3 + J4 );
869 if ( JA <= Precision::Confusion() )
872 double T1 = fabs( ( J1 - JA ) / JA );
873 double T2 = fabs( ( J2 - JA ) / JA );
874 double T3 = fabs( ( J3 - JA ) / JA );
875 double T4 = fabs( ( J4 - JA ) / JA );
877 return Max( Max( T1, T2 ), Max( T3, T4 ) );
880 double Taper::GetBadRate( double Value, int /*nbNodes*/ ) const
882 // the taper is in the range [0.0,1.0]
883 // 0.0 = good (no taper)
884 // 1.0 = bad (les cotes opposes sont allignes)
888 SMDSAbs_ElementType Taper::GetType() const
896 Description : Functor for calculating skew in degrees
898 static inline double skewAngle( const gp_XYZ& p1, const gp_XYZ& p2, const gp_XYZ& p3 )
900 gp_XYZ p12 = ( p2 + p1 ) / 2.;
901 gp_XYZ p23 = ( p3 + p2 ) / 2.;
902 gp_XYZ p31 = ( p3 + p1 ) / 2.;
904 gp_Vec v1( p31 - p2 ), v2( p12 - p23 );
906 return v1.Magnitude() < gp::Resolution() || v2.Magnitude() < gp::Resolution() ? 0. : v1.Angle( v2 );
909 double Skew::GetValue( const TSequenceOfXYZ& P )
911 if ( P.size() != 3 && P.size() != 4 )
915 static double PI2 = PI / 2.;
918 double A0 = fabs( PI2 - skewAngle( P( 3 ), P( 1 ), P( 2 ) ) );
919 double A1 = fabs( PI2 - skewAngle( P( 1 ), P( 2 ), P( 3 ) ) );
920 double A2 = fabs( PI2 - skewAngle( P( 2 ), P( 3 ), P( 1 ) ) );
922 return Max( A0, Max( A1, A2 ) ) * 180. / PI;
926 gp_XYZ p12 = ( P( 1 ) + P( 2 ) ) / 2.;
927 gp_XYZ p23 = ( P( 2 ) + P( 3 ) ) / 2.;
928 gp_XYZ p34 = ( P( 3 ) + P( 4 ) ) / 2.;
929 gp_XYZ p41 = ( P( 4 ) + P( 1 ) ) / 2.;
931 gp_Vec v1( p34 - p12 ), v2( p23 - p41 );
932 double A = v1.Magnitude() <= gp::Resolution() || v2.Magnitude() <= gp::Resolution()
933 ? 0. : fabs( PI2 - v1.Angle( v2 ) );
936 if ( A < Precision::Angular() )
939 return A * 180. / PI;
943 double Skew::GetBadRate( double Value, int /*nbNodes*/ ) const
945 // the skew is in the range [0.0,PI/2].
951 SMDSAbs_ElementType Skew::GetType() const
959 Description : Functor for calculating area
961 double Area::GetValue( const TSequenceOfXYZ& P )
963 gp_Vec aVec1( P(2) - P(1) );
964 gp_Vec aVec2( P(3) - P(1) );
965 gp_Vec SumVec = aVec1 ^ aVec2;
966 for (int i=4; i<=P.size(); i++) {
967 gp_Vec aVec1( P(i-1) - P(1) );
968 gp_Vec aVec2( P(i) - P(1) );
969 gp_Vec tmp = aVec1 ^ aVec2;
972 return SumVec.Magnitude() * 0.5;
975 double Area::GetBadRate( double Value, int /*nbNodes*/ ) const
977 // meaningless as it is not a quality control functor
981 SMDSAbs_ElementType Area::GetType() const
989 Description : Functor for calculating length off edge
991 double Length::GetValue( const TSequenceOfXYZ& P )
993 switch ( P.size() ) {
994 case 2: return getDistance( P( 1 ), P( 2 ) );
995 case 3: return getDistance( P( 1 ), P( 2 ) ) + getDistance( P( 2 ), P( 3 ) );
1000 double Length::GetBadRate( double Value, int /*nbNodes*/ ) const
1002 // meaningless as it is not quality control functor
1006 SMDSAbs_ElementType Length::GetType() const
1008 return SMDSAbs_Edge;
1013 Description : Functor for calculating length of edge
1016 double Length2D::GetValue( long theElementId)
1020 //cout<<"Length2D::GetValue"<<endl;
1021 if (GetPoints(theElementId,P)){
1022 //for(int jj=1; jj<=P.size(); jj++)
1023 // cout<<"jj="<<jj<<" P("<<P(jj).X()<<","<<P(jj).Y()<<","<<P(jj).Z()<<")"<<endl;
1025 double aVal;// = GetValue( P );
1026 const SMDS_MeshElement* aElem = myMesh->FindElement( theElementId );
1027 SMDSAbs_ElementType aType = aElem->GetType();
1036 aVal = getDistance( P( 1 ), P( 2 ) );
1039 else if (len == 3){ // quadratic edge
1040 aVal = getDistance(P( 1 ),P( 3 )) + getDistance(P( 3 ),P( 2 ));
1044 if (len == 3){ // triangles
1045 double L1 = getDistance(P( 1 ),P( 2 ));
1046 double L2 = getDistance(P( 2 ),P( 3 ));
1047 double L3 = getDistance(P( 3 ),P( 1 ));
1048 aVal = Max(L1,Max(L2,L3));
1051 else if (len == 4){ // quadrangles
1052 double L1 = getDistance(P( 1 ),P( 2 ));
1053 double L2 = getDistance(P( 2 ),P( 3 ));
1054 double L3 = getDistance(P( 3 ),P( 4 ));
1055 double L4 = getDistance(P( 4 ),P( 1 ));
1056 aVal = Max(Max(L1,L2),Max(L3,L4));
1059 if (len == 6){ // quadratic triangles
1060 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1061 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1062 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 1 ));
1063 aVal = Max(L1,Max(L2,L3));
1064 //cout<<"L1="<<L1<<" L2="<<L2<<"L3="<<L3<<" aVal="<<aVal<<endl;
1067 else if (len == 8){ // quadratic quadrangles
1068 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1069 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1070 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 7 ));
1071 double L4 = getDistance(P( 7 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
1072 aVal = Max(Max(L1,L2),Max(L3,L4));
1075 case SMDSAbs_Volume:
1076 if (len == 4){ // tetraidrs
1077 double L1 = getDistance(P( 1 ),P( 2 ));
1078 double L2 = getDistance(P( 2 ),P( 3 ));
1079 double L3 = getDistance(P( 3 ),P( 1 ));
1080 double L4 = getDistance(P( 1 ),P( 4 ));
1081 double L5 = getDistance(P( 2 ),P( 4 ));
1082 double L6 = getDistance(P( 3 ),P( 4 ));
1083 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1086 else if (len == 5){ // piramids
1087 double L1 = getDistance(P( 1 ),P( 2 ));
1088 double L2 = getDistance(P( 2 ),P( 3 ));
1089 double L3 = getDistance(P( 3 ),P( 1 ));
1090 double L4 = getDistance(P( 4 ),P( 1 ));
1091 double L5 = getDistance(P( 1 ),P( 5 ));
1092 double L6 = getDistance(P( 2 ),P( 5 ));
1093 double L7 = getDistance(P( 3 ),P( 5 ));
1094 double L8 = getDistance(P( 4 ),P( 5 ));
1096 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1097 aVal = Max(aVal,Max(L7,L8));
1100 else if (len == 6){ // pentaidres
1101 double L1 = getDistance(P( 1 ),P( 2 ));
1102 double L2 = getDistance(P( 2 ),P( 3 ));
1103 double L3 = getDistance(P( 3 ),P( 1 ));
1104 double L4 = getDistance(P( 4 ),P( 5 ));
1105 double L5 = getDistance(P( 5 ),P( 6 ));
1106 double L6 = getDistance(P( 6 ),P( 4 ));
1107 double L7 = getDistance(P( 1 ),P( 4 ));
1108 double L8 = getDistance(P( 2 ),P( 5 ));
1109 double L9 = getDistance(P( 3 ),P( 6 ));
1111 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1112 aVal = Max(aVal,Max(Max(L7,L8),L9));
1115 else if (len == 8){ // hexaider
1116 double L1 = getDistance(P( 1 ),P( 2 ));
1117 double L2 = getDistance(P( 2 ),P( 3 ));
1118 double L3 = getDistance(P( 3 ),P( 4 ));
1119 double L4 = getDistance(P( 4 ),P( 1 ));
1120 double L5 = getDistance(P( 5 ),P( 6 ));
1121 double L6 = getDistance(P( 6 ),P( 7 ));
1122 double L7 = getDistance(P( 7 ),P( 8 ));
1123 double L8 = getDistance(P( 8 ),P( 5 ));
1124 double L9 = getDistance(P( 1 ),P( 5 ));
1125 double L10= getDistance(P( 2 ),P( 6 ));
1126 double L11= getDistance(P( 3 ),P( 7 ));
1127 double L12= getDistance(P( 4 ),P( 8 ));
1129 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1130 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
1131 aVal = Max(aVal,Max(L11,L12));
1136 if (len == 10){ // quadratic tetraidrs
1137 double L1 = getDistance(P( 1 ),P( 5 )) + getDistance(P( 5 ),P( 2 ));
1138 double L2 = getDistance(P( 2 ),P( 6 )) + getDistance(P( 6 ),P( 3 ));
1139 double L3 = getDistance(P( 3 ),P( 7 )) + getDistance(P( 7 ),P( 1 ));
1140 double L4 = getDistance(P( 1 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
1141 double L5 = getDistance(P( 2 ),P( 9 )) + getDistance(P( 9 ),P( 4 ));
1142 double L6 = getDistance(P( 3 ),P( 10 )) + getDistance(P( 10 ),P( 4 ));
1143 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1146 else if (len == 13){ // quadratic piramids
1147 double L1 = getDistance(P( 1 ),P( 6 )) + getDistance(P( 6 ),P( 2 ));
1148 double L2 = getDistance(P( 2 ),P( 7 )) + getDistance(P( 7 ),P( 3 ));
1149 double L3 = getDistance(P( 3 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
1150 double L4 = getDistance(P( 4 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1151 double L5 = getDistance(P( 1 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1152 double L6 = getDistance(P( 2 ),P( 11 )) + getDistance(P( 11 ),P( 5 ));
1153 double L7 = getDistance(P( 3 ),P( 12 )) + getDistance(P( 12 ),P( 5 ));
1154 double L8 = getDistance(P( 4 ),P( 13 )) + getDistance(P( 13 ),P( 5 ));
1155 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1156 aVal = Max(aVal,Max(L7,L8));
1159 else if (len == 15){ // quadratic pentaidres
1160 double L1 = getDistance(P( 1 ),P( 7 )) + getDistance(P( 7 ),P( 2 ));
1161 double L2 = getDistance(P( 2 ),P( 8 )) + getDistance(P( 8 ),P( 3 ));
1162 double L3 = getDistance(P( 3 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1163 double L4 = getDistance(P( 4 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1164 double L5 = getDistance(P( 5 ),P( 11 )) + getDistance(P( 11 ),P( 6 ));
1165 double L6 = getDistance(P( 6 ),P( 12 )) + getDistance(P( 12 ),P( 4 ));
1166 double L7 = getDistance(P( 1 ),P( 13 )) + getDistance(P( 13 ),P( 4 ));
1167 double L8 = getDistance(P( 2 ),P( 14 )) + getDistance(P( 14 ),P( 5 ));
1168 double L9 = getDistance(P( 3 ),P( 15 )) + getDistance(P( 15 ),P( 6 ));
1169 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1170 aVal = Max(aVal,Max(Max(L7,L8),L9));
1173 else if (len == 20){ // quadratic hexaider
1174 double L1 = getDistance(P( 1 ),P( 9 )) + getDistance(P( 9 ),P( 2 ));
1175 double L2 = getDistance(P( 2 ),P( 10 )) + getDistance(P( 10 ),P( 3 ));
1176 double L3 = getDistance(P( 3 ),P( 11 )) + getDistance(P( 11 ),P( 4 ));
1177 double L4 = getDistance(P( 4 ),P( 12 )) + getDistance(P( 12 ),P( 1 ));
1178 double L5 = getDistance(P( 5 ),P( 13 )) + getDistance(P( 13 ),P( 6 ));
1179 double L6 = getDistance(P( 6 ),P( 14 )) + getDistance(P( 14 ),P( 7 ));
1180 double L7 = getDistance(P( 7 ),P( 15 )) + getDistance(P( 15 ),P( 8 ));
1181 double L8 = getDistance(P( 8 ),P( 16 )) + getDistance(P( 16 ),P( 5 ));
1182 double L9 = getDistance(P( 1 ),P( 17 )) + getDistance(P( 17 ),P( 5 ));
1183 double L10= getDistance(P( 2 ),P( 18 )) + getDistance(P( 18 ),P( 6 ));
1184 double L11= getDistance(P( 3 ),P( 19 )) + getDistance(P( 19 ),P( 7 ));
1185 double L12= getDistance(P( 4 ),P( 20 )) + getDistance(P( 20 ),P( 8 ));
1186 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1187 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
1188 aVal = Max(aVal,Max(L11,L12));
1200 if ( myPrecision >= 0 )
1202 double prec = pow( 10., (double)( myPrecision ) );
1203 aVal = floor( aVal * prec + 0.5 ) / prec;
1212 double Length2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1214 // meaningless as it is not quality control functor
1218 SMDSAbs_ElementType Length2D::GetType() const
1220 return SMDSAbs_Face;
1223 Length2D::Value::Value(double theLength,long thePntId1, long thePntId2):
1226 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1227 if(thePntId1 > thePntId2){
1228 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1232 bool Length2D::Value::operator<(const Length2D::Value& x) const{
1233 if(myPntId[0] < x.myPntId[0]) return true;
1234 if(myPntId[0] == x.myPntId[0])
1235 if(myPntId[1] < x.myPntId[1]) return true;
1239 void Length2D::GetValues(TValues& theValues){
1241 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1242 for(; anIter->more(); ){
1243 const SMDS_MeshFace* anElem = anIter->next();
1245 if(anElem->IsQuadratic()) {
1246 const SMDS_QuadraticFaceOfNodes* F =
1247 static_cast<const SMDS_QuadraticFaceOfNodes*>(anElem);
1248 // use special nodes iterator
1249 SMDS_NodeIteratorPtr anIter = F->interlacedNodesIterator();
1254 const SMDS_MeshElement* aNode;
1256 aNode = anIter->next();
1257 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1258 P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1259 aNodeId[0] = aNodeId[1] = aNode->GetID();
1262 for(; anIter->more(); ){
1263 const SMDS_MeshNode* N1 = static_cast<const SMDS_MeshNode*> (anIter->next());
1264 P[2] = gp_Pnt(N1->X(),N1->Y(),N1->Z());
1265 aNodeId[2] = N1->GetID();
1266 aLength = P[1].Distance(P[2]);
1267 if(!anIter->more()) break;
1268 const SMDS_MeshNode* N2 = static_cast<const SMDS_MeshNode*> (anIter->next());
1269 P[3] = gp_Pnt(N2->X(),N2->Y(),N2->Z());
1270 aNodeId[3] = N2->GetID();
1271 aLength += P[2].Distance(P[3]);
1272 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1273 Value aValue2(aLength,aNodeId[2],aNodeId[3]);
1275 aNodeId[1] = aNodeId[3];
1276 theValues.insert(aValue1);
1277 theValues.insert(aValue2);
1279 aLength += P[2].Distance(P[0]);
1280 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1281 Value aValue2(aLength,aNodeId[2],aNodeId[0]);
1282 theValues.insert(aValue1);
1283 theValues.insert(aValue2);
1286 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
1291 const SMDS_MeshElement* aNode;
1292 if(aNodesIter->more()){
1293 aNode = aNodesIter->next();
1294 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1295 P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1296 aNodeId[0] = aNodeId[1] = aNode->GetID();
1299 for(; aNodesIter->more(); ){
1300 aNode = aNodesIter->next();
1301 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1302 long anId = aNode->GetID();
1304 P[2] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1306 aLength = P[1].Distance(P[2]);
1308 Value aValue(aLength,aNodeId[1],anId);
1311 theValues.insert(aValue);
1314 aLength = P[0].Distance(P[1]);
1316 Value aValue(aLength,aNodeId[0],aNodeId[1]);
1317 theValues.insert(aValue);
1323 Class : MultiConnection
1324 Description : Functor for calculating number of faces conneted to the edge
1326 double MultiConnection::GetValue( const TSequenceOfXYZ& P )
1330 double MultiConnection::GetValue( long theId )
1332 return getNbMultiConnection( myMesh, theId );
1335 double MultiConnection::GetBadRate( double Value, int /*nbNodes*/ ) const
1337 // meaningless as it is not quality control functor
1341 SMDSAbs_ElementType MultiConnection::GetType() const
1343 return SMDSAbs_Edge;
1347 Class : MultiConnection2D
1348 Description : Functor for calculating number of faces conneted to the edge
1350 double MultiConnection2D::GetValue( const TSequenceOfXYZ& P )
1355 double MultiConnection2D::GetValue( long theElementId )
1359 const SMDS_MeshElement* aFaceElem = myMesh->FindElement(theElementId);
1360 SMDSAbs_ElementType aType = aFaceElem->GetType();
1365 int i = 0, len = aFaceElem->NbNodes();
1366 SMDS_ElemIteratorPtr anIter = aFaceElem->nodesIterator();
1369 const SMDS_MeshNode *aNode, *aNode0;
1370 TColStd_MapOfInteger aMap, aMapPrev;
1372 for (i = 0; i <= len; i++) {
1377 if (anIter->more()) {
1378 aNode = (SMDS_MeshNode*)anIter->next();
1386 if (i == 0) aNode0 = aNode;
1388 SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator();
1389 while (anElemIter->more()) {
1390 const SMDS_MeshElement* anElem = anElemIter->next();
1391 if (anElem != 0 && anElem->GetType() == SMDSAbs_Face) {
1392 int anId = anElem->GetID();
1395 if (aMapPrev.Contains(anId)) {
1400 aResult = Max(aResult, aNb);
1411 double MultiConnection2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1413 // meaningless as it is not quality control functor
1417 SMDSAbs_ElementType MultiConnection2D::GetType() const
1419 return SMDSAbs_Face;
1422 MultiConnection2D::Value::Value(long thePntId1, long thePntId2)
1424 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1425 if(thePntId1 > thePntId2){
1426 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1430 bool MultiConnection2D::Value::operator<(const MultiConnection2D::Value& x) const{
1431 if(myPntId[0] < x.myPntId[0]) return true;
1432 if(myPntId[0] == x.myPntId[0])
1433 if(myPntId[1] < x.myPntId[1]) return true;
1437 void MultiConnection2D::GetValues(MValues& theValues){
1438 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1439 for(; anIter->more(); ){
1440 const SMDS_MeshFace* anElem = anIter->next();
1441 SMDS_ElemIteratorPtr aNodesIter;
1442 if ( anElem->IsQuadratic() )
1443 aNodesIter = static_cast<const SMDS_QuadraticFaceOfNodes*>
1444 (anElem)->interlacedNodesElemIterator();
1446 aNodesIter = anElem->nodesIterator();
1449 //int aNbConnects=0;
1450 const SMDS_MeshNode* aNode0;
1451 const SMDS_MeshNode* aNode1;
1452 const SMDS_MeshNode* aNode2;
1453 if(aNodesIter->more()){
1454 aNode0 = (SMDS_MeshNode*) aNodesIter->next();
1456 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode1;
1457 aNodeId[0] = aNodeId[1] = aNodes->GetID();
1459 for(; aNodesIter->more(); ) {
1460 aNode2 = (SMDS_MeshNode*) aNodesIter->next();
1461 long anId = aNode2->GetID();
1464 Value aValue(aNodeId[1],aNodeId[2]);
1465 MValues::iterator aItr = theValues.find(aValue);
1466 if (aItr != theValues.end()){
1471 theValues[aValue] = 1;
1474 //cout << "NodeIds: "<<aNodeId[1]<<","<<aNodeId[2]<<" nbconn="<<aNbConnects<<endl;
1475 aNodeId[1] = aNodeId[2];
1478 Value aValue(aNodeId[0],aNodeId[2]);
1479 MValues::iterator aItr = theValues.find(aValue);
1480 if (aItr != theValues.end()) {
1485 theValues[aValue] = 1;
1488 //cout << "NodeIds: "<<aNodeId[0]<<","<<aNodeId[2]<<" nbconn="<<aNbConnects<<endl;
1498 Class : BadOrientedVolume
1499 Description : Predicate bad oriented volumes
1502 BadOrientedVolume::BadOrientedVolume()
1507 void BadOrientedVolume::SetMesh( const SMDS_Mesh* theMesh )
1512 bool BadOrientedVolume::IsSatisfy( long theId )
1517 SMDS_VolumeTool vTool( myMesh->FindElement( theId ));
1518 return !vTool.IsForward();
1521 SMDSAbs_ElementType BadOrientedVolume::GetType() const
1523 return SMDSAbs_Volume;
1530 Description : Predicate for free borders
1533 FreeBorders::FreeBorders()
1538 void FreeBorders::SetMesh( const SMDS_Mesh* theMesh )
1543 bool FreeBorders::IsSatisfy( long theId )
1545 return getNbMultiConnection( myMesh, theId ) == 1;
1548 SMDSAbs_ElementType FreeBorders::GetType() const
1550 return SMDSAbs_Edge;
1556 Description : Predicate for free Edges
1558 FreeEdges::FreeEdges()
1563 void FreeEdges::SetMesh( const SMDS_Mesh* theMesh )
1568 bool FreeEdges::IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId )
1570 TColStd_MapOfInteger aMap;
1571 for ( int i = 0; i < 2; i++ )
1573 SMDS_ElemIteratorPtr anElemIter = theNodes[ i ]->GetInverseElementIterator();
1574 while( anElemIter->more() )
1576 const SMDS_MeshElement* anElem = anElemIter->next();
1577 if ( anElem != 0 && anElem->GetType() == SMDSAbs_Face )
1579 int anId = anElem->GetID();
1583 else if ( aMap.Contains( anId ) && anId != theFaceId )
1591 bool FreeEdges::IsSatisfy( long theId )
1596 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
1597 if ( aFace == 0 || aFace->GetType() != SMDSAbs_Face || aFace->NbNodes() < 3 )
1600 SMDS_ElemIteratorPtr anIter;
1601 if ( aFace->IsQuadratic() ) {
1602 anIter = static_cast<const SMDS_QuadraticFaceOfNodes*>
1603 (aFace)->interlacedNodesElemIterator();
1606 anIter = aFace->nodesIterator();
1611 int i = 0, nbNodes = aFace->NbNodes();
1612 std::vector <const SMDS_MeshNode*> aNodes( nbNodes+1 );
1613 while( anIter->more() )
1615 const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next();
1618 aNodes[ i++ ] = aNode;
1620 aNodes[ nbNodes ] = aNodes[ 0 ];
1622 for ( i = 0; i < nbNodes; i++ )
1623 if ( IsFreeEdge( &aNodes[ i ], theId ) )
1629 SMDSAbs_ElementType FreeEdges::GetType() const
1631 return SMDSAbs_Face;
1634 FreeEdges::Border::Border(long theElemId, long thePntId1, long thePntId2):
1637 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1638 if(thePntId1 > thePntId2){
1639 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1643 bool FreeEdges::Border::operator<(const FreeEdges::Border& x) const{
1644 if(myPntId[0] < x.myPntId[0]) return true;
1645 if(myPntId[0] == x.myPntId[0])
1646 if(myPntId[1] < x.myPntId[1]) return true;
1650 inline void UpdateBorders(const FreeEdges::Border& theBorder,
1651 FreeEdges::TBorders& theRegistry,
1652 FreeEdges::TBorders& theContainer)
1654 if(theRegistry.find(theBorder) == theRegistry.end()){
1655 theRegistry.insert(theBorder);
1656 theContainer.insert(theBorder);
1658 theContainer.erase(theBorder);
1662 void FreeEdges::GetBoreders(TBorders& theBorders)
1665 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1666 for(; anIter->more(); ){
1667 const SMDS_MeshFace* anElem = anIter->next();
1668 long anElemId = anElem->GetID();
1669 SMDS_ElemIteratorPtr aNodesIter;
1670 if ( anElem->IsQuadratic() )
1671 aNodesIter = static_cast<const SMDS_QuadraticFaceOfNodes*>(anElem)->
1672 interlacedNodesElemIterator();
1674 aNodesIter = anElem->nodesIterator();
1676 const SMDS_MeshElement* aNode;
1677 if(aNodesIter->more()){
1678 aNode = aNodesIter->next();
1679 aNodeId[0] = aNodeId[1] = aNode->GetID();
1681 for(; aNodesIter->more(); ){
1682 aNode = aNodesIter->next();
1683 long anId = aNode->GetID();
1684 Border aBorder(anElemId,aNodeId[1],anId);
1686 //std::cout<<aBorder.myPntId[0]<<"; "<<aBorder.myPntId[1]<<"; "<<aBorder.myElemId<<endl;
1687 UpdateBorders(aBorder,aRegistry,theBorders);
1689 Border aBorder(anElemId,aNodeId[0],aNodeId[1]);
1690 //std::cout<<aBorder.myPntId[0]<<"; "<<aBorder.myPntId[1]<<"; "<<aBorder.myElemId<<endl;
1691 UpdateBorders(aBorder,aRegistry,theBorders);
1693 //std::cout<<"theBorders.size() = "<<theBorders.size()<<endl;
1698 Description : Predicate for Range of Ids.
1699 Range may be specified with two ways.
1700 1. Using AddToRange method
1701 2. With SetRangeStr method. Parameter of this method is a string
1702 like as "1,2,3,50-60,63,67,70-"
1705 //=======================================================================
1706 // name : RangeOfIds
1707 // Purpose : Constructor
1708 //=======================================================================
1709 RangeOfIds::RangeOfIds()
1712 myType = SMDSAbs_All;
1715 //=======================================================================
1717 // Purpose : Set mesh
1718 //=======================================================================
1719 void RangeOfIds::SetMesh( const SMDS_Mesh* theMesh )
1724 //=======================================================================
1725 // name : AddToRange
1726 // Purpose : Add ID to the range
1727 //=======================================================================
1728 bool RangeOfIds::AddToRange( long theEntityId )
1730 myIds.Add( theEntityId );
1734 //=======================================================================
1735 // name : GetRangeStr
1736 // Purpose : Get range as a string.
1737 // Example: "1,2,3,50-60,63,67,70-"
1738 //=======================================================================
1739 void RangeOfIds::GetRangeStr( TCollection_AsciiString& theResStr )
1743 TColStd_SequenceOfInteger anIntSeq;
1744 TColStd_SequenceOfAsciiString aStrSeq;
1746 TColStd_MapIteratorOfMapOfInteger anIter( myIds );
1747 for ( ; anIter.More(); anIter.Next() )
1749 int anId = anIter.Key();
1750 TCollection_AsciiString aStr( anId );
1751 anIntSeq.Append( anId );
1752 aStrSeq.Append( aStr );
1755 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
1757 int aMinId = myMin( i );
1758 int aMaxId = myMax( i );
1760 TCollection_AsciiString aStr;
1761 if ( aMinId != IntegerFirst() )
1766 if ( aMaxId != IntegerLast() )
1769 // find position of the string in result sequence and insert string in it
1770 if ( anIntSeq.Length() == 0 )
1772 anIntSeq.Append( aMinId );
1773 aStrSeq.Append( aStr );
1777 if ( aMinId < anIntSeq.First() )
1779 anIntSeq.Prepend( aMinId );
1780 aStrSeq.Prepend( aStr );
1782 else if ( aMinId > anIntSeq.Last() )
1784 anIntSeq.Append( aMinId );
1785 aStrSeq.Append( aStr );
1788 for ( int j = 1, k = anIntSeq.Length(); j <= k; j++ )
1789 if ( aMinId < anIntSeq( j ) )
1791 anIntSeq.InsertBefore( j, aMinId );
1792 aStrSeq.InsertBefore( j, aStr );
1798 if ( aStrSeq.Length() == 0 )
1801 theResStr = aStrSeq( 1 );
1802 for ( int j = 2, k = aStrSeq.Length(); j <= k; j++ )
1805 theResStr += aStrSeq( j );
1809 //=======================================================================
1810 // name : SetRangeStr
1811 // Purpose : Define range with string
1812 // Example of entry string: "1,2,3,50-60,63,67,70-"
1813 //=======================================================================
1814 bool RangeOfIds::SetRangeStr( const TCollection_AsciiString& theStr )
1820 TCollection_AsciiString aStr = theStr;
1821 aStr.RemoveAll( ' ' );
1822 aStr.RemoveAll( '\t' );
1824 for ( int aPos = aStr.Search( ",," ); aPos != -1; aPos = aStr.Search( ",," ) )
1825 aStr.Remove( aPos, 2 );
1827 TCollection_AsciiString tmpStr = aStr.Token( ",", 1 );
1829 while ( tmpStr != "" )
1831 tmpStr = aStr.Token( ",", i++ );
1832 int aPos = tmpStr.Search( '-' );
1836 if ( tmpStr.IsIntegerValue() )
1837 myIds.Add( tmpStr.IntegerValue() );
1843 TCollection_AsciiString aMaxStr = tmpStr.Split( aPos );
1844 TCollection_AsciiString aMinStr = tmpStr;
1846 while ( aMinStr.Search( "-" ) != -1 ) aMinStr.RemoveAll( '-' );
1847 while ( aMaxStr.Search( "-" ) != -1 ) aMaxStr.RemoveAll( '-' );
1849 if ( !aMinStr.IsEmpty() && !aMinStr.IsIntegerValue() ||
1850 !aMaxStr.IsEmpty() && !aMaxStr.IsIntegerValue() )
1853 myMin.Append( aMinStr.IsEmpty() ? IntegerFirst() : aMinStr.IntegerValue() );
1854 myMax.Append( aMaxStr.IsEmpty() ? IntegerLast() : aMaxStr.IntegerValue() );
1861 //=======================================================================
1863 // Purpose : Get type of supported entities
1864 //=======================================================================
1865 SMDSAbs_ElementType RangeOfIds::GetType() const
1870 //=======================================================================
1872 // Purpose : Set type of supported entities
1873 //=======================================================================
1874 void RangeOfIds::SetType( SMDSAbs_ElementType theType )
1879 //=======================================================================
1881 // Purpose : Verify whether entity satisfies to this rpedicate
1882 //=======================================================================
1883 bool RangeOfIds::IsSatisfy( long theId )
1888 if ( myType == SMDSAbs_Node )
1890 if ( myMesh->FindNode( theId ) == 0 )
1895 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
1896 if ( anElem == 0 || myType != anElem->GetType() && myType != SMDSAbs_All )
1900 if ( myIds.Contains( theId ) )
1903 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
1904 if ( theId >= myMin( i ) && theId <= myMax( i ) )
1912 Description : Base class for comparators
1914 Comparator::Comparator():
1918 Comparator::~Comparator()
1921 void Comparator::SetMesh( const SMDS_Mesh* theMesh )
1924 myFunctor->SetMesh( theMesh );
1927 void Comparator::SetMargin( double theValue )
1929 myMargin = theValue;
1932 void Comparator::SetNumFunctor( NumericalFunctorPtr theFunct )
1934 myFunctor = theFunct;
1937 SMDSAbs_ElementType Comparator::GetType() const
1939 return myFunctor ? myFunctor->GetType() : SMDSAbs_All;
1942 double Comparator::GetMargin()
1950 Description : Comparator "<"
1952 bool LessThan::IsSatisfy( long theId )
1954 return myFunctor && myFunctor->GetValue( theId ) < myMargin;
1960 Description : Comparator ">"
1962 bool MoreThan::IsSatisfy( long theId )
1964 return myFunctor && myFunctor->GetValue( theId ) > myMargin;
1970 Description : Comparator "="
1973 myToler(Precision::Confusion())
1976 bool EqualTo::IsSatisfy( long theId )
1978 return myFunctor && fabs( myFunctor->GetValue( theId ) - myMargin ) < myToler;
1981 void EqualTo::SetTolerance( double theToler )
1986 double EqualTo::GetTolerance()
1993 Description : Logical NOT predicate
1995 LogicalNOT::LogicalNOT()
1998 LogicalNOT::~LogicalNOT()
2001 bool LogicalNOT::IsSatisfy( long theId )
2003 return myPredicate && !myPredicate->IsSatisfy( theId );
2006 void LogicalNOT::SetMesh( const SMDS_Mesh* theMesh )
2009 myPredicate->SetMesh( theMesh );
2012 void LogicalNOT::SetPredicate( PredicatePtr thePred )
2014 myPredicate = thePred;
2017 SMDSAbs_ElementType LogicalNOT::GetType() const
2019 return myPredicate ? myPredicate->GetType() : SMDSAbs_All;
2024 Class : LogicalBinary
2025 Description : Base class for binary logical predicate
2027 LogicalBinary::LogicalBinary()
2030 LogicalBinary::~LogicalBinary()
2033 void LogicalBinary::SetMesh( const SMDS_Mesh* theMesh )
2036 myPredicate1->SetMesh( theMesh );
2039 myPredicate2->SetMesh( theMesh );
2042 void LogicalBinary::SetPredicate1( PredicatePtr thePredicate )
2044 myPredicate1 = thePredicate;
2047 void LogicalBinary::SetPredicate2( PredicatePtr thePredicate )
2049 myPredicate2 = thePredicate;
2052 SMDSAbs_ElementType LogicalBinary::GetType() const
2054 if ( !myPredicate1 || !myPredicate2 )
2057 SMDSAbs_ElementType aType1 = myPredicate1->GetType();
2058 SMDSAbs_ElementType aType2 = myPredicate2->GetType();
2060 return aType1 == aType2 ? aType1 : SMDSAbs_All;
2066 Description : Logical AND
2068 bool LogicalAND::IsSatisfy( long theId )
2073 myPredicate1->IsSatisfy( theId ) &&
2074 myPredicate2->IsSatisfy( theId );
2080 Description : Logical OR
2082 bool LogicalOR::IsSatisfy( long theId )
2087 myPredicate1->IsSatisfy( theId ) ||
2088 myPredicate2->IsSatisfy( theId );
2102 void Filter::SetPredicate( PredicatePtr thePredicate )
2104 myPredicate = thePredicate;
2107 template<class TElement, class TIterator, class TPredicate>
2108 inline void FillSequence(const TIterator& theIterator,
2109 TPredicate& thePredicate,
2110 Filter::TIdSequence& theSequence)
2112 if ( theIterator ) {
2113 while( theIterator->more() ) {
2114 TElement anElem = theIterator->next();
2115 long anId = anElem->GetID();
2116 if ( thePredicate->IsSatisfy( anId ) )
2117 theSequence.push_back( anId );
2124 GetElementsId( const SMDS_Mesh* theMesh,
2125 PredicatePtr thePredicate,
2126 TIdSequence& theSequence )
2128 theSequence.clear();
2130 if ( !theMesh || !thePredicate )
2133 thePredicate->SetMesh( theMesh );
2135 SMDSAbs_ElementType aType = thePredicate->GetType();
2138 FillSequence<const SMDS_MeshNode*>(theMesh->nodesIterator(),thePredicate,theSequence);
2141 FillSequence<const SMDS_MeshElement*>(theMesh->edgesIterator(),thePredicate,theSequence);
2144 FillSequence<const SMDS_MeshElement*>(theMesh->facesIterator(),thePredicate,theSequence);
2146 case SMDSAbs_Volume:
2147 FillSequence<const SMDS_MeshElement*>(theMesh->volumesIterator(),thePredicate,theSequence);
2150 FillSequence<const SMDS_MeshElement*>(theMesh->edgesIterator(),thePredicate,theSequence);
2151 FillSequence<const SMDS_MeshElement*>(theMesh->facesIterator(),thePredicate,theSequence);
2152 FillSequence<const SMDS_MeshElement*>(theMesh->volumesIterator(),thePredicate,theSequence);
2158 Filter::GetElementsId( const SMDS_Mesh* theMesh,
2159 Filter::TIdSequence& theSequence )
2161 GetElementsId(theMesh,myPredicate,theSequence);
2168 typedef std::set<SMDS_MeshFace*> TMapOfFacePtr;
2174 ManifoldPart::Link::Link( SMDS_MeshNode* theNode1,
2175 SMDS_MeshNode* theNode2 )
2181 ManifoldPart::Link::~Link()
2187 bool ManifoldPart::Link::IsEqual( const ManifoldPart::Link& theLink ) const
2189 if ( myNode1 == theLink.myNode1 &&
2190 myNode2 == theLink.myNode2 )
2192 else if ( myNode1 == theLink.myNode2 &&
2193 myNode2 == theLink.myNode1 )
2199 bool ManifoldPart::Link::operator<( const ManifoldPart::Link& x ) const
2201 if(myNode1 < x.myNode1) return true;
2202 if(myNode1 == x.myNode1)
2203 if(myNode2 < x.myNode2) return true;
2207 bool ManifoldPart::IsEqual( const ManifoldPart::Link& theLink1,
2208 const ManifoldPart::Link& theLink2 )
2210 return theLink1.IsEqual( theLink2 );
2213 ManifoldPart::ManifoldPart()
2216 myAngToler = Precision::Angular();
2217 myIsOnlyManifold = true;
2220 ManifoldPart::~ManifoldPart()
2225 void ManifoldPart::SetMesh( const SMDS_Mesh* theMesh )
2231 SMDSAbs_ElementType ManifoldPart::GetType() const
2232 { return SMDSAbs_Face; }
2234 bool ManifoldPart::IsSatisfy( long theElementId )
2236 return myMapIds.Contains( theElementId );
2239 void ManifoldPart::SetAngleTolerance( const double theAngToler )
2240 { myAngToler = theAngToler; }
2242 double ManifoldPart::GetAngleTolerance() const
2243 { return myAngToler; }
2245 void ManifoldPart::SetIsOnlyManifold( const bool theIsOnly )
2246 { myIsOnlyManifold = theIsOnly; }
2248 void ManifoldPart::SetStartElem( const long theStartId )
2249 { myStartElemId = theStartId; }
2251 bool ManifoldPart::process()
2254 myMapBadGeomIds.Clear();
2256 myAllFacePtr.clear();
2257 myAllFacePtrIntDMap.clear();
2261 // collect all faces into own map
2262 SMDS_FaceIteratorPtr anFaceItr = myMesh->facesIterator();
2263 for (; anFaceItr->more(); )
2265 SMDS_MeshFace* aFacePtr = (SMDS_MeshFace*)anFaceItr->next();
2266 myAllFacePtr.push_back( aFacePtr );
2267 myAllFacePtrIntDMap[aFacePtr] = myAllFacePtr.size()-1;
2270 SMDS_MeshFace* aStartFace = (SMDS_MeshFace*)myMesh->FindElement( myStartElemId );
2274 // the map of non manifold links and bad geometry
2275 TMapOfLink aMapOfNonManifold;
2276 TColStd_MapOfInteger aMapOfTreated;
2278 // begin cycle on faces from start index and run on vector till the end
2279 // and from begin to start index to cover whole vector
2280 const int aStartIndx = myAllFacePtrIntDMap[aStartFace];
2281 bool isStartTreat = false;
2282 for ( int fi = aStartIndx; !isStartTreat || fi != aStartIndx ; fi++ )
2284 if ( fi == aStartIndx )
2285 isStartTreat = true;
2286 // as result next time when fi will be equal to aStartIndx
2288 SMDS_MeshFace* aFacePtr = myAllFacePtr[ fi ];
2289 if ( aMapOfTreated.Contains( aFacePtr->GetID() ) )
2292 aMapOfTreated.Add( aFacePtr->GetID() );
2293 TColStd_MapOfInteger aResFaces;
2294 if ( !findConnected( myAllFacePtrIntDMap, aFacePtr,
2295 aMapOfNonManifold, aResFaces ) )
2297 TColStd_MapIteratorOfMapOfInteger anItr( aResFaces );
2298 for ( ; anItr.More(); anItr.Next() )
2300 int aFaceId = anItr.Key();
2301 aMapOfTreated.Add( aFaceId );
2302 myMapIds.Add( aFaceId );
2305 if ( fi == ( myAllFacePtr.size() - 1 ) )
2307 } // end run on vector of faces
2308 return !myMapIds.IsEmpty();
2311 static void getLinks( const SMDS_MeshFace* theFace,
2312 ManifoldPart::TVectorOfLink& theLinks )
2314 int aNbNode = theFace->NbNodes();
2315 SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
2317 SMDS_MeshNode* aNode = 0;
2318 for ( ; aNodeItr->more() && i <= aNbNode; )
2321 SMDS_MeshNode* aN1 = (SMDS_MeshNode*)aNodeItr->next();
2325 SMDS_MeshNode* aN2 = ( i >= aNbNode ) ? aNode : (SMDS_MeshNode*)aNodeItr->next();
2327 ManifoldPart::Link aLink( aN1, aN2 );
2328 theLinks.push_back( aLink );
2332 static gp_XYZ getNormale( const SMDS_MeshFace* theFace )
2335 int aNbNode = theFace->NbNodes();
2336 TColgp_Array1OfXYZ anArrOfXYZ(1,4);
2337 SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
2339 for ( ; aNodeItr->more() && i <= 4; i++ ) {
2340 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
2341 anArrOfXYZ.SetValue(i, gp_XYZ( aNode->X(), aNode->Y(), aNode->Z() ) );
2344 gp_XYZ q1 = anArrOfXYZ.Value(2) - anArrOfXYZ.Value(1);
2345 gp_XYZ q2 = anArrOfXYZ.Value(3) - anArrOfXYZ.Value(1);
2347 if ( aNbNode > 3 ) {
2348 gp_XYZ q3 = anArrOfXYZ.Value(4) - anArrOfXYZ.Value(1);
2351 double len = n.Modulus();
2358 bool ManifoldPart::findConnected
2359 ( const ManifoldPart::TDataMapFacePtrInt& theAllFacePtrInt,
2360 SMDS_MeshFace* theStartFace,
2361 ManifoldPart::TMapOfLink& theNonManifold,
2362 TColStd_MapOfInteger& theResFaces )
2364 theResFaces.Clear();
2365 if ( !theAllFacePtrInt.size() )
2368 if ( getNormale( theStartFace ).SquareModulus() <= gp::Resolution() )
2370 myMapBadGeomIds.Add( theStartFace->GetID() );
2374 ManifoldPart::TMapOfLink aMapOfBoundary, aMapToSkip;
2375 ManifoldPart::TVectorOfLink aSeqOfBoundary;
2376 theResFaces.Add( theStartFace->GetID() );
2377 ManifoldPart::TDataMapOfLinkFacePtr aDMapLinkFace;
2379 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
2380 aDMapLinkFace, theNonManifold, theStartFace );
2382 bool isDone = false;
2383 while ( !isDone && aMapOfBoundary.size() != 0 )
2385 bool isToReset = false;
2386 ManifoldPart::TVectorOfLink::iterator pLink = aSeqOfBoundary.begin();
2387 for ( ; !isToReset && pLink != aSeqOfBoundary.end(); ++pLink )
2389 ManifoldPart::Link aLink = *pLink;
2390 if ( aMapToSkip.find( aLink ) != aMapToSkip.end() )
2392 // each link could be treated only once
2393 aMapToSkip.insert( aLink );
2395 ManifoldPart::TVectorOfFacePtr aFaces;
2397 if ( myIsOnlyManifold &&
2398 (theNonManifold.find( aLink ) != theNonManifold.end()) )
2402 getFacesByLink( aLink, aFaces );
2403 // filter the element to keep only indicated elements
2404 ManifoldPart::TVectorOfFacePtr aFiltered;
2405 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
2406 for ( ; pFace != aFaces.end(); ++pFace )
2408 SMDS_MeshFace* aFace = *pFace;
2409 if ( myAllFacePtrIntDMap.find( aFace ) != myAllFacePtrIntDMap.end() )
2410 aFiltered.push_back( aFace );
2413 if ( aFaces.size() < 2 ) // no neihgbour faces
2415 else if ( myIsOnlyManifold && aFaces.size() > 2 ) // non manifold case
2417 theNonManifold.insert( aLink );
2422 // compare normal with normals of neighbor element
2423 SMDS_MeshFace* aPrevFace = aDMapLinkFace[ aLink ];
2424 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
2425 for ( ; pFace != aFaces.end(); ++pFace )
2427 SMDS_MeshFace* aNextFace = *pFace;
2428 if ( aPrevFace == aNextFace )
2430 int anNextFaceID = aNextFace->GetID();
2431 if ( myIsOnlyManifold && theResFaces.Contains( anNextFaceID ) )
2432 // should not be with non manifold restriction. probably bad topology
2434 // check if face was treated and skipped
2435 if ( myMapBadGeomIds.Contains( anNextFaceID ) ||
2436 !isInPlane( aPrevFace, aNextFace ) )
2438 // add new element to connected and extend the boundaries.
2439 theResFaces.Add( anNextFaceID );
2440 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
2441 aDMapLinkFace, theNonManifold, aNextFace );
2445 isDone = !isToReset;
2448 return !theResFaces.IsEmpty();
2451 bool ManifoldPart::isInPlane( const SMDS_MeshFace* theFace1,
2452 const SMDS_MeshFace* theFace2 )
2454 gp_Dir aNorm1 = gp_Dir( getNormale( theFace1 ) );
2455 gp_XYZ aNorm2XYZ = getNormale( theFace2 );
2456 if ( aNorm2XYZ.SquareModulus() <= gp::Resolution() )
2458 myMapBadGeomIds.Add( theFace2->GetID() );
2461 if ( aNorm1.IsParallel( gp_Dir( aNorm2XYZ ), myAngToler ) )
2467 void ManifoldPart::expandBoundary
2468 ( ManifoldPart::TMapOfLink& theMapOfBoundary,
2469 ManifoldPart::TVectorOfLink& theSeqOfBoundary,
2470 ManifoldPart::TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
2471 ManifoldPart::TMapOfLink& theNonManifold,
2472 SMDS_MeshFace* theNextFace ) const
2474 ManifoldPart::TVectorOfLink aLinks;
2475 getLinks( theNextFace, aLinks );
2476 int aNbLink = (int)aLinks.size();
2477 for ( int i = 0; i < aNbLink; i++ )
2479 ManifoldPart::Link aLink = aLinks[ i ];
2480 if ( myIsOnlyManifold && (theNonManifold.find( aLink ) != theNonManifold.end()) )
2482 if ( theMapOfBoundary.find( aLink ) != theMapOfBoundary.end() )
2484 if ( myIsOnlyManifold )
2486 // remove from boundary
2487 theMapOfBoundary.erase( aLink );
2488 ManifoldPart::TVectorOfLink::iterator pLink = theSeqOfBoundary.begin();
2489 for ( ; pLink != theSeqOfBoundary.end(); ++pLink )
2491 ManifoldPart::Link aBoundLink = *pLink;
2492 if ( aBoundLink.IsEqual( aLink ) )
2494 theSeqOfBoundary.erase( pLink );
2502 theMapOfBoundary.insert( aLink );
2503 theSeqOfBoundary.push_back( aLink );
2504 theDMapLinkFacePtr[ aLink ] = theNextFace;
2509 void ManifoldPart::getFacesByLink( const ManifoldPart::Link& theLink,
2510 ManifoldPart::TVectorOfFacePtr& theFaces ) const
2512 SMDS_Mesh::SetOfFaces aSetOfFaces;
2513 // take all faces that shared first node
2514 SMDS_ElemIteratorPtr anItr = theLink.myNode1->facesIterator();
2515 for ( ; anItr->more(); )
2517 SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
2520 aSetOfFaces.Add( aFace );
2522 // take all faces that shared second node
2523 anItr = theLink.myNode2->facesIterator();
2524 // find the common part of two sets
2525 for ( ; anItr->more(); )
2527 SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
2528 if ( aSetOfFaces.Contains( aFace ) )
2529 theFaces.push_back( aFace );
2538 ElementsOnSurface::ElementsOnSurface()
2542 myType = SMDSAbs_All;
2544 myToler = Precision::Confusion();
2545 myUseBoundaries = false;
2548 ElementsOnSurface::~ElementsOnSurface()
2553 void ElementsOnSurface::SetMesh( const SMDS_Mesh* theMesh )
2555 if ( myMesh == theMesh )
2561 bool ElementsOnSurface::IsSatisfy( long theElementId )
2563 return myIds.Contains( theElementId );
2566 SMDSAbs_ElementType ElementsOnSurface::GetType() const
2569 void ElementsOnSurface::SetTolerance( const double theToler )
2571 if ( myToler != theToler )
2576 double ElementsOnSurface::GetTolerance() const
2579 void ElementsOnSurface::SetUseBoundaries( bool theUse )
2581 if ( myUseBoundaries != theUse ) {
2582 myUseBoundaries = theUse;
2583 SetSurface( mySurf, myType );
2587 void ElementsOnSurface::SetSurface( const TopoDS_Shape& theShape,
2588 const SMDSAbs_ElementType theType )
2593 if ( theShape.IsNull() || theShape.ShapeType() != TopAbs_FACE )
2595 mySurf = TopoDS::Face( theShape );
2596 BRepAdaptor_Surface SA( mySurf, myUseBoundaries );
2598 u1 = SA.FirstUParameter(),
2599 u2 = SA.LastUParameter(),
2600 v1 = SA.FirstVParameter(),
2601 v2 = SA.LastVParameter();
2602 Handle(Geom_Surface) surf = BRep_Tool::Surface( mySurf );
2603 myProjector.Init( surf, u1,u2, v1,v2 );
2607 void ElementsOnSurface::process()
2610 if ( mySurf.IsNull() )
2616 if ( myType == SMDSAbs_Face || myType == SMDSAbs_All )
2618 myIds.ReSize( myMesh->NbFaces() );
2619 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
2620 for(; anIter->more(); )
2621 process( anIter->next() );
2624 if ( myType == SMDSAbs_Edge || myType == SMDSAbs_All )
2626 myIds.ReSize( myIds.Extent() + myMesh->NbEdges() );
2627 SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
2628 for(; anIter->more(); )
2629 process( anIter->next() );
2632 if ( myType == SMDSAbs_Node )
2634 myIds.ReSize( myMesh->NbNodes() );
2635 SMDS_NodeIteratorPtr anIter = myMesh->nodesIterator();
2636 for(; anIter->more(); )
2637 process( anIter->next() );
2641 void ElementsOnSurface::process( const SMDS_MeshElement* theElemPtr )
2643 SMDS_ElemIteratorPtr aNodeItr = theElemPtr->nodesIterator();
2644 bool isSatisfy = true;
2645 for ( ; aNodeItr->more(); )
2647 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
2648 if ( !isOnSurface( aNode ) )
2655 myIds.Add( theElemPtr->GetID() );
2658 bool ElementsOnSurface::isOnSurface( const SMDS_MeshNode* theNode )
2660 if ( mySurf.IsNull() )
2663 gp_Pnt aPnt( theNode->X(), theNode->Y(), theNode->Z() );
2664 // double aToler2 = myToler * myToler;
2665 // if ( mySurf->IsKind(STANDARD_TYPE(Geom_Plane)))
2667 // gp_Pln aPln = Handle(Geom_Plane)::DownCast(mySurf)->Pln();
2668 // if ( aPln.SquareDistance( aPnt ) > aToler2 )
2671 // else if ( mySurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)))
2673 // gp_Cylinder aCyl = Handle(Geom_CylindricalSurface)::DownCast(mySurf)->Cylinder();
2674 // double aRad = aCyl.Radius();
2675 // gp_Ax3 anAxis = aCyl.Position();
2676 // gp_XYZ aLoc = aCyl.Location().XYZ();
2677 // double aXDist = anAxis.XDirection().XYZ() * ( aPnt.XYZ() - aLoc );
2678 // double aYDist = anAxis.YDirection().XYZ() * ( aPnt.XYZ() - aLoc );
2679 // if ( fabs(aXDist*aXDist + aYDist*aYDist - aRad*aRad) > aToler2 )
2684 myProjector.Perform( aPnt );
2685 bool isOn = ( myProjector.IsDone() && myProjector.LowerDistance() <= myToler );
2695 ElementsOnShape::ElementsOnShape()
2697 myType(SMDSAbs_All),
2698 myToler(Precision::Confusion()),
2699 myAllNodesFlag(false)
2701 myCurShapeType = TopAbs_SHAPE;
2704 ElementsOnShape::~ElementsOnShape()
2708 void ElementsOnShape::SetMesh (const SMDS_Mesh* theMesh)
2710 if (myMesh != theMesh) {
2712 SetShape(myShape, myType);
2716 bool ElementsOnShape::IsSatisfy (long theElementId)
2718 return myIds.Contains(theElementId);
2721 SMDSAbs_ElementType ElementsOnShape::GetType() const
2726 void ElementsOnShape::SetTolerance (const double theToler)
2728 if (myToler != theToler) {
2730 SetShape(myShape, myType);
2734 double ElementsOnShape::GetTolerance() const
2739 void ElementsOnShape::SetAllNodes (bool theAllNodes)
2741 if (myAllNodesFlag != theAllNodes) {
2742 myAllNodesFlag = theAllNodes;
2743 SetShape(myShape, myType);
2747 void ElementsOnShape::SetShape (const TopoDS_Shape& theShape,
2748 const SMDSAbs_ElementType theType)
2754 if (myMesh == 0) return;
2759 myIds.ReSize(myMesh->NbEdges() + myMesh->NbFaces() + myMesh->NbVolumes());
2762 myIds.ReSize(myMesh->NbNodes());
2765 myIds.ReSize(myMesh->NbEdges());
2768 myIds.ReSize(myMesh->NbFaces());
2770 case SMDSAbs_Volume:
2771 myIds.ReSize(myMesh->NbVolumes());
2777 myShapesMap.Clear();
2781 void ElementsOnShape::addShape (const TopoDS_Shape& theShape)
2783 if (theShape.IsNull() || myMesh == 0)
2786 if (!myShapesMap.Add(theShape)) return;
2788 myCurShapeType = theShape.ShapeType();
2789 switch (myCurShapeType)
2791 case TopAbs_COMPOUND:
2792 case TopAbs_COMPSOLID:
2796 TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
2797 for (; anIt.More(); anIt.Next()) addShape(anIt.Value());
2802 myCurSC.Load(theShape);
2808 TopoDS_Face aFace = TopoDS::Face(theShape);
2809 BRepAdaptor_Surface SA (aFace, true);
2811 u1 = SA.FirstUParameter(),
2812 u2 = SA.LastUParameter(),
2813 v1 = SA.FirstVParameter(),
2814 v2 = SA.LastVParameter();
2815 Handle(Geom_Surface) surf = BRep_Tool::Surface(aFace);
2816 myCurProjFace.Init(surf, u1,u2, v1,v2);
2823 TopoDS_Edge anEdge = TopoDS::Edge(theShape);
2824 Standard_Real u1, u2;
2825 Handle(Geom_Curve) curve = BRep_Tool::Curve(anEdge, u1, u2);
2826 myCurProjEdge.Init(curve, u1, u2);
2832 TopoDS_Vertex aV = TopoDS::Vertex(theShape);
2833 myCurPnt = BRep_Tool::Pnt(aV);
2842 void ElementsOnShape::process()
2844 if (myShape.IsNull() || myMesh == 0)
2847 if (myType == SMDSAbs_Node)
2849 SMDS_NodeIteratorPtr anIter = myMesh->nodesIterator();
2850 while (anIter->more())
2851 process(anIter->next());
2855 if (myType == SMDSAbs_Edge || myType == SMDSAbs_All)
2857 SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
2858 while (anIter->more())
2859 process(anIter->next());
2862 if (myType == SMDSAbs_Face || myType == SMDSAbs_All)
2864 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
2865 while (anIter->more()) {
2866 process(anIter->next());
2870 if (myType == SMDSAbs_Volume || myType == SMDSAbs_All)
2872 SMDS_VolumeIteratorPtr anIter = myMesh->volumesIterator();
2873 while (anIter->more())
2874 process(anIter->next());
2879 void ElementsOnShape::process (const SMDS_MeshElement* theElemPtr)
2881 if (myShape.IsNull())
2884 SMDS_ElemIteratorPtr aNodeItr = theElemPtr->nodesIterator();
2885 bool isSatisfy = myAllNodesFlag;
2887 while (aNodeItr->more() && (isSatisfy == myAllNodesFlag))
2889 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
2890 gp_Pnt aPnt (aNode->X(), aNode->Y(), aNode->Z());
2892 switch (myCurShapeType)
2896 myCurSC.Perform(aPnt, myToler);
2897 isSatisfy = (myCurSC.State() == TopAbs_IN || myCurSC.State() == TopAbs_ON);
2902 myCurProjFace.Perform(aPnt);
2903 isSatisfy = (myCurProjFace.IsDone() && myCurProjFace.LowerDistance() <= myToler);
2906 // check relatively the face
2907 Quantity_Parameter u, v;
2908 myCurProjFace.LowerDistanceParameters(u, v);
2909 gp_Pnt2d aProjPnt (u, v);
2910 BRepClass_FaceClassifier aClsf (myCurFace, aProjPnt, myToler);
2911 isSatisfy = (aClsf.State() == TopAbs_IN || aClsf.State() == TopAbs_ON);
2917 myCurProjEdge.Perform(aPnt);
2918 isSatisfy = (myCurProjEdge.NbPoints() > 0 && myCurProjEdge.LowerDistance() <= myToler);
2923 isSatisfy = (aPnt.Distance(myCurPnt) <= myToler);
2934 myIds.Add(theElemPtr->GetID());