1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "SMESH_ControlsDef.hxx"
26 #include <BRepAdaptor_Surface.hxx>
27 #include <BRepClass_FaceClassifier.hxx>
28 #include <BRep_Tool.hxx>
32 #include <TopoDS_Edge.hxx>
33 #include <TopoDS_Face.hxx>
34 #include <TopoDS_Shape.hxx>
35 #include <TopoDS_Vertex.hxx>
36 #include <TopoDS_Iterator.hxx>
38 #include <Geom_CylindricalSurface.hxx>
39 #include <Geom_Plane.hxx>
40 #include <Geom_Surface.hxx>
42 #include <Precision.hxx>
43 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
44 #include <TColStd_MapOfInteger.hxx>
45 #include <TColStd_SequenceOfAsciiString.hxx>
46 #include <TColgp_Array1OfXYZ.hxx>
49 #include <gp_Cylinder.hxx>
56 #include "SMDS_Mesh.hxx"
57 #include "SMDS_Iterator.hxx"
58 #include "SMDS_MeshElement.hxx"
59 #include "SMDS_MeshNode.hxx"
60 #include "SMDS_VolumeTool.hxx"
61 #include "SMDS_QuadraticFaceOfNodes.hxx"
62 #include "SMDS_QuadraticEdge.hxx"
64 #include "SMESHDS_Mesh.hxx"
65 #include "SMESHDS_GroupBase.hxx"
72 inline double getAngle( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
74 gp_Vec v1( P1 - P2 ), v2( P3 - P2 );
76 return v1.Magnitude() < gp::Resolution() ||
77 v2.Magnitude() < gp::Resolution() ? 0 : v1.Angle( v2 );
80 inline double getArea( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
82 gp_Vec aVec1( P2 - P1 );
83 gp_Vec aVec2( P3 - P1 );
84 return ( aVec1 ^ aVec2 ).Magnitude() * 0.5;
87 inline double getArea( const gp_Pnt& P1, const gp_Pnt& P2, const gp_Pnt& P3 )
89 return getArea( P1.XYZ(), P2.XYZ(), P3.XYZ() );
94 inline double getDistance( const gp_XYZ& P1, const gp_XYZ& P2 )
96 double aDist = gp_Pnt( P1 ).Distance( gp_Pnt( P2 ) );
100 int getNbMultiConnection( const SMDS_Mesh* theMesh, const int theId )
105 const SMDS_MeshElement* anEdge = theMesh->FindElement( theId );
106 if ( anEdge == 0 || anEdge->GetType() != SMDSAbs_Edge/* || anEdge->NbNodes() != 2 */)
109 // for each pair of nodes in anEdge (there are 2 pairs in a quadratic edge)
110 // count elements containing both nodes of the pair.
111 // Note that there may be such cases for a quadratic edge (a horizontal line):
116 // +-----+------+ +-----+------+
119 // result sould be 2 in both cases
121 int aResult0 = 0, aResult1 = 0;
122 // last node, it is a medium one in a quadratic edge
123 const SMDS_MeshNode* aLastNode = anEdge->GetNode( anEdge->NbNodes() - 1 );
124 const SMDS_MeshNode* aNode0 = anEdge->GetNode( 0 );
125 const SMDS_MeshNode* aNode1 = anEdge->GetNode( 1 );
126 if ( aNode1 == aLastNode ) aNode1 = 0;
128 SMDS_ElemIteratorPtr anElemIter = aLastNode->GetInverseElementIterator();
129 while( anElemIter->more() ) {
130 const SMDS_MeshElement* anElem = anElemIter->next();
131 if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) {
132 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
133 while ( anIter->more() ) {
134 if ( const SMDS_MeshElement* anElemNode = anIter->next() ) {
135 if ( anElemNode == aNode0 ) {
137 if ( !aNode1 ) break; // not a quadratic edge
139 else if ( anElemNode == aNode1 )
145 int aResult = std::max ( aResult0, aResult1 );
147 // TColStd_MapOfInteger aMap;
149 // SMDS_ElemIteratorPtr anIter = anEdge->nodesIterator();
150 // if ( anIter != 0 ) {
151 // while( anIter->more() ) {
152 // const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next();
155 // SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator();
156 // while( anElemIter->more() ) {
157 // const SMDS_MeshElement* anElem = anElemIter->next();
158 // if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) {
159 // int anId = anElem->GetID();
161 // if ( anIter->more() ) // i.e. first node
163 // else if ( aMap.Contains( anId ) )
177 using namespace SMESH::Controls;
184 Class : NumericalFunctor
185 Description : Base class for numerical functors
187 NumericalFunctor::NumericalFunctor():
193 void NumericalFunctor::SetMesh( const SMDS_Mesh* theMesh )
198 bool NumericalFunctor::GetPoints(const int theId,
199 TSequenceOfXYZ& theRes ) const
206 return GetPoints( myMesh->FindElement( theId ), theRes );
209 bool NumericalFunctor::GetPoints(const SMDS_MeshElement* anElem,
210 TSequenceOfXYZ& theRes )
217 theRes.reserve( anElem->NbNodes() );
219 // Get nodes of the element
220 SMDS_ElemIteratorPtr anIter;
222 if ( anElem->IsQuadratic() ) {
223 switch ( anElem->GetType() ) {
225 anIter = static_cast<const SMDS_QuadraticEdge*>
226 (anElem)->interlacedNodesElemIterator();
229 anIter = static_cast<const SMDS_QuadraticFaceOfNodes*>
230 (anElem)->interlacedNodesElemIterator();
233 anIter = anElem->nodesIterator();
238 anIter = anElem->nodesIterator();
242 while( anIter->more() ) {
243 if ( const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>( anIter->next() ))
244 theRes.push_back( gp_XYZ( aNode->X(), aNode->Y(), aNode->Z() ) );
251 long NumericalFunctor::GetPrecision() const
256 void NumericalFunctor::SetPrecision( const long thePrecision )
258 myPrecision = thePrecision;
261 double NumericalFunctor::GetValue( long theId )
263 myCurrElement = myMesh->FindElement( theId );
265 if ( GetPoints( theId, P ))
267 double aVal = GetValue( P );
268 if ( myPrecision >= 0 )
270 double prec = pow( 10., (double)( myPrecision ) );
271 aVal = floor( aVal * prec + 0.5 ) / prec;
279 //=======================================================================
280 //function : GetValue
282 //=======================================================================
284 double Volume::GetValue( long theElementId )
286 if ( theElementId && myMesh ) {
287 SMDS_VolumeTool aVolumeTool;
288 if ( aVolumeTool.Set( myMesh->FindElement( theElementId )))
289 return aVolumeTool.GetSize();
294 //=======================================================================
295 //function : GetBadRate
296 //purpose : meaningless as it is not quality control functor
297 //=======================================================================
299 double Volume::GetBadRate( double Value, int /*nbNodes*/ ) const
304 //=======================================================================
307 //=======================================================================
309 SMDSAbs_ElementType Volume::GetType() const
311 return SMDSAbs_Volume;
317 Description : Functor for calculation of minimum angle
320 double MinimumAngle::GetValue( const TSequenceOfXYZ& P )
327 aMin = getAngle(P( P.size() ), P( 1 ), P( 2 ));
328 aMin = Min(aMin,getAngle(P( P.size()-1 ), P( P.size() ), P( 1 )));
330 for (int i=2; i<P.size();i++){
331 double A0 = getAngle( P( i-1 ), P( i ), P( i+1 ) );
335 return aMin * 180.0 / PI;
338 double MinimumAngle::GetBadRate( double Value, int nbNodes ) const
340 //const double aBestAngle = PI / nbNodes;
341 const double aBestAngle = 180.0 - ( 360.0 / double(nbNodes) );
342 return ( fabs( aBestAngle - Value ));
345 SMDSAbs_ElementType MinimumAngle::GetType() const
353 Description : Functor for calculating aspect ratio
355 double AspectRatio::GetValue( const TSequenceOfXYZ& P )
357 // According to "Mesh quality control" by Nadir Bouhamau referring to
358 // Pascal Jean Frey and Paul-Louis George. Maillages, applications aux elements finis.
359 // Hermes Science publications, Paris 1999 ISBN 2-7462-0024-4
362 int nbNodes = P.size();
367 // Compute aspect ratio
369 if ( nbNodes == 3 ) {
370 // Compute lengths of the sides
371 std::vector< double > aLen (nbNodes);
372 for ( int i = 0; i < nbNodes - 1; i++ )
373 aLen[ i ] = getDistance( P( i + 1 ), P( i + 2 ) );
374 aLen[ nbNodes - 1 ] = getDistance( P( 1 ), P( nbNodes ) );
375 // Q = alfa * h * p / S, where
377 // alfa = sqrt( 3 ) / 6
378 // h - length of the longest edge
379 // p - half perimeter
380 // S - triangle surface
381 const double alfa = sqrt( 3. ) / 6.;
382 double maxLen = Max( aLen[ 0 ], Max( aLen[ 1 ], aLen[ 2 ] ) );
383 double half_perimeter = ( aLen[0] + aLen[1] + aLen[2] ) / 2.;
384 double anArea = getArea( P( 1 ), P( 2 ), P( 3 ) );
385 if ( anArea <= Precision::Confusion() )
387 return alfa * maxLen * half_perimeter / anArea;
389 else if ( nbNodes == 6 ) { // quadratic triangles
390 // Compute lengths of the sides
391 std::vector< double > aLen (3);
392 aLen[0] = getDistance( P(1), P(3) );
393 aLen[1] = getDistance( P(3), P(5) );
394 aLen[2] = getDistance( P(5), P(1) );
395 // Q = alfa * h * p / S, where
397 // alfa = sqrt( 3 ) / 6
398 // h - length of the longest edge
399 // p - half perimeter
400 // S - triangle surface
401 const double alfa = sqrt( 3. ) / 6.;
402 double maxLen = Max( aLen[ 0 ], Max( aLen[ 1 ], aLen[ 2 ] ) );
403 double half_perimeter = ( aLen[0] + aLen[1] + aLen[2] ) / 2.;
404 double anArea = getArea( P(1), P(3), P(5) );
405 if ( anArea <= Precision::Confusion() )
407 return alfa * maxLen * half_perimeter / anArea;
409 else if( nbNodes == 4 ) { // quadrangle
410 // return aspect ratio of the worst triange which can be built
411 // taking three nodes of the quadrangle
412 TSequenceOfXYZ triaPnts(3);
413 // triangle on nodes 1 3 2
417 double ar = GetValue( triaPnts );
418 // triangle on nodes 1 3 4
420 ar = Max ( ar, GetValue( triaPnts ));
421 // triangle on nodes 1 2 4
423 ar = Max ( ar, GetValue( triaPnts ));
424 // triangle on nodes 3 2 4
426 ar = Max ( ar, GetValue( triaPnts ));
430 else { // nbNodes==8 - quadratic quadrangle
431 // return aspect ratio of the worst triange which can be built
432 // taking three nodes of the quadrangle
433 TSequenceOfXYZ triaPnts(3);
434 // triangle on nodes 1 3 2
438 double ar = GetValue( triaPnts );
439 // triangle on nodes 1 3 4
441 ar = Max ( ar, GetValue( triaPnts ));
442 // triangle on nodes 1 2 4
444 ar = Max ( ar, GetValue( triaPnts ));
445 // triangle on nodes 3 2 4
447 ar = Max ( ar, GetValue( triaPnts ));
453 double AspectRatio::GetBadRate( double Value, int /*nbNodes*/ ) const
455 // the aspect ratio is in the range [1.0,infinity]
458 return Value / 1000.;
461 SMDSAbs_ElementType AspectRatio::GetType() const
468 Class : AspectRatio3D
469 Description : Functor for calculating aspect ratio
473 inline double getHalfPerimeter(double theTria[3]){
474 return (theTria[0] + theTria[1] + theTria[2])/2.0;
477 inline double getArea(double theHalfPerim, double theTria[3]){
478 return sqrt(theHalfPerim*
479 (theHalfPerim-theTria[0])*
480 (theHalfPerim-theTria[1])*
481 (theHalfPerim-theTria[2]));
484 inline double getVolume(double theLen[6]){
485 double a2 = theLen[0]*theLen[0];
486 double b2 = theLen[1]*theLen[1];
487 double c2 = theLen[2]*theLen[2];
488 double d2 = theLen[3]*theLen[3];
489 double e2 = theLen[4]*theLen[4];
490 double f2 = theLen[5]*theLen[5];
491 double P = 4.0*a2*b2*d2;
492 double Q = a2*(b2+d2-e2)-b2*(a2+d2-f2)-d2*(a2+b2-c2);
493 double R = (b2+d2-e2)*(a2+d2-f2)*(a2+d2-f2);
494 return sqrt(P-Q+R)/12.0;
497 inline double getVolume2(double theLen[6]){
498 double a2 = theLen[0]*theLen[0];
499 double b2 = theLen[1]*theLen[1];
500 double c2 = theLen[2]*theLen[2];
501 double d2 = theLen[3]*theLen[3];
502 double e2 = theLen[4]*theLen[4];
503 double f2 = theLen[5]*theLen[5];
505 double P = a2*e2*(b2+c2+d2+f2-a2-e2);
506 double Q = b2*f2*(a2+c2+d2+e2-b2-f2);
507 double R = c2*d2*(a2+b2+e2+f2-c2-d2);
508 double S = a2*b2*d2+b2*c2*e2+a2*c2*f2+d2*e2*f2;
510 return sqrt(P+Q+R-S)/12.0;
513 inline double getVolume(const TSequenceOfXYZ& P){
514 gp_Vec aVec1( P( 2 ) - P( 1 ) );
515 gp_Vec aVec2( P( 3 ) - P( 1 ) );
516 gp_Vec aVec3( P( 4 ) - P( 1 ) );
517 gp_Vec anAreaVec( aVec1 ^ aVec2 );
518 return fabs(aVec3 * anAreaVec) / 6.0;
521 inline double getMaxHeight(double theLen[6])
523 double aHeight = std::max(theLen[0],theLen[1]);
524 aHeight = std::max(aHeight,theLen[2]);
525 aHeight = std::max(aHeight,theLen[3]);
526 aHeight = std::max(aHeight,theLen[4]);
527 aHeight = std::max(aHeight,theLen[5]);
533 double AspectRatio3D::GetValue( const TSequenceOfXYZ& P )
535 double aQuality = 0.0;
536 if(myCurrElement->IsPoly()) return aQuality;
538 int nbNodes = P.size();
540 if(myCurrElement->IsQuadratic()) {
541 if(nbNodes==10) nbNodes=4; // quadratic tetrahedron
542 else if(nbNodes==13) nbNodes=5; // quadratic pyramid
543 else if(nbNodes==15) nbNodes=6; // quadratic pentahedron
544 else if(nbNodes==20) nbNodes=8; // quadratic hexahedron
545 else return aQuality;
551 getDistance(P( 1 ),P( 2 )), // a
552 getDistance(P( 2 ),P( 3 )), // b
553 getDistance(P( 3 ),P( 1 )), // c
554 getDistance(P( 2 ),P( 4 )), // d
555 getDistance(P( 3 ),P( 4 )), // e
556 getDistance(P( 1 ),P( 4 )) // f
558 double aTria[4][3] = {
559 {aLen[0],aLen[1],aLen[2]}, // abc
560 {aLen[0],aLen[3],aLen[5]}, // adf
561 {aLen[1],aLen[3],aLen[4]}, // bde
562 {aLen[2],aLen[4],aLen[5]} // cef
564 double aSumArea = 0.0;
565 double aHalfPerimeter = getHalfPerimeter(aTria[0]);
566 double anArea = getArea(aHalfPerimeter,aTria[0]);
568 aHalfPerimeter = getHalfPerimeter(aTria[1]);
569 anArea = getArea(aHalfPerimeter,aTria[1]);
571 aHalfPerimeter = getHalfPerimeter(aTria[2]);
572 anArea = getArea(aHalfPerimeter,aTria[2]);
574 aHalfPerimeter = getHalfPerimeter(aTria[3]);
575 anArea = getArea(aHalfPerimeter,aTria[3]);
577 double aVolume = getVolume(P);
578 //double aVolume = getVolume(aLen);
579 double aHeight = getMaxHeight(aLen);
580 static double aCoeff = sqrt(2.0)/12.0;
581 if ( aVolume > DBL_MIN )
582 aQuality = aCoeff*aHeight*aSumArea/aVolume;
587 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 3 ),P( 5 )};
588 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
591 gp_XYZ aXYZ[4] = {P( 1 ),P( 3 ),P( 4 ),P( 5 )};
592 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
595 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 5 )};
596 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
599 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 4 ),P( 5 )};
600 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
606 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 6 )};
607 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
610 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 3 )};
611 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
614 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 6 )};
615 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
618 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
619 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
622 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 6 )};
623 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
626 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 3 )};
627 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
633 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
634 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
637 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 4 )};
638 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
641 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 7 )};
642 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
645 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 8 )};
646 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
649 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 3 )};
650 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
653 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 4 )};
654 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
657 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 7 )};
658 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
661 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 8 )};
662 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
665 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 3 )};
666 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
669 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 4 )};
670 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
673 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 7 )};
674 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
677 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 8 )};
678 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
681 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 1 )};
682 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
685 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 2 )};
686 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
689 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 5 )};
690 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
693 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 6 )};
694 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
697 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 1 )};
698 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
701 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 2 )};
702 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
705 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 5 )};
706 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
709 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 6 )};
710 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
713 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 1 )};
714 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
717 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
718 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
721 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 5 )};
722 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
725 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 6 )};
726 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
729 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
730 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
733 gp_XYZ aXYZ[4] = {P( 4 ),P( 5 ),P( 8 ),P( 2 )};
734 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
737 gp_XYZ aXYZ[4] = {P( 1 ),P( 4 ),P( 5 ),P( 3 )};
738 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
741 gp_XYZ aXYZ[4] = {P( 3 ),P( 6 ),P( 7 ),P( 1 )};
742 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
745 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 6 ),P( 4 )};
746 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
749 gp_XYZ aXYZ[4] = {P( 5 ),P( 6 ),P( 8 ),P( 3 )};
750 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
753 gp_XYZ aXYZ[4] = {P( 7 ),P( 8 ),P( 6 ),P( 1 )};
754 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
757 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 7 )};
758 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
761 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 2 ),P( 5 )};
762 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
768 // avaluate aspect ratio of quadranle faces
769 AspectRatio aspect2D;
770 SMDS_VolumeTool::VolumeType type = SMDS_VolumeTool::GetType( nbNodes );
771 int nbFaces = SMDS_VolumeTool::NbFaces( type );
772 TSequenceOfXYZ points(4);
773 for ( int i = 0; i < nbFaces; ++i ) { // loop on faces of a volume
774 if ( SMDS_VolumeTool::NbFaceNodes( type, i ) != 4 )
776 const int* pInd = SMDS_VolumeTool::GetFaceNodesIndices( type, i, true );
777 for ( int p = 0; p < 4; ++p ) // loop on nodes of a quadranle face
778 points( p + 1 ) = P( pInd[ p ] + 1 );
779 aQuality = std::max( aQuality, aspect2D.GetValue( points ));
785 double AspectRatio3D::GetBadRate( double Value, int /*nbNodes*/ ) const
787 // the aspect ratio is in the range [1.0,infinity]
790 return Value / 1000.;
793 SMDSAbs_ElementType AspectRatio3D::GetType() const
795 return SMDSAbs_Volume;
801 Description : Functor for calculating warping
803 double Warping::GetValue( const TSequenceOfXYZ& P )
808 gp_XYZ G = ( P( 1 ) + P( 2 ) + P( 3 ) + P( 4 ) ) / 4.;
810 double A1 = ComputeA( P( 1 ), P( 2 ), P( 3 ), G );
811 double A2 = ComputeA( P( 2 ), P( 3 ), P( 4 ), G );
812 double A3 = ComputeA( P( 3 ), P( 4 ), P( 1 ), G );
813 double A4 = ComputeA( P( 4 ), P( 1 ), P( 2 ), G );
815 return Max( Max( A1, A2 ), Max( A3, A4 ) );
818 double Warping::ComputeA( const gp_XYZ& thePnt1,
819 const gp_XYZ& thePnt2,
820 const gp_XYZ& thePnt3,
821 const gp_XYZ& theG ) const
823 double aLen1 = gp_Pnt( thePnt1 ).Distance( gp_Pnt( thePnt2 ) );
824 double aLen2 = gp_Pnt( thePnt2 ).Distance( gp_Pnt( thePnt3 ) );
825 double L = Min( aLen1, aLen2 ) * 0.5;
826 if ( L < Precision::Confusion())
829 gp_XYZ GI = ( thePnt2 + thePnt1 ) / 2. - theG;
830 gp_XYZ GJ = ( thePnt3 + thePnt2 ) / 2. - theG;
831 gp_XYZ N = GI.Crossed( GJ );
833 if ( N.Modulus() < gp::Resolution() )
838 double H = ( thePnt2 - theG ).Dot( N );
839 return asin( fabs( H / L ) ) * 180. / PI;
842 double Warping::GetBadRate( double Value, int /*nbNodes*/ ) const
844 // the warp is in the range [0.0,PI/2]
845 // 0.0 = good (no warp)
846 // PI/2 = bad (face pliee)
850 SMDSAbs_ElementType Warping::GetType() const
858 Description : Functor for calculating taper
860 double Taper::GetValue( const TSequenceOfXYZ& P )
866 double J1 = getArea( P( 4 ), P( 1 ), P( 2 ) ) / 2.;
867 double J2 = getArea( P( 3 ), P( 1 ), P( 2 ) ) / 2.;
868 double J3 = getArea( P( 2 ), P( 3 ), P( 4 ) ) / 2.;
869 double J4 = getArea( P( 3 ), P( 4 ), P( 1 ) ) / 2.;
871 double JA = 0.25 * ( J1 + J2 + J3 + J4 );
872 if ( JA <= Precision::Confusion() )
875 double T1 = fabs( ( J1 - JA ) / JA );
876 double T2 = fabs( ( J2 - JA ) / JA );
877 double T3 = fabs( ( J3 - JA ) / JA );
878 double T4 = fabs( ( J4 - JA ) / JA );
880 return Max( Max( T1, T2 ), Max( T3, T4 ) );
883 double Taper::GetBadRate( double Value, int /*nbNodes*/ ) const
885 // the taper is in the range [0.0,1.0]
886 // 0.0 = good (no taper)
887 // 1.0 = bad (les cotes opposes sont allignes)
891 SMDSAbs_ElementType Taper::GetType() const
899 Description : Functor for calculating skew in degrees
901 static inline double skewAngle( const gp_XYZ& p1, const gp_XYZ& p2, const gp_XYZ& p3 )
903 gp_XYZ p12 = ( p2 + p1 ) / 2.;
904 gp_XYZ p23 = ( p3 + p2 ) / 2.;
905 gp_XYZ p31 = ( p3 + p1 ) / 2.;
907 gp_Vec v1( p31 - p2 ), v2( p12 - p23 );
909 return v1.Magnitude() < gp::Resolution() || v2.Magnitude() < gp::Resolution() ? 0. : v1.Angle( v2 );
912 double Skew::GetValue( const TSequenceOfXYZ& P )
914 if ( P.size() != 3 && P.size() != 4 )
918 static double PI2 = PI / 2.;
921 double A0 = fabs( PI2 - skewAngle( P( 3 ), P( 1 ), P( 2 ) ) );
922 double A1 = fabs( PI2 - skewAngle( P( 1 ), P( 2 ), P( 3 ) ) );
923 double A2 = fabs( PI2 - skewAngle( P( 2 ), P( 3 ), P( 1 ) ) );
925 return Max( A0, Max( A1, A2 ) ) * 180. / PI;
929 gp_XYZ p12 = ( P( 1 ) + P( 2 ) ) / 2.;
930 gp_XYZ p23 = ( P( 2 ) + P( 3 ) ) / 2.;
931 gp_XYZ p34 = ( P( 3 ) + P( 4 ) ) / 2.;
932 gp_XYZ p41 = ( P( 4 ) + P( 1 ) ) / 2.;
934 gp_Vec v1( p34 - p12 ), v2( p23 - p41 );
935 double A = v1.Magnitude() <= gp::Resolution() || v2.Magnitude() <= gp::Resolution()
936 ? 0. : fabs( PI2 - v1.Angle( v2 ) );
939 if ( A < Precision::Angular() )
942 return A * 180. / PI;
946 double Skew::GetBadRate( double Value, int /*nbNodes*/ ) const
948 // the skew is in the range [0.0,PI/2].
954 SMDSAbs_ElementType Skew::GetType() const
962 Description : Functor for calculating area
964 double Area::GetValue( const TSequenceOfXYZ& P )
966 gp_Vec aVec1( P(2) - P(1) );
967 gp_Vec aVec2( P(3) - P(1) );
968 gp_Vec SumVec = aVec1 ^ aVec2;
969 for (int i=4; i<=P.size(); i++) {
970 gp_Vec aVec1( P(i-1) - P(1) );
971 gp_Vec aVec2( P(i) - P(1) );
972 gp_Vec tmp = aVec1 ^ aVec2;
975 return SumVec.Magnitude() * 0.5;
978 double Area::GetBadRate( double Value, int /*nbNodes*/ ) const
980 // meaningless as it is not a quality control functor
984 SMDSAbs_ElementType Area::GetType() const
992 Description : Functor for calculating length off edge
994 double Length::GetValue( const TSequenceOfXYZ& P )
996 switch ( P.size() ) {
997 case 2: return getDistance( P( 1 ), P( 2 ) );
998 case 3: return getDistance( P( 1 ), P( 2 ) ) + getDistance( P( 2 ), P( 3 ) );
1003 double Length::GetBadRate( double Value, int /*nbNodes*/ ) const
1005 // meaningless as it is not quality control functor
1009 SMDSAbs_ElementType Length::GetType() const
1011 return SMDSAbs_Edge;
1016 Description : Functor for calculating length of edge
1019 double Length2D::GetValue( long theElementId)
1023 //cout<<"Length2D::GetValue"<<endl;
1024 if (GetPoints(theElementId,P)){
1025 //for(int jj=1; jj<=P.size(); jj++)
1026 // cout<<"jj="<<jj<<" P("<<P(jj).X()<<","<<P(jj).Y()<<","<<P(jj).Z()<<")"<<endl;
1028 double aVal;// = GetValue( P );
1029 const SMDS_MeshElement* aElem = myMesh->FindElement( theElementId );
1030 SMDSAbs_ElementType aType = aElem->GetType();
1039 aVal = getDistance( P( 1 ), P( 2 ) );
1042 else if (len == 3){ // quadratic edge
1043 aVal = getDistance(P( 1 ),P( 3 )) + getDistance(P( 3 ),P( 2 ));
1047 if (len == 3){ // triangles
1048 double L1 = getDistance(P( 1 ),P( 2 ));
1049 double L2 = getDistance(P( 2 ),P( 3 ));
1050 double L3 = getDistance(P( 3 ),P( 1 ));
1051 aVal = Max(L1,Max(L2,L3));
1054 else if (len == 4){ // quadrangles
1055 double L1 = getDistance(P( 1 ),P( 2 ));
1056 double L2 = getDistance(P( 2 ),P( 3 ));
1057 double L3 = getDistance(P( 3 ),P( 4 ));
1058 double L4 = getDistance(P( 4 ),P( 1 ));
1059 aVal = Max(Max(L1,L2),Max(L3,L4));
1062 if (len == 6){ // quadratic triangles
1063 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1064 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1065 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 1 ));
1066 aVal = Max(L1,Max(L2,L3));
1067 //cout<<"L1="<<L1<<" L2="<<L2<<"L3="<<L3<<" aVal="<<aVal<<endl;
1070 else if (len == 8){ // quadratic quadrangles
1071 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1072 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1073 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 7 ));
1074 double L4 = getDistance(P( 7 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
1075 aVal = Max(Max(L1,L2),Max(L3,L4));
1078 case SMDSAbs_Volume:
1079 if (len == 4){ // tetraidrs
1080 double L1 = getDistance(P( 1 ),P( 2 ));
1081 double L2 = getDistance(P( 2 ),P( 3 ));
1082 double L3 = getDistance(P( 3 ),P( 1 ));
1083 double L4 = getDistance(P( 1 ),P( 4 ));
1084 double L5 = getDistance(P( 2 ),P( 4 ));
1085 double L6 = getDistance(P( 3 ),P( 4 ));
1086 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1089 else if (len == 5){ // piramids
1090 double L1 = getDistance(P( 1 ),P( 2 ));
1091 double L2 = getDistance(P( 2 ),P( 3 ));
1092 double L3 = getDistance(P( 3 ),P( 1 ));
1093 double L4 = getDistance(P( 4 ),P( 1 ));
1094 double L5 = getDistance(P( 1 ),P( 5 ));
1095 double L6 = getDistance(P( 2 ),P( 5 ));
1096 double L7 = getDistance(P( 3 ),P( 5 ));
1097 double L8 = getDistance(P( 4 ),P( 5 ));
1099 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1100 aVal = Max(aVal,Max(L7,L8));
1103 else if (len == 6){ // pentaidres
1104 double L1 = getDistance(P( 1 ),P( 2 ));
1105 double L2 = getDistance(P( 2 ),P( 3 ));
1106 double L3 = getDistance(P( 3 ),P( 1 ));
1107 double L4 = getDistance(P( 4 ),P( 5 ));
1108 double L5 = getDistance(P( 5 ),P( 6 ));
1109 double L6 = getDistance(P( 6 ),P( 4 ));
1110 double L7 = getDistance(P( 1 ),P( 4 ));
1111 double L8 = getDistance(P( 2 ),P( 5 ));
1112 double L9 = getDistance(P( 3 ),P( 6 ));
1114 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1115 aVal = Max(aVal,Max(Max(L7,L8),L9));
1118 else if (len == 8){ // hexaider
1119 double L1 = getDistance(P( 1 ),P( 2 ));
1120 double L2 = getDistance(P( 2 ),P( 3 ));
1121 double L3 = getDistance(P( 3 ),P( 4 ));
1122 double L4 = getDistance(P( 4 ),P( 1 ));
1123 double L5 = getDistance(P( 5 ),P( 6 ));
1124 double L6 = getDistance(P( 6 ),P( 7 ));
1125 double L7 = getDistance(P( 7 ),P( 8 ));
1126 double L8 = getDistance(P( 8 ),P( 5 ));
1127 double L9 = getDistance(P( 1 ),P( 5 ));
1128 double L10= getDistance(P( 2 ),P( 6 ));
1129 double L11= getDistance(P( 3 ),P( 7 ));
1130 double L12= getDistance(P( 4 ),P( 8 ));
1132 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1133 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
1134 aVal = Max(aVal,Max(L11,L12));
1139 if (len == 10){ // quadratic tetraidrs
1140 double L1 = getDistance(P( 1 ),P( 5 )) + getDistance(P( 5 ),P( 2 ));
1141 double L2 = getDistance(P( 2 ),P( 6 )) + getDistance(P( 6 ),P( 3 ));
1142 double L3 = getDistance(P( 3 ),P( 7 )) + getDistance(P( 7 ),P( 1 ));
1143 double L4 = getDistance(P( 1 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
1144 double L5 = getDistance(P( 2 ),P( 9 )) + getDistance(P( 9 ),P( 4 ));
1145 double L6 = getDistance(P( 3 ),P( 10 )) + getDistance(P( 10 ),P( 4 ));
1146 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1149 else if (len == 13){ // quadratic piramids
1150 double L1 = getDistance(P( 1 ),P( 6 )) + getDistance(P( 6 ),P( 2 ));
1151 double L2 = getDistance(P( 2 ),P( 7 )) + getDistance(P( 7 ),P( 3 ));
1152 double L3 = getDistance(P( 3 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
1153 double L4 = getDistance(P( 4 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1154 double L5 = getDistance(P( 1 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1155 double L6 = getDistance(P( 2 ),P( 11 )) + getDistance(P( 11 ),P( 5 ));
1156 double L7 = getDistance(P( 3 ),P( 12 )) + getDistance(P( 12 ),P( 5 ));
1157 double L8 = getDistance(P( 4 ),P( 13 )) + getDistance(P( 13 ),P( 5 ));
1158 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1159 aVal = Max(aVal,Max(L7,L8));
1162 else if (len == 15){ // quadratic pentaidres
1163 double L1 = getDistance(P( 1 ),P( 7 )) + getDistance(P( 7 ),P( 2 ));
1164 double L2 = getDistance(P( 2 ),P( 8 )) + getDistance(P( 8 ),P( 3 ));
1165 double L3 = getDistance(P( 3 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1166 double L4 = getDistance(P( 4 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1167 double L5 = getDistance(P( 5 ),P( 11 )) + getDistance(P( 11 ),P( 6 ));
1168 double L6 = getDistance(P( 6 ),P( 12 )) + getDistance(P( 12 ),P( 4 ));
1169 double L7 = getDistance(P( 1 ),P( 13 )) + getDistance(P( 13 ),P( 4 ));
1170 double L8 = getDistance(P( 2 ),P( 14 )) + getDistance(P( 14 ),P( 5 ));
1171 double L9 = getDistance(P( 3 ),P( 15 )) + getDistance(P( 15 ),P( 6 ));
1172 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1173 aVal = Max(aVal,Max(Max(L7,L8),L9));
1176 else if (len == 20){ // quadratic hexaider
1177 double L1 = getDistance(P( 1 ),P( 9 )) + getDistance(P( 9 ),P( 2 ));
1178 double L2 = getDistance(P( 2 ),P( 10 )) + getDistance(P( 10 ),P( 3 ));
1179 double L3 = getDistance(P( 3 ),P( 11 )) + getDistance(P( 11 ),P( 4 ));
1180 double L4 = getDistance(P( 4 ),P( 12 )) + getDistance(P( 12 ),P( 1 ));
1181 double L5 = getDistance(P( 5 ),P( 13 )) + getDistance(P( 13 ),P( 6 ));
1182 double L6 = getDistance(P( 6 ),P( 14 )) + getDistance(P( 14 ),P( 7 ));
1183 double L7 = getDistance(P( 7 ),P( 15 )) + getDistance(P( 15 ),P( 8 ));
1184 double L8 = getDistance(P( 8 ),P( 16 )) + getDistance(P( 16 ),P( 5 ));
1185 double L9 = getDistance(P( 1 ),P( 17 )) + getDistance(P( 17 ),P( 5 ));
1186 double L10= getDistance(P( 2 ),P( 18 )) + getDistance(P( 18 ),P( 6 ));
1187 double L11= getDistance(P( 3 ),P( 19 )) + getDistance(P( 19 ),P( 7 ));
1188 double L12= getDistance(P( 4 ),P( 20 )) + getDistance(P( 20 ),P( 8 ));
1189 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1190 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
1191 aVal = Max(aVal,Max(L11,L12));
1203 if ( myPrecision >= 0 )
1205 double prec = pow( 10., (double)( myPrecision ) );
1206 aVal = floor( aVal * prec + 0.5 ) / prec;
1215 double Length2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1217 // meaningless as it is not quality control functor
1221 SMDSAbs_ElementType Length2D::GetType() const
1223 return SMDSAbs_Face;
1226 Length2D::Value::Value(double theLength,long thePntId1, long thePntId2):
1229 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1230 if(thePntId1 > thePntId2){
1231 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1235 bool Length2D::Value::operator<(const Length2D::Value& x) const{
1236 if(myPntId[0] < x.myPntId[0]) return true;
1237 if(myPntId[0] == x.myPntId[0])
1238 if(myPntId[1] < x.myPntId[1]) return true;
1242 void Length2D::GetValues(TValues& theValues){
1244 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1245 for(; anIter->more(); ){
1246 const SMDS_MeshFace* anElem = anIter->next();
1248 if(anElem->IsQuadratic()) {
1249 const SMDS_QuadraticFaceOfNodes* F =
1250 static_cast<const SMDS_QuadraticFaceOfNodes*>(anElem);
1251 // use special nodes iterator
1252 SMDS_NodeIteratorPtr anIter = F->interlacedNodesIterator();
1257 const SMDS_MeshElement* aNode;
1259 aNode = anIter->next();
1260 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1261 P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1262 aNodeId[0] = aNodeId[1] = aNode->GetID();
1265 for(; anIter->more(); ){
1266 const SMDS_MeshNode* N1 = static_cast<const SMDS_MeshNode*> (anIter->next());
1267 P[2] = gp_Pnt(N1->X(),N1->Y(),N1->Z());
1268 aNodeId[2] = N1->GetID();
1269 aLength = P[1].Distance(P[2]);
1270 if(!anIter->more()) break;
1271 const SMDS_MeshNode* N2 = static_cast<const SMDS_MeshNode*> (anIter->next());
1272 P[3] = gp_Pnt(N2->X(),N2->Y(),N2->Z());
1273 aNodeId[3] = N2->GetID();
1274 aLength += P[2].Distance(P[3]);
1275 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1276 Value aValue2(aLength,aNodeId[2],aNodeId[3]);
1278 aNodeId[1] = aNodeId[3];
1279 theValues.insert(aValue1);
1280 theValues.insert(aValue2);
1282 aLength += P[2].Distance(P[0]);
1283 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1284 Value aValue2(aLength,aNodeId[2],aNodeId[0]);
1285 theValues.insert(aValue1);
1286 theValues.insert(aValue2);
1289 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
1294 const SMDS_MeshElement* aNode;
1295 if(aNodesIter->more()){
1296 aNode = aNodesIter->next();
1297 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1298 P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1299 aNodeId[0] = aNodeId[1] = aNode->GetID();
1302 for(; aNodesIter->more(); ){
1303 aNode = aNodesIter->next();
1304 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1305 long anId = aNode->GetID();
1307 P[2] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1309 aLength = P[1].Distance(P[2]);
1311 Value aValue(aLength,aNodeId[1],anId);
1314 theValues.insert(aValue);
1317 aLength = P[0].Distance(P[1]);
1319 Value aValue(aLength,aNodeId[0],aNodeId[1]);
1320 theValues.insert(aValue);
1326 Class : MultiConnection
1327 Description : Functor for calculating number of faces conneted to the edge
1329 double MultiConnection::GetValue( const TSequenceOfXYZ& P )
1333 double MultiConnection::GetValue( long theId )
1335 return getNbMultiConnection( myMesh, theId );
1338 double MultiConnection::GetBadRate( double Value, int /*nbNodes*/ ) const
1340 // meaningless as it is not quality control functor
1344 SMDSAbs_ElementType MultiConnection::GetType() const
1346 return SMDSAbs_Edge;
1350 Class : MultiConnection2D
1351 Description : Functor for calculating number of faces conneted to the edge
1353 double MultiConnection2D::GetValue( const TSequenceOfXYZ& P )
1358 double MultiConnection2D::GetValue( long theElementId )
1362 const SMDS_MeshElement* aFaceElem = myMesh->FindElement(theElementId);
1363 SMDSAbs_ElementType aType = aFaceElem->GetType();
1368 int i = 0, len = aFaceElem->NbNodes();
1369 SMDS_ElemIteratorPtr anIter = aFaceElem->nodesIterator();
1372 const SMDS_MeshNode *aNode, *aNode0;
1373 TColStd_MapOfInteger aMap, aMapPrev;
1375 for (i = 0; i <= len; i++) {
1380 if (anIter->more()) {
1381 aNode = (SMDS_MeshNode*)anIter->next();
1389 if (i == 0) aNode0 = aNode;
1391 SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator();
1392 while (anElemIter->more()) {
1393 const SMDS_MeshElement* anElem = anElemIter->next();
1394 if (anElem != 0 && anElem->GetType() == SMDSAbs_Face) {
1395 int anId = anElem->GetID();
1398 if (aMapPrev.Contains(anId)) {
1403 aResult = Max(aResult, aNb);
1414 double MultiConnection2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1416 // meaningless as it is not quality control functor
1420 SMDSAbs_ElementType MultiConnection2D::GetType() const
1422 return SMDSAbs_Face;
1425 MultiConnection2D::Value::Value(long thePntId1, long thePntId2)
1427 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1428 if(thePntId1 > thePntId2){
1429 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1433 bool MultiConnection2D::Value::operator<(const MultiConnection2D::Value& x) const{
1434 if(myPntId[0] < x.myPntId[0]) return true;
1435 if(myPntId[0] == x.myPntId[0])
1436 if(myPntId[1] < x.myPntId[1]) return true;
1440 void MultiConnection2D::GetValues(MValues& theValues){
1441 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1442 for(; anIter->more(); ){
1443 const SMDS_MeshFace* anElem = anIter->next();
1444 SMDS_ElemIteratorPtr aNodesIter;
1445 if ( anElem->IsQuadratic() )
1446 aNodesIter = static_cast<const SMDS_QuadraticFaceOfNodes*>
1447 (anElem)->interlacedNodesElemIterator();
1449 aNodesIter = anElem->nodesIterator();
1452 //int aNbConnects=0;
1453 const SMDS_MeshNode* aNode0;
1454 const SMDS_MeshNode* aNode1;
1455 const SMDS_MeshNode* aNode2;
1456 if(aNodesIter->more()){
1457 aNode0 = (SMDS_MeshNode*) aNodesIter->next();
1459 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode1;
1460 aNodeId[0] = aNodeId[1] = aNodes->GetID();
1462 for(; aNodesIter->more(); ) {
1463 aNode2 = (SMDS_MeshNode*) aNodesIter->next();
1464 long anId = aNode2->GetID();
1467 Value aValue(aNodeId[1],aNodeId[2]);
1468 MValues::iterator aItr = theValues.find(aValue);
1469 if (aItr != theValues.end()){
1474 theValues[aValue] = 1;
1477 //cout << "NodeIds: "<<aNodeId[1]<<","<<aNodeId[2]<<" nbconn="<<aNbConnects<<endl;
1478 aNodeId[1] = aNodeId[2];
1481 Value aValue(aNodeId[0],aNodeId[2]);
1482 MValues::iterator aItr = theValues.find(aValue);
1483 if (aItr != theValues.end()) {
1488 theValues[aValue] = 1;
1491 //cout << "NodeIds: "<<aNodeId[0]<<","<<aNodeId[2]<<" nbconn="<<aNbConnects<<endl;
1501 Class : BadOrientedVolume
1502 Description : Predicate bad oriented volumes
1505 BadOrientedVolume::BadOrientedVolume()
1510 void BadOrientedVolume::SetMesh( const SMDS_Mesh* theMesh )
1515 bool BadOrientedVolume::IsSatisfy( long theId )
1520 SMDS_VolumeTool vTool( myMesh->FindElement( theId ));
1521 return !vTool.IsForward();
1524 SMDSAbs_ElementType BadOrientedVolume::GetType() const
1526 return SMDSAbs_Volume;
1533 Description : Predicate for free borders
1536 FreeBorders::FreeBorders()
1541 void FreeBorders::SetMesh( const SMDS_Mesh* theMesh )
1546 bool FreeBorders::IsSatisfy( long theId )
1548 return getNbMultiConnection( myMesh, theId ) == 1;
1551 SMDSAbs_ElementType FreeBorders::GetType() const
1553 return SMDSAbs_Edge;
1559 Description : Predicate for free Edges
1561 FreeEdges::FreeEdges()
1566 void FreeEdges::SetMesh( const SMDS_Mesh* theMesh )
1571 bool FreeEdges::IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId )
1573 TColStd_MapOfInteger aMap;
1574 for ( int i = 0; i < 2; i++ )
1576 SMDS_ElemIteratorPtr anElemIter = theNodes[ i ]->GetInverseElementIterator();
1577 while( anElemIter->more() )
1579 const SMDS_MeshElement* anElem = anElemIter->next();
1580 if ( anElem != 0 && anElem->GetType() == SMDSAbs_Face )
1582 int anId = anElem->GetID();
1586 else if ( aMap.Contains( anId ) && anId != theFaceId )
1594 bool FreeEdges::IsSatisfy( long theId )
1599 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
1600 if ( aFace == 0 || aFace->GetType() != SMDSAbs_Face || aFace->NbNodes() < 3 )
1603 SMDS_ElemIteratorPtr anIter;
1604 if ( aFace->IsQuadratic() ) {
1605 anIter = static_cast<const SMDS_QuadraticFaceOfNodes*>
1606 (aFace)->interlacedNodesElemIterator();
1609 anIter = aFace->nodesIterator();
1614 int i = 0, nbNodes = aFace->NbNodes();
1615 std::vector <const SMDS_MeshNode*> aNodes( nbNodes+1 );
1616 while( anIter->more() )
1618 const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next();
1621 aNodes[ i++ ] = aNode;
1623 aNodes[ nbNodes ] = aNodes[ 0 ];
1625 for ( i = 0; i < nbNodes; i++ )
1626 if ( IsFreeEdge( &aNodes[ i ], theId ) )
1632 SMDSAbs_ElementType FreeEdges::GetType() const
1634 return SMDSAbs_Face;
1637 FreeEdges::Border::Border(long theElemId, long thePntId1, long thePntId2):
1640 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1641 if(thePntId1 > thePntId2){
1642 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1646 bool FreeEdges::Border::operator<(const FreeEdges::Border& x) const{
1647 if(myPntId[0] < x.myPntId[0]) return true;
1648 if(myPntId[0] == x.myPntId[0])
1649 if(myPntId[1] < x.myPntId[1]) return true;
1653 inline void UpdateBorders(const FreeEdges::Border& theBorder,
1654 FreeEdges::TBorders& theRegistry,
1655 FreeEdges::TBorders& theContainer)
1657 if(theRegistry.find(theBorder) == theRegistry.end()){
1658 theRegistry.insert(theBorder);
1659 theContainer.insert(theBorder);
1661 theContainer.erase(theBorder);
1665 void FreeEdges::GetBoreders(TBorders& theBorders)
1668 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1669 for(; anIter->more(); ){
1670 const SMDS_MeshFace* anElem = anIter->next();
1671 long anElemId = anElem->GetID();
1672 SMDS_ElemIteratorPtr aNodesIter;
1673 if ( anElem->IsQuadratic() )
1674 aNodesIter = static_cast<const SMDS_QuadraticFaceOfNodes*>(anElem)->
1675 interlacedNodesElemIterator();
1677 aNodesIter = anElem->nodesIterator();
1679 const SMDS_MeshElement* aNode;
1680 if(aNodesIter->more()){
1681 aNode = aNodesIter->next();
1682 aNodeId[0] = aNodeId[1] = aNode->GetID();
1684 for(; aNodesIter->more(); ){
1685 aNode = aNodesIter->next();
1686 long anId = aNode->GetID();
1687 Border aBorder(anElemId,aNodeId[1],anId);
1689 //std::cout<<aBorder.myPntId[0]<<"; "<<aBorder.myPntId[1]<<"; "<<aBorder.myElemId<<endl;
1690 UpdateBorders(aBorder,aRegistry,theBorders);
1692 Border aBorder(anElemId,aNodeId[0],aNodeId[1]);
1693 //std::cout<<aBorder.myPntId[0]<<"; "<<aBorder.myPntId[1]<<"; "<<aBorder.myElemId<<endl;
1694 UpdateBorders(aBorder,aRegistry,theBorders);
1696 //std::cout<<"theBorders.size() = "<<theBorders.size()<<endl;
1702 Description : Predicate for free nodes
1705 FreeNodes::FreeNodes()
1710 void FreeNodes::SetMesh( const SMDS_Mesh* theMesh )
1715 bool FreeNodes::IsSatisfy( long theNodeId )
1717 const SMDS_MeshNode* aNode = myMesh->FindNode( theNodeId );
1721 return (aNode->NbInverseElements() < 1);
1724 SMDSAbs_ElementType FreeNodes::GetType() const
1726 return SMDSAbs_Node;
1732 Description : Predicate for free faces
1735 FreeFaces::FreeFaces()
1740 void FreeFaces::SetMesh( const SMDS_Mesh* theMesh )
1745 bool FreeFaces::IsSatisfy( long theId )
1747 if (!myMesh) return false;
1748 // check that faces nodes refers to less than two common volumes
1749 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
1750 if ( !aFace || aFace->GetType() != SMDSAbs_Face )
1753 int nbNode = aFace->NbNodes();
1755 // collect volumes check that number of volumss with count equal nbNode not less than 2
1756 typedef map< SMDS_MeshElement*, int > TMapOfVolume; // map of volume counters
1757 typedef map< SMDS_MeshElement*, int >::iterator TItrMapOfVolume; // iterator
1758 TMapOfVolume mapOfVol;
1760 SMDS_ElemIteratorPtr nodeItr = aFace->nodesIterator();
1761 while ( nodeItr->more() ) {
1762 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(nodeItr->next());
1763 if ( !aNode ) continue;
1764 SMDS_ElemIteratorPtr volItr = aNode->GetInverseElementIterator(SMDSAbs_Volume);
1765 while ( volItr->more() ) {
1766 SMDS_MeshElement* aVol = (SMDS_MeshElement*)volItr->next();
1767 TItrMapOfVolume itr = mapOfVol.insert(make_pair(aVol, 0)).first;
1772 TItrMapOfVolume volItr = mapOfVol.begin();
1773 TItrMapOfVolume volEnd = mapOfVol.end();
1774 for ( ; volItr != volEnd; ++volItr )
1775 if ( (*volItr).second >= nbNode )
1777 // face is not free if number of volumes constructed on thier nodes more than one
1781 SMDSAbs_ElementType FreeFaces::GetType() const
1783 return SMDSAbs_Face;
1787 Class : LinearOrQuadratic
1788 Description : Predicate to verify whether a mesh element is linear
1791 LinearOrQuadratic::LinearOrQuadratic()
1796 void LinearOrQuadratic::SetMesh( const SMDS_Mesh* theMesh )
1801 bool LinearOrQuadratic::IsSatisfy( long theId )
1803 if (!myMesh) return false;
1804 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
1805 if ( !anElem || (myType != SMDSAbs_All && anElem->GetType() != myType) )
1807 return (!anElem->IsQuadratic());
1810 void LinearOrQuadratic::SetType( SMDSAbs_ElementType theType )
1815 SMDSAbs_ElementType LinearOrQuadratic::GetType() const
1822 Description : Functor for check color of group to whic mesh element belongs to
1825 GroupColor::GroupColor()
1829 bool GroupColor::IsSatisfy( long theId )
1831 return (myIDs.find( theId ) != myIDs.end());
1834 void GroupColor::SetType( SMDSAbs_ElementType theType )
1839 SMDSAbs_ElementType GroupColor::GetType() const
1844 static bool isEqual( const Quantity_Color& theColor1,
1845 const Quantity_Color& theColor2 )
1847 // tolerance to compare colors
1848 const double tol = 5*1e-3;
1849 return ( fabs( theColor1.Red() - theColor2.Red() ) < tol &&
1850 fabs( theColor1.Green() - theColor2.Green() ) < tol &&
1851 fabs( theColor1.Blue() - theColor2.Blue() ) < tol );
1855 void GroupColor::SetMesh( const SMDS_Mesh* theMesh )
1859 const SMESHDS_Mesh* aMesh = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
1863 int nbGrp = aMesh->GetNbGroups();
1867 // iterates on groups and find necessary elements ids
1868 const std::set<SMESHDS_GroupBase*>& aGroups = aMesh->GetGroups();
1869 set<SMESHDS_GroupBase*>::const_iterator GrIt = aGroups.begin();
1870 for (; GrIt != aGroups.end(); GrIt++) {
1871 SMESHDS_GroupBase* aGrp = (*GrIt);
1874 // check type and color of group
1875 if ( !isEqual( myColor, aGrp->GetColor() ) )
1877 if ( myType != SMDSAbs_All && myType != (SMDSAbs_ElementType)aGrp->GetType() )
1880 SMDSAbs_ElementType aGrpElType = (SMDSAbs_ElementType)aGrp->GetType();
1881 if ( myType == aGrpElType || (myType == SMDSAbs_All && aGrpElType != SMDSAbs_Node) ) {
1882 // add elements IDS into control
1883 int aSize = aGrp->Extent();
1884 for (int i = 0; i < aSize; i++)
1885 myIDs.insert( aGrp->GetID(i+1) );
1890 void GroupColor::SetColorStr( const TCollection_AsciiString& theStr )
1892 TCollection_AsciiString aStr = theStr;
1893 aStr.RemoveAll( ' ' );
1894 aStr.RemoveAll( '\t' );
1895 for ( int aPos = aStr.Search( ";;" ); aPos != -1; aPos = aStr.Search( ";;" ) )
1896 aStr.Remove( aPos, 2 );
1897 Standard_Real clr[3];
1898 clr[0] = clr[1] = clr[2] = 0.;
1899 for ( int i = 0; i < 3; i++ ) {
1900 TCollection_AsciiString tmpStr = aStr.Token( ";", i+1 );
1901 if ( !tmpStr.IsEmpty() && tmpStr.IsRealValue() )
1902 clr[i] = tmpStr.RealValue();
1904 myColor = Quantity_Color( clr[0], clr[1], clr[2], Quantity_TOC_RGB );
1907 //=======================================================================
1908 // name : GetRangeStr
1909 // Purpose : Get range as a string.
1910 // Example: "1,2,3,50-60,63,67,70-"
1911 //=======================================================================
1912 void GroupColor::GetColorStr( TCollection_AsciiString& theResStr ) const
1915 theResStr += TCollection_AsciiString( myColor.Red() );
1916 theResStr += TCollection_AsciiString( ";" ) + TCollection_AsciiString( myColor.Green() );
1917 theResStr += TCollection_AsciiString( ";" ) + TCollection_AsciiString( myColor.Blue() );
1921 Class : ElemGeomType
1922 Description : Predicate to check element geometry type
1925 ElemGeomType::ElemGeomType()
1928 myType = SMDSAbs_All;
1929 myGeomType = SMDSGeom_TRIANGLE;
1932 void ElemGeomType::SetMesh( const SMDS_Mesh* theMesh )
1937 bool ElemGeomType::IsSatisfy( long theId )
1939 if (!myMesh) return false;
1940 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
1941 const SMDSAbs_ElementType anElemType = anElem->GetType();
1942 if ( !anElem || (myType != SMDSAbs_All && anElemType != myType) )
1944 const int aNbNode = anElem->NbNodes();
1946 switch( anElemType )
1949 isOk = (myGeomType == SMDSGeom_POINT);
1953 isOk = (myGeomType == SMDSGeom_EDGE);
1957 if ( myGeomType == SMDSGeom_TRIANGLE )
1958 isOk = (!anElem->IsPoly() && (anElem->IsQuadratic() ? aNbNode == 6 : aNbNode == 3));
1959 else if ( myGeomType == SMDSGeom_QUADRANGLE )
1960 isOk = (!anElem->IsPoly() && (anElem->IsQuadratic() ? aNbNode == 8 : aNbNode == 4));
1961 else if ( myGeomType == SMDSGeom_POLYGON )
1962 isOk = anElem->IsPoly();
1965 case SMDSAbs_Volume:
1966 if ( myGeomType == SMDSGeom_TETRA )
1967 isOk = (!anElem->IsPoly() && (anElem->IsQuadratic() ? aNbNode == 10 : aNbNode == 4));
1968 else if ( myGeomType == SMDSGeom_PYRAMID )
1969 isOk = (!anElem->IsPoly() && (anElem->IsQuadratic() ? aNbNode == 13 : aNbNode == 5));
1970 else if ( myGeomType == SMDSGeom_PENTA )
1971 isOk = (!anElem->IsPoly() && (anElem->IsQuadratic() ? aNbNode == 15 : aNbNode == 6));
1972 else if ( myGeomType == SMDSGeom_HEXA )
1973 isOk = (!anElem->IsPoly() && (anElem->IsQuadratic() ? aNbNode == 20 : aNbNode == 8));
1974 else if ( myGeomType == SMDSGeom_POLYHEDRA )
1975 isOk = anElem->IsPoly();
1982 void ElemGeomType::SetType( SMDSAbs_ElementType theType )
1987 SMDSAbs_ElementType ElemGeomType::GetType() const
1992 void ElemGeomType::SetGeomType( SMDSAbs_GeometryType theType )
1994 myGeomType = theType;
1997 SMDSAbs_GeometryType ElemGeomType::GetGeomType() const
2004 Description : Predicate for Range of Ids.
2005 Range may be specified with two ways.
2006 1. Using AddToRange method
2007 2. With SetRangeStr method. Parameter of this method is a string
2008 like as "1,2,3,50-60,63,67,70-"
2011 //=======================================================================
2012 // name : RangeOfIds
2013 // Purpose : Constructor
2014 //=======================================================================
2015 RangeOfIds::RangeOfIds()
2018 myType = SMDSAbs_All;
2021 //=======================================================================
2023 // Purpose : Set mesh
2024 //=======================================================================
2025 void RangeOfIds::SetMesh( const SMDS_Mesh* theMesh )
2030 //=======================================================================
2031 // name : AddToRange
2032 // Purpose : Add ID to the range
2033 //=======================================================================
2034 bool RangeOfIds::AddToRange( long theEntityId )
2036 myIds.Add( theEntityId );
2040 //=======================================================================
2041 // name : GetRangeStr
2042 // Purpose : Get range as a string.
2043 // Example: "1,2,3,50-60,63,67,70-"
2044 //=======================================================================
2045 void RangeOfIds::GetRangeStr( TCollection_AsciiString& theResStr )
2049 TColStd_SequenceOfInteger anIntSeq;
2050 TColStd_SequenceOfAsciiString aStrSeq;
2052 TColStd_MapIteratorOfMapOfInteger anIter( myIds );
2053 for ( ; anIter.More(); anIter.Next() )
2055 int anId = anIter.Key();
2056 TCollection_AsciiString aStr( anId );
2057 anIntSeq.Append( anId );
2058 aStrSeq.Append( aStr );
2061 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
2063 int aMinId = myMin( i );
2064 int aMaxId = myMax( i );
2066 TCollection_AsciiString aStr;
2067 if ( aMinId != IntegerFirst() )
2072 if ( aMaxId != IntegerLast() )
2075 // find position of the string in result sequence and insert string in it
2076 if ( anIntSeq.Length() == 0 )
2078 anIntSeq.Append( aMinId );
2079 aStrSeq.Append( aStr );
2083 if ( aMinId < anIntSeq.First() )
2085 anIntSeq.Prepend( aMinId );
2086 aStrSeq.Prepend( aStr );
2088 else if ( aMinId > anIntSeq.Last() )
2090 anIntSeq.Append( aMinId );
2091 aStrSeq.Append( aStr );
2094 for ( int j = 1, k = anIntSeq.Length(); j <= k; j++ )
2095 if ( aMinId < anIntSeq( j ) )
2097 anIntSeq.InsertBefore( j, aMinId );
2098 aStrSeq.InsertBefore( j, aStr );
2104 if ( aStrSeq.Length() == 0 )
2107 theResStr = aStrSeq( 1 );
2108 for ( int j = 2, k = aStrSeq.Length(); j <= k; j++ )
2111 theResStr += aStrSeq( j );
2115 //=======================================================================
2116 // name : SetRangeStr
2117 // Purpose : Define range with string
2118 // Example of entry string: "1,2,3,50-60,63,67,70-"
2119 //=======================================================================
2120 bool RangeOfIds::SetRangeStr( const TCollection_AsciiString& theStr )
2126 TCollection_AsciiString aStr = theStr;
2127 aStr.RemoveAll( ' ' );
2128 aStr.RemoveAll( '\t' );
2130 for ( int aPos = aStr.Search( ",," ); aPos != -1; aPos = aStr.Search( ",," ) )
2131 aStr.Remove( aPos, 2 );
2133 TCollection_AsciiString tmpStr = aStr.Token( ",", 1 );
2135 while ( tmpStr != "" )
2137 tmpStr = aStr.Token( ",", i++ );
2138 int aPos = tmpStr.Search( '-' );
2142 if ( tmpStr.IsIntegerValue() )
2143 myIds.Add( tmpStr.IntegerValue() );
2149 TCollection_AsciiString aMaxStr = tmpStr.Split( aPos );
2150 TCollection_AsciiString aMinStr = tmpStr;
2152 while ( aMinStr.Search( "-" ) != -1 ) aMinStr.RemoveAll( '-' );
2153 while ( aMaxStr.Search( "-" ) != -1 ) aMaxStr.RemoveAll( '-' );
2155 if ( !aMinStr.IsEmpty() && !aMinStr.IsIntegerValue() ||
2156 !aMaxStr.IsEmpty() && !aMaxStr.IsIntegerValue() )
2159 myMin.Append( aMinStr.IsEmpty() ? IntegerFirst() : aMinStr.IntegerValue() );
2160 myMax.Append( aMaxStr.IsEmpty() ? IntegerLast() : aMaxStr.IntegerValue() );
2167 //=======================================================================
2169 // Purpose : Get type of supported entities
2170 //=======================================================================
2171 SMDSAbs_ElementType RangeOfIds::GetType() const
2176 //=======================================================================
2178 // Purpose : Set type of supported entities
2179 //=======================================================================
2180 void RangeOfIds::SetType( SMDSAbs_ElementType theType )
2185 //=======================================================================
2187 // Purpose : Verify whether entity satisfies to this rpedicate
2188 //=======================================================================
2189 bool RangeOfIds::IsSatisfy( long theId )
2194 if ( myType == SMDSAbs_Node )
2196 if ( myMesh->FindNode( theId ) == 0 )
2201 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2202 if ( anElem == 0 || myType != anElem->GetType() && myType != SMDSAbs_All )
2206 if ( myIds.Contains( theId ) )
2209 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
2210 if ( theId >= myMin( i ) && theId <= myMax( i ) )
2218 Description : Base class for comparators
2220 Comparator::Comparator():
2224 Comparator::~Comparator()
2227 void Comparator::SetMesh( const SMDS_Mesh* theMesh )
2230 myFunctor->SetMesh( theMesh );
2233 void Comparator::SetMargin( double theValue )
2235 myMargin = theValue;
2238 void Comparator::SetNumFunctor( NumericalFunctorPtr theFunct )
2240 myFunctor = theFunct;
2243 SMDSAbs_ElementType Comparator::GetType() const
2245 return myFunctor ? myFunctor->GetType() : SMDSAbs_All;
2248 double Comparator::GetMargin()
2256 Description : Comparator "<"
2258 bool LessThan::IsSatisfy( long theId )
2260 return myFunctor && myFunctor->GetValue( theId ) < myMargin;
2266 Description : Comparator ">"
2268 bool MoreThan::IsSatisfy( long theId )
2270 return myFunctor && myFunctor->GetValue( theId ) > myMargin;
2276 Description : Comparator "="
2279 myToler(Precision::Confusion())
2282 bool EqualTo::IsSatisfy( long theId )
2284 return myFunctor && fabs( myFunctor->GetValue( theId ) - myMargin ) < myToler;
2287 void EqualTo::SetTolerance( double theToler )
2292 double EqualTo::GetTolerance()
2299 Description : Logical NOT predicate
2301 LogicalNOT::LogicalNOT()
2304 LogicalNOT::~LogicalNOT()
2307 bool LogicalNOT::IsSatisfy( long theId )
2309 return myPredicate && !myPredicate->IsSatisfy( theId );
2312 void LogicalNOT::SetMesh( const SMDS_Mesh* theMesh )
2315 myPredicate->SetMesh( theMesh );
2318 void LogicalNOT::SetPredicate( PredicatePtr thePred )
2320 myPredicate = thePred;
2323 SMDSAbs_ElementType LogicalNOT::GetType() const
2325 return myPredicate ? myPredicate->GetType() : SMDSAbs_All;
2330 Class : LogicalBinary
2331 Description : Base class for binary logical predicate
2333 LogicalBinary::LogicalBinary()
2336 LogicalBinary::~LogicalBinary()
2339 void LogicalBinary::SetMesh( const SMDS_Mesh* theMesh )
2342 myPredicate1->SetMesh( theMesh );
2345 myPredicate2->SetMesh( theMesh );
2348 void LogicalBinary::SetPredicate1( PredicatePtr thePredicate )
2350 myPredicate1 = thePredicate;
2353 void LogicalBinary::SetPredicate2( PredicatePtr thePredicate )
2355 myPredicate2 = thePredicate;
2358 SMDSAbs_ElementType LogicalBinary::GetType() const
2360 if ( !myPredicate1 || !myPredicate2 )
2363 SMDSAbs_ElementType aType1 = myPredicate1->GetType();
2364 SMDSAbs_ElementType aType2 = myPredicate2->GetType();
2366 return aType1 == aType2 ? aType1 : SMDSAbs_All;
2372 Description : Logical AND
2374 bool LogicalAND::IsSatisfy( long theId )
2379 myPredicate1->IsSatisfy( theId ) &&
2380 myPredicate2->IsSatisfy( theId );
2386 Description : Logical OR
2388 bool LogicalOR::IsSatisfy( long theId )
2393 myPredicate1->IsSatisfy( theId ) ||
2394 myPredicate2->IsSatisfy( theId );
2408 void Filter::SetPredicate( PredicatePtr thePredicate )
2410 myPredicate = thePredicate;
2413 template<class TElement, class TIterator, class TPredicate>
2414 inline void FillSequence(const TIterator& theIterator,
2415 TPredicate& thePredicate,
2416 Filter::TIdSequence& theSequence)
2418 if ( theIterator ) {
2419 while( theIterator->more() ) {
2420 TElement anElem = theIterator->next();
2421 long anId = anElem->GetID();
2422 if ( thePredicate->IsSatisfy( anId ) )
2423 theSequence.push_back( anId );
2430 GetElementsId( const SMDS_Mesh* theMesh,
2431 PredicatePtr thePredicate,
2432 TIdSequence& theSequence )
2434 theSequence.clear();
2436 if ( !theMesh || !thePredicate )
2439 thePredicate->SetMesh( theMesh );
2441 SMDSAbs_ElementType aType = thePredicate->GetType();
2444 FillSequence<const SMDS_MeshNode*>(theMesh->nodesIterator(),thePredicate,theSequence);
2447 FillSequence<const SMDS_MeshElement*>(theMesh->edgesIterator(),thePredicate,theSequence);
2450 FillSequence<const SMDS_MeshElement*>(theMesh->facesIterator(),thePredicate,theSequence);
2452 case SMDSAbs_Volume:
2453 FillSequence<const SMDS_MeshElement*>(theMesh->volumesIterator(),thePredicate,theSequence);
2456 FillSequence<const SMDS_MeshElement*>(theMesh->edgesIterator(),thePredicate,theSequence);
2457 FillSequence<const SMDS_MeshElement*>(theMesh->facesIterator(),thePredicate,theSequence);
2458 FillSequence<const SMDS_MeshElement*>(theMesh->volumesIterator(),thePredicate,theSequence);
2464 Filter::GetElementsId( const SMDS_Mesh* theMesh,
2465 Filter::TIdSequence& theSequence )
2467 GetElementsId(theMesh,myPredicate,theSequence);
2474 typedef std::set<SMDS_MeshFace*> TMapOfFacePtr;
2480 ManifoldPart::Link::Link( SMDS_MeshNode* theNode1,
2481 SMDS_MeshNode* theNode2 )
2487 ManifoldPart::Link::~Link()
2493 bool ManifoldPart::Link::IsEqual( const ManifoldPart::Link& theLink ) const
2495 if ( myNode1 == theLink.myNode1 &&
2496 myNode2 == theLink.myNode2 )
2498 else if ( myNode1 == theLink.myNode2 &&
2499 myNode2 == theLink.myNode1 )
2505 bool ManifoldPart::Link::operator<( const ManifoldPart::Link& x ) const
2507 if(myNode1 < x.myNode1) return true;
2508 if(myNode1 == x.myNode1)
2509 if(myNode2 < x.myNode2) return true;
2513 bool ManifoldPart::IsEqual( const ManifoldPart::Link& theLink1,
2514 const ManifoldPart::Link& theLink2 )
2516 return theLink1.IsEqual( theLink2 );
2519 ManifoldPart::ManifoldPart()
2522 myAngToler = Precision::Angular();
2523 myIsOnlyManifold = true;
2526 ManifoldPart::~ManifoldPart()
2531 void ManifoldPart::SetMesh( const SMDS_Mesh* theMesh )
2537 SMDSAbs_ElementType ManifoldPart::GetType() const
2538 { return SMDSAbs_Face; }
2540 bool ManifoldPart::IsSatisfy( long theElementId )
2542 return myMapIds.Contains( theElementId );
2545 void ManifoldPart::SetAngleTolerance( const double theAngToler )
2546 { myAngToler = theAngToler; }
2548 double ManifoldPart::GetAngleTolerance() const
2549 { return myAngToler; }
2551 void ManifoldPart::SetIsOnlyManifold( const bool theIsOnly )
2552 { myIsOnlyManifold = theIsOnly; }
2554 void ManifoldPart::SetStartElem( const long theStartId )
2555 { myStartElemId = theStartId; }
2557 bool ManifoldPart::process()
2560 myMapBadGeomIds.Clear();
2562 myAllFacePtr.clear();
2563 myAllFacePtrIntDMap.clear();
2567 // collect all faces into own map
2568 SMDS_FaceIteratorPtr anFaceItr = myMesh->facesIterator();
2569 for (; anFaceItr->more(); )
2571 SMDS_MeshFace* aFacePtr = (SMDS_MeshFace*)anFaceItr->next();
2572 myAllFacePtr.push_back( aFacePtr );
2573 myAllFacePtrIntDMap[aFacePtr] = myAllFacePtr.size()-1;
2576 SMDS_MeshFace* aStartFace = (SMDS_MeshFace*)myMesh->FindElement( myStartElemId );
2580 // the map of non manifold links and bad geometry
2581 TMapOfLink aMapOfNonManifold;
2582 TColStd_MapOfInteger aMapOfTreated;
2584 // begin cycle on faces from start index and run on vector till the end
2585 // and from begin to start index to cover whole vector
2586 const int aStartIndx = myAllFacePtrIntDMap[aStartFace];
2587 bool isStartTreat = false;
2588 for ( int fi = aStartIndx; !isStartTreat || fi != aStartIndx ; fi++ )
2590 if ( fi == aStartIndx )
2591 isStartTreat = true;
2592 // as result next time when fi will be equal to aStartIndx
2594 SMDS_MeshFace* aFacePtr = myAllFacePtr[ fi ];
2595 if ( aMapOfTreated.Contains( aFacePtr->GetID() ) )
2598 aMapOfTreated.Add( aFacePtr->GetID() );
2599 TColStd_MapOfInteger aResFaces;
2600 if ( !findConnected( myAllFacePtrIntDMap, aFacePtr,
2601 aMapOfNonManifold, aResFaces ) )
2603 TColStd_MapIteratorOfMapOfInteger anItr( aResFaces );
2604 for ( ; anItr.More(); anItr.Next() )
2606 int aFaceId = anItr.Key();
2607 aMapOfTreated.Add( aFaceId );
2608 myMapIds.Add( aFaceId );
2611 if ( fi == ( myAllFacePtr.size() - 1 ) )
2613 } // end run on vector of faces
2614 return !myMapIds.IsEmpty();
2617 static void getLinks( const SMDS_MeshFace* theFace,
2618 ManifoldPart::TVectorOfLink& theLinks )
2620 int aNbNode = theFace->NbNodes();
2621 SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
2623 SMDS_MeshNode* aNode = 0;
2624 for ( ; aNodeItr->more() && i <= aNbNode; )
2627 SMDS_MeshNode* aN1 = (SMDS_MeshNode*)aNodeItr->next();
2631 SMDS_MeshNode* aN2 = ( i >= aNbNode ) ? aNode : (SMDS_MeshNode*)aNodeItr->next();
2633 ManifoldPart::Link aLink( aN1, aN2 );
2634 theLinks.push_back( aLink );
2638 static gp_XYZ getNormale( const SMDS_MeshFace* theFace )
2641 int aNbNode = theFace->NbNodes();
2642 TColgp_Array1OfXYZ anArrOfXYZ(1,4);
2643 SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
2645 for ( ; aNodeItr->more() && i <= 4; i++ ) {
2646 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
2647 anArrOfXYZ.SetValue(i, gp_XYZ( aNode->X(), aNode->Y(), aNode->Z() ) );
2650 gp_XYZ q1 = anArrOfXYZ.Value(2) - anArrOfXYZ.Value(1);
2651 gp_XYZ q2 = anArrOfXYZ.Value(3) - anArrOfXYZ.Value(1);
2653 if ( aNbNode > 3 ) {
2654 gp_XYZ q3 = anArrOfXYZ.Value(4) - anArrOfXYZ.Value(1);
2657 double len = n.Modulus();
2664 bool ManifoldPart::findConnected
2665 ( const ManifoldPart::TDataMapFacePtrInt& theAllFacePtrInt,
2666 SMDS_MeshFace* theStartFace,
2667 ManifoldPart::TMapOfLink& theNonManifold,
2668 TColStd_MapOfInteger& theResFaces )
2670 theResFaces.Clear();
2671 if ( !theAllFacePtrInt.size() )
2674 if ( getNormale( theStartFace ).SquareModulus() <= gp::Resolution() )
2676 myMapBadGeomIds.Add( theStartFace->GetID() );
2680 ManifoldPart::TMapOfLink aMapOfBoundary, aMapToSkip;
2681 ManifoldPart::TVectorOfLink aSeqOfBoundary;
2682 theResFaces.Add( theStartFace->GetID() );
2683 ManifoldPart::TDataMapOfLinkFacePtr aDMapLinkFace;
2685 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
2686 aDMapLinkFace, theNonManifold, theStartFace );
2688 bool isDone = false;
2689 while ( !isDone && aMapOfBoundary.size() != 0 )
2691 bool isToReset = false;
2692 ManifoldPart::TVectorOfLink::iterator pLink = aSeqOfBoundary.begin();
2693 for ( ; !isToReset && pLink != aSeqOfBoundary.end(); ++pLink )
2695 ManifoldPart::Link aLink = *pLink;
2696 if ( aMapToSkip.find( aLink ) != aMapToSkip.end() )
2698 // each link could be treated only once
2699 aMapToSkip.insert( aLink );
2701 ManifoldPart::TVectorOfFacePtr aFaces;
2703 if ( myIsOnlyManifold &&
2704 (theNonManifold.find( aLink ) != theNonManifold.end()) )
2708 getFacesByLink( aLink, aFaces );
2709 // filter the element to keep only indicated elements
2710 ManifoldPart::TVectorOfFacePtr aFiltered;
2711 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
2712 for ( ; pFace != aFaces.end(); ++pFace )
2714 SMDS_MeshFace* aFace = *pFace;
2715 if ( myAllFacePtrIntDMap.find( aFace ) != myAllFacePtrIntDMap.end() )
2716 aFiltered.push_back( aFace );
2719 if ( aFaces.size() < 2 ) // no neihgbour faces
2721 else if ( myIsOnlyManifold && aFaces.size() > 2 ) // non manifold case
2723 theNonManifold.insert( aLink );
2728 // compare normal with normals of neighbor element
2729 SMDS_MeshFace* aPrevFace = aDMapLinkFace[ aLink ];
2730 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
2731 for ( ; pFace != aFaces.end(); ++pFace )
2733 SMDS_MeshFace* aNextFace = *pFace;
2734 if ( aPrevFace == aNextFace )
2736 int anNextFaceID = aNextFace->GetID();
2737 if ( myIsOnlyManifold && theResFaces.Contains( anNextFaceID ) )
2738 // should not be with non manifold restriction. probably bad topology
2740 // check if face was treated and skipped
2741 if ( myMapBadGeomIds.Contains( anNextFaceID ) ||
2742 !isInPlane( aPrevFace, aNextFace ) )
2744 // add new element to connected and extend the boundaries.
2745 theResFaces.Add( anNextFaceID );
2746 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
2747 aDMapLinkFace, theNonManifold, aNextFace );
2751 isDone = !isToReset;
2754 return !theResFaces.IsEmpty();
2757 bool ManifoldPart::isInPlane( const SMDS_MeshFace* theFace1,
2758 const SMDS_MeshFace* theFace2 )
2760 gp_Dir aNorm1 = gp_Dir( getNormale( theFace1 ) );
2761 gp_XYZ aNorm2XYZ = getNormale( theFace2 );
2762 if ( aNorm2XYZ.SquareModulus() <= gp::Resolution() )
2764 myMapBadGeomIds.Add( theFace2->GetID() );
2767 if ( aNorm1.IsParallel( gp_Dir( aNorm2XYZ ), myAngToler ) )
2773 void ManifoldPart::expandBoundary
2774 ( ManifoldPart::TMapOfLink& theMapOfBoundary,
2775 ManifoldPart::TVectorOfLink& theSeqOfBoundary,
2776 ManifoldPart::TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
2777 ManifoldPart::TMapOfLink& theNonManifold,
2778 SMDS_MeshFace* theNextFace ) const
2780 ManifoldPart::TVectorOfLink aLinks;
2781 getLinks( theNextFace, aLinks );
2782 int aNbLink = (int)aLinks.size();
2783 for ( int i = 0; i < aNbLink; i++ )
2785 ManifoldPart::Link aLink = aLinks[ i ];
2786 if ( myIsOnlyManifold && (theNonManifold.find( aLink ) != theNonManifold.end()) )
2788 if ( theMapOfBoundary.find( aLink ) != theMapOfBoundary.end() )
2790 if ( myIsOnlyManifold )
2792 // remove from boundary
2793 theMapOfBoundary.erase( aLink );
2794 ManifoldPart::TVectorOfLink::iterator pLink = theSeqOfBoundary.begin();
2795 for ( ; pLink != theSeqOfBoundary.end(); ++pLink )
2797 ManifoldPart::Link aBoundLink = *pLink;
2798 if ( aBoundLink.IsEqual( aLink ) )
2800 theSeqOfBoundary.erase( pLink );
2808 theMapOfBoundary.insert( aLink );
2809 theSeqOfBoundary.push_back( aLink );
2810 theDMapLinkFacePtr[ aLink ] = theNextFace;
2815 void ManifoldPart::getFacesByLink( const ManifoldPart::Link& theLink,
2816 ManifoldPart::TVectorOfFacePtr& theFaces ) const
2818 SMDS_Mesh::SetOfFaces aSetOfFaces;
2819 // take all faces that shared first node
2820 SMDS_ElemIteratorPtr anItr = theLink.myNode1->facesIterator();
2821 for ( ; anItr->more(); )
2823 SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
2826 aSetOfFaces.Add( aFace );
2828 // take all faces that shared second node
2829 anItr = theLink.myNode2->facesIterator();
2830 // find the common part of two sets
2831 for ( ; anItr->more(); )
2833 SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
2834 if ( aSetOfFaces.Contains( aFace ) )
2835 theFaces.push_back( aFace );
2844 ElementsOnSurface::ElementsOnSurface()
2848 myType = SMDSAbs_All;
2850 myToler = Precision::Confusion();
2851 myUseBoundaries = false;
2854 ElementsOnSurface::~ElementsOnSurface()
2859 void ElementsOnSurface::SetMesh( const SMDS_Mesh* theMesh )
2861 if ( myMesh == theMesh )
2867 bool ElementsOnSurface::IsSatisfy( long theElementId )
2869 return myIds.Contains( theElementId );
2872 SMDSAbs_ElementType ElementsOnSurface::GetType() const
2875 void ElementsOnSurface::SetTolerance( const double theToler )
2877 if ( myToler != theToler )
2882 double ElementsOnSurface::GetTolerance() const
2885 void ElementsOnSurface::SetUseBoundaries( bool theUse )
2887 if ( myUseBoundaries != theUse ) {
2888 myUseBoundaries = theUse;
2889 SetSurface( mySurf, myType );
2893 void ElementsOnSurface::SetSurface( const TopoDS_Shape& theShape,
2894 const SMDSAbs_ElementType theType )
2899 if ( theShape.IsNull() || theShape.ShapeType() != TopAbs_FACE )
2901 mySurf = TopoDS::Face( theShape );
2902 BRepAdaptor_Surface SA( mySurf, myUseBoundaries );
2904 u1 = SA.FirstUParameter(),
2905 u2 = SA.LastUParameter(),
2906 v1 = SA.FirstVParameter(),
2907 v2 = SA.LastVParameter();
2908 Handle(Geom_Surface) surf = BRep_Tool::Surface( mySurf );
2909 myProjector.Init( surf, u1,u2, v1,v2 );
2913 void ElementsOnSurface::process()
2916 if ( mySurf.IsNull() )
2922 if ( myType == SMDSAbs_Face || myType == SMDSAbs_All )
2924 myIds.ReSize( myMesh->NbFaces() );
2925 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
2926 for(; anIter->more(); )
2927 process( anIter->next() );
2930 if ( myType == SMDSAbs_Edge || myType == SMDSAbs_All )
2932 myIds.ReSize( myIds.Extent() + myMesh->NbEdges() );
2933 SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
2934 for(; anIter->more(); )
2935 process( anIter->next() );
2938 if ( myType == SMDSAbs_Node )
2940 myIds.ReSize( myMesh->NbNodes() );
2941 SMDS_NodeIteratorPtr anIter = myMesh->nodesIterator();
2942 for(; anIter->more(); )
2943 process( anIter->next() );
2947 void ElementsOnSurface::process( const SMDS_MeshElement* theElemPtr )
2949 SMDS_ElemIteratorPtr aNodeItr = theElemPtr->nodesIterator();
2950 bool isSatisfy = true;
2951 for ( ; aNodeItr->more(); )
2953 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
2954 if ( !isOnSurface( aNode ) )
2961 myIds.Add( theElemPtr->GetID() );
2964 bool ElementsOnSurface::isOnSurface( const SMDS_MeshNode* theNode )
2966 if ( mySurf.IsNull() )
2969 gp_Pnt aPnt( theNode->X(), theNode->Y(), theNode->Z() );
2970 // double aToler2 = myToler * myToler;
2971 // if ( mySurf->IsKind(STANDARD_TYPE(Geom_Plane)))
2973 // gp_Pln aPln = Handle(Geom_Plane)::DownCast(mySurf)->Pln();
2974 // if ( aPln.SquareDistance( aPnt ) > aToler2 )
2977 // else if ( mySurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)))
2979 // gp_Cylinder aCyl = Handle(Geom_CylindricalSurface)::DownCast(mySurf)->Cylinder();
2980 // double aRad = aCyl.Radius();
2981 // gp_Ax3 anAxis = aCyl.Position();
2982 // gp_XYZ aLoc = aCyl.Location().XYZ();
2983 // double aXDist = anAxis.XDirection().XYZ() * ( aPnt.XYZ() - aLoc );
2984 // double aYDist = anAxis.YDirection().XYZ() * ( aPnt.XYZ() - aLoc );
2985 // if ( fabs(aXDist*aXDist + aYDist*aYDist - aRad*aRad) > aToler2 )
2990 myProjector.Perform( aPnt );
2991 bool isOn = ( myProjector.IsDone() && myProjector.LowerDistance() <= myToler );
3001 ElementsOnShape::ElementsOnShape()
3003 myType(SMDSAbs_All),
3004 myToler(Precision::Confusion()),
3005 myAllNodesFlag(false)
3007 myCurShapeType = TopAbs_SHAPE;
3010 ElementsOnShape::~ElementsOnShape()
3014 void ElementsOnShape::SetMesh (const SMDS_Mesh* theMesh)
3016 if (myMesh != theMesh) {
3018 SetShape(myShape, myType);
3022 bool ElementsOnShape::IsSatisfy (long theElementId)
3024 return myIds.Contains(theElementId);
3027 SMDSAbs_ElementType ElementsOnShape::GetType() const
3032 void ElementsOnShape::SetTolerance (const double theToler)
3034 if (myToler != theToler) {
3036 SetShape(myShape, myType);
3040 double ElementsOnShape::GetTolerance() const
3045 void ElementsOnShape::SetAllNodes (bool theAllNodes)
3047 if (myAllNodesFlag != theAllNodes) {
3048 myAllNodesFlag = theAllNodes;
3049 SetShape(myShape, myType);
3053 void ElementsOnShape::SetShape (const TopoDS_Shape& theShape,
3054 const SMDSAbs_ElementType theType)
3060 if (myMesh == 0) return;
3065 myIds.ReSize(myMesh->NbEdges() + myMesh->NbFaces() + myMesh->NbVolumes());
3068 myIds.ReSize(myMesh->NbNodes());
3071 myIds.ReSize(myMesh->NbEdges());
3074 myIds.ReSize(myMesh->NbFaces());
3076 case SMDSAbs_Volume:
3077 myIds.ReSize(myMesh->NbVolumes());
3083 myShapesMap.Clear();
3087 void ElementsOnShape::addShape (const TopoDS_Shape& theShape)
3089 if (theShape.IsNull() || myMesh == 0)
3092 if (!myShapesMap.Add(theShape)) return;
3094 myCurShapeType = theShape.ShapeType();
3095 switch (myCurShapeType)
3097 case TopAbs_COMPOUND:
3098 case TopAbs_COMPSOLID:
3102 TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
3103 for (; anIt.More(); anIt.Next()) addShape(anIt.Value());
3108 myCurSC.Load(theShape);
3114 TopoDS_Face aFace = TopoDS::Face(theShape);
3115 BRepAdaptor_Surface SA (aFace, true);
3117 u1 = SA.FirstUParameter(),
3118 u2 = SA.LastUParameter(),
3119 v1 = SA.FirstVParameter(),
3120 v2 = SA.LastVParameter();
3121 Handle(Geom_Surface) surf = BRep_Tool::Surface(aFace);
3122 myCurProjFace.Init(surf, u1,u2, v1,v2);
3129 TopoDS_Edge anEdge = TopoDS::Edge(theShape);
3130 Standard_Real u1, u2;
3131 Handle(Geom_Curve) curve = BRep_Tool::Curve(anEdge, u1, u2);
3132 myCurProjEdge.Init(curve, u1, u2);
3138 TopoDS_Vertex aV = TopoDS::Vertex(theShape);
3139 myCurPnt = BRep_Tool::Pnt(aV);
3148 void ElementsOnShape::process()
3150 if (myShape.IsNull() || myMesh == 0)
3153 if (myType == SMDSAbs_Node)
3155 SMDS_NodeIteratorPtr anIter = myMesh->nodesIterator();
3156 while (anIter->more())
3157 process(anIter->next());
3161 if (myType == SMDSAbs_Edge || myType == SMDSAbs_All)
3163 SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
3164 while (anIter->more())
3165 process(anIter->next());
3168 if (myType == SMDSAbs_Face || myType == SMDSAbs_All)
3170 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
3171 while (anIter->more()) {
3172 process(anIter->next());
3176 if (myType == SMDSAbs_Volume || myType == SMDSAbs_All)
3178 SMDS_VolumeIteratorPtr anIter = myMesh->volumesIterator();
3179 while (anIter->more())
3180 process(anIter->next());
3185 void ElementsOnShape::process (const SMDS_MeshElement* theElemPtr)
3187 if (myShape.IsNull())
3190 SMDS_ElemIteratorPtr aNodeItr = theElemPtr->nodesIterator();
3191 bool isSatisfy = myAllNodesFlag;
3193 gp_XYZ centerXYZ (0, 0, 0);
3195 while (aNodeItr->more() && (isSatisfy == myAllNodesFlag))
3197 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
3198 gp_Pnt aPnt (aNode->X(), aNode->Y(), aNode->Z());
3199 centerXYZ += aPnt.XYZ();
3201 switch (myCurShapeType)
3205 myCurSC.Perform(aPnt, myToler);
3206 isSatisfy = (myCurSC.State() == TopAbs_IN || myCurSC.State() == TopAbs_ON);
3211 myCurProjFace.Perform(aPnt);
3212 isSatisfy = (myCurProjFace.IsDone() && myCurProjFace.LowerDistance() <= myToler);
3215 // check relatively the face
3216 Quantity_Parameter u, v;
3217 myCurProjFace.LowerDistanceParameters(u, v);
3218 gp_Pnt2d aProjPnt (u, v);
3219 BRepClass_FaceClassifier aClsf (myCurFace, aProjPnt, myToler);
3220 isSatisfy = (aClsf.State() == TopAbs_IN || aClsf.State() == TopAbs_ON);
3226 myCurProjEdge.Perform(aPnt);
3227 isSatisfy = (myCurProjEdge.NbPoints() > 0 && myCurProjEdge.LowerDistance() <= myToler);
3232 isSatisfy = (aPnt.Distance(myCurPnt) <= myToler);
3242 if (isSatisfy && myCurShapeType == TopAbs_SOLID) { // Check the center point for volumes MantisBug 0020168
3243 centerXYZ /= theElemPtr->NbNodes();
3244 gp_Pnt aCenterPnt (centerXYZ);
3245 myCurSC.Perform(aCenterPnt, myToler);
3246 if ( !(myCurSC.State() == TopAbs_IN || myCurSC.State() == TopAbs_ON))
3251 myIds.Add(theElemPtr->GetID());
3254 TSequenceOfXYZ::TSequenceOfXYZ()
3257 TSequenceOfXYZ::TSequenceOfXYZ(size_type n) : myArray(n)
3260 TSequenceOfXYZ::TSequenceOfXYZ(size_type n, const gp_XYZ& t) : myArray(n,t)
3263 TSequenceOfXYZ::TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ) : myArray(theSequenceOfXYZ.myArray)
3266 template <class InputIterator>
3267 TSequenceOfXYZ::TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd): myArray(theBegin,theEnd)
3270 TSequenceOfXYZ::~TSequenceOfXYZ()
3273 TSequenceOfXYZ& TSequenceOfXYZ::operator=(const TSequenceOfXYZ& theSequenceOfXYZ)
3275 myArray = theSequenceOfXYZ.myArray;
3279 gp_XYZ& TSequenceOfXYZ::operator()(size_type n)
3281 return myArray[n-1];
3284 const gp_XYZ& TSequenceOfXYZ::operator()(size_type n) const
3286 return myArray[n-1];
3289 void TSequenceOfXYZ::clear()
3294 void TSequenceOfXYZ::reserve(size_type n)
3299 void TSequenceOfXYZ::push_back(const gp_XYZ& v)
3301 myArray.push_back(v);
3304 TSequenceOfXYZ::size_type TSequenceOfXYZ::size() const
3306 return myArray.size();