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"
73 inline double getAngle( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
75 gp_Vec v1( P1 - P2 ), v2( P3 - P2 );
77 return v1.Magnitude() < gp::Resolution() ||
78 v2.Magnitude() < gp::Resolution() ? 0 : v1.Angle( v2 );
81 inline double getArea( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
83 gp_Vec aVec1( P2 - P1 );
84 gp_Vec aVec2( P3 - P1 );
85 return ( aVec1 ^ aVec2 ).Magnitude() * 0.5;
88 inline double getArea( const gp_Pnt& P1, const gp_Pnt& P2, const gp_Pnt& P3 )
90 return getArea( P1.XYZ(), P2.XYZ(), P3.XYZ() );
95 inline double getDistance( const gp_XYZ& P1, const gp_XYZ& P2 )
97 double aDist = gp_Pnt( P1 ).Distance( gp_Pnt( P2 ) );
101 int getNbMultiConnection( const SMDS_Mesh* theMesh, const int theId )
106 const SMDS_MeshElement* anEdge = theMesh->FindElement( theId );
107 if ( anEdge == 0 || anEdge->GetType() != SMDSAbs_Edge/* || anEdge->NbNodes() != 2 */)
110 // for each pair of nodes in anEdge (there are 2 pairs in a quadratic edge)
111 // count elements containing both nodes of the pair.
112 // Note that there may be such cases for a quadratic edge (a horizontal line):
117 // +-----+------+ +-----+------+
120 // result sould be 2 in both cases
122 int aResult0 = 0, aResult1 = 0;
123 // last node, it is a medium one in a quadratic edge
124 const SMDS_MeshNode* aLastNode = anEdge->GetNode( anEdge->NbNodes() - 1 );
125 const SMDS_MeshNode* aNode0 = anEdge->GetNode( 0 );
126 const SMDS_MeshNode* aNode1 = anEdge->GetNode( 1 );
127 if ( aNode1 == aLastNode ) aNode1 = 0;
129 SMDS_ElemIteratorPtr anElemIter = aLastNode->GetInverseElementIterator();
130 while( anElemIter->more() ) {
131 const SMDS_MeshElement* anElem = anElemIter->next();
132 if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) {
133 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
134 while ( anIter->more() ) {
135 if ( const SMDS_MeshElement* anElemNode = anIter->next() ) {
136 if ( anElemNode == aNode0 ) {
138 if ( !aNode1 ) break; // not a quadratic edge
140 else if ( anElemNode == aNode1 )
146 int aResult = std::max ( aResult0, aResult1 );
148 // TColStd_MapOfInteger aMap;
150 // SMDS_ElemIteratorPtr anIter = anEdge->nodesIterator();
151 // if ( anIter != 0 ) {
152 // while( anIter->more() ) {
153 // const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next();
156 // SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator();
157 // while( anElemIter->more() ) {
158 // const SMDS_MeshElement* anElem = anElemIter->next();
159 // if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) {
160 // int anId = anElem->GetID();
162 // if ( anIter->more() ) // i.e. first node
164 // else if ( aMap.Contains( anId ) )
178 using namespace SMESH::Controls;
185 Class : NumericalFunctor
186 Description : Base class for numerical functors
188 NumericalFunctor::NumericalFunctor():
194 void NumericalFunctor::SetMesh( const SMDS_Mesh* theMesh )
199 bool NumericalFunctor::GetPoints(const int theId,
200 TSequenceOfXYZ& theRes ) const
207 return GetPoints( myMesh->FindElement( theId ), theRes );
210 bool NumericalFunctor::GetPoints(const SMDS_MeshElement* anElem,
211 TSequenceOfXYZ& theRes )
218 theRes.reserve( anElem->NbNodes() );
220 // Get nodes of the element
221 SMDS_ElemIteratorPtr anIter;
223 if ( anElem->IsQuadratic() ) {
224 switch ( anElem->GetType() ) {
226 anIter = static_cast<const SMDS_QuadraticEdge*>
227 (anElem)->interlacedNodesElemIterator();
230 anIter = static_cast<const SMDS_QuadraticFaceOfNodes*>
231 (anElem)->interlacedNodesElemIterator();
234 anIter = anElem->nodesIterator();
239 anIter = anElem->nodesIterator();
243 while( anIter->more() ) {
244 if ( const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>( anIter->next() ))
245 theRes.push_back( gp_XYZ( aNode->X(), aNode->Y(), aNode->Z() ) );
252 long NumericalFunctor::GetPrecision() const
257 void NumericalFunctor::SetPrecision( const long thePrecision )
259 myPrecision = thePrecision;
262 double NumericalFunctor::GetValue( long theId )
264 myCurrElement = myMesh->FindElement( theId );
266 if ( GetPoints( theId, P ))
268 double aVal = GetValue( P );
269 if ( myPrecision >= 0 )
271 double prec = pow( 10., (double)( myPrecision ) );
272 aVal = floor( aVal * prec + 0.5 ) / prec;
280 //================================================================================
282 * \brief Return histogram of functor values
283 * \param nbIntervals - number of intervals
284 * \param nbEvents - number of mesh elements having values within i-th interval
285 * \param funValues - boundaries of intervals
287 //================================================================================
289 void NumericalFunctor::GetHistogram(int nbIntervals,
290 std::vector<int>& nbEvents,
291 std::vector<double>& funValues)
293 if ( nbIntervals < 1 ||
295 !myMesh->GetMeshInfo().NbElements( GetType() ))
297 nbEvents.resize( nbIntervals, 0 );
298 funValues.resize( nbIntervals+1 );
300 // get all values sorted
301 std::multiset< double > values;
302 SMDS_ElemIteratorPtr elemIt = myMesh->elementsIterator(GetType());
303 while ( elemIt->more() )
304 values.insert( GetValue( elemIt->next()->GetID() ));
306 // case nbIntervals == 1
307 funValues[0] = *values.begin();
308 funValues[nbIntervals] = *values.rbegin();
309 if ( nbIntervals == 1 )
311 nbEvents[0] = values.size();
315 if (funValues.front() == funValues.back())
318 nbEvents.resize( nbIntervals, values.size() );
319 funValues.resize( nbIntervals+1);
322 std::multiset< double >::iterator min = values.begin(), max;
323 for ( int i = 0; i < nbIntervals; ++i )
325 double r = (i+1) / double( nbIntervals );
326 funValues[i+1] = funValues.front() * (1-r) + funValues.back() * r;
327 if ( min != values.end() && *min <= funValues[i+1] )
329 max = values.upper_bound( funValues[i+1] ); // greater than funValues[i+1], or end()
330 nbEvents[i] = std::distance( min, max );
336 //=======================================================================
337 //function : GetValue
339 //=======================================================================
341 double Volume::GetValue( long theElementId )
343 if ( theElementId && myMesh ) {
344 SMDS_VolumeTool aVolumeTool;
345 if ( aVolumeTool.Set( myMesh->FindElement( theElementId )))
346 return aVolumeTool.GetSize();
351 //=======================================================================
352 //function : GetBadRate
353 //purpose : meaningless as it is not quality control functor
354 //=======================================================================
356 double Volume::GetBadRate( double Value, int /*nbNodes*/ ) const
361 //=======================================================================
364 //=======================================================================
366 SMDSAbs_ElementType Volume::GetType() const
368 return SMDSAbs_Volume;
374 Description : Functor for calculation of minimum angle
377 double MinimumAngle::GetValue( const TSequenceOfXYZ& P )
384 aMin = getAngle(P( P.size() ), P( 1 ), P( 2 ));
385 aMin = Min(aMin,getAngle(P( P.size()-1 ), P( P.size() ), P( 1 )));
387 for (int i=2; i<P.size();i++){
388 double A0 = getAngle( P( i-1 ), P( i ), P( i+1 ) );
392 return aMin * 180.0 / PI;
395 double MinimumAngle::GetBadRate( double Value, int nbNodes ) const
397 //const double aBestAngle = PI / nbNodes;
398 const double aBestAngle = 180.0 - ( 360.0 / double(nbNodes) );
399 return ( fabs( aBestAngle - Value ));
402 SMDSAbs_ElementType MinimumAngle::GetType() const
410 Description : Functor for calculating aspect ratio
412 double AspectRatio::GetValue( const TSequenceOfXYZ& P )
414 // According to "Mesh quality control" by Nadir Bouhamau referring to
415 // Pascal Jean Frey and Paul-Louis George. Maillages, applications aux elements finis.
416 // Hermes Science publications, Paris 1999 ISBN 2-7462-0024-4
419 int nbNodes = P.size();
424 // Compute aspect ratio
426 if ( nbNodes == 3 ) {
427 // Compute lengths of the sides
428 std::vector< double > aLen (nbNodes);
429 for ( int i = 0; i < nbNodes - 1; i++ )
430 aLen[ i ] = getDistance( P( i + 1 ), P( i + 2 ) );
431 aLen[ nbNodes - 1 ] = getDistance( P( 1 ), P( nbNodes ) );
432 // Q = alfa * h * p / S, where
434 // alfa = sqrt( 3 ) / 6
435 // h - length of the longest edge
436 // p - half perimeter
437 // S - triangle surface
438 const double alfa = sqrt( 3. ) / 6.;
439 double maxLen = Max( aLen[ 0 ], Max( aLen[ 1 ], aLen[ 2 ] ) );
440 double half_perimeter = ( aLen[0] + aLen[1] + aLen[2] ) / 2.;
441 double anArea = getArea( P( 1 ), P( 2 ), P( 3 ) );
442 if ( anArea <= Precision::Confusion() )
444 return alfa * maxLen * half_perimeter / anArea;
446 else if ( nbNodes == 6 ) { // quadratic triangles
447 // Compute lengths of the sides
448 std::vector< double > aLen (3);
449 aLen[0] = getDistance( P(1), P(3) );
450 aLen[1] = getDistance( P(3), P(5) );
451 aLen[2] = getDistance( P(5), P(1) );
452 // Q = alfa * h * p / S, where
454 // alfa = sqrt( 3 ) / 6
455 // h - length of the longest edge
456 // p - half perimeter
457 // S - triangle surface
458 const double alfa = sqrt( 3. ) / 6.;
459 double maxLen = Max( aLen[ 0 ], Max( aLen[ 1 ], aLen[ 2 ] ) );
460 double half_perimeter = ( aLen[0] + aLen[1] + aLen[2] ) / 2.;
461 double anArea = getArea( P(1), P(3), P(5) );
462 if ( anArea <= Precision::Confusion() )
464 return alfa * maxLen * half_perimeter / anArea;
466 else if( nbNodes == 4 ) { // quadrangle
467 // return aspect ratio of the worst triange which can be built
468 // taking three nodes of the quadrangle
469 TSequenceOfXYZ triaPnts(3);
470 // triangle on nodes 1 3 2
474 double ar = GetValue( triaPnts );
475 // triangle on nodes 1 3 4
477 ar = Max ( ar, GetValue( triaPnts ));
478 // triangle on nodes 1 2 4
480 ar = Max ( ar, GetValue( triaPnts ));
481 // triangle on nodes 3 2 4
483 ar = Max ( ar, GetValue( triaPnts ));
487 else if( nbNodes == 8 ){ // nbNodes==8 - quadratic quadrangle
488 // return aspect ratio of the worst triange which can be built
489 // taking three nodes of the quadrangle
490 TSequenceOfXYZ triaPnts(3);
491 // triangle on nodes 1 3 2
495 double ar = GetValue( triaPnts );
496 // triangle on nodes 1 3 4
498 ar = Max ( ar, GetValue( triaPnts ));
499 // triangle on nodes 1 2 4
501 ar = Max ( ar, GetValue( triaPnts ));
502 // triangle on nodes 3 2 4
504 ar = Max ( ar, GetValue( triaPnts ));
511 double AspectRatio::GetBadRate( double Value, int /*nbNodes*/ ) const
513 // the aspect ratio is in the range [1.0,infinity]
516 return Value / 1000.;
519 SMDSAbs_ElementType AspectRatio::GetType() const
526 Class : AspectRatio3D
527 Description : Functor for calculating aspect ratio
531 inline double getHalfPerimeter(double theTria[3]){
532 return (theTria[0] + theTria[1] + theTria[2])/2.0;
535 inline double getArea(double theHalfPerim, double theTria[3]){
536 return sqrt(theHalfPerim*
537 (theHalfPerim-theTria[0])*
538 (theHalfPerim-theTria[1])*
539 (theHalfPerim-theTria[2]));
542 inline double getVolume(double theLen[6]){
543 double a2 = theLen[0]*theLen[0];
544 double b2 = theLen[1]*theLen[1];
545 double c2 = theLen[2]*theLen[2];
546 double d2 = theLen[3]*theLen[3];
547 double e2 = theLen[4]*theLen[4];
548 double f2 = theLen[5]*theLen[5];
549 double P = 4.0*a2*b2*d2;
550 double Q = a2*(b2+d2-e2)-b2*(a2+d2-f2)-d2*(a2+b2-c2);
551 double R = (b2+d2-e2)*(a2+d2-f2)*(a2+d2-f2);
552 return sqrt(P-Q+R)/12.0;
555 inline double getVolume2(double theLen[6]){
556 double a2 = theLen[0]*theLen[0];
557 double b2 = theLen[1]*theLen[1];
558 double c2 = theLen[2]*theLen[2];
559 double d2 = theLen[3]*theLen[3];
560 double e2 = theLen[4]*theLen[4];
561 double f2 = theLen[5]*theLen[5];
563 double P = a2*e2*(b2+c2+d2+f2-a2-e2);
564 double Q = b2*f2*(a2+c2+d2+e2-b2-f2);
565 double R = c2*d2*(a2+b2+e2+f2-c2-d2);
566 double S = a2*b2*d2+b2*c2*e2+a2*c2*f2+d2*e2*f2;
568 return sqrt(P+Q+R-S)/12.0;
571 inline double getVolume(const TSequenceOfXYZ& P){
572 gp_Vec aVec1( P( 2 ) - P( 1 ) );
573 gp_Vec aVec2( P( 3 ) - P( 1 ) );
574 gp_Vec aVec3( P( 4 ) - P( 1 ) );
575 gp_Vec anAreaVec( aVec1 ^ aVec2 );
576 return fabs(aVec3 * anAreaVec) / 6.0;
579 inline double getMaxHeight(double theLen[6])
581 double aHeight = std::max(theLen[0],theLen[1]);
582 aHeight = std::max(aHeight,theLen[2]);
583 aHeight = std::max(aHeight,theLen[3]);
584 aHeight = std::max(aHeight,theLen[4]);
585 aHeight = std::max(aHeight,theLen[5]);
591 double AspectRatio3D::GetValue( const TSequenceOfXYZ& P )
593 double aQuality = 0.0;
594 if(myCurrElement->IsPoly()) return aQuality;
596 int nbNodes = P.size();
598 if(myCurrElement->IsQuadratic()) {
599 if(nbNodes==10) nbNodes=4; // quadratic tetrahedron
600 else if(nbNodes==13) nbNodes=5; // quadratic pyramid
601 else if(nbNodes==15) nbNodes=6; // quadratic pentahedron
602 else if(nbNodes==20) nbNodes=8; // quadratic hexahedron
603 else return aQuality;
609 getDistance(P( 1 ),P( 2 )), // a
610 getDistance(P( 2 ),P( 3 )), // b
611 getDistance(P( 3 ),P( 1 )), // c
612 getDistance(P( 2 ),P( 4 )), // d
613 getDistance(P( 3 ),P( 4 )), // e
614 getDistance(P( 1 ),P( 4 )) // f
616 double aTria[4][3] = {
617 {aLen[0],aLen[1],aLen[2]}, // abc
618 {aLen[0],aLen[3],aLen[5]}, // adf
619 {aLen[1],aLen[3],aLen[4]}, // bde
620 {aLen[2],aLen[4],aLen[5]} // cef
622 double aSumArea = 0.0;
623 double aHalfPerimeter = getHalfPerimeter(aTria[0]);
624 double anArea = getArea(aHalfPerimeter,aTria[0]);
626 aHalfPerimeter = getHalfPerimeter(aTria[1]);
627 anArea = getArea(aHalfPerimeter,aTria[1]);
629 aHalfPerimeter = getHalfPerimeter(aTria[2]);
630 anArea = getArea(aHalfPerimeter,aTria[2]);
632 aHalfPerimeter = getHalfPerimeter(aTria[3]);
633 anArea = getArea(aHalfPerimeter,aTria[3]);
635 double aVolume = getVolume(P);
636 //double aVolume = getVolume(aLen);
637 double aHeight = getMaxHeight(aLen);
638 static double aCoeff = sqrt(2.0)/12.0;
639 if ( aVolume > DBL_MIN )
640 aQuality = aCoeff*aHeight*aSumArea/aVolume;
645 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 3 ),P( 5 )};
646 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
649 gp_XYZ aXYZ[4] = {P( 1 ),P( 3 ),P( 4 ),P( 5 )};
650 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
653 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 5 )};
654 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
657 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 4 ),P( 5 )};
658 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
664 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 6 )};
665 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
668 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 3 )};
669 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
672 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 6 )};
673 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
676 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
677 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
680 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 6 )};
681 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
684 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 3 )};
685 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
691 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
692 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
695 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 4 )};
696 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
699 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 7 )};
700 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
703 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 8 )};
704 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
707 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 3 )};
708 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
711 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 4 )};
712 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
715 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 7 )};
716 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
719 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 8 )};
720 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
723 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 3 )};
724 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
727 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 4 )};
728 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
731 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 7 )};
732 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
735 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 8 )};
736 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
739 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 1 )};
740 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
743 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 2 )};
744 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
747 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 5 )};
748 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
751 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 6 )};
752 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
755 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 1 )};
756 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
759 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 2 )};
760 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
763 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 5 )};
764 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
767 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 6 )};
768 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
771 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 1 )};
772 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
775 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
776 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
779 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 5 )};
780 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
783 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 6 )};
784 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
787 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
788 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
791 gp_XYZ aXYZ[4] = {P( 4 ),P( 5 ),P( 8 ),P( 2 )};
792 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
795 gp_XYZ aXYZ[4] = {P( 1 ),P( 4 ),P( 5 ),P( 3 )};
796 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
799 gp_XYZ aXYZ[4] = {P( 3 ),P( 6 ),P( 7 ),P( 1 )};
800 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
803 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 6 ),P( 4 )};
804 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
807 gp_XYZ aXYZ[4] = {P( 5 ),P( 6 ),P( 8 ),P( 3 )};
808 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
811 gp_XYZ aXYZ[4] = {P( 7 ),P( 8 ),P( 6 ),P( 1 )};
812 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
815 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 7 )};
816 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
819 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 2 ),P( 5 )};
820 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
826 // avaluate aspect ratio of quadranle faces
827 AspectRatio aspect2D;
828 SMDS_VolumeTool::VolumeType type = SMDS_VolumeTool::GetType( nbNodes );
829 int nbFaces = SMDS_VolumeTool::NbFaces( type );
830 TSequenceOfXYZ points(4);
831 for ( int i = 0; i < nbFaces; ++i ) { // loop on faces of a volume
832 if ( SMDS_VolumeTool::NbFaceNodes( type, i ) != 4 )
834 const int* pInd = SMDS_VolumeTool::GetFaceNodesIndices( type, i, true );
835 for ( int p = 0; p < 4; ++p ) // loop on nodes of a quadranle face
836 points( p + 1 ) = P( pInd[ p ] + 1 );
837 aQuality = std::max( aQuality, aspect2D.GetValue( points ));
843 double AspectRatio3D::GetBadRate( double Value, int /*nbNodes*/ ) const
845 // the aspect ratio is in the range [1.0,infinity]
848 return Value / 1000.;
851 SMDSAbs_ElementType AspectRatio3D::GetType() const
853 return SMDSAbs_Volume;
859 Description : Functor for calculating warping
861 double Warping::GetValue( const TSequenceOfXYZ& P )
866 gp_XYZ G = ( P( 1 ) + P( 2 ) + P( 3 ) + P( 4 ) ) / 4.;
868 double A1 = ComputeA( P( 1 ), P( 2 ), P( 3 ), G );
869 double A2 = ComputeA( P( 2 ), P( 3 ), P( 4 ), G );
870 double A3 = ComputeA( P( 3 ), P( 4 ), P( 1 ), G );
871 double A4 = ComputeA( P( 4 ), P( 1 ), P( 2 ), G );
873 return Max( Max( A1, A2 ), Max( A3, A4 ) );
876 double Warping::ComputeA( const gp_XYZ& thePnt1,
877 const gp_XYZ& thePnt2,
878 const gp_XYZ& thePnt3,
879 const gp_XYZ& theG ) const
881 double aLen1 = gp_Pnt( thePnt1 ).Distance( gp_Pnt( thePnt2 ) );
882 double aLen2 = gp_Pnt( thePnt2 ).Distance( gp_Pnt( thePnt3 ) );
883 double L = Min( aLen1, aLen2 ) * 0.5;
884 if ( L < Precision::Confusion())
887 gp_XYZ GI = ( thePnt2 + thePnt1 ) / 2. - theG;
888 gp_XYZ GJ = ( thePnt3 + thePnt2 ) / 2. - theG;
889 gp_XYZ N = GI.Crossed( GJ );
891 if ( N.Modulus() < gp::Resolution() )
896 double H = ( thePnt2 - theG ).Dot( N );
897 return asin( fabs( H / L ) ) * 180. / PI;
900 double Warping::GetBadRate( double Value, int /*nbNodes*/ ) const
902 // the warp is in the range [0.0,PI/2]
903 // 0.0 = good (no warp)
904 // PI/2 = bad (face pliee)
908 SMDSAbs_ElementType Warping::GetType() const
916 Description : Functor for calculating taper
918 double Taper::GetValue( const TSequenceOfXYZ& P )
924 double J1 = getArea( P( 4 ), P( 1 ), P( 2 ) ) / 2.;
925 double J2 = getArea( P( 3 ), P( 1 ), P( 2 ) ) / 2.;
926 double J3 = getArea( P( 2 ), P( 3 ), P( 4 ) ) / 2.;
927 double J4 = getArea( P( 3 ), P( 4 ), P( 1 ) ) / 2.;
929 double JA = 0.25 * ( J1 + J2 + J3 + J4 );
930 if ( JA <= Precision::Confusion() )
933 double T1 = fabs( ( J1 - JA ) / JA );
934 double T2 = fabs( ( J2 - JA ) / JA );
935 double T3 = fabs( ( J3 - JA ) / JA );
936 double T4 = fabs( ( J4 - JA ) / JA );
938 return Max( Max( T1, T2 ), Max( T3, T4 ) );
941 double Taper::GetBadRate( double Value, int /*nbNodes*/ ) const
943 // the taper is in the range [0.0,1.0]
944 // 0.0 = good (no taper)
945 // 1.0 = bad (les cotes opposes sont allignes)
949 SMDSAbs_ElementType Taper::GetType() const
957 Description : Functor for calculating skew in degrees
959 static inline double skewAngle( const gp_XYZ& p1, const gp_XYZ& p2, const gp_XYZ& p3 )
961 gp_XYZ p12 = ( p2 + p1 ) / 2.;
962 gp_XYZ p23 = ( p3 + p2 ) / 2.;
963 gp_XYZ p31 = ( p3 + p1 ) / 2.;
965 gp_Vec v1( p31 - p2 ), v2( p12 - p23 );
967 return v1.Magnitude() < gp::Resolution() || v2.Magnitude() < gp::Resolution() ? 0. : v1.Angle( v2 );
970 double Skew::GetValue( const TSequenceOfXYZ& P )
972 if ( P.size() != 3 && P.size() != 4 )
976 static double PI2 = PI / 2.;
979 double A0 = fabs( PI2 - skewAngle( P( 3 ), P( 1 ), P( 2 ) ) );
980 double A1 = fabs( PI2 - skewAngle( P( 1 ), P( 2 ), P( 3 ) ) );
981 double A2 = fabs( PI2 - skewAngle( P( 2 ), P( 3 ), P( 1 ) ) );
983 return Max( A0, Max( A1, A2 ) ) * 180. / PI;
987 gp_XYZ p12 = ( P( 1 ) + P( 2 ) ) / 2.;
988 gp_XYZ p23 = ( P( 2 ) + P( 3 ) ) / 2.;
989 gp_XYZ p34 = ( P( 3 ) + P( 4 ) ) / 2.;
990 gp_XYZ p41 = ( P( 4 ) + P( 1 ) ) / 2.;
992 gp_Vec v1( p34 - p12 ), v2( p23 - p41 );
993 double A = v1.Magnitude() <= gp::Resolution() || v2.Magnitude() <= gp::Resolution()
994 ? 0. : fabs( PI2 - v1.Angle( v2 ) );
997 if ( A < Precision::Angular() )
1000 return A * 180. / PI;
1004 double Skew::GetBadRate( double Value, int /*nbNodes*/ ) const
1006 // the skew is in the range [0.0,PI/2].
1012 SMDSAbs_ElementType Skew::GetType() const
1014 return SMDSAbs_Face;
1020 Description : Functor for calculating area
1022 double Area::GetValue( const TSequenceOfXYZ& P )
1025 if ( P.size() > 2 ) {
1026 gp_Vec aVec1( P(2) - P(1) );
1027 gp_Vec aVec2( P(3) - P(1) );
1028 gp_Vec SumVec = aVec1 ^ aVec2;
1029 for (int i=4; i<=P.size(); i++) {
1030 gp_Vec aVec1( P(i-1) - P(1) );
1031 gp_Vec aVec2( P(i) - P(1) );
1032 gp_Vec tmp = aVec1 ^ aVec2;
1035 val = SumVec.Magnitude() * 0.5;
1040 double Area::GetBadRate( double Value, int /*nbNodes*/ ) const
1042 // meaningless as it is not a quality control functor
1046 SMDSAbs_ElementType Area::GetType() const
1048 return SMDSAbs_Face;
1054 Description : Functor for calculating length off edge
1056 double Length::GetValue( const TSequenceOfXYZ& P )
1058 switch ( P.size() ) {
1059 case 2: return getDistance( P( 1 ), P( 2 ) );
1060 case 3: return getDistance( P( 1 ), P( 2 ) ) + getDistance( P( 2 ), P( 3 ) );
1065 double Length::GetBadRate( double Value, int /*nbNodes*/ ) const
1067 // meaningless as it is not quality control functor
1071 SMDSAbs_ElementType Length::GetType() const
1073 return SMDSAbs_Edge;
1078 Description : Functor for calculating length of edge
1081 double Length2D::GetValue( long theElementId)
1085 //cout<<"Length2D::GetValue"<<endl;
1086 if (GetPoints(theElementId,P)){
1087 //for(int jj=1; jj<=P.size(); jj++)
1088 // cout<<"jj="<<jj<<" P("<<P(jj).X()<<","<<P(jj).Y()<<","<<P(jj).Z()<<")"<<endl;
1090 double aVal;// = GetValue( P );
1091 const SMDS_MeshElement* aElem = myMesh->FindElement( theElementId );
1092 SMDSAbs_ElementType aType = aElem->GetType();
1101 aVal = getDistance( P( 1 ), P( 2 ) );
1104 else if (len == 3){ // quadratic edge
1105 aVal = getDistance(P( 1 ),P( 3 )) + getDistance(P( 3 ),P( 2 ));
1109 if (len == 3){ // triangles
1110 double L1 = getDistance(P( 1 ),P( 2 ));
1111 double L2 = getDistance(P( 2 ),P( 3 ));
1112 double L3 = getDistance(P( 3 ),P( 1 ));
1113 aVal = Max(L1,Max(L2,L3));
1116 else if (len == 4){ // quadrangles
1117 double L1 = getDistance(P( 1 ),P( 2 ));
1118 double L2 = getDistance(P( 2 ),P( 3 ));
1119 double L3 = getDistance(P( 3 ),P( 4 ));
1120 double L4 = getDistance(P( 4 ),P( 1 ));
1121 aVal = Max(Max(L1,L2),Max(L3,L4));
1124 if (len == 6){ // quadratic triangles
1125 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1126 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1127 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 1 ));
1128 aVal = Max(L1,Max(L2,L3));
1129 //cout<<"L1="<<L1<<" L2="<<L2<<"L3="<<L3<<" aVal="<<aVal<<endl;
1132 else if (len == 8){ // quadratic quadrangles
1133 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1134 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1135 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 7 ));
1136 double L4 = getDistance(P( 7 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
1137 aVal = Max(Max(L1,L2),Max(L3,L4));
1140 case SMDSAbs_Volume:
1141 if (len == 4){ // tetraidrs
1142 double L1 = getDistance(P( 1 ),P( 2 ));
1143 double L2 = getDistance(P( 2 ),P( 3 ));
1144 double L3 = getDistance(P( 3 ),P( 1 ));
1145 double L4 = getDistance(P( 1 ),P( 4 ));
1146 double L5 = getDistance(P( 2 ),P( 4 ));
1147 double L6 = getDistance(P( 3 ),P( 4 ));
1148 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1151 else if (len == 5){ // piramids
1152 double L1 = getDistance(P( 1 ),P( 2 ));
1153 double L2 = getDistance(P( 2 ),P( 3 ));
1154 double L3 = getDistance(P( 3 ),P( 1 ));
1155 double L4 = getDistance(P( 4 ),P( 1 ));
1156 double L5 = getDistance(P( 1 ),P( 5 ));
1157 double L6 = getDistance(P( 2 ),P( 5 ));
1158 double L7 = getDistance(P( 3 ),P( 5 ));
1159 double L8 = getDistance(P( 4 ),P( 5 ));
1161 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1162 aVal = Max(aVal,Max(L7,L8));
1165 else if (len == 6){ // pentaidres
1166 double L1 = getDistance(P( 1 ),P( 2 ));
1167 double L2 = getDistance(P( 2 ),P( 3 ));
1168 double L3 = getDistance(P( 3 ),P( 1 ));
1169 double L4 = getDistance(P( 4 ),P( 5 ));
1170 double L5 = getDistance(P( 5 ),P( 6 ));
1171 double L6 = getDistance(P( 6 ),P( 4 ));
1172 double L7 = getDistance(P( 1 ),P( 4 ));
1173 double L8 = getDistance(P( 2 ),P( 5 ));
1174 double L9 = getDistance(P( 3 ),P( 6 ));
1176 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1177 aVal = Max(aVal,Max(Max(L7,L8),L9));
1180 else if (len == 8){ // hexaider
1181 double L1 = getDistance(P( 1 ),P( 2 ));
1182 double L2 = getDistance(P( 2 ),P( 3 ));
1183 double L3 = getDistance(P( 3 ),P( 4 ));
1184 double L4 = getDistance(P( 4 ),P( 1 ));
1185 double L5 = getDistance(P( 5 ),P( 6 ));
1186 double L6 = getDistance(P( 6 ),P( 7 ));
1187 double L7 = getDistance(P( 7 ),P( 8 ));
1188 double L8 = getDistance(P( 8 ),P( 5 ));
1189 double L9 = getDistance(P( 1 ),P( 5 ));
1190 double L10= getDistance(P( 2 ),P( 6 ));
1191 double L11= getDistance(P( 3 ),P( 7 ));
1192 double L12= getDistance(P( 4 ),P( 8 ));
1194 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1195 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
1196 aVal = Max(aVal,Max(L11,L12));
1201 if (len == 10){ // quadratic tetraidrs
1202 double L1 = getDistance(P( 1 ),P( 5 )) + getDistance(P( 5 ),P( 2 ));
1203 double L2 = getDistance(P( 2 ),P( 6 )) + getDistance(P( 6 ),P( 3 ));
1204 double L3 = getDistance(P( 3 ),P( 7 )) + getDistance(P( 7 ),P( 1 ));
1205 double L4 = getDistance(P( 1 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
1206 double L5 = getDistance(P( 2 ),P( 9 )) + getDistance(P( 9 ),P( 4 ));
1207 double L6 = getDistance(P( 3 ),P( 10 )) + getDistance(P( 10 ),P( 4 ));
1208 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1211 else if (len == 13){ // quadratic piramids
1212 double L1 = getDistance(P( 1 ),P( 6 )) + getDistance(P( 6 ),P( 2 ));
1213 double L2 = getDistance(P( 2 ),P( 7 )) + getDistance(P( 7 ),P( 3 ));
1214 double L3 = getDistance(P( 3 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
1215 double L4 = getDistance(P( 4 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1216 double L5 = getDistance(P( 1 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1217 double L6 = getDistance(P( 2 ),P( 11 )) + getDistance(P( 11 ),P( 5 ));
1218 double L7 = getDistance(P( 3 ),P( 12 )) + getDistance(P( 12 ),P( 5 ));
1219 double L8 = getDistance(P( 4 ),P( 13 )) + getDistance(P( 13 ),P( 5 ));
1220 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1221 aVal = Max(aVal,Max(L7,L8));
1224 else if (len == 15){ // quadratic pentaidres
1225 double L1 = getDistance(P( 1 ),P( 7 )) + getDistance(P( 7 ),P( 2 ));
1226 double L2 = getDistance(P( 2 ),P( 8 )) + getDistance(P( 8 ),P( 3 ));
1227 double L3 = getDistance(P( 3 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1228 double L4 = getDistance(P( 4 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1229 double L5 = getDistance(P( 5 ),P( 11 )) + getDistance(P( 11 ),P( 6 ));
1230 double L6 = getDistance(P( 6 ),P( 12 )) + getDistance(P( 12 ),P( 4 ));
1231 double L7 = getDistance(P( 1 ),P( 13 )) + getDistance(P( 13 ),P( 4 ));
1232 double L8 = getDistance(P( 2 ),P( 14 )) + getDistance(P( 14 ),P( 5 ));
1233 double L9 = getDistance(P( 3 ),P( 15 )) + getDistance(P( 15 ),P( 6 ));
1234 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1235 aVal = Max(aVal,Max(Max(L7,L8),L9));
1238 else if (len == 20){ // quadratic hexaider
1239 double L1 = getDistance(P( 1 ),P( 9 )) + getDistance(P( 9 ),P( 2 ));
1240 double L2 = getDistance(P( 2 ),P( 10 )) + getDistance(P( 10 ),P( 3 ));
1241 double L3 = getDistance(P( 3 ),P( 11 )) + getDistance(P( 11 ),P( 4 ));
1242 double L4 = getDistance(P( 4 ),P( 12 )) + getDistance(P( 12 ),P( 1 ));
1243 double L5 = getDistance(P( 5 ),P( 13 )) + getDistance(P( 13 ),P( 6 ));
1244 double L6 = getDistance(P( 6 ),P( 14 )) + getDistance(P( 14 ),P( 7 ));
1245 double L7 = getDistance(P( 7 ),P( 15 )) + getDistance(P( 15 ),P( 8 ));
1246 double L8 = getDistance(P( 8 ),P( 16 )) + getDistance(P( 16 ),P( 5 ));
1247 double L9 = getDistance(P( 1 ),P( 17 )) + getDistance(P( 17 ),P( 5 ));
1248 double L10= getDistance(P( 2 ),P( 18 )) + getDistance(P( 18 ),P( 6 ));
1249 double L11= getDistance(P( 3 ),P( 19 )) + getDistance(P( 19 ),P( 7 ));
1250 double L12= getDistance(P( 4 ),P( 20 )) + getDistance(P( 20 ),P( 8 ));
1251 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1252 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
1253 aVal = Max(aVal,Max(L11,L12));
1265 if ( myPrecision >= 0 )
1267 double prec = pow( 10., (double)( myPrecision ) );
1268 aVal = floor( aVal * prec + 0.5 ) / prec;
1277 double Length2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1279 // meaningless as it is not quality control functor
1283 SMDSAbs_ElementType Length2D::GetType() const
1285 return SMDSAbs_Face;
1288 Length2D::Value::Value(double theLength,long thePntId1, long thePntId2):
1291 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1292 if(thePntId1 > thePntId2){
1293 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1297 bool Length2D::Value::operator<(const Length2D::Value& x) const{
1298 if(myPntId[0] < x.myPntId[0]) return true;
1299 if(myPntId[0] == x.myPntId[0])
1300 if(myPntId[1] < x.myPntId[1]) return true;
1304 void Length2D::GetValues(TValues& theValues){
1306 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1307 for(; anIter->more(); ){
1308 const SMDS_MeshFace* anElem = anIter->next();
1310 if(anElem->IsQuadratic()) {
1311 const SMDS_QuadraticFaceOfNodes* F =
1312 static_cast<const SMDS_QuadraticFaceOfNodes*>(anElem);
1313 // use special nodes iterator
1314 SMDS_NodeIteratorPtr anIter = F->interlacedNodesIterator();
1319 const SMDS_MeshElement* aNode;
1321 aNode = anIter->next();
1322 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1323 P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1324 aNodeId[0] = aNodeId[1] = aNode->GetID();
1327 for(; anIter->more(); ){
1328 const SMDS_MeshNode* N1 = static_cast<const SMDS_MeshNode*> (anIter->next());
1329 P[2] = gp_Pnt(N1->X(),N1->Y(),N1->Z());
1330 aNodeId[2] = N1->GetID();
1331 aLength = P[1].Distance(P[2]);
1332 if(!anIter->more()) break;
1333 const SMDS_MeshNode* N2 = static_cast<const SMDS_MeshNode*> (anIter->next());
1334 P[3] = gp_Pnt(N2->X(),N2->Y(),N2->Z());
1335 aNodeId[3] = N2->GetID();
1336 aLength += P[2].Distance(P[3]);
1337 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1338 Value aValue2(aLength,aNodeId[2],aNodeId[3]);
1340 aNodeId[1] = aNodeId[3];
1341 theValues.insert(aValue1);
1342 theValues.insert(aValue2);
1344 aLength += P[2].Distance(P[0]);
1345 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1346 Value aValue2(aLength,aNodeId[2],aNodeId[0]);
1347 theValues.insert(aValue1);
1348 theValues.insert(aValue2);
1351 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
1356 const SMDS_MeshElement* aNode;
1357 if(aNodesIter->more()){
1358 aNode = aNodesIter->next();
1359 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1360 P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1361 aNodeId[0] = aNodeId[1] = aNode->GetID();
1364 for(; aNodesIter->more(); ){
1365 aNode = aNodesIter->next();
1366 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1367 long anId = aNode->GetID();
1369 P[2] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1371 aLength = P[1].Distance(P[2]);
1373 Value aValue(aLength,aNodeId[1],anId);
1376 theValues.insert(aValue);
1379 aLength = P[0].Distance(P[1]);
1381 Value aValue(aLength,aNodeId[0],aNodeId[1]);
1382 theValues.insert(aValue);
1388 Class : MultiConnection
1389 Description : Functor for calculating number of faces conneted to the edge
1391 double MultiConnection::GetValue( const TSequenceOfXYZ& P )
1395 double MultiConnection::GetValue( long theId )
1397 return getNbMultiConnection( myMesh, theId );
1400 double MultiConnection::GetBadRate( double Value, int /*nbNodes*/ ) const
1402 // meaningless as it is not quality control functor
1406 SMDSAbs_ElementType MultiConnection::GetType() const
1408 return SMDSAbs_Edge;
1412 Class : MultiConnection2D
1413 Description : Functor for calculating number of faces conneted to the edge
1415 double MultiConnection2D::GetValue( const TSequenceOfXYZ& P )
1420 double MultiConnection2D::GetValue( long theElementId )
1424 const SMDS_MeshElement* aFaceElem = myMesh->FindElement(theElementId);
1425 SMDSAbs_ElementType aType = aFaceElem->GetType();
1430 int i = 0, len = aFaceElem->NbNodes();
1431 SMDS_ElemIteratorPtr anIter = aFaceElem->nodesIterator();
1434 const SMDS_MeshNode *aNode, *aNode0;
1435 TColStd_MapOfInteger aMap, aMapPrev;
1437 for (i = 0; i <= len; i++) {
1442 if (anIter->more()) {
1443 aNode = (SMDS_MeshNode*)anIter->next();
1451 if (i == 0) aNode0 = aNode;
1453 SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator();
1454 while (anElemIter->more()) {
1455 const SMDS_MeshElement* anElem = anElemIter->next();
1456 if (anElem != 0 && anElem->GetType() == SMDSAbs_Face) {
1457 int anId = anElem->GetID();
1460 if (aMapPrev.Contains(anId)) {
1465 aResult = Max(aResult, aNb);
1476 double MultiConnection2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1478 // meaningless as it is not quality control functor
1482 SMDSAbs_ElementType MultiConnection2D::GetType() const
1484 return SMDSAbs_Face;
1487 MultiConnection2D::Value::Value(long thePntId1, long thePntId2)
1489 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1490 if(thePntId1 > thePntId2){
1491 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1495 bool MultiConnection2D::Value::operator<(const MultiConnection2D::Value& x) const{
1496 if(myPntId[0] < x.myPntId[0]) return true;
1497 if(myPntId[0] == x.myPntId[0])
1498 if(myPntId[1] < x.myPntId[1]) return true;
1502 void MultiConnection2D::GetValues(MValues& theValues){
1503 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1504 for(; anIter->more(); ){
1505 const SMDS_MeshFace* anElem = anIter->next();
1506 SMDS_ElemIteratorPtr aNodesIter;
1507 if ( anElem->IsQuadratic() )
1508 aNodesIter = static_cast<const SMDS_QuadraticFaceOfNodes*>
1509 (anElem)->interlacedNodesElemIterator();
1511 aNodesIter = anElem->nodesIterator();
1514 //int aNbConnects=0;
1515 const SMDS_MeshNode* aNode0;
1516 const SMDS_MeshNode* aNode1;
1517 const SMDS_MeshNode* aNode2;
1518 if(aNodesIter->more()){
1519 aNode0 = (SMDS_MeshNode*) aNodesIter->next();
1521 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode1;
1522 aNodeId[0] = aNodeId[1] = aNodes->GetID();
1524 for(; aNodesIter->more(); ) {
1525 aNode2 = (SMDS_MeshNode*) aNodesIter->next();
1526 long anId = aNode2->GetID();
1529 Value aValue(aNodeId[1],aNodeId[2]);
1530 MValues::iterator aItr = theValues.find(aValue);
1531 if (aItr != theValues.end()){
1536 theValues[aValue] = 1;
1539 //cout << "NodeIds: "<<aNodeId[1]<<","<<aNodeId[2]<<" nbconn="<<aNbConnects<<endl;
1540 aNodeId[1] = aNodeId[2];
1543 Value aValue(aNodeId[0],aNodeId[2]);
1544 MValues::iterator aItr = theValues.find(aValue);
1545 if (aItr != theValues.end()) {
1550 theValues[aValue] = 1;
1553 //cout << "NodeIds: "<<aNodeId[0]<<","<<aNodeId[2]<<" nbconn="<<aNbConnects<<endl;
1563 Class : BadOrientedVolume
1564 Description : Predicate bad oriented volumes
1567 BadOrientedVolume::BadOrientedVolume()
1572 void BadOrientedVolume::SetMesh( const SMDS_Mesh* theMesh )
1577 bool BadOrientedVolume::IsSatisfy( long theId )
1582 SMDS_VolumeTool vTool( myMesh->FindElement( theId ));
1583 return !vTool.IsForward();
1586 SMDSAbs_ElementType BadOrientedVolume::GetType() const
1588 return SMDSAbs_Volume;
1595 Description : Predicate for free borders
1598 FreeBorders::FreeBorders()
1603 void FreeBorders::SetMesh( const SMDS_Mesh* theMesh )
1608 bool FreeBorders::IsSatisfy( long theId )
1610 return getNbMultiConnection( myMesh, theId ) == 1;
1613 SMDSAbs_ElementType FreeBorders::GetType() const
1615 return SMDSAbs_Edge;
1621 Description : Predicate for free Edges
1623 FreeEdges::FreeEdges()
1628 void FreeEdges::SetMesh( const SMDS_Mesh* theMesh )
1633 bool FreeEdges::IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId )
1635 TColStd_MapOfInteger aMap;
1636 for ( int i = 0; i < 2; i++ )
1638 SMDS_ElemIteratorPtr anElemIter = theNodes[ i ]->GetInverseElementIterator();
1639 while( anElemIter->more() )
1641 const SMDS_MeshElement* anElem = anElemIter->next();
1642 if ( anElem != 0 && anElem->GetType() == SMDSAbs_Face )
1644 int anId = anElem->GetID();
1648 else if ( aMap.Contains( anId ) && anId != theFaceId )
1656 bool FreeEdges::IsSatisfy( long theId )
1661 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
1662 if ( aFace == 0 || aFace->GetType() != SMDSAbs_Face || aFace->NbNodes() < 3 )
1665 SMDS_ElemIteratorPtr anIter;
1666 if ( aFace->IsQuadratic() ) {
1667 anIter = static_cast<const SMDS_QuadraticFaceOfNodes*>
1668 (aFace)->interlacedNodesElemIterator();
1671 anIter = aFace->nodesIterator();
1676 int i = 0, nbNodes = aFace->NbNodes();
1677 std::vector <const SMDS_MeshNode*> aNodes( nbNodes+1 );
1678 while( anIter->more() )
1680 const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next();
1683 aNodes[ i++ ] = aNode;
1685 aNodes[ nbNodes ] = aNodes[ 0 ];
1687 for ( i = 0; i < nbNodes; i++ )
1688 if ( IsFreeEdge( &aNodes[ i ], theId ) )
1694 SMDSAbs_ElementType FreeEdges::GetType() const
1696 return SMDSAbs_Face;
1699 FreeEdges::Border::Border(long theElemId, long thePntId1, long thePntId2):
1702 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1703 if(thePntId1 > thePntId2){
1704 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1708 bool FreeEdges::Border::operator<(const FreeEdges::Border& x) const{
1709 if(myPntId[0] < x.myPntId[0]) return true;
1710 if(myPntId[0] == x.myPntId[0])
1711 if(myPntId[1] < x.myPntId[1]) return true;
1715 inline void UpdateBorders(const FreeEdges::Border& theBorder,
1716 FreeEdges::TBorders& theRegistry,
1717 FreeEdges::TBorders& theContainer)
1719 if(theRegistry.find(theBorder) == theRegistry.end()){
1720 theRegistry.insert(theBorder);
1721 theContainer.insert(theBorder);
1723 theContainer.erase(theBorder);
1727 void FreeEdges::GetBoreders(TBorders& theBorders)
1730 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1731 for(; anIter->more(); ){
1732 const SMDS_MeshFace* anElem = anIter->next();
1733 long anElemId = anElem->GetID();
1734 SMDS_ElemIteratorPtr aNodesIter;
1735 if ( anElem->IsQuadratic() )
1736 aNodesIter = static_cast<const SMDS_QuadraticFaceOfNodes*>(anElem)->
1737 interlacedNodesElemIterator();
1739 aNodesIter = anElem->nodesIterator();
1741 const SMDS_MeshElement* aNode;
1742 if(aNodesIter->more()){
1743 aNode = aNodesIter->next();
1744 aNodeId[0] = aNodeId[1] = aNode->GetID();
1746 for(; aNodesIter->more(); ){
1747 aNode = aNodesIter->next();
1748 long anId = aNode->GetID();
1749 Border aBorder(anElemId,aNodeId[1],anId);
1751 //std::cout<<aBorder.myPntId[0]<<"; "<<aBorder.myPntId[1]<<"; "<<aBorder.myElemId<<endl;
1752 UpdateBorders(aBorder,aRegistry,theBorders);
1754 Border aBorder(anElemId,aNodeId[0],aNodeId[1]);
1755 //std::cout<<aBorder.myPntId[0]<<"; "<<aBorder.myPntId[1]<<"; "<<aBorder.myElemId<<endl;
1756 UpdateBorders(aBorder,aRegistry,theBorders);
1758 //std::cout<<"theBorders.size() = "<<theBorders.size()<<endl;
1764 Description : Predicate for free nodes
1767 FreeNodes::FreeNodes()
1772 void FreeNodes::SetMesh( const SMDS_Mesh* theMesh )
1777 bool FreeNodes::IsSatisfy( long theNodeId )
1779 const SMDS_MeshNode* aNode = myMesh->FindNode( theNodeId );
1783 return (aNode->NbInverseElements() < 1);
1786 SMDSAbs_ElementType FreeNodes::GetType() const
1788 return SMDSAbs_Node;
1794 Description : Predicate for free faces
1797 FreeFaces::FreeFaces()
1802 void FreeFaces::SetMesh( const SMDS_Mesh* theMesh )
1807 bool FreeFaces::IsSatisfy( long theId )
1809 if (!myMesh) return false;
1810 // check that faces nodes refers to less than two common volumes
1811 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
1812 if ( !aFace || aFace->GetType() != SMDSAbs_Face )
1815 int nbNode = aFace->NbNodes();
1817 // collect volumes check that number of volumss with count equal nbNode not less than 2
1818 typedef map< SMDS_MeshElement*, int > TMapOfVolume; // map of volume counters
1819 typedef map< SMDS_MeshElement*, int >::iterator TItrMapOfVolume; // iterator
1820 TMapOfVolume mapOfVol;
1822 SMDS_ElemIteratorPtr nodeItr = aFace->nodesIterator();
1823 while ( nodeItr->more() ) {
1824 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(nodeItr->next());
1825 if ( !aNode ) continue;
1826 SMDS_ElemIteratorPtr volItr = aNode->GetInverseElementIterator(SMDSAbs_Volume);
1827 while ( volItr->more() ) {
1828 SMDS_MeshElement* aVol = (SMDS_MeshElement*)volItr->next();
1829 TItrMapOfVolume itr = mapOfVol.insert(make_pair(aVol, 0)).first;
1834 TItrMapOfVolume volItr = mapOfVol.begin();
1835 TItrMapOfVolume volEnd = mapOfVol.end();
1836 for ( ; volItr != volEnd; ++volItr )
1837 if ( (*volItr).second >= nbNode )
1839 // face is not free if number of volumes constructed on thier nodes more than one
1843 SMDSAbs_ElementType FreeFaces::GetType() const
1845 return SMDSAbs_Face;
1849 Class : LinearOrQuadratic
1850 Description : Predicate to verify whether a mesh element is linear
1853 LinearOrQuadratic::LinearOrQuadratic()
1858 void LinearOrQuadratic::SetMesh( const SMDS_Mesh* theMesh )
1863 bool LinearOrQuadratic::IsSatisfy( long theId )
1865 if (!myMesh) return false;
1866 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
1867 if ( !anElem || (myType != SMDSAbs_All && anElem->GetType() != myType) )
1869 return (!anElem->IsQuadratic());
1872 void LinearOrQuadratic::SetType( SMDSAbs_ElementType theType )
1877 SMDSAbs_ElementType LinearOrQuadratic::GetType() const
1884 Description : Functor for check color of group to whic mesh element belongs to
1887 GroupColor::GroupColor()
1891 bool GroupColor::IsSatisfy( long theId )
1893 return (myIDs.find( theId ) != myIDs.end());
1896 void GroupColor::SetType( SMDSAbs_ElementType theType )
1901 SMDSAbs_ElementType GroupColor::GetType() const
1906 static bool isEqual( const Quantity_Color& theColor1,
1907 const Quantity_Color& theColor2 )
1909 // tolerance to compare colors
1910 const double tol = 5*1e-3;
1911 return ( fabs( theColor1.Red() - theColor2.Red() ) < tol &&
1912 fabs( theColor1.Green() - theColor2.Green() ) < tol &&
1913 fabs( theColor1.Blue() - theColor2.Blue() ) < tol );
1917 void GroupColor::SetMesh( const SMDS_Mesh* theMesh )
1921 const SMESHDS_Mesh* aMesh = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
1925 int nbGrp = aMesh->GetNbGroups();
1929 // iterates on groups and find necessary elements ids
1930 const std::set<SMESHDS_GroupBase*>& aGroups = aMesh->GetGroups();
1931 set<SMESHDS_GroupBase*>::const_iterator GrIt = aGroups.begin();
1932 for (; GrIt != aGroups.end(); GrIt++) {
1933 SMESHDS_GroupBase* aGrp = (*GrIt);
1936 // check type and color of group
1937 if ( !isEqual( myColor, aGrp->GetColor() ) )
1939 if ( myType != SMDSAbs_All && myType != (SMDSAbs_ElementType)aGrp->GetType() )
1942 SMDSAbs_ElementType aGrpElType = (SMDSAbs_ElementType)aGrp->GetType();
1943 if ( myType == aGrpElType || (myType == SMDSAbs_All && aGrpElType != SMDSAbs_Node) ) {
1944 // add elements IDS into control
1945 int aSize = aGrp->Extent();
1946 for (int i = 0; i < aSize; i++)
1947 myIDs.insert( aGrp->GetID(i+1) );
1952 void GroupColor::SetColorStr( const TCollection_AsciiString& theStr )
1954 TCollection_AsciiString aStr = theStr;
1955 aStr.RemoveAll( ' ' );
1956 aStr.RemoveAll( '\t' );
1957 for ( int aPos = aStr.Search( ";;" ); aPos != -1; aPos = aStr.Search( ";;" ) )
1958 aStr.Remove( aPos, 2 );
1959 Standard_Real clr[3];
1960 clr[0] = clr[1] = clr[2] = 0.;
1961 for ( int i = 0; i < 3; i++ ) {
1962 TCollection_AsciiString tmpStr = aStr.Token( ";", i+1 );
1963 if ( !tmpStr.IsEmpty() && tmpStr.IsRealValue() )
1964 clr[i] = tmpStr.RealValue();
1966 myColor = Quantity_Color( clr[0], clr[1], clr[2], Quantity_TOC_RGB );
1969 //=======================================================================
1970 // name : GetRangeStr
1971 // Purpose : Get range as a string.
1972 // Example: "1,2,3,50-60,63,67,70-"
1973 //=======================================================================
1974 void GroupColor::GetColorStr( TCollection_AsciiString& theResStr ) const
1977 theResStr += TCollection_AsciiString( myColor.Red() );
1978 theResStr += TCollection_AsciiString( ";" ) + TCollection_AsciiString( myColor.Green() );
1979 theResStr += TCollection_AsciiString( ";" ) + TCollection_AsciiString( myColor.Blue() );
1983 Class : ElemGeomType
1984 Description : Predicate to check element geometry type
1987 ElemGeomType::ElemGeomType()
1990 myType = SMDSAbs_All;
1991 myGeomType = SMDSGeom_TRIANGLE;
1994 void ElemGeomType::SetMesh( const SMDS_Mesh* theMesh )
1999 bool ElemGeomType::IsSatisfy( long theId )
2001 if (!myMesh) return false;
2002 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2005 const SMDSAbs_ElementType anElemType = anElem->GetType();
2006 if ( myType != SMDSAbs_All && anElemType != myType )
2008 const int aNbNode = anElem->NbNodes();
2010 switch( anElemType )
2013 isOk = (myGeomType == SMDSGeom_POINT);
2017 isOk = (myGeomType == SMDSGeom_EDGE);
2021 if ( myGeomType == SMDSGeom_TRIANGLE )
2022 isOk = (!anElem->IsPoly() && (anElem->IsQuadratic() ? aNbNode == 6 : aNbNode == 3));
2023 else if ( myGeomType == SMDSGeom_QUADRANGLE )
2024 isOk = (!anElem->IsPoly() && (anElem->IsQuadratic() ? aNbNode == 8 : aNbNode == 4));
2025 else if ( myGeomType == SMDSGeom_POLYGON )
2026 isOk = anElem->IsPoly();
2029 case SMDSAbs_Volume:
2030 if ( myGeomType == SMDSGeom_TETRA )
2031 isOk = (!anElem->IsPoly() && (anElem->IsQuadratic() ? aNbNode == 10 : aNbNode == 4));
2032 else if ( myGeomType == SMDSGeom_PYRAMID )
2033 isOk = (!anElem->IsPoly() && (anElem->IsQuadratic() ? aNbNode == 13 : aNbNode == 5));
2034 else if ( myGeomType == SMDSGeom_PENTA )
2035 isOk = (!anElem->IsPoly() && (anElem->IsQuadratic() ? aNbNode == 15 : aNbNode == 6));
2036 else if ( myGeomType == SMDSGeom_HEXA )
2037 isOk = (!anElem->IsPoly() && (anElem->IsQuadratic() ? aNbNode == 20 : aNbNode == 8));
2038 else if ( myGeomType == SMDSGeom_POLYHEDRA )
2039 isOk = anElem->IsPoly();
2046 void ElemGeomType::SetType( SMDSAbs_ElementType theType )
2051 SMDSAbs_ElementType ElemGeomType::GetType() const
2056 void ElemGeomType::SetGeomType( SMDSAbs_GeometryType theType )
2058 myGeomType = theType;
2061 SMDSAbs_GeometryType ElemGeomType::GetGeomType() const
2068 Description : Predicate for Range of Ids.
2069 Range may be specified with two ways.
2070 1. Using AddToRange method
2071 2. With SetRangeStr method. Parameter of this method is a string
2072 like as "1,2,3,50-60,63,67,70-"
2075 //=======================================================================
2076 // name : RangeOfIds
2077 // Purpose : Constructor
2078 //=======================================================================
2079 RangeOfIds::RangeOfIds()
2082 myType = SMDSAbs_All;
2085 //=======================================================================
2087 // Purpose : Set mesh
2088 //=======================================================================
2089 void RangeOfIds::SetMesh( const SMDS_Mesh* theMesh )
2094 //=======================================================================
2095 // name : AddToRange
2096 // Purpose : Add ID to the range
2097 //=======================================================================
2098 bool RangeOfIds::AddToRange( long theEntityId )
2100 myIds.Add( theEntityId );
2104 //=======================================================================
2105 // name : GetRangeStr
2106 // Purpose : Get range as a string.
2107 // Example: "1,2,3,50-60,63,67,70-"
2108 //=======================================================================
2109 void RangeOfIds::GetRangeStr( TCollection_AsciiString& theResStr )
2113 TColStd_SequenceOfInteger anIntSeq;
2114 TColStd_SequenceOfAsciiString aStrSeq;
2116 TColStd_MapIteratorOfMapOfInteger anIter( myIds );
2117 for ( ; anIter.More(); anIter.Next() )
2119 int anId = anIter.Key();
2120 TCollection_AsciiString aStr( anId );
2121 anIntSeq.Append( anId );
2122 aStrSeq.Append( aStr );
2125 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
2127 int aMinId = myMin( i );
2128 int aMaxId = myMax( i );
2130 TCollection_AsciiString aStr;
2131 if ( aMinId != IntegerFirst() )
2136 if ( aMaxId != IntegerLast() )
2139 // find position of the string in result sequence and insert string in it
2140 if ( anIntSeq.Length() == 0 )
2142 anIntSeq.Append( aMinId );
2143 aStrSeq.Append( aStr );
2147 if ( aMinId < anIntSeq.First() )
2149 anIntSeq.Prepend( aMinId );
2150 aStrSeq.Prepend( aStr );
2152 else if ( aMinId > anIntSeq.Last() )
2154 anIntSeq.Append( aMinId );
2155 aStrSeq.Append( aStr );
2158 for ( int j = 1, k = anIntSeq.Length(); j <= k; j++ )
2159 if ( aMinId < anIntSeq( j ) )
2161 anIntSeq.InsertBefore( j, aMinId );
2162 aStrSeq.InsertBefore( j, aStr );
2168 if ( aStrSeq.Length() == 0 )
2171 theResStr = aStrSeq( 1 );
2172 for ( int j = 2, k = aStrSeq.Length(); j <= k; j++ )
2175 theResStr += aStrSeq( j );
2179 //=======================================================================
2180 // name : SetRangeStr
2181 // Purpose : Define range with string
2182 // Example of entry string: "1,2,3,50-60,63,67,70-"
2183 //=======================================================================
2184 bool RangeOfIds::SetRangeStr( const TCollection_AsciiString& theStr )
2190 TCollection_AsciiString aStr = theStr;
2191 aStr.RemoveAll( ' ' );
2192 aStr.RemoveAll( '\t' );
2194 for ( int aPos = aStr.Search( ",," ); aPos != -1; aPos = aStr.Search( ",," ) )
2195 aStr.Remove( aPos, 2 );
2197 TCollection_AsciiString tmpStr = aStr.Token( ",", 1 );
2199 while ( tmpStr != "" )
2201 tmpStr = aStr.Token( ",", i++ );
2202 int aPos = tmpStr.Search( '-' );
2206 if ( tmpStr.IsIntegerValue() )
2207 myIds.Add( tmpStr.IntegerValue() );
2213 TCollection_AsciiString aMaxStr = tmpStr.Split( aPos );
2214 TCollection_AsciiString aMinStr = tmpStr;
2216 while ( aMinStr.Search( "-" ) != -1 ) aMinStr.RemoveAll( '-' );
2217 while ( aMaxStr.Search( "-" ) != -1 ) aMaxStr.RemoveAll( '-' );
2219 if ( !aMinStr.IsEmpty() && !aMinStr.IsIntegerValue() ||
2220 !aMaxStr.IsEmpty() && !aMaxStr.IsIntegerValue() )
2223 myMin.Append( aMinStr.IsEmpty() ? IntegerFirst() : aMinStr.IntegerValue() );
2224 myMax.Append( aMaxStr.IsEmpty() ? IntegerLast() : aMaxStr.IntegerValue() );
2231 //=======================================================================
2233 // Purpose : Get type of supported entities
2234 //=======================================================================
2235 SMDSAbs_ElementType RangeOfIds::GetType() const
2240 //=======================================================================
2242 // Purpose : Set type of supported entities
2243 //=======================================================================
2244 void RangeOfIds::SetType( SMDSAbs_ElementType theType )
2249 //=======================================================================
2251 // Purpose : Verify whether entity satisfies to this rpedicate
2252 //=======================================================================
2253 bool RangeOfIds::IsSatisfy( long theId )
2258 if ( myType == SMDSAbs_Node )
2260 if ( myMesh->FindNode( theId ) == 0 )
2265 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2266 if ( anElem == 0 || myType != anElem->GetType() && myType != SMDSAbs_All )
2270 if ( myIds.Contains( theId ) )
2273 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
2274 if ( theId >= myMin( i ) && theId <= myMax( i ) )
2282 Description : Base class for comparators
2284 Comparator::Comparator():
2288 Comparator::~Comparator()
2291 void Comparator::SetMesh( const SMDS_Mesh* theMesh )
2294 myFunctor->SetMesh( theMesh );
2297 void Comparator::SetMargin( double theValue )
2299 myMargin = theValue;
2302 void Comparator::SetNumFunctor( NumericalFunctorPtr theFunct )
2304 myFunctor = theFunct;
2307 SMDSAbs_ElementType Comparator::GetType() const
2309 return myFunctor ? myFunctor->GetType() : SMDSAbs_All;
2312 double Comparator::GetMargin()
2320 Description : Comparator "<"
2322 bool LessThan::IsSatisfy( long theId )
2324 return myFunctor && myFunctor->GetValue( theId ) < myMargin;
2330 Description : Comparator ">"
2332 bool MoreThan::IsSatisfy( long theId )
2334 return myFunctor && myFunctor->GetValue( theId ) > myMargin;
2340 Description : Comparator "="
2343 myToler(Precision::Confusion())
2346 bool EqualTo::IsSatisfy( long theId )
2348 return myFunctor && fabs( myFunctor->GetValue( theId ) - myMargin ) < myToler;
2351 void EqualTo::SetTolerance( double theToler )
2356 double EqualTo::GetTolerance()
2363 Description : Logical NOT predicate
2365 LogicalNOT::LogicalNOT()
2368 LogicalNOT::~LogicalNOT()
2371 bool LogicalNOT::IsSatisfy( long theId )
2373 return myPredicate && !myPredicate->IsSatisfy( theId );
2376 void LogicalNOT::SetMesh( const SMDS_Mesh* theMesh )
2379 myPredicate->SetMesh( theMesh );
2382 void LogicalNOT::SetPredicate( PredicatePtr thePred )
2384 myPredicate = thePred;
2387 SMDSAbs_ElementType LogicalNOT::GetType() const
2389 return myPredicate ? myPredicate->GetType() : SMDSAbs_All;
2394 Class : LogicalBinary
2395 Description : Base class for binary logical predicate
2397 LogicalBinary::LogicalBinary()
2400 LogicalBinary::~LogicalBinary()
2403 void LogicalBinary::SetMesh( const SMDS_Mesh* theMesh )
2406 myPredicate1->SetMesh( theMesh );
2409 myPredicate2->SetMesh( theMesh );
2412 void LogicalBinary::SetPredicate1( PredicatePtr thePredicate )
2414 myPredicate1 = thePredicate;
2417 void LogicalBinary::SetPredicate2( PredicatePtr thePredicate )
2419 myPredicate2 = thePredicate;
2422 SMDSAbs_ElementType LogicalBinary::GetType() const
2424 if ( !myPredicate1 || !myPredicate2 )
2427 SMDSAbs_ElementType aType1 = myPredicate1->GetType();
2428 SMDSAbs_ElementType aType2 = myPredicate2->GetType();
2430 return aType1 == aType2 ? aType1 : SMDSAbs_All;
2436 Description : Logical AND
2438 bool LogicalAND::IsSatisfy( long theId )
2443 myPredicate1->IsSatisfy( theId ) &&
2444 myPredicate2->IsSatisfy( theId );
2450 Description : Logical OR
2452 bool LogicalOR::IsSatisfy( long theId )
2457 myPredicate1->IsSatisfy( theId ) ||
2458 myPredicate2->IsSatisfy( theId );
2472 void Filter::SetPredicate( PredicatePtr thePredicate )
2474 myPredicate = thePredicate;
2477 template<class TElement, class TIterator, class TPredicate>
2478 inline void FillSequence(const TIterator& theIterator,
2479 TPredicate& thePredicate,
2480 Filter::TIdSequence& theSequence)
2482 if ( theIterator ) {
2483 while( theIterator->more() ) {
2484 TElement anElem = theIterator->next();
2485 long anId = anElem->GetID();
2486 if ( thePredicate->IsSatisfy( anId ) )
2487 theSequence.push_back( anId );
2494 GetElementsId( const SMDS_Mesh* theMesh,
2495 PredicatePtr thePredicate,
2496 TIdSequence& theSequence )
2498 theSequence.clear();
2500 if ( !theMesh || !thePredicate )
2503 thePredicate->SetMesh( theMesh );
2505 SMDSAbs_ElementType aType = thePredicate->GetType();
2508 FillSequence<const SMDS_MeshNode*>(theMesh->nodesIterator(),thePredicate,theSequence);
2511 FillSequence<const SMDS_MeshElement*>(theMesh->edgesIterator(),thePredicate,theSequence);
2514 FillSequence<const SMDS_MeshElement*>(theMesh->facesIterator(),thePredicate,theSequence);
2516 case SMDSAbs_Volume:
2517 FillSequence<const SMDS_MeshElement*>(theMesh->volumesIterator(),thePredicate,theSequence);
2520 FillSequence<const SMDS_MeshElement*>(theMesh->edgesIterator(),thePredicate,theSequence);
2521 FillSequence<const SMDS_MeshElement*>(theMesh->facesIterator(),thePredicate,theSequence);
2522 FillSequence<const SMDS_MeshElement*>(theMesh->volumesIterator(),thePredicate,theSequence);
2528 Filter::GetElementsId( const SMDS_Mesh* theMesh,
2529 Filter::TIdSequence& theSequence )
2531 GetElementsId(theMesh,myPredicate,theSequence);
2538 typedef std::set<SMDS_MeshFace*> TMapOfFacePtr;
2544 ManifoldPart::Link::Link( SMDS_MeshNode* theNode1,
2545 SMDS_MeshNode* theNode2 )
2551 ManifoldPart::Link::~Link()
2557 bool ManifoldPart::Link::IsEqual( const ManifoldPart::Link& theLink ) const
2559 if ( myNode1 == theLink.myNode1 &&
2560 myNode2 == theLink.myNode2 )
2562 else if ( myNode1 == theLink.myNode2 &&
2563 myNode2 == theLink.myNode1 )
2569 bool ManifoldPart::Link::operator<( const ManifoldPart::Link& x ) const
2571 if(myNode1 < x.myNode1) return true;
2572 if(myNode1 == x.myNode1)
2573 if(myNode2 < x.myNode2) return true;
2577 bool ManifoldPart::IsEqual( const ManifoldPart::Link& theLink1,
2578 const ManifoldPart::Link& theLink2 )
2580 return theLink1.IsEqual( theLink2 );
2583 ManifoldPart::ManifoldPart()
2586 myAngToler = Precision::Angular();
2587 myIsOnlyManifold = true;
2590 ManifoldPart::~ManifoldPart()
2595 void ManifoldPart::SetMesh( const SMDS_Mesh* theMesh )
2601 SMDSAbs_ElementType ManifoldPart::GetType() const
2602 { return SMDSAbs_Face; }
2604 bool ManifoldPart::IsSatisfy( long theElementId )
2606 return myMapIds.Contains( theElementId );
2609 void ManifoldPart::SetAngleTolerance( const double theAngToler )
2610 { myAngToler = theAngToler; }
2612 double ManifoldPart::GetAngleTolerance() const
2613 { return myAngToler; }
2615 void ManifoldPart::SetIsOnlyManifold( const bool theIsOnly )
2616 { myIsOnlyManifold = theIsOnly; }
2618 void ManifoldPart::SetStartElem( const long theStartId )
2619 { myStartElemId = theStartId; }
2621 bool ManifoldPart::process()
2624 myMapBadGeomIds.Clear();
2626 myAllFacePtr.clear();
2627 myAllFacePtrIntDMap.clear();
2631 // collect all faces into own map
2632 SMDS_FaceIteratorPtr anFaceItr = myMesh->facesIterator();
2633 for (; anFaceItr->more(); )
2635 SMDS_MeshFace* aFacePtr = (SMDS_MeshFace*)anFaceItr->next();
2636 myAllFacePtr.push_back( aFacePtr );
2637 myAllFacePtrIntDMap[aFacePtr] = myAllFacePtr.size()-1;
2640 SMDS_MeshFace* aStartFace = (SMDS_MeshFace*)myMesh->FindElement( myStartElemId );
2644 // the map of non manifold links and bad geometry
2645 TMapOfLink aMapOfNonManifold;
2646 TColStd_MapOfInteger aMapOfTreated;
2648 // begin cycle on faces from start index and run on vector till the end
2649 // and from begin to start index to cover whole vector
2650 const int aStartIndx = myAllFacePtrIntDMap[aStartFace];
2651 bool isStartTreat = false;
2652 for ( int fi = aStartIndx; !isStartTreat || fi != aStartIndx ; fi++ )
2654 if ( fi == aStartIndx )
2655 isStartTreat = true;
2656 // as result next time when fi will be equal to aStartIndx
2658 SMDS_MeshFace* aFacePtr = myAllFacePtr[ fi ];
2659 if ( aMapOfTreated.Contains( aFacePtr->GetID() ) )
2662 aMapOfTreated.Add( aFacePtr->GetID() );
2663 TColStd_MapOfInteger aResFaces;
2664 if ( !findConnected( myAllFacePtrIntDMap, aFacePtr,
2665 aMapOfNonManifold, aResFaces ) )
2667 TColStd_MapIteratorOfMapOfInteger anItr( aResFaces );
2668 for ( ; anItr.More(); anItr.Next() )
2670 int aFaceId = anItr.Key();
2671 aMapOfTreated.Add( aFaceId );
2672 myMapIds.Add( aFaceId );
2675 if ( fi == ( myAllFacePtr.size() - 1 ) )
2677 } // end run on vector of faces
2678 return !myMapIds.IsEmpty();
2681 static void getLinks( const SMDS_MeshFace* theFace,
2682 ManifoldPart::TVectorOfLink& theLinks )
2684 int aNbNode = theFace->NbNodes();
2685 SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
2687 SMDS_MeshNode* aNode = 0;
2688 for ( ; aNodeItr->more() && i <= aNbNode; )
2691 SMDS_MeshNode* aN1 = (SMDS_MeshNode*)aNodeItr->next();
2695 SMDS_MeshNode* aN2 = ( i >= aNbNode ) ? aNode : (SMDS_MeshNode*)aNodeItr->next();
2697 ManifoldPart::Link aLink( aN1, aN2 );
2698 theLinks.push_back( aLink );
2702 static gp_XYZ getNormale( const SMDS_MeshFace* theFace )
2705 int aNbNode = theFace->NbNodes();
2706 TColgp_Array1OfXYZ anArrOfXYZ(1,4);
2707 SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
2709 for ( ; aNodeItr->more() && i <= 4; i++ ) {
2710 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
2711 anArrOfXYZ.SetValue(i, gp_XYZ( aNode->X(), aNode->Y(), aNode->Z() ) );
2714 gp_XYZ q1 = anArrOfXYZ.Value(2) - anArrOfXYZ.Value(1);
2715 gp_XYZ q2 = anArrOfXYZ.Value(3) - anArrOfXYZ.Value(1);
2717 if ( aNbNode > 3 ) {
2718 gp_XYZ q3 = anArrOfXYZ.Value(4) - anArrOfXYZ.Value(1);
2721 double len = n.Modulus();
2728 bool ManifoldPart::findConnected
2729 ( const ManifoldPart::TDataMapFacePtrInt& theAllFacePtrInt,
2730 SMDS_MeshFace* theStartFace,
2731 ManifoldPart::TMapOfLink& theNonManifold,
2732 TColStd_MapOfInteger& theResFaces )
2734 theResFaces.Clear();
2735 if ( !theAllFacePtrInt.size() )
2738 if ( getNormale( theStartFace ).SquareModulus() <= gp::Resolution() )
2740 myMapBadGeomIds.Add( theStartFace->GetID() );
2744 ManifoldPart::TMapOfLink aMapOfBoundary, aMapToSkip;
2745 ManifoldPart::TVectorOfLink aSeqOfBoundary;
2746 theResFaces.Add( theStartFace->GetID() );
2747 ManifoldPart::TDataMapOfLinkFacePtr aDMapLinkFace;
2749 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
2750 aDMapLinkFace, theNonManifold, theStartFace );
2752 bool isDone = false;
2753 while ( !isDone && aMapOfBoundary.size() != 0 )
2755 bool isToReset = false;
2756 ManifoldPart::TVectorOfLink::iterator pLink = aSeqOfBoundary.begin();
2757 for ( ; !isToReset && pLink != aSeqOfBoundary.end(); ++pLink )
2759 ManifoldPart::Link aLink = *pLink;
2760 if ( aMapToSkip.find( aLink ) != aMapToSkip.end() )
2762 // each link could be treated only once
2763 aMapToSkip.insert( aLink );
2765 ManifoldPart::TVectorOfFacePtr aFaces;
2767 if ( myIsOnlyManifold &&
2768 (theNonManifold.find( aLink ) != theNonManifold.end()) )
2772 getFacesByLink( aLink, aFaces );
2773 // filter the element to keep only indicated elements
2774 ManifoldPart::TVectorOfFacePtr aFiltered;
2775 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
2776 for ( ; pFace != aFaces.end(); ++pFace )
2778 SMDS_MeshFace* aFace = *pFace;
2779 if ( myAllFacePtrIntDMap.find( aFace ) != myAllFacePtrIntDMap.end() )
2780 aFiltered.push_back( aFace );
2783 if ( aFaces.size() < 2 ) // no neihgbour faces
2785 else if ( myIsOnlyManifold && aFaces.size() > 2 ) // non manifold case
2787 theNonManifold.insert( aLink );
2792 // compare normal with normals of neighbor element
2793 SMDS_MeshFace* aPrevFace = aDMapLinkFace[ aLink ];
2794 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
2795 for ( ; pFace != aFaces.end(); ++pFace )
2797 SMDS_MeshFace* aNextFace = *pFace;
2798 if ( aPrevFace == aNextFace )
2800 int anNextFaceID = aNextFace->GetID();
2801 if ( myIsOnlyManifold && theResFaces.Contains( anNextFaceID ) )
2802 // should not be with non manifold restriction. probably bad topology
2804 // check if face was treated and skipped
2805 if ( myMapBadGeomIds.Contains( anNextFaceID ) ||
2806 !isInPlane( aPrevFace, aNextFace ) )
2808 // add new element to connected and extend the boundaries.
2809 theResFaces.Add( anNextFaceID );
2810 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
2811 aDMapLinkFace, theNonManifold, aNextFace );
2815 isDone = !isToReset;
2818 return !theResFaces.IsEmpty();
2821 bool ManifoldPart::isInPlane( const SMDS_MeshFace* theFace1,
2822 const SMDS_MeshFace* theFace2 )
2824 gp_Dir aNorm1 = gp_Dir( getNormale( theFace1 ) );
2825 gp_XYZ aNorm2XYZ = getNormale( theFace2 );
2826 if ( aNorm2XYZ.SquareModulus() <= gp::Resolution() )
2828 myMapBadGeomIds.Add( theFace2->GetID() );
2831 if ( aNorm1.IsParallel( gp_Dir( aNorm2XYZ ), myAngToler ) )
2837 void ManifoldPart::expandBoundary
2838 ( ManifoldPart::TMapOfLink& theMapOfBoundary,
2839 ManifoldPart::TVectorOfLink& theSeqOfBoundary,
2840 ManifoldPart::TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
2841 ManifoldPart::TMapOfLink& theNonManifold,
2842 SMDS_MeshFace* theNextFace ) const
2844 ManifoldPart::TVectorOfLink aLinks;
2845 getLinks( theNextFace, aLinks );
2846 int aNbLink = (int)aLinks.size();
2847 for ( int i = 0; i < aNbLink; i++ )
2849 ManifoldPart::Link aLink = aLinks[ i ];
2850 if ( myIsOnlyManifold && (theNonManifold.find( aLink ) != theNonManifold.end()) )
2852 if ( theMapOfBoundary.find( aLink ) != theMapOfBoundary.end() )
2854 if ( myIsOnlyManifold )
2856 // remove from boundary
2857 theMapOfBoundary.erase( aLink );
2858 ManifoldPart::TVectorOfLink::iterator pLink = theSeqOfBoundary.begin();
2859 for ( ; pLink != theSeqOfBoundary.end(); ++pLink )
2861 ManifoldPart::Link aBoundLink = *pLink;
2862 if ( aBoundLink.IsEqual( aLink ) )
2864 theSeqOfBoundary.erase( pLink );
2872 theMapOfBoundary.insert( aLink );
2873 theSeqOfBoundary.push_back( aLink );
2874 theDMapLinkFacePtr[ aLink ] = theNextFace;
2879 void ManifoldPart::getFacesByLink( const ManifoldPart::Link& theLink,
2880 ManifoldPart::TVectorOfFacePtr& theFaces ) const
2882 SMDS_Mesh::SetOfFaces aSetOfFaces;
2883 // take all faces that shared first node
2884 SMDS_ElemIteratorPtr anItr = theLink.myNode1->facesIterator();
2885 for ( ; anItr->more(); )
2887 SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
2890 aSetOfFaces.Add( aFace );
2892 // take all faces that shared second node
2893 anItr = theLink.myNode2->facesIterator();
2894 // find the common part of two sets
2895 for ( ; anItr->more(); )
2897 SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
2898 if ( aSetOfFaces.Contains( aFace ) )
2899 theFaces.push_back( aFace );
2908 ElementsOnSurface::ElementsOnSurface()
2912 myType = SMDSAbs_All;
2914 myToler = Precision::Confusion();
2915 myUseBoundaries = false;
2918 ElementsOnSurface::~ElementsOnSurface()
2923 void ElementsOnSurface::SetMesh( const SMDS_Mesh* theMesh )
2925 if ( myMesh == theMesh )
2931 bool ElementsOnSurface::IsSatisfy( long theElementId )
2933 return myIds.Contains( theElementId );
2936 SMDSAbs_ElementType ElementsOnSurface::GetType() const
2939 void ElementsOnSurface::SetTolerance( const double theToler )
2941 if ( myToler != theToler )
2946 double ElementsOnSurface::GetTolerance() const
2949 void ElementsOnSurface::SetUseBoundaries( bool theUse )
2951 if ( myUseBoundaries != theUse ) {
2952 myUseBoundaries = theUse;
2953 SetSurface( mySurf, myType );
2957 void ElementsOnSurface::SetSurface( const TopoDS_Shape& theShape,
2958 const SMDSAbs_ElementType theType )
2963 if ( theShape.IsNull() || theShape.ShapeType() != TopAbs_FACE )
2965 mySurf = TopoDS::Face( theShape );
2966 BRepAdaptor_Surface SA( mySurf, myUseBoundaries );
2968 u1 = SA.FirstUParameter(),
2969 u2 = SA.LastUParameter(),
2970 v1 = SA.FirstVParameter(),
2971 v2 = SA.LastVParameter();
2972 Handle(Geom_Surface) surf = BRep_Tool::Surface( mySurf );
2973 myProjector.Init( surf, u1,u2, v1,v2 );
2977 void ElementsOnSurface::process()
2980 if ( mySurf.IsNull() )
2986 if ( myType == SMDSAbs_Face || myType == SMDSAbs_All )
2988 myIds.ReSize( myMesh->NbFaces() );
2989 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
2990 for(; anIter->more(); )
2991 process( anIter->next() );
2994 if ( myType == SMDSAbs_Edge || myType == SMDSAbs_All )
2996 myIds.ReSize( myIds.Extent() + myMesh->NbEdges() );
2997 SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
2998 for(; anIter->more(); )
2999 process( anIter->next() );
3002 if ( myType == SMDSAbs_Node )
3004 myIds.ReSize( myMesh->NbNodes() );
3005 SMDS_NodeIteratorPtr anIter = myMesh->nodesIterator();
3006 for(; anIter->more(); )
3007 process( anIter->next() );
3011 void ElementsOnSurface::process( const SMDS_MeshElement* theElemPtr )
3013 SMDS_ElemIteratorPtr aNodeItr = theElemPtr->nodesIterator();
3014 bool isSatisfy = true;
3015 for ( ; aNodeItr->more(); )
3017 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
3018 if ( !isOnSurface( aNode ) )
3025 myIds.Add( theElemPtr->GetID() );
3028 bool ElementsOnSurface::isOnSurface( const SMDS_MeshNode* theNode )
3030 if ( mySurf.IsNull() )
3033 gp_Pnt aPnt( theNode->X(), theNode->Y(), theNode->Z() );
3034 // double aToler2 = myToler * myToler;
3035 // if ( mySurf->IsKind(STANDARD_TYPE(Geom_Plane)))
3037 // gp_Pln aPln = Handle(Geom_Plane)::DownCast(mySurf)->Pln();
3038 // if ( aPln.SquareDistance( aPnt ) > aToler2 )
3041 // else if ( mySurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)))
3043 // gp_Cylinder aCyl = Handle(Geom_CylindricalSurface)::DownCast(mySurf)->Cylinder();
3044 // double aRad = aCyl.Radius();
3045 // gp_Ax3 anAxis = aCyl.Position();
3046 // gp_XYZ aLoc = aCyl.Location().XYZ();
3047 // double aXDist = anAxis.XDirection().XYZ() * ( aPnt.XYZ() - aLoc );
3048 // double aYDist = anAxis.YDirection().XYZ() * ( aPnt.XYZ() - aLoc );
3049 // if ( fabs(aXDist*aXDist + aYDist*aYDist - aRad*aRad) > aToler2 )
3054 myProjector.Perform( aPnt );
3055 bool isOn = ( myProjector.IsDone() && myProjector.LowerDistance() <= myToler );
3065 ElementsOnShape::ElementsOnShape()
3067 myType(SMDSAbs_All),
3068 myToler(Precision::Confusion()),
3069 myAllNodesFlag(false)
3071 myCurShapeType = TopAbs_SHAPE;
3074 ElementsOnShape::~ElementsOnShape()
3078 void ElementsOnShape::SetMesh (const SMDS_Mesh* theMesh)
3080 if (myMesh != theMesh) {
3082 SetShape(myShape, myType);
3086 bool ElementsOnShape::IsSatisfy (long theElementId)
3088 return myIds.Contains(theElementId);
3091 SMDSAbs_ElementType ElementsOnShape::GetType() const
3096 void ElementsOnShape::SetTolerance (const double theToler)
3098 if (myToler != theToler) {
3100 SetShape(myShape, myType);
3104 double ElementsOnShape::GetTolerance() const
3109 void ElementsOnShape::SetAllNodes (bool theAllNodes)
3111 if (myAllNodesFlag != theAllNodes) {
3112 myAllNodesFlag = theAllNodes;
3113 SetShape(myShape, myType);
3117 void ElementsOnShape::SetShape (const TopoDS_Shape& theShape,
3118 const SMDSAbs_ElementType theType)
3124 if (myMesh == 0) return;
3129 myIds.ReSize(myMesh->NbEdges() + myMesh->NbFaces() + myMesh->NbVolumes());
3132 myIds.ReSize(myMesh->NbNodes());
3135 myIds.ReSize(myMesh->NbEdges());
3138 myIds.ReSize(myMesh->NbFaces());
3140 case SMDSAbs_Volume:
3141 myIds.ReSize(myMesh->NbVolumes());
3147 myShapesMap.Clear();
3151 void ElementsOnShape::addShape (const TopoDS_Shape& theShape)
3153 if (theShape.IsNull() || myMesh == 0)
3156 if (!myShapesMap.Add(theShape)) return;
3158 myCurShapeType = theShape.ShapeType();
3159 switch (myCurShapeType)
3161 case TopAbs_COMPOUND:
3162 case TopAbs_COMPSOLID:
3166 TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
3167 for (; anIt.More(); anIt.Next()) addShape(anIt.Value());
3172 myCurSC.Load(theShape);
3178 TopoDS_Face aFace = TopoDS::Face(theShape);
3179 BRepAdaptor_Surface SA (aFace, true);
3181 u1 = SA.FirstUParameter(),
3182 u2 = SA.LastUParameter(),
3183 v1 = SA.FirstVParameter(),
3184 v2 = SA.LastVParameter();
3185 Handle(Geom_Surface) surf = BRep_Tool::Surface(aFace);
3186 myCurProjFace.Init(surf, u1,u2, v1,v2);
3193 TopoDS_Edge anEdge = TopoDS::Edge(theShape);
3194 Standard_Real u1, u2;
3195 Handle(Geom_Curve) curve = BRep_Tool::Curve(anEdge, u1, u2);
3196 myCurProjEdge.Init(curve, u1, u2);
3202 TopoDS_Vertex aV = TopoDS::Vertex(theShape);
3203 myCurPnt = BRep_Tool::Pnt(aV);
3212 void ElementsOnShape::process()
3214 if (myShape.IsNull() || myMesh == 0)
3217 if (myType == SMDSAbs_Node)
3219 SMDS_NodeIteratorPtr anIter = myMesh->nodesIterator();
3220 while (anIter->more())
3221 process(anIter->next());
3225 if (myType == SMDSAbs_Edge || myType == SMDSAbs_All)
3227 SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
3228 while (anIter->more())
3229 process(anIter->next());
3232 if (myType == SMDSAbs_Face || myType == SMDSAbs_All)
3234 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
3235 while (anIter->more()) {
3236 process(anIter->next());
3240 if (myType == SMDSAbs_Volume || myType == SMDSAbs_All)
3242 SMDS_VolumeIteratorPtr anIter = myMesh->volumesIterator();
3243 while (anIter->more())
3244 process(anIter->next());
3249 void ElementsOnShape::process (const SMDS_MeshElement* theElemPtr)
3251 if (myShape.IsNull())
3254 SMDS_ElemIteratorPtr aNodeItr = theElemPtr->nodesIterator();
3255 bool isSatisfy = myAllNodesFlag;
3257 gp_XYZ centerXYZ (0, 0, 0);
3259 while (aNodeItr->more() && (isSatisfy == myAllNodesFlag))
3261 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
3262 gp_Pnt aPnt (aNode->X(), aNode->Y(), aNode->Z());
3263 centerXYZ += aPnt.XYZ();
3265 switch (myCurShapeType)
3269 myCurSC.Perform(aPnt, myToler);
3270 isSatisfy = (myCurSC.State() == TopAbs_IN || myCurSC.State() == TopAbs_ON);
3275 myCurProjFace.Perform(aPnt);
3276 isSatisfy = (myCurProjFace.IsDone() && myCurProjFace.LowerDistance() <= myToler);
3279 // check relatively the face
3280 Quantity_Parameter u, v;
3281 myCurProjFace.LowerDistanceParameters(u, v);
3282 gp_Pnt2d aProjPnt (u, v);
3283 BRepClass_FaceClassifier aClsf (myCurFace, aProjPnt, myToler);
3284 isSatisfy = (aClsf.State() == TopAbs_IN || aClsf.State() == TopAbs_ON);
3290 myCurProjEdge.Perform(aPnt);
3291 isSatisfy = (myCurProjEdge.NbPoints() > 0 && myCurProjEdge.LowerDistance() <= myToler);
3296 isSatisfy = (aPnt.Distance(myCurPnt) <= myToler);
3306 if (isSatisfy && myCurShapeType == TopAbs_SOLID) { // Check the center point for volumes MantisBug 0020168
3307 centerXYZ /= theElemPtr->NbNodes();
3308 gp_Pnt aCenterPnt (centerXYZ);
3309 myCurSC.Perform(aCenterPnt, myToler);
3310 if ( !(myCurSC.State() == TopAbs_IN || myCurSC.State() == TopAbs_ON))
3315 myIds.Add(theElemPtr->GetID());
3318 TSequenceOfXYZ::TSequenceOfXYZ()
3321 TSequenceOfXYZ::TSequenceOfXYZ(size_type n) : myArray(n)
3324 TSequenceOfXYZ::TSequenceOfXYZ(size_type n, const gp_XYZ& t) : myArray(n,t)
3327 TSequenceOfXYZ::TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ) : myArray(theSequenceOfXYZ.myArray)
3330 template <class InputIterator>
3331 TSequenceOfXYZ::TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd): myArray(theBegin,theEnd)
3334 TSequenceOfXYZ::~TSequenceOfXYZ()
3337 TSequenceOfXYZ& TSequenceOfXYZ::operator=(const TSequenceOfXYZ& theSequenceOfXYZ)
3339 myArray = theSequenceOfXYZ.myArray;
3343 gp_XYZ& TSequenceOfXYZ::operator()(size_type n)
3345 return myArray[n-1];
3348 const gp_XYZ& TSequenceOfXYZ::operator()(size_type n) const
3350 return myArray[n-1];
3353 void TSequenceOfXYZ::clear()
3358 void TSequenceOfXYZ::reserve(size_type n)
3363 void TSequenceOfXYZ::push_back(const gp_XYZ& v)
3365 myArray.push_back(v);
3368 TSequenceOfXYZ::size_type TSequenceOfXYZ::size() const
3370 return myArray.size();