1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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"
25 #include "SMDS_BallElement.hxx"
26 #include "SMDS_FacePosition.hxx"
27 #include "SMDS_Iterator.hxx"
28 #include "SMDS_Mesh.hxx"
29 #include "SMDS_MeshElement.hxx"
30 #include "SMDS_MeshNode.hxx"
31 #include "SMDS_VolumeTool.hxx"
32 #include "SMESHDS_GroupBase.hxx"
33 #include "SMESHDS_GroupOnFilter.hxx"
34 #include "SMESHDS_Mesh.hxx"
35 #include "SMESH_MeshAlgos.hxx"
36 #include "SMESH_OctreeNode.hxx"
38 #include <Basics_Utils.hxx>
40 #include <BRepAdaptor_Surface.hxx>
41 #include <BRepBndLib.hxx>
42 #include <BRepBuilderAPI_Copy.hxx>
43 #include <BRepClass3d_SolidClassifier.hxx>
44 #include <BRepClass_FaceClassifier.hxx>
45 #include <BRep_Tool.hxx>
46 #include <GeomLib_IsPlanarSurface.hxx>
47 #include <Geom_CylindricalSurface.hxx>
48 #include <Geom_Plane.hxx>
49 #include <Geom_Surface.hxx>
50 #include <NCollection_Map.hxx>
51 #include <Precision.hxx>
52 #include <ShapeAnalysis_Surface.hxx>
53 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
54 #include <TColStd_MapOfInteger.hxx>
55 #include <TColStd_SequenceOfAsciiString.hxx>
56 #include <TColgp_Array1OfXYZ.hxx>
60 #include <TopoDS_Edge.hxx>
61 #include <TopoDS_Face.hxx>
62 #include <TopoDS_Iterator.hxx>
63 #include <TopoDS_Shape.hxx>
64 #include <TopoDS_Vertex.hxx>
66 #include <gp_Cylinder.hxx>
73 #include <vtkMeshQuality.h>
84 const double theEps = 1e-100;
85 const double theInf = 1e+100;
87 inline gp_XYZ gpXYZ(const SMDS_MeshNode* aNode )
89 return gp_XYZ(aNode->X(), aNode->Y(), aNode->Z() );
92 inline double getAngle( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
94 gp_Vec v1( P1 - P2 ), v2( P3 - P2 );
96 return v1.Magnitude() < gp::Resolution() ||
97 v2.Magnitude() < gp::Resolution() ? 0 : v1.Angle( v2 );
100 inline double getCos2( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
102 gp_Vec v1( P1 - P2 ), v2( P3 - P2 );
103 double dot = v1 * v2, len1 = v1.SquareMagnitude(), len2 = v2.SquareMagnitude();
105 return ( dot < 0 || len1 < gp::Resolution() || len2 < gp::Resolution() ? -1 :
106 dot * dot / len1 / len2 );
109 inline double getArea( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
111 gp_Vec aVec1( P2 - P1 );
112 gp_Vec aVec2( P3 - P1 );
113 return ( aVec1 ^ aVec2 ).Magnitude() * 0.5;
116 inline double getArea( const gp_Pnt& P1, const gp_Pnt& P2, const gp_Pnt& P3 )
118 return getArea( P1.XYZ(), P2.XYZ(), P3.XYZ() );
123 inline double getDistance( const gp_XYZ& P1, const gp_XYZ& P2 )
125 double aDist = gp_Pnt( P1 ).Distance( gp_Pnt( P2 ) );
129 int getNbMultiConnection( const SMDS_Mesh* theMesh, const int theId )
134 const SMDS_MeshElement* anEdge = theMesh->FindElement( theId );
135 if ( anEdge == 0 || anEdge->GetType() != SMDSAbs_Edge/* || anEdge->NbNodes() != 2 */)
138 // for each pair of nodes in anEdge (there are 2 pairs in a quadratic edge)
139 // count elements containing both nodes of the pair.
140 // Note that there may be such cases for a quadratic edge (a horizontal line):
145 // +-----+------+ +-----+------+
148 // result should be 2 in both cases
150 int aResult0 = 0, aResult1 = 0;
151 // last node, it is a medium one in a quadratic edge
152 const SMDS_MeshNode* aLastNode = anEdge->GetNode( anEdge->NbNodes() - 1 );
153 const SMDS_MeshNode* aNode0 = anEdge->GetNode( 0 );
154 const SMDS_MeshNode* aNode1 = anEdge->GetNode( 1 );
155 if ( aNode1 == aLastNode ) aNode1 = 0;
157 SMDS_ElemIteratorPtr anElemIter = aLastNode->GetInverseElementIterator();
158 while( anElemIter->more() ) {
159 const SMDS_MeshElement* anElem = anElemIter->next();
160 if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) {
161 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
162 while ( anIter->more() ) {
163 if ( const SMDS_MeshElement* anElemNode = anIter->next() ) {
164 if ( anElemNode == aNode0 ) {
166 if ( !aNode1 ) break; // not a quadratic edge
168 else if ( anElemNode == aNode1 )
174 int aResult = std::max ( aResult0, aResult1 );
179 gp_XYZ getNormale( const SMDS_MeshFace* theFace, bool* ok=0 )
181 int aNbNode = theFace->NbNodes();
183 gp_XYZ q1 = gpXYZ( theFace->GetNode(1)) - gpXYZ( theFace->GetNode(0));
184 gp_XYZ q2 = gpXYZ( theFace->GetNode(2)) - gpXYZ( theFace->GetNode(0));
187 gp_XYZ q3 = gpXYZ( theFace->GetNode(3)) - gpXYZ( theFace->GetNode(0));
190 double len = n.Modulus();
191 bool zeroLen = ( len <= std::numeric_limits<double>::min());
195 if (ok) *ok = !zeroLen;
203 using namespace SMESH::Controls;
209 //================================================================================
211 Class : NumericalFunctor
212 Description : Base class for numerical functors
214 //================================================================================
216 NumericalFunctor::NumericalFunctor():
222 void NumericalFunctor::SetMesh( const SMDS_Mesh* theMesh )
227 bool NumericalFunctor::GetPoints(const int theId,
228 TSequenceOfXYZ& theRes ) const
235 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
236 if ( !anElem || anElem->GetType() != this->GetType() )
239 return GetPoints( anElem, theRes );
242 bool NumericalFunctor::GetPoints(const SMDS_MeshElement* anElem,
243 TSequenceOfXYZ& theRes )
250 theRes.reserve( anElem->NbNodes() );
251 theRes.setElement( anElem );
253 // Get nodes of the element
254 SMDS_NodeIteratorPtr anIter= anElem->interlacedNodesIterator();
257 while( anIter->more() ) {
258 if ( p.Set( anIter->next() ))
259 theRes.push_back( p );
266 long NumericalFunctor::GetPrecision() const
271 void NumericalFunctor::SetPrecision( const long thePrecision )
273 myPrecision = thePrecision;
274 myPrecisionValue = pow( 10., (double)( myPrecision ) );
277 double NumericalFunctor::GetValue( long theId )
281 myCurrElement = myMesh->FindElement( theId );
284 if ( GetPoints( theId, P )) // elem type is checked here
285 aVal = Round( GetValue( P ));
290 double NumericalFunctor::Round( const double & aVal )
292 return ( myPrecision >= 0 ) ? floor( aVal * myPrecisionValue + 0.5 ) / myPrecisionValue : aVal;
295 //================================================================================
297 * \brief Return histogram of functor values
298 * \param nbIntervals - number of intervals
299 * \param nbEvents - number of mesh elements having values within i-th interval
300 * \param funValues - boundaries of intervals
301 * \param elements - elements to check vulue of; empty list means "of all"
302 * \param minmax - boundaries of diapason of values to divide into intervals
304 //================================================================================
306 void NumericalFunctor::GetHistogram(int nbIntervals,
307 std::vector<int>& nbEvents,
308 std::vector<double>& funValues,
309 const std::vector<int>& elements,
310 const double* minmax,
311 const bool isLogarithmic)
313 if ( nbIntervals < 1 ||
315 !myMesh->GetMeshInfo().NbElements( GetType() ))
317 nbEvents.resize( nbIntervals, 0 );
318 funValues.resize( nbIntervals+1 );
320 // get all values sorted
321 std::multiset< double > values;
322 if ( elements.empty() )
324 SMDS_ElemIteratorPtr elemIt = myMesh->elementsIterator( GetType() );
325 while ( elemIt->more() )
326 values.insert( GetValue( elemIt->next()->GetID() ));
330 std::vector<int>::const_iterator id = elements.begin();
331 for ( ; id != elements.end(); ++id )
332 values.insert( GetValue( *id ));
337 funValues[0] = minmax[0];
338 funValues[nbIntervals] = minmax[1];
342 funValues[0] = *values.begin();
343 funValues[nbIntervals] = *values.rbegin();
345 // case nbIntervals == 1
346 if ( nbIntervals == 1 )
348 nbEvents[0] = values.size();
352 if (funValues.front() == funValues.back())
354 nbEvents.resize( 1 );
355 nbEvents[0] = values.size();
356 funValues[1] = funValues.back();
357 funValues.resize( 2 );
360 std::multiset< double >::iterator min = values.begin(), max;
361 for ( int i = 0; i < nbIntervals; ++i )
363 // find end value of i-th interval
364 double r = (i+1) / double(nbIntervals);
365 if (isLogarithmic && funValues.front() > 1e-07 && funValues.back() > 1e-07) {
366 double logmin = log10(funValues.front());
367 double lval = logmin + r * (log10(funValues.back()) - logmin);
368 funValues[i+1] = pow(10.0, lval);
371 funValues[i+1] = funValues.front() * (1-r) + funValues.back() * r;
374 // count values in the i-th interval if there are any
375 if ( min != values.end() && *min <= funValues[i+1] )
377 // find the first value out of the interval
378 max = values.upper_bound( funValues[i+1] ); // max is greater than funValues[i+1], or end()
379 nbEvents[i] = std::distance( min, max );
383 // add values larger than minmax[1]
384 nbEvents.back() += std::distance( min, values.end() );
387 //=======================================================================
390 Description : Functor calculating volume of a 3D element
392 //================================================================================
394 double Volume::GetValue( long theElementId )
396 if ( theElementId && myMesh ) {
397 SMDS_VolumeTool aVolumeTool;
398 if ( aVolumeTool.Set( myMesh->FindElement( theElementId )))
399 return aVolumeTool.GetSize();
404 double Volume::GetBadRate( double Value, int /*nbNodes*/ ) const
409 SMDSAbs_ElementType Volume::GetType() const
411 return SMDSAbs_Volume;
414 //=======================================================================
416 Class : MaxElementLength2D
417 Description : Functor calculating maximum length of 2D element
419 //================================================================================
421 double MaxElementLength2D::GetValue( const TSequenceOfXYZ& P )
427 if( len == 3 ) { // triangles
428 double L1 = getDistance(P( 1 ),P( 2 ));
429 double L2 = getDistance(P( 2 ),P( 3 ));
430 double L3 = getDistance(P( 3 ),P( 1 ));
431 aVal = Max(L1,Max(L2,L3));
433 else if( len == 4 ) { // quadrangles
434 double L1 = getDistance(P( 1 ),P( 2 ));
435 double L2 = getDistance(P( 2 ),P( 3 ));
436 double L3 = getDistance(P( 3 ),P( 4 ));
437 double L4 = getDistance(P( 4 ),P( 1 ));
438 double D1 = getDistance(P( 1 ),P( 3 ));
439 double D2 = getDistance(P( 2 ),P( 4 ));
440 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(D1,D2));
442 else if( len == 6 ) { // quadratic triangles
443 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
444 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
445 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 1 ));
446 aVal = Max(L1,Max(L2,L3));
448 else if( len == 8 || len == 9 ) { // quadratic quadrangles
449 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
450 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
451 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 7 ));
452 double L4 = getDistance(P( 7 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
453 double D1 = getDistance(P( 1 ),P( 5 ));
454 double D2 = getDistance(P( 3 ),P( 7 ));
455 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(D1,D2));
457 // Diagonals are undefined for concave polygons
458 // else if ( P.getElementEntity() == SMDSEntity_Quad_Polygon && P.size() > 2 ) // quad polygon
461 // aVal = getDistance( P( 1 ), P( P.size() )) + getDistance( P( P.size() ), P( P.size()-1 ));
462 // for ( size_t i = 1; i < P.size()-1; i += 2 )
464 // double L = getDistance( P( i ), P( i+1 )) + getDistance( P( i+1 ), P( i+2 ));
465 // aVal = Max( aVal, L );
468 // for ( int i = P.size()-5; i > 0; i -= 2 )
469 // for ( int j = i + 4; j < P.size() + i - 2; i += 2 )
471 // double D = getDistance( P( i ), P( j ));
472 // aVal = Max( aVal, D );
479 if( myPrecision >= 0 )
481 double prec = pow( 10., (double)myPrecision );
482 aVal = floor( aVal * prec + 0.5 ) / prec;
487 double MaxElementLength2D::GetValue( long theElementId )
490 return GetPoints( theElementId, P ) ? GetValue(P) : 0.0;
493 double MaxElementLength2D::GetBadRate( double Value, int /*nbNodes*/ ) const
498 SMDSAbs_ElementType MaxElementLength2D::GetType() const
503 //=======================================================================
505 Class : MaxElementLength3D
506 Description : Functor calculating maximum length of 3D element
508 //================================================================================
510 double MaxElementLength3D::GetValue( long theElementId )
513 if( GetPoints( theElementId, P ) ) {
515 const SMDS_MeshElement* aElem = myMesh->FindElement( theElementId );
516 SMDSAbs_EntityType aType = aElem->GetEntityType();
519 case SMDSEntity_Tetra: { // tetras
520 double L1 = getDistance(P( 1 ),P( 2 ));
521 double L2 = getDistance(P( 2 ),P( 3 ));
522 double L3 = getDistance(P( 3 ),P( 1 ));
523 double L4 = getDistance(P( 1 ),P( 4 ));
524 double L5 = getDistance(P( 2 ),P( 4 ));
525 double L6 = getDistance(P( 3 ),P( 4 ));
526 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
529 case SMDSEntity_Pyramid: { // pyramids
530 double L1 = getDistance(P( 1 ),P( 2 ));
531 double L2 = getDistance(P( 2 ),P( 3 ));
532 double L3 = getDistance(P( 3 ),P( 4 ));
533 double L4 = getDistance(P( 4 ),P( 1 ));
534 double L5 = getDistance(P( 1 ),P( 5 ));
535 double L6 = getDistance(P( 2 ),P( 5 ));
536 double L7 = getDistance(P( 3 ),P( 5 ));
537 double L8 = getDistance(P( 4 ),P( 5 ));
538 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
539 aVal = Max(aVal,Max(L7,L8));
542 case SMDSEntity_Penta: { // pentas
543 double L1 = getDistance(P( 1 ),P( 2 ));
544 double L2 = getDistance(P( 2 ),P( 3 ));
545 double L3 = getDistance(P( 3 ),P( 1 ));
546 double L4 = getDistance(P( 4 ),P( 5 ));
547 double L5 = getDistance(P( 5 ),P( 6 ));
548 double L6 = getDistance(P( 6 ),P( 4 ));
549 double L7 = getDistance(P( 1 ),P( 4 ));
550 double L8 = getDistance(P( 2 ),P( 5 ));
551 double L9 = getDistance(P( 3 ),P( 6 ));
552 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
553 aVal = Max(aVal,Max(Max(L7,L8),L9));
556 case SMDSEntity_Hexa: { // hexas
557 double L1 = getDistance(P( 1 ),P( 2 ));
558 double L2 = getDistance(P( 2 ),P( 3 ));
559 double L3 = getDistance(P( 3 ),P( 4 ));
560 double L4 = getDistance(P( 4 ),P( 1 ));
561 double L5 = getDistance(P( 5 ),P( 6 ));
562 double L6 = getDistance(P( 6 ),P( 7 ));
563 double L7 = getDistance(P( 7 ),P( 8 ));
564 double L8 = getDistance(P( 8 ),P( 5 ));
565 double L9 = getDistance(P( 1 ),P( 5 ));
566 double L10= getDistance(P( 2 ),P( 6 ));
567 double L11= getDistance(P( 3 ),P( 7 ));
568 double L12= getDistance(P( 4 ),P( 8 ));
569 double D1 = getDistance(P( 1 ),P( 7 ));
570 double D2 = getDistance(P( 2 ),P( 8 ));
571 double D3 = getDistance(P( 3 ),P( 5 ));
572 double D4 = getDistance(P( 4 ),P( 6 ));
573 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
574 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
575 aVal = Max(aVal,Max(L11,L12));
576 aVal = Max(aVal,Max(Max(D1,D2),Max(D3,D4)));
579 case SMDSEntity_Hexagonal_Prism: { // hexagonal prism
580 for ( int i1 = 1; i1 < 12; ++i1 )
581 for ( int i2 = i1+1; i1 <= 12; ++i1 )
582 aVal = Max( aVal, getDistance(P( i1 ),P( i2 )));
585 case SMDSEntity_Quad_Tetra: { // quadratic tetras
586 double L1 = getDistance(P( 1 ),P( 5 )) + getDistance(P( 5 ),P( 2 ));
587 double L2 = getDistance(P( 2 ),P( 6 )) + getDistance(P( 6 ),P( 3 ));
588 double L3 = getDistance(P( 3 ),P( 7 )) + getDistance(P( 7 ),P( 1 ));
589 double L4 = getDistance(P( 1 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
590 double L5 = getDistance(P( 2 ),P( 9 )) + getDistance(P( 9 ),P( 4 ));
591 double L6 = getDistance(P( 3 ),P( 10 )) + getDistance(P( 10 ),P( 4 ));
592 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
595 case SMDSEntity_Quad_Pyramid: { // quadratic pyramids
596 double L1 = getDistance(P( 1 ),P( 6 )) + getDistance(P( 6 ),P( 2 ));
597 double L2 = getDistance(P( 2 ),P( 7 )) + getDistance(P( 7 ),P( 3 ));
598 double L3 = getDistance(P( 3 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
599 double L4 = getDistance(P( 4 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
600 double L5 = getDistance(P( 1 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
601 double L6 = getDistance(P( 2 ),P( 11 )) + getDistance(P( 11 ),P( 5 ));
602 double L7 = getDistance(P( 3 ),P( 12 )) + getDistance(P( 12 ),P( 5 ));
603 double L8 = getDistance(P( 4 ),P( 13 )) + getDistance(P( 13 ),P( 5 ));
604 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
605 aVal = Max(aVal,Max(L7,L8));
608 case SMDSEntity_Quad_Penta:
609 case SMDSEntity_BiQuad_Penta: { // quadratic pentas
610 double L1 = getDistance(P( 1 ),P( 7 )) + getDistance(P( 7 ),P( 2 ));
611 double L2 = getDistance(P( 2 ),P( 8 )) + getDistance(P( 8 ),P( 3 ));
612 double L3 = getDistance(P( 3 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
613 double L4 = getDistance(P( 4 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
614 double L5 = getDistance(P( 5 ),P( 11 )) + getDistance(P( 11 ),P( 6 ));
615 double L6 = getDistance(P( 6 ),P( 12 )) + getDistance(P( 12 ),P( 4 ));
616 double L7 = getDistance(P( 1 ),P( 13 )) + getDistance(P( 13 ),P( 4 ));
617 double L8 = getDistance(P( 2 ),P( 14 )) + getDistance(P( 14 ),P( 5 ));
618 double L9 = getDistance(P( 3 ),P( 15 )) + getDistance(P( 15 ),P( 6 ));
619 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
620 aVal = Max(aVal,Max(Max(L7,L8),L9));
623 case SMDSEntity_Quad_Hexa:
624 case SMDSEntity_TriQuad_Hexa: { // quadratic hexas
625 double L1 = getDistance(P( 1 ),P( 9 )) + getDistance(P( 9 ),P( 2 ));
626 double L2 = getDistance(P( 2 ),P( 10 )) + getDistance(P( 10 ),P( 3 ));
627 double L3 = getDistance(P( 3 ),P( 11 )) + getDistance(P( 11 ),P( 4 ));
628 double L4 = getDistance(P( 4 ),P( 12 )) + getDistance(P( 12 ),P( 1 ));
629 double L5 = getDistance(P( 5 ),P( 13 )) + getDistance(P( 13 ),P( 6 ));
630 double L6 = getDistance(P( 6 ),P( 14 )) + getDistance(P( 14 ),P( 7 ));
631 double L7 = getDistance(P( 7 ),P( 15 )) + getDistance(P( 15 ),P( 8 ));
632 double L8 = getDistance(P( 8 ),P( 16 )) + getDistance(P( 16 ),P( 5 ));
633 double L9 = getDistance(P( 1 ),P( 17 )) + getDistance(P( 17 ),P( 5 ));
634 double L10= getDistance(P( 2 ),P( 18 )) + getDistance(P( 18 ),P( 6 ));
635 double L11= getDistance(P( 3 ),P( 19 )) + getDistance(P( 19 ),P( 7 ));
636 double L12= getDistance(P( 4 ),P( 20 )) + getDistance(P( 20 ),P( 8 ));
637 double D1 = getDistance(P( 1 ),P( 7 ));
638 double D2 = getDistance(P( 2 ),P( 8 ));
639 double D3 = getDistance(P( 3 ),P( 5 ));
640 double D4 = getDistance(P( 4 ),P( 6 ));
641 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
642 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
643 aVal = Max(aVal,Max(L11,L12));
644 aVal = Max(aVal,Max(Max(D1,D2),Max(D3,D4)));
647 case SMDSEntity_Quad_Polyhedra:
648 case SMDSEntity_Polyhedra: { // polys
649 // get the maximum distance between all pairs of nodes
650 for( int i = 1; i <= len; i++ ) {
651 for( int j = 1; j <= len; j++ ) {
652 if( j > i ) { // optimization of the loop
653 double D = getDistance( P(i), P(j) );
654 aVal = Max( aVal, D );
660 case SMDSEntity_Node:
662 case SMDSEntity_Edge:
663 case SMDSEntity_Quad_Edge:
664 case SMDSEntity_Triangle:
665 case SMDSEntity_Quad_Triangle:
666 case SMDSEntity_BiQuad_Triangle:
667 case SMDSEntity_Quadrangle:
668 case SMDSEntity_Quad_Quadrangle:
669 case SMDSEntity_BiQuad_Quadrangle:
670 case SMDSEntity_Polygon:
671 case SMDSEntity_Quad_Polygon:
672 case SMDSEntity_Ball:
673 case SMDSEntity_Last: return 0;
674 } // switch ( aType )
676 if( myPrecision >= 0 )
678 double prec = pow( 10., (double)myPrecision );
679 aVal = floor( aVal * prec + 0.5 ) / prec;
686 double MaxElementLength3D::GetBadRate( double Value, int /*nbNodes*/ ) const
691 SMDSAbs_ElementType MaxElementLength3D::GetType() const
693 return SMDSAbs_Volume;
696 //=======================================================================
699 Description : Functor for calculation of minimum angle
701 //================================================================================
703 double MinimumAngle::GetValue( const TSequenceOfXYZ& P )
710 aMaxCos2 = getCos2( P( P.size() ), P( 1 ), P( 2 ));
711 aMaxCos2 = Max( aMaxCos2, getCos2( P( P.size()-1 ), P( P.size() ), P( 1 )));
713 for ( size_t i = 2; i < P.size(); i++ )
715 double A0 = getCos2( P( i-1 ), P( i ), P( i+1 ) );
716 aMaxCos2 = Max( aMaxCos2, A0 );
719 return 0; // all nodes coincide
721 double cos = sqrt( aMaxCos2 );
722 if ( cos >= 1 ) return 0;
723 return acos( cos ) * 180.0 / M_PI;
726 double MinimumAngle::GetBadRate( double Value, int nbNodes ) const
728 //const double aBestAngle = PI / nbNodes;
729 const double aBestAngle = 180.0 - ( 360.0 / double(nbNodes) );
730 return ( fabs( aBestAngle - Value ));
733 SMDSAbs_ElementType MinimumAngle::GetType() const
739 //================================================================================
742 Description : Functor for calculating aspect ratio
744 //================================================================================
746 double AspectRatio::GetValue( long theId )
749 myCurrElement = myMesh->FindElement( theId );
750 if ( myCurrElement && myCurrElement->GetVtkType() == VTK_QUAD )
753 vtkUnstructuredGrid* grid = const_cast<SMDS_Mesh*>( myMesh )->GetGrid();
754 if ( vtkCell* avtkCell = grid->GetCell( myCurrElement->GetVtkID() ))
755 aVal = Round( vtkMeshQuality::QuadAspectRatio( avtkCell ));
760 if ( GetPoints( myCurrElement, P ))
761 aVal = Round( GetValue( P ));
766 double AspectRatio::GetValue( const TSequenceOfXYZ& P )
768 // According to "Mesh quality control" by Nadir Bouhamau referring to
769 // Pascal Jean Frey and Paul-Louis George. Maillages, applications aux elements finis.
770 // Hermes Science publications, Paris 1999 ISBN 2-7462-0024-4
773 int nbNodes = P.size();
778 // Compute aspect ratio
780 if ( nbNodes == 3 ) {
781 // Compute lengths of the sides
782 double aLen1 = getDistance( P( 1 ), P( 2 ));
783 double aLen2 = getDistance( P( 2 ), P( 3 ));
784 double aLen3 = getDistance( P( 3 ), P( 1 ));
785 // Q = alfa * h * p / S, where
787 // alfa = sqrt( 3 ) / 6
788 // h - length of the longest edge
789 // p - half perimeter
790 // S - triangle surface
791 const double alfa = sqrt( 3. ) / 6.;
792 double maxLen = Max( aLen1, Max( aLen2, aLen3 ));
793 double half_perimeter = ( aLen1 + aLen2 + aLen3 ) / 2.;
794 double anArea = getArea( P( 1 ), P( 2 ), P( 3 ));
795 if ( anArea <= theEps )
797 return alfa * maxLen * half_perimeter / anArea;
799 else if ( nbNodes == 6 ) { // quadratic triangles
800 // Compute lengths of the sides
801 double aLen1 = getDistance( P( 1 ), P( 3 ));
802 double aLen2 = getDistance( P( 3 ), P( 5 ));
803 double aLen3 = getDistance( P( 5 ), P( 1 ));
804 // algo same as for the linear triangle
805 const double alfa = sqrt( 3. ) / 6.;
806 double maxLen = Max( aLen1, Max( aLen2, aLen3 ));
807 double half_perimeter = ( aLen1 + aLen2 + aLen3 ) / 2.;
808 double anArea = getArea( P( 1 ), P( 3 ), P( 5 ));
809 if ( anArea <= theEps )
811 return alfa * maxLen * half_perimeter / anArea;
813 else if( nbNodes == 4 ) { // quadrangle
814 // Compute lengths of the sides
816 aLen[0] = getDistance( P(1), P(2) );
817 aLen[1] = getDistance( P(2), P(3) );
818 aLen[2] = getDistance( P(3), P(4) );
819 aLen[3] = getDistance( P(4), P(1) );
820 // Compute lengths of the diagonals
822 aDia[0] = getDistance( P(1), P(3) );
823 aDia[1] = getDistance( P(2), P(4) );
824 // Compute areas of all triangles which can be built
825 // taking three nodes of the quadrangle
827 anArea[0] = getArea( P(1), P(2), P(3) );
828 anArea[1] = getArea( P(1), P(2), P(4) );
829 anArea[2] = getArea( P(1), P(3), P(4) );
830 anArea[3] = getArea( P(2), P(3), P(4) );
831 // Q = alpha * L * C1 / C2, where
833 // alpha = sqrt( 1/32 )
834 // L = max( L1, L2, L3, L4, D1, D2 )
835 // C1 = sqrt( ( L1^2 + L1^2 + L1^2 + L1^2 ) / 4 )
836 // C2 = min( S1, S2, S3, S4 )
837 // Li - lengths of the edges
838 // Di - lengths of the diagonals
839 // Si - areas of the triangles
840 const double alpha = sqrt( 1 / 32. );
841 double L = Max( aLen[ 0 ],
845 Max( aDia[ 0 ], aDia[ 1 ] ) ) ) ) );
846 double C1 = sqrt( ( aLen[0] * aLen[0] +
849 aLen[3] * aLen[3] ) / 4. );
850 double C2 = Min( anArea[ 0 ],
852 Min( anArea[ 2 ], anArea[ 3 ] ) ) );
855 return alpha * L * C1 / C2;
857 else if( nbNodes == 8 || nbNodes == 9 ) { // nbNodes==8 - quadratic quadrangle
858 // Compute lengths of the sides
860 aLen[0] = getDistance( P(1), P(3) );
861 aLen[1] = getDistance( P(3), P(5) );
862 aLen[2] = getDistance( P(5), P(7) );
863 aLen[3] = getDistance( P(7), P(1) );
864 // Compute lengths of the diagonals
866 aDia[0] = getDistance( P(1), P(5) );
867 aDia[1] = getDistance( P(3), P(7) );
868 // Compute areas of all triangles which can be built
869 // taking three nodes of the quadrangle
871 anArea[0] = getArea( P(1), P(3), P(5) );
872 anArea[1] = getArea( P(1), P(3), P(7) );
873 anArea[2] = getArea( P(1), P(5), P(7) );
874 anArea[3] = getArea( P(3), P(5), P(7) );
875 // Q = alpha * L * C1 / C2, where
877 // alpha = sqrt( 1/32 )
878 // L = max( L1, L2, L3, L4, D1, D2 )
879 // C1 = sqrt( ( L1^2 + L1^2 + L1^2 + L1^2 ) / 4 )
880 // C2 = min( S1, S2, S3, S4 )
881 // Li - lengths of the edges
882 // Di - lengths of the diagonals
883 // Si - areas of the triangles
884 const double alpha = sqrt( 1 / 32. );
885 double L = Max( aLen[ 0 ],
889 Max( aDia[ 0 ], aDia[ 1 ] ) ) ) ) );
890 double C1 = sqrt( ( aLen[0] * aLen[0] +
893 aLen[3] * aLen[3] ) / 4. );
894 double C2 = Min( anArea[ 0 ],
896 Min( anArea[ 2 ], anArea[ 3 ] ) ) );
899 return alpha * L * C1 / C2;
904 double AspectRatio::GetBadRate( double Value, int /*nbNodes*/ ) const
906 // the aspect ratio is in the range [1.0,infinity]
907 // < 1.0 = very bad, zero area
910 return ( Value < 0.9 ) ? 1000 : Value / 1000.;
913 SMDSAbs_ElementType AspectRatio::GetType() const
919 //================================================================================
921 Class : AspectRatio3D
922 Description : Functor for calculating aspect ratio
924 //================================================================================
928 inline double getHalfPerimeter(double theTria[3]){
929 return (theTria[0] + theTria[1] + theTria[2])/2.0;
932 inline double getArea(double theHalfPerim, double theTria[3]){
933 return sqrt(theHalfPerim*
934 (theHalfPerim-theTria[0])*
935 (theHalfPerim-theTria[1])*
936 (theHalfPerim-theTria[2]));
939 inline double getVolume(double theLen[6]){
940 double a2 = theLen[0]*theLen[0];
941 double b2 = theLen[1]*theLen[1];
942 double c2 = theLen[2]*theLen[2];
943 double d2 = theLen[3]*theLen[3];
944 double e2 = theLen[4]*theLen[4];
945 double f2 = theLen[5]*theLen[5];
946 double P = 4.0*a2*b2*d2;
947 double Q = a2*(b2+d2-e2)-b2*(a2+d2-f2)-d2*(a2+b2-c2);
948 double R = (b2+d2-e2)*(a2+d2-f2)*(a2+d2-f2);
949 return sqrt(P-Q+R)/12.0;
952 inline double getVolume2(double theLen[6]){
953 double a2 = theLen[0]*theLen[0];
954 double b2 = theLen[1]*theLen[1];
955 double c2 = theLen[2]*theLen[2];
956 double d2 = theLen[3]*theLen[3];
957 double e2 = theLen[4]*theLen[4];
958 double f2 = theLen[5]*theLen[5];
960 double P = a2*e2*(b2+c2+d2+f2-a2-e2);
961 double Q = b2*f2*(a2+c2+d2+e2-b2-f2);
962 double R = c2*d2*(a2+b2+e2+f2-c2-d2);
963 double S = a2*b2*d2+b2*c2*e2+a2*c2*f2+d2*e2*f2;
965 return sqrt(P+Q+R-S)/12.0;
968 inline double getVolume(const TSequenceOfXYZ& P){
969 gp_Vec aVec1( P( 2 ) - P( 1 ) );
970 gp_Vec aVec2( P( 3 ) - P( 1 ) );
971 gp_Vec aVec3( P( 4 ) - P( 1 ) );
972 gp_Vec anAreaVec( aVec1 ^ aVec2 );
973 return fabs(aVec3 * anAreaVec) / 6.0;
976 inline double getMaxHeight(double theLen[6])
978 double aHeight = std::max(theLen[0],theLen[1]);
979 aHeight = std::max(aHeight,theLen[2]);
980 aHeight = std::max(aHeight,theLen[3]);
981 aHeight = std::max(aHeight,theLen[4]);
982 aHeight = std::max(aHeight,theLen[5]);
988 double AspectRatio3D::GetValue( long theId )
991 myCurrElement = myMesh->FindElement( theId );
992 if ( myCurrElement && myCurrElement->GetVtkType() == VTK_TETRA )
994 // Action from CoTech | ACTION 31.3:
995 // EURIWARE BO: Homogenize the formulas used to calculate the Controls in SMESH to fit with
996 // those of ParaView. The library used by ParaView for those calculations can be reused in SMESH.
997 vtkUnstructuredGrid* grid = const_cast<SMDS_Mesh*>( myMesh )->GetGrid();
998 if ( vtkCell* avtkCell = grid->GetCell( myCurrElement->GetVtkID() ))
999 aVal = Round( vtkMeshQuality::TetAspectRatio( avtkCell ));
1004 if ( GetPoints( myCurrElement, P ))
1005 aVal = Round( GetValue( P ));
1010 double AspectRatio3D::GetValue( const TSequenceOfXYZ& P )
1012 double aQuality = 0.0;
1013 if(myCurrElement->IsPoly()) return aQuality;
1015 int nbNodes = P.size();
1017 if( myCurrElement->IsQuadratic() ) {
1018 if(nbNodes==10) nbNodes=4; // quadratic tetrahedron
1019 else if(nbNodes==13) nbNodes=5; // quadratic pyramid
1020 else if(nbNodes==15) nbNodes=6; // quadratic pentahedron
1021 else if(nbNodes==20) nbNodes=8; // quadratic hexahedron
1022 else if(nbNodes==27) nbNodes=8; // quadratic hexahedron
1023 else return aQuality;
1029 getDistance(P( 1 ),P( 2 )), // a
1030 getDistance(P( 2 ),P( 3 )), // b
1031 getDistance(P( 3 ),P( 1 )), // c
1032 getDistance(P( 2 ),P( 4 )), // d
1033 getDistance(P( 3 ),P( 4 )), // e
1034 getDistance(P( 1 ),P( 4 )) // f
1036 double aTria[4][3] = {
1037 {aLen[0],aLen[1],aLen[2]}, // abc
1038 {aLen[0],aLen[3],aLen[5]}, // adf
1039 {aLen[1],aLen[3],aLen[4]}, // bde
1040 {aLen[2],aLen[4],aLen[5]} // cef
1042 double aSumArea = 0.0;
1043 double aHalfPerimeter = getHalfPerimeter(aTria[0]);
1044 double anArea = getArea(aHalfPerimeter,aTria[0]);
1046 aHalfPerimeter = getHalfPerimeter(aTria[1]);
1047 anArea = getArea(aHalfPerimeter,aTria[1]);
1049 aHalfPerimeter = getHalfPerimeter(aTria[2]);
1050 anArea = getArea(aHalfPerimeter,aTria[2]);
1052 aHalfPerimeter = getHalfPerimeter(aTria[3]);
1053 anArea = getArea(aHalfPerimeter,aTria[3]);
1055 double aVolume = getVolume(P);
1056 //double aVolume = getVolume(aLen);
1057 double aHeight = getMaxHeight(aLen);
1058 static double aCoeff = sqrt(2.0)/12.0;
1059 if ( aVolume > DBL_MIN )
1060 aQuality = aCoeff*aHeight*aSumArea/aVolume;
1065 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 3 ),P( 5 )};
1066 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1069 gp_XYZ aXYZ[4] = {P( 1 ),P( 3 ),P( 4 ),P( 5 )};
1070 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1073 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 5 )};
1074 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1077 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 4 ),P( 5 )};
1078 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1084 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 6 )};
1085 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1088 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 3 )};
1089 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1092 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 6 )};
1093 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1096 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
1097 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1100 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 6 )};
1101 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1104 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 3 )};
1105 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1111 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
1112 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1115 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 4 )};
1116 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1119 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 7 )};
1120 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1123 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 8 )};
1124 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1127 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 3 )};
1128 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1131 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 4 )};
1132 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1135 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 7 )};
1136 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1139 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 8 )};
1140 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1143 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 3 )};
1144 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1147 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 4 )};
1148 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1151 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 7 )};
1152 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1155 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 8 )};
1156 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1159 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 1 )};
1160 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1163 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 2 )};
1164 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1167 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 5 )};
1168 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1171 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 6 )};
1172 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1175 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 1 )};
1176 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1179 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 2 )};
1180 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1183 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 5 )};
1184 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1187 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 6 )};
1188 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1191 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 1 )};
1192 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1195 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
1196 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1199 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 5 )};
1200 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1203 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 6 )};
1204 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1207 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
1208 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1211 gp_XYZ aXYZ[4] = {P( 4 ),P( 5 ),P( 8 ),P( 2 )};
1212 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1215 gp_XYZ aXYZ[4] = {P( 1 ),P( 4 ),P( 5 ),P( 3 )};
1216 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1219 gp_XYZ aXYZ[4] = {P( 3 ),P( 6 ),P( 7 ),P( 1 )};
1220 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1223 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 6 ),P( 4 )};
1224 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1227 gp_XYZ aXYZ[4] = {P( 5 ),P( 6 ),P( 8 ),P( 3 )};
1228 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1231 gp_XYZ aXYZ[4] = {P( 7 ),P( 8 ),P( 6 ),P( 1 )};
1232 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1235 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 7 )};
1236 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1239 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 2 ),P( 5 )};
1240 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1246 gp_XYZ aXYZ[8] = {P( 1 ),P( 2 ),P( 4 ),P( 5 ),P( 7 ),P( 8 ),P( 10 ),P( 11 )};
1247 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[8])),aQuality);
1250 gp_XYZ aXYZ[8] = {P( 2 ),P( 3 ),P( 5 ),P( 6 ),P( 8 ),P( 9 ),P( 11 ),P( 12 )};
1251 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[8])),aQuality);
1254 gp_XYZ aXYZ[8] = {P( 3 ),P( 4 ),P( 6 ),P( 1 ),P( 9 ),P( 10 ),P( 12 ),P( 7 )};
1255 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[8])),aQuality);
1258 } // switch(nbNodes)
1260 if ( nbNodes > 4 ) {
1261 // evaluate aspect ratio of quadrangle faces
1262 AspectRatio aspect2D;
1263 SMDS_VolumeTool::VolumeType type = SMDS_VolumeTool::GetType( nbNodes );
1264 int nbFaces = SMDS_VolumeTool::NbFaces( type );
1265 TSequenceOfXYZ points(4);
1266 for ( int i = 0; i < nbFaces; ++i ) { // loop on faces of a volume
1267 if ( SMDS_VolumeTool::NbFaceNodes( type, i ) != 4 )
1269 const int* pInd = SMDS_VolumeTool::GetFaceNodesIndices( type, i, true );
1270 for ( int p = 0; p < 4; ++p ) // loop on nodes of a quadrangle face
1271 points( p + 1 ) = P( pInd[ p ] + 1 );
1272 aQuality = std::max( aQuality, aspect2D.GetValue( points ));
1278 double AspectRatio3D::GetBadRate( double Value, int /*nbNodes*/ ) const
1280 // the aspect ratio is in the range [1.0,infinity]
1283 return Value / 1000.;
1286 SMDSAbs_ElementType AspectRatio3D::GetType() const
1288 return SMDSAbs_Volume;
1292 //================================================================================
1295 Description : Functor for calculating warping
1297 //================================================================================
1299 double Warping::GetValue( const TSequenceOfXYZ& P )
1301 if ( P.size() != 4 )
1304 gp_XYZ G = ( P( 1 ) + P( 2 ) + P( 3 ) + P( 4 ) ) / 4.;
1306 double A1 = ComputeA( P( 1 ), P( 2 ), P( 3 ), G );
1307 double A2 = ComputeA( P( 2 ), P( 3 ), P( 4 ), G );
1308 double A3 = ComputeA( P( 3 ), P( 4 ), P( 1 ), G );
1309 double A4 = ComputeA( P( 4 ), P( 1 ), P( 2 ), G );
1311 double val = Max( Max( A1, A2 ), Max( A3, A4 ) );
1313 const double eps = 0.1; // val is in degrees
1315 return val < eps ? 0. : val;
1318 double Warping::ComputeA( const gp_XYZ& thePnt1,
1319 const gp_XYZ& thePnt2,
1320 const gp_XYZ& thePnt3,
1321 const gp_XYZ& theG ) const
1323 double aLen1 = gp_Pnt( thePnt1 ).Distance( gp_Pnt( thePnt2 ) );
1324 double aLen2 = gp_Pnt( thePnt2 ).Distance( gp_Pnt( thePnt3 ) );
1325 double L = Min( aLen1, aLen2 ) * 0.5;
1329 gp_XYZ GI = ( thePnt2 + thePnt1 ) / 2. - theG;
1330 gp_XYZ GJ = ( thePnt3 + thePnt2 ) / 2. - theG;
1331 gp_XYZ N = GI.Crossed( GJ );
1333 if ( N.Modulus() < gp::Resolution() )
1338 double H = ( thePnt2 - theG ).Dot( N );
1339 return asin( fabs( H / L ) ) * 180. / M_PI;
1342 double Warping::GetBadRate( double Value, int /*nbNodes*/ ) const
1344 // the warp is in the range [0.0,PI/2]
1345 // 0.0 = good (no warp)
1346 // PI/2 = bad (face pliee)
1350 SMDSAbs_ElementType Warping::GetType() const
1352 return SMDSAbs_Face;
1356 //================================================================================
1359 Description : Functor for calculating taper
1361 //================================================================================
1363 double Taper::GetValue( const TSequenceOfXYZ& P )
1365 if ( P.size() != 4 )
1369 double J1 = getArea( P( 4 ), P( 1 ), P( 2 ) );
1370 double J2 = getArea( P( 3 ), P( 1 ), P( 2 ) );
1371 double J3 = getArea( P( 2 ), P( 3 ), P( 4 ) );
1372 double J4 = getArea( P( 3 ), P( 4 ), P( 1 ) );
1374 double JA = 0.25 * ( J1 + J2 + J3 + J4 );
1378 double T1 = fabs( ( J1 - JA ) / JA );
1379 double T2 = fabs( ( J2 - JA ) / JA );
1380 double T3 = fabs( ( J3 - JA ) / JA );
1381 double T4 = fabs( ( J4 - JA ) / JA );
1383 double val = Max( Max( T1, T2 ), Max( T3, T4 ) );
1385 const double eps = 0.01;
1387 return val < eps ? 0. : val;
1390 double Taper::GetBadRate( double Value, int /*nbNodes*/ ) const
1392 // the taper is in the range [0.0,1.0]
1393 // 0.0 = good (no taper)
1394 // 1.0 = bad (les cotes opposes sont allignes)
1398 SMDSAbs_ElementType Taper::GetType() const
1400 return SMDSAbs_Face;
1403 //================================================================================
1406 Description : Functor for calculating skew in degrees
1408 //================================================================================
1410 static inline double skewAngle( const gp_XYZ& p1, const gp_XYZ& p2, const gp_XYZ& p3 )
1412 gp_XYZ p12 = ( p2 + p1 ) / 2.;
1413 gp_XYZ p23 = ( p3 + p2 ) / 2.;
1414 gp_XYZ p31 = ( p3 + p1 ) / 2.;
1416 gp_Vec v1( p31 - p2 ), v2( p12 - p23 );
1418 return v1.Magnitude() < gp::Resolution() || v2.Magnitude() < gp::Resolution() ? 0. : v1.Angle( v2 );
1421 double Skew::GetValue( const TSequenceOfXYZ& P )
1423 if ( P.size() != 3 && P.size() != 4 )
1427 const double PI2 = M_PI / 2.;
1428 if ( P.size() == 3 )
1430 double A0 = fabs( PI2 - skewAngle( P( 3 ), P( 1 ), P( 2 ) ) );
1431 double A1 = fabs( PI2 - skewAngle( P( 1 ), P( 2 ), P( 3 ) ) );
1432 double A2 = fabs( PI2 - skewAngle( P( 2 ), P( 3 ), P( 1 ) ) );
1434 return Max( A0, Max( A1, A2 ) ) * 180. / M_PI;
1438 gp_XYZ p12 = ( P( 1 ) + P( 2 ) ) / 2.;
1439 gp_XYZ p23 = ( P( 2 ) + P( 3 ) ) / 2.;
1440 gp_XYZ p34 = ( P( 3 ) + P( 4 ) ) / 2.;
1441 gp_XYZ p41 = ( P( 4 ) + P( 1 ) ) / 2.;
1443 gp_Vec v1( p34 - p12 ), v2( p23 - p41 );
1444 double A = v1.Magnitude() <= gp::Resolution() || v2.Magnitude() <= gp::Resolution()
1445 ? 0. : fabs( PI2 - v1.Angle( v2 ) );
1447 double val = A * 180. / M_PI;
1449 const double eps = 0.1; // val is in degrees
1451 return val < eps ? 0. : val;
1455 double Skew::GetBadRate( double Value, int /*nbNodes*/ ) const
1457 // the skew is in the range [0.0,PI/2].
1463 SMDSAbs_ElementType Skew::GetType() const
1465 return SMDSAbs_Face;
1469 //================================================================================
1472 Description : Functor for calculating area
1474 //================================================================================
1476 double Area::GetValue( const TSequenceOfXYZ& P )
1481 gp_Vec aVec1( P(2) - P(1) );
1482 gp_Vec aVec2( P(3) - P(1) );
1483 gp_Vec SumVec = aVec1 ^ aVec2;
1485 for (size_t i=4; i<=P.size(); i++)
1487 gp_Vec aVec1( P(i-1) - P(1) );
1488 gp_Vec aVec2( P(i ) - P(1) );
1489 gp_Vec tmp = aVec1 ^ aVec2;
1492 val = SumVec.Magnitude() * 0.5;
1497 double Area::GetBadRate( double Value, int /*nbNodes*/ ) const
1499 // meaningless as it is not a quality control functor
1503 SMDSAbs_ElementType Area::GetType() const
1505 return SMDSAbs_Face;
1508 //================================================================================
1511 Description : Functor for calculating length of edge
1513 //================================================================================
1515 double Length::GetValue( const TSequenceOfXYZ& P )
1517 switch ( P.size() ) {
1518 case 2: return getDistance( P( 1 ), P( 2 ) );
1519 case 3: return getDistance( P( 1 ), P( 2 ) ) + getDistance( P( 2 ), P( 3 ) );
1524 double Length::GetBadRate( double Value, int /*nbNodes*/ ) const
1526 // meaningless as it is not quality control functor
1530 SMDSAbs_ElementType Length::GetType() const
1532 return SMDSAbs_Edge;
1535 //================================================================================
1538 Description : Functor for calculating minimal length of edge
1540 //================================================================================
1542 double Length2D::GetValue( const TSequenceOfXYZ& P )
1546 SMDSAbs_EntityType aType = P.getElementEntity();
1549 case SMDSEntity_Edge:
1551 aVal = getDistance( P( 1 ), P( 2 ) );
1553 case SMDSEntity_Quad_Edge:
1554 if (len == 3) // quadratic edge
1555 aVal = getDistance(P( 1 ),P( 3 )) + getDistance(P( 3 ),P( 2 ));
1557 case SMDSEntity_Triangle:
1558 if (len == 3){ // triangles
1559 double L1 = getDistance(P( 1 ),P( 2 ));
1560 double L2 = getDistance(P( 2 ),P( 3 ));
1561 double L3 = getDistance(P( 3 ),P( 1 ));
1562 aVal = Min(L1,Min(L2,L3));
1565 case SMDSEntity_Quadrangle:
1566 if (len == 4){ // quadrangles
1567 double L1 = getDistance(P( 1 ),P( 2 ));
1568 double L2 = getDistance(P( 2 ),P( 3 ));
1569 double L3 = getDistance(P( 3 ),P( 4 ));
1570 double L4 = getDistance(P( 4 ),P( 1 ));
1571 aVal = Min(Min(L1,L2),Min(L3,L4));
1574 case SMDSEntity_Quad_Triangle:
1575 case SMDSEntity_BiQuad_Triangle:
1576 if (len >= 6){ // quadratic triangles
1577 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1578 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1579 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 1 ));
1580 aVal = Min(L1,Min(L2,L3));
1583 case SMDSEntity_Quad_Quadrangle:
1584 case SMDSEntity_BiQuad_Quadrangle:
1585 if (len >= 8){ // quadratic quadrangles
1586 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1587 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1588 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 7 ));
1589 double L4 = getDistance(P( 7 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
1590 aVal = Min(Min(L1,L2),Min(L3,L4));
1593 case SMDSEntity_Tetra:
1594 if (len == 4){ // tetrahedra
1595 double L1 = getDistance(P( 1 ),P( 2 ));
1596 double L2 = getDistance(P( 2 ),P( 3 ));
1597 double L3 = getDistance(P( 3 ),P( 1 ));
1598 double L4 = getDistance(P( 1 ),P( 4 ));
1599 double L5 = getDistance(P( 2 ),P( 4 ));
1600 double L6 = getDistance(P( 3 ),P( 4 ));
1601 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1604 case SMDSEntity_Pyramid:
1605 if (len == 5){ // pyramid
1606 double L1 = getDistance(P( 1 ),P( 2 ));
1607 double L2 = getDistance(P( 2 ),P( 3 ));
1608 double L3 = getDistance(P( 3 ),P( 4 ));
1609 double L4 = getDistance(P( 4 ),P( 1 ));
1610 double L5 = getDistance(P( 1 ),P( 5 ));
1611 double L6 = getDistance(P( 2 ),P( 5 ));
1612 double L7 = getDistance(P( 3 ),P( 5 ));
1613 double L8 = getDistance(P( 4 ),P( 5 ));
1615 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1616 aVal = Min(aVal,Min(L7,L8));
1619 case SMDSEntity_Penta:
1620 if (len == 6) { // pentahedron
1621 double L1 = getDistance(P( 1 ),P( 2 ));
1622 double L2 = getDistance(P( 2 ),P( 3 ));
1623 double L3 = getDistance(P( 3 ),P( 1 ));
1624 double L4 = getDistance(P( 4 ),P( 5 ));
1625 double L5 = getDistance(P( 5 ),P( 6 ));
1626 double L6 = getDistance(P( 6 ),P( 4 ));
1627 double L7 = getDistance(P( 1 ),P( 4 ));
1628 double L8 = getDistance(P( 2 ),P( 5 ));
1629 double L9 = getDistance(P( 3 ),P( 6 ));
1631 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1632 aVal = Min(aVal,Min(Min(L7,L8),L9));
1635 case SMDSEntity_Hexa:
1636 if (len == 8){ // hexahedron
1637 double L1 = getDistance(P( 1 ),P( 2 ));
1638 double L2 = getDistance(P( 2 ),P( 3 ));
1639 double L3 = getDistance(P( 3 ),P( 4 ));
1640 double L4 = getDistance(P( 4 ),P( 1 ));
1641 double L5 = getDistance(P( 5 ),P( 6 ));
1642 double L6 = getDistance(P( 6 ),P( 7 ));
1643 double L7 = getDistance(P( 7 ),P( 8 ));
1644 double L8 = getDistance(P( 8 ),P( 5 ));
1645 double L9 = getDistance(P( 1 ),P( 5 ));
1646 double L10= getDistance(P( 2 ),P( 6 ));
1647 double L11= getDistance(P( 3 ),P( 7 ));
1648 double L12= getDistance(P( 4 ),P( 8 ));
1650 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1651 aVal = Min(aVal,Min(Min(L7,L8),Min(L9,L10)));
1652 aVal = Min(aVal,Min(L11,L12));
1655 case SMDSEntity_Quad_Tetra:
1656 if (len == 10){ // quadratic tetrahedron
1657 double L1 = getDistance(P( 1 ),P( 5 )) + getDistance(P( 5 ),P( 2 ));
1658 double L2 = getDistance(P( 2 ),P( 6 )) + getDistance(P( 6 ),P( 3 ));
1659 double L3 = getDistance(P( 3 ),P( 7 )) + getDistance(P( 7 ),P( 1 ));
1660 double L4 = getDistance(P( 1 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
1661 double L5 = getDistance(P( 2 ),P( 9 )) + getDistance(P( 9 ),P( 4 ));
1662 double L6 = getDistance(P( 3 ),P( 10 )) + getDistance(P( 10 ),P( 4 ));
1663 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1666 case SMDSEntity_Quad_Pyramid:
1667 if (len == 13){ // quadratic pyramid
1668 double L1 = getDistance(P( 1 ),P( 6 )) + getDistance(P( 6 ),P( 2 ));
1669 double L2 = getDistance(P( 2 ),P( 7 )) + getDistance(P( 7 ),P( 3 ));
1670 double L3 = getDistance(P( 3 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
1671 double L4 = getDistance(P( 4 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1672 double L5 = getDistance(P( 1 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1673 double L6 = getDistance(P( 2 ),P( 11 )) + getDistance(P( 11 ),P( 5 ));
1674 double L7 = getDistance(P( 3 ),P( 12 )) + getDistance(P( 12 ),P( 5 ));
1675 double L8 = getDistance(P( 4 ),P( 13 )) + getDistance(P( 13 ),P( 5 ));
1676 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1677 aVal = Min(aVal,Min(L7,L8));
1680 case SMDSEntity_Quad_Penta:
1681 case SMDSEntity_BiQuad_Penta:
1682 if (len >= 15){ // quadratic pentahedron
1683 double L1 = getDistance(P( 1 ),P( 7 )) + getDistance(P( 7 ),P( 2 ));
1684 double L2 = getDistance(P( 2 ),P( 8 )) + getDistance(P( 8 ),P( 3 ));
1685 double L3 = getDistance(P( 3 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1686 double L4 = getDistance(P( 4 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1687 double L5 = getDistance(P( 5 ),P( 11 )) + getDistance(P( 11 ),P( 6 ));
1688 double L6 = getDistance(P( 6 ),P( 12 )) + getDistance(P( 12 ),P( 4 ));
1689 double L7 = getDistance(P( 1 ),P( 13 )) + getDistance(P( 13 ),P( 4 ));
1690 double L8 = getDistance(P( 2 ),P( 14 )) + getDistance(P( 14 ),P( 5 ));
1691 double L9 = getDistance(P( 3 ),P( 15 )) + getDistance(P( 15 ),P( 6 ));
1692 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1693 aVal = Min(aVal,Min(Min(L7,L8),L9));
1696 case SMDSEntity_Quad_Hexa:
1697 case SMDSEntity_TriQuad_Hexa:
1698 if (len >= 20) { // quadratic hexahedron
1699 double L1 = getDistance(P( 1 ),P( 9 )) + getDistance(P( 9 ),P( 2 ));
1700 double L2 = getDistance(P( 2 ),P( 10 )) + getDistance(P( 10 ),P( 3 ));
1701 double L3 = getDistance(P( 3 ),P( 11 )) + getDistance(P( 11 ),P( 4 ));
1702 double L4 = getDistance(P( 4 ),P( 12 )) + getDistance(P( 12 ),P( 1 ));
1703 double L5 = getDistance(P( 5 ),P( 13 )) + getDistance(P( 13 ),P( 6 ));
1704 double L6 = getDistance(P( 6 ),P( 14 )) + getDistance(P( 14 ),P( 7 ));
1705 double L7 = getDistance(P( 7 ),P( 15 )) + getDistance(P( 15 ),P( 8 ));
1706 double L8 = getDistance(P( 8 ),P( 16 )) + getDistance(P( 16 ),P( 5 ));
1707 double L9 = getDistance(P( 1 ),P( 17 )) + getDistance(P( 17 ),P( 5 ));
1708 double L10= getDistance(P( 2 ),P( 18 )) + getDistance(P( 18 ),P( 6 ));
1709 double L11= getDistance(P( 3 ),P( 19 )) + getDistance(P( 19 ),P( 7 ));
1710 double L12= getDistance(P( 4 ),P( 20 )) + getDistance(P( 20 ),P( 8 ));
1711 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1712 aVal = Min(aVal,Min(Min(L7,L8),Min(L9,L10)));
1713 aVal = Min(aVal,Min(L11,L12));
1716 case SMDSEntity_Polygon:
1718 aVal = getDistance( P(1), P( P.size() ));
1719 for ( size_t i = 1; i < P.size(); ++i )
1720 aVal = Min( aVal, getDistance( P( i ), P( i+1 )));
1723 case SMDSEntity_Quad_Polygon:
1725 aVal = getDistance( P(1), P( P.size() )) + getDistance( P(P.size()), P( P.size()-1 ));
1726 for ( size_t i = 1; i < P.size()-1; i += 2 )
1727 aVal = Min( aVal, getDistance( P( i ), P( i+1 )) + getDistance( P( i+1 ), P( i+2 )));
1730 case SMDSEntity_Hexagonal_Prism:
1731 if (len == 12) { // hexagonal prism
1732 double L1 = getDistance(P( 1 ),P( 2 ));
1733 double L2 = getDistance(P( 2 ),P( 3 ));
1734 double L3 = getDistance(P( 3 ),P( 4 ));
1735 double L4 = getDistance(P( 4 ),P( 5 ));
1736 double L5 = getDistance(P( 5 ),P( 6 ));
1737 double L6 = getDistance(P( 6 ),P( 1 ));
1739 double L7 = getDistance(P( 7 ), P( 8 ));
1740 double L8 = getDistance(P( 8 ), P( 9 ));
1741 double L9 = getDistance(P( 9 ), P( 10 ));
1742 double L10= getDistance(P( 10 ),P( 11 ));
1743 double L11= getDistance(P( 11 ),P( 12 ));
1744 double L12= getDistance(P( 12 ),P( 7 ));
1746 double L13 = getDistance(P( 1 ),P( 7 ));
1747 double L14 = getDistance(P( 2 ),P( 8 ));
1748 double L15 = getDistance(P( 3 ),P( 9 ));
1749 double L16 = getDistance(P( 4 ),P( 10 ));
1750 double L17 = getDistance(P( 5 ),P( 11 ));
1751 double L18 = getDistance(P( 6 ),P( 12 ));
1752 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1753 aVal = Min(aVal, Min(Min(Min(L7,L8),Min(L9,L10)),Min(L11,L12)));
1754 aVal = Min(aVal, Min(Min(Min(L13,L14),Min(L15,L16)),Min(L17,L18)));
1757 case SMDSEntity_Polyhedra:
1769 if ( myPrecision >= 0 )
1771 double prec = pow( 10., (double)( myPrecision ) );
1772 aVal = floor( aVal * prec + 0.5 ) / prec;
1778 double Length2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1780 // meaningless as it is not a quality control functor
1784 SMDSAbs_ElementType Length2D::GetType() const
1786 return SMDSAbs_Face;
1789 Length2D::Value::Value(double theLength,long thePntId1, long thePntId2):
1792 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1793 if(thePntId1 > thePntId2){
1794 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1798 bool Length2D::Value::operator<(const Length2D::Value& x) const
1800 if(myPntId[0] < x.myPntId[0]) return true;
1801 if(myPntId[0] == x.myPntId[0])
1802 if(myPntId[1] < x.myPntId[1]) return true;
1806 void Length2D::GetValues(TValues& theValues)
1809 for ( SMDS_FaceIteratorPtr anIter = myMesh->facesIterator(); anIter->more(); )
1811 const SMDS_MeshFace* anElem = anIter->next();
1812 if ( anElem->IsQuadratic() )
1814 // use special nodes iterator
1815 SMDS_NodeIteratorPtr anIter = anElem->interlacedNodesIterator();
1816 long aNodeId[4] = { 0,0,0,0 };
1820 if ( anIter->more() )
1822 const SMDS_MeshNode* aNode = anIter->next();
1823 P[0] = P[1] = SMESH_NodeXYZ( aNode );
1824 aNodeId[0] = aNodeId[1] = aNode->GetID();
1827 for ( ; anIter->more(); )
1829 const SMDS_MeshNode* N1 = anIter->next();
1830 P[2] = SMESH_NodeXYZ( N1 );
1831 aNodeId[2] = N1->GetID();
1832 aLength = P[1].Distance(P[2]);
1833 if(!anIter->more()) break;
1834 const SMDS_MeshNode* N2 = anIter->next();
1835 P[3] = SMESH_NodeXYZ( N2 );
1836 aNodeId[3] = N2->GetID();
1837 aLength += P[2].Distance(P[3]);
1838 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1839 Value aValue2(aLength,aNodeId[2],aNodeId[3]);
1841 aNodeId[1] = aNodeId[3];
1842 theValues.insert(aValue1);
1843 theValues.insert(aValue2);
1845 aLength += P[2].Distance(P[0]);
1846 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1847 Value aValue2(aLength,aNodeId[2],aNodeId[0]);
1848 theValues.insert(aValue1);
1849 theValues.insert(aValue2);
1852 SMDS_NodeIteratorPtr aNodesIter = anElem->nodeIterator();
1853 long aNodeId[2] = {0,0};
1857 const SMDS_MeshElement* aNode;
1858 if ( aNodesIter->more())
1860 aNode = aNodesIter->next();
1861 P[0] = P[1] = SMESH_NodeXYZ( aNode );
1862 aNodeId[0] = aNodeId[1] = aNode->GetID();
1865 for( ; aNodesIter->more(); )
1867 aNode = aNodesIter->next();
1868 long anId = aNode->GetID();
1870 P[2] = SMESH_NodeXYZ( aNode );
1872 aLength = P[1].Distance(P[2]);
1874 Value aValue(aLength,aNodeId[1],anId);
1877 theValues.insert(aValue);
1880 aLength = P[0].Distance(P[1]);
1882 Value aValue(aLength,aNodeId[0],aNodeId[1]);
1883 theValues.insert(aValue);
1888 //================================================================================
1890 Class : Deflection2D
1891 Description : Functor for calculating number of faces conneted to the edge
1893 //================================================================================
1895 double Deflection2D::GetValue( const TSequenceOfXYZ& P )
1897 if ( myMesh && P.getElement() )
1899 // get underlying surface
1900 if ( myShapeIndex != P.getElement()->getshapeId() )
1902 mySurface.Nullify();
1903 myShapeIndex = P.getElement()->getshapeId();
1904 const TopoDS_Shape& S =
1905 static_cast< const SMESHDS_Mesh* >( myMesh )->IndexToShape( myShapeIndex );
1906 if ( !S.IsNull() && S.ShapeType() == TopAbs_FACE )
1908 mySurface = new ShapeAnalysis_Surface( BRep_Tool::Surface( TopoDS::Face( S )));
1910 GeomLib_IsPlanarSurface isPlaneCheck( mySurface->Surface() );
1911 if ( isPlaneCheck.IsPlanar() )
1912 myPlane.reset( new gp_Pln( isPlaneCheck.Plan() ));
1917 // project gravity center to the surface
1918 if ( !mySurface.IsNull() )
1923 for ( size_t i = 0; i < P.size(); ++i )
1927 if ( SMDS_FacePositionPtr fPos = P.getElement()->GetNode( i )->GetPosition() )
1929 uv.ChangeCoord(1) += fPos->GetUParameter();
1930 uv.ChangeCoord(2) += fPos->GetVParameter();
1935 if ( nbUV ) uv /= nbUV;
1937 double maxLen = MaxElementLength2D().GetValue( P );
1938 double tol = 1e-3 * maxLen;
1942 dist = myPlane->Distance( gc );
1948 if ( uv.X() != 0 && uv.Y() != 0 ) // faster way
1949 mySurface->NextValueOfUV( uv, gc, tol, 0.5 * maxLen );
1951 mySurface->ValueOfUV( gc, tol );
1952 dist = mySurface->Gap();
1954 return Round( dist );
1960 void Deflection2D::SetMesh( const SMDS_Mesh* theMesh )
1962 NumericalFunctor::SetMesh( dynamic_cast<const SMESHDS_Mesh* >( theMesh ));
1963 myShapeIndex = -100;
1967 SMDSAbs_ElementType Deflection2D::GetType() const
1969 return SMDSAbs_Face;
1972 double Deflection2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1974 // meaningless as it is not quality control functor
1978 //================================================================================
1980 Class : MultiConnection
1981 Description : Functor for calculating number of faces conneted to the edge
1983 //================================================================================
1985 double MultiConnection::GetValue( const TSequenceOfXYZ& P )
1989 double MultiConnection::GetValue( long theId )
1991 return getNbMultiConnection( myMesh, theId );
1994 double MultiConnection::GetBadRate( double Value, int /*nbNodes*/ ) const
1996 // meaningless as it is not quality control functor
2000 SMDSAbs_ElementType MultiConnection::GetType() const
2002 return SMDSAbs_Edge;
2005 //================================================================================
2007 Class : MultiConnection2D
2008 Description : Functor for calculating number of faces conneted to the edge
2010 //================================================================================
2012 double MultiConnection2D::GetValue( const TSequenceOfXYZ& P )
2017 double MultiConnection2D::GetValue( long theElementId )
2021 const SMDS_MeshElement* aFaceElem = myMesh->FindElement(theElementId);
2022 SMDSAbs_ElementType aType = aFaceElem->GetType();
2027 int i = 0, len = aFaceElem->NbNodes();
2028 SMDS_ElemIteratorPtr anIter = aFaceElem->nodesIterator();
2031 const SMDS_MeshNode *aNode, *aNode0 = 0;
2032 TColStd_MapOfInteger aMap, aMapPrev;
2034 for (i = 0; i <= len; i++) {
2039 if (anIter->more()) {
2040 aNode = (SMDS_MeshNode*)anIter->next();
2048 if (i == 0) aNode0 = aNode;
2050 SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator();
2051 while (anElemIter->more()) {
2052 const SMDS_MeshElement* anElem = anElemIter->next();
2053 if (anElem != 0 && anElem->GetType() == SMDSAbs_Face) {
2054 int anId = anElem->GetID();
2057 if (aMapPrev.Contains(anId)) {
2062 aResult = Max(aResult, aNb);
2073 double MultiConnection2D::GetBadRate( double Value, int /*nbNodes*/ ) const
2075 // meaningless as it is not quality control functor
2079 SMDSAbs_ElementType MultiConnection2D::GetType() const
2081 return SMDSAbs_Face;
2084 MultiConnection2D::Value::Value(long thePntId1, long thePntId2)
2086 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
2087 if(thePntId1 > thePntId2){
2088 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
2092 bool MultiConnection2D::Value::operator<(const MultiConnection2D::Value& x) const
2094 if(myPntId[0] < x.myPntId[0]) return true;
2095 if(myPntId[0] == x.myPntId[0])
2096 if(myPntId[1] < x.myPntId[1]) return true;
2100 void MultiConnection2D::GetValues(MValues& theValues)
2102 if ( !myMesh ) return;
2103 for ( SMDS_FaceIteratorPtr anIter = myMesh->facesIterator(); anIter->more(); )
2105 const SMDS_MeshFace* anElem = anIter->next();
2106 SMDS_NodeIteratorPtr aNodesIter = anElem->interlacedNodesIterator();
2108 const SMDS_MeshNode* aNode1 = anElem->GetNode( anElem->NbNodes() - 1 );
2109 const SMDS_MeshNode* aNode2;
2110 for ( ; aNodesIter->more(); )
2112 aNode2 = aNodesIter->next();
2114 Value aValue ( aNode1->GetID(), aNode2->GetID() );
2115 MValues::iterator aItr = theValues.insert( std::make_pair( aValue, 0 )).first;
2123 //================================================================================
2125 Class : BallDiameter
2126 Description : Functor returning diameter of a ball element
2128 //================================================================================
2130 double BallDiameter::GetValue( long theId )
2132 double diameter = 0;
2134 if ( const SMDS_BallElement* ball =
2135 myMesh->DownCast< SMDS_BallElement >( myMesh->FindElement( theId )))
2137 diameter = ball->GetDiameter();
2142 double BallDiameter::GetBadRate( double Value, int /*nbNodes*/ ) const
2144 // meaningless as it is not a quality control functor
2148 SMDSAbs_ElementType BallDiameter::GetType() const
2150 return SMDSAbs_Ball;
2153 //================================================================================
2155 Class : NodeConnectivityNumber
2156 Description : Functor returning number of elements connected to a node
2158 //================================================================================
2160 double NodeConnectivityNumber::GetValue( long theId )
2164 if ( const SMDS_MeshNode* node = myMesh->FindNode( theId ))
2166 SMDSAbs_ElementType type;
2167 if ( myMesh->NbVolumes() > 0 )
2168 type = SMDSAbs_Volume;
2169 else if ( myMesh->NbFaces() > 0 )
2170 type = SMDSAbs_Face;
2171 else if ( myMesh->NbEdges() > 0 )
2172 type = SMDSAbs_Edge;
2175 nb = node->NbInverseElements( type );
2180 double NodeConnectivityNumber::GetBadRate( double Value, int /*nbNodes*/ ) const
2185 SMDSAbs_ElementType NodeConnectivityNumber::GetType() const
2187 return SMDSAbs_Node;
2194 //================================================================================
2196 Class : BadOrientedVolume
2197 Description : Predicate bad oriented volumes
2199 //================================================================================
2201 BadOrientedVolume::BadOrientedVolume()
2206 void BadOrientedVolume::SetMesh( const SMDS_Mesh* theMesh )
2211 bool BadOrientedVolume::IsSatisfy( long theId )
2216 SMDS_VolumeTool vTool( myMesh->FindElement( theId ));
2217 return !vTool.IsForward();
2220 SMDSAbs_ElementType BadOrientedVolume::GetType() const
2222 return SMDSAbs_Volume;
2226 Class : BareBorderVolume
2229 bool BareBorderVolume::IsSatisfy(long theElementId )
2231 SMDS_VolumeTool myTool;
2232 if ( myTool.Set( myMesh->FindElement(theElementId)))
2234 for ( int iF = 0; iF < myTool.NbFaces(); ++iF )
2235 if ( myTool.IsFreeFace( iF ))
2237 const SMDS_MeshNode** n = myTool.GetFaceNodes(iF);
2238 std::vector< const SMDS_MeshNode*> nodes( n, n+myTool.NbFaceNodes(iF));
2239 if ( !myMesh->FindElement( nodes, SMDSAbs_Face, /*Nomedium=*/false))
2246 //================================================================================
2248 Class : BareBorderFace
2250 //================================================================================
2252 bool BareBorderFace::IsSatisfy(long theElementId )
2255 if ( const SMDS_MeshElement* face = myMesh->FindElement(theElementId))
2257 if ( face->GetType() == SMDSAbs_Face )
2259 int nbN = face->NbCornerNodes();
2260 for ( int i = 0; i < nbN && !ok; ++i )
2262 // check if a link is shared by another face
2263 const SMDS_MeshNode* n1 = face->GetNode( i );
2264 const SMDS_MeshNode* n2 = face->GetNode( (i+1)%nbN );
2265 SMDS_ElemIteratorPtr fIt = n1->GetInverseElementIterator( SMDSAbs_Face );
2266 bool isShared = false;
2267 while ( !isShared && fIt->more() )
2269 const SMDS_MeshElement* f = fIt->next();
2270 isShared = ( f != face && f->GetNodeIndex(n2) != -1 );
2274 const int iQuad = face->IsQuadratic();
2275 myLinkNodes.resize( 2 + iQuad);
2276 myLinkNodes[0] = n1;
2277 myLinkNodes[1] = n2;
2279 myLinkNodes[2] = face->GetNode( i+nbN );
2280 ok = !myMesh->FindElement( myLinkNodes, SMDSAbs_Edge, /*noMedium=*/false);
2288 //================================================================================
2290 Class : OverConstrainedVolume
2292 //================================================================================
2294 bool OverConstrainedVolume::IsSatisfy(long theElementId )
2296 // An element is over-constrained if it has N-1 free borders where
2297 // N is the number of edges/faces for a 2D/3D element.
2298 SMDS_VolumeTool myTool;
2299 if ( myTool.Set( myMesh->FindElement(theElementId)))
2301 int nbSharedFaces = 0;
2302 for ( int iF = 0; iF < myTool.NbFaces(); ++iF )
2303 if ( !myTool.IsFreeFace( iF ) && ++nbSharedFaces > 1 )
2305 return ( nbSharedFaces == 1 );
2310 //================================================================================
2312 Class : OverConstrainedFace
2314 //================================================================================
2316 bool OverConstrainedFace::IsSatisfy(long theElementId )
2318 // An element is over-constrained if it has N-1 free borders where
2319 // N is the number of edges/faces for a 2D/3D element.
2320 if ( const SMDS_MeshElement* face = myMesh->FindElement(theElementId))
2321 if ( face->GetType() == SMDSAbs_Face )
2323 int nbSharedBorders = 0;
2324 int nbN = face->NbCornerNodes();
2325 for ( int i = 0; i < nbN; ++i )
2327 // check if a link is shared by another face
2328 const SMDS_MeshNode* n1 = face->GetNode( i );
2329 const SMDS_MeshNode* n2 = face->GetNode( (i+1)%nbN );
2330 SMDS_ElemIteratorPtr fIt = n1->GetInverseElementIterator( SMDSAbs_Face );
2331 bool isShared = false;
2332 while ( !isShared && fIt->more() )
2334 const SMDS_MeshElement* f = fIt->next();
2335 isShared = ( f != face && f->GetNodeIndex(n2) != -1 );
2337 if ( isShared && ++nbSharedBorders > 1 )
2340 return ( nbSharedBorders == 1 );
2345 //================================================================================
2347 Class : CoincidentNodes
2348 Description : Predicate of Coincident nodes
2350 //================================================================================
2352 CoincidentNodes::CoincidentNodes()
2357 bool CoincidentNodes::IsSatisfy( long theElementId )
2359 return myCoincidentIDs.Contains( theElementId );
2362 SMDSAbs_ElementType CoincidentNodes::GetType() const
2364 return SMDSAbs_Node;
2367 void CoincidentNodes::SetMesh( const SMDS_Mesh* theMesh )
2369 myMeshModifTracer.SetMesh( theMesh );
2370 if ( myMeshModifTracer.IsMeshModified() )
2372 TIDSortedNodeSet nodesToCheck;
2373 SMDS_NodeIteratorPtr nIt = theMesh->nodesIterator();
2374 while ( nIt->more() )
2375 nodesToCheck.insert( nodesToCheck.end(), nIt->next() );
2377 std::list< std::list< const SMDS_MeshNode*> > nodeGroups;
2378 SMESH_OctreeNode::FindCoincidentNodes ( nodesToCheck, &nodeGroups, myToler );
2380 myCoincidentIDs.Clear();
2381 std::list< std::list< const SMDS_MeshNode*> >::iterator groupIt = nodeGroups.begin();
2382 for ( ; groupIt != nodeGroups.end(); ++groupIt )
2384 std::list< const SMDS_MeshNode*>& coincNodes = *groupIt;
2385 std::list< const SMDS_MeshNode*>::iterator n = coincNodes.begin();
2386 for ( ; n != coincNodes.end(); ++n )
2387 myCoincidentIDs.Add( (*n)->GetID() );
2392 //================================================================================
2394 Class : CoincidentElements
2395 Description : Predicate of Coincident Elements
2396 Note : This class is suitable only for visualization of Coincident Elements
2398 //================================================================================
2400 CoincidentElements::CoincidentElements()
2405 void CoincidentElements::SetMesh( const SMDS_Mesh* theMesh )
2410 bool CoincidentElements::IsSatisfy( long theElementId )
2412 if ( !myMesh ) return false;
2414 if ( const SMDS_MeshElement* e = myMesh->FindElement( theElementId ))
2416 if ( e->GetType() != GetType() ) return false;
2417 std::set< const SMDS_MeshNode* > elemNodes( e->begin_nodes(), e->end_nodes() );
2418 const int nbNodes = e->NbNodes();
2419 SMDS_ElemIteratorPtr invIt = (*elemNodes.begin())->GetInverseElementIterator( GetType() );
2420 while ( invIt->more() )
2422 const SMDS_MeshElement* e2 = invIt->next();
2423 if ( e2 == e || e2->NbNodes() != nbNodes ) continue;
2425 bool sameNodes = true;
2426 for ( size_t i = 0; i < elemNodes.size() && sameNodes; ++i )
2427 sameNodes = ( elemNodes.count( e2->GetNode( i )));
2435 SMDSAbs_ElementType CoincidentElements1D::GetType() const
2437 return SMDSAbs_Edge;
2439 SMDSAbs_ElementType CoincidentElements2D::GetType() const
2441 return SMDSAbs_Face;
2443 SMDSAbs_ElementType CoincidentElements3D::GetType() const
2445 return SMDSAbs_Volume;
2449 //================================================================================
2452 Description : Predicate for free borders
2454 //================================================================================
2456 FreeBorders::FreeBorders()
2461 void FreeBorders::SetMesh( const SMDS_Mesh* theMesh )
2466 bool FreeBorders::IsSatisfy( long theId )
2468 return getNbMultiConnection( myMesh, theId ) == 1;
2471 SMDSAbs_ElementType FreeBorders::GetType() const
2473 return SMDSAbs_Edge;
2477 //================================================================================
2480 Description : Predicate for free Edges
2482 //================================================================================
2484 FreeEdges::FreeEdges()
2489 void FreeEdges::SetMesh( const SMDS_Mesh* theMesh )
2494 bool FreeEdges::IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId )
2496 TColStd_MapOfInteger aMap;
2497 for ( int i = 0; i < 2; i++ )
2499 SMDS_ElemIteratorPtr anElemIter = theNodes[ i ]->GetInverseElementIterator(SMDSAbs_Face);
2500 while( anElemIter->more() )
2502 if ( const SMDS_MeshElement* anElem = anElemIter->next())
2504 const int anId = anElem->GetID();
2505 if ( anId != theFaceId && !aMap.Add( anId ))
2513 bool FreeEdges::IsSatisfy( long theId )
2518 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
2519 if ( aFace == 0 || aFace->GetType() != SMDSAbs_Face || aFace->NbNodes() < 3 )
2522 SMDS_NodeIteratorPtr anIter = aFace->interlacedNodesIterator();
2526 int i = 0, nbNodes = aFace->NbNodes();
2527 std::vector <const SMDS_MeshNode*> aNodes( nbNodes+1 );
2528 while( anIter->more() )
2529 if ( ! ( aNodes[ i++ ] = anIter->next() ))
2531 aNodes[ nbNodes ] = aNodes[ 0 ];
2533 for ( i = 0; i < nbNodes; i++ )
2534 if ( IsFreeEdge( &aNodes[ i ], theId ) )
2540 SMDSAbs_ElementType FreeEdges::GetType() const
2542 return SMDSAbs_Face;
2545 FreeEdges::Border::Border(long theElemId, long thePntId1, long thePntId2):
2548 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
2549 if(thePntId1 > thePntId2){
2550 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
2554 bool FreeEdges::Border::operator<(const FreeEdges::Border& x) const{
2555 if(myPntId[0] < x.myPntId[0]) return true;
2556 if(myPntId[0] == x.myPntId[0])
2557 if(myPntId[1] < x.myPntId[1]) return true;
2561 inline void UpdateBorders(const FreeEdges::Border& theBorder,
2562 FreeEdges::TBorders& theRegistry,
2563 FreeEdges::TBorders& theContainer)
2565 if(theRegistry.find(theBorder) == theRegistry.end()){
2566 theRegistry.insert(theBorder);
2567 theContainer.insert(theBorder);
2569 theContainer.erase(theBorder);
2573 void FreeEdges::GetBoreders(TBorders& theBorders)
2576 for ( SMDS_FaceIteratorPtr anIter = myMesh->facesIterator(); anIter->more(); )
2578 const SMDS_MeshFace* anElem = anIter->next();
2579 long anElemId = anElem->GetID();
2580 SMDS_NodeIteratorPtr aNodesIter = anElem->interlacedNodesIterator();
2581 if ( !aNodesIter->more() ) continue;
2582 long aNodeId[2] = {0,0};
2583 aNodeId[0] = anElem->GetNode( anElem->NbNodes()-1 )->GetID();
2584 for ( ; aNodesIter->more(); )
2586 aNodeId[1] = aNodesIter->next()->GetID();
2587 Border aBorder( anElemId, aNodeId[0], aNodeId[1] );
2588 UpdateBorders( aBorder, aRegistry, theBorders );
2589 aNodeId[0] = aNodeId[1];
2594 //================================================================================
2597 Description : Predicate for free nodes
2599 //================================================================================
2601 FreeNodes::FreeNodes()
2606 void FreeNodes::SetMesh( const SMDS_Mesh* theMesh )
2611 bool FreeNodes::IsSatisfy( long theNodeId )
2613 const SMDS_MeshNode* aNode = myMesh->FindNode( theNodeId );
2617 return (aNode->NbInverseElements() < 1);
2620 SMDSAbs_ElementType FreeNodes::GetType() const
2622 return SMDSAbs_Node;
2626 //================================================================================
2629 Description : Predicate for free faces
2631 //================================================================================
2633 FreeFaces::FreeFaces()
2638 void FreeFaces::SetMesh( const SMDS_Mesh* theMesh )
2643 bool FreeFaces::IsSatisfy( long theId )
2645 if (!myMesh) return false;
2646 // check that faces nodes refers to less than two common volumes
2647 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
2648 if ( !aFace || aFace->GetType() != SMDSAbs_Face )
2651 int nbNode = aFace->NbNodes();
2653 // collect volumes to check that number of volumes with count equal nbNode not less than 2
2654 typedef std::map< SMDS_MeshElement*, int > TMapOfVolume; // map of volume counters
2655 typedef std::map< SMDS_MeshElement*, int >::iterator TItrMapOfVolume; // iterator
2656 TMapOfVolume mapOfVol;
2658 SMDS_ElemIteratorPtr nodeItr = aFace->nodesIterator();
2659 while ( nodeItr->more() )
2661 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(nodeItr->next());
2662 if ( !aNode ) continue;
2663 SMDS_ElemIteratorPtr volItr = aNode->GetInverseElementIterator(SMDSAbs_Volume);
2664 while ( volItr->more() )
2666 SMDS_MeshElement* aVol = (SMDS_MeshElement*)volItr->next();
2667 TItrMapOfVolume itr = mapOfVol.insert( std::make_pair( aVol, 0 )).first;
2672 TItrMapOfVolume volItr = mapOfVol.begin();
2673 TItrMapOfVolume volEnd = mapOfVol.end();
2674 for ( ; volItr != volEnd; ++volItr )
2675 if ( (*volItr).second >= nbNode )
2677 // face is not free if number of volumes constructed on their nodes more than one
2681 SMDSAbs_ElementType FreeFaces::GetType() const
2683 return SMDSAbs_Face;
2686 //================================================================================
2688 Class : LinearOrQuadratic
2689 Description : Predicate to verify whether a mesh element is linear
2691 //================================================================================
2693 LinearOrQuadratic::LinearOrQuadratic()
2698 void LinearOrQuadratic::SetMesh( const SMDS_Mesh* theMesh )
2703 bool LinearOrQuadratic::IsSatisfy( long theId )
2705 if (!myMesh) return false;
2706 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2707 if ( !anElem || (myType != SMDSAbs_All && anElem->GetType() != myType) )
2709 return (!anElem->IsQuadratic());
2712 void LinearOrQuadratic::SetType( SMDSAbs_ElementType theType )
2717 SMDSAbs_ElementType LinearOrQuadratic::GetType() const
2722 //================================================================================
2725 Description : Functor for check color of group to which mesh element belongs to
2727 //================================================================================
2729 GroupColor::GroupColor()
2733 bool GroupColor::IsSatisfy( long theId )
2735 return myIDs.count( theId );
2738 void GroupColor::SetType( SMDSAbs_ElementType theType )
2743 SMDSAbs_ElementType GroupColor::GetType() const
2748 static bool isEqual( const Quantity_Color& theColor1,
2749 const Quantity_Color& theColor2 )
2751 // tolerance to compare colors
2752 const double tol = 5*1e-3;
2753 return ( fabs( theColor1.Red() - theColor2.Red() ) < tol &&
2754 fabs( theColor1.Green() - theColor2.Green() ) < tol &&
2755 fabs( theColor1.Blue() - theColor2.Blue() ) < tol );
2758 void GroupColor::SetMesh( const SMDS_Mesh* theMesh )
2762 const SMESHDS_Mesh* aMesh = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
2766 int nbGrp = aMesh->GetNbGroups();
2770 // iterates on groups and find necessary elements ids
2771 const std::set<SMESHDS_GroupBase*>& aGroups = aMesh->GetGroups();
2772 std::set<SMESHDS_GroupBase*>::const_iterator GrIt = aGroups.begin();
2773 for (; GrIt != aGroups.end(); GrIt++)
2775 SMESHDS_GroupBase* aGrp = (*GrIt);
2778 // check type and color of group
2779 if ( !isEqual( myColor, aGrp->GetColor() ))
2782 // IPAL52867 (prevent infinite recursion via GroupOnFilter)
2783 if ( SMESHDS_GroupOnFilter * gof = dynamic_cast< SMESHDS_GroupOnFilter* >( aGrp ))
2784 if ( gof->GetPredicate().get() == this )
2787 SMDSAbs_ElementType aGrpElType = (SMDSAbs_ElementType)aGrp->GetType();
2788 if ( myType == aGrpElType || (myType == SMDSAbs_All && aGrpElType != SMDSAbs_Node) ) {
2789 // add elements IDS into control
2790 int aSize = aGrp->Extent();
2791 for (int i = 0; i < aSize; i++)
2792 myIDs.insert( aGrp->GetID(i+1) );
2797 void GroupColor::SetColorStr( const TCollection_AsciiString& theStr )
2799 Kernel_Utils::Localizer loc;
2800 TCollection_AsciiString aStr = theStr;
2801 aStr.RemoveAll( ' ' );
2802 aStr.RemoveAll( '\t' );
2803 for ( int aPos = aStr.Search( ";;" ); aPos != -1; aPos = aStr.Search( ";;" ) )
2804 aStr.Remove( aPos, 2 );
2805 Standard_Real clr[3];
2806 clr[0] = clr[1] = clr[2] = 0.;
2807 for ( int i = 0; i < 3; i++ ) {
2808 TCollection_AsciiString tmpStr = aStr.Token( ";", i+1 );
2809 if ( !tmpStr.IsEmpty() && tmpStr.IsRealValue() )
2810 clr[i] = tmpStr.RealValue();
2812 myColor = Quantity_Color( clr[0], clr[1], clr[2], Quantity_TOC_RGB );
2815 //=======================================================================
2816 // name : GetRangeStr
2817 // Purpose : Get range as a string.
2818 // Example: "1,2,3,50-60,63,67,70-"
2819 //=======================================================================
2821 void GroupColor::GetColorStr( TCollection_AsciiString& theResStr ) const
2824 theResStr += TCollection_AsciiString( myColor.Red() );
2825 theResStr += TCollection_AsciiString( ";" ) + TCollection_AsciiString( myColor.Green() );
2826 theResStr += TCollection_AsciiString( ";" ) + TCollection_AsciiString( myColor.Blue() );
2829 //================================================================================
2831 Class : ElemGeomType
2832 Description : Predicate to check element geometry type
2834 //================================================================================
2836 ElemGeomType::ElemGeomType()
2839 myType = SMDSAbs_All;
2840 myGeomType = SMDSGeom_TRIANGLE;
2843 void ElemGeomType::SetMesh( const SMDS_Mesh* theMesh )
2848 bool ElemGeomType::IsSatisfy( long theId )
2850 if (!myMesh) return false;
2851 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2854 const SMDSAbs_ElementType anElemType = anElem->GetType();
2855 if ( myType != SMDSAbs_All && anElemType != myType )
2857 bool isOk = ( anElem->GetGeomType() == myGeomType );
2861 void ElemGeomType::SetType( SMDSAbs_ElementType theType )
2866 SMDSAbs_ElementType ElemGeomType::GetType() const
2871 void ElemGeomType::SetGeomType( SMDSAbs_GeometryType theType )
2873 myGeomType = theType;
2876 SMDSAbs_GeometryType ElemGeomType::GetGeomType() const
2881 //================================================================================
2883 Class : ElemEntityType
2884 Description : Predicate to check element entity type
2886 //================================================================================
2888 ElemEntityType::ElemEntityType():
2890 myType( SMDSAbs_All ),
2891 myEntityType( SMDSEntity_0D )
2895 void ElemEntityType::SetMesh( const SMDS_Mesh* theMesh )
2900 bool ElemEntityType::IsSatisfy( long theId )
2902 if ( !myMesh ) return false;
2903 if ( myType == SMDSAbs_Node )
2904 return myMesh->FindNode( theId );
2905 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2907 myEntityType == anElem->GetEntityType() );
2910 void ElemEntityType::SetType( SMDSAbs_ElementType theType )
2915 SMDSAbs_ElementType ElemEntityType::GetType() const
2920 void ElemEntityType::SetElemEntityType( SMDSAbs_EntityType theEntityType )
2922 myEntityType = theEntityType;
2925 SMDSAbs_EntityType ElemEntityType::GetElemEntityType() const
2927 return myEntityType;
2930 //================================================================================
2932 * \brief Class ConnectedElements
2934 //================================================================================
2936 ConnectedElements::ConnectedElements():
2937 myNodeID(0), myType( SMDSAbs_All ), myOkIDsReady( false ) {}
2939 SMDSAbs_ElementType ConnectedElements::GetType() const
2942 int ConnectedElements::GetNode() const
2943 { return myXYZ.empty() ? myNodeID : 0; } // myNodeID can be found by myXYZ
2945 std::vector<double> ConnectedElements::GetPoint() const
2948 void ConnectedElements::clearOkIDs()
2949 { myOkIDsReady = false; myOkIDs.clear(); }
2951 void ConnectedElements::SetType( SMDSAbs_ElementType theType )
2953 if ( myType != theType || myMeshModifTracer.IsMeshModified() )
2958 void ConnectedElements::SetMesh( const SMDS_Mesh* theMesh )
2960 myMeshModifTracer.SetMesh( theMesh );
2961 if ( myMeshModifTracer.IsMeshModified() )
2964 if ( !myXYZ.empty() )
2965 SetPoint( myXYZ[0], myXYZ[1], myXYZ[2] ); // find a node near myXYZ it in a new mesh
2969 void ConnectedElements::SetNode( int nodeID )
2974 bool isSameDomain = false;
2975 if ( myOkIDsReady && myMeshModifTracer.GetMesh() && !myMeshModifTracer.IsMeshModified() )
2976 if ( const SMDS_MeshNode* n = myMeshModifTracer.GetMesh()->FindNode( myNodeID ))
2978 SMDS_ElemIteratorPtr eIt = n->GetInverseElementIterator( myType );
2979 while ( !isSameDomain && eIt->more() )
2980 isSameDomain = IsSatisfy( eIt->next()->GetID() );
2982 if ( !isSameDomain )
2986 void ConnectedElements::SetPoint( double x, double y, double z )
2994 bool isSameDomain = false;
2996 // find myNodeID by myXYZ if possible
2997 if ( myMeshModifTracer.GetMesh() )
2999 SMESHUtils::Deleter<SMESH_ElementSearcher> searcher
3000 ( SMESH_MeshAlgos::GetElementSearcher( (SMDS_Mesh&) *myMeshModifTracer.GetMesh() ));
3002 std::vector< const SMDS_MeshElement* > foundElems;
3003 searcher->FindElementsByPoint( gp_Pnt(x,y,z), SMDSAbs_All, foundElems );
3005 if ( !foundElems.empty() )
3007 myNodeID = foundElems[0]->GetNode(0)->GetID();
3008 if ( myOkIDsReady && !myMeshModifTracer.IsMeshModified() )
3009 isSameDomain = IsSatisfy( foundElems[0]->GetID() );
3012 if ( !isSameDomain )
3016 bool ConnectedElements::IsSatisfy( long theElementId )
3018 // Here we do NOT check if the mesh has changed, we do it in Set...() only!!!
3020 if ( !myOkIDsReady )
3022 if ( !myMeshModifTracer.GetMesh() )
3024 const SMDS_MeshNode* node0 = myMeshModifTracer.GetMesh()->FindNode( myNodeID );
3028 std::list< const SMDS_MeshNode* > nodeQueue( 1, node0 );
3029 std::set< int > checkedNodeIDs;
3031 // foreach node in nodeQueue:
3032 // foreach element sharing a node:
3033 // add ID of an element of myType to myOkIDs;
3034 // push all element nodes absent from checkedNodeIDs to nodeQueue;
3035 while ( !nodeQueue.empty() )
3037 const SMDS_MeshNode* node = nodeQueue.front();
3038 nodeQueue.pop_front();
3040 // loop on elements sharing the node
3041 SMDS_ElemIteratorPtr eIt = node->GetInverseElementIterator();
3042 while ( eIt->more() )
3044 // keep elements of myType
3045 const SMDS_MeshElement* element = eIt->next();
3046 if ( myType == SMDSAbs_All || element->GetType() == myType )
3047 myOkIDs.insert( myOkIDs.end(), element->GetID() );
3049 // enqueue nodes of the element
3050 SMDS_ElemIteratorPtr nIt = element->nodesIterator();
3051 while ( nIt->more() )
3053 const SMDS_MeshNode* n = static_cast< const SMDS_MeshNode* >( nIt->next() );
3054 if ( checkedNodeIDs.insert( n->GetID() ).second )
3055 nodeQueue.push_back( n );
3059 if ( myType == SMDSAbs_Node )
3060 std::swap( myOkIDs, checkedNodeIDs );
3062 size_t totalNbElems = myMeshModifTracer.GetMesh()->GetMeshInfo().NbElements( myType );
3063 if ( myOkIDs.size() == totalNbElems )
3066 myOkIDsReady = true;
3069 return myOkIDs.empty() ? true : myOkIDs.count( theElementId );
3072 //================================================================================
3074 * \brief Class CoplanarFaces
3076 //================================================================================
3080 inline bool isLessAngle( const gp_Vec& v1, const gp_Vec& v2, const double cos )
3082 double dot = v1 * v2; // cos * |v1| * |v2|
3083 double l1 = v1.SquareMagnitude();
3084 double l2 = v2.SquareMagnitude();
3085 return (( dot * cos >= 0 ) &&
3086 ( dot * dot ) / l1 / l2 >= ( cos * cos ));
3089 CoplanarFaces::CoplanarFaces()
3090 : myFaceID(0), myToler(0)
3093 void CoplanarFaces::SetMesh( const SMDS_Mesh* theMesh )
3095 myMeshModifTracer.SetMesh( theMesh );
3096 if ( myMeshModifTracer.IsMeshModified() )
3098 // Build a set of coplanar face ids
3100 myCoplanarIDs.Clear();
3102 if ( !myMeshModifTracer.GetMesh() || !myFaceID || !myToler )
3105 const SMDS_MeshElement* face = myMeshModifTracer.GetMesh()->FindElement( myFaceID );
3106 if ( !face || face->GetType() != SMDSAbs_Face )
3110 gp_Vec myNorm = getNormale( static_cast<const SMDS_MeshFace*>(face), &normOK );
3114 const double cosTol = Cos( myToler * M_PI / 180. );
3115 NCollection_Map< SMESH_TLink, SMESH_TLink > checkedLinks;
3117 std::list< std::pair< const SMDS_MeshElement*, gp_Vec > > faceQueue;
3118 faceQueue.push_back( std::make_pair( face, myNorm ));
3119 while ( !faceQueue.empty() )
3121 face = faceQueue.front().first;
3122 myNorm = faceQueue.front().second;
3123 faceQueue.pop_front();
3125 for ( int i = 0, nbN = face->NbCornerNodes(); i < nbN; ++i )
3127 const SMDS_MeshNode* n1 = face->GetNode( i );
3128 const SMDS_MeshNode* n2 = face->GetNode(( i+1 )%nbN);
3129 if ( !checkedLinks.Add( SMESH_TLink( n1, n2 )))
3131 SMDS_ElemIteratorPtr fIt = n1->GetInverseElementIterator(SMDSAbs_Face);
3132 while ( fIt->more() )
3134 const SMDS_MeshElement* f = fIt->next();
3135 if ( f->GetNodeIndex( n2 ) > -1 )
3137 gp_Vec norm = getNormale( static_cast<const SMDS_MeshFace*>(f), &normOK );
3138 if (!normOK || isLessAngle( myNorm, norm, cosTol))
3140 myCoplanarIDs.Add( f->GetID() );
3141 faceQueue.push_back( std::make_pair( f, norm ));
3149 bool CoplanarFaces::IsSatisfy( long theElementId )
3151 return myCoplanarIDs.Contains( theElementId );
3156 *Description : Predicate for Range of Ids.
3157 * Range may be specified with two ways.
3158 * 1. Using AddToRange method
3159 * 2. With SetRangeStr method. Parameter of this method is a string
3160 * like as "1,2,3,50-60,63,67,70-"
3163 //=======================================================================
3164 // name : RangeOfIds
3165 // Purpose : Constructor
3166 //=======================================================================
3167 RangeOfIds::RangeOfIds()
3170 myType = SMDSAbs_All;
3173 //=======================================================================
3175 // Purpose : Set mesh
3176 //=======================================================================
3177 void RangeOfIds::SetMesh( const SMDS_Mesh* theMesh )
3182 //=======================================================================
3183 // name : AddToRange
3184 // Purpose : Add ID to the range
3185 //=======================================================================
3186 bool RangeOfIds::AddToRange( long theEntityId )
3188 myIds.Add( theEntityId );
3192 //=======================================================================
3193 // name : GetRangeStr
3194 // Purpose : Get range as a string.
3195 // Example: "1,2,3,50-60,63,67,70-"
3196 //=======================================================================
3197 void RangeOfIds::GetRangeStr( TCollection_AsciiString& theResStr )
3201 TColStd_SequenceOfInteger anIntSeq;
3202 TColStd_SequenceOfAsciiString aStrSeq;
3204 TColStd_MapIteratorOfMapOfInteger anIter( myIds );
3205 for ( ; anIter.More(); anIter.Next() )
3207 int anId = anIter.Key();
3208 TCollection_AsciiString aStr( anId );
3209 anIntSeq.Append( anId );
3210 aStrSeq.Append( aStr );
3213 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
3215 int aMinId = myMin( i );
3216 int aMaxId = myMax( i );
3218 TCollection_AsciiString aStr;
3219 if ( aMinId != IntegerFirst() )
3224 if ( aMaxId != IntegerLast() )
3227 // find position of the string in result sequence and insert string in it
3228 if ( anIntSeq.Length() == 0 )
3230 anIntSeq.Append( aMinId );
3231 aStrSeq.Append( aStr );
3235 if ( aMinId < anIntSeq.First() )
3237 anIntSeq.Prepend( aMinId );
3238 aStrSeq.Prepend( aStr );
3240 else if ( aMinId > anIntSeq.Last() )
3242 anIntSeq.Append( aMinId );
3243 aStrSeq.Append( aStr );
3246 for ( int j = 1, k = anIntSeq.Length(); j <= k; j++ )
3247 if ( aMinId < anIntSeq( j ) )
3249 anIntSeq.InsertBefore( j, aMinId );
3250 aStrSeq.InsertBefore( j, aStr );
3256 if ( aStrSeq.Length() == 0 )
3259 theResStr = aStrSeq( 1 );
3260 for ( int j = 2, k = aStrSeq.Length(); j <= k; j++ )
3263 theResStr += aStrSeq( j );
3267 //=======================================================================
3268 // name : SetRangeStr
3269 // Purpose : Define range with string
3270 // Example of entry string: "1,2,3,50-60,63,67,70-"
3271 //=======================================================================
3272 bool RangeOfIds::SetRangeStr( const TCollection_AsciiString& theStr )
3278 TCollection_AsciiString aStr = theStr;
3279 for ( int i = 1; i <= aStr.Length(); ++i )
3281 char c = aStr.Value( i );
3282 if ( !isdigit( c ) && c != ',' && c != '-' )
3283 aStr.SetValue( i, ',');
3285 aStr.RemoveAll( ' ' );
3287 TCollection_AsciiString tmpStr = aStr.Token( ",", 1 );
3289 while ( tmpStr != "" )
3291 tmpStr = aStr.Token( ",", i++ );
3292 int aPos = tmpStr.Search( '-' );
3296 if ( tmpStr.IsIntegerValue() )
3297 myIds.Add( tmpStr.IntegerValue() );
3303 TCollection_AsciiString aMaxStr = tmpStr.Split( aPos );
3304 TCollection_AsciiString aMinStr = tmpStr;
3306 while ( aMinStr.Search( "-" ) != -1 ) aMinStr.RemoveAll( '-' );
3307 while ( aMaxStr.Search( "-" ) != -1 ) aMaxStr.RemoveAll( '-' );
3309 if ( (!aMinStr.IsEmpty() && !aMinStr.IsIntegerValue()) ||
3310 (!aMaxStr.IsEmpty() && !aMaxStr.IsIntegerValue()) )
3313 myMin.Append( aMinStr.IsEmpty() ? IntegerFirst() : aMinStr.IntegerValue() );
3314 myMax.Append( aMaxStr.IsEmpty() ? IntegerLast() : aMaxStr.IntegerValue() );
3321 //=======================================================================
3323 // Purpose : Get type of supported entities
3324 //=======================================================================
3325 SMDSAbs_ElementType RangeOfIds::GetType() const
3330 //=======================================================================
3332 // Purpose : Set type of supported entities
3333 //=======================================================================
3334 void RangeOfIds::SetType( SMDSAbs_ElementType theType )
3339 //=======================================================================
3341 // Purpose : Verify whether entity satisfies to this rpedicate
3342 //=======================================================================
3343 bool RangeOfIds::IsSatisfy( long theId )
3348 if ( myType == SMDSAbs_Node )
3350 if ( myMesh->FindNode( theId ) == 0 )
3355 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
3356 if ( anElem == 0 || (myType != anElem->GetType() && myType != SMDSAbs_All ))
3360 if ( myIds.Contains( theId ) )
3363 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
3364 if ( theId >= myMin( i ) && theId <= myMax( i ) )
3372 Description : Base class for comparators
3374 Comparator::Comparator():
3378 Comparator::~Comparator()
3381 void Comparator::SetMesh( const SMDS_Mesh* theMesh )
3384 myFunctor->SetMesh( theMesh );
3387 void Comparator::SetMargin( double theValue )
3389 myMargin = theValue;
3392 void Comparator::SetNumFunctor( NumericalFunctorPtr theFunct )
3394 myFunctor = theFunct;
3397 SMDSAbs_ElementType Comparator::GetType() const
3399 return myFunctor ? myFunctor->GetType() : SMDSAbs_All;
3402 double Comparator::GetMargin()
3410 Description : Comparator "<"
3412 bool LessThan::IsSatisfy( long theId )
3414 return myFunctor && myFunctor->GetValue( theId ) < myMargin;
3420 Description : Comparator ">"
3422 bool MoreThan::IsSatisfy( long theId )
3424 return myFunctor && myFunctor->GetValue( theId ) > myMargin;
3430 Description : Comparator "="
3433 myToler(Precision::Confusion())
3436 bool EqualTo::IsSatisfy( long theId )
3438 return myFunctor && fabs( myFunctor->GetValue( theId ) - myMargin ) < myToler;
3441 void EqualTo::SetTolerance( double theToler )
3446 double EqualTo::GetTolerance()
3453 Description : Logical NOT predicate
3455 LogicalNOT::LogicalNOT()
3458 LogicalNOT::~LogicalNOT()
3461 bool LogicalNOT::IsSatisfy( long theId )
3463 return myPredicate && !myPredicate->IsSatisfy( theId );
3466 void LogicalNOT::SetMesh( const SMDS_Mesh* theMesh )
3469 myPredicate->SetMesh( theMesh );
3472 void LogicalNOT::SetPredicate( PredicatePtr thePred )
3474 myPredicate = thePred;
3477 SMDSAbs_ElementType LogicalNOT::GetType() const
3479 return myPredicate ? myPredicate->GetType() : SMDSAbs_All;
3484 Class : LogicalBinary
3485 Description : Base class for binary logical predicate
3487 LogicalBinary::LogicalBinary()
3490 LogicalBinary::~LogicalBinary()
3493 void LogicalBinary::SetMesh( const SMDS_Mesh* theMesh )
3496 myPredicate1->SetMesh( theMesh );
3499 myPredicate2->SetMesh( theMesh );
3502 void LogicalBinary::SetPredicate1( PredicatePtr thePredicate )
3504 myPredicate1 = thePredicate;
3507 void LogicalBinary::SetPredicate2( PredicatePtr thePredicate )
3509 myPredicate2 = thePredicate;
3512 SMDSAbs_ElementType LogicalBinary::GetType() const
3514 if ( !myPredicate1 || !myPredicate2 )
3517 SMDSAbs_ElementType aType1 = myPredicate1->GetType();
3518 SMDSAbs_ElementType aType2 = myPredicate2->GetType();
3520 return aType1 == aType2 ? aType1 : SMDSAbs_All;
3526 Description : Logical AND
3528 bool LogicalAND::IsSatisfy( long theId )
3533 myPredicate1->IsSatisfy( theId ) &&
3534 myPredicate2->IsSatisfy( theId );
3540 Description : Logical OR
3542 bool LogicalOR::IsSatisfy( long theId )
3547 (myPredicate1->IsSatisfy( theId ) ||
3548 myPredicate2->IsSatisfy( theId ));
3557 // #include <tbb/parallel_for.h>
3558 // #include <tbb/enumerable_thread_specific.h>
3560 // namespace Parallel
3562 // typedef tbb::enumerable_thread_specific< TIdSequence > TIdSeq;
3566 // const SMDS_Mesh* myMesh;
3567 // PredicatePtr myPredicate;
3568 // TIdSeq & myOKIds;
3569 // Predicate( const SMDS_Mesh* m, PredicatePtr p, TIdSeq & ids ):
3570 // myMesh(m), myPredicate(p->Duplicate()), myOKIds(ids) {}
3571 // void operator() ( const tbb::blocked_range<size_t>& r ) const
3573 // for ( size_t i = r.begin(); i != r.end(); ++i )
3574 // if ( myPredicate->IsSatisfy( i ))
3575 // myOKIds.local().push_back();
3587 void Filter::SetPredicate( PredicatePtr thePredicate )
3589 myPredicate = thePredicate;
3592 void Filter::GetElementsId( const SMDS_Mesh* theMesh,
3593 PredicatePtr thePredicate,
3594 TIdSequence& theSequence )
3596 theSequence.clear();
3598 if ( !theMesh || !thePredicate )
3601 thePredicate->SetMesh( theMesh );
3603 SMDS_ElemIteratorPtr elemIt = theMesh->elementsIterator( thePredicate->GetType() );
3605 while ( elemIt->more() ) {
3606 const SMDS_MeshElement* anElem = elemIt->next();
3607 long anId = anElem->GetID();
3608 if ( thePredicate->IsSatisfy( anId ) )
3609 theSequence.push_back( anId );
3614 void Filter::GetElementsId( const SMDS_Mesh* theMesh,
3615 Filter::TIdSequence& theSequence )
3617 GetElementsId(theMesh,myPredicate,theSequence);
3624 typedef std::set<SMDS_MeshFace*> TMapOfFacePtr;
3630 ManifoldPart::Link::Link( SMDS_MeshNode* theNode1,
3631 SMDS_MeshNode* theNode2 )
3637 ManifoldPart::Link::~Link()
3643 bool ManifoldPart::Link::IsEqual( const ManifoldPart::Link& theLink ) const
3645 if ( myNode1 == theLink.myNode1 &&
3646 myNode2 == theLink.myNode2 )
3648 else if ( myNode1 == theLink.myNode2 &&
3649 myNode2 == theLink.myNode1 )
3655 bool ManifoldPart::Link::operator<( const ManifoldPart::Link& x ) const
3657 if(myNode1 < x.myNode1) return true;
3658 if(myNode1 == x.myNode1)
3659 if(myNode2 < x.myNode2) return true;
3663 bool ManifoldPart::IsEqual( const ManifoldPart::Link& theLink1,
3664 const ManifoldPart::Link& theLink2 )
3666 return theLink1.IsEqual( theLink2 );
3669 ManifoldPart::ManifoldPart()
3672 myAngToler = Precision::Angular();
3673 myIsOnlyManifold = true;
3676 ManifoldPart::~ManifoldPart()
3681 void ManifoldPart::SetMesh( const SMDS_Mesh* theMesh )
3687 SMDSAbs_ElementType ManifoldPart::GetType() const
3688 { return SMDSAbs_Face; }
3690 bool ManifoldPart::IsSatisfy( long theElementId )
3692 return myMapIds.Contains( theElementId );
3695 void ManifoldPart::SetAngleTolerance( const double theAngToler )
3696 { myAngToler = theAngToler; }
3698 double ManifoldPart::GetAngleTolerance() const
3699 { return myAngToler; }
3701 void ManifoldPart::SetIsOnlyManifold( const bool theIsOnly )
3702 { myIsOnlyManifold = theIsOnly; }
3704 void ManifoldPart::SetStartElem( const long theStartId )
3705 { myStartElemId = theStartId; }
3707 bool ManifoldPart::process()
3710 myMapBadGeomIds.Clear();
3712 myAllFacePtr.clear();
3713 myAllFacePtrIntDMap.clear();
3717 // collect all faces into own map
3718 SMDS_FaceIteratorPtr anFaceItr = myMesh->facesIterator();
3719 for (; anFaceItr->more(); )
3721 SMDS_MeshFace* aFacePtr = (SMDS_MeshFace*)anFaceItr->next();
3722 myAllFacePtr.push_back( aFacePtr );
3723 myAllFacePtrIntDMap[aFacePtr] = myAllFacePtr.size()-1;
3726 SMDS_MeshFace* aStartFace = (SMDS_MeshFace*)myMesh->FindElement( myStartElemId );
3730 // the map of non manifold links and bad geometry
3731 TMapOfLink aMapOfNonManifold;
3732 TColStd_MapOfInteger aMapOfTreated;
3734 // begin cycle on faces from start index and run on vector till the end
3735 // and from begin to start index to cover whole vector
3736 const int aStartIndx = myAllFacePtrIntDMap[aStartFace];
3737 bool isStartTreat = false;
3738 for ( int fi = aStartIndx; !isStartTreat || fi != aStartIndx ; fi++ )
3740 if ( fi == aStartIndx )
3741 isStartTreat = true;
3742 // as result next time when fi will be equal to aStartIndx
3744 SMDS_MeshFace* aFacePtr = myAllFacePtr[ fi ];
3745 if ( aMapOfTreated.Contains( aFacePtr->GetID() ) )
3748 aMapOfTreated.Add( aFacePtr->GetID() );
3749 TColStd_MapOfInteger aResFaces;
3750 if ( !findConnected( myAllFacePtrIntDMap, aFacePtr,
3751 aMapOfNonManifold, aResFaces ) )
3753 TColStd_MapIteratorOfMapOfInteger anItr( aResFaces );
3754 for ( ; anItr.More(); anItr.Next() )
3756 int aFaceId = anItr.Key();
3757 aMapOfTreated.Add( aFaceId );
3758 myMapIds.Add( aFaceId );
3761 if ( fi == int( myAllFacePtr.size() - 1 ))
3763 } // end run on vector of faces
3764 return !myMapIds.IsEmpty();
3767 static void getLinks( const SMDS_MeshFace* theFace,
3768 ManifoldPart::TVectorOfLink& theLinks )
3770 int aNbNode = theFace->NbNodes();
3771 SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
3773 SMDS_MeshNode* aNode = 0;
3774 for ( ; aNodeItr->more() && i <= aNbNode; )
3777 SMDS_MeshNode* aN1 = (SMDS_MeshNode*)aNodeItr->next();
3781 SMDS_MeshNode* aN2 = ( i >= aNbNode ) ? aNode : (SMDS_MeshNode*)aNodeItr->next();
3783 ManifoldPart::Link aLink( aN1, aN2 );
3784 theLinks.push_back( aLink );
3788 bool ManifoldPart::findConnected
3789 ( const ManifoldPart::TDataMapFacePtrInt& theAllFacePtrInt,
3790 SMDS_MeshFace* theStartFace,
3791 ManifoldPart::TMapOfLink& theNonManifold,
3792 TColStd_MapOfInteger& theResFaces )
3794 theResFaces.Clear();
3795 if ( !theAllFacePtrInt.size() )
3798 if ( getNormale( theStartFace ).SquareModulus() <= gp::Resolution() )
3800 myMapBadGeomIds.Add( theStartFace->GetID() );
3804 ManifoldPart::TMapOfLink aMapOfBoundary, aMapToSkip;
3805 ManifoldPart::TVectorOfLink aSeqOfBoundary;
3806 theResFaces.Add( theStartFace->GetID() );
3807 ManifoldPart::TDataMapOfLinkFacePtr aDMapLinkFace;
3809 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
3810 aDMapLinkFace, theNonManifold, theStartFace );
3812 bool isDone = false;
3813 while ( !isDone && aMapOfBoundary.size() != 0 )
3815 bool isToReset = false;
3816 ManifoldPart::TVectorOfLink::iterator pLink = aSeqOfBoundary.begin();
3817 for ( ; !isToReset && pLink != aSeqOfBoundary.end(); ++pLink )
3819 ManifoldPart::Link aLink = *pLink;
3820 if ( aMapToSkip.find( aLink ) != aMapToSkip.end() )
3822 // each link could be treated only once
3823 aMapToSkip.insert( aLink );
3825 ManifoldPart::TVectorOfFacePtr aFaces;
3827 if ( myIsOnlyManifold &&
3828 (theNonManifold.find( aLink ) != theNonManifold.end()) )
3832 getFacesByLink( aLink, aFaces );
3833 // filter the element to keep only indicated elements
3834 ManifoldPart::TVectorOfFacePtr aFiltered;
3835 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
3836 for ( ; pFace != aFaces.end(); ++pFace )
3838 SMDS_MeshFace* aFace = *pFace;
3839 if ( myAllFacePtrIntDMap.find( aFace ) != myAllFacePtrIntDMap.end() )
3840 aFiltered.push_back( aFace );
3843 if ( aFaces.size() < 2 ) // no neihgbour faces
3845 else if ( myIsOnlyManifold && aFaces.size() > 2 ) // non manifold case
3847 theNonManifold.insert( aLink );
3852 // compare normal with normals of neighbor element
3853 SMDS_MeshFace* aPrevFace = aDMapLinkFace[ aLink ];
3854 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
3855 for ( ; pFace != aFaces.end(); ++pFace )
3857 SMDS_MeshFace* aNextFace = *pFace;
3858 if ( aPrevFace == aNextFace )
3860 int anNextFaceID = aNextFace->GetID();
3861 if ( myIsOnlyManifold && theResFaces.Contains( anNextFaceID ) )
3862 // should not be with non manifold restriction. probably bad topology
3864 // check if face was treated and skipped
3865 if ( myMapBadGeomIds.Contains( anNextFaceID ) ||
3866 !isInPlane( aPrevFace, aNextFace ) )
3868 // add new element to connected and extend the boundaries.
3869 theResFaces.Add( anNextFaceID );
3870 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
3871 aDMapLinkFace, theNonManifold, aNextFace );
3875 isDone = !isToReset;
3878 return !theResFaces.IsEmpty();
3881 bool ManifoldPart::isInPlane( const SMDS_MeshFace* theFace1,
3882 const SMDS_MeshFace* theFace2 )
3884 gp_Dir aNorm1 = gp_Dir( getNormale( theFace1 ) );
3885 gp_XYZ aNorm2XYZ = getNormale( theFace2 );
3886 if ( aNorm2XYZ.SquareModulus() <= gp::Resolution() )
3888 myMapBadGeomIds.Add( theFace2->GetID() );
3891 if ( aNorm1.IsParallel( gp_Dir( aNorm2XYZ ), myAngToler ) )
3897 void ManifoldPart::expandBoundary
3898 ( ManifoldPart::TMapOfLink& theMapOfBoundary,
3899 ManifoldPart::TVectorOfLink& theSeqOfBoundary,
3900 ManifoldPart::TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
3901 ManifoldPart::TMapOfLink& theNonManifold,
3902 SMDS_MeshFace* theNextFace ) const
3904 ManifoldPart::TVectorOfLink aLinks;
3905 getLinks( theNextFace, aLinks );
3906 int aNbLink = (int)aLinks.size();
3907 for ( int i = 0; i < aNbLink; i++ )
3909 ManifoldPart::Link aLink = aLinks[ i ];
3910 if ( myIsOnlyManifold && (theNonManifold.find( aLink ) != theNonManifold.end()) )
3912 if ( theMapOfBoundary.find( aLink ) != theMapOfBoundary.end() )
3914 if ( myIsOnlyManifold )
3916 // remove from boundary
3917 theMapOfBoundary.erase( aLink );
3918 ManifoldPart::TVectorOfLink::iterator pLink = theSeqOfBoundary.begin();
3919 for ( ; pLink != theSeqOfBoundary.end(); ++pLink )
3921 ManifoldPart::Link aBoundLink = *pLink;
3922 if ( aBoundLink.IsEqual( aLink ) )
3924 theSeqOfBoundary.erase( pLink );
3932 theMapOfBoundary.insert( aLink );
3933 theSeqOfBoundary.push_back( aLink );
3934 theDMapLinkFacePtr[ aLink ] = theNextFace;
3939 void ManifoldPart::getFacesByLink( const ManifoldPart::Link& theLink,
3940 ManifoldPart::TVectorOfFacePtr& theFaces ) const
3943 // take all faces that shared first node
3944 SMDS_ElemIteratorPtr anItr = theLink.myNode1->GetInverseElementIterator( SMDSAbs_Face );
3945 SMDS_StdIterator< const SMDS_MeshElement*, SMDS_ElemIteratorPtr > faces( anItr ), facesEnd;
3946 std::set<const SMDS_MeshElement *> aSetOfFaces( faces, facesEnd );
3948 // take all faces that shared second node
3949 anItr = theLink.myNode2->GetInverseElementIterator( SMDSAbs_Face );
3950 // find the common part of two sets
3951 for ( ; anItr->more(); )
3953 const SMDS_MeshElement* aFace = anItr->next();
3954 if ( aSetOfFaces.count( aFace ))
3955 theFaces.push_back( (SMDS_MeshFace*) aFace );
3960 Class : BelongToMeshGroup
3961 Description : Verify whether a mesh element is included into a mesh group
3963 BelongToMeshGroup::BelongToMeshGroup(): myGroup( 0 )
3967 void BelongToMeshGroup::SetGroup( SMESHDS_GroupBase* g )
3972 void BelongToMeshGroup::SetStoreName( const std::string& sn )
3977 void BelongToMeshGroup::SetMesh( const SMDS_Mesh* theMesh )
3979 if ( myGroup && myGroup->GetMesh() != theMesh )
3983 if ( !myGroup && !myStoreName.empty() )
3985 if ( const SMESHDS_Mesh* aMesh = dynamic_cast<const SMESHDS_Mesh*>(theMesh))
3987 const std::set<SMESHDS_GroupBase*>& grps = aMesh->GetGroups();
3988 std::set<SMESHDS_GroupBase*>::const_iterator g = grps.begin();
3989 for ( ; g != grps.end() && !myGroup; ++g )
3990 if ( *g && myStoreName == (*g)->GetStoreName() )
3996 myGroup->IsEmpty(); // make GroupOnFilter update its predicate
4000 bool BelongToMeshGroup::IsSatisfy( long theElementId )
4002 return myGroup ? myGroup->Contains( theElementId ) : false;
4005 SMDSAbs_ElementType BelongToMeshGroup::GetType() const
4007 return myGroup ? myGroup->GetType() : SMDSAbs_All;
4010 //================================================================================
4011 // ElementsOnSurface
4012 //================================================================================
4014 ElementsOnSurface::ElementsOnSurface()
4017 myType = SMDSAbs_All;
4019 myToler = Precision::Confusion();
4020 myUseBoundaries = false;
4023 ElementsOnSurface::~ElementsOnSurface()
4027 void ElementsOnSurface::SetMesh( const SMDS_Mesh* theMesh )
4029 myMeshModifTracer.SetMesh( theMesh );
4030 if ( myMeshModifTracer.IsMeshModified())
4034 bool ElementsOnSurface::IsSatisfy( long theElementId )
4036 return myIds.Contains( theElementId );
4039 SMDSAbs_ElementType ElementsOnSurface::GetType() const
4042 void ElementsOnSurface::SetTolerance( const double theToler )
4044 if ( myToler != theToler )
4049 double ElementsOnSurface::GetTolerance() const
4052 void ElementsOnSurface::SetUseBoundaries( bool theUse )
4054 if ( myUseBoundaries != theUse ) {
4055 myUseBoundaries = theUse;
4056 SetSurface( mySurf, myType );
4060 void ElementsOnSurface::SetSurface( const TopoDS_Shape& theShape,
4061 const SMDSAbs_ElementType theType )
4066 if ( theShape.IsNull() || theShape.ShapeType() != TopAbs_FACE )
4068 mySurf = TopoDS::Face( theShape );
4069 BRepAdaptor_Surface SA( mySurf, myUseBoundaries );
4071 u1 = SA.FirstUParameter(),
4072 u2 = SA.LastUParameter(),
4073 v1 = SA.FirstVParameter(),
4074 v2 = SA.LastVParameter();
4075 Handle(Geom_Surface) surf = BRep_Tool::Surface( mySurf );
4076 myProjector.Init( surf, u1,u2, v1,v2 );
4080 void ElementsOnSurface::process()
4083 if ( mySurf.IsNull() )
4086 if ( !myMeshModifTracer.GetMesh() )
4089 myIds.ReSize( myMeshModifTracer.GetMesh()->GetMeshInfo().NbElements( myType ));
4091 SMDS_ElemIteratorPtr anIter = myMeshModifTracer.GetMesh()->elementsIterator( myType );
4092 for(; anIter->more(); )
4093 process( anIter->next() );
4096 void ElementsOnSurface::process( const SMDS_MeshElement* theElemPtr )
4098 SMDS_ElemIteratorPtr aNodeItr = theElemPtr->nodesIterator();
4099 bool isSatisfy = true;
4100 for ( ; aNodeItr->more(); )
4102 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
4103 if ( !isOnSurface( aNode ) )
4110 myIds.Add( theElemPtr->GetID() );
4113 bool ElementsOnSurface::isOnSurface( const SMDS_MeshNode* theNode )
4115 if ( mySurf.IsNull() )
4118 gp_Pnt aPnt( theNode->X(), theNode->Y(), theNode->Z() );
4119 // double aToler2 = myToler * myToler;
4120 // if ( mySurf->IsKind(STANDARD_TYPE(Geom_Plane)))
4122 // gp_Pln aPln = Handle(Geom_Plane)::DownCast(mySurf)->Pln();
4123 // if ( aPln.SquareDistance( aPnt ) > aToler2 )
4126 // else if ( mySurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)))
4128 // gp_Cylinder aCyl = Handle(Geom_CylindricalSurface)::DownCast(mySurf)->Cylinder();
4129 // double aRad = aCyl.Radius();
4130 // gp_Ax3 anAxis = aCyl.Position();
4131 // gp_XYZ aLoc = aCyl.Location().XYZ();
4132 // double aXDist = anAxis.XDirection().XYZ() * ( aPnt.XYZ() - aLoc );
4133 // double aYDist = anAxis.YDirection().XYZ() * ( aPnt.XYZ() - aLoc );
4134 // if ( fabs(aXDist*aXDist + aYDist*aYDist - aRad*aRad) > aToler2 )
4139 myProjector.Perform( aPnt );
4140 bool isOn = ( myProjector.IsDone() && myProjector.LowerDistance() <= myToler );
4146 //================================================================================
4148 //================================================================================
4151 const int theIsCheckedFlag = 0x0000100;
4154 struct ElementsOnShape::Classifier
4156 Classifier() { mySolidClfr = 0; myFlags = 0; }
4158 void Init(const TopoDS_Shape& s, double tol, const Bnd_B3d* box = 0 );
4159 bool IsOut(const gp_Pnt& p) { return SetChecked( true ), (this->*myIsOutFun)( p ); }
4160 TopAbs_ShapeEnum ShapeType() const { return myShape.ShapeType(); }
4161 const TopoDS_Shape& Shape() const { return myShape; }
4162 const Bnd_B3d* GetBndBox() const { return & myBox; }
4163 bool IsChecked() { return myFlags & theIsCheckedFlag; }
4164 bool IsSetFlag( int flag ) const { return myFlags & flag; }
4165 void SetChecked( bool is ) { is ? SetFlag( theIsCheckedFlag ) : UnsetFlag( theIsCheckedFlag ); }
4166 void SetFlag ( int flag ) { myFlags |= flag; }
4167 void UnsetFlag( int flag ) { myFlags &= ~flag; }
4170 bool isOutOfSolid (const gp_Pnt& p);
4171 bool isOutOfBox (const gp_Pnt& p);
4172 bool isOutOfFace (const gp_Pnt& p);
4173 bool isOutOfEdge (const gp_Pnt& p);
4174 bool isOutOfVertex(const gp_Pnt& p);
4175 bool isBox (const TopoDS_Shape& s);
4177 bool (Classifier::* myIsOutFun)(const gp_Pnt& p);
4178 BRepClass3d_SolidClassifier* mySolidClfr; // ptr because of a run-time forbidden copy-constructor
4180 GeomAPI_ProjectPointOnSurf myProjFace;
4181 GeomAPI_ProjectPointOnCurve myProjEdge;
4183 TopoDS_Shape myShape;
4188 struct ElementsOnShape::OctreeClassifier : public SMESH_Octree
4190 OctreeClassifier( const std::vector< ElementsOnShape::Classifier* >& classifiers );
4191 OctreeClassifier( const OctreeClassifier* otherTree,
4192 const std::vector< ElementsOnShape::Classifier >& clsOther,
4193 std::vector< ElementsOnShape::Classifier >& cls );
4194 void GetClassifiersAtPoint( const gp_XYZ& p,
4195 std::vector< ElementsOnShape::Classifier* >& classifiers );
4197 OctreeClassifier() {}
4198 SMESH_Octree* newChild() const { return new OctreeClassifier; }
4199 void buildChildrenData();
4200 Bnd_B3d* buildRootBox();
4202 std::vector< ElementsOnShape::Classifier* > myClassifiers;
4206 ElementsOnShape::ElementsOnShape():
4208 myType(SMDSAbs_All),
4209 myToler(Precision::Confusion()),
4210 myAllNodesFlag(false)
4214 ElementsOnShape::~ElementsOnShape()
4219 Predicate* ElementsOnShape::clone() const
4221 ElementsOnShape* cln = new ElementsOnShape();
4222 cln->SetAllNodes ( myAllNodesFlag );
4223 cln->SetTolerance( myToler );
4224 cln->SetMesh ( myMeshModifTracer.GetMesh() );
4225 cln->myShape = myShape; // avoid creation of myClassifiers
4226 cln->SetShape ( myShape, myType );
4227 cln->myClassifiers.resize( myClassifiers.size() );
4228 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4229 cln->myClassifiers[ i ].Init( BRepBuilderAPI_Copy( myClassifiers[ i ].Shape()),
4230 myToler, myClassifiers[ i ].GetBndBox() );
4231 if ( myOctree ) // copy myOctree
4233 cln->myOctree = new OctreeClassifier( myOctree, myClassifiers, cln->myClassifiers );
4238 SMDSAbs_ElementType ElementsOnShape::GetType() const
4243 void ElementsOnShape::SetTolerance (const double theToler)
4245 if (myToler != theToler) {
4247 SetShape(myShape, myType);
4251 double ElementsOnShape::GetTolerance() const
4256 void ElementsOnShape::SetAllNodes (bool theAllNodes)
4258 myAllNodesFlag = theAllNodes;
4261 void ElementsOnShape::SetMesh (const SMDS_Mesh* theMesh)
4263 myMeshModifTracer.SetMesh( theMesh );
4264 if ( myMeshModifTracer.IsMeshModified())
4266 size_t nbNodes = theMesh ? theMesh->NbNodes() : 0;
4267 if ( myNodeIsChecked.size() == nbNodes )
4269 std::fill( myNodeIsChecked.begin(), myNodeIsChecked.end(), false );
4273 SMESHUtils::FreeVector( myNodeIsChecked );
4274 SMESHUtils::FreeVector( myNodeIsOut );
4275 myNodeIsChecked.resize( nbNodes, false );
4276 myNodeIsOut.resize( nbNodes );
4281 bool ElementsOnShape::getNodeIsOut( const SMDS_MeshNode* n, bool& isOut )
4283 if ( n->GetID() >= (int) myNodeIsChecked.size() ||
4284 !myNodeIsChecked[ n->GetID() ])
4287 isOut = myNodeIsOut[ n->GetID() ];
4291 void ElementsOnShape::setNodeIsOut( const SMDS_MeshNode* n, bool isOut )
4293 if ( n->GetID() < (int) myNodeIsChecked.size() )
4295 myNodeIsChecked[ n->GetID() ] = true;
4296 myNodeIsOut [ n->GetID() ] = isOut;
4300 void ElementsOnShape::SetShape (const TopoDS_Shape& theShape,
4301 const SMDSAbs_ElementType theType)
4303 bool shapeChanges = ( myShape != theShape );
4306 if ( myShape.IsNull() ) return;
4310 // find most complex shapes
4311 TopTools_IndexedMapOfShape shapesMap;
4312 TopAbs_ShapeEnum shapeTypes[4] = { TopAbs_SOLID, TopAbs_FACE, TopAbs_EDGE, TopAbs_VERTEX };
4313 TopExp_Explorer sub;
4314 for ( int i = 0; i < 4; ++i )
4316 if ( shapesMap.IsEmpty() )
4317 for ( sub.Init( myShape, shapeTypes[i] ); sub.More(); sub.Next() )
4318 shapesMap.Add( sub.Current() );
4320 for ( sub.Init( myShape, shapeTypes[i], shapeTypes[i-1] ); sub.More(); sub.Next() )
4321 shapesMap.Add( sub.Current() );
4325 myClassifiers.resize( shapesMap.Extent() );
4326 for ( int i = 0; i < shapesMap.Extent(); ++i )
4327 myClassifiers[ i ].Init( shapesMap( i+1 ), myToler );
4330 if ( theType == SMDSAbs_Node )
4332 SMESHUtils::FreeVector( myNodeIsChecked );
4333 SMESHUtils::FreeVector( myNodeIsOut );
4337 std::fill( myNodeIsChecked.begin(), myNodeIsChecked.end(), false );
4341 void ElementsOnShape::clearClassifiers()
4343 // for ( size_t i = 0; i < myClassifiers.size(); ++i )
4344 // delete myClassifiers[ i ];
4345 myClassifiers.clear();
4351 bool ElementsOnShape::IsSatisfy( long elemId )
4353 if ( myClassifiers.empty() )
4356 const SMDS_Mesh* mesh = myMeshModifTracer.GetMesh();
4357 if ( myType == SMDSAbs_Node )
4358 return IsSatisfy( mesh->FindNode( elemId ));
4359 return IsSatisfy( mesh->FindElement( elemId ));
4362 bool ElementsOnShape::IsSatisfy (const SMDS_MeshElement* elem)
4367 bool isSatisfy = myAllNodesFlag, isNodeOut;
4369 gp_XYZ centerXYZ (0, 0, 0);
4371 if ( !myOctree && myClassifiers.size() > 5 )
4373 myWorkClassifiers.resize( myClassifiers.size() );
4374 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4375 myWorkClassifiers[ i ] = & myClassifiers[ i ];
4376 myOctree = new OctreeClassifier( myWorkClassifiers );
4379 SMDS_ElemIteratorPtr aNodeItr = elem->nodesIterator();
4380 while (aNodeItr->more() && (isSatisfy == myAllNodesFlag))
4382 SMESH_TNodeXYZ aPnt( aNodeItr->next() );
4386 if ( !getNodeIsOut( aPnt._node, isNodeOut ))
4390 myWorkClassifiers.clear();
4391 myOctree->GetClassifiersAtPoint( aPnt, myWorkClassifiers );
4393 for ( size_t i = 0; i < myWorkClassifiers.size(); ++i )
4394 myWorkClassifiers[i]->SetChecked( false );
4396 for ( size_t i = 0; i < myWorkClassifiers.size() && isNodeOut; ++i )
4397 if ( !myWorkClassifiers[i]->IsChecked() )
4398 isNodeOut = myWorkClassifiers[i]->IsOut( aPnt );
4402 for ( size_t i = 0; i < myClassifiers.size() && isNodeOut; ++i )
4403 isNodeOut = myClassifiers[i].IsOut( aPnt );
4405 setNodeIsOut( aPnt._node, isNodeOut );
4407 isSatisfy = !isNodeOut;
4410 // Check the center point for volumes MantisBug 0020168
4413 myClassifiers[0].ShapeType() == TopAbs_SOLID )
4415 centerXYZ /= elem->NbNodes();
4418 for ( size_t i = 0; i < myWorkClassifiers.size() && !isSatisfy; ++i )
4419 isSatisfy = ! myWorkClassifiers[i]->IsOut( centerXYZ );
4421 for ( size_t i = 0; i < myClassifiers.size() && !isSatisfy; ++i )
4422 isSatisfy = ! myClassifiers[i].IsOut( centerXYZ );
4428 //================================================================================
4430 * \brief Check and optionally return a satisfying shape
4432 //================================================================================
4434 bool ElementsOnShape::IsSatisfy (const SMDS_MeshNode* node,
4435 TopoDS_Shape* okShape)
4440 if ( !myOctree && myClassifiers.size() > 5 )
4442 myWorkClassifiers.resize( myClassifiers.size() );
4443 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4444 myWorkClassifiers[ i ] = & myClassifiers[ i ];
4445 myOctree = new OctreeClassifier( myWorkClassifiers );
4448 bool isNodeOut = true;
4450 if ( okShape || !getNodeIsOut( node, isNodeOut ))
4452 SMESH_NodeXYZ aPnt = node;
4455 myWorkClassifiers.clear();
4456 myOctree->GetClassifiersAtPoint( aPnt, myWorkClassifiers );
4458 for ( size_t i = 0; i < myWorkClassifiers.size(); ++i )
4459 myWorkClassifiers[i]->SetChecked( false );
4461 for ( size_t i = 0; i < myWorkClassifiers.size(); ++i )
4462 if ( !myWorkClassifiers[i]->IsChecked() &&
4463 !myWorkClassifiers[i]->IsOut( aPnt ))
4467 *okShape = myWorkClassifiers[i]->Shape();
4473 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4474 if ( !myClassifiers[i].IsOut( aPnt ))
4478 *okShape = myWorkClassifiers[i]->Shape();
4482 setNodeIsOut( node, isNodeOut );
4488 void ElementsOnShape::Classifier::Init( const TopoDS_Shape& theShape,
4490 const Bnd_B3d* theBox )
4496 bool isShapeBox = false;
4497 switch ( myShape.ShapeType() )
4501 if (( isShapeBox = isBox( theShape )))
4503 myIsOutFun = & ElementsOnShape::Classifier::isOutOfBox;
4507 mySolidClfr = new BRepClass3d_SolidClassifier(theShape);
4508 myIsOutFun = & ElementsOnShape::Classifier::isOutOfSolid;
4514 Standard_Real u1,u2,v1,v2;
4515 Handle(Geom_Surface) surf = BRep_Tool::Surface( TopoDS::Face( theShape ));
4516 surf->Bounds( u1,u2,v1,v2 );
4517 myProjFace.Init(surf, u1,u2, v1,v2, myTol );
4518 myIsOutFun = & ElementsOnShape::Classifier::isOutOfFace;
4523 Standard_Real u1, u2;
4524 Handle(Geom_Curve) curve = BRep_Tool::Curve( TopoDS::Edge( theShape ), u1, u2);
4525 myProjEdge.Init(curve, u1, u2);
4526 myIsOutFun = & ElementsOnShape::Classifier::isOutOfEdge;
4531 myVertexXYZ = BRep_Tool::Pnt( TopoDS::Vertex( theShape ) );
4532 myIsOutFun = & ElementsOnShape::Classifier::isOutOfVertex;
4536 throw SALOME_Exception("Programmer error in usage of ElementsOnShape::Classifier");
4548 BRepBndLib::Add( myShape, box );
4550 myBox.Add( box.CornerMin() );
4551 myBox.Add( box.CornerMax() );
4552 gp_XYZ halfSize = 0.5 * ( box.CornerMax().XYZ() - box.CornerMin().XYZ() );
4553 for ( int iDim = 1; iDim <= 3; ++iDim )
4555 double x = halfSize.Coord( iDim );
4556 halfSize.SetCoord( iDim, x + Max( myTol, 1e-2 * x ));
4558 myBox.SetHSize( halfSize );
4563 ElementsOnShape::Classifier::~Classifier()
4565 delete mySolidClfr; mySolidClfr = 0;
4568 bool ElementsOnShape::Classifier::isOutOfSolid (const gp_Pnt& p)
4570 if ( isOutOfBox( p )) return true;
4571 mySolidClfr->Perform( p, myTol );
4572 return ( mySolidClfr->State() != TopAbs_IN && mySolidClfr->State() != TopAbs_ON );
4575 bool ElementsOnShape::Classifier::isOutOfBox (const gp_Pnt& p)
4577 return myBox.IsOut( p.XYZ() );
4580 bool ElementsOnShape::Classifier::isOutOfFace (const gp_Pnt& p)
4582 if ( isOutOfBox( p )) return true;
4583 myProjFace.Perform( p );
4584 if ( myProjFace.IsDone() && myProjFace.LowerDistance() <= myTol )
4586 // check relatively to the face
4588 myProjFace.LowerDistanceParameters(u, v);
4589 gp_Pnt2d aProjPnt (u, v);
4590 BRepClass_FaceClassifier aClsf ( TopoDS::Face( myShape ), aProjPnt, myTol );
4591 if ( aClsf.State() == TopAbs_IN || aClsf.State() == TopAbs_ON )
4597 bool ElementsOnShape::Classifier::isOutOfEdge (const gp_Pnt& p)
4599 if ( isOutOfBox( p )) return true;
4600 myProjEdge.Perform( p );
4601 return ! ( myProjEdge.NbPoints() > 0 && myProjEdge.LowerDistance() <= myTol );
4604 bool ElementsOnShape::Classifier::isOutOfVertex(const gp_Pnt& p)
4606 return ( myVertexXYZ.Distance( p ) > myTol );
4609 bool ElementsOnShape::Classifier::isBox (const TopoDS_Shape& theShape)
4611 TopTools_IndexedMapOfShape vMap;
4612 TopExp::MapShapes( theShape, TopAbs_VERTEX, vMap );
4613 if ( vMap.Extent() != 8 )
4617 for ( int i = 1; i <= 8; ++i )
4618 myBox.Add( BRep_Tool::Pnt( TopoDS::Vertex( vMap( i ))).XYZ() );
4620 gp_XYZ pMin = myBox.CornerMin(), pMax = myBox.CornerMax();
4621 for ( int i = 1; i <= 8; ++i )
4623 gp_Pnt p = BRep_Tool::Pnt( TopoDS::Vertex( vMap( i )));
4624 for ( int iC = 1; iC <= 3; ++ iC )
4626 double d1 = Abs( pMin.Coord( iC ) - p.Coord( iC ));
4627 double d2 = Abs( pMax.Coord( iC ) - p.Coord( iC ));
4628 if ( Min( d1, d2 ) > myTol )
4632 myBox.Enlarge( myTol );
4637 OctreeClassifier::OctreeClassifier( const std::vector< ElementsOnShape::Classifier* >& classifiers )
4638 :SMESH_Octree( new SMESH_TreeLimit )
4640 myClassifiers = classifiers;
4645 OctreeClassifier::OctreeClassifier( const OctreeClassifier* otherTree,
4646 const std::vector< ElementsOnShape::Classifier >& clsOther,
4647 std::vector< ElementsOnShape::Classifier >& cls )
4648 :SMESH_Octree( new SMESH_TreeLimit )
4650 myBox = new Bnd_B3d( *otherTree->getBox() );
4652 if (( myIsLeaf = otherTree->isLeaf() ))
4654 myClassifiers.resize( otherTree->myClassifiers.size() );
4655 for ( size_t i = 0; i < otherTree->myClassifiers.size(); ++i )
4657 int ind = otherTree->myClassifiers[i] - & clsOther[0];
4658 myClassifiers[ i ] = & cls[ ind ];
4661 else if ( otherTree->myChildren )
4663 myChildren = new SMESH_Tree< Bnd_B3d, 8 > * [ 8 ];
4664 for ( int i = 0; i < nbChildren(); i++ )
4666 new OctreeClassifier( static_cast<const OctreeClassifier*>( otherTree->myChildren[i]),
4671 void ElementsOnShape::
4672 OctreeClassifier::GetClassifiersAtPoint( const gp_XYZ& point,
4673 std::vector< ElementsOnShape::Classifier* >& result )
4675 if ( getBox()->IsOut( point ))
4680 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4681 if ( !myClassifiers[i]->GetBndBox()->IsOut( point ))
4682 result.push_back( myClassifiers[i] );
4686 for (int i = 0; i < nbChildren(); i++)
4687 ((OctreeClassifier*) myChildren[i])->GetClassifiersAtPoint( point, result );
4691 void ElementsOnShape::OctreeClassifier::buildChildrenData()
4693 // distribute myClassifiers among myChildren
4695 const int childFlag[8] = { 0x0000001,
4703 int nbInChild[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
4705 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4707 for ( int j = 0; j < nbChildren(); j++ )
4709 if ( !myClassifiers[i]->GetBndBox()->IsOut( *myChildren[j]->getBox() ))
4711 myClassifiers[i]->SetFlag( childFlag[ j ]);
4717 for ( int j = 0; j < nbChildren(); j++ )
4719 OctreeClassifier* child = static_cast<OctreeClassifier*>( myChildren[ j ]);
4720 child->myClassifiers.resize( nbInChild[ j ]);
4721 for ( size_t i = 0; nbInChild[ j ] && i < myClassifiers.size(); ++i )
4723 if ( myClassifiers[ i ]->IsSetFlag( childFlag[ j ]))
4726 child->myClassifiers[ nbInChild[ j ]] = myClassifiers[ i ];
4727 myClassifiers[ i ]->UnsetFlag( childFlag[ j ]);
4731 SMESHUtils::FreeVector( myClassifiers );
4733 // define if a child isLeaf()
4734 for ( int i = 0; i < nbChildren(); i++ )
4736 OctreeClassifier* child = static_cast<OctreeClassifier*>( myChildren[ i ]);
4737 child->myIsLeaf = ( child->myClassifiers.size() <= 5 );
4741 Bnd_B3d* ElementsOnShape::OctreeClassifier::buildRootBox()
4743 Bnd_B3d* box = new Bnd_B3d;
4744 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4745 box->Add( *myClassifiers[i]->GetBndBox() );
4750 Class : BelongToGeom
4751 Description : Predicate for verifying whether entity belongs to
4752 specified geometrical support
4755 BelongToGeom::BelongToGeom()
4757 myType(SMDSAbs_NbElementTypes),
4758 myIsSubshape(false),
4759 myTolerance(Precision::Confusion())
4762 Predicate* BelongToGeom::clone() const
4764 BelongToGeom* cln = new BelongToGeom( *this );
4765 cln->myElementsOnShapePtr.reset( static_cast<ElementsOnShape*>( myElementsOnShapePtr->clone() ));
4769 void BelongToGeom::SetMesh( const SMDS_Mesh* theMesh )
4771 if ( myMeshDS != theMesh )
4773 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
4778 void BelongToGeom::SetGeom( const TopoDS_Shape& theShape )
4780 if ( myShape != theShape )
4787 static bool IsSubShape (const TopTools_IndexedMapOfShape& theMap,
4788 const TopoDS_Shape& theShape)
4790 if (theMap.Contains(theShape)) return true;
4792 if (theShape.ShapeType() == TopAbs_COMPOUND ||
4793 theShape.ShapeType() == TopAbs_COMPSOLID)
4795 TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
4796 for (; anIt.More(); anIt.Next())
4798 if (!IsSubShape(theMap, anIt.Value())) {
4808 void BelongToGeom::init()
4810 if ( !myMeshDS || myShape.IsNull() ) return;
4812 // is sub-shape of main shape?
4813 TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
4814 if (aMainShape.IsNull()) {
4815 myIsSubshape = false;
4818 TopTools_IndexedMapOfShape aMap;
4819 TopExp::MapShapes( aMainShape, aMap );
4820 myIsSubshape = IsSubShape( aMap, myShape );
4824 TopExp::MapShapes( myShape, aMap );
4825 mySubShapesIDs.Clear();
4826 for ( int i = 1; i <= aMap.Extent(); ++i )
4828 int subID = myMeshDS->ShapeToIndex( aMap( i ));
4830 mySubShapesIDs.Add( subID );
4835 //if (!myIsSubshape) // to be always ready to check an element not bound to geometry
4837 if ( !myElementsOnShapePtr )
4838 myElementsOnShapePtr.reset( new ElementsOnShape() );
4839 myElementsOnShapePtr->SetTolerance( myTolerance );
4840 myElementsOnShapePtr->SetAllNodes( true ); // "belong", while false means "lays on"
4841 myElementsOnShapePtr->SetMesh( myMeshDS );
4842 myElementsOnShapePtr->SetShape( myShape, myType );
4846 bool BelongToGeom::IsSatisfy (long theId)
4848 if (myMeshDS == 0 || myShape.IsNull())
4853 return myElementsOnShapePtr->IsSatisfy(theId);
4858 if (myType == SMDSAbs_Node)
4860 if ( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ))
4862 if ( aNode->getshapeId() < 1 )
4863 return myElementsOnShapePtr->IsSatisfy(theId);
4865 return mySubShapesIDs.Contains( aNode->getshapeId() );
4870 if ( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ))
4872 if ( myType == SMDSAbs_All || anElem->GetType() == myType )
4874 if ( anElem->getshapeId() < 1 )
4875 return myElementsOnShapePtr->IsSatisfy(theId);
4877 return mySubShapesIDs.Contains( anElem->getshapeId() );
4885 void BelongToGeom::SetType (SMDSAbs_ElementType theType)
4887 if ( myType != theType )
4894 SMDSAbs_ElementType BelongToGeom::GetType() const
4899 TopoDS_Shape BelongToGeom::GetShape()
4904 const SMESHDS_Mesh* BelongToGeom::GetMeshDS() const
4909 void BelongToGeom::SetTolerance (double theTolerance)
4911 myTolerance = theTolerance;
4915 double BelongToGeom::GetTolerance()
4922 Description : Predicate for verifying whether entiy lying or partially lying on
4923 specified geometrical support
4926 LyingOnGeom::LyingOnGeom()
4928 myType(SMDSAbs_NbElementTypes),
4929 myIsSubshape(false),
4930 myTolerance(Precision::Confusion())
4933 Predicate* LyingOnGeom::clone() const
4935 LyingOnGeom* cln = new LyingOnGeom( *this );
4936 cln->myElementsOnShapePtr.reset( static_cast<ElementsOnShape*>( myElementsOnShapePtr->clone() ));
4940 void LyingOnGeom::SetMesh( const SMDS_Mesh* theMesh )
4942 if ( myMeshDS != theMesh )
4944 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
4949 void LyingOnGeom::SetGeom( const TopoDS_Shape& theShape )
4951 if ( myShape != theShape )
4958 void LyingOnGeom::init()
4960 if (!myMeshDS || myShape.IsNull()) return;
4962 // is sub-shape of main shape?
4963 TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
4964 if (aMainShape.IsNull()) {
4965 myIsSubshape = false;
4968 myIsSubshape = myMeshDS->IsGroupOfSubShapes( myShape );
4973 TopTools_IndexedMapOfShape shapes;
4974 TopExp::MapShapes( myShape, shapes );
4975 mySubShapesIDs.Clear();
4976 for ( int i = 1; i <= shapes.Extent(); ++i )
4978 int subID = myMeshDS->ShapeToIndex( shapes( i ));
4980 mySubShapesIDs.Add( subID );
4983 // else // to be always ready to check an element not bound to geometry
4985 if ( !myElementsOnShapePtr )
4986 myElementsOnShapePtr.reset( new ElementsOnShape() );
4987 myElementsOnShapePtr->SetTolerance( myTolerance );
4988 myElementsOnShapePtr->SetAllNodes( false ); // lays on, while true means "belong"
4989 myElementsOnShapePtr->SetMesh( myMeshDS );
4990 myElementsOnShapePtr->SetShape( myShape, myType );
4994 bool LyingOnGeom::IsSatisfy( long theId )
4996 if ( myMeshDS == 0 || myShape.IsNull() )
5001 return myElementsOnShapePtr->IsSatisfy(theId);
5006 const SMDS_MeshElement* elem =
5007 ( myType == SMDSAbs_Node ) ? myMeshDS->FindNode( theId ) : myMeshDS->FindElement( theId );
5009 if ( mySubShapesIDs.Contains( elem->getshapeId() ))
5012 if (( elem->GetType() != SMDSAbs_Node ) &&
5013 ( myType == SMDSAbs_All || elem->GetType() == myType ))
5015 SMDS_ElemIteratorPtr nodeItr = elem->nodesIterator();
5016 while ( nodeItr->more() )
5018 const SMDS_MeshElement* aNode = nodeItr->next();
5019 if ( mySubShapesIDs.Contains( aNode->getshapeId() ))
5027 void LyingOnGeom::SetType( SMDSAbs_ElementType theType )
5029 if ( myType != theType )
5036 SMDSAbs_ElementType LyingOnGeom::GetType() const
5041 TopoDS_Shape LyingOnGeom::GetShape()
5046 const SMESHDS_Mesh* LyingOnGeom::GetMeshDS() const
5051 void LyingOnGeom::SetTolerance (double theTolerance)
5053 myTolerance = theTolerance;
5057 double LyingOnGeom::GetTolerance()
5062 TSequenceOfXYZ::TSequenceOfXYZ(): myElem(0)
5065 TSequenceOfXYZ::TSequenceOfXYZ(size_type n) : myArray(n), myElem(0)
5068 TSequenceOfXYZ::TSequenceOfXYZ(size_type n, const gp_XYZ& t) : myArray(n,t), myElem(0)
5071 TSequenceOfXYZ::TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ) : myArray(theSequenceOfXYZ.myArray), myElem(theSequenceOfXYZ.myElem)
5074 template <class InputIterator>
5075 TSequenceOfXYZ::TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd): myArray(theBegin,theEnd), myElem(0)
5078 TSequenceOfXYZ::~TSequenceOfXYZ()
5081 TSequenceOfXYZ& TSequenceOfXYZ::operator=(const TSequenceOfXYZ& theSequenceOfXYZ)
5083 myArray = theSequenceOfXYZ.myArray;
5084 myElem = theSequenceOfXYZ.myElem;
5088 gp_XYZ& TSequenceOfXYZ::operator()(size_type n)
5090 return myArray[n-1];
5093 const gp_XYZ& TSequenceOfXYZ::operator()(size_type n) const
5095 return myArray[n-1];
5098 void TSequenceOfXYZ::clear()
5103 void TSequenceOfXYZ::reserve(size_type n)
5108 void TSequenceOfXYZ::push_back(const gp_XYZ& v)
5110 myArray.push_back(v);
5113 TSequenceOfXYZ::size_type TSequenceOfXYZ::size() const
5115 return myArray.size();
5118 SMDSAbs_EntityType TSequenceOfXYZ::getElementEntity() const
5120 return myElem ? myElem->GetEntityType() : SMDSEntity_Last;
5123 TMeshModifTracer::TMeshModifTracer():
5124 myMeshModifTime(0), myMesh(0)
5127 void TMeshModifTracer::SetMesh( const SMDS_Mesh* theMesh )
5129 if ( theMesh != myMesh )
5130 myMeshModifTime = 0;
5133 bool TMeshModifTracer::IsMeshModified()
5135 bool modified = false;
5138 modified = ( myMeshModifTime != myMesh->GetMTime() );
5139 myMeshModifTime = myMesh->GetMTime();