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
286 * \param elements - elements to check vulue of; empty list means "of all"
288 //================================================================================
290 void NumericalFunctor::GetHistogram(int nbIntervals,
291 std::vector<int>& nbEvents,
292 std::vector<double>& funValues,
293 const vector<int>& elements)
295 if ( nbIntervals < 1 ||
297 !myMesh->GetMeshInfo().NbElements( GetType() ))
299 nbEvents.resize( nbIntervals, 0 );
300 funValues.resize( nbIntervals+1 );
302 // get all values sorted
303 std::multiset< double > values;
304 if ( elements.empty() )
306 SMDS_ElemIteratorPtr elemIt = myMesh->elementsIterator(GetType());
307 while ( elemIt->more() )
308 values.insert( GetValue( elemIt->next()->GetID() ));
312 vector<int>::const_iterator id = elements.begin();
313 for ( ; id != elements.end(); ++id )
314 values.insert( GetValue( *id ));
317 // case nbIntervals == 1
318 funValues[0] = *values.begin();
319 funValues[nbIntervals] = *values.rbegin();
320 if ( nbIntervals == 1 )
322 nbEvents[0] = values.size();
326 if (funValues.front() == funValues.back())
328 nbEvents.resize( 1 );
329 nbEvents[0] = values.size();
330 funValues[1] = funValues.back();
331 funValues.resize( 2 );
334 std::multiset< double >::iterator min = values.begin(), max;
335 for ( int i = 0; i < nbIntervals; ++i )
337 double r = (i+1) / double( nbIntervals );
338 funValues[i+1] = funValues.front() * (1-r) + funValues.back() * r;
339 if ( min != values.end() && *min <= funValues[i+1] )
341 max = values.upper_bound( funValues[i+1] ); // greater than funValues[i+1], or end()
342 nbEvents[i] = std::distance( min, max );
348 //=======================================================================
349 //function : GetValue
351 //=======================================================================
353 double Volume::GetValue( long theElementId )
355 if ( theElementId && myMesh ) {
356 SMDS_VolumeTool aVolumeTool;
357 if ( aVolumeTool.Set( myMesh->FindElement( theElementId )))
358 return aVolumeTool.GetSize();
363 //=======================================================================
364 //function : GetBadRate
365 //purpose : meaningless as it is not quality control functor
366 //=======================================================================
368 double Volume::GetBadRate( double Value, int /*nbNodes*/ ) const
373 //=======================================================================
376 //=======================================================================
378 SMDSAbs_ElementType Volume::GetType() const
380 return SMDSAbs_Volume;
385 Class : MaxElementLength2D
386 Description : Functor calculating maximum length of 2D element
389 double MaxElementLength2D::GetValue( long theElementId )
392 if( GetPoints( theElementId, P ) ) {
394 const SMDS_MeshElement* aElem = myMesh->FindElement( theElementId );
395 SMDSAbs_ElementType aType = aElem->GetType();
399 if( len == 3 ) { // triangles
400 double L1 = getDistance(P( 1 ),P( 2 ));
401 double L2 = getDistance(P( 2 ),P( 3 ));
402 double L3 = getDistance(P( 3 ),P( 1 ));
403 aVal = Max(L1,Max(L2,L3));
406 else if( len == 4 ) { // quadrangles
407 double L1 = getDistance(P( 1 ),P( 2 ));
408 double L2 = getDistance(P( 2 ),P( 3 ));
409 double L3 = getDistance(P( 3 ),P( 4 ));
410 double L4 = getDistance(P( 4 ),P( 1 ));
411 double D1 = getDistance(P( 1 ),P( 3 ));
412 double D2 = getDistance(P( 2 ),P( 4 ));
413 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(D1,D2));
416 else if( len == 6 ) { // quadratic triangles
417 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
418 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
419 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 1 ));
420 aVal = Max(L1,Max(L2,L3));
423 else if( len == 8 ) { // quadratic quadrangles
424 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
425 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
426 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 7 ));
427 double L4 = getDistance(P( 7 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
428 double D1 = getDistance(P( 1 ),P( 5 ));
429 double D2 = getDistance(P( 3 ),P( 7 ));
430 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(D1,D2));
435 if( myPrecision >= 0 )
437 double prec = pow( 10., (double)myPrecision );
438 aVal = floor( aVal * prec + 0.5 ) / prec;
445 double MaxElementLength2D::GetBadRate( double Value, int /*nbNodes*/ ) const
450 SMDSAbs_ElementType MaxElementLength2D::GetType() const
456 Class : MaxElementLength3D
457 Description : Functor calculating maximum length of 3D element
460 double MaxElementLength3D::GetValue( long theElementId )
463 if( GetPoints( theElementId, P ) ) {
465 const SMDS_MeshElement* aElem = myMesh->FindElement( theElementId );
466 SMDSAbs_ElementType aType = aElem->GetType();
470 if( len == 4 ) { // tetras
471 double L1 = getDistance(P( 1 ),P( 2 ));
472 double L2 = getDistance(P( 2 ),P( 3 ));
473 double L3 = getDistance(P( 3 ),P( 1 ));
474 double L4 = getDistance(P( 1 ),P( 4 ));
475 double L5 = getDistance(P( 2 ),P( 4 ));
476 double L6 = getDistance(P( 3 ),P( 4 ));
477 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
480 else if( len == 5 ) { // pyramids
481 double L1 = getDistance(P( 1 ),P( 2 ));
482 double L2 = getDistance(P( 2 ),P( 3 ));
483 double L3 = getDistance(P( 3 ),P( 4 ));
484 double L4 = getDistance(P( 4 ),P( 1 ));
485 double L5 = getDistance(P( 1 ),P( 5 ));
486 double L6 = getDistance(P( 2 ),P( 5 ));
487 double L7 = getDistance(P( 3 ),P( 5 ));
488 double L8 = getDistance(P( 4 ),P( 5 ));
489 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
490 aVal = Max(aVal,Max(L7,L8));
493 else if( len == 6 ) { // pentas
494 double L1 = getDistance(P( 1 ),P( 2 ));
495 double L2 = getDistance(P( 2 ),P( 3 ));
496 double L3 = getDistance(P( 3 ),P( 1 ));
497 double L4 = getDistance(P( 4 ),P( 5 ));
498 double L5 = getDistance(P( 5 ),P( 6 ));
499 double L6 = getDistance(P( 6 ),P( 4 ));
500 double L7 = getDistance(P( 1 ),P( 4 ));
501 double L8 = getDistance(P( 2 ),P( 5 ));
502 double L9 = getDistance(P( 3 ),P( 6 ));
503 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
504 aVal = Max(aVal,Max(Max(L7,L8),L9));
507 else if( len == 8 ) { // hexas
508 double L1 = getDistance(P( 1 ),P( 2 ));
509 double L2 = getDistance(P( 2 ),P( 3 ));
510 double L3 = getDistance(P( 3 ),P( 4 ));
511 double L4 = getDistance(P( 4 ),P( 1 ));
512 double L5 = getDistance(P( 5 ),P( 6 ));
513 double L6 = getDistance(P( 6 ),P( 7 ));
514 double L7 = getDistance(P( 7 ),P( 8 ));
515 double L8 = getDistance(P( 8 ),P( 5 ));
516 double L9 = getDistance(P( 1 ),P( 5 ));
517 double L10= getDistance(P( 2 ),P( 6 ));
518 double L11= getDistance(P( 3 ),P( 7 ));
519 double L12= getDistance(P( 4 ),P( 8 ));
520 double D1 = getDistance(P( 1 ),P( 7 ));
521 double D2 = getDistance(P( 2 ),P( 8 ));
522 double D3 = getDistance(P( 3 ),P( 5 ));
523 double D4 = getDistance(P( 4 ),P( 6 ));
524 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
525 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
526 aVal = Max(aVal,Max(L11,L12));
527 aVal = Max(aVal,Max(Max(D1,D2),Max(D3,D4)));
530 else if( len == 10 ) { // quadratic tetras
531 double L1 = getDistance(P( 1 ),P( 5 )) + getDistance(P( 5 ),P( 2 ));
532 double L2 = getDistance(P( 2 ),P( 6 )) + getDistance(P( 6 ),P( 3 ));
533 double L3 = getDistance(P( 3 ),P( 7 )) + getDistance(P( 7 ),P( 1 ));
534 double L4 = getDistance(P( 1 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
535 double L5 = getDistance(P( 2 ),P( 9 )) + getDistance(P( 9 ),P( 4 ));
536 double L6 = getDistance(P( 3 ),P( 10 )) + getDistance(P( 10 ),P( 4 ));
537 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
540 else if( len == 13 ) { // quadratic pyramids
541 double L1 = getDistance(P( 1 ),P( 6 )) + getDistance(P( 6 ),P( 2 ));
542 double L2 = getDistance(P( 2 ),P( 7 )) + getDistance(P( 7 ),P( 3 ));
543 double L3 = getDistance(P( 3 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
544 double L4 = getDistance(P( 4 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
545 double L5 = getDistance(P( 1 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
546 double L6 = getDistance(P( 2 ),P( 11 )) + getDistance(P( 11 ),P( 5 ));
547 double L7 = getDistance(P( 3 ),P( 12 )) + getDistance(P( 12 ),P( 5 ));
548 double L8 = getDistance(P( 4 ),P( 13 )) + getDistance(P( 13 ),P( 5 ));
549 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
550 aVal = Max(aVal,Max(L7,L8));
553 else if( len == 15 ) { // quadratic pentas
554 double L1 = getDistance(P( 1 ),P( 7 )) + getDistance(P( 7 ),P( 2 ));
555 double L2 = getDistance(P( 2 ),P( 8 )) + getDistance(P( 8 ),P( 3 ));
556 double L3 = getDistance(P( 3 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
557 double L4 = getDistance(P( 4 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
558 double L5 = getDistance(P( 5 ),P( 11 )) + getDistance(P( 11 ),P( 6 ));
559 double L6 = getDistance(P( 6 ),P( 12 )) + getDistance(P( 12 ),P( 4 ));
560 double L7 = getDistance(P( 1 ),P( 13 )) + getDistance(P( 13 ),P( 4 ));
561 double L8 = getDistance(P( 2 ),P( 14 )) + getDistance(P( 14 ),P( 5 ));
562 double L9 = getDistance(P( 3 ),P( 15 )) + getDistance(P( 15 ),P( 6 ));
563 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
564 aVal = Max(aVal,Max(Max(L7,L8),L9));
567 else if( len == 20 ) { // quadratic hexas
568 double L1 = getDistance(P( 1 ),P( 9 )) + getDistance(P( 9 ),P( 2 ));
569 double L2 = getDistance(P( 2 ),P( 10 )) + getDistance(P( 10 ),P( 3 ));
570 double L3 = getDistance(P( 3 ),P( 11 )) + getDistance(P( 11 ),P( 4 ));
571 double L4 = getDistance(P( 4 ),P( 12 )) + getDistance(P( 12 ),P( 1 ));
572 double L5 = getDistance(P( 5 ),P( 13 )) + getDistance(P( 13 ),P( 6 ));
573 double L6 = getDistance(P( 6 ),P( 14 )) + getDistance(P( 14 ),P( 7 ));
574 double L7 = getDistance(P( 7 ),P( 15 )) + getDistance(P( 15 ),P( 8 ));
575 double L8 = getDistance(P( 8 ),P( 16 )) + getDistance(P( 16 ),P( 5 ));
576 double L9 = getDistance(P( 1 ),P( 17 )) + getDistance(P( 17 ),P( 5 ));
577 double L10= getDistance(P( 2 ),P( 18 )) + getDistance(P( 18 ),P( 6 ));
578 double L11= getDistance(P( 3 ),P( 19 )) + getDistance(P( 19 ),P( 7 ));
579 double L12= getDistance(P( 4 ),P( 20 )) + getDistance(P( 20 ),P( 8 ));
580 double D1 = getDistance(P( 1 ),P( 7 ));
581 double D2 = getDistance(P( 2 ),P( 8 ));
582 double D3 = getDistance(P( 3 ),P( 5 ));
583 double D4 = getDistance(P( 4 ),P( 6 ));
584 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
585 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
586 aVal = Max(aVal,Max(L11,L12));
587 aVal = Max(aVal,Max(Max(D1,D2),Max(D3,D4)));
590 else if( len > 1 && aElem->IsPoly() ) { // polys
591 // get the maximum distance between all pairs of nodes
592 for( int i = 1; i <= len; i++ ) {
593 for( int j = 1; j <= len; j++ ) {
594 if( j > i ) { // optimization of the loop
595 double D = getDistance( P(i), P(j) );
596 aVal = Max( aVal, D );
603 if( myPrecision >= 0 )
605 double prec = pow( 10., (double)myPrecision );
606 aVal = floor( aVal * prec + 0.5 ) / prec;
613 double MaxElementLength3D::GetBadRate( double Value, int /*nbNodes*/ ) const
618 SMDSAbs_ElementType MaxElementLength3D::GetType() const
620 return SMDSAbs_Volume;
626 Description : Functor for calculation of minimum angle
629 double MinimumAngle::GetValue( const TSequenceOfXYZ& P )
636 aMin = getAngle(P( P.size() ), P( 1 ), P( 2 ));
637 aMin = Min(aMin,getAngle(P( P.size()-1 ), P( P.size() ), P( 1 )));
639 for (int i=2; i<P.size();i++){
640 double A0 = getAngle( P( i-1 ), P( i ), P( i+1 ) );
644 return aMin * 180.0 / PI;
647 double MinimumAngle::GetBadRate( double Value, int nbNodes ) const
649 //const double aBestAngle = PI / nbNodes;
650 const double aBestAngle = 180.0 - ( 360.0 / double(nbNodes) );
651 return ( fabs( aBestAngle - Value ));
654 SMDSAbs_ElementType MinimumAngle::GetType() const
662 Description : Functor for calculating aspect ratio
664 double AspectRatio::GetValue( const TSequenceOfXYZ& P )
666 // According to "Mesh quality control" by Nadir Bouhamau referring to
667 // Pascal Jean Frey and Paul-Louis George. Maillages, applications aux elements finis.
668 // Hermes Science publications, Paris 1999 ISBN 2-7462-0024-4
671 int nbNodes = P.size();
676 // Compute aspect ratio
678 if ( nbNodes == 3 ) {
679 // Compute lengths of the sides
680 std::vector< double > aLen (nbNodes);
681 for ( int i = 0; i < nbNodes - 1; i++ )
682 aLen[ i ] = getDistance( P( i + 1 ), P( i + 2 ) );
683 aLen[ nbNodes - 1 ] = getDistance( P( 1 ), P( nbNodes ) );
684 // Q = alfa * h * p / S, where
686 // alfa = sqrt( 3 ) / 6
687 // h - length of the longest edge
688 // p - half perimeter
689 // S - triangle surface
690 const double alfa = sqrt( 3. ) / 6.;
691 double maxLen = Max( aLen[ 0 ], Max( aLen[ 1 ], aLen[ 2 ] ) );
692 double half_perimeter = ( aLen[0] + aLen[1] + aLen[2] ) / 2.;
693 double anArea = getArea( P( 1 ), P( 2 ), P( 3 ) );
694 if ( anArea <= Precision::Confusion() )
696 return alfa * maxLen * half_perimeter / anArea;
698 else if ( nbNodes == 6 ) { // quadratic triangles
699 // Compute lengths of the sides
700 std::vector< double > aLen (3);
701 aLen[0] = getDistance( P(1), P(3) );
702 aLen[1] = getDistance( P(3), P(5) );
703 aLen[2] = getDistance( P(5), P(1) );
704 // Q = alfa * h * p / S, where
706 // alfa = sqrt( 3 ) / 6
707 // h - length of the longest edge
708 // p - half perimeter
709 // S - triangle surface
710 const double alfa = sqrt( 3. ) / 6.;
711 double maxLen = Max( aLen[ 0 ], Max( aLen[ 1 ], aLen[ 2 ] ) );
712 double half_perimeter = ( aLen[0] + aLen[1] + aLen[2] ) / 2.;
713 double anArea = getArea( P(1), P(3), P(5) );
714 if ( anArea <= Precision::Confusion() )
716 return alfa * maxLen * half_perimeter / anArea;
718 else if( nbNodes == 4 ) { // quadrangle
719 // Compute lengths of the sides
720 std::vector< double > aLen (4);
721 aLen[0] = getDistance( P(1), P(2) );
722 aLen[1] = getDistance( P(2), P(3) );
723 aLen[2] = getDistance( P(3), P(4) );
724 aLen[3] = getDistance( P(4), P(1) );
725 // Compute lengths of the diagonals
726 std::vector< double > aDia (2);
727 aDia[0] = getDistance( P(1), P(3) );
728 aDia[1] = getDistance( P(2), P(4) );
729 // Compute areas of all triangles which can be built
730 // taking three nodes of the quadrangle
731 std::vector< double > anArea (4);
732 anArea[0] = getArea( P(1), P(2), P(3) );
733 anArea[1] = getArea( P(1), P(2), P(4) );
734 anArea[2] = getArea( P(1), P(3), P(4) );
735 anArea[3] = getArea( P(2), P(3), P(4) );
736 // Q = alpha * L * C1 / C2, where
738 // alpha = sqrt( 1/32 )
739 // L = max( L1, L2, L3, L4, D1, D2 )
740 // C1 = sqrt( ( L1^2 + L1^2 + L1^2 + L1^2 ) / 4 )
741 // C2 = min( S1, S2, S3, S4 )
742 // Li - lengths of the edges
743 // Di - lengths of the diagonals
744 // Si - areas of the triangles
745 const double alpha = sqrt( 1 / 32. );
746 double L = Max( aLen[ 0 ],
750 Max( aDia[ 0 ], aDia[ 1 ] ) ) ) ) );
751 double C1 = sqrt( ( aLen[0] * aLen[0] +
754 aLen[3] * aLen[3] ) / 4. );
755 double C2 = Min( anArea[ 0 ],
757 Min( anArea[ 2 ], anArea[ 3 ] ) ) );
758 if ( C2 <= Precision::Confusion() )
760 return alpha * L * C1 / C2;
762 else if( nbNodes == 8 ){ // nbNodes==8 - quadratic quadrangle
763 // Compute lengths of the sides
764 std::vector< double > aLen (4);
765 aLen[0] = getDistance( P(1), P(3) );
766 aLen[1] = getDistance( P(3), P(5) );
767 aLen[2] = getDistance( P(5), P(7) );
768 aLen[3] = getDistance( P(7), P(1) );
769 // Compute lengths of the diagonals
770 std::vector< double > aDia (2);
771 aDia[0] = getDistance( P(1), P(5) );
772 aDia[1] = getDistance( P(3), P(7) );
773 // Compute areas of all triangles which can be built
774 // taking three nodes of the quadrangle
775 std::vector< double > anArea (4);
776 anArea[0] = getArea( P(1), P(3), P(5) );
777 anArea[1] = getArea( P(1), P(3), P(7) );
778 anArea[2] = getArea( P(1), P(5), P(7) );
779 anArea[3] = getArea( P(3), P(5), P(7) );
780 // Q = alpha * L * C1 / C2, where
782 // alpha = sqrt( 1/32 )
783 // L = max( L1, L2, L3, L4, D1, D2 )
784 // C1 = sqrt( ( L1^2 + L1^2 + L1^2 + L1^2 ) / 4 )
785 // C2 = min( S1, S2, S3, S4 )
786 // Li - lengths of the edges
787 // Di - lengths of the diagonals
788 // Si - areas of the triangles
789 const double alpha = sqrt( 1 / 32. );
790 double L = Max( aLen[ 0 ],
794 Max( aDia[ 0 ], aDia[ 1 ] ) ) ) ) );
795 double C1 = sqrt( ( aLen[0] * aLen[0] +
798 aLen[3] * aLen[3] ) / 4. );
799 double C2 = Min( anArea[ 0 ],
801 Min( anArea[ 2 ], anArea[ 3 ] ) ) );
802 if ( C2 <= Precision::Confusion() )
804 return alpha * L * C1 / C2;
809 double AspectRatio::GetBadRate( double Value, int /*nbNodes*/ ) const
811 // the aspect ratio is in the range [1.0,infinity]
814 return Value / 1000.;
817 SMDSAbs_ElementType AspectRatio::GetType() const
824 Class : AspectRatio3D
825 Description : Functor for calculating aspect ratio
829 inline double getHalfPerimeter(double theTria[3]){
830 return (theTria[0] + theTria[1] + theTria[2])/2.0;
833 inline double getArea(double theHalfPerim, double theTria[3]){
834 return sqrt(theHalfPerim*
835 (theHalfPerim-theTria[0])*
836 (theHalfPerim-theTria[1])*
837 (theHalfPerim-theTria[2]));
840 inline double getVolume(double theLen[6]){
841 double a2 = theLen[0]*theLen[0];
842 double b2 = theLen[1]*theLen[1];
843 double c2 = theLen[2]*theLen[2];
844 double d2 = theLen[3]*theLen[3];
845 double e2 = theLen[4]*theLen[4];
846 double f2 = theLen[5]*theLen[5];
847 double P = 4.0*a2*b2*d2;
848 double Q = a2*(b2+d2-e2)-b2*(a2+d2-f2)-d2*(a2+b2-c2);
849 double R = (b2+d2-e2)*(a2+d2-f2)*(a2+d2-f2);
850 return sqrt(P-Q+R)/12.0;
853 inline double getVolume2(double theLen[6]){
854 double a2 = theLen[0]*theLen[0];
855 double b2 = theLen[1]*theLen[1];
856 double c2 = theLen[2]*theLen[2];
857 double d2 = theLen[3]*theLen[3];
858 double e2 = theLen[4]*theLen[4];
859 double f2 = theLen[5]*theLen[5];
861 double P = a2*e2*(b2+c2+d2+f2-a2-e2);
862 double Q = b2*f2*(a2+c2+d2+e2-b2-f2);
863 double R = c2*d2*(a2+b2+e2+f2-c2-d2);
864 double S = a2*b2*d2+b2*c2*e2+a2*c2*f2+d2*e2*f2;
866 return sqrt(P+Q+R-S)/12.0;
869 inline double getVolume(const TSequenceOfXYZ& P){
870 gp_Vec aVec1( P( 2 ) - P( 1 ) );
871 gp_Vec aVec2( P( 3 ) - P( 1 ) );
872 gp_Vec aVec3( P( 4 ) - P( 1 ) );
873 gp_Vec anAreaVec( aVec1 ^ aVec2 );
874 return fabs(aVec3 * anAreaVec) / 6.0;
877 inline double getMaxHeight(double theLen[6])
879 double aHeight = std::max(theLen[0],theLen[1]);
880 aHeight = std::max(aHeight,theLen[2]);
881 aHeight = std::max(aHeight,theLen[3]);
882 aHeight = std::max(aHeight,theLen[4]);
883 aHeight = std::max(aHeight,theLen[5]);
889 double AspectRatio3D::GetValue( const TSequenceOfXYZ& P )
891 double aQuality = 0.0;
892 if(myCurrElement->IsPoly()) return aQuality;
894 int nbNodes = P.size();
896 if(myCurrElement->IsQuadratic()) {
897 if(nbNodes==10) nbNodes=4; // quadratic tetrahedron
898 else if(nbNodes==13) nbNodes=5; // quadratic pyramid
899 else if(nbNodes==15) nbNodes=6; // quadratic pentahedron
900 else if(nbNodes==20) nbNodes=8; // quadratic hexahedron
901 else return aQuality;
907 getDistance(P( 1 ),P( 2 )), // a
908 getDistance(P( 2 ),P( 3 )), // b
909 getDistance(P( 3 ),P( 1 )), // c
910 getDistance(P( 2 ),P( 4 )), // d
911 getDistance(P( 3 ),P( 4 )), // e
912 getDistance(P( 1 ),P( 4 )) // f
914 double aTria[4][3] = {
915 {aLen[0],aLen[1],aLen[2]}, // abc
916 {aLen[0],aLen[3],aLen[5]}, // adf
917 {aLen[1],aLen[3],aLen[4]}, // bde
918 {aLen[2],aLen[4],aLen[5]} // cef
920 double aSumArea = 0.0;
921 double aHalfPerimeter = getHalfPerimeter(aTria[0]);
922 double anArea = getArea(aHalfPerimeter,aTria[0]);
924 aHalfPerimeter = getHalfPerimeter(aTria[1]);
925 anArea = getArea(aHalfPerimeter,aTria[1]);
927 aHalfPerimeter = getHalfPerimeter(aTria[2]);
928 anArea = getArea(aHalfPerimeter,aTria[2]);
930 aHalfPerimeter = getHalfPerimeter(aTria[3]);
931 anArea = getArea(aHalfPerimeter,aTria[3]);
933 double aVolume = getVolume(P);
934 //double aVolume = getVolume(aLen);
935 double aHeight = getMaxHeight(aLen);
936 static double aCoeff = sqrt(2.0)/12.0;
937 if ( aVolume > DBL_MIN )
938 aQuality = aCoeff*aHeight*aSumArea/aVolume;
943 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 3 ),P( 5 )};
944 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
947 gp_XYZ aXYZ[4] = {P( 1 ),P( 3 ),P( 4 ),P( 5 )};
948 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
951 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 5 )};
952 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
955 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 4 ),P( 5 )};
956 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
962 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 6 )};
963 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
966 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 3 )};
967 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
970 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 6 )};
971 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
974 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
975 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
978 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 6 )};
979 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
982 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 3 )};
983 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
989 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
990 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
993 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 4 )};
994 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
997 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 7 )};
998 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1001 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 8 )};
1002 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1005 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 3 )};
1006 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1009 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 4 )};
1010 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1013 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 7 )};
1014 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1017 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 8 )};
1018 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1021 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 3 )};
1022 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1025 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 4 )};
1026 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1029 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 7 )};
1030 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1033 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 8 )};
1034 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1037 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 1 )};
1038 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1041 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 2 )};
1042 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1045 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 5 )};
1046 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1049 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 6 )};
1050 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1053 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 1 )};
1054 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1057 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 2 )};
1058 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1061 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 5 )};
1062 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1065 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 6 )};
1066 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1069 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 1 )};
1070 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1073 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
1074 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1077 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 5 )};
1078 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1081 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 6 )};
1082 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1085 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
1086 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1089 gp_XYZ aXYZ[4] = {P( 4 ),P( 5 ),P( 8 ),P( 2 )};
1090 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1093 gp_XYZ aXYZ[4] = {P( 1 ),P( 4 ),P( 5 ),P( 3 )};
1094 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1097 gp_XYZ aXYZ[4] = {P( 3 ),P( 6 ),P( 7 ),P( 1 )};
1098 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1101 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 6 ),P( 4 )};
1102 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1105 gp_XYZ aXYZ[4] = {P( 5 ),P( 6 ),P( 8 ),P( 3 )};
1106 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1109 gp_XYZ aXYZ[4] = {P( 7 ),P( 8 ),P( 6 ),P( 1 )};
1110 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1113 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 7 )};
1114 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1117 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 2 ),P( 5 )};
1118 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1123 if ( nbNodes > 4 ) {
1124 // avaluate aspect ratio of quadranle faces
1125 AspectRatio aspect2D;
1126 SMDS_VolumeTool::VolumeType type = SMDS_VolumeTool::GetType( nbNodes );
1127 int nbFaces = SMDS_VolumeTool::NbFaces( type );
1128 TSequenceOfXYZ points(4);
1129 for ( int i = 0; i < nbFaces; ++i ) { // loop on faces of a volume
1130 if ( SMDS_VolumeTool::NbFaceNodes( type, i ) != 4 )
1132 const int* pInd = SMDS_VolumeTool::GetFaceNodesIndices( type, i, true );
1133 for ( int p = 0; p < 4; ++p ) // loop on nodes of a quadranle face
1134 points( p + 1 ) = P( pInd[ p ] + 1 );
1135 aQuality = std::max( aQuality, aspect2D.GetValue( points ));
1141 double AspectRatio3D::GetBadRate( double Value, int /*nbNodes*/ ) const
1143 // the aspect ratio is in the range [1.0,infinity]
1146 return Value / 1000.;
1149 SMDSAbs_ElementType AspectRatio3D::GetType() const
1151 return SMDSAbs_Volume;
1157 Description : Functor for calculating warping
1159 double Warping::GetValue( const TSequenceOfXYZ& P )
1161 if ( P.size() != 4 )
1164 gp_XYZ G = ( P( 1 ) + P( 2 ) + P( 3 ) + P( 4 ) ) / 4.;
1166 double A1 = ComputeA( P( 1 ), P( 2 ), P( 3 ), G );
1167 double A2 = ComputeA( P( 2 ), P( 3 ), P( 4 ), G );
1168 double A3 = ComputeA( P( 3 ), P( 4 ), P( 1 ), G );
1169 double A4 = ComputeA( P( 4 ), P( 1 ), P( 2 ), G );
1171 return Max( Max( A1, A2 ), Max( A3, A4 ) );
1174 double Warping::ComputeA( const gp_XYZ& thePnt1,
1175 const gp_XYZ& thePnt2,
1176 const gp_XYZ& thePnt3,
1177 const gp_XYZ& theG ) const
1179 double aLen1 = gp_Pnt( thePnt1 ).Distance( gp_Pnt( thePnt2 ) );
1180 double aLen2 = gp_Pnt( thePnt2 ).Distance( gp_Pnt( thePnt3 ) );
1181 double L = Min( aLen1, aLen2 ) * 0.5;
1182 if ( L < Precision::Confusion())
1185 gp_XYZ GI = ( thePnt2 + thePnt1 ) / 2. - theG;
1186 gp_XYZ GJ = ( thePnt3 + thePnt2 ) / 2. - theG;
1187 gp_XYZ N = GI.Crossed( GJ );
1189 if ( N.Modulus() < gp::Resolution() )
1194 double H = ( thePnt2 - theG ).Dot( N );
1195 return asin( fabs( H / L ) ) * 180. / PI;
1198 double Warping::GetBadRate( double Value, int /*nbNodes*/ ) const
1200 // the warp is in the range [0.0,PI/2]
1201 // 0.0 = good (no warp)
1202 // PI/2 = bad (face pliee)
1206 SMDSAbs_ElementType Warping::GetType() const
1208 return SMDSAbs_Face;
1214 Description : Functor for calculating taper
1216 double Taper::GetValue( const TSequenceOfXYZ& P )
1218 if ( P.size() != 4 )
1222 double J1 = getArea( P( 4 ), P( 1 ), P( 2 ) ) / 2.;
1223 double J2 = getArea( P( 3 ), P( 1 ), P( 2 ) ) / 2.;
1224 double J3 = getArea( P( 2 ), P( 3 ), P( 4 ) ) / 2.;
1225 double J4 = getArea( P( 3 ), P( 4 ), P( 1 ) ) / 2.;
1227 double JA = 0.25 * ( J1 + J2 + J3 + J4 );
1228 if ( JA <= Precision::Confusion() )
1231 double T1 = fabs( ( J1 - JA ) / JA );
1232 double T2 = fabs( ( J2 - JA ) / JA );
1233 double T3 = fabs( ( J3 - JA ) / JA );
1234 double T4 = fabs( ( J4 - JA ) / JA );
1236 return Max( Max( T1, T2 ), Max( T3, T4 ) );
1239 double Taper::GetBadRate( double Value, int /*nbNodes*/ ) const
1241 // the taper is in the range [0.0,1.0]
1242 // 0.0 = good (no taper)
1243 // 1.0 = bad (les cotes opposes sont allignes)
1247 SMDSAbs_ElementType Taper::GetType() const
1249 return SMDSAbs_Face;
1255 Description : Functor for calculating skew in degrees
1257 static inline double skewAngle( const gp_XYZ& p1, const gp_XYZ& p2, const gp_XYZ& p3 )
1259 gp_XYZ p12 = ( p2 + p1 ) / 2.;
1260 gp_XYZ p23 = ( p3 + p2 ) / 2.;
1261 gp_XYZ p31 = ( p3 + p1 ) / 2.;
1263 gp_Vec v1( p31 - p2 ), v2( p12 - p23 );
1265 return v1.Magnitude() < gp::Resolution() || v2.Magnitude() < gp::Resolution() ? 0. : v1.Angle( v2 );
1268 double Skew::GetValue( const TSequenceOfXYZ& P )
1270 if ( P.size() != 3 && P.size() != 4 )
1274 static double PI2 = PI / 2.;
1275 if ( P.size() == 3 )
1277 double A0 = fabs( PI2 - skewAngle( P( 3 ), P( 1 ), P( 2 ) ) );
1278 double A1 = fabs( PI2 - skewAngle( P( 1 ), P( 2 ), P( 3 ) ) );
1279 double A2 = fabs( PI2 - skewAngle( P( 2 ), P( 3 ), P( 1 ) ) );
1281 return Max( A0, Max( A1, A2 ) ) * 180. / PI;
1285 gp_XYZ p12 = ( P( 1 ) + P( 2 ) ) / 2.;
1286 gp_XYZ p23 = ( P( 2 ) + P( 3 ) ) / 2.;
1287 gp_XYZ p34 = ( P( 3 ) + P( 4 ) ) / 2.;
1288 gp_XYZ p41 = ( P( 4 ) + P( 1 ) ) / 2.;
1290 gp_Vec v1( p34 - p12 ), v2( p23 - p41 );
1291 double A = v1.Magnitude() <= gp::Resolution() || v2.Magnitude() <= gp::Resolution()
1292 ? 0. : fabs( PI2 - v1.Angle( v2 ) );
1295 if ( A < Precision::Angular() )
1298 return A * 180. / PI;
1302 double Skew::GetBadRate( double Value, int /*nbNodes*/ ) const
1304 // the skew is in the range [0.0,PI/2].
1310 SMDSAbs_ElementType Skew::GetType() const
1312 return SMDSAbs_Face;
1318 Description : Functor for calculating area
1320 double Area::GetValue( const TSequenceOfXYZ& P )
1323 if ( P.size() > 2 ) {
1324 gp_Vec aVec1( P(2) - P(1) );
1325 gp_Vec aVec2( P(3) - P(1) );
1326 gp_Vec SumVec = aVec1 ^ aVec2;
1327 for (int i=4; i<=P.size(); i++) {
1328 gp_Vec aVec1( P(i-1) - P(1) );
1329 gp_Vec aVec2( P(i) - P(1) );
1330 gp_Vec tmp = aVec1 ^ aVec2;
1333 val = SumVec.Magnitude() * 0.5;
1338 double Area::GetBadRate( double Value, int /*nbNodes*/ ) const
1340 // meaningless as it is not a quality control functor
1344 SMDSAbs_ElementType Area::GetType() const
1346 return SMDSAbs_Face;
1352 Description : Functor for calculating length off edge
1354 double Length::GetValue( const TSequenceOfXYZ& P )
1356 switch ( P.size() ) {
1357 case 2: return getDistance( P( 1 ), P( 2 ) );
1358 case 3: return getDistance( P( 1 ), P( 2 ) ) + getDistance( P( 2 ), P( 3 ) );
1363 double Length::GetBadRate( double Value, int /*nbNodes*/ ) const
1365 // meaningless as it is not quality control functor
1369 SMDSAbs_ElementType Length::GetType() const
1371 return SMDSAbs_Edge;
1376 Description : Functor for calculating length of edge
1379 double Length2D::GetValue( long theElementId)
1383 //cout<<"Length2D::GetValue"<<endl;
1384 if (GetPoints(theElementId,P)){
1385 //for(int jj=1; jj<=P.size(); jj++)
1386 // cout<<"jj="<<jj<<" P("<<P(jj).X()<<","<<P(jj).Y()<<","<<P(jj).Z()<<")"<<endl;
1388 double aVal;// = GetValue( P );
1389 const SMDS_MeshElement* aElem = myMesh->FindElement( theElementId );
1390 SMDSAbs_ElementType aType = aElem->GetType();
1399 aVal = getDistance( P( 1 ), P( 2 ) );
1402 else if (len == 3){ // quadratic edge
1403 aVal = getDistance(P( 1 ),P( 3 )) + getDistance(P( 3 ),P( 2 ));
1407 if (len == 3){ // triangles
1408 double L1 = getDistance(P( 1 ),P( 2 ));
1409 double L2 = getDistance(P( 2 ),P( 3 ));
1410 double L3 = getDistance(P( 3 ),P( 1 ));
1411 aVal = Max(L1,Max(L2,L3));
1414 else if (len == 4){ // quadrangles
1415 double L1 = getDistance(P( 1 ),P( 2 ));
1416 double L2 = getDistance(P( 2 ),P( 3 ));
1417 double L3 = getDistance(P( 3 ),P( 4 ));
1418 double L4 = getDistance(P( 4 ),P( 1 ));
1419 aVal = Max(Max(L1,L2),Max(L3,L4));
1422 if (len == 6){ // quadratic triangles
1423 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1424 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1425 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 1 ));
1426 aVal = Max(L1,Max(L2,L3));
1427 //cout<<"L1="<<L1<<" L2="<<L2<<"L3="<<L3<<" aVal="<<aVal<<endl;
1430 else if (len == 8){ // quadratic quadrangles
1431 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1432 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1433 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 7 ));
1434 double L4 = getDistance(P( 7 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
1435 aVal = Max(Max(L1,L2),Max(L3,L4));
1438 case SMDSAbs_Volume:
1439 if (len == 4){ // tetraidrs
1440 double L1 = getDistance(P( 1 ),P( 2 ));
1441 double L2 = getDistance(P( 2 ),P( 3 ));
1442 double L3 = getDistance(P( 3 ),P( 1 ));
1443 double L4 = getDistance(P( 1 ),P( 4 ));
1444 double L5 = getDistance(P( 2 ),P( 4 ));
1445 double L6 = getDistance(P( 3 ),P( 4 ));
1446 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1449 else if (len == 5){ // piramids
1450 double L1 = getDistance(P( 1 ),P( 2 ));
1451 double L2 = getDistance(P( 2 ),P( 3 ));
1452 double L3 = getDistance(P( 3 ),P( 4 ));
1453 double L4 = getDistance(P( 4 ),P( 1 ));
1454 double L5 = getDistance(P( 1 ),P( 5 ));
1455 double L6 = getDistance(P( 2 ),P( 5 ));
1456 double L7 = getDistance(P( 3 ),P( 5 ));
1457 double L8 = getDistance(P( 4 ),P( 5 ));
1459 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1460 aVal = Max(aVal,Max(L7,L8));
1463 else if (len == 6){ // pentaidres
1464 double L1 = getDistance(P( 1 ),P( 2 ));
1465 double L2 = getDistance(P( 2 ),P( 3 ));
1466 double L3 = getDistance(P( 3 ),P( 1 ));
1467 double L4 = getDistance(P( 4 ),P( 5 ));
1468 double L5 = getDistance(P( 5 ),P( 6 ));
1469 double L6 = getDistance(P( 6 ),P( 4 ));
1470 double L7 = getDistance(P( 1 ),P( 4 ));
1471 double L8 = getDistance(P( 2 ),P( 5 ));
1472 double L9 = getDistance(P( 3 ),P( 6 ));
1474 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1475 aVal = Max(aVal,Max(Max(L7,L8),L9));
1478 else if (len == 8){ // hexaider
1479 double L1 = getDistance(P( 1 ),P( 2 ));
1480 double L2 = getDistance(P( 2 ),P( 3 ));
1481 double L3 = getDistance(P( 3 ),P( 4 ));
1482 double L4 = getDistance(P( 4 ),P( 1 ));
1483 double L5 = getDistance(P( 5 ),P( 6 ));
1484 double L6 = getDistance(P( 6 ),P( 7 ));
1485 double L7 = getDistance(P( 7 ),P( 8 ));
1486 double L8 = getDistance(P( 8 ),P( 5 ));
1487 double L9 = getDistance(P( 1 ),P( 5 ));
1488 double L10= getDistance(P( 2 ),P( 6 ));
1489 double L11= getDistance(P( 3 ),P( 7 ));
1490 double L12= getDistance(P( 4 ),P( 8 ));
1492 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1493 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
1494 aVal = Max(aVal,Max(L11,L12));
1499 if (len == 10){ // quadratic tetraidrs
1500 double L1 = getDistance(P( 1 ),P( 5 )) + getDistance(P( 5 ),P( 2 ));
1501 double L2 = getDistance(P( 2 ),P( 6 )) + getDistance(P( 6 ),P( 3 ));
1502 double L3 = getDistance(P( 3 ),P( 7 )) + getDistance(P( 7 ),P( 1 ));
1503 double L4 = getDistance(P( 1 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
1504 double L5 = getDistance(P( 2 ),P( 9 )) + getDistance(P( 9 ),P( 4 ));
1505 double L6 = getDistance(P( 3 ),P( 10 )) + getDistance(P( 10 ),P( 4 ));
1506 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1509 else if (len == 13){ // quadratic piramids
1510 double L1 = getDistance(P( 1 ),P( 6 )) + getDistance(P( 6 ),P( 2 ));
1511 double L2 = getDistance(P( 2 ),P( 7 )) + getDistance(P( 7 ),P( 3 ));
1512 double L3 = getDistance(P( 3 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
1513 double L4 = getDistance(P( 4 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1514 double L5 = getDistance(P( 1 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1515 double L6 = getDistance(P( 2 ),P( 11 )) + getDistance(P( 11 ),P( 5 ));
1516 double L7 = getDistance(P( 3 ),P( 12 )) + getDistance(P( 12 ),P( 5 ));
1517 double L8 = getDistance(P( 4 ),P( 13 )) + getDistance(P( 13 ),P( 5 ));
1518 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1519 aVal = Max(aVal,Max(L7,L8));
1522 else if (len == 15){ // quadratic pentaidres
1523 double L1 = getDistance(P( 1 ),P( 7 )) + getDistance(P( 7 ),P( 2 ));
1524 double L2 = getDistance(P( 2 ),P( 8 )) + getDistance(P( 8 ),P( 3 ));
1525 double L3 = getDistance(P( 3 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1526 double L4 = getDistance(P( 4 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1527 double L5 = getDistance(P( 5 ),P( 11 )) + getDistance(P( 11 ),P( 6 ));
1528 double L6 = getDistance(P( 6 ),P( 12 )) + getDistance(P( 12 ),P( 4 ));
1529 double L7 = getDistance(P( 1 ),P( 13 )) + getDistance(P( 13 ),P( 4 ));
1530 double L8 = getDistance(P( 2 ),P( 14 )) + getDistance(P( 14 ),P( 5 ));
1531 double L9 = getDistance(P( 3 ),P( 15 )) + getDistance(P( 15 ),P( 6 ));
1532 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1533 aVal = Max(aVal,Max(Max(L7,L8),L9));
1536 else if (len == 20){ // quadratic hexaider
1537 double L1 = getDistance(P( 1 ),P( 9 )) + getDistance(P( 9 ),P( 2 ));
1538 double L2 = getDistance(P( 2 ),P( 10 )) + getDistance(P( 10 ),P( 3 ));
1539 double L3 = getDistance(P( 3 ),P( 11 )) + getDistance(P( 11 ),P( 4 ));
1540 double L4 = getDistance(P( 4 ),P( 12 )) + getDistance(P( 12 ),P( 1 ));
1541 double L5 = getDistance(P( 5 ),P( 13 )) + getDistance(P( 13 ),P( 6 ));
1542 double L6 = getDistance(P( 6 ),P( 14 )) + getDistance(P( 14 ),P( 7 ));
1543 double L7 = getDistance(P( 7 ),P( 15 )) + getDistance(P( 15 ),P( 8 ));
1544 double L8 = getDistance(P( 8 ),P( 16 )) + getDistance(P( 16 ),P( 5 ));
1545 double L9 = getDistance(P( 1 ),P( 17 )) + getDistance(P( 17 ),P( 5 ));
1546 double L10= getDistance(P( 2 ),P( 18 )) + getDistance(P( 18 ),P( 6 ));
1547 double L11= getDistance(P( 3 ),P( 19 )) + getDistance(P( 19 ),P( 7 ));
1548 double L12= getDistance(P( 4 ),P( 20 )) + getDistance(P( 20 ),P( 8 ));
1549 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1550 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
1551 aVal = Max(aVal,Max(L11,L12));
1563 if ( myPrecision >= 0 )
1565 double prec = pow( 10., (double)( myPrecision ) );
1566 aVal = floor( aVal * prec + 0.5 ) / prec;
1575 double Length2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1577 // meaningless as it is not quality control functor
1581 SMDSAbs_ElementType Length2D::GetType() const
1583 return SMDSAbs_Face;
1586 Length2D::Value::Value(double theLength,long thePntId1, long thePntId2):
1589 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1590 if(thePntId1 > thePntId2){
1591 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1595 bool Length2D::Value::operator<(const Length2D::Value& x) const{
1596 if(myPntId[0] < x.myPntId[0]) return true;
1597 if(myPntId[0] == x.myPntId[0])
1598 if(myPntId[1] < x.myPntId[1]) return true;
1602 void Length2D::GetValues(TValues& theValues){
1604 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1605 for(; anIter->more(); ){
1606 const SMDS_MeshFace* anElem = anIter->next();
1608 if(anElem->IsQuadratic()) {
1609 const SMDS_QuadraticFaceOfNodes* F =
1610 static_cast<const SMDS_QuadraticFaceOfNodes*>(anElem);
1611 // use special nodes iterator
1612 SMDS_NodeIteratorPtr anIter = F->interlacedNodesIterator();
1617 const SMDS_MeshElement* aNode;
1619 aNode = anIter->next();
1620 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1621 P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1622 aNodeId[0] = aNodeId[1] = aNode->GetID();
1625 for(; anIter->more(); ){
1626 const SMDS_MeshNode* N1 = static_cast<const SMDS_MeshNode*> (anIter->next());
1627 P[2] = gp_Pnt(N1->X(),N1->Y(),N1->Z());
1628 aNodeId[2] = N1->GetID();
1629 aLength = P[1].Distance(P[2]);
1630 if(!anIter->more()) break;
1631 const SMDS_MeshNode* N2 = static_cast<const SMDS_MeshNode*> (anIter->next());
1632 P[3] = gp_Pnt(N2->X(),N2->Y(),N2->Z());
1633 aNodeId[3] = N2->GetID();
1634 aLength += P[2].Distance(P[3]);
1635 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1636 Value aValue2(aLength,aNodeId[2],aNodeId[3]);
1638 aNodeId[1] = aNodeId[3];
1639 theValues.insert(aValue1);
1640 theValues.insert(aValue2);
1642 aLength += P[2].Distance(P[0]);
1643 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1644 Value aValue2(aLength,aNodeId[2],aNodeId[0]);
1645 theValues.insert(aValue1);
1646 theValues.insert(aValue2);
1649 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
1654 const SMDS_MeshElement* aNode;
1655 if(aNodesIter->more()){
1656 aNode = aNodesIter->next();
1657 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1658 P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1659 aNodeId[0] = aNodeId[1] = aNode->GetID();
1662 for(; aNodesIter->more(); ){
1663 aNode = aNodesIter->next();
1664 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1665 long anId = aNode->GetID();
1667 P[2] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1669 aLength = P[1].Distance(P[2]);
1671 Value aValue(aLength,aNodeId[1],anId);
1674 theValues.insert(aValue);
1677 aLength = P[0].Distance(P[1]);
1679 Value aValue(aLength,aNodeId[0],aNodeId[1]);
1680 theValues.insert(aValue);
1686 Class : MultiConnection
1687 Description : Functor for calculating number of faces conneted to the edge
1689 double MultiConnection::GetValue( const TSequenceOfXYZ& P )
1693 double MultiConnection::GetValue( long theId )
1695 return getNbMultiConnection( myMesh, theId );
1698 double MultiConnection::GetBadRate( double Value, int /*nbNodes*/ ) const
1700 // meaningless as it is not quality control functor
1704 SMDSAbs_ElementType MultiConnection::GetType() const
1706 return SMDSAbs_Edge;
1710 Class : MultiConnection2D
1711 Description : Functor for calculating number of faces conneted to the edge
1713 double MultiConnection2D::GetValue( const TSequenceOfXYZ& P )
1718 double MultiConnection2D::GetValue( long theElementId )
1722 const SMDS_MeshElement* aFaceElem = myMesh->FindElement(theElementId);
1723 SMDSAbs_ElementType aType = aFaceElem->GetType();
1728 int i = 0, len = aFaceElem->NbNodes();
1729 SMDS_ElemIteratorPtr anIter = aFaceElem->nodesIterator();
1732 const SMDS_MeshNode *aNode, *aNode0;
1733 TColStd_MapOfInteger aMap, aMapPrev;
1735 for (i = 0; i <= len; i++) {
1740 if (anIter->more()) {
1741 aNode = (SMDS_MeshNode*)anIter->next();
1749 if (i == 0) aNode0 = aNode;
1751 SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator();
1752 while (anElemIter->more()) {
1753 const SMDS_MeshElement* anElem = anElemIter->next();
1754 if (anElem != 0 && anElem->GetType() == SMDSAbs_Face) {
1755 int anId = anElem->GetID();
1758 if (aMapPrev.Contains(anId)) {
1763 aResult = Max(aResult, aNb);
1774 double MultiConnection2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1776 // meaningless as it is not quality control functor
1780 SMDSAbs_ElementType MultiConnection2D::GetType() const
1782 return SMDSAbs_Face;
1785 MultiConnection2D::Value::Value(long thePntId1, long thePntId2)
1787 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1788 if(thePntId1 > thePntId2){
1789 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1793 bool MultiConnection2D::Value::operator<(const MultiConnection2D::Value& x) const{
1794 if(myPntId[0] < x.myPntId[0]) return true;
1795 if(myPntId[0] == x.myPntId[0])
1796 if(myPntId[1] < x.myPntId[1]) return true;
1800 void MultiConnection2D::GetValues(MValues& theValues){
1801 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1802 for(; anIter->more(); ){
1803 const SMDS_MeshFace* anElem = anIter->next();
1804 SMDS_ElemIteratorPtr aNodesIter;
1805 if ( anElem->IsQuadratic() )
1806 aNodesIter = static_cast<const SMDS_QuadraticFaceOfNodes*>
1807 (anElem)->interlacedNodesElemIterator();
1809 aNodesIter = anElem->nodesIterator();
1812 //int aNbConnects=0;
1813 const SMDS_MeshNode* aNode0;
1814 const SMDS_MeshNode* aNode1;
1815 const SMDS_MeshNode* aNode2;
1816 if(aNodesIter->more()){
1817 aNode0 = (SMDS_MeshNode*) aNodesIter->next();
1819 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode1;
1820 aNodeId[0] = aNodeId[1] = aNodes->GetID();
1822 for(; aNodesIter->more(); ) {
1823 aNode2 = (SMDS_MeshNode*) aNodesIter->next();
1824 long anId = aNode2->GetID();
1827 Value aValue(aNodeId[1],aNodeId[2]);
1828 MValues::iterator aItr = theValues.find(aValue);
1829 if (aItr != theValues.end()){
1834 theValues[aValue] = 1;
1837 //cout << "NodeIds: "<<aNodeId[1]<<","<<aNodeId[2]<<" nbconn="<<aNbConnects<<endl;
1838 aNodeId[1] = aNodeId[2];
1841 Value aValue(aNodeId[0],aNodeId[2]);
1842 MValues::iterator aItr = theValues.find(aValue);
1843 if (aItr != theValues.end()) {
1848 theValues[aValue] = 1;
1851 //cout << "NodeIds: "<<aNodeId[0]<<","<<aNodeId[2]<<" nbconn="<<aNbConnects<<endl;
1861 Class : BadOrientedVolume
1862 Description : Predicate bad oriented volumes
1865 BadOrientedVolume::BadOrientedVolume()
1870 void BadOrientedVolume::SetMesh( const SMDS_Mesh* theMesh )
1875 bool BadOrientedVolume::IsSatisfy( long theId )
1880 SMDS_VolumeTool vTool( myMesh->FindElement( theId ));
1881 return !vTool.IsForward();
1884 SMDSAbs_ElementType BadOrientedVolume::GetType() const
1886 return SMDSAbs_Volume;
1890 Class : BareBorderVolume
1893 bool BareBorderVolume::IsSatisfy(long theElementId )
1895 SMDS_VolumeTool myTool;
1896 if ( myTool.Set( myMesh->FindElement(theElementId)))
1898 for ( int iF = 0; iF < myTool.NbFaces(); ++iF )
1899 if ( myTool.IsFreeFace( iF ))
1901 const SMDS_MeshNode** n = myTool.GetFaceNodes(iF);
1902 vector< const SMDS_MeshNode*> nodes( n, n+myTool.NbFaceNodes(iF));
1903 if ( !myMesh->FindElement( nodes, SMDSAbs_Face, /*Nomedium=*/false))
1911 Class : BareBorderFace
1914 bool BareBorderFace::IsSatisfy(long theElementId )
1916 if ( const SMDS_MeshElement* face = myMesh->FindElement(theElementId))
1917 if ( face->GetType() == SMDSAbs_Face )
1919 int nbN = face->NbCornerNodes();
1920 for ( int i = 0; i < nbN; ++i )
1922 // check if a link is shared by another face
1923 const SMDS_MeshNode* n1 = face->GetNode( i );
1924 const SMDS_MeshNode* n2 = face->GetNode( (i+1)%nbN );
1925 SMDS_ElemIteratorPtr fIt = n1->GetInverseElementIterator( SMDSAbs_Face );
1926 bool isShared = false;
1927 while ( !isShared && fIt->more() )
1929 const SMDS_MeshElement* f = fIt->next();
1930 isShared = ( f != face && f->GetNodeIndex(n2) != -1 );
1934 myLinkNodes.resize( 2 + face->IsQuadratic());
1935 myLinkNodes[0] = n1;
1936 myLinkNodes[1] = n2;
1937 if ( face->IsQuadratic() )
1938 myLinkNodes[2] = face->GetNode( i+nbN );
1939 return !myMesh->FindElement( myLinkNodes, SMDSAbs_Edge, /*noMedium=*/false);
1947 Class : OverConstrainedVolume
1950 bool OverConstrainedVolume::IsSatisfy(long theElementId )
1952 // An element is over-constrained if it has N-1 free borders where
1953 // N is the number of edges/faces for a 2D/3D element.
1954 SMDS_VolumeTool myTool;
1955 if ( myTool.Set( myMesh->FindElement(theElementId)))
1957 int nbSharedFaces = 0;
1958 for ( int iF = 0; iF < myTool.NbFaces(); ++iF )
1959 if ( !myTool.IsFreeFace( iF ) && ++nbSharedFaces > 1 )
1961 return ( nbSharedFaces == 1 );
1967 Class : OverConstrainedFace
1970 bool OverConstrainedFace::IsSatisfy(long theElementId )
1972 // An element is over-constrained if it has N-1 free borders where
1973 // N is the number of edges/faces for a 2D/3D element.
1974 if ( const SMDS_MeshElement* face = myMesh->FindElement(theElementId))
1975 if ( face->GetType() == SMDSAbs_Face )
1977 int nbSharedBorders = 0;
1978 int nbN = face->NbCornerNodes();
1979 for ( int i = 0; i < nbN; ++i )
1981 // check if a link is shared by another face
1982 const SMDS_MeshNode* n1 = face->GetNode( i );
1983 const SMDS_MeshNode* n2 = face->GetNode( (i+1)%nbN );
1984 SMDS_ElemIteratorPtr fIt = n1->GetInverseElementIterator( SMDSAbs_Face );
1985 bool isShared = false;
1986 while ( !isShared && fIt->more() )
1988 const SMDS_MeshElement* f = fIt->next();
1989 isShared = ( f != face && f->GetNodeIndex(n2) != -1 );
1991 if ( isShared && ++nbSharedBorders > 1 )
1994 return ( nbSharedBorders == 1 );
2001 Description : Predicate for free borders
2004 FreeBorders::FreeBorders()
2009 void FreeBorders::SetMesh( const SMDS_Mesh* theMesh )
2014 bool FreeBorders::IsSatisfy( long theId )
2016 return getNbMultiConnection( myMesh, theId ) == 1;
2019 SMDSAbs_ElementType FreeBorders::GetType() const
2021 return SMDSAbs_Edge;
2027 Description : Predicate for free Edges
2029 FreeEdges::FreeEdges()
2034 void FreeEdges::SetMesh( const SMDS_Mesh* theMesh )
2039 bool FreeEdges::IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId )
2041 TColStd_MapOfInteger aMap;
2042 for ( int i = 0; i < 2; i++ )
2044 SMDS_ElemIteratorPtr anElemIter = theNodes[ i ]->GetInverseElementIterator();
2045 while( anElemIter->more() )
2047 const SMDS_MeshElement* anElem = anElemIter->next();
2048 if ( anElem != 0 && anElem->GetType() == SMDSAbs_Face )
2050 int anId = anElem->GetID();
2054 else if ( aMap.Contains( anId ) && anId != theFaceId )
2062 bool FreeEdges::IsSatisfy( long theId )
2067 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
2068 if ( aFace == 0 || aFace->GetType() != SMDSAbs_Face || aFace->NbNodes() < 3 )
2071 SMDS_ElemIteratorPtr anIter;
2072 if ( aFace->IsQuadratic() ) {
2073 anIter = static_cast<const SMDS_QuadraticFaceOfNodes*>
2074 (aFace)->interlacedNodesElemIterator();
2077 anIter = aFace->nodesIterator();
2082 int i = 0, nbNodes = aFace->NbNodes();
2083 std::vector <const SMDS_MeshNode*> aNodes( nbNodes+1 );
2084 while( anIter->more() )
2086 const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next();
2089 aNodes[ i++ ] = aNode;
2091 aNodes[ nbNodes ] = aNodes[ 0 ];
2093 for ( i = 0; i < nbNodes; i++ )
2094 if ( IsFreeEdge( &aNodes[ i ], theId ) )
2100 SMDSAbs_ElementType FreeEdges::GetType() const
2102 return SMDSAbs_Face;
2105 FreeEdges::Border::Border(long theElemId, long thePntId1, long thePntId2):
2108 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
2109 if(thePntId1 > thePntId2){
2110 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
2114 bool FreeEdges::Border::operator<(const FreeEdges::Border& x) const{
2115 if(myPntId[0] < x.myPntId[0]) return true;
2116 if(myPntId[0] == x.myPntId[0])
2117 if(myPntId[1] < x.myPntId[1]) return true;
2121 inline void UpdateBorders(const FreeEdges::Border& theBorder,
2122 FreeEdges::TBorders& theRegistry,
2123 FreeEdges::TBorders& theContainer)
2125 if(theRegistry.find(theBorder) == theRegistry.end()){
2126 theRegistry.insert(theBorder);
2127 theContainer.insert(theBorder);
2129 theContainer.erase(theBorder);
2133 void FreeEdges::GetBoreders(TBorders& theBorders)
2136 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
2137 for(; anIter->more(); ){
2138 const SMDS_MeshFace* anElem = anIter->next();
2139 long anElemId = anElem->GetID();
2140 SMDS_ElemIteratorPtr aNodesIter;
2141 if ( anElem->IsQuadratic() )
2142 aNodesIter = static_cast<const SMDS_QuadraticFaceOfNodes*>(anElem)->
2143 interlacedNodesElemIterator();
2145 aNodesIter = anElem->nodesIterator();
2147 const SMDS_MeshElement* aNode;
2148 if(aNodesIter->more()){
2149 aNode = aNodesIter->next();
2150 aNodeId[0] = aNodeId[1] = aNode->GetID();
2152 for(; aNodesIter->more(); ){
2153 aNode = aNodesIter->next();
2154 long anId = aNode->GetID();
2155 Border aBorder(anElemId,aNodeId[1],anId);
2157 //std::cout<<aBorder.myPntId[0]<<"; "<<aBorder.myPntId[1]<<"; "<<aBorder.myElemId<<endl;
2158 UpdateBorders(aBorder,aRegistry,theBorders);
2160 Border aBorder(anElemId,aNodeId[0],aNodeId[1]);
2161 //std::cout<<aBorder.myPntId[0]<<"; "<<aBorder.myPntId[1]<<"; "<<aBorder.myElemId<<endl;
2162 UpdateBorders(aBorder,aRegistry,theBorders);
2164 //std::cout<<"theBorders.size() = "<<theBorders.size()<<endl;
2170 Description : Predicate for free nodes
2173 FreeNodes::FreeNodes()
2178 void FreeNodes::SetMesh( const SMDS_Mesh* theMesh )
2183 bool FreeNodes::IsSatisfy( long theNodeId )
2185 const SMDS_MeshNode* aNode = myMesh->FindNode( theNodeId );
2189 return (aNode->NbInverseElements() < 1);
2192 SMDSAbs_ElementType FreeNodes::GetType() const
2194 return SMDSAbs_Node;
2200 Description : Predicate for free faces
2203 FreeFaces::FreeFaces()
2208 void FreeFaces::SetMesh( const SMDS_Mesh* theMesh )
2213 bool FreeFaces::IsSatisfy( long theId )
2215 if (!myMesh) return false;
2216 // check that faces nodes refers to less than two common volumes
2217 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
2218 if ( !aFace || aFace->GetType() != SMDSAbs_Face )
2221 int nbNode = aFace->NbNodes();
2223 // collect volumes check that number of volumss with count equal nbNode not less than 2
2224 typedef map< SMDS_MeshElement*, int > TMapOfVolume; // map of volume counters
2225 typedef map< SMDS_MeshElement*, int >::iterator TItrMapOfVolume; // iterator
2226 TMapOfVolume mapOfVol;
2228 SMDS_ElemIteratorPtr nodeItr = aFace->nodesIterator();
2229 while ( nodeItr->more() ) {
2230 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(nodeItr->next());
2231 if ( !aNode ) continue;
2232 SMDS_ElemIteratorPtr volItr = aNode->GetInverseElementIterator(SMDSAbs_Volume);
2233 while ( volItr->more() ) {
2234 SMDS_MeshElement* aVol = (SMDS_MeshElement*)volItr->next();
2235 TItrMapOfVolume itr = mapOfVol.insert(make_pair(aVol, 0)).first;
2240 TItrMapOfVolume volItr = mapOfVol.begin();
2241 TItrMapOfVolume volEnd = mapOfVol.end();
2242 for ( ; volItr != volEnd; ++volItr )
2243 if ( (*volItr).second >= nbNode )
2245 // face is not free if number of volumes constructed on thier nodes more than one
2249 SMDSAbs_ElementType FreeFaces::GetType() const
2251 return SMDSAbs_Face;
2255 Class : LinearOrQuadratic
2256 Description : Predicate to verify whether a mesh element is linear
2259 LinearOrQuadratic::LinearOrQuadratic()
2264 void LinearOrQuadratic::SetMesh( const SMDS_Mesh* theMesh )
2269 bool LinearOrQuadratic::IsSatisfy( long theId )
2271 if (!myMesh) return false;
2272 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2273 if ( !anElem || (myType != SMDSAbs_All && anElem->GetType() != myType) )
2275 return (!anElem->IsQuadratic());
2278 void LinearOrQuadratic::SetType( SMDSAbs_ElementType theType )
2283 SMDSAbs_ElementType LinearOrQuadratic::GetType() const
2290 Description : Functor for check color of group to whic mesh element belongs to
2293 GroupColor::GroupColor()
2297 bool GroupColor::IsSatisfy( long theId )
2299 return (myIDs.find( theId ) != myIDs.end());
2302 void GroupColor::SetType( SMDSAbs_ElementType theType )
2307 SMDSAbs_ElementType GroupColor::GetType() const
2312 static bool isEqual( const Quantity_Color& theColor1,
2313 const Quantity_Color& theColor2 )
2315 // tolerance to compare colors
2316 const double tol = 5*1e-3;
2317 return ( fabs( theColor1.Red() - theColor2.Red() ) < tol &&
2318 fabs( theColor1.Green() - theColor2.Green() ) < tol &&
2319 fabs( theColor1.Blue() - theColor2.Blue() ) < tol );
2323 void GroupColor::SetMesh( const SMDS_Mesh* theMesh )
2327 const SMESHDS_Mesh* aMesh = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
2331 int nbGrp = aMesh->GetNbGroups();
2335 // iterates on groups and find necessary elements ids
2336 const std::set<SMESHDS_GroupBase*>& aGroups = aMesh->GetGroups();
2337 set<SMESHDS_GroupBase*>::const_iterator GrIt = aGroups.begin();
2338 for (; GrIt != aGroups.end(); GrIt++) {
2339 SMESHDS_GroupBase* aGrp = (*GrIt);
2342 // check type and color of group
2343 if ( !isEqual( myColor, aGrp->GetColor() ) )
2345 if ( myType != SMDSAbs_All && myType != (SMDSAbs_ElementType)aGrp->GetType() )
2348 SMDSAbs_ElementType aGrpElType = (SMDSAbs_ElementType)aGrp->GetType();
2349 if ( myType == aGrpElType || (myType == SMDSAbs_All && aGrpElType != SMDSAbs_Node) ) {
2350 // add elements IDS into control
2351 int aSize = aGrp->Extent();
2352 for (int i = 0; i < aSize; i++)
2353 myIDs.insert( aGrp->GetID(i+1) );
2358 void GroupColor::SetColorStr( const TCollection_AsciiString& theStr )
2360 TCollection_AsciiString aStr = theStr;
2361 aStr.RemoveAll( ' ' );
2362 aStr.RemoveAll( '\t' );
2363 for ( int aPos = aStr.Search( ";;" ); aPos != -1; aPos = aStr.Search( ";;" ) )
2364 aStr.Remove( aPos, 2 );
2365 Standard_Real clr[3];
2366 clr[0] = clr[1] = clr[2] = 0.;
2367 for ( int i = 0; i < 3; i++ ) {
2368 TCollection_AsciiString tmpStr = aStr.Token( ";", i+1 );
2369 if ( !tmpStr.IsEmpty() && tmpStr.IsRealValue() )
2370 clr[i] = tmpStr.RealValue();
2372 myColor = Quantity_Color( clr[0], clr[1], clr[2], Quantity_TOC_RGB );
2375 //=======================================================================
2376 // name : GetRangeStr
2377 // Purpose : Get range as a string.
2378 // Example: "1,2,3,50-60,63,67,70-"
2379 //=======================================================================
2380 void GroupColor::GetColorStr( TCollection_AsciiString& theResStr ) const
2383 theResStr += TCollection_AsciiString( myColor.Red() );
2384 theResStr += TCollection_AsciiString( ";" ) + TCollection_AsciiString( myColor.Green() );
2385 theResStr += TCollection_AsciiString( ";" ) + TCollection_AsciiString( myColor.Blue() );
2389 Class : ElemGeomType
2390 Description : Predicate to check element geometry type
2393 ElemGeomType::ElemGeomType()
2396 myType = SMDSAbs_All;
2397 myGeomType = SMDSGeom_TRIANGLE;
2400 void ElemGeomType::SetMesh( const SMDS_Mesh* theMesh )
2405 bool ElemGeomType::IsSatisfy( long theId )
2407 if (!myMesh) return false;
2408 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2411 const SMDSAbs_ElementType anElemType = anElem->GetType();
2412 if ( myType != SMDSAbs_All && anElemType != myType )
2414 const int aNbNode = anElem->NbNodes();
2416 switch( anElemType )
2419 isOk = (myGeomType == SMDSGeom_POINT);
2423 isOk = (myGeomType == SMDSGeom_EDGE);
2427 if ( myGeomType == SMDSGeom_TRIANGLE )
2428 isOk = (!anElem->IsPoly() && (anElem->IsQuadratic() ? aNbNode == 6 : aNbNode == 3));
2429 else if ( myGeomType == SMDSGeom_QUADRANGLE )
2430 isOk = (!anElem->IsPoly() && (anElem->IsQuadratic() ? aNbNode == 8 : aNbNode == 4));
2431 else if ( myGeomType == SMDSGeom_POLYGON )
2432 isOk = anElem->IsPoly();
2435 case SMDSAbs_Volume:
2436 if ( myGeomType == SMDSGeom_TETRA )
2437 isOk = (!anElem->IsPoly() && (anElem->IsQuadratic() ? aNbNode == 10 : aNbNode == 4));
2438 else if ( myGeomType == SMDSGeom_PYRAMID )
2439 isOk = (!anElem->IsPoly() && (anElem->IsQuadratic() ? aNbNode == 13 : aNbNode == 5));
2440 else if ( myGeomType == SMDSGeom_PENTA )
2441 isOk = (!anElem->IsPoly() && (anElem->IsQuadratic() ? aNbNode == 15 : aNbNode == 6));
2442 else if ( myGeomType == SMDSGeom_HEXA )
2443 isOk = (!anElem->IsPoly() && (anElem->IsQuadratic() ? aNbNode == 20 : aNbNode == 8));
2444 else if ( myGeomType == SMDSGeom_POLYHEDRA )
2445 isOk = anElem->IsPoly();
2452 void ElemGeomType::SetType( SMDSAbs_ElementType theType )
2457 SMDSAbs_ElementType ElemGeomType::GetType() const
2462 void ElemGeomType::SetGeomType( SMDSAbs_GeometryType theType )
2464 myGeomType = theType;
2467 SMDSAbs_GeometryType ElemGeomType::GetGeomType() const
2474 Description : Predicate for Range of Ids.
2475 Range may be specified with two ways.
2476 1. Using AddToRange method
2477 2. With SetRangeStr method. Parameter of this method is a string
2478 like as "1,2,3,50-60,63,67,70-"
2481 //=======================================================================
2482 // name : RangeOfIds
2483 // Purpose : Constructor
2484 //=======================================================================
2485 RangeOfIds::RangeOfIds()
2488 myType = SMDSAbs_All;
2491 //=======================================================================
2493 // Purpose : Set mesh
2494 //=======================================================================
2495 void RangeOfIds::SetMesh( const SMDS_Mesh* theMesh )
2500 //=======================================================================
2501 // name : AddToRange
2502 // Purpose : Add ID to the range
2503 //=======================================================================
2504 bool RangeOfIds::AddToRange( long theEntityId )
2506 myIds.Add( theEntityId );
2510 //=======================================================================
2511 // name : GetRangeStr
2512 // Purpose : Get range as a string.
2513 // Example: "1,2,3,50-60,63,67,70-"
2514 //=======================================================================
2515 void RangeOfIds::GetRangeStr( TCollection_AsciiString& theResStr )
2519 TColStd_SequenceOfInteger anIntSeq;
2520 TColStd_SequenceOfAsciiString aStrSeq;
2522 TColStd_MapIteratorOfMapOfInteger anIter( myIds );
2523 for ( ; anIter.More(); anIter.Next() )
2525 int anId = anIter.Key();
2526 TCollection_AsciiString aStr( anId );
2527 anIntSeq.Append( anId );
2528 aStrSeq.Append( aStr );
2531 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
2533 int aMinId = myMin( i );
2534 int aMaxId = myMax( i );
2536 TCollection_AsciiString aStr;
2537 if ( aMinId != IntegerFirst() )
2542 if ( aMaxId != IntegerLast() )
2545 // find position of the string in result sequence and insert string in it
2546 if ( anIntSeq.Length() == 0 )
2548 anIntSeq.Append( aMinId );
2549 aStrSeq.Append( aStr );
2553 if ( aMinId < anIntSeq.First() )
2555 anIntSeq.Prepend( aMinId );
2556 aStrSeq.Prepend( aStr );
2558 else if ( aMinId > anIntSeq.Last() )
2560 anIntSeq.Append( aMinId );
2561 aStrSeq.Append( aStr );
2564 for ( int j = 1, k = anIntSeq.Length(); j <= k; j++ )
2565 if ( aMinId < anIntSeq( j ) )
2567 anIntSeq.InsertBefore( j, aMinId );
2568 aStrSeq.InsertBefore( j, aStr );
2574 if ( aStrSeq.Length() == 0 )
2577 theResStr = aStrSeq( 1 );
2578 for ( int j = 2, k = aStrSeq.Length(); j <= k; j++ )
2581 theResStr += aStrSeq( j );
2585 //=======================================================================
2586 // name : SetRangeStr
2587 // Purpose : Define range with string
2588 // Example of entry string: "1,2,3,50-60,63,67,70-"
2589 //=======================================================================
2590 bool RangeOfIds::SetRangeStr( const TCollection_AsciiString& theStr )
2596 TCollection_AsciiString aStr = theStr;
2597 aStr.RemoveAll( ' ' );
2598 aStr.RemoveAll( '\t' );
2600 for ( int aPos = aStr.Search( ",," ); aPos != -1; aPos = aStr.Search( ",," ) )
2601 aStr.Remove( aPos, 2 );
2603 TCollection_AsciiString tmpStr = aStr.Token( ",", 1 );
2605 while ( tmpStr != "" )
2607 tmpStr = aStr.Token( ",", i++ );
2608 int aPos = tmpStr.Search( '-' );
2612 if ( tmpStr.IsIntegerValue() )
2613 myIds.Add( tmpStr.IntegerValue() );
2619 TCollection_AsciiString aMaxStr = tmpStr.Split( aPos );
2620 TCollection_AsciiString aMinStr = tmpStr;
2622 while ( aMinStr.Search( "-" ) != -1 ) aMinStr.RemoveAll( '-' );
2623 while ( aMaxStr.Search( "-" ) != -1 ) aMaxStr.RemoveAll( '-' );
2625 if ( !aMinStr.IsEmpty() && !aMinStr.IsIntegerValue() ||
2626 !aMaxStr.IsEmpty() && !aMaxStr.IsIntegerValue() )
2629 myMin.Append( aMinStr.IsEmpty() ? IntegerFirst() : aMinStr.IntegerValue() );
2630 myMax.Append( aMaxStr.IsEmpty() ? IntegerLast() : aMaxStr.IntegerValue() );
2637 //=======================================================================
2639 // Purpose : Get type of supported entities
2640 //=======================================================================
2641 SMDSAbs_ElementType RangeOfIds::GetType() const
2646 //=======================================================================
2648 // Purpose : Set type of supported entities
2649 //=======================================================================
2650 void RangeOfIds::SetType( SMDSAbs_ElementType theType )
2655 //=======================================================================
2657 // Purpose : Verify whether entity satisfies to this rpedicate
2658 //=======================================================================
2659 bool RangeOfIds::IsSatisfy( long theId )
2664 if ( myType == SMDSAbs_Node )
2666 if ( myMesh->FindNode( theId ) == 0 )
2671 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2672 if ( anElem == 0 || myType != anElem->GetType() && myType != SMDSAbs_All )
2676 if ( myIds.Contains( theId ) )
2679 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
2680 if ( theId >= myMin( i ) && theId <= myMax( i ) )
2688 Description : Base class for comparators
2690 Comparator::Comparator():
2694 Comparator::~Comparator()
2697 void Comparator::SetMesh( const SMDS_Mesh* theMesh )
2700 myFunctor->SetMesh( theMesh );
2703 void Comparator::SetMargin( double theValue )
2705 myMargin = theValue;
2708 void Comparator::SetNumFunctor( NumericalFunctorPtr theFunct )
2710 myFunctor = theFunct;
2713 SMDSAbs_ElementType Comparator::GetType() const
2715 return myFunctor ? myFunctor->GetType() : SMDSAbs_All;
2718 double Comparator::GetMargin()
2726 Description : Comparator "<"
2728 bool LessThan::IsSatisfy( long theId )
2730 return myFunctor && myFunctor->GetValue( theId ) < myMargin;
2736 Description : Comparator ">"
2738 bool MoreThan::IsSatisfy( long theId )
2740 return myFunctor && myFunctor->GetValue( theId ) > myMargin;
2746 Description : Comparator "="
2749 myToler(Precision::Confusion())
2752 bool EqualTo::IsSatisfy( long theId )
2754 return myFunctor && fabs( myFunctor->GetValue( theId ) - myMargin ) < myToler;
2757 void EqualTo::SetTolerance( double theToler )
2762 double EqualTo::GetTolerance()
2769 Description : Logical NOT predicate
2771 LogicalNOT::LogicalNOT()
2774 LogicalNOT::~LogicalNOT()
2777 bool LogicalNOT::IsSatisfy( long theId )
2779 return myPredicate && !myPredicate->IsSatisfy( theId );
2782 void LogicalNOT::SetMesh( const SMDS_Mesh* theMesh )
2785 myPredicate->SetMesh( theMesh );
2788 void LogicalNOT::SetPredicate( PredicatePtr thePred )
2790 myPredicate = thePred;
2793 SMDSAbs_ElementType LogicalNOT::GetType() const
2795 return myPredicate ? myPredicate->GetType() : SMDSAbs_All;
2800 Class : LogicalBinary
2801 Description : Base class for binary logical predicate
2803 LogicalBinary::LogicalBinary()
2806 LogicalBinary::~LogicalBinary()
2809 void LogicalBinary::SetMesh( const SMDS_Mesh* theMesh )
2812 myPredicate1->SetMesh( theMesh );
2815 myPredicate2->SetMesh( theMesh );
2818 void LogicalBinary::SetPredicate1( PredicatePtr thePredicate )
2820 myPredicate1 = thePredicate;
2823 void LogicalBinary::SetPredicate2( PredicatePtr thePredicate )
2825 myPredicate2 = thePredicate;
2828 SMDSAbs_ElementType LogicalBinary::GetType() const
2830 if ( !myPredicate1 || !myPredicate2 )
2833 SMDSAbs_ElementType aType1 = myPredicate1->GetType();
2834 SMDSAbs_ElementType aType2 = myPredicate2->GetType();
2836 return aType1 == aType2 ? aType1 : SMDSAbs_All;
2842 Description : Logical AND
2844 bool LogicalAND::IsSatisfy( long theId )
2849 myPredicate1->IsSatisfy( theId ) &&
2850 myPredicate2->IsSatisfy( theId );
2856 Description : Logical OR
2858 bool LogicalOR::IsSatisfy( long theId )
2863 myPredicate1->IsSatisfy( theId ) ||
2864 myPredicate2->IsSatisfy( theId );
2878 void Filter::SetPredicate( PredicatePtr thePredicate )
2880 myPredicate = thePredicate;
2883 template<class TElement, class TIterator, class TPredicate>
2884 inline void FillSequence(const TIterator& theIterator,
2885 TPredicate& thePredicate,
2886 Filter::TIdSequence& theSequence)
2888 if ( theIterator ) {
2889 while( theIterator->more() ) {
2890 TElement anElem = theIterator->next();
2891 long anId = anElem->GetID();
2892 if ( thePredicate->IsSatisfy( anId ) )
2893 theSequence.push_back( anId );
2900 GetElementsId( const SMDS_Mesh* theMesh,
2901 PredicatePtr thePredicate,
2902 TIdSequence& theSequence )
2904 theSequence.clear();
2906 if ( !theMesh || !thePredicate )
2909 thePredicate->SetMesh( theMesh );
2911 SMDSAbs_ElementType aType = thePredicate->GetType();
2914 FillSequence<const SMDS_MeshNode*>(theMesh->nodesIterator(),thePredicate,theSequence);
2917 FillSequence<const SMDS_MeshElement*>(theMesh->edgesIterator(),thePredicate,theSequence);
2920 FillSequence<const SMDS_MeshElement*>(theMesh->facesIterator(),thePredicate,theSequence);
2922 case SMDSAbs_Volume:
2923 FillSequence<const SMDS_MeshElement*>(theMesh->volumesIterator(),thePredicate,theSequence);
2926 FillSequence<const SMDS_MeshElement*>(theMesh->edgesIterator(),thePredicate,theSequence);
2927 FillSequence<const SMDS_MeshElement*>(theMesh->facesIterator(),thePredicate,theSequence);
2928 FillSequence<const SMDS_MeshElement*>(theMesh->volumesIterator(),thePredicate,theSequence);
2934 Filter::GetElementsId( const SMDS_Mesh* theMesh,
2935 Filter::TIdSequence& theSequence )
2937 GetElementsId(theMesh,myPredicate,theSequence);
2944 typedef std::set<SMDS_MeshFace*> TMapOfFacePtr;
2950 ManifoldPart::Link::Link( SMDS_MeshNode* theNode1,
2951 SMDS_MeshNode* theNode2 )
2957 ManifoldPart::Link::~Link()
2963 bool ManifoldPart::Link::IsEqual( const ManifoldPart::Link& theLink ) const
2965 if ( myNode1 == theLink.myNode1 &&
2966 myNode2 == theLink.myNode2 )
2968 else if ( myNode1 == theLink.myNode2 &&
2969 myNode2 == theLink.myNode1 )
2975 bool ManifoldPart::Link::operator<( const ManifoldPart::Link& x ) const
2977 if(myNode1 < x.myNode1) return true;
2978 if(myNode1 == x.myNode1)
2979 if(myNode2 < x.myNode2) return true;
2983 bool ManifoldPart::IsEqual( const ManifoldPart::Link& theLink1,
2984 const ManifoldPart::Link& theLink2 )
2986 return theLink1.IsEqual( theLink2 );
2989 ManifoldPart::ManifoldPart()
2992 myAngToler = Precision::Angular();
2993 myIsOnlyManifold = true;
2996 ManifoldPart::~ManifoldPart()
3001 void ManifoldPart::SetMesh( const SMDS_Mesh* theMesh )
3007 SMDSAbs_ElementType ManifoldPart::GetType() const
3008 { return SMDSAbs_Face; }
3010 bool ManifoldPart::IsSatisfy( long theElementId )
3012 return myMapIds.Contains( theElementId );
3015 void ManifoldPart::SetAngleTolerance( const double theAngToler )
3016 { myAngToler = theAngToler; }
3018 double ManifoldPart::GetAngleTolerance() const
3019 { return myAngToler; }
3021 void ManifoldPart::SetIsOnlyManifold( const bool theIsOnly )
3022 { myIsOnlyManifold = theIsOnly; }
3024 void ManifoldPart::SetStartElem( const long theStartId )
3025 { myStartElemId = theStartId; }
3027 bool ManifoldPart::process()
3030 myMapBadGeomIds.Clear();
3032 myAllFacePtr.clear();
3033 myAllFacePtrIntDMap.clear();
3037 // collect all faces into own map
3038 SMDS_FaceIteratorPtr anFaceItr = myMesh->facesIterator();
3039 for (; anFaceItr->more(); )
3041 SMDS_MeshFace* aFacePtr = (SMDS_MeshFace*)anFaceItr->next();
3042 myAllFacePtr.push_back( aFacePtr );
3043 myAllFacePtrIntDMap[aFacePtr] = myAllFacePtr.size()-1;
3046 SMDS_MeshFace* aStartFace = (SMDS_MeshFace*)myMesh->FindElement( myStartElemId );
3050 // the map of non manifold links and bad geometry
3051 TMapOfLink aMapOfNonManifold;
3052 TColStd_MapOfInteger aMapOfTreated;
3054 // begin cycle on faces from start index and run on vector till the end
3055 // and from begin to start index to cover whole vector
3056 const int aStartIndx = myAllFacePtrIntDMap[aStartFace];
3057 bool isStartTreat = false;
3058 for ( int fi = aStartIndx; !isStartTreat || fi != aStartIndx ; fi++ )
3060 if ( fi == aStartIndx )
3061 isStartTreat = true;
3062 // as result next time when fi will be equal to aStartIndx
3064 SMDS_MeshFace* aFacePtr = myAllFacePtr[ fi ];
3065 if ( aMapOfTreated.Contains( aFacePtr->GetID() ) )
3068 aMapOfTreated.Add( aFacePtr->GetID() );
3069 TColStd_MapOfInteger aResFaces;
3070 if ( !findConnected( myAllFacePtrIntDMap, aFacePtr,
3071 aMapOfNonManifold, aResFaces ) )
3073 TColStd_MapIteratorOfMapOfInteger anItr( aResFaces );
3074 for ( ; anItr.More(); anItr.Next() )
3076 int aFaceId = anItr.Key();
3077 aMapOfTreated.Add( aFaceId );
3078 myMapIds.Add( aFaceId );
3081 if ( fi == ( myAllFacePtr.size() - 1 ) )
3083 } // end run on vector of faces
3084 return !myMapIds.IsEmpty();
3087 static void getLinks( const SMDS_MeshFace* theFace,
3088 ManifoldPart::TVectorOfLink& theLinks )
3090 int aNbNode = theFace->NbNodes();
3091 SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
3093 SMDS_MeshNode* aNode = 0;
3094 for ( ; aNodeItr->more() && i <= aNbNode; )
3097 SMDS_MeshNode* aN1 = (SMDS_MeshNode*)aNodeItr->next();
3101 SMDS_MeshNode* aN2 = ( i >= aNbNode ) ? aNode : (SMDS_MeshNode*)aNodeItr->next();
3103 ManifoldPart::Link aLink( aN1, aN2 );
3104 theLinks.push_back( aLink );
3108 static gp_XYZ getNormale( const SMDS_MeshFace* theFace )
3111 int aNbNode = theFace->NbNodes();
3112 TColgp_Array1OfXYZ anArrOfXYZ(1,4);
3113 SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
3115 for ( ; aNodeItr->more() && i <= 4; i++ ) {
3116 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
3117 anArrOfXYZ.SetValue(i, gp_XYZ( aNode->X(), aNode->Y(), aNode->Z() ) );
3120 gp_XYZ q1 = anArrOfXYZ.Value(2) - anArrOfXYZ.Value(1);
3121 gp_XYZ q2 = anArrOfXYZ.Value(3) - anArrOfXYZ.Value(1);
3123 if ( aNbNode > 3 ) {
3124 gp_XYZ q3 = anArrOfXYZ.Value(4) - anArrOfXYZ.Value(1);
3127 double len = n.Modulus();
3134 bool ManifoldPart::findConnected
3135 ( const ManifoldPart::TDataMapFacePtrInt& theAllFacePtrInt,
3136 SMDS_MeshFace* theStartFace,
3137 ManifoldPart::TMapOfLink& theNonManifold,
3138 TColStd_MapOfInteger& theResFaces )
3140 theResFaces.Clear();
3141 if ( !theAllFacePtrInt.size() )
3144 if ( getNormale( theStartFace ).SquareModulus() <= gp::Resolution() )
3146 myMapBadGeomIds.Add( theStartFace->GetID() );
3150 ManifoldPart::TMapOfLink aMapOfBoundary, aMapToSkip;
3151 ManifoldPart::TVectorOfLink aSeqOfBoundary;
3152 theResFaces.Add( theStartFace->GetID() );
3153 ManifoldPart::TDataMapOfLinkFacePtr aDMapLinkFace;
3155 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
3156 aDMapLinkFace, theNonManifold, theStartFace );
3158 bool isDone = false;
3159 while ( !isDone && aMapOfBoundary.size() != 0 )
3161 bool isToReset = false;
3162 ManifoldPart::TVectorOfLink::iterator pLink = aSeqOfBoundary.begin();
3163 for ( ; !isToReset && pLink != aSeqOfBoundary.end(); ++pLink )
3165 ManifoldPart::Link aLink = *pLink;
3166 if ( aMapToSkip.find( aLink ) != aMapToSkip.end() )
3168 // each link could be treated only once
3169 aMapToSkip.insert( aLink );
3171 ManifoldPart::TVectorOfFacePtr aFaces;
3173 if ( myIsOnlyManifold &&
3174 (theNonManifold.find( aLink ) != theNonManifold.end()) )
3178 getFacesByLink( aLink, aFaces );
3179 // filter the element to keep only indicated elements
3180 ManifoldPart::TVectorOfFacePtr aFiltered;
3181 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
3182 for ( ; pFace != aFaces.end(); ++pFace )
3184 SMDS_MeshFace* aFace = *pFace;
3185 if ( myAllFacePtrIntDMap.find( aFace ) != myAllFacePtrIntDMap.end() )
3186 aFiltered.push_back( aFace );
3189 if ( aFaces.size() < 2 ) // no neihgbour faces
3191 else if ( myIsOnlyManifold && aFaces.size() > 2 ) // non manifold case
3193 theNonManifold.insert( aLink );
3198 // compare normal with normals of neighbor element
3199 SMDS_MeshFace* aPrevFace = aDMapLinkFace[ aLink ];
3200 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
3201 for ( ; pFace != aFaces.end(); ++pFace )
3203 SMDS_MeshFace* aNextFace = *pFace;
3204 if ( aPrevFace == aNextFace )
3206 int anNextFaceID = aNextFace->GetID();
3207 if ( myIsOnlyManifold && theResFaces.Contains( anNextFaceID ) )
3208 // should not be with non manifold restriction. probably bad topology
3210 // check if face was treated and skipped
3211 if ( myMapBadGeomIds.Contains( anNextFaceID ) ||
3212 !isInPlane( aPrevFace, aNextFace ) )
3214 // add new element to connected and extend the boundaries.
3215 theResFaces.Add( anNextFaceID );
3216 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
3217 aDMapLinkFace, theNonManifold, aNextFace );
3221 isDone = !isToReset;
3224 return !theResFaces.IsEmpty();
3227 bool ManifoldPart::isInPlane( const SMDS_MeshFace* theFace1,
3228 const SMDS_MeshFace* theFace2 )
3230 gp_Dir aNorm1 = gp_Dir( getNormale( theFace1 ) );
3231 gp_XYZ aNorm2XYZ = getNormale( theFace2 );
3232 if ( aNorm2XYZ.SquareModulus() <= gp::Resolution() )
3234 myMapBadGeomIds.Add( theFace2->GetID() );
3237 if ( aNorm1.IsParallel( gp_Dir( aNorm2XYZ ), myAngToler ) )
3243 void ManifoldPart::expandBoundary
3244 ( ManifoldPart::TMapOfLink& theMapOfBoundary,
3245 ManifoldPart::TVectorOfLink& theSeqOfBoundary,
3246 ManifoldPart::TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
3247 ManifoldPart::TMapOfLink& theNonManifold,
3248 SMDS_MeshFace* theNextFace ) const
3250 ManifoldPart::TVectorOfLink aLinks;
3251 getLinks( theNextFace, aLinks );
3252 int aNbLink = (int)aLinks.size();
3253 for ( int i = 0; i < aNbLink; i++ )
3255 ManifoldPart::Link aLink = aLinks[ i ];
3256 if ( myIsOnlyManifold && (theNonManifold.find( aLink ) != theNonManifold.end()) )
3258 if ( theMapOfBoundary.find( aLink ) != theMapOfBoundary.end() )
3260 if ( myIsOnlyManifold )
3262 // remove from boundary
3263 theMapOfBoundary.erase( aLink );
3264 ManifoldPart::TVectorOfLink::iterator pLink = theSeqOfBoundary.begin();
3265 for ( ; pLink != theSeqOfBoundary.end(); ++pLink )
3267 ManifoldPart::Link aBoundLink = *pLink;
3268 if ( aBoundLink.IsEqual( aLink ) )
3270 theSeqOfBoundary.erase( pLink );
3278 theMapOfBoundary.insert( aLink );
3279 theSeqOfBoundary.push_back( aLink );
3280 theDMapLinkFacePtr[ aLink ] = theNextFace;
3285 void ManifoldPart::getFacesByLink( const ManifoldPart::Link& theLink,
3286 ManifoldPart::TVectorOfFacePtr& theFaces ) const
3288 SMDS_Mesh::SetOfFaces aSetOfFaces;
3289 // take all faces that shared first node
3290 SMDS_ElemIteratorPtr anItr = theLink.myNode1->facesIterator();
3291 for ( ; anItr->more(); )
3293 SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
3296 aSetOfFaces.Add( aFace );
3298 // take all faces that shared second node
3299 anItr = theLink.myNode2->facesIterator();
3300 // find the common part of two sets
3301 for ( ; anItr->more(); )
3303 SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
3304 if ( aSetOfFaces.Contains( aFace ) )
3305 theFaces.push_back( aFace );
3314 ElementsOnSurface::ElementsOnSurface()
3318 myType = SMDSAbs_All;
3320 myToler = Precision::Confusion();
3321 myUseBoundaries = false;
3324 ElementsOnSurface::~ElementsOnSurface()
3329 void ElementsOnSurface::SetMesh( const SMDS_Mesh* theMesh )
3331 if ( myMesh == theMesh )
3337 bool ElementsOnSurface::IsSatisfy( long theElementId )
3339 return myIds.Contains( theElementId );
3342 SMDSAbs_ElementType ElementsOnSurface::GetType() const
3345 void ElementsOnSurface::SetTolerance( const double theToler )
3347 if ( myToler != theToler )
3352 double ElementsOnSurface::GetTolerance() const
3355 void ElementsOnSurface::SetUseBoundaries( bool theUse )
3357 if ( myUseBoundaries != theUse ) {
3358 myUseBoundaries = theUse;
3359 SetSurface( mySurf, myType );
3363 void ElementsOnSurface::SetSurface( const TopoDS_Shape& theShape,
3364 const SMDSAbs_ElementType theType )
3369 if ( theShape.IsNull() || theShape.ShapeType() != TopAbs_FACE )
3371 mySurf = TopoDS::Face( theShape );
3372 BRepAdaptor_Surface SA( mySurf, myUseBoundaries );
3374 u1 = SA.FirstUParameter(),
3375 u2 = SA.LastUParameter(),
3376 v1 = SA.FirstVParameter(),
3377 v2 = SA.LastVParameter();
3378 Handle(Geom_Surface) surf = BRep_Tool::Surface( mySurf );
3379 myProjector.Init( surf, u1,u2, v1,v2 );
3383 void ElementsOnSurface::process()
3386 if ( mySurf.IsNull() )
3392 if ( myType == SMDSAbs_Face || myType == SMDSAbs_All )
3394 myIds.ReSize( myMesh->NbFaces() );
3395 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
3396 for(; anIter->more(); )
3397 process( anIter->next() );
3400 if ( myType == SMDSAbs_Edge || myType == SMDSAbs_All )
3402 myIds.ReSize( myIds.Extent() + myMesh->NbEdges() );
3403 SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
3404 for(; anIter->more(); )
3405 process( anIter->next() );
3408 if ( myType == SMDSAbs_Node )
3410 myIds.ReSize( myMesh->NbNodes() );
3411 SMDS_NodeIteratorPtr anIter = myMesh->nodesIterator();
3412 for(; anIter->more(); )
3413 process( anIter->next() );
3417 void ElementsOnSurface::process( const SMDS_MeshElement* theElemPtr )
3419 SMDS_ElemIteratorPtr aNodeItr = theElemPtr->nodesIterator();
3420 bool isSatisfy = true;
3421 for ( ; aNodeItr->more(); )
3423 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
3424 if ( !isOnSurface( aNode ) )
3431 myIds.Add( theElemPtr->GetID() );
3434 bool ElementsOnSurface::isOnSurface( const SMDS_MeshNode* theNode )
3436 if ( mySurf.IsNull() )
3439 gp_Pnt aPnt( theNode->X(), theNode->Y(), theNode->Z() );
3440 // double aToler2 = myToler * myToler;
3441 // if ( mySurf->IsKind(STANDARD_TYPE(Geom_Plane)))
3443 // gp_Pln aPln = Handle(Geom_Plane)::DownCast(mySurf)->Pln();
3444 // if ( aPln.SquareDistance( aPnt ) > aToler2 )
3447 // else if ( mySurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)))
3449 // gp_Cylinder aCyl = Handle(Geom_CylindricalSurface)::DownCast(mySurf)->Cylinder();
3450 // double aRad = aCyl.Radius();
3451 // gp_Ax3 anAxis = aCyl.Position();
3452 // gp_XYZ aLoc = aCyl.Location().XYZ();
3453 // double aXDist = anAxis.XDirection().XYZ() * ( aPnt.XYZ() - aLoc );
3454 // double aYDist = anAxis.YDirection().XYZ() * ( aPnt.XYZ() - aLoc );
3455 // if ( fabs(aXDist*aXDist + aYDist*aYDist - aRad*aRad) > aToler2 )
3460 myProjector.Perform( aPnt );
3461 bool isOn = ( myProjector.IsDone() && myProjector.LowerDistance() <= myToler );
3471 ElementsOnShape::ElementsOnShape()
3473 myType(SMDSAbs_All),
3474 myToler(Precision::Confusion()),
3475 myAllNodesFlag(false)
3477 myCurShapeType = TopAbs_SHAPE;
3480 ElementsOnShape::~ElementsOnShape()
3484 void ElementsOnShape::SetMesh (const SMDS_Mesh* theMesh)
3486 if (myMesh != theMesh) {
3488 SetShape(myShape, myType);
3492 bool ElementsOnShape::IsSatisfy (long theElementId)
3494 return myIds.Contains(theElementId);
3497 SMDSAbs_ElementType ElementsOnShape::GetType() const
3502 void ElementsOnShape::SetTolerance (const double theToler)
3504 if (myToler != theToler) {
3506 SetShape(myShape, myType);
3510 double ElementsOnShape::GetTolerance() const
3515 void ElementsOnShape::SetAllNodes (bool theAllNodes)
3517 if (myAllNodesFlag != theAllNodes) {
3518 myAllNodesFlag = theAllNodes;
3519 SetShape(myShape, myType);
3523 void ElementsOnShape::SetShape (const TopoDS_Shape& theShape,
3524 const SMDSAbs_ElementType theType)
3530 if (myMesh == 0) return;
3535 myIds.ReSize(myMesh->NbEdges() + myMesh->NbFaces() + myMesh->NbVolumes());
3538 myIds.ReSize(myMesh->NbNodes());
3541 myIds.ReSize(myMesh->NbEdges());
3544 myIds.ReSize(myMesh->NbFaces());
3546 case SMDSAbs_Volume:
3547 myIds.ReSize(myMesh->NbVolumes());
3553 myShapesMap.Clear();
3557 void ElementsOnShape::addShape (const TopoDS_Shape& theShape)
3559 if (theShape.IsNull() || myMesh == 0)
3562 if (!myShapesMap.Add(theShape)) return;
3564 myCurShapeType = theShape.ShapeType();
3565 switch (myCurShapeType)
3567 case TopAbs_COMPOUND:
3568 case TopAbs_COMPSOLID:
3572 TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
3573 for (; anIt.More(); anIt.Next()) addShape(anIt.Value());
3578 myCurSC.Load(theShape);
3584 TopoDS_Face aFace = TopoDS::Face(theShape);
3585 BRepAdaptor_Surface SA (aFace, true);
3587 u1 = SA.FirstUParameter(),
3588 u2 = SA.LastUParameter(),
3589 v1 = SA.FirstVParameter(),
3590 v2 = SA.LastVParameter();
3591 Handle(Geom_Surface) surf = BRep_Tool::Surface(aFace);
3592 myCurProjFace.Init(surf, u1,u2, v1,v2);
3599 TopoDS_Edge anEdge = TopoDS::Edge(theShape);
3600 Standard_Real u1, u2;
3601 Handle(Geom_Curve) curve = BRep_Tool::Curve(anEdge, u1, u2);
3602 myCurProjEdge.Init(curve, u1, u2);
3608 TopoDS_Vertex aV = TopoDS::Vertex(theShape);
3609 myCurPnt = BRep_Tool::Pnt(aV);
3618 void ElementsOnShape::process()
3620 if (myShape.IsNull() || myMesh == 0)
3623 if (myType == SMDSAbs_Node)
3625 SMDS_NodeIteratorPtr anIter = myMesh->nodesIterator();
3626 while (anIter->more())
3627 process(anIter->next());
3631 if (myType == SMDSAbs_Edge || myType == SMDSAbs_All)
3633 SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
3634 while (anIter->more())
3635 process(anIter->next());
3638 if (myType == SMDSAbs_Face || myType == SMDSAbs_All)
3640 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
3641 while (anIter->more()) {
3642 process(anIter->next());
3646 if (myType == SMDSAbs_Volume || myType == SMDSAbs_All)
3648 SMDS_VolumeIteratorPtr anIter = myMesh->volumesIterator();
3649 while (anIter->more())
3650 process(anIter->next());
3655 void ElementsOnShape::process (const SMDS_MeshElement* theElemPtr)
3657 if (myShape.IsNull())
3660 SMDS_ElemIteratorPtr aNodeItr = theElemPtr->nodesIterator();
3661 bool isSatisfy = myAllNodesFlag;
3663 gp_XYZ centerXYZ (0, 0, 0);
3665 while (aNodeItr->more() && (isSatisfy == myAllNodesFlag))
3667 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
3668 gp_Pnt aPnt (aNode->X(), aNode->Y(), aNode->Z());
3669 centerXYZ += aPnt.XYZ();
3671 switch (myCurShapeType)
3675 myCurSC.Perform(aPnt, myToler);
3676 isSatisfy = (myCurSC.State() == TopAbs_IN || myCurSC.State() == TopAbs_ON);
3681 myCurProjFace.Perform(aPnt);
3682 isSatisfy = (myCurProjFace.IsDone() && myCurProjFace.LowerDistance() <= myToler);
3685 // check relatively the face
3686 Quantity_Parameter u, v;
3687 myCurProjFace.LowerDistanceParameters(u, v);
3688 gp_Pnt2d aProjPnt (u, v);
3689 BRepClass_FaceClassifier aClsf (myCurFace, aProjPnt, myToler);
3690 isSatisfy = (aClsf.State() == TopAbs_IN || aClsf.State() == TopAbs_ON);
3696 myCurProjEdge.Perform(aPnt);
3697 isSatisfy = (myCurProjEdge.NbPoints() > 0 && myCurProjEdge.LowerDistance() <= myToler);
3702 isSatisfy = (aPnt.Distance(myCurPnt) <= myToler);
3712 if (isSatisfy && myCurShapeType == TopAbs_SOLID) { // Check the center point for volumes MantisBug 0020168
3713 centerXYZ /= theElemPtr->NbNodes();
3714 gp_Pnt aCenterPnt (centerXYZ);
3715 myCurSC.Perform(aCenterPnt, myToler);
3716 if ( !(myCurSC.State() == TopAbs_IN || myCurSC.State() == TopAbs_ON))
3721 myIds.Add(theElemPtr->GetID());
3724 TSequenceOfXYZ::TSequenceOfXYZ()
3727 TSequenceOfXYZ::TSequenceOfXYZ(size_type n) : myArray(n)
3730 TSequenceOfXYZ::TSequenceOfXYZ(size_type n, const gp_XYZ& t) : myArray(n,t)
3733 TSequenceOfXYZ::TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ) : myArray(theSequenceOfXYZ.myArray)
3736 template <class InputIterator>
3737 TSequenceOfXYZ::TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd): myArray(theBegin,theEnd)
3740 TSequenceOfXYZ::~TSequenceOfXYZ()
3743 TSequenceOfXYZ& TSequenceOfXYZ::operator=(const TSequenceOfXYZ& theSequenceOfXYZ)
3745 myArray = theSequenceOfXYZ.myArray;
3749 gp_XYZ& TSequenceOfXYZ::operator()(size_type n)
3751 return myArray[n-1];
3754 const gp_XYZ& TSequenceOfXYZ::operator()(size_type n) const
3756 return myArray[n-1];
3759 void TSequenceOfXYZ::clear()
3764 void TSequenceOfXYZ::reserve(size_type n)
3769 void TSequenceOfXYZ::push_back(const gp_XYZ& v)
3771 myArray.push_back(v);
3774 TSequenceOfXYZ::size_type TSequenceOfXYZ::size() const
3776 return myArray.size();