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_Iterator.hxx"
27 #include "SMDS_Mesh.hxx"
28 #include "SMDS_MeshElement.hxx"
29 #include "SMDS_MeshNode.hxx"
30 #include "SMDS_QuadraticEdge.hxx"
31 #include "SMDS_QuadraticFaceOfNodes.hxx"
32 #include "SMDS_VolumeTool.hxx"
33 #include "SMESHDS_GroupBase.hxx"
34 #include "SMESHDS_GroupOnFilter.hxx"
35 #include "SMESHDS_Mesh.hxx"
36 #include "SMESH_MeshAlgos.hxx"
37 #include "SMESH_OctreeNode.hxx"
39 #include <Basics_Utils.hxx>
41 #include <BRepAdaptor_Surface.hxx>
42 #include <BRepBndLib.hxx>
43 #include <BRepBuilderAPI_Copy.hxx>
44 #include <BRepClass_FaceClassifier.hxx>
45 #include <BRep_Tool.hxx>
46 #include <Geom_CylindricalSurface.hxx>
47 #include <Geom_Plane.hxx>
48 #include <Geom_Surface.hxx>
49 #include <NCollection_Map.hxx>
50 #include <Precision.hxx>
51 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
52 #include <TColStd_MapOfInteger.hxx>
53 #include <TColStd_SequenceOfAsciiString.hxx>
54 #include <TColgp_Array1OfXYZ.hxx>
58 #include <TopoDS_Edge.hxx>
59 #include <TopoDS_Face.hxx>
60 #include <TopoDS_Iterator.hxx>
61 #include <TopoDS_Shape.hxx>
62 #include <TopoDS_Vertex.hxx>
64 #include <gp_Cylinder.hxx>
71 #include <vtkMeshQuality.h>
82 const double theEps = 1e-100;
83 const double theInf = 1e+100;
85 inline gp_XYZ gpXYZ(const SMDS_MeshNode* aNode )
87 return gp_XYZ(aNode->X(), aNode->Y(), aNode->Z() );
90 inline double getAngle( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
92 gp_Vec v1( P1 - P2 ), v2( P3 - P2 );
94 return v1.Magnitude() < gp::Resolution() ||
95 v2.Magnitude() < gp::Resolution() ? 0 : v1.Angle( v2 );
98 inline double getArea( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
100 gp_Vec aVec1( P2 - P1 );
101 gp_Vec aVec2( P3 - P1 );
102 return ( aVec1 ^ aVec2 ).Magnitude() * 0.5;
105 inline double getArea( const gp_Pnt& P1, const gp_Pnt& P2, const gp_Pnt& P3 )
107 return getArea( P1.XYZ(), P2.XYZ(), P3.XYZ() );
112 inline double getDistance( const gp_XYZ& P1, const gp_XYZ& P2 )
114 double aDist = gp_Pnt( P1 ).Distance( gp_Pnt( P2 ) );
118 int getNbMultiConnection( const SMDS_Mesh* theMesh, const int theId )
123 const SMDS_MeshElement* anEdge = theMesh->FindElement( theId );
124 if ( anEdge == 0 || anEdge->GetType() != SMDSAbs_Edge/* || anEdge->NbNodes() != 2 */)
127 // for each pair of nodes in anEdge (there are 2 pairs in a quadratic edge)
128 // count elements containing both nodes of the pair.
129 // Note that there may be such cases for a quadratic edge (a horizontal line):
134 // +-----+------+ +-----+------+
137 // result should be 2 in both cases
139 int aResult0 = 0, aResult1 = 0;
140 // last node, it is a medium one in a quadratic edge
141 const SMDS_MeshNode* aLastNode = anEdge->GetNode( anEdge->NbNodes() - 1 );
142 const SMDS_MeshNode* aNode0 = anEdge->GetNode( 0 );
143 const SMDS_MeshNode* aNode1 = anEdge->GetNode( 1 );
144 if ( aNode1 == aLastNode ) aNode1 = 0;
146 SMDS_ElemIteratorPtr anElemIter = aLastNode->GetInverseElementIterator();
147 while( anElemIter->more() ) {
148 const SMDS_MeshElement* anElem = anElemIter->next();
149 if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) {
150 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
151 while ( anIter->more() ) {
152 if ( const SMDS_MeshElement* anElemNode = anIter->next() ) {
153 if ( anElemNode == aNode0 ) {
155 if ( !aNode1 ) break; // not a quadratic edge
157 else if ( anElemNode == aNode1 )
163 int aResult = std::max ( aResult0, aResult1 );
168 gp_XYZ getNormale( const SMDS_MeshFace* theFace, bool* ok=0 )
170 int aNbNode = theFace->NbNodes();
172 gp_XYZ q1 = gpXYZ( theFace->GetNode(1)) - gpXYZ( theFace->GetNode(0));
173 gp_XYZ q2 = gpXYZ( theFace->GetNode(2)) - gpXYZ( theFace->GetNode(0));
176 gp_XYZ q3 = gpXYZ( theFace->GetNode(3)) - gpXYZ( theFace->GetNode(0));
179 double len = n.Modulus();
180 bool zeroLen = ( len <= std::numeric_limits<double>::min());
184 if (ok) *ok = !zeroLen;
192 using namespace SMESH::Controls;
198 //================================================================================
200 Class : NumericalFunctor
201 Description : Base class for numerical functors
203 //================================================================================
205 NumericalFunctor::NumericalFunctor():
211 void NumericalFunctor::SetMesh( const SMDS_Mesh* theMesh )
216 bool NumericalFunctor::GetPoints(const int theId,
217 TSequenceOfXYZ& theRes ) const
224 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
225 if ( !anElem || anElem->GetType() != this->GetType() )
228 return GetPoints( anElem, theRes );
231 bool NumericalFunctor::GetPoints(const SMDS_MeshElement* anElem,
232 TSequenceOfXYZ& theRes )
239 theRes.reserve( anElem->NbNodes() );
240 theRes.setElement( anElem );
242 // Get nodes of the element
243 SMDS_ElemIteratorPtr anIter;
245 if ( anElem->IsQuadratic() ) {
246 switch ( anElem->GetType() ) {
248 anIter = dynamic_cast<const SMDS_VtkEdge*>
249 (anElem)->interlacedNodesElemIterator();
252 anIter = dynamic_cast<const SMDS_VtkFace*>
253 (anElem)->interlacedNodesElemIterator();
256 anIter = anElem->nodesIterator();
260 anIter = anElem->nodesIterator();
265 while( anIter->more() ) {
266 if ( const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>( anIter->next() ))
268 aNode->GetXYZ( xyz );
269 theRes.push_back( gp_XYZ( xyz[0], xyz[1], xyz[2] ));
277 long NumericalFunctor::GetPrecision() const
282 void NumericalFunctor::SetPrecision( const long thePrecision )
284 myPrecision = thePrecision;
285 myPrecisionValue = pow( 10., (double)( myPrecision ) );
288 double NumericalFunctor::GetValue( long theId )
292 myCurrElement = myMesh->FindElement( theId );
295 if ( GetPoints( theId, P )) // elem type is checked here
296 aVal = Round( GetValue( P ));
301 double NumericalFunctor::Round( const double & aVal )
303 return ( myPrecision >= 0 ) ? floor( aVal * myPrecisionValue + 0.5 ) / myPrecisionValue : aVal;
306 //================================================================================
308 * \brief Return histogram of functor values
309 * \param nbIntervals - number of intervals
310 * \param nbEvents - number of mesh elements having values within i-th interval
311 * \param funValues - boundaries of intervals
312 * \param elements - elements to check vulue of; empty list means "of all"
313 * \param minmax - boundaries of diapason of values to divide into intervals
315 //================================================================================
317 void NumericalFunctor::GetHistogram(int nbIntervals,
318 std::vector<int>& nbEvents,
319 std::vector<double>& funValues,
320 const std::vector<int>& elements,
321 const double* minmax,
322 const bool isLogarithmic)
324 if ( nbIntervals < 1 ||
326 !myMesh->GetMeshInfo().NbElements( GetType() ))
328 nbEvents.resize( nbIntervals, 0 );
329 funValues.resize( nbIntervals+1 );
331 // get all values sorted
332 std::multiset< double > values;
333 if ( elements.empty() )
335 SMDS_ElemIteratorPtr elemIt = myMesh->elementsIterator( GetType() );
336 while ( elemIt->more() )
337 values.insert( GetValue( elemIt->next()->GetID() ));
341 std::vector<int>::const_iterator id = elements.begin();
342 for ( ; id != elements.end(); ++id )
343 values.insert( GetValue( *id ));
348 funValues[0] = minmax[0];
349 funValues[nbIntervals] = minmax[1];
353 funValues[0] = *values.begin();
354 funValues[nbIntervals] = *values.rbegin();
356 // case nbIntervals == 1
357 if ( nbIntervals == 1 )
359 nbEvents[0] = values.size();
363 if (funValues.front() == funValues.back())
365 nbEvents.resize( 1 );
366 nbEvents[0] = values.size();
367 funValues[1] = funValues.back();
368 funValues.resize( 2 );
371 std::multiset< double >::iterator min = values.begin(), max;
372 for ( int i = 0; i < nbIntervals; ++i )
374 // find end value of i-th interval
375 double r = (i+1) / double(nbIntervals);
376 if (isLogarithmic && funValues.front() > 1e-07 && funValues.back() > 1e-07) {
377 double logmin = log10(funValues.front());
378 double lval = logmin + r * (log10(funValues.back()) - logmin);
379 funValues[i+1] = pow(10.0, lval);
382 funValues[i+1] = funValues.front() * (1-r) + funValues.back() * r;
385 // count values in the i-th interval if there are any
386 if ( min != values.end() && *min <= funValues[i+1] )
388 // find the first value out of the interval
389 max = values.upper_bound( funValues[i+1] ); // max is greater than funValues[i+1], or end()
390 nbEvents[i] = std::distance( min, max );
394 // add values larger than minmax[1]
395 nbEvents.back() += std::distance( min, values.end() );
398 //=======================================================================
401 Description : Functor calculating volume of a 3D element
403 //================================================================================
405 double Volume::GetValue( long theElementId )
407 if ( theElementId && myMesh ) {
408 SMDS_VolumeTool aVolumeTool;
409 if ( aVolumeTool.Set( myMesh->FindElement( theElementId )))
410 return aVolumeTool.GetSize();
415 double Volume::GetBadRate( double Value, int /*nbNodes*/ ) const
420 SMDSAbs_ElementType Volume::GetType() const
422 return SMDSAbs_Volume;
425 //=======================================================================
427 Class : MaxElementLength2D
428 Description : Functor calculating maximum length of 2D element
430 //================================================================================
432 double MaxElementLength2D::GetValue( const TSequenceOfXYZ& P )
438 if( len == 3 ) { // triangles
439 double L1 = getDistance(P( 1 ),P( 2 ));
440 double L2 = getDistance(P( 2 ),P( 3 ));
441 double L3 = getDistance(P( 3 ),P( 1 ));
442 aVal = Max(L1,Max(L2,L3));
444 else if( len == 4 ) { // quadrangles
445 double L1 = getDistance(P( 1 ),P( 2 ));
446 double L2 = getDistance(P( 2 ),P( 3 ));
447 double L3 = getDistance(P( 3 ),P( 4 ));
448 double L4 = getDistance(P( 4 ),P( 1 ));
449 double D1 = getDistance(P( 1 ),P( 3 ));
450 double D2 = getDistance(P( 2 ),P( 4 ));
451 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(D1,D2));
453 else if( len == 6 ) { // quadratic triangles
454 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
455 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
456 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 1 ));
457 aVal = Max(L1,Max(L2,L3));
459 else if( len == 8 || len == 9 ) { // quadratic quadrangles
460 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
461 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
462 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 7 ));
463 double L4 = getDistance(P( 7 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
464 double D1 = getDistance(P( 1 ),P( 5 ));
465 double D2 = getDistance(P( 3 ),P( 7 ));
466 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(D1,D2));
468 // Diagonals are undefined for concave polygons
469 // else if ( P.getElementEntity() == SMDSEntity_Quad_Polygon && P.size() > 2 ) // quad polygon
472 // aVal = getDistance( P( 1 ), P( P.size() )) + getDistance( P( P.size() ), P( P.size()-1 ));
473 // for ( size_t i = 1; i < P.size()-1; i += 2 )
475 // double L = getDistance( P( i ), P( i+1 )) + getDistance( P( i+1 ), P( i+2 ));
476 // aVal = Max( aVal, L );
479 // for ( int i = P.size()-5; i > 0; i -= 2 )
480 // for ( int j = i + 4; j < P.size() + i - 2; i += 2 )
482 // double D = getDistance( P( i ), P( j ));
483 // aVal = Max( aVal, D );
490 if( myPrecision >= 0 )
492 double prec = pow( 10., (double)myPrecision );
493 aVal = floor( aVal * prec + 0.5 ) / prec;
498 double MaxElementLength2D::GetValue( long theElementId )
501 return GetPoints( theElementId, P ) ? GetValue(P) : 0.0;
504 double MaxElementLength2D::GetBadRate( double Value, int /*nbNodes*/ ) const
509 SMDSAbs_ElementType MaxElementLength2D::GetType() const
514 //=======================================================================
516 Class : MaxElementLength3D
517 Description : Functor calculating maximum length of 3D element
519 //================================================================================
521 double MaxElementLength3D::GetValue( long theElementId )
524 if( GetPoints( theElementId, P ) ) {
526 const SMDS_MeshElement* aElem = myMesh->FindElement( theElementId );
527 SMDSAbs_EntityType aType = aElem->GetEntityType();
530 case SMDSEntity_Tetra: { // tetras
531 double L1 = getDistance(P( 1 ),P( 2 ));
532 double L2 = getDistance(P( 2 ),P( 3 ));
533 double L3 = getDistance(P( 3 ),P( 1 ));
534 double L4 = getDistance(P( 1 ),P( 4 ));
535 double L5 = getDistance(P( 2 ),P( 4 ));
536 double L6 = getDistance(P( 3 ),P( 4 ));
537 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
540 case SMDSEntity_Pyramid: { // pyramids
541 double L1 = getDistance(P( 1 ),P( 2 ));
542 double L2 = getDistance(P( 2 ),P( 3 ));
543 double L3 = getDistance(P( 3 ),P( 4 ));
544 double L4 = getDistance(P( 4 ),P( 1 ));
545 double L5 = getDistance(P( 1 ),P( 5 ));
546 double L6 = getDistance(P( 2 ),P( 5 ));
547 double L7 = getDistance(P( 3 ),P( 5 ));
548 double L8 = getDistance(P( 4 ),P( 5 ));
549 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
550 aVal = Max(aVal,Max(L7,L8));
553 case SMDSEntity_Penta: { // pentas
554 double L1 = getDistance(P( 1 ),P( 2 ));
555 double L2 = getDistance(P( 2 ),P( 3 ));
556 double L3 = getDistance(P( 3 ),P( 1 ));
557 double L4 = getDistance(P( 4 ),P( 5 ));
558 double L5 = getDistance(P( 5 ),P( 6 ));
559 double L6 = getDistance(P( 6 ),P( 4 ));
560 double L7 = getDistance(P( 1 ),P( 4 ));
561 double L8 = getDistance(P( 2 ),P( 5 ));
562 double L9 = getDistance(P( 3 ),P( 6 ));
563 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
564 aVal = Max(aVal,Max(Max(L7,L8),L9));
567 case SMDSEntity_Hexa: { // hexas
568 double L1 = getDistance(P( 1 ),P( 2 ));
569 double L2 = getDistance(P( 2 ),P( 3 ));
570 double L3 = getDistance(P( 3 ),P( 4 ));
571 double L4 = getDistance(P( 4 ),P( 1 ));
572 double L5 = getDistance(P( 5 ),P( 6 ));
573 double L6 = getDistance(P( 6 ),P( 7 ));
574 double L7 = getDistance(P( 7 ),P( 8 ));
575 double L8 = getDistance(P( 8 ),P( 5 ));
576 double L9 = getDistance(P( 1 ),P( 5 ));
577 double L10= getDistance(P( 2 ),P( 6 ));
578 double L11= getDistance(P( 3 ),P( 7 ));
579 double L12= getDistance(P( 4 ),P( 8 ));
580 double D1 = getDistance(P( 1 ),P( 7 ));
581 double D2 = getDistance(P( 2 ),P( 8 ));
582 double D3 = getDistance(P( 3 ),P( 5 ));
583 double D4 = getDistance(P( 4 ),P( 6 ));
584 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
585 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
586 aVal = Max(aVal,Max(L11,L12));
587 aVal = Max(aVal,Max(Max(D1,D2),Max(D3,D4)));
590 case SMDSEntity_Hexagonal_Prism: { // hexagonal prism
591 for ( int i1 = 1; i1 < 12; ++i1 )
592 for ( int i2 = i1+1; i1 <= 12; ++i1 )
593 aVal = Max( aVal, getDistance(P( i1 ),P( i2 )));
596 case SMDSEntity_Quad_Tetra: { // quadratic tetras
597 double L1 = getDistance(P( 1 ),P( 5 )) + getDistance(P( 5 ),P( 2 ));
598 double L2 = getDistance(P( 2 ),P( 6 )) + getDistance(P( 6 ),P( 3 ));
599 double L3 = getDistance(P( 3 ),P( 7 )) + getDistance(P( 7 ),P( 1 ));
600 double L4 = getDistance(P( 1 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
601 double L5 = getDistance(P( 2 ),P( 9 )) + getDistance(P( 9 ),P( 4 ));
602 double L6 = getDistance(P( 3 ),P( 10 )) + getDistance(P( 10 ),P( 4 ));
603 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
606 case SMDSEntity_Quad_Pyramid: { // quadratic pyramids
607 double L1 = getDistance(P( 1 ),P( 6 )) + getDistance(P( 6 ),P( 2 ));
608 double L2 = getDistance(P( 2 ),P( 7 )) + getDistance(P( 7 ),P( 3 ));
609 double L3 = getDistance(P( 3 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
610 double L4 = getDistance(P( 4 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
611 double L5 = getDistance(P( 1 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
612 double L6 = getDistance(P( 2 ),P( 11 )) + getDistance(P( 11 ),P( 5 ));
613 double L7 = getDistance(P( 3 ),P( 12 )) + getDistance(P( 12 ),P( 5 ));
614 double L8 = getDistance(P( 4 ),P( 13 )) + getDistance(P( 13 ),P( 5 ));
615 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
616 aVal = Max(aVal,Max(L7,L8));
619 case SMDSEntity_Quad_Penta:
620 case SMDSEntity_BiQuad_Penta: { // quadratic pentas
621 double L1 = getDistance(P( 1 ),P( 7 )) + getDistance(P( 7 ),P( 2 ));
622 double L2 = getDistance(P( 2 ),P( 8 )) + getDistance(P( 8 ),P( 3 ));
623 double L3 = getDistance(P( 3 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
624 double L4 = getDistance(P( 4 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
625 double L5 = getDistance(P( 5 ),P( 11 )) + getDistance(P( 11 ),P( 6 ));
626 double L6 = getDistance(P( 6 ),P( 12 )) + getDistance(P( 12 ),P( 4 ));
627 double L7 = getDistance(P( 1 ),P( 13 )) + getDistance(P( 13 ),P( 4 ));
628 double L8 = getDistance(P( 2 ),P( 14 )) + getDistance(P( 14 ),P( 5 ));
629 double L9 = getDistance(P( 3 ),P( 15 )) + getDistance(P( 15 ),P( 6 ));
630 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
631 aVal = Max(aVal,Max(Max(L7,L8),L9));
634 case SMDSEntity_Quad_Hexa:
635 case SMDSEntity_TriQuad_Hexa: { // quadratic hexas
636 double L1 = getDistance(P( 1 ),P( 9 )) + getDistance(P( 9 ),P( 2 ));
637 double L2 = getDistance(P( 2 ),P( 10 )) + getDistance(P( 10 ),P( 3 ));
638 double L3 = getDistance(P( 3 ),P( 11 )) + getDistance(P( 11 ),P( 4 ));
639 double L4 = getDistance(P( 4 ),P( 12 )) + getDistance(P( 12 ),P( 1 ));
640 double L5 = getDistance(P( 5 ),P( 13 )) + getDistance(P( 13 ),P( 6 ));
641 double L6 = getDistance(P( 6 ),P( 14 )) + getDistance(P( 14 ),P( 7 ));
642 double L7 = getDistance(P( 7 ),P( 15 )) + getDistance(P( 15 ),P( 8 ));
643 double L8 = getDistance(P( 8 ),P( 16 )) + getDistance(P( 16 ),P( 5 ));
644 double L9 = getDistance(P( 1 ),P( 17 )) + getDistance(P( 17 ),P( 5 ));
645 double L10= getDistance(P( 2 ),P( 18 )) + getDistance(P( 18 ),P( 6 ));
646 double L11= getDistance(P( 3 ),P( 19 )) + getDistance(P( 19 ),P( 7 ));
647 double L12= getDistance(P( 4 ),P( 20 )) + getDistance(P( 20 ),P( 8 ));
648 double D1 = getDistance(P( 1 ),P( 7 ));
649 double D2 = getDistance(P( 2 ),P( 8 ));
650 double D3 = getDistance(P( 3 ),P( 5 ));
651 double D4 = getDistance(P( 4 ),P( 6 ));
652 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
653 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
654 aVal = Max(aVal,Max(L11,L12));
655 aVal = Max(aVal,Max(Max(D1,D2),Max(D3,D4)));
658 case SMDSEntity_Quad_Polyhedra:
659 case SMDSEntity_Polyhedra: { // polys
660 // get the maximum distance between all pairs of nodes
661 for( int i = 1; i <= len; i++ ) {
662 for( int j = 1; j <= len; j++ ) {
663 if( j > i ) { // optimization of the loop
664 double D = getDistance( P(i), P(j) );
665 aVal = Max( aVal, D );
671 case SMDSEntity_Node:
673 case SMDSEntity_Edge:
674 case SMDSEntity_Quad_Edge:
675 case SMDSEntity_Triangle:
676 case SMDSEntity_Quad_Triangle:
677 case SMDSEntity_BiQuad_Triangle:
678 case SMDSEntity_Quadrangle:
679 case SMDSEntity_Quad_Quadrangle:
680 case SMDSEntity_BiQuad_Quadrangle:
681 case SMDSEntity_Polygon:
682 case SMDSEntity_Quad_Polygon:
683 case SMDSEntity_Ball:
684 case SMDSEntity_Last: return 0;
685 } // switch ( aType )
687 if( myPrecision >= 0 )
689 double prec = pow( 10., (double)myPrecision );
690 aVal = floor( aVal * prec + 0.5 ) / prec;
697 double MaxElementLength3D::GetBadRate( double Value, int /*nbNodes*/ ) const
702 SMDSAbs_ElementType MaxElementLength3D::GetType() const
704 return SMDSAbs_Volume;
707 //=======================================================================
710 Description : Functor for calculation of minimum angle
712 //================================================================================
714 double MinimumAngle::GetValue( const TSequenceOfXYZ& P )
721 aMin = getAngle(P( P.size() ), P( 1 ), P( 2 ));
722 aMin = Min(aMin,getAngle(P( P.size()-1 ), P( P.size() ), P( 1 )));
724 for ( size_t i = 2; i < P.size(); i++ )
726 double A0 = getAngle( P( i-1 ), P( i ), P( i+1 ) );
730 return aMin * 180.0 / M_PI;
733 double MinimumAngle::GetBadRate( double Value, int nbNodes ) const
735 //const double aBestAngle = PI / nbNodes;
736 const double aBestAngle = 180.0 - ( 360.0 / double(nbNodes) );
737 return ( fabs( aBestAngle - Value ));
740 SMDSAbs_ElementType MinimumAngle::GetType() const
746 //================================================================================
749 Description : Functor for calculating aspect ratio
751 //================================================================================
753 double AspectRatio::GetValue( long theId )
756 myCurrElement = myMesh->FindElement( theId );
757 if ( myCurrElement && myCurrElement->GetVtkType() == VTK_QUAD )
760 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myCurrElement->getMeshId()]->getGrid();
761 if ( vtkCell* avtkCell = grid->GetCell( myCurrElement->getVtkId() ))
762 aVal = Round( vtkMeshQuality::QuadAspectRatio( avtkCell ));
767 if ( GetPoints( myCurrElement, P ))
768 aVal = Round( GetValue( P ));
773 double AspectRatio::GetValue( const TSequenceOfXYZ& P )
775 // According to "Mesh quality control" by Nadir Bouhamau referring to
776 // Pascal Jean Frey and Paul-Louis George. Maillages, applications aux elements finis.
777 // Hermes Science publications, Paris 1999 ISBN 2-7462-0024-4
780 int nbNodes = P.size();
785 // Compute aspect ratio
787 if ( nbNodes == 3 ) {
788 // Compute lengths of the sides
789 std::vector< double > aLen (nbNodes);
790 for ( int i = 0; i < nbNodes - 1; i++ )
791 aLen[ i ] = getDistance( P( i + 1 ), P( i + 2 ) );
792 aLen[ nbNodes - 1 ] = getDistance( P( 1 ), P( nbNodes ) );
793 // Q = alfa * h * p / S, where
795 // alfa = sqrt( 3 ) / 6
796 // h - length of the longest edge
797 // p - half perimeter
798 // S - triangle surface
799 const double alfa = sqrt( 3. ) / 6.;
800 double maxLen = Max( aLen[ 0 ], Max( aLen[ 1 ], aLen[ 2 ] ) );
801 double half_perimeter = ( aLen[0] + aLen[1] + aLen[2] ) / 2.;
802 double anArea = getArea( P( 1 ), P( 2 ), P( 3 ) );
803 if ( anArea <= theEps )
805 return alfa * maxLen * half_perimeter / anArea;
807 else if ( nbNodes == 6 ) { // quadratic triangles
808 // Compute lengths of the sides
809 std::vector< double > aLen (3);
810 aLen[0] = getDistance( P(1), P(3) );
811 aLen[1] = getDistance( P(3), P(5) );
812 aLen[2] = getDistance( P(5), P(1) );
813 // Q = alfa * h * p / S, where
815 // alfa = sqrt( 3 ) / 6
816 // h - length of the longest edge
817 // p - half perimeter
818 // S - triangle surface
819 const double alfa = sqrt( 3. ) / 6.;
820 double maxLen = Max( aLen[ 0 ], Max( aLen[ 1 ], aLen[ 2 ] ) );
821 double half_perimeter = ( aLen[0] + aLen[1] + aLen[2] ) / 2.;
822 double anArea = getArea( P(1), P(3), P(5) );
823 if ( anArea <= theEps )
825 return alfa * maxLen * half_perimeter / anArea;
827 else if( nbNodes == 4 ) { // quadrangle
828 // Compute lengths of the sides
829 std::vector< double > aLen (4);
830 aLen[0] = getDistance( P(1), P(2) );
831 aLen[1] = getDistance( P(2), P(3) );
832 aLen[2] = getDistance( P(3), P(4) );
833 aLen[3] = getDistance( P(4), P(1) );
834 // Compute lengths of the diagonals
835 std::vector< double > aDia (2);
836 aDia[0] = getDistance( P(1), P(3) );
837 aDia[1] = getDistance( P(2), P(4) );
838 // Compute areas of all triangles which can be built
839 // taking three nodes of the quadrangle
840 std::vector< double > anArea (4);
841 anArea[0] = getArea( P(1), P(2), P(3) );
842 anArea[1] = getArea( P(1), P(2), P(4) );
843 anArea[2] = getArea( P(1), P(3), P(4) );
844 anArea[3] = getArea( P(2), P(3), P(4) );
845 // Q = alpha * L * C1 / C2, where
847 // alpha = sqrt( 1/32 )
848 // L = max( L1, L2, L3, L4, D1, D2 )
849 // C1 = sqrt( ( L1^2 + L1^2 + L1^2 + L1^2 ) / 4 )
850 // C2 = min( S1, S2, S3, S4 )
851 // Li - lengths of the edges
852 // Di - lengths of the diagonals
853 // Si - areas of the triangles
854 const double alpha = sqrt( 1 / 32. );
855 double L = Max( aLen[ 0 ],
859 Max( aDia[ 0 ], aDia[ 1 ] ) ) ) ) );
860 double C1 = sqrt( ( aLen[0] * aLen[0] +
863 aLen[3] * aLen[3] ) / 4. );
864 double C2 = Min( anArea[ 0 ],
866 Min( anArea[ 2 ], anArea[ 3 ] ) ) );
869 return alpha * L * C1 / C2;
871 else if( nbNodes == 8 || nbNodes == 9 ) { // nbNodes==8 - quadratic quadrangle
872 // Compute lengths of the sides
873 std::vector< double > aLen (4);
874 aLen[0] = getDistance( P(1), P(3) );
875 aLen[1] = getDistance( P(3), P(5) );
876 aLen[2] = getDistance( P(5), P(7) );
877 aLen[3] = getDistance( P(7), P(1) );
878 // Compute lengths of the diagonals
879 std::vector< double > aDia (2);
880 aDia[0] = getDistance( P(1), P(5) );
881 aDia[1] = getDistance( P(3), P(7) );
882 // Compute areas of all triangles which can be built
883 // taking three nodes of the quadrangle
884 std::vector< double > anArea (4);
885 anArea[0] = getArea( P(1), P(3), P(5) );
886 anArea[1] = getArea( P(1), P(3), P(7) );
887 anArea[2] = getArea( P(1), P(5), P(7) );
888 anArea[3] = getArea( P(3), P(5), P(7) );
889 // Q = alpha * L * C1 / C2, where
891 // alpha = sqrt( 1/32 )
892 // L = max( L1, L2, L3, L4, D1, D2 )
893 // C1 = sqrt( ( L1^2 + L1^2 + L1^2 + L1^2 ) / 4 )
894 // C2 = min( S1, S2, S3, S4 )
895 // Li - lengths of the edges
896 // Di - lengths of the diagonals
897 // Si - areas of the triangles
898 const double alpha = sqrt( 1 / 32. );
899 double L = Max( aLen[ 0 ],
903 Max( aDia[ 0 ], aDia[ 1 ] ) ) ) ) );
904 double C1 = sqrt( ( aLen[0] * aLen[0] +
907 aLen[3] * aLen[3] ) / 4. );
908 double C2 = Min( anArea[ 0 ],
910 Min( anArea[ 2 ], anArea[ 3 ] ) ) );
913 return alpha * L * C1 / C2;
918 double AspectRatio::GetBadRate( double Value, int /*nbNodes*/ ) const
920 // the aspect ratio is in the range [1.0,infinity]
921 // < 1.0 = very bad, zero area
924 return ( Value < 0.9 ) ? 1000 : Value / 1000.;
927 SMDSAbs_ElementType AspectRatio::GetType() const
933 //================================================================================
935 Class : AspectRatio3D
936 Description : Functor for calculating aspect ratio
938 //================================================================================
942 inline double getHalfPerimeter(double theTria[3]){
943 return (theTria[0] + theTria[1] + theTria[2])/2.0;
946 inline double getArea(double theHalfPerim, double theTria[3]){
947 return sqrt(theHalfPerim*
948 (theHalfPerim-theTria[0])*
949 (theHalfPerim-theTria[1])*
950 (theHalfPerim-theTria[2]));
953 inline double getVolume(double theLen[6]){
954 double a2 = theLen[0]*theLen[0];
955 double b2 = theLen[1]*theLen[1];
956 double c2 = theLen[2]*theLen[2];
957 double d2 = theLen[3]*theLen[3];
958 double e2 = theLen[4]*theLen[4];
959 double f2 = theLen[5]*theLen[5];
960 double P = 4.0*a2*b2*d2;
961 double Q = a2*(b2+d2-e2)-b2*(a2+d2-f2)-d2*(a2+b2-c2);
962 double R = (b2+d2-e2)*(a2+d2-f2)*(a2+d2-f2);
963 return sqrt(P-Q+R)/12.0;
966 inline double getVolume2(double theLen[6]){
967 double a2 = theLen[0]*theLen[0];
968 double b2 = theLen[1]*theLen[1];
969 double c2 = theLen[2]*theLen[2];
970 double d2 = theLen[3]*theLen[3];
971 double e2 = theLen[4]*theLen[4];
972 double f2 = theLen[5]*theLen[5];
974 double P = a2*e2*(b2+c2+d2+f2-a2-e2);
975 double Q = b2*f2*(a2+c2+d2+e2-b2-f2);
976 double R = c2*d2*(a2+b2+e2+f2-c2-d2);
977 double S = a2*b2*d2+b2*c2*e2+a2*c2*f2+d2*e2*f2;
979 return sqrt(P+Q+R-S)/12.0;
982 inline double getVolume(const TSequenceOfXYZ& P){
983 gp_Vec aVec1( P( 2 ) - P( 1 ) );
984 gp_Vec aVec2( P( 3 ) - P( 1 ) );
985 gp_Vec aVec3( P( 4 ) - P( 1 ) );
986 gp_Vec anAreaVec( aVec1 ^ aVec2 );
987 return fabs(aVec3 * anAreaVec) / 6.0;
990 inline double getMaxHeight(double theLen[6])
992 double aHeight = std::max(theLen[0],theLen[1]);
993 aHeight = std::max(aHeight,theLen[2]);
994 aHeight = std::max(aHeight,theLen[3]);
995 aHeight = std::max(aHeight,theLen[4]);
996 aHeight = std::max(aHeight,theLen[5]);
1002 double AspectRatio3D::GetValue( long theId )
1005 myCurrElement = myMesh->FindElement( theId );
1006 if ( myCurrElement && myCurrElement->GetVtkType() == VTK_TETRA )
1008 // Action from CoTech | ACTION 31.3:
1009 // EURIWARE BO: Homogenize the formulas used to calculate the Controls in SMESH to fit with
1010 // those of ParaView. The library used by ParaView for those calculations can be reused in SMESH.
1011 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myCurrElement->getMeshId()]->getGrid();
1012 if ( vtkCell* avtkCell = grid->GetCell( myCurrElement->getVtkId() ))
1013 aVal = Round( vtkMeshQuality::TetAspectRatio( avtkCell ));
1018 if ( GetPoints( myCurrElement, P ))
1019 aVal = Round( GetValue( P ));
1024 double AspectRatio3D::GetValue( const TSequenceOfXYZ& P )
1026 double aQuality = 0.0;
1027 if(myCurrElement->IsPoly()) return aQuality;
1029 int nbNodes = P.size();
1031 if(myCurrElement->IsQuadratic()) {
1032 if(nbNodes==10) nbNodes=4; // quadratic tetrahedron
1033 else if(nbNodes==13) nbNodes=5; // quadratic pyramid
1034 else if(nbNodes==15) nbNodes=6; // quadratic pentahedron
1035 else if(nbNodes==20) nbNodes=8; // quadratic hexahedron
1036 else if(nbNodes==27) nbNodes=8; // quadratic hexahedron
1037 else return aQuality;
1043 getDistance(P( 1 ),P( 2 )), // a
1044 getDistance(P( 2 ),P( 3 )), // b
1045 getDistance(P( 3 ),P( 1 )), // c
1046 getDistance(P( 2 ),P( 4 )), // d
1047 getDistance(P( 3 ),P( 4 )), // e
1048 getDistance(P( 1 ),P( 4 )) // f
1050 double aTria[4][3] = {
1051 {aLen[0],aLen[1],aLen[2]}, // abc
1052 {aLen[0],aLen[3],aLen[5]}, // adf
1053 {aLen[1],aLen[3],aLen[4]}, // bde
1054 {aLen[2],aLen[4],aLen[5]} // cef
1056 double aSumArea = 0.0;
1057 double aHalfPerimeter = getHalfPerimeter(aTria[0]);
1058 double anArea = getArea(aHalfPerimeter,aTria[0]);
1060 aHalfPerimeter = getHalfPerimeter(aTria[1]);
1061 anArea = getArea(aHalfPerimeter,aTria[1]);
1063 aHalfPerimeter = getHalfPerimeter(aTria[2]);
1064 anArea = getArea(aHalfPerimeter,aTria[2]);
1066 aHalfPerimeter = getHalfPerimeter(aTria[3]);
1067 anArea = getArea(aHalfPerimeter,aTria[3]);
1069 double aVolume = getVolume(P);
1070 //double aVolume = getVolume(aLen);
1071 double aHeight = getMaxHeight(aLen);
1072 static double aCoeff = sqrt(2.0)/12.0;
1073 if ( aVolume > DBL_MIN )
1074 aQuality = aCoeff*aHeight*aSumArea/aVolume;
1079 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 3 ),P( 5 )};
1080 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1083 gp_XYZ aXYZ[4] = {P( 1 ),P( 3 ),P( 4 ),P( 5 )};
1084 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1087 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 5 )};
1088 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1091 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 4 ),P( 5 )};
1092 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1098 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 6 )};
1099 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1102 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 3 )};
1103 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1106 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 6 )};
1107 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1110 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
1111 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1114 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 6 )};
1115 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1118 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 3 )};
1119 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1125 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
1126 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1129 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 4 )};
1130 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1133 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 7 )};
1134 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1137 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 8 )};
1138 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1141 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 3 )};
1142 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1145 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 4 )};
1146 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1149 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 7 )};
1150 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1153 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 8 )};
1154 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1157 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 3 )};
1158 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1161 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 4 )};
1162 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1165 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 7 )};
1166 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1169 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 8 )};
1170 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1173 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 1 )};
1174 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1177 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 2 )};
1178 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1181 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 5 )};
1182 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1185 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 6 )};
1186 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1189 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 1 )};
1190 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1193 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 2 )};
1194 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1197 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 5 )};
1198 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1201 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 6 )};
1202 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1205 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 1 )};
1206 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1209 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
1210 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1213 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 5 )};
1214 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1217 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 6 )};
1218 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1221 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
1222 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1225 gp_XYZ aXYZ[4] = {P( 4 ),P( 5 ),P( 8 ),P( 2 )};
1226 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1229 gp_XYZ aXYZ[4] = {P( 1 ),P( 4 ),P( 5 ),P( 3 )};
1230 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1233 gp_XYZ aXYZ[4] = {P( 3 ),P( 6 ),P( 7 ),P( 1 )};
1234 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1237 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 6 ),P( 4 )};
1238 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1241 gp_XYZ aXYZ[4] = {P( 5 ),P( 6 ),P( 8 ),P( 3 )};
1242 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1245 gp_XYZ aXYZ[4] = {P( 7 ),P( 8 ),P( 6 ),P( 1 )};
1246 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1249 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 7 )};
1250 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1253 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 2 ),P( 5 )};
1254 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1260 gp_XYZ aXYZ[8] = {P( 1 ),P( 2 ),P( 4 ),P( 5 ),P( 7 ),P( 8 ),P( 10 ),P( 11 )};
1261 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[8])),aQuality);
1264 gp_XYZ aXYZ[8] = {P( 2 ),P( 3 ),P( 5 ),P( 6 ),P( 8 ),P( 9 ),P( 11 ),P( 12 )};
1265 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[8])),aQuality);
1268 gp_XYZ aXYZ[8] = {P( 3 ),P( 4 ),P( 6 ),P( 1 ),P( 9 ),P( 10 ),P( 12 ),P( 7 )};
1269 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[8])),aQuality);
1272 } // switch(nbNodes)
1274 if ( nbNodes > 4 ) {
1275 // avaluate aspect ratio of quadranle faces
1276 AspectRatio aspect2D;
1277 SMDS_VolumeTool::VolumeType type = SMDS_VolumeTool::GetType( nbNodes );
1278 int nbFaces = SMDS_VolumeTool::NbFaces( type );
1279 TSequenceOfXYZ points(4);
1280 for ( int i = 0; i < nbFaces; ++i ) { // loop on faces of a volume
1281 if ( SMDS_VolumeTool::NbFaceNodes( type, i ) != 4 )
1283 const int* pInd = SMDS_VolumeTool::GetFaceNodesIndices( type, i, true );
1284 for ( int p = 0; p < 4; ++p ) // loop on nodes of a quadranle face
1285 points( p + 1 ) = P( pInd[ p ] + 1 );
1286 aQuality = std::max( aQuality, aspect2D.GetValue( points ));
1292 double AspectRatio3D::GetBadRate( double Value, int /*nbNodes*/ ) const
1294 // the aspect ratio is in the range [1.0,infinity]
1297 return Value / 1000.;
1300 SMDSAbs_ElementType AspectRatio3D::GetType() const
1302 return SMDSAbs_Volume;
1306 //================================================================================
1309 Description : Functor for calculating warping
1311 //================================================================================
1313 double Warping::GetValue( const TSequenceOfXYZ& P )
1315 if ( P.size() != 4 )
1318 gp_XYZ G = ( P( 1 ) + P( 2 ) + P( 3 ) + P( 4 ) ) / 4.;
1320 double A1 = ComputeA( P( 1 ), P( 2 ), P( 3 ), G );
1321 double A2 = ComputeA( P( 2 ), P( 3 ), P( 4 ), G );
1322 double A3 = ComputeA( P( 3 ), P( 4 ), P( 1 ), G );
1323 double A4 = ComputeA( P( 4 ), P( 1 ), P( 2 ), G );
1325 double val = Max( Max( A1, A2 ), Max( A3, A4 ) );
1327 const double eps = 0.1; // val is in degrees
1329 return val < eps ? 0. : val;
1332 double Warping::ComputeA( const gp_XYZ& thePnt1,
1333 const gp_XYZ& thePnt2,
1334 const gp_XYZ& thePnt3,
1335 const gp_XYZ& theG ) const
1337 double aLen1 = gp_Pnt( thePnt1 ).Distance( gp_Pnt( thePnt2 ) );
1338 double aLen2 = gp_Pnt( thePnt2 ).Distance( gp_Pnt( thePnt3 ) );
1339 double L = Min( aLen1, aLen2 ) * 0.5;
1343 gp_XYZ GI = ( thePnt2 + thePnt1 ) / 2. - theG;
1344 gp_XYZ GJ = ( thePnt3 + thePnt2 ) / 2. - theG;
1345 gp_XYZ N = GI.Crossed( GJ );
1347 if ( N.Modulus() < gp::Resolution() )
1352 double H = ( thePnt2 - theG ).Dot( N );
1353 return asin( fabs( H / L ) ) * 180. / M_PI;
1356 double Warping::GetBadRate( double Value, int /*nbNodes*/ ) const
1358 // the warp is in the range [0.0,PI/2]
1359 // 0.0 = good (no warp)
1360 // PI/2 = bad (face pliee)
1364 SMDSAbs_ElementType Warping::GetType() const
1366 return SMDSAbs_Face;
1370 //================================================================================
1373 Description : Functor for calculating taper
1375 //================================================================================
1377 double Taper::GetValue( const TSequenceOfXYZ& P )
1379 if ( P.size() != 4 )
1383 double J1 = getArea( P( 4 ), P( 1 ), P( 2 ) );
1384 double J2 = getArea( P( 3 ), P( 1 ), P( 2 ) );
1385 double J3 = getArea( P( 2 ), P( 3 ), P( 4 ) );
1386 double J4 = getArea( P( 3 ), P( 4 ), P( 1 ) );
1388 double JA = 0.25 * ( J1 + J2 + J3 + J4 );
1392 double T1 = fabs( ( J1 - JA ) / JA );
1393 double T2 = fabs( ( J2 - JA ) / JA );
1394 double T3 = fabs( ( J3 - JA ) / JA );
1395 double T4 = fabs( ( J4 - JA ) / JA );
1397 double val = Max( Max( T1, T2 ), Max( T3, T4 ) );
1399 const double eps = 0.01;
1401 return val < eps ? 0. : val;
1404 double Taper::GetBadRate( double Value, int /*nbNodes*/ ) const
1406 // the taper is in the range [0.0,1.0]
1407 // 0.0 = good (no taper)
1408 // 1.0 = bad (les cotes opposes sont allignes)
1412 SMDSAbs_ElementType Taper::GetType() const
1414 return SMDSAbs_Face;
1417 //================================================================================
1420 Description : Functor for calculating skew in degrees
1422 //================================================================================
1424 static inline double skewAngle( const gp_XYZ& p1, const gp_XYZ& p2, const gp_XYZ& p3 )
1426 gp_XYZ p12 = ( p2 + p1 ) / 2.;
1427 gp_XYZ p23 = ( p3 + p2 ) / 2.;
1428 gp_XYZ p31 = ( p3 + p1 ) / 2.;
1430 gp_Vec v1( p31 - p2 ), v2( p12 - p23 );
1432 return v1.Magnitude() < gp::Resolution() || v2.Magnitude() < gp::Resolution() ? 0. : v1.Angle( v2 );
1435 double Skew::GetValue( const TSequenceOfXYZ& P )
1437 if ( P.size() != 3 && P.size() != 4 )
1441 const double PI2 = M_PI / 2.;
1442 if ( P.size() == 3 )
1444 double A0 = fabs( PI2 - skewAngle( P( 3 ), P( 1 ), P( 2 ) ) );
1445 double A1 = fabs( PI2 - skewAngle( P( 1 ), P( 2 ), P( 3 ) ) );
1446 double A2 = fabs( PI2 - skewAngle( P( 2 ), P( 3 ), P( 1 ) ) );
1448 return Max( A0, Max( A1, A2 ) ) * 180. / M_PI;
1452 gp_XYZ p12 = ( P( 1 ) + P( 2 ) ) / 2.;
1453 gp_XYZ p23 = ( P( 2 ) + P( 3 ) ) / 2.;
1454 gp_XYZ p34 = ( P( 3 ) + P( 4 ) ) / 2.;
1455 gp_XYZ p41 = ( P( 4 ) + P( 1 ) ) / 2.;
1457 gp_Vec v1( p34 - p12 ), v2( p23 - p41 );
1458 double A = v1.Magnitude() <= gp::Resolution() || v2.Magnitude() <= gp::Resolution()
1459 ? 0. : fabs( PI2 - v1.Angle( v2 ) );
1461 double val = A * 180. / M_PI;
1463 const double eps = 0.1; // val is in degrees
1465 return val < eps ? 0. : val;
1469 double Skew::GetBadRate( double Value, int /*nbNodes*/ ) const
1471 // the skew is in the range [0.0,PI/2].
1477 SMDSAbs_ElementType Skew::GetType() const
1479 return SMDSAbs_Face;
1483 //================================================================================
1486 Description : Functor for calculating area
1488 //================================================================================
1490 double Area::GetValue( const TSequenceOfXYZ& P )
1495 gp_Vec aVec1( P(2) - P(1) );
1496 gp_Vec aVec2( P(3) - P(1) );
1497 gp_Vec SumVec = aVec1 ^ aVec2;
1499 for (size_t i=4; i<=P.size(); i++)
1501 gp_Vec aVec1( P(i-1) - P(1) );
1502 gp_Vec aVec2( P(i ) - P(1) );
1503 gp_Vec tmp = aVec1 ^ aVec2;
1506 val = SumVec.Magnitude() * 0.5;
1511 double Area::GetBadRate( double Value, int /*nbNodes*/ ) const
1513 // meaningless as it is not a quality control functor
1517 SMDSAbs_ElementType Area::GetType() const
1519 return SMDSAbs_Face;
1522 //================================================================================
1525 Description : Functor for calculating length of edge
1527 //================================================================================
1529 double Length::GetValue( const TSequenceOfXYZ& P )
1531 switch ( P.size() ) {
1532 case 2: return getDistance( P( 1 ), P( 2 ) );
1533 case 3: return getDistance( P( 1 ), P( 2 ) ) + getDistance( P( 2 ), P( 3 ) );
1538 double Length::GetBadRate( double Value, int /*nbNodes*/ ) const
1540 // meaningless as it is not quality control functor
1544 SMDSAbs_ElementType Length::GetType() const
1546 return SMDSAbs_Edge;
1549 //================================================================================
1552 Description : Functor for calculating minimal length of edge
1554 //================================================================================
1556 double Length2D::GetValue( long theElementId )
1560 if ( GetPoints( theElementId, P ))
1564 SMDSAbs_EntityType aType = P.getElementEntity();
1567 case SMDSEntity_Edge:
1569 aVal = getDistance( P( 1 ), P( 2 ) );
1571 case SMDSEntity_Quad_Edge:
1572 if (len == 3) // quadratic edge
1573 aVal = getDistance(P( 1 ),P( 3 )) + getDistance(P( 3 ),P( 2 ));
1575 case SMDSEntity_Triangle:
1576 if (len == 3){ // triangles
1577 double L1 = getDistance(P( 1 ),P( 2 ));
1578 double L2 = getDistance(P( 2 ),P( 3 ));
1579 double L3 = getDistance(P( 3 ),P( 1 ));
1580 aVal = Min(L1,Min(L2,L3));
1583 case SMDSEntity_Quadrangle:
1584 if (len == 4){ // quadrangles
1585 double L1 = getDistance(P( 1 ),P( 2 ));
1586 double L2 = getDistance(P( 2 ),P( 3 ));
1587 double L3 = getDistance(P( 3 ),P( 4 ));
1588 double L4 = getDistance(P( 4 ),P( 1 ));
1589 aVal = Min(Min(L1,L2),Min(L3,L4));
1592 case SMDSEntity_Quad_Triangle:
1593 case SMDSEntity_BiQuad_Triangle:
1594 if (len >= 6){ // quadratic triangles
1595 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1596 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1597 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 1 ));
1598 aVal = Min(L1,Min(L2,L3));
1601 case SMDSEntity_Quad_Quadrangle:
1602 case SMDSEntity_BiQuad_Quadrangle:
1603 if (len >= 8){ // quadratic quadrangles
1604 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1605 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1606 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 7 ));
1607 double L4 = getDistance(P( 7 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
1608 aVal = Min(Min(L1,L2),Min(L3,L4));
1611 case SMDSEntity_Tetra:
1612 if (len == 4){ // tetrahedra
1613 double L1 = getDistance(P( 1 ),P( 2 ));
1614 double L2 = getDistance(P( 2 ),P( 3 ));
1615 double L3 = getDistance(P( 3 ),P( 1 ));
1616 double L4 = getDistance(P( 1 ),P( 4 ));
1617 double L5 = getDistance(P( 2 ),P( 4 ));
1618 double L6 = getDistance(P( 3 ),P( 4 ));
1619 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1622 case SMDSEntity_Pyramid:
1623 if (len == 5){ // pyramid
1624 double L1 = getDistance(P( 1 ),P( 2 ));
1625 double L2 = getDistance(P( 2 ),P( 3 ));
1626 double L3 = getDistance(P( 3 ),P( 4 ));
1627 double L4 = getDistance(P( 4 ),P( 1 ));
1628 double L5 = getDistance(P( 1 ),P( 5 ));
1629 double L6 = getDistance(P( 2 ),P( 5 ));
1630 double L7 = getDistance(P( 3 ),P( 5 ));
1631 double L8 = getDistance(P( 4 ),P( 5 ));
1633 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1634 aVal = Min(aVal,Min(L7,L8));
1637 case SMDSEntity_Penta:
1638 if (len == 6) { // pentahedron
1639 double L1 = getDistance(P( 1 ),P( 2 ));
1640 double L2 = getDistance(P( 2 ),P( 3 ));
1641 double L3 = getDistance(P( 3 ),P( 1 ));
1642 double L4 = getDistance(P( 4 ),P( 5 ));
1643 double L5 = getDistance(P( 5 ),P( 6 ));
1644 double L6 = getDistance(P( 6 ),P( 4 ));
1645 double L7 = getDistance(P( 1 ),P( 4 ));
1646 double L8 = getDistance(P( 2 ),P( 5 ));
1647 double L9 = getDistance(P( 3 ),P( 6 ));
1649 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1650 aVal = Min(aVal,Min(Min(L7,L8),L9));
1653 case SMDSEntity_Hexa:
1654 if (len == 8){ // hexahedron
1655 double L1 = getDistance(P( 1 ),P( 2 ));
1656 double L2 = getDistance(P( 2 ),P( 3 ));
1657 double L3 = getDistance(P( 3 ),P( 4 ));
1658 double L4 = getDistance(P( 4 ),P( 1 ));
1659 double L5 = getDistance(P( 5 ),P( 6 ));
1660 double L6 = getDistance(P( 6 ),P( 7 ));
1661 double L7 = getDistance(P( 7 ),P( 8 ));
1662 double L8 = getDistance(P( 8 ),P( 5 ));
1663 double L9 = getDistance(P( 1 ),P( 5 ));
1664 double L10= getDistance(P( 2 ),P( 6 ));
1665 double L11= getDistance(P( 3 ),P( 7 ));
1666 double L12= getDistance(P( 4 ),P( 8 ));
1668 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1669 aVal = Min(aVal,Min(Min(L7,L8),Min(L9,L10)));
1670 aVal = Min(aVal,Min(L11,L12));
1673 case SMDSEntity_Quad_Tetra:
1674 if (len == 10){ // quadratic tetrahedron
1675 double L1 = getDistance(P( 1 ),P( 5 )) + getDistance(P( 5 ),P( 2 ));
1676 double L2 = getDistance(P( 2 ),P( 6 )) + getDistance(P( 6 ),P( 3 ));
1677 double L3 = getDistance(P( 3 ),P( 7 )) + getDistance(P( 7 ),P( 1 ));
1678 double L4 = getDistance(P( 1 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
1679 double L5 = getDistance(P( 2 ),P( 9 )) + getDistance(P( 9 ),P( 4 ));
1680 double L6 = getDistance(P( 3 ),P( 10 )) + getDistance(P( 10 ),P( 4 ));
1681 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1684 case SMDSEntity_Quad_Pyramid:
1685 if (len == 13){ // quadratic pyramid
1686 double L1 = getDistance(P( 1 ),P( 6 )) + getDistance(P( 6 ),P( 2 ));
1687 double L2 = getDistance(P( 2 ),P( 7 )) + getDistance(P( 7 ),P( 3 ));
1688 double L3 = getDistance(P( 3 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
1689 double L4 = getDistance(P( 4 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1690 double L5 = getDistance(P( 1 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1691 double L6 = getDistance(P( 2 ),P( 11 )) + getDistance(P( 11 ),P( 5 ));
1692 double L7 = getDistance(P( 3 ),P( 12 )) + getDistance(P( 12 ),P( 5 ));
1693 double L8 = getDistance(P( 4 ),P( 13 )) + getDistance(P( 13 ),P( 5 ));
1694 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1695 aVal = Min(aVal,Min(L7,L8));
1698 case SMDSEntity_Quad_Penta:
1699 case SMDSEntity_BiQuad_Penta:
1700 if (len >= 15){ // quadratic pentahedron
1701 double L1 = getDistance(P( 1 ),P( 7 )) + getDistance(P( 7 ),P( 2 ));
1702 double L2 = getDistance(P( 2 ),P( 8 )) + getDistance(P( 8 ),P( 3 ));
1703 double L3 = getDistance(P( 3 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1704 double L4 = getDistance(P( 4 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1705 double L5 = getDistance(P( 5 ),P( 11 )) + getDistance(P( 11 ),P( 6 ));
1706 double L6 = getDistance(P( 6 ),P( 12 )) + getDistance(P( 12 ),P( 4 ));
1707 double L7 = getDistance(P( 1 ),P( 13 )) + getDistance(P( 13 ),P( 4 ));
1708 double L8 = getDistance(P( 2 ),P( 14 )) + getDistance(P( 14 ),P( 5 ));
1709 double L9 = getDistance(P( 3 ),P( 15 )) + getDistance(P( 15 ),P( 6 ));
1710 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1711 aVal = Min(aVal,Min(Min(L7,L8),L9));
1714 case SMDSEntity_Quad_Hexa:
1715 case SMDSEntity_TriQuad_Hexa:
1716 if (len >= 20) { // quadratic hexahedron
1717 double L1 = getDistance(P( 1 ),P( 9 )) + getDistance(P( 9 ),P( 2 ));
1718 double L2 = getDistance(P( 2 ),P( 10 )) + getDistance(P( 10 ),P( 3 ));
1719 double L3 = getDistance(P( 3 ),P( 11 )) + getDistance(P( 11 ),P( 4 ));
1720 double L4 = getDistance(P( 4 ),P( 12 )) + getDistance(P( 12 ),P( 1 ));
1721 double L5 = getDistance(P( 5 ),P( 13 )) + getDistance(P( 13 ),P( 6 ));
1722 double L6 = getDistance(P( 6 ),P( 14 )) + getDistance(P( 14 ),P( 7 ));
1723 double L7 = getDistance(P( 7 ),P( 15 )) + getDistance(P( 15 ),P( 8 ));
1724 double L8 = getDistance(P( 8 ),P( 16 )) + getDistance(P( 16 ),P( 5 ));
1725 double L9 = getDistance(P( 1 ),P( 17 )) + getDistance(P( 17 ),P( 5 ));
1726 double L10= getDistance(P( 2 ),P( 18 )) + getDistance(P( 18 ),P( 6 ));
1727 double L11= getDistance(P( 3 ),P( 19 )) + getDistance(P( 19 ),P( 7 ));
1728 double L12= getDistance(P( 4 ),P( 20 )) + getDistance(P( 20 ),P( 8 ));
1729 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1730 aVal = Min(aVal,Min(Min(L7,L8),Min(L9,L10)));
1731 aVal = Min(aVal,Min(L11,L12));
1734 case SMDSEntity_Polygon:
1736 aVal = getDistance( P(1), P( P.size() ));
1737 for ( size_t i = 1; i < P.size(); ++i )
1738 aVal = Min( aVal, getDistance( P( i ), P( i+1 )));
1741 case SMDSEntity_Quad_Polygon:
1743 aVal = getDistance( P(1), P( P.size() )) + getDistance( P(P.size()), P( P.size()-1 ));
1744 for ( size_t i = 1; i < P.size()-1; i += 2 )
1745 aVal = Min( aVal, getDistance( P( i ), P( i+1 )) + getDistance( P( i+1 ), P( i+2 )));
1748 case SMDSEntity_Hexagonal_Prism:
1749 if (len == 12) { // hexagonal prism
1750 double L1 = getDistance(P( 1 ),P( 2 ));
1751 double L2 = getDistance(P( 2 ),P( 3 ));
1752 double L3 = getDistance(P( 3 ),P( 4 ));
1753 double L4 = getDistance(P( 4 ),P( 5 ));
1754 double L5 = getDistance(P( 5 ),P( 6 ));
1755 double L6 = getDistance(P( 6 ),P( 1 ));
1757 double L7 = getDistance(P( 7 ), P( 8 ));
1758 double L8 = getDistance(P( 8 ), P( 9 ));
1759 double L9 = getDistance(P( 9 ), P( 10 ));
1760 double L10= getDistance(P( 10 ),P( 11 ));
1761 double L11= getDistance(P( 11 ),P( 12 ));
1762 double L12= getDistance(P( 12 ),P( 7 ));
1764 double L13 = getDistance(P( 1 ),P( 7 ));
1765 double L14 = getDistance(P( 2 ),P( 8 ));
1766 double L15 = getDistance(P( 3 ),P( 9 ));
1767 double L16 = getDistance(P( 4 ),P( 10 ));
1768 double L17 = getDistance(P( 5 ),P( 11 ));
1769 double L18 = getDistance(P( 6 ),P( 12 ));
1770 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1771 aVal = Min(aVal, Min(Min(Min(L7,L8),Min(L9,L10)),Min(L11,L12)));
1772 aVal = Min(aVal, Min(Min(Min(L13,L14),Min(L15,L16)),Min(L17,L18)));
1775 case SMDSEntity_Polyhedra:
1787 if ( myPrecision >= 0 )
1789 double prec = pow( 10., (double)( myPrecision ) );
1790 aVal = floor( aVal * prec + 0.5 ) / prec;
1799 double Length2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1801 // meaningless as it is not a quality control functor
1805 SMDSAbs_ElementType Length2D::GetType() const
1807 return SMDSAbs_Face;
1810 Length2D::Value::Value(double theLength,long thePntId1, long thePntId2):
1813 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1814 if(thePntId1 > thePntId2){
1815 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1819 bool Length2D::Value::operator<(const Length2D::Value& x) const
1821 if(myPntId[0] < x.myPntId[0]) return true;
1822 if(myPntId[0] == x.myPntId[0])
1823 if(myPntId[1] < x.myPntId[1]) return true;
1827 void Length2D::GetValues(TValues& theValues)
1830 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1831 for(; anIter->more(); ){
1832 const SMDS_MeshFace* anElem = anIter->next();
1834 if(anElem->IsQuadratic()) {
1835 const SMDS_VtkFace* F =
1836 dynamic_cast<const SMDS_VtkFace*>(anElem);
1837 // use special nodes iterator
1838 SMDS_ElemIteratorPtr anIter = F->interlacedNodesElemIterator();
1839 long aNodeId[4] = { 0,0,0,0 };
1843 const SMDS_MeshElement* aNode;
1845 aNode = anIter->next();
1846 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1847 P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1848 aNodeId[0] = aNodeId[1] = aNode->GetID();
1851 for(; anIter->more(); ){
1852 const SMDS_MeshNode* N1 = static_cast<const SMDS_MeshNode*> (anIter->next());
1853 P[2] = gp_Pnt(N1->X(),N1->Y(),N1->Z());
1854 aNodeId[2] = N1->GetID();
1855 aLength = P[1].Distance(P[2]);
1856 if(!anIter->more()) break;
1857 const SMDS_MeshNode* N2 = static_cast<const SMDS_MeshNode*> (anIter->next());
1858 P[3] = gp_Pnt(N2->X(),N2->Y(),N2->Z());
1859 aNodeId[3] = N2->GetID();
1860 aLength += P[2].Distance(P[3]);
1861 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1862 Value aValue2(aLength,aNodeId[2],aNodeId[3]);
1864 aNodeId[1] = aNodeId[3];
1865 theValues.insert(aValue1);
1866 theValues.insert(aValue2);
1868 aLength += P[2].Distance(P[0]);
1869 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1870 Value aValue2(aLength,aNodeId[2],aNodeId[0]);
1871 theValues.insert(aValue1);
1872 theValues.insert(aValue2);
1875 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
1876 long aNodeId[2] = {0,0};
1880 const SMDS_MeshElement* aNode;
1881 if(aNodesIter->more()){
1882 aNode = aNodesIter->next();
1883 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1884 P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1885 aNodeId[0] = aNodeId[1] = aNode->GetID();
1888 for(; aNodesIter->more(); ){
1889 aNode = aNodesIter->next();
1890 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1891 long anId = aNode->GetID();
1893 P[2] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1895 aLength = P[1].Distance(P[2]);
1897 Value aValue(aLength,aNodeId[1],anId);
1900 theValues.insert(aValue);
1903 aLength = P[0].Distance(P[1]);
1905 Value aValue(aLength,aNodeId[0],aNodeId[1]);
1906 theValues.insert(aValue);
1911 //================================================================================
1913 Class : MultiConnection
1914 Description : Functor for calculating number of faces conneted to the edge
1916 //================================================================================
1918 double MultiConnection::GetValue( const TSequenceOfXYZ& P )
1922 double MultiConnection::GetValue( long theId )
1924 return getNbMultiConnection( myMesh, theId );
1927 double MultiConnection::GetBadRate( double Value, int /*nbNodes*/ ) const
1929 // meaningless as it is not quality control functor
1933 SMDSAbs_ElementType MultiConnection::GetType() const
1935 return SMDSAbs_Edge;
1938 //================================================================================
1940 Class : MultiConnection2D
1941 Description : Functor for calculating number of faces conneted to the edge
1943 //================================================================================
1945 double MultiConnection2D::GetValue( const TSequenceOfXYZ& P )
1950 double MultiConnection2D::GetValue( long theElementId )
1954 const SMDS_MeshElement* aFaceElem = myMesh->FindElement(theElementId);
1955 SMDSAbs_ElementType aType = aFaceElem->GetType();
1960 int i = 0, len = aFaceElem->NbNodes();
1961 SMDS_ElemIteratorPtr anIter = aFaceElem->nodesIterator();
1964 const SMDS_MeshNode *aNode, *aNode0 = 0;
1965 TColStd_MapOfInteger aMap, aMapPrev;
1967 for (i = 0; i <= len; i++) {
1972 if (anIter->more()) {
1973 aNode = (SMDS_MeshNode*)anIter->next();
1981 if (i == 0) aNode0 = aNode;
1983 SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator();
1984 while (anElemIter->more()) {
1985 const SMDS_MeshElement* anElem = anElemIter->next();
1986 if (anElem != 0 && anElem->GetType() == SMDSAbs_Face) {
1987 int anId = anElem->GetID();
1990 if (aMapPrev.Contains(anId)) {
1995 aResult = Max(aResult, aNb);
2006 double MultiConnection2D::GetBadRate( double Value, int /*nbNodes*/ ) const
2008 // meaningless as it is not quality control functor
2012 SMDSAbs_ElementType MultiConnection2D::GetType() const
2014 return SMDSAbs_Face;
2017 MultiConnection2D::Value::Value(long thePntId1, long thePntId2)
2019 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
2020 if(thePntId1 > thePntId2){
2021 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
2025 bool MultiConnection2D::Value::operator<(const MultiConnection2D::Value& x) const
2027 if(myPntId[0] < x.myPntId[0]) return true;
2028 if(myPntId[0] == x.myPntId[0])
2029 if(myPntId[1] < x.myPntId[1]) return true;
2033 void MultiConnection2D::GetValues(MValues& theValues)
2035 if ( !myMesh ) return;
2036 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
2037 for(; anIter->more(); ){
2038 const SMDS_MeshFace* anElem = anIter->next();
2039 SMDS_ElemIteratorPtr aNodesIter;
2040 if ( anElem->IsQuadratic() )
2041 aNodesIter = dynamic_cast<const SMDS_VtkFace*>
2042 (anElem)->interlacedNodesElemIterator();
2044 aNodesIter = anElem->nodesIterator();
2045 long aNodeId[3] = {0,0,0};
2047 //int aNbConnects=0;
2048 const SMDS_MeshNode* aNode0;
2049 const SMDS_MeshNode* aNode1;
2050 const SMDS_MeshNode* aNode2;
2051 if(aNodesIter->more()){
2052 aNode0 = (SMDS_MeshNode*) aNodesIter->next();
2054 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode1;
2055 aNodeId[0] = aNodeId[1] = aNodes->GetID();
2057 for(; aNodesIter->more(); ) {
2058 aNode2 = (SMDS_MeshNode*) aNodesIter->next();
2059 long anId = aNode2->GetID();
2062 Value aValue(aNodeId[1],aNodeId[2]);
2063 MValues::iterator aItr = theValues.find(aValue);
2064 if (aItr != theValues.end()){
2069 theValues[aValue] = 1;
2072 //cout << "NodeIds: "<<aNodeId[1]<<","<<aNodeId[2]<<" nbconn="<<aNbConnects<<endl;
2073 aNodeId[1] = aNodeId[2];
2076 Value aValue(aNodeId[0],aNodeId[2]);
2077 MValues::iterator aItr = theValues.find(aValue);
2078 if (aItr != theValues.end()) {
2083 theValues[aValue] = 1;
2086 //cout << "NodeIds: "<<aNodeId[0]<<","<<aNodeId[2]<<" nbconn="<<aNbConnects<<endl;
2091 //================================================================================
2093 Class : BallDiameter
2094 Description : Functor returning diameter of a ball element
2096 //================================================================================
2098 double BallDiameter::GetValue( long theId )
2100 double diameter = 0;
2102 if ( const SMDS_BallElement* ball =
2103 dynamic_cast<const SMDS_BallElement*>( myMesh->FindElement( theId )))
2105 diameter = ball->GetDiameter();
2110 double BallDiameter::GetBadRate( double Value, int /*nbNodes*/ ) const
2112 // meaningless as it is not a quality control functor
2116 SMDSAbs_ElementType BallDiameter::GetType() const
2118 return SMDSAbs_Ball;
2121 //================================================================================
2123 Class : NodeConnectivityNumber
2124 Description : Functor returning number of elements connected to a node
2126 //================================================================================
2128 double NodeConnectivityNumber::GetValue( long theId )
2132 if ( const SMDS_MeshNode* node = myMesh->FindNode( theId ))
2134 SMDSAbs_ElementType type;
2135 if ( myMesh->NbVolumes() > 0 )
2136 type = SMDSAbs_Volume;
2137 else if ( myMesh->NbFaces() > 0 )
2138 type = SMDSAbs_Face;
2139 else if ( myMesh->NbEdges() > 0 )
2140 type = SMDSAbs_Edge;
2143 nb = node->NbInverseElements( type );
2148 double NodeConnectivityNumber::GetBadRate( double Value, int /*nbNodes*/ ) const
2153 SMDSAbs_ElementType NodeConnectivityNumber::GetType() const
2155 return SMDSAbs_Node;
2162 //================================================================================
2164 Class : BadOrientedVolume
2165 Description : Predicate bad oriented volumes
2167 //================================================================================
2169 BadOrientedVolume::BadOrientedVolume()
2174 void BadOrientedVolume::SetMesh( const SMDS_Mesh* theMesh )
2179 bool BadOrientedVolume::IsSatisfy( long theId )
2184 SMDS_VolumeTool vTool( myMesh->FindElement( theId ));
2185 return !vTool.IsForward();
2188 SMDSAbs_ElementType BadOrientedVolume::GetType() const
2190 return SMDSAbs_Volume;
2194 Class : BareBorderVolume
2197 bool BareBorderVolume::IsSatisfy(long theElementId )
2199 SMDS_VolumeTool myTool;
2200 if ( myTool.Set( myMesh->FindElement(theElementId)))
2202 for ( int iF = 0; iF < myTool.NbFaces(); ++iF )
2203 if ( myTool.IsFreeFace( iF ))
2205 const SMDS_MeshNode** n = myTool.GetFaceNodes(iF);
2206 std::vector< const SMDS_MeshNode*> nodes( n, n+myTool.NbFaceNodes(iF));
2207 if ( !myMesh->FindElement( nodes, SMDSAbs_Face, /*Nomedium=*/false))
2214 //================================================================================
2216 Class : BareBorderFace
2218 //================================================================================
2220 bool BareBorderFace::IsSatisfy(long theElementId )
2223 if ( const SMDS_MeshElement* face = myMesh->FindElement(theElementId))
2225 if ( face->GetType() == SMDSAbs_Face )
2227 int nbN = face->NbCornerNodes();
2228 for ( int i = 0; i < nbN && !ok; ++i )
2230 // check if a link is shared by another face
2231 const SMDS_MeshNode* n1 = face->GetNode( i );
2232 const SMDS_MeshNode* n2 = face->GetNode( (i+1)%nbN );
2233 SMDS_ElemIteratorPtr fIt = n1->GetInverseElementIterator( SMDSAbs_Face );
2234 bool isShared = false;
2235 while ( !isShared && fIt->more() )
2237 const SMDS_MeshElement* f = fIt->next();
2238 isShared = ( f != face && f->GetNodeIndex(n2) != -1 );
2242 const int iQuad = face->IsQuadratic();
2243 myLinkNodes.resize( 2 + iQuad);
2244 myLinkNodes[0] = n1;
2245 myLinkNodes[1] = n2;
2247 myLinkNodes[2] = face->GetNode( i+nbN );
2248 ok = !myMesh->FindElement( myLinkNodes, SMDSAbs_Edge, /*noMedium=*/false);
2256 //================================================================================
2258 Class : OverConstrainedVolume
2260 //================================================================================
2262 bool OverConstrainedVolume::IsSatisfy(long theElementId )
2264 // An element is over-constrained if it has N-1 free borders where
2265 // N is the number of edges/faces for a 2D/3D element.
2266 SMDS_VolumeTool myTool;
2267 if ( myTool.Set( myMesh->FindElement(theElementId)))
2269 int nbSharedFaces = 0;
2270 for ( int iF = 0; iF < myTool.NbFaces(); ++iF )
2271 if ( !myTool.IsFreeFace( iF ) && ++nbSharedFaces > 1 )
2273 return ( nbSharedFaces == 1 );
2278 //================================================================================
2280 Class : OverConstrainedFace
2282 //================================================================================
2284 bool OverConstrainedFace::IsSatisfy(long theElementId )
2286 // An element is over-constrained if it has N-1 free borders where
2287 // N is the number of edges/faces for a 2D/3D element.
2288 if ( const SMDS_MeshElement* face = myMesh->FindElement(theElementId))
2289 if ( face->GetType() == SMDSAbs_Face )
2291 int nbSharedBorders = 0;
2292 int nbN = face->NbCornerNodes();
2293 for ( int i = 0; i < nbN; ++i )
2295 // check if a link is shared by another face
2296 const SMDS_MeshNode* n1 = face->GetNode( i );
2297 const SMDS_MeshNode* n2 = face->GetNode( (i+1)%nbN );
2298 SMDS_ElemIteratorPtr fIt = n1->GetInverseElementIterator( SMDSAbs_Face );
2299 bool isShared = false;
2300 while ( !isShared && fIt->more() )
2302 const SMDS_MeshElement* f = fIt->next();
2303 isShared = ( f != face && f->GetNodeIndex(n2) != -1 );
2305 if ( isShared && ++nbSharedBorders > 1 )
2308 return ( nbSharedBorders == 1 );
2313 //================================================================================
2315 Class : CoincidentNodes
2316 Description : Predicate of Coincident nodes
2318 //================================================================================
2320 CoincidentNodes::CoincidentNodes()
2325 bool CoincidentNodes::IsSatisfy( long theElementId )
2327 return myCoincidentIDs.Contains( theElementId );
2330 SMDSAbs_ElementType CoincidentNodes::GetType() const
2332 return SMDSAbs_Node;
2335 void CoincidentNodes::SetMesh( const SMDS_Mesh* theMesh )
2337 myMeshModifTracer.SetMesh( theMesh );
2338 if ( myMeshModifTracer.IsMeshModified() )
2340 TIDSortedNodeSet nodesToCheck;
2341 SMDS_NodeIteratorPtr nIt = theMesh->nodesIterator(/*idInceasingOrder=*/true);
2342 while ( nIt->more() )
2343 nodesToCheck.insert( nodesToCheck.end(), nIt->next() );
2345 std::list< std::list< const SMDS_MeshNode*> > nodeGroups;
2346 SMESH_OctreeNode::FindCoincidentNodes ( nodesToCheck, &nodeGroups, myToler );
2348 myCoincidentIDs.Clear();
2349 std::list< std::list< const SMDS_MeshNode*> >::iterator groupIt = nodeGroups.begin();
2350 for ( ; groupIt != nodeGroups.end(); ++groupIt )
2352 std::list< const SMDS_MeshNode*>& coincNodes = *groupIt;
2353 std::list< const SMDS_MeshNode*>::iterator n = coincNodes.begin();
2354 for ( ; n != coincNodes.end(); ++n )
2355 myCoincidentIDs.Add( (*n)->GetID() );
2360 //================================================================================
2362 Class : CoincidentElements
2363 Description : Predicate of Coincident Elements
2364 Note : This class is suitable only for visualization of Coincident Elements
2366 //================================================================================
2368 CoincidentElements::CoincidentElements()
2373 void CoincidentElements::SetMesh( const SMDS_Mesh* theMesh )
2378 bool CoincidentElements::IsSatisfy( long theElementId )
2380 if ( !myMesh ) return false;
2382 if ( const SMDS_MeshElement* e = myMesh->FindElement( theElementId ))
2384 if ( e->GetType() != GetType() ) return false;
2385 std::set< const SMDS_MeshNode* > elemNodes( e->begin_nodes(), e->end_nodes() );
2386 const int nbNodes = e->NbNodes();
2387 SMDS_ElemIteratorPtr invIt = (*elemNodes.begin())->GetInverseElementIterator( GetType() );
2388 while ( invIt->more() )
2390 const SMDS_MeshElement* e2 = invIt->next();
2391 if ( e2 == e || e2->NbNodes() != nbNodes ) continue;
2393 bool sameNodes = true;
2394 for ( size_t i = 0; i < elemNodes.size() && sameNodes; ++i )
2395 sameNodes = ( elemNodes.count( e2->GetNode( i )));
2403 SMDSAbs_ElementType CoincidentElements1D::GetType() const
2405 return SMDSAbs_Edge;
2407 SMDSAbs_ElementType CoincidentElements2D::GetType() const
2409 return SMDSAbs_Face;
2411 SMDSAbs_ElementType CoincidentElements3D::GetType() const
2413 return SMDSAbs_Volume;
2417 //================================================================================
2420 Description : Predicate for free borders
2422 //================================================================================
2424 FreeBorders::FreeBorders()
2429 void FreeBorders::SetMesh( const SMDS_Mesh* theMesh )
2434 bool FreeBorders::IsSatisfy( long theId )
2436 return getNbMultiConnection( myMesh, theId ) == 1;
2439 SMDSAbs_ElementType FreeBorders::GetType() const
2441 return SMDSAbs_Edge;
2445 //================================================================================
2448 Description : Predicate for free Edges
2450 //================================================================================
2452 FreeEdges::FreeEdges()
2457 void FreeEdges::SetMesh( const SMDS_Mesh* theMesh )
2462 bool FreeEdges::IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId )
2464 TColStd_MapOfInteger aMap;
2465 for ( int i = 0; i < 2; i++ )
2467 SMDS_ElemIteratorPtr anElemIter = theNodes[ i ]->GetInverseElementIterator(SMDSAbs_Face);
2468 while( anElemIter->more() )
2470 if ( const SMDS_MeshElement* anElem = anElemIter->next())
2472 const int anId = anElem->GetID();
2473 if ( anId != theFaceId && !aMap.Add( anId ))
2481 bool FreeEdges::IsSatisfy( long theId )
2486 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
2487 if ( aFace == 0 || aFace->GetType() != SMDSAbs_Face || aFace->NbNodes() < 3 )
2490 SMDS_NodeIteratorPtr anIter = aFace->interlacedNodesIterator();
2494 int i = 0, nbNodes = aFace->NbNodes();
2495 std::vector <const SMDS_MeshNode*> aNodes( nbNodes+1 );
2496 while( anIter->more() )
2497 if ( ! ( aNodes[ i++ ] = anIter->next() ))
2499 aNodes[ nbNodes ] = aNodes[ 0 ];
2501 for ( i = 0; i < nbNodes; i++ )
2502 if ( IsFreeEdge( &aNodes[ i ], theId ) )
2508 SMDSAbs_ElementType FreeEdges::GetType() const
2510 return SMDSAbs_Face;
2513 FreeEdges::Border::Border(long theElemId, long thePntId1, long thePntId2):
2516 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
2517 if(thePntId1 > thePntId2){
2518 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
2522 bool FreeEdges::Border::operator<(const FreeEdges::Border& x) const{
2523 if(myPntId[0] < x.myPntId[0]) return true;
2524 if(myPntId[0] == x.myPntId[0])
2525 if(myPntId[1] < x.myPntId[1]) return true;
2529 inline void UpdateBorders(const FreeEdges::Border& theBorder,
2530 FreeEdges::TBorders& theRegistry,
2531 FreeEdges::TBorders& theContainer)
2533 if(theRegistry.find(theBorder) == theRegistry.end()){
2534 theRegistry.insert(theBorder);
2535 theContainer.insert(theBorder);
2537 theContainer.erase(theBorder);
2541 void FreeEdges::GetBoreders(TBorders& theBorders)
2544 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
2545 for(; anIter->more(); ){
2546 const SMDS_MeshFace* anElem = anIter->next();
2547 long anElemId = anElem->GetID();
2548 SMDS_ElemIteratorPtr aNodesIter;
2549 if ( anElem->IsQuadratic() )
2550 aNodesIter = static_cast<const SMDS_VtkFace*>(anElem)->
2551 interlacedNodesElemIterator();
2553 aNodesIter = anElem->nodesIterator();
2554 long aNodeId[2] = {0,0};
2555 const SMDS_MeshElement* aNode;
2556 if(aNodesIter->more()){
2557 aNode = aNodesIter->next();
2558 aNodeId[0] = aNodeId[1] = aNode->GetID();
2560 for(; aNodesIter->more(); ){
2561 aNode = aNodesIter->next();
2562 long anId = aNode->GetID();
2563 Border aBorder(anElemId,aNodeId[1],anId);
2565 UpdateBorders(aBorder,aRegistry,theBorders);
2567 Border aBorder(anElemId,aNodeId[0],aNodeId[1]);
2568 UpdateBorders(aBorder,aRegistry,theBorders);
2572 //================================================================================
2575 Description : Predicate for free nodes
2577 //================================================================================
2579 FreeNodes::FreeNodes()
2584 void FreeNodes::SetMesh( const SMDS_Mesh* theMesh )
2589 bool FreeNodes::IsSatisfy( long theNodeId )
2591 const SMDS_MeshNode* aNode = myMesh->FindNode( theNodeId );
2595 return (aNode->NbInverseElements() < 1);
2598 SMDSAbs_ElementType FreeNodes::GetType() const
2600 return SMDSAbs_Node;
2604 //================================================================================
2607 Description : Predicate for free faces
2609 //================================================================================
2611 FreeFaces::FreeFaces()
2616 void FreeFaces::SetMesh( const SMDS_Mesh* theMesh )
2621 bool FreeFaces::IsSatisfy( long theId )
2623 if (!myMesh) return false;
2624 // check that faces nodes refers to less than two common volumes
2625 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
2626 if ( !aFace || aFace->GetType() != SMDSAbs_Face )
2629 int nbNode = aFace->NbNodes();
2631 // collect volumes to check that number of volumes with count equal nbNode not less than 2
2632 typedef std::map< SMDS_MeshElement*, int > TMapOfVolume; // map of volume counters
2633 typedef std::map< SMDS_MeshElement*, int >::iterator TItrMapOfVolume; // iterator
2634 TMapOfVolume mapOfVol;
2636 SMDS_ElemIteratorPtr nodeItr = aFace->nodesIterator();
2637 while ( nodeItr->more() )
2639 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(nodeItr->next());
2640 if ( !aNode ) continue;
2641 SMDS_ElemIteratorPtr volItr = aNode->GetInverseElementIterator(SMDSAbs_Volume);
2642 while ( volItr->more() )
2644 SMDS_MeshElement* aVol = (SMDS_MeshElement*)volItr->next();
2645 TItrMapOfVolume itr = mapOfVol.insert( std::make_pair( aVol, 0 )).first;
2650 TItrMapOfVolume volItr = mapOfVol.begin();
2651 TItrMapOfVolume volEnd = mapOfVol.end();
2652 for ( ; volItr != volEnd; ++volItr )
2653 if ( (*volItr).second >= nbNode )
2655 // face is not free if number of volumes constructed on their nodes more than one
2659 SMDSAbs_ElementType FreeFaces::GetType() const
2661 return SMDSAbs_Face;
2664 //================================================================================
2666 Class : LinearOrQuadratic
2667 Description : Predicate to verify whether a mesh element is linear
2669 //================================================================================
2671 LinearOrQuadratic::LinearOrQuadratic()
2676 void LinearOrQuadratic::SetMesh( const SMDS_Mesh* theMesh )
2681 bool LinearOrQuadratic::IsSatisfy( long theId )
2683 if (!myMesh) return false;
2684 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2685 if ( !anElem || (myType != SMDSAbs_All && anElem->GetType() != myType) )
2687 return (!anElem->IsQuadratic());
2690 void LinearOrQuadratic::SetType( SMDSAbs_ElementType theType )
2695 SMDSAbs_ElementType LinearOrQuadratic::GetType() const
2700 //================================================================================
2703 Description : Functor for check color of group to which mesh element belongs to
2705 //================================================================================
2707 GroupColor::GroupColor()
2711 bool GroupColor::IsSatisfy( long theId )
2713 return myIDs.count( theId );
2716 void GroupColor::SetType( SMDSAbs_ElementType theType )
2721 SMDSAbs_ElementType GroupColor::GetType() const
2726 static bool isEqual( const Quantity_Color& theColor1,
2727 const Quantity_Color& theColor2 )
2729 // tolerance to compare colors
2730 const double tol = 5*1e-3;
2731 return ( fabs( theColor1.Red() - theColor2.Red() ) < tol &&
2732 fabs( theColor1.Green() - theColor2.Green() ) < tol &&
2733 fabs( theColor1.Blue() - theColor2.Blue() ) < tol );
2736 void GroupColor::SetMesh( const SMDS_Mesh* theMesh )
2740 const SMESHDS_Mesh* aMesh = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
2744 int nbGrp = aMesh->GetNbGroups();
2748 // iterates on groups and find necessary elements ids
2749 const std::set<SMESHDS_GroupBase*>& aGroups = aMesh->GetGroups();
2750 std::set<SMESHDS_GroupBase*>::const_iterator GrIt = aGroups.begin();
2751 for (; GrIt != aGroups.end(); GrIt++)
2753 SMESHDS_GroupBase* aGrp = (*GrIt);
2756 // check type and color of group
2757 if ( !isEqual( myColor, aGrp->GetColor() ))
2760 // IPAL52867 (prevent infinite recursion via GroupOnFilter)
2761 if ( SMESHDS_GroupOnFilter * gof = dynamic_cast< SMESHDS_GroupOnFilter* >( aGrp ))
2762 if ( gof->GetPredicate().get() == this )
2765 SMDSAbs_ElementType aGrpElType = (SMDSAbs_ElementType)aGrp->GetType();
2766 if ( myType == aGrpElType || (myType == SMDSAbs_All && aGrpElType != SMDSAbs_Node) ) {
2767 // add elements IDS into control
2768 int aSize = aGrp->Extent();
2769 for (int i = 0; i < aSize; i++)
2770 myIDs.insert( aGrp->GetID(i+1) );
2775 void GroupColor::SetColorStr( const TCollection_AsciiString& theStr )
2777 Kernel_Utils::Localizer loc;
2778 TCollection_AsciiString aStr = theStr;
2779 aStr.RemoveAll( ' ' );
2780 aStr.RemoveAll( '\t' );
2781 for ( int aPos = aStr.Search( ";;" ); aPos != -1; aPos = aStr.Search( ";;" ) )
2782 aStr.Remove( aPos, 2 );
2783 Standard_Real clr[3];
2784 clr[0] = clr[1] = clr[2] = 0.;
2785 for ( int i = 0; i < 3; i++ ) {
2786 TCollection_AsciiString tmpStr = aStr.Token( ";", i+1 );
2787 if ( !tmpStr.IsEmpty() && tmpStr.IsRealValue() )
2788 clr[i] = tmpStr.RealValue();
2790 myColor = Quantity_Color( clr[0], clr[1], clr[2], Quantity_TOC_RGB );
2793 //=======================================================================
2794 // name : GetRangeStr
2795 // Purpose : Get range as a string.
2796 // Example: "1,2,3,50-60,63,67,70-"
2797 //=======================================================================
2799 void GroupColor::GetColorStr( TCollection_AsciiString& theResStr ) const
2802 theResStr += TCollection_AsciiString( myColor.Red() );
2803 theResStr += TCollection_AsciiString( ";" ) + TCollection_AsciiString( myColor.Green() );
2804 theResStr += TCollection_AsciiString( ";" ) + TCollection_AsciiString( myColor.Blue() );
2807 //================================================================================
2809 Class : ElemGeomType
2810 Description : Predicate to check element geometry type
2812 //================================================================================
2814 ElemGeomType::ElemGeomType()
2817 myType = SMDSAbs_All;
2818 myGeomType = SMDSGeom_TRIANGLE;
2821 void ElemGeomType::SetMesh( const SMDS_Mesh* theMesh )
2826 bool ElemGeomType::IsSatisfy( long theId )
2828 if (!myMesh) return false;
2829 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2832 const SMDSAbs_ElementType anElemType = anElem->GetType();
2833 if ( myType != SMDSAbs_All && anElemType != myType )
2835 bool isOk = ( anElem->GetGeomType() == myGeomType );
2839 void ElemGeomType::SetType( SMDSAbs_ElementType theType )
2844 SMDSAbs_ElementType ElemGeomType::GetType() const
2849 void ElemGeomType::SetGeomType( SMDSAbs_GeometryType theType )
2851 myGeomType = theType;
2854 SMDSAbs_GeometryType ElemGeomType::GetGeomType() const
2859 //================================================================================
2861 Class : ElemEntityType
2862 Description : Predicate to check element entity type
2864 //================================================================================
2866 ElemEntityType::ElemEntityType():
2868 myType( SMDSAbs_All ),
2869 myEntityType( SMDSEntity_0D )
2873 void ElemEntityType::SetMesh( const SMDS_Mesh* theMesh )
2878 bool ElemEntityType::IsSatisfy( long theId )
2880 if ( !myMesh ) return false;
2881 if ( myType == SMDSAbs_Node )
2882 return myMesh->FindNode( theId );
2883 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2885 myEntityType == anElem->GetEntityType() );
2888 void ElemEntityType::SetType( SMDSAbs_ElementType theType )
2893 SMDSAbs_ElementType ElemEntityType::GetType() const
2898 void ElemEntityType::SetElemEntityType( SMDSAbs_EntityType theEntityType )
2900 myEntityType = theEntityType;
2903 SMDSAbs_EntityType ElemEntityType::GetElemEntityType() const
2905 return myEntityType;
2908 //================================================================================
2910 * \brief Class ConnectedElements
2912 //================================================================================
2914 ConnectedElements::ConnectedElements():
2915 myNodeID(0), myType( SMDSAbs_All ), myOkIDsReady( false ) {}
2917 SMDSAbs_ElementType ConnectedElements::GetType() const
2920 int ConnectedElements::GetNode() const
2921 { return myXYZ.empty() ? myNodeID : 0; } // myNodeID can be found by myXYZ
2923 std::vector<double> ConnectedElements::GetPoint() const
2926 void ConnectedElements::clearOkIDs()
2927 { myOkIDsReady = false; myOkIDs.clear(); }
2929 void ConnectedElements::SetType( SMDSAbs_ElementType theType )
2931 if ( myType != theType || myMeshModifTracer.IsMeshModified() )
2936 void ConnectedElements::SetMesh( const SMDS_Mesh* theMesh )
2938 myMeshModifTracer.SetMesh( theMesh );
2939 if ( myMeshModifTracer.IsMeshModified() )
2942 if ( !myXYZ.empty() )
2943 SetPoint( myXYZ[0], myXYZ[1], myXYZ[2] ); // find a node near myXYZ it in a new mesh
2947 void ConnectedElements::SetNode( int nodeID )
2952 bool isSameDomain = false;
2953 if ( myOkIDsReady && myMeshModifTracer.GetMesh() && !myMeshModifTracer.IsMeshModified() )
2954 if ( const SMDS_MeshNode* n = myMeshModifTracer.GetMesh()->FindNode( myNodeID ))
2956 SMDS_ElemIteratorPtr eIt = n->GetInverseElementIterator( myType );
2957 while ( !isSameDomain && eIt->more() )
2958 isSameDomain = IsSatisfy( eIt->next()->GetID() );
2960 if ( !isSameDomain )
2964 void ConnectedElements::SetPoint( double x, double y, double z )
2972 bool isSameDomain = false;
2974 // find myNodeID by myXYZ if possible
2975 if ( myMeshModifTracer.GetMesh() )
2977 SMESHUtils::Deleter<SMESH_ElementSearcher> searcher
2978 ( SMESH_MeshAlgos::GetElementSearcher( (SMDS_Mesh&) *myMeshModifTracer.GetMesh() ));
2980 std::vector< const SMDS_MeshElement* > foundElems;
2981 searcher->FindElementsByPoint( gp_Pnt(x,y,z), SMDSAbs_All, foundElems );
2983 if ( !foundElems.empty() )
2985 myNodeID = foundElems[0]->GetNode(0)->GetID();
2986 if ( myOkIDsReady && !myMeshModifTracer.IsMeshModified() )
2987 isSameDomain = IsSatisfy( foundElems[0]->GetID() );
2990 if ( !isSameDomain )
2994 bool ConnectedElements::IsSatisfy( long theElementId )
2996 // Here we do NOT check if the mesh has changed, we do it in Set...() only!!!
2998 if ( !myOkIDsReady )
3000 if ( !myMeshModifTracer.GetMesh() )
3002 const SMDS_MeshNode* node0 = myMeshModifTracer.GetMesh()->FindNode( myNodeID );
3006 std::list< const SMDS_MeshNode* > nodeQueue( 1, node0 );
3007 std::set< int > checkedNodeIDs;
3009 // foreach node in nodeQueue:
3010 // foreach element sharing a node:
3011 // add ID of an element of myType to myOkIDs;
3012 // push all element nodes absent from checkedNodeIDs to nodeQueue;
3013 while ( !nodeQueue.empty() )
3015 const SMDS_MeshNode* node = nodeQueue.front();
3016 nodeQueue.pop_front();
3018 // loop on elements sharing the node
3019 SMDS_ElemIteratorPtr eIt = node->GetInverseElementIterator();
3020 while ( eIt->more() )
3022 // keep elements of myType
3023 const SMDS_MeshElement* element = eIt->next();
3024 if ( element->GetType() == myType )
3025 myOkIDs.insert( myOkIDs.end(), element->GetID() );
3027 // enqueue nodes of the element
3028 SMDS_ElemIteratorPtr nIt = element->nodesIterator();
3029 while ( nIt->more() )
3031 const SMDS_MeshNode* n = static_cast< const SMDS_MeshNode* >( nIt->next() );
3032 if ( checkedNodeIDs.insert( n->GetID() ).second )
3033 nodeQueue.push_back( n );
3037 if ( myType == SMDSAbs_Node )
3038 std::swap( myOkIDs, checkedNodeIDs );
3040 size_t totalNbElems = myMeshModifTracer.GetMesh()->GetMeshInfo().NbElements( myType );
3041 if ( myOkIDs.size() == totalNbElems )
3044 myOkIDsReady = true;
3047 return myOkIDs.empty() ? true : myOkIDs.count( theElementId );
3050 //================================================================================
3052 * \brief Class CoplanarFaces
3054 //================================================================================
3058 inline bool isLessAngle( const gp_Vec& v1, const gp_Vec& v2, const double cos )
3060 double dot = v1 * v2; // cos * |v1| * |v2|
3061 double l1 = v1.SquareMagnitude();
3062 double l2 = v2.SquareMagnitude();
3063 return (( dot * cos >= 0 ) &&
3064 ( dot * dot ) / l1 / l2 >= ( cos * cos ));
3067 CoplanarFaces::CoplanarFaces()
3068 : myFaceID(0), myToler(0)
3071 void CoplanarFaces::SetMesh( const SMDS_Mesh* theMesh )
3073 myMeshModifTracer.SetMesh( theMesh );
3074 if ( myMeshModifTracer.IsMeshModified() )
3076 // Build a set of coplanar face ids
3078 myCoplanarIDs.Clear();
3080 if ( !myMeshModifTracer.GetMesh() || !myFaceID || !myToler )
3083 const SMDS_MeshElement* face = myMeshModifTracer.GetMesh()->FindElement( myFaceID );
3084 if ( !face || face->GetType() != SMDSAbs_Face )
3088 gp_Vec myNorm = getNormale( static_cast<const SMDS_MeshFace*>(face), &normOK );
3092 const double cosTol = Cos( myToler * M_PI / 180. );
3093 NCollection_Map< SMESH_TLink, SMESH_TLink > checkedLinks;
3095 std::list< std::pair< const SMDS_MeshElement*, gp_Vec > > faceQueue;
3096 faceQueue.push_back( std::make_pair( face, myNorm ));
3097 while ( !faceQueue.empty() )
3099 face = faceQueue.front().first;
3100 myNorm = faceQueue.front().second;
3101 faceQueue.pop_front();
3103 for ( int i = 0, nbN = face->NbCornerNodes(); i < nbN; ++i )
3105 const SMDS_MeshNode* n1 = face->GetNode( i );
3106 const SMDS_MeshNode* n2 = face->GetNode(( i+1 )%nbN);
3107 if ( !checkedLinks.Add( SMESH_TLink( n1, n2 )))
3109 SMDS_ElemIteratorPtr fIt = n1->GetInverseElementIterator(SMDSAbs_Face);
3110 while ( fIt->more() )
3112 const SMDS_MeshElement* f = fIt->next();
3113 if ( f->GetNodeIndex( n2 ) > -1 )
3115 gp_Vec norm = getNormale( static_cast<const SMDS_MeshFace*>(f), &normOK );
3116 if (!normOK || isLessAngle( myNorm, norm, cosTol))
3118 myCoplanarIDs.Add( f->GetID() );
3119 faceQueue.push_back( std::make_pair( f, norm ));
3127 bool CoplanarFaces::IsSatisfy( long theElementId )
3129 return myCoplanarIDs.Contains( theElementId );
3134 *Description : Predicate for Range of Ids.
3135 * Range may be specified with two ways.
3136 * 1. Using AddToRange method
3137 * 2. With SetRangeStr method. Parameter of this method is a string
3138 * like as "1,2,3,50-60,63,67,70-"
3141 //=======================================================================
3142 // name : RangeOfIds
3143 // Purpose : Constructor
3144 //=======================================================================
3145 RangeOfIds::RangeOfIds()
3148 myType = SMDSAbs_All;
3151 //=======================================================================
3153 // Purpose : Set mesh
3154 //=======================================================================
3155 void RangeOfIds::SetMesh( const SMDS_Mesh* theMesh )
3160 //=======================================================================
3161 // name : AddToRange
3162 // Purpose : Add ID to the range
3163 //=======================================================================
3164 bool RangeOfIds::AddToRange( long theEntityId )
3166 myIds.Add( theEntityId );
3170 //=======================================================================
3171 // name : GetRangeStr
3172 // Purpose : Get range as a string.
3173 // Example: "1,2,3,50-60,63,67,70-"
3174 //=======================================================================
3175 void RangeOfIds::GetRangeStr( TCollection_AsciiString& theResStr )
3179 TColStd_SequenceOfInteger anIntSeq;
3180 TColStd_SequenceOfAsciiString aStrSeq;
3182 TColStd_MapIteratorOfMapOfInteger anIter( myIds );
3183 for ( ; anIter.More(); anIter.Next() )
3185 int anId = anIter.Key();
3186 TCollection_AsciiString aStr( anId );
3187 anIntSeq.Append( anId );
3188 aStrSeq.Append( aStr );
3191 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
3193 int aMinId = myMin( i );
3194 int aMaxId = myMax( i );
3196 TCollection_AsciiString aStr;
3197 if ( aMinId != IntegerFirst() )
3202 if ( aMaxId != IntegerLast() )
3205 // find position of the string in result sequence and insert string in it
3206 if ( anIntSeq.Length() == 0 )
3208 anIntSeq.Append( aMinId );
3209 aStrSeq.Append( aStr );
3213 if ( aMinId < anIntSeq.First() )
3215 anIntSeq.Prepend( aMinId );
3216 aStrSeq.Prepend( aStr );
3218 else if ( aMinId > anIntSeq.Last() )
3220 anIntSeq.Append( aMinId );
3221 aStrSeq.Append( aStr );
3224 for ( int j = 1, k = anIntSeq.Length(); j <= k; j++ )
3225 if ( aMinId < anIntSeq( j ) )
3227 anIntSeq.InsertBefore( j, aMinId );
3228 aStrSeq.InsertBefore( j, aStr );
3234 if ( aStrSeq.Length() == 0 )
3237 theResStr = aStrSeq( 1 );
3238 for ( int j = 2, k = aStrSeq.Length(); j <= k; j++ )
3241 theResStr += aStrSeq( j );
3245 //=======================================================================
3246 // name : SetRangeStr
3247 // Purpose : Define range with string
3248 // Example of entry string: "1,2,3,50-60,63,67,70-"
3249 //=======================================================================
3250 bool RangeOfIds::SetRangeStr( const TCollection_AsciiString& theStr )
3256 TCollection_AsciiString aStr = theStr;
3257 for ( int i = 1; i <= aStr.Length(); ++i )
3259 char c = aStr.Value( i );
3260 if ( !isdigit( c ) && c != ',' && c != '-' )
3261 aStr.SetValue( i, ',');
3263 aStr.RemoveAll( ' ' );
3265 TCollection_AsciiString tmpStr = aStr.Token( ",", 1 );
3267 while ( tmpStr != "" )
3269 tmpStr = aStr.Token( ",", i++ );
3270 int aPos = tmpStr.Search( '-' );
3274 if ( tmpStr.IsIntegerValue() )
3275 myIds.Add( tmpStr.IntegerValue() );
3281 TCollection_AsciiString aMaxStr = tmpStr.Split( aPos );
3282 TCollection_AsciiString aMinStr = tmpStr;
3284 while ( aMinStr.Search( "-" ) != -1 ) aMinStr.RemoveAll( '-' );
3285 while ( aMaxStr.Search( "-" ) != -1 ) aMaxStr.RemoveAll( '-' );
3287 if ( (!aMinStr.IsEmpty() && !aMinStr.IsIntegerValue()) ||
3288 (!aMaxStr.IsEmpty() && !aMaxStr.IsIntegerValue()) )
3291 myMin.Append( aMinStr.IsEmpty() ? IntegerFirst() : aMinStr.IntegerValue() );
3292 myMax.Append( aMaxStr.IsEmpty() ? IntegerLast() : aMaxStr.IntegerValue() );
3299 //=======================================================================
3301 // Purpose : Get type of supported entities
3302 //=======================================================================
3303 SMDSAbs_ElementType RangeOfIds::GetType() const
3308 //=======================================================================
3310 // Purpose : Set type of supported entities
3311 //=======================================================================
3312 void RangeOfIds::SetType( SMDSAbs_ElementType theType )
3317 //=======================================================================
3319 // Purpose : Verify whether entity satisfies to this rpedicate
3320 //=======================================================================
3321 bool RangeOfIds::IsSatisfy( long theId )
3326 if ( myType == SMDSAbs_Node )
3328 if ( myMesh->FindNode( theId ) == 0 )
3333 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
3334 if ( anElem == 0 || (myType != anElem->GetType() && myType != SMDSAbs_All ))
3338 if ( myIds.Contains( theId ) )
3341 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
3342 if ( theId >= myMin( i ) && theId <= myMax( i ) )
3350 Description : Base class for comparators
3352 Comparator::Comparator():
3356 Comparator::~Comparator()
3359 void Comparator::SetMesh( const SMDS_Mesh* theMesh )
3362 myFunctor->SetMesh( theMesh );
3365 void Comparator::SetMargin( double theValue )
3367 myMargin = theValue;
3370 void Comparator::SetNumFunctor( NumericalFunctorPtr theFunct )
3372 myFunctor = theFunct;
3375 SMDSAbs_ElementType Comparator::GetType() const
3377 return myFunctor ? myFunctor->GetType() : SMDSAbs_All;
3380 double Comparator::GetMargin()
3388 Description : Comparator "<"
3390 bool LessThan::IsSatisfy( long theId )
3392 return myFunctor && myFunctor->GetValue( theId ) < myMargin;
3398 Description : Comparator ">"
3400 bool MoreThan::IsSatisfy( long theId )
3402 return myFunctor && myFunctor->GetValue( theId ) > myMargin;
3408 Description : Comparator "="
3411 myToler(Precision::Confusion())
3414 bool EqualTo::IsSatisfy( long theId )
3416 return myFunctor && fabs( myFunctor->GetValue( theId ) - myMargin ) < myToler;
3419 void EqualTo::SetTolerance( double theToler )
3424 double EqualTo::GetTolerance()
3431 Description : Logical NOT predicate
3433 LogicalNOT::LogicalNOT()
3436 LogicalNOT::~LogicalNOT()
3439 bool LogicalNOT::IsSatisfy( long theId )
3441 return myPredicate && !myPredicate->IsSatisfy( theId );
3444 void LogicalNOT::SetMesh( const SMDS_Mesh* theMesh )
3447 myPredicate->SetMesh( theMesh );
3450 void LogicalNOT::SetPredicate( PredicatePtr thePred )
3452 myPredicate = thePred;
3455 SMDSAbs_ElementType LogicalNOT::GetType() const
3457 return myPredicate ? myPredicate->GetType() : SMDSAbs_All;
3462 Class : LogicalBinary
3463 Description : Base class for binary logical predicate
3465 LogicalBinary::LogicalBinary()
3468 LogicalBinary::~LogicalBinary()
3471 void LogicalBinary::SetMesh( const SMDS_Mesh* theMesh )
3474 myPredicate1->SetMesh( theMesh );
3477 myPredicate2->SetMesh( theMesh );
3480 void LogicalBinary::SetPredicate1( PredicatePtr thePredicate )
3482 myPredicate1 = thePredicate;
3485 void LogicalBinary::SetPredicate2( PredicatePtr thePredicate )
3487 myPredicate2 = thePredicate;
3490 SMDSAbs_ElementType LogicalBinary::GetType() const
3492 if ( !myPredicate1 || !myPredicate2 )
3495 SMDSAbs_ElementType aType1 = myPredicate1->GetType();
3496 SMDSAbs_ElementType aType2 = myPredicate2->GetType();
3498 return aType1 == aType2 ? aType1 : SMDSAbs_All;
3504 Description : Logical AND
3506 bool LogicalAND::IsSatisfy( long theId )
3511 myPredicate1->IsSatisfy( theId ) &&
3512 myPredicate2->IsSatisfy( theId );
3518 Description : Logical OR
3520 bool LogicalOR::IsSatisfy( long theId )
3525 (myPredicate1->IsSatisfy( theId ) ||
3526 myPredicate2->IsSatisfy( theId ));
3535 // #include <tbb/parallel_for.h>
3536 // #include <tbb/enumerable_thread_specific.h>
3538 // namespace Parallel
3540 // typedef tbb::enumerable_thread_specific< TIdSequence > TIdSeq;
3544 // const SMDS_Mesh* myMesh;
3545 // PredicatePtr myPredicate;
3546 // TIdSeq & myOKIds;
3547 // Predicate( const SMDS_Mesh* m, PredicatePtr p, TIdSeq & ids ):
3548 // myMesh(m), myPredicate(p->Duplicate()), myOKIds(ids) {}
3549 // void operator() ( const tbb::blocked_range<size_t>& r ) const
3551 // for ( size_t i = r.begin(); i != r.end(); ++i )
3552 // if ( myPredicate->IsSatisfy( i ))
3553 // myOKIds.local().push_back();
3565 void Filter::SetPredicate( PredicatePtr thePredicate )
3567 myPredicate = thePredicate;
3570 void Filter::GetElementsId( const SMDS_Mesh* theMesh,
3571 PredicatePtr thePredicate,
3572 TIdSequence& theSequence )
3574 theSequence.clear();
3576 if ( !theMesh || !thePredicate )
3579 thePredicate->SetMesh( theMesh );
3581 SMDS_ElemIteratorPtr elemIt = theMesh->elementsIterator( thePredicate->GetType() );
3583 while ( elemIt->more() ) {
3584 const SMDS_MeshElement* anElem = elemIt->next();
3585 long anId = anElem->GetID();
3586 if ( thePredicate->IsSatisfy( anId ) )
3587 theSequence.push_back( anId );
3592 void Filter::GetElementsId( const SMDS_Mesh* theMesh,
3593 Filter::TIdSequence& theSequence )
3595 GetElementsId(theMesh,myPredicate,theSequence);
3602 typedef std::set<SMDS_MeshFace*> TMapOfFacePtr;
3608 ManifoldPart::Link::Link( SMDS_MeshNode* theNode1,
3609 SMDS_MeshNode* theNode2 )
3615 ManifoldPart::Link::~Link()
3621 bool ManifoldPart::Link::IsEqual( const ManifoldPart::Link& theLink ) const
3623 if ( myNode1 == theLink.myNode1 &&
3624 myNode2 == theLink.myNode2 )
3626 else if ( myNode1 == theLink.myNode2 &&
3627 myNode2 == theLink.myNode1 )
3633 bool ManifoldPart::Link::operator<( const ManifoldPart::Link& x ) const
3635 if(myNode1 < x.myNode1) return true;
3636 if(myNode1 == x.myNode1)
3637 if(myNode2 < x.myNode2) return true;
3641 bool ManifoldPart::IsEqual( const ManifoldPart::Link& theLink1,
3642 const ManifoldPart::Link& theLink2 )
3644 return theLink1.IsEqual( theLink2 );
3647 ManifoldPart::ManifoldPart()
3650 myAngToler = Precision::Angular();
3651 myIsOnlyManifold = true;
3654 ManifoldPart::~ManifoldPart()
3659 void ManifoldPart::SetMesh( const SMDS_Mesh* theMesh )
3665 SMDSAbs_ElementType ManifoldPart::GetType() const
3666 { return SMDSAbs_Face; }
3668 bool ManifoldPart::IsSatisfy( long theElementId )
3670 return myMapIds.Contains( theElementId );
3673 void ManifoldPart::SetAngleTolerance( const double theAngToler )
3674 { myAngToler = theAngToler; }
3676 double ManifoldPart::GetAngleTolerance() const
3677 { return myAngToler; }
3679 void ManifoldPart::SetIsOnlyManifold( const bool theIsOnly )
3680 { myIsOnlyManifold = theIsOnly; }
3682 void ManifoldPart::SetStartElem( const long theStartId )
3683 { myStartElemId = theStartId; }
3685 bool ManifoldPart::process()
3688 myMapBadGeomIds.Clear();
3690 myAllFacePtr.clear();
3691 myAllFacePtrIntDMap.clear();
3695 // collect all faces into own map
3696 SMDS_FaceIteratorPtr anFaceItr = myMesh->facesIterator();
3697 for (; anFaceItr->more(); )
3699 SMDS_MeshFace* aFacePtr = (SMDS_MeshFace*)anFaceItr->next();
3700 myAllFacePtr.push_back( aFacePtr );
3701 myAllFacePtrIntDMap[aFacePtr] = myAllFacePtr.size()-1;
3704 SMDS_MeshFace* aStartFace = (SMDS_MeshFace*)myMesh->FindElement( myStartElemId );
3708 // the map of non manifold links and bad geometry
3709 TMapOfLink aMapOfNonManifold;
3710 TColStd_MapOfInteger aMapOfTreated;
3712 // begin cycle on faces from start index and run on vector till the end
3713 // and from begin to start index to cover whole vector
3714 const int aStartIndx = myAllFacePtrIntDMap[aStartFace];
3715 bool isStartTreat = false;
3716 for ( int fi = aStartIndx; !isStartTreat || fi != aStartIndx ; fi++ )
3718 if ( fi == aStartIndx )
3719 isStartTreat = true;
3720 // as result next time when fi will be equal to aStartIndx
3722 SMDS_MeshFace* aFacePtr = myAllFacePtr[ fi ];
3723 if ( aMapOfTreated.Contains( aFacePtr->GetID() ) )
3726 aMapOfTreated.Add( aFacePtr->GetID() );
3727 TColStd_MapOfInteger aResFaces;
3728 if ( !findConnected( myAllFacePtrIntDMap, aFacePtr,
3729 aMapOfNonManifold, aResFaces ) )
3731 TColStd_MapIteratorOfMapOfInteger anItr( aResFaces );
3732 for ( ; anItr.More(); anItr.Next() )
3734 int aFaceId = anItr.Key();
3735 aMapOfTreated.Add( aFaceId );
3736 myMapIds.Add( aFaceId );
3739 if ( fi == int( myAllFacePtr.size() - 1 ))
3741 } // end run on vector of faces
3742 return !myMapIds.IsEmpty();
3745 static void getLinks( const SMDS_MeshFace* theFace,
3746 ManifoldPart::TVectorOfLink& theLinks )
3748 int aNbNode = theFace->NbNodes();
3749 SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
3751 SMDS_MeshNode* aNode = 0;
3752 for ( ; aNodeItr->more() && i <= aNbNode; )
3755 SMDS_MeshNode* aN1 = (SMDS_MeshNode*)aNodeItr->next();
3759 SMDS_MeshNode* aN2 = ( i >= aNbNode ) ? aNode : (SMDS_MeshNode*)aNodeItr->next();
3761 ManifoldPart::Link aLink( aN1, aN2 );
3762 theLinks.push_back( aLink );
3766 bool ManifoldPart::findConnected
3767 ( const ManifoldPart::TDataMapFacePtrInt& theAllFacePtrInt,
3768 SMDS_MeshFace* theStartFace,
3769 ManifoldPart::TMapOfLink& theNonManifold,
3770 TColStd_MapOfInteger& theResFaces )
3772 theResFaces.Clear();
3773 if ( !theAllFacePtrInt.size() )
3776 if ( getNormale( theStartFace ).SquareModulus() <= gp::Resolution() )
3778 myMapBadGeomIds.Add( theStartFace->GetID() );
3782 ManifoldPart::TMapOfLink aMapOfBoundary, aMapToSkip;
3783 ManifoldPart::TVectorOfLink aSeqOfBoundary;
3784 theResFaces.Add( theStartFace->GetID() );
3785 ManifoldPart::TDataMapOfLinkFacePtr aDMapLinkFace;
3787 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
3788 aDMapLinkFace, theNonManifold, theStartFace );
3790 bool isDone = false;
3791 while ( !isDone && aMapOfBoundary.size() != 0 )
3793 bool isToReset = false;
3794 ManifoldPart::TVectorOfLink::iterator pLink = aSeqOfBoundary.begin();
3795 for ( ; !isToReset && pLink != aSeqOfBoundary.end(); ++pLink )
3797 ManifoldPart::Link aLink = *pLink;
3798 if ( aMapToSkip.find( aLink ) != aMapToSkip.end() )
3800 // each link could be treated only once
3801 aMapToSkip.insert( aLink );
3803 ManifoldPart::TVectorOfFacePtr aFaces;
3805 if ( myIsOnlyManifold &&
3806 (theNonManifold.find( aLink ) != theNonManifold.end()) )
3810 getFacesByLink( aLink, aFaces );
3811 // filter the element to keep only indicated elements
3812 ManifoldPart::TVectorOfFacePtr aFiltered;
3813 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
3814 for ( ; pFace != aFaces.end(); ++pFace )
3816 SMDS_MeshFace* aFace = *pFace;
3817 if ( myAllFacePtrIntDMap.find( aFace ) != myAllFacePtrIntDMap.end() )
3818 aFiltered.push_back( aFace );
3821 if ( aFaces.size() < 2 ) // no neihgbour faces
3823 else if ( myIsOnlyManifold && aFaces.size() > 2 ) // non manifold case
3825 theNonManifold.insert( aLink );
3830 // compare normal with normals of neighbor element
3831 SMDS_MeshFace* aPrevFace = aDMapLinkFace[ aLink ];
3832 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
3833 for ( ; pFace != aFaces.end(); ++pFace )
3835 SMDS_MeshFace* aNextFace = *pFace;
3836 if ( aPrevFace == aNextFace )
3838 int anNextFaceID = aNextFace->GetID();
3839 if ( myIsOnlyManifold && theResFaces.Contains( anNextFaceID ) )
3840 // should not be with non manifold restriction. probably bad topology
3842 // check if face was treated and skipped
3843 if ( myMapBadGeomIds.Contains( anNextFaceID ) ||
3844 !isInPlane( aPrevFace, aNextFace ) )
3846 // add new element to connected and extend the boundaries.
3847 theResFaces.Add( anNextFaceID );
3848 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
3849 aDMapLinkFace, theNonManifold, aNextFace );
3853 isDone = !isToReset;
3856 return !theResFaces.IsEmpty();
3859 bool ManifoldPart::isInPlane( const SMDS_MeshFace* theFace1,
3860 const SMDS_MeshFace* theFace2 )
3862 gp_Dir aNorm1 = gp_Dir( getNormale( theFace1 ) );
3863 gp_XYZ aNorm2XYZ = getNormale( theFace2 );
3864 if ( aNorm2XYZ.SquareModulus() <= gp::Resolution() )
3866 myMapBadGeomIds.Add( theFace2->GetID() );
3869 if ( aNorm1.IsParallel( gp_Dir( aNorm2XYZ ), myAngToler ) )
3875 void ManifoldPart::expandBoundary
3876 ( ManifoldPart::TMapOfLink& theMapOfBoundary,
3877 ManifoldPart::TVectorOfLink& theSeqOfBoundary,
3878 ManifoldPart::TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
3879 ManifoldPart::TMapOfLink& theNonManifold,
3880 SMDS_MeshFace* theNextFace ) const
3882 ManifoldPart::TVectorOfLink aLinks;
3883 getLinks( theNextFace, aLinks );
3884 int aNbLink = (int)aLinks.size();
3885 for ( int i = 0; i < aNbLink; i++ )
3887 ManifoldPart::Link aLink = aLinks[ i ];
3888 if ( myIsOnlyManifold && (theNonManifold.find( aLink ) != theNonManifold.end()) )
3890 if ( theMapOfBoundary.find( aLink ) != theMapOfBoundary.end() )
3892 if ( myIsOnlyManifold )
3894 // remove from boundary
3895 theMapOfBoundary.erase( aLink );
3896 ManifoldPart::TVectorOfLink::iterator pLink = theSeqOfBoundary.begin();
3897 for ( ; pLink != theSeqOfBoundary.end(); ++pLink )
3899 ManifoldPart::Link aBoundLink = *pLink;
3900 if ( aBoundLink.IsEqual( aLink ) )
3902 theSeqOfBoundary.erase( pLink );
3910 theMapOfBoundary.insert( aLink );
3911 theSeqOfBoundary.push_back( aLink );
3912 theDMapLinkFacePtr[ aLink ] = theNextFace;
3917 void ManifoldPart::getFacesByLink( const ManifoldPart::Link& theLink,
3918 ManifoldPart::TVectorOfFacePtr& theFaces ) const
3920 std::set<SMDS_MeshCell *> aSetOfFaces;
3921 // take all faces that shared first node
3922 SMDS_ElemIteratorPtr anItr = theLink.myNode1->facesIterator();
3923 for ( ; anItr->more(); )
3925 SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
3928 aSetOfFaces.insert( aFace );
3930 // take all faces that shared second node
3931 anItr = theLink.myNode2->facesIterator();
3932 // find the common part of two sets
3933 for ( ; anItr->more(); )
3935 SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
3936 if ( aSetOfFaces.count( aFace ) )
3937 theFaces.push_back( aFace );
3942 Class : BelongToMeshGroup
3943 Description : Verify whether a mesh element is included into a mesh group
3945 BelongToMeshGroup::BelongToMeshGroup(): myGroup( 0 )
3949 void BelongToMeshGroup::SetGroup( SMESHDS_GroupBase* g )
3954 void BelongToMeshGroup::SetStoreName( const std::string& sn )
3959 void BelongToMeshGroup::SetMesh( const SMDS_Mesh* theMesh )
3961 if ( myGroup && myGroup->GetMesh() != theMesh )
3965 if ( !myGroup && !myStoreName.empty() )
3967 if ( const SMESHDS_Mesh* aMesh = dynamic_cast<const SMESHDS_Mesh*>(theMesh))
3969 const std::set<SMESHDS_GroupBase*>& grps = aMesh->GetGroups();
3970 std::set<SMESHDS_GroupBase*>::const_iterator g = grps.begin();
3971 for ( ; g != grps.end() && !myGroup; ++g )
3972 if ( *g && myStoreName == (*g)->GetStoreName() )
3978 myGroup->IsEmpty(); // make GroupOnFilter update its predicate
3982 bool BelongToMeshGroup::IsSatisfy( long theElementId )
3984 return myGroup ? myGroup->Contains( theElementId ) : false;
3987 SMDSAbs_ElementType BelongToMeshGroup::GetType() const
3989 return myGroup ? myGroup->GetType() : SMDSAbs_All;
3992 //================================================================================
3993 // ElementsOnSurface
3994 //================================================================================
3996 ElementsOnSurface::ElementsOnSurface()
3999 myType = SMDSAbs_All;
4001 myToler = Precision::Confusion();
4002 myUseBoundaries = false;
4005 ElementsOnSurface::~ElementsOnSurface()
4009 void ElementsOnSurface::SetMesh( const SMDS_Mesh* theMesh )
4011 myMeshModifTracer.SetMesh( theMesh );
4012 if ( myMeshModifTracer.IsMeshModified())
4016 bool ElementsOnSurface::IsSatisfy( long theElementId )
4018 return myIds.Contains( theElementId );
4021 SMDSAbs_ElementType ElementsOnSurface::GetType() const
4024 void ElementsOnSurface::SetTolerance( const double theToler )
4026 if ( myToler != theToler )
4031 double ElementsOnSurface::GetTolerance() const
4034 void ElementsOnSurface::SetUseBoundaries( bool theUse )
4036 if ( myUseBoundaries != theUse ) {
4037 myUseBoundaries = theUse;
4038 SetSurface( mySurf, myType );
4042 void ElementsOnSurface::SetSurface( const TopoDS_Shape& theShape,
4043 const SMDSAbs_ElementType theType )
4048 if ( theShape.IsNull() || theShape.ShapeType() != TopAbs_FACE )
4050 mySurf = TopoDS::Face( theShape );
4051 BRepAdaptor_Surface SA( mySurf, myUseBoundaries );
4053 u1 = SA.FirstUParameter(),
4054 u2 = SA.LastUParameter(),
4055 v1 = SA.FirstVParameter(),
4056 v2 = SA.LastVParameter();
4057 Handle(Geom_Surface) surf = BRep_Tool::Surface( mySurf );
4058 myProjector.Init( surf, u1,u2, v1,v2 );
4062 void ElementsOnSurface::process()
4065 if ( mySurf.IsNull() )
4068 if ( !myMeshModifTracer.GetMesh() )
4071 myIds.ReSize( myMeshModifTracer.GetMesh()->GetMeshInfo().NbElements( myType ));
4073 SMDS_ElemIteratorPtr anIter = myMeshModifTracer.GetMesh()->elementsIterator( myType );
4074 for(; anIter->more(); )
4075 process( anIter->next() );
4078 void ElementsOnSurface::process( const SMDS_MeshElement* theElemPtr )
4080 SMDS_ElemIteratorPtr aNodeItr = theElemPtr->nodesIterator();
4081 bool isSatisfy = true;
4082 for ( ; aNodeItr->more(); )
4084 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
4085 if ( !isOnSurface( aNode ) )
4092 myIds.Add( theElemPtr->GetID() );
4095 bool ElementsOnSurface::isOnSurface( const SMDS_MeshNode* theNode )
4097 if ( mySurf.IsNull() )
4100 gp_Pnt aPnt( theNode->X(), theNode->Y(), theNode->Z() );
4101 // double aToler2 = myToler * myToler;
4102 // if ( mySurf->IsKind(STANDARD_TYPE(Geom_Plane)))
4104 // gp_Pln aPln = Handle(Geom_Plane)::DownCast(mySurf)->Pln();
4105 // if ( aPln.SquareDistance( aPnt ) > aToler2 )
4108 // else if ( mySurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)))
4110 // gp_Cylinder aCyl = Handle(Geom_CylindricalSurface)::DownCast(mySurf)->Cylinder();
4111 // double aRad = aCyl.Radius();
4112 // gp_Ax3 anAxis = aCyl.Position();
4113 // gp_XYZ aLoc = aCyl.Location().XYZ();
4114 // double aXDist = anAxis.XDirection().XYZ() * ( aPnt.XYZ() - aLoc );
4115 // double aYDist = anAxis.YDirection().XYZ() * ( aPnt.XYZ() - aLoc );
4116 // if ( fabs(aXDist*aXDist + aYDist*aYDist - aRad*aRad) > aToler2 )
4121 myProjector.Perform( aPnt );
4122 bool isOn = ( myProjector.IsDone() && myProjector.LowerDistance() <= myToler );
4128 //================================================================================
4130 //================================================================================
4133 const int theIsCheckedFlag = 0x0000100;
4136 struct ElementsOnShape::Classifier
4138 Classifier() { mySolidClfr = 0; myFlags = 0; }
4140 void Init(const TopoDS_Shape& s, double tol, const Bnd_B3d* box = 0 );
4141 bool IsOut(const gp_Pnt& p) { return SetChecked( true ), (this->*myIsOutFun)( p ); }
4142 TopAbs_ShapeEnum ShapeType() const { return myShape.ShapeType(); }
4143 const TopoDS_Shape& Shape() const { return myShape; }
4144 const Bnd_B3d* GetBndBox() const { return & myBox; }
4145 bool IsChecked() { return myFlags & theIsCheckedFlag; }
4146 bool IsSetFlag( int flag ) const { return myFlags & flag; }
4147 void SetChecked( bool is ) { is ? SetFlag( theIsCheckedFlag ) : UnsetFlag( theIsCheckedFlag ); }
4148 void SetFlag ( int flag ) { myFlags |= flag; }
4149 void UnsetFlag( int flag ) { myFlags &= ~flag; }
4152 bool isOutOfSolid (const gp_Pnt& p);
4153 bool isOutOfBox (const gp_Pnt& p);
4154 bool isOutOfFace (const gp_Pnt& p);
4155 bool isOutOfEdge (const gp_Pnt& p);
4156 bool isOutOfVertex(const gp_Pnt& p);
4157 bool isBox (const TopoDS_Shape& s);
4159 bool (Classifier::* myIsOutFun)(const gp_Pnt& p);
4160 BRepClass3d_SolidClassifier* mySolidClfr; // ptr because of a run-time forbidden copy-constructor
4162 GeomAPI_ProjectPointOnSurf myProjFace;
4163 GeomAPI_ProjectPointOnCurve myProjEdge;
4165 TopoDS_Shape myShape;
4170 struct ElementsOnShape::OctreeClassifier : public SMESH_Octree
4172 OctreeClassifier( const std::vector< ElementsOnShape::Classifier* >& classifiers );
4173 OctreeClassifier( const OctreeClassifier* otherTree,
4174 const std::vector< ElementsOnShape::Classifier >& clsOther,
4175 std::vector< ElementsOnShape::Classifier >& cls );
4176 void GetClassifiersAtPoint( const gp_XYZ& p,
4177 std::vector< ElementsOnShape::Classifier* >& classifiers );
4179 OctreeClassifier() {}
4180 SMESH_Octree* newChild() const { return new OctreeClassifier; }
4181 void buildChildrenData();
4182 Bnd_B3d* buildRootBox();
4184 std::vector< ElementsOnShape::Classifier* > myClassifiers;
4188 ElementsOnShape::ElementsOnShape():
4190 myType(SMDSAbs_All),
4191 myToler(Precision::Confusion()),
4192 myAllNodesFlag(false)
4196 ElementsOnShape::~ElementsOnShape()
4201 Predicate* ElementsOnShape::clone() const
4203 ElementsOnShape* cln = new ElementsOnShape();
4204 cln->SetAllNodes ( myAllNodesFlag );
4205 cln->SetTolerance( myToler );
4206 cln->SetMesh ( myMeshModifTracer.GetMesh() );
4207 cln->myShape = myShape; // avoid creation of myClassifiers
4208 cln->SetShape ( myShape, myType );
4209 cln->myClassifiers.resize( myClassifiers.size() );
4210 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4211 cln->myClassifiers[ i ].Init( BRepBuilderAPI_Copy( myClassifiers[ i ].Shape()),
4212 myToler, myClassifiers[ i ].GetBndBox() );
4213 if ( myOctree ) // copy myOctree
4215 cln->myOctree = new OctreeClassifier( myOctree, myClassifiers, cln->myClassifiers );
4220 SMDSAbs_ElementType ElementsOnShape::GetType() const
4225 void ElementsOnShape::SetTolerance (const double theToler)
4227 if (myToler != theToler) {
4229 SetShape(myShape, myType);
4233 double ElementsOnShape::GetTolerance() const
4238 void ElementsOnShape::SetAllNodes (bool theAllNodes)
4240 myAllNodesFlag = theAllNodes;
4243 void ElementsOnShape::SetMesh (const SMDS_Mesh* theMesh)
4245 myMeshModifTracer.SetMesh( theMesh );
4246 if ( myMeshModifTracer.IsMeshModified())
4248 size_t nbNodes = theMesh ? theMesh->NbNodes() : 0;
4249 if ( myNodeIsChecked.size() == nbNodes )
4251 std::fill( myNodeIsChecked.begin(), myNodeIsChecked.end(), false );
4255 SMESHUtils::FreeVector( myNodeIsChecked );
4256 SMESHUtils::FreeVector( myNodeIsOut );
4257 myNodeIsChecked.resize( nbNodes, false );
4258 myNodeIsOut.resize( nbNodes );
4263 bool ElementsOnShape::getNodeIsOut( const SMDS_MeshNode* n, bool& isOut )
4265 if ( n->GetID() >= (int) myNodeIsChecked.size() ||
4266 !myNodeIsChecked[ n->GetID() ])
4269 isOut = myNodeIsOut[ n->GetID() ];
4273 void ElementsOnShape::setNodeIsOut( const SMDS_MeshNode* n, bool isOut )
4275 if ( n->GetID() < (int) myNodeIsChecked.size() )
4277 myNodeIsChecked[ n->GetID() ] = true;
4278 myNodeIsOut [ n->GetID() ] = isOut;
4282 void ElementsOnShape::SetShape (const TopoDS_Shape& theShape,
4283 const SMDSAbs_ElementType theType)
4285 bool shapeChanges = ( myShape != theShape );
4288 if ( myShape.IsNull() ) return;
4292 // find most complex shapes
4293 TopTools_IndexedMapOfShape shapesMap;
4294 TopAbs_ShapeEnum shapeTypes[4] = { TopAbs_SOLID, TopAbs_FACE, TopAbs_EDGE, TopAbs_VERTEX };
4295 TopExp_Explorer sub;
4296 for ( int i = 0; i < 4; ++i )
4298 if ( shapesMap.IsEmpty() )
4299 for ( sub.Init( myShape, shapeTypes[i] ); sub.More(); sub.Next() )
4300 shapesMap.Add( sub.Current() );
4302 for ( sub.Init( myShape, shapeTypes[i], shapeTypes[i-1] ); sub.More(); sub.Next() )
4303 shapesMap.Add( sub.Current() );
4307 myClassifiers.resize( shapesMap.Extent() );
4308 for ( int i = 0; i < shapesMap.Extent(); ++i )
4309 myClassifiers[ i ].Init( shapesMap( i+1 ), myToler );
4312 if ( theType == SMDSAbs_Node )
4314 SMESHUtils::FreeVector( myNodeIsChecked );
4315 SMESHUtils::FreeVector( myNodeIsOut );
4319 std::fill( myNodeIsChecked.begin(), myNodeIsChecked.end(), false );
4323 void ElementsOnShape::clearClassifiers()
4325 // for ( size_t i = 0; i < myClassifiers.size(); ++i )
4326 // delete myClassifiers[ i ];
4327 myClassifiers.clear();
4333 bool ElementsOnShape::IsSatisfy( long elemId )
4335 if ( myClassifiers.empty() )
4338 const SMDS_Mesh* mesh = myMeshModifTracer.GetMesh();
4339 if ( myType == SMDSAbs_Node )
4340 return IsSatisfy( mesh->FindNode( elemId ));
4341 return IsSatisfy( mesh->FindElement( elemId ));
4344 bool ElementsOnShape::IsSatisfy (const SMDS_MeshElement* elem)
4349 bool isSatisfy = myAllNodesFlag, isNodeOut;
4351 gp_XYZ centerXYZ (0, 0, 0);
4353 if ( !myOctree && myClassifiers.size() > 5 )
4355 myWorkClassifiers.resize( myClassifiers.size() );
4356 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4357 myWorkClassifiers[ i ] = & myClassifiers[ i ];
4358 myOctree = new OctreeClassifier( myWorkClassifiers );
4361 SMDS_ElemIteratorPtr aNodeItr = elem->nodesIterator();
4362 while (aNodeItr->more() && (isSatisfy == myAllNodesFlag))
4364 SMESH_TNodeXYZ aPnt( aNodeItr->next() );
4368 if ( !getNodeIsOut( aPnt._node, isNodeOut ))
4372 myWorkClassifiers.clear();
4373 myOctree->GetClassifiersAtPoint( aPnt, myWorkClassifiers );
4375 for ( size_t i = 0; i < myWorkClassifiers.size(); ++i )
4376 myWorkClassifiers[i]->SetChecked( false );
4378 for ( size_t i = 0; i < myWorkClassifiers.size() && isNodeOut; ++i )
4379 if ( !myWorkClassifiers[i]->IsChecked() )
4380 isNodeOut = myWorkClassifiers[i]->IsOut( aPnt );
4384 for ( size_t i = 0; i < myClassifiers.size() && isNodeOut; ++i )
4385 isNodeOut = myClassifiers[i].IsOut( aPnt );
4387 setNodeIsOut( aPnt._node, isNodeOut );
4389 isSatisfy = !isNodeOut;
4392 // Check the center point for volumes MantisBug 0020168
4395 myClassifiers[0].ShapeType() == TopAbs_SOLID )
4397 centerXYZ /= elem->NbNodes();
4400 for ( size_t i = 0; i < myWorkClassifiers.size() && !isSatisfy; ++i )
4401 isSatisfy = ! myWorkClassifiers[i]->IsOut( centerXYZ );
4403 for ( size_t i = 0; i < myClassifiers.size() && !isSatisfy; ++i )
4404 isSatisfy = ! myClassifiers[i].IsOut( centerXYZ );
4410 bool ElementsOnShape::IsSatisfy (const SMDS_MeshNode* node,
4411 TopoDS_Shape* okShape)
4416 if ( !myOctree && myClassifiers.size() > 5 )
4418 myWorkClassifiers.resize( myClassifiers.size() );
4419 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4420 myWorkClassifiers[ i ] = & myClassifiers[ i ];
4421 myOctree = new OctreeClassifier( myWorkClassifiers );
4424 bool isNodeOut = true;
4426 if ( okShape || !getNodeIsOut( node, isNodeOut ))
4428 SMESH_NodeXYZ aPnt = node;
4431 myWorkClassifiers.clear();
4432 myOctree->GetClassifiersAtPoint( aPnt, myWorkClassifiers );
4434 for ( size_t i = 0; i < myWorkClassifiers.size(); ++i )
4435 myWorkClassifiers[i]->SetChecked( false );
4437 for ( size_t i = 0; i < myWorkClassifiers.size(); ++i )
4438 if ( !myWorkClassifiers[i]->IsChecked() &&
4439 !myWorkClassifiers[i]->IsOut( aPnt ))
4443 *okShape = myWorkClassifiers[i]->Shape();
4449 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4450 if ( !myClassifiers[i].IsOut( aPnt ))
4454 *okShape = myWorkClassifiers[i]->Shape();
4458 setNodeIsOut( node, isNodeOut );
4464 void ElementsOnShape::Classifier::Init( const TopoDS_Shape& theShape,
4466 const Bnd_B3d* theBox )
4472 bool isShapeBox = false;
4473 switch ( myShape.ShapeType() )
4477 if (( isShapeBox = isBox( theShape )))
4479 myIsOutFun = & ElementsOnShape::Classifier::isOutOfBox;
4483 mySolidClfr = new BRepClass3d_SolidClassifier(theShape);
4484 myIsOutFun = & ElementsOnShape::Classifier::isOutOfSolid;
4490 Standard_Real u1,u2,v1,v2;
4491 Handle(Geom_Surface) surf = BRep_Tool::Surface( TopoDS::Face( theShape ));
4492 surf->Bounds( u1,u2,v1,v2 );
4493 myProjFace.Init(surf, u1,u2, v1,v2, myTol );
4494 myIsOutFun = & ElementsOnShape::Classifier::isOutOfFace;
4499 Standard_Real u1, u2;
4500 Handle(Geom_Curve) curve = BRep_Tool::Curve( TopoDS::Edge( theShape ), u1, u2);
4501 myProjEdge.Init(curve, u1, u2);
4502 myIsOutFun = & ElementsOnShape::Classifier::isOutOfEdge;
4507 myVertexXYZ = BRep_Tool::Pnt( TopoDS::Vertex( theShape ) );
4508 myIsOutFun = & ElementsOnShape::Classifier::isOutOfVertex;
4512 throw SALOME_Exception("Programmer error in usage of ElementsOnShape::Classifier");
4524 BRepBndLib::Add( myShape, box );
4526 myBox.Add( box.CornerMin() );
4527 myBox.Add( box.CornerMax() );
4528 gp_XYZ halfSize = 0.5 * ( box.CornerMax().XYZ() - box.CornerMin().XYZ() );
4529 for ( int iDim = 1; iDim <= 3; ++iDim )
4531 double x = halfSize.Coord( iDim );
4532 halfSize.SetCoord( iDim, x + Max( myTol, 1e-2 * x ));
4534 myBox.SetHSize( halfSize );
4539 ElementsOnShape::Classifier::~Classifier()
4541 delete mySolidClfr; mySolidClfr = 0;
4544 bool ElementsOnShape::Classifier::isOutOfSolid (const gp_Pnt& p)
4546 mySolidClfr->Perform( p, myTol );
4547 return ( mySolidClfr->State() != TopAbs_IN && mySolidClfr->State() != TopAbs_ON );
4550 bool ElementsOnShape::Classifier::isOutOfBox (const gp_Pnt& p)
4552 return myBox.IsOut( p.XYZ() );
4555 bool ElementsOnShape::Classifier::isOutOfFace (const gp_Pnt& p)
4557 myProjFace.Perform( p );
4558 if ( myProjFace.IsDone() && myProjFace.LowerDistance() <= myTol )
4560 // check relatively to the face
4562 myProjFace.LowerDistanceParameters(u, v);
4563 gp_Pnt2d aProjPnt (u, v);
4564 BRepClass_FaceClassifier aClsf ( TopoDS::Face( myShape ), aProjPnt, myTol );
4565 if ( aClsf.State() == TopAbs_IN || aClsf.State() == TopAbs_ON )
4571 bool ElementsOnShape::Classifier::isOutOfEdge (const gp_Pnt& p)
4573 myProjEdge.Perform( p );
4574 return ! ( myProjEdge.NbPoints() > 0 && myProjEdge.LowerDistance() <= myTol );
4577 bool ElementsOnShape::Classifier::isOutOfVertex(const gp_Pnt& p)
4579 return ( myVertexXYZ.Distance( p ) > myTol );
4582 bool ElementsOnShape::Classifier::isBox (const TopoDS_Shape& theShape)
4584 TopTools_IndexedMapOfShape vMap;
4585 TopExp::MapShapes( theShape, TopAbs_VERTEX, vMap );
4586 if ( vMap.Extent() != 8 )
4590 for ( int i = 1; i <= 8; ++i )
4591 myBox.Add( BRep_Tool::Pnt( TopoDS::Vertex( vMap( i ))).XYZ() );
4593 gp_XYZ pMin = myBox.CornerMin(), pMax = myBox.CornerMax();
4594 for ( int i = 1; i <= 8; ++i )
4596 gp_Pnt p = BRep_Tool::Pnt( TopoDS::Vertex( vMap( i )));
4597 for ( int iC = 1; iC <= 3; ++ iC )
4599 double d1 = Abs( pMin.Coord( iC ) - p.Coord( iC ));
4600 double d2 = Abs( pMax.Coord( iC ) - p.Coord( iC ));
4601 if ( Min( d1, d2 ) > myTol )
4605 myBox.Enlarge( myTol );
4610 OctreeClassifier::OctreeClassifier( const std::vector< ElementsOnShape::Classifier* >& classifiers )
4611 :SMESH_Octree( new SMESH_TreeLimit )
4613 myClassifiers = classifiers;
4618 OctreeClassifier::OctreeClassifier( const OctreeClassifier* otherTree,
4619 const std::vector< ElementsOnShape::Classifier >& clsOther,
4620 std::vector< ElementsOnShape::Classifier >& cls )
4621 :SMESH_Octree( new SMESH_TreeLimit )
4623 myBox = new Bnd_B3d( *otherTree->getBox() );
4625 if (( myIsLeaf = otherTree->isLeaf() ))
4627 myClassifiers.resize( otherTree->myClassifiers.size() );
4628 for ( size_t i = 0; i < otherTree->myClassifiers.size(); ++i )
4630 int ind = otherTree->myClassifiers[i] - & clsOther[0];
4631 myClassifiers[ i ] = & cls[ ind ];
4634 else if ( otherTree->myChildren )
4636 myChildren = new SMESH_Tree< Bnd_B3d, 8 > * [ 8 ];
4637 for ( int i = 0; i < nbChildren(); i++ )
4639 new OctreeClassifier( static_cast<const OctreeClassifier*>( otherTree->myChildren[i]),
4644 void ElementsOnShape::
4645 OctreeClassifier::GetClassifiersAtPoint( const gp_XYZ& point,
4646 std::vector< ElementsOnShape::Classifier* >& result )
4648 if ( getBox()->IsOut( point ))
4653 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4654 if ( !myClassifiers[i]->GetBndBox()->IsOut( point ))
4655 result.push_back( myClassifiers[i] );
4659 for (int i = 0; i < nbChildren(); i++)
4660 ((OctreeClassifier*) myChildren[i])->GetClassifiersAtPoint( point, result );
4664 void ElementsOnShape::OctreeClassifier::buildChildrenData()
4666 // distribute myClassifiers among myChildren
4668 const int childFlag[8] = { 0x0000001,
4676 int nbInChild[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
4678 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4680 for ( int j = 0; j < nbChildren(); j++ )
4682 if ( !myClassifiers[i]->GetBndBox()->IsOut( *myChildren[j]->getBox() ))
4684 myClassifiers[i]->SetFlag( childFlag[ j ]);
4690 for ( int j = 0; j < nbChildren(); j++ )
4692 OctreeClassifier* child = static_cast<OctreeClassifier*>( myChildren[ j ]);
4693 child->myClassifiers.resize( nbInChild[ j ]);
4694 for ( size_t i = 0; nbInChild[ j ] && i < myClassifiers.size(); ++i )
4696 if ( myClassifiers[ i ]->IsSetFlag( childFlag[ j ]))
4699 child->myClassifiers[ nbInChild[ j ]] = myClassifiers[ i ];
4700 myClassifiers[ i ]->UnsetFlag( childFlag[ j ]);
4704 SMESHUtils::FreeVector( myClassifiers );
4706 // define if a child isLeaf()
4707 for ( int i = 0; i < nbChildren(); i++ )
4709 OctreeClassifier* child = static_cast<OctreeClassifier*>( myChildren[ i ]);
4710 child->myIsLeaf = ( child->myClassifiers.size() <= 5 );
4714 Bnd_B3d* ElementsOnShape::OctreeClassifier::buildRootBox()
4716 Bnd_B3d* box = new Bnd_B3d;
4717 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4718 box->Add( *myClassifiers[i]->GetBndBox() );
4723 Class : BelongToGeom
4724 Description : Predicate for verifying whether entity belongs to
4725 specified geometrical support
4728 BelongToGeom::BelongToGeom()
4730 myType(SMDSAbs_NbElementTypes),
4731 myIsSubshape(false),
4732 myTolerance(Precision::Confusion())
4735 Predicate* BelongToGeom::clone() const
4737 BelongToGeom* cln = new BelongToGeom( *this );
4738 cln->myElementsOnShapePtr.reset( static_cast<ElementsOnShape*>( myElementsOnShapePtr->clone() ));
4742 void BelongToGeom::SetMesh( const SMDS_Mesh* theMesh )
4744 if ( myMeshDS != theMesh )
4746 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
4751 void BelongToGeom::SetGeom( const TopoDS_Shape& theShape )
4753 if ( myShape != theShape )
4760 static bool IsSubShape (const TopTools_IndexedMapOfShape& theMap,
4761 const TopoDS_Shape& theShape)
4763 if (theMap.Contains(theShape)) return true;
4765 if (theShape.ShapeType() == TopAbs_COMPOUND ||
4766 theShape.ShapeType() == TopAbs_COMPSOLID)
4768 TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
4769 for (; anIt.More(); anIt.Next())
4771 if (!IsSubShape(theMap, anIt.Value())) {
4781 void BelongToGeom::init()
4783 if ( !myMeshDS || myShape.IsNull() ) return;
4785 // is sub-shape of main shape?
4786 TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
4787 if (aMainShape.IsNull()) {
4788 myIsSubshape = false;
4791 TopTools_IndexedMapOfShape aMap;
4792 TopExp::MapShapes( aMainShape, aMap );
4793 myIsSubshape = IsSubShape( aMap, myShape );
4797 TopExp::MapShapes( myShape, aMap );
4798 mySubShapesIDs.Clear();
4799 for ( int i = 1; i <= aMap.Extent(); ++i )
4801 int subID = myMeshDS->ShapeToIndex( aMap( i ));
4803 mySubShapesIDs.Add( subID );
4808 //if (!myIsSubshape) // to be always ready to check an element not bound to geometry
4810 if ( !myElementsOnShapePtr )
4811 myElementsOnShapePtr.reset( new ElementsOnShape() );
4812 myElementsOnShapePtr->SetTolerance( myTolerance );
4813 myElementsOnShapePtr->SetAllNodes( true ); // "belong", while false means "lays on"
4814 myElementsOnShapePtr->SetMesh( myMeshDS );
4815 myElementsOnShapePtr->SetShape( myShape, myType );
4819 bool BelongToGeom::IsSatisfy (long theId)
4821 if (myMeshDS == 0 || myShape.IsNull())
4826 return myElementsOnShapePtr->IsSatisfy(theId);
4831 if (myType == SMDSAbs_Node)
4833 if ( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ))
4835 if ( aNode->getshapeId() < 1 )
4836 return myElementsOnShapePtr->IsSatisfy(theId);
4838 return mySubShapesIDs.Contains( aNode->getshapeId() );
4843 if ( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ))
4845 if ( anElem->GetType() == myType )
4847 if ( anElem->getshapeId() < 1 )
4848 return myElementsOnShapePtr->IsSatisfy(theId);
4850 return mySubShapesIDs.Contains( anElem->getshapeId() );
4858 void BelongToGeom::SetType (SMDSAbs_ElementType theType)
4860 if ( myType != theType )
4867 SMDSAbs_ElementType BelongToGeom::GetType() const
4872 TopoDS_Shape BelongToGeom::GetShape()
4877 const SMESHDS_Mesh* BelongToGeom::GetMeshDS() const
4882 void BelongToGeom::SetTolerance (double theTolerance)
4884 myTolerance = theTolerance;
4888 double BelongToGeom::GetTolerance()
4895 Description : Predicate for verifying whether entiy lying or partially lying on
4896 specified geometrical support
4899 LyingOnGeom::LyingOnGeom()
4901 myType(SMDSAbs_NbElementTypes),
4902 myIsSubshape(false),
4903 myTolerance(Precision::Confusion())
4906 Predicate* LyingOnGeom::clone() const
4908 LyingOnGeom* cln = new LyingOnGeom( *this );
4909 cln->myElementsOnShapePtr.reset( static_cast<ElementsOnShape*>( myElementsOnShapePtr->clone() ));
4913 void LyingOnGeom::SetMesh( const SMDS_Mesh* theMesh )
4915 if ( myMeshDS != theMesh )
4917 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
4922 void LyingOnGeom::SetGeom( const TopoDS_Shape& theShape )
4924 if ( myShape != theShape )
4931 void LyingOnGeom::init()
4933 if (!myMeshDS || myShape.IsNull()) return;
4935 // is sub-shape of main shape?
4936 TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
4937 if (aMainShape.IsNull()) {
4938 myIsSubshape = false;
4941 myIsSubshape = myMeshDS->IsGroupOfSubShapes( myShape );
4946 TopTools_IndexedMapOfShape shapes;
4947 TopExp::MapShapes( myShape, shapes );
4948 mySubShapesIDs.Clear();
4949 for ( int i = 1; i <= shapes.Extent(); ++i )
4951 int subID = myMeshDS->ShapeToIndex( shapes( i ));
4953 mySubShapesIDs.Add( subID );
4956 // else // to be always ready to check an element not bound to geometry
4958 if ( !myElementsOnShapePtr )
4959 myElementsOnShapePtr.reset( new ElementsOnShape() );
4960 myElementsOnShapePtr->SetTolerance( myTolerance );
4961 myElementsOnShapePtr->SetAllNodes( false ); // lays on, while true means "belong"
4962 myElementsOnShapePtr->SetMesh( myMeshDS );
4963 myElementsOnShapePtr->SetShape( myShape, myType );
4967 bool LyingOnGeom::IsSatisfy( long theId )
4969 if ( myMeshDS == 0 || myShape.IsNull() )
4974 return myElementsOnShapePtr->IsSatisfy(theId);
4979 const SMDS_MeshElement* elem =
4980 ( myType == SMDSAbs_Node ) ? myMeshDS->FindNode( theId ) : myMeshDS->FindElement( theId );
4982 if ( mySubShapesIDs.Contains( elem->getshapeId() ))
4985 if ( elem->GetType() != SMDSAbs_Node && elem->GetType() == myType )
4987 SMDS_ElemIteratorPtr nodeItr = elem->nodesIterator();
4988 while ( nodeItr->more() )
4990 const SMDS_MeshElement* aNode = nodeItr->next();
4991 if ( mySubShapesIDs.Contains( aNode->getshapeId() ))
4999 void LyingOnGeom::SetType( SMDSAbs_ElementType theType )
5001 if ( myType != theType )
5008 SMDSAbs_ElementType LyingOnGeom::GetType() const
5013 TopoDS_Shape LyingOnGeom::GetShape()
5018 const SMESHDS_Mesh* LyingOnGeom::GetMeshDS() const
5023 void LyingOnGeom::SetTolerance (double theTolerance)
5025 myTolerance = theTolerance;
5029 double LyingOnGeom::GetTolerance()
5034 TSequenceOfXYZ::TSequenceOfXYZ(): myElem(0)
5037 TSequenceOfXYZ::TSequenceOfXYZ(size_type n) : myArray(n), myElem(0)
5040 TSequenceOfXYZ::TSequenceOfXYZ(size_type n, const gp_XYZ& t) : myArray(n,t), myElem(0)
5043 TSequenceOfXYZ::TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ) : myArray(theSequenceOfXYZ.myArray), myElem(theSequenceOfXYZ.myElem)
5046 template <class InputIterator>
5047 TSequenceOfXYZ::TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd): myArray(theBegin,theEnd), myElem(0)
5050 TSequenceOfXYZ::~TSequenceOfXYZ()
5053 TSequenceOfXYZ& TSequenceOfXYZ::operator=(const TSequenceOfXYZ& theSequenceOfXYZ)
5055 myArray = theSequenceOfXYZ.myArray;
5056 myElem = theSequenceOfXYZ.myElem;
5060 gp_XYZ& TSequenceOfXYZ::operator()(size_type n)
5062 return myArray[n-1];
5065 const gp_XYZ& TSequenceOfXYZ::operator()(size_type n) const
5067 return myArray[n-1];
5070 void TSequenceOfXYZ::clear()
5075 void TSequenceOfXYZ::reserve(size_type n)
5080 void TSequenceOfXYZ::push_back(const gp_XYZ& v)
5082 myArray.push_back(v);
5085 TSequenceOfXYZ::size_type TSequenceOfXYZ::size() const
5087 return myArray.size();
5090 SMDSAbs_EntityType TSequenceOfXYZ::getElementEntity() const
5092 return myElem ? myElem->GetEntityType() : SMDSEntity_Last;
5095 TMeshModifTracer::TMeshModifTracer():
5096 myMeshModifTime(0), myMesh(0)
5099 void TMeshModifTracer::SetMesh( const SMDS_Mesh* theMesh )
5101 if ( theMesh != myMesh )
5102 myMeshModifTime = 0;
5105 bool TMeshModifTracer::IsMeshModified()
5107 bool modified = false;
5110 modified = ( myMeshModifTime != myMesh->GetMTime() );
5111 myMeshModifTime = myMesh->GetMTime();