1 // Copyright (C) 2007-2021 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 int 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 int 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<int>& 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<int>::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]);
1000 //================================================================================
1002 * \brief Standard quality of a tetrahedron but not normalized
1004 //================================================================================
1006 double tetQualityByHomardMethod( const gp_XYZ & p1,
1012 edgeVec[0] = ( p1 - p2 );
1013 edgeVec[1] = ( p2 - p3 );
1014 edgeVec[2] = ( p3 - p1 );
1015 edgeVec[3] = ( p4 - p1 );
1016 edgeVec[4] = ( p4 - p2 );
1017 edgeVec[5] = ( p4 - p3 );
1019 double maxEdgeLen2 = edgeVec[0].SquareModulus();
1020 maxEdgeLen2 = Max( maxEdgeLen2, edgeVec[1].SquareModulus() );
1021 maxEdgeLen2 = Max( maxEdgeLen2, edgeVec[2].SquareModulus() );
1022 maxEdgeLen2 = Max( maxEdgeLen2, edgeVec[3].SquareModulus() );
1023 maxEdgeLen2 = Max( maxEdgeLen2, edgeVec[4].SquareModulus() );
1024 maxEdgeLen2 = Max( maxEdgeLen2, edgeVec[5].SquareModulus() );
1025 double maxEdgeLen = Sqrt( maxEdgeLen2 );
1027 gp_XYZ cross01 = edgeVec[0] ^ edgeVec[1];
1028 double sumArea = ( cross01 ).Modulus(); // actually double area
1029 sumArea += ( edgeVec[0] ^ edgeVec[3] ).Modulus();
1030 sumArea += ( edgeVec[1] ^ edgeVec[4] ).Modulus();
1031 sumArea += ( edgeVec[2] ^ edgeVec[5] ).Modulus();
1033 double sixVolume = Abs( cross01 * edgeVec[4] ); // 6 * volume
1034 double quality = maxEdgeLen * sumArea / sixVolume; // not normalized!!!
1038 //================================================================================
1040 * \brief HOMARD method of hexahedron quality
1041 * 1. Decompose the hexa into 24 tetra: each face is splitted into 4 triangles by
1042 * adding the diagonals and every triangle is connected to the center of the hexa.
1043 * 2. Compute the quality of every tetra with the same formula as for the standard quality,
1044 * except that the factor for the normalization is not the same because the final goal
1045 * is to have a quality equal to 1 for a perfect cube. So the formula is:
1046 * qual = max(lengthes of 6 edges) * (sum of surfaces of 4 faces) / (7.6569*6*volume)
1047 * 3. The quality of the hexa is the highest value of the qualities of the 24 tetra
1049 //================================================================================
1051 double hexQualityByHomardMethod( const TSequenceOfXYZ& P )
1053 gp_XYZ quadCenter[6];
1054 quadCenter[0] = ( P(1) + P(2) + P(3) + P(4) ) / 4.;
1055 quadCenter[1] = ( P(5) + P(6) + P(7) + P(8) ) / 4.;
1056 quadCenter[2] = ( P(1) + P(2) + P(6) + P(5) ) / 4.;
1057 quadCenter[3] = ( P(2) + P(3) + P(7) + P(6) ) / 4.;
1058 quadCenter[4] = ( P(3) + P(4) + P(8) + P(7) ) / 4.;
1059 quadCenter[5] = ( P(1) + P(4) + P(8) + P(5) ) / 4.;
1061 gp_XYZ hexCenter = ( P(1) + P(2) + P(3) + P(4) + P(5) + P(6) + P(7) + P(8) ) / 8.;
1063 // quad 1 ( 1 2 3 4 )
1064 double quality = tetQualityByHomardMethod( P(1), P(2), quadCenter[0], hexCenter );
1065 quality = Max( quality, tetQualityByHomardMethod( P(2), P(3), quadCenter[0], hexCenter ));
1066 quality = Max( quality, tetQualityByHomardMethod( P(3), P(4), quadCenter[0], hexCenter ));
1067 quality = Max( quality, tetQualityByHomardMethod( P(4), P(1), quadCenter[0], hexCenter ));
1068 // quad 2 ( 5 6 7 8 )
1069 quality = Max( quality, tetQualityByHomardMethod( P(5), P(6), quadCenter[1], hexCenter ));
1070 quality = Max( quality, tetQualityByHomardMethod( P(6), P(7), quadCenter[1], hexCenter ));
1071 quality = Max( quality, tetQualityByHomardMethod( P(7), P(8), quadCenter[1], hexCenter ));
1072 quality = Max( quality, tetQualityByHomardMethod( P(8), P(5), quadCenter[1], hexCenter ));
1073 // quad 3 ( 1 2 6 5 )
1074 quality = Max( quality, tetQualityByHomardMethod( P(1), P(2), quadCenter[2], hexCenter ));
1075 quality = Max( quality, tetQualityByHomardMethod( P(2), P(6), quadCenter[2], hexCenter ));
1076 quality = Max( quality, tetQualityByHomardMethod( P(6), P(5), quadCenter[2], hexCenter ));
1077 quality = Max( quality, tetQualityByHomardMethod( P(5), P(1), quadCenter[2], hexCenter ));
1078 // quad 4 ( 2 3 7 6 )
1079 quality = Max( quality, tetQualityByHomardMethod( P(2), P(3), quadCenter[3], hexCenter ));
1080 quality = Max( quality, tetQualityByHomardMethod( P(3), P(7), quadCenter[3], hexCenter ));
1081 quality = Max( quality, tetQualityByHomardMethod( P(7), P(6), quadCenter[3], hexCenter ));
1082 quality = Max( quality, tetQualityByHomardMethod( P(6), P(2), quadCenter[3], hexCenter ));
1083 // quad 5 ( 3 4 8 7 )
1084 quality = Max( quality, tetQualityByHomardMethod( P(3), P(4), quadCenter[4], hexCenter ));
1085 quality = Max( quality, tetQualityByHomardMethod( P(4), P(8), quadCenter[4], hexCenter ));
1086 quality = Max( quality, tetQualityByHomardMethod( P(8), P(7), quadCenter[4], hexCenter ));
1087 quality = Max( quality, tetQualityByHomardMethod( P(7), P(3), quadCenter[4], hexCenter ));
1088 // quad 6 ( 1 4 8 5 )
1089 quality = Max( quality, tetQualityByHomardMethod( P(1), P(4), quadCenter[5], hexCenter ));
1090 quality = Max( quality, tetQualityByHomardMethod( P(4), P(8), quadCenter[5], hexCenter ));
1091 quality = Max( quality, tetQualityByHomardMethod( P(8), P(5), quadCenter[5], hexCenter ));
1092 quality = Max( quality, tetQualityByHomardMethod( P(5), P(1), quadCenter[5], hexCenter ));
1094 return quality / 7.65685424949;
1098 double AspectRatio3D::GetValue( long theId )
1101 myCurrElement = myMesh->FindElement( theId );
1102 if ( myCurrElement && myCurrElement->GetVtkType() == VTK_TETRA )
1104 // Action from CoTech | ACTION 31.3:
1105 // EURIWARE BO: Homogenize the formulas used to calculate the Controls in SMESH to fit with
1106 // those of ParaView. The library used by ParaView for those calculations can be reused in SMESH.
1107 vtkUnstructuredGrid* grid = const_cast<SMDS_Mesh*>( myMesh )->GetGrid();
1108 if ( vtkCell* avtkCell = grid->GetCell( myCurrElement->GetVtkID() ))
1109 aVal = Round( vtkMeshQuality::TetAspectRatio( avtkCell ));
1114 if ( GetPoints( myCurrElement, P ))
1115 aVal = Round( GetValue( P ));
1120 bool AspectRatio3D::IsApplicable( const SMDS_MeshElement* element ) const
1122 return ( NumericalFunctor::IsApplicable( element ) && !element->IsPoly() );
1125 double AspectRatio3D::GetValue( const TSequenceOfXYZ& P )
1127 double aQuality = 0.0;
1128 if(myCurrElement->IsPoly()) return aQuality;
1130 int nbNodes = P.size();
1132 if( myCurrElement->IsQuadratic() ) {
1133 if (nbNodes==10) nbNodes=4; // quadratic tetrahedron
1134 else if(nbNodes==13) nbNodes=5; // quadratic pyramid
1135 else if(nbNodes==15) nbNodes=6; // quadratic pentahedron
1136 else if(nbNodes==20) nbNodes=8; // quadratic hexahedron
1137 else if(nbNodes==27) nbNodes=8; // tri-quadratic hexahedron
1138 else return aQuality;
1144 getDistance(P( 1 ),P( 2 )), // a
1145 getDistance(P( 2 ),P( 3 )), // b
1146 getDistance(P( 3 ),P( 1 )), // c
1147 getDistance(P( 2 ),P( 4 )), // d
1148 getDistance(P( 3 ),P( 4 )), // e
1149 getDistance(P( 1 ),P( 4 )) // f
1151 double aTria[4][3] = {
1152 {aLen[0],aLen[1],aLen[2]}, // abc
1153 {aLen[0],aLen[3],aLen[5]}, // adf
1154 {aLen[1],aLen[3],aLen[4]}, // bde
1155 {aLen[2],aLen[4],aLen[5]} // cef
1157 double aSumArea = 0.0;
1158 double aHalfPerimeter = getHalfPerimeter(aTria[0]);
1159 double anArea = getArea(aHalfPerimeter,aTria[0]);
1161 aHalfPerimeter = getHalfPerimeter(aTria[1]);
1162 anArea = getArea(aHalfPerimeter,aTria[1]);
1164 aHalfPerimeter = getHalfPerimeter(aTria[2]);
1165 anArea = getArea(aHalfPerimeter,aTria[2]);
1167 aHalfPerimeter = getHalfPerimeter(aTria[3]);
1168 anArea = getArea(aHalfPerimeter,aTria[3]);
1170 double aVolume = getVolume(P);
1171 //double aVolume = getVolume(aLen);
1172 double aHeight = getMaxHeight(aLen);
1173 static double aCoeff = sqrt(2.0)/12.0;
1174 if ( aVolume > DBL_MIN )
1175 aQuality = aCoeff*aHeight*aSumArea/aVolume;
1180 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 3 ),P( 5 )};
1181 aQuality = GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4]));
1184 gp_XYZ aXYZ[4] = {P( 1 ),P( 3 ),P( 4 ),P( 5 )};
1185 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1188 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 5 )};
1189 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1192 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 4 ),P( 5 )};
1193 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1199 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 6 )};
1200 aQuality = GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4]));
1203 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 3 )};
1204 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1207 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 6 )};
1208 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1211 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
1212 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1215 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 6 )};
1216 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1219 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 3 )};
1220 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1226 return hexQualityByHomardMethod( P ); // bos #23982
1230 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
1231 aQuality = GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4]));
1234 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 4 )};
1235 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1238 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 7 )};
1239 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1242 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 8 )};
1243 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1246 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 3 )};
1247 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1250 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 4 )};
1251 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1254 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 7 )};
1255 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1258 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 8 )};
1259 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1262 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 3 )};
1263 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1266 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 4 )};
1267 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1270 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 7 )};
1271 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1274 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 8 )};
1275 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1278 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 1 )};
1279 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1282 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 2 )};
1283 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1286 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 5 )};
1287 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1290 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 6 )};
1291 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1294 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 1 )};
1295 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1298 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 2 )};
1299 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1302 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 5 )};
1303 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1306 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 6 )};
1307 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1310 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 1 )};
1311 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1314 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
1315 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1318 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 5 )};
1319 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1322 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 6 )};
1323 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1326 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
1327 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1330 gp_XYZ aXYZ[4] = {P( 4 ),P( 5 ),P( 8 ),P( 2 )};
1331 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1334 gp_XYZ aXYZ[4] = {P( 1 ),P( 4 ),P( 5 ),P( 3 )};
1335 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1338 gp_XYZ aXYZ[4] = {P( 3 ),P( 6 ),P( 7 ),P( 1 )};
1339 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1342 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 6 ),P( 4 )};
1343 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1346 gp_XYZ aXYZ[4] = {P( 5 ),P( 6 ),P( 8 ),P( 3 )};
1347 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1350 gp_XYZ aXYZ[4] = {P( 7 ),P( 8 ),P( 6 ),P( 1 )};
1351 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1354 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 7 )};
1355 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1358 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 2 ),P( 5 )};
1359 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1365 gp_XYZ aXYZ[8] = {P( 1 ),P( 2 ),P( 4 ),P( 5 ),P( 7 ),P( 8 ),P( 10 ),P( 11 )};
1366 aQuality = GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[8]));
1369 gp_XYZ aXYZ[8] = {P( 2 ),P( 3 ),P( 5 ),P( 6 ),P( 8 ),P( 9 ),P( 11 ),P( 12 )};
1370 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[8])),aQuality);
1373 gp_XYZ aXYZ[8] = {P( 3 ),P( 4 ),P( 6 ),P( 1 ),P( 9 ),P( 10 ),P( 12 ),P( 7 )};
1374 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[8])),aQuality);
1377 } // switch(nbNodes)
1379 if ( nbNodes > 4 ) {
1380 // evaluate aspect ratio of quadrangle faces
1381 AspectRatio aspect2D;
1382 SMDS_VolumeTool::VolumeType type = SMDS_VolumeTool::GetType( nbNodes );
1383 int nbFaces = SMDS_VolumeTool::NbFaces( type );
1384 TSequenceOfXYZ points(4);
1385 for ( int i = 0; i < nbFaces; ++i ) { // loop on faces of a volume
1386 if ( SMDS_VolumeTool::NbFaceNodes( type, i ) != 4 )
1388 const int* pInd = SMDS_VolumeTool::GetFaceNodesIndices( type, i, true );
1389 for ( int p = 0; p < 4; ++p ) // loop on nodes of a quadrangle face
1390 points( p + 1 ) = P( pInd[ p ] + 1 );
1391 aQuality = std::max( aQuality, aspect2D.GetValue( points ));
1397 double AspectRatio3D::GetBadRate( double Value, int /*nbNodes*/ ) const
1399 // the aspect ratio is in the range [1.0,infinity]
1402 return Value / 1000.;
1405 SMDSAbs_ElementType AspectRatio3D::GetType() const
1407 return SMDSAbs_Volume;
1411 //================================================================================
1414 Description : Functor for calculating warping
1416 //================================================================================
1418 bool Warping::IsApplicable( const SMDS_MeshElement* element ) const
1420 return NumericalFunctor::IsApplicable( element ) && element->NbNodes() == 4;
1423 double Warping::GetValue( const TSequenceOfXYZ& P )
1425 if ( P.size() != 4 )
1428 gp_XYZ G = ( P( 1 ) + P( 2 ) + P( 3 ) + P( 4 ) ) / 4.;
1430 double A1 = ComputeA( P( 1 ), P( 2 ), P( 3 ), G );
1431 double A2 = ComputeA( P( 2 ), P( 3 ), P( 4 ), G );
1432 double A3 = ComputeA( P( 3 ), P( 4 ), P( 1 ), G );
1433 double A4 = ComputeA( P( 4 ), P( 1 ), P( 2 ), G );
1435 double val = Max( Max( A1, A2 ), Max( A3, A4 ) );
1437 const double eps = 0.1; // val is in degrees
1439 return val < eps ? 0. : val;
1442 double Warping::ComputeA( const gp_XYZ& thePnt1,
1443 const gp_XYZ& thePnt2,
1444 const gp_XYZ& thePnt3,
1445 const gp_XYZ& theG ) const
1447 double aLen1 = gp_Pnt( thePnt1 ).Distance( gp_Pnt( thePnt2 ) );
1448 double aLen2 = gp_Pnt( thePnt2 ).Distance( gp_Pnt( thePnt3 ) );
1449 double L = Min( aLen1, aLen2 ) * 0.5;
1453 gp_XYZ GI = ( thePnt2 + thePnt1 ) / 2. - theG;
1454 gp_XYZ GJ = ( thePnt3 + thePnt2 ) / 2. - theG;
1455 gp_XYZ N = GI.Crossed( GJ );
1457 if ( N.Modulus() < gp::Resolution() )
1462 double H = ( thePnt2 - theG ).Dot( N );
1463 return asin( fabs( H / L ) ) * 180. / M_PI;
1466 double Warping::GetBadRate( double Value, int /*nbNodes*/ ) const
1468 // the warp is in the range [0.0,PI/2]
1469 // 0.0 = good (no warp)
1470 // PI/2 = bad (face pliee)
1474 SMDSAbs_ElementType Warping::GetType() const
1476 return SMDSAbs_Face;
1480 //================================================================================
1483 Description : Functor for calculating taper
1485 //================================================================================
1487 bool Taper::IsApplicable( const SMDS_MeshElement* element ) const
1489 return ( NumericalFunctor::IsApplicable( element ) && element->NbNodes() == 4 );
1492 double Taper::GetValue( const TSequenceOfXYZ& P )
1494 if ( P.size() != 4 )
1498 double J1 = getArea( P( 4 ), P( 1 ), P( 2 ) );
1499 double J2 = getArea( P( 3 ), P( 1 ), P( 2 ) );
1500 double J3 = getArea( P( 2 ), P( 3 ), P( 4 ) );
1501 double J4 = getArea( P( 3 ), P( 4 ), P( 1 ) );
1503 double JA = 0.25 * ( J1 + J2 + J3 + J4 );
1507 double T1 = fabs( ( J1 - JA ) / JA );
1508 double T2 = fabs( ( J2 - JA ) / JA );
1509 double T3 = fabs( ( J3 - JA ) / JA );
1510 double T4 = fabs( ( J4 - JA ) / JA );
1512 double val = Max( Max( T1, T2 ), Max( T3, T4 ) );
1514 const double eps = 0.01;
1516 return val < eps ? 0. : val;
1519 double Taper::GetBadRate( double Value, int /*nbNodes*/ ) const
1521 // the taper is in the range [0.0,1.0]
1522 // 0.0 = good (no taper)
1523 // 1.0 = bad (les cotes opposes sont allignes)
1527 SMDSAbs_ElementType Taper::GetType() const
1529 return SMDSAbs_Face;
1532 //================================================================================
1535 Description : Functor for calculating skew in degrees
1537 //================================================================================
1539 static inline double skewAngle( const gp_XYZ& p1, const gp_XYZ& p2, const gp_XYZ& p3 )
1541 gp_XYZ p12 = ( p2 + p1 ) / 2.;
1542 gp_XYZ p23 = ( p3 + p2 ) / 2.;
1543 gp_XYZ p31 = ( p3 + p1 ) / 2.;
1545 gp_Vec v1( p31 - p2 ), v2( p12 - p23 );
1547 return v1.Magnitude() < gp::Resolution() || v2.Magnitude() < gp::Resolution() ? 0. : v1.Angle( v2 );
1550 bool Skew::IsApplicable( const SMDS_MeshElement* element ) const
1552 return ( NumericalFunctor::IsApplicable( element ) && element->NbNodes() <= 4 );
1555 double Skew::GetValue( const TSequenceOfXYZ& P )
1557 if ( P.size() != 3 && P.size() != 4 )
1561 const double PI2 = M_PI / 2.;
1562 if ( P.size() == 3 )
1564 double A0 = fabs( PI2 - skewAngle( P( 3 ), P( 1 ), P( 2 ) ) );
1565 double A1 = fabs( PI2 - skewAngle( P( 1 ), P( 2 ), P( 3 ) ) );
1566 double A2 = fabs( PI2 - skewAngle( P( 2 ), P( 3 ), P( 1 ) ) );
1568 return Max( A0, Max( A1, A2 ) ) * 180. / M_PI;
1572 gp_XYZ p12 = ( P( 1 ) + P( 2 ) ) / 2.;
1573 gp_XYZ p23 = ( P( 2 ) + P( 3 ) ) / 2.;
1574 gp_XYZ p34 = ( P( 3 ) + P( 4 ) ) / 2.;
1575 gp_XYZ p41 = ( P( 4 ) + P( 1 ) ) / 2.;
1577 gp_Vec v1( p34 - p12 ), v2( p23 - p41 );
1578 double A = v1.Magnitude() <= gp::Resolution() || v2.Magnitude() <= gp::Resolution()
1579 ? 0. : fabs( PI2 - v1.Angle( v2 ) );
1581 double val = A * 180. / M_PI;
1583 const double eps = 0.1; // val is in degrees
1585 return val < eps ? 0. : val;
1589 double Skew::GetBadRate( double Value, int /*nbNodes*/ ) const
1591 // the skew is in the range [0.0,PI/2].
1597 SMDSAbs_ElementType Skew::GetType() const
1599 return SMDSAbs_Face;
1603 //================================================================================
1606 Description : Functor for calculating area
1608 //================================================================================
1610 double Area::GetValue( const TSequenceOfXYZ& P )
1615 gp_Vec aVec1( P(2) - P(1) );
1616 gp_Vec aVec2( P(3) - P(1) );
1617 gp_Vec SumVec = aVec1 ^ aVec2;
1619 for (size_t i=4; i<=P.size(); i++)
1621 gp_Vec aVec1( P(i-1) - P(1) );
1622 gp_Vec aVec2( P(i ) - P(1) );
1623 gp_Vec tmp = aVec1 ^ aVec2;
1626 val = SumVec.Magnitude() * 0.5;
1631 double Area::GetBadRate( double Value, int /*nbNodes*/ ) const
1633 // meaningless as it is not a quality control functor
1637 SMDSAbs_ElementType Area::GetType() const
1639 return SMDSAbs_Face;
1642 //================================================================================
1645 Description : Functor for calculating length of edge
1647 //================================================================================
1649 double Length::GetValue( const TSequenceOfXYZ& P )
1651 switch ( P.size() ) {
1652 case 2: return getDistance( P( 1 ), P( 2 ) );
1653 case 3: return getDistance( P( 1 ), P( 2 ) ) + getDistance( P( 2 ), P( 3 ) );
1658 double Length::GetBadRate( double Value, int /*nbNodes*/ ) const
1660 // meaningless as it is not quality control functor
1664 SMDSAbs_ElementType Length::GetType() const
1666 return SMDSAbs_Edge;
1669 //================================================================================
1672 Description : Functor for calculating minimal length of element edge
1674 //================================================================================
1676 Length3D::Length3D():
1677 Length2D ( SMDSAbs_Volume )
1681 //================================================================================
1684 Description : Functor for calculating minimal length of element edge
1686 //================================================================================
1688 Length2D::Length2D( SMDSAbs_ElementType type ):
1693 bool Length2D::IsApplicable( const SMDS_MeshElement* element ) const
1695 return ( NumericalFunctor::IsApplicable( element ) &&
1696 element->GetEntityType() != SMDSEntity_Polyhedra );
1699 double Length2D::GetValue( const TSequenceOfXYZ& P )
1703 SMDSAbs_EntityType aType = P.getElementEntity();
1706 case SMDSEntity_Edge:
1708 aVal = getDistance( P( 1 ), P( 2 ) );
1710 case SMDSEntity_Quad_Edge:
1711 if (len == 3) // quadratic edge
1712 aVal = getDistance(P( 1 ),P( 3 )) + getDistance(P( 3 ),P( 2 ));
1714 case SMDSEntity_Triangle:
1715 if (len == 3){ // triangles
1716 double L1 = getDistance(P( 1 ),P( 2 ));
1717 double L2 = getDistance(P( 2 ),P( 3 ));
1718 double L3 = getDistance(P( 3 ),P( 1 ));
1719 aVal = Min(L1,Min(L2,L3));
1722 case SMDSEntity_Quadrangle:
1723 if (len == 4){ // quadrangles
1724 double L1 = getDistance(P( 1 ),P( 2 ));
1725 double L2 = getDistance(P( 2 ),P( 3 ));
1726 double L3 = getDistance(P( 3 ),P( 4 ));
1727 double L4 = getDistance(P( 4 ),P( 1 ));
1728 aVal = Min(Min(L1,L2),Min(L3,L4));
1731 case SMDSEntity_Quad_Triangle:
1732 case SMDSEntity_BiQuad_Triangle:
1733 if (len >= 6){ // quadratic triangles
1734 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1735 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1736 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 1 ));
1737 aVal = Min(L1,Min(L2,L3));
1740 case SMDSEntity_Quad_Quadrangle:
1741 case SMDSEntity_BiQuad_Quadrangle:
1742 if (len >= 8){ // quadratic quadrangles
1743 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1744 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1745 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 7 ));
1746 double L4 = getDistance(P( 7 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
1747 aVal = Min(Min(L1,L2),Min(L3,L4));
1750 case SMDSEntity_Tetra:
1751 if (len == 4){ // tetrahedra
1752 double L1 = getDistance(P( 1 ),P( 2 ));
1753 double L2 = getDistance(P( 2 ),P( 3 ));
1754 double L3 = getDistance(P( 3 ),P( 1 ));
1755 double L4 = getDistance(P( 1 ),P( 4 ));
1756 double L5 = getDistance(P( 2 ),P( 4 ));
1757 double L6 = getDistance(P( 3 ),P( 4 ));
1758 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1761 case SMDSEntity_Pyramid:
1762 if (len == 5){ // pyramid
1763 double L1 = getDistance(P( 1 ),P( 2 ));
1764 double L2 = getDistance(P( 2 ),P( 3 ));
1765 double L3 = getDistance(P( 3 ),P( 4 ));
1766 double L4 = getDistance(P( 4 ),P( 1 ));
1767 double L5 = getDistance(P( 1 ),P( 5 ));
1768 double L6 = getDistance(P( 2 ),P( 5 ));
1769 double L7 = getDistance(P( 3 ),P( 5 ));
1770 double L8 = getDistance(P( 4 ),P( 5 ));
1772 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1773 aVal = Min(aVal,Min(L7,L8));
1776 case SMDSEntity_Penta:
1777 if (len == 6) { // pentahedron
1778 double L1 = getDistance(P( 1 ),P( 2 ));
1779 double L2 = getDistance(P( 2 ),P( 3 ));
1780 double L3 = getDistance(P( 3 ),P( 1 ));
1781 double L4 = getDistance(P( 4 ),P( 5 ));
1782 double L5 = getDistance(P( 5 ),P( 6 ));
1783 double L6 = getDistance(P( 6 ),P( 4 ));
1784 double L7 = getDistance(P( 1 ),P( 4 ));
1785 double L8 = getDistance(P( 2 ),P( 5 ));
1786 double L9 = getDistance(P( 3 ),P( 6 ));
1788 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1789 aVal = Min(aVal,Min(Min(L7,L8),L9));
1792 case SMDSEntity_Hexa:
1793 if (len == 8){ // hexahedron
1794 double L1 = getDistance(P( 1 ),P( 2 ));
1795 double L2 = getDistance(P( 2 ),P( 3 ));
1796 double L3 = getDistance(P( 3 ),P( 4 ));
1797 double L4 = getDistance(P( 4 ),P( 1 ));
1798 double L5 = getDistance(P( 5 ),P( 6 ));
1799 double L6 = getDistance(P( 6 ),P( 7 ));
1800 double L7 = getDistance(P( 7 ),P( 8 ));
1801 double L8 = getDistance(P( 8 ),P( 5 ));
1802 double L9 = getDistance(P( 1 ),P( 5 ));
1803 double L10= getDistance(P( 2 ),P( 6 ));
1804 double L11= getDistance(P( 3 ),P( 7 ));
1805 double L12= getDistance(P( 4 ),P( 8 ));
1807 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1808 aVal = Min(aVal,Min(Min(L7,L8),Min(L9,L10)));
1809 aVal = Min(aVal,Min(L11,L12));
1812 case SMDSEntity_Quad_Tetra:
1813 if (len == 10){ // quadratic tetrahedron
1814 double L1 = getDistance(P( 1 ),P( 5 )) + getDistance(P( 5 ),P( 2 ));
1815 double L2 = getDistance(P( 2 ),P( 6 )) + getDistance(P( 6 ),P( 3 ));
1816 double L3 = getDistance(P( 3 ),P( 7 )) + getDistance(P( 7 ),P( 1 ));
1817 double L4 = getDistance(P( 1 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
1818 double L5 = getDistance(P( 2 ),P( 9 )) + getDistance(P( 9 ),P( 4 ));
1819 double L6 = getDistance(P( 3 ),P( 10 )) + getDistance(P( 10 ),P( 4 ));
1820 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1823 case SMDSEntity_Quad_Pyramid:
1824 if (len == 13){ // quadratic pyramid
1825 double L1 = getDistance(P( 1 ),P( 6 )) + getDistance(P( 6 ),P( 2 ));
1826 double L2 = getDistance(P( 2 ),P( 7 )) + getDistance(P( 7 ),P( 3 ));
1827 double L3 = getDistance(P( 3 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
1828 double L4 = getDistance(P( 4 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1829 double L5 = getDistance(P( 1 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1830 double L6 = getDistance(P( 2 ),P( 11 )) + getDistance(P( 11 ),P( 5 ));
1831 double L7 = getDistance(P( 3 ),P( 12 )) + getDistance(P( 12 ),P( 5 ));
1832 double L8 = getDistance(P( 4 ),P( 13 )) + getDistance(P( 13 ),P( 5 ));
1833 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1834 aVal = Min(aVal,Min(L7,L8));
1837 case SMDSEntity_Quad_Penta:
1838 case SMDSEntity_BiQuad_Penta:
1839 if (len >= 15){ // quadratic pentahedron
1840 double L1 = getDistance(P( 1 ),P( 7 )) + getDistance(P( 7 ),P( 2 ));
1841 double L2 = getDistance(P( 2 ),P( 8 )) + getDistance(P( 8 ),P( 3 ));
1842 double L3 = getDistance(P( 3 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1843 double L4 = getDistance(P( 4 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1844 double L5 = getDistance(P( 5 ),P( 11 )) + getDistance(P( 11 ),P( 6 ));
1845 double L6 = getDistance(P( 6 ),P( 12 )) + getDistance(P( 12 ),P( 4 ));
1846 double L7 = getDistance(P( 1 ),P( 13 )) + getDistance(P( 13 ),P( 4 ));
1847 double L8 = getDistance(P( 2 ),P( 14 )) + getDistance(P( 14 ),P( 5 ));
1848 double L9 = getDistance(P( 3 ),P( 15 )) + getDistance(P( 15 ),P( 6 ));
1849 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1850 aVal = Min(aVal,Min(Min(L7,L8),L9));
1853 case SMDSEntity_Quad_Hexa:
1854 case SMDSEntity_TriQuad_Hexa:
1855 if (len >= 20) { // quadratic hexahedron
1856 double L1 = getDistance(P( 1 ),P( 9 )) + getDistance(P( 9 ),P( 2 ));
1857 double L2 = getDistance(P( 2 ),P( 10 )) + getDistance(P( 10 ),P( 3 ));
1858 double L3 = getDistance(P( 3 ),P( 11 )) + getDistance(P( 11 ),P( 4 ));
1859 double L4 = getDistance(P( 4 ),P( 12 )) + getDistance(P( 12 ),P( 1 ));
1860 double L5 = getDistance(P( 5 ),P( 13 )) + getDistance(P( 13 ),P( 6 ));
1861 double L6 = getDistance(P( 6 ),P( 14 )) + getDistance(P( 14 ),P( 7 ));
1862 double L7 = getDistance(P( 7 ),P( 15 )) + getDistance(P( 15 ),P( 8 ));
1863 double L8 = getDistance(P( 8 ),P( 16 )) + getDistance(P( 16 ),P( 5 ));
1864 double L9 = getDistance(P( 1 ),P( 17 )) + getDistance(P( 17 ),P( 5 ));
1865 double L10= getDistance(P( 2 ),P( 18 )) + getDistance(P( 18 ),P( 6 ));
1866 double L11= getDistance(P( 3 ),P( 19 )) + getDistance(P( 19 ),P( 7 ));
1867 double L12= getDistance(P( 4 ),P( 20 )) + getDistance(P( 20 ),P( 8 ));
1868 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1869 aVal = Min(aVal,Min(Min(L7,L8),Min(L9,L10)));
1870 aVal = Min(aVal,Min(L11,L12));
1873 case SMDSEntity_Polygon:
1875 aVal = getDistance( P(1), P( P.size() ));
1876 for ( size_t i = 1; i < P.size(); ++i )
1877 aVal = Min( aVal, getDistance( P( i ), P( i+1 )));
1880 case SMDSEntity_Quad_Polygon:
1882 aVal = getDistance( P(1), P( P.size() )) + getDistance( P(P.size()), P( P.size()-1 ));
1883 for ( size_t i = 1; i < P.size()-1; i += 2 )
1884 aVal = Min( aVal, getDistance( P( i ), P( i+1 )) + getDistance( P( i+1 ), P( i+2 )));
1887 case SMDSEntity_Hexagonal_Prism:
1888 if (len == 12) { // hexagonal prism
1889 double L1 = getDistance(P( 1 ),P( 2 ));
1890 double L2 = getDistance(P( 2 ),P( 3 ));
1891 double L3 = getDistance(P( 3 ),P( 4 ));
1892 double L4 = getDistance(P( 4 ),P( 5 ));
1893 double L5 = getDistance(P( 5 ),P( 6 ));
1894 double L6 = getDistance(P( 6 ),P( 1 ));
1896 double L7 = getDistance(P( 7 ), P( 8 ));
1897 double L8 = getDistance(P( 8 ), P( 9 ));
1898 double L9 = getDistance(P( 9 ), P( 10 ));
1899 double L10= getDistance(P( 10 ),P( 11 ));
1900 double L11= getDistance(P( 11 ),P( 12 ));
1901 double L12= getDistance(P( 12 ),P( 7 ));
1903 double L13 = getDistance(P( 1 ),P( 7 ));
1904 double L14 = getDistance(P( 2 ),P( 8 ));
1905 double L15 = getDistance(P( 3 ),P( 9 ));
1906 double L16 = getDistance(P( 4 ),P( 10 ));
1907 double L17 = getDistance(P( 5 ),P( 11 ));
1908 double L18 = getDistance(P( 6 ),P( 12 ));
1909 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1910 aVal = Min(aVal, Min(Min(Min(L7,L8),Min(L9,L10)),Min(L11,L12)));
1911 aVal = Min(aVal, Min(Min(Min(L13,L14),Min(L15,L16)),Min(L17,L18)));
1914 case SMDSEntity_Polyhedra:
1926 if ( myPrecision >= 0 )
1928 double prec = pow( 10., (double)( myPrecision ) );
1929 aVal = floor( aVal * prec + 0.5 ) / prec;
1935 double Length2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1937 // meaningless as it is not a quality control functor
1941 SMDSAbs_ElementType Length2D::GetType() const
1946 Length2D::Value::Value(double theLength,long thePntId1, long thePntId2):
1949 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1950 if(thePntId1 > thePntId2){
1951 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1955 bool Length2D::Value::operator<(const Length2D::Value& x) const
1957 if(myPntId[0] < x.myPntId[0]) return true;
1958 if(myPntId[0] == x.myPntId[0])
1959 if(myPntId[1] < x.myPntId[1]) return true;
1963 void Length2D::GetValues(TValues& theValues)
1965 if ( myType == SMDSAbs_Face )
1967 for ( SMDS_FaceIteratorPtr anIter = myMesh->facesIterator(); anIter->more(); )
1969 const SMDS_MeshFace* anElem = anIter->next();
1970 if ( anElem->IsQuadratic() )
1972 // use special nodes iterator
1973 SMDS_NodeIteratorPtr anIter = anElem->interlacedNodesIterator();
1974 long aNodeId[4] = { 0,0,0,0 };
1978 if ( anIter->more() )
1980 const SMDS_MeshNode* aNode = anIter->next();
1981 P[0] = P[1] = SMESH_NodeXYZ( aNode );
1982 aNodeId[0] = aNodeId[1] = aNode->GetID();
1985 for ( ; anIter->more(); )
1987 const SMDS_MeshNode* N1 = anIter->next();
1988 P[2] = SMESH_NodeXYZ( N1 );
1989 aNodeId[2] = N1->GetID();
1990 aLength = P[1].Distance(P[2]);
1991 if(!anIter->more()) break;
1992 const SMDS_MeshNode* N2 = anIter->next();
1993 P[3] = SMESH_NodeXYZ( N2 );
1994 aNodeId[3] = N2->GetID();
1995 aLength += P[2].Distance(P[3]);
1996 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1997 Value aValue2(aLength,aNodeId[2],aNodeId[3]);
1999 aNodeId[1] = aNodeId[3];
2000 theValues.insert(aValue1);
2001 theValues.insert(aValue2);
2003 aLength += P[2].Distance(P[0]);
2004 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
2005 Value aValue2(aLength,aNodeId[2],aNodeId[0]);
2006 theValues.insert(aValue1);
2007 theValues.insert(aValue2);
2010 SMDS_NodeIteratorPtr aNodesIter = anElem->nodeIterator();
2011 long aNodeId[2] = {0,0};
2015 const SMDS_MeshElement* aNode;
2016 if ( aNodesIter->more())
2018 aNode = aNodesIter->next();
2019 P[0] = P[1] = SMESH_NodeXYZ( aNode );
2020 aNodeId[0] = aNodeId[1] = aNode->GetID();
2023 for( ; aNodesIter->more(); )
2025 aNode = aNodesIter->next();
2026 long anId = aNode->GetID();
2028 P[2] = SMESH_NodeXYZ( aNode );
2030 aLength = P[1].Distance(P[2]);
2032 Value aValue(aLength,aNodeId[1],anId);
2035 theValues.insert(aValue);
2038 aLength = P[0].Distance(P[1]);
2040 Value aValue(aLength,aNodeId[0],aNodeId[1]);
2041 theValues.insert(aValue);
2051 //================================================================================
2053 Class : Deflection2D
2054 Description : computes distance between a face center and an underlying surface
2056 //================================================================================
2058 double Deflection2D::GetValue( const TSequenceOfXYZ& P )
2060 if ( myMesh && P.getElement() )
2062 // get underlying surface
2063 if ( myShapeIndex != P.getElement()->getshapeId() )
2065 mySurface.Nullify();
2066 myShapeIndex = P.getElement()->getshapeId();
2067 const TopoDS_Shape& S =
2068 static_cast< const SMESHDS_Mesh* >( myMesh )->IndexToShape( myShapeIndex );
2069 if ( !S.IsNull() && S.ShapeType() == TopAbs_FACE )
2071 mySurface = new ShapeAnalysis_Surface( BRep_Tool::Surface( TopoDS::Face( S )));
2073 GeomLib_IsPlanarSurface isPlaneCheck( mySurface->Surface() );
2074 if ( isPlaneCheck.IsPlanar() )
2075 myPlane.reset( new gp_Pln( isPlaneCheck.Plan() ));
2080 // project gravity center to the surface
2081 if ( !mySurface.IsNull() )
2086 for ( size_t i = 0; i < P.size(); ++i )
2090 if ( SMDS_FacePositionPtr fPos = P.getElement()->GetNode( i )->GetPosition() )
2092 uv.ChangeCoord(1) += fPos->GetUParameter();
2093 uv.ChangeCoord(2) += fPos->GetVParameter();
2098 if ( nbUV ) uv /= nbUV;
2100 double maxLen = MaxElementLength2D().GetValue( P );
2101 double tol = 1e-3 * maxLen;
2105 dist = myPlane->Distance( gc );
2111 if ( uv.X() != 0 && uv.Y() != 0 ) // faster way
2112 mySurface->NextValueOfUV( uv, gc, tol, 0.5 * maxLen );
2114 mySurface->ValueOfUV( gc, tol );
2115 dist = mySurface->Gap();
2117 return Round( dist );
2123 void Deflection2D::SetMesh( const SMDS_Mesh* theMesh )
2125 NumericalFunctor::SetMesh( dynamic_cast<const SMESHDS_Mesh* >( theMesh ));
2126 myShapeIndex = -100;
2130 SMDSAbs_ElementType Deflection2D::GetType() const
2132 return SMDSAbs_Face;
2135 double Deflection2D::GetBadRate( double Value, int /*nbNodes*/ ) const
2137 // meaningless as it is not quality control functor
2141 //================================================================================
2143 Class : MultiConnection
2144 Description : Functor for calculating number of faces conneted to the edge
2146 //================================================================================
2148 double MultiConnection::GetValue( const TSequenceOfXYZ& /*P*/ )
2152 double MultiConnection::GetValue( long theId )
2154 return getNbMultiConnection( myMesh, theId );
2157 double MultiConnection::GetBadRate( double Value, int /*nbNodes*/ ) const
2159 // meaningless as it is not quality control functor
2163 SMDSAbs_ElementType MultiConnection::GetType() const
2165 return SMDSAbs_Edge;
2168 //================================================================================
2170 Class : MultiConnection2D
2171 Description : Functor for calculating number of faces conneted to the edge
2173 //================================================================================
2175 double MultiConnection2D::GetValue( const TSequenceOfXYZ& /*P*/ )
2180 double MultiConnection2D::GetValue( long theElementId )
2184 const SMDS_MeshElement* aFaceElem = myMesh->FindElement(theElementId);
2185 SMDSAbs_ElementType aType = aFaceElem->GetType();
2190 int i = 0, len = aFaceElem->NbNodes();
2191 SMDS_ElemIteratorPtr anIter = aFaceElem->nodesIterator();
2194 const SMDS_MeshNode *aNode, *aNode0 = 0;
2195 TColStd_MapOfInteger aMap, aMapPrev;
2197 for (i = 0; i <= len; i++) {
2202 if (anIter->more()) {
2203 aNode = (SMDS_MeshNode*)anIter->next();
2211 if (i == 0) aNode0 = aNode;
2213 SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator();
2214 while (anElemIter->more()) {
2215 const SMDS_MeshElement* anElem = anElemIter->next();
2216 if (anElem != 0 && anElem->GetType() == SMDSAbs_Face) {
2217 int anId = anElem->GetID();
2220 if (aMapPrev.Contains(anId)) {
2225 aResult = Max(aResult, aNb);
2236 double MultiConnection2D::GetBadRate( double Value, int /*nbNodes*/ ) const
2238 // meaningless as it is not quality control functor
2242 SMDSAbs_ElementType MultiConnection2D::GetType() const
2244 return SMDSAbs_Face;
2247 MultiConnection2D::Value::Value(long thePntId1, long thePntId2)
2249 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
2250 if(thePntId1 > thePntId2){
2251 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
2255 bool MultiConnection2D::Value::operator<(const MultiConnection2D::Value& x) const
2257 if(myPntId[0] < x.myPntId[0]) return true;
2258 if(myPntId[0] == x.myPntId[0])
2259 if(myPntId[1] < x.myPntId[1]) return true;
2263 void MultiConnection2D::GetValues(MValues& theValues)
2265 if ( !myMesh ) return;
2266 for ( SMDS_FaceIteratorPtr anIter = myMesh->facesIterator(); anIter->more(); )
2268 const SMDS_MeshFace* anElem = anIter->next();
2269 SMDS_NodeIteratorPtr aNodesIter = anElem->interlacedNodesIterator();
2271 const SMDS_MeshNode* aNode1 = anElem->GetNode( anElem->NbNodes() - 1 );
2272 const SMDS_MeshNode* aNode2;
2273 for ( ; aNodesIter->more(); )
2275 aNode2 = aNodesIter->next();
2277 Value aValue ( aNode1->GetID(), aNode2->GetID() );
2278 MValues::iterator aItr = theValues.insert( std::make_pair( aValue, 0 )).first;
2286 //================================================================================
2288 Class : BallDiameter
2289 Description : Functor returning diameter of a ball element
2291 //================================================================================
2293 double BallDiameter::GetValue( long theId )
2295 double diameter = 0;
2297 if ( const SMDS_BallElement* ball =
2298 myMesh->DownCast< SMDS_BallElement >( myMesh->FindElement( theId )))
2300 diameter = ball->GetDiameter();
2305 double BallDiameter::GetBadRate( double Value, int /*nbNodes*/ ) const
2307 // meaningless as it is not a quality control functor
2311 SMDSAbs_ElementType BallDiameter::GetType() const
2313 return SMDSAbs_Ball;
2316 //================================================================================
2318 Class : NodeConnectivityNumber
2319 Description : Functor returning number of elements connected to a node
2321 //================================================================================
2323 double NodeConnectivityNumber::GetValue( long theId )
2327 if ( const SMDS_MeshNode* node = myMesh->FindNode( theId ))
2329 SMDSAbs_ElementType type;
2330 if ( myMesh->NbVolumes() > 0 )
2331 type = SMDSAbs_Volume;
2332 else if ( myMesh->NbFaces() > 0 )
2333 type = SMDSAbs_Face;
2334 else if ( myMesh->NbEdges() > 0 )
2335 type = SMDSAbs_Edge;
2338 nb = node->NbInverseElements( type );
2343 double NodeConnectivityNumber::GetBadRate( double Value, int /*nbNodes*/ ) const
2348 SMDSAbs_ElementType NodeConnectivityNumber::GetType() const
2350 return SMDSAbs_Node;
2357 //================================================================================
2359 Class : BadOrientedVolume
2360 Description : Predicate bad oriented volumes
2362 //================================================================================
2364 BadOrientedVolume::BadOrientedVolume()
2369 void BadOrientedVolume::SetMesh( const SMDS_Mesh* theMesh )
2374 bool BadOrientedVolume::IsSatisfy( long theId )
2379 SMDS_VolumeTool vTool( myMesh->FindElement( theId ));
2382 if ( vTool.IsPoly() )
2385 for ( int i = 0; i < vTool.NbFaces() && isOk; ++i )
2386 isOk = vTool.IsFaceExternal( i );
2390 isOk = vTool.IsForward();
2395 SMDSAbs_ElementType BadOrientedVolume::GetType() const
2397 return SMDSAbs_Volume;
2401 Class : BareBorderVolume
2404 bool BareBorderVolume::IsSatisfy(long theElementId )
2406 SMDS_VolumeTool myTool;
2407 if ( myTool.Set( myMesh->FindElement(theElementId)))
2409 for ( int iF = 0; iF < myTool.NbFaces(); ++iF )
2410 if ( myTool.IsFreeFace( iF ))
2412 const SMDS_MeshNode** n = myTool.GetFaceNodes(iF);
2413 std::vector< const SMDS_MeshNode*> nodes( n, n+myTool.NbFaceNodes(iF));
2414 if ( !myMesh->FindElement( nodes, SMDSAbs_Face, /*Nomedium=*/false))
2421 //================================================================================
2423 Class : BareBorderFace
2425 //================================================================================
2427 bool BareBorderFace::IsSatisfy(long theElementId )
2430 if ( const SMDS_MeshElement* face = myMesh->FindElement(theElementId))
2432 if ( face->GetType() == SMDSAbs_Face )
2434 int nbN = face->NbCornerNodes();
2435 for ( int i = 0; i < nbN && !ok; ++i )
2437 // check if a link is shared by another face
2438 const SMDS_MeshNode* n1 = face->GetNode( i );
2439 const SMDS_MeshNode* n2 = face->GetNode( (i+1)%nbN );
2440 SMDS_ElemIteratorPtr fIt = n1->GetInverseElementIterator( SMDSAbs_Face );
2441 bool isShared = false;
2442 while ( !isShared && fIt->more() )
2444 const SMDS_MeshElement* f = fIt->next();
2445 isShared = ( f != face && f->GetNodeIndex(n2) != -1 );
2449 const int iQuad = face->IsQuadratic();
2450 myLinkNodes.resize( 2 + iQuad);
2451 myLinkNodes[0] = n1;
2452 myLinkNodes[1] = n2;
2454 myLinkNodes[2] = face->GetNode( i+nbN );
2455 ok = !myMesh->FindElement( myLinkNodes, SMDSAbs_Edge, /*noMedium=*/false);
2463 //================================================================================
2465 Class : OverConstrainedVolume
2467 //================================================================================
2469 bool OverConstrainedVolume::IsSatisfy(long theElementId )
2471 // An element is over-constrained if it has N-1 free borders where
2472 // N is the number of edges/faces for a 2D/3D element.
2473 SMDS_VolumeTool myTool;
2474 if ( myTool.Set( myMesh->FindElement(theElementId)))
2476 int nbSharedFaces = 0;
2477 for ( int iF = 0; iF < myTool.NbFaces(); ++iF )
2478 if ( !myTool.IsFreeFace( iF ) && ++nbSharedFaces > 1 )
2480 return ( nbSharedFaces == 1 );
2485 //================================================================================
2487 Class : OverConstrainedFace
2489 //================================================================================
2491 bool OverConstrainedFace::IsSatisfy(long theElementId )
2493 // An element is over-constrained if it has N-1 free borders where
2494 // N is the number of edges/faces for a 2D/3D element.
2495 if ( const SMDS_MeshElement* face = myMesh->FindElement(theElementId))
2496 if ( face->GetType() == SMDSAbs_Face )
2498 int nbSharedBorders = 0;
2499 int nbN = face->NbCornerNodes();
2500 for ( int i = 0; i < nbN; ++i )
2502 // check if a link is shared by another face
2503 const SMDS_MeshNode* n1 = face->GetNode( i );
2504 const SMDS_MeshNode* n2 = face->GetNode( (i+1)%nbN );
2505 SMDS_ElemIteratorPtr fIt = n1->GetInverseElementIterator( SMDSAbs_Face );
2506 bool isShared = false;
2507 while ( !isShared && fIt->more() )
2509 const SMDS_MeshElement* f = fIt->next();
2510 isShared = ( f != face && f->GetNodeIndex(n2) != -1 );
2512 if ( isShared && ++nbSharedBorders > 1 )
2515 return ( nbSharedBorders == 1 );
2520 //================================================================================
2522 Class : CoincidentNodes
2523 Description : Predicate of Coincident nodes
2525 //================================================================================
2527 CoincidentNodes::CoincidentNodes()
2532 bool CoincidentNodes::IsSatisfy( long theElementId )
2534 return myCoincidentIDs.Contains( theElementId );
2537 SMDSAbs_ElementType CoincidentNodes::GetType() const
2539 return SMDSAbs_Node;
2542 void CoincidentNodes::SetTolerance( const double theToler )
2544 if ( myToler != theToler )
2551 void CoincidentNodes::SetMesh( const SMDS_Mesh* theMesh )
2553 myMeshModifTracer.SetMesh( theMesh );
2554 if ( myMeshModifTracer.IsMeshModified() )
2556 TIDSortedNodeSet nodesToCheck;
2557 SMDS_NodeIteratorPtr nIt = theMesh->nodesIterator();
2558 while ( nIt->more() )
2559 nodesToCheck.insert( nodesToCheck.end(), nIt->next() );
2561 std::list< std::list< const SMDS_MeshNode*> > nodeGroups;
2562 SMESH_OctreeNode::FindCoincidentNodes ( nodesToCheck, &nodeGroups, myToler );
2564 myCoincidentIDs.Clear();
2565 std::list< std::list< const SMDS_MeshNode*> >::iterator groupIt = nodeGroups.begin();
2566 for ( ; groupIt != nodeGroups.end(); ++groupIt )
2568 std::list< const SMDS_MeshNode*>& coincNodes = *groupIt;
2569 std::list< const SMDS_MeshNode*>::iterator n = coincNodes.begin();
2570 for ( ; n != coincNodes.end(); ++n )
2571 myCoincidentIDs.Add( (*n)->GetID() );
2576 //================================================================================
2578 Class : CoincidentElements
2579 Description : Predicate of Coincident Elements
2580 Note : This class is suitable only for visualization of Coincident Elements
2582 //================================================================================
2584 CoincidentElements::CoincidentElements()
2589 void CoincidentElements::SetMesh( const SMDS_Mesh* theMesh )
2594 bool CoincidentElements::IsSatisfy( long theElementId )
2596 if ( !myMesh ) return false;
2598 if ( const SMDS_MeshElement* e = myMesh->FindElement( theElementId ))
2600 if ( e->GetType() != GetType() ) return false;
2601 std::set< const SMDS_MeshNode* > elemNodes( e->begin_nodes(), e->end_nodes() );
2602 const int nbNodes = e->NbNodes();
2603 SMDS_ElemIteratorPtr invIt = (*elemNodes.begin())->GetInverseElementIterator( GetType() );
2604 while ( invIt->more() )
2606 const SMDS_MeshElement* e2 = invIt->next();
2607 if ( e2 == e || e2->NbNodes() != nbNodes ) continue;
2609 bool sameNodes = true;
2610 for ( size_t i = 0; i < elemNodes.size() && sameNodes; ++i )
2611 sameNodes = ( elemNodes.count( e2->GetNode( i )));
2619 SMDSAbs_ElementType CoincidentElements1D::GetType() const
2621 return SMDSAbs_Edge;
2623 SMDSAbs_ElementType CoincidentElements2D::GetType() const
2625 return SMDSAbs_Face;
2627 SMDSAbs_ElementType CoincidentElements3D::GetType() const
2629 return SMDSAbs_Volume;
2633 //================================================================================
2636 Description : Predicate for free borders
2638 //================================================================================
2640 FreeBorders::FreeBorders()
2645 void FreeBorders::SetMesh( const SMDS_Mesh* theMesh )
2650 bool FreeBorders::IsSatisfy( long theId )
2652 return getNbMultiConnection( myMesh, theId ) == 1;
2655 SMDSAbs_ElementType FreeBorders::GetType() const
2657 return SMDSAbs_Edge;
2661 //================================================================================
2664 Description : Predicate for free Edges
2666 //================================================================================
2668 FreeEdges::FreeEdges()
2673 void FreeEdges::SetMesh( const SMDS_Mesh* theMesh )
2678 bool FreeEdges::IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId )
2680 SMDS_ElemIteratorPtr anElemIter = theNodes[ 0 ]->GetInverseElementIterator(SMDSAbs_Face);
2681 while( anElemIter->more() )
2683 if ( const SMDS_MeshElement* anElem = anElemIter->next())
2685 const int anId = anElem->GetID();
2686 if ( anId != theFaceId && anElem->GetNodeIndex( theNodes[1] ) >= 0 )
2693 bool FreeEdges::IsSatisfy( long theId )
2698 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
2699 if ( aFace == 0 || aFace->GetType() != SMDSAbs_Face || aFace->NbNodes() < 3 )
2702 SMDS_NodeIteratorPtr anIter = aFace->interlacedNodesIterator();
2706 int i = 0, nbNodes = aFace->NbNodes();
2707 std::vector <const SMDS_MeshNode*> aNodes( nbNodes+1 );
2708 while( anIter->more() )
2709 if ( ! ( aNodes[ i++ ] = anIter->next() ))
2711 aNodes[ nbNodes ] = aNodes[ 0 ];
2713 for ( i = 0; i < nbNodes; i++ )
2714 if ( IsFreeEdge( &aNodes[ i ], theId ) )
2720 SMDSAbs_ElementType FreeEdges::GetType() const
2722 return SMDSAbs_Face;
2725 FreeEdges::Border::Border(long theElemId, long thePntId1, long thePntId2):
2728 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
2729 if(thePntId1 > thePntId2){
2730 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
2734 bool FreeEdges::Border::operator<(const FreeEdges::Border& x) const{
2735 if(myPntId[0] < x.myPntId[0]) return true;
2736 if(myPntId[0] == x.myPntId[0])
2737 if(myPntId[1] < x.myPntId[1]) return true;
2741 inline void UpdateBorders(const FreeEdges::Border& theBorder,
2742 FreeEdges::TBorders& theRegistry,
2743 FreeEdges::TBorders& theContainer)
2745 if(theRegistry.find(theBorder) == theRegistry.end()){
2746 theRegistry.insert(theBorder);
2747 theContainer.insert(theBorder);
2749 theContainer.erase(theBorder);
2753 void FreeEdges::GetBoreders(TBorders& theBorders)
2756 for ( SMDS_FaceIteratorPtr anIter = myMesh->facesIterator(); anIter->more(); )
2758 const SMDS_MeshFace* anElem = anIter->next();
2759 long anElemId = anElem->GetID();
2760 SMDS_NodeIteratorPtr aNodesIter = anElem->interlacedNodesIterator();
2761 if ( !aNodesIter->more() ) continue;
2762 long aNodeId[2] = {0,0};
2763 aNodeId[0] = anElem->GetNode( anElem->NbNodes()-1 )->GetID();
2764 for ( ; aNodesIter->more(); )
2766 aNodeId[1] = aNodesIter->next()->GetID();
2767 Border aBorder( anElemId, aNodeId[0], aNodeId[1] );
2768 UpdateBorders( aBorder, aRegistry, theBorders );
2769 aNodeId[0] = aNodeId[1];
2774 //================================================================================
2777 Description : Predicate for free nodes
2779 //================================================================================
2781 FreeNodes::FreeNodes()
2786 void FreeNodes::SetMesh( const SMDS_Mesh* theMesh )
2791 bool FreeNodes::IsSatisfy( long theNodeId )
2793 const SMDS_MeshNode* aNode = myMesh->FindNode( theNodeId );
2797 return (aNode->NbInverseElements() < 1);
2800 SMDSAbs_ElementType FreeNodes::GetType() const
2802 return SMDSAbs_Node;
2806 //================================================================================
2809 Description : Predicate for free faces
2811 //================================================================================
2813 FreeFaces::FreeFaces()
2818 void FreeFaces::SetMesh( const SMDS_Mesh* theMesh )
2823 bool FreeFaces::IsSatisfy( long theId )
2825 if (!myMesh) return false;
2826 // check that faces nodes refers to less than two common volumes
2827 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
2828 if ( !aFace || aFace->GetType() != SMDSAbs_Face )
2831 int nbNode = aFace->NbNodes();
2833 // collect volumes to check that number of volumes with count equal nbNode not less than 2
2834 typedef std::map< SMDS_MeshElement*, int > TMapOfVolume; // map of volume counters
2835 typedef std::map< SMDS_MeshElement*, int >::iterator TItrMapOfVolume; // iterator
2836 TMapOfVolume mapOfVol;
2838 SMDS_ElemIteratorPtr nodeItr = aFace->nodesIterator();
2839 while ( nodeItr->more() )
2841 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(nodeItr->next());
2842 if ( !aNode ) continue;
2843 SMDS_ElemIteratorPtr volItr = aNode->GetInverseElementIterator(SMDSAbs_Volume);
2844 while ( volItr->more() )
2846 SMDS_MeshElement* aVol = (SMDS_MeshElement*)volItr->next();
2847 TItrMapOfVolume itr = mapOfVol.insert( std::make_pair( aVol, 0 )).first;
2852 TItrMapOfVolume volItr = mapOfVol.begin();
2853 TItrMapOfVolume volEnd = mapOfVol.end();
2854 for ( ; volItr != volEnd; ++volItr )
2855 if ( (*volItr).second >= nbNode )
2857 // face is not free if number of volumes constructed on their nodes more than one
2861 SMDSAbs_ElementType FreeFaces::GetType() const
2863 return SMDSAbs_Face;
2866 //================================================================================
2868 Class : LinearOrQuadratic
2869 Description : Predicate to verify whether a mesh element is linear
2871 //================================================================================
2873 LinearOrQuadratic::LinearOrQuadratic()
2878 void LinearOrQuadratic::SetMesh( const SMDS_Mesh* theMesh )
2883 bool LinearOrQuadratic::IsSatisfy( long theId )
2885 if (!myMesh) return false;
2886 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2887 if ( !anElem || (myType != SMDSAbs_All && anElem->GetType() != myType) )
2889 return (!anElem->IsQuadratic());
2892 void LinearOrQuadratic::SetType( SMDSAbs_ElementType theType )
2897 SMDSAbs_ElementType LinearOrQuadratic::GetType() const
2902 //================================================================================
2905 Description : Functor for check color of group to which mesh element belongs to
2907 //================================================================================
2909 GroupColor::GroupColor()
2913 bool GroupColor::IsSatisfy( long theId )
2915 return myIDs.count( theId );
2918 void GroupColor::SetType( SMDSAbs_ElementType theType )
2923 SMDSAbs_ElementType GroupColor::GetType() const
2928 static bool isEqual( const Quantity_Color& theColor1,
2929 const Quantity_Color& theColor2 )
2931 // tolerance to compare colors
2932 const double tol = 5*1e-3;
2933 return ( fabs( theColor1.Red() - theColor2.Red() ) < tol &&
2934 fabs( theColor1.Green() - theColor2.Green() ) < tol &&
2935 fabs( theColor1.Blue() - theColor2.Blue() ) < tol );
2938 void GroupColor::SetMesh( const SMDS_Mesh* theMesh )
2942 const SMESHDS_Mesh* aMesh = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
2946 int nbGrp = aMesh->GetNbGroups();
2950 // iterates on groups and find necessary elements ids
2951 const std::set<SMESHDS_GroupBase*>& aGroups = aMesh->GetGroups();
2952 std::set<SMESHDS_GroupBase*>::const_iterator GrIt = aGroups.begin();
2953 for (; GrIt != aGroups.end(); GrIt++)
2955 SMESHDS_GroupBase* aGrp = (*GrIt);
2958 // check type and color of group
2959 if ( !isEqual( myColor, aGrp->GetColor() ))
2962 // IPAL52867 (prevent infinite recursion via GroupOnFilter)
2963 if ( SMESHDS_GroupOnFilter * gof = dynamic_cast< SMESHDS_GroupOnFilter* >( aGrp ))
2964 if ( gof->GetPredicate().get() == this )
2967 SMDSAbs_ElementType aGrpElType = (SMDSAbs_ElementType)aGrp->GetType();
2968 if ( myType == aGrpElType || (myType == SMDSAbs_All && aGrpElType != SMDSAbs_Node) ) {
2969 // add elements IDS into control
2970 int aSize = aGrp->Extent();
2971 for (int i = 0; i < aSize; i++)
2972 myIDs.insert( aGrp->GetID(i+1) );
2977 void GroupColor::SetColorStr( const TCollection_AsciiString& theStr )
2979 Kernel_Utils::Localizer loc;
2980 TCollection_AsciiString aStr = theStr;
2981 aStr.RemoveAll( ' ' );
2982 aStr.RemoveAll( '\t' );
2983 for ( int aPos = aStr.Search( ";;" ); aPos != -1; aPos = aStr.Search( ";;" ) )
2984 aStr.Remove( aPos, 2 );
2985 Standard_Real clr[3];
2986 clr[0] = clr[1] = clr[2] = 0.;
2987 for ( int i = 0; i < 3; i++ ) {
2988 TCollection_AsciiString tmpStr = aStr.Token( ";", i+1 );
2989 if ( !tmpStr.IsEmpty() && tmpStr.IsRealValue() )
2990 clr[i] = tmpStr.RealValue();
2992 myColor = Quantity_Color( clr[0], clr[1], clr[2], Quantity_TOC_RGB );
2995 //=======================================================================
2996 // name : GetRangeStr
2997 // Purpose : Get range as a string.
2998 // Example: "1,2,3,50-60,63,67,70-"
2999 //=======================================================================
3001 void GroupColor::GetColorStr( TCollection_AsciiString& theResStr ) const
3004 theResStr += TCollection_AsciiString( myColor.Red() );
3005 theResStr += TCollection_AsciiString( ";" ) + TCollection_AsciiString( myColor.Green() );
3006 theResStr += TCollection_AsciiString( ";" ) + TCollection_AsciiString( myColor.Blue() );
3009 //================================================================================
3011 Class : ElemGeomType
3012 Description : Predicate to check element geometry type
3014 //================================================================================
3016 ElemGeomType::ElemGeomType()
3019 myType = SMDSAbs_All;
3020 myGeomType = SMDSGeom_TRIANGLE;
3023 void ElemGeomType::SetMesh( const SMDS_Mesh* theMesh )
3028 bool ElemGeomType::IsSatisfy( long theId )
3030 if (!myMesh) return false;
3031 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
3034 const SMDSAbs_ElementType anElemType = anElem->GetType();
3035 if ( myType != SMDSAbs_All && anElemType != myType )
3037 bool isOk = ( anElem->GetGeomType() == myGeomType );
3041 void ElemGeomType::SetType( SMDSAbs_ElementType theType )
3046 SMDSAbs_ElementType ElemGeomType::GetType() const
3051 void ElemGeomType::SetGeomType( SMDSAbs_GeometryType theType )
3053 myGeomType = theType;
3056 SMDSAbs_GeometryType ElemGeomType::GetGeomType() const
3061 //================================================================================
3063 Class : ElemEntityType
3064 Description : Predicate to check element entity type
3066 //================================================================================
3068 ElemEntityType::ElemEntityType():
3070 myType( SMDSAbs_All ),
3071 myEntityType( SMDSEntity_0D )
3075 void ElemEntityType::SetMesh( const SMDS_Mesh* theMesh )
3080 bool ElemEntityType::IsSatisfy( long theId )
3082 if ( !myMesh ) return false;
3083 if ( myType == SMDSAbs_Node )
3084 return myMesh->FindNode( theId );
3085 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
3087 myEntityType == anElem->GetEntityType() );
3090 void ElemEntityType::SetType( SMDSAbs_ElementType theType )
3095 SMDSAbs_ElementType ElemEntityType::GetType() const
3100 void ElemEntityType::SetElemEntityType( SMDSAbs_EntityType theEntityType )
3102 myEntityType = theEntityType;
3105 SMDSAbs_EntityType ElemEntityType::GetElemEntityType() const
3107 return myEntityType;
3110 //================================================================================
3112 * \brief Class ConnectedElements
3114 //================================================================================
3116 ConnectedElements::ConnectedElements():
3117 myNodeID(0), myType( SMDSAbs_All ), myOkIDsReady( false ) {}
3119 SMDSAbs_ElementType ConnectedElements::GetType() const
3122 int ConnectedElements::GetNode() const
3123 { return myXYZ.empty() ? myNodeID : 0; } // myNodeID can be found by myXYZ
3125 std::vector<double> ConnectedElements::GetPoint() const
3128 void ConnectedElements::clearOkIDs()
3129 { myOkIDsReady = false; myOkIDs.clear(); }
3131 void ConnectedElements::SetType( SMDSAbs_ElementType theType )
3133 if ( myType != theType || myMeshModifTracer.IsMeshModified() )
3138 void ConnectedElements::SetMesh( const SMDS_Mesh* theMesh )
3140 myMeshModifTracer.SetMesh( theMesh );
3141 if ( myMeshModifTracer.IsMeshModified() )
3144 if ( !myXYZ.empty() )
3145 SetPoint( myXYZ[0], myXYZ[1], myXYZ[2] ); // find a node near myXYZ it in a new mesh
3149 void ConnectedElements::SetNode( int nodeID )
3154 bool isSameDomain = false;
3155 if ( myOkIDsReady && myMeshModifTracer.GetMesh() && !myMeshModifTracer.IsMeshModified() )
3156 if ( const SMDS_MeshNode* n = myMeshModifTracer.GetMesh()->FindNode( myNodeID ))
3158 SMDS_ElemIteratorPtr eIt = n->GetInverseElementIterator( myType );
3159 while ( !isSameDomain && eIt->more() )
3160 isSameDomain = IsSatisfy( eIt->next()->GetID() );
3162 if ( !isSameDomain )
3166 void ConnectedElements::SetPoint( double x, double y, double z )
3174 bool isSameDomain = false;
3176 // find myNodeID by myXYZ if possible
3177 if ( myMeshModifTracer.GetMesh() )
3179 SMESHUtils::Deleter<SMESH_ElementSearcher> searcher
3180 ( SMESH_MeshAlgos::GetElementSearcher( (SMDS_Mesh&) *myMeshModifTracer.GetMesh() ));
3182 std::vector< const SMDS_MeshElement* > foundElems;
3183 searcher->FindElementsByPoint( gp_Pnt(x,y,z), SMDSAbs_All, foundElems );
3185 if ( !foundElems.empty() )
3187 myNodeID = foundElems[0]->GetNode(0)->GetID();
3188 if ( myOkIDsReady && !myMeshModifTracer.IsMeshModified() )
3189 isSameDomain = IsSatisfy( foundElems[0]->GetID() );
3192 if ( !isSameDomain )
3196 bool ConnectedElements::IsSatisfy( long theElementId )
3198 // Here we do NOT check if the mesh has changed, we do it in Set...() only!!!
3200 if ( !myOkIDsReady )
3202 if ( !myMeshModifTracer.GetMesh() )
3204 const SMDS_MeshNode* node0 = myMeshModifTracer.GetMesh()->FindNode( myNodeID );
3208 std::list< const SMDS_MeshNode* > nodeQueue( 1, node0 );
3209 std::set< int > checkedNodeIDs;
3211 // foreach node in nodeQueue:
3212 // foreach element sharing a node:
3213 // add ID of an element of myType to myOkIDs;
3214 // push all element nodes absent from checkedNodeIDs to nodeQueue;
3215 while ( !nodeQueue.empty() )
3217 const SMDS_MeshNode* node = nodeQueue.front();
3218 nodeQueue.pop_front();
3220 // loop on elements sharing the node
3221 SMDS_ElemIteratorPtr eIt = node->GetInverseElementIterator();
3222 while ( eIt->more() )
3224 // keep elements of myType
3225 const SMDS_MeshElement* element = eIt->next();
3226 if ( myType == SMDSAbs_All || element->GetType() == myType )
3227 myOkIDs.insert( myOkIDs.end(), element->GetID() );
3229 // enqueue nodes of the element
3230 SMDS_ElemIteratorPtr nIt = element->nodesIterator();
3231 while ( nIt->more() )
3233 const SMDS_MeshNode* n = static_cast< const SMDS_MeshNode* >( nIt->next() );
3234 if ( checkedNodeIDs.insert( n->GetID() ).second )
3235 nodeQueue.push_back( n );
3239 if ( myType == SMDSAbs_Node )
3240 std::swap( myOkIDs, checkedNodeIDs );
3242 size_t totalNbElems = myMeshModifTracer.GetMesh()->GetMeshInfo().NbElements( myType );
3243 if ( myOkIDs.size() == totalNbElems )
3246 myOkIDsReady = true;
3249 return myOkIDs.empty() ? true : myOkIDs.count( theElementId );
3252 //================================================================================
3254 * \brief Class CoplanarFaces
3256 //================================================================================
3260 inline bool isLessAngle( const gp_Vec& v1, const gp_Vec& v2, const double cos )
3262 double dot = v1 * v2; // cos * |v1| * |v2|
3263 double l1 = v1.SquareMagnitude();
3264 double l2 = v2.SquareMagnitude();
3265 return (( dot * cos >= 0 ) &&
3266 ( dot * dot ) / l1 / l2 >= ( cos * cos ));
3269 CoplanarFaces::CoplanarFaces()
3270 : myFaceID(0), myToler(0)
3273 void CoplanarFaces::SetMesh( const SMDS_Mesh* theMesh )
3275 myMeshModifTracer.SetMesh( theMesh );
3276 if ( myMeshModifTracer.IsMeshModified() )
3278 // Build a set of coplanar face ids
3280 myCoplanarIDs.Clear();
3282 if ( !myMeshModifTracer.GetMesh() || !myFaceID || !myToler )
3285 const SMDS_MeshElement* face = myMeshModifTracer.GetMesh()->FindElement( myFaceID );
3286 if ( !face || face->GetType() != SMDSAbs_Face )
3290 gp_Vec myNorm = getNormale( static_cast<const SMDS_MeshFace*>(face), &normOK );
3294 const double cosTol = Cos( myToler * M_PI / 180. );
3295 NCollection_Map< SMESH_TLink, SMESH_TLink > checkedLinks;
3297 std::list< std::pair< const SMDS_MeshElement*, gp_Vec > > faceQueue;
3298 faceQueue.push_back( std::make_pair( face, myNorm ));
3299 while ( !faceQueue.empty() )
3301 face = faceQueue.front().first;
3302 myNorm = faceQueue.front().second;
3303 faceQueue.pop_front();
3305 for ( int i = 0, nbN = face->NbCornerNodes(); i < nbN; ++i )
3307 const SMDS_MeshNode* n1 = face->GetNode( i );
3308 const SMDS_MeshNode* n2 = face->GetNode(( i+1 )%nbN);
3309 if ( !checkedLinks.Add( SMESH_TLink( n1, n2 )))
3311 SMDS_ElemIteratorPtr fIt = n1->GetInverseElementIterator(SMDSAbs_Face);
3312 while ( fIt->more() )
3314 const SMDS_MeshElement* f = fIt->next();
3315 if ( f->GetNodeIndex( n2 ) > -1 )
3317 gp_Vec norm = getNormale( static_cast<const SMDS_MeshFace*>(f), &normOK );
3318 if (!normOK || isLessAngle( myNorm, norm, cosTol))
3320 myCoplanarIDs.Add( f->GetID() );
3321 faceQueue.push_back( std::make_pair( f, norm ));
3329 bool CoplanarFaces::IsSatisfy( long theElementId )
3331 return myCoplanarIDs.Contains( theElementId );
3336 *Description : Predicate for Range of Ids.
3337 * Range may be specified with two ways.
3338 * 1. Using AddToRange method
3339 * 2. With SetRangeStr method. Parameter of this method is a string
3340 * like as "1,2,3,50-60,63,67,70-"
3343 //=======================================================================
3344 // name : RangeOfIds
3345 // Purpose : Constructor
3346 //=======================================================================
3347 RangeOfIds::RangeOfIds()
3350 myType = SMDSAbs_All;
3353 //=======================================================================
3355 // Purpose : Set mesh
3356 //=======================================================================
3357 void RangeOfIds::SetMesh( const SMDS_Mesh* theMesh )
3362 //=======================================================================
3363 // name : AddToRange
3364 // Purpose : Add ID to the range
3365 //=======================================================================
3366 bool RangeOfIds::AddToRange( long theEntityId )
3368 myIds.Add( theEntityId );
3372 //=======================================================================
3373 // name : GetRangeStr
3374 // Purpose : Get range as a string.
3375 // Example: "1,2,3,50-60,63,67,70-"
3376 //=======================================================================
3377 void RangeOfIds::GetRangeStr( TCollection_AsciiString& theResStr )
3381 TColStd_SequenceOfInteger anIntSeq;
3382 TColStd_SequenceOfAsciiString aStrSeq;
3384 TColStd_MapIteratorOfMapOfInteger anIter( myIds );
3385 for ( ; anIter.More(); anIter.Next() )
3387 int anId = anIter.Key();
3388 TCollection_AsciiString aStr( anId );
3389 anIntSeq.Append( anId );
3390 aStrSeq.Append( aStr );
3393 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
3395 int aMinId = myMin( i );
3396 int aMaxId = myMax( i );
3398 TCollection_AsciiString aStr;
3399 if ( aMinId != IntegerFirst() )
3404 if ( aMaxId != IntegerLast() )
3407 // find position of the string in result sequence and insert string in it
3408 if ( anIntSeq.Length() == 0 )
3410 anIntSeq.Append( aMinId );
3411 aStrSeq.Append( aStr );
3415 if ( aMinId < anIntSeq.First() )
3417 anIntSeq.Prepend( aMinId );
3418 aStrSeq.Prepend( aStr );
3420 else if ( aMinId > anIntSeq.Last() )
3422 anIntSeq.Append( aMinId );
3423 aStrSeq.Append( aStr );
3426 for ( int j = 1, k = anIntSeq.Length(); j <= k; j++ )
3427 if ( aMinId < anIntSeq( j ) )
3429 anIntSeq.InsertBefore( j, aMinId );
3430 aStrSeq.InsertBefore( j, aStr );
3436 if ( aStrSeq.Length() == 0 )
3439 theResStr = aStrSeq( 1 );
3440 for ( int j = 2, k = aStrSeq.Length(); j <= k; j++ )
3443 theResStr += aStrSeq( j );
3447 //=======================================================================
3448 // name : SetRangeStr
3449 // Purpose : Define range with string
3450 // Example of entry string: "1,2,3,50-60,63,67,70-"
3451 //=======================================================================
3452 bool RangeOfIds::SetRangeStr( const TCollection_AsciiString& theStr )
3458 TCollection_AsciiString aStr = theStr;
3459 for ( int i = 1; i <= aStr.Length(); ++i )
3461 char c = aStr.Value( i );
3462 if ( !isdigit( c ) && c != ',' && c != '-' )
3463 aStr.SetValue( i, ',');
3465 aStr.RemoveAll( ' ' );
3467 TCollection_AsciiString tmpStr = aStr.Token( ",", 1 );
3469 while ( tmpStr != "" )
3471 tmpStr = aStr.Token( ",", i++ );
3472 int aPos = tmpStr.Search( '-' );
3476 if ( tmpStr.IsIntegerValue() )
3477 myIds.Add( tmpStr.IntegerValue() );
3483 TCollection_AsciiString aMaxStr = tmpStr.Split( aPos );
3484 TCollection_AsciiString aMinStr = tmpStr;
3486 while ( aMinStr.Search( "-" ) != -1 ) aMinStr.RemoveAll( '-' );
3487 while ( aMaxStr.Search( "-" ) != -1 ) aMaxStr.RemoveAll( '-' );
3489 if ( (!aMinStr.IsEmpty() && !aMinStr.IsIntegerValue()) ||
3490 (!aMaxStr.IsEmpty() && !aMaxStr.IsIntegerValue()) )
3493 myMin.Append( aMinStr.IsEmpty() ? IntegerFirst() : aMinStr.IntegerValue() );
3494 myMax.Append( aMaxStr.IsEmpty() ? IntegerLast() : aMaxStr.IntegerValue() );
3501 //=======================================================================
3503 // Purpose : Get type of supported entities
3504 //=======================================================================
3505 SMDSAbs_ElementType RangeOfIds::GetType() const
3510 //=======================================================================
3512 // Purpose : Set type of supported entities
3513 //=======================================================================
3514 void RangeOfIds::SetType( SMDSAbs_ElementType theType )
3519 //=======================================================================
3521 // Purpose : Verify whether entity satisfies to this rpedicate
3522 //=======================================================================
3523 bool RangeOfIds::IsSatisfy( long theId )
3528 if ( myType == SMDSAbs_Node )
3530 if ( myMesh->FindNode( theId ) == 0 )
3535 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
3536 if ( anElem == 0 || (myType != anElem->GetType() && myType != SMDSAbs_All ))
3540 if ( myIds.Contains( theId ) )
3543 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
3544 if ( theId >= myMin( i ) && theId <= myMax( i ) )
3552 Description : Base class for comparators
3554 Comparator::Comparator():
3558 Comparator::~Comparator()
3561 void Comparator::SetMesh( const SMDS_Mesh* theMesh )
3564 myFunctor->SetMesh( theMesh );
3567 void Comparator::SetMargin( double theValue )
3569 myMargin = theValue;
3572 void Comparator::SetNumFunctor( NumericalFunctorPtr theFunct )
3574 myFunctor = theFunct;
3577 SMDSAbs_ElementType Comparator::GetType() const
3579 return myFunctor ? myFunctor->GetType() : SMDSAbs_All;
3582 double Comparator::GetMargin()
3590 Description : Comparator "<"
3592 bool LessThan::IsSatisfy( long theId )
3594 return myFunctor && myFunctor->GetValue( theId ) < myMargin;
3600 Description : Comparator ">"
3602 bool MoreThan::IsSatisfy( long theId )
3604 return myFunctor && myFunctor->GetValue( theId ) > myMargin;
3610 Description : Comparator "="
3613 myToler(Precision::Confusion())
3616 bool EqualTo::IsSatisfy( long theId )
3618 return myFunctor && fabs( myFunctor->GetValue( theId ) - myMargin ) < myToler;
3621 void EqualTo::SetTolerance( double theToler )
3626 double EqualTo::GetTolerance()
3633 Description : Logical NOT predicate
3635 LogicalNOT::LogicalNOT()
3638 LogicalNOT::~LogicalNOT()
3641 bool LogicalNOT::IsSatisfy( long theId )
3643 return myPredicate && !myPredicate->IsSatisfy( theId );
3646 void LogicalNOT::SetMesh( const SMDS_Mesh* theMesh )
3649 myPredicate->SetMesh( theMesh );
3652 void LogicalNOT::SetPredicate( PredicatePtr thePred )
3654 myPredicate = thePred;
3657 SMDSAbs_ElementType LogicalNOT::GetType() const
3659 return myPredicate ? myPredicate->GetType() : SMDSAbs_All;
3664 Class : LogicalBinary
3665 Description : Base class for binary logical predicate
3667 LogicalBinary::LogicalBinary()
3670 LogicalBinary::~LogicalBinary()
3673 void LogicalBinary::SetMesh( const SMDS_Mesh* theMesh )
3676 myPredicate1->SetMesh( theMesh );
3679 myPredicate2->SetMesh( theMesh );
3682 void LogicalBinary::SetPredicate1( PredicatePtr thePredicate )
3684 myPredicate1 = thePredicate;
3687 void LogicalBinary::SetPredicate2( PredicatePtr thePredicate )
3689 myPredicate2 = thePredicate;
3692 SMDSAbs_ElementType LogicalBinary::GetType() const
3694 if ( !myPredicate1 || !myPredicate2 )
3697 SMDSAbs_ElementType aType1 = myPredicate1->GetType();
3698 SMDSAbs_ElementType aType2 = myPredicate2->GetType();
3700 return aType1 == aType2 ? aType1 : SMDSAbs_All;
3706 Description : Logical AND
3708 bool LogicalAND::IsSatisfy( long theId )
3713 myPredicate1->IsSatisfy( theId ) &&
3714 myPredicate2->IsSatisfy( theId );
3720 Description : Logical OR
3722 bool LogicalOR::IsSatisfy( long theId )
3727 (myPredicate1->IsSatisfy( theId ) ||
3728 myPredicate2->IsSatisfy( theId ));
3737 // #include <tbb/parallel_for.h>
3738 // #include <tbb/enumerable_thread_specific.h>
3740 // namespace Parallel
3742 // typedef tbb::enumerable_thread_specific< TIdSequence > TIdSeq;
3746 // const SMDS_Mesh* myMesh;
3747 // PredicatePtr myPredicate;
3748 // TIdSeq & myOKIds;
3749 // Predicate( const SMDS_Mesh* m, PredicatePtr p, TIdSeq & ids ):
3750 // myMesh(m), myPredicate(p->Duplicate()), myOKIds(ids) {}
3751 // void operator() ( const tbb::blocked_range<size_t>& r ) const
3753 // for ( size_t i = r.begin(); i != r.end(); ++i )
3754 // if ( myPredicate->IsSatisfy( i ))
3755 // myOKIds.local().push_back();
3767 void Filter::SetPredicate( PredicatePtr thePredicate )
3769 myPredicate = thePredicate;
3772 void Filter::GetElementsId( const SMDS_Mesh* theMesh,
3773 PredicatePtr thePredicate,
3774 TIdSequence& theSequence,
3775 SMDS_ElemIteratorPtr theElements )
3777 theSequence.clear();
3779 if ( !theMesh || !thePredicate )
3782 thePredicate->SetMesh( theMesh );
3785 theElements = theMesh->elementsIterator( thePredicate->GetType() );
3787 if ( theElements ) {
3788 while ( theElements->more() ) {
3789 const SMDS_MeshElement* anElem = theElements->next();
3790 if ( thePredicate->GetType() == SMDSAbs_All ||
3791 thePredicate->GetType() == anElem->GetType() )
3793 long anId = anElem->GetID();
3794 if ( thePredicate->IsSatisfy( anId ) )
3795 theSequence.push_back( anId );
3801 void Filter::GetElementsId( const SMDS_Mesh* theMesh,
3802 Filter::TIdSequence& theSequence,
3803 SMDS_ElemIteratorPtr theElements )
3805 GetElementsId(theMesh,myPredicate,theSequence,theElements);
3812 typedef std::set<SMDS_MeshFace*> TMapOfFacePtr;
3818 ManifoldPart::Link::Link( SMDS_MeshNode* theNode1,
3819 SMDS_MeshNode* theNode2 )
3825 ManifoldPart::Link::~Link()
3831 bool ManifoldPart::Link::IsEqual( const ManifoldPart::Link& theLink ) const
3833 if ( myNode1 == theLink.myNode1 &&
3834 myNode2 == theLink.myNode2 )
3836 else if ( myNode1 == theLink.myNode2 &&
3837 myNode2 == theLink.myNode1 )
3843 bool ManifoldPart::Link::operator<( const ManifoldPart::Link& x ) const
3845 if(myNode1 < x.myNode1) return true;
3846 if(myNode1 == x.myNode1)
3847 if(myNode2 < x.myNode2) return true;
3851 bool ManifoldPart::IsEqual( const ManifoldPart::Link& theLink1,
3852 const ManifoldPart::Link& theLink2 )
3854 return theLink1.IsEqual( theLink2 );
3857 ManifoldPart::ManifoldPart()
3860 myAngToler = Precision::Angular();
3861 myIsOnlyManifold = true;
3864 ManifoldPart::~ManifoldPart()
3869 void ManifoldPart::SetMesh( const SMDS_Mesh* theMesh )
3875 SMDSAbs_ElementType ManifoldPart::GetType() const
3876 { return SMDSAbs_Face; }
3878 bool ManifoldPart::IsSatisfy( long theElementId )
3880 return myMapIds.Contains( theElementId );
3883 void ManifoldPart::SetAngleTolerance( const double theAngToler )
3884 { myAngToler = theAngToler; }
3886 double ManifoldPart::GetAngleTolerance() const
3887 { return myAngToler; }
3889 void ManifoldPart::SetIsOnlyManifold( const bool theIsOnly )
3890 { myIsOnlyManifold = theIsOnly; }
3892 void ManifoldPart::SetStartElem( const long theStartId )
3893 { myStartElemId = theStartId; }
3895 bool ManifoldPart::process()
3898 myMapBadGeomIds.Clear();
3900 myAllFacePtr.clear();
3901 myAllFacePtrIntDMap.clear();
3905 // collect all faces into own map
3906 SMDS_FaceIteratorPtr anFaceItr = myMesh->facesIterator();
3907 for (; anFaceItr->more(); )
3909 SMDS_MeshFace* aFacePtr = (SMDS_MeshFace*)anFaceItr->next();
3910 myAllFacePtr.push_back( aFacePtr );
3911 myAllFacePtrIntDMap[aFacePtr] = myAllFacePtr.size()-1;
3914 SMDS_MeshFace* aStartFace = (SMDS_MeshFace*)myMesh->FindElement( myStartElemId );
3918 // the map of non manifold links and bad geometry
3919 TMapOfLink aMapOfNonManifold;
3920 TColStd_MapOfInteger aMapOfTreated;
3922 // begin cycle on faces from start index and run on vector till the end
3923 // and from begin to start index to cover whole vector
3924 const int aStartIndx = myAllFacePtrIntDMap[aStartFace];
3925 bool isStartTreat = false;
3926 for ( int fi = aStartIndx; !isStartTreat || fi != aStartIndx ; fi++ )
3928 if ( fi == aStartIndx )
3929 isStartTreat = true;
3930 // as result next time when fi will be equal to aStartIndx
3932 SMDS_MeshFace* aFacePtr = myAllFacePtr[ fi ];
3933 if ( aMapOfTreated.Contains( aFacePtr->GetID() ) )
3936 aMapOfTreated.Add( aFacePtr->GetID() );
3937 TColStd_MapOfInteger aResFaces;
3938 if ( !findConnected( myAllFacePtrIntDMap, aFacePtr,
3939 aMapOfNonManifold, aResFaces ) )
3941 TColStd_MapIteratorOfMapOfInteger anItr( aResFaces );
3942 for ( ; anItr.More(); anItr.Next() )
3944 int aFaceId = anItr.Key();
3945 aMapOfTreated.Add( aFaceId );
3946 myMapIds.Add( aFaceId );
3949 if ( fi == int( myAllFacePtr.size() - 1 ))
3951 } // end run on vector of faces
3952 return !myMapIds.IsEmpty();
3955 static void getLinks( const SMDS_MeshFace* theFace,
3956 ManifoldPart::TVectorOfLink& theLinks )
3958 int aNbNode = theFace->NbNodes();
3959 SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
3961 SMDS_MeshNode* aNode = 0;
3962 for ( ; aNodeItr->more() && i <= aNbNode; )
3965 SMDS_MeshNode* aN1 = (SMDS_MeshNode*)aNodeItr->next();
3969 SMDS_MeshNode* aN2 = ( i >= aNbNode ) ? aNode : (SMDS_MeshNode*)aNodeItr->next();
3971 ManifoldPart::Link aLink( aN1, aN2 );
3972 theLinks.push_back( aLink );
3976 bool ManifoldPart::findConnected
3977 ( const ManifoldPart::TDataMapFacePtrInt& theAllFacePtrInt,
3978 SMDS_MeshFace* theStartFace,
3979 ManifoldPart::TMapOfLink& theNonManifold,
3980 TColStd_MapOfInteger& theResFaces )
3982 theResFaces.Clear();
3983 if ( !theAllFacePtrInt.size() )
3986 if ( getNormale( theStartFace ).SquareModulus() <= gp::Resolution() )
3988 myMapBadGeomIds.Add( theStartFace->GetID() );
3992 ManifoldPart::TMapOfLink aMapOfBoundary, aMapToSkip;
3993 ManifoldPart::TVectorOfLink aSeqOfBoundary;
3994 theResFaces.Add( theStartFace->GetID() );
3995 ManifoldPart::TDataMapOfLinkFacePtr aDMapLinkFace;
3997 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
3998 aDMapLinkFace, theNonManifold, theStartFace );
4000 bool isDone = false;
4001 while ( !isDone && aMapOfBoundary.size() != 0 )
4003 bool isToReset = false;
4004 ManifoldPart::TVectorOfLink::iterator pLink = aSeqOfBoundary.begin();
4005 for ( ; !isToReset && pLink != aSeqOfBoundary.end(); ++pLink )
4007 ManifoldPart::Link aLink = *pLink;
4008 if ( aMapToSkip.find( aLink ) != aMapToSkip.end() )
4010 // each link could be treated only once
4011 aMapToSkip.insert( aLink );
4013 ManifoldPart::TVectorOfFacePtr aFaces;
4015 if ( myIsOnlyManifold &&
4016 (theNonManifold.find( aLink ) != theNonManifold.end()) )
4020 getFacesByLink( aLink, aFaces );
4021 // filter the element to keep only indicated elements
4022 ManifoldPart::TVectorOfFacePtr aFiltered;
4023 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
4024 for ( ; pFace != aFaces.end(); ++pFace )
4026 SMDS_MeshFace* aFace = *pFace;
4027 if ( myAllFacePtrIntDMap.find( aFace ) != myAllFacePtrIntDMap.end() )
4028 aFiltered.push_back( aFace );
4031 if ( aFaces.size() < 2 ) // no neihgbour faces
4033 else if ( myIsOnlyManifold && aFaces.size() > 2 ) // non manifold case
4035 theNonManifold.insert( aLink );
4040 // compare normal with normals of neighbor element
4041 SMDS_MeshFace* aPrevFace = aDMapLinkFace[ aLink ];
4042 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
4043 for ( ; pFace != aFaces.end(); ++pFace )
4045 SMDS_MeshFace* aNextFace = *pFace;
4046 if ( aPrevFace == aNextFace )
4048 int anNextFaceID = aNextFace->GetID();
4049 if ( myIsOnlyManifold && theResFaces.Contains( anNextFaceID ) )
4050 // should not be with non manifold restriction. probably bad topology
4052 // check if face was treated and skipped
4053 if ( myMapBadGeomIds.Contains( anNextFaceID ) ||
4054 !isInPlane( aPrevFace, aNextFace ) )
4056 // add new element to connected and extend the boundaries.
4057 theResFaces.Add( anNextFaceID );
4058 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
4059 aDMapLinkFace, theNonManifold, aNextFace );
4063 isDone = !isToReset;
4066 return !theResFaces.IsEmpty();
4069 bool ManifoldPart::isInPlane( const SMDS_MeshFace* theFace1,
4070 const SMDS_MeshFace* theFace2 )
4072 gp_Dir aNorm1 = gp_Dir( getNormale( theFace1 ) );
4073 gp_XYZ aNorm2XYZ = getNormale( theFace2 );
4074 if ( aNorm2XYZ.SquareModulus() <= gp::Resolution() )
4076 myMapBadGeomIds.Add( theFace2->GetID() );
4079 if ( aNorm1.IsParallel( gp_Dir( aNorm2XYZ ), myAngToler ) )
4085 void ManifoldPart::expandBoundary
4086 ( ManifoldPart::TMapOfLink& theMapOfBoundary,
4087 ManifoldPart::TVectorOfLink& theSeqOfBoundary,
4088 ManifoldPart::TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
4089 ManifoldPart::TMapOfLink& theNonManifold,
4090 SMDS_MeshFace* theNextFace ) const
4092 ManifoldPart::TVectorOfLink aLinks;
4093 getLinks( theNextFace, aLinks );
4094 int aNbLink = (int)aLinks.size();
4095 for ( int i = 0; i < aNbLink; i++ )
4097 ManifoldPart::Link aLink = aLinks[ i ];
4098 if ( myIsOnlyManifold && (theNonManifold.find( aLink ) != theNonManifold.end()) )
4100 if ( theMapOfBoundary.find( aLink ) != theMapOfBoundary.end() )
4102 if ( myIsOnlyManifold )
4104 // remove from boundary
4105 theMapOfBoundary.erase( aLink );
4106 ManifoldPart::TVectorOfLink::iterator pLink = theSeqOfBoundary.begin();
4107 for ( ; pLink != theSeqOfBoundary.end(); ++pLink )
4109 ManifoldPart::Link aBoundLink = *pLink;
4110 if ( aBoundLink.IsEqual( aLink ) )
4112 theSeqOfBoundary.erase( pLink );
4120 theMapOfBoundary.insert( aLink );
4121 theSeqOfBoundary.push_back( aLink );
4122 theDMapLinkFacePtr[ aLink ] = theNextFace;
4127 void ManifoldPart::getFacesByLink( const ManifoldPart::Link& theLink,
4128 ManifoldPart::TVectorOfFacePtr& theFaces ) const
4131 // take all faces that shared first node
4132 SMDS_ElemIteratorPtr anItr = theLink.myNode1->GetInverseElementIterator( SMDSAbs_Face );
4133 SMDS_StdIterator< const SMDS_MeshElement*, SMDS_ElemIteratorPtr > faces( anItr ), facesEnd;
4134 std::set<const SMDS_MeshElement *> aSetOfFaces( faces, facesEnd );
4136 // take all faces that shared second node
4137 anItr = theLink.myNode2->GetInverseElementIterator( SMDSAbs_Face );
4138 // find the common part of two sets
4139 for ( ; anItr->more(); )
4141 const SMDS_MeshElement* aFace = anItr->next();
4142 if ( aSetOfFaces.count( aFace ))
4143 theFaces.push_back( (SMDS_MeshFace*) aFace );
4148 Class : BelongToMeshGroup
4149 Description : Verify whether a mesh element is included into a mesh group
4151 BelongToMeshGroup::BelongToMeshGroup(): myGroup( 0 )
4155 void BelongToMeshGroup::SetGroup( SMESHDS_GroupBase* g )
4160 void BelongToMeshGroup::SetStoreName( const std::string& sn )
4165 void BelongToMeshGroup::SetMesh( const SMDS_Mesh* theMesh )
4167 if ( myGroup && myGroup->GetMesh() != theMesh )
4171 if ( !myGroup && !myStoreName.empty() )
4173 if ( const SMESHDS_Mesh* aMesh = dynamic_cast<const SMESHDS_Mesh*>(theMesh))
4175 const std::set<SMESHDS_GroupBase*>& grps = aMesh->GetGroups();
4176 std::set<SMESHDS_GroupBase*>::const_iterator g = grps.begin();
4177 for ( ; g != grps.end() && !myGroup; ++g )
4178 if ( *g && myStoreName == (*g)->GetStoreName() )
4184 myGroup->IsEmpty(); // make GroupOnFilter update its predicate
4188 bool BelongToMeshGroup::IsSatisfy( long theElementId )
4190 return myGroup ? myGroup->Contains( theElementId ) : false;
4193 SMDSAbs_ElementType BelongToMeshGroup::GetType() const
4195 return myGroup ? myGroup->GetType() : SMDSAbs_All;
4198 //================================================================================
4199 // ElementsOnSurface
4200 //================================================================================
4202 ElementsOnSurface::ElementsOnSurface()
4205 myType = SMDSAbs_All;
4207 myToler = Precision::Confusion();
4208 myUseBoundaries = false;
4211 ElementsOnSurface::~ElementsOnSurface()
4215 void ElementsOnSurface::SetMesh( const SMDS_Mesh* theMesh )
4217 myMeshModifTracer.SetMesh( theMesh );
4218 if ( myMeshModifTracer.IsMeshModified())
4222 bool ElementsOnSurface::IsSatisfy( long theElementId )
4224 return myIds.Contains( theElementId );
4227 SMDSAbs_ElementType ElementsOnSurface::GetType() const
4230 void ElementsOnSurface::SetTolerance( const double theToler )
4232 if ( myToler != theToler )
4239 double ElementsOnSurface::GetTolerance() const
4242 void ElementsOnSurface::SetUseBoundaries( bool theUse )
4244 if ( myUseBoundaries != theUse ) {
4245 myUseBoundaries = theUse;
4246 SetSurface( mySurf, myType );
4250 void ElementsOnSurface::SetSurface( const TopoDS_Shape& theShape,
4251 const SMDSAbs_ElementType theType )
4256 if ( theShape.IsNull() || theShape.ShapeType() != TopAbs_FACE )
4258 mySurf = TopoDS::Face( theShape );
4259 BRepAdaptor_Surface SA( mySurf, myUseBoundaries );
4261 u1 = SA.FirstUParameter(),
4262 u2 = SA.LastUParameter(),
4263 v1 = SA.FirstVParameter(),
4264 v2 = SA.LastVParameter();
4265 Handle(Geom_Surface) surf = BRep_Tool::Surface( mySurf );
4266 myProjector.Init( surf, u1,u2, v1,v2 );
4270 void ElementsOnSurface::process()
4273 if ( mySurf.IsNull() )
4276 if ( !myMeshModifTracer.GetMesh() )
4279 myIds.ReSize( myMeshModifTracer.GetMesh()->GetMeshInfo().NbElements( myType ));
4281 SMDS_ElemIteratorPtr anIter = myMeshModifTracer.GetMesh()->elementsIterator( myType );
4282 for(; anIter->more(); )
4283 process( anIter->next() );
4286 void ElementsOnSurface::process( const SMDS_MeshElement* theElemPtr )
4288 SMDS_ElemIteratorPtr aNodeItr = theElemPtr->nodesIterator();
4289 bool isSatisfy = true;
4290 for ( ; aNodeItr->more(); )
4292 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
4293 if ( !isOnSurface( aNode ) )
4300 myIds.Add( theElemPtr->GetID() );
4303 bool ElementsOnSurface::isOnSurface( const SMDS_MeshNode* theNode )
4305 if ( mySurf.IsNull() )
4308 gp_Pnt aPnt( theNode->X(), theNode->Y(), theNode->Z() );
4309 // double aToler2 = myToler * myToler;
4310 // if ( mySurf->IsKind(STANDARD_TYPE(Geom_Plane)))
4312 // gp_Pln aPln = Handle(Geom_Plane)::DownCast(mySurf)->Pln();
4313 // if ( aPln.SquareDistance( aPnt ) > aToler2 )
4316 // else if ( mySurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)))
4318 // gp_Cylinder aCyl = Handle(Geom_CylindricalSurface)::DownCast(mySurf)->Cylinder();
4319 // double aRad = aCyl.Radius();
4320 // gp_Ax3 anAxis = aCyl.Position();
4321 // gp_XYZ aLoc = aCyl.Location().XYZ();
4322 // double aXDist = anAxis.XDirection().XYZ() * ( aPnt.XYZ() - aLoc );
4323 // double aYDist = anAxis.YDirection().XYZ() * ( aPnt.XYZ() - aLoc );
4324 // if ( fabs(aXDist*aXDist + aYDist*aYDist - aRad*aRad) > aToler2 )
4329 myProjector.Perform( aPnt );
4330 bool isOn = ( myProjector.IsDone() && myProjector.LowerDistance() <= myToler );
4336 //================================================================================
4338 //================================================================================
4341 const int theIsCheckedFlag = 0x0000100;
4344 struct ElementsOnShape::Classifier
4346 Classifier() { mySolidClfr = 0; myFlags = 0; }
4348 void Init(const TopoDS_Shape& s, double tol, const Bnd_B3d* box = 0 );
4349 bool IsOut(const gp_Pnt& p) { return SetChecked( true ), (this->*myIsOutFun)( p ); }
4350 TopAbs_ShapeEnum ShapeType() const { return myShape.ShapeType(); }
4351 const TopoDS_Shape& Shape() const { return myShape; }
4352 const Bnd_B3d* GetBndBox() const { return & myBox; }
4353 double Tolerance() const { return myTol; }
4354 bool IsChecked() { return myFlags & theIsCheckedFlag; }
4355 bool IsSetFlag( int flag ) const { return myFlags & flag; }
4356 void SetChecked( bool is ) { is ? SetFlag( theIsCheckedFlag ) : UnsetFlag( theIsCheckedFlag ); }
4357 void SetFlag ( int flag ) { myFlags |= flag; }
4358 void UnsetFlag( int flag ) { myFlags &= ~flag; }
4361 bool isOutOfSolid (const gp_Pnt& p);
4362 bool isOutOfBox (const gp_Pnt& p);
4363 bool isOutOfFace (const gp_Pnt& p);
4364 bool isOutOfEdge (const gp_Pnt& p);
4365 bool isOutOfVertex(const gp_Pnt& p);
4366 bool isOutOfNone (const gp_Pnt& /*p*/) { return true; }
4367 bool isBox (const TopoDS_Shape& s);
4369 TopoDS_Shape prepareSolid( const TopoDS_Shape& theSolid );
4371 bool (Classifier::* myIsOutFun)(const gp_Pnt& p);
4372 BRepClass3d_SolidClassifier* mySolidClfr; // ptr because of a run-time forbidden copy-constructor
4374 GeomAPI_ProjectPointOnSurf myProjFace;
4375 GeomAPI_ProjectPointOnCurve myProjEdge;
4377 TopoDS_Shape myShape;
4382 struct ElementsOnShape::OctreeClassifier : public SMESH_Octree
4384 OctreeClassifier( const std::vector< ElementsOnShape::Classifier* >& classifiers );
4385 OctreeClassifier( const OctreeClassifier* otherTree,
4386 const std::vector< ElementsOnShape::Classifier >& clsOther,
4387 std::vector< ElementsOnShape::Classifier >& cls );
4388 void GetClassifiersAtPoint( const gp_XYZ& p,
4389 std::vector< ElementsOnShape::Classifier* >& classifiers );
4393 OctreeClassifier() {}
4394 SMESH_Octree* newChild() const { return new OctreeClassifier; }
4395 void buildChildrenData();
4396 Bnd_B3d* buildRootBox();
4398 std::vector< ElementsOnShape::Classifier* > myClassifiers;
4402 ElementsOnShape::ElementsOnShape():
4404 myType(SMDSAbs_All),
4405 myToler(Precision::Confusion()),
4406 myAllNodesFlag(false)
4410 ElementsOnShape::~ElementsOnShape()
4415 Predicate* ElementsOnShape::clone() const
4417 size_t size = sizeof( *this );
4419 size += myOctree->GetSize();
4420 if ( !myClassifiers.empty() )
4421 size += sizeof( myClassifiers[0] ) * myClassifiers.size();
4422 if ( !myWorkClassifiers.empty() )
4423 size += sizeof( myWorkClassifiers[0] ) * myWorkClassifiers.size();
4424 if ( size > 1e+9 ) // 1G
4427 std::cout << "Avoid ElementsOnShape::clone(), too large: " << size << " bytes " << std::endl;
4432 ElementsOnShape* cln = new ElementsOnShape();
4433 cln->SetAllNodes ( myAllNodesFlag );
4434 cln->SetTolerance( myToler );
4435 cln->SetMesh ( myMeshModifTracer.GetMesh() );
4436 cln->myShape = myShape; // avoid creation of myClassifiers
4437 cln->SetShape ( myShape, myType );
4438 cln->myClassifiers.resize( myClassifiers.size() );
4439 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4440 cln->myClassifiers[ i ].Init( BRepBuilderAPI_Copy( myClassifiers[ i ].Shape()),
4441 myToler, myClassifiers[ i ].GetBndBox() );
4442 if ( myOctree ) // copy myOctree
4444 cln->myOctree = new OctreeClassifier( myOctree, myClassifiers, cln->myClassifiers );
4449 SMDSAbs_ElementType ElementsOnShape::GetType() const
4454 void ElementsOnShape::SetTolerance (const double theToler)
4456 if (myToler != theToler) {
4458 SetShape(myShape, myType);
4462 double ElementsOnShape::GetTolerance() const
4467 void ElementsOnShape::SetAllNodes (bool theAllNodes)
4469 myAllNodesFlag = theAllNodes;
4472 void ElementsOnShape::SetMesh (const SMDS_Mesh* theMesh)
4474 myMeshModifTracer.SetMesh( theMesh );
4475 if ( myMeshModifTracer.IsMeshModified())
4477 size_t nbNodes = theMesh ? theMesh->NbNodes() : 0;
4478 if ( myNodeIsChecked.size() == nbNodes )
4480 std::fill( myNodeIsChecked.begin(), myNodeIsChecked.end(), false );
4484 SMESHUtils::FreeVector( myNodeIsChecked );
4485 SMESHUtils::FreeVector( myNodeIsOut );
4486 myNodeIsChecked.resize( nbNodes, false );
4487 myNodeIsOut.resize( nbNodes );
4492 bool ElementsOnShape::getNodeIsOut( const SMDS_MeshNode* n, bool& isOut )
4494 if ( n->GetID() >= (int) myNodeIsChecked.size() ||
4495 !myNodeIsChecked[ n->GetID() ])
4498 isOut = myNodeIsOut[ n->GetID() ];
4502 void ElementsOnShape::setNodeIsOut( const SMDS_MeshNode* n, bool isOut )
4504 if ( n->GetID() < (int) myNodeIsChecked.size() )
4506 myNodeIsChecked[ n->GetID() ] = true;
4507 myNodeIsOut [ n->GetID() ] = isOut;
4511 void ElementsOnShape::SetShape (const TopoDS_Shape& theShape,
4512 const SMDSAbs_ElementType theType)
4514 bool shapeChanges = ( myShape != theShape );
4517 if ( myShape.IsNull() ) return;
4521 // find most complex shapes
4522 TopTools_IndexedMapOfShape shapesMap;
4523 TopAbs_ShapeEnum shapeTypes[4] = { TopAbs_SOLID, TopAbs_FACE, TopAbs_EDGE, TopAbs_VERTEX };
4524 TopExp_Explorer sub;
4525 for ( int i = 0; i < 4; ++i )
4527 if ( shapesMap.IsEmpty() )
4528 for ( sub.Init( myShape, shapeTypes[i] ); sub.More(); sub.Next() )
4529 shapesMap.Add( sub.Current() );
4531 for ( sub.Init( myShape, shapeTypes[i], shapeTypes[i-1] ); sub.More(); sub.Next() )
4532 shapesMap.Add( sub.Current() );
4536 myClassifiers.resize( shapesMap.Extent() );
4537 for ( int i = 0; i < shapesMap.Extent(); ++i )
4538 myClassifiers[ i ].Init( shapesMap( i+1 ), myToler );
4541 if ( theType == SMDSAbs_Node )
4543 SMESHUtils::FreeVector( myNodeIsChecked );
4544 SMESHUtils::FreeVector( myNodeIsOut );
4548 std::fill( myNodeIsChecked.begin(), myNodeIsChecked.end(), false );
4552 void ElementsOnShape::clearClassifiers()
4554 // for ( size_t i = 0; i < myClassifiers.size(); ++i )
4555 // delete myClassifiers[ i ];
4556 myClassifiers.clear();
4562 bool ElementsOnShape::IsSatisfy( long elemId )
4564 if ( myClassifiers.empty() )
4567 const SMDS_Mesh* mesh = myMeshModifTracer.GetMesh();
4568 if ( myType == SMDSAbs_Node )
4569 return IsSatisfy( mesh->FindNode( elemId ));
4570 return IsSatisfy( mesh->FindElement( elemId ));
4573 bool ElementsOnShape::IsSatisfy (const SMDS_MeshElement* elem)
4578 bool isSatisfy = myAllNodesFlag, isNodeOut;
4580 gp_XYZ centerXYZ (0, 0, 0);
4582 if ( !myOctree && myClassifiers.size() > 5 )
4584 myWorkClassifiers.resize( myClassifiers.size() );
4585 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4586 myWorkClassifiers[ i ] = & myClassifiers[ i ];
4587 myOctree = new OctreeClassifier( myWorkClassifiers );
4589 SMESHUtils::FreeVector( myWorkClassifiers );
4592 for ( int i = 0, nb = elem->NbNodes(); i < nb && (isSatisfy == myAllNodesFlag); ++i )
4594 SMESH_TNodeXYZ aPnt( elem->GetNode( i ));
4598 if ( !getNodeIsOut( aPnt._node, isNodeOut ))
4602 myWorkClassifiers.clear();
4603 myOctree->GetClassifiersAtPoint( aPnt, myWorkClassifiers );
4605 for ( size_t i = 0; i < myWorkClassifiers.size(); ++i )
4606 myWorkClassifiers[i]->SetChecked( false );
4608 for ( size_t i = 0; i < myWorkClassifiers.size() && isNodeOut; ++i )
4609 if ( !myWorkClassifiers[i]->IsChecked() )
4610 isNodeOut = myWorkClassifiers[i]->IsOut( aPnt );
4614 for ( size_t i = 0; i < myClassifiers.size() && isNodeOut; ++i )
4615 isNodeOut = myClassifiers[i].IsOut( aPnt );
4617 setNodeIsOut( aPnt._node, isNodeOut );
4619 isSatisfy = !isNodeOut;
4622 // Check the center point for volumes MantisBug 0020168
4625 myClassifiers[0].ShapeType() == TopAbs_SOLID )
4627 centerXYZ /= elem->NbNodes();
4631 myWorkClassifiers.clear();
4632 myOctree->GetClassifiersAtPoint( centerXYZ, myWorkClassifiers );
4633 for ( size_t i = 0; i < myWorkClassifiers.size() && !isSatisfy; ++i )
4634 isSatisfy = ! myWorkClassifiers[i]->IsOut( centerXYZ );
4638 for ( size_t i = 0; i < myClassifiers.size() && !isSatisfy; ++i )
4639 isSatisfy = ! myClassifiers[i].IsOut( centerXYZ );
4646 //================================================================================
4648 * \brief Check and optionally return a satisfying shape
4650 //================================================================================
4652 bool ElementsOnShape::IsSatisfy (const SMDS_MeshNode* node,
4653 TopoDS_Shape* okShape)
4658 if ( !myOctree && myClassifiers.size() > 5 )
4660 myWorkClassifiers.resize( myClassifiers.size() );
4661 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4662 myWorkClassifiers[ i ] = & myClassifiers[ i ];
4663 myOctree = new OctreeClassifier( myWorkClassifiers );
4666 bool isNodeOut = true;
4668 if ( okShape || !getNodeIsOut( node, isNodeOut ))
4670 SMESH_NodeXYZ aPnt = node;
4673 myWorkClassifiers.clear();
4674 myOctree->GetClassifiersAtPoint( aPnt, myWorkClassifiers );
4676 for ( size_t i = 0; i < myWorkClassifiers.size(); ++i )
4677 myWorkClassifiers[i]->SetChecked( false );
4679 for ( size_t i = 0; i < myWorkClassifiers.size(); ++i )
4680 if ( !myWorkClassifiers[i]->IsChecked() &&
4681 !myWorkClassifiers[i]->IsOut( aPnt ))
4685 *okShape = myWorkClassifiers[i]->Shape();
4691 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4692 if ( !myClassifiers[i].IsOut( aPnt ))
4696 *okShape = myClassifiers[i].Shape();
4700 setNodeIsOut( node, isNodeOut );
4706 void ElementsOnShape::Classifier::Init( const TopoDS_Shape& theShape,
4708 const Bnd_B3d* theBox )
4714 bool isShapeBox = false;
4715 switch ( myShape.ShapeType() )
4719 if (( isShapeBox = isBox( theShape )))
4721 myIsOutFun = & ElementsOnShape::Classifier::isOutOfBox;
4725 mySolidClfr = new BRepClass3d_SolidClassifier( prepareSolid( theShape ));
4726 myIsOutFun = & ElementsOnShape::Classifier::isOutOfSolid;
4732 Standard_Real u1,u2,v1,v2;
4733 Handle(Geom_Surface) surf = BRep_Tool::Surface( TopoDS::Face( theShape ));
4734 if ( surf.IsNull() )
4735 myIsOutFun = & ElementsOnShape::Classifier::isOutOfNone;
4738 surf->Bounds( u1,u2,v1,v2 );
4739 myProjFace.Init(surf, u1,u2, v1,v2, myTol );
4740 myIsOutFun = & ElementsOnShape::Classifier::isOutOfFace;
4746 Standard_Real u1, u2;
4747 Handle(Geom_Curve) curve = BRep_Tool::Curve( TopoDS::Edge( theShape ), u1, u2);
4748 if ( curve.IsNull() )
4749 myIsOutFun = & ElementsOnShape::Classifier::isOutOfNone;
4752 myProjEdge.Init(curve, u1, u2);
4753 myIsOutFun = & ElementsOnShape::Classifier::isOutOfEdge;
4759 myVertexXYZ = BRep_Tool::Pnt( TopoDS::Vertex( theShape ) );
4760 myIsOutFun = & ElementsOnShape::Classifier::isOutOfVertex;
4764 throw SALOME_Exception("Programmer error in usage of ElementsOnShape::Classifier");
4776 if ( myShape.ShapeType() == TopAbs_FACE )
4778 BRepAdaptor_Surface SA( TopoDS::Face( myShape ), /*useBoundaries=*/false );
4779 if ( SA.GetType() == GeomAbs_BSplineSurface )
4780 BRepBndLib::AddOptimal( myShape, box,
4781 /*useTriangulation=*/true, /*useShapeTolerance=*/true );
4784 BRepBndLib::Add( myShape, box );
4786 myBox.Add( box.CornerMin() );
4787 myBox.Add( box.CornerMax() );
4788 gp_XYZ halfSize = 0.5 * ( box.CornerMax().XYZ() - box.CornerMin().XYZ() );
4789 for ( int iDim = 1; iDim <= 3; ++iDim )
4791 double x = halfSize.Coord( iDim );
4792 halfSize.SetCoord( iDim, x + Max( myTol, 1e-2 * x ));
4794 myBox.SetHSize( halfSize );
4799 ElementsOnShape::Classifier::~Classifier()
4801 delete mySolidClfr; mySolidClfr = 0;
4804 TopoDS_Shape ElementsOnShape::Classifier::prepareSolid( const TopoDS_Shape& theSolid )
4806 // try to limit tolerance of theSolid down to myTol (issue #19026)
4808 // check if tolerance of theSolid is more than myTol
4809 bool tolIsOk = true; // max tolerance is at VERTEXes
4810 for ( TopExp_Explorer exp( theSolid, TopAbs_VERTEX ); exp.More() && tolIsOk; exp.Next() )
4811 tolIsOk = ( myTol >= BRep_Tool::Tolerance( TopoDS::Vertex( exp.Current() )));
4815 // make a copy to prevent the original shape from changes
4816 TopoDS_Shape resultShape = BRepBuilderAPI_Copy( theSolid );
4818 if ( !GEOMUtils::FixShapeTolerance( resultShape, TopAbs_SHAPE, myTol ))
4823 bool ElementsOnShape::Classifier::isOutOfSolid( const gp_Pnt& p )
4825 if ( isOutOfBox( p )) return true;
4826 mySolidClfr->Perform( p, myTol );
4827 return ( mySolidClfr->State() != TopAbs_IN && mySolidClfr->State() != TopAbs_ON );
4830 bool ElementsOnShape::Classifier::isOutOfBox( const gp_Pnt& p )
4832 return myBox.IsOut( p.XYZ() );
4835 bool ElementsOnShape::Classifier::isOutOfFace( const gp_Pnt& p )
4837 if ( isOutOfBox( p )) return true;
4838 myProjFace.Perform( p );
4839 if ( myProjFace.IsDone() && myProjFace.LowerDistance() <= myTol )
4841 // check relatively to the face
4843 myProjFace.LowerDistanceParameters(u, v);
4844 gp_Pnt2d aProjPnt (u, v);
4845 BRepClass_FaceClassifier aClsf ( TopoDS::Face( myShape ), aProjPnt, myTol );
4846 if ( aClsf.State() == TopAbs_IN || aClsf.State() == TopAbs_ON )
4852 bool ElementsOnShape::Classifier::isOutOfEdge( const gp_Pnt& p )
4854 if ( isOutOfBox( p )) return true;
4855 myProjEdge.Perform( p );
4856 return ! ( myProjEdge.NbPoints() > 0 && myProjEdge.LowerDistance() <= myTol );
4859 bool ElementsOnShape::Classifier::isOutOfVertex( const gp_Pnt& p )
4861 return ( myVertexXYZ.Distance( p ) > myTol );
4864 bool ElementsOnShape::Classifier::isBox(const TopoDS_Shape& theShape )
4866 TopTools_IndexedMapOfShape vMap;
4867 TopExp::MapShapes( theShape, TopAbs_VERTEX, vMap );
4868 if ( vMap.Extent() != 8 )
4872 for ( int i = 1; i <= 8; ++i )
4873 myBox.Add( BRep_Tool::Pnt( TopoDS::Vertex( vMap( i ))).XYZ() );
4875 gp_XYZ pMin = myBox.CornerMin(), pMax = myBox.CornerMax();
4876 for ( int i = 1; i <= 8; ++i )
4878 gp_Pnt p = BRep_Tool::Pnt( TopoDS::Vertex( vMap( i )));
4879 for ( int iC = 1; iC <= 3; ++ iC )
4881 double d1 = Abs( pMin.Coord( iC ) - p.Coord( iC ));
4882 double d2 = Abs( pMax.Coord( iC ) - p.Coord( iC ));
4883 if ( Min( d1, d2 ) > myTol )
4887 myBox.Enlarge( myTol );
4892 OctreeClassifier::OctreeClassifier( const std::vector< ElementsOnShape::Classifier* >& classifiers )
4893 :SMESH_Octree( new SMESH_TreeLimit )
4895 myClassifiers = classifiers;
4900 OctreeClassifier::OctreeClassifier( const OctreeClassifier* otherTree,
4901 const std::vector< ElementsOnShape::Classifier >& clsOther,
4902 std::vector< ElementsOnShape::Classifier >& cls )
4903 :SMESH_Octree( new SMESH_TreeLimit )
4905 myBox = new Bnd_B3d( *otherTree->getBox() );
4907 if (( myIsLeaf = otherTree->isLeaf() ))
4909 myClassifiers.resize( otherTree->myClassifiers.size() );
4910 for ( size_t i = 0; i < otherTree->myClassifiers.size(); ++i )
4912 int ind = otherTree->myClassifiers[i] - & clsOther[0];
4913 myClassifiers[ i ] = & cls[ ind ];
4916 else if ( otherTree->myChildren )
4918 myChildren = new SMESH_Tree< Bnd_B3d, 8 > * [ 8 ];
4919 for ( int i = 0; i < nbChildren(); i++ )
4921 new OctreeClassifier( static_cast<const OctreeClassifier*>( otherTree->myChildren[i]),
4926 void ElementsOnShape::
4927 OctreeClassifier::GetClassifiersAtPoint( const gp_XYZ& point,
4928 std::vector< ElementsOnShape::Classifier* >& result )
4930 if ( getBox()->IsOut( point ))
4935 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4936 if ( !myClassifiers[i]->GetBndBox()->IsOut( point ))
4937 result.push_back( myClassifiers[i] );
4941 for (int i = 0; i < nbChildren(); i++)
4942 ((OctreeClassifier*) myChildren[i])->GetClassifiersAtPoint( point, result );
4946 size_t ElementsOnShape::OctreeClassifier::GetSize()
4948 size_t res = sizeof( *this );
4949 if ( !myClassifiers.empty() )
4950 res += sizeof( myClassifiers[0] ) * myClassifiers.size();
4953 for (int i = 0; i < nbChildren(); i++)
4954 res += ((OctreeClassifier*) myChildren[i])->GetSize();
4959 void ElementsOnShape::OctreeClassifier::buildChildrenData()
4961 // distribute myClassifiers among myChildren
4963 const int childFlag[8] = { 0x0000001,
4971 int nbInChild[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
4973 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4975 for ( int j = 0; j < nbChildren(); j++ )
4977 if ( !myClassifiers[i]->GetBndBox()->IsOut( *myChildren[j]->getBox() ))
4979 myClassifiers[i]->SetFlag( childFlag[ j ]);
4985 for ( int j = 0; j < nbChildren(); j++ )
4987 OctreeClassifier* child = static_cast<OctreeClassifier*>( myChildren[ j ]);
4988 child->myClassifiers.resize( nbInChild[ j ]);
4989 for ( size_t i = 0; nbInChild[ j ] && i < myClassifiers.size(); ++i )
4991 if ( myClassifiers[ i ]->IsSetFlag( childFlag[ j ]))
4994 child->myClassifiers[ nbInChild[ j ]] = myClassifiers[ i ];
4995 myClassifiers[ i ]->UnsetFlag( childFlag[ j ]);
4999 SMESHUtils::FreeVector( myClassifiers );
5001 // define if a child isLeaf()
5002 for ( int i = 0; i < nbChildren(); i++ )
5004 OctreeClassifier* child = static_cast<OctreeClassifier*>( myChildren[ i ]);
5005 child->myIsLeaf = ( child->myClassifiers.size() <= 5 ||
5006 child->maxSize() < child->myClassifiers[0]->Tolerance() );
5010 Bnd_B3d* ElementsOnShape::OctreeClassifier::buildRootBox()
5012 Bnd_B3d* box = new Bnd_B3d;
5013 for ( size_t i = 0; i < myClassifiers.size(); ++i )
5014 box->Add( *myClassifiers[i]->GetBndBox() );
5019 Class : BelongToGeom
5020 Description : Predicate for verifying whether entity belongs to
5021 specified geometrical support
5024 BelongToGeom::BelongToGeom()
5026 myType(SMDSAbs_NbElementTypes),
5027 myIsSubshape(false),
5028 myTolerance(Precision::Confusion())
5031 Predicate* BelongToGeom::clone() const
5033 BelongToGeom* cln = 0;
5034 if ( myElementsOnShapePtr )
5035 if ( ElementsOnShape* eos = static_cast<ElementsOnShape*>( myElementsOnShapePtr->clone() ))
5037 cln = new BelongToGeom( *this );
5038 cln->myElementsOnShapePtr.reset( eos );
5043 void BelongToGeom::SetMesh( const SMDS_Mesh* theMesh )
5045 if ( myMeshDS != theMesh )
5047 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
5050 if ( myElementsOnShapePtr )
5051 myElementsOnShapePtr->SetMesh( myMeshDS );
5054 void BelongToGeom::SetGeom( const TopoDS_Shape& theShape )
5056 if ( myShape != theShape )
5063 static bool IsSubShape (const TopTools_IndexedMapOfShape& theMap,
5064 const TopoDS_Shape& theShape)
5066 if (theMap.Contains(theShape)) return true;
5068 if (theShape.ShapeType() == TopAbs_COMPOUND ||
5069 theShape.ShapeType() == TopAbs_COMPSOLID)
5071 TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
5072 for (; anIt.More(); anIt.Next())
5074 if (!IsSubShape(theMap, anIt.Value())) {
5084 void BelongToGeom::init()
5086 if ( !myMeshDS || myShape.IsNull() ) return;
5088 // is sub-shape of main shape?
5089 TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
5090 if (aMainShape.IsNull()) {
5091 myIsSubshape = false;
5094 TopTools_IndexedMapOfShape aMap;
5095 TopExp::MapShapes( aMainShape, aMap );
5096 myIsSubshape = IsSubShape( aMap, myShape );
5100 TopExp::MapShapes( myShape, aMap );
5101 mySubShapesIDs.Clear();
5102 for ( int i = 1; i <= aMap.Extent(); ++i )
5104 int subID = myMeshDS->ShapeToIndex( aMap( i ));
5106 mySubShapesIDs.Add( subID );
5111 //if (!myIsSubshape) // to be always ready to check an element not bound to geometry
5113 if ( !myElementsOnShapePtr )
5114 myElementsOnShapePtr.reset( new ElementsOnShape() );
5115 myElementsOnShapePtr->SetTolerance( myTolerance );
5116 myElementsOnShapePtr->SetAllNodes( true ); // "belong", while false means "lays on"
5117 myElementsOnShapePtr->SetMesh( myMeshDS );
5118 myElementsOnShapePtr->SetShape( myShape, myType );
5122 bool BelongToGeom::IsSatisfy (long theId)
5124 if (myMeshDS == 0 || myShape.IsNull())
5129 return myElementsOnShapePtr->IsSatisfy(theId);
5134 if (myType == SMDSAbs_Node)
5136 if ( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ))
5138 if ( aNode->getshapeId() < 1 )
5139 return myElementsOnShapePtr->IsSatisfy(theId);
5141 return mySubShapesIDs.Contains( aNode->getshapeId() );
5146 if ( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ))
5148 if ( myType == SMDSAbs_All || anElem->GetType() == myType )
5150 if ( anElem->getshapeId() < 1 )
5151 return myElementsOnShapePtr->IsSatisfy(theId);
5153 return mySubShapesIDs.Contains( anElem->getshapeId() );
5161 void BelongToGeom::SetType (SMDSAbs_ElementType theType)
5163 if ( myType != theType )
5170 SMDSAbs_ElementType BelongToGeom::GetType() const
5175 TopoDS_Shape BelongToGeom::GetShape()
5180 const SMESHDS_Mesh* BelongToGeom::GetMeshDS() const
5185 void BelongToGeom::SetTolerance (double theTolerance)
5187 myTolerance = theTolerance;
5191 double BelongToGeom::GetTolerance()
5198 Description : Predicate for verifying whether entiy lying or partially lying on
5199 specified geometrical support
5202 LyingOnGeom::LyingOnGeom()
5204 myType(SMDSAbs_NbElementTypes),
5205 myIsSubshape(false),
5206 myTolerance(Precision::Confusion())
5209 Predicate* LyingOnGeom::clone() const
5211 LyingOnGeom* cln = 0;
5212 if ( myElementsOnShapePtr )
5213 if ( ElementsOnShape* eos = static_cast<ElementsOnShape*>( myElementsOnShapePtr->clone() ))
5215 cln = new LyingOnGeom( *this );
5216 cln->myElementsOnShapePtr.reset( eos );
5221 void LyingOnGeom::SetMesh( const SMDS_Mesh* theMesh )
5223 if ( myMeshDS != theMesh )
5225 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
5228 if ( myElementsOnShapePtr )
5229 myElementsOnShapePtr->SetMesh( myMeshDS );
5232 void LyingOnGeom::SetGeom( const TopoDS_Shape& theShape )
5234 if ( myShape != theShape )
5241 void LyingOnGeom::init()
5243 if (!myMeshDS || myShape.IsNull()) return;
5245 // is sub-shape of main shape?
5246 TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
5247 if (aMainShape.IsNull()) {
5248 myIsSubshape = false;
5251 myIsSubshape = myMeshDS->IsGroupOfSubShapes( myShape );
5256 TopTools_IndexedMapOfShape shapes;
5257 TopExp::MapShapes( myShape, shapes );
5258 mySubShapesIDs.Clear();
5259 for ( int i = 1; i <= shapes.Extent(); ++i )
5261 int subID = myMeshDS->ShapeToIndex( shapes( i ));
5263 mySubShapesIDs.Add( subID );
5266 // else // to be always ready to check an element not bound to geometry
5268 if ( !myElementsOnShapePtr )
5269 myElementsOnShapePtr.reset( new ElementsOnShape() );
5270 myElementsOnShapePtr->SetTolerance( myTolerance );
5271 myElementsOnShapePtr->SetAllNodes( false ); // lays on, while true means "belong"
5272 myElementsOnShapePtr->SetMesh( myMeshDS );
5273 myElementsOnShapePtr->SetShape( myShape, myType );
5277 bool LyingOnGeom::IsSatisfy( long theId )
5279 if ( myMeshDS == 0 || myShape.IsNull() )
5284 return myElementsOnShapePtr->IsSatisfy(theId);
5289 const SMDS_MeshElement* elem =
5290 ( myType == SMDSAbs_Node ) ? myMeshDS->FindNode( theId ) : myMeshDS->FindElement( theId );
5292 if ( mySubShapesIDs.Contains( elem->getshapeId() ))
5295 if (( elem->GetType() != SMDSAbs_Node ) &&
5296 ( myType == SMDSAbs_All || elem->GetType() == myType ))
5298 SMDS_ElemIteratorPtr nodeItr = elem->nodesIterator();
5299 while ( nodeItr->more() )
5301 const SMDS_MeshElement* aNode = nodeItr->next();
5302 if ( mySubShapesIDs.Contains( aNode->getshapeId() ))
5310 void LyingOnGeom::SetType( SMDSAbs_ElementType theType )
5312 if ( myType != theType )
5319 SMDSAbs_ElementType LyingOnGeom::GetType() const
5324 TopoDS_Shape LyingOnGeom::GetShape()
5329 const SMESHDS_Mesh* LyingOnGeom::GetMeshDS() const
5334 void LyingOnGeom::SetTolerance (double theTolerance)
5336 myTolerance = theTolerance;
5340 double LyingOnGeom::GetTolerance()
5345 TSequenceOfXYZ::TSequenceOfXYZ(): myElem(0)
5348 TSequenceOfXYZ::TSequenceOfXYZ(size_type n) : myArray(n), myElem(0)
5351 TSequenceOfXYZ::TSequenceOfXYZ(size_type n, const gp_XYZ& t) : myArray(n,t), myElem(0)
5354 TSequenceOfXYZ::TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ) : myArray(theSequenceOfXYZ.myArray), myElem(theSequenceOfXYZ.myElem)
5357 template <class InputIterator>
5358 TSequenceOfXYZ::TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd): myArray(theBegin,theEnd), myElem(0)
5361 TSequenceOfXYZ::~TSequenceOfXYZ()
5364 TSequenceOfXYZ& TSequenceOfXYZ::operator=(const TSequenceOfXYZ& theSequenceOfXYZ)
5366 myArray = theSequenceOfXYZ.myArray;
5367 myElem = theSequenceOfXYZ.myElem;
5371 gp_XYZ& TSequenceOfXYZ::operator()(size_type n)
5373 return myArray[n-1];
5376 const gp_XYZ& TSequenceOfXYZ::operator()(size_type n) const
5378 return myArray[n-1];
5381 void TSequenceOfXYZ::clear()
5386 void TSequenceOfXYZ::reserve(size_type n)
5391 void TSequenceOfXYZ::push_back(const gp_XYZ& v)
5393 myArray.push_back(v);
5396 TSequenceOfXYZ::size_type TSequenceOfXYZ::size() const
5398 return myArray.size();
5401 SMDSAbs_EntityType TSequenceOfXYZ::getElementEntity() const
5403 return myElem ? myElem->GetEntityType() : SMDSEntity_Last;
5406 TMeshModifTracer::TMeshModifTracer():
5407 myMeshModifTime(0), myMesh(0)
5410 void TMeshModifTracer::SetMesh( const SMDS_Mesh* theMesh )
5412 if ( theMesh != myMesh )
5413 myMeshModifTime = 0;
5416 bool TMeshModifTracer::IsMeshModified()
5418 bool modified = false;
5421 modified = ( myMeshModifTime != myMesh->GetMTime() );
5422 myMeshModifTime = myMesh->GetMTime();