1 // Copyright (C) 2007-2010 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
23 #include "SMESH_ControlsDef.hxx"
27 #include <BRepAdaptor_Surface.hxx>
28 #include <BRepClass_FaceClassifier.hxx>
29 #include <BRep_Tool.hxx>
33 #include <TopoDS_Edge.hxx>
34 #include <TopoDS_Face.hxx>
35 #include <TopoDS_Shape.hxx>
36 #include <TopoDS_Vertex.hxx>
37 #include <TopoDS_Iterator.hxx>
39 #include <Geom_CylindricalSurface.hxx>
40 #include <Geom_Plane.hxx>
41 #include <Geom_Surface.hxx>
43 #include <Precision.hxx>
44 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
45 #include <TColStd_MapOfInteger.hxx>
46 #include <TColStd_SequenceOfAsciiString.hxx>
47 #include <TColgp_Array1OfXYZ.hxx>
50 #include <gp_Cylinder.hxx>
57 #include "SMDS_Mesh.hxx"
58 #include "SMDS_Iterator.hxx"
59 #include "SMDS_MeshElement.hxx"
60 #include "SMDS_MeshNode.hxx"
61 #include "SMDS_VolumeTool.hxx"
62 #include "SMDS_QuadraticFaceOfNodes.hxx"
63 #include "SMDS_QuadraticEdge.hxx"
65 #include "SMESHDS_Mesh.hxx"
66 #include "SMESHDS_GroupBase.hxx"
74 inline gp_XYZ gpXYZ(const SMDS_MeshNode* aNode )
76 return gp_XYZ(aNode->X(), aNode->Y(), aNode->Z() );
79 inline double getAngle( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
81 gp_Vec v1( P1 - P2 ), v2( P3 - P2 );
83 return v1.Magnitude() < gp::Resolution() ||
84 v2.Magnitude() < gp::Resolution() ? 0 : v1.Angle( v2 );
87 inline double getArea( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
89 gp_Vec aVec1( P2 - P1 );
90 gp_Vec aVec2( P3 - P1 );
91 return ( aVec1 ^ aVec2 ).Magnitude() * 0.5;
94 inline double getArea( const gp_Pnt& P1, const gp_Pnt& P2, const gp_Pnt& P3 )
96 return getArea( P1.XYZ(), P2.XYZ(), P3.XYZ() );
101 inline double getDistance( const gp_XYZ& P1, const gp_XYZ& P2 )
103 double aDist = gp_Pnt( P1 ).Distance( gp_Pnt( P2 ) );
107 int getNbMultiConnection( const SMDS_Mesh* theMesh, const int theId )
112 const SMDS_MeshElement* anEdge = theMesh->FindElement( theId );
113 if ( anEdge == 0 || anEdge->GetType() != SMDSAbs_Edge/* || anEdge->NbNodes() != 2 */)
116 // for each pair of nodes in anEdge (there are 2 pairs in a quadratic edge)
117 // count elements containing both nodes of the pair.
118 // Note that there may be such cases for a quadratic edge (a horizontal line):
123 // +-----+------+ +-----+------+
126 // result sould be 2 in both cases
128 int aResult0 = 0, aResult1 = 0;
129 // last node, it is a medium one in a quadratic edge
130 const SMDS_MeshNode* aLastNode = anEdge->GetNode( anEdge->NbNodes() - 1 );
131 const SMDS_MeshNode* aNode0 = anEdge->GetNode( 0 );
132 const SMDS_MeshNode* aNode1 = anEdge->GetNode( 1 );
133 if ( aNode1 == aLastNode ) aNode1 = 0;
135 SMDS_ElemIteratorPtr anElemIter = aLastNode->GetInverseElementIterator();
136 while( anElemIter->more() ) {
137 const SMDS_MeshElement* anElem = anElemIter->next();
138 if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) {
139 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
140 while ( anIter->more() ) {
141 if ( const SMDS_MeshElement* anElemNode = anIter->next() ) {
142 if ( anElemNode == aNode0 ) {
144 if ( !aNode1 ) break; // not a quadratic edge
146 else if ( anElemNode == aNode1 )
152 int aResult = std::max ( aResult0, aResult1 );
154 // TColStd_MapOfInteger aMap;
156 // SMDS_ElemIteratorPtr anIter = anEdge->nodesIterator();
157 // if ( anIter != 0 ) {
158 // while( anIter->more() ) {
159 // const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next();
162 // SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator();
163 // while( anElemIter->more() ) {
164 // const SMDS_MeshElement* anElem = anElemIter->next();
165 // if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) {
166 // int anId = anElem->GetID();
168 // if ( anIter->more() ) // i.e. first node
170 // else if ( aMap.Contains( anId ) )
180 gp_XYZ getNormale( const SMDS_MeshFace* theFace, bool* ok=0 )
182 int aNbNode = theFace->NbNodes();
184 gp_XYZ q1 = gpXYZ( theFace->GetNode(1)) - gpXYZ( theFace->GetNode(0));
185 gp_XYZ q2 = gpXYZ( theFace->GetNode(2)) - gpXYZ( theFace->GetNode(0));
188 gp_XYZ q3 = gpXYZ( theFace->GetNode(3)) - gpXYZ( theFace->GetNode(0));
191 double len = n.Modulus();
192 bool zeroLen = ( len <= numeric_limits<double>::min());
196 if (ok) *ok = !zeroLen;
204 using namespace SMESH::Controls;
211 Class : NumericalFunctor
212 Description : Base class for numerical functors
214 NumericalFunctor::NumericalFunctor():
220 void NumericalFunctor::SetMesh( const SMDS_Mesh* theMesh )
225 bool NumericalFunctor::GetPoints(const int theId,
226 TSequenceOfXYZ& theRes ) const
233 return GetPoints( myMesh->FindElement( theId ), theRes );
236 bool NumericalFunctor::GetPoints(const SMDS_MeshElement* anElem,
237 TSequenceOfXYZ& theRes )
244 theRes.reserve( anElem->NbNodes() );
246 // Get nodes of the element
247 SMDS_ElemIteratorPtr anIter;
249 if ( anElem->IsQuadratic() ) {
250 switch ( anElem->GetType() ) {
252 anIter = static_cast<const SMDS_QuadraticEdge*>
253 (anElem)->interlacedNodesElemIterator();
256 anIter = static_cast<const SMDS_QuadraticFaceOfNodes*>
257 (anElem)->interlacedNodesElemIterator();
260 anIter = anElem->nodesIterator();
265 anIter = anElem->nodesIterator();
269 while( anIter->more() ) {
270 if ( const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>( anIter->next() ))
271 theRes.push_back( gp_XYZ( aNode->X(), aNode->Y(), aNode->Z() ) );
278 long NumericalFunctor::GetPrecision() const
283 void NumericalFunctor::SetPrecision( const long thePrecision )
285 myPrecision = thePrecision;
288 double NumericalFunctor::GetValue( long theId )
290 myCurrElement = myMesh->FindElement( theId );
292 if ( GetPoints( theId, P ))
294 double aVal = GetValue( P );
295 if ( myPrecision >= 0 )
297 double prec = pow( 10., (double)( myPrecision ) );
298 aVal = floor( aVal * prec + 0.5 ) / prec;
306 //=======================================================================
307 //function : GetValue
309 //=======================================================================
311 double Volume::GetValue( long theElementId )
313 if ( theElementId && myMesh ) {
314 SMDS_VolumeTool aVolumeTool;
315 if ( aVolumeTool.Set( myMesh->FindElement( theElementId )))
316 return aVolumeTool.GetSize();
321 //=======================================================================
322 //function : GetBadRate
323 //purpose : meaningless as it is not quality control functor
324 //=======================================================================
326 double Volume::GetBadRate( double Value, int /*nbNodes*/ ) const
331 //=======================================================================
334 //=======================================================================
336 SMDSAbs_ElementType Volume::GetType() const
338 return SMDSAbs_Volume;
344 Description : Functor for calculation of minimum angle
347 double MinimumAngle::GetValue( const TSequenceOfXYZ& P )
354 aMin = getAngle(P( P.size() ), P( 1 ), P( 2 ));
355 aMin = Min(aMin,getAngle(P( P.size()-1 ), P( P.size() ), P( 1 )));
357 for (int i=2; i<P.size();i++){
358 double A0 = getAngle( P( i-1 ), P( i ), P( i+1 ) );
362 return aMin * 180.0 / PI;
365 double MinimumAngle::GetBadRate( double Value, int nbNodes ) const
367 //const double aBestAngle = PI / nbNodes;
368 const double aBestAngle = 180.0 - ( 360.0 / double(nbNodes) );
369 return ( fabs( aBestAngle - Value ));
372 SMDSAbs_ElementType MinimumAngle::GetType() const
380 Description : Functor for calculating aspect ratio
382 double AspectRatio::GetValue( const TSequenceOfXYZ& P )
384 // According to "Mesh quality control" by Nadir Bouhamau referring to
385 // Pascal Jean Frey and Paul-Louis George. Maillages, applications aux elements finis.
386 // Hermes Science publications, Paris 1999 ISBN 2-7462-0024-4
389 int nbNodes = P.size();
394 // Compute aspect ratio
396 if ( nbNodes == 3 ) {
397 // Compute lengths of the sides
398 std::vector< double > aLen (nbNodes);
399 for ( int i = 0; i < nbNodes - 1; i++ )
400 aLen[ i ] = getDistance( P( i + 1 ), P( i + 2 ) );
401 aLen[ nbNodes - 1 ] = getDistance( P( 1 ), P( nbNodes ) );
402 // Q = alfa * h * p / S, where
404 // alfa = sqrt( 3 ) / 6
405 // h - length of the longest edge
406 // p - half perimeter
407 // S - triangle surface
408 const double alfa = sqrt( 3. ) / 6.;
409 double maxLen = Max( aLen[ 0 ], Max( aLen[ 1 ], aLen[ 2 ] ) );
410 double half_perimeter = ( aLen[0] + aLen[1] + aLen[2] ) / 2.;
411 double anArea = getArea( P( 1 ), P( 2 ), P( 3 ) );
412 if ( anArea <= Precision::Confusion() )
414 return alfa * maxLen * half_perimeter / anArea;
416 else if ( nbNodes == 6 ) { // quadratic triangles
417 // Compute lengths of the sides
418 std::vector< double > aLen (3);
419 aLen[0] = getDistance( P(1), P(3) );
420 aLen[1] = getDistance( P(3), P(5) );
421 aLen[2] = getDistance( P(5), P(1) );
422 // Q = alfa * h * p / S, where
424 // alfa = sqrt( 3 ) / 6
425 // h - length of the longest edge
426 // p - half perimeter
427 // S - triangle surface
428 const double alfa = sqrt( 3. ) / 6.;
429 double maxLen = Max( aLen[ 0 ], Max( aLen[ 1 ], aLen[ 2 ] ) );
430 double half_perimeter = ( aLen[0] + aLen[1] + aLen[2] ) / 2.;
431 double anArea = getArea( P(1), P(3), P(5) );
432 if ( anArea <= Precision::Confusion() )
434 return alfa * maxLen * half_perimeter / anArea;
436 else if( nbNodes == 4 ) { // quadrangle
437 // return aspect ratio of the worst triange which can be built
438 // taking three nodes of the quadrangle
439 TSequenceOfXYZ triaPnts(3);
440 // triangle on nodes 1 3 2
444 double ar = GetValue( triaPnts );
445 // triangle on nodes 1 3 4
447 ar = Max ( ar, GetValue( triaPnts ));
448 // triangle on nodes 1 2 4
450 ar = Max ( ar, GetValue( triaPnts ));
451 // triangle on nodes 3 2 4
453 ar = Max ( ar, GetValue( triaPnts ));
457 else { // nbNodes==8 - quadratic quadrangle
458 // return aspect ratio of the worst triange which can be built
459 // taking three nodes of the quadrangle
460 TSequenceOfXYZ triaPnts(3);
461 // triangle on nodes 1 3 2
465 double ar = GetValue( triaPnts );
466 // triangle on nodes 1 3 4
468 ar = Max ( ar, GetValue( triaPnts ));
469 // triangle on nodes 1 2 4
471 ar = Max ( ar, GetValue( triaPnts ));
472 // triangle on nodes 3 2 4
474 ar = Max ( ar, GetValue( triaPnts ));
480 double AspectRatio::GetBadRate( double Value, int /*nbNodes*/ ) const
482 // the aspect ratio is in the range [1.0,infinity]
485 return Value / 1000.;
488 SMDSAbs_ElementType AspectRatio::GetType() const
495 Class : AspectRatio3D
496 Description : Functor for calculating aspect ratio
500 inline double getHalfPerimeter(double theTria[3]){
501 return (theTria[0] + theTria[1] + theTria[2])/2.0;
504 inline double getArea(double theHalfPerim, double theTria[3]){
505 return sqrt(theHalfPerim*
506 (theHalfPerim-theTria[0])*
507 (theHalfPerim-theTria[1])*
508 (theHalfPerim-theTria[2]));
511 inline double getVolume(double theLen[6]){
512 double a2 = theLen[0]*theLen[0];
513 double b2 = theLen[1]*theLen[1];
514 double c2 = theLen[2]*theLen[2];
515 double d2 = theLen[3]*theLen[3];
516 double e2 = theLen[4]*theLen[4];
517 double f2 = theLen[5]*theLen[5];
518 double P = 4.0*a2*b2*d2;
519 double Q = a2*(b2+d2-e2)-b2*(a2+d2-f2)-d2*(a2+b2-c2);
520 double R = (b2+d2-e2)*(a2+d2-f2)*(a2+d2-f2);
521 return sqrt(P-Q+R)/12.0;
524 inline double getVolume2(double theLen[6]){
525 double a2 = theLen[0]*theLen[0];
526 double b2 = theLen[1]*theLen[1];
527 double c2 = theLen[2]*theLen[2];
528 double d2 = theLen[3]*theLen[3];
529 double e2 = theLen[4]*theLen[4];
530 double f2 = theLen[5]*theLen[5];
532 double P = a2*e2*(b2+c2+d2+f2-a2-e2);
533 double Q = b2*f2*(a2+c2+d2+e2-b2-f2);
534 double R = c2*d2*(a2+b2+e2+f2-c2-d2);
535 double S = a2*b2*d2+b2*c2*e2+a2*c2*f2+d2*e2*f2;
537 return sqrt(P+Q+R-S)/12.0;
540 inline double getVolume(const TSequenceOfXYZ& P){
541 gp_Vec aVec1( P( 2 ) - P( 1 ) );
542 gp_Vec aVec2( P( 3 ) - P( 1 ) );
543 gp_Vec aVec3( P( 4 ) - P( 1 ) );
544 gp_Vec anAreaVec( aVec1 ^ aVec2 );
545 return fabs(aVec3 * anAreaVec) / 6.0;
548 inline double getMaxHeight(double theLen[6])
550 double aHeight = std::max(theLen[0],theLen[1]);
551 aHeight = std::max(aHeight,theLen[2]);
552 aHeight = std::max(aHeight,theLen[3]);
553 aHeight = std::max(aHeight,theLen[4]);
554 aHeight = std::max(aHeight,theLen[5]);
560 double AspectRatio3D::GetValue( const TSequenceOfXYZ& P )
562 double aQuality = 0.0;
563 if(myCurrElement->IsPoly()) return aQuality;
565 int nbNodes = P.size();
567 if(myCurrElement->IsQuadratic()) {
568 if(nbNodes==10) nbNodes=4; // quadratic tetrahedron
569 else if(nbNodes==13) nbNodes=5; // quadratic pyramid
570 else if(nbNodes==15) nbNodes=6; // quadratic pentahedron
571 else if(nbNodes==20) nbNodes=8; // quadratic hexahedron
572 else return aQuality;
578 getDistance(P( 1 ),P( 2 )), // a
579 getDistance(P( 2 ),P( 3 )), // b
580 getDistance(P( 3 ),P( 1 )), // c
581 getDistance(P( 2 ),P( 4 )), // d
582 getDistance(P( 3 ),P( 4 )), // e
583 getDistance(P( 1 ),P( 4 )) // f
585 double aTria[4][3] = {
586 {aLen[0],aLen[1],aLen[2]}, // abc
587 {aLen[0],aLen[3],aLen[5]}, // adf
588 {aLen[1],aLen[3],aLen[4]}, // bde
589 {aLen[2],aLen[4],aLen[5]} // cef
591 double aSumArea = 0.0;
592 double aHalfPerimeter = getHalfPerimeter(aTria[0]);
593 double anArea = getArea(aHalfPerimeter,aTria[0]);
595 aHalfPerimeter = getHalfPerimeter(aTria[1]);
596 anArea = getArea(aHalfPerimeter,aTria[1]);
598 aHalfPerimeter = getHalfPerimeter(aTria[2]);
599 anArea = getArea(aHalfPerimeter,aTria[2]);
601 aHalfPerimeter = getHalfPerimeter(aTria[3]);
602 anArea = getArea(aHalfPerimeter,aTria[3]);
604 double aVolume = getVolume(P);
605 //double aVolume = getVolume(aLen);
606 double aHeight = getMaxHeight(aLen);
607 static double aCoeff = sqrt(2.0)/12.0;
608 if ( aVolume > DBL_MIN )
609 aQuality = aCoeff*aHeight*aSumArea/aVolume;
614 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 3 ),P( 5 )};
615 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
618 gp_XYZ aXYZ[4] = {P( 1 ),P( 3 ),P( 4 ),P( 5 )};
619 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
622 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 5 )};
623 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
626 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 4 ),P( 5 )};
627 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
633 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 6 )};
634 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
637 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 3 )};
638 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
641 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 6 )};
642 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
645 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
646 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
649 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 6 )};
650 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
653 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 3 )};
654 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
660 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
661 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
664 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 4 )};
665 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
668 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 7 )};
669 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
672 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 8 )};
673 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
676 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 3 )};
677 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
680 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 4 )};
681 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
684 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 7 )};
685 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
688 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 8 )};
689 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
692 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 3 )};
693 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
696 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 4 )};
697 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
700 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 7 )};
701 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
704 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 8 )};
705 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
708 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 1 )};
709 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
712 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 2 )};
713 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
716 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 5 )};
717 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
720 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 6 )};
721 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
724 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 1 )};
725 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
728 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 2 )};
729 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
732 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 5 )};
733 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
736 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 6 )};
737 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
740 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 1 )};
741 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
744 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
745 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
748 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 5 )};
749 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
752 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 6 )};
753 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
756 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
757 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
760 gp_XYZ aXYZ[4] = {P( 4 ),P( 5 ),P( 8 ),P( 2 )};
761 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
764 gp_XYZ aXYZ[4] = {P( 1 ),P( 4 ),P( 5 ),P( 3 )};
765 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
768 gp_XYZ aXYZ[4] = {P( 3 ),P( 6 ),P( 7 ),P( 1 )};
769 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
772 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 6 ),P( 4 )};
773 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
776 gp_XYZ aXYZ[4] = {P( 5 ),P( 6 ),P( 8 ),P( 3 )};
777 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
780 gp_XYZ aXYZ[4] = {P( 7 ),P( 8 ),P( 6 ),P( 1 )};
781 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
784 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 7 )};
785 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
788 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 2 ),P( 5 )};
789 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
795 // avaluate aspect ratio of quadranle faces
796 AspectRatio aspect2D;
797 SMDS_VolumeTool::VolumeType type = SMDS_VolumeTool::GetType( nbNodes );
798 int nbFaces = SMDS_VolumeTool::NbFaces( type );
799 TSequenceOfXYZ points(4);
800 for ( int i = 0; i < nbFaces; ++i ) { // loop on faces of a volume
801 if ( SMDS_VolumeTool::NbFaceNodes( type, i ) != 4 )
803 const int* pInd = SMDS_VolumeTool::GetFaceNodesIndices( type, i, true );
804 for ( int p = 0; p < 4; ++p ) // loop on nodes of a quadranle face
805 points( p + 1 ) = P( pInd[ p ] + 1 );
806 aQuality = std::max( aQuality, aspect2D.GetValue( points ));
812 double AspectRatio3D::GetBadRate( double Value, int /*nbNodes*/ ) const
814 // the aspect ratio is in the range [1.0,infinity]
817 return Value / 1000.;
820 SMDSAbs_ElementType AspectRatio3D::GetType() const
822 return SMDSAbs_Volume;
828 Description : Functor for calculating warping
830 double Warping::GetValue( const TSequenceOfXYZ& P )
835 gp_XYZ G = ( P( 1 ) + P( 2 ) + P( 3 ) + P( 4 ) ) / 4.;
837 double A1 = ComputeA( P( 1 ), P( 2 ), P( 3 ), G );
838 double A2 = ComputeA( P( 2 ), P( 3 ), P( 4 ), G );
839 double A3 = ComputeA( P( 3 ), P( 4 ), P( 1 ), G );
840 double A4 = ComputeA( P( 4 ), P( 1 ), P( 2 ), G );
842 return Max( Max( A1, A2 ), Max( A3, A4 ) );
845 double Warping::ComputeA( const gp_XYZ& thePnt1,
846 const gp_XYZ& thePnt2,
847 const gp_XYZ& thePnt3,
848 const gp_XYZ& theG ) const
850 double aLen1 = gp_Pnt( thePnt1 ).Distance( gp_Pnt( thePnt2 ) );
851 double aLen2 = gp_Pnt( thePnt2 ).Distance( gp_Pnt( thePnt3 ) );
852 double L = Min( aLen1, aLen2 ) * 0.5;
853 if ( L < Precision::Confusion())
856 gp_XYZ GI = ( thePnt2 + thePnt1 ) / 2. - theG;
857 gp_XYZ GJ = ( thePnt3 + thePnt2 ) / 2. - theG;
858 gp_XYZ N = GI.Crossed( GJ );
860 if ( N.Modulus() < gp::Resolution() )
865 double H = ( thePnt2 - theG ).Dot( N );
866 return asin( fabs( H / L ) ) * 180. / PI;
869 double Warping::GetBadRate( double Value, int /*nbNodes*/ ) const
871 // the warp is in the range [0.0,PI/2]
872 // 0.0 = good (no warp)
873 // PI/2 = bad (face pliee)
877 SMDSAbs_ElementType Warping::GetType() const
885 Description : Functor for calculating taper
887 double Taper::GetValue( const TSequenceOfXYZ& P )
893 double J1 = getArea( P( 4 ), P( 1 ), P( 2 ) ) / 2.;
894 double J2 = getArea( P( 3 ), P( 1 ), P( 2 ) ) / 2.;
895 double J3 = getArea( P( 2 ), P( 3 ), P( 4 ) ) / 2.;
896 double J4 = getArea( P( 3 ), P( 4 ), P( 1 ) ) / 2.;
898 double JA = 0.25 * ( J1 + J2 + J3 + J4 );
899 if ( JA <= Precision::Confusion() )
902 double T1 = fabs( ( J1 - JA ) / JA );
903 double T2 = fabs( ( J2 - JA ) / JA );
904 double T3 = fabs( ( J3 - JA ) / JA );
905 double T4 = fabs( ( J4 - JA ) / JA );
907 return Max( Max( T1, T2 ), Max( T3, T4 ) );
910 double Taper::GetBadRate( double Value, int /*nbNodes*/ ) const
912 // the taper is in the range [0.0,1.0]
913 // 0.0 = good (no taper)
914 // 1.0 = bad (les cotes opposes sont allignes)
918 SMDSAbs_ElementType Taper::GetType() const
926 Description : Functor for calculating skew in degrees
928 static inline double skewAngle( const gp_XYZ& p1, const gp_XYZ& p2, const gp_XYZ& p3 )
930 gp_XYZ p12 = ( p2 + p1 ) / 2.;
931 gp_XYZ p23 = ( p3 + p2 ) / 2.;
932 gp_XYZ p31 = ( p3 + p1 ) / 2.;
934 gp_Vec v1( p31 - p2 ), v2( p12 - p23 );
936 return v1.Magnitude() < gp::Resolution() || v2.Magnitude() < gp::Resolution() ? 0. : v1.Angle( v2 );
939 double Skew::GetValue( const TSequenceOfXYZ& P )
941 if ( P.size() != 3 && P.size() != 4 )
945 static double PI2 = PI / 2.;
948 double A0 = fabs( PI2 - skewAngle( P( 3 ), P( 1 ), P( 2 ) ) );
949 double A1 = fabs( PI2 - skewAngle( P( 1 ), P( 2 ), P( 3 ) ) );
950 double A2 = fabs( PI2 - skewAngle( P( 2 ), P( 3 ), P( 1 ) ) );
952 return Max( A0, Max( A1, A2 ) ) * 180. / PI;
956 gp_XYZ p12 = ( P( 1 ) + P( 2 ) ) / 2.;
957 gp_XYZ p23 = ( P( 2 ) + P( 3 ) ) / 2.;
958 gp_XYZ p34 = ( P( 3 ) + P( 4 ) ) / 2.;
959 gp_XYZ p41 = ( P( 4 ) + P( 1 ) ) / 2.;
961 gp_Vec v1( p34 - p12 ), v2( p23 - p41 );
962 double A = v1.Magnitude() <= gp::Resolution() || v2.Magnitude() <= gp::Resolution()
963 ? 0. : fabs( PI2 - v1.Angle( v2 ) );
966 if ( A < Precision::Angular() )
969 return A * 180. / PI;
973 double Skew::GetBadRate( double Value, int /*nbNodes*/ ) const
975 // the skew is in the range [0.0,PI/2].
981 SMDSAbs_ElementType Skew::GetType() const
989 Description : Functor for calculating area
991 double Area::GetValue( const TSequenceOfXYZ& P )
993 gp_Vec aVec1( P(2) - P(1) );
994 gp_Vec aVec2( P(3) - P(1) );
995 gp_Vec SumVec = aVec1 ^ aVec2;
996 for (int i=4; i<=P.size(); i++) {
997 gp_Vec aVec1( P(i-1) - P(1) );
998 gp_Vec aVec2( P(i) - P(1) );
999 gp_Vec tmp = aVec1 ^ aVec2;
1002 return SumVec.Magnitude() * 0.5;
1005 double Area::GetBadRate( double Value, int /*nbNodes*/ ) const
1007 // meaningless as it is not a quality control functor
1011 SMDSAbs_ElementType Area::GetType() const
1013 return SMDSAbs_Face;
1019 Description : Functor for calculating length off edge
1021 double Length::GetValue( const TSequenceOfXYZ& P )
1023 switch ( P.size() ) {
1024 case 2: return getDistance( P( 1 ), P( 2 ) );
1025 case 3: return getDistance( P( 1 ), P( 2 ) ) + getDistance( P( 2 ), P( 3 ) );
1030 double Length::GetBadRate( double Value, int /*nbNodes*/ ) const
1032 // meaningless as it is not quality control functor
1036 SMDSAbs_ElementType Length::GetType() const
1038 return SMDSAbs_Edge;
1043 Description : Functor for calculating length of edge
1046 double Length2D::GetValue( long theElementId)
1050 //cout<<"Length2D::GetValue"<<endl;
1051 if (GetPoints(theElementId,P)){
1052 //for(int jj=1; jj<=P.size(); jj++)
1053 // cout<<"jj="<<jj<<" P("<<P(jj).X()<<","<<P(jj).Y()<<","<<P(jj).Z()<<")"<<endl;
1055 double aVal;// = GetValue( P );
1056 const SMDS_MeshElement* aElem = myMesh->FindElement( theElementId );
1057 SMDSAbs_ElementType aType = aElem->GetType();
1066 aVal = getDistance( P( 1 ), P( 2 ) );
1069 else if (len == 3){ // quadratic edge
1070 aVal = getDistance(P( 1 ),P( 3 )) + getDistance(P( 3 ),P( 2 ));
1074 if (len == 3){ // triangles
1075 double L1 = getDistance(P( 1 ),P( 2 ));
1076 double L2 = getDistance(P( 2 ),P( 3 ));
1077 double L3 = getDistance(P( 3 ),P( 1 ));
1078 aVal = Max(L1,Max(L2,L3));
1081 else if (len == 4){ // quadrangles
1082 double L1 = getDistance(P( 1 ),P( 2 ));
1083 double L2 = getDistance(P( 2 ),P( 3 ));
1084 double L3 = getDistance(P( 3 ),P( 4 ));
1085 double L4 = getDistance(P( 4 ),P( 1 ));
1086 aVal = Max(Max(L1,L2),Max(L3,L4));
1089 if (len == 6){ // quadratic triangles
1090 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1091 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1092 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 1 ));
1093 aVal = Max(L1,Max(L2,L3));
1094 //cout<<"L1="<<L1<<" L2="<<L2<<"L3="<<L3<<" aVal="<<aVal<<endl;
1097 else if (len == 8){ // quadratic quadrangles
1098 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1099 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1100 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 7 ));
1101 double L4 = getDistance(P( 7 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
1102 aVal = Max(Max(L1,L2),Max(L3,L4));
1105 case SMDSAbs_Volume:
1106 if (len == 4){ // tetraidrs
1107 double L1 = getDistance(P( 1 ),P( 2 ));
1108 double L2 = getDistance(P( 2 ),P( 3 ));
1109 double L3 = getDistance(P( 3 ),P( 1 ));
1110 double L4 = getDistance(P( 1 ),P( 4 ));
1111 double L5 = getDistance(P( 2 ),P( 4 ));
1112 double L6 = getDistance(P( 3 ),P( 4 ));
1113 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1116 else if (len == 5){ // piramids
1117 double L1 = getDistance(P( 1 ),P( 2 ));
1118 double L2 = getDistance(P( 2 ),P( 3 ));
1119 double L3 = getDistance(P( 3 ),P( 1 ));
1120 double L4 = getDistance(P( 4 ),P( 1 ));
1121 double L5 = getDistance(P( 1 ),P( 5 ));
1122 double L6 = getDistance(P( 2 ),P( 5 ));
1123 double L7 = getDistance(P( 3 ),P( 5 ));
1124 double L8 = getDistance(P( 4 ),P( 5 ));
1126 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1127 aVal = Max(aVal,Max(L7,L8));
1130 else if (len == 6){ // pentaidres
1131 double L1 = getDistance(P( 1 ),P( 2 ));
1132 double L2 = getDistance(P( 2 ),P( 3 ));
1133 double L3 = getDistance(P( 3 ),P( 1 ));
1134 double L4 = getDistance(P( 4 ),P( 5 ));
1135 double L5 = getDistance(P( 5 ),P( 6 ));
1136 double L6 = getDistance(P( 6 ),P( 4 ));
1137 double L7 = getDistance(P( 1 ),P( 4 ));
1138 double L8 = getDistance(P( 2 ),P( 5 ));
1139 double L9 = getDistance(P( 3 ),P( 6 ));
1141 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1142 aVal = Max(aVal,Max(Max(L7,L8),L9));
1145 else if (len == 8){ // hexaider
1146 double L1 = getDistance(P( 1 ),P( 2 ));
1147 double L2 = getDistance(P( 2 ),P( 3 ));
1148 double L3 = getDistance(P( 3 ),P( 4 ));
1149 double L4 = getDistance(P( 4 ),P( 1 ));
1150 double L5 = getDistance(P( 5 ),P( 6 ));
1151 double L6 = getDistance(P( 6 ),P( 7 ));
1152 double L7 = getDistance(P( 7 ),P( 8 ));
1153 double L8 = getDistance(P( 8 ),P( 5 ));
1154 double L9 = getDistance(P( 1 ),P( 5 ));
1155 double L10= getDistance(P( 2 ),P( 6 ));
1156 double L11= getDistance(P( 3 ),P( 7 ));
1157 double L12= getDistance(P( 4 ),P( 8 ));
1159 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1160 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
1161 aVal = Max(aVal,Max(L11,L12));
1166 if (len == 10){ // quadratic tetraidrs
1167 double L1 = getDistance(P( 1 ),P( 5 )) + getDistance(P( 5 ),P( 2 ));
1168 double L2 = getDistance(P( 2 ),P( 6 )) + getDistance(P( 6 ),P( 3 ));
1169 double L3 = getDistance(P( 3 ),P( 7 )) + getDistance(P( 7 ),P( 1 ));
1170 double L4 = getDistance(P( 1 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
1171 double L5 = getDistance(P( 2 ),P( 9 )) + getDistance(P( 9 ),P( 4 ));
1172 double L6 = getDistance(P( 3 ),P( 10 )) + getDistance(P( 10 ),P( 4 ));
1173 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1176 else if (len == 13){ // quadratic piramids
1177 double L1 = getDistance(P( 1 ),P( 6 )) + getDistance(P( 6 ),P( 2 ));
1178 double L2 = getDistance(P( 2 ),P( 7 )) + getDistance(P( 7 ),P( 3 ));
1179 double L3 = getDistance(P( 3 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
1180 double L4 = getDistance(P( 4 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1181 double L5 = getDistance(P( 1 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1182 double L6 = getDistance(P( 2 ),P( 11 )) + getDistance(P( 11 ),P( 5 ));
1183 double L7 = getDistance(P( 3 ),P( 12 )) + getDistance(P( 12 ),P( 5 ));
1184 double L8 = getDistance(P( 4 ),P( 13 )) + getDistance(P( 13 ),P( 5 ));
1185 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1186 aVal = Max(aVal,Max(L7,L8));
1189 else if (len == 15){ // quadratic pentaidres
1190 double L1 = getDistance(P( 1 ),P( 7 )) + getDistance(P( 7 ),P( 2 ));
1191 double L2 = getDistance(P( 2 ),P( 8 )) + getDistance(P( 8 ),P( 3 ));
1192 double L3 = getDistance(P( 3 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1193 double L4 = getDistance(P( 4 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1194 double L5 = getDistance(P( 5 ),P( 11 )) + getDistance(P( 11 ),P( 6 ));
1195 double L6 = getDistance(P( 6 ),P( 12 )) + getDistance(P( 12 ),P( 4 ));
1196 double L7 = getDistance(P( 1 ),P( 13 )) + getDistance(P( 13 ),P( 4 ));
1197 double L8 = getDistance(P( 2 ),P( 14 )) + getDistance(P( 14 ),P( 5 ));
1198 double L9 = getDistance(P( 3 ),P( 15 )) + getDistance(P( 15 ),P( 6 ));
1199 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1200 aVal = Max(aVal,Max(Max(L7,L8),L9));
1203 else if (len == 20){ // quadratic hexaider
1204 double L1 = getDistance(P( 1 ),P( 9 )) + getDistance(P( 9 ),P( 2 ));
1205 double L2 = getDistance(P( 2 ),P( 10 )) + getDistance(P( 10 ),P( 3 ));
1206 double L3 = getDistance(P( 3 ),P( 11 )) + getDistance(P( 11 ),P( 4 ));
1207 double L4 = getDistance(P( 4 ),P( 12 )) + getDistance(P( 12 ),P( 1 ));
1208 double L5 = getDistance(P( 5 ),P( 13 )) + getDistance(P( 13 ),P( 6 ));
1209 double L6 = getDistance(P( 6 ),P( 14 )) + getDistance(P( 14 ),P( 7 ));
1210 double L7 = getDistance(P( 7 ),P( 15 )) + getDistance(P( 15 ),P( 8 ));
1211 double L8 = getDistance(P( 8 ),P( 16 )) + getDistance(P( 16 ),P( 5 ));
1212 double L9 = getDistance(P( 1 ),P( 17 )) + getDistance(P( 17 ),P( 5 ));
1213 double L10= getDistance(P( 2 ),P( 18 )) + getDistance(P( 18 ),P( 6 ));
1214 double L11= getDistance(P( 3 ),P( 19 )) + getDistance(P( 19 ),P( 7 ));
1215 double L12= getDistance(P( 4 ),P( 20 )) + getDistance(P( 20 ),P( 8 ));
1216 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1217 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
1218 aVal = Max(aVal,Max(L11,L12));
1230 if ( myPrecision >= 0 )
1232 double prec = pow( 10., (double)( myPrecision ) );
1233 aVal = floor( aVal * prec + 0.5 ) / prec;
1242 double Length2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1244 // meaningless as it is not quality control functor
1248 SMDSAbs_ElementType Length2D::GetType() const
1250 return SMDSAbs_Face;
1253 Length2D::Value::Value(double theLength,long thePntId1, long thePntId2):
1256 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1257 if(thePntId1 > thePntId2){
1258 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1262 bool Length2D::Value::operator<(const Length2D::Value& x) const{
1263 if(myPntId[0] < x.myPntId[0]) return true;
1264 if(myPntId[0] == x.myPntId[0])
1265 if(myPntId[1] < x.myPntId[1]) return true;
1269 void Length2D::GetValues(TValues& theValues){
1271 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1272 for(; anIter->more(); ){
1273 const SMDS_MeshFace* anElem = anIter->next();
1275 if(anElem->IsQuadratic()) {
1276 const SMDS_QuadraticFaceOfNodes* F =
1277 static_cast<const SMDS_QuadraticFaceOfNodes*>(anElem);
1278 // use special nodes iterator
1279 SMDS_NodeIteratorPtr anIter = F->interlacedNodesIterator();
1284 const SMDS_MeshElement* aNode;
1286 aNode = anIter->next();
1287 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1288 P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1289 aNodeId[0] = aNodeId[1] = aNode->GetID();
1292 for(; anIter->more(); ){
1293 const SMDS_MeshNode* N1 = static_cast<const SMDS_MeshNode*> (anIter->next());
1294 P[2] = gp_Pnt(N1->X(),N1->Y(),N1->Z());
1295 aNodeId[2] = N1->GetID();
1296 aLength = P[1].Distance(P[2]);
1297 if(!anIter->more()) break;
1298 const SMDS_MeshNode* N2 = static_cast<const SMDS_MeshNode*> (anIter->next());
1299 P[3] = gp_Pnt(N2->X(),N2->Y(),N2->Z());
1300 aNodeId[3] = N2->GetID();
1301 aLength += P[2].Distance(P[3]);
1302 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1303 Value aValue2(aLength,aNodeId[2],aNodeId[3]);
1305 aNodeId[1] = aNodeId[3];
1306 theValues.insert(aValue1);
1307 theValues.insert(aValue2);
1309 aLength += P[2].Distance(P[0]);
1310 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1311 Value aValue2(aLength,aNodeId[2],aNodeId[0]);
1312 theValues.insert(aValue1);
1313 theValues.insert(aValue2);
1316 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
1321 const SMDS_MeshElement* aNode;
1322 if(aNodesIter->more()){
1323 aNode = aNodesIter->next();
1324 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1325 P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1326 aNodeId[0] = aNodeId[1] = aNode->GetID();
1329 for(; aNodesIter->more(); ){
1330 aNode = aNodesIter->next();
1331 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1332 long anId = aNode->GetID();
1334 P[2] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1336 aLength = P[1].Distance(P[2]);
1338 Value aValue(aLength,aNodeId[1],anId);
1341 theValues.insert(aValue);
1344 aLength = P[0].Distance(P[1]);
1346 Value aValue(aLength,aNodeId[0],aNodeId[1]);
1347 theValues.insert(aValue);
1353 Class : MultiConnection
1354 Description : Functor for calculating number of faces conneted to the edge
1356 double MultiConnection::GetValue( const TSequenceOfXYZ& P )
1360 double MultiConnection::GetValue( long theId )
1362 return getNbMultiConnection( myMesh, theId );
1365 double MultiConnection::GetBadRate( double Value, int /*nbNodes*/ ) const
1367 // meaningless as it is not quality control functor
1371 SMDSAbs_ElementType MultiConnection::GetType() const
1373 return SMDSAbs_Edge;
1377 Class : MultiConnection2D
1378 Description : Functor for calculating number of faces conneted to the edge
1380 double MultiConnection2D::GetValue( const TSequenceOfXYZ& P )
1385 double MultiConnection2D::GetValue( long theElementId )
1389 const SMDS_MeshElement* aFaceElem = myMesh->FindElement(theElementId);
1390 SMDSAbs_ElementType aType = aFaceElem->GetType();
1395 int i = 0, len = aFaceElem->NbNodes();
1396 SMDS_ElemIteratorPtr anIter = aFaceElem->nodesIterator();
1399 const SMDS_MeshNode *aNode, *aNode0;
1400 TColStd_MapOfInteger aMap, aMapPrev;
1402 for (i = 0; i <= len; i++) {
1407 if (anIter->more()) {
1408 aNode = (SMDS_MeshNode*)anIter->next();
1416 if (i == 0) aNode0 = aNode;
1418 SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator();
1419 while (anElemIter->more()) {
1420 const SMDS_MeshElement* anElem = anElemIter->next();
1421 if (anElem != 0 && anElem->GetType() == SMDSAbs_Face) {
1422 int anId = anElem->GetID();
1425 if (aMapPrev.Contains(anId)) {
1430 aResult = Max(aResult, aNb);
1441 double MultiConnection2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1443 // meaningless as it is not quality control functor
1447 SMDSAbs_ElementType MultiConnection2D::GetType() const
1449 return SMDSAbs_Face;
1452 MultiConnection2D::Value::Value(long thePntId1, long thePntId2)
1454 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1455 if(thePntId1 > thePntId2){
1456 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1460 bool MultiConnection2D::Value::operator<(const MultiConnection2D::Value& x) const{
1461 if(myPntId[0] < x.myPntId[0]) return true;
1462 if(myPntId[0] == x.myPntId[0])
1463 if(myPntId[1] < x.myPntId[1]) return true;
1467 void MultiConnection2D::GetValues(MValues& theValues){
1468 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1469 for(; anIter->more(); ){
1470 const SMDS_MeshFace* anElem = anIter->next();
1471 SMDS_ElemIteratorPtr aNodesIter;
1472 if ( anElem->IsQuadratic() )
1473 aNodesIter = static_cast<const SMDS_QuadraticFaceOfNodes*>
1474 (anElem)->interlacedNodesElemIterator();
1476 aNodesIter = anElem->nodesIterator();
1479 //int aNbConnects=0;
1480 const SMDS_MeshNode* aNode0;
1481 const SMDS_MeshNode* aNode1;
1482 const SMDS_MeshNode* aNode2;
1483 if(aNodesIter->more()){
1484 aNode0 = (SMDS_MeshNode*) aNodesIter->next();
1486 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode1;
1487 aNodeId[0] = aNodeId[1] = aNodes->GetID();
1489 for(; aNodesIter->more(); ) {
1490 aNode2 = (SMDS_MeshNode*) aNodesIter->next();
1491 long anId = aNode2->GetID();
1494 Value aValue(aNodeId[1],aNodeId[2]);
1495 MValues::iterator aItr = theValues.find(aValue);
1496 if (aItr != theValues.end()){
1501 theValues[aValue] = 1;
1504 //cout << "NodeIds: "<<aNodeId[1]<<","<<aNodeId[2]<<" nbconn="<<aNbConnects<<endl;
1505 aNodeId[1] = aNodeId[2];
1508 Value aValue(aNodeId[0],aNodeId[2]);
1509 MValues::iterator aItr = theValues.find(aValue);
1510 if (aItr != theValues.end()) {
1515 theValues[aValue] = 1;
1518 //cout << "NodeIds: "<<aNodeId[0]<<","<<aNodeId[2]<<" nbconn="<<aNbConnects<<endl;
1528 Class : BadOrientedVolume
1529 Description : Predicate bad oriented volumes
1532 BadOrientedVolume::BadOrientedVolume()
1537 void BadOrientedVolume::SetMesh( const SMDS_Mesh* theMesh )
1542 bool BadOrientedVolume::IsSatisfy( long theId )
1547 SMDS_VolumeTool vTool( myMesh->FindElement( theId ));
1548 return !vTool.IsForward();
1551 SMDSAbs_ElementType BadOrientedVolume::GetType() const
1553 return SMDSAbs_Volume;
1560 Description : Predicate for free borders
1563 FreeBorders::FreeBorders()
1568 void FreeBorders::SetMesh( const SMDS_Mesh* theMesh )
1573 bool FreeBorders::IsSatisfy( long theId )
1575 return getNbMultiConnection( myMesh, theId ) == 1;
1578 SMDSAbs_ElementType FreeBorders::GetType() const
1580 return SMDSAbs_Edge;
1586 Description : Predicate for free Edges
1588 FreeEdges::FreeEdges()
1593 void FreeEdges::SetMesh( const SMDS_Mesh* theMesh )
1598 bool FreeEdges::IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId )
1600 TColStd_MapOfInteger aMap;
1601 for ( int i = 0; i < 2; i++ )
1603 SMDS_ElemIteratorPtr anElemIter = theNodes[ i ]->GetInverseElementIterator();
1604 while( anElemIter->more() )
1606 const SMDS_MeshElement* anElem = anElemIter->next();
1607 if ( anElem != 0 && anElem->GetType() == SMDSAbs_Face )
1609 int anId = anElem->GetID();
1613 else if ( aMap.Contains( anId ) && anId != theFaceId )
1621 bool FreeEdges::IsSatisfy( long theId )
1626 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
1627 if ( aFace == 0 || aFace->GetType() != SMDSAbs_Face || aFace->NbNodes() < 3 )
1630 SMDS_ElemIteratorPtr anIter;
1631 if ( aFace->IsQuadratic() ) {
1632 anIter = static_cast<const SMDS_QuadraticFaceOfNodes*>
1633 (aFace)->interlacedNodesElemIterator();
1636 anIter = aFace->nodesIterator();
1641 int i = 0, nbNodes = aFace->NbNodes();
1642 std::vector <const SMDS_MeshNode*> aNodes( nbNodes+1 );
1643 while( anIter->more() )
1645 const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next();
1648 aNodes[ i++ ] = aNode;
1650 aNodes[ nbNodes ] = aNodes[ 0 ];
1652 for ( i = 0; i < nbNodes; i++ )
1653 if ( IsFreeEdge( &aNodes[ i ], theId ) )
1659 SMDSAbs_ElementType FreeEdges::GetType() const
1661 return SMDSAbs_Face;
1664 FreeEdges::Border::Border(long theElemId, long thePntId1, long thePntId2):
1667 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1668 if(thePntId1 > thePntId2){
1669 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1673 bool FreeEdges::Border::operator<(const FreeEdges::Border& x) const{
1674 if(myPntId[0] < x.myPntId[0]) return true;
1675 if(myPntId[0] == x.myPntId[0])
1676 if(myPntId[1] < x.myPntId[1]) return true;
1680 inline void UpdateBorders(const FreeEdges::Border& theBorder,
1681 FreeEdges::TBorders& theRegistry,
1682 FreeEdges::TBorders& theContainer)
1684 if(theRegistry.find(theBorder) == theRegistry.end()){
1685 theRegistry.insert(theBorder);
1686 theContainer.insert(theBorder);
1688 theContainer.erase(theBorder);
1692 void FreeEdges::GetBoreders(TBorders& theBorders)
1695 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1696 for(; anIter->more(); ){
1697 const SMDS_MeshFace* anElem = anIter->next();
1698 long anElemId = anElem->GetID();
1699 SMDS_ElemIteratorPtr aNodesIter;
1700 if ( anElem->IsQuadratic() )
1701 aNodesIter = static_cast<const SMDS_QuadraticFaceOfNodes*>(anElem)->
1702 interlacedNodesElemIterator();
1704 aNodesIter = anElem->nodesIterator();
1706 const SMDS_MeshElement* aNode;
1707 if(aNodesIter->more()){
1708 aNode = aNodesIter->next();
1709 aNodeId[0] = aNodeId[1] = aNode->GetID();
1711 for(; aNodesIter->more(); ){
1712 aNode = aNodesIter->next();
1713 long anId = aNode->GetID();
1714 Border aBorder(anElemId,aNodeId[1],anId);
1716 //std::cout<<aBorder.myPntId[0]<<"; "<<aBorder.myPntId[1]<<"; "<<aBorder.myElemId<<endl;
1717 UpdateBorders(aBorder,aRegistry,theBorders);
1719 Border aBorder(anElemId,aNodeId[0],aNodeId[1]);
1720 //std::cout<<aBorder.myPntId[0]<<"; "<<aBorder.myPntId[1]<<"; "<<aBorder.myElemId<<endl;
1721 UpdateBorders(aBorder,aRegistry,theBorders);
1723 //std::cout<<"theBorders.size() = "<<theBorders.size()<<endl;
1729 Description : Predicate for free nodes
1732 FreeNodes::FreeNodes()
1737 void FreeNodes::SetMesh( const SMDS_Mesh* theMesh )
1742 bool FreeNodes::IsSatisfy( long theNodeId )
1744 const SMDS_MeshNode* aNode = myMesh->FindNode( theNodeId );
1748 return (aNode->NbInverseElements() < 1);
1751 SMDSAbs_ElementType FreeNodes::GetType() const
1753 return SMDSAbs_Node;
1759 Description : Predicate for free faces
1762 FreeFaces::FreeFaces()
1767 void FreeFaces::SetMesh( const SMDS_Mesh* theMesh )
1772 bool FreeFaces::IsSatisfy( long theId )
1774 if (!myMesh) return false;
1775 // check that faces nodes refers to less than two common volumes
1776 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
1777 if ( !aFace || aFace->GetType() != SMDSAbs_Face )
1780 int nbNode = aFace->NbNodes();
1782 // collect volumes check that number of volumss with count equal nbNode not less than 2
1783 typedef map< SMDS_MeshElement*, int > TMapOfVolume; // map of volume counters
1784 typedef map< SMDS_MeshElement*, int >::iterator TItrMapOfVolume; // iterator
1785 TMapOfVolume mapOfVol;
1787 SMDS_ElemIteratorPtr nodeItr = aFace->nodesIterator();
1788 while ( nodeItr->more() ) {
1789 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(nodeItr->next());
1790 if ( !aNode ) continue;
1791 SMDS_ElemIteratorPtr volItr = aNode->GetInverseElementIterator(SMDSAbs_Volume);
1792 while ( volItr->more() ) {
1793 SMDS_MeshElement* aVol = (SMDS_MeshElement*)volItr->next();
1794 TItrMapOfVolume itr = mapOfVol.insert(make_pair(aVol, 0)).first;
1799 TItrMapOfVolume volItr = mapOfVol.begin();
1800 TItrMapOfVolume volEnd = mapOfVol.end();
1801 for ( ; volItr != volEnd; ++volItr )
1802 if ( (*volItr).second >= nbNode )
1804 // face is not free if number of volumes constructed on thier nodes more than one
1808 SMDSAbs_ElementType FreeFaces::GetType() const
1810 return SMDSAbs_Face;
1814 Class : LinearOrQuadratic
1815 Description : Predicate to verify whether a mesh element is linear
1818 LinearOrQuadratic::LinearOrQuadratic()
1823 void LinearOrQuadratic::SetMesh( const SMDS_Mesh* theMesh )
1828 bool LinearOrQuadratic::IsSatisfy( long theId )
1830 if (!myMesh) return false;
1831 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
1832 if ( !anElem || (myType != SMDSAbs_All && anElem->GetType() != myType) )
1834 return (!anElem->IsQuadratic());
1837 void LinearOrQuadratic::SetType( SMDSAbs_ElementType theType )
1842 SMDSAbs_ElementType LinearOrQuadratic::GetType() const
1849 Description : Functor for check color of group to whic mesh element belongs to
1852 GroupColor::GroupColor()
1856 bool GroupColor::IsSatisfy( long theId )
1858 return (myIDs.find( theId ) != myIDs.end());
1861 void GroupColor::SetType( SMDSAbs_ElementType theType )
1866 SMDSAbs_ElementType GroupColor::GetType() const
1871 static bool isEqual( const Quantity_Color& theColor1,
1872 const Quantity_Color& theColor2 )
1874 // tolerance to compare colors
1875 const double tol = 5*1e-3;
1876 return ( fabs( theColor1.Red() - theColor2.Red() ) < tol &&
1877 fabs( theColor1.Green() - theColor2.Green() ) < tol &&
1878 fabs( theColor1.Blue() - theColor2.Blue() ) < tol );
1882 void GroupColor::SetMesh( const SMDS_Mesh* theMesh )
1886 const SMESHDS_Mesh* aMesh = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
1890 int nbGrp = aMesh->GetNbGroups();
1894 // iterates on groups and find necessary elements ids
1895 const std::set<SMESHDS_GroupBase*>& aGroups = aMesh->GetGroups();
1896 set<SMESHDS_GroupBase*>::const_iterator GrIt = aGroups.begin();
1897 for (; GrIt != aGroups.end(); GrIt++) {
1898 SMESHDS_GroupBase* aGrp = (*GrIt);
1901 // check type and color of group
1902 if ( !isEqual( myColor, aGrp->GetColor() ) )
1904 if ( myType != SMDSAbs_All && myType != (SMDSAbs_ElementType)aGrp->GetType() )
1907 SMDSAbs_ElementType aGrpElType = (SMDSAbs_ElementType)aGrp->GetType();
1908 if ( myType == aGrpElType || (myType == SMDSAbs_All && aGrpElType != SMDSAbs_Node) ) {
1909 // add elements IDS into control
1910 int aSize = aGrp->Extent();
1911 for (int i = 0; i < aSize; i++)
1912 myIDs.insert( aGrp->GetID(i+1) );
1917 void GroupColor::SetColorStr( const TCollection_AsciiString& theStr )
1919 TCollection_AsciiString aStr = theStr;
1920 aStr.RemoveAll( ' ' );
1921 aStr.RemoveAll( '\t' );
1922 for ( int aPos = aStr.Search( ";;" ); aPos != -1; aPos = aStr.Search( ";;" ) )
1923 aStr.Remove( aPos, 2 );
1924 Standard_Real clr[3];
1925 clr[0] = clr[1] = clr[2] = 0.;
1926 for ( int i = 0; i < 3; i++ ) {
1927 TCollection_AsciiString tmpStr = aStr.Token( ";", i+1 );
1928 if ( !tmpStr.IsEmpty() && tmpStr.IsRealValue() )
1929 clr[i] = tmpStr.RealValue();
1931 myColor = Quantity_Color( clr[0], clr[1], clr[2], Quantity_TOC_RGB );
1934 //=======================================================================
1935 // name : GetRangeStr
1936 // Purpose : Get range as a string.
1937 // Example: "1,2,3,50-60,63,67,70-"
1938 //=======================================================================
1939 void GroupColor::GetColorStr( TCollection_AsciiString& theResStr ) const
1942 theResStr += TCollection_AsciiString( myColor.Red() );
1943 theResStr += TCollection_AsciiString( ";" ) + TCollection_AsciiString( myColor.Green() );
1944 theResStr += TCollection_AsciiString( ";" ) + TCollection_AsciiString( myColor.Blue() );
1948 Class : ElemGeomType
1949 Description : Predicate to check element geometry type
1952 ElemGeomType::ElemGeomType()
1955 myType = SMDSAbs_All;
1956 myGeomType = SMDSGeom_TRIANGLE;
1959 void ElemGeomType::SetMesh( const SMDS_Mesh* theMesh )
1964 bool ElemGeomType::IsSatisfy( long theId )
1966 if (!myMesh) return false;
1967 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
1970 const SMDSAbs_ElementType anElemType = anElem->GetType();
1971 if ( myType != SMDSAbs_All && anElemType != myType )
1973 const int aNbNode = anElem->NbNodes();
1975 switch( anElemType )
1978 isOk = (myGeomType == SMDSGeom_POINT);
1982 isOk = (myGeomType == SMDSGeom_EDGE);
1986 if ( myGeomType == SMDSGeom_TRIANGLE )
1987 isOk = (!anElem->IsPoly() && (anElem->IsQuadratic() ? aNbNode == 6 : aNbNode == 3));
1988 else if ( myGeomType == SMDSGeom_QUADRANGLE )
1989 isOk = (!anElem->IsPoly() && (anElem->IsQuadratic() ? aNbNode == 8 : aNbNode == 4));
1990 else if ( myGeomType == SMDSGeom_POLYGON )
1991 isOk = anElem->IsPoly();
1994 case SMDSAbs_Volume:
1995 if ( myGeomType == SMDSGeom_TETRA )
1996 isOk = (!anElem->IsPoly() && (anElem->IsQuadratic() ? aNbNode == 10 : aNbNode == 4));
1997 else if ( myGeomType == SMDSGeom_PYRAMID )
1998 isOk = (!anElem->IsPoly() && (anElem->IsQuadratic() ? aNbNode == 13 : aNbNode == 5));
1999 else if ( myGeomType == SMDSGeom_PENTA )
2000 isOk = (!anElem->IsPoly() && (anElem->IsQuadratic() ? aNbNode == 15 : aNbNode == 6));
2001 else if ( myGeomType == SMDSGeom_HEXA )
2002 isOk = (!anElem->IsPoly() && (anElem->IsQuadratic() ? aNbNode == 20 : aNbNode == 8));
2003 else if ( myGeomType == SMDSGeom_POLYHEDRA )
2004 isOk = anElem->IsPoly();
2011 void ElemGeomType::SetType( SMDSAbs_ElementType theType )
2016 SMDSAbs_ElementType ElemGeomType::GetType() const
2021 void ElemGeomType::SetGeomType( SMDSAbs_GeometryType theType )
2023 myGeomType = theType;
2026 SMDSAbs_GeometryType ElemGeomType::GetGeomType() const
2031 //================================================================================
2033 * \brief Class CoplanarFaces
2035 //================================================================================
2037 CoplanarFaces::CoplanarFaces()
2038 : myMesh(0), myFaceID(0), myToler(0)
2041 bool CoplanarFaces::IsSatisfy( long theElementId )
2043 if ( myCoplanarIDs.empty() )
2045 // Build a set of coplanar face ids
2047 if ( !myMesh || !myFaceID || !myToler )
2050 const SMDS_MeshElement* face = myMesh->FindElement( myFaceID );
2051 if ( !face || face->GetType() != SMDSAbs_Face )
2055 gp_Vec myNorm = getNormale( static_cast<const SMDS_MeshFace*>(face), &normOK );
2059 const double radianTol = myToler * PI180;
2060 typedef SMDS_StdIterator< const SMDS_MeshElement*, SMDS_ElemIteratorPtr > TFaceIt;
2061 std::set<const SMDS_MeshElement*> checkedFaces, checkedNodes;
2062 std::list<const SMDS_MeshElement*> faceQueue( 1, face );
2063 while ( !faceQueue.empty() )
2065 face = faceQueue.front();
2066 if ( checkedFaces.insert( face ).second )
2068 gp_Vec norm = getNormale( static_cast<const SMDS_MeshFace*>(face), &normOK );
2069 if (!normOK || myNorm.Angle( norm ) <= radianTol)
2071 myCoplanarIDs.insert( face->GetID() );
2072 std::set<const SMDS_MeshElement*> neighborFaces;
2073 for ( int i = 0; i < face->NbCornerNodes(); ++i )
2075 const SMDS_MeshNode* n = face->GetNode( i );
2076 if ( checkedNodes.insert( n ).second )
2077 neighborFaces.insert( TFaceIt( n->GetInverseElementIterator(SMDSAbs_Face)),
2080 faceQueue.insert( faceQueue.end(), neighborFaces.begin(), neighborFaces.end() );
2083 faceQueue.pop_front();
2086 return myCoplanarIDs.count( theElementId );
2091 *Description : Predicate for Range of Ids.
2092 * Range may be specified with two ways.
2093 * 1. Using AddToRange method
2094 * 2. With SetRangeStr method. Parameter of this method is a string
2095 * like as "1,2,3,50-60,63,67,70-"
2098 //=======================================================================
2099 // name : RangeOfIds
2100 // Purpose : Constructor
2101 //=======================================================================
2102 RangeOfIds::RangeOfIds()
2105 myType = SMDSAbs_All;
2108 //=======================================================================
2110 // Purpose : Set mesh
2111 //=======================================================================
2112 void RangeOfIds::SetMesh( const SMDS_Mesh* theMesh )
2117 //=======================================================================
2118 // name : AddToRange
2119 // Purpose : Add ID to the range
2120 //=======================================================================
2121 bool RangeOfIds::AddToRange( long theEntityId )
2123 myIds.Add( theEntityId );
2127 //=======================================================================
2128 // name : GetRangeStr
2129 // Purpose : Get range as a string.
2130 // Example: "1,2,3,50-60,63,67,70-"
2131 //=======================================================================
2132 void RangeOfIds::GetRangeStr( TCollection_AsciiString& theResStr )
2136 TColStd_SequenceOfInteger anIntSeq;
2137 TColStd_SequenceOfAsciiString aStrSeq;
2139 TColStd_MapIteratorOfMapOfInteger anIter( myIds );
2140 for ( ; anIter.More(); anIter.Next() )
2142 int anId = anIter.Key();
2143 TCollection_AsciiString aStr( anId );
2144 anIntSeq.Append( anId );
2145 aStrSeq.Append( aStr );
2148 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
2150 int aMinId = myMin( i );
2151 int aMaxId = myMax( i );
2153 TCollection_AsciiString aStr;
2154 if ( aMinId != IntegerFirst() )
2159 if ( aMaxId != IntegerLast() )
2162 // find position of the string in result sequence and insert string in it
2163 if ( anIntSeq.Length() == 0 )
2165 anIntSeq.Append( aMinId );
2166 aStrSeq.Append( aStr );
2170 if ( aMinId < anIntSeq.First() )
2172 anIntSeq.Prepend( aMinId );
2173 aStrSeq.Prepend( aStr );
2175 else if ( aMinId > anIntSeq.Last() )
2177 anIntSeq.Append( aMinId );
2178 aStrSeq.Append( aStr );
2181 for ( int j = 1, k = anIntSeq.Length(); j <= k; j++ )
2182 if ( aMinId < anIntSeq( j ) )
2184 anIntSeq.InsertBefore( j, aMinId );
2185 aStrSeq.InsertBefore( j, aStr );
2191 if ( aStrSeq.Length() == 0 )
2194 theResStr = aStrSeq( 1 );
2195 for ( int j = 2, k = aStrSeq.Length(); j <= k; j++ )
2198 theResStr += aStrSeq( j );
2202 //=======================================================================
2203 // name : SetRangeStr
2204 // Purpose : Define range with string
2205 // Example of entry string: "1,2,3,50-60,63,67,70-"
2206 //=======================================================================
2207 bool RangeOfIds::SetRangeStr( const TCollection_AsciiString& theStr )
2213 TCollection_AsciiString aStr = theStr;
2214 aStr.RemoveAll( ' ' );
2215 aStr.RemoveAll( '\t' );
2217 for ( int aPos = aStr.Search( ",," ); aPos != -1; aPos = aStr.Search( ",," ) )
2218 aStr.Remove( aPos, 2 );
2220 TCollection_AsciiString tmpStr = aStr.Token( ",", 1 );
2222 while ( tmpStr != "" )
2224 tmpStr = aStr.Token( ",", i++ );
2225 int aPos = tmpStr.Search( '-' );
2229 if ( tmpStr.IsIntegerValue() )
2230 myIds.Add( tmpStr.IntegerValue() );
2236 TCollection_AsciiString aMaxStr = tmpStr.Split( aPos );
2237 TCollection_AsciiString aMinStr = tmpStr;
2239 while ( aMinStr.Search( "-" ) != -1 ) aMinStr.RemoveAll( '-' );
2240 while ( aMaxStr.Search( "-" ) != -1 ) aMaxStr.RemoveAll( '-' );
2242 if ( !aMinStr.IsEmpty() && !aMinStr.IsIntegerValue() ||
2243 !aMaxStr.IsEmpty() && !aMaxStr.IsIntegerValue() )
2246 myMin.Append( aMinStr.IsEmpty() ? IntegerFirst() : aMinStr.IntegerValue() );
2247 myMax.Append( aMaxStr.IsEmpty() ? IntegerLast() : aMaxStr.IntegerValue() );
2254 //=======================================================================
2256 // Purpose : Get type of supported entities
2257 //=======================================================================
2258 SMDSAbs_ElementType RangeOfIds::GetType() const
2263 //=======================================================================
2265 // Purpose : Set type of supported entities
2266 //=======================================================================
2267 void RangeOfIds::SetType( SMDSAbs_ElementType theType )
2272 //=======================================================================
2274 // Purpose : Verify whether entity satisfies to this rpedicate
2275 //=======================================================================
2276 bool RangeOfIds::IsSatisfy( long theId )
2281 if ( myType == SMDSAbs_Node )
2283 if ( myMesh->FindNode( theId ) == 0 )
2288 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2289 if ( anElem == 0 || myType != anElem->GetType() && myType != SMDSAbs_All )
2293 if ( myIds.Contains( theId ) )
2296 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
2297 if ( theId >= myMin( i ) && theId <= myMax( i ) )
2305 Description : Base class for comparators
2307 Comparator::Comparator():
2311 Comparator::~Comparator()
2314 void Comparator::SetMesh( const SMDS_Mesh* theMesh )
2317 myFunctor->SetMesh( theMesh );
2320 void Comparator::SetMargin( double theValue )
2322 myMargin = theValue;
2325 void Comparator::SetNumFunctor( NumericalFunctorPtr theFunct )
2327 myFunctor = theFunct;
2330 SMDSAbs_ElementType Comparator::GetType() const
2332 return myFunctor ? myFunctor->GetType() : SMDSAbs_All;
2335 double Comparator::GetMargin()
2343 Description : Comparator "<"
2345 bool LessThan::IsSatisfy( long theId )
2347 return myFunctor && myFunctor->GetValue( theId ) < myMargin;
2353 Description : Comparator ">"
2355 bool MoreThan::IsSatisfy( long theId )
2357 return myFunctor && myFunctor->GetValue( theId ) > myMargin;
2363 Description : Comparator "="
2366 myToler(Precision::Confusion())
2369 bool EqualTo::IsSatisfy( long theId )
2371 return myFunctor && fabs( myFunctor->GetValue( theId ) - myMargin ) < myToler;
2374 void EqualTo::SetTolerance( double theToler )
2379 double EqualTo::GetTolerance()
2386 Description : Logical NOT predicate
2388 LogicalNOT::LogicalNOT()
2391 LogicalNOT::~LogicalNOT()
2394 bool LogicalNOT::IsSatisfy( long theId )
2396 return myPredicate && !myPredicate->IsSatisfy( theId );
2399 void LogicalNOT::SetMesh( const SMDS_Mesh* theMesh )
2402 myPredicate->SetMesh( theMesh );
2405 void LogicalNOT::SetPredicate( PredicatePtr thePred )
2407 myPredicate = thePred;
2410 SMDSAbs_ElementType LogicalNOT::GetType() const
2412 return myPredicate ? myPredicate->GetType() : SMDSAbs_All;
2417 Class : LogicalBinary
2418 Description : Base class for binary logical predicate
2420 LogicalBinary::LogicalBinary()
2423 LogicalBinary::~LogicalBinary()
2426 void LogicalBinary::SetMesh( const SMDS_Mesh* theMesh )
2429 myPredicate1->SetMesh( theMesh );
2432 myPredicate2->SetMesh( theMesh );
2435 void LogicalBinary::SetPredicate1( PredicatePtr thePredicate )
2437 myPredicate1 = thePredicate;
2440 void LogicalBinary::SetPredicate2( PredicatePtr thePredicate )
2442 myPredicate2 = thePredicate;
2445 SMDSAbs_ElementType LogicalBinary::GetType() const
2447 if ( !myPredicate1 || !myPredicate2 )
2450 SMDSAbs_ElementType aType1 = myPredicate1->GetType();
2451 SMDSAbs_ElementType aType2 = myPredicate2->GetType();
2453 return aType1 == aType2 ? aType1 : SMDSAbs_All;
2459 Description : Logical AND
2461 bool LogicalAND::IsSatisfy( long theId )
2466 myPredicate1->IsSatisfy( theId ) &&
2467 myPredicate2->IsSatisfy( theId );
2473 Description : Logical OR
2475 bool LogicalOR::IsSatisfy( long theId )
2480 myPredicate1->IsSatisfy( theId ) ||
2481 myPredicate2->IsSatisfy( theId );
2495 void Filter::SetPredicate( PredicatePtr thePredicate )
2497 myPredicate = thePredicate;
2500 template<class TElement, class TIterator, class TPredicate>
2501 inline void FillSequence(const TIterator& theIterator,
2502 TPredicate& thePredicate,
2503 Filter::TIdSequence& theSequence)
2505 if ( theIterator ) {
2506 while( theIterator->more() ) {
2507 TElement anElem = theIterator->next();
2508 long anId = anElem->GetID();
2509 if ( thePredicate->IsSatisfy( anId ) )
2510 theSequence.push_back( anId );
2517 GetElementsId( const SMDS_Mesh* theMesh,
2518 PredicatePtr thePredicate,
2519 TIdSequence& theSequence )
2521 theSequence.clear();
2523 if ( !theMesh || !thePredicate )
2526 thePredicate->SetMesh( theMesh );
2528 SMDSAbs_ElementType aType = thePredicate->GetType();
2531 FillSequence<const SMDS_MeshNode*>(theMesh->nodesIterator(),thePredicate,theSequence);
2534 FillSequence<const SMDS_MeshElement*>(theMesh->edgesIterator(),thePredicate,theSequence);
2537 FillSequence<const SMDS_MeshElement*>(theMesh->facesIterator(),thePredicate,theSequence);
2539 case SMDSAbs_Volume:
2540 FillSequence<const SMDS_MeshElement*>(theMesh->volumesIterator(),thePredicate,theSequence);
2543 FillSequence<const SMDS_MeshElement*>(theMesh->edgesIterator(),thePredicate,theSequence);
2544 FillSequence<const SMDS_MeshElement*>(theMesh->facesIterator(),thePredicate,theSequence);
2545 FillSequence<const SMDS_MeshElement*>(theMesh->volumesIterator(),thePredicate,theSequence);
2551 Filter::GetElementsId( const SMDS_Mesh* theMesh,
2552 Filter::TIdSequence& theSequence )
2554 GetElementsId(theMesh,myPredicate,theSequence);
2561 typedef std::set<SMDS_MeshFace*> TMapOfFacePtr;
2567 ManifoldPart::Link::Link( SMDS_MeshNode* theNode1,
2568 SMDS_MeshNode* theNode2 )
2574 ManifoldPart::Link::~Link()
2580 bool ManifoldPart::Link::IsEqual( const ManifoldPart::Link& theLink ) const
2582 if ( myNode1 == theLink.myNode1 &&
2583 myNode2 == theLink.myNode2 )
2585 else if ( myNode1 == theLink.myNode2 &&
2586 myNode2 == theLink.myNode1 )
2592 bool ManifoldPart::Link::operator<( const ManifoldPart::Link& x ) const
2594 if(myNode1 < x.myNode1) return true;
2595 if(myNode1 == x.myNode1)
2596 if(myNode2 < x.myNode2) return true;
2600 bool ManifoldPart::IsEqual( const ManifoldPart::Link& theLink1,
2601 const ManifoldPart::Link& theLink2 )
2603 return theLink1.IsEqual( theLink2 );
2606 ManifoldPart::ManifoldPart()
2609 myAngToler = Precision::Angular();
2610 myIsOnlyManifold = true;
2613 ManifoldPart::~ManifoldPart()
2618 void ManifoldPart::SetMesh( const SMDS_Mesh* theMesh )
2624 SMDSAbs_ElementType ManifoldPart::GetType() const
2625 { return SMDSAbs_Face; }
2627 bool ManifoldPart::IsSatisfy( long theElementId )
2629 return myMapIds.Contains( theElementId );
2632 void ManifoldPart::SetAngleTolerance( const double theAngToler )
2633 { myAngToler = theAngToler; }
2635 double ManifoldPart::GetAngleTolerance() const
2636 { return myAngToler; }
2638 void ManifoldPart::SetIsOnlyManifold( const bool theIsOnly )
2639 { myIsOnlyManifold = theIsOnly; }
2641 void ManifoldPart::SetStartElem( const long theStartId )
2642 { myStartElemId = theStartId; }
2644 bool ManifoldPart::process()
2647 myMapBadGeomIds.Clear();
2649 myAllFacePtr.clear();
2650 myAllFacePtrIntDMap.clear();
2654 // collect all faces into own map
2655 SMDS_FaceIteratorPtr anFaceItr = myMesh->facesIterator();
2656 for (; anFaceItr->more(); )
2658 SMDS_MeshFace* aFacePtr = (SMDS_MeshFace*)anFaceItr->next();
2659 myAllFacePtr.push_back( aFacePtr );
2660 myAllFacePtrIntDMap[aFacePtr] = myAllFacePtr.size()-1;
2663 SMDS_MeshFace* aStartFace = (SMDS_MeshFace*)myMesh->FindElement( myStartElemId );
2667 // the map of non manifold links and bad geometry
2668 TMapOfLink aMapOfNonManifold;
2669 TColStd_MapOfInteger aMapOfTreated;
2671 // begin cycle on faces from start index and run on vector till the end
2672 // and from begin to start index to cover whole vector
2673 const int aStartIndx = myAllFacePtrIntDMap[aStartFace];
2674 bool isStartTreat = false;
2675 for ( int fi = aStartIndx; !isStartTreat || fi != aStartIndx ; fi++ )
2677 if ( fi == aStartIndx )
2678 isStartTreat = true;
2679 // as result next time when fi will be equal to aStartIndx
2681 SMDS_MeshFace* aFacePtr = myAllFacePtr[ fi ];
2682 if ( aMapOfTreated.Contains( aFacePtr->GetID() ) )
2685 aMapOfTreated.Add( aFacePtr->GetID() );
2686 TColStd_MapOfInteger aResFaces;
2687 if ( !findConnected( myAllFacePtrIntDMap, aFacePtr,
2688 aMapOfNonManifold, aResFaces ) )
2690 TColStd_MapIteratorOfMapOfInteger anItr( aResFaces );
2691 for ( ; anItr.More(); anItr.Next() )
2693 int aFaceId = anItr.Key();
2694 aMapOfTreated.Add( aFaceId );
2695 myMapIds.Add( aFaceId );
2698 if ( fi == ( myAllFacePtr.size() - 1 ) )
2700 } // end run on vector of faces
2701 return !myMapIds.IsEmpty();
2704 static void getLinks( const SMDS_MeshFace* theFace,
2705 ManifoldPart::TVectorOfLink& theLinks )
2707 int aNbNode = theFace->NbNodes();
2708 SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
2710 SMDS_MeshNode* aNode = 0;
2711 for ( ; aNodeItr->more() && i <= aNbNode; )
2714 SMDS_MeshNode* aN1 = (SMDS_MeshNode*)aNodeItr->next();
2718 SMDS_MeshNode* aN2 = ( i >= aNbNode ) ? aNode : (SMDS_MeshNode*)aNodeItr->next();
2720 ManifoldPart::Link aLink( aN1, aN2 );
2721 theLinks.push_back( aLink );
2725 bool ManifoldPart::findConnected
2726 ( const ManifoldPart::TDataMapFacePtrInt& theAllFacePtrInt,
2727 SMDS_MeshFace* theStartFace,
2728 ManifoldPart::TMapOfLink& theNonManifold,
2729 TColStd_MapOfInteger& theResFaces )
2731 theResFaces.Clear();
2732 if ( !theAllFacePtrInt.size() )
2735 if ( getNormale( theStartFace ).SquareModulus() <= gp::Resolution() )
2737 myMapBadGeomIds.Add( theStartFace->GetID() );
2741 ManifoldPart::TMapOfLink aMapOfBoundary, aMapToSkip;
2742 ManifoldPart::TVectorOfLink aSeqOfBoundary;
2743 theResFaces.Add( theStartFace->GetID() );
2744 ManifoldPart::TDataMapOfLinkFacePtr aDMapLinkFace;
2746 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
2747 aDMapLinkFace, theNonManifold, theStartFace );
2749 bool isDone = false;
2750 while ( !isDone && aMapOfBoundary.size() != 0 )
2752 bool isToReset = false;
2753 ManifoldPart::TVectorOfLink::iterator pLink = aSeqOfBoundary.begin();
2754 for ( ; !isToReset && pLink != aSeqOfBoundary.end(); ++pLink )
2756 ManifoldPart::Link aLink = *pLink;
2757 if ( aMapToSkip.find( aLink ) != aMapToSkip.end() )
2759 // each link could be treated only once
2760 aMapToSkip.insert( aLink );
2762 ManifoldPart::TVectorOfFacePtr aFaces;
2764 if ( myIsOnlyManifold &&
2765 (theNonManifold.find( aLink ) != theNonManifold.end()) )
2769 getFacesByLink( aLink, aFaces );
2770 // filter the element to keep only indicated elements
2771 ManifoldPart::TVectorOfFacePtr aFiltered;
2772 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
2773 for ( ; pFace != aFaces.end(); ++pFace )
2775 SMDS_MeshFace* aFace = *pFace;
2776 if ( myAllFacePtrIntDMap.find( aFace ) != myAllFacePtrIntDMap.end() )
2777 aFiltered.push_back( aFace );
2780 if ( aFaces.size() < 2 ) // no neihgbour faces
2782 else if ( myIsOnlyManifold && aFaces.size() > 2 ) // non manifold case
2784 theNonManifold.insert( aLink );
2789 // compare normal with normals of neighbor element
2790 SMDS_MeshFace* aPrevFace = aDMapLinkFace[ aLink ];
2791 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
2792 for ( ; pFace != aFaces.end(); ++pFace )
2794 SMDS_MeshFace* aNextFace = *pFace;
2795 if ( aPrevFace == aNextFace )
2797 int anNextFaceID = aNextFace->GetID();
2798 if ( myIsOnlyManifold && theResFaces.Contains( anNextFaceID ) )
2799 // should not be with non manifold restriction. probably bad topology
2801 // check if face was treated and skipped
2802 if ( myMapBadGeomIds.Contains( anNextFaceID ) ||
2803 !isInPlane( aPrevFace, aNextFace ) )
2805 // add new element to connected and extend the boundaries.
2806 theResFaces.Add( anNextFaceID );
2807 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
2808 aDMapLinkFace, theNonManifold, aNextFace );
2812 isDone = !isToReset;
2815 return !theResFaces.IsEmpty();
2818 bool ManifoldPart::isInPlane( const SMDS_MeshFace* theFace1,
2819 const SMDS_MeshFace* theFace2 )
2821 gp_Dir aNorm1 = gp_Dir( getNormale( theFace1 ) );
2822 gp_XYZ aNorm2XYZ = getNormale( theFace2 );
2823 if ( aNorm2XYZ.SquareModulus() <= gp::Resolution() )
2825 myMapBadGeomIds.Add( theFace2->GetID() );
2828 if ( aNorm1.IsParallel( gp_Dir( aNorm2XYZ ), myAngToler ) )
2834 void ManifoldPart::expandBoundary
2835 ( ManifoldPart::TMapOfLink& theMapOfBoundary,
2836 ManifoldPart::TVectorOfLink& theSeqOfBoundary,
2837 ManifoldPart::TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
2838 ManifoldPart::TMapOfLink& theNonManifold,
2839 SMDS_MeshFace* theNextFace ) const
2841 ManifoldPart::TVectorOfLink aLinks;
2842 getLinks( theNextFace, aLinks );
2843 int aNbLink = (int)aLinks.size();
2844 for ( int i = 0; i < aNbLink; i++ )
2846 ManifoldPart::Link aLink = aLinks[ i ];
2847 if ( myIsOnlyManifold && (theNonManifold.find( aLink ) != theNonManifold.end()) )
2849 if ( theMapOfBoundary.find( aLink ) != theMapOfBoundary.end() )
2851 if ( myIsOnlyManifold )
2853 // remove from boundary
2854 theMapOfBoundary.erase( aLink );
2855 ManifoldPart::TVectorOfLink::iterator pLink = theSeqOfBoundary.begin();
2856 for ( ; pLink != theSeqOfBoundary.end(); ++pLink )
2858 ManifoldPart::Link aBoundLink = *pLink;
2859 if ( aBoundLink.IsEqual( aLink ) )
2861 theSeqOfBoundary.erase( pLink );
2869 theMapOfBoundary.insert( aLink );
2870 theSeqOfBoundary.push_back( aLink );
2871 theDMapLinkFacePtr[ aLink ] = theNextFace;
2876 void ManifoldPart::getFacesByLink( const ManifoldPart::Link& theLink,
2877 ManifoldPart::TVectorOfFacePtr& theFaces ) const
2879 SMDS_Mesh::SetOfFaces aSetOfFaces;
2880 // take all faces that shared first node
2881 SMDS_ElemIteratorPtr anItr = theLink.myNode1->facesIterator();
2882 for ( ; anItr->more(); )
2884 SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
2887 aSetOfFaces.Add( aFace );
2889 // take all faces that shared second node
2890 anItr = theLink.myNode2->facesIterator();
2891 // find the common part of two sets
2892 for ( ; anItr->more(); )
2894 SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
2895 if ( aSetOfFaces.Contains( aFace ) )
2896 theFaces.push_back( aFace );
2905 ElementsOnSurface::ElementsOnSurface()
2909 myType = SMDSAbs_All;
2911 myToler = Precision::Confusion();
2912 myUseBoundaries = false;
2915 ElementsOnSurface::~ElementsOnSurface()
2920 void ElementsOnSurface::SetMesh( const SMDS_Mesh* theMesh )
2922 if ( myMesh == theMesh )
2928 bool ElementsOnSurface::IsSatisfy( long theElementId )
2930 return myIds.Contains( theElementId );
2933 SMDSAbs_ElementType ElementsOnSurface::GetType() const
2936 void ElementsOnSurface::SetTolerance( const double theToler )
2938 if ( myToler != theToler )
2943 double ElementsOnSurface::GetTolerance() const
2946 void ElementsOnSurface::SetUseBoundaries( bool theUse )
2948 if ( myUseBoundaries != theUse ) {
2949 myUseBoundaries = theUse;
2950 SetSurface( mySurf, myType );
2954 void ElementsOnSurface::SetSurface( const TopoDS_Shape& theShape,
2955 const SMDSAbs_ElementType theType )
2960 if ( theShape.IsNull() || theShape.ShapeType() != TopAbs_FACE )
2962 mySurf = TopoDS::Face( theShape );
2963 BRepAdaptor_Surface SA( mySurf, myUseBoundaries );
2965 u1 = SA.FirstUParameter(),
2966 u2 = SA.LastUParameter(),
2967 v1 = SA.FirstVParameter(),
2968 v2 = SA.LastVParameter();
2969 Handle(Geom_Surface) surf = BRep_Tool::Surface( mySurf );
2970 myProjector.Init( surf, u1,u2, v1,v2 );
2974 void ElementsOnSurface::process()
2977 if ( mySurf.IsNull() )
2983 if ( myType == SMDSAbs_Face || myType == SMDSAbs_All )
2985 myIds.ReSize( myMesh->NbFaces() );
2986 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
2987 for(; anIter->more(); )
2988 process( anIter->next() );
2991 if ( myType == SMDSAbs_Edge || myType == SMDSAbs_All )
2993 myIds.ReSize( myIds.Extent() + myMesh->NbEdges() );
2994 SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
2995 for(; anIter->more(); )
2996 process( anIter->next() );
2999 if ( myType == SMDSAbs_Node )
3001 myIds.ReSize( myMesh->NbNodes() );
3002 SMDS_NodeIteratorPtr anIter = myMesh->nodesIterator();
3003 for(; anIter->more(); )
3004 process( anIter->next() );
3008 void ElementsOnSurface::process( const SMDS_MeshElement* theElemPtr )
3010 SMDS_ElemIteratorPtr aNodeItr = theElemPtr->nodesIterator();
3011 bool isSatisfy = true;
3012 for ( ; aNodeItr->more(); )
3014 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
3015 if ( !isOnSurface( aNode ) )
3022 myIds.Add( theElemPtr->GetID() );
3025 bool ElementsOnSurface::isOnSurface( const SMDS_MeshNode* theNode )
3027 if ( mySurf.IsNull() )
3030 gp_Pnt aPnt( theNode->X(), theNode->Y(), theNode->Z() );
3031 // double aToler2 = myToler * myToler;
3032 // if ( mySurf->IsKind(STANDARD_TYPE(Geom_Plane)))
3034 // gp_Pln aPln = Handle(Geom_Plane)::DownCast(mySurf)->Pln();
3035 // if ( aPln.SquareDistance( aPnt ) > aToler2 )
3038 // else if ( mySurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)))
3040 // gp_Cylinder aCyl = Handle(Geom_CylindricalSurface)::DownCast(mySurf)->Cylinder();
3041 // double aRad = aCyl.Radius();
3042 // gp_Ax3 anAxis = aCyl.Position();
3043 // gp_XYZ aLoc = aCyl.Location().XYZ();
3044 // double aXDist = anAxis.XDirection().XYZ() * ( aPnt.XYZ() - aLoc );
3045 // double aYDist = anAxis.YDirection().XYZ() * ( aPnt.XYZ() - aLoc );
3046 // if ( fabs(aXDist*aXDist + aYDist*aYDist - aRad*aRad) > aToler2 )
3051 myProjector.Perform( aPnt );
3052 bool isOn = ( myProjector.IsDone() && myProjector.LowerDistance() <= myToler );
3062 ElementsOnShape::ElementsOnShape()
3064 myType(SMDSAbs_All),
3065 myToler(Precision::Confusion()),
3066 myAllNodesFlag(false)
3068 myCurShapeType = TopAbs_SHAPE;
3071 ElementsOnShape::~ElementsOnShape()
3075 void ElementsOnShape::SetMesh (const SMDS_Mesh* theMesh)
3077 if (myMesh != theMesh) {
3079 SetShape(myShape, myType);
3083 bool ElementsOnShape::IsSatisfy (long theElementId)
3085 return myIds.Contains(theElementId);
3088 SMDSAbs_ElementType ElementsOnShape::GetType() const
3093 void ElementsOnShape::SetTolerance (const double theToler)
3095 if (myToler != theToler) {
3097 SetShape(myShape, myType);
3101 double ElementsOnShape::GetTolerance() const
3106 void ElementsOnShape::SetAllNodes (bool theAllNodes)
3108 if (myAllNodesFlag != theAllNodes) {
3109 myAllNodesFlag = theAllNodes;
3110 SetShape(myShape, myType);
3114 void ElementsOnShape::SetShape (const TopoDS_Shape& theShape,
3115 const SMDSAbs_ElementType theType)
3121 if (myMesh == 0) return;
3126 myIds.ReSize(myMesh->NbEdges() + myMesh->NbFaces() + myMesh->NbVolumes());
3129 myIds.ReSize(myMesh->NbNodes());
3132 myIds.ReSize(myMesh->NbEdges());
3135 myIds.ReSize(myMesh->NbFaces());
3137 case SMDSAbs_Volume:
3138 myIds.ReSize(myMesh->NbVolumes());
3144 myShapesMap.Clear();
3148 void ElementsOnShape::addShape (const TopoDS_Shape& theShape)
3150 if (theShape.IsNull() || myMesh == 0)
3153 if (!myShapesMap.Add(theShape)) return;
3155 myCurShapeType = theShape.ShapeType();
3156 switch (myCurShapeType)
3158 case TopAbs_COMPOUND:
3159 case TopAbs_COMPSOLID:
3163 TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
3164 for (; anIt.More(); anIt.Next()) addShape(anIt.Value());
3169 myCurSC.Load(theShape);
3175 TopoDS_Face aFace = TopoDS::Face(theShape);
3176 BRepAdaptor_Surface SA (aFace, true);
3178 u1 = SA.FirstUParameter(),
3179 u2 = SA.LastUParameter(),
3180 v1 = SA.FirstVParameter(),
3181 v2 = SA.LastVParameter();
3182 Handle(Geom_Surface) surf = BRep_Tool::Surface(aFace);
3183 myCurProjFace.Init(surf, u1,u2, v1,v2);
3190 TopoDS_Edge anEdge = TopoDS::Edge(theShape);
3191 Standard_Real u1, u2;
3192 Handle(Geom_Curve) curve = BRep_Tool::Curve(anEdge, u1, u2);
3193 myCurProjEdge.Init(curve, u1, u2);
3199 TopoDS_Vertex aV = TopoDS::Vertex(theShape);
3200 myCurPnt = BRep_Tool::Pnt(aV);
3209 void ElementsOnShape::process()
3211 if (myShape.IsNull() || myMesh == 0)
3214 if (myType == SMDSAbs_Node)
3216 SMDS_NodeIteratorPtr anIter = myMesh->nodesIterator();
3217 while (anIter->more())
3218 process(anIter->next());
3222 if (myType == SMDSAbs_Edge || myType == SMDSAbs_All)
3224 SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
3225 while (anIter->more())
3226 process(anIter->next());
3229 if (myType == SMDSAbs_Face || myType == SMDSAbs_All)
3231 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
3232 while (anIter->more()) {
3233 process(anIter->next());
3237 if (myType == SMDSAbs_Volume || myType == SMDSAbs_All)
3239 SMDS_VolumeIteratorPtr anIter = myMesh->volumesIterator();
3240 while (anIter->more())
3241 process(anIter->next());
3246 void ElementsOnShape::process (const SMDS_MeshElement* theElemPtr)
3248 if (myShape.IsNull())
3251 SMDS_ElemIteratorPtr aNodeItr = theElemPtr->nodesIterator();
3252 bool isSatisfy = myAllNodesFlag;
3254 gp_XYZ centerXYZ (0, 0, 0);
3256 while (aNodeItr->more() && (isSatisfy == myAllNodesFlag))
3258 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
3259 gp_Pnt aPnt (aNode->X(), aNode->Y(), aNode->Z());
3260 centerXYZ += aPnt.XYZ();
3262 switch (myCurShapeType)
3266 myCurSC.Perform(aPnt, myToler);
3267 isSatisfy = (myCurSC.State() == TopAbs_IN || myCurSC.State() == TopAbs_ON);
3272 myCurProjFace.Perform(aPnt);
3273 isSatisfy = (myCurProjFace.IsDone() && myCurProjFace.LowerDistance() <= myToler);
3276 // check relatively the face
3277 Quantity_Parameter u, v;
3278 myCurProjFace.LowerDistanceParameters(u, v);
3279 gp_Pnt2d aProjPnt (u, v);
3280 BRepClass_FaceClassifier aClsf (myCurFace, aProjPnt, myToler);
3281 isSatisfy = (aClsf.State() == TopAbs_IN || aClsf.State() == TopAbs_ON);
3287 myCurProjEdge.Perform(aPnt);
3288 isSatisfy = (myCurProjEdge.NbPoints() > 0 && myCurProjEdge.LowerDistance() <= myToler);
3293 isSatisfy = (aPnt.Distance(myCurPnt) <= myToler);
3303 if (isSatisfy && myCurShapeType == TopAbs_SOLID) { // Check the center point for volumes MantisBug 0020168
3304 centerXYZ /= theElemPtr->NbNodes();
3305 gp_Pnt aCenterPnt (centerXYZ);
3306 myCurSC.Perform(aCenterPnt, myToler);
3307 if ( !(myCurSC.State() == TopAbs_IN || myCurSC.State() == TopAbs_ON))
3312 myIds.Add(theElemPtr->GetID());
3315 TSequenceOfXYZ::TSequenceOfXYZ()
3318 TSequenceOfXYZ::TSequenceOfXYZ(size_type n) : myArray(n)
3321 TSequenceOfXYZ::TSequenceOfXYZ(size_type n, const gp_XYZ& t) : myArray(n,t)
3324 TSequenceOfXYZ::TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ) : myArray(theSequenceOfXYZ.myArray)
3327 template <class InputIterator>
3328 TSequenceOfXYZ::TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd): myArray(theBegin,theEnd)
3331 TSequenceOfXYZ::~TSequenceOfXYZ()
3334 TSequenceOfXYZ& TSequenceOfXYZ::operator=(const TSequenceOfXYZ& theSequenceOfXYZ)
3336 myArray = theSequenceOfXYZ.myArray;
3340 gp_XYZ& TSequenceOfXYZ::operator()(size_type n)
3342 return myArray[n-1];
3345 const gp_XYZ& TSequenceOfXYZ::operator()(size_type n) const
3347 return myArray[n-1];
3350 void TSequenceOfXYZ::clear()
3355 void TSequenceOfXYZ::reserve(size_type n)
3360 void TSequenceOfXYZ::push_back(const gp_XYZ& v)
3362 myArray.push_back(v);
3365 TSequenceOfXYZ::size_type TSequenceOfXYZ::size() const
3367 return myArray.size();