1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "SMESH_ControlsDef.hxx"
25 #include "SMDS_BallElement.hxx"
26 #include "SMDS_FacePosition.hxx"
27 #include "SMDS_Iterator.hxx"
28 #include "SMDS_Mesh.hxx"
29 #include "SMDS_MeshElement.hxx"
30 #include "SMDS_MeshNode.hxx"
31 #include "SMDS_QuadraticEdge.hxx"
32 #include "SMDS_QuadraticFaceOfNodes.hxx"
33 #include "SMDS_VolumeTool.hxx"
34 #include "SMESHDS_GroupBase.hxx"
35 #include "SMESHDS_GroupOnFilter.hxx"
36 #include "SMESHDS_Mesh.hxx"
37 #include "SMESH_MeshAlgos.hxx"
38 #include "SMESH_OctreeNode.hxx"
40 #include <Basics_Utils.hxx>
42 #include <BRepAdaptor_Surface.hxx>
43 #include <BRepBndLib.hxx>
44 #include <BRepBuilderAPI_Copy.hxx>
45 #include <BRepClass3d_SolidClassifier.hxx>
46 #include <BRepClass_FaceClassifier.hxx>
47 #include <BRep_Tool.hxx>
48 #include <GeomLib_IsPlanarSurface.hxx>
49 #include <Geom_CylindricalSurface.hxx>
50 #include <Geom_Plane.hxx>
51 #include <Geom_Surface.hxx>
52 #include <NCollection_Map.hxx>
53 #include <Precision.hxx>
54 #include <ShapeAnalysis_Surface.hxx>
55 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
56 #include <TColStd_MapOfInteger.hxx>
57 #include <TColStd_SequenceOfAsciiString.hxx>
58 #include <TColgp_Array1OfXYZ.hxx>
62 #include <TopoDS_Edge.hxx>
63 #include <TopoDS_Face.hxx>
64 #include <TopoDS_Iterator.hxx>
65 #include <TopoDS_Shape.hxx>
66 #include <TopoDS_Vertex.hxx>
68 #include <gp_Cylinder.hxx>
75 #include <vtkMeshQuality.h>
86 const double theEps = 1e-100;
87 const double theInf = 1e+100;
89 inline gp_XYZ gpXYZ(const SMDS_MeshNode* aNode )
91 return gp_XYZ(aNode->X(), aNode->Y(), aNode->Z() );
94 inline double getAngle( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
96 gp_Vec v1( P1 - P2 ), v2( P3 - P2 );
98 return v1.Magnitude() < gp::Resolution() ||
99 v2.Magnitude() < gp::Resolution() ? 0 : v1.Angle( v2 );
102 inline double getArea( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
104 gp_Vec aVec1( P2 - P1 );
105 gp_Vec aVec2( P3 - P1 );
106 return ( aVec1 ^ aVec2 ).Magnitude() * 0.5;
109 inline double getArea( const gp_Pnt& P1, const gp_Pnt& P2, const gp_Pnt& P3 )
111 return getArea( P1.XYZ(), P2.XYZ(), P3.XYZ() );
116 inline double getDistance( const gp_XYZ& P1, const gp_XYZ& P2 )
118 double aDist = gp_Pnt( P1 ).Distance( gp_Pnt( P2 ) );
122 int getNbMultiConnection( const SMDS_Mesh* theMesh, const int theId )
127 const SMDS_MeshElement* anEdge = theMesh->FindElement( theId );
128 if ( anEdge == 0 || anEdge->GetType() != SMDSAbs_Edge/* || anEdge->NbNodes() != 2 */)
131 // for each pair of nodes in anEdge (there are 2 pairs in a quadratic edge)
132 // count elements containing both nodes of the pair.
133 // Note that there may be such cases for a quadratic edge (a horizontal line):
138 // +-----+------+ +-----+------+
141 // result should be 2 in both cases
143 int aResult0 = 0, aResult1 = 0;
144 // last node, it is a medium one in a quadratic edge
145 const SMDS_MeshNode* aLastNode = anEdge->GetNode( anEdge->NbNodes() - 1 );
146 const SMDS_MeshNode* aNode0 = anEdge->GetNode( 0 );
147 const SMDS_MeshNode* aNode1 = anEdge->GetNode( 1 );
148 if ( aNode1 == aLastNode ) aNode1 = 0;
150 SMDS_ElemIteratorPtr anElemIter = aLastNode->GetInverseElementIterator();
151 while( anElemIter->more() ) {
152 const SMDS_MeshElement* anElem = anElemIter->next();
153 if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) {
154 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
155 while ( anIter->more() ) {
156 if ( const SMDS_MeshElement* anElemNode = anIter->next() ) {
157 if ( anElemNode == aNode0 ) {
159 if ( !aNode1 ) break; // not a quadratic edge
161 else if ( anElemNode == aNode1 )
167 int aResult = std::max ( aResult0, aResult1 );
172 gp_XYZ getNormale( const SMDS_MeshFace* theFace, bool* ok=0 )
174 int aNbNode = theFace->NbNodes();
176 gp_XYZ q1 = gpXYZ( theFace->GetNode(1)) - gpXYZ( theFace->GetNode(0));
177 gp_XYZ q2 = gpXYZ( theFace->GetNode(2)) - gpXYZ( theFace->GetNode(0));
180 gp_XYZ q3 = gpXYZ( theFace->GetNode(3)) - gpXYZ( theFace->GetNode(0));
183 double len = n.Modulus();
184 bool zeroLen = ( len <= std::numeric_limits<double>::min());
188 if (ok) *ok = !zeroLen;
196 using namespace SMESH::Controls;
202 //================================================================================
204 Class : NumericalFunctor
205 Description : Base class for numerical functors
207 //================================================================================
209 NumericalFunctor::NumericalFunctor():
215 void NumericalFunctor::SetMesh( const SMDS_Mesh* theMesh )
220 bool NumericalFunctor::GetPoints(const int theId,
221 TSequenceOfXYZ& theRes ) const
228 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
229 if ( !anElem || anElem->GetType() != this->GetType() )
232 return GetPoints( anElem, theRes );
235 bool NumericalFunctor::GetPoints(const SMDS_MeshElement* anElem,
236 TSequenceOfXYZ& theRes )
243 theRes.reserve( anElem->NbNodes() );
244 theRes.setElement( anElem );
246 // Get nodes of the element
247 SMDS_ElemIteratorPtr anIter;
249 if ( anElem->IsQuadratic() ) {
250 switch ( anElem->GetType() ) {
252 anIter = dynamic_cast<const SMDS_VtkEdge*>
253 (anElem)->interlacedNodesElemIterator();
256 anIter = dynamic_cast<const SMDS_VtkFace*>
257 (anElem)->interlacedNodesElemIterator();
260 anIter = anElem->nodesIterator();
264 anIter = anElem->nodesIterator();
269 while( anIter->more() ) {
270 if ( p.Set( anIter->next() ))
271 theRes.push_back( p );
278 long NumericalFunctor::GetPrecision() const
283 void NumericalFunctor::SetPrecision( const long thePrecision )
285 myPrecision = thePrecision;
286 myPrecisionValue = pow( 10., (double)( myPrecision ) );
289 double NumericalFunctor::GetValue( long theId )
293 myCurrElement = myMesh->FindElement( theId );
296 if ( GetPoints( theId, P )) // elem type is checked here
297 aVal = Round( GetValue( P ));
302 double NumericalFunctor::Round( const double & aVal )
304 return ( myPrecision >= 0 ) ? floor( aVal * myPrecisionValue + 0.5 ) / myPrecisionValue : aVal;
307 //================================================================================
309 * \brief Return histogram of functor values
310 * \param nbIntervals - number of intervals
311 * \param nbEvents - number of mesh elements having values within i-th interval
312 * \param funValues - boundaries of intervals
313 * \param elements - elements to check vulue of; empty list means "of all"
314 * \param minmax - boundaries of diapason of values to divide into intervals
316 //================================================================================
318 void NumericalFunctor::GetHistogram(int nbIntervals,
319 std::vector<int>& nbEvents,
320 std::vector<double>& funValues,
321 const std::vector<int>& elements,
322 const double* minmax,
323 const bool isLogarithmic)
325 if ( nbIntervals < 1 ||
327 !myMesh->GetMeshInfo().NbElements( GetType() ))
329 nbEvents.resize( nbIntervals, 0 );
330 funValues.resize( nbIntervals+1 );
332 // get all values sorted
333 std::multiset< double > values;
334 if ( elements.empty() )
336 SMDS_ElemIteratorPtr elemIt = myMesh->elementsIterator( GetType() );
337 while ( elemIt->more() )
338 values.insert( GetValue( elemIt->next()->GetID() ));
342 std::vector<int>::const_iterator id = elements.begin();
343 for ( ; id != elements.end(); ++id )
344 values.insert( GetValue( *id ));
349 funValues[0] = minmax[0];
350 funValues[nbIntervals] = minmax[1];
354 funValues[0] = *values.begin();
355 funValues[nbIntervals] = *values.rbegin();
357 // case nbIntervals == 1
358 if ( nbIntervals == 1 )
360 nbEvents[0] = values.size();
364 if (funValues.front() == funValues.back())
366 nbEvents.resize( 1 );
367 nbEvents[0] = values.size();
368 funValues[1] = funValues.back();
369 funValues.resize( 2 );
372 std::multiset< double >::iterator min = values.begin(), max;
373 for ( int i = 0; i < nbIntervals; ++i )
375 // find end value of i-th interval
376 double r = (i+1) / double(nbIntervals);
377 if (isLogarithmic && funValues.front() > 1e-07 && funValues.back() > 1e-07) {
378 double logmin = log10(funValues.front());
379 double lval = logmin + r * (log10(funValues.back()) - logmin);
380 funValues[i+1] = pow(10.0, lval);
383 funValues[i+1] = funValues.front() * (1-r) + funValues.back() * r;
386 // count values in the i-th interval if there are any
387 if ( min != values.end() && *min <= funValues[i+1] )
389 // find the first value out of the interval
390 max = values.upper_bound( funValues[i+1] ); // max is greater than funValues[i+1], or end()
391 nbEvents[i] = std::distance( min, max );
395 // add values larger than minmax[1]
396 nbEvents.back() += std::distance( min, values.end() );
399 //=======================================================================
402 Description : Functor calculating volume of a 3D element
404 //================================================================================
406 double Volume::GetValue( long theElementId )
408 if ( theElementId && myMesh ) {
409 SMDS_VolumeTool aVolumeTool;
410 if ( aVolumeTool.Set( myMesh->FindElement( theElementId )))
411 return aVolumeTool.GetSize();
416 double Volume::GetBadRate( double Value, int /*nbNodes*/ ) const
421 SMDSAbs_ElementType Volume::GetType() const
423 return SMDSAbs_Volume;
426 //=======================================================================
428 Class : MaxElementLength2D
429 Description : Functor calculating maximum length of 2D element
431 //================================================================================
433 double MaxElementLength2D::GetValue( const TSequenceOfXYZ& P )
439 if( len == 3 ) { // triangles
440 double L1 = getDistance(P( 1 ),P( 2 ));
441 double L2 = getDistance(P( 2 ),P( 3 ));
442 double L3 = getDistance(P( 3 ),P( 1 ));
443 aVal = Max(L1,Max(L2,L3));
445 else if( len == 4 ) { // quadrangles
446 double L1 = getDistance(P( 1 ),P( 2 ));
447 double L2 = getDistance(P( 2 ),P( 3 ));
448 double L3 = getDistance(P( 3 ),P( 4 ));
449 double L4 = getDistance(P( 4 ),P( 1 ));
450 double D1 = getDistance(P( 1 ),P( 3 ));
451 double D2 = getDistance(P( 2 ),P( 4 ));
452 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(D1,D2));
454 else if( len == 6 ) { // quadratic triangles
455 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
456 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
457 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 1 ));
458 aVal = Max(L1,Max(L2,L3));
460 else if( len == 8 || len == 9 ) { // quadratic quadrangles
461 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
462 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
463 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 7 ));
464 double L4 = getDistance(P( 7 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
465 double D1 = getDistance(P( 1 ),P( 5 ));
466 double D2 = getDistance(P( 3 ),P( 7 ));
467 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(D1,D2));
469 // Diagonals are undefined for concave polygons
470 // else if ( P.getElementEntity() == SMDSEntity_Quad_Polygon && P.size() > 2 ) // quad polygon
473 // aVal = getDistance( P( 1 ), P( P.size() )) + getDistance( P( P.size() ), P( P.size()-1 ));
474 // for ( size_t i = 1; i < P.size()-1; i += 2 )
476 // double L = getDistance( P( i ), P( i+1 )) + getDistance( P( i+1 ), P( i+2 ));
477 // aVal = Max( aVal, L );
480 // for ( int i = P.size()-5; i > 0; i -= 2 )
481 // for ( int j = i + 4; j < P.size() + i - 2; i += 2 )
483 // double D = getDistance( P( i ), P( j ));
484 // aVal = Max( aVal, D );
491 if( myPrecision >= 0 )
493 double prec = pow( 10., (double)myPrecision );
494 aVal = floor( aVal * prec + 0.5 ) / prec;
499 double MaxElementLength2D::GetValue( long theElementId )
502 return GetPoints( theElementId, P ) ? GetValue(P) : 0.0;
505 double MaxElementLength2D::GetBadRate( double Value, int /*nbNodes*/ ) const
510 SMDSAbs_ElementType MaxElementLength2D::GetType() const
515 //=======================================================================
517 Class : MaxElementLength3D
518 Description : Functor calculating maximum length of 3D element
520 //================================================================================
522 double MaxElementLength3D::GetValue( long theElementId )
525 if( GetPoints( theElementId, P ) ) {
527 const SMDS_MeshElement* aElem = myMesh->FindElement( theElementId );
528 SMDSAbs_EntityType aType = aElem->GetEntityType();
531 case SMDSEntity_Tetra: { // tetras
532 double L1 = getDistance(P( 1 ),P( 2 ));
533 double L2 = getDistance(P( 2 ),P( 3 ));
534 double L3 = getDistance(P( 3 ),P( 1 ));
535 double L4 = getDistance(P( 1 ),P( 4 ));
536 double L5 = getDistance(P( 2 ),P( 4 ));
537 double L6 = getDistance(P( 3 ),P( 4 ));
538 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
541 case SMDSEntity_Pyramid: { // pyramids
542 double L1 = getDistance(P( 1 ),P( 2 ));
543 double L2 = getDistance(P( 2 ),P( 3 ));
544 double L3 = getDistance(P( 3 ),P( 4 ));
545 double L4 = getDistance(P( 4 ),P( 1 ));
546 double L5 = getDistance(P( 1 ),P( 5 ));
547 double L6 = getDistance(P( 2 ),P( 5 ));
548 double L7 = getDistance(P( 3 ),P( 5 ));
549 double L8 = getDistance(P( 4 ),P( 5 ));
550 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
551 aVal = Max(aVal,Max(L7,L8));
554 case SMDSEntity_Penta: { // pentas
555 double L1 = getDistance(P( 1 ),P( 2 ));
556 double L2 = getDistance(P( 2 ),P( 3 ));
557 double L3 = getDistance(P( 3 ),P( 1 ));
558 double L4 = getDistance(P( 4 ),P( 5 ));
559 double L5 = getDistance(P( 5 ),P( 6 ));
560 double L6 = getDistance(P( 6 ),P( 4 ));
561 double L7 = getDistance(P( 1 ),P( 4 ));
562 double L8 = getDistance(P( 2 ),P( 5 ));
563 double L9 = getDistance(P( 3 ),P( 6 ));
564 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
565 aVal = Max(aVal,Max(Max(L7,L8),L9));
568 case SMDSEntity_Hexa: { // hexas
569 double L1 = getDistance(P( 1 ),P( 2 ));
570 double L2 = getDistance(P( 2 ),P( 3 ));
571 double L3 = getDistance(P( 3 ),P( 4 ));
572 double L4 = getDistance(P( 4 ),P( 1 ));
573 double L5 = getDistance(P( 5 ),P( 6 ));
574 double L6 = getDistance(P( 6 ),P( 7 ));
575 double L7 = getDistance(P( 7 ),P( 8 ));
576 double L8 = getDistance(P( 8 ),P( 5 ));
577 double L9 = getDistance(P( 1 ),P( 5 ));
578 double L10= getDistance(P( 2 ),P( 6 ));
579 double L11= getDistance(P( 3 ),P( 7 ));
580 double L12= getDistance(P( 4 ),P( 8 ));
581 double D1 = getDistance(P( 1 ),P( 7 ));
582 double D2 = getDistance(P( 2 ),P( 8 ));
583 double D3 = getDistance(P( 3 ),P( 5 ));
584 double D4 = getDistance(P( 4 ),P( 6 ));
585 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
586 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
587 aVal = Max(aVal,Max(L11,L12));
588 aVal = Max(aVal,Max(Max(D1,D2),Max(D3,D4)));
591 case SMDSEntity_Hexagonal_Prism: { // hexagonal prism
592 for ( int i1 = 1; i1 < 12; ++i1 )
593 for ( int i2 = i1+1; i1 <= 12; ++i1 )
594 aVal = Max( aVal, getDistance(P( i1 ),P( i2 )));
597 case SMDSEntity_Quad_Tetra: { // quadratic tetras
598 double L1 = getDistance(P( 1 ),P( 5 )) + getDistance(P( 5 ),P( 2 ));
599 double L2 = getDistance(P( 2 ),P( 6 )) + getDistance(P( 6 ),P( 3 ));
600 double L3 = getDistance(P( 3 ),P( 7 )) + getDistance(P( 7 ),P( 1 ));
601 double L4 = getDistance(P( 1 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
602 double L5 = getDistance(P( 2 ),P( 9 )) + getDistance(P( 9 ),P( 4 ));
603 double L6 = getDistance(P( 3 ),P( 10 )) + getDistance(P( 10 ),P( 4 ));
604 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
607 case SMDSEntity_Quad_Pyramid: { // quadratic pyramids
608 double L1 = getDistance(P( 1 ),P( 6 )) + getDistance(P( 6 ),P( 2 ));
609 double L2 = getDistance(P( 2 ),P( 7 )) + getDistance(P( 7 ),P( 3 ));
610 double L3 = getDistance(P( 3 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
611 double L4 = getDistance(P( 4 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
612 double L5 = getDistance(P( 1 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
613 double L6 = getDistance(P( 2 ),P( 11 )) + getDistance(P( 11 ),P( 5 ));
614 double L7 = getDistance(P( 3 ),P( 12 )) + getDistance(P( 12 ),P( 5 ));
615 double L8 = getDistance(P( 4 ),P( 13 )) + getDistance(P( 13 ),P( 5 ));
616 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
617 aVal = Max(aVal,Max(L7,L8));
620 case SMDSEntity_Quad_Penta:
621 /*case SMDSEntity_BiQuad_Penta:*/ { // quadratic pentas
622 double L1 = getDistance(P( 1 ),P( 7 )) + getDistance(P( 7 ),P( 2 ));
623 double L2 = getDistance(P( 2 ),P( 8 )) + getDistance(P( 8 ),P( 3 ));
624 double L3 = getDistance(P( 3 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
625 double L4 = getDistance(P( 4 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
626 double L5 = getDistance(P( 5 ),P( 11 )) + getDistance(P( 11 ),P( 6 ));
627 double L6 = getDistance(P( 6 ),P( 12 )) + getDistance(P( 12 ),P( 4 ));
628 double L7 = getDistance(P( 1 ),P( 13 )) + getDistance(P( 13 ),P( 4 ));
629 double L8 = getDistance(P( 2 ),P( 14 )) + getDistance(P( 14 ),P( 5 ));
630 double L9 = getDistance(P( 3 ),P( 15 )) + getDistance(P( 15 ),P( 6 ));
631 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
632 aVal = Max(aVal,Max(Max(L7,L8),L9));
635 case SMDSEntity_Quad_Hexa:
636 case SMDSEntity_TriQuad_Hexa: { // quadratic hexas
637 double L1 = getDistance(P( 1 ),P( 9 )) + getDistance(P( 9 ),P( 2 ));
638 double L2 = getDistance(P( 2 ),P( 10 )) + getDistance(P( 10 ),P( 3 ));
639 double L3 = getDistance(P( 3 ),P( 11 )) + getDistance(P( 11 ),P( 4 ));
640 double L4 = getDistance(P( 4 ),P( 12 )) + getDistance(P( 12 ),P( 1 ));
641 double L5 = getDistance(P( 5 ),P( 13 )) + getDistance(P( 13 ),P( 6 ));
642 double L6 = getDistance(P( 6 ),P( 14 )) + getDistance(P( 14 ),P( 7 ));
643 double L7 = getDistance(P( 7 ),P( 15 )) + getDistance(P( 15 ),P( 8 ));
644 double L8 = getDistance(P( 8 ),P( 16 )) + getDistance(P( 16 ),P( 5 ));
645 double L9 = getDistance(P( 1 ),P( 17 )) + getDistance(P( 17 ),P( 5 ));
646 double L10= getDistance(P( 2 ),P( 18 )) + getDistance(P( 18 ),P( 6 ));
647 double L11= getDistance(P( 3 ),P( 19 )) + getDistance(P( 19 ),P( 7 ));
648 double L12= getDistance(P( 4 ),P( 20 )) + getDistance(P( 20 ),P( 8 ));
649 double D1 = getDistance(P( 1 ),P( 7 ));
650 double D2 = getDistance(P( 2 ),P( 8 ));
651 double D3 = getDistance(P( 3 ),P( 5 ));
652 double D4 = getDistance(P( 4 ),P( 6 ));
653 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
654 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
655 aVal = Max(aVal,Max(L11,L12));
656 aVal = Max(aVal,Max(Max(D1,D2),Max(D3,D4)));
659 case SMDSEntity_Quad_Polyhedra:
660 case SMDSEntity_Polyhedra: { // polys
661 // get the maximum distance between all pairs of nodes
662 for( int i = 1; i <= len; i++ ) {
663 for( int j = 1; j <= len; j++ ) {
664 if( j > i ) { // optimization of the loop
665 double D = getDistance( P(i), P(j) );
666 aVal = Max( aVal, D );
672 case SMDSEntity_Node:
674 case SMDSEntity_Edge:
675 case SMDSEntity_Quad_Edge:
676 case SMDSEntity_Triangle:
677 case SMDSEntity_Quad_Triangle:
678 case SMDSEntity_BiQuad_Triangle:
679 case SMDSEntity_Quadrangle:
680 case SMDSEntity_Quad_Quadrangle:
681 case SMDSEntity_BiQuad_Quadrangle:
682 case SMDSEntity_Polygon:
683 case SMDSEntity_Quad_Polygon:
684 case SMDSEntity_Ball:
685 case SMDSEntity_Last: return 0;
686 } // switch ( aType )
688 if( myPrecision >= 0 )
690 double prec = pow( 10., (double)myPrecision );
691 aVal = floor( aVal * prec + 0.5 ) / prec;
698 double MaxElementLength3D::GetBadRate( double Value, int /*nbNodes*/ ) const
703 SMDSAbs_ElementType MaxElementLength3D::GetType() const
705 return SMDSAbs_Volume;
708 //=======================================================================
711 Description : Functor for calculation of minimum angle
713 //================================================================================
715 double MinimumAngle::GetValue( const TSequenceOfXYZ& P )
722 aMin = getAngle(P( P.size() ), P( 1 ), P( 2 ));
723 aMin = Min(aMin,getAngle(P( P.size()-1 ), P( P.size() ), P( 1 )));
725 for ( size_t i = 2; i < P.size(); i++ )
727 double A0 = getAngle( P( i-1 ), P( i ), P( i+1 ) );
731 return aMin * 180.0 / M_PI;
734 double MinimumAngle::GetBadRate( double Value, int nbNodes ) const
736 //const double aBestAngle = PI / nbNodes;
737 const double aBestAngle = 180.0 - ( 360.0 / double(nbNodes) );
738 return ( fabs( aBestAngle - Value ));
741 SMDSAbs_ElementType MinimumAngle::GetType() const
747 //================================================================================
750 Description : Functor for calculating aspect ratio
752 //================================================================================
754 double AspectRatio::GetValue( long theId )
757 myCurrElement = myMesh->FindElement( theId );
758 if ( myCurrElement && myCurrElement->GetVtkType() == VTK_QUAD )
761 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myCurrElement->getMeshId()]->getGrid();
762 if ( vtkCell* avtkCell = grid->GetCell( myCurrElement->getVtkId() ))
763 aVal = Round( vtkMeshQuality::QuadAspectRatio( avtkCell ));
768 if ( GetPoints( myCurrElement, P ))
769 aVal = Round( GetValue( P ));
774 double AspectRatio::GetValue( const TSequenceOfXYZ& P )
776 // According to "Mesh quality control" by Nadir Bouhamau referring to
777 // Pascal Jean Frey and Paul-Louis George. Maillages, applications aux elements finis.
778 // Hermes Science publications, Paris 1999 ISBN 2-7462-0024-4
781 int nbNodes = P.size();
786 // Compute aspect ratio
788 if ( nbNodes == 3 ) {
789 // Compute lengths of the sides
790 std::vector< double > aLen (nbNodes);
791 for ( int i = 0; i < nbNodes - 1; i++ )
792 aLen[ i ] = getDistance( P( i + 1 ), P( i + 2 ) );
793 aLen[ nbNodes - 1 ] = getDistance( P( 1 ), P( nbNodes ) );
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( aLen[ 0 ], Max( aLen[ 1 ], aLen[ 2 ] ) );
802 double half_perimeter = ( aLen[0] + aLen[1] + aLen[2] ) / 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 std::vector< double > aLen (3);
811 aLen[0] = getDistance( P(1), P(3) );
812 aLen[1] = getDistance( P(3), P(5) );
813 aLen[2] = getDistance( P(5), P(1) );
814 // Q = alfa * h * p / S, where
816 // alfa = sqrt( 3 ) / 6
817 // h - length of the longest edge
818 // p - half perimeter
819 // S - triangle surface
820 const double alfa = sqrt( 3. ) / 6.;
821 double maxLen = Max( aLen[ 0 ], Max( aLen[ 1 ], aLen[ 2 ] ) );
822 double half_perimeter = ( aLen[0] + aLen[1] + aLen[2] ) / 2.;
823 double anArea = getArea( P(1), P(3), P(5) );
824 if ( anArea <= theEps )
826 return alfa * maxLen * half_perimeter / anArea;
828 else if( nbNodes == 4 ) { // quadrangle
829 // Compute lengths of the sides
830 std::vector< double > aLen (4);
831 aLen[0] = getDistance( P(1), P(2) );
832 aLen[1] = getDistance( P(2), P(3) );
833 aLen[2] = getDistance( P(3), P(4) );
834 aLen[3] = getDistance( P(4), P(1) );
835 // Compute lengths of the diagonals
836 std::vector< double > aDia (2);
837 aDia[0] = getDistance( P(1), P(3) );
838 aDia[1] = getDistance( P(2), P(4) );
839 // Compute areas of all triangles which can be built
840 // taking three nodes of the quadrangle
841 std::vector< double > anArea (4);
842 anArea[0] = getArea( P(1), P(2), P(3) );
843 anArea[1] = getArea( P(1), P(2), P(4) );
844 anArea[2] = getArea( P(1), P(3), P(4) );
845 anArea[3] = getArea( P(2), P(3), P(4) );
846 // Q = alpha * L * C1 / C2, where
848 // alpha = sqrt( 1/32 )
849 // L = max( L1, L2, L3, L4, D1, D2 )
850 // C1 = sqrt( ( L1^2 + L1^2 + L1^2 + L1^2 ) / 4 )
851 // C2 = min( S1, S2, S3, S4 )
852 // Li - lengths of the edges
853 // Di - lengths of the diagonals
854 // Si - areas of the triangles
855 const double alpha = sqrt( 1 / 32. );
856 double L = Max( aLen[ 0 ],
860 Max( aDia[ 0 ], aDia[ 1 ] ) ) ) ) );
861 double C1 = sqrt( ( aLen[0] * aLen[0] +
864 aLen[3] * aLen[3] ) / 4. );
865 double C2 = Min( anArea[ 0 ],
867 Min( anArea[ 2 ], anArea[ 3 ] ) ) );
870 return alpha * L * C1 / C2;
872 else if( nbNodes == 8 || nbNodes == 9 ) { // nbNodes==8 - quadratic quadrangle
873 // Compute lengths of the sides
874 std::vector< double > aLen (4);
875 aLen[0] = getDistance( P(1), P(3) );
876 aLen[1] = getDistance( P(3), P(5) );
877 aLen[2] = getDistance( P(5), P(7) );
878 aLen[3] = getDistance( P(7), P(1) );
879 // Compute lengths of the diagonals
880 std::vector< double > aDia (2);
881 aDia[0] = getDistance( P(1), P(5) );
882 aDia[1] = getDistance( P(3), P(7) );
883 // Compute areas of all triangles which can be built
884 // taking three nodes of the quadrangle
885 std::vector< double > anArea (4);
886 anArea[0] = getArea( P(1), P(3), P(5) );
887 anArea[1] = getArea( P(1), P(3), P(7) );
888 anArea[2] = getArea( P(1), P(5), P(7) );
889 anArea[3] = getArea( P(3), P(5), P(7) );
890 // Q = alpha * L * C1 / C2, where
892 // alpha = sqrt( 1/32 )
893 // L = max( L1, L2, L3, L4, D1, D2 )
894 // C1 = sqrt( ( L1^2 + L1^2 + L1^2 + L1^2 ) / 4 )
895 // C2 = min( S1, S2, S3, S4 )
896 // Li - lengths of the edges
897 // Di - lengths of the diagonals
898 // Si - areas of the triangles
899 const double alpha = sqrt( 1 / 32. );
900 double L = Max( aLen[ 0 ],
904 Max( aDia[ 0 ], aDia[ 1 ] ) ) ) ) );
905 double C1 = sqrt( ( aLen[0] * aLen[0] +
908 aLen[3] * aLen[3] ) / 4. );
909 double C2 = Min( anArea[ 0 ],
911 Min( anArea[ 2 ], anArea[ 3 ] ) ) );
914 return alpha * L * C1 / C2;
919 double AspectRatio::GetBadRate( double Value, int /*nbNodes*/ ) const
921 // the aspect ratio is in the range [1.0,infinity]
922 // < 1.0 = very bad, zero area
925 return ( Value < 0.9 ) ? 1000 : Value / 1000.;
928 SMDSAbs_ElementType AspectRatio::GetType() const
934 //================================================================================
936 Class : AspectRatio3D
937 Description : Functor for calculating aspect ratio
939 //================================================================================
943 inline double getHalfPerimeter(double theTria[3]){
944 return (theTria[0] + theTria[1] + theTria[2])/2.0;
947 inline double getArea(double theHalfPerim, double theTria[3]){
948 return sqrt(theHalfPerim*
949 (theHalfPerim-theTria[0])*
950 (theHalfPerim-theTria[1])*
951 (theHalfPerim-theTria[2]));
954 inline double getVolume(double theLen[6]){
955 double a2 = theLen[0]*theLen[0];
956 double b2 = theLen[1]*theLen[1];
957 double c2 = theLen[2]*theLen[2];
958 double d2 = theLen[3]*theLen[3];
959 double e2 = theLen[4]*theLen[4];
960 double f2 = theLen[5]*theLen[5];
961 double P = 4.0*a2*b2*d2;
962 double Q = a2*(b2+d2-e2)-b2*(a2+d2-f2)-d2*(a2+b2-c2);
963 double R = (b2+d2-e2)*(a2+d2-f2)*(a2+d2-f2);
964 return sqrt(P-Q+R)/12.0;
967 inline double getVolume2(double theLen[6]){
968 double a2 = theLen[0]*theLen[0];
969 double b2 = theLen[1]*theLen[1];
970 double c2 = theLen[2]*theLen[2];
971 double d2 = theLen[3]*theLen[3];
972 double e2 = theLen[4]*theLen[4];
973 double f2 = theLen[5]*theLen[5];
975 double P = a2*e2*(b2+c2+d2+f2-a2-e2);
976 double Q = b2*f2*(a2+c2+d2+e2-b2-f2);
977 double R = c2*d2*(a2+b2+e2+f2-c2-d2);
978 double S = a2*b2*d2+b2*c2*e2+a2*c2*f2+d2*e2*f2;
980 return sqrt(P+Q+R-S)/12.0;
983 inline double getVolume(const TSequenceOfXYZ& P){
984 gp_Vec aVec1( P( 2 ) - P( 1 ) );
985 gp_Vec aVec2( P( 3 ) - P( 1 ) );
986 gp_Vec aVec3( P( 4 ) - P( 1 ) );
987 gp_Vec anAreaVec( aVec1 ^ aVec2 );
988 return fabs(aVec3 * anAreaVec) / 6.0;
991 inline double getMaxHeight(double theLen[6])
993 double aHeight = std::max(theLen[0],theLen[1]);
994 aHeight = std::max(aHeight,theLen[2]);
995 aHeight = std::max(aHeight,theLen[3]);
996 aHeight = std::max(aHeight,theLen[4]);
997 aHeight = std::max(aHeight,theLen[5]);
1003 double AspectRatio3D::GetValue( long theId )
1006 myCurrElement = myMesh->FindElement( theId );
1007 if ( myCurrElement && myCurrElement->GetVtkType() == VTK_TETRA )
1009 // Action from CoTech | ACTION 31.3:
1010 // EURIWARE BO: Homogenize the formulas used to calculate the Controls in SMESH to fit with
1011 // those of ParaView. The library used by ParaView for those calculations can be reused in SMESH.
1012 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myCurrElement->getMeshId()]->getGrid();
1013 if ( vtkCell* avtkCell = grid->GetCell( myCurrElement->getVtkId() ))
1014 aVal = Round( vtkMeshQuality::TetAspectRatio( avtkCell ));
1019 if ( GetPoints( myCurrElement, P ))
1020 aVal = Round( GetValue( P ));
1025 double AspectRatio3D::GetValue( const TSequenceOfXYZ& P )
1027 double aQuality = 0.0;
1028 if(myCurrElement->IsPoly()) return aQuality;
1030 int nbNodes = P.size();
1032 if(myCurrElement->IsQuadratic()) {
1033 if(nbNodes==10) nbNodes=4; // quadratic tetrahedron
1034 else if(nbNodes==13) nbNodes=5; // quadratic pyramid
1035 else if(nbNodes==15) nbNodes=6; // quadratic pentahedron
1036 else if(nbNodes==20) nbNodes=8; // quadratic hexahedron
1037 else if(nbNodes==27) nbNodes=8; // quadratic hexahedron
1038 else return aQuality;
1044 getDistance(P( 1 ),P( 2 )), // a
1045 getDistance(P( 2 ),P( 3 )), // b
1046 getDistance(P( 3 ),P( 1 )), // c
1047 getDistance(P( 2 ),P( 4 )), // d
1048 getDistance(P( 3 ),P( 4 )), // e
1049 getDistance(P( 1 ),P( 4 )) // f
1051 double aTria[4][3] = {
1052 {aLen[0],aLen[1],aLen[2]}, // abc
1053 {aLen[0],aLen[3],aLen[5]}, // adf
1054 {aLen[1],aLen[3],aLen[4]}, // bde
1055 {aLen[2],aLen[4],aLen[5]} // cef
1057 double aSumArea = 0.0;
1058 double aHalfPerimeter = getHalfPerimeter(aTria[0]);
1059 double anArea = getArea(aHalfPerimeter,aTria[0]);
1061 aHalfPerimeter = getHalfPerimeter(aTria[1]);
1062 anArea = getArea(aHalfPerimeter,aTria[1]);
1064 aHalfPerimeter = getHalfPerimeter(aTria[2]);
1065 anArea = getArea(aHalfPerimeter,aTria[2]);
1067 aHalfPerimeter = getHalfPerimeter(aTria[3]);
1068 anArea = getArea(aHalfPerimeter,aTria[3]);
1070 double aVolume = getVolume(P);
1071 //double aVolume = getVolume(aLen);
1072 double aHeight = getMaxHeight(aLen);
1073 static double aCoeff = sqrt(2.0)/12.0;
1074 if ( aVolume > DBL_MIN )
1075 aQuality = aCoeff*aHeight*aSumArea/aVolume;
1080 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 3 ),P( 5 )};
1081 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1084 gp_XYZ aXYZ[4] = {P( 1 ),P( 3 ),P( 4 ),P( 5 )};
1085 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1088 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 5 )};
1089 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1092 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 4 ),P( 5 )};
1093 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1099 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 6 )};
1100 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1103 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 3 )};
1104 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1107 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 6 )};
1108 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1111 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
1112 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1115 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 6 )};
1116 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1119 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 3 )};
1120 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1126 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
1127 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1130 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 4 )};
1131 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1134 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 7 )};
1135 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1138 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 8 )};
1139 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1142 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 3 )};
1143 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1146 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 4 )};
1147 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1150 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 7 )};
1151 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1154 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 8 )};
1155 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1158 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 3 )};
1159 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1162 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 4 )};
1163 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1166 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 7 )};
1167 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1170 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 8 )};
1171 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1174 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 1 )};
1175 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1178 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 2 )};
1179 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1182 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 5 )};
1183 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1186 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 6 )};
1187 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1190 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 1 )};
1191 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1194 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 2 )};
1195 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1198 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 5 )};
1199 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1202 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 6 )};
1203 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1206 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 1 )};
1207 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1210 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
1211 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1214 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 5 )};
1215 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1218 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 6 )};
1219 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1222 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
1223 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1226 gp_XYZ aXYZ[4] = {P( 4 ),P( 5 ),P( 8 ),P( 2 )};
1227 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1230 gp_XYZ aXYZ[4] = {P( 1 ),P( 4 ),P( 5 ),P( 3 )};
1231 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1234 gp_XYZ aXYZ[4] = {P( 3 ),P( 6 ),P( 7 ),P( 1 )};
1235 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1238 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 6 ),P( 4 )};
1239 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1242 gp_XYZ aXYZ[4] = {P( 5 ),P( 6 ),P( 8 ),P( 3 )};
1243 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1246 gp_XYZ aXYZ[4] = {P( 7 ),P( 8 ),P( 6 ),P( 1 )};
1247 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1250 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 7 )};
1251 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1254 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 2 ),P( 5 )};
1255 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1261 gp_XYZ aXYZ[8] = {P( 1 ),P( 2 ),P( 4 ),P( 5 ),P( 7 ),P( 8 ),P( 10 ),P( 11 )};
1262 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[8])),aQuality);
1265 gp_XYZ aXYZ[8] = {P( 2 ),P( 3 ),P( 5 ),P( 6 ),P( 8 ),P( 9 ),P( 11 ),P( 12 )};
1266 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[8])),aQuality);
1269 gp_XYZ aXYZ[8] = {P( 3 ),P( 4 ),P( 6 ),P( 1 ),P( 9 ),P( 10 ),P( 12 ),P( 7 )};
1270 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[8])),aQuality);
1273 } // switch(nbNodes)
1275 if ( nbNodes > 4 ) {
1276 // avaluate aspect ratio of quadranle faces
1277 AspectRatio aspect2D;
1278 SMDS_VolumeTool::VolumeType type = SMDS_VolumeTool::GetType( nbNodes );
1279 int nbFaces = SMDS_VolumeTool::NbFaces( type );
1280 TSequenceOfXYZ points(4);
1281 for ( int i = 0; i < nbFaces; ++i ) { // loop on faces of a volume
1282 if ( SMDS_VolumeTool::NbFaceNodes( type, i ) != 4 )
1284 const int* pInd = SMDS_VolumeTool::GetFaceNodesIndices( type, i, true );
1285 for ( int p = 0; p < 4; ++p ) // loop on nodes of a quadranle face
1286 points( p + 1 ) = P( pInd[ p ] + 1 );
1287 aQuality = std::max( aQuality, aspect2D.GetValue( points ));
1293 double AspectRatio3D::GetBadRate( double Value, int /*nbNodes*/ ) const
1295 // the aspect ratio is in the range [1.0,infinity]
1298 return Value / 1000.;
1301 SMDSAbs_ElementType AspectRatio3D::GetType() const
1303 return SMDSAbs_Volume;
1307 //================================================================================
1310 Description : Functor for calculating warping
1312 //================================================================================
1314 double Warping::GetValue( const TSequenceOfXYZ& P )
1316 if ( P.size() != 4 )
1319 gp_XYZ G = ( P( 1 ) + P( 2 ) + P( 3 ) + P( 4 ) ) / 4.;
1321 double A1 = ComputeA( P( 1 ), P( 2 ), P( 3 ), G );
1322 double A2 = ComputeA( P( 2 ), P( 3 ), P( 4 ), G );
1323 double A3 = ComputeA( P( 3 ), P( 4 ), P( 1 ), G );
1324 double A4 = ComputeA( P( 4 ), P( 1 ), P( 2 ), G );
1326 double val = Max( Max( A1, A2 ), Max( A3, A4 ) );
1328 const double eps = 0.1; // val is in degrees
1330 return val < eps ? 0. : val;
1333 double Warping::ComputeA( const gp_XYZ& thePnt1,
1334 const gp_XYZ& thePnt2,
1335 const gp_XYZ& thePnt3,
1336 const gp_XYZ& theG ) const
1338 double aLen1 = gp_Pnt( thePnt1 ).Distance( gp_Pnt( thePnt2 ) );
1339 double aLen2 = gp_Pnt( thePnt2 ).Distance( gp_Pnt( thePnt3 ) );
1340 double L = Min( aLen1, aLen2 ) * 0.5;
1344 gp_XYZ GI = ( thePnt2 + thePnt1 ) / 2. - theG;
1345 gp_XYZ GJ = ( thePnt3 + thePnt2 ) / 2. - theG;
1346 gp_XYZ N = GI.Crossed( GJ );
1348 if ( N.Modulus() < gp::Resolution() )
1353 double H = ( thePnt2 - theG ).Dot( N );
1354 return asin( fabs( H / L ) ) * 180. / M_PI;
1357 double Warping::GetBadRate( double Value, int /*nbNodes*/ ) const
1359 // the warp is in the range [0.0,PI/2]
1360 // 0.0 = good (no warp)
1361 // PI/2 = bad (face pliee)
1365 SMDSAbs_ElementType Warping::GetType() const
1367 return SMDSAbs_Face;
1371 //================================================================================
1374 Description : Functor for calculating taper
1376 //================================================================================
1378 double Taper::GetValue( const TSequenceOfXYZ& P )
1380 if ( P.size() != 4 )
1384 double J1 = getArea( P( 4 ), P( 1 ), P( 2 ) );
1385 double J2 = getArea( P( 3 ), P( 1 ), P( 2 ) );
1386 double J3 = getArea( P( 2 ), P( 3 ), P( 4 ) );
1387 double J4 = getArea( P( 3 ), P( 4 ), P( 1 ) );
1389 double JA = 0.25 * ( J1 + J2 + J3 + J4 );
1393 double T1 = fabs( ( J1 - JA ) / JA );
1394 double T2 = fabs( ( J2 - JA ) / JA );
1395 double T3 = fabs( ( J3 - JA ) / JA );
1396 double T4 = fabs( ( J4 - JA ) / JA );
1398 double val = Max( Max( T1, T2 ), Max( T3, T4 ) );
1400 const double eps = 0.01;
1402 return val < eps ? 0. : val;
1405 double Taper::GetBadRate( double Value, int /*nbNodes*/ ) const
1407 // the taper is in the range [0.0,1.0]
1408 // 0.0 = good (no taper)
1409 // 1.0 = bad (les cotes opposes sont allignes)
1413 SMDSAbs_ElementType Taper::GetType() const
1415 return SMDSAbs_Face;
1418 //================================================================================
1421 Description : Functor for calculating skew in degrees
1423 //================================================================================
1425 static inline double skewAngle( const gp_XYZ& p1, const gp_XYZ& p2, const gp_XYZ& p3 )
1427 gp_XYZ p12 = ( p2 + p1 ) / 2.;
1428 gp_XYZ p23 = ( p3 + p2 ) / 2.;
1429 gp_XYZ p31 = ( p3 + p1 ) / 2.;
1431 gp_Vec v1( p31 - p2 ), v2( p12 - p23 );
1433 return v1.Magnitude() < gp::Resolution() || v2.Magnitude() < gp::Resolution() ? 0. : v1.Angle( v2 );
1436 double Skew::GetValue( const TSequenceOfXYZ& P )
1438 if ( P.size() != 3 && P.size() != 4 )
1442 const double PI2 = M_PI / 2.;
1443 if ( P.size() == 3 )
1445 double A0 = fabs( PI2 - skewAngle( P( 3 ), P( 1 ), P( 2 ) ) );
1446 double A1 = fabs( PI2 - skewAngle( P( 1 ), P( 2 ), P( 3 ) ) );
1447 double A2 = fabs( PI2 - skewAngle( P( 2 ), P( 3 ), P( 1 ) ) );
1449 return Max( A0, Max( A1, A2 ) ) * 180. / M_PI;
1453 gp_XYZ p12 = ( P( 1 ) + P( 2 ) ) / 2.;
1454 gp_XYZ p23 = ( P( 2 ) + P( 3 ) ) / 2.;
1455 gp_XYZ p34 = ( P( 3 ) + P( 4 ) ) / 2.;
1456 gp_XYZ p41 = ( P( 4 ) + P( 1 ) ) / 2.;
1458 gp_Vec v1( p34 - p12 ), v2( p23 - p41 );
1459 double A = v1.Magnitude() <= gp::Resolution() || v2.Magnitude() <= gp::Resolution()
1460 ? 0. : fabs( PI2 - v1.Angle( v2 ) );
1462 double val = A * 180. / M_PI;
1464 const double eps = 0.1; // val is in degrees
1466 return val < eps ? 0. : val;
1470 double Skew::GetBadRate( double Value, int /*nbNodes*/ ) const
1472 // the skew is in the range [0.0,PI/2].
1478 SMDSAbs_ElementType Skew::GetType() const
1480 return SMDSAbs_Face;
1484 //================================================================================
1487 Description : Functor for calculating area
1489 //================================================================================
1491 double Area::GetValue( const TSequenceOfXYZ& P )
1496 gp_Vec aVec1( P(2) - P(1) );
1497 gp_Vec aVec2( P(3) - P(1) );
1498 gp_Vec SumVec = aVec1 ^ aVec2;
1500 for (size_t i=4; i<=P.size(); i++)
1502 gp_Vec aVec1( P(i-1) - P(1) );
1503 gp_Vec aVec2( P(i ) - P(1) );
1504 gp_Vec tmp = aVec1 ^ aVec2;
1507 val = SumVec.Magnitude() * 0.5;
1512 double Area::GetBadRate( double Value, int /*nbNodes*/ ) const
1514 // meaningless as it is not a quality control functor
1518 SMDSAbs_ElementType Area::GetType() const
1520 return SMDSAbs_Face;
1523 //================================================================================
1526 Description : Functor for calculating length of edge
1528 //================================================================================
1530 double Length::GetValue( const TSequenceOfXYZ& P )
1532 switch ( P.size() ) {
1533 case 2: return getDistance( P( 1 ), P( 2 ) );
1534 case 3: return getDistance( P( 1 ), P( 2 ) ) + getDistance( P( 2 ), P( 3 ) );
1539 double Length::GetBadRate( double Value, int /*nbNodes*/ ) const
1541 // meaningless as it is not quality control functor
1545 SMDSAbs_ElementType Length::GetType() const
1547 return SMDSAbs_Edge;
1550 //================================================================================
1553 Description : Functor for calculating minimal length of edge
1555 //================================================================================
1557 double Length2D::GetValue( const TSequenceOfXYZ& P )
1561 SMDSAbs_EntityType aType = P.getElementEntity();
1564 case SMDSEntity_Edge:
1566 aVal = getDistance( P( 1 ), P( 2 ) );
1568 case SMDSEntity_Quad_Edge:
1569 if (len == 3) // quadratic edge
1570 aVal = getDistance(P( 1 ),P( 3 )) + getDistance(P( 3 ),P( 2 ));
1572 case SMDSEntity_Triangle:
1573 if (len == 3){ // triangles
1574 double L1 = getDistance(P( 1 ),P( 2 ));
1575 double L2 = getDistance(P( 2 ),P( 3 ));
1576 double L3 = getDistance(P( 3 ),P( 1 ));
1577 aVal = Min(L1,Min(L2,L3));
1580 case SMDSEntity_Quadrangle:
1581 if (len == 4){ // quadrangles
1582 double L1 = getDistance(P( 1 ),P( 2 ));
1583 double L2 = getDistance(P( 2 ),P( 3 ));
1584 double L3 = getDistance(P( 3 ),P( 4 ));
1585 double L4 = getDistance(P( 4 ),P( 1 ));
1586 aVal = Min(Min(L1,L2),Min(L3,L4));
1589 case SMDSEntity_Quad_Triangle:
1590 case SMDSEntity_BiQuad_Triangle:
1591 if (len >= 6){ // quadratic triangles
1592 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1593 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1594 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 1 ));
1595 aVal = Min(L1,Min(L2,L3));
1598 case SMDSEntity_Quad_Quadrangle:
1599 case SMDSEntity_BiQuad_Quadrangle:
1600 if (len >= 8){ // quadratic quadrangles
1601 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1602 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1603 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 7 ));
1604 double L4 = getDistance(P( 7 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
1605 aVal = Min(Min(L1,L2),Min(L3,L4));
1608 case SMDSEntity_Tetra:
1609 if (len == 4){ // tetrahedra
1610 double L1 = getDistance(P( 1 ),P( 2 ));
1611 double L2 = getDistance(P( 2 ),P( 3 ));
1612 double L3 = getDistance(P( 3 ),P( 1 ));
1613 double L4 = getDistance(P( 1 ),P( 4 ));
1614 double L5 = getDistance(P( 2 ),P( 4 ));
1615 double L6 = getDistance(P( 3 ),P( 4 ));
1616 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1619 case SMDSEntity_Pyramid:
1620 if (len == 5){ // pyramid
1621 double L1 = getDistance(P( 1 ),P( 2 ));
1622 double L2 = getDistance(P( 2 ),P( 3 ));
1623 double L3 = getDistance(P( 3 ),P( 4 ));
1624 double L4 = getDistance(P( 4 ),P( 1 ));
1625 double L5 = getDistance(P( 1 ),P( 5 ));
1626 double L6 = getDistance(P( 2 ),P( 5 ));
1627 double L7 = getDistance(P( 3 ),P( 5 ));
1628 double L8 = getDistance(P( 4 ),P( 5 ));
1630 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1631 aVal = Min(aVal,Min(L7,L8));
1634 case SMDSEntity_Penta:
1635 if (len == 6) { // pentahedron
1636 double L1 = getDistance(P( 1 ),P( 2 ));
1637 double L2 = getDistance(P( 2 ),P( 3 ));
1638 double L3 = getDistance(P( 3 ),P( 1 ));
1639 double L4 = getDistance(P( 4 ),P( 5 ));
1640 double L5 = getDistance(P( 5 ),P( 6 ));
1641 double L6 = getDistance(P( 6 ),P( 4 ));
1642 double L7 = getDistance(P( 1 ),P( 4 ));
1643 double L8 = getDistance(P( 2 ),P( 5 ));
1644 double L9 = getDistance(P( 3 ),P( 6 ));
1646 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1647 aVal = Min(aVal,Min(Min(L7,L8),L9));
1650 case SMDSEntity_Hexa:
1651 if (len == 8){ // hexahedron
1652 double L1 = getDistance(P( 1 ),P( 2 ));
1653 double L2 = getDistance(P( 2 ),P( 3 ));
1654 double L3 = getDistance(P( 3 ),P( 4 ));
1655 double L4 = getDistance(P( 4 ),P( 1 ));
1656 double L5 = getDistance(P( 5 ),P( 6 ));
1657 double L6 = getDistance(P( 6 ),P( 7 ));
1658 double L7 = getDistance(P( 7 ),P( 8 ));
1659 double L8 = getDistance(P( 8 ),P( 5 ));
1660 double L9 = getDistance(P( 1 ),P( 5 ));
1661 double L10= getDistance(P( 2 ),P( 6 ));
1662 double L11= getDistance(P( 3 ),P( 7 ));
1663 double L12= getDistance(P( 4 ),P( 8 ));
1665 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1666 aVal = Min(aVal,Min(Min(L7,L8),Min(L9,L10)));
1667 aVal = Min(aVal,Min(L11,L12));
1670 case SMDSEntity_Quad_Tetra:
1671 if (len == 10){ // quadratic tetrahedron
1672 double L1 = getDistance(P( 1 ),P( 5 )) + getDistance(P( 5 ),P( 2 ));
1673 double L2 = getDistance(P( 2 ),P( 6 )) + getDistance(P( 6 ),P( 3 ));
1674 double L3 = getDistance(P( 3 ),P( 7 )) + getDistance(P( 7 ),P( 1 ));
1675 double L4 = getDistance(P( 1 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
1676 double L5 = getDistance(P( 2 ),P( 9 )) + getDistance(P( 9 ),P( 4 ));
1677 double L6 = getDistance(P( 3 ),P( 10 )) + getDistance(P( 10 ),P( 4 ));
1678 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1681 case SMDSEntity_Quad_Pyramid:
1682 if (len == 13){ // quadratic pyramid
1683 double L1 = getDistance(P( 1 ),P( 6 )) + getDistance(P( 6 ),P( 2 ));
1684 double L2 = getDistance(P( 2 ),P( 7 )) + getDistance(P( 7 ),P( 3 ));
1685 double L3 = getDistance(P( 3 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
1686 double L4 = getDistance(P( 4 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1687 double L5 = getDistance(P( 1 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1688 double L6 = getDistance(P( 2 ),P( 11 )) + getDistance(P( 11 ),P( 5 ));
1689 double L7 = getDistance(P( 3 ),P( 12 )) + getDistance(P( 12 ),P( 5 ));
1690 double L8 = getDistance(P( 4 ),P( 13 )) + getDistance(P( 13 ),P( 5 ));
1691 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1692 aVal = Min(aVal,Min(L7,L8));
1695 case SMDSEntity_Quad_Penta:
1696 //case SMDSEntity_BiQuad_Penta:
1697 if (len >= 15){ // quadratic pentahedron
1698 double L1 = getDistance(P( 1 ),P( 7 )) + getDistance(P( 7 ),P( 2 ));
1699 double L2 = getDistance(P( 2 ),P( 8 )) + getDistance(P( 8 ),P( 3 ));
1700 double L3 = getDistance(P( 3 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1701 double L4 = getDistance(P( 4 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1702 double L5 = getDistance(P( 5 ),P( 11 )) + getDistance(P( 11 ),P( 6 ));
1703 double L6 = getDistance(P( 6 ),P( 12 )) + getDistance(P( 12 ),P( 4 ));
1704 double L7 = getDistance(P( 1 ),P( 13 )) + getDistance(P( 13 ),P( 4 ));
1705 double L8 = getDistance(P( 2 ),P( 14 )) + getDistance(P( 14 ),P( 5 ));
1706 double L9 = getDistance(P( 3 ),P( 15 )) + getDistance(P( 15 ),P( 6 ));
1707 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1708 aVal = Min(aVal,Min(Min(L7,L8),L9));
1711 case SMDSEntity_Quad_Hexa:
1712 case SMDSEntity_TriQuad_Hexa:
1713 if (len >= 20) { // quadratic hexahedron
1714 double L1 = getDistance(P( 1 ),P( 9 )) + getDistance(P( 9 ),P( 2 ));
1715 double L2 = getDistance(P( 2 ),P( 10 )) + getDistance(P( 10 ),P( 3 ));
1716 double L3 = getDistance(P( 3 ),P( 11 )) + getDistance(P( 11 ),P( 4 ));
1717 double L4 = getDistance(P( 4 ),P( 12 )) + getDistance(P( 12 ),P( 1 ));
1718 double L5 = getDistance(P( 5 ),P( 13 )) + getDistance(P( 13 ),P( 6 ));
1719 double L6 = getDistance(P( 6 ),P( 14 )) + getDistance(P( 14 ),P( 7 ));
1720 double L7 = getDistance(P( 7 ),P( 15 )) + getDistance(P( 15 ),P( 8 ));
1721 double L8 = getDistance(P( 8 ),P( 16 )) + getDistance(P( 16 ),P( 5 ));
1722 double L9 = getDistance(P( 1 ),P( 17 )) + getDistance(P( 17 ),P( 5 ));
1723 double L10= getDistance(P( 2 ),P( 18 )) + getDistance(P( 18 ),P( 6 ));
1724 double L11= getDistance(P( 3 ),P( 19 )) + getDistance(P( 19 ),P( 7 ));
1725 double L12= getDistance(P( 4 ),P( 20 )) + getDistance(P( 20 ),P( 8 ));
1726 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1727 aVal = Min(aVal,Min(Min(L7,L8),Min(L9,L10)));
1728 aVal = Min(aVal,Min(L11,L12));
1731 case SMDSEntity_Polygon:
1733 aVal = getDistance( P(1), P( P.size() ));
1734 for ( size_t i = 1; i < P.size(); ++i )
1735 aVal = Min( aVal, getDistance( P( i ), P( i+1 )));
1738 case SMDSEntity_Quad_Polygon:
1740 aVal = getDistance( P(1), P( P.size() )) + getDistance( P(P.size()), P( P.size()-1 ));
1741 for ( size_t i = 1; i < P.size()-1; i += 2 )
1742 aVal = Min( aVal, getDistance( P( i ), P( i+1 )) + getDistance( P( i+1 ), P( i+2 )));
1745 case SMDSEntity_Hexagonal_Prism:
1746 if (len == 12) { // hexagonal prism
1747 double L1 = getDistance(P( 1 ),P( 2 ));
1748 double L2 = getDistance(P( 2 ),P( 3 ));
1749 double L3 = getDistance(P( 3 ),P( 4 ));
1750 double L4 = getDistance(P( 4 ),P( 5 ));
1751 double L5 = getDistance(P( 5 ),P( 6 ));
1752 double L6 = getDistance(P( 6 ),P( 1 ));
1754 double L7 = getDistance(P( 7 ), P( 8 ));
1755 double L8 = getDistance(P( 8 ), P( 9 ));
1756 double L9 = getDistance(P( 9 ), P( 10 ));
1757 double L10= getDistance(P( 10 ),P( 11 ));
1758 double L11= getDistance(P( 11 ),P( 12 ));
1759 double L12= getDistance(P( 12 ),P( 7 ));
1761 double L13 = getDistance(P( 1 ),P( 7 ));
1762 double L14 = getDistance(P( 2 ),P( 8 ));
1763 double L15 = getDistance(P( 3 ),P( 9 ));
1764 double L16 = getDistance(P( 4 ),P( 10 ));
1765 double L17 = getDistance(P( 5 ),P( 11 ));
1766 double L18 = getDistance(P( 6 ),P( 12 ));
1767 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1768 aVal = Min(aVal, Min(Min(Min(L7,L8),Min(L9,L10)),Min(L11,L12)));
1769 aVal = Min(aVal, Min(Min(Min(L13,L14),Min(L15,L16)),Min(L17,L18)));
1772 case SMDSEntity_Polyhedra:
1784 if ( myPrecision >= 0 )
1786 double prec = pow( 10., (double)( myPrecision ) );
1787 aVal = floor( aVal * prec + 0.5 ) / prec;
1793 double Length2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1795 // meaningless as it is not a quality control functor
1799 SMDSAbs_ElementType Length2D::GetType() const
1801 return SMDSAbs_Face;
1804 Length2D::Value::Value(double theLength,long thePntId1, long thePntId2):
1807 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1808 if(thePntId1 > thePntId2){
1809 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1813 bool Length2D::Value::operator<(const Length2D::Value& x) const
1815 if(myPntId[0] < x.myPntId[0]) return true;
1816 if(myPntId[0] == x.myPntId[0])
1817 if(myPntId[1] < x.myPntId[1]) return true;
1821 void Length2D::GetValues(TValues& theValues)
1824 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1825 for(; anIter->more(); ){
1826 const SMDS_MeshFace* anElem = anIter->next();
1828 if(anElem->IsQuadratic()) {
1829 const SMDS_VtkFace* F =
1830 dynamic_cast<const SMDS_VtkFace*>(anElem);
1831 // use special nodes iterator
1832 SMDS_ElemIteratorPtr anIter = F->interlacedNodesElemIterator();
1833 long aNodeId[4] = { 0,0,0,0 };
1837 const SMDS_MeshElement* aNode;
1839 aNode = anIter->next();
1840 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1841 P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1842 aNodeId[0] = aNodeId[1] = aNode->GetID();
1845 for(; anIter->more(); ){
1846 const SMDS_MeshNode* N1 = static_cast<const SMDS_MeshNode*> (anIter->next());
1847 P[2] = gp_Pnt(N1->X(),N1->Y(),N1->Z());
1848 aNodeId[2] = N1->GetID();
1849 aLength = P[1].Distance(P[2]);
1850 if(!anIter->more()) break;
1851 const SMDS_MeshNode* N2 = static_cast<const SMDS_MeshNode*> (anIter->next());
1852 P[3] = gp_Pnt(N2->X(),N2->Y(),N2->Z());
1853 aNodeId[3] = N2->GetID();
1854 aLength += P[2].Distance(P[3]);
1855 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1856 Value aValue2(aLength,aNodeId[2],aNodeId[3]);
1858 aNodeId[1] = aNodeId[3];
1859 theValues.insert(aValue1);
1860 theValues.insert(aValue2);
1862 aLength += P[2].Distance(P[0]);
1863 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1864 Value aValue2(aLength,aNodeId[2],aNodeId[0]);
1865 theValues.insert(aValue1);
1866 theValues.insert(aValue2);
1869 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
1870 long aNodeId[2] = {0,0};
1874 const SMDS_MeshElement* aNode;
1875 if(aNodesIter->more()){
1876 aNode = aNodesIter->next();
1877 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1878 P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1879 aNodeId[0] = aNodeId[1] = aNode->GetID();
1882 for(; aNodesIter->more(); ){
1883 aNode = aNodesIter->next();
1884 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1885 long anId = aNode->GetID();
1887 P[2] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1889 aLength = P[1].Distance(P[2]);
1891 Value aValue(aLength,aNodeId[1],anId);
1894 theValues.insert(aValue);
1897 aLength = P[0].Distance(P[1]);
1899 Value aValue(aLength,aNodeId[0],aNodeId[1]);
1900 theValues.insert(aValue);
1905 //================================================================================
1907 Class : Deflection2D
1908 Description : Functor for calculating number of faces conneted to the edge
1910 //================================================================================
1912 double Deflection2D::GetValue( const TSequenceOfXYZ& P )
1914 if ( myMesh && P.getElement() )
1916 // get underlying surface
1917 if ( myShapeIndex != P.getElement()->getshapeId() )
1919 mySurface.Nullify();
1920 myShapeIndex = P.getElement()->getshapeId();
1921 const TopoDS_Shape& S =
1922 static_cast< const SMESHDS_Mesh* >( myMesh )->IndexToShape( myShapeIndex );
1923 if ( !S.IsNull() && S.ShapeType() == TopAbs_FACE )
1925 mySurface = new ShapeAnalysis_Surface( BRep_Tool::Surface( TopoDS::Face( S )));
1927 GeomLib_IsPlanarSurface isPlaneCheck( mySurface->Surface() );
1928 if ( isPlaneCheck.IsPlanar() )
1929 myPlane.reset( new gp_Pln( isPlaneCheck.Plan() ));
1934 // project gravity center to the surface
1935 if ( !mySurface.IsNull() )
1940 for ( size_t i = 0; i < P.size(); ++i )
1944 if ( const SMDS_FacePosition* fPos = dynamic_cast<const SMDS_FacePosition*>
1945 ( P.getElement()->GetNode( i )->GetPosition() ))
1947 uv.ChangeCoord(1) += fPos->GetUParameter();
1948 uv.ChangeCoord(2) += fPos->GetVParameter();
1953 if ( nbUV ) uv /= nbUV;
1955 double maxLen = MaxElementLength2D().GetValue( P );
1956 double tol = 1e-3 * maxLen;
1960 dist = myPlane->Distance( gc );
1966 if ( uv.X() != 0 && uv.Y() != 0 ) // faster way
1967 mySurface->NextValueOfUV( uv, gc, tol, 0.5 * maxLen );
1969 mySurface->ValueOfUV( gc, tol );
1970 dist = mySurface->Gap();
1972 return Round( dist );
1978 void Deflection2D::SetMesh( const SMDS_Mesh* theMesh )
1980 NumericalFunctor::SetMesh( dynamic_cast<const SMESHDS_Mesh* >( theMesh ));
1981 myShapeIndex = -100;
1985 SMDSAbs_ElementType Deflection2D::GetType() const
1987 return SMDSAbs_Face;
1990 double Deflection2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1992 // meaningless as it is not quality control functor
1996 //================================================================================
1998 Class : MultiConnection
1999 Description : Functor for calculating number of faces conneted to the edge
2001 //================================================================================
2003 double MultiConnection::GetValue( const TSequenceOfXYZ& P )
2007 double MultiConnection::GetValue( long theId )
2009 return getNbMultiConnection( myMesh, theId );
2012 double MultiConnection::GetBadRate( double Value, int /*nbNodes*/ ) const
2014 // meaningless as it is not quality control functor
2018 SMDSAbs_ElementType MultiConnection::GetType() const
2020 return SMDSAbs_Edge;
2023 //================================================================================
2025 Class : MultiConnection2D
2026 Description : Functor for calculating number of faces conneted to the edge
2028 //================================================================================
2030 double MultiConnection2D::GetValue( const TSequenceOfXYZ& P )
2035 double MultiConnection2D::GetValue( long theElementId )
2039 const SMDS_MeshElement* aFaceElem = myMesh->FindElement(theElementId);
2040 SMDSAbs_ElementType aType = aFaceElem->GetType();
2045 int i = 0, len = aFaceElem->NbNodes();
2046 SMDS_ElemIteratorPtr anIter = aFaceElem->nodesIterator();
2049 const SMDS_MeshNode *aNode, *aNode0 = 0;
2050 TColStd_MapOfInteger aMap, aMapPrev;
2052 for (i = 0; i <= len; i++) {
2057 if (anIter->more()) {
2058 aNode = (SMDS_MeshNode*)anIter->next();
2066 if (i == 0) aNode0 = aNode;
2068 SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator();
2069 while (anElemIter->more()) {
2070 const SMDS_MeshElement* anElem = anElemIter->next();
2071 if (anElem != 0 && anElem->GetType() == SMDSAbs_Face) {
2072 int anId = anElem->GetID();
2075 if (aMapPrev.Contains(anId)) {
2080 aResult = Max(aResult, aNb);
2091 double MultiConnection2D::GetBadRate( double Value, int /*nbNodes*/ ) const
2093 // meaningless as it is not quality control functor
2097 SMDSAbs_ElementType MultiConnection2D::GetType() const
2099 return SMDSAbs_Face;
2102 MultiConnection2D::Value::Value(long thePntId1, long thePntId2)
2104 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
2105 if(thePntId1 > thePntId2){
2106 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
2110 bool MultiConnection2D::Value::operator<(const MultiConnection2D::Value& x) const
2112 if(myPntId[0] < x.myPntId[0]) return true;
2113 if(myPntId[0] == x.myPntId[0])
2114 if(myPntId[1] < x.myPntId[1]) return true;
2118 void MultiConnection2D::GetValues(MValues& theValues)
2120 if ( !myMesh ) return;
2121 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
2122 for(; anIter->more(); ){
2123 const SMDS_MeshFace* anElem = anIter->next();
2124 SMDS_ElemIteratorPtr aNodesIter;
2125 if ( anElem->IsQuadratic() )
2126 aNodesIter = dynamic_cast<const SMDS_VtkFace*>
2127 (anElem)->interlacedNodesElemIterator();
2129 aNodesIter = anElem->nodesIterator();
2130 long aNodeId[3] = {0,0,0};
2132 //int aNbConnects=0;
2133 const SMDS_MeshNode* aNode0;
2134 const SMDS_MeshNode* aNode1;
2135 const SMDS_MeshNode* aNode2;
2136 if(aNodesIter->more()){
2137 aNode0 = (SMDS_MeshNode*) aNodesIter->next();
2139 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode1;
2140 aNodeId[0] = aNodeId[1] = aNodes->GetID();
2142 for(; aNodesIter->more(); ) {
2143 aNode2 = (SMDS_MeshNode*) aNodesIter->next();
2144 long anId = aNode2->GetID();
2147 Value aValue(aNodeId[1],aNodeId[2]);
2148 MValues::iterator aItr = theValues.find(aValue);
2149 if (aItr != theValues.end()){
2154 theValues[aValue] = 1;
2157 //cout << "NodeIds: "<<aNodeId[1]<<","<<aNodeId[2]<<" nbconn="<<aNbConnects<<endl;
2158 aNodeId[1] = aNodeId[2];
2161 Value aValue(aNodeId[0],aNodeId[2]);
2162 MValues::iterator aItr = theValues.find(aValue);
2163 if (aItr != theValues.end()) {
2168 theValues[aValue] = 1;
2171 //cout << "NodeIds: "<<aNodeId[0]<<","<<aNodeId[2]<<" nbconn="<<aNbConnects<<endl;
2176 //================================================================================
2178 Class : BallDiameter
2179 Description : Functor returning diameter of a ball element
2181 //================================================================================
2183 double BallDiameter::GetValue( long theId )
2185 double diameter = 0;
2187 if ( const SMDS_BallElement* ball =
2188 dynamic_cast<const SMDS_BallElement*>( myMesh->FindElement( theId )))
2190 diameter = ball->GetDiameter();
2195 double BallDiameter::GetBadRate( double Value, int /*nbNodes*/ ) const
2197 // meaningless as it is not a quality control functor
2201 SMDSAbs_ElementType BallDiameter::GetType() const
2203 return SMDSAbs_Ball;
2206 //================================================================================
2208 Class : NodeConnectivityNumber
2209 Description : Functor returning number of elements connected to a node
2211 //================================================================================
2213 double NodeConnectivityNumber::GetValue( long theId )
2217 if ( const SMDS_MeshNode* node = myMesh->FindNode( theId ))
2219 SMDSAbs_ElementType type;
2220 if ( myMesh->NbVolumes() > 0 )
2221 type = SMDSAbs_Volume;
2222 else if ( myMesh->NbFaces() > 0 )
2223 type = SMDSAbs_Face;
2224 else if ( myMesh->NbEdges() > 0 )
2225 type = SMDSAbs_Edge;
2228 nb = node->NbInverseElements( type );
2233 double NodeConnectivityNumber::GetBadRate( double Value, int /*nbNodes*/ ) const
2238 SMDSAbs_ElementType NodeConnectivityNumber::GetType() const
2240 return SMDSAbs_Node;
2247 //================================================================================
2249 Class : BadOrientedVolume
2250 Description : Predicate bad oriented volumes
2252 //================================================================================
2254 BadOrientedVolume::BadOrientedVolume()
2259 void BadOrientedVolume::SetMesh( const SMDS_Mesh* theMesh )
2264 bool BadOrientedVolume::IsSatisfy( long theId )
2269 SMDS_VolumeTool vTool( myMesh->FindElement( theId ));
2270 return !vTool.IsForward();
2273 SMDSAbs_ElementType BadOrientedVolume::GetType() const
2275 return SMDSAbs_Volume;
2279 Class : BareBorderVolume
2282 bool BareBorderVolume::IsSatisfy(long theElementId )
2284 SMDS_VolumeTool myTool;
2285 if ( myTool.Set( myMesh->FindElement(theElementId)))
2287 for ( int iF = 0; iF < myTool.NbFaces(); ++iF )
2288 if ( myTool.IsFreeFace( iF ))
2290 const SMDS_MeshNode** n = myTool.GetFaceNodes(iF);
2291 std::vector< const SMDS_MeshNode*> nodes( n, n+myTool.NbFaceNodes(iF));
2292 if ( !myMesh->FindElement( nodes, SMDSAbs_Face, /*Nomedium=*/false))
2299 //================================================================================
2301 Class : BareBorderFace
2303 //================================================================================
2305 bool BareBorderFace::IsSatisfy(long theElementId )
2308 if ( const SMDS_MeshElement* face = myMesh->FindElement(theElementId))
2310 if ( face->GetType() == SMDSAbs_Face )
2312 int nbN = face->NbCornerNodes();
2313 for ( int i = 0; i < nbN && !ok; ++i )
2315 // check if a link is shared by another face
2316 const SMDS_MeshNode* n1 = face->GetNode( i );
2317 const SMDS_MeshNode* n2 = face->GetNode( (i+1)%nbN );
2318 SMDS_ElemIteratorPtr fIt = n1->GetInverseElementIterator( SMDSAbs_Face );
2319 bool isShared = false;
2320 while ( !isShared && fIt->more() )
2322 const SMDS_MeshElement* f = fIt->next();
2323 isShared = ( f != face && f->GetNodeIndex(n2) != -1 );
2327 const int iQuad = face->IsQuadratic();
2328 myLinkNodes.resize( 2 + iQuad);
2329 myLinkNodes[0] = n1;
2330 myLinkNodes[1] = n2;
2332 myLinkNodes[2] = face->GetNode( i+nbN );
2333 ok = !myMesh->FindElement( myLinkNodes, SMDSAbs_Edge, /*noMedium=*/false);
2341 //================================================================================
2343 Class : OverConstrainedVolume
2345 //================================================================================
2347 bool OverConstrainedVolume::IsSatisfy(long theElementId )
2349 // An element is over-constrained if it has N-1 free borders where
2350 // N is the number of edges/faces for a 2D/3D element.
2351 SMDS_VolumeTool myTool;
2352 if ( myTool.Set( myMesh->FindElement(theElementId)))
2354 int nbSharedFaces = 0;
2355 for ( int iF = 0; iF < myTool.NbFaces(); ++iF )
2356 if ( !myTool.IsFreeFace( iF ) && ++nbSharedFaces > 1 )
2358 return ( nbSharedFaces == 1 );
2363 //================================================================================
2365 Class : OverConstrainedFace
2367 //================================================================================
2369 bool OverConstrainedFace::IsSatisfy(long theElementId )
2371 // An element is over-constrained if it has N-1 free borders where
2372 // N is the number of edges/faces for a 2D/3D element.
2373 if ( const SMDS_MeshElement* face = myMesh->FindElement(theElementId))
2374 if ( face->GetType() == SMDSAbs_Face )
2376 int nbSharedBorders = 0;
2377 int nbN = face->NbCornerNodes();
2378 for ( int i = 0; i < nbN; ++i )
2380 // check if a link is shared by another face
2381 const SMDS_MeshNode* n1 = face->GetNode( i );
2382 const SMDS_MeshNode* n2 = face->GetNode( (i+1)%nbN );
2383 SMDS_ElemIteratorPtr fIt = n1->GetInverseElementIterator( SMDSAbs_Face );
2384 bool isShared = false;
2385 while ( !isShared && fIt->more() )
2387 const SMDS_MeshElement* f = fIt->next();
2388 isShared = ( f != face && f->GetNodeIndex(n2) != -1 );
2390 if ( isShared && ++nbSharedBorders > 1 )
2393 return ( nbSharedBorders == 1 );
2398 //================================================================================
2400 Class : CoincidentNodes
2401 Description : Predicate of Coincident nodes
2403 //================================================================================
2405 CoincidentNodes::CoincidentNodes()
2410 bool CoincidentNodes::IsSatisfy( long theElementId )
2412 return myCoincidentIDs.Contains( theElementId );
2415 SMDSAbs_ElementType CoincidentNodes::GetType() const
2417 return SMDSAbs_Node;
2420 void CoincidentNodes::SetMesh( const SMDS_Mesh* theMesh )
2422 myMeshModifTracer.SetMesh( theMesh );
2423 if ( myMeshModifTracer.IsMeshModified() )
2425 TIDSortedNodeSet nodesToCheck;
2426 SMDS_NodeIteratorPtr nIt = theMesh->nodesIterator(/*idInceasingOrder=*/true);
2427 while ( nIt->more() )
2428 nodesToCheck.insert( nodesToCheck.end(), nIt->next() );
2430 std::list< std::list< const SMDS_MeshNode*> > nodeGroups;
2431 SMESH_OctreeNode::FindCoincidentNodes ( nodesToCheck, &nodeGroups, myToler );
2433 myCoincidentIDs.Clear();
2434 std::list< std::list< const SMDS_MeshNode*> >::iterator groupIt = nodeGroups.begin();
2435 for ( ; groupIt != nodeGroups.end(); ++groupIt )
2437 std::list< const SMDS_MeshNode*>& coincNodes = *groupIt;
2438 std::list< const SMDS_MeshNode*>::iterator n = coincNodes.begin();
2439 for ( ; n != coincNodes.end(); ++n )
2440 myCoincidentIDs.Add( (*n)->GetID() );
2445 //================================================================================
2447 Class : CoincidentElements
2448 Description : Predicate of Coincident Elements
2449 Note : This class is suitable only for visualization of Coincident Elements
2451 //================================================================================
2453 CoincidentElements::CoincidentElements()
2458 void CoincidentElements::SetMesh( const SMDS_Mesh* theMesh )
2463 bool CoincidentElements::IsSatisfy( long theElementId )
2465 if ( !myMesh ) return false;
2467 if ( const SMDS_MeshElement* e = myMesh->FindElement( theElementId ))
2469 if ( e->GetType() != GetType() ) return false;
2470 std::set< const SMDS_MeshNode* > elemNodes( e->begin_nodes(), e->end_nodes() );
2471 const int nbNodes = e->NbNodes();
2472 SMDS_ElemIteratorPtr invIt = (*elemNodes.begin())->GetInverseElementIterator( GetType() );
2473 while ( invIt->more() )
2475 const SMDS_MeshElement* e2 = invIt->next();
2476 if ( e2 == e || e2->NbNodes() != nbNodes ) continue;
2478 bool sameNodes = true;
2479 for ( size_t i = 0; i < elemNodes.size() && sameNodes; ++i )
2480 sameNodes = ( elemNodes.count( e2->GetNode( i )));
2488 SMDSAbs_ElementType CoincidentElements1D::GetType() const
2490 return SMDSAbs_Edge;
2492 SMDSAbs_ElementType CoincidentElements2D::GetType() const
2494 return SMDSAbs_Face;
2496 SMDSAbs_ElementType CoincidentElements3D::GetType() const
2498 return SMDSAbs_Volume;
2502 //================================================================================
2505 Description : Predicate for free borders
2507 //================================================================================
2509 FreeBorders::FreeBorders()
2514 void FreeBorders::SetMesh( const SMDS_Mesh* theMesh )
2519 bool FreeBorders::IsSatisfy( long theId )
2521 return getNbMultiConnection( myMesh, theId ) == 1;
2524 SMDSAbs_ElementType FreeBorders::GetType() const
2526 return SMDSAbs_Edge;
2530 //================================================================================
2533 Description : Predicate for free Edges
2535 //================================================================================
2537 FreeEdges::FreeEdges()
2542 void FreeEdges::SetMesh( const SMDS_Mesh* theMesh )
2547 bool FreeEdges::IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId )
2549 TColStd_MapOfInteger aMap;
2550 for ( int i = 0; i < 2; i++ )
2552 SMDS_ElemIteratorPtr anElemIter = theNodes[ i ]->GetInverseElementIterator(SMDSAbs_Face);
2553 while( anElemIter->more() )
2555 if ( const SMDS_MeshElement* anElem = anElemIter->next())
2557 const int anId = anElem->GetID();
2558 if ( anId != theFaceId && !aMap.Add( anId ))
2566 bool FreeEdges::IsSatisfy( long theId )
2571 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
2572 if ( aFace == 0 || aFace->GetType() != SMDSAbs_Face || aFace->NbNodes() < 3 )
2575 SMDS_NodeIteratorPtr anIter = aFace->interlacedNodesIterator();
2579 int i = 0, nbNodes = aFace->NbNodes();
2580 std::vector <const SMDS_MeshNode*> aNodes( nbNodes+1 );
2581 while( anIter->more() )
2582 if ( ! ( aNodes[ i++ ] = anIter->next() ))
2584 aNodes[ nbNodes ] = aNodes[ 0 ];
2586 for ( i = 0; i < nbNodes; i++ )
2587 if ( IsFreeEdge( &aNodes[ i ], theId ) )
2593 SMDSAbs_ElementType FreeEdges::GetType() const
2595 return SMDSAbs_Face;
2598 FreeEdges::Border::Border(long theElemId, long thePntId1, long thePntId2):
2601 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
2602 if(thePntId1 > thePntId2){
2603 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
2607 bool FreeEdges::Border::operator<(const FreeEdges::Border& x) const{
2608 if(myPntId[0] < x.myPntId[0]) return true;
2609 if(myPntId[0] == x.myPntId[0])
2610 if(myPntId[1] < x.myPntId[1]) return true;
2614 inline void UpdateBorders(const FreeEdges::Border& theBorder,
2615 FreeEdges::TBorders& theRegistry,
2616 FreeEdges::TBorders& theContainer)
2618 if(theRegistry.find(theBorder) == theRegistry.end()){
2619 theRegistry.insert(theBorder);
2620 theContainer.insert(theBorder);
2622 theContainer.erase(theBorder);
2626 void FreeEdges::GetBoreders(TBorders& theBorders)
2629 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
2630 for(; anIter->more(); ){
2631 const SMDS_MeshFace* anElem = anIter->next();
2632 long anElemId = anElem->GetID();
2633 SMDS_ElemIteratorPtr aNodesIter;
2634 if ( anElem->IsQuadratic() )
2635 aNodesIter = static_cast<const SMDS_VtkFace*>(anElem)->
2636 interlacedNodesElemIterator();
2638 aNodesIter = anElem->nodesIterator();
2639 long aNodeId[2] = {0,0};
2640 const SMDS_MeshElement* aNode;
2641 if(aNodesIter->more()){
2642 aNode = aNodesIter->next();
2643 aNodeId[0] = aNodeId[1] = aNode->GetID();
2645 for(; aNodesIter->more(); ){
2646 aNode = aNodesIter->next();
2647 long anId = aNode->GetID();
2648 Border aBorder(anElemId,aNodeId[1],anId);
2650 UpdateBorders(aBorder,aRegistry,theBorders);
2652 Border aBorder(anElemId,aNodeId[0],aNodeId[1]);
2653 UpdateBorders(aBorder,aRegistry,theBorders);
2657 //================================================================================
2660 Description : Predicate for free nodes
2662 //================================================================================
2664 FreeNodes::FreeNodes()
2669 void FreeNodes::SetMesh( const SMDS_Mesh* theMesh )
2674 bool FreeNodes::IsSatisfy( long theNodeId )
2676 const SMDS_MeshNode* aNode = myMesh->FindNode( theNodeId );
2680 return (aNode->NbInverseElements() < 1);
2683 SMDSAbs_ElementType FreeNodes::GetType() const
2685 return SMDSAbs_Node;
2689 //================================================================================
2692 Description : Predicate for free faces
2694 //================================================================================
2696 FreeFaces::FreeFaces()
2701 void FreeFaces::SetMesh( const SMDS_Mesh* theMesh )
2706 bool FreeFaces::IsSatisfy( long theId )
2708 if (!myMesh) return false;
2709 // check that faces nodes refers to less than two common volumes
2710 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
2711 if ( !aFace || aFace->GetType() != SMDSAbs_Face )
2714 int nbNode = aFace->NbNodes();
2716 // collect volumes to check that number of volumes with count equal nbNode not less than 2
2717 typedef std::map< SMDS_MeshElement*, int > TMapOfVolume; // map of volume counters
2718 typedef std::map< SMDS_MeshElement*, int >::iterator TItrMapOfVolume; // iterator
2719 TMapOfVolume mapOfVol;
2721 SMDS_ElemIteratorPtr nodeItr = aFace->nodesIterator();
2722 while ( nodeItr->more() )
2724 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(nodeItr->next());
2725 if ( !aNode ) continue;
2726 SMDS_ElemIteratorPtr volItr = aNode->GetInverseElementIterator(SMDSAbs_Volume);
2727 while ( volItr->more() )
2729 SMDS_MeshElement* aVol = (SMDS_MeshElement*)volItr->next();
2730 TItrMapOfVolume itr = mapOfVol.insert( std::make_pair( aVol, 0 )).first;
2735 TItrMapOfVolume volItr = mapOfVol.begin();
2736 TItrMapOfVolume volEnd = mapOfVol.end();
2737 for ( ; volItr != volEnd; ++volItr )
2738 if ( (*volItr).second >= nbNode )
2740 // face is not free if number of volumes constructed on their nodes more than one
2744 SMDSAbs_ElementType FreeFaces::GetType() const
2746 return SMDSAbs_Face;
2749 //================================================================================
2751 Class : LinearOrQuadratic
2752 Description : Predicate to verify whether a mesh element is linear
2754 //================================================================================
2756 LinearOrQuadratic::LinearOrQuadratic()
2761 void LinearOrQuadratic::SetMesh( const SMDS_Mesh* theMesh )
2766 bool LinearOrQuadratic::IsSatisfy( long theId )
2768 if (!myMesh) return false;
2769 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2770 if ( !anElem || (myType != SMDSAbs_All && anElem->GetType() != myType) )
2772 return (!anElem->IsQuadratic());
2775 void LinearOrQuadratic::SetType( SMDSAbs_ElementType theType )
2780 SMDSAbs_ElementType LinearOrQuadratic::GetType() const
2785 //================================================================================
2788 Description : Functor for check color of group to which mesh element belongs to
2790 //================================================================================
2792 GroupColor::GroupColor()
2796 bool GroupColor::IsSatisfy( long theId )
2798 return myIDs.count( theId );
2801 void GroupColor::SetType( SMDSAbs_ElementType theType )
2806 SMDSAbs_ElementType GroupColor::GetType() const
2811 static bool isEqual( const Quantity_Color& theColor1,
2812 const Quantity_Color& theColor2 )
2814 // tolerance to compare colors
2815 const double tol = 5*1e-3;
2816 return ( fabs( theColor1.Red() - theColor2.Red() ) < tol &&
2817 fabs( theColor1.Green() - theColor2.Green() ) < tol &&
2818 fabs( theColor1.Blue() - theColor2.Blue() ) < tol );
2821 void GroupColor::SetMesh( const SMDS_Mesh* theMesh )
2825 const SMESHDS_Mesh* aMesh = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
2829 int nbGrp = aMesh->GetNbGroups();
2833 // iterates on groups and find necessary elements ids
2834 const std::set<SMESHDS_GroupBase*>& aGroups = aMesh->GetGroups();
2835 std::set<SMESHDS_GroupBase*>::const_iterator GrIt = aGroups.begin();
2836 for (; GrIt != aGroups.end(); GrIt++)
2838 SMESHDS_GroupBase* aGrp = (*GrIt);
2841 // check type and color of group
2842 if ( !isEqual( myColor, aGrp->GetColor() ))
2845 // IPAL52867 (prevent infinite recursion via GroupOnFilter)
2846 if ( SMESHDS_GroupOnFilter * gof = dynamic_cast< SMESHDS_GroupOnFilter* >( aGrp ))
2847 if ( gof->GetPredicate().get() == this )
2850 SMDSAbs_ElementType aGrpElType = (SMDSAbs_ElementType)aGrp->GetType();
2851 if ( myType == aGrpElType || (myType == SMDSAbs_All && aGrpElType != SMDSAbs_Node) ) {
2852 // add elements IDS into control
2853 int aSize = aGrp->Extent();
2854 for (int i = 0; i < aSize; i++)
2855 myIDs.insert( aGrp->GetID(i+1) );
2860 void GroupColor::SetColorStr( const TCollection_AsciiString& theStr )
2862 Kernel_Utils::Localizer loc;
2863 TCollection_AsciiString aStr = theStr;
2864 aStr.RemoveAll( ' ' );
2865 aStr.RemoveAll( '\t' );
2866 for ( int aPos = aStr.Search( ";;" ); aPos != -1; aPos = aStr.Search( ";;" ) )
2867 aStr.Remove( aPos, 2 );
2868 Standard_Real clr[3];
2869 clr[0] = clr[1] = clr[2] = 0.;
2870 for ( int i = 0; i < 3; i++ ) {
2871 TCollection_AsciiString tmpStr = aStr.Token( ";", i+1 );
2872 if ( !tmpStr.IsEmpty() && tmpStr.IsRealValue() )
2873 clr[i] = tmpStr.RealValue();
2875 myColor = Quantity_Color( clr[0], clr[1], clr[2], Quantity_TOC_RGB );
2878 //=======================================================================
2879 // name : GetRangeStr
2880 // Purpose : Get range as a string.
2881 // Example: "1,2,3,50-60,63,67,70-"
2882 //=======================================================================
2884 void GroupColor::GetColorStr( TCollection_AsciiString& theResStr ) const
2887 theResStr += TCollection_AsciiString( myColor.Red() );
2888 theResStr += TCollection_AsciiString( ";" ) + TCollection_AsciiString( myColor.Green() );
2889 theResStr += TCollection_AsciiString( ";" ) + TCollection_AsciiString( myColor.Blue() );
2892 //================================================================================
2894 Class : ElemGeomType
2895 Description : Predicate to check element geometry type
2897 //================================================================================
2899 ElemGeomType::ElemGeomType()
2902 myType = SMDSAbs_All;
2903 myGeomType = SMDSGeom_TRIANGLE;
2906 void ElemGeomType::SetMesh( const SMDS_Mesh* theMesh )
2911 bool ElemGeomType::IsSatisfy( long theId )
2913 if (!myMesh) return false;
2914 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2917 const SMDSAbs_ElementType anElemType = anElem->GetType();
2918 if ( myType != SMDSAbs_All && anElemType != myType )
2920 bool isOk = ( anElem->GetGeomType() == myGeomType );
2924 void ElemGeomType::SetType( SMDSAbs_ElementType theType )
2929 SMDSAbs_ElementType ElemGeomType::GetType() const
2934 void ElemGeomType::SetGeomType( SMDSAbs_GeometryType theType )
2936 myGeomType = theType;
2939 SMDSAbs_GeometryType ElemGeomType::GetGeomType() const
2944 //================================================================================
2946 Class : ElemEntityType
2947 Description : Predicate to check element entity type
2949 //================================================================================
2951 ElemEntityType::ElemEntityType():
2953 myType( SMDSAbs_All ),
2954 myEntityType( SMDSEntity_0D )
2958 void ElemEntityType::SetMesh( const SMDS_Mesh* theMesh )
2963 bool ElemEntityType::IsSatisfy( long theId )
2965 if ( !myMesh ) return false;
2966 if ( myType == SMDSAbs_Node )
2967 return myMesh->FindNode( theId );
2968 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2970 myEntityType == anElem->GetEntityType() );
2973 void ElemEntityType::SetType( SMDSAbs_ElementType theType )
2978 SMDSAbs_ElementType ElemEntityType::GetType() const
2983 void ElemEntityType::SetElemEntityType( SMDSAbs_EntityType theEntityType )
2985 myEntityType = theEntityType;
2988 SMDSAbs_EntityType ElemEntityType::GetElemEntityType() const
2990 return myEntityType;
2993 //================================================================================
2995 * \brief Class ConnectedElements
2997 //================================================================================
2999 ConnectedElements::ConnectedElements():
3000 myNodeID(0), myType( SMDSAbs_All ), myOkIDsReady( false ) {}
3002 SMDSAbs_ElementType ConnectedElements::GetType() const
3005 int ConnectedElements::GetNode() const
3006 { return myXYZ.empty() ? myNodeID : 0; } // myNodeID can be found by myXYZ
3008 std::vector<double> ConnectedElements::GetPoint() const
3011 void ConnectedElements::clearOkIDs()
3012 { myOkIDsReady = false; myOkIDs.clear(); }
3014 void ConnectedElements::SetType( SMDSAbs_ElementType theType )
3016 if ( myType != theType || myMeshModifTracer.IsMeshModified() )
3021 void ConnectedElements::SetMesh( const SMDS_Mesh* theMesh )
3023 myMeshModifTracer.SetMesh( theMesh );
3024 if ( myMeshModifTracer.IsMeshModified() )
3027 if ( !myXYZ.empty() )
3028 SetPoint( myXYZ[0], myXYZ[1], myXYZ[2] ); // find a node near myXYZ it in a new mesh
3032 void ConnectedElements::SetNode( int nodeID )
3037 bool isSameDomain = false;
3038 if ( myOkIDsReady && myMeshModifTracer.GetMesh() && !myMeshModifTracer.IsMeshModified() )
3039 if ( const SMDS_MeshNode* n = myMeshModifTracer.GetMesh()->FindNode( myNodeID ))
3041 SMDS_ElemIteratorPtr eIt = n->GetInverseElementIterator( myType );
3042 while ( !isSameDomain && eIt->more() )
3043 isSameDomain = IsSatisfy( eIt->next()->GetID() );
3045 if ( !isSameDomain )
3049 void ConnectedElements::SetPoint( double x, double y, double z )
3057 bool isSameDomain = false;
3059 // find myNodeID by myXYZ if possible
3060 if ( myMeshModifTracer.GetMesh() )
3062 SMESHUtils::Deleter<SMESH_ElementSearcher> searcher
3063 ( SMESH_MeshAlgos::GetElementSearcher( (SMDS_Mesh&) *myMeshModifTracer.GetMesh() ));
3065 std::vector< const SMDS_MeshElement* > foundElems;
3066 searcher->FindElementsByPoint( gp_Pnt(x,y,z), SMDSAbs_All, foundElems );
3068 if ( !foundElems.empty() )
3070 myNodeID = foundElems[0]->GetNode(0)->GetID();
3071 if ( myOkIDsReady && !myMeshModifTracer.IsMeshModified() )
3072 isSameDomain = IsSatisfy( foundElems[0]->GetID() );
3075 if ( !isSameDomain )
3079 bool ConnectedElements::IsSatisfy( long theElementId )
3081 // Here we do NOT check if the mesh has changed, we do it in Set...() only!!!
3083 if ( !myOkIDsReady )
3085 if ( !myMeshModifTracer.GetMesh() )
3087 const SMDS_MeshNode* node0 = myMeshModifTracer.GetMesh()->FindNode( myNodeID );
3091 std::list< const SMDS_MeshNode* > nodeQueue( 1, node0 );
3092 std::set< int > checkedNodeIDs;
3094 // foreach node in nodeQueue:
3095 // foreach element sharing a node:
3096 // add ID of an element of myType to myOkIDs;
3097 // push all element nodes absent from checkedNodeIDs to nodeQueue;
3098 while ( !nodeQueue.empty() )
3100 const SMDS_MeshNode* node = nodeQueue.front();
3101 nodeQueue.pop_front();
3103 // loop on elements sharing the node
3104 SMDS_ElemIteratorPtr eIt = node->GetInverseElementIterator();
3105 while ( eIt->more() )
3107 // keep elements of myType
3108 const SMDS_MeshElement* element = eIt->next();
3109 if ( element->GetType() == myType )
3110 myOkIDs.insert( myOkIDs.end(), element->GetID() );
3112 // enqueue nodes of the element
3113 SMDS_ElemIteratorPtr nIt = element->nodesIterator();
3114 while ( nIt->more() )
3116 const SMDS_MeshNode* n = static_cast< const SMDS_MeshNode* >( nIt->next() );
3117 if ( checkedNodeIDs.insert( n->GetID() ).second )
3118 nodeQueue.push_back( n );
3122 if ( myType == SMDSAbs_Node )
3123 std::swap( myOkIDs, checkedNodeIDs );
3125 size_t totalNbElems = myMeshModifTracer.GetMesh()->GetMeshInfo().NbElements( myType );
3126 if ( myOkIDs.size() == totalNbElems )
3129 myOkIDsReady = true;
3132 return myOkIDs.empty() ? true : myOkIDs.count( theElementId );
3135 //================================================================================
3137 * \brief Class CoplanarFaces
3139 //================================================================================
3143 inline bool isLessAngle( const gp_Vec& v1, const gp_Vec& v2, const double cos )
3145 double dot = v1 * v2; // cos * |v1| * |v2|
3146 double l1 = v1.SquareMagnitude();
3147 double l2 = v2.SquareMagnitude();
3148 return (( dot * cos >= 0 ) &&
3149 ( dot * dot ) / l1 / l2 >= ( cos * cos ));
3152 CoplanarFaces::CoplanarFaces()
3153 : myFaceID(0), myToler(0)
3156 void CoplanarFaces::SetMesh( const SMDS_Mesh* theMesh )
3158 myMeshModifTracer.SetMesh( theMesh );
3159 if ( myMeshModifTracer.IsMeshModified() )
3161 // Build a set of coplanar face ids
3163 myCoplanarIDs.Clear();
3165 if ( !myMeshModifTracer.GetMesh() || !myFaceID || !myToler )
3168 const SMDS_MeshElement* face = myMeshModifTracer.GetMesh()->FindElement( myFaceID );
3169 if ( !face || face->GetType() != SMDSAbs_Face )
3173 gp_Vec myNorm = getNormale( static_cast<const SMDS_MeshFace*>(face), &normOK );
3177 const double cosTol = Cos( myToler * M_PI / 180. );
3178 NCollection_Map< SMESH_TLink, SMESH_TLink > checkedLinks;
3180 std::list< std::pair< const SMDS_MeshElement*, gp_Vec > > faceQueue;
3181 faceQueue.push_back( std::make_pair( face, myNorm ));
3182 while ( !faceQueue.empty() )
3184 face = faceQueue.front().first;
3185 myNorm = faceQueue.front().second;
3186 faceQueue.pop_front();
3188 for ( int i = 0, nbN = face->NbCornerNodes(); i < nbN; ++i )
3190 const SMDS_MeshNode* n1 = face->GetNode( i );
3191 const SMDS_MeshNode* n2 = face->GetNode(( i+1 )%nbN);
3192 if ( !checkedLinks.Add( SMESH_TLink( n1, n2 )))
3194 SMDS_ElemIteratorPtr fIt = n1->GetInverseElementIterator(SMDSAbs_Face);
3195 while ( fIt->more() )
3197 const SMDS_MeshElement* f = fIt->next();
3198 if ( f->GetNodeIndex( n2 ) > -1 )
3200 gp_Vec norm = getNormale( static_cast<const SMDS_MeshFace*>(f), &normOK );
3201 if (!normOK || isLessAngle( myNorm, norm, cosTol))
3203 myCoplanarIDs.Add( f->GetID() );
3204 faceQueue.push_back( std::make_pair( f, norm ));
3212 bool CoplanarFaces::IsSatisfy( long theElementId )
3214 return myCoplanarIDs.Contains( theElementId );
3219 *Description : Predicate for Range of Ids.
3220 * Range may be specified with two ways.
3221 * 1. Using AddToRange method
3222 * 2. With SetRangeStr method. Parameter of this method is a string
3223 * like as "1,2,3,50-60,63,67,70-"
3226 //=======================================================================
3227 // name : RangeOfIds
3228 // Purpose : Constructor
3229 //=======================================================================
3230 RangeOfIds::RangeOfIds()
3233 myType = SMDSAbs_All;
3236 //=======================================================================
3238 // Purpose : Set mesh
3239 //=======================================================================
3240 void RangeOfIds::SetMesh( const SMDS_Mesh* theMesh )
3245 //=======================================================================
3246 // name : AddToRange
3247 // Purpose : Add ID to the range
3248 //=======================================================================
3249 bool RangeOfIds::AddToRange( long theEntityId )
3251 myIds.Add( theEntityId );
3255 //=======================================================================
3256 // name : GetRangeStr
3257 // Purpose : Get range as a string.
3258 // Example: "1,2,3,50-60,63,67,70-"
3259 //=======================================================================
3260 void RangeOfIds::GetRangeStr( TCollection_AsciiString& theResStr )
3264 TColStd_SequenceOfInteger anIntSeq;
3265 TColStd_SequenceOfAsciiString aStrSeq;
3267 TColStd_MapIteratorOfMapOfInteger anIter( myIds );
3268 for ( ; anIter.More(); anIter.Next() )
3270 int anId = anIter.Key();
3271 TCollection_AsciiString aStr( anId );
3272 anIntSeq.Append( anId );
3273 aStrSeq.Append( aStr );
3276 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
3278 int aMinId = myMin( i );
3279 int aMaxId = myMax( i );
3281 TCollection_AsciiString aStr;
3282 if ( aMinId != IntegerFirst() )
3287 if ( aMaxId != IntegerLast() )
3290 // find position of the string in result sequence and insert string in it
3291 if ( anIntSeq.Length() == 0 )
3293 anIntSeq.Append( aMinId );
3294 aStrSeq.Append( aStr );
3298 if ( aMinId < anIntSeq.First() )
3300 anIntSeq.Prepend( aMinId );
3301 aStrSeq.Prepend( aStr );
3303 else if ( aMinId > anIntSeq.Last() )
3305 anIntSeq.Append( aMinId );
3306 aStrSeq.Append( aStr );
3309 for ( int j = 1, k = anIntSeq.Length(); j <= k; j++ )
3310 if ( aMinId < anIntSeq( j ) )
3312 anIntSeq.InsertBefore( j, aMinId );
3313 aStrSeq.InsertBefore( j, aStr );
3319 if ( aStrSeq.Length() == 0 )
3322 theResStr = aStrSeq( 1 );
3323 for ( int j = 2, k = aStrSeq.Length(); j <= k; j++ )
3326 theResStr += aStrSeq( j );
3330 //=======================================================================
3331 // name : SetRangeStr
3332 // Purpose : Define range with string
3333 // Example of entry string: "1,2,3,50-60,63,67,70-"
3334 //=======================================================================
3335 bool RangeOfIds::SetRangeStr( const TCollection_AsciiString& theStr )
3341 TCollection_AsciiString aStr = theStr;
3342 for ( int i = 1; i <= aStr.Length(); ++i )
3344 char c = aStr.Value( i );
3345 if ( !isdigit( c ) && c != ',' && c != '-' )
3346 aStr.SetValue( i, ',');
3348 aStr.RemoveAll( ' ' );
3350 TCollection_AsciiString tmpStr = aStr.Token( ",", 1 );
3352 while ( tmpStr != "" )
3354 tmpStr = aStr.Token( ",", i++ );
3355 int aPos = tmpStr.Search( '-' );
3359 if ( tmpStr.IsIntegerValue() )
3360 myIds.Add( tmpStr.IntegerValue() );
3366 TCollection_AsciiString aMaxStr = tmpStr.Split( aPos );
3367 TCollection_AsciiString aMinStr = tmpStr;
3369 while ( aMinStr.Search( "-" ) != -1 ) aMinStr.RemoveAll( '-' );
3370 while ( aMaxStr.Search( "-" ) != -1 ) aMaxStr.RemoveAll( '-' );
3372 if ( (!aMinStr.IsEmpty() && !aMinStr.IsIntegerValue()) ||
3373 (!aMaxStr.IsEmpty() && !aMaxStr.IsIntegerValue()) )
3376 myMin.Append( aMinStr.IsEmpty() ? IntegerFirst() : aMinStr.IntegerValue() );
3377 myMax.Append( aMaxStr.IsEmpty() ? IntegerLast() : aMaxStr.IntegerValue() );
3384 //=======================================================================
3386 // Purpose : Get type of supported entities
3387 //=======================================================================
3388 SMDSAbs_ElementType RangeOfIds::GetType() const
3393 //=======================================================================
3395 // Purpose : Set type of supported entities
3396 //=======================================================================
3397 void RangeOfIds::SetType( SMDSAbs_ElementType theType )
3402 //=======================================================================
3404 // Purpose : Verify whether entity satisfies to this rpedicate
3405 //=======================================================================
3406 bool RangeOfIds::IsSatisfy( long theId )
3411 if ( myType == SMDSAbs_Node )
3413 if ( myMesh->FindNode( theId ) == 0 )
3418 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
3419 if ( anElem == 0 || (myType != anElem->GetType() && myType != SMDSAbs_All ))
3423 if ( myIds.Contains( theId ) )
3426 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
3427 if ( theId >= myMin( i ) && theId <= myMax( i ) )
3435 Description : Base class for comparators
3437 Comparator::Comparator():
3441 Comparator::~Comparator()
3444 void Comparator::SetMesh( const SMDS_Mesh* theMesh )
3447 myFunctor->SetMesh( theMesh );
3450 void Comparator::SetMargin( double theValue )
3452 myMargin = theValue;
3455 void Comparator::SetNumFunctor( NumericalFunctorPtr theFunct )
3457 myFunctor = theFunct;
3460 SMDSAbs_ElementType Comparator::GetType() const
3462 return myFunctor ? myFunctor->GetType() : SMDSAbs_All;
3465 double Comparator::GetMargin()
3473 Description : Comparator "<"
3475 bool LessThan::IsSatisfy( long theId )
3477 return myFunctor && myFunctor->GetValue( theId ) < myMargin;
3483 Description : Comparator ">"
3485 bool MoreThan::IsSatisfy( long theId )
3487 return myFunctor && myFunctor->GetValue( theId ) > myMargin;
3493 Description : Comparator "="
3496 myToler(Precision::Confusion())
3499 bool EqualTo::IsSatisfy( long theId )
3501 return myFunctor && fabs( myFunctor->GetValue( theId ) - myMargin ) < myToler;
3504 void EqualTo::SetTolerance( double theToler )
3509 double EqualTo::GetTolerance()
3516 Description : Logical NOT predicate
3518 LogicalNOT::LogicalNOT()
3521 LogicalNOT::~LogicalNOT()
3524 bool LogicalNOT::IsSatisfy( long theId )
3526 return myPredicate && !myPredicate->IsSatisfy( theId );
3529 void LogicalNOT::SetMesh( const SMDS_Mesh* theMesh )
3532 myPredicate->SetMesh( theMesh );
3535 void LogicalNOT::SetPredicate( PredicatePtr thePred )
3537 myPredicate = thePred;
3540 SMDSAbs_ElementType LogicalNOT::GetType() const
3542 return myPredicate ? myPredicate->GetType() : SMDSAbs_All;
3547 Class : LogicalBinary
3548 Description : Base class for binary logical predicate
3550 LogicalBinary::LogicalBinary()
3553 LogicalBinary::~LogicalBinary()
3556 void LogicalBinary::SetMesh( const SMDS_Mesh* theMesh )
3559 myPredicate1->SetMesh( theMesh );
3562 myPredicate2->SetMesh( theMesh );
3565 void LogicalBinary::SetPredicate1( PredicatePtr thePredicate )
3567 myPredicate1 = thePredicate;
3570 void LogicalBinary::SetPredicate2( PredicatePtr thePredicate )
3572 myPredicate2 = thePredicate;
3575 SMDSAbs_ElementType LogicalBinary::GetType() const
3577 if ( !myPredicate1 || !myPredicate2 )
3580 SMDSAbs_ElementType aType1 = myPredicate1->GetType();
3581 SMDSAbs_ElementType aType2 = myPredicate2->GetType();
3583 return aType1 == aType2 ? aType1 : SMDSAbs_All;
3589 Description : Logical AND
3591 bool LogicalAND::IsSatisfy( long theId )
3596 myPredicate1->IsSatisfy( theId ) &&
3597 myPredicate2->IsSatisfy( theId );
3603 Description : Logical OR
3605 bool LogicalOR::IsSatisfy( long theId )
3610 (myPredicate1->IsSatisfy( theId ) ||
3611 myPredicate2->IsSatisfy( theId ));
3620 // #include <tbb/parallel_for.h>
3621 // #include <tbb/enumerable_thread_specific.h>
3623 // namespace Parallel
3625 // typedef tbb::enumerable_thread_specific< TIdSequence > TIdSeq;
3629 // const SMDS_Mesh* myMesh;
3630 // PredicatePtr myPredicate;
3631 // TIdSeq & myOKIds;
3632 // Predicate( const SMDS_Mesh* m, PredicatePtr p, TIdSeq & ids ):
3633 // myMesh(m), myPredicate(p->Duplicate()), myOKIds(ids) {}
3634 // void operator() ( const tbb::blocked_range<size_t>& r ) const
3636 // for ( size_t i = r.begin(); i != r.end(); ++i )
3637 // if ( myPredicate->IsSatisfy( i ))
3638 // myOKIds.local().push_back();
3650 void Filter::SetPredicate( PredicatePtr thePredicate )
3652 myPredicate = thePredicate;
3655 void Filter::GetElementsId( const SMDS_Mesh* theMesh,
3656 PredicatePtr thePredicate,
3657 TIdSequence& theSequence )
3659 theSequence.clear();
3661 if ( !theMesh || !thePredicate )
3664 thePredicate->SetMesh( theMesh );
3666 SMDS_ElemIteratorPtr elemIt = theMesh->elementsIterator( thePredicate->GetType() );
3668 while ( elemIt->more() ) {
3669 const SMDS_MeshElement* anElem = elemIt->next();
3670 long anId = anElem->GetID();
3671 if ( thePredicate->IsSatisfy( anId ) )
3672 theSequence.push_back( anId );
3677 void Filter::GetElementsId( const SMDS_Mesh* theMesh,
3678 Filter::TIdSequence& theSequence )
3680 GetElementsId(theMesh,myPredicate,theSequence);
3687 typedef std::set<SMDS_MeshFace*> TMapOfFacePtr;
3693 ManifoldPart::Link::Link( SMDS_MeshNode* theNode1,
3694 SMDS_MeshNode* theNode2 )
3700 ManifoldPart::Link::~Link()
3706 bool ManifoldPart::Link::IsEqual( const ManifoldPart::Link& theLink ) const
3708 if ( myNode1 == theLink.myNode1 &&
3709 myNode2 == theLink.myNode2 )
3711 else if ( myNode1 == theLink.myNode2 &&
3712 myNode2 == theLink.myNode1 )
3718 bool ManifoldPart::Link::operator<( const ManifoldPart::Link& x ) const
3720 if(myNode1 < x.myNode1) return true;
3721 if(myNode1 == x.myNode1)
3722 if(myNode2 < x.myNode2) return true;
3726 bool ManifoldPart::IsEqual( const ManifoldPart::Link& theLink1,
3727 const ManifoldPart::Link& theLink2 )
3729 return theLink1.IsEqual( theLink2 );
3732 ManifoldPart::ManifoldPart()
3735 myAngToler = Precision::Angular();
3736 myIsOnlyManifold = true;
3739 ManifoldPart::~ManifoldPart()
3744 void ManifoldPart::SetMesh( const SMDS_Mesh* theMesh )
3750 SMDSAbs_ElementType ManifoldPart::GetType() const
3751 { return SMDSAbs_Face; }
3753 bool ManifoldPart::IsSatisfy( long theElementId )
3755 return myMapIds.Contains( theElementId );
3758 void ManifoldPart::SetAngleTolerance( const double theAngToler )
3759 { myAngToler = theAngToler; }
3761 double ManifoldPart::GetAngleTolerance() const
3762 { return myAngToler; }
3764 void ManifoldPart::SetIsOnlyManifold( const bool theIsOnly )
3765 { myIsOnlyManifold = theIsOnly; }
3767 void ManifoldPart::SetStartElem( const long theStartId )
3768 { myStartElemId = theStartId; }
3770 bool ManifoldPart::process()
3773 myMapBadGeomIds.Clear();
3775 myAllFacePtr.clear();
3776 myAllFacePtrIntDMap.clear();
3780 // collect all faces into own map
3781 SMDS_FaceIteratorPtr anFaceItr = myMesh->facesIterator();
3782 for (; anFaceItr->more(); )
3784 SMDS_MeshFace* aFacePtr = (SMDS_MeshFace*)anFaceItr->next();
3785 myAllFacePtr.push_back( aFacePtr );
3786 myAllFacePtrIntDMap[aFacePtr] = myAllFacePtr.size()-1;
3789 SMDS_MeshFace* aStartFace = (SMDS_MeshFace*)myMesh->FindElement( myStartElemId );
3793 // the map of non manifold links and bad geometry
3794 TMapOfLink aMapOfNonManifold;
3795 TColStd_MapOfInteger aMapOfTreated;
3797 // begin cycle on faces from start index and run on vector till the end
3798 // and from begin to start index to cover whole vector
3799 const int aStartIndx = myAllFacePtrIntDMap[aStartFace];
3800 bool isStartTreat = false;
3801 for ( int fi = aStartIndx; !isStartTreat || fi != aStartIndx ; fi++ )
3803 if ( fi == aStartIndx )
3804 isStartTreat = true;
3805 // as result next time when fi will be equal to aStartIndx
3807 SMDS_MeshFace* aFacePtr = myAllFacePtr[ fi ];
3808 if ( aMapOfTreated.Contains( aFacePtr->GetID() ) )
3811 aMapOfTreated.Add( aFacePtr->GetID() );
3812 TColStd_MapOfInteger aResFaces;
3813 if ( !findConnected( myAllFacePtrIntDMap, aFacePtr,
3814 aMapOfNonManifold, aResFaces ) )
3816 TColStd_MapIteratorOfMapOfInteger anItr( aResFaces );
3817 for ( ; anItr.More(); anItr.Next() )
3819 int aFaceId = anItr.Key();
3820 aMapOfTreated.Add( aFaceId );
3821 myMapIds.Add( aFaceId );
3824 if ( fi == int( myAllFacePtr.size() - 1 ))
3826 } // end run on vector of faces
3827 return !myMapIds.IsEmpty();
3830 static void getLinks( const SMDS_MeshFace* theFace,
3831 ManifoldPart::TVectorOfLink& theLinks )
3833 int aNbNode = theFace->NbNodes();
3834 SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
3836 SMDS_MeshNode* aNode = 0;
3837 for ( ; aNodeItr->more() && i <= aNbNode; )
3840 SMDS_MeshNode* aN1 = (SMDS_MeshNode*)aNodeItr->next();
3844 SMDS_MeshNode* aN2 = ( i >= aNbNode ) ? aNode : (SMDS_MeshNode*)aNodeItr->next();
3846 ManifoldPart::Link aLink( aN1, aN2 );
3847 theLinks.push_back( aLink );
3851 bool ManifoldPart::findConnected
3852 ( const ManifoldPart::TDataMapFacePtrInt& theAllFacePtrInt,
3853 SMDS_MeshFace* theStartFace,
3854 ManifoldPart::TMapOfLink& theNonManifold,
3855 TColStd_MapOfInteger& theResFaces )
3857 theResFaces.Clear();
3858 if ( !theAllFacePtrInt.size() )
3861 if ( getNormale( theStartFace ).SquareModulus() <= gp::Resolution() )
3863 myMapBadGeomIds.Add( theStartFace->GetID() );
3867 ManifoldPart::TMapOfLink aMapOfBoundary, aMapToSkip;
3868 ManifoldPart::TVectorOfLink aSeqOfBoundary;
3869 theResFaces.Add( theStartFace->GetID() );
3870 ManifoldPart::TDataMapOfLinkFacePtr aDMapLinkFace;
3872 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
3873 aDMapLinkFace, theNonManifold, theStartFace );
3875 bool isDone = false;
3876 while ( !isDone && aMapOfBoundary.size() != 0 )
3878 bool isToReset = false;
3879 ManifoldPart::TVectorOfLink::iterator pLink = aSeqOfBoundary.begin();
3880 for ( ; !isToReset && pLink != aSeqOfBoundary.end(); ++pLink )
3882 ManifoldPart::Link aLink = *pLink;
3883 if ( aMapToSkip.find( aLink ) != aMapToSkip.end() )
3885 // each link could be treated only once
3886 aMapToSkip.insert( aLink );
3888 ManifoldPart::TVectorOfFacePtr aFaces;
3890 if ( myIsOnlyManifold &&
3891 (theNonManifold.find( aLink ) != theNonManifold.end()) )
3895 getFacesByLink( aLink, aFaces );
3896 // filter the element to keep only indicated elements
3897 ManifoldPart::TVectorOfFacePtr aFiltered;
3898 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
3899 for ( ; pFace != aFaces.end(); ++pFace )
3901 SMDS_MeshFace* aFace = *pFace;
3902 if ( myAllFacePtrIntDMap.find( aFace ) != myAllFacePtrIntDMap.end() )
3903 aFiltered.push_back( aFace );
3906 if ( aFaces.size() < 2 ) // no neihgbour faces
3908 else if ( myIsOnlyManifold && aFaces.size() > 2 ) // non manifold case
3910 theNonManifold.insert( aLink );
3915 // compare normal with normals of neighbor element
3916 SMDS_MeshFace* aPrevFace = aDMapLinkFace[ aLink ];
3917 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
3918 for ( ; pFace != aFaces.end(); ++pFace )
3920 SMDS_MeshFace* aNextFace = *pFace;
3921 if ( aPrevFace == aNextFace )
3923 int anNextFaceID = aNextFace->GetID();
3924 if ( myIsOnlyManifold && theResFaces.Contains( anNextFaceID ) )
3925 // should not be with non manifold restriction. probably bad topology
3927 // check if face was treated and skipped
3928 if ( myMapBadGeomIds.Contains( anNextFaceID ) ||
3929 !isInPlane( aPrevFace, aNextFace ) )
3931 // add new element to connected and extend the boundaries.
3932 theResFaces.Add( anNextFaceID );
3933 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
3934 aDMapLinkFace, theNonManifold, aNextFace );
3938 isDone = !isToReset;
3941 return !theResFaces.IsEmpty();
3944 bool ManifoldPart::isInPlane( const SMDS_MeshFace* theFace1,
3945 const SMDS_MeshFace* theFace2 )
3947 gp_Dir aNorm1 = gp_Dir( getNormale( theFace1 ) );
3948 gp_XYZ aNorm2XYZ = getNormale( theFace2 );
3949 if ( aNorm2XYZ.SquareModulus() <= gp::Resolution() )
3951 myMapBadGeomIds.Add( theFace2->GetID() );
3954 if ( aNorm1.IsParallel( gp_Dir( aNorm2XYZ ), myAngToler ) )
3960 void ManifoldPart::expandBoundary
3961 ( ManifoldPart::TMapOfLink& theMapOfBoundary,
3962 ManifoldPart::TVectorOfLink& theSeqOfBoundary,
3963 ManifoldPart::TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
3964 ManifoldPart::TMapOfLink& theNonManifold,
3965 SMDS_MeshFace* theNextFace ) const
3967 ManifoldPart::TVectorOfLink aLinks;
3968 getLinks( theNextFace, aLinks );
3969 int aNbLink = (int)aLinks.size();
3970 for ( int i = 0; i < aNbLink; i++ )
3972 ManifoldPart::Link aLink = aLinks[ i ];
3973 if ( myIsOnlyManifold && (theNonManifold.find( aLink ) != theNonManifold.end()) )
3975 if ( theMapOfBoundary.find( aLink ) != theMapOfBoundary.end() )
3977 if ( myIsOnlyManifold )
3979 // remove from boundary
3980 theMapOfBoundary.erase( aLink );
3981 ManifoldPart::TVectorOfLink::iterator pLink = theSeqOfBoundary.begin();
3982 for ( ; pLink != theSeqOfBoundary.end(); ++pLink )
3984 ManifoldPart::Link aBoundLink = *pLink;
3985 if ( aBoundLink.IsEqual( aLink ) )
3987 theSeqOfBoundary.erase( pLink );
3995 theMapOfBoundary.insert( aLink );
3996 theSeqOfBoundary.push_back( aLink );
3997 theDMapLinkFacePtr[ aLink ] = theNextFace;
4002 void ManifoldPart::getFacesByLink( const ManifoldPart::Link& theLink,
4003 ManifoldPart::TVectorOfFacePtr& theFaces ) const
4005 std::set<SMDS_MeshCell *> aSetOfFaces;
4006 // take all faces that shared first node
4007 SMDS_ElemIteratorPtr anItr = theLink.myNode1->facesIterator();
4008 for ( ; anItr->more(); )
4010 SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
4013 aSetOfFaces.insert( aFace );
4015 // take all faces that shared second node
4016 anItr = theLink.myNode2->facesIterator();
4017 // find the common part of two sets
4018 for ( ; anItr->more(); )
4020 SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
4021 if ( aSetOfFaces.count( aFace ) )
4022 theFaces.push_back( aFace );
4027 Class : BelongToMeshGroup
4028 Description : Verify whether a mesh element is included into a mesh group
4030 BelongToMeshGroup::BelongToMeshGroup(): myGroup( 0 )
4034 void BelongToMeshGroup::SetGroup( SMESHDS_GroupBase* g )
4039 void BelongToMeshGroup::SetStoreName( const std::string& sn )
4044 void BelongToMeshGroup::SetMesh( const SMDS_Mesh* theMesh )
4046 if ( myGroup && myGroup->GetMesh() != theMesh )
4050 if ( !myGroup && !myStoreName.empty() )
4052 if ( const SMESHDS_Mesh* aMesh = dynamic_cast<const SMESHDS_Mesh*>(theMesh))
4054 const std::set<SMESHDS_GroupBase*>& grps = aMesh->GetGroups();
4055 std::set<SMESHDS_GroupBase*>::const_iterator g = grps.begin();
4056 for ( ; g != grps.end() && !myGroup; ++g )
4057 if ( *g && myStoreName == (*g)->GetStoreName() )
4063 myGroup->IsEmpty(); // make GroupOnFilter update its predicate
4067 bool BelongToMeshGroup::IsSatisfy( long theElementId )
4069 return myGroup ? myGroup->Contains( theElementId ) : false;
4072 SMDSAbs_ElementType BelongToMeshGroup::GetType() const
4074 return myGroup ? myGroup->GetType() : SMDSAbs_All;
4077 //================================================================================
4078 // ElementsOnSurface
4079 //================================================================================
4081 ElementsOnSurface::ElementsOnSurface()
4084 myType = SMDSAbs_All;
4086 myToler = Precision::Confusion();
4087 myUseBoundaries = false;
4090 ElementsOnSurface::~ElementsOnSurface()
4094 void ElementsOnSurface::SetMesh( const SMDS_Mesh* theMesh )
4096 myMeshModifTracer.SetMesh( theMesh );
4097 if ( myMeshModifTracer.IsMeshModified())
4101 bool ElementsOnSurface::IsSatisfy( long theElementId )
4103 return myIds.Contains( theElementId );
4106 SMDSAbs_ElementType ElementsOnSurface::GetType() const
4109 void ElementsOnSurface::SetTolerance( const double theToler )
4111 if ( myToler != theToler )
4116 double ElementsOnSurface::GetTolerance() const
4119 void ElementsOnSurface::SetUseBoundaries( bool theUse )
4121 if ( myUseBoundaries != theUse ) {
4122 myUseBoundaries = theUse;
4123 SetSurface( mySurf, myType );
4127 void ElementsOnSurface::SetSurface( const TopoDS_Shape& theShape,
4128 const SMDSAbs_ElementType theType )
4133 if ( theShape.IsNull() || theShape.ShapeType() != TopAbs_FACE )
4135 mySurf = TopoDS::Face( theShape );
4136 BRepAdaptor_Surface SA( mySurf, myUseBoundaries );
4138 u1 = SA.FirstUParameter(),
4139 u2 = SA.LastUParameter(),
4140 v1 = SA.FirstVParameter(),
4141 v2 = SA.LastVParameter();
4142 Handle(Geom_Surface) surf = BRep_Tool::Surface( mySurf );
4143 myProjector.Init( surf, u1,u2, v1,v2 );
4147 void ElementsOnSurface::process()
4150 if ( mySurf.IsNull() )
4153 if ( !myMeshModifTracer.GetMesh() )
4156 myIds.ReSize( myMeshModifTracer.GetMesh()->GetMeshInfo().NbElements( myType ));
4158 SMDS_ElemIteratorPtr anIter = myMeshModifTracer.GetMesh()->elementsIterator( myType );
4159 for(; anIter->more(); )
4160 process( anIter->next() );
4163 void ElementsOnSurface::process( const SMDS_MeshElement* theElemPtr )
4165 SMDS_ElemIteratorPtr aNodeItr = theElemPtr->nodesIterator();
4166 bool isSatisfy = true;
4167 for ( ; aNodeItr->more(); )
4169 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
4170 if ( !isOnSurface( aNode ) )
4177 myIds.Add( theElemPtr->GetID() );
4180 bool ElementsOnSurface::isOnSurface( const SMDS_MeshNode* theNode )
4182 if ( mySurf.IsNull() )
4185 gp_Pnt aPnt( theNode->X(), theNode->Y(), theNode->Z() );
4186 // double aToler2 = myToler * myToler;
4187 // if ( mySurf->IsKind(STANDARD_TYPE(Geom_Plane)))
4189 // gp_Pln aPln = Handle(Geom_Plane)::DownCast(mySurf)->Pln();
4190 // if ( aPln.SquareDistance( aPnt ) > aToler2 )
4193 // else if ( mySurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)))
4195 // gp_Cylinder aCyl = Handle(Geom_CylindricalSurface)::DownCast(mySurf)->Cylinder();
4196 // double aRad = aCyl.Radius();
4197 // gp_Ax3 anAxis = aCyl.Position();
4198 // gp_XYZ aLoc = aCyl.Location().XYZ();
4199 // double aXDist = anAxis.XDirection().XYZ() * ( aPnt.XYZ() - aLoc );
4200 // double aYDist = anAxis.YDirection().XYZ() * ( aPnt.XYZ() - aLoc );
4201 // if ( fabs(aXDist*aXDist + aYDist*aYDist - aRad*aRad) > aToler2 )
4206 myProjector.Perform( aPnt );
4207 bool isOn = ( myProjector.IsDone() && myProjector.LowerDistance() <= myToler );
4213 //================================================================================
4215 //================================================================================
4218 const int theIsCheckedFlag = 0x0000100;
4221 struct ElementsOnShape::Classifier
4223 Classifier() { mySolidClfr = 0; myFlags = 0; }
4225 void Init(const TopoDS_Shape& s, double tol, const Bnd_B3d* box = 0 );
4226 bool IsOut(const gp_Pnt& p) { return SetChecked( true ), (this->*myIsOutFun)( p ); }
4227 TopAbs_ShapeEnum ShapeType() const { return myShape.ShapeType(); }
4228 const TopoDS_Shape& Shape() const { return myShape; }
4229 const Bnd_B3d* GetBndBox() const { return & myBox; }
4230 bool IsChecked() { return myFlags & theIsCheckedFlag; }
4231 bool IsSetFlag( int flag ) const { return myFlags & flag; }
4232 void SetChecked( bool is ) { is ? SetFlag( theIsCheckedFlag ) : UnsetFlag( theIsCheckedFlag ); }
4233 void SetFlag ( int flag ) { myFlags |= flag; }
4234 void UnsetFlag( int flag ) { myFlags &= ~flag; }
4237 bool isOutOfSolid (const gp_Pnt& p);
4238 bool isOutOfBox (const gp_Pnt& p);
4239 bool isOutOfFace (const gp_Pnt& p);
4240 bool isOutOfEdge (const gp_Pnt& p);
4241 bool isOutOfVertex(const gp_Pnt& p);
4242 bool isBox (const TopoDS_Shape& s);
4244 bool (Classifier::* myIsOutFun)(const gp_Pnt& p);
4245 BRepClass3d_SolidClassifier* mySolidClfr; // ptr because of a run-time forbidden copy-constructor
4247 GeomAPI_ProjectPointOnSurf myProjFace;
4248 GeomAPI_ProjectPointOnCurve myProjEdge;
4250 TopoDS_Shape myShape;
4255 struct ElementsOnShape::OctreeClassifier : public SMESH_Octree
4257 OctreeClassifier( const std::vector< ElementsOnShape::Classifier* >& classifiers );
4258 OctreeClassifier( const OctreeClassifier* otherTree,
4259 const std::vector< ElementsOnShape::Classifier >& clsOther,
4260 std::vector< ElementsOnShape::Classifier >& cls );
4261 void GetClassifiersAtPoint( const gp_XYZ& p,
4262 std::vector< ElementsOnShape::Classifier* >& classifiers );
4264 OctreeClassifier() {}
4265 SMESH_Octree* newChild() const { return new OctreeClassifier; }
4266 void buildChildrenData();
4267 Bnd_B3d* buildRootBox();
4269 std::vector< ElementsOnShape::Classifier* > myClassifiers;
4273 ElementsOnShape::ElementsOnShape():
4275 myType(SMDSAbs_All),
4276 myToler(Precision::Confusion()),
4277 myAllNodesFlag(false)
4281 ElementsOnShape::~ElementsOnShape()
4286 Predicate* ElementsOnShape::clone() const
4288 ElementsOnShape* cln = new ElementsOnShape();
4289 cln->SetAllNodes ( myAllNodesFlag );
4290 cln->SetTolerance( myToler );
4291 cln->SetMesh ( myMeshModifTracer.GetMesh() );
4292 cln->myShape = myShape; // avoid creation of myClassifiers
4293 cln->SetShape ( myShape, myType );
4294 cln->myClassifiers.resize( myClassifiers.size() );
4295 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4296 cln->myClassifiers[ i ].Init( BRepBuilderAPI_Copy( myClassifiers[ i ].Shape()),
4297 myToler, myClassifiers[ i ].GetBndBox() );
4298 if ( myOctree ) // copy myOctree
4300 cln->myOctree = new OctreeClassifier( myOctree, myClassifiers, cln->myClassifiers );
4305 SMDSAbs_ElementType ElementsOnShape::GetType() const
4310 void ElementsOnShape::SetTolerance (const double theToler)
4312 if (myToler != theToler) {
4314 SetShape(myShape, myType);
4318 double ElementsOnShape::GetTolerance() const
4323 void ElementsOnShape::SetAllNodes (bool theAllNodes)
4325 myAllNodesFlag = theAllNodes;
4328 void ElementsOnShape::SetMesh (const SMDS_Mesh* theMesh)
4330 myMeshModifTracer.SetMesh( theMesh );
4331 if ( myMeshModifTracer.IsMeshModified())
4333 size_t nbNodes = theMesh ? theMesh->NbNodes() : 0;
4334 if ( myNodeIsChecked.size() == nbNodes )
4336 std::fill( myNodeIsChecked.begin(), myNodeIsChecked.end(), false );
4340 SMESHUtils::FreeVector( myNodeIsChecked );
4341 SMESHUtils::FreeVector( myNodeIsOut );
4342 myNodeIsChecked.resize( nbNodes, false );
4343 myNodeIsOut.resize( nbNodes );
4348 bool ElementsOnShape::getNodeIsOut( const SMDS_MeshNode* n, bool& isOut )
4350 if ( n->GetID() >= (int) myNodeIsChecked.size() ||
4351 !myNodeIsChecked[ n->GetID() ])
4354 isOut = myNodeIsOut[ n->GetID() ];
4358 void ElementsOnShape::setNodeIsOut( const SMDS_MeshNode* n, bool isOut )
4360 if ( n->GetID() < (int) myNodeIsChecked.size() )
4362 myNodeIsChecked[ n->GetID() ] = true;
4363 myNodeIsOut [ n->GetID() ] = isOut;
4367 void ElementsOnShape::SetShape (const TopoDS_Shape& theShape,
4368 const SMDSAbs_ElementType theType)
4370 bool shapeChanges = ( myShape != theShape );
4373 if ( myShape.IsNull() ) return;
4377 // find most complex shapes
4378 TopTools_IndexedMapOfShape shapesMap;
4379 TopAbs_ShapeEnum shapeTypes[4] = { TopAbs_SOLID, TopAbs_FACE, TopAbs_EDGE, TopAbs_VERTEX };
4380 TopExp_Explorer sub;
4381 for ( int i = 0; i < 4; ++i )
4383 if ( shapesMap.IsEmpty() )
4384 for ( sub.Init( myShape, shapeTypes[i] ); sub.More(); sub.Next() )
4385 shapesMap.Add( sub.Current() );
4387 for ( sub.Init( myShape, shapeTypes[i], shapeTypes[i-1] ); sub.More(); sub.Next() )
4388 shapesMap.Add( sub.Current() );
4392 myClassifiers.resize( shapesMap.Extent() );
4393 for ( int i = 0; i < shapesMap.Extent(); ++i )
4394 myClassifiers[ i ].Init( shapesMap( i+1 ), myToler );
4397 if ( theType == SMDSAbs_Node )
4399 SMESHUtils::FreeVector( myNodeIsChecked );
4400 SMESHUtils::FreeVector( myNodeIsOut );
4404 std::fill( myNodeIsChecked.begin(), myNodeIsChecked.end(), false );
4408 void ElementsOnShape::clearClassifiers()
4410 // for ( size_t i = 0; i < myClassifiers.size(); ++i )
4411 // delete myClassifiers[ i ];
4412 myClassifiers.clear();
4418 bool ElementsOnShape::IsSatisfy( long elemId )
4420 if ( myClassifiers.empty() )
4423 const SMDS_Mesh* mesh = myMeshModifTracer.GetMesh();
4424 if ( myType == SMDSAbs_Node )
4425 return IsSatisfy( mesh->FindNode( elemId ));
4426 return IsSatisfy( mesh->FindElement( elemId ));
4429 bool ElementsOnShape::IsSatisfy (const SMDS_MeshElement* elem)
4434 bool isSatisfy = myAllNodesFlag, isNodeOut;
4436 gp_XYZ centerXYZ (0, 0, 0);
4438 if ( !myOctree && myClassifiers.size() > 5 )
4440 myWorkClassifiers.resize( myClassifiers.size() );
4441 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4442 myWorkClassifiers[ i ] = & myClassifiers[ i ];
4443 myOctree = new OctreeClassifier( myWorkClassifiers );
4446 SMDS_ElemIteratorPtr aNodeItr = elem->nodesIterator();
4447 while (aNodeItr->more() && (isSatisfy == myAllNodesFlag))
4449 SMESH_TNodeXYZ aPnt( aNodeItr->next() );
4453 if ( !getNodeIsOut( aPnt._node, isNodeOut ))
4457 myWorkClassifiers.clear();
4458 myOctree->GetClassifiersAtPoint( aPnt, myWorkClassifiers );
4460 for ( size_t i = 0; i < myWorkClassifiers.size(); ++i )
4461 myWorkClassifiers[i]->SetChecked( false );
4463 for ( size_t i = 0; i < myWorkClassifiers.size() && isNodeOut; ++i )
4464 if ( !myWorkClassifiers[i]->IsChecked() )
4465 isNodeOut = myWorkClassifiers[i]->IsOut( aPnt );
4469 for ( size_t i = 0; i < myClassifiers.size() && isNodeOut; ++i )
4470 isNodeOut = myClassifiers[i].IsOut( aPnt );
4472 setNodeIsOut( aPnt._node, isNodeOut );
4474 isSatisfy = !isNodeOut;
4477 // Check the center point for volumes MantisBug 0020168
4480 myClassifiers[0].ShapeType() == TopAbs_SOLID )
4482 centerXYZ /= elem->NbNodes();
4485 for ( size_t i = 0; i < myWorkClassifiers.size() && !isSatisfy; ++i )
4486 isSatisfy = ! myWorkClassifiers[i]->IsOut( centerXYZ );
4488 for ( size_t i = 0; i < myClassifiers.size() && !isSatisfy; ++i )
4489 isSatisfy = ! myClassifiers[i].IsOut( centerXYZ );
4495 bool ElementsOnShape::IsSatisfy (const SMDS_MeshNode* node,
4496 TopoDS_Shape* okShape)
4501 if ( !myOctree && myClassifiers.size() > 5 )
4503 myWorkClassifiers.resize( myClassifiers.size() );
4504 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4505 myWorkClassifiers[ i ] = & myClassifiers[ i ];
4506 myOctree = new OctreeClassifier( myWorkClassifiers );
4509 bool isNodeOut = true;
4511 if ( okShape || !getNodeIsOut( node, isNodeOut ))
4513 SMESH_NodeXYZ aPnt = node;
4516 myWorkClassifiers.clear();
4517 myOctree->GetClassifiersAtPoint( aPnt, myWorkClassifiers );
4519 for ( size_t i = 0; i < myWorkClassifiers.size(); ++i )
4520 myWorkClassifiers[i]->SetChecked( false );
4522 for ( size_t i = 0; i < myWorkClassifiers.size(); ++i )
4523 if ( !myWorkClassifiers[i]->IsChecked() &&
4524 !myWorkClassifiers[i]->IsOut( aPnt ))
4528 *okShape = myWorkClassifiers[i]->Shape();
4534 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4535 if ( !myClassifiers[i].IsOut( aPnt ))
4539 *okShape = myWorkClassifiers[i]->Shape();
4543 setNodeIsOut( node, isNodeOut );
4549 void ElementsOnShape::Classifier::Init( const TopoDS_Shape& theShape,
4551 const Bnd_B3d* theBox )
4557 bool isShapeBox = false;
4558 switch ( myShape.ShapeType() )
4562 if (( isShapeBox = isBox( theShape )))
4564 myIsOutFun = & ElementsOnShape::Classifier::isOutOfBox;
4568 mySolidClfr = new BRepClass3d_SolidClassifier(theShape);
4569 myIsOutFun = & ElementsOnShape::Classifier::isOutOfSolid;
4575 Standard_Real u1,u2,v1,v2;
4576 Handle(Geom_Surface) surf = BRep_Tool::Surface( TopoDS::Face( theShape ));
4577 surf->Bounds( u1,u2,v1,v2 );
4578 myProjFace.Init(surf, u1,u2, v1,v2, myTol );
4579 myIsOutFun = & ElementsOnShape::Classifier::isOutOfFace;
4584 Standard_Real u1, u2;
4585 Handle(Geom_Curve) curve = BRep_Tool::Curve( TopoDS::Edge( theShape ), u1, u2);
4586 myProjEdge.Init(curve, u1, u2);
4587 myIsOutFun = & ElementsOnShape::Classifier::isOutOfEdge;
4592 myVertexXYZ = BRep_Tool::Pnt( TopoDS::Vertex( theShape ) );
4593 myIsOutFun = & ElementsOnShape::Classifier::isOutOfVertex;
4597 throw SALOME_Exception("Programmer error in usage of ElementsOnShape::Classifier");
4609 BRepBndLib::Add( myShape, box );
4611 myBox.Add( box.CornerMin() );
4612 myBox.Add( box.CornerMax() );
4613 gp_XYZ halfSize = 0.5 * ( box.CornerMax().XYZ() - box.CornerMin().XYZ() );
4614 for ( int iDim = 1; iDim <= 3; ++iDim )
4616 double x = halfSize.Coord( iDim );
4617 halfSize.SetCoord( iDim, x + Max( myTol, 1e-2 * x ));
4619 myBox.SetHSize( halfSize );
4624 ElementsOnShape::Classifier::~Classifier()
4626 delete mySolidClfr; mySolidClfr = 0;
4629 bool ElementsOnShape::Classifier::isOutOfSolid (const gp_Pnt& p)
4631 mySolidClfr->Perform( p, myTol );
4632 return ( mySolidClfr->State() != TopAbs_IN && mySolidClfr->State() != TopAbs_ON );
4635 bool ElementsOnShape::Classifier::isOutOfBox (const gp_Pnt& p)
4637 return myBox.IsOut( p.XYZ() );
4640 bool ElementsOnShape::Classifier::isOutOfFace (const gp_Pnt& p)
4642 myProjFace.Perform( p );
4643 if ( myProjFace.IsDone() && myProjFace.LowerDistance() <= myTol )
4645 // check relatively to the face
4647 myProjFace.LowerDistanceParameters(u, v);
4648 gp_Pnt2d aProjPnt (u, v);
4649 BRepClass_FaceClassifier aClsf ( TopoDS::Face( myShape ), aProjPnt, myTol );
4650 if ( aClsf.State() == TopAbs_IN || aClsf.State() == TopAbs_ON )
4656 bool ElementsOnShape::Classifier::isOutOfEdge (const gp_Pnt& p)
4658 myProjEdge.Perform( p );
4659 return ! ( myProjEdge.NbPoints() > 0 && myProjEdge.LowerDistance() <= myTol );
4662 bool ElementsOnShape::Classifier::isOutOfVertex(const gp_Pnt& p)
4664 return ( myVertexXYZ.Distance( p ) > myTol );
4667 bool ElementsOnShape::Classifier::isBox (const TopoDS_Shape& theShape)
4669 TopTools_IndexedMapOfShape vMap;
4670 TopExp::MapShapes( theShape, TopAbs_VERTEX, vMap );
4671 if ( vMap.Extent() != 8 )
4675 for ( int i = 1; i <= 8; ++i )
4676 myBox.Add( BRep_Tool::Pnt( TopoDS::Vertex( vMap( i ))).XYZ() );
4678 gp_XYZ pMin = myBox.CornerMin(), pMax = myBox.CornerMax();
4679 for ( int i = 1; i <= 8; ++i )
4681 gp_Pnt p = BRep_Tool::Pnt( TopoDS::Vertex( vMap( i )));
4682 for ( int iC = 1; iC <= 3; ++ iC )
4684 double d1 = Abs( pMin.Coord( iC ) - p.Coord( iC ));
4685 double d2 = Abs( pMax.Coord( iC ) - p.Coord( iC ));
4686 if ( Min( d1, d2 ) > myTol )
4690 myBox.Enlarge( myTol );
4695 OctreeClassifier::OctreeClassifier( const std::vector< ElementsOnShape::Classifier* >& classifiers )
4696 :SMESH_Octree( new SMESH_TreeLimit )
4698 myClassifiers = classifiers;
4703 OctreeClassifier::OctreeClassifier( const OctreeClassifier* otherTree,
4704 const std::vector< ElementsOnShape::Classifier >& clsOther,
4705 std::vector< ElementsOnShape::Classifier >& cls )
4706 :SMESH_Octree( new SMESH_TreeLimit )
4708 myBox = new Bnd_B3d( *otherTree->getBox() );
4710 if (( myIsLeaf = otherTree->isLeaf() ))
4712 myClassifiers.resize( otherTree->myClassifiers.size() );
4713 for ( size_t i = 0; i < otherTree->myClassifiers.size(); ++i )
4715 int ind = otherTree->myClassifiers[i] - & clsOther[0];
4716 myClassifiers[ i ] = & cls[ ind ];
4719 else if ( otherTree->myChildren )
4721 myChildren = new SMESH_Tree< Bnd_B3d, 8 > * [ 8 ];
4722 for ( int i = 0; i < nbChildren(); i++ )
4724 new OctreeClassifier( static_cast<const OctreeClassifier*>( otherTree->myChildren[i]),
4729 void ElementsOnShape::
4730 OctreeClassifier::GetClassifiersAtPoint( const gp_XYZ& point,
4731 std::vector< ElementsOnShape::Classifier* >& result )
4733 if ( getBox()->IsOut( point ))
4738 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4739 if ( !myClassifiers[i]->GetBndBox()->IsOut( point ))
4740 result.push_back( myClassifiers[i] );
4744 for (int i = 0; i < nbChildren(); i++)
4745 ((OctreeClassifier*) myChildren[i])->GetClassifiersAtPoint( point, result );
4749 void ElementsOnShape::OctreeClassifier::buildChildrenData()
4751 // distribute myClassifiers among myChildren
4753 const int childFlag[8] = { 0x0000001,
4761 int nbInChild[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
4763 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4765 for ( int j = 0; j < nbChildren(); j++ )
4767 if ( !myClassifiers[i]->GetBndBox()->IsOut( *myChildren[j]->getBox() ))
4769 myClassifiers[i]->SetFlag( childFlag[ j ]);
4775 for ( int j = 0; j < nbChildren(); j++ )
4777 OctreeClassifier* child = static_cast<OctreeClassifier*>( myChildren[ j ]);
4778 child->myClassifiers.resize( nbInChild[ j ]);
4779 for ( size_t i = 0; nbInChild[ j ] && i < myClassifiers.size(); ++i )
4781 if ( myClassifiers[ i ]->IsSetFlag( childFlag[ j ]))
4784 child->myClassifiers[ nbInChild[ j ]] = myClassifiers[ i ];
4785 myClassifiers[ i ]->UnsetFlag( childFlag[ j ]);
4789 SMESHUtils::FreeVector( myClassifiers );
4791 // define if a child isLeaf()
4792 for ( int i = 0; i < nbChildren(); i++ )
4794 OctreeClassifier* child = static_cast<OctreeClassifier*>( myChildren[ i ]);
4795 child->myIsLeaf = ( child->myClassifiers.size() <= 5 );
4799 Bnd_B3d* ElementsOnShape::OctreeClassifier::buildRootBox()
4801 Bnd_B3d* box = new Bnd_B3d;
4802 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4803 box->Add( *myClassifiers[i]->GetBndBox() );
4808 Class : BelongToGeom
4809 Description : Predicate for verifying whether entity belongs to
4810 specified geometrical support
4813 BelongToGeom::BelongToGeom()
4815 myType(SMDSAbs_NbElementTypes),
4816 myIsSubshape(false),
4817 myTolerance(Precision::Confusion())
4820 Predicate* BelongToGeom::clone() const
4822 BelongToGeom* cln = new BelongToGeom( *this );
4823 cln->myElementsOnShapePtr.reset( static_cast<ElementsOnShape*>( myElementsOnShapePtr->clone() ));
4827 void BelongToGeom::SetMesh( const SMDS_Mesh* theMesh )
4829 if ( myMeshDS != theMesh )
4831 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
4836 void BelongToGeom::SetGeom( const TopoDS_Shape& theShape )
4838 if ( myShape != theShape )
4845 static bool IsSubShape (const TopTools_IndexedMapOfShape& theMap,
4846 const TopoDS_Shape& theShape)
4848 if (theMap.Contains(theShape)) return true;
4850 if (theShape.ShapeType() == TopAbs_COMPOUND ||
4851 theShape.ShapeType() == TopAbs_COMPSOLID)
4853 TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
4854 for (; anIt.More(); anIt.Next())
4856 if (!IsSubShape(theMap, anIt.Value())) {
4866 void BelongToGeom::init()
4868 if ( !myMeshDS || myShape.IsNull() ) return;
4870 // is sub-shape of main shape?
4871 TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
4872 if (aMainShape.IsNull()) {
4873 myIsSubshape = false;
4876 TopTools_IndexedMapOfShape aMap;
4877 TopExp::MapShapes( aMainShape, aMap );
4878 myIsSubshape = IsSubShape( aMap, myShape );
4882 TopExp::MapShapes( myShape, aMap );
4883 mySubShapesIDs.Clear();
4884 for ( int i = 1; i <= aMap.Extent(); ++i )
4886 int subID = myMeshDS->ShapeToIndex( aMap( i ));
4888 mySubShapesIDs.Add( subID );
4893 //if (!myIsSubshape) // to be always ready to check an element not bound to geometry
4895 if ( !myElementsOnShapePtr )
4896 myElementsOnShapePtr.reset( new ElementsOnShape() );
4897 myElementsOnShapePtr->SetTolerance( myTolerance );
4898 myElementsOnShapePtr->SetAllNodes( true ); // "belong", while false means "lays on"
4899 myElementsOnShapePtr->SetMesh( myMeshDS );
4900 myElementsOnShapePtr->SetShape( myShape, myType );
4904 bool BelongToGeom::IsSatisfy (long theId)
4906 if (myMeshDS == 0 || myShape.IsNull())
4911 return myElementsOnShapePtr->IsSatisfy(theId);
4916 if (myType == SMDSAbs_Node)
4918 if ( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ))
4920 if ( aNode->getshapeId() < 1 )
4921 return myElementsOnShapePtr->IsSatisfy(theId);
4923 return mySubShapesIDs.Contains( aNode->getshapeId() );
4928 if ( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ))
4930 if ( anElem->GetType() == myType )
4932 if ( anElem->getshapeId() < 1 )
4933 return myElementsOnShapePtr->IsSatisfy(theId);
4935 return mySubShapesIDs.Contains( anElem->getshapeId() );
4943 void BelongToGeom::SetType (SMDSAbs_ElementType theType)
4945 if ( myType != theType )
4952 SMDSAbs_ElementType BelongToGeom::GetType() const
4957 TopoDS_Shape BelongToGeom::GetShape()
4962 const SMESHDS_Mesh* BelongToGeom::GetMeshDS() const
4967 void BelongToGeom::SetTolerance (double theTolerance)
4969 myTolerance = theTolerance;
4973 double BelongToGeom::GetTolerance()
4980 Description : Predicate for verifying whether entiy lying or partially lying on
4981 specified geometrical support
4984 LyingOnGeom::LyingOnGeom()
4986 myType(SMDSAbs_NbElementTypes),
4987 myIsSubshape(false),
4988 myTolerance(Precision::Confusion())
4991 Predicate* LyingOnGeom::clone() const
4993 LyingOnGeom* cln = new LyingOnGeom( *this );
4994 cln->myElementsOnShapePtr.reset( static_cast<ElementsOnShape*>( myElementsOnShapePtr->clone() ));
4998 void LyingOnGeom::SetMesh( const SMDS_Mesh* theMesh )
5000 if ( myMeshDS != theMesh )
5002 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
5007 void LyingOnGeom::SetGeom( const TopoDS_Shape& theShape )
5009 if ( myShape != theShape )
5016 void LyingOnGeom::init()
5018 if (!myMeshDS || myShape.IsNull()) return;
5020 // is sub-shape of main shape?
5021 TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
5022 if (aMainShape.IsNull()) {
5023 myIsSubshape = false;
5026 myIsSubshape = myMeshDS->IsGroupOfSubShapes( myShape );
5031 TopTools_IndexedMapOfShape shapes;
5032 TopExp::MapShapes( myShape, shapes );
5033 mySubShapesIDs.Clear();
5034 for ( int i = 1; i <= shapes.Extent(); ++i )
5036 int subID = myMeshDS->ShapeToIndex( shapes( i ));
5038 mySubShapesIDs.Add( subID );
5041 // else // to be always ready to check an element not bound to geometry
5043 if ( !myElementsOnShapePtr )
5044 myElementsOnShapePtr.reset( new ElementsOnShape() );
5045 myElementsOnShapePtr->SetTolerance( myTolerance );
5046 myElementsOnShapePtr->SetAllNodes( false ); // lays on, while true means "belong"
5047 myElementsOnShapePtr->SetMesh( myMeshDS );
5048 myElementsOnShapePtr->SetShape( myShape, myType );
5052 bool LyingOnGeom::IsSatisfy( long theId )
5054 if ( myMeshDS == 0 || myShape.IsNull() )
5059 return myElementsOnShapePtr->IsSatisfy(theId);
5064 const SMDS_MeshElement* elem =
5065 ( myType == SMDSAbs_Node ) ? myMeshDS->FindNode( theId ) : myMeshDS->FindElement( theId );
5067 if ( mySubShapesIDs.Contains( elem->getshapeId() ))
5070 if ( elem->GetType() != SMDSAbs_Node && elem->GetType() == myType )
5072 SMDS_ElemIteratorPtr nodeItr = elem->nodesIterator();
5073 while ( nodeItr->more() )
5075 const SMDS_MeshElement* aNode = nodeItr->next();
5076 if ( mySubShapesIDs.Contains( aNode->getshapeId() ))
5084 void LyingOnGeom::SetType( SMDSAbs_ElementType theType )
5086 if ( myType != theType )
5093 SMDSAbs_ElementType LyingOnGeom::GetType() const
5098 TopoDS_Shape LyingOnGeom::GetShape()
5103 const SMESHDS_Mesh* LyingOnGeom::GetMeshDS() const
5108 void LyingOnGeom::SetTolerance (double theTolerance)
5110 myTolerance = theTolerance;
5114 double LyingOnGeom::GetTolerance()
5119 TSequenceOfXYZ::TSequenceOfXYZ(): myElem(0)
5122 TSequenceOfXYZ::TSequenceOfXYZ(size_type n) : myArray(n), myElem(0)
5125 TSequenceOfXYZ::TSequenceOfXYZ(size_type n, const gp_XYZ& t) : myArray(n,t), myElem(0)
5128 TSequenceOfXYZ::TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ) : myArray(theSequenceOfXYZ.myArray), myElem(theSequenceOfXYZ.myElem)
5131 template <class InputIterator>
5132 TSequenceOfXYZ::TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd): myArray(theBegin,theEnd), myElem(0)
5135 TSequenceOfXYZ::~TSequenceOfXYZ()
5138 TSequenceOfXYZ& TSequenceOfXYZ::operator=(const TSequenceOfXYZ& theSequenceOfXYZ)
5140 myArray = theSequenceOfXYZ.myArray;
5141 myElem = theSequenceOfXYZ.myElem;
5145 gp_XYZ& TSequenceOfXYZ::operator()(size_type n)
5147 return myArray[n-1];
5150 const gp_XYZ& TSequenceOfXYZ::operator()(size_type n) const
5152 return myArray[n-1];
5155 void TSequenceOfXYZ::clear()
5160 void TSequenceOfXYZ::reserve(size_type n)
5165 void TSequenceOfXYZ::push_back(const gp_XYZ& v)
5167 myArray.push_back(v);
5170 TSequenceOfXYZ::size_type TSequenceOfXYZ::size() const
5172 return myArray.size();
5175 SMDSAbs_EntityType TSequenceOfXYZ::getElementEntity() const
5177 return myElem ? myElem->GetEntityType() : SMDSEntity_Last;
5180 TMeshModifTracer::TMeshModifTracer():
5181 myMeshModifTime(0), myMesh(0)
5184 void TMeshModifTracer::SetMesh( const SMDS_Mesh* theMesh )
5186 if ( theMesh != myMesh )
5187 myMeshModifTime = 0;
5190 bool TMeshModifTracer::IsMeshModified()
5192 bool modified = false;
5195 modified = ( myMeshModifTime != myMesh->GetMTime() );
5196 myMeshModifTime = myMesh->GetMTime();