1 // Copyright (C) 2007-2020 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 <GEOMUtils.hxx>
39 #include <Basics_Utils.hxx>
41 #include <BRepAdaptor_Surface.hxx>
42 #include <BRepBndLib.hxx>
43 #include <BRepBuilderAPI_Copy.hxx>
44 #include <BRepClass3d_SolidClassifier.hxx>
45 #include <BRepClass_FaceClassifier.hxx>
46 #include <BRep_Tool.hxx>
47 #include <GeomLib_IsPlanarSurface.hxx>
48 #include <Geom_CylindricalSurface.hxx>
49 #include <Geom_Plane.hxx>
50 #include <Geom_Surface.hxx>
51 #include <NCollection_Map.hxx>
52 #include <Precision.hxx>
53 #include <ShapeAnalysis_Surface.hxx>
54 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
55 #include <TColStd_MapOfInteger.hxx>
56 #include <TColStd_SequenceOfAsciiString.hxx>
57 #include <TColgp_Array1OfXYZ.hxx>
61 #include <TopoDS_Edge.hxx>
62 #include <TopoDS_Face.hxx>
63 #include <TopoDS_Iterator.hxx>
64 #include <TopoDS_Shape.hxx>
65 #include <TopoDS_Vertex.hxx>
67 #include <gp_Cylinder.hxx>
74 #include <vtkMeshQuality.h>
85 const double theEps = 1e-100;
86 const double theInf = 1e+100;
88 inline gp_XYZ gpXYZ(const SMDS_MeshNode* aNode )
90 return gp_XYZ(aNode->X(), aNode->Y(), aNode->Z() );
93 inline double getAngle( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
95 gp_Vec v1( P1 - P2 ), v2( P3 - P2 );
97 return v1.Magnitude() < gp::Resolution() ||
98 v2.Magnitude() < gp::Resolution() ? 0 : v1.Angle( v2 );
101 inline double getCos2( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
103 gp_Vec v1( P1 - P2 ), v2( P3 - P2 );
104 double dot = v1 * v2, len1 = v1.SquareMagnitude(), len2 = v2.SquareMagnitude();
106 return ( dot < 0 || len1 < gp::Resolution() || len2 < gp::Resolution() ? -1 :
107 dot * dot / len1 / len2 );
110 inline double getArea( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
112 gp_Vec aVec1( P2 - P1 );
113 gp_Vec aVec2( P3 - P1 );
114 return ( aVec1 ^ aVec2 ).Magnitude() * 0.5;
117 inline double getArea( const gp_Pnt& P1, const gp_Pnt& P2, const gp_Pnt& P3 )
119 return getArea( P1.XYZ(), P2.XYZ(), P3.XYZ() );
124 inline double getDistance( const gp_XYZ& P1, const gp_XYZ& P2 )
126 double aDist = gp_Pnt( P1 ).Distance( gp_Pnt( P2 ) );
130 int getNbMultiConnection( const SMDS_Mesh* theMesh, const smIdType theId )
135 const SMDS_MeshElement* anEdge = theMesh->FindElement( theId );
136 if ( anEdge == 0 || anEdge->GetType() != SMDSAbs_Edge/* || anEdge->NbNodes() != 2 */)
139 // for each pair of nodes in anEdge (there are 2 pairs in a quadratic edge)
140 // count elements containing both nodes of the pair.
141 // Note that there may be such cases for a quadratic edge (a horizontal line):
146 // +-----+------+ +-----+------+
149 // result should be 2 in both cases
151 int aResult0 = 0, aResult1 = 0;
152 // last node, it is a medium one in a quadratic edge
153 const SMDS_MeshNode* aLastNode = anEdge->GetNode( anEdge->NbNodes() - 1 );
154 const SMDS_MeshNode* aNode0 = anEdge->GetNode( 0 );
155 const SMDS_MeshNode* aNode1 = anEdge->GetNode( 1 );
156 if ( aNode1 == aLastNode ) aNode1 = 0;
158 SMDS_ElemIteratorPtr anElemIter = aLastNode->GetInverseElementIterator();
159 while( anElemIter->more() ) {
160 const SMDS_MeshElement* anElem = anElemIter->next();
161 if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) {
162 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
163 while ( anIter->more() ) {
164 if ( const SMDS_MeshElement* anElemNode = anIter->next() ) {
165 if ( anElemNode == aNode0 ) {
167 if ( !aNode1 ) break; // not a quadratic edge
169 else if ( anElemNode == aNode1 )
175 int aResult = std::max ( aResult0, aResult1 );
180 gp_XYZ getNormale( const SMDS_MeshFace* theFace, bool* ok=0 )
182 int aNbNode = theFace->NbNodes();
184 gp_XYZ q1 = gpXYZ( theFace->GetNode(1)) - gpXYZ( theFace->GetNode(0));
185 gp_XYZ q2 = gpXYZ( theFace->GetNode(2)) - gpXYZ( theFace->GetNode(0));
188 gp_XYZ q3 = gpXYZ( theFace->GetNode(3)) - gpXYZ( theFace->GetNode(0));
191 double len = n.Modulus();
192 bool zeroLen = ( len <= std::numeric_limits<double>::min());
196 if (ok) *ok = !zeroLen;
204 using namespace SMESH::Controls;
210 //================================================================================
212 Class : NumericalFunctor
213 Description : Base class for numerical functors
215 //================================================================================
217 NumericalFunctor::NumericalFunctor():
223 void NumericalFunctor::SetMesh( const SMDS_Mesh* theMesh )
228 bool NumericalFunctor::GetPoints(const smIdType theId,
229 TSequenceOfXYZ& theRes ) const
236 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
237 if ( !IsApplicable( anElem ))
240 return GetPoints( anElem, theRes );
243 bool NumericalFunctor::GetPoints(const SMDS_MeshElement* anElem,
244 TSequenceOfXYZ& theRes )
251 theRes.reserve( anElem->NbNodes() );
252 theRes.setElement( anElem );
254 // Get nodes of the element
255 SMDS_NodeIteratorPtr anIter= anElem->interlacedNodesIterator();
258 while( anIter->more() ) {
259 if ( p.Set( anIter->next() ))
260 theRes.push_back( p );
267 long NumericalFunctor::GetPrecision() const
272 void NumericalFunctor::SetPrecision( const long thePrecision )
274 myPrecision = thePrecision;
275 myPrecisionValue = pow( 10., (double)( myPrecision ) );
278 double NumericalFunctor::GetValue( long theId )
282 myCurrElement = myMesh->FindElement( theId );
285 if ( GetPoints( theId, P )) // elem type is checked here
286 aVal = Round( GetValue( P ));
291 double NumericalFunctor::Round( const double & aVal )
293 return ( myPrecision >= 0 ) ? floor( aVal * myPrecisionValue + 0.5 ) / myPrecisionValue : aVal;
296 //================================================================================
298 * \brief Return true if a value can be computed for a given element.
299 * Some NumericalFunctor's are meaningful for elements of a certain
302 //================================================================================
304 bool NumericalFunctor::IsApplicable( const SMDS_MeshElement* element ) const
306 return element && element->GetType() == this->GetType();
309 bool NumericalFunctor::IsApplicable( long theElementId ) const
311 return IsApplicable( myMesh->FindElement( theElementId ));
314 //================================================================================
316 * \brief Return histogram of functor values
317 * \param nbIntervals - number of intervals
318 * \param nbEvents - number of mesh elements having values within i-th interval
319 * \param funValues - boundaries of intervals
320 * \param elements - elements to check vulue of; empty list means "of all"
321 * \param minmax - boundaries of diapason of values to divide into intervals
323 //================================================================================
325 void NumericalFunctor::GetHistogram(int nbIntervals,
326 std::vector<int>& nbEvents,
327 std::vector<double>& funValues,
328 const std::vector<smIdType>& elements,
329 const double* minmax,
330 const bool isLogarithmic)
332 if ( nbIntervals < 1 ||
334 !myMesh->GetMeshInfo().NbElements( GetType() ))
336 nbEvents.resize( nbIntervals, 0 );
337 funValues.resize( nbIntervals+1 );
339 // get all values sorted
340 std::multiset< double > values;
341 if ( elements.empty() )
343 SMDS_ElemIteratorPtr elemIt = myMesh->elementsIterator( GetType() );
344 while ( elemIt->more() )
345 values.insert( GetValue( elemIt->next()->GetID() ));
349 std::vector<smIdType>::const_iterator id = elements.begin();
350 for ( ; id != elements.end(); ++id )
351 values.insert( GetValue( *id ));
356 funValues[0] = minmax[0];
357 funValues[nbIntervals] = minmax[1];
361 funValues[0] = *values.begin();
362 funValues[nbIntervals] = *values.rbegin();
364 // case nbIntervals == 1
365 if ( nbIntervals == 1 )
367 nbEvents[0] = values.size();
371 if (funValues.front() == funValues.back())
373 nbEvents.resize( 1 );
374 nbEvents[0] = values.size();
375 funValues[1] = funValues.back();
376 funValues.resize( 2 );
379 std::multiset< double >::iterator min = values.begin(), max;
380 for ( int i = 0; i < nbIntervals; ++i )
382 // find end value of i-th interval
383 double r = (i+1) / double(nbIntervals);
384 if (isLogarithmic && funValues.front() > 1e-07 && funValues.back() > 1e-07) {
385 double logmin = log10(funValues.front());
386 double lval = logmin + r * (log10(funValues.back()) - logmin);
387 funValues[i+1] = pow(10.0, lval);
390 funValues[i+1] = funValues.front() * (1-r) + funValues.back() * r;
393 // count values in the i-th interval if there are any
394 if ( min != values.end() && *min <= funValues[i+1] )
396 // find the first value out of the interval
397 max = values.upper_bound( funValues[i+1] ); // max is greater than funValues[i+1], or end()
398 nbEvents[i] = std::distance( min, max );
402 // add values larger than minmax[1]
403 nbEvents.back() += std::distance( min, values.end() );
406 //=======================================================================
409 Description : Functor calculating volume of a 3D element
411 //================================================================================
413 double Volume::GetValue( long theElementId )
415 if ( theElementId && myMesh ) {
416 SMDS_VolumeTool aVolumeTool;
417 if ( aVolumeTool.Set( myMesh->FindElement( theElementId )))
418 return aVolumeTool.GetSize();
423 double Volume::GetBadRate( double Value, int /*nbNodes*/ ) const
428 SMDSAbs_ElementType Volume::GetType() const
430 return SMDSAbs_Volume;
433 //=======================================================================
435 Class : MaxElementLength2D
436 Description : Functor calculating maximum length of 2D element
438 //================================================================================
440 double MaxElementLength2D::GetValue( const TSequenceOfXYZ& P )
446 if( len == 3 ) { // triangles
447 double L1 = getDistance(P( 1 ),P( 2 ));
448 double L2 = getDistance(P( 2 ),P( 3 ));
449 double L3 = getDistance(P( 3 ),P( 1 ));
450 aVal = Max(L1,Max(L2,L3));
452 else if( len == 4 ) { // quadrangles
453 double L1 = getDistance(P( 1 ),P( 2 ));
454 double L2 = getDistance(P( 2 ),P( 3 ));
455 double L3 = getDistance(P( 3 ),P( 4 ));
456 double L4 = getDistance(P( 4 ),P( 1 ));
457 double D1 = getDistance(P( 1 ),P( 3 ));
458 double D2 = getDistance(P( 2 ),P( 4 ));
459 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(D1,D2));
461 else if( len == 6 ) { // quadratic triangles
462 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
463 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
464 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 1 ));
465 aVal = Max(L1,Max(L2,L3));
467 else if( len == 8 || len == 9 ) { // quadratic quadrangles
468 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
469 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
470 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 7 ));
471 double L4 = getDistance(P( 7 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
472 double D1 = getDistance(P( 1 ),P( 5 ));
473 double D2 = getDistance(P( 3 ),P( 7 ));
474 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(D1,D2));
476 // Diagonals are undefined for concave polygons
477 // else if ( P.getElementEntity() == SMDSEntity_Quad_Polygon && P.size() > 2 ) // quad polygon
480 // aVal = getDistance( P( 1 ), P( P.size() )) + getDistance( P( P.size() ), P( P.size()-1 ));
481 // for ( size_t i = 1; i < P.size()-1; i += 2 )
483 // double L = getDistance( P( i ), P( i+1 )) + getDistance( P( i+1 ), P( i+2 ));
484 // aVal = Max( aVal, L );
487 // for ( int i = P.size()-5; i > 0; i -= 2 )
488 // for ( int j = i + 4; j < P.size() + i - 2; i += 2 )
490 // double D = getDistance( P( i ), P( j ));
491 // aVal = Max( aVal, D );
498 if( myPrecision >= 0 )
500 double prec = pow( 10., (double)myPrecision );
501 aVal = floor( aVal * prec + 0.5 ) / prec;
506 double MaxElementLength2D::GetValue( long theElementId )
509 return GetPoints( theElementId, P ) ? GetValue(P) : 0.0;
512 double MaxElementLength2D::GetBadRate( double Value, int /*nbNodes*/ ) const
517 SMDSAbs_ElementType MaxElementLength2D::GetType() const
522 //=======================================================================
524 Class : MaxElementLength3D
525 Description : Functor calculating maximum length of 3D element
527 //================================================================================
529 double MaxElementLength3D::GetValue( long theElementId )
532 if( GetPoints( theElementId, P ) ) {
534 const SMDS_MeshElement* aElem = myMesh->FindElement( theElementId );
535 SMDSAbs_EntityType aType = aElem->GetEntityType();
538 case SMDSEntity_Tetra: { // tetras
539 double L1 = getDistance(P( 1 ),P( 2 ));
540 double L2 = getDistance(P( 2 ),P( 3 ));
541 double L3 = getDistance(P( 3 ),P( 1 ));
542 double L4 = getDistance(P( 1 ),P( 4 ));
543 double L5 = getDistance(P( 2 ),P( 4 ));
544 double L6 = getDistance(P( 3 ),P( 4 ));
545 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
548 case SMDSEntity_Pyramid: { // pyramids
549 double L1 = getDistance(P( 1 ),P( 2 ));
550 double L2 = getDistance(P( 2 ),P( 3 ));
551 double L3 = getDistance(P( 3 ),P( 4 ));
552 double L4 = getDistance(P( 4 ),P( 1 ));
553 double L5 = getDistance(P( 1 ),P( 5 ));
554 double L6 = getDistance(P( 2 ),P( 5 ));
555 double L7 = getDistance(P( 3 ),P( 5 ));
556 double L8 = getDistance(P( 4 ),P( 5 ));
557 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
558 aVal = Max(aVal,Max(L7,L8));
561 case SMDSEntity_Penta: { // pentas
562 double L1 = getDistance(P( 1 ),P( 2 ));
563 double L2 = getDistance(P( 2 ),P( 3 ));
564 double L3 = getDistance(P( 3 ),P( 1 ));
565 double L4 = getDistance(P( 4 ),P( 5 ));
566 double L5 = getDistance(P( 5 ),P( 6 ));
567 double L6 = getDistance(P( 6 ),P( 4 ));
568 double L7 = getDistance(P( 1 ),P( 4 ));
569 double L8 = getDistance(P( 2 ),P( 5 ));
570 double L9 = getDistance(P( 3 ),P( 6 ));
571 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
572 aVal = Max(aVal,Max(Max(L7,L8),L9));
575 case SMDSEntity_Hexa: { // hexas
576 double L1 = getDistance(P( 1 ),P( 2 ));
577 double L2 = getDistance(P( 2 ),P( 3 ));
578 double L3 = getDistance(P( 3 ),P( 4 ));
579 double L4 = getDistance(P( 4 ),P( 1 ));
580 double L5 = getDistance(P( 5 ),P( 6 ));
581 double L6 = getDistance(P( 6 ),P( 7 ));
582 double L7 = getDistance(P( 7 ),P( 8 ));
583 double L8 = getDistance(P( 8 ),P( 5 ));
584 double L9 = getDistance(P( 1 ),P( 5 ));
585 double L10= getDistance(P( 2 ),P( 6 ));
586 double L11= getDistance(P( 3 ),P( 7 ));
587 double L12= getDistance(P( 4 ),P( 8 ));
588 double D1 = getDistance(P( 1 ),P( 7 ));
589 double D2 = getDistance(P( 2 ),P( 8 ));
590 double D3 = getDistance(P( 3 ),P( 5 ));
591 double D4 = getDistance(P( 4 ),P( 6 ));
592 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
593 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
594 aVal = Max(aVal,Max(L11,L12));
595 aVal = Max(aVal,Max(Max(D1,D2),Max(D3,D4)));
598 case SMDSEntity_Hexagonal_Prism: { // hexagonal prism
599 for ( int i1 = 1; i1 < 12; ++i1 )
600 for ( int i2 = i1+1; i1 <= 12; ++i1 )
601 aVal = Max( aVal, getDistance(P( i1 ),P( i2 )));
604 case SMDSEntity_Quad_Tetra: { // quadratic tetras
605 double L1 = getDistance(P( 1 ),P( 5 )) + getDistance(P( 5 ),P( 2 ));
606 double L2 = getDistance(P( 2 ),P( 6 )) + getDistance(P( 6 ),P( 3 ));
607 double L3 = getDistance(P( 3 ),P( 7 )) + getDistance(P( 7 ),P( 1 ));
608 double L4 = getDistance(P( 1 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
609 double L5 = getDistance(P( 2 ),P( 9 )) + getDistance(P( 9 ),P( 4 ));
610 double L6 = getDistance(P( 3 ),P( 10 )) + getDistance(P( 10 ),P( 4 ));
611 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
614 case SMDSEntity_Quad_Pyramid: { // quadratic pyramids
615 double L1 = getDistance(P( 1 ),P( 6 )) + getDistance(P( 6 ),P( 2 ));
616 double L2 = getDistance(P( 2 ),P( 7 )) + getDistance(P( 7 ),P( 3 ));
617 double L3 = getDistance(P( 3 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
618 double L4 = getDistance(P( 4 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
619 double L5 = getDistance(P( 1 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
620 double L6 = getDistance(P( 2 ),P( 11 )) + getDistance(P( 11 ),P( 5 ));
621 double L7 = getDistance(P( 3 ),P( 12 )) + getDistance(P( 12 ),P( 5 ));
622 double L8 = getDistance(P( 4 ),P( 13 )) + getDistance(P( 13 ),P( 5 ));
623 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
624 aVal = Max(aVal,Max(L7,L8));
627 case SMDSEntity_Quad_Penta:
628 case SMDSEntity_BiQuad_Penta: { // quadratic pentas
629 double L1 = getDistance(P( 1 ),P( 7 )) + getDistance(P( 7 ),P( 2 ));
630 double L2 = getDistance(P( 2 ),P( 8 )) + getDistance(P( 8 ),P( 3 ));
631 double L3 = getDistance(P( 3 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
632 double L4 = getDistance(P( 4 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
633 double L5 = getDistance(P( 5 ),P( 11 )) + getDistance(P( 11 ),P( 6 ));
634 double L6 = getDistance(P( 6 ),P( 12 )) + getDistance(P( 12 ),P( 4 ));
635 double L7 = getDistance(P( 1 ),P( 13 )) + getDistance(P( 13 ),P( 4 ));
636 double L8 = getDistance(P( 2 ),P( 14 )) + getDistance(P( 14 ),P( 5 ));
637 double L9 = getDistance(P( 3 ),P( 15 )) + getDistance(P( 15 ),P( 6 ));
638 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
639 aVal = Max(aVal,Max(Max(L7,L8),L9));
642 case SMDSEntity_Quad_Hexa:
643 case SMDSEntity_TriQuad_Hexa: { // quadratic hexas
644 double L1 = getDistance(P( 1 ),P( 9 )) + getDistance(P( 9 ),P( 2 ));
645 double L2 = getDistance(P( 2 ),P( 10 )) + getDistance(P( 10 ),P( 3 ));
646 double L3 = getDistance(P( 3 ),P( 11 )) + getDistance(P( 11 ),P( 4 ));
647 double L4 = getDistance(P( 4 ),P( 12 )) + getDistance(P( 12 ),P( 1 ));
648 double L5 = getDistance(P( 5 ),P( 13 )) + getDistance(P( 13 ),P( 6 ));
649 double L6 = getDistance(P( 6 ),P( 14 )) + getDistance(P( 14 ),P( 7 ));
650 double L7 = getDistance(P( 7 ),P( 15 )) + getDistance(P( 15 ),P( 8 ));
651 double L8 = getDistance(P( 8 ),P( 16 )) + getDistance(P( 16 ),P( 5 ));
652 double L9 = getDistance(P( 1 ),P( 17 )) + getDistance(P( 17 ),P( 5 ));
653 double L10= getDistance(P( 2 ),P( 18 )) + getDistance(P( 18 ),P( 6 ));
654 double L11= getDistance(P( 3 ),P( 19 )) + getDistance(P( 19 ),P( 7 ));
655 double L12= getDistance(P( 4 ),P( 20 )) + getDistance(P( 20 ),P( 8 ));
656 double D1 = getDistance(P( 1 ),P( 7 ));
657 double D2 = getDistance(P( 2 ),P( 8 ));
658 double D3 = getDistance(P( 3 ),P( 5 ));
659 double D4 = getDistance(P( 4 ),P( 6 ));
660 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
661 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
662 aVal = Max(aVal,Max(L11,L12));
663 aVal = Max(aVal,Max(Max(D1,D2),Max(D3,D4)));
666 case SMDSEntity_Quad_Polyhedra:
667 case SMDSEntity_Polyhedra: { // polys
668 // get the maximum distance between all pairs of nodes
669 for( int i = 1; i <= len; i++ ) {
670 for( int j = 1; j <= len; j++ ) {
671 if( j > i ) { // optimization of the loop
672 double D = getDistance( P(i), P(j) );
673 aVal = Max( aVal, D );
679 case SMDSEntity_Node:
681 case SMDSEntity_Edge:
682 case SMDSEntity_Quad_Edge:
683 case SMDSEntity_Triangle:
684 case SMDSEntity_Quad_Triangle:
685 case SMDSEntity_BiQuad_Triangle:
686 case SMDSEntity_Quadrangle:
687 case SMDSEntity_Quad_Quadrangle:
688 case SMDSEntity_BiQuad_Quadrangle:
689 case SMDSEntity_Polygon:
690 case SMDSEntity_Quad_Polygon:
691 case SMDSEntity_Ball:
692 case SMDSEntity_Last: return 0;
693 } // switch ( aType )
695 if( myPrecision >= 0 )
697 double prec = pow( 10., (double)myPrecision );
698 aVal = floor( aVal * prec + 0.5 ) / prec;
705 double MaxElementLength3D::GetBadRate( double Value, int /*nbNodes*/ ) const
710 SMDSAbs_ElementType MaxElementLength3D::GetType() const
712 return SMDSAbs_Volume;
715 //=======================================================================
718 Description : Functor for calculation of minimum angle
720 //================================================================================
722 double MinimumAngle::GetValue( const TSequenceOfXYZ& P )
729 aMaxCos2 = getCos2( P( P.size() ), P( 1 ), P( 2 ));
730 aMaxCos2 = Max( aMaxCos2, getCos2( P( P.size()-1 ), P( P.size() ), P( 1 )));
732 for ( size_t i = 2; i < P.size(); i++ )
734 double A0 = getCos2( P( i-1 ), P( i ), P( i+1 ) );
735 aMaxCos2 = Max( aMaxCos2, A0 );
738 return 0; // all nodes coincide
740 double cos = sqrt( aMaxCos2 );
741 if ( cos >= 1 ) return 0;
742 return acos( cos ) * 180.0 / M_PI;
745 double MinimumAngle::GetBadRate( double Value, int nbNodes ) const
747 //const double aBestAngle = PI / nbNodes;
748 const double aBestAngle = 180.0 - ( 360.0 / double(nbNodes) );
749 return ( fabs( aBestAngle - Value ));
752 SMDSAbs_ElementType MinimumAngle::GetType() const
758 //================================================================================
761 Description : Functor for calculating aspect ratio
763 //================================================================================
765 double AspectRatio::GetValue( long theId )
768 myCurrElement = myMesh->FindElement( theId );
770 if ( GetPoints( myCurrElement, P ))
771 aVal = Round( GetValue( P ));
775 double AspectRatio::GetValue( const TSequenceOfXYZ& P )
777 // According to "Mesh quality control" by Nadir Bouhamau referring to
778 // Pascal Jean Frey and Paul-Louis George. Maillages, applications aux elements finis.
779 // Hermes Science publications, Paris 1999 ISBN 2-7462-0024-4
782 int nbNodes = P.size();
787 // Compute aspect ratio
789 if ( nbNodes == 3 ) {
790 // Compute lengths of the sides
791 double aLen1 = getDistance( P( 1 ), P( 2 ));
792 double aLen2 = getDistance( P( 2 ), P( 3 ));
793 double aLen3 = getDistance( P( 3 ), P( 1 ));
794 // Q = alfa * h * p / S, where
796 // alfa = sqrt( 3 ) / 6
797 // h - length of the longest edge
798 // p - half perimeter
799 // S - triangle surface
800 const double alfa = sqrt( 3. ) / 6.;
801 double maxLen = Max( aLen1, Max( aLen2, aLen3 ));
802 double half_perimeter = ( aLen1 + aLen2 + aLen3 ) / 2.;
803 double anArea = getArea( P( 1 ), P( 2 ), P( 3 ));
804 if ( anArea <= theEps )
806 return alfa * maxLen * half_perimeter / anArea;
808 else if ( nbNodes == 6 ) { // quadratic triangles
809 // Compute lengths of the sides
810 double aLen1 = getDistance( P( 1 ), P( 3 ));
811 double aLen2 = getDistance( P( 3 ), P( 5 ));
812 double aLen3 = getDistance( P( 5 ), P( 1 ));
813 // algo same as for the linear triangle
814 const double alfa = sqrt( 3. ) / 6.;
815 double maxLen = Max( aLen1, Max( aLen2, aLen3 ));
816 double half_perimeter = ( aLen1 + aLen2 + aLen3 ) / 2.;
817 double anArea = getArea( P( 1 ), P( 3 ), P( 5 ));
818 if ( anArea <= theEps )
820 return alfa * maxLen * half_perimeter / anArea;
822 else if( nbNodes == 4 ) { // quadrangle
823 // Compute lengths of the sides
825 aLen[0] = getDistance( P(1), P(2) );
826 aLen[1] = getDistance( P(2), P(3) );
827 aLen[2] = getDistance( P(3), P(4) );
828 aLen[3] = getDistance( P(4), P(1) );
829 // Compute lengths of the diagonals
831 aDia[0] = getDistance( P(1), P(3) );
832 aDia[1] = getDistance( P(2), P(4) );
833 // Compute areas of all triangles which can be built
834 // taking three nodes of the quadrangle
836 anArea[0] = getArea( P(1), P(2), P(3) );
837 anArea[1] = getArea( P(1), P(2), P(4) );
838 anArea[2] = getArea( P(1), P(3), P(4) );
839 anArea[3] = getArea( P(2), P(3), P(4) );
840 // Q = alpha * L * C1 / C2, where
842 // alpha = sqrt( 1/32 )
843 // L = max( L1, L2, L3, L4, D1, D2 )
844 // C1 = sqrt( L1^2 + L1^2 + L1^2 + L1^2 )
845 // C2 = min( S1, S2, S3, S4 )
846 // Li - lengths of the edges
847 // Di - lengths of the diagonals
848 // Si - areas of the triangles
849 const double alpha = sqrt( 1 / 32. );
850 double L = Max( aLen[ 0 ],
854 Max( aDia[ 0 ], aDia[ 1 ] ) ) ) ) );
855 double C1 = sqrt( aLen[0] * aLen[0] +
859 double C2 = Min( anArea[ 0 ],
861 Min( anArea[ 2 ], anArea[ 3 ] ) ) );
864 return alpha * L * C1 / C2;
866 else if( nbNodes == 8 || nbNodes == 9 ) { // nbNodes==8 - quadratic quadrangle
867 // Compute lengths of the sides
869 aLen[0] = getDistance( P(1), P(3) );
870 aLen[1] = getDistance( P(3), P(5) );
871 aLen[2] = getDistance( P(5), P(7) );
872 aLen[3] = getDistance( P(7), P(1) );
873 // Compute lengths of the diagonals
875 aDia[0] = getDistance( P(1), P(5) );
876 aDia[1] = getDistance( P(3), P(7) );
877 // Compute areas of all triangles which can be built
878 // taking three nodes of the quadrangle
880 anArea[0] = getArea( P(1), P(3), P(5) );
881 anArea[1] = getArea( P(1), P(3), P(7) );
882 anArea[2] = getArea( P(1), P(5), P(7) );
883 anArea[3] = getArea( P(3), P(5), P(7) );
884 // Q = alpha * L * C1 / C2, where
886 // alpha = sqrt( 1/32 )
887 // L = max( L1, L2, L3, L4, D1, D2 )
888 // C1 = sqrt( L1^2 + L1^2 + L1^2 + L1^2 )
889 // C2 = min( S1, S2, S3, S4 )
890 // Li - lengths of the edges
891 // Di - lengths of the diagonals
892 // Si - areas of the triangles
893 const double alpha = sqrt( 1 / 32. );
894 double L = Max( aLen[ 0 ],
898 Max( aDia[ 0 ], aDia[ 1 ] ) ) ) ) );
899 double C1 = sqrt( aLen[0] * aLen[0] +
903 double C2 = Min( anArea[ 0 ],
905 Min( anArea[ 2 ], anArea[ 3 ] ) ) );
908 return alpha * L * C1 / C2;
913 bool AspectRatio::IsApplicable( const SMDS_MeshElement* element ) const
915 return ( NumericalFunctor::IsApplicable( element ) && !element->IsPoly() );
918 double AspectRatio::GetBadRate( double Value, int /*nbNodes*/ ) const
920 // the aspect ratio is in the range [1.0,infinity]
921 // < 1.0 = very bad, zero area
924 return ( Value < 0.9 ) ? 1000 : Value / 1000.;
927 SMDSAbs_ElementType AspectRatio::GetType() const
933 //================================================================================
935 Class : AspectRatio3D
936 Description : Functor for calculating aspect ratio
938 //================================================================================
942 inline double getHalfPerimeter(double theTria[3]){
943 return (theTria[0] + theTria[1] + theTria[2])/2.0;
946 inline double getArea(double theHalfPerim, double theTria[3]){
947 return sqrt(theHalfPerim*
948 (theHalfPerim-theTria[0])*
949 (theHalfPerim-theTria[1])*
950 (theHalfPerim-theTria[2]));
953 inline double getVolume(double theLen[6]){
954 double a2 = theLen[0]*theLen[0];
955 double b2 = theLen[1]*theLen[1];
956 double c2 = theLen[2]*theLen[2];
957 double d2 = theLen[3]*theLen[3];
958 double e2 = theLen[4]*theLen[4];
959 double f2 = theLen[5]*theLen[5];
960 double P = 4.0*a2*b2*d2;
961 double Q = a2*(b2+d2-e2)-b2*(a2+d2-f2)-d2*(a2+b2-c2);
962 double R = (b2+d2-e2)*(a2+d2-f2)*(a2+d2-f2);
963 return sqrt(P-Q+R)/12.0;
966 inline double getVolume2(double theLen[6]){
967 double a2 = theLen[0]*theLen[0];
968 double b2 = theLen[1]*theLen[1];
969 double c2 = theLen[2]*theLen[2];
970 double d2 = theLen[3]*theLen[3];
971 double e2 = theLen[4]*theLen[4];
972 double f2 = theLen[5]*theLen[5];
974 double P = a2*e2*(b2+c2+d2+f2-a2-e2);
975 double Q = b2*f2*(a2+c2+d2+e2-b2-f2);
976 double R = c2*d2*(a2+b2+e2+f2-c2-d2);
977 double S = a2*b2*d2+b2*c2*e2+a2*c2*f2+d2*e2*f2;
979 return sqrt(P+Q+R-S)/12.0;
982 inline double getVolume(const TSequenceOfXYZ& P){
983 gp_Vec aVec1( P( 2 ) - P( 1 ) );
984 gp_Vec aVec2( P( 3 ) - P( 1 ) );
985 gp_Vec aVec3( P( 4 ) - P( 1 ) );
986 gp_Vec anAreaVec( aVec1 ^ aVec2 );
987 return fabs(aVec3 * anAreaVec) / 6.0;
990 inline double getMaxHeight(double theLen[6])
992 double aHeight = std::max(theLen[0],theLen[1]);
993 aHeight = std::max(aHeight,theLen[2]);
994 aHeight = std::max(aHeight,theLen[3]);
995 aHeight = std::max(aHeight,theLen[4]);
996 aHeight = std::max(aHeight,theLen[5]);
1002 double AspectRatio3D::GetValue( long theId )
1005 myCurrElement = myMesh->FindElement( theId );
1006 if ( myCurrElement && myCurrElement->GetVtkType() == VTK_TETRA )
1008 // Action from CoTech | ACTION 31.3:
1009 // EURIWARE BO: Homogenize the formulas used to calculate the Controls in SMESH to fit with
1010 // those of ParaView. The library used by ParaView for those calculations can be reused in SMESH.
1011 vtkUnstructuredGrid* grid = const_cast<SMDS_Mesh*>( myMesh )->GetGrid();
1012 if ( vtkCell* avtkCell = grid->GetCell( myCurrElement->GetVtkID() ))
1013 aVal = Round( vtkMeshQuality::TetAspectRatio( avtkCell ));
1018 if ( GetPoints( myCurrElement, P ))
1019 aVal = Round( GetValue( P ));
1024 bool AspectRatio3D::IsApplicable( const SMDS_MeshElement* element ) const
1026 return ( NumericalFunctor::IsApplicable( element ) && !element->IsPoly() );
1029 double AspectRatio3D::GetValue( const TSequenceOfXYZ& P )
1031 double aQuality = 0.0;
1032 if(myCurrElement->IsPoly()) return aQuality;
1034 int nbNodes = P.size();
1036 if( myCurrElement->IsQuadratic() ) {
1037 if (nbNodes==10) nbNodes=4; // quadratic tetrahedron
1038 else if(nbNodes==13) nbNodes=5; // quadratic pyramid
1039 else if(nbNodes==15) nbNodes=6; // quadratic pentahedron
1040 else if(nbNodes==20) nbNodes=8; // quadratic hexahedron
1041 else if(nbNodes==27) nbNodes=8; // tri-quadratic hexahedron
1042 else return aQuality;
1048 getDistance(P( 1 ),P( 2 )), // a
1049 getDistance(P( 2 ),P( 3 )), // b
1050 getDistance(P( 3 ),P( 1 )), // c
1051 getDistance(P( 2 ),P( 4 )), // d
1052 getDistance(P( 3 ),P( 4 )), // e
1053 getDistance(P( 1 ),P( 4 )) // f
1055 double aTria[4][3] = {
1056 {aLen[0],aLen[1],aLen[2]}, // abc
1057 {aLen[0],aLen[3],aLen[5]}, // adf
1058 {aLen[1],aLen[3],aLen[4]}, // bde
1059 {aLen[2],aLen[4],aLen[5]} // cef
1061 double aSumArea = 0.0;
1062 double aHalfPerimeter = getHalfPerimeter(aTria[0]);
1063 double anArea = getArea(aHalfPerimeter,aTria[0]);
1065 aHalfPerimeter = getHalfPerimeter(aTria[1]);
1066 anArea = getArea(aHalfPerimeter,aTria[1]);
1068 aHalfPerimeter = getHalfPerimeter(aTria[2]);
1069 anArea = getArea(aHalfPerimeter,aTria[2]);
1071 aHalfPerimeter = getHalfPerimeter(aTria[3]);
1072 anArea = getArea(aHalfPerimeter,aTria[3]);
1074 double aVolume = getVolume(P);
1075 //double aVolume = getVolume(aLen);
1076 double aHeight = getMaxHeight(aLen);
1077 static double aCoeff = sqrt(2.0)/12.0;
1078 if ( aVolume > DBL_MIN )
1079 aQuality = aCoeff*aHeight*aSumArea/aVolume;
1084 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 3 ),P( 5 )};
1085 aQuality = GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4]));
1088 gp_XYZ aXYZ[4] = {P( 1 ),P( 3 ),P( 4 ),P( 5 )};
1089 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1092 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 5 )};
1093 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1096 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 4 ),P( 5 )};
1097 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1103 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 6 )};
1104 aQuality = GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4]));
1107 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 3 )};
1108 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1111 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 6 )};
1112 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1115 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
1116 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1119 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 6 )};
1120 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1123 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 3 )};
1124 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1130 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
1131 aQuality = GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4]));
1134 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 4 )};
1135 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1138 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 7 )};
1139 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1142 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 8 )};
1143 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1146 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 3 )};
1147 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1150 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 4 )};
1151 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1154 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 7 )};
1155 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1158 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 8 )};
1159 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1162 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 3 )};
1163 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1166 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 4 )};
1167 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1170 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 7 )};
1171 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1174 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 8 )};
1175 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1178 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 1 )};
1179 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1182 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 2 )};
1183 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1186 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 5 )};
1187 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1190 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 6 )};
1191 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1194 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 1 )};
1195 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1198 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 2 )};
1199 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1202 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 5 )};
1203 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1206 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 6 )};
1207 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1210 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 1 )};
1211 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1214 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
1215 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1218 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 5 )};
1219 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1222 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 6 )};
1223 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1226 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
1227 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1230 gp_XYZ aXYZ[4] = {P( 4 ),P( 5 ),P( 8 ),P( 2 )};
1231 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1234 gp_XYZ aXYZ[4] = {P( 1 ),P( 4 ),P( 5 ),P( 3 )};
1235 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1238 gp_XYZ aXYZ[4] = {P( 3 ),P( 6 ),P( 7 ),P( 1 )};
1239 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1242 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 6 ),P( 4 )};
1243 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1246 gp_XYZ aXYZ[4] = {P( 5 ),P( 6 ),P( 8 ),P( 3 )};
1247 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1250 gp_XYZ aXYZ[4] = {P( 7 ),P( 8 ),P( 6 ),P( 1 )};
1251 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1254 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 7 )};
1255 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1258 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 2 ),P( 5 )};
1259 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1265 gp_XYZ aXYZ[8] = {P( 1 ),P( 2 ),P( 4 ),P( 5 ),P( 7 ),P( 8 ),P( 10 ),P( 11 )};
1266 aQuality = GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[8]));
1269 gp_XYZ aXYZ[8] = {P( 2 ),P( 3 ),P( 5 ),P( 6 ),P( 8 ),P( 9 ),P( 11 ),P( 12 )};
1270 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[8])),aQuality);
1273 gp_XYZ aXYZ[8] = {P( 3 ),P( 4 ),P( 6 ),P( 1 ),P( 9 ),P( 10 ),P( 12 ),P( 7 )};
1274 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[8])),aQuality);
1277 } // switch(nbNodes)
1279 if ( nbNodes > 4 ) {
1280 // evaluate aspect ratio of quadrangle faces
1281 AspectRatio aspect2D;
1282 SMDS_VolumeTool::VolumeType type = SMDS_VolumeTool::GetType( nbNodes );
1283 int nbFaces = SMDS_VolumeTool::NbFaces( type );
1284 TSequenceOfXYZ points(4);
1285 for ( int i = 0; i < nbFaces; ++i ) { // loop on faces of a volume
1286 if ( SMDS_VolumeTool::NbFaceNodes( type, i ) != 4 )
1288 const int* pInd = SMDS_VolumeTool::GetFaceNodesIndices( type, i, true );
1289 for ( int p = 0; p < 4; ++p ) // loop on nodes of a quadrangle face
1290 points( p + 1 ) = P( pInd[ p ] + 1 );
1291 aQuality = std::max( aQuality, aspect2D.GetValue( points ));
1297 double AspectRatio3D::GetBadRate( double Value, int /*nbNodes*/ ) const
1299 // the aspect ratio is in the range [1.0,infinity]
1302 return Value / 1000.;
1305 SMDSAbs_ElementType AspectRatio3D::GetType() const
1307 return SMDSAbs_Volume;
1311 //================================================================================
1314 Description : Functor for calculating warping
1316 //================================================================================
1318 bool Warping::IsApplicable( const SMDS_MeshElement* element ) const
1320 return NumericalFunctor::IsApplicable( element ) && element->NbNodes() == 4;
1323 double Warping::GetValue( const TSequenceOfXYZ& P )
1325 if ( P.size() != 4 )
1328 gp_XYZ G = ( P( 1 ) + P( 2 ) + P( 3 ) + P( 4 ) ) / 4.;
1330 double A1 = ComputeA( P( 1 ), P( 2 ), P( 3 ), G );
1331 double A2 = ComputeA( P( 2 ), P( 3 ), P( 4 ), G );
1332 double A3 = ComputeA( P( 3 ), P( 4 ), P( 1 ), G );
1333 double A4 = ComputeA( P( 4 ), P( 1 ), P( 2 ), G );
1335 double val = Max( Max( A1, A2 ), Max( A3, A4 ) );
1337 const double eps = 0.1; // val is in degrees
1339 return val < eps ? 0. : val;
1342 double Warping::ComputeA( const gp_XYZ& thePnt1,
1343 const gp_XYZ& thePnt2,
1344 const gp_XYZ& thePnt3,
1345 const gp_XYZ& theG ) const
1347 double aLen1 = gp_Pnt( thePnt1 ).Distance( gp_Pnt( thePnt2 ) );
1348 double aLen2 = gp_Pnt( thePnt2 ).Distance( gp_Pnt( thePnt3 ) );
1349 double L = Min( aLen1, aLen2 ) * 0.5;
1353 gp_XYZ GI = ( thePnt2 + thePnt1 ) / 2. - theG;
1354 gp_XYZ GJ = ( thePnt3 + thePnt2 ) / 2. - theG;
1355 gp_XYZ N = GI.Crossed( GJ );
1357 if ( N.Modulus() < gp::Resolution() )
1362 double H = ( thePnt2 - theG ).Dot( N );
1363 return asin( fabs( H / L ) ) * 180. / M_PI;
1366 double Warping::GetBadRate( double Value, int /*nbNodes*/ ) const
1368 // the warp is in the range [0.0,PI/2]
1369 // 0.0 = good (no warp)
1370 // PI/2 = bad (face pliee)
1374 SMDSAbs_ElementType Warping::GetType() const
1376 return SMDSAbs_Face;
1380 //================================================================================
1383 Description : Functor for calculating taper
1385 //================================================================================
1387 bool Taper::IsApplicable( const SMDS_MeshElement* element ) const
1389 return ( NumericalFunctor::IsApplicable( element ) && element->NbNodes() == 4 );
1392 double Taper::GetValue( const TSequenceOfXYZ& P )
1394 if ( P.size() != 4 )
1398 double J1 = getArea( P( 4 ), P( 1 ), P( 2 ) );
1399 double J2 = getArea( P( 3 ), P( 1 ), P( 2 ) );
1400 double J3 = getArea( P( 2 ), P( 3 ), P( 4 ) );
1401 double J4 = getArea( P( 3 ), P( 4 ), P( 1 ) );
1403 double JA = 0.25 * ( J1 + J2 + J3 + J4 );
1407 double T1 = fabs( ( J1 - JA ) / JA );
1408 double T2 = fabs( ( J2 - JA ) / JA );
1409 double T3 = fabs( ( J3 - JA ) / JA );
1410 double T4 = fabs( ( J4 - JA ) / JA );
1412 double val = Max( Max( T1, T2 ), Max( T3, T4 ) );
1414 const double eps = 0.01;
1416 return val < eps ? 0. : val;
1419 double Taper::GetBadRate( double Value, int /*nbNodes*/ ) const
1421 // the taper is in the range [0.0,1.0]
1422 // 0.0 = good (no taper)
1423 // 1.0 = bad (les cotes opposes sont allignes)
1427 SMDSAbs_ElementType Taper::GetType() const
1429 return SMDSAbs_Face;
1432 //================================================================================
1435 Description : Functor for calculating skew in degrees
1437 //================================================================================
1439 static inline double skewAngle( const gp_XYZ& p1, const gp_XYZ& p2, const gp_XYZ& p3 )
1441 gp_XYZ p12 = ( p2 + p1 ) / 2.;
1442 gp_XYZ p23 = ( p3 + p2 ) / 2.;
1443 gp_XYZ p31 = ( p3 + p1 ) / 2.;
1445 gp_Vec v1( p31 - p2 ), v2( p12 - p23 );
1447 return v1.Magnitude() < gp::Resolution() || v2.Magnitude() < gp::Resolution() ? 0. : v1.Angle( v2 );
1450 bool Skew::IsApplicable( const SMDS_MeshElement* element ) const
1452 return ( NumericalFunctor::IsApplicable( element ) && element->NbNodes() <= 4 );
1455 double Skew::GetValue( const TSequenceOfXYZ& P )
1457 if ( P.size() != 3 && P.size() != 4 )
1461 const double PI2 = M_PI / 2.;
1462 if ( P.size() == 3 )
1464 double A0 = fabs( PI2 - skewAngle( P( 3 ), P( 1 ), P( 2 ) ) );
1465 double A1 = fabs( PI2 - skewAngle( P( 1 ), P( 2 ), P( 3 ) ) );
1466 double A2 = fabs( PI2 - skewAngle( P( 2 ), P( 3 ), P( 1 ) ) );
1468 return Max( A0, Max( A1, A2 ) ) * 180. / M_PI;
1472 gp_XYZ p12 = ( P( 1 ) + P( 2 ) ) / 2.;
1473 gp_XYZ p23 = ( P( 2 ) + P( 3 ) ) / 2.;
1474 gp_XYZ p34 = ( P( 3 ) + P( 4 ) ) / 2.;
1475 gp_XYZ p41 = ( P( 4 ) + P( 1 ) ) / 2.;
1477 gp_Vec v1( p34 - p12 ), v2( p23 - p41 );
1478 double A = v1.Magnitude() <= gp::Resolution() || v2.Magnitude() <= gp::Resolution()
1479 ? 0. : fabs( PI2 - v1.Angle( v2 ) );
1481 double val = A * 180. / M_PI;
1483 const double eps = 0.1; // val is in degrees
1485 return val < eps ? 0. : val;
1489 double Skew::GetBadRate( double Value, int /*nbNodes*/ ) const
1491 // the skew is in the range [0.0,PI/2].
1497 SMDSAbs_ElementType Skew::GetType() const
1499 return SMDSAbs_Face;
1503 //================================================================================
1506 Description : Functor for calculating area
1508 //================================================================================
1510 double Area::GetValue( const TSequenceOfXYZ& P )
1515 gp_Vec aVec1( P(2) - P(1) );
1516 gp_Vec aVec2( P(3) - P(1) );
1517 gp_Vec SumVec = aVec1 ^ aVec2;
1519 for (size_t i=4; i<=P.size(); i++)
1521 gp_Vec aVec1( P(i-1) - P(1) );
1522 gp_Vec aVec2( P(i ) - P(1) );
1523 gp_Vec tmp = aVec1 ^ aVec2;
1526 val = SumVec.Magnitude() * 0.5;
1531 double Area::GetBadRate( double Value, int /*nbNodes*/ ) const
1533 // meaningless as it is not a quality control functor
1537 SMDSAbs_ElementType Area::GetType() const
1539 return SMDSAbs_Face;
1542 //================================================================================
1545 Description : Functor for calculating length of edge
1547 //================================================================================
1549 double Length::GetValue( const TSequenceOfXYZ& P )
1551 switch ( P.size() ) {
1552 case 2: return getDistance( P( 1 ), P( 2 ) );
1553 case 3: return getDistance( P( 1 ), P( 2 ) ) + getDistance( P( 2 ), P( 3 ) );
1558 double Length::GetBadRate( double Value, int /*nbNodes*/ ) const
1560 // meaningless as it is not quality control functor
1564 SMDSAbs_ElementType Length::GetType() const
1566 return SMDSAbs_Edge;
1569 //================================================================================
1572 Description : Functor for calculating minimal length of element edge
1574 //================================================================================
1576 Length3D::Length3D():
1577 Length2D ( SMDSAbs_Volume )
1581 //================================================================================
1584 Description : Functor for calculating minimal length of element edge
1586 //================================================================================
1588 Length2D::Length2D( SMDSAbs_ElementType type ):
1593 bool Length2D::IsApplicable( const SMDS_MeshElement* element ) const
1595 return ( NumericalFunctor::IsApplicable( element ) &&
1596 element->GetEntityType() != SMDSEntity_Polyhedra );
1599 double Length2D::GetValue( const TSequenceOfXYZ& P )
1603 SMDSAbs_EntityType aType = P.getElementEntity();
1606 case SMDSEntity_Edge:
1608 aVal = getDistance( P( 1 ), P( 2 ) );
1610 case SMDSEntity_Quad_Edge:
1611 if (len == 3) // quadratic edge
1612 aVal = getDistance(P( 1 ),P( 3 )) + getDistance(P( 3 ),P( 2 ));
1614 case SMDSEntity_Triangle:
1615 if (len == 3){ // triangles
1616 double L1 = getDistance(P( 1 ),P( 2 ));
1617 double L2 = getDistance(P( 2 ),P( 3 ));
1618 double L3 = getDistance(P( 3 ),P( 1 ));
1619 aVal = Min(L1,Min(L2,L3));
1622 case SMDSEntity_Quadrangle:
1623 if (len == 4){ // quadrangles
1624 double L1 = getDistance(P( 1 ),P( 2 ));
1625 double L2 = getDistance(P( 2 ),P( 3 ));
1626 double L3 = getDistance(P( 3 ),P( 4 ));
1627 double L4 = getDistance(P( 4 ),P( 1 ));
1628 aVal = Min(Min(L1,L2),Min(L3,L4));
1631 case SMDSEntity_Quad_Triangle:
1632 case SMDSEntity_BiQuad_Triangle:
1633 if (len >= 6){ // quadratic triangles
1634 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1635 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1636 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 1 ));
1637 aVal = Min(L1,Min(L2,L3));
1640 case SMDSEntity_Quad_Quadrangle:
1641 case SMDSEntity_BiQuad_Quadrangle:
1642 if (len >= 8){ // quadratic quadrangles
1643 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1644 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1645 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 7 ));
1646 double L4 = getDistance(P( 7 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
1647 aVal = Min(Min(L1,L2),Min(L3,L4));
1650 case SMDSEntity_Tetra:
1651 if (len == 4){ // tetrahedra
1652 double L1 = getDistance(P( 1 ),P( 2 ));
1653 double L2 = getDistance(P( 2 ),P( 3 ));
1654 double L3 = getDistance(P( 3 ),P( 1 ));
1655 double L4 = getDistance(P( 1 ),P( 4 ));
1656 double L5 = getDistance(P( 2 ),P( 4 ));
1657 double L6 = getDistance(P( 3 ),P( 4 ));
1658 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1661 case SMDSEntity_Pyramid:
1662 if (len == 5){ // pyramid
1663 double L1 = getDistance(P( 1 ),P( 2 ));
1664 double L2 = getDistance(P( 2 ),P( 3 ));
1665 double L3 = getDistance(P( 3 ),P( 4 ));
1666 double L4 = getDistance(P( 4 ),P( 1 ));
1667 double L5 = getDistance(P( 1 ),P( 5 ));
1668 double L6 = getDistance(P( 2 ),P( 5 ));
1669 double L7 = getDistance(P( 3 ),P( 5 ));
1670 double L8 = getDistance(P( 4 ),P( 5 ));
1672 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1673 aVal = Min(aVal,Min(L7,L8));
1676 case SMDSEntity_Penta:
1677 if (len == 6) { // pentahedron
1678 double L1 = getDistance(P( 1 ),P( 2 ));
1679 double L2 = getDistance(P( 2 ),P( 3 ));
1680 double L3 = getDistance(P( 3 ),P( 1 ));
1681 double L4 = getDistance(P( 4 ),P( 5 ));
1682 double L5 = getDistance(P( 5 ),P( 6 ));
1683 double L6 = getDistance(P( 6 ),P( 4 ));
1684 double L7 = getDistance(P( 1 ),P( 4 ));
1685 double L8 = getDistance(P( 2 ),P( 5 ));
1686 double L9 = getDistance(P( 3 ),P( 6 ));
1688 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1689 aVal = Min(aVal,Min(Min(L7,L8),L9));
1692 case SMDSEntity_Hexa:
1693 if (len == 8){ // hexahedron
1694 double L1 = getDistance(P( 1 ),P( 2 ));
1695 double L2 = getDistance(P( 2 ),P( 3 ));
1696 double L3 = getDistance(P( 3 ),P( 4 ));
1697 double L4 = getDistance(P( 4 ),P( 1 ));
1698 double L5 = getDistance(P( 5 ),P( 6 ));
1699 double L6 = getDistance(P( 6 ),P( 7 ));
1700 double L7 = getDistance(P( 7 ),P( 8 ));
1701 double L8 = getDistance(P( 8 ),P( 5 ));
1702 double L9 = getDistance(P( 1 ),P( 5 ));
1703 double L10= getDistance(P( 2 ),P( 6 ));
1704 double L11= getDistance(P( 3 ),P( 7 ));
1705 double L12= getDistance(P( 4 ),P( 8 ));
1707 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1708 aVal = Min(aVal,Min(Min(L7,L8),Min(L9,L10)));
1709 aVal = Min(aVal,Min(L11,L12));
1712 case SMDSEntity_Quad_Tetra:
1713 if (len == 10){ // quadratic tetrahedron
1714 double L1 = getDistance(P( 1 ),P( 5 )) + getDistance(P( 5 ),P( 2 ));
1715 double L2 = getDistance(P( 2 ),P( 6 )) + getDistance(P( 6 ),P( 3 ));
1716 double L3 = getDistance(P( 3 ),P( 7 )) + getDistance(P( 7 ),P( 1 ));
1717 double L4 = getDistance(P( 1 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
1718 double L5 = getDistance(P( 2 ),P( 9 )) + getDistance(P( 9 ),P( 4 ));
1719 double L6 = getDistance(P( 3 ),P( 10 )) + getDistance(P( 10 ),P( 4 ));
1720 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1723 case SMDSEntity_Quad_Pyramid:
1724 if (len == 13){ // quadratic pyramid
1725 double L1 = getDistance(P( 1 ),P( 6 )) + getDistance(P( 6 ),P( 2 ));
1726 double L2 = getDistance(P( 2 ),P( 7 )) + getDistance(P( 7 ),P( 3 ));
1727 double L3 = getDistance(P( 3 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
1728 double L4 = getDistance(P( 4 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1729 double L5 = getDistance(P( 1 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1730 double L6 = getDistance(P( 2 ),P( 11 )) + getDistance(P( 11 ),P( 5 ));
1731 double L7 = getDistance(P( 3 ),P( 12 )) + getDistance(P( 12 ),P( 5 ));
1732 double L8 = getDistance(P( 4 ),P( 13 )) + getDistance(P( 13 ),P( 5 ));
1733 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1734 aVal = Min(aVal,Min(L7,L8));
1737 case SMDSEntity_Quad_Penta:
1738 case SMDSEntity_BiQuad_Penta:
1739 if (len >= 15){ // quadratic pentahedron
1740 double L1 = getDistance(P( 1 ),P( 7 )) + getDistance(P( 7 ),P( 2 ));
1741 double L2 = getDistance(P( 2 ),P( 8 )) + getDistance(P( 8 ),P( 3 ));
1742 double L3 = getDistance(P( 3 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1743 double L4 = getDistance(P( 4 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1744 double L5 = getDistance(P( 5 ),P( 11 )) + getDistance(P( 11 ),P( 6 ));
1745 double L6 = getDistance(P( 6 ),P( 12 )) + getDistance(P( 12 ),P( 4 ));
1746 double L7 = getDistance(P( 1 ),P( 13 )) + getDistance(P( 13 ),P( 4 ));
1747 double L8 = getDistance(P( 2 ),P( 14 )) + getDistance(P( 14 ),P( 5 ));
1748 double L9 = getDistance(P( 3 ),P( 15 )) + getDistance(P( 15 ),P( 6 ));
1749 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1750 aVal = Min(aVal,Min(Min(L7,L8),L9));
1753 case SMDSEntity_Quad_Hexa:
1754 case SMDSEntity_TriQuad_Hexa:
1755 if (len >= 20) { // quadratic hexahedron
1756 double L1 = getDistance(P( 1 ),P( 9 )) + getDistance(P( 9 ),P( 2 ));
1757 double L2 = getDistance(P( 2 ),P( 10 )) + getDistance(P( 10 ),P( 3 ));
1758 double L3 = getDistance(P( 3 ),P( 11 )) + getDistance(P( 11 ),P( 4 ));
1759 double L4 = getDistance(P( 4 ),P( 12 )) + getDistance(P( 12 ),P( 1 ));
1760 double L5 = getDistance(P( 5 ),P( 13 )) + getDistance(P( 13 ),P( 6 ));
1761 double L6 = getDistance(P( 6 ),P( 14 )) + getDistance(P( 14 ),P( 7 ));
1762 double L7 = getDistance(P( 7 ),P( 15 )) + getDistance(P( 15 ),P( 8 ));
1763 double L8 = getDistance(P( 8 ),P( 16 )) + getDistance(P( 16 ),P( 5 ));
1764 double L9 = getDistance(P( 1 ),P( 17 )) + getDistance(P( 17 ),P( 5 ));
1765 double L10= getDistance(P( 2 ),P( 18 )) + getDistance(P( 18 ),P( 6 ));
1766 double L11= getDistance(P( 3 ),P( 19 )) + getDistance(P( 19 ),P( 7 ));
1767 double L12= getDistance(P( 4 ),P( 20 )) + getDistance(P( 20 ),P( 8 ));
1768 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1769 aVal = Min(aVal,Min(Min(L7,L8),Min(L9,L10)));
1770 aVal = Min(aVal,Min(L11,L12));
1773 case SMDSEntity_Polygon:
1775 aVal = getDistance( P(1), P( P.size() ));
1776 for ( size_t i = 1; i < P.size(); ++i )
1777 aVal = Min( aVal, getDistance( P( i ), P( i+1 )));
1780 case SMDSEntity_Quad_Polygon:
1782 aVal = getDistance( P(1), P( P.size() )) + getDistance( P(P.size()), P( P.size()-1 ));
1783 for ( size_t i = 1; i < P.size()-1; i += 2 )
1784 aVal = Min( aVal, getDistance( P( i ), P( i+1 )) + getDistance( P( i+1 ), P( i+2 )));
1787 case SMDSEntity_Hexagonal_Prism:
1788 if (len == 12) { // hexagonal prism
1789 double L1 = getDistance(P( 1 ),P( 2 ));
1790 double L2 = getDistance(P( 2 ),P( 3 ));
1791 double L3 = getDistance(P( 3 ),P( 4 ));
1792 double L4 = getDistance(P( 4 ),P( 5 ));
1793 double L5 = getDistance(P( 5 ),P( 6 ));
1794 double L6 = getDistance(P( 6 ),P( 1 ));
1796 double L7 = getDistance(P( 7 ), P( 8 ));
1797 double L8 = getDistance(P( 8 ), P( 9 ));
1798 double L9 = getDistance(P( 9 ), P( 10 ));
1799 double L10= getDistance(P( 10 ),P( 11 ));
1800 double L11= getDistance(P( 11 ),P( 12 ));
1801 double L12= getDistance(P( 12 ),P( 7 ));
1803 double L13 = getDistance(P( 1 ),P( 7 ));
1804 double L14 = getDistance(P( 2 ),P( 8 ));
1805 double L15 = getDistance(P( 3 ),P( 9 ));
1806 double L16 = getDistance(P( 4 ),P( 10 ));
1807 double L17 = getDistance(P( 5 ),P( 11 ));
1808 double L18 = getDistance(P( 6 ),P( 12 ));
1809 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1810 aVal = Min(aVal, Min(Min(Min(L7,L8),Min(L9,L10)),Min(L11,L12)));
1811 aVal = Min(aVal, Min(Min(Min(L13,L14),Min(L15,L16)),Min(L17,L18)));
1814 case SMDSEntity_Polyhedra:
1826 if ( myPrecision >= 0 )
1828 double prec = pow( 10., (double)( myPrecision ) );
1829 aVal = floor( aVal * prec + 0.5 ) / prec;
1835 double Length2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1837 // meaningless as it is not a quality control functor
1841 SMDSAbs_ElementType Length2D::GetType() const
1846 Length2D::Value::Value(double theLength,long thePntId1, long thePntId2):
1849 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1850 if(thePntId1 > thePntId2){
1851 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1855 bool Length2D::Value::operator<(const Length2D::Value& x) const
1857 if(myPntId[0] < x.myPntId[0]) return true;
1858 if(myPntId[0] == x.myPntId[0])
1859 if(myPntId[1] < x.myPntId[1]) return true;
1863 void Length2D::GetValues(TValues& theValues)
1865 if ( myType == SMDSAbs_Face )
1867 for ( SMDS_FaceIteratorPtr anIter = myMesh->facesIterator(); anIter->more(); )
1869 const SMDS_MeshFace* anElem = anIter->next();
1870 if ( anElem->IsQuadratic() )
1872 // use special nodes iterator
1873 SMDS_NodeIteratorPtr anIter = anElem->interlacedNodesIterator();
1874 smIdType aNodeId[4] = { 0,0,0,0 };
1878 if ( anIter->more() )
1880 const SMDS_MeshNode* aNode = anIter->next();
1881 P[0] = P[1] = SMESH_NodeXYZ( aNode );
1882 aNodeId[0] = aNodeId[1] = aNode->GetID();
1885 for ( ; anIter->more(); )
1887 const SMDS_MeshNode* N1 = anIter->next();
1888 P[2] = SMESH_NodeXYZ( N1 );
1889 aNodeId[2] = N1->GetID();
1890 aLength = P[1].Distance(P[2]);
1891 if(!anIter->more()) break;
1892 const SMDS_MeshNode* N2 = anIter->next();
1893 P[3] = SMESH_NodeXYZ( N2 );
1894 aNodeId[3] = N2->GetID();
1895 aLength += P[2].Distance(P[3]);
1896 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1897 Value aValue2(aLength,aNodeId[2],aNodeId[3]);
1899 aNodeId[1] = aNodeId[3];
1900 theValues.insert(aValue1);
1901 theValues.insert(aValue2);
1903 aLength += P[2].Distance(P[0]);
1904 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1905 Value aValue2(aLength,aNodeId[2],aNodeId[0]);
1906 theValues.insert(aValue1);
1907 theValues.insert(aValue2);
1910 SMDS_NodeIteratorPtr aNodesIter = anElem->nodeIterator();
1911 smIdType aNodeId[2] = {0,0};
1915 const SMDS_MeshElement* aNode;
1916 if ( aNodesIter->more())
1918 aNode = aNodesIter->next();
1919 P[0] = P[1] = SMESH_NodeXYZ( aNode );
1920 aNodeId[0] = aNodeId[1] = aNode->GetID();
1923 for( ; aNodesIter->more(); )
1925 aNode = aNodesIter->next();
1926 smIdType anId = aNode->GetID();
1928 P[2] = SMESH_NodeXYZ( aNode );
1930 aLength = P[1].Distance(P[2]);
1932 Value aValue(aLength,aNodeId[1],anId);
1935 theValues.insert(aValue);
1938 aLength = P[0].Distance(P[1]);
1940 Value aValue(aLength,aNodeId[0],aNodeId[1]);
1941 theValues.insert(aValue);
1951 //================================================================================
1953 Class : Deflection2D
1954 Description : computes distance between a face center and an underlying surface
1956 //================================================================================
1958 double Deflection2D::GetValue( const TSequenceOfXYZ& P )
1960 if ( myMesh && P.getElement() )
1962 // get underlying surface
1963 if ( myShapeIndex != P.getElement()->getshapeId() )
1965 mySurface.Nullify();
1966 myShapeIndex = P.getElement()->getshapeId();
1967 const TopoDS_Shape& S =
1968 static_cast< const SMESHDS_Mesh* >( myMesh )->IndexToShape( myShapeIndex );
1969 if ( !S.IsNull() && S.ShapeType() == TopAbs_FACE )
1971 mySurface = new ShapeAnalysis_Surface( BRep_Tool::Surface( TopoDS::Face( S )));
1973 GeomLib_IsPlanarSurface isPlaneCheck( mySurface->Surface() );
1974 if ( isPlaneCheck.IsPlanar() )
1975 myPlane.reset( new gp_Pln( isPlaneCheck.Plan() ));
1980 // project gravity center to the surface
1981 if ( !mySurface.IsNull() )
1986 for ( size_t i = 0; i < P.size(); ++i )
1990 if ( SMDS_FacePositionPtr fPos = P.getElement()->GetNode( i )->GetPosition() )
1992 uv.ChangeCoord(1) += fPos->GetUParameter();
1993 uv.ChangeCoord(2) += fPos->GetVParameter();
1998 if ( nbUV ) uv /= nbUV;
2000 double maxLen = MaxElementLength2D().GetValue( P );
2001 double tol = 1e-3 * maxLen;
2005 dist = myPlane->Distance( gc );
2011 if ( uv.X() != 0 && uv.Y() != 0 ) // faster way
2012 mySurface->NextValueOfUV( uv, gc, tol, 0.5 * maxLen );
2014 mySurface->ValueOfUV( gc, tol );
2015 dist = mySurface->Gap();
2017 return Round( dist );
2023 void Deflection2D::SetMesh( const SMDS_Mesh* theMesh )
2025 NumericalFunctor::SetMesh( dynamic_cast<const SMESHDS_Mesh* >( theMesh ));
2026 myShapeIndex = -100;
2030 SMDSAbs_ElementType Deflection2D::GetType() const
2032 return SMDSAbs_Face;
2035 double Deflection2D::GetBadRate( double Value, int /*nbNodes*/ ) const
2037 // meaningless as it is not quality control functor
2041 //================================================================================
2043 Class : MultiConnection
2044 Description : Functor for calculating number of faces conneted to the edge
2046 //================================================================================
2048 double MultiConnection::GetValue( const TSequenceOfXYZ& /*P*/ )
2052 double MultiConnection::GetValue( long theId )
2054 return getNbMultiConnection( myMesh, theId );
2057 double MultiConnection::GetBadRate( double Value, int /*nbNodes*/ ) const
2059 // meaningless as it is not quality control functor
2063 SMDSAbs_ElementType MultiConnection::GetType() const
2065 return SMDSAbs_Edge;
2068 //================================================================================
2070 Class : MultiConnection2D
2071 Description : Functor for calculating number of faces conneted to the edge
2073 //================================================================================
2075 double MultiConnection2D::GetValue( const TSequenceOfXYZ& /*P*/ )
2080 double MultiConnection2D::GetValue( long theElementId )
2084 const SMDS_MeshElement* aFaceElem = myMesh->FindElement(theElementId);
2085 SMDSAbs_ElementType aType = aFaceElem->GetType();
2090 int i = 0, len = aFaceElem->NbNodes();
2091 SMDS_ElemIteratorPtr anIter = aFaceElem->nodesIterator();
2094 const SMDS_MeshNode *aNode, *aNode0 = 0;
2095 NCollection_Map< smIdType > aMap, aMapPrev;
2097 for (i = 0; i <= len; i++) {
2102 if (anIter->more()) {
2103 aNode = (SMDS_MeshNode*)anIter->next();
2111 if (i == 0) aNode0 = aNode;
2113 SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator();
2114 while (anElemIter->more()) {
2115 const SMDS_MeshElement* anElem = anElemIter->next();
2116 if (anElem != 0 && anElem->GetType() == SMDSAbs_Face) {
2117 smIdType anId = anElem->GetID();
2120 if (aMapPrev.Contains(anId)) {
2125 aResult = Max(aResult, aNb);
2136 double MultiConnection2D::GetBadRate( double Value, int /*nbNodes*/ ) const
2138 // meaningless as it is not quality control functor
2142 SMDSAbs_ElementType MultiConnection2D::GetType() const
2144 return SMDSAbs_Face;
2147 MultiConnection2D::Value::Value(long thePntId1, long thePntId2)
2149 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
2150 if(thePntId1 > thePntId2){
2151 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
2155 bool MultiConnection2D::Value::operator<(const MultiConnection2D::Value& x) const
2157 if(myPntId[0] < x.myPntId[0]) return true;
2158 if(myPntId[0] == x.myPntId[0])
2159 if(myPntId[1] < x.myPntId[1]) return true;
2163 void MultiConnection2D::GetValues(MValues& theValues)
2165 if ( !myMesh ) return;
2166 for ( SMDS_FaceIteratorPtr anIter = myMesh->facesIterator(); anIter->more(); )
2168 const SMDS_MeshFace* anElem = anIter->next();
2169 SMDS_NodeIteratorPtr aNodesIter = anElem->interlacedNodesIterator();
2171 const SMDS_MeshNode* aNode1 = anElem->GetNode( anElem->NbNodes() - 1 );
2172 const SMDS_MeshNode* aNode2;
2173 for ( ; aNodesIter->more(); )
2175 aNode2 = aNodesIter->next();
2177 Value aValue ( aNode1->GetID(), aNode2->GetID() );
2178 MValues::iterator aItr = theValues.insert( std::make_pair( aValue, 0 )).first;
2186 //================================================================================
2188 Class : BallDiameter
2189 Description : Functor returning diameter of a ball element
2191 //================================================================================
2193 double BallDiameter::GetValue( long theId )
2195 double diameter = 0;
2197 if ( const SMDS_BallElement* ball =
2198 myMesh->DownCast< SMDS_BallElement >( myMesh->FindElement( theId )))
2200 diameter = ball->GetDiameter();
2205 double BallDiameter::GetBadRate( double Value, int /*nbNodes*/ ) const
2207 // meaningless as it is not a quality control functor
2211 SMDSAbs_ElementType BallDiameter::GetType() const
2213 return SMDSAbs_Ball;
2216 //================================================================================
2218 Class : NodeConnectivityNumber
2219 Description : Functor returning number of elements connected to a node
2221 //================================================================================
2223 double NodeConnectivityNumber::GetValue( long theId )
2227 if ( const SMDS_MeshNode* node = myMesh->FindNode( theId ))
2229 SMDSAbs_ElementType type;
2230 if ( myMesh->NbVolumes() > 0 )
2231 type = SMDSAbs_Volume;
2232 else if ( myMesh->NbFaces() > 0 )
2233 type = SMDSAbs_Face;
2234 else if ( myMesh->NbEdges() > 0 )
2235 type = SMDSAbs_Edge;
2238 nb = node->NbInverseElements( type );
2243 double NodeConnectivityNumber::GetBadRate( double Value, int /*nbNodes*/ ) const
2248 SMDSAbs_ElementType NodeConnectivityNumber::GetType() const
2250 return SMDSAbs_Node;
2257 //================================================================================
2259 Class : BadOrientedVolume
2260 Description : Predicate bad oriented volumes
2262 //================================================================================
2264 BadOrientedVolume::BadOrientedVolume()
2269 void BadOrientedVolume::SetMesh( const SMDS_Mesh* theMesh )
2274 bool BadOrientedVolume::IsSatisfy( long theId )
2279 SMDS_VolumeTool vTool( myMesh->FindElement( theId ));
2282 if ( vTool.IsPoly() )
2285 for ( int i = 0; i < vTool.NbFaces() && isOk; ++i )
2286 isOk = vTool.IsFaceExternal( i );
2290 isOk = vTool.IsForward();
2295 SMDSAbs_ElementType BadOrientedVolume::GetType() const
2297 return SMDSAbs_Volume;
2301 Class : BareBorderVolume
2304 bool BareBorderVolume::IsSatisfy(long theElementId )
2306 SMDS_VolumeTool myTool;
2307 if ( myTool.Set( myMesh->FindElement(theElementId)))
2309 for ( int iF = 0; iF < myTool.NbFaces(); ++iF )
2310 if ( myTool.IsFreeFace( iF ))
2312 const SMDS_MeshNode** n = myTool.GetFaceNodes(iF);
2313 std::vector< const SMDS_MeshNode*> nodes( n, n+myTool.NbFaceNodes(iF));
2314 if ( !myMesh->FindElement( nodes, SMDSAbs_Face, /*Nomedium=*/false))
2321 //================================================================================
2323 Class : BareBorderFace
2325 //================================================================================
2327 bool BareBorderFace::IsSatisfy(long theElementId )
2330 if ( const SMDS_MeshElement* face = myMesh->FindElement(theElementId))
2332 if ( face->GetType() == SMDSAbs_Face )
2334 int nbN = face->NbCornerNodes();
2335 for ( int i = 0; i < nbN && !ok; ++i )
2337 // check if a link is shared by another face
2338 const SMDS_MeshNode* n1 = face->GetNode( i );
2339 const SMDS_MeshNode* n2 = face->GetNode( (i+1)%nbN );
2340 SMDS_ElemIteratorPtr fIt = n1->GetInverseElementIterator( SMDSAbs_Face );
2341 bool isShared = false;
2342 while ( !isShared && fIt->more() )
2344 const SMDS_MeshElement* f = fIt->next();
2345 isShared = ( f != face && f->GetNodeIndex(n2) != -1 );
2349 const int iQuad = face->IsQuadratic();
2350 myLinkNodes.resize( 2 + iQuad);
2351 myLinkNodes[0] = n1;
2352 myLinkNodes[1] = n2;
2354 myLinkNodes[2] = face->GetNode( i+nbN );
2355 ok = !myMesh->FindElement( myLinkNodes, SMDSAbs_Edge, /*noMedium=*/false);
2363 //================================================================================
2365 Class : OverConstrainedVolume
2367 //================================================================================
2369 bool OverConstrainedVolume::IsSatisfy(long theElementId )
2371 // An element is over-constrained if it has N-1 free borders where
2372 // N is the number of edges/faces for a 2D/3D element.
2373 SMDS_VolumeTool myTool;
2374 if ( myTool.Set( myMesh->FindElement(theElementId)))
2376 int nbSharedFaces = 0;
2377 for ( int iF = 0; iF < myTool.NbFaces(); ++iF )
2378 if ( !myTool.IsFreeFace( iF ) && ++nbSharedFaces > 1 )
2380 return ( nbSharedFaces == 1 );
2385 //================================================================================
2387 Class : OverConstrainedFace
2389 //================================================================================
2391 bool OverConstrainedFace::IsSatisfy(long theElementId )
2393 // An element is over-constrained if it has N-1 free borders where
2394 // N is the number of edges/faces for a 2D/3D element.
2395 if ( const SMDS_MeshElement* face = myMesh->FindElement(theElementId))
2396 if ( face->GetType() == SMDSAbs_Face )
2398 int nbSharedBorders = 0;
2399 int nbN = face->NbCornerNodes();
2400 for ( int i = 0; i < nbN; ++i )
2402 // check if a link is shared by another face
2403 const SMDS_MeshNode* n1 = face->GetNode( i );
2404 const SMDS_MeshNode* n2 = face->GetNode( (i+1)%nbN );
2405 SMDS_ElemIteratorPtr fIt = n1->GetInverseElementIterator( SMDSAbs_Face );
2406 bool isShared = false;
2407 while ( !isShared && fIt->more() )
2409 const SMDS_MeshElement* f = fIt->next();
2410 isShared = ( f != face && f->GetNodeIndex(n2) != -1 );
2412 if ( isShared && ++nbSharedBorders > 1 )
2415 return ( nbSharedBorders == 1 );
2420 //================================================================================
2422 Class : CoincidentNodes
2423 Description : Predicate of Coincident nodes
2425 //================================================================================
2427 CoincidentNodes::CoincidentNodes()
2432 bool CoincidentNodes::IsSatisfy( long theElementId )
2434 return myCoincidentIDs.Contains( theElementId );
2437 SMDSAbs_ElementType CoincidentNodes::GetType() const
2439 return SMDSAbs_Node;
2442 void CoincidentNodes::SetTolerance( const double theToler )
2444 if ( myToler != theToler )
2451 void CoincidentNodes::SetMesh( const SMDS_Mesh* theMesh )
2453 myMeshModifTracer.SetMesh( theMesh );
2454 if ( myMeshModifTracer.IsMeshModified() )
2456 TIDSortedNodeSet nodesToCheck;
2457 SMDS_NodeIteratorPtr nIt = theMesh->nodesIterator();
2458 while ( nIt->more() )
2459 nodesToCheck.insert( nodesToCheck.end(), nIt->next() );
2461 std::list< std::list< const SMDS_MeshNode*> > nodeGroups;
2462 SMESH_OctreeNode::FindCoincidentNodes ( nodesToCheck, &nodeGroups, myToler );
2464 myCoincidentIDs.Clear();
2465 std::list< std::list< const SMDS_MeshNode*> >::iterator groupIt = nodeGroups.begin();
2466 for ( ; groupIt != nodeGroups.end(); ++groupIt )
2468 std::list< const SMDS_MeshNode*>& coincNodes = *groupIt;
2469 std::list< const SMDS_MeshNode*>::iterator n = coincNodes.begin();
2470 for ( ; n != coincNodes.end(); ++n )
2471 myCoincidentIDs.Add( (*n)->GetID() );
2476 //================================================================================
2478 Class : CoincidentElements
2479 Description : Predicate of Coincident Elements
2480 Note : This class is suitable only for visualization of Coincident Elements
2482 //================================================================================
2484 CoincidentElements::CoincidentElements()
2489 void CoincidentElements::SetMesh( const SMDS_Mesh* theMesh )
2494 bool CoincidentElements::IsSatisfy( long theElementId )
2496 if ( !myMesh ) return false;
2498 if ( const SMDS_MeshElement* e = myMesh->FindElement( theElementId ))
2500 if ( e->GetType() != GetType() ) return false;
2501 std::set< const SMDS_MeshNode* > elemNodes( e->begin_nodes(), e->end_nodes() );
2502 const int nbNodes = e->NbNodes();
2503 SMDS_ElemIteratorPtr invIt = (*elemNodes.begin())->GetInverseElementIterator( GetType() );
2504 while ( invIt->more() )
2506 const SMDS_MeshElement* e2 = invIt->next();
2507 if ( e2 == e || e2->NbNodes() != nbNodes ) continue;
2509 bool sameNodes = true;
2510 for ( size_t i = 0; i < elemNodes.size() && sameNodes; ++i )
2511 sameNodes = ( elemNodes.count( e2->GetNode( i )));
2519 SMDSAbs_ElementType CoincidentElements1D::GetType() const
2521 return SMDSAbs_Edge;
2523 SMDSAbs_ElementType CoincidentElements2D::GetType() const
2525 return SMDSAbs_Face;
2527 SMDSAbs_ElementType CoincidentElements3D::GetType() const
2529 return SMDSAbs_Volume;
2533 //================================================================================
2536 Description : Predicate for free borders
2538 //================================================================================
2540 FreeBorders::FreeBorders()
2545 void FreeBorders::SetMesh( const SMDS_Mesh* theMesh )
2550 bool FreeBorders::IsSatisfy( long theId )
2552 return getNbMultiConnection( myMesh, theId ) == 1;
2555 SMDSAbs_ElementType FreeBorders::GetType() const
2557 return SMDSAbs_Edge;
2561 //================================================================================
2564 Description : Predicate for free Edges
2566 //================================================================================
2568 FreeEdges::FreeEdges()
2573 void FreeEdges::SetMesh( const SMDS_Mesh* theMesh )
2578 bool FreeEdges::IsFreeEdge( const SMDS_MeshNode** theNodes, const smIdType theFaceId )
2580 SMDS_ElemIteratorPtr anElemIter = theNodes[ 0 ]->GetInverseElementIterator(SMDSAbs_Face);
2581 while( anElemIter->more() )
2583 if ( const SMDS_MeshElement* anElem = anElemIter->next())
2585 const smIdType anId = anElem->GetID();
2586 if ( anId != theFaceId && anElem->GetNodeIndex( theNodes[1] ) >= 0 )
2593 bool FreeEdges::IsSatisfy( long theId )
2598 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
2599 if ( aFace == 0 || aFace->GetType() != SMDSAbs_Face || aFace->NbNodes() < 3 )
2602 SMDS_NodeIteratorPtr anIter = aFace->interlacedNodesIterator();
2606 int i = 0, nbNodes = aFace->NbNodes();
2607 std::vector <const SMDS_MeshNode*> aNodes( nbNodes+1 );
2608 while( anIter->more() )
2609 if ( ! ( aNodes[ i++ ] = anIter->next() ))
2611 aNodes[ nbNodes ] = aNodes[ 0 ];
2613 for ( i = 0; i < nbNodes; i++ )
2614 if ( IsFreeEdge( &aNodes[ i ], theId ) )
2620 SMDSAbs_ElementType FreeEdges::GetType() const
2622 return SMDSAbs_Face;
2625 FreeEdges::Border::Border(long theElemId, long thePntId1, long thePntId2):
2628 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
2629 if(thePntId1 > thePntId2){
2630 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
2634 bool FreeEdges::Border::operator<(const FreeEdges::Border& x) const{
2635 if(myPntId[0] < x.myPntId[0]) return true;
2636 if(myPntId[0] == x.myPntId[0])
2637 if(myPntId[1] < x.myPntId[1]) return true;
2641 inline void UpdateBorders(const FreeEdges::Border& theBorder,
2642 FreeEdges::TBorders& theRegistry,
2643 FreeEdges::TBorders& theContainer)
2645 if(theRegistry.find(theBorder) == theRegistry.end()){
2646 theRegistry.insert(theBorder);
2647 theContainer.insert(theBorder);
2649 theContainer.erase(theBorder);
2653 void FreeEdges::GetBoreders(TBorders& theBorders)
2656 for ( SMDS_FaceIteratorPtr anIter = myMesh->facesIterator(); anIter->more(); )
2658 const SMDS_MeshFace* anElem = anIter->next();
2659 long anElemId = anElem->GetID();
2660 SMDS_NodeIteratorPtr aNodesIter = anElem->interlacedNodesIterator();
2661 if ( !aNodesIter->more() ) continue;
2662 long aNodeId[2] = {0,0};
2663 aNodeId[0] = anElem->GetNode( anElem->NbNodes()-1 )->GetID();
2664 for ( ; aNodesIter->more(); )
2666 aNodeId[1] = aNodesIter->next()->GetID();
2667 Border aBorder( anElemId, aNodeId[0], aNodeId[1] );
2668 UpdateBorders( aBorder, aRegistry, theBorders );
2669 aNodeId[0] = aNodeId[1];
2674 //================================================================================
2677 Description : Predicate for free nodes
2679 //================================================================================
2681 FreeNodes::FreeNodes()
2686 void FreeNodes::SetMesh( const SMDS_Mesh* theMesh )
2691 bool FreeNodes::IsSatisfy( long theNodeId )
2693 const SMDS_MeshNode* aNode = myMesh->FindNode( theNodeId );
2697 return (aNode->NbInverseElements() < 1);
2700 SMDSAbs_ElementType FreeNodes::GetType() const
2702 return SMDSAbs_Node;
2706 //================================================================================
2709 Description : Predicate for free faces
2711 //================================================================================
2713 FreeFaces::FreeFaces()
2718 void FreeFaces::SetMesh( const SMDS_Mesh* theMesh )
2723 bool FreeFaces::IsSatisfy( long theId )
2725 if (!myMesh) return false;
2726 // check that faces nodes refers to less than two common volumes
2727 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
2728 if ( !aFace || aFace->GetType() != SMDSAbs_Face )
2731 int nbNode = aFace->NbNodes();
2733 // collect volumes to check that number of volumes with count equal nbNode not less than 2
2734 typedef std::map< SMDS_MeshElement*, int > TMapOfVolume; // map of volume counters
2735 typedef std::map< SMDS_MeshElement*, int >::iterator TItrMapOfVolume; // iterator
2736 TMapOfVolume mapOfVol;
2738 SMDS_ElemIteratorPtr nodeItr = aFace->nodesIterator();
2739 while ( nodeItr->more() )
2741 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(nodeItr->next());
2742 if ( !aNode ) continue;
2743 SMDS_ElemIteratorPtr volItr = aNode->GetInverseElementIterator(SMDSAbs_Volume);
2744 while ( volItr->more() )
2746 SMDS_MeshElement* aVol = (SMDS_MeshElement*)volItr->next();
2747 TItrMapOfVolume itr = mapOfVol.insert( std::make_pair( aVol, 0 )).first;
2752 TItrMapOfVolume volItr = mapOfVol.begin();
2753 TItrMapOfVolume volEnd = mapOfVol.end();
2754 for ( ; volItr != volEnd; ++volItr )
2755 if ( (*volItr).second >= nbNode )
2757 // face is not free if number of volumes constructed on their nodes more than one
2761 SMDSAbs_ElementType FreeFaces::GetType() const
2763 return SMDSAbs_Face;
2766 //================================================================================
2768 Class : LinearOrQuadratic
2769 Description : Predicate to verify whether a mesh element is linear
2771 //================================================================================
2773 LinearOrQuadratic::LinearOrQuadratic()
2778 void LinearOrQuadratic::SetMesh( const SMDS_Mesh* theMesh )
2783 bool LinearOrQuadratic::IsSatisfy( long theId )
2785 if (!myMesh) return false;
2786 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2787 if ( !anElem || (myType != SMDSAbs_All && anElem->GetType() != myType) )
2789 return (!anElem->IsQuadratic());
2792 void LinearOrQuadratic::SetType( SMDSAbs_ElementType theType )
2797 SMDSAbs_ElementType LinearOrQuadratic::GetType() const
2802 //================================================================================
2805 Description : Functor for check color of group to which mesh element belongs to
2807 //================================================================================
2809 GroupColor::GroupColor()
2813 bool GroupColor::IsSatisfy( long theId )
2815 return myIDs.count( theId );
2818 void GroupColor::SetType( SMDSAbs_ElementType theType )
2823 SMDSAbs_ElementType GroupColor::GetType() const
2828 static bool isEqual( const Quantity_Color& theColor1,
2829 const Quantity_Color& theColor2 )
2831 // tolerance to compare colors
2832 const double tol = 5*1e-3;
2833 return ( fabs( theColor1.Red() - theColor2.Red() ) < tol &&
2834 fabs( theColor1.Green() - theColor2.Green() ) < tol &&
2835 fabs( theColor1.Blue() - theColor2.Blue() ) < tol );
2838 void GroupColor::SetMesh( const SMDS_Mesh* theMesh )
2842 const SMESHDS_Mesh* aMesh = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
2846 int nbGrp = aMesh->GetNbGroups();
2850 // iterates on groups and find necessary elements ids
2851 const std::set<SMESHDS_GroupBase*>& aGroups = aMesh->GetGroups();
2852 std::set<SMESHDS_GroupBase*>::const_iterator GrIt = aGroups.begin();
2853 for (; GrIt != aGroups.end(); GrIt++)
2855 SMESHDS_GroupBase* aGrp = (*GrIt);
2858 // check type and color of group
2859 if ( !isEqual( myColor, aGrp->GetColor() ))
2862 // IPAL52867 (prevent infinite recursion via GroupOnFilter)
2863 if ( SMESHDS_GroupOnFilter * gof = dynamic_cast< SMESHDS_GroupOnFilter* >( aGrp ))
2864 if ( gof->GetPredicate().get() == this )
2867 SMDSAbs_ElementType aGrpElType = (SMDSAbs_ElementType)aGrp->GetType();
2868 if ( myType == aGrpElType || (myType == SMDSAbs_All && aGrpElType != SMDSAbs_Node) ) {
2869 // add elements IDS into control
2870 int aSize = aGrp->Extent();
2871 for (int i = 0; i < aSize; i++)
2872 myIDs.insert( aGrp->GetID(i+1) );
2877 void GroupColor::SetColorStr( const TCollection_AsciiString& theStr )
2879 Kernel_Utils::Localizer loc;
2880 TCollection_AsciiString aStr = theStr;
2881 aStr.RemoveAll( ' ' );
2882 aStr.RemoveAll( '\t' );
2883 for ( int aPos = aStr.Search( ";;" ); aPos != -1; aPos = aStr.Search( ";;" ) )
2884 aStr.Remove( aPos, 2 );
2885 Standard_Real clr[3];
2886 clr[0] = clr[1] = clr[2] = 0.;
2887 for ( int i = 0; i < 3; i++ ) {
2888 TCollection_AsciiString tmpStr = aStr.Token( ";", i+1 );
2889 if ( !tmpStr.IsEmpty() && tmpStr.IsRealValue() )
2890 clr[i] = tmpStr.RealValue();
2892 myColor = Quantity_Color( clr[0], clr[1], clr[2], Quantity_TOC_RGB );
2895 //=======================================================================
2896 // name : GetRangeStr
2897 // Purpose : Get range as a string.
2898 // Example: "1,2,3,50-60,63,67,70-"
2899 //=======================================================================
2901 void GroupColor::GetColorStr( TCollection_AsciiString& theResStr ) const
2904 theResStr += TCollection_AsciiString( myColor.Red() );
2905 theResStr += TCollection_AsciiString( ";" ) + TCollection_AsciiString( myColor.Green() );
2906 theResStr += TCollection_AsciiString( ";" ) + TCollection_AsciiString( myColor.Blue() );
2909 //================================================================================
2911 Class : ElemGeomType
2912 Description : Predicate to check element geometry type
2914 //================================================================================
2916 ElemGeomType::ElemGeomType()
2919 myType = SMDSAbs_All;
2920 myGeomType = SMDSGeom_TRIANGLE;
2923 void ElemGeomType::SetMesh( const SMDS_Mesh* theMesh )
2928 bool ElemGeomType::IsSatisfy( long theId )
2930 if (!myMesh) return false;
2931 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2934 const SMDSAbs_ElementType anElemType = anElem->GetType();
2935 if ( myType != SMDSAbs_All && anElemType != myType )
2937 bool isOk = ( anElem->GetGeomType() == myGeomType );
2941 void ElemGeomType::SetType( SMDSAbs_ElementType theType )
2946 SMDSAbs_ElementType ElemGeomType::GetType() const
2951 void ElemGeomType::SetGeomType( SMDSAbs_GeometryType theType )
2953 myGeomType = theType;
2956 SMDSAbs_GeometryType ElemGeomType::GetGeomType() const
2961 //================================================================================
2963 Class : ElemEntityType
2964 Description : Predicate to check element entity type
2966 //================================================================================
2968 ElemEntityType::ElemEntityType():
2970 myType( SMDSAbs_All ),
2971 myEntityType( SMDSEntity_0D )
2975 void ElemEntityType::SetMesh( const SMDS_Mesh* theMesh )
2980 bool ElemEntityType::IsSatisfy( long theId )
2982 if ( !myMesh ) return false;
2983 if ( myType == SMDSAbs_Node )
2984 return myMesh->FindNode( theId );
2985 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2987 myEntityType == anElem->GetEntityType() );
2990 void ElemEntityType::SetType( SMDSAbs_ElementType theType )
2995 SMDSAbs_ElementType ElemEntityType::GetType() const
3000 void ElemEntityType::SetElemEntityType( SMDSAbs_EntityType theEntityType )
3002 myEntityType = theEntityType;
3005 SMDSAbs_EntityType ElemEntityType::GetElemEntityType() const
3007 return myEntityType;
3010 //================================================================================
3012 * \brief Class ConnectedElements
3014 //================================================================================
3016 ConnectedElements::ConnectedElements():
3017 myNodeID(0), myType( SMDSAbs_All ), myOkIDsReady( false ) {}
3019 SMDSAbs_ElementType ConnectedElements::GetType() const
3022 int ConnectedElements::GetNode() const
3023 { return myXYZ.empty() ? myNodeID : 0; } // myNodeID can be found by myXYZ
3025 std::vector<double> ConnectedElements::GetPoint() const
3028 void ConnectedElements::clearOkIDs()
3029 { myOkIDsReady = false; myOkIDs.clear(); }
3031 void ConnectedElements::SetType( SMDSAbs_ElementType theType )
3033 if ( myType != theType || myMeshModifTracer.IsMeshModified() )
3038 void ConnectedElements::SetMesh( const SMDS_Mesh* theMesh )
3040 myMeshModifTracer.SetMesh( theMesh );
3041 if ( myMeshModifTracer.IsMeshModified() )
3044 if ( !myXYZ.empty() )
3045 SetPoint( myXYZ[0], myXYZ[1], myXYZ[2] ); // find a node near myXYZ it in a new mesh
3049 void ConnectedElements::SetNode( int nodeID )
3054 bool isSameDomain = false;
3055 if ( myOkIDsReady && myMeshModifTracer.GetMesh() && !myMeshModifTracer.IsMeshModified() )
3056 if ( const SMDS_MeshNode* n = myMeshModifTracer.GetMesh()->FindNode( myNodeID ))
3058 SMDS_ElemIteratorPtr eIt = n->GetInverseElementIterator( myType );
3059 while ( !isSameDomain && eIt->more() )
3060 isSameDomain = IsSatisfy( eIt->next()->GetID() );
3062 if ( !isSameDomain )
3066 void ConnectedElements::SetPoint( double x, double y, double z )
3074 bool isSameDomain = false;
3076 // find myNodeID by myXYZ if possible
3077 if ( myMeshModifTracer.GetMesh() )
3079 SMESHUtils::Deleter<SMESH_ElementSearcher> searcher
3080 ( SMESH_MeshAlgos::GetElementSearcher( (SMDS_Mesh&) *myMeshModifTracer.GetMesh() ));
3082 std::vector< const SMDS_MeshElement* > foundElems;
3083 searcher->FindElementsByPoint( gp_Pnt(x,y,z), SMDSAbs_All, foundElems );
3085 if ( !foundElems.empty() )
3087 myNodeID = foundElems[0]->GetNode(0)->GetID();
3088 if ( myOkIDsReady && !myMeshModifTracer.IsMeshModified() )
3089 isSameDomain = IsSatisfy( foundElems[0]->GetID() );
3092 if ( !isSameDomain )
3096 bool ConnectedElements::IsSatisfy( long theElementId )
3098 // Here we do NOT check if the mesh has changed, we do it in Set...() only!!!
3100 if ( !myOkIDsReady )
3102 if ( !myMeshModifTracer.GetMesh() )
3104 const SMDS_MeshNode* node0 = myMeshModifTracer.GetMesh()->FindNode( myNodeID );
3108 std::list< const SMDS_MeshNode* > nodeQueue( 1, node0 );
3109 std::set< smIdType > checkedNodeIDs;
3111 // foreach node in nodeQueue:
3112 // foreach element sharing a node:
3113 // add ID of an element of myType to myOkIDs;
3114 // push all element nodes absent from checkedNodeIDs to nodeQueue;
3115 while ( !nodeQueue.empty() )
3117 const SMDS_MeshNode* node = nodeQueue.front();
3118 nodeQueue.pop_front();
3120 // loop on elements sharing the node
3121 SMDS_ElemIteratorPtr eIt = node->GetInverseElementIterator();
3122 while ( eIt->more() )
3124 // keep elements of myType
3125 const SMDS_MeshElement* element = eIt->next();
3126 if ( myType == SMDSAbs_All || element->GetType() == myType )
3127 myOkIDs.insert( myOkIDs.end(), element->GetID() );
3129 // enqueue nodes of the element
3130 SMDS_ElemIteratorPtr nIt = element->nodesIterator();
3131 while ( nIt->more() )
3133 const SMDS_MeshNode* n = static_cast< const SMDS_MeshNode* >( nIt->next() );
3134 if ( checkedNodeIDs.insert( n->GetID()) )
3135 nodeQueue.push_back( n );
3139 if ( myType == SMDSAbs_Node )
3140 std::swap( myOkIDs, checkedNodeIDs );
3142 size_t totalNbElems = myMeshModifTracer.GetMesh()->GetMeshInfo().NbElements( myType );
3143 if ( myOkIDs.size() == totalNbElems )
3146 myOkIDsReady = true;
3149 return myOkIDs.empty() ? true : myOkIDs.count( theElementId );
3152 //================================================================================
3154 * \brief Class CoplanarFaces
3156 //================================================================================
3160 inline bool isLessAngle( const gp_Vec& v1, const gp_Vec& v2, const double cos )
3162 double dot = v1 * v2; // cos * |v1| * |v2|
3163 double l1 = v1.SquareMagnitude();
3164 double l2 = v2.SquareMagnitude();
3165 return (( dot * cos >= 0 ) &&
3166 ( dot * dot ) / l1 / l2 >= ( cos * cos ));
3169 CoplanarFaces::CoplanarFaces()
3170 : myFaceID(0), myToler(0)
3173 void CoplanarFaces::SetMesh( const SMDS_Mesh* theMesh )
3175 myMeshModifTracer.SetMesh( theMesh );
3176 if ( myMeshModifTracer.IsMeshModified() )
3178 // Build a set of coplanar face ids
3180 myCoplanarIDs.Clear();
3182 if ( !myMeshModifTracer.GetMesh() || !myFaceID || !myToler )
3185 const SMDS_MeshElement* face = myMeshModifTracer.GetMesh()->FindElement( myFaceID );
3186 if ( !face || face->GetType() != SMDSAbs_Face )
3190 gp_Vec myNorm = getNormale( static_cast<const SMDS_MeshFace*>(face), &normOK );
3194 const double cosTol = Cos( myToler * M_PI / 180. );
3195 NCollection_Map< SMESH_TLink, SMESH_TLink > checkedLinks;
3197 std::list< std::pair< const SMDS_MeshElement*, gp_Vec > > faceQueue;
3198 faceQueue.push_back( std::make_pair( face, myNorm ));
3199 while ( !faceQueue.empty() )
3201 face = faceQueue.front().first;
3202 myNorm = faceQueue.front().second;
3203 faceQueue.pop_front();
3205 for ( int i = 0, nbN = face->NbCornerNodes(); i < nbN; ++i )
3207 const SMDS_MeshNode* n1 = face->GetNode( i );
3208 const SMDS_MeshNode* n2 = face->GetNode(( i+1 )%nbN);
3209 if ( !checkedLinks.Add( SMESH_TLink( n1, n2 )))
3211 SMDS_ElemIteratorPtr fIt = n1->GetInverseElementIterator(SMDSAbs_Face);
3212 while ( fIt->more() )
3214 const SMDS_MeshElement* f = fIt->next();
3215 if ( f->GetNodeIndex( n2 ) > -1 )
3217 gp_Vec norm = getNormale( static_cast<const SMDS_MeshFace*>(f), &normOK );
3218 if (!normOK || isLessAngle( myNorm, norm, cosTol))
3220 myCoplanarIDs.Add( f->GetID() );
3221 faceQueue.push_back( std::make_pair( f, norm ));
3229 bool CoplanarFaces::IsSatisfy( long theElementId )
3231 return myCoplanarIDs.Contains( theElementId );
3236 *Description : Predicate for Range of Ids.
3237 * Range may be specified with two ways.
3238 * 1. Using AddToRange method
3239 * 2. With SetRangeStr method. Parameter of this method is a string
3240 * like as "1,2,3,50-60,63,67,70-"
3243 //=======================================================================
3244 // name : RangeOfIds
3245 // Purpose : Constructor
3246 //=======================================================================
3247 RangeOfIds::RangeOfIds()
3250 myType = SMDSAbs_All;
3253 //=======================================================================
3255 // Purpose : Set mesh
3256 //=======================================================================
3257 void RangeOfIds::SetMesh( const SMDS_Mesh* theMesh )
3262 //=======================================================================
3263 // name : AddToRange
3264 // Purpose : Add ID to the range
3265 //=======================================================================
3266 bool RangeOfIds::AddToRange( long theEntityId )
3268 myIds.Add( theEntityId );
3272 //=======================================================================
3273 // name : GetRangeStr
3274 // Purpose : Get range as a string.
3275 // Example: "1,2,3,50-60,63,67,70-"
3276 //=======================================================================
3277 void RangeOfIds::GetRangeStr( TCollection_AsciiString& theResStr )
3281 TColStd_SequenceOfInteger anIntSeq;
3282 TColStd_SequenceOfAsciiString aStrSeq;
3284 TColStd_MapIteratorOfMapOfInteger anIter( myIds );
3285 for ( ; anIter.More(); anIter.Next() )
3287 int anId = anIter.Key();
3288 TCollection_AsciiString aStr( anId );
3289 anIntSeq.Append( anId );
3290 aStrSeq.Append( aStr );
3293 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
3295 int aMinId = myMin( i );
3296 int aMaxId = myMax( i );
3298 TCollection_AsciiString aStr;
3299 if ( aMinId != IntegerFirst() )
3304 if ( aMaxId != IntegerLast() )
3307 // find position of the string in result sequence and insert string in it
3308 if ( anIntSeq.Length() == 0 )
3310 anIntSeq.Append( aMinId );
3311 aStrSeq.Append( aStr );
3315 if ( aMinId < anIntSeq.First() )
3317 anIntSeq.Prepend( aMinId );
3318 aStrSeq.Prepend( aStr );
3320 else if ( aMinId > anIntSeq.Last() )
3322 anIntSeq.Append( aMinId );
3323 aStrSeq.Append( aStr );
3326 for ( int j = 1, k = anIntSeq.Length(); j <= k; j++ )
3327 if ( aMinId < anIntSeq( j ) )
3329 anIntSeq.InsertBefore( j, aMinId );
3330 aStrSeq.InsertBefore( j, aStr );
3336 if ( aStrSeq.Length() == 0 )
3339 theResStr = aStrSeq( 1 );
3340 for ( int j = 2, k = aStrSeq.Length(); j <= k; j++ )
3343 theResStr += aStrSeq( j );
3347 //=======================================================================
3348 // name : SetRangeStr
3349 // Purpose : Define range with string
3350 // Example of entry string: "1,2,3,50-60,63,67,70-"
3351 //=======================================================================
3352 bool RangeOfIds::SetRangeStr( const TCollection_AsciiString& theStr )
3358 TCollection_AsciiString aStr = theStr;
3359 for ( int i = 1; i <= aStr.Length(); ++i )
3361 char c = aStr.Value( i );
3362 if ( !isdigit( c ) && c != ',' && c != '-' )
3363 aStr.SetValue( i, ',');
3365 aStr.RemoveAll( ' ' );
3367 TCollection_AsciiString tmpStr = aStr.Token( ",", 1 );
3369 while ( tmpStr != "" )
3371 tmpStr = aStr.Token( ",", i++ );
3372 int aPos = tmpStr.Search( '-' );
3376 if ( tmpStr.IsIntegerValue() )
3377 myIds.Add( tmpStr.IntegerValue() );
3383 TCollection_AsciiString aMaxStr = tmpStr.Split( aPos );
3384 TCollection_AsciiString aMinStr = tmpStr;
3386 while ( aMinStr.Search( "-" ) != -1 ) aMinStr.RemoveAll( '-' );
3387 while ( aMaxStr.Search( "-" ) != -1 ) aMaxStr.RemoveAll( '-' );
3389 if ( (!aMinStr.IsEmpty() && !aMinStr.IsIntegerValue()) ||
3390 (!aMaxStr.IsEmpty() && !aMaxStr.IsIntegerValue()) )
3393 myMin.Append( aMinStr.IsEmpty() ? IntegerFirst() : aMinStr.IntegerValue() );
3394 myMax.Append( aMaxStr.IsEmpty() ? IntegerLast() : aMaxStr.IntegerValue() );
3401 //=======================================================================
3403 // Purpose : Get type of supported entities
3404 //=======================================================================
3405 SMDSAbs_ElementType RangeOfIds::GetType() const
3410 //=======================================================================
3412 // Purpose : Set type of supported entities
3413 //=======================================================================
3414 void RangeOfIds::SetType( SMDSAbs_ElementType theType )
3419 //=======================================================================
3421 // Purpose : Verify whether entity satisfies to this rpedicate
3422 //=======================================================================
3423 bool RangeOfIds::IsSatisfy( long theId )
3428 if ( myType == SMDSAbs_Node )
3430 if ( myMesh->FindNode( theId ) == 0 )
3435 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
3436 if ( anElem == 0 || (myType != anElem->GetType() && myType != SMDSAbs_All ))
3440 if ( myIds.Contains( theId ) )
3443 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
3444 if ( theId >= myMin( i ) && theId <= myMax( i ) )
3452 Description : Base class for comparators
3454 Comparator::Comparator():
3458 Comparator::~Comparator()
3461 void Comparator::SetMesh( const SMDS_Mesh* theMesh )
3464 myFunctor->SetMesh( theMesh );
3467 void Comparator::SetMargin( double theValue )
3469 myMargin = theValue;
3472 void Comparator::SetNumFunctor( NumericalFunctorPtr theFunct )
3474 myFunctor = theFunct;
3477 SMDSAbs_ElementType Comparator::GetType() const
3479 return myFunctor ? myFunctor->GetType() : SMDSAbs_All;
3482 double Comparator::GetMargin()
3490 Description : Comparator "<"
3492 bool LessThan::IsSatisfy( long theId )
3494 return myFunctor && myFunctor->GetValue( theId ) < myMargin;
3500 Description : Comparator ">"
3502 bool MoreThan::IsSatisfy( long theId )
3504 return myFunctor && myFunctor->GetValue( theId ) > myMargin;
3510 Description : Comparator "="
3513 myToler(Precision::Confusion())
3516 bool EqualTo::IsSatisfy( long theId )
3518 return myFunctor && fabs( myFunctor->GetValue( theId ) - myMargin ) < myToler;
3521 void EqualTo::SetTolerance( double theToler )
3526 double EqualTo::GetTolerance()
3533 Description : Logical NOT predicate
3535 LogicalNOT::LogicalNOT()
3538 LogicalNOT::~LogicalNOT()
3541 bool LogicalNOT::IsSatisfy( long theId )
3543 return myPredicate && !myPredicate->IsSatisfy( theId );
3546 void LogicalNOT::SetMesh( const SMDS_Mesh* theMesh )
3549 myPredicate->SetMesh( theMesh );
3552 void LogicalNOT::SetPredicate( PredicatePtr thePred )
3554 myPredicate = thePred;
3557 SMDSAbs_ElementType LogicalNOT::GetType() const
3559 return myPredicate ? myPredicate->GetType() : SMDSAbs_All;
3564 Class : LogicalBinary
3565 Description : Base class for binary logical predicate
3567 LogicalBinary::LogicalBinary()
3570 LogicalBinary::~LogicalBinary()
3573 void LogicalBinary::SetMesh( const SMDS_Mesh* theMesh )
3576 myPredicate1->SetMesh( theMesh );
3579 myPredicate2->SetMesh( theMesh );
3582 void LogicalBinary::SetPredicate1( PredicatePtr thePredicate )
3584 myPredicate1 = thePredicate;
3587 void LogicalBinary::SetPredicate2( PredicatePtr thePredicate )
3589 myPredicate2 = thePredicate;
3592 SMDSAbs_ElementType LogicalBinary::GetType() const
3594 if ( !myPredicate1 || !myPredicate2 )
3597 SMDSAbs_ElementType aType1 = myPredicate1->GetType();
3598 SMDSAbs_ElementType aType2 = myPredicate2->GetType();
3600 return aType1 == aType2 ? aType1 : SMDSAbs_All;
3606 Description : Logical AND
3608 bool LogicalAND::IsSatisfy( long theId )
3613 myPredicate1->IsSatisfy( theId ) &&
3614 myPredicate2->IsSatisfy( theId );
3620 Description : Logical OR
3622 bool LogicalOR::IsSatisfy( long theId )
3627 (myPredicate1->IsSatisfy( theId ) ||
3628 myPredicate2->IsSatisfy( theId ));
3637 // #include <tbb/parallel_for.h>
3638 // #include <tbb/enumerable_thread_specific.h>
3640 // namespace Parallel
3642 // typedef tbb::enumerable_thread_specific< TIdSequence > TIdSeq;
3646 // const SMDS_Mesh* myMesh;
3647 // PredicatePtr myPredicate;
3648 // TIdSeq & myOKIds;
3649 // Predicate( const SMDS_Mesh* m, PredicatePtr p, TIdSeq & ids ):
3650 // myMesh(m), myPredicate(p->Duplicate()), myOKIds(ids) {}
3651 // void operator() ( const tbb::blocked_range<size_t>& r ) const
3653 // for ( size_t i = r.begin(); i != r.end(); ++i )
3654 // if ( myPredicate->IsSatisfy( i ))
3655 // myOKIds.local().push_back();
3667 void Filter::SetPredicate( PredicatePtr thePredicate )
3669 myPredicate = thePredicate;
3672 void Filter::GetElementsId( const SMDS_Mesh* theMesh,
3673 PredicatePtr thePredicate,
3674 TIdSequence& theSequence,
3675 SMDS_ElemIteratorPtr theElements )
3677 theSequence.clear();
3679 if ( !theMesh || !thePredicate )
3682 thePredicate->SetMesh( theMesh );
3685 theElements = theMesh->elementsIterator( thePredicate->GetType() );
3687 if ( theElements ) {
3688 while ( theElements->more() ) {
3689 const SMDS_MeshElement* anElem = theElements->next();
3690 if ( thePredicate->GetType() == SMDSAbs_All ||
3691 thePredicate->GetType() == anElem->GetType() )
3693 long anId = anElem->GetID();
3694 if ( thePredicate->IsSatisfy( anId ) )
3695 theSequence.push_back( anId );
3701 void Filter::GetElementsId( const SMDS_Mesh* theMesh,
3702 Filter::TIdSequence& theSequence,
3703 SMDS_ElemIteratorPtr theElements )
3705 GetElementsId(theMesh,myPredicate,theSequence,theElements);
3712 typedef std::set<SMDS_MeshFace*> TMapOfFacePtr;
3718 ManifoldPart::Link::Link( SMDS_MeshNode* theNode1,
3719 SMDS_MeshNode* theNode2 )
3725 ManifoldPart::Link::~Link()
3731 bool ManifoldPart::Link::IsEqual( const ManifoldPart::Link& theLink ) const
3733 if ( myNode1 == theLink.myNode1 &&
3734 myNode2 == theLink.myNode2 )
3736 else if ( myNode1 == theLink.myNode2 &&
3737 myNode2 == theLink.myNode1 )
3743 bool ManifoldPart::Link::operator<( const ManifoldPart::Link& x ) const
3745 if(myNode1 < x.myNode1) return true;
3746 if(myNode1 == x.myNode1)
3747 if(myNode2 < x.myNode2) return true;
3751 bool ManifoldPart::IsEqual( const ManifoldPart::Link& theLink1,
3752 const ManifoldPart::Link& theLink2 )
3754 return theLink1.IsEqual( theLink2 );
3757 ManifoldPart::ManifoldPart()
3760 myAngToler = Precision::Angular();
3761 myIsOnlyManifold = true;
3764 ManifoldPart::~ManifoldPart()
3769 void ManifoldPart::SetMesh( const SMDS_Mesh* theMesh )
3775 SMDSAbs_ElementType ManifoldPart::GetType() const
3776 { return SMDSAbs_Face; }
3778 bool ManifoldPart::IsSatisfy( long theElementId )
3780 return myMapIds.Contains( theElementId );
3783 void ManifoldPart::SetAngleTolerance( const double theAngToler )
3784 { myAngToler = theAngToler; }
3786 double ManifoldPart::GetAngleTolerance() const
3787 { return myAngToler; }
3789 void ManifoldPart::SetIsOnlyManifold( const bool theIsOnly )
3790 { myIsOnlyManifold = theIsOnly; }
3792 void ManifoldPart::SetStartElem( const long theStartId )
3793 { myStartElemId = theStartId; }
3795 bool ManifoldPart::process()
3798 myMapBadGeomIds.Clear();
3800 myAllFacePtr.clear();
3801 myAllFacePtrIntDMap.clear();
3805 // collect all faces into own map
3806 SMDS_FaceIteratorPtr anFaceItr = myMesh->facesIterator();
3807 for (; anFaceItr->more(); )
3809 SMDS_MeshFace* aFacePtr = (SMDS_MeshFace*)anFaceItr->next();
3810 myAllFacePtr.push_back( aFacePtr );
3811 myAllFacePtrIntDMap[aFacePtr] = myAllFacePtr.size()-1;
3814 SMDS_MeshFace* aStartFace = (SMDS_MeshFace*)myMesh->FindElement( myStartElemId );
3818 // the map of non manifold links and bad geometry
3819 TMapOfLink aMapOfNonManifold;
3820 TIDsMap aMapOfTreated;
3822 // begin cycle on faces from start index and run on vector till the end
3823 // and from begin to start index to cover whole vector
3824 const int aStartIndx = myAllFacePtrIntDMap[aStartFace];
3825 bool isStartTreat = false;
3826 for ( int fi = aStartIndx; !isStartTreat || fi != aStartIndx ; fi++ )
3828 if ( fi == aStartIndx )
3829 isStartTreat = true;
3830 // as result next time when fi will be equal to aStartIndx
3832 SMDS_MeshFace* aFacePtr = myAllFacePtr[ fi ];
3833 if ( aMapOfTreated.Contains( aFacePtr->GetID()) )
3836 aMapOfTreated.Add( aFacePtr->GetID() );
3838 if ( !findConnected( myAllFacePtrIntDMap, aFacePtr,
3839 aMapOfNonManifold, aResFaces ) )
3841 TIDsMap::Iterator anItr( aResFaces );
3842 for ( ; anItr.More(); anItr.Next() )
3844 smIdType aFaceId = anItr.Key();
3845 aMapOfTreated.Add( aFaceId );
3846 myMapIds.Add( aFaceId );
3849 if ( fi == int( myAllFacePtr.size() - 1 ))
3851 } // end run on vector of faces
3852 return !myMapIds.IsEmpty();
3855 static void getLinks( const SMDS_MeshFace* theFace,
3856 ManifoldPart::TVectorOfLink& theLinks )
3858 int aNbNode = theFace->NbNodes();
3859 SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
3861 SMDS_MeshNode* aNode = 0;
3862 for ( ; aNodeItr->more() && i <= aNbNode; )
3865 SMDS_MeshNode* aN1 = (SMDS_MeshNode*)aNodeItr->next();
3869 SMDS_MeshNode* aN2 = ( i >= aNbNode ) ? aNode : (SMDS_MeshNode*)aNodeItr->next();
3871 ManifoldPart::Link aLink( aN1, aN2 );
3872 theLinks.push_back( aLink );
3876 bool ManifoldPart::findConnected
3877 ( const ManifoldPart::TDataMapFacePtrInt& theAllFacePtrInt,
3878 SMDS_MeshFace* theStartFace,
3879 ManifoldPart::TMapOfLink& theNonManifold,
3880 TIDsMap& theResFaces )
3882 theResFaces.Clear();
3883 if ( !theAllFacePtrInt.size() )
3886 if ( getNormale( theStartFace ).SquareModulus() <= gp::Resolution() )
3888 myMapBadGeomIds.Add( theStartFace->GetID() );
3892 ManifoldPart::TMapOfLink aMapOfBoundary, aMapToSkip;
3893 ManifoldPart::TVectorOfLink aSeqOfBoundary;
3894 theResFaces.Add( theStartFace->GetID() );
3895 ManifoldPart::TDataMapOfLinkFacePtr aDMapLinkFace;
3897 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
3898 aDMapLinkFace, theNonManifold, theStartFace );
3900 bool isDone = false;
3901 while ( !isDone && aMapOfBoundary.size() != 0 )
3903 bool isToReset = false;
3904 ManifoldPart::TVectorOfLink::iterator pLink = aSeqOfBoundary.begin();
3905 for ( ; !isToReset && pLink != aSeqOfBoundary.end(); ++pLink )
3907 ManifoldPart::Link aLink = *pLink;
3908 if ( aMapToSkip.find( aLink ) != aMapToSkip.end() )
3910 // each link could be treated only once
3911 aMapToSkip.insert( aLink );
3913 ManifoldPart::TVectorOfFacePtr aFaces;
3915 if ( myIsOnlyManifold &&
3916 (theNonManifold.find( aLink ) != theNonManifold.end()) )
3920 getFacesByLink( aLink, aFaces );
3921 // filter the element to keep only indicated elements
3922 ManifoldPart::TVectorOfFacePtr aFiltered;
3923 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
3924 for ( ; pFace != aFaces.end(); ++pFace )
3926 SMDS_MeshFace* aFace = *pFace;
3927 if ( myAllFacePtrIntDMap.find( aFace ) != myAllFacePtrIntDMap.end() )
3928 aFiltered.push_back( aFace );
3931 if ( aFaces.size() < 2 ) // no neihgbour faces
3933 else if ( myIsOnlyManifold && aFaces.size() > 2 ) // non manifold case
3935 theNonManifold.insert( aLink );
3940 // compare normal with normals of neighbor element
3941 SMDS_MeshFace* aPrevFace = aDMapLinkFace[ aLink ];
3942 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
3943 for ( ; pFace != aFaces.end(); ++pFace )
3945 SMDS_MeshFace* aNextFace = *pFace;
3946 if ( aPrevFace == aNextFace )
3948 smIdType anNextFaceID = aNextFace->GetID();
3949 if ( myIsOnlyManifold && theResFaces.Contains( anNextFaceID ) )
3950 // should not be with non manifold restriction. probably bad topology
3952 // check if face was treated and skipped
3953 if ( myMapBadGeomIds.Contains( anNextFaceID ) ||
3954 !isInPlane( aPrevFace, aNextFace ) )
3956 // add new element to connected and extend the boundaries.
3957 theResFaces.Add( anNextFaceID );
3958 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
3959 aDMapLinkFace, theNonManifold, aNextFace );
3963 isDone = !isToReset;
3966 return !theResFaces.IsEmpty();
3969 bool ManifoldPart::isInPlane( const SMDS_MeshFace* theFace1,
3970 const SMDS_MeshFace* theFace2 )
3972 gp_Dir aNorm1 = gp_Dir( getNormale( theFace1 ) );
3973 gp_XYZ aNorm2XYZ = getNormale( theFace2 );
3974 if ( aNorm2XYZ.SquareModulus() <= gp::Resolution() )
3976 myMapBadGeomIds.Add( theFace2->GetID() );
3979 if ( aNorm1.IsParallel( gp_Dir( aNorm2XYZ ), myAngToler ) )
3985 void ManifoldPart::expandBoundary
3986 ( ManifoldPart::TMapOfLink& theMapOfBoundary,
3987 ManifoldPart::TVectorOfLink& theSeqOfBoundary,
3988 ManifoldPart::TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
3989 ManifoldPart::TMapOfLink& theNonManifold,
3990 SMDS_MeshFace* theNextFace ) const
3992 ManifoldPart::TVectorOfLink aLinks;
3993 getLinks( theNextFace, aLinks );
3994 int aNbLink = (int)aLinks.size();
3995 for ( int i = 0; i < aNbLink; i++ )
3997 ManifoldPart::Link aLink = aLinks[ i ];
3998 if ( myIsOnlyManifold && (theNonManifold.find( aLink ) != theNonManifold.end()) )
4000 if ( theMapOfBoundary.find( aLink ) != theMapOfBoundary.end() )
4002 if ( myIsOnlyManifold )
4004 // remove from boundary
4005 theMapOfBoundary.erase( aLink );
4006 ManifoldPart::TVectorOfLink::iterator pLink = theSeqOfBoundary.begin();
4007 for ( ; pLink != theSeqOfBoundary.end(); ++pLink )
4009 ManifoldPart::Link aBoundLink = *pLink;
4010 if ( aBoundLink.IsEqual( aLink ) )
4012 theSeqOfBoundary.erase( pLink );
4020 theMapOfBoundary.insert( aLink );
4021 theSeqOfBoundary.push_back( aLink );
4022 theDMapLinkFacePtr[ aLink ] = theNextFace;
4027 void ManifoldPart::getFacesByLink( const ManifoldPart::Link& theLink,
4028 ManifoldPart::TVectorOfFacePtr& theFaces ) const
4031 // take all faces that shared first node
4032 SMDS_ElemIteratorPtr anItr = theLink.myNode1->GetInverseElementIterator( SMDSAbs_Face );
4033 SMDS_StdIterator< const SMDS_MeshElement*, SMDS_ElemIteratorPtr > faces( anItr ), facesEnd;
4034 std::set<const SMDS_MeshElement *> aSetOfFaces( faces, facesEnd );
4036 // take all faces that shared second node
4037 anItr = theLink.myNode2->GetInverseElementIterator( SMDSAbs_Face );
4038 // find the common part of two sets
4039 for ( ; anItr->more(); )
4041 const SMDS_MeshElement* aFace = anItr->next();
4042 if ( aSetOfFaces.count( aFace ))
4043 theFaces.push_back( (SMDS_MeshFace*) aFace );
4048 Class : BelongToMeshGroup
4049 Description : Verify whether a mesh element is included into a mesh group
4051 BelongToMeshGroup::BelongToMeshGroup(): myGroup( 0 )
4055 void BelongToMeshGroup::SetGroup( SMESHDS_GroupBase* g )
4060 void BelongToMeshGroup::SetStoreName( const std::string& sn )
4065 void BelongToMeshGroup::SetMesh( const SMDS_Mesh* theMesh )
4067 if ( myGroup && myGroup->GetMesh() != theMesh )
4071 if ( !myGroup && !myStoreName.empty() )
4073 if ( const SMESHDS_Mesh* aMesh = dynamic_cast<const SMESHDS_Mesh*>(theMesh))
4075 const std::set<SMESHDS_GroupBase*>& grps = aMesh->GetGroups();
4076 std::set<SMESHDS_GroupBase*>::const_iterator g = grps.begin();
4077 for ( ; g != grps.end() && !myGroup; ++g )
4078 if ( *g && myStoreName == (*g)->GetStoreName() )
4084 myGroup->IsEmpty(); // make GroupOnFilter update its predicate
4088 bool BelongToMeshGroup::IsSatisfy( long theElementId )
4090 return myGroup ? myGroup->Contains( theElementId ) : false;
4093 SMDSAbs_ElementType BelongToMeshGroup::GetType() const
4095 return myGroup ? myGroup->GetType() : SMDSAbs_All;
4098 //================================================================================
4099 // ElementsOnSurface
4100 //================================================================================
4102 ElementsOnSurface::ElementsOnSurface()
4105 myType = SMDSAbs_All;
4107 myToler = Precision::Confusion();
4108 myUseBoundaries = false;
4111 ElementsOnSurface::~ElementsOnSurface()
4115 void ElementsOnSurface::SetMesh( const SMDS_Mesh* theMesh )
4117 myMeshModifTracer.SetMesh( theMesh );
4118 if ( myMeshModifTracer.IsMeshModified())
4122 bool ElementsOnSurface::IsSatisfy( long theElementId )
4124 return myIds.Contains( theElementId );
4127 SMDSAbs_ElementType ElementsOnSurface::GetType() const
4130 void ElementsOnSurface::SetTolerance( const double theToler )
4132 if ( myToler != theToler )
4139 double ElementsOnSurface::GetTolerance() const
4142 void ElementsOnSurface::SetUseBoundaries( bool theUse )
4144 if ( myUseBoundaries != theUse ) {
4145 myUseBoundaries = theUse;
4146 SetSurface( mySurf, myType );
4150 void ElementsOnSurface::SetSurface( const TopoDS_Shape& theShape,
4151 const SMDSAbs_ElementType theType )
4156 if ( theShape.IsNull() || theShape.ShapeType() != TopAbs_FACE )
4158 mySurf = TopoDS::Face( theShape );
4159 BRepAdaptor_Surface SA( mySurf, myUseBoundaries );
4161 u1 = SA.FirstUParameter(),
4162 u2 = SA.LastUParameter(),
4163 v1 = SA.FirstVParameter(),
4164 v2 = SA.LastVParameter();
4165 Handle(Geom_Surface) surf = BRep_Tool::Surface( mySurf );
4166 myProjector.Init( surf, u1,u2, v1,v2 );
4170 void ElementsOnSurface::process()
4173 if ( mySurf.IsNull() )
4176 if ( !myMeshModifTracer.GetMesh() )
4179 int nbElems = FromIdType<int>( myMeshModifTracer.GetMesh()->GetMeshInfo().NbElements( myType ));
4181 myIds.ReSize( nbElems );
4183 SMDS_ElemIteratorPtr anIter = myMeshModifTracer.GetMesh()->elementsIterator( myType );
4184 for(; anIter->more(); )
4185 process( anIter->next() );
4188 void ElementsOnSurface::process( const SMDS_MeshElement* theElemPtr )
4190 SMDS_ElemIteratorPtr aNodeItr = theElemPtr->nodesIterator();
4191 bool isSatisfy = true;
4192 for ( ; aNodeItr->more(); )
4194 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
4195 if ( !isOnSurface( aNode ) )
4202 myIds.Add( heElemPtr->GetID() );
4205 bool ElementsOnSurface::isOnSurface( const SMDS_MeshNode* theNode )
4207 if ( mySurf.IsNull() )
4210 gp_Pnt aPnt( theNode->X(), theNode->Y(), theNode->Z() );
4211 // double aToler2 = myToler * myToler;
4212 // if ( mySurf->IsKind(STANDARD_TYPE(Geom_Plane)))
4214 // gp_Pln aPln = Handle(Geom_Plane)::DownCast(mySurf)->Pln();
4215 // if ( aPln.SquareDistance( aPnt ) > aToler2 )
4218 // else if ( mySurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)))
4220 // gp_Cylinder aCyl = Handle(Geom_CylindricalSurface)::DownCast(mySurf)->Cylinder();
4221 // double aRad = aCyl.Radius();
4222 // gp_Ax3 anAxis = aCyl.Position();
4223 // gp_XYZ aLoc = aCyl.Location().XYZ();
4224 // double aXDist = anAxis.XDirection().XYZ() * ( aPnt.XYZ() - aLoc );
4225 // double aYDist = anAxis.YDirection().XYZ() * ( aPnt.XYZ() - aLoc );
4226 // if ( fabs(aXDist*aXDist + aYDist*aYDist - aRad*aRad) > aToler2 )
4231 myProjector.Perform( aPnt );
4232 bool isOn = ( myProjector.IsDone() && myProjector.LowerDistance() <= myToler );
4238 //================================================================================
4240 //================================================================================
4243 const int theIsCheckedFlag = 0x0000100;
4246 struct ElementsOnShape::Classifier
4248 Classifier() { mySolidClfr = 0; myFlags = 0; }
4250 void Init(const TopoDS_Shape& s, double tol, const Bnd_B3d* box = 0 );
4251 bool IsOut(const gp_Pnt& p) { return SetChecked( true ), (this->*myIsOutFun)( p ); }
4252 TopAbs_ShapeEnum ShapeType() const { return myShape.ShapeType(); }
4253 const TopoDS_Shape& Shape() const { return myShape; }
4254 const Bnd_B3d* GetBndBox() const { return & myBox; }
4255 double Tolerance() const { return myTol; }
4256 bool IsChecked() { return myFlags & theIsCheckedFlag; }
4257 bool IsSetFlag( int flag ) const { return myFlags & flag; }
4258 void SetChecked( bool is ) { is ? SetFlag( theIsCheckedFlag ) : UnsetFlag( theIsCheckedFlag ); }
4259 void SetFlag ( int flag ) { myFlags |= flag; }
4260 void UnsetFlag( int flag ) { myFlags &= ~flag; }
4263 bool isOutOfSolid (const gp_Pnt& p);
4264 bool isOutOfBox (const gp_Pnt& p);
4265 bool isOutOfFace (const gp_Pnt& p);
4266 bool isOutOfEdge (const gp_Pnt& p);
4267 bool isOutOfVertex(const gp_Pnt& p);
4268 bool isOutOfNone (const gp_Pnt& /*p*/) { return true; }
4269 bool isBox (const TopoDS_Shape& s);
4271 TopoDS_Shape prepareSolid( const TopoDS_Shape& theSolid );
4273 bool (Classifier::* myIsOutFun)(const gp_Pnt& p);
4274 BRepClass3d_SolidClassifier* mySolidClfr; // ptr because of a run-time forbidden copy-constructor
4276 GeomAPI_ProjectPointOnSurf myProjFace;
4277 GeomAPI_ProjectPointOnCurve myProjEdge;
4279 TopoDS_Shape myShape;
4284 struct ElementsOnShape::OctreeClassifier : public SMESH_Octree
4286 OctreeClassifier( const std::vector< ElementsOnShape::Classifier* >& classifiers );
4287 OctreeClassifier( const OctreeClassifier* otherTree,
4288 const std::vector< ElementsOnShape::Classifier >& clsOther,
4289 std::vector< ElementsOnShape::Classifier >& cls );
4290 void GetClassifiersAtPoint( const gp_XYZ& p,
4291 std::vector< ElementsOnShape::Classifier* >& classifiers );
4295 OctreeClassifier() {}
4296 SMESH_Octree* newChild() const { return new OctreeClassifier; }
4297 void buildChildrenData();
4298 Bnd_B3d* buildRootBox();
4300 std::vector< ElementsOnShape::Classifier* > myClassifiers;
4304 ElementsOnShape::ElementsOnShape():
4306 myType(SMDSAbs_All),
4307 myToler(Precision::Confusion()),
4308 myAllNodesFlag(false)
4312 ElementsOnShape::~ElementsOnShape()
4317 Predicate* ElementsOnShape::clone() const
4319 size_t size = sizeof( *this );
4321 size += myOctree->GetSize();
4322 if ( !myClassifiers.empty() )
4323 size += sizeof( myClassifiers[0] ) * myClassifiers.size();
4324 if ( !myWorkClassifiers.empty() )
4325 size += sizeof( myWorkClassifiers[0] ) * myWorkClassifiers.size();
4326 if ( size > 1e+9 ) // 1G
4329 std::cout << "Avoid ElementsOnShape::clone(), too large: " << size << " bytes " << std::endl;
4334 ElementsOnShape* cln = new ElementsOnShape();
4335 cln->SetAllNodes ( myAllNodesFlag );
4336 cln->SetTolerance( myToler );
4337 cln->SetMesh ( myMeshModifTracer.GetMesh() );
4338 cln->myShape = myShape; // avoid creation of myClassifiers
4339 cln->SetShape ( myShape, myType );
4340 cln->myClassifiers.resize( myClassifiers.size() );
4341 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4342 cln->myClassifiers[ i ].Init( BRepBuilderAPI_Copy( myClassifiers[ i ].Shape()),
4343 myToler, myClassifiers[ i ].GetBndBox() );
4344 if ( myOctree ) // copy myOctree
4346 cln->myOctree = new OctreeClassifier( myOctree, myClassifiers, cln->myClassifiers );
4351 SMDSAbs_ElementType ElementsOnShape::GetType() const
4356 void ElementsOnShape::SetTolerance (const double theToler)
4358 if (myToler != theToler) {
4360 SetShape(myShape, myType);
4364 double ElementsOnShape::GetTolerance() const
4369 void ElementsOnShape::SetAllNodes (bool theAllNodes)
4371 myAllNodesFlag = theAllNodes;
4374 void ElementsOnShape::SetMesh (const SMDS_Mesh* theMesh)
4376 myMeshModifTracer.SetMesh( theMesh );
4377 if ( myMeshModifTracer.IsMeshModified())
4379 size_t nbNodes = theMesh ? theMesh->NbNodes() : 0;
4380 if ( myNodeIsChecked.size() == nbNodes )
4382 std::fill( myNodeIsChecked.begin(), myNodeIsChecked.end(), false );
4386 SMESHUtils::FreeVector( myNodeIsChecked );
4387 SMESHUtils::FreeVector( myNodeIsOut );
4388 myNodeIsChecked.resize( nbNodes, false );
4389 myNodeIsOut.resize( nbNodes );
4394 bool ElementsOnShape::getNodeIsOut( const SMDS_MeshNode* n, bool& isOut )
4396 if ( n->GetID() >= (int) myNodeIsChecked.size() ||
4397 !myNodeIsChecked[ n->GetID() ])
4400 isOut = myNodeIsOut[ n->GetID() ];
4404 void ElementsOnShape::setNodeIsOut( const SMDS_MeshNode* n, bool isOut )
4406 if ( n->GetID() < (int) myNodeIsChecked.size() )
4408 myNodeIsChecked[ n->GetID() ] = true;
4409 myNodeIsOut [ n->GetID() ] = isOut;
4413 void ElementsOnShape::SetShape (const TopoDS_Shape& theShape,
4414 const SMDSAbs_ElementType theType)
4416 bool shapeChanges = ( myShape != theShape );
4419 if ( myShape.IsNull() ) return;
4423 // find most complex shapes
4424 TopTools_IndexedMapOfShape shapesMap;
4425 TopAbs_ShapeEnum shapeTypes[4] = { TopAbs_SOLID, TopAbs_FACE, TopAbs_EDGE, TopAbs_VERTEX };
4426 TopExp_Explorer sub;
4427 for ( int i = 0; i < 4; ++i )
4429 if ( shapesMap.IsEmpty() )
4430 for ( sub.Init( myShape, shapeTypes[i] ); sub.More(); sub.Next() )
4431 shapesMap.Add( sub.Current() );
4433 for ( sub.Init( myShape, shapeTypes[i], shapeTypes[i-1] ); sub.More(); sub.Next() )
4434 shapesMap.Add( sub.Current() );
4438 myClassifiers.resize( shapesMap.Extent() );
4439 for ( int i = 0; i < shapesMap.Extent(); ++i )
4440 myClassifiers[ i ].Init( shapesMap( i+1 ), myToler );
4443 if ( theType == SMDSAbs_Node )
4445 SMESHUtils::FreeVector( myNodeIsChecked );
4446 SMESHUtils::FreeVector( myNodeIsOut );
4450 std::fill( myNodeIsChecked.begin(), myNodeIsChecked.end(), false );
4454 void ElementsOnShape::clearClassifiers()
4456 // for ( size_t i = 0; i < myClassifiers.size(); ++i )
4457 // delete myClassifiers[ i ];
4458 myClassifiers.clear();
4464 bool ElementsOnShape::IsSatisfy( long elemId )
4466 if ( myClassifiers.empty() )
4469 const SMDS_Mesh* mesh = myMeshModifTracer.GetMesh();
4470 if ( myType == SMDSAbs_Node )
4471 return IsSatisfy( mesh->FindNode( elemId ));
4472 return IsSatisfy( mesh->FindElement( elemId ));
4475 bool ElementsOnShape::IsSatisfy (const SMDS_MeshElement* elem)
4480 bool isSatisfy = myAllNodesFlag, isNodeOut;
4482 gp_XYZ centerXYZ (0, 0, 0);
4484 if ( !myOctree && myClassifiers.size() > 5 )
4486 myWorkClassifiers.resize( myClassifiers.size() );
4487 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4488 myWorkClassifiers[ i ] = & myClassifiers[ i ];
4489 myOctree = new OctreeClassifier( myWorkClassifiers );
4491 SMESHUtils::FreeVector( myWorkClassifiers );
4494 for ( int i = 0, nb = elem->NbNodes(); i < nb && (isSatisfy == myAllNodesFlag); ++i )
4496 SMESH_TNodeXYZ aPnt( elem->GetNode( i ));
4500 if ( !getNodeIsOut( aPnt._node, isNodeOut ))
4504 myWorkClassifiers.clear();
4505 myOctree->GetClassifiersAtPoint( aPnt, myWorkClassifiers );
4507 for ( size_t i = 0; i < myWorkClassifiers.size(); ++i )
4508 myWorkClassifiers[i]->SetChecked( false );
4510 for ( size_t i = 0; i < myWorkClassifiers.size() && isNodeOut; ++i )
4511 if ( !myWorkClassifiers[i]->IsChecked() )
4512 isNodeOut = myWorkClassifiers[i]->IsOut( aPnt );
4516 for ( size_t i = 0; i < myClassifiers.size() && isNodeOut; ++i )
4517 isNodeOut = myClassifiers[i].IsOut( aPnt );
4519 setNodeIsOut( aPnt._node, isNodeOut );
4521 isSatisfy = !isNodeOut;
4524 // Check the center point for volumes MantisBug 0020168
4527 myClassifiers[0].ShapeType() == TopAbs_SOLID )
4529 centerXYZ /= elem->NbNodes();
4533 myWorkClassifiers.clear();
4534 myOctree->GetClassifiersAtPoint( centerXYZ, myWorkClassifiers );
4535 for ( size_t i = 0; i < myWorkClassifiers.size() && !isSatisfy; ++i )
4536 isSatisfy = ! myWorkClassifiers[i]->IsOut( centerXYZ );
4540 for ( size_t i = 0; i < myClassifiers.size() && !isSatisfy; ++i )
4541 isSatisfy = ! myClassifiers[i].IsOut( centerXYZ );
4548 //================================================================================
4550 * \brief Check and optionally return a satisfying shape
4552 //================================================================================
4554 bool ElementsOnShape::IsSatisfy (const SMDS_MeshNode* node,
4555 TopoDS_Shape* okShape)
4560 if ( !myOctree && myClassifiers.size() > 5 )
4562 myWorkClassifiers.resize( myClassifiers.size() );
4563 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4564 myWorkClassifiers[ i ] = & myClassifiers[ i ];
4565 myOctree = new OctreeClassifier( myWorkClassifiers );
4568 bool isNodeOut = true;
4570 if ( okShape || !getNodeIsOut( node, isNodeOut ))
4572 SMESH_NodeXYZ aPnt = node;
4575 myWorkClassifiers.clear();
4576 myOctree->GetClassifiersAtPoint( aPnt, myWorkClassifiers );
4578 for ( size_t i = 0; i < myWorkClassifiers.size(); ++i )
4579 myWorkClassifiers[i]->SetChecked( false );
4581 for ( size_t i = 0; i < myWorkClassifiers.size(); ++i )
4582 if ( !myWorkClassifiers[i]->IsChecked() &&
4583 !myWorkClassifiers[i]->IsOut( aPnt ))
4587 *okShape = myWorkClassifiers[i]->Shape();
4593 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4594 if ( !myClassifiers[i].IsOut( aPnt ))
4598 *okShape = myClassifiers[i].Shape();
4602 setNodeIsOut( node, isNodeOut );
4608 void ElementsOnShape::Classifier::Init( const TopoDS_Shape& theShape,
4610 const Bnd_B3d* theBox )
4616 bool isShapeBox = false;
4617 switch ( myShape.ShapeType() )
4621 if (( isShapeBox = isBox( theShape )))
4623 myIsOutFun = & ElementsOnShape::Classifier::isOutOfBox;
4627 mySolidClfr = new BRepClass3d_SolidClassifier( prepareSolid( theShape ));
4628 myIsOutFun = & ElementsOnShape::Classifier::isOutOfSolid;
4634 Standard_Real u1,u2,v1,v2;
4635 Handle(Geom_Surface) surf = BRep_Tool::Surface( TopoDS::Face( theShape ));
4636 if ( surf.IsNull() )
4637 myIsOutFun = & ElementsOnShape::Classifier::isOutOfNone;
4640 surf->Bounds( u1,u2,v1,v2 );
4641 myProjFace.Init(surf, u1,u2, v1,v2, myTol );
4642 myIsOutFun = & ElementsOnShape::Classifier::isOutOfFace;
4648 Standard_Real u1, u2;
4649 Handle(Geom_Curve) curve = BRep_Tool::Curve( TopoDS::Edge( theShape ), u1, u2);
4650 if ( curve.IsNull() )
4651 myIsOutFun = & ElementsOnShape::Classifier::isOutOfNone;
4654 myProjEdge.Init(curve, u1, u2);
4655 myIsOutFun = & ElementsOnShape::Classifier::isOutOfEdge;
4661 myVertexXYZ = BRep_Tool::Pnt( TopoDS::Vertex( theShape ) );
4662 myIsOutFun = & ElementsOnShape::Classifier::isOutOfVertex;
4666 throw SALOME_Exception("Programmer error in usage of ElementsOnShape::Classifier");
4678 if ( myShape.ShapeType() == TopAbs_FACE )
4680 BRepAdaptor_Surface SA( TopoDS::Face( myShape ), /*useBoundaries=*/false );
4681 if ( SA.GetType() == GeomAbs_BSplineSurface )
4682 BRepBndLib::AddOptimal( myShape, box,
4683 /*useTriangulation=*/true, /*useShapeTolerance=*/true );
4686 BRepBndLib::Add( myShape, box );
4688 myBox.Add( box.CornerMin() );
4689 myBox.Add( box.CornerMax() );
4690 gp_XYZ halfSize = 0.5 * ( box.CornerMax().XYZ() - box.CornerMin().XYZ() );
4691 for ( int iDim = 1; iDim <= 3; ++iDim )
4693 double x = halfSize.Coord( iDim );
4694 halfSize.SetCoord( iDim, x + Max( myTol, 1e-2 * x ));
4696 myBox.SetHSize( halfSize );
4701 ElementsOnShape::Classifier::~Classifier()
4703 delete mySolidClfr; mySolidClfr = 0;
4706 TopoDS_Shape ElementsOnShape::Classifier::prepareSolid( const TopoDS_Shape& theSolid )
4708 // try to limit tolerance of theSolid down to myTol (issue #19026)
4710 // check if tolerance of theSolid is more than myTol
4711 bool tolIsOk = true; // max tolerance is at VERTEXes
4712 for ( TopExp_Explorer exp( theSolid, TopAbs_VERTEX ); exp.More() && tolIsOk; exp.Next() )
4713 tolIsOk = ( myTol >= BRep_Tool::Tolerance( TopoDS::Vertex( exp.Current() )));
4717 // make a copy to prevent the original shape from changes
4718 TopoDS_Shape resultShape = BRepBuilderAPI_Copy( theSolid );
4720 if ( !GEOMUtils::FixShapeTolerance( resultShape, TopAbs_SHAPE, myTol ))
4725 bool ElementsOnShape::Classifier::isOutOfSolid( const gp_Pnt& p )
4727 if ( isOutOfBox( p )) return true;
4728 mySolidClfr->Perform( p, myTol );
4729 return ( mySolidClfr->State() != TopAbs_IN && mySolidClfr->State() != TopAbs_ON );
4732 bool ElementsOnShape::Classifier::isOutOfBox( const gp_Pnt& p )
4734 return myBox.IsOut( p.XYZ() );
4737 bool ElementsOnShape::Classifier::isOutOfFace( const gp_Pnt& p )
4739 if ( isOutOfBox( p )) return true;
4740 myProjFace.Perform( p );
4741 if ( myProjFace.IsDone() && myProjFace.LowerDistance() <= myTol )
4743 // check relatively to the face
4745 myProjFace.LowerDistanceParameters(u, v);
4746 gp_Pnt2d aProjPnt (u, v);
4747 BRepClass_FaceClassifier aClsf ( TopoDS::Face( myShape ), aProjPnt, myTol );
4748 if ( aClsf.State() == TopAbs_IN || aClsf.State() == TopAbs_ON )
4754 bool ElementsOnShape::Classifier::isOutOfEdge( const gp_Pnt& p )
4756 if ( isOutOfBox( p )) return true;
4757 myProjEdge.Perform( p );
4758 return ! ( myProjEdge.NbPoints() > 0 && myProjEdge.LowerDistance() <= myTol );
4761 bool ElementsOnShape::Classifier::isOutOfVertex( const gp_Pnt& p )
4763 return ( myVertexXYZ.Distance( p ) > myTol );
4766 bool ElementsOnShape::Classifier::isBox(const TopoDS_Shape& theShape )
4768 TopTools_IndexedMapOfShape vMap;
4769 TopExp::MapShapes( theShape, TopAbs_VERTEX, vMap );
4770 if ( vMap.Extent() != 8 )
4774 for ( int i = 1; i <= 8; ++i )
4775 myBox.Add( BRep_Tool::Pnt( TopoDS::Vertex( vMap( i ))).XYZ() );
4777 gp_XYZ pMin = myBox.CornerMin(), pMax = myBox.CornerMax();
4778 for ( int i = 1; i <= 8; ++i )
4780 gp_Pnt p = BRep_Tool::Pnt( TopoDS::Vertex( vMap( i )));
4781 for ( int iC = 1; iC <= 3; ++ iC )
4783 double d1 = Abs( pMin.Coord( iC ) - p.Coord( iC ));
4784 double d2 = Abs( pMax.Coord( iC ) - p.Coord( iC ));
4785 if ( Min( d1, d2 ) > myTol )
4789 myBox.Enlarge( myTol );
4794 OctreeClassifier::OctreeClassifier( const std::vector< ElementsOnShape::Classifier* >& classifiers )
4795 :SMESH_Octree( new SMESH_TreeLimit )
4797 myClassifiers = classifiers;
4802 OctreeClassifier::OctreeClassifier( const OctreeClassifier* otherTree,
4803 const std::vector< ElementsOnShape::Classifier >& clsOther,
4804 std::vector< ElementsOnShape::Classifier >& cls )
4805 :SMESH_Octree( new SMESH_TreeLimit )
4807 myBox = new Bnd_B3d( *otherTree->getBox() );
4809 if (( myIsLeaf = otherTree->isLeaf() ))
4811 myClassifiers.resize( otherTree->myClassifiers.size() );
4812 for ( size_t i = 0; i < otherTree->myClassifiers.size(); ++i )
4814 int ind = otherTree->myClassifiers[i] - & clsOther[0];
4815 myClassifiers[ i ] = & cls[ ind ];
4818 else if ( otherTree->myChildren )
4820 myChildren = new SMESH_Tree< Bnd_B3d, 8 > * [ 8 ];
4821 for ( int i = 0; i < nbChildren(); i++ )
4823 new OctreeClassifier( static_cast<const OctreeClassifier*>( otherTree->myChildren[i]),
4828 void ElementsOnShape::
4829 OctreeClassifier::GetClassifiersAtPoint( const gp_XYZ& point,
4830 std::vector< ElementsOnShape::Classifier* >& result )
4832 if ( getBox()->IsOut( point ))
4837 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4838 if ( !myClassifiers[i]->GetBndBox()->IsOut( point ))
4839 result.push_back( myClassifiers[i] );
4843 for (int i = 0; i < nbChildren(); i++)
4844 ((OctreeClassifier*) myChildren[i])->GetClassifiersAtPoint( point, result );
4848 size_t ElementsOnShape::OctreeClassifier::GetSize()
4850 size_t res = sizeof( *this );
4851 if ( !myClassifiers.empty() )
4852 res += sizeof( myClassifiers[0] ) * myClassifiers.size();
4855 for (int i = 0; i < nbChildren(); i++)
4856 res += ((OctreeClassifier*) myChildren[i])->GetSize();
4861 void ElementsOnShape::OctreeClassifier::buildChildrenData()
4863 // distribute myClassifiers among myChildren
4865 const int childFlag[8] = { 0x0000001,
4873 int nbInChild[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
4875 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4877 for ( int j = 0; j < nbChildren(); j++ )
4879 if ( !myClassifiers[i]->GetBndBox()->IsOut( *myChildren[j]->getBox() ))
4881 myClassifiers[i]->SetFlag( childFlag[ j ]);
4887 for ( int j = 0; j < nbChildren(); j++ )
4889 OctreeClassifier* child = static_cast<OctreeClassifier*>( myChildren[ j ]);
4890 child->myClassifiers.resize( nbInChild[ j ]);
4891 for ( size_t i = 0; nbInChild[ j ] && i < myClassifiers.size(); ++i )
4893 if ( myClassifiers[ i ]->IsSetFlag( childFlag[ j ]))
4896 child->myClassifiers[ nbInChild[ j ]] = myClassifiers[ i ];
4897 myClassifiers[ i ]->UnsetFlag( childFlag[ j ]);
4901 SMESHUtils::FreeVector( myClassifiers );
4903 // define if a child isLeaf()
4904 for ( int i = 0; i < nbChildren(); i++ )
4906 OctreeClassifier* child = static_cast<OctreeClassifier*>( myChildren[ i ]);
4907 child->myIsLeaf = ( child->myClassifiers.size() <= 5 ||
4908 child->maxSize() < child->myClassifiers[0]->Tolerance() );
4912 Bnd_B3d* ElementsOnShape::OctreeClassifier::buildRootBox()
4914 Bnd_B3d* box = new Bnd_B3d;
4915 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4916 box->Add( *myClassifiers[i]->GetBndBox() );
4921 Class : BelongToGeom
4922 Description : Predicate for verifying whether entity belongs to
4923 specified geometrical support
4926 BelongToGeom::BelongToGeom()
4928 myType(SMDSAbs_NbElementTypes),
4929 myIsSubshape(false),
4930 myTolerance(Precision::Confusion())
4933 Predicate* BelongToGeom::clone() const
4935 BelongToGeom* cln = 0;
4936 if ( myElementsOnShapePtr )
4937 if ( ElementsOnShape* eos = static_cast<ElementsOnShape*>( myElementsOnShapePtr->clone() ))
4939 cln = new BelongToGeom( *this );
4940 cln->myElementsOnShapePtr.reset( eos );
4945 void BelongToGeom::SetMesh( const SMDS_Mesh* theMesh )
4947 if ( myMeshDS != theMesh )
4949 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
4952 if ( myElementsOnShapePtr )
4953 myElementsOnShapePtr->SetMesh( myMeshDS );
4956 void BelongToGeom::SetGeom( const TopoDS_Shape& theShape )
4958 if ( myShape != theShape )
4965 static bool IsSubShape (const TopTools_IndexedMapOfShape& theMap,
4966 const TopoDS_Shape& theShape)
4968 if (theMap.Contains(theShape)) return true;
4970 if (theShape.ShapeType() == TopAbs_COMPOUND ||
4971 theShape.ShapeType() == TopAbs_COMPSOLID)
4973 TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
4974 for (; anIt.More(); anIt.Next())
4976 if (!IsSubShape(theMap, anIt.Value())) {
4986 void BelongToGeom::init()
4988 if ( !myMeshDS || myShape.IsNull() ) return;
4990 // is sub-shape of main shape?
4991 TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
4992 if (aMainShape.IsNull()) {
4993 myIsSubshape = false;
4996 TopTools_IndexedMapOfShape aMap;
4997 TopExp::MapShapes( aMainShape, aMap );
4998 myIsSubshape = IsSubShape( aMap, myShape );
5002 TopExp::MapShapes( myShape, aMap );
5003 mySubShapesIDs.Clear();
5004 for ( int i = 1; i <= aMap.Extent(); ++i )
5006 int subID = myMeshDS->ShapeToIndex( aMap( i ));
5008 mySubShapesIDs.Add( subID );
5013 //if (!myIsSubshape) // to be always ready to check an element not bound to geometry
5015 if ( !myElementsOnShapePtr )
5016 myElementsOnShapePtr.reset( new ElementsOnShape() );
5017 myElementsOnShapePtr->SetTolerance( myTolerance );
5018 myElementsOnShapePtr->SetAllNodes( true ); // "belong", while false means "lays on"
5019 myElementsOnShapePtr->SetMesh( myMeshDS );
5020 myElementsOnShapePtr->SetShape( myShape, myType );
5024 bool BelongToGeom::IsSatisfy (long theId)
5026 if (myMeshDS == 0 || myShape.IsNull())
5031 return myElementsOnShapePtr->IsSatisfy(theId);
5036 if (myType == SMDSAbs_Node)
5038 if ( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ))
5040 if ( aNode->getshapeId() < 1 )
5041 return myElementsOnShapePtr->IsSatisfy(theId);
5043 return mySubShapesIDs.Contains( aNode->getshapeId() );
5048 if ( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ))
5050 if ( myType == SMDSAbs_All || anElem->GetType() == myType )
5052 if ( anElem->getshapeId() < 1 )
5053 return myElementsOnShapePtr->IsSatisfy(theId);
5055 return mySubShapesIDs.Contains( anElem->getshapeId() );
5063 void BelongToGeom::SetType (SMDSAbs_ElementType theType)
5065 if ( myType != theType )
5072 SMDSAbs_ElementType BelongToGeom::GetType() const
5077 TopoDS_Shape BelongToGeom::GetShape()
5082 const SMESHDS_Mesh* BelongToGeom::GetMeshDS() const
5087 void BelongToGeom::SetTolerance (double theTolerance)
5089 myTolerance = theTolerance;
5093 double BelongToGeom::GetTolerance()
5100 Description : Predicate for verifying whether entiy lying or partially lying on
5101 specified geometrical support
5104 LyingOnGeom::LyingOnGeom()
5106 myType(SMDSAbs_NbElementTypes),
5107 myIsSubshape(false),
5108 myTolerance(Precision::Confusion())
5111 Predicate* LyingOnGeom::clone() const
5113 LyingOnGeom* cln = 0;
5114 if ( myElementsOnShapePtr )
5115 if ( ElementsOnShape* eos = static_cast<ElementsOnShape*>( myElementsOnShapePtr->clone() ))
5117 cln = new LyingOnGeom( *this );
5118 cln->myElementsOnShapePtr.reset( eos );
5123 void LyingOnGeom::SetMesh( const SMDS_Mesh* theMesh )
5125 if ( myMeshDS != theMesh )
5127 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
5130 if ( myElementsOnShapePtr )
5131 myElementsOnShapePtr->SetMesh( myMeshDS );
5134 void LyingOnGeom::SetGeom( const TopoDS_Shape& theShape )
5136 if ( myShape != theShape )
5143 void LyingOnGeom::init()
5145 if (!myMeshDS || myShape.IsNull()) return;
5147 // is sub-shape of main shape?
5148 TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
5149 if (aMainShape.IsNull()) {
5150 myIsSubshape = false;
5153 myIsSubshape = myMeshDS->IsGroupOfSubShapes( myShape );
5158 TopTools_IndexedMapOfShape shapes;
5159 TopExp::MapShapes( myShape, shapes );
5160 mySubShapesIDs.Clear();
5161 for ( int i = 1; i <= shapes.Extent(); ++i )
5163 int subID = myMeshDS->ShapeToIndex( shapes( i ));
5165 mySubShapesIDs.Add( subID );
5168 // else // to be always ready to check an element not bound to geometry
5170 if ( !myElementsOnShapePtr )
5171 myElementsOnShapePtr.reset( new ElementsOnShape() );
5172 myElementsOnShapePtr->SetTolerance( myTolerance );
5173 myElementsOnShapePtr->SetAllNodes( false ); // lays on, while true means "belong"
5174 myElementsOnShapePtr->SetMesh( myMeshDS );
5175 myElementsOnShapePtr->SetShape( myShape, myType );
5179 bool LyingOnGeom::IsSatisfy( long theId )
5181 if ( myMeshDS == 0 || myShape.IsNull() )
5186 return myElementsOnShapePtr->IsSatisfy(theId);
5191 const SMDS_MeshElement* elem =
5192 ( myType == SMDSAbs_Node ) ? myMeshDS->FindNode( theId ) : myMeshDS->FindElement( theId );
5194 if ( mySubShapesIDs.Contains( elem->getshapeId() ))
5197 if (( elem->GetType() != SMDSAbs_Node ) &&
5198 ( myType == SMDSAbs_All || elem->GetType() == myType ))
5200 SMDS_ElemIteratorPtr nodeItr = elem->nodesIterator();
5201 while ( nodeItr->more() )
5203 const SMDS_MeshElement* aNode = nodeItr->next();
5204 if ( mySubShapesIDs.Contains( aNode->getshapeId() ))
5212 void LyingOnGeom::SetType( SMDSAbs_ElementType theType )
5214 if ( myType != theType )
5221 SMDSAbs_ElementType LyingOnGeom::GetType() const
5226 TopoDS_Shape LyingOnGeom::GetShape()
5231 const SMESHDS_Mesh* LyingOnGeom::GetMeshDS() const
5236 void LyingOnGeom::SetTolerance (double theTolerance)
5238 myTolerance = theTolerance;
5242 double LyingOnGeom::GetTolerance()
5247 TSequenceOfXYZ::TSequenceOfXYZ(): myElem(0)
5250 TSequenceOfXYZ::TSequenceOfXYZ(size_type n) : myArray(n), myElem(0)
5253 TSequenceOfXYZ::TSequenceOfXYZ(size_type n, const gp_XYZ& t) : myArray(n,t), myElem(0)
5256 TSequenceOfXYZ::TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ) : myArray(theSequenceOfXYZ.myArray), myElem(theSequenceOfXYZ.myElem)
5259 template <class InputIterator>
5260 TSequenceOfXYZ::TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd): myArray(theBegin,theEnd), myElem(0)
5263 TSequenceOfXYZ::~TSequenceOfXYZ()
5266 TSequenceOfXYZ& TSequenceOfXYZ::operator=(const TSequenceOfXYZ& theSequenceOfXYZ)
5268 myArray = theSequenceOfXYZ.myArray;
5269 myElem = theSequenceOfXYZ.myElem;
5273 gp_XYZ& TSequenceOfXYZ::operator()(size_type n)
5275 return myArray[n-1];
5278 const gp_XYZ& TSequenceOfXYZ::operator()(size_type n) const
5280 return myArray[n-1];
5283 void TSequenceOfXYZ::clear()
5288 void TSequenceOfXYZ::reserve(size_type n)
5293 void TSequenceOfXYZ::push_back(const gp_XYZ& v)
5295 myArray.push_back(v);
5298 TSequenceOfXYZ::size_type TSequenceOfXYZ::size() const
5300 return myArray.size();
5303 SMDSAbs_EntityType TSequenceOfXYZ::getElementEntity() const
5305 return myElem ? myElem->GetEntityType() : SMDSEntity_Last;
5308 TMeshModifTracer::TMeshModifTracer():
5309 myMeshModifTime(0), myMesh(0)
5312 void TMeshModifTracer::SetMesh( const SMDS_Mesh* theMesh )
5314 if ( theMesh != myMesh )
5315 myMeshModifTime = 0;
5318 bool TMeshModifTracer::IsMeshModified()
5320 bool modified = false;
5323 modified = ( myMeshModifTime != myMesh->GetMTime() );
5324 myMeshModifTime = myMesh->GetMTime();