1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "SMESH_ControlsDef.hxx"
25 #include "SMDS_BallElement.hxx"
26 #include "SMDS_FacePosition.hxx"
27 #include "SMDS_Iterator.hxx"
28 #include "SMDS_Mesh.hxx"
29 #include "SMDS_MeshElement.hxx"
30 #include "SMDS_MeshNode.hxx"
31 #include "SMDS_QuadraticEdge.hxx"
32 #include "SMDS_QuadraticFaceOfNodes.hxx"
33 #include "SMDS_VolumeTool.hxx"
34 #include "SMESHDS_GroupBase.hxx"
35 #include "SMESHDS_GroupOnFilter.hxx"
36 #include "SMESHDS_Mesh.hxx"
37 #include "SMESH_MeshAlgos.hxx"
38 #include "SMESH_OctreeNode.hxx"
40 #include <Basics_Utils.hxx>
42 #include <BRepAdaptor_Surface.hxx>
43 #include <BRepBndLib.hxx>
44 #include <BRepBuilderAPI_Copy.hxx>
45 #include <BRepClass3d_SolidClassifier.hxx>
46 #include <BRepClass_FaceClassifier.hxx>
47 #include <BRep_Tool.hxx>
48 #include <Geom_CylindricalSurface.hxx>
49 #include <Geom_Plane.hxx>
50 #include <Geom_Surface.hxx>
51 #include <NCollection_Map.hxx>
52 #include <Precision.hxx>
53 #include <ShapeAnalysis_Surface.hxx>
54 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
55 #include <TColStd_MapOfInteger.hxx>
56 #include <TColStd_SequenceOfAsciiString.hxx>
57 #include <TColgp_Array1OfXYZ.hxx>
61 #include <TopoDS_Edge.hxx>
62 #include <TopoDS_Face.hxx>
63 #include <TopoDS_Iterator.hxx>
64 #include <TopoDS_Shape.hxx>
65 #include <TopoDS_Vertex.hxx>
67 #include <gp_Cylinder.hxx>
74 #include <vtkMeshQuality.h>
85 const double theEps = 1e-100;
86 const double theInf = 1e+100;
88 inline gp_XYZ gpXYZ(const SMDS_MeshNode* aNode )
90 return gp_XYZ(aNode->X(), aNode->Y(), aNode->Z() );
93 inline double getAngle( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
95 gp_Vec v1( P1 - P2 ), v2( P3 - P2 );
97 return v1.Magnitude() < gp::Resolution() ||
98 v2.Magnitude() < gp::Resolution() ? 0 : v1.Angle( v2 );
101 inline double getArea( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
103 gp_Vec aVec1( P2 - P1 );
104 gp_Vec aVec2( P3 - P1 );
105 return ( aVec1 ^ aVec2 ).Magnitude() * 0.5;
108 inline double getArea( const gp_Pnt& P1, const gp_Pnt& P2, const gp_Pnt& P3 )
110 return getArea( P1.XYZ(), P2.XYZ(), P3.XYZ() );
115 inline double getDistance( const gp_XYZ& P1, const gp_XYZ& P2 )
117 double aDist = gp_Pnt( P1 ).Distance( gp_Pnt( P2 ) );
121 int getNbMultiConnection( const SMDS_Mesh* theMesh, const int theId )
126 const SMDS_MeshElement* anEdge = theMesh->FindElement( theId );
127 if ( anEdge == 0 || anEdge->GetType() != SMDSAbs_Edge/* || anEdge->NbNodes() != 2 */)
130 // for each pair of nodes in anEdge (there are 2 pairs in a quadratic edge)
131 // count elements containing both nodes of the pair.
132 // Note that there may be such cases for a quadratic edge (a horizontal line):
137 // +-----+------+ +-----+------+
140 // result should be 2 in both cases
142 int aResult0 = 0, aResult1 = 0;
143 // last node, it is a medium one in a quadratic edge
144 const SMDS_MeshNode* aLastNode = anEdge->GetNode( anEdge->NbNodes() - 1 );
145 const SMDS_MeshNode* aNode0 = anEdge->GetNode( 0 );
146 const SMDS_MeshNode* aNode1 = anEdge->GetNode( 1 );
147 if ( aNode1 == aLastNode ) aNode1 = 0;
149 SMDS_ElemIteratorPtr anElemIter = aLastNode->GetInverseElementIterator();
150 while( anElemIter->more() ) {
151 const SMDS_MeshElement* anElem = anElemIter->next();
152 if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) {
153 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
154 while ( anIter->more() ) {
155 if ( const SMDS_MeshElement* anElemNode = anIter->next() ) {
156 if ( anElemNode == aNode0 ) {
158 if ( !aNode1 ) break; // not a quadratic edge
160 else if ( anElemNode == aNode1 )
166 int aResult = std::max ( aResult0, aResult1 );
171 gp_XYZ getNormale( const SMDS_MeshFace* theFace, bool* ok=0 )
173 int aNbNode = theFace->NbNodes();
175 gp_XYZ q1 = gpXYZ( theFace->GetNode(1)) - gpXYZ( theFace->GetNode(0));
176 gp_XYZ q2 = gpXYZ( theFace->GetNode(2)) - gpXYZ( theFace->GetNode(0));
179 gp_XYZ q3 = gpXYZ( theFace->GetNode(3)) - gpXYZ( theFace->GetNode(0));
182 double len = n.Modulus();
183 bool zeroLen = ( len <= std::numeric_limits<double>::min());
187 if (ok) *ok = !zeroLen;
195 using namespace SMESH::Controls;
201 //================================================================================
203 Class : NumericalFunctor
204 Description : Base class for numerical functors
206 //================================================================================
208 NumericalFunctor::NumericalFunctor():
214 void NumericalFunctor::SetMesh( const SMDS_Mesh* theMesh )
219 bool NumericalFunctor::GetPoints(const int theId,
220 TSequenceOfXYZ& theRes ) const
227 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
228 if ( !anElem || anElem->GetType() != this->GetType() )
231 return GetPoints( anElem, theRes );
234 bool NumericalFunctor::GetPoints(const SMDS_MeshElement* anElem,
235 TSequenceOfXYZ& theRes )
242 theRes.reserve( anElem->NbNodes() );
243 theRes.setElement( anElem );
245 // Get nodes of the element
246 SMDS_ElemIteratorPtr anIter;
248 if ( anElem->IsQuadratic() ) {
249 switch ( anElem->GetType() ) {
251 anIter = dynamic_cast<const SMDS_VtkEdge*>
252 (anElem)->interlacedNodesElemIterator();
255 anIter = dynamic_cast<const SMDS_VtkFace*>
256 (anElem)->interlacedNodesElemIterator();
259 anIter = anElem->nodesIterator();
263 anIter = anElem->nodesIterator();
268 while( anIter->more() ) {
269 if ( p.Set( anIter->next() ))
270 theRes.push_back( p );
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( const TSequenceOfXYZ& P )
1560 SMDSAbs_EntityType aType = P.getElementEntity();
1563 case SMDSEntity_Edge:
1565 aVal = getDistance( P( 1 ), P( 2 ) );
1567 case SMDSEntity_Quad_Edge:
1568 if (len == 3) // quadratic edge
1569 aVal = getDistance(P( 1 ),P( 3 )) + getDistance(P( 3 ),P( 2 ));
1571 case SMDSEntity_Triangle:
1572 if (len == 3){ // triangles
1573 double L1 = getDistance(P( 1 ),P( 2 ));
1574 double L2 = getDistance(P( 2 ),P( 3 ));
1575 double L3 = getDistance(P( 3 ),P( 1 ));
1576 aVal = Min(L1,Min(L2,L3));
1579 case SMDSEntity_Quadrangle:
1580 if (len == 4){ // quadrangles
1581 double L1 = getDistance(P( 1 ),P( 2 ));
1582 double L2 = getDistance(P( 2 ),P( 3 ));
1583 double L3 = getDistance(P( 3 ),P( 4 ));
1584 double L4 = getDistance(P( 4 ),P( 1 ));
1585 aVal = Min(Min(L1,L2),Min(L3,L4));
1588 case SMDSEntity_Quad_Triangle:
1589 case SMDSEntity_BiQuad_Triangle:
1590 if (len >= 6){ // quadratic triangles
1591 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1592 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1593 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 1 ));
1594 aVal = Min(L1,Min(L2,L3));
1597 case SMDSEntity_Quad_Quadrangle:
1598 case SMDSEntity_BiQuad_Quadrangle:
1599 if (len >= 8){ // quadratic quadrangles
1600 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1601 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1602 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 7 ));
1603 double L4 = getDistance(P( 7 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
1604 aVal = Min(Min(L1,L2),Min(L3,L4));
1607 case SMDSEntity_Tetra:
1608 if (len == 4){ // tetrahedra
1609 double L1 = getDistance(P( 1 ),P( 2 ));
1610 double L2 = getDistance(P( 2 ),P( 3 ));
1611 double L3 = getDistance(P( 3 ),P( 1 ));
1612 double L4 = getDistance(P( 1 ),P( 4 ));
1613 double L5 = getDistance(P( 2 ),P( 4 ));
1614 double L6 = getDistance(P( 3 ),P( 4 ));
1615 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1618 case SMDSEntity_Pyramid:
1619 if (len == 5){ // pyramid
1620 double L1 = getDistance(P( 1 ),P( 2 ));
1621 double L2 = getDistance(P( 2 ),P( 3 ));
1622 double L3 = getDistance(P( 3 ),P( 4 ));
1623 double L4 = getDistance(P( 4 ),P( 1 ));
1624 double L5 = getDistance(P( 1 ),P( 5 ));
1625 double L6 = getDistance(P( 2 ),P( 5 ));
1626 double L7 = getDistance(P( 3 ),P( 5 ));
1627 double L8 = getDistance(P( 4 ),P( 5 ));
1629 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1630 aVal = Min(aVal,Min(L7,L8));
1633 case SMDSEntity_Penta:
1634 if (len == 6) { // pentahedron
1635 double L1 = getDistance(P( 1 ),P( 2 ));
1636 double L2 = getDistance(P( 2 ),P( 3 ));
1637 double L3 = getDistance(P( 3 ),P( 1 ));
1638 double L4 = getDistance(P( 4 ),P( 5 ));
1639 double L5 = getDistance(P( 5 ),P( 6 ));
1640 double L6 = getDistance(P( 6 ),P( 4 ));
1641 double L7 = getDistance(P( 1 ),P( 4 ));
1642 double L8 = getDistance(P( 2 ),P( 5 ));
1643 double L9 = getDistance(P( 3 ),P( 6 ));
1645 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1646 aVal = Min(aVal,Min(Min(L7,L8),L9));
1649 case SMDSEntity_Hexa:
1650 if (len == 8){ // hexahedron
1651 double L1 = getDistance(P( 1 ),P( 2 ));
1652 double L2 = getDistance(P( 2 ),P( 3 ));
1653 double L3 = getDistance(P( 3 ),P( 4 ));
1654 double L4 = getDistance(P( 4 ),P( 1 ));
1655 double L5 = getDistance(P( 5 ),P( 6 ));
1656 double L6 = getDistance(P( 6 ),P( 7 ));
1657 double L7 = getDistance(P( 7 ),P( 8 ));
1658 double L8 = getDistance(P( 8 ),P( 5 ));
1659 double L9 = getDistance(P( 1 ),P( 5 ));
1660 double L10= getDistance(P( 2 ),P( 6 ));
1661 double L11= getDistance(P( 3 ),P( 7 ));
1662 double L12= getDistance(P( 4 ),P( 8 ));
1664 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1665 aVal = Min(aVal,Min(Min(L7,L8),Min(L9,L10)));
1666 aVal = Min(aVal,Min(L11,L12));
1669 case SMDSEntity_Quad_Tetra:
1670 if (len == 10){ // quadratic tetrahedron
1671 double L1 = getDistance(P( 1 ),P( 5 )) + getDistance(P( 5 ),P( 2 ));
1672 double L2 = getDistance(P( 2 ),P( 6 )) + getDistance(P( 6 ),P( 3 ));
1673 double L3 = getDistance(P( 3 ),P( 7 )) + getDistance(P( 7 ),P( 1 ));
1674 double L4 = getDistance(P( 1 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
1675 double L5 = getDistance(P( 2 ),P( 9 )) + getDistance(P( 9 ),P( 4 ));
1676 double L6 = getDistance(P( 3 ),P( 10 )) + getDistance(P( 10 ),P( 4 ));
1677 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1680 case SMDSEntity_Quad_Pyramid:
1681 if (len == 13){ // quadratic pyramid
1682 double L1 = getDistance(P( 1 ),P( 6 )) + getDistance(P( 6 ),P( 2 ));
1683 double L2 = getDistance(P( 2 ),P( 7 )) + getDistance(P( 7 ),P( 3 ));
1684 double L3 = getDistance(P( 3 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
1685 double L4 = getDistance(P( 4 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1686 double L5 = getDistance(P( 1 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1687 double L6 = getDistance(P( 2 ),P( 11 )) + getDistance(P( 11 ),P( 5 ));
1688 double L7 = getDistance(P( 3 ),P( 12 )) + getDistance(P( 12 ),P( 5 ));
1689 double L8 = getDistance(P( 4 ),P( 13 )) + getDistance(P( 13 ),P( 5 ));
1690 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1691 aVal = Min(aVal,Min(L7,L8));
1694 case SMDSEntity_Quad_Penta:
1695 case SMDSEntity_BiQuad_Penta:
1696 if (len >= 15){ // quadratic pentahedron
1697 double L1 = getDistance(P( 1 ),P( 7 )) + getDistance(P( 7 ),P( 2 ));
1698 double L2 = getDistance(P( 2 ),P( 8 )) + getDistance(P( 8 ),P( 3 ));
1699 double L3 = getDistance(P( 3 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1700 double L4 = getDistance(P( 4 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1701 double L5 = getDistance(P( 5 ),P( 11 )) + getDistance(P( 11 ),P( 6 ));
1702 double L6 = getDistance(P( 6 ),P( 12 )) + getDistance(P( 12 ),P( 4 ));
1703 double L7 = getDistance(P( 1 ),P( 13 )) + getDistance(P( 13 ),P( 4 ));
1704 double L8 = getDistance(P( 2 ),P( 14 )) + getDistance(P( 14 ),P( 5 ));
1705 double L9 = getDistance(P( 3 ),P( 15 )) + getDistance(P( 15 ),P( 6 ));
1706 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1707 aVal = Min(aVal,Min(Min(L7,L8),L9));
1710 case SMDSEntity_Quad_Hexa:
1711 case SMDSEntity_TriQuad_Hexa:
1712 if (len >= 20) { // quadratic hexahedron
1713 double L1 = getDistance(P( 1 ),P( 9 )) + getDistance(P( 9 ),P( 2 ));
1714 double L2 = getDistance(P( 2 ),P( 10 )) + getDistance(P( 10 ),P( 3 ));
1715 double L3 = getDistance(P( 3 ),P( 11 )) + getDistance(P( 11 ),P( 4 ));
1716 double L4 = getDistance(P( 4 ),P( 12 )) + getDistance(P( 12 ),P( 1 ));
1717 double L5 = getDistance(P( 5 ),P( 13 )) + getDistance(P( 13 ),P( 6 ));
1718 double L6 = getDistance(P( 6 ),P( 14 )) + getDistance(P( 14 ),P( 7 ));
1719 double L7 = getDistance(P( 7 ),P( 15 )) + getDistance(P( 15 ),P( 8 ));
1720 double L8 = getDistance(P( 8 ),P( 16 )) + getDistance(P( 16 ),P( 5 ));
1721 double L9 = getDistance(P( 1 ),P( 17 )) + getDistance(P( 17 ),P( 5 ));
1722 double L10= getDistance(P( 2 ),P( 18 )) + getDistance(P( 18 ),P( 6 ));
1723 double L11= getDistance(P( 3 ),P( 19 )) + getDistance(P( 19 ),P( 7 ));
1724 double L12= getDistance(P( 4 ),P( 20 )) + getDistance(P( 20 ),P( 8 ));
1725 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1726 aVal = Min(aVal,Min(Min(L7,L8),Min(L9,L10)));
1727 aVal = Min(aVal,Min(L11,L12));
1730 case SMDSEntity_Polygon:
1732 aVal = getDistance( P(1), P( P.size() ));
1733 for ( size_t i = 1; i < P.size(); ++i )
1734 aVal = Min( aVal, getDistance( P( i ), P( i+1 )));
1737 case SMDSEntity_Quad_Polygon:
1739 aVal = getDistance( P(1), P( P.size() )) + getDistance( P(P.size()), P( P.size()-1 ));
1740 for ( size_t i = 1; i < P.size()-1; i += 2 )
1741 aVal = Min( aVal, getDistance( P( i ), P( i+1 )) + getDistance( P( i+1 ), P( i+2 )));
1744 case SMDSEntity_Hexagonal_Prism:
1745 if (len == 12) { // hexagonal prism
1746 double L1 = getDistance(P( 1 ),P( 2 ));
1747 double L2 = getDistance(P( 2 ),P( 3 ));
1748 double L3 = getDistance(P( 3 ),P( 4 ));
1749 double L4 = getDistance(P( 4 ),P( 5 ));
1750 double L5 = getDistance(P( 5 ),P( 6 ));
1751 double L6 = getDistance(P( 6 ),P( 1 ));
1753 double L7 = getDistance(P( 7 ), P( 8 ));
1754 double L8 = getDistance(P( 8 ), P( 9 ));
1755 double L9 = getDistance(P( 9 ), P( 10 ));
1756 double L10= getDistance(P( 10 ),P( 11 ));
1757 double L11= getDistance(P( 11 ),P( 12 ));
1758 double L12= getDistance(P( 12 ),P( 7 ));
1760 double L13 = getDistance(P( 1 ),P( 7 ));
1761 double L14 = getDistance(P( 2 ),P( 8 ));
1762 double L15 = getDistance(P( 3 ),P( 9 ));
1763 double L16 = getDistance(P( 4 ),P( 10 ));
1764 double L17 = getDistance(P( 5 ),P( 11 ));
1765 double L18 = getDistance(P( 6 ),P( 12 ));
1766 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1767 aVal = Min(aVal, Min(Min(Min(L7,L8),Min(L9,L10)),Min(L11,L12)));
1768 aVal = Min(aVal, Min(Min(Min(L13,L14),Min(L15,L16)),Min(L17,L18)));
1771 case SMDSEntity_Polyhedra:
1783 if ( myPrecision >= 0 )
1785 double prec = pow( 10., (double)( myPrecision ) );
1786 aVal = floor( aVal * prec + 0.5 ) / prec;
1792 double Length2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1794 // meaningless as it is not a quality control functor
1798 SMDSAbs_ElementType Length2D::GetType() const
1800 return SMDSAbs_Face;
1803 Length2D::Value::Value(double theLength,long thePntId1, long thePntId2):
1806 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1807 if(thePntId1 > thePntId2){
1808 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1812 bool Length2D::Value::operator<(const Length2D::Value& x) const
1814 if(myPntId[0] < x.myPntId[0]) return true;
1815 if(myPntId[0] == x.myPntId[0])
1816 if(myPntId[1] < x.myPntId[1]) return true;
1820 void Length2D::GetValues(TValues& theValues)
1823 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1824 for(; anIter->more(); ){
1825 const SMDS_MeshFace* anElem = anIter->next();
1827 if(anElem->IsQuadratic()) {
1828 const SMDS_VtkFace* F =
1829 dynamic_cast<const SMDS_VtkFace*>(anElem);
1830 // use special nodes iterator
1831 SMDS_ElemIteratorPtr anIter = F->interlacedNodesElemIterator();
1832 long aNodeId[4] = { 0,0,0,0 };
1836 const SMDS_MeshElement* aNode;
1838 aNode = anIter->next();
1839 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1840 P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1841 aNodeId[0] = aNodeId[1] = aNode->GetID();
1844 for(; anIter->more(); ){
1845 const SMDS_MeshNode* N1 = static_cast<const SMDS_MeshNode*> (anIter->next());
1846 P[2] = gp_Pnt(N1->X(),N1->Y(),N1->Z());
1847 aNodeId[2] = N1->GetID();
1848 aLength = P[1].Distance(P[2]);
1849 if(!anIter->more()) break;
1850 const SMDS_MeshNode* N2 = static_cast<const SMDS_MeshNode*> (anIter->next());
1851 P[3] = gp_Pnt(N2->X(),N2->Y(),N2->Z());
1852 aNodeId[3] = N2->GetID();
1853 aLength += P[2].Distance(P[3]);
1854 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1855 Value aValue2(aLength,aNodeId[2],aNodeId[3]);
1857 aNodeId[1] = aNodeId[3];
1858 theValues.insert(aValue1);
1859 theValues.insert(aValue2);
1861 aLength += P[2].Distance(P[0]);
1862 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1863 Value aValue2(aLength,aNodeId[2],aNodeId[0]);
1864 theValues.insert(aValue1);
1865 theValues.insert(aValue2);
1868 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
1869 long aNodeId[2] = {0,0};
1873 const SMDS_MeshElement* aNode;
1874 if(aNodesIter->more()){
1875 aNode = aNodesIter->next();
1876 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1877 P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1878 aNodeId[0] = aNodeId[1] = aNode->GetID();
1881 for(; aNodesIter->more(); ){
1882 aNode = aNodesIter->next();
1883 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1884 long anId = aNode->GetID();
1886 P[2] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1888 aLength = P[1].Distance(P[2]);
1890 Value aValue(aLength,aNodeId[1],anId);
1893 theValues.insert(aValue);
1896 aLength = P[0].Distance(P[1]);
1898 Value aValue(aLength,aNodeId[0],aNodeId[1]);
1899 theValues.insert(aValue);
1904 //================================================================================
1906 Class : Deflection2D
1907 Description : Functor for calculating number of faces conneted to the edge
1909 //================================================================================
1911 double Deflection2D::GetValue( const TSequenceOfXYZ& P )
1913 if ( myMesh && P.getElement() )
1915 // get underlying surface
1916 if ( myShapeIndex != P.getElement()->getshapeId() )
1918 mySurface.Nullify();
1919 myShapeIndex = P.getElement()->getshapeId();
1920 const TopoDS_Shape& S =
1921 static_cast< const SMESHDS_Mesh* >( myMesh )->IndexToShape( myShapeIndex );
1922 if ( !S.IsNull() && S.ShapeType() == TopAbs_FACE )
1924 mySurface = new ShapeAnalysis_Surface( BRep_Tool::Surface( TopoDS::Face( S )));
1927 // project gravity center to the surface
1928 if ( !mySurface.IsNull() )
1933 for ( size_t i = 0; i < P.size(); ++i )
1937 if ( const SMDS_FacePosition* fPos = dynamic_cast<const SMDS_FacePosition*>
1938 ( P.getElement()->GetNode( i )->GetPosition() ))
1940 uv.ChangeCoord(1) += fPos->GetUParameter();
1941 uv.ChangeCoord(2) += fPos->GetVParameter();
1946 if ( nbUV ) uv /= nbUV;
1948 double maxLen = MaxElementLength2D().GetValue( P );
1949 double tol = 1e-3 * maxLen;
1950 if ( uv.X() != 0 && uv.Y() != 0 ) // faster way
1951 mySurface->NextValueOfUV( uv, gc, tol, 0.5 * maxLen );
1953 mySurface->ValueOfUV( gc, tol );
1955 return Round( mySurface->Gap() );
1961 void Deflection2D::SetMesh( const SMDS_Mesh* theMesh )
1963 NumericalFunctor::SetMesh( dynamic_cast<const SMESHDS_Mesh* >( theMesh ));
1964 myShapeIndex = -100;
1967 SMDSAbs_ElementType Deflection2D::GetType() const
1969 return SMDSAbs_Face;
1972 double Deflection2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1974 // meaningless as it is not quality control functor
1978 //================================================================================
1980 Class : MultiConnection
1981 Description : Functor for calculating number of faces conneted to the edge
1983 //================================================================================
1985 double MultiConnection::GetValue( const TSequenceOfXYZ& P )
1989 double MultiConnection::GetValue( long theId )
1991 return getNbMultiConnection( myMesh, theId );
1994 double MultiConnection::GetBadRate( double Value, int /*nbNodes*/ ) const
1996 // meaningless as it is not quality control functor
2000 SMDSAbs_ElementType MultiConnection::GetType() const
2002 return SMDSAbs_Edge;
2005 //================================================================================
2007 Class : MultiConnection2D
2008 Description : Functor for calculating number of faces conneted to the edge
2010 //================================================================================
2012 double MultiConnection2D::GetValue( const TSequenceOfXYZ& P )
2017 double MultiConnection2D::GetValue( long theElementId )
2021 const SMDS_MeshElement* aFaceElem = myMesh->FindElement(theElementId);
2022 SMDSAbs_ElementType aType = aFaceElem->GetType();
2027 int i = 0, len = aFaceElem->NbNodes();
2028 SMDS_ElemIteratorPtr anIter = aFaceElem->nodesIterator();
2031 const SMDS_MeshNode *aNode, *aNode0 = 0;
2032 TColStd_MapOfInteger aMap, aMapPrev;
2034 for (i = 0; i <= len; i++) {
2039 if (anIter->more()) {
2040 aNode = (SMDS_MeshNode*)anIter->next();
2048 if (i == 0) aNode0 = aNode;
2050 SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator();
2051 while (anElemIter->more()) {
2052 const SMDS_MeshElement* anElem = anElemIter->next();
2053 if (anElem != 0 && anElem->GetType() == SMDSAbs_Face) {
2054 int anId = anElem->GetID();
2057 if (aMapPrev.Contains(anId)) {
2062 aResult = Max(aResult, aNb);
2073 double MultiConnection2D::GetBadRate( double Value, int /*nbNodes*/ ) const
2075 // meaningless as it is not quality control functor
2079 SMDSAbs_ElementType MultiConnection2D::GetType() const
2081 return SMDSAbs_Face;
2084 MultiConnection2D::Value::Value(long thePntId1, long thePntId2)
2086 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
2087 if(thePntId1 > thePntId2){
2088 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
2092 bool MultiConnection2D::Value::operator<(const MultiConnection2D::Value& x) const
2094 if(myPntId[0] < x.myPntId[0]) return true;
2095 if(myPntId[0] == x.myPntId[0])
2096 if(myPntId[1] < x.myPntId[1]) return true;
2100 void MultiConnection2D::GetValues(MValues& theValues)
2102 if ( !myMesh ) return;
2103 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
2104 for(; anIter->more(); ){
2105 const SMDS_MeshFace* anElem = anIter->next();
2106 SMDS_ElemIteratorPtr aNodesIter;
2107 if ( anElem->IsQuadratic() )
2108 aNodesIter = dynamic_cast<const SMDS_VtkFace*>
2109 (anElem)->interlacedNodesElemIterator();
2111 aNodesIter = anElem->nodesIterator();
2112 long aNodeId[3] = {0,0,0};
2114 //int aNbConnects=0;
2115 const SMDS_MeshNode* aNode0;
2116 const SMDS_MeshNode* aNode1;
2117 const SMDS_MeshNode* aNode2;
2118 if(aNodesIter->more()){
2119 aNode0 = (SMDS_MeshNode*) aNodesIter->next();
2121 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode1;
2122 aNodeId[0] = aNodeId[1] = aNodes->GetID();
2124 for(; aNodesIter->more(); ) {
2125 aNode2 = (SMDS_MeshNode*) aNodesIter->next();
2126 long anId = aNode2->GetID();
2129 Value aValue(aNodeId[1],aNodeId[2]);
2130 MValues::iterator aItr = theValues.find(aValue);
2131 if (aItr != theValues.end()){
2136 theValues[aValue] = 1;
2139 //cout << "NodeIds: "<<aNodeId[1]<<","<<aNodeId[2]<<" nbconn="<<aNbConnects<<endl;
2140 aNodeId[1] = aNodeId[2];
2143 Value aValue(aNodeId[0],aNodeId[2]);
2144 MValues::iterator aItr = theValues.find(aValue);
2145 if (aItr != theValues.end()) {
2150 theValues[aValue] = 1;
2153 //cout << "NodeIds: "<<aNodeId[0]<<","<<aNodeId[2]<<" nbconn="<<aNbConnects<<endl;
2158 //================================================================================
2160 Class : BallDiameter
2161 Description : Functor returning diameter of a ball element
2163 //================================================================================
2165 double BallDiameter::GetValue( long theId )
2167 double diameter = 0;
2169 if ( const SMDS_BallElement* ball =
2170 dynamic_cast<const SMDS_BallElement*>( myMesh->FindElement( theId )))
2172 diameter = ball->GetDiameter();
2177 double BallDiameter::GetBadRate( double Value, int /*nbNodes*/ ) const
2179 // meaningless as it is not a quality control functor
2183 SMDSAbs_ElementType BallDiameter::GetType() const
2185 return SMDSAbs_Ball;
2188 //================================================================================
2190 Class : NodeConnectivityNumber
2191 Description : Functor returning number of elements connected to a node
2193 //================================================================================
2195 double NodeConnectivityNumber::GetValue( long theId )
2199 if ( const SMDS_MeshNode* node = myMesh->FindNode( theId ))
2201 SMDSAbs_ElementType type;
2202 if ( myMesh->NbVolumes() > 0 )
2203 type = SMDSAbs_Volume;
2204 else if ( myMesh->NbFaces() > 0 )
2205 type = SMDSAbs_Face;
2206 else if ( myMesh->NbEdges() > 0 )
2207 type = SMDSAbs_Edge;
2210 nb = node->NbInverseElements( type );
2215 double NodeConnectivityNumber::GetBadRate( double Value, int /*nbNodes*/ ) const
2220 SMDSAbs_ElementType NodeConnectivityNumber::GetType() const
2222 return SMDSAbs_Node;
2229 //================================================================================
2231 Class : BadOrientedVolume
2232 Description : Predicate bad oriented volumes
2234 //================================================================================
2236 BadOrientedVolume::BadOrientedVolume()
2241 void BadOrientedVolume::SetMesh( const SMDS_Mesh* theMesh )
2246 bool BadOrientedVolume::IsSatisfy( long theId )
2251 SMDS_VolumeTool vTool( myMesh->FindElement( theId ));
2252 return !vTool.IsForward();
2255 SMDSAbs_ElementType BadOrientedVolume::GetType() const
2257 return SMDSAbs_Volume;
2261 Class : BareBorderVolume
2264 bool BareBorderVolume::IsSatisfy(long theElementId )
2266 SMDS_VolumeTool myTool;
2267 if ( myTool.Set( myMesh->FindElement(theElementId)))
2269 for ( int iF = 0; iF < myTool.NbFaces(); ++iF )
2270 if ( myTool.IsFreeFace( iF ))
2272 const SMDS_MeshNode** n = myTool.GetFaceNodes(iF);
2273 std::vector< const SMDS_MeshNode*> nodes( n, n+myTool.NbFaceNodes(iF));
2274 if ( !myMesh->FindElement( nodes, SMDSAbs_Face, /*Nomedium=*/false))
2281 //================================================================================
2283 Class : BareBorderFace
2285 //================================================================================
2287 bool BareBorderFace::IsSatisfy(long theElementId )
2290 if ( const SMDS_MeshElement* face = myMesh->FindElement(theElementId))
2292 if ( face->GetType() == SMDSAbs_Face )
2294 int nbN = face->NbCornerNodes();
2295 for ( int i = 0; i < nbN && !ok; ++i )
2297 // check if a link is shared by another face
2298 const SMDS_MeshNode* n1 = face->GetNode( i );
2299 const SMDS_MeshNode* n2 = face->GetNode( (i+1)%nbN );
2300 SMDS_ElemIteratorPtr fIt = n1->GetInverseElementIterator( SMDSAbs_Face );
2301 bool isShared = false;
2302 while ( !isShared && fIt->more() )
2304 const SMDS_MeshElement* f = fIt->next();
2305 isShared = ( f != face && f->GetNodeIndex(n2) != -1 );
2309 const int iQuad = face->IsQuadratic();
2310 myLinkNodes.resize( 2 + iQuad);
2311 myLinkNodes[0] = n1;
2312 myLinkNodes[1] = n2;
2314 myLinkNodes[2] = face->GetNode( i+nbN );
2315 ok = !myMesh->FindElement( myLinkNodes, SMDSAbs_Edge, /*noMedium=*/false);
2323 //================================================================================
2325 Class : OverConstrainedVolume
2327 //================================================================================
2329 bool OverConstrainedVolume::IsSatisfy(long theElementId )
2331 // An element is over-constrained if it has N-1 free borders where
2332 // N is the number of edges/faces for a 2D/3D element.
2333 SMDS_VolumeTool myTool;
2334 if ( myTool.Set( myMesh->FindElement(theElementId)))
2336 int nbSharedFaces = 0;
2337 for ( int iF = 0; iF < myTool.NbFaces(); ++iF )
2338 if ( !myTool.IsFreeFace( iF ) && ++nbSharedFaces > 1 )
2340 return ( nbSharedFaces == 1 );
2345 //================================================================================
2347 Class : OverConstrainedFace
2349 //================================================================================
2351 bool OverConstrainedFace::IsSatisfy(long theElementId )
2353 // An element is over-constrained if it has N-1 free borders where
2354 // N is the number of edges/faces for a 2D/3D element.
2355 if ( const SMDS_MeshElement* face = myMesh->FindElement(theElementId))
2356 if ( face->GetType() == SMDSAbs_Face )
2358 int nbSharedBorders = 0;
2359 int nbN = face->NbCornerNodes();
2360 for ( int i = 0; i < nbN; ++i )
2362 // check if a link is shared by another face
2363 const SMDS_MeshNode* n1 = face->GetNode( i );
2364 const SMDS_MeshNode* n2 = face->GetNode( (i+1)%nbN );
2365 SMDS_ElemIteratorPtr fIt = n1->GetInverseElementIterator( SMDSAbs_Face );
2366 bool isShared = false;
2367 while ( !isShared && fIt->more() )
2369 const SMDS_MeshElement* f = fIt->next();
2370 isShared = ( f != face && f->GetNodeIndex(n2) != -1 );
2372 if ( isShared && ++nbSharedBorders > 1 )
2375 return ( nbSharedBorders == 1 );
2380 //================================================================================
2382 Class : CoincidentNodes
2383 Description : Predicate of Coincident nodes
2385 //================================================================================
2387 CoincidentNodes::CoincidentNodes()
2392 bool CoincidentNodes::IsSatisfy( long theElementId )
2394 return myCoincidentIDs.Contains( theElementId );
2397 SMDSAbs_ElementType CoincidentNodes::GetType() const
2399 return SMDSAbs_Node;
2402 void CoincidentNodes::SetMesh( const SMDS_Mesh* theMesh )
2404 myMeshModifTracer.SetMesh( theMesh );
2405 if ( myMeshModifTracer.IsMeshModified() )
2407 TIDSortedNodeSet nodesToCheck;
2408 SMDS_NodeIteratorPtr nIt = theMesh->nodesIterator(/*idInceasingOrder=*/true);
2409 while ( nIt->more() )
2410 nodesToCheck.insert( nodesToCheck.end(), nIt->next() );
2412 std::list< std::list< const SMDS_MeshNode*> > nodeGroups;
2413 SMESH_OctreeNode::FindCoincidentNodes ( nodesToCheck, &nodeGroups, myToler );
2415 myCoincidentIDs.Clear();
2416 std::list< std::list< const SMDS_MeshNode*> >::iterator groupIt = nodeGroups.begin();
2417 for ( ; groupIt != nodeGroups.end(); ++groupIt )
2419 std::list< const SMDS_MeshNode*>& coincNodes = *groupIt;
2420 std::list< const SMDS_MeshNode*>::iterator n = coincNodes.begin();
2421 for ( ; n != coincNodes.end(); ++n )
2422 myCoincidentIDs.Add( (*n)->GetID() );
2427 //================================================================================
2429 Class : CoincidentElements
2430 Description : Predicate of Coincident Elements
2431 Note : This class is suitable only for visualization of Coincident Elements
2433 //================================================================================
2435 CoincidentElements::CoincidentElements()
2440 void CoincidentElements::SetMesh( const SMDS_Mesh* theMesh )
2445 bool CoincidentElements::IsSatisfy( long theElementId )
2447 if ( !myMesh ) return false;
2449 if ( const SMDS_MeshElement* e = myMesh->FindElement( theElementId ))
2451 if ( e->GetType() != GetType() ) return false;
2452 std::set< const SMDS_MeshNode* > elemNodes( e->begin_nodes(), e->end_nodes() );
2453 const int nbNodes = e->NbNodes();
2454 SMDS_ElemIteratorPtr invIt = (*elemNodes.begin())->GetInverseElementIterator( GetType() );
2455 while ( invIt->more() )
2457 const SMDS_MeshElement* e2 = invIt->next();
2458 if ( e2 == e || e2->NbNodes() != nbNodes ) continue;
2460 bool sameNodes = true;
2461 for ( size_t i = 0; i < elemNodes.size() && sameNodes; ++i )
2462 sameNodes = ( elemNodes.count( e2->GetNode( i )));
2470 SMDSAbs_ElementType CoincidentElements1D::GetType() const
2472 return SMDSAbs_Edge;
2474 SMDSAbs_ElementType CoincidentElements2D::GetType() const
2476 return SMDSAbs_Face;
2478 SMDSAbs_ElementType CoincidentElements3D::GetType() const
2480 return SMDSAbs_Volume;
2484 //================================================================================
2487 Description : Predicate for free borders
2489 //================================================================================
2491 FreeBorders::FreeBorders()
2496 void FreeBorders::SetMesh( const SMDS_Mesh* theMesh )
2501 bool FreeBorders::IsSatisfy( long theId )
2503 return getNbMultiConnection( myMesh, theId ) == 1;
2506 SMDSAbs_ElementType FreeBorders::GetType() const
2508 return SMDSAbs_Edge;
2512 //================================================================================
2515 Description : Predicate for free Edges
2517 //================================================================================
2519 FreeEdges::FreeEdges()
2524 void FreeEdges::SetMesh( const SMDS_Mesh* theMesh )
2529 bool FreeEdges::IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId )
2531 TColStd_MapOfInteger aMap;
2532 for ( int i = 0; i < 2; i++ )
2534 SMDS_ElemIteratorPtr anElemIter = theNodes[ i ]->GetInverseElementIterator(SMDSAbs_Face);
2535 while( anElemIter->more() )
2537 if ( const SMDS_MeshElement* anElem = anElemIter->next())
2539 const int anId = anElem->GetID();
2540 if ( anId != theFaceId && !aMap.Add( anId ))
2548 bool FreeEdges::IsSatisfy( long theId )
2553 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
2554 if ( aFace == 0 || aFace->GetType() != SMDSAbs_Face || aFace->NbNodes() < 3 )
2557 SMDS_NodeIteratorPtr anIter = aFace->interlacedNodesIterator();
2561 int i = 0, nbNodes = aFace->NbNodes();
2562 std::vector <const SMDS_MeshNode*> aNodes( nbNodes+1 );
2563 while( anIter->more() )
2564 if ( ! ( aNodes[ i++ ] = anIter->next() ))
2566 aNodes[ nbNodes ] = aNodes[ 0 ];
2568 for ( i = 0; i < nbNodes; i++ )
2569 if ( IsFreeEdge( &aNodes[ i ], theId ) )
2575 SMDSAbs_ElementType FreeEdges::GetType() const
2577 return SMDSAbs_Face;
2580 FreeEdges::Border::Border(long theElemId, long thePntId1, long thePntId2):
2583 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
2584 if(thePntId1 > thePntId2){
2585 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
2589 bool FreeEdges::Border::operator<(const FreeEdges::Border& x) const{
2590 if(myPntId[0] < x.myPntId[0]) return true;
2591 if(myPntId[0] == x.myPntId[0])
2592 if(myPntId[1] < x.myPntId[1]) return true;
2596 inline void UpdateBorders(const FreeEdges::Border& theBorder,
2597 FreeEdges::TBorders& theRegistry,
2598 FreeEdges::TBorders& theContainer)
2600 if(theRegistry.find(theBorder) == theRegistry.end()){
2601 theRegistry.insert(theBorder);
2602 theContainer.insert(theBorder);
2604 theContainer.erase(theBorder);
2608 void FreeEdges::GetBoreders(TBorders& theBorders)
2611 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
2612 for(; anIter->more(); ){
2613 const SMDS_MeshFace* anElem = anIter->next();
2614 long anElemId = anElem->GetID();
2615 SMDS_ElemIteratorPtr aNodesIter;
2616 if ( anElem->IsQuadratic() )
2617 aNodesIter = static_cast<const SMDS_VtkFace*>(anElem)->
2618 interlacedNodesElemIterator();
2620 aNodesIter = anElem->nodesIterator();
2621 long aNodeId[2] = {0,0};
2622 const SMDS_MeshElement* aNode;
2623 if(aNodesIter->more()){
2624 aNode = aNodesIter->next();
2625 aNodeId[0] = aNodeId[1] = aNode->GetID();
2627 for(; aNodesIter->more(); ){
2628 aNode = aNodesIter->next();
2629 long anId = aNode->GetID();
2630 Border aBorder(anElemId,aNodeId[1],anId);
2632 UpdateBorders(aBorder,aRegistry,theBorders);
2634 Border aBorder(anElemId,aNodeId[0],aNodeId[1]);
2635 UpdateBorders(aBorder,aRegistry,theBorders);
2639 //================================================================================
2642 Description : Predicate for free nodes
2644 //================================================================================
2646 FreeNodes::FreeNodes()
2651 void FreeNodes::SetMesh( const SMDS_Mesh* theMesh )
2656 bool FreeNodes::IsSatisfy( long theNodeId )
2658 const SMDS_MeshNode* aNode = myMesh->FindNode( theNodeId );
2662 return (aNode->NbInverseElements() < 1);
2665 SMDSAbs_ElementType FreeNodes::GetType() const
2667 return SMDSAbs_Node;
2671 //================================================================================
2674 Description : Predicate for free faces
2676 //================================================================================
2678 FreeFaces::FreeFaces()
2683 void FreeFaces::SetMesh( const SMDS_Mesh* theMesh )
2688 bool FreeFaces::IsSatisfy( long theId )
2690 if (!myMesh) return false;
2691 // check that faces nodes refers to less than two common volumes
2692 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
2693 if ( !aFace || aFace->GetType() != SMDSAbs_Face )
2696 int nbNode = aFace->NbNodes();
2698 // collect volumes to check that number of volumes with count equal nbNode not less than 2
2699 typedef std::map< SMDS_MeshElement*, int > TMapOfVolume; // map of volume counters
2700 typedef std::map< SMDS_MeshElement*, int >::iterator TItrMapOfVolume; // iterator
2701 TMapOfVolume mapOfVol;
2703 SMDS_ElemIteratorPtr nodeItr = aFace->nodesIterator();
2704 while ( nodeItr->more() )
2706 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(nodeItr->next());
2707 if ( !aNode ) continue;
2708 SMDS_ElemIteratorPtr volItr = aNode->GetInverseElementIterator(SMDSAbs_Volume);
2709 while ( volItr->more() )
2711 SMDS_MeshElement* aVol = (SMDS_MeshElement*)volItr->next();
2712 TItrMapOfVolume itr = mapOfVol.insert( std::make_pair( aVol, 0 )).first;
2717 TItrMapOfVolume volItr = mapOfVol.begin();
2718 TItrMapOfVolume volEnd = mapOfVol.end();
2719 for ( ; volItr != volEnd; ++volItr )
2720 if ( (*volItr).second >= nbNode )
2722 // face is not free if number of volumes constructed on their nodes more than one
2726 SMDSAbs_ElementType FreeFaces::GetType() const
2728 return SMDSAbs_Face;
2731 //================================================================================
2733 Class : LinearOrQuadratic
2734 Description : Predicate to verify whether a mesh element is linear
2736 //================================================================================
2738 LinearOrQuadratic::LinearOrQuadratic()
2743 void LinearOrQuadratic::SetMesh( const SMDS_Mesh* theMesh )
2748 bool LinearOrQuadratic::IsSatisfy( long theId )
2750 if (!myMesh) return false;
2751 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2752 if ( !anElem || (myType != SMDSAbs_All && anElem->GetType() != myType) )
2754 return (!anElem->IsQuadratic());
2757 void LinearOrQuadratic::SetType( SMDSAbs_ElementType theType )
2762 SMDSAbs_ElementType LinearOrQuadratic::GetType() const
2767 //================================================================================
2770 Description : Functor for check color of group to which mesh element belongs to
2772 //================================================================================
2774 GroupColor::GroupColor()
2778 bool GroupColor::IsSatisfy( long theId )
2780 return myIDs.count( theId );
2783 void GroupColor::SetType( SMDSAbs_ElementType theType )
2788 SMDSAbs_ElementType GroupColor::GetType() const
2793 static bool isEqual( const Quantity_Color& theColor1,
2794 const Quantity_Color& theColor2 )
2796 // tolerance to compare colors
2797 const double tol = 5*1e-3;
2798 return ( fabs( theColor1.Red() - theColor2.Red() ) < tol &&
2799 fabs( theColor1.Green() - theColor2.Green() ) < tol &&
2800 fabs( theColor1.Blue() - theColor2.Blue() ) < tol );
2803 void GroupColor::SetMesh( const SMDS_Mesh* theMesh )
2807 const SMESHDS_Mesh* aMesh = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
2811 int nbGrp = aMesh->GetNbGroups();
2815 // iterates on groups and find necessary elements ids
2816 const std::set<SMESHDS_GroupBase*>& aGroups = aMesh->GetGroups();
2817 std::set<SMESHDS_GroupBase*>::const_iterator GrIt = aGroups.begin();
2818 for (; GrIt != aGroups.end(); GrIt++)
2820 SMESHDS_GroupBase* aGrp = (*GrIt);
2823 // check type and color of group
2824 if ( !isEqual( myColor, aGrp->GetColor() ))
2827 // IPAL52867 (prevent infinite recursion via GroupOnFilter)
2828 if ( SMESHDS_GroupOnFilter * gof = dynamic_cast< SMESHDS_GroupOnFilter* >( aGrp ))
2829 if ( gof->GetPredicate().get() == this )
2832 SMDSAbs_ElementType aGrpElType = (SMDSAbs_ElementType)aGrp->GetType();
2833 if ( myType == aGrpElType || (myType == SMDSAbs_All && aGrpElType != SMDSAbs_Node) ) {
2834 // add elements IDS into control
2835 int aSize = aGrp->Extent();
2836 for (int i = 0; i < aSize; i++)
2837 myIDs.insert( aGrp->GetID(i+1) );
2842 void GroupColor::SetColorStr( const TCollection_AsciiString& theStr )
2844 Kernel_Utils::Localizer loc;
2845 TCollection_AsciiString aStr = theStr;
2846 aStr.RemoveAll( ' ' );
2847 aStr.RemoveAll( '\t' );
2848 for ( int aPos = aStr.Search( ";;" ); aPos != -1; aPos = aStr.Search( ";;" ) )
2849 aStr.Remove( aPos, 2 );
2850 Standard_Real clr[3];
2851 clr[0] = clr[1] = clr[2] = 0.;
2852 for ( int i = 0; i < 3; i++ ) {
2853 TCollection_AsciiString tmpStr = aStr.Token( ";", i+1 );
2854 if ( !tmpStr.IsEmpty() && tmpStr.IsRealValue() )
2855 clr[i] = tmpStr.RealValue();
2857 myColor = Quantity_Color( clr[0], clr[1], clr[2], Quantity_TOC_RGB );
2860 //=======================================================================
2861 // name : GetRangeStr
2862 // Purpose : Get range as a string.
2863 // Example: "1,2,3,50-60,63,67,70-"
2864 //=======================================================================
2866 void GroupColor::GetColorStr( TCollection_AsciiString& theResStr ) const
2869 theResStr += TCollection_AsciiString( myColor.Red() );
2870 theResStr += TCollection_AsciiString( ";" ) + TCollection_AsciiString( myColor.Green() );
2871 theResStr += TCollection_AsciiString( ";" ) + TCollection_AsciiString( myColor.Blue() );
2874 //================================================================================
2876 Class : ElemGeomType
2877 Description : Predicate to check element geometry type
2879 //================================================================================
2881 ElemGeomType::ElemGeomType()
2884 myType = SMDSAbs_All;
2885 myGeomType = SMDSGeom_TRIANGLE;
2888 void ElemGeomType::SetMesh( const SMDS_Mesh* theMesh )
2893 bool ElemGeomType::IsSatisfy( long theId )
2895 if (!myMesh) return false;
2896 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2899 const SMDSAbs_ElementType anElemType = anElem->GetType();
2900 if ( myType != SMDSAbs_All && anElemType != myType )
2902 bool isOk = ( anElem->GetGeomType() == myGeomType );
2906 void ElemGeomType::SetType( SMDSAbs_ElementType theType )
2911 SMDSAbs_ElementType ElemGeomType::GetType() const
2916 void ElemGeomType::SetGeomType( SMDSAbs_GeometryType theType )
2918 myGeomType = theType;
2921 SMDSAbs_GeometryType ElemGeomType::GetGeomType() const
2926 //================================================================================
2928 Class : ElemEntityType
2929 Description : Predicate to check element entity type
2931 //================================================================================
2933 ElemEntityType::ElemEntityType():
2935 myType( SMDSAbs_All ),
2936 myEntityType( SMDSEntity_0D )
2940 void ElemEntityType::SetMesh( const SMDS_Mesh* theMesh )
2945 bool ElemEntityType::IsSatisfy( long theId )
2947 if ( !myMesh ) return false;
2948 if ( myType == SMDSAbs_Node )
2949 return myMesh->FindNode( theId );
2950 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2952 myEntityType == anElem->GetEntityType() );
2955 void ElemEntityType::SetType( SMDSAbs_ElementType theType )
2960 SMDSAbs_ElementType ElemEntityType::GetType() const
2965 void ElemEntityType::SetElemEntityType( SMDSAbs_EntityType theEntityType )
2967 myEntityType = theEntityType;
2970 SMDSAbs_EntityType ElemEntityType::GetElemEntityType() const
2972 return myEntityType;
2975 //================================================================================
2977 * \brief Class ConnectedElements
2979 //================================================================================
2981 ConnectedElements::ConnectedElements():
2982 myNodeID(0), myType( SMDSAbs_All ), myOkIDsReady( false ) {}
2984 SMDSAbs_ElementType ConnectedElements::GetType() const
2987 int ConnectedElements::GetNode() const
2988 { return myXYZ.empty() ? myNodeID : 0; } // myNodeID can be found by myXYZ
2990 std::vector<double> ConnectedElements::GetPoint() const
2993 void ConnectedElements::clearOkIDs()
2994 { myOkIDsReady = false; myOkIDs.clear(); }
2996 void ConnectedElements::SetType( SMDSAbs_ElementType theType )
2998 if ( myType != theType || myMeshModifTracer.IsMeshModified() )
3003 void ConnectedElements::SetMesh( const SMDS_Mesh* theMesh )
3005 myMeshModifTracer.SetMesh( theMesh );
3006 if ( myMeshModifTracer.IsMeshModified() )
3009 if ( !myXYZ.empty() )
3010 SetPoint( myXYZ[0], myXYZ[1], myXYZ[2] ); // find a node near myXYZ it in a new mesh
3014 void ConnectedElements::SetNode( int nodeID )
3019 bool isSameDomain = false;
3020 if ( myOkIDsReady && myMeshModifTracer.GetMesh() && !myMeshModifTracer.IsMeshModified() )
3021 if ( const SMDS_MeshNode* n = myMeshModifTracer.GetMesh()->FindNode( myNodeID ))
3023 SMDS_ElemIteratorPtr eIt = n->GetInverseElementIterator( myType );
3024 while ( !isSameDomain && eIt->more() )
3025 isSameDomain = IsSatisfy( eIt->next()->GetID() );
3027 if ( !isSameDomain )
3031 void ConnectedElements::SetPoint( double x, double y, double z )
3039 bool isSameDomain = false;
3041 // find myNodeID by myXYZ if possible
3042 if ( myMeshModifTracer.GetMesh() )
3044 SMESHUtils::Deleter<SMESH_ElementSearcher> searcher
3045 ( SMESH_MeshAlgos::GetElementSearcher( (SMDS_Mesh&) *myMeshModifTracer.GetMesh() ));
3047 std::vector< const SMDS_MeshElement* > foundElems;
3048 searcher->FindElementsByPoint( gp_Pnt(x,y,z), SMDSAbs_All, foundElems );
3050 if ( !foundElems.empty() )
3052 myNodeID = foundElems[0]->GetNode(0)->GetID();
3053 if ( myOkIDsReady && !myMeshModifTracer.IsMeshModified() )
3054 isSameDomain = IsSatisfy( foundElems[0]->GetID() );
3057 if ( !isSameDomain )
3061 bool ConnectedElements::IsSatisfy( long theElementId )
3063 // Here we do NOT check if the mesh has changed, we do it in Set...() only!!!
3065 if ( !myOkIDsReady )
3067 if ( !myMeshModifTracer.GetMesh() )
3069 const SMDS_MeshNode* node0 = myMeshModifTracer.GetMesh()->FindNode( myNodeID );
3073 std::list< const SMDS_MeshNode* > nodeQueue( 1, node0 );
3074 std::set< int > checkedNodeIDs;
3076 // foreach node in nodeQueue:
3077 // foreach element sharing a node:
3078 // add ID of an element of myType to myOkIDs;
3079 // push all element nodes absent from checkedNodeIDs to nodeQueue;
3080 while ( !nodeQueue.empty() )
3082 const SMDS_MeshNode* node = nodeQueue.front();
3083 nodeQueue.pop_front();
3085 // loop on elements sharing the node
3086 SMDS_ElemIteratorPtr eIt = node->GetInverseElementIterator();
3087 while ( eIt->more() )
3089 // keep elements of myType
3090 const SMDS_MeshElement* element = eIt->next();
3091 if ( element->GetType() == myType )
3092 myOkIDs.insert( myOkIDs.end(), element->GetID() );
3094 // enqueue nodes of the element
3095 SMDS_ElemIteratorPtr nIt = element->nodesIterator();
3096 while ( nIt->more() )
3098 const SMDS_MeshNode* n = static_cast< const SMDS_MeshNode* >( nIt->next() );
3099 if ( checkedNodeIDs.insert( n->GetID() ).second )
3100 nodeQueue.push_back( n );
3104 if ( myType == SMDSAbs_Node )
3105 std::swap( myOkIDs, checkedNodeIDs );
3107 size_t totalNbElems = myMeshModifTracer.GetMesh()->GetMeshInfo().NbElements( myType );
3108 if ( myOkIDs.size() == totalNbElems )
3111 myOkIDsReady = true;
3114 return myOkIDs.empty() ? true : myOkIDs.count( theElementId );
3117 //================================================================================
3119 * \brief Class CoplanarFaces
3121 //================================================================================
3125 inline bool isLessAngle( const gp_Vec& v1, const gp_Vec& v2, const double cos )
3127 double dot = v1 * v2; // cos * |v1| * |v2|
3128 double l1 = v1.SquareMagnitude();
3129 double l2 = v2.SquareMagnitude();
3130 return (( dot * cos >= 0 ) &&
3131 ( dot * dot ) / l1 / l2 >= ( cos * cos ));
3134 CoplanarFaces::CoplanarFaces()
3135 : myFaceID(0), myToler(0)
3138 void CoplanarFaces::SetMesh( const SMDS_Mesh* theMesh )
3140 myMeshModifTracer.SetMesh( theMesh );
3141 if ( myMeshModifTracer.IsMeshModified() )
3143 // Build a set of coplanar face ids
3145 myCoplanarIDs.Clear();
3147 if ( !myMeshModifTracer.GetMesh() || !myFaceID || !myToler )
3150 const SMDS_MeshElement* face = myMeshModifTracer.GetMesh()->FindElement( myFaceID );
3151 if ( !face || face->GetType() != SMDSAbs_Face )
3155 gp_Vec myNorm = getNormale( static_cast<const SMDS_MeshFace*>(face), &normOK );
3159 const double cosTol = Cos( myToler * M_PI / 180. );
3160 NCollection_Map< SMESH_TLink, SMESH_TLink > checkedLinks;
3162 std::list< std::pair< const SMDS_MeshElement*, gp_Vec > > faceQueue;
3163 faceQueue.push_back( std::make_pair( face, myNorm ));
3164 while ( !faceQueue.empty() )
3166 face = faceQueue.front().first;
3167 myNorm = faceQueue.front().second;
3168 faceQueue.pop_front();
3170 for ( int i = 0, nbN = face->NbCornerNodes(); i < nbN; ++i )
3172 const SMDS_MeshNode* n1 = face->GetNode( i );
3173 const SMDS_MeshNode* n2 = face->GetNode(( i+1 )%nbN);
3174 if ( !checkedLinks.Add( SMESH_TLink( n1, n2 )))
3176 SMDS_ElemIteratorPtr fIt = n1->GetInverseElementIterator(SMDSAbs_Face);
3177 while ( fIt->more() )
3179 const SMDS_MeshElement* f = fIt->next();
3180 if ( f->GetNodeIndex( n2 ) > -1 )
3182 gp_Vec norm = getNormale( static_cast<const SMDS_MeshFace*>(f), &normOK );
3183 if (!normOK || isLessAngle( myNorm, norm, cosTol))
3185 myCoplanarIDs.Add( f->GetID() );
3186 faceQueue.push_back( std::make_pair( f, norm ));
3194 bool CoplanarFaces::IsSatisfy( long theElementId )
3196 return myCoplanarIDs.Contains( theElementId );
3201 *Description : Predicate for Range of Ids.
3202 * Range may be specified with two ways.
3203 * 1. Using AddToRange method
3204 * 2. With SetRangeStr method. Parameter of this method is a string
3205 * like as "1,2,3,50-60,63,67,70-"
3208 //=======================================================================
3209 // name : RangeOfIds
3210 // Purpose : Constructor
3211 //=======================================================================
3212 RangeOfIds::RangeOfIds()
3215 myType = SMDSAbs_All;
3218 //=======================================================================
3220 // Purpose : Set mesh
3221 //=======================================================================
3222 void RangeOfIds::SetMesh( const SMDS_Mesh* theMesh )
3227 //=======================================================================
3228 // name : AddToRange
3229 // Purpose : Add ID to the range
3230 //=======================================================================
3231 bool RangeOfIds::AddToRange( long theEntityId )
3233 myIds.Add( theEntityId );
3237 //=======================================================================
3238 // name : GetRangeStr
3239 // Purpose : Get range as a string.
3240 // Example: "1,2,3,50-60,63,67,70-"
3241 //=======================================================================
3242 void RangeOfIds::GetRangeStr( TCollection_AsciiString& theResStr )
3246 TColStd_SequenceOfInteger anIntSeq;
3247 TColStd_SequenceOfAsciiString aStrSeq;
3249 TColStd_MapIteratorOfMapOfInteger anIter( myIds );
3250 for ( ; anIter.More(); anIter.Next() )
3252 int anId = anIter.Key();
3253 TCollection_AsciiString aStr( anId );
3254 anIntSeq.Append( anId );
3255 aStrSeq.Append( aStr );
3258 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
3260 int aMinId = myMin( i );
3261 int aMaxId = myMax( i );
3263 TCollection_AsciiString aStr;
3264 if ( aMinId != IntegerFirst() )
3269 if ( aMaxId != IntegerLast() )
3272 // find position of the string in result sequence and insert string in it
3273 if ( anIntSeq.Length() == 0 )
3275 anIntSeq.Append( aMinId );
3276 aStrSeq.Append( aStr );
3280 if ( aMinId < anIntSeq.First() )
3282 anIntSeq.Prepend( aMinId );
3283 aStrSeq.Prepend( aStr );
3285 else if ( aMinId > anIntSeq.Last() )
3287 anIntSeq.Append( aMinId );
3288 aStrSeq.Append( aStr );
3291 for ( int j = 1, k = anIntSeq.Length(); j <= k; j++ )
3292 if ( aMinId < anIntSeq( j ) )
3294 anIntSeq.InsertBefore( j, aMinId );
3295 aStrSeq.InsertBefore( j, aStr );
3301 if ( aStrSeq.Length() == 0 )
3304 theResStr = aStrSeq( 1 );
3305 for ( int j = 2, k = aStrSeq.Length(); j <= k; j++ )
3308 theResStr += aStrSeq( j );
3312 //=======================================================================
3313 // name : SetRangeStr
3314 // Purpose : Define range with string
3315 // Example of entry string: "1,2,3,50-60,63,67,70-"
3316 //=======================================================================
3317 bool RangeOfIds::SetRangeStr( const TCollection_AsciiString& theStr )
3323 TCollection_AsciiString aStr = theStr;
3324 for ( int i = 1; i <= aStr.Length(); ++i )
3326 char c = aStr.Value( i );
3327 if ( !isdigit( c ) && c != ',' && c != '-' )
3328 aStr.SetValue( i, ',');
3330 aStr.RemoveAll( ' ' );
3332 TCollection_AsciiString tmpStr = aStr.Token( ",", 1 );
3334 while ( tmpStr != "" )
3336 tmpStr = aStr.Token( ",", i++ );
3337 int aPos = tmpStr.Search( '-' );
3341 if ( tmpStr.IsIntegerValue() )
3342 myIds.Add( tmpStr.IntegerValue() );
3348 TCollection_AsciiString aMaxStr = tmpStr.Split( aPos );
3349 TCollection_AsciiString aMinStr = tmpStr;
3351 while ( aMinStr.Search( "-" ) != -1 ) aMinStr.RemoveAll( '-' );
3352 while ( aMaxStr.Search( "-" ) != -1 ) aMaxStr.RemoveAll( '-' );
3354 if ( (!aMinStr.IsEmpty() && !aMinStr.IsIntegerValue()) ||
3355 (!aMaxStr.IsEmpty() && !aMaxStr.IsIntegerValue()) )
3358 myMin.Append( aMinStr.IsEmpty() ? IntegerFirst() : aMinStr.IntegerValue() );
3359 myMax.Append( aMaxStr.IsEmpty() ? IntegerLast() : aMaxStr.IntegerValue() );
3366 //=======================================================================
3368 // Purpose : Get type of supported entities
3369 //=======================================================================
3370 SMDSAbs_ElementType RangeOfIds::GetType() const
3375 //=======================================================================
3377 // Purpose : Set type of supported entities
3378 //=======================================================================
3379 void RangeOfIds::SetType( SMDSAbs_ElementType theType )
3384 //=======================================================================
3386 // Purpose : Verify whether entity satisfies to this rpedicate
3387 //=======================================================================
3388 bool RangeOfIds::IsSatisfy( long theId )
3393 if ( myType == SMDSAbs_Node )
3395 if ( myMesh->FindNode( theId ) == 0 )
3400 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
3401 if ( anElem == 0 || (myType != anElem->GetType() && myType != SMDSAbs_All ))
3405 if ( myIds.Contains( theId ) )
3408 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
3409 if ( theId >= myMin( i ) && theId <= myMax( i ) )
3417 Description : Base class for comparators
3419 Comparator::Comparator():
3423 Comparator::~Comparator()
3426 void Comparator::SetMesh( const SMDS_Mesh* theMesh )
3429 myFunctor->SetMesh( theMesh );
3432 void Comparator::SetMargin( double theValue )
3434 myMargin = theValue;
3437 void Comparator::SetNumFunctor( NumericalFunctorPtr theFunct )
3439 myFunctor = theFunct;
3442 SMDSAbs_ElementType Comparator::GetType() const
3444 return myFunctor ? myFunctor->GetType() : SMDSAbs_All;
3447 double Comparator::GetMargin()
3455 Description : Comparator "<"
3457 bool LessThan::IsSatisfy( long theId )
3459 return myFunctor && myFunctor->GetValue( theId ) < myMargin;
3465 Description : Comparator ">"
3467 bool MoreThan::IsSatisfy( long theId )
3469 return myFunctor && myFunctor->GetValue( theId ) > myMargin;
3475 Description : Comparator "="
3478 myToler(Precision::Confusion())
3481 bool EqualTo::IsSatisfy( long theId )
3483 return myFunctor && fabs( myFunctor->GetValue( theId ) - myMargin ) < myToler;
3486 void EqualTo::SetTolerance( double theToler )
3491 double EqualTo::GetTolerance()
3498 Description : Logical NOT predicate
3500 LogicalNOT::LogicalNOT()
3503 LogicalNOT::~LogicalNOT()
3506 bool LogicalNOT::IsSatisfy( long theId )
3508 return myPredicate && !myPredicate->IsSatisfy( theId );
3511 void LogicalNOT::SetMesh( const SMDS_Mesh* theMesh )
3514 myPredicate->SetMesh( theMesh );
3517 void LogicalNOT::SetPredicate( PredicatePtr thePred )
3519 myPredicate = thePred;
3522 SMDSAbs_ElementType LogicalNOT::GetType() const
3524 return myPredicate ? myPredicate->GetType() : SMDSAbs_All;
3529 Class : LogicalBinary
3530 Description : Base class for binary logical predicate
3532 LogicalBinary::LogicalBinary()
3535 LogicalBinary::~LogicalBinary()
3538 void LogicalBinary::SetMesh( const SMDS_Mesh* theMesh )
3541 myPredicate1->SetMesh( theMesh );
3544 myPredicate2->SetMesh( theMesh );
3547 void LogicalBinary::SetPredicate1( PredicatePtr thePredicate )
3549 myPredicate1 = thePredicate;
3552 void LogicalBinary::SetPredicate2( PredicatePtr thePredicate )
3554 myPredicate2 = thePredicate;
3557 SMDSAbs_ElementType LogicalBinary::GetType() const
3559 if ( !myPredicate1 || !myPredicate2 )
3562 SMDSAbs_ElementType aType1 = myPredicate1->GetType();
3563 SMDSAbs_ElementType aType2 = myPredicate2->GetType();
3565 return aType1 == aType2 ? aType1 : SMDSAbs_All;
3571 Description : Logical AND
3573 bool LogicalAND::IsSatisfy( long theId )
3578 myPredicate1->IsSatisfy( theId ) &&
3579 myPredicate2->IsSatisfy( theId );
3585 Description : Logical OR
3587 bool LogicalOR::IsSatisfy( long theId )
3592 (myPredicate1->IsSatisfy( theId ) ||
3593 myPredicate2->IsSatisfy( theId ));
3602 // #include <tbb/parallel_for.h>
3603 // #include <tbb/enumerable_thread_specific.h>
3605 // namespace Parallel
3607 // typedef tbb::enumerable_thread_specific< TIdSequence > TIdSeq;
3611 // const SMDS_Mesh* myMesh;
3612 // PredicatePtr myPredicate;
3613 // TIdSeq & myOKIds;
3614 // Predicate( const SMDS_Mesh* m, PredicatePtr p, TIdSeq & ids ):
3615 // myMesh(m), myPredicate(p->Duplicate()), myOKIds(ids) {}
3616 // void operator() ( const tbb::blocked_range<size_t>& r ) const
3618 // for ( size_t i = r.begin(); i != r.end(); ++i )
3619 // if ( myPredicate->IsSatisfy( i ))
3620 // myOKIds.local().push_back();
3632 void Filter::SetPredicate( PredicatePtr thePredicate )
3634 myPredicate = thePredicate;
3637 void Filter::GetElementsId( const SMDS_Mesh* theMesh,
3638 PredicatePtr thePredicate,
3639 TIdSequence& theSequence )
3641 theSequence.clear();
3643 if ( !theMesh || !thePredicate )
3646 thePredicate->SetMesh( theMesh );
3648 SMDS_ElemIteratorPtr elemIt = theMesh->elementsIterator( thePredicate->GetType() );
3650 while ( elemIt->more() ) {
3651 const SMDS_MeshElement* anElem = elemIt->next();
3652 long anId = anElem->GetID();
3653 if ( thePredicate->IsSatisfy( anId ) )
3654 theSequence.push_back( anId );
3659 void Filter::GetElementsId( const SMDS_Mesh* theMesh,
3660 Filter::TIdSequence& theSequence )
3662 GetElementsId(theMesh,myPredicate,theSequence);
3669 typedef std::set<SMDS_MeshFace*> TMapOfFacePtr;
3675 ManifoldPart::Link::Link( SMDS_MeshNode* theNode1,
3676 SMDS_MeshNode* theNode2 )
3682 ManifoldPart::Link::~Link()
3688 bool ManifoldPart::Link::IsEqual( const ManifoldPart::Link& theLink ) const
3690 if ( myNode1 == theLink.myNode1 &&
3691 myNode2 == theLink.myNode2 )
3693 else if ( myNode1 == theLink.myNode2 &&
3694 myNode2 == theLink.myNode1 )
3700 bool ManifoldPart::Link::operator<( const ManifoldPart::Link& x ) const
3702 if(myNode1 < x.myNode1) return true;
3703 if(myNode1 == x.myNode1)
3704 if(myNode2 < x.myNode2) return true;
3708 bool ManifoldPart::IsEqual( const ManifoldPart::Link& theLink1,
3709 const ManifoldPart::Link& theLink2 )
3711 return theLink1.IsEqual( theLink2 );
3714 ManifoldPart::ManifoldPart()
3717 myAngToler = Precision::Angular();
3718 myIsOnlyManifold = true;
3721 ManifoldPart::~ManifoldPart()
3726 void ManifoldPart::SetMesh( const SMDS_Mesh* theMesh )
3732 SMDSAbs_ElementType ManifoldPart::GetType() const
3733 { return SMDSAbs_Face; }
3735 bool ManifoldPart::IsSatisfy( long theElementId )
3737 return myMapIds.Contains( theElementId );
3740 void ManifoldPart::SetAngleTolerance( const double theAngToler )
3741 { myAngToler = theAngToler; }
3743 double ManifoldPart::GetAngleTolerance() const
3744 { return myAngToler; }
3746 void ManifoldPart::SetIsOnlyManifold( const bool theIsOnly )
3747 { myIsOnlyManifold = theIsOnly; }
3749 void ManifoldPart::SetStartElem( const long theStartId )
3750 { myStartElemId = theStartId; }
3752 bool ManifoldPart::process()
3755 myMapBadGeomIds.Clear();
3757 myAllFacePtr.clear();
3758 myAllFacePtrIntDMap.clear();
3762 // collect all faces into own map
3763 SMDS_FaceIteratorPtr anFaceItr = myMesh->facesIterator();
3764 for (; anFaceItr->more(); )
3766 SMDS_MeshFace* aFacePtr = (SMDS_MeshFace*)anFaceItr->next();
3767 myAllFacePtr.push_back( aFacePtr );
3768 myAllFacePtrIntDMap[aFacePtr] = myAllFacePtr.size()-1;
3771 SMDS_MeshFace* aStartFace = (SMDS_MeshFace*)myMesh->FindElement( myStartElemId );
3775 // the map of non manifold links and bad geometry
3776 TMapOfLink aMapOfNonManifold;
3777 TColStd_MapOfInteger aMapOfTreated;
3779 // begin cycle on faces from start index and run on vector till the end
3780 // and from begin to start index to cover whole vector
3781 const int aStartIndx = myAllFacePtrIntDMap[aStartFace];
3782 bool isStartTreat = false;
3783 for ( int fi = aStartIndx; !isStartTreat || fi != aStartIndx ; fi++ )
3785 if ( fi == aStartIndx )
3786 isStartTreat = true;
3787 // as result next time when fi will be equal to aStartIndx
3789 SMDS_MeshFace* aFacePtr = myAllFacePtr[ fi ];
3790 if ( aMapOfTreated.Contains( aFacePtr->GetID() ) )
3793 aMapOfTreated.Add( aFacePtr->GetID() );
3794 TColStd_MapOfInteger aResFaces;
3795 if ( !findConnected( myAllFacePtrIntDMap, aFacePtr,
3796 aMapOfNonManifold, aResFaces ) )
3798 TColStd_MapIteratorOfMapOfInteger anItr( aResFaces );
3799 for ( ; anItr.More(); anItr.Next() )
3801 int aFaceId = anItr.Key();
3802 aMapOfTreated.Add( aFaceId );
3803 myMapIds.Add( aFaceId );
3806 if ( fi == int( myAllFacePtr.size() - 1 ))
3808 } // end run on vector of faces
3809 return !myMapIds.IsEmpty();
3812 static void getLinks( const SMDS_MeshFace* theFace,
3813 ManifoldPart::TVectorOfLink& theLinks )
3815 int aNbNode = theFace->NbNodes();
3816 SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
3818 SMDS_MeshNode* aNode = 0;
3819 for ( ; aNodeItr->more() && i <= aNbNode; )
3822 SMDS_MeshNode* aN1 = (SMDS_MeshNode*)aNodeItr->next();
3826 SMDS_MeshNode* aN2 = ( i >= aNbNode ) ? aNode : (SMDS_MeshNode*)aNodeItr->next();
3828 ManifoldPart::Link aLink( aN1, aN2 );
3829 theLinks.push_back( aLink );
3833 bool ManifoldPart::findConnected
3834 ( const ManifoldPart::TDataMapFacePtrInt& theAllFacePtrInt,
3835 SMDS_MeshFace* theStartFace,
3836 ManifoldPart::TMapOfLink& theNonManifold,
3837 TColStd_MapOfInteger& theResFaces )
3839 theResFaces.Clear();
3840 if ( !theAllFacePtrInt.size() )
3843 if ( getNormale( theStartFace ).SquareModulus() <= gp::Resolution() )
3845 myMapBadGeomIds.Add( theStartFace->GetID() );
3849 ManifoldPart::TMapOfLink aMapOfBoundary, aMapToSkip;
3850 ManifoldPart::TVectorOfLink aSeqOfBoundary;
3851 theResFaces.Add( theStartFace->GetID() );
3852 ManifoldPart::TDataMapOfLinkFacePtr aDMapLinkFace;
3854 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
3855 aDMapLinkFace, theNonManifold, theStartFace );
3857 bool isDone = false;
3858 while ( !isDone && aMapOfBoundary.size() != 0 )
3860 bool isToReset = false;
3861 ManifoldPart::TVectorOfLink::iterator pLink = aSeqOfBoundary.begin();
3862 for ( ; !isToReset && pLink != aSeqOfBoundary.end(); ++pLink )
3864 ManifoldPart::Link aLink = *pLink;
3865 if ( aMapToSkip.find( aLink ) != aMapToSkip.end() )
3867 // each link could be treated only once
3868 aMapToSkip.insert( aLink );
3870 ManifoldPart::TVectorOfFacePtr aFaces;
3872 if ( myIsOnlyManifold &&
3873 (theNonManifold.find( aLink ) != theNonManifold.end()) )
3877 getFacesByLink( aLink, aFaces );
3878 // filter the element to keep only indicated elements
3879 ManifoldPart::TVectorOfFacePtr aFiltered;
3880 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
3881 for ( ; pFace != aFaces.end(); ++pFace )
3883 SMDS_MeshFace* aFace = *pFace;
3884 if ( myAllFacePtrIntDMap.find( aFace ) != myAllFacePtrIntDMap.end() )
3885 aFiltered.push_back( aFace );
3888 if ( aFaces.size() < 2 ) // no neihgbour faces
3890 else if ( myIsOnlyManifold && aFaces.size() > 2 ) // non manifold case
3892 theNonManifold.insert( aLink );
3897 // compare normal with normals of neighbor element
3898 SMDS_MeshFace* aPrevFace = aDMapLinkFace[ aLink ];
3899 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
3900 for ( ; pFace != aFaces.end(); ++pFace )
3902 SMDS_MeshFace* aNextFace = *pFace;
3903 if ( aPrevFace == aNextFace )
3905 int anNextFaceID = aNextFace->GetID();
3906 if ( myIsOnlyManifold && theResFaces.Contains( anNextFaceID ) )
3907 // should not be with non manifold restriction. probably bad topology
3909 // check if face was treated and skipped
3910 if ( myMapBadGeomIds.Contains( anNextFaceID ) ||
3911 !isInPlane( aPrevFace, aNextFace ) )
3913 // add new element to connected and extend the boundaries.
3914 theResFaces.Add( anNextFaceID );
3915 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
3916 aDMapLinkFace, theNonManifold, aNextFace );
3920 isDone = !isToReset;
3923 return !theResFaces.IsEmpty();
3926 bool ManifoldPart::isInPlane( const SMDS_MeshFace* theFace1,
3927 const SMDS_MeshFace* theFace2 )
3929 gp_Dir aNorm1 = gp_Dir( getNormale( theFace1 ) );
3930 gp_XYZ aNorm2XYZ = getNormale( theFace2 );
3931 if ( aNorm2XYZ.SquareModulus() <= gp::Resolution() )
3933 myMapBadGeomIds.Add( theFace2->GetID() );
3936 if ( aNorm1.IsParallel( gp_Dir( aNorm2XYZ ), myAngToler ) )
3942 void ManifoldPart::expandBoundary
3943 ( ManifoldPart::TMapOfLink& theMapOfBoundary,
3944 ManifoldPart::TVectorOfLink& theSeqOfBoundary,
3945 ManifoldPart::TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
3946 ManifoldPart::TMapOfLink& theNonManifold,
3947 SMDS_MeshFace* theNextFace ) const
3949 ManifoldPart::TVectorOfLink aLinks;
3950 getLinks( theNextFace, aLinks );
3951 int aNbLink = (int)aLinks.size();
3952 for ( int i = 0; i < aNbLink; i++ )
3954 ManifoldPart::Link aLink = aLinks[ i ];
3955 if ( myIsOnlyManifold && (theNonManifold.find( aLink ) != theNonManifold.end()) )
3957 if ( theMapOfBoundary.find( aLink ) != theMapOfBoundary.end() )
3959 if ( myIsOnlyManifold )
3961 // remove from boundary
3962 theMapOfBoundary.erase( aLink );
3963 ManifoldPart::TVectorOfLink::iterator pLink = theSeqOfBoundary.begin();
3964 for ( ; pLink != theSeqOfBoundary.end(); ++pLink )
3966 ManifoldPart::Link aBoundLink = *pLink;
3967 if ( aBoundLink.IsEqual( aLink ) )
3969 theSeqOfBoundary.erase( pLink );
3977 theMapOfBoundary.insert( aLink );
3978 theSeqOfBoundary.push_back( aLink );
3979 theDMapLinkFacePtr[ aLink ] = theNextFace;
3984 void ManifoldPart::getFacesByLink( const ManifoldPart::Link& theLink,
3985 ManifoldPart::TVectorOfFacePtr& theFaces ) const
3987 std::set<SMDS_MeshCell *> aSetOfFaces;
3988 // take all faces that shared first node
3989 SMDS_ElemIteratorPtr anItr = theLink.myNode1->facesIterator();
3990 for ( ; anItr->more(); )
3992 SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
3995 aSetOfFaces.insert( aFace );
3997 // take all faces that shared second node
3998 anItr = theLink.myNode2->facesIterator();
3999 // find the common part of two sets
4000 for ( ; anItr->more(); )
4002 SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
4003 if ( aSetOfFaces.count( aFace ) )
4004 theFaces.push_back( aFace );
4009 Class : BelongToMeshGroup
4010 Description : Verify whether a mesh element is included into a mesh group
4012 BelongToMeshGroup::BelongToMeshGroup(): myGroup( 0 )
4016 void BelongToMeshGroup::SetGroup( SMESHDS_GroupBase* g )
4021 void BelongToMeshGroup::SetStoreName( const std::string& sn )
4026 void BelongToMeshGroup::SetMesh( const SMDS_Mesh* theMesh )
4028 if ( myGroup && myGroup->GetMesh() != theMesh )
4032 if ( !myGroup && !myStoreName.empty() )
4034 if ( const SMESHDS_Mesh* aMesh = dynamic_cast<const SMESHDS_Mesh*>(theMesh))
4036 const std::set<SMESHDS_GroupBase*>& grps = aMesh->GetGroups();
4037 std::set<SMESHDS_GroupBase*>::const_iterator g = grps.begin();
4038 for ( ; g != grps.end() && !myGroup; ++g )
4039 if ( *g && myStoreName == (*g)->GetStoreName() )
4045 myGroup->IsEmpty(); // make GroupOnFilter update its predicate
4049 bool BelongToMeshGroup::IsSatisfy( long theElementId )
4051 return myGroup ? myGroup->Contains( theElementId ) : false;
4054 SMDSAbs_ElementType BelongToMeshGroup::GetType() const
4056 return myGroup ? myGroup->GetType() : SMDSAbs_All;
4059 //================================================================================
4060 // ElementsOnSurface
4061 //================================================================================
4063 ElementsOnSurface::ElementsOnSurface()
4066 myType = SMDSAbs_All;
4068 myToler = Precision::Confusion();
4069 myUseBoundaries = false;
4072 ElementsOnSurface::~ElementsOnSurface()
4076 void ElementsOnSurface::SetMesh( const SMDS_Mesh* theMesh )
4078 myMeshModifTracer.SetMesh( theMesh );
4079 if ( myMeshModifTracer.IsMeshModified())
4083 bool ElementsOnSurface::IsSatisfy( long theElementId )
4085 return myIds.Contains( theElementId );
4088 SMDSAbs_ElementType ElementsOnSurface::GetType() const
4091 void ElementsOnSurface::SetTolerance( const double theToler )
4093 if ( myToler != theToler )
4098 double ElementsOnSurface::GetTolerance() const
4101 void ElementsOnSurface::SetUseBoundaries( bool theUse )
4103 if ( myUseBoundaries != theUse ) {
4104 myUseBoundaries = theUse;
4105 SetSurface( mySurf, myType );
4109 void ElementsOnSurface::SetSurface( const TopoDS_Shape& theShape,
4110 const SMDSAbs_ElementType theType )
4115 if ( theShape.IsNull() || theShape.ShapeType() != TopAbs_FACE )
4117 mySurf = TopoDS::Face( theShape );
4118 BRepAdaptor_Surface SA( mySurf, myUseBoundaries );
4120 u1 = SA.FirstUParameter(),
4121 u2 = SA.LastUParameter(),
4122 v1 = SA.FirstVParameter(),
4123 v2 = SA.LastVParameter();
4124 Handle(Geom_Surface) surf = BRep_Tool::Surface( mySurf );
4125 myProjector.Init( surf, u1,u2, v1,v2 );
4129 void ElementsOnSurface::process()
4132 if ( mySurf.IsNull() )
4135 if ( !myMeshModifTracer.GetMesh() )
4138 myIds.ReSize( myMeshModifTracer.GetMesh()->GetMeshInfo().NbElements( myType ));
4140 SMDS_ElemIteratorPtr anIter = myMeshModifTracer.GetMesh()->elementsIterator( myType );
4141 for(; anIter->more(); )
4142 process( anIter->next() );
4145 void ElementsOnSurface::process( const SMDS_MeshElement* theElemPtr )
4147 SMDS_ElemIteratorPtr aNodeItr = theElemPtr->nodesIterator();
4148 bool isSatisfy = true;
4149 for ( ; aNodeItr->more(); )
4151 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
4152 if ( !isOnSurface( aNode ) )
4159 myIds.Add( theElemPtr->GetID() );
4162 bool ElementsOnSurface::isOnSurface( const SMDS_MeshNode* theNode )
4164 if ( mySurf.IsNull() )
4167 gp_Pnt aPnt( theNode->X(), theNode->Y(), theNode->Z() );
4168 // double aToler2 = myToler * myToler;
4169 // if ( mySurf->IsKind(STANDARD_TYPE(Geom_Plane)))
4171 // gp_Pln aPln = Handle(Geom_Plane)::DownCast(mySurf)->Pln();
4172 // if ( aPln.SquareDistance( aPnt ) > aToler2 )
4175 // else if ( mySurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)))
4177 // gp_Cylinder aCyl = Handle(Geom_CylindricalSurface)::DownCast(mySurf)->Cylinder();
4178 // double aRad = aCyl.Radius();
4179 // gp_Ax3 anAxis = aCyl.Position();
4180 // gp_XYZ aLoc = aCyl.Location().XYZ();
4181 // double aXDist = anAxis.XDirection().XYZ() * ( aPnt.XYZ() - aLoc );
4182 // double aYDist = anAxis.YDirection().XYZ() * ( aPnt.XYZ() - aLoc );
4183 // if ( fabs(aXDist*aXDist + aYDist*aYDist - aRad*aRad) > aToler2 )
4188 myProjector.Perform( aPnt );
4189 bool isOn = ( myProjector.IsDone() && myProjector.LowerDistance() <= myToler );
4195 //================================================================================
4197 //================================================================================
4200 const int theIsCheckedFlag = 0x0000100;
4203 struct ElementsOnShape::Classifier
4205 Classifier() { mySolidClfr = 0; myFlags = 0; }
4207 void Init(const TopoDS_Shape& s, double tol, const Bnd_B3d* box = 0 );
4208 bool IsOut(const gp_Pnt& p) { return SetChecked( true ), (this->*myIsOutFun)( p ); }
4209 TopAbs_ShapeEnum ShapeType() const { return myShape.ShapeType(); }
4210 const TopoDS_Shape& Shape() const { return myShape; }
4211 const Bnd_B3d* GetBndBox() const { return & myBox; }
4212 bool IsChecked() { return myFlags & theIsCheckedFlag; }
4213 bool IsSetFlag( int flag ) const { return myFlags & flag; }
4214 void SetChecked( bool is ) { is ? SetFlag( theIsCheckedFlag ) : UnsetFlag( theIsCheckedFlag ); }
4215 void SetFlag ( int flag ) { myFlags |= flag; }
4216 void UnsetFlag( int flag ) { myFlags &= ~flag; }
4219 bool isOutOfSolid (const gp_Pnt& p);
4220 bool isOutOfBox (const gp_Pnt& p);
4221 bool isOutOfFace (const gp_Pnt& p);
4222 bool isOutOfEdge (const gp_Pnt& p);
4223 bool isOutOfVertex(const gp_Pnt& p);
4224 bool isBox (const TopoDS_Shape& s);
4226 bool (Classifier::* myIsOutFun)(const gp_Pnt& p);
4227 BRepClass3d_SolidClassifier* mySolidClfr; // ptr because of a run-time forbidden copy-constructor
4229 GeomAPI_ProjectPointOnSurf myProjFace;
4230 GeomAPI_ProjectPointOnCurve myProjEdge;
4232 TopoDS_Shape myShape;
4237 struct ElementsOnShape::OctreeClassifier : public SMESH_Octree
4239 OctreeClassifier( const std::vector< ElementsOnShape::Classifier* >& classifiers );
4240 OctreeClassifier( const OctreeClassifier* otherTree,
4241 const std::vector< ElementsOnShape::Classifier >& clsOther,
4242 std::vector< ElementsOnShape::Classifier >& cls );
4243 void GetClassifiersAtPoint( const gp_XYZ& p,
4244 std::vector< ElementsOnShape::Classifier* >& classifiers );
4246 OctreeClassifier() {}
4247 SMESH_Octree* newChild() const { return new OctreeClassifier; }
4248 void buildChildrenData();
4249 Bnd_B3d* buildRootBox();
4251 std::vector< ElementsOnShape::Classifier* > myClassifiers;
4255 ElementsOnShape::ElementsOnShape():
4257 myType(SMDSAbs_All),
4258 myToler(Precision::Confusion()),
4259 myAllNodesFlag(false)
4263 ElementsOnShape::~ElementsOnShape()
4268 Predicate* ElementsOnShape::clone() const
4270 ElementsOnShape* cln = new ElementsOnShape();
4271 cln->SetAllNodes ( myAllNodesFlag );
4272 cln->SetTolerance( myToler );
4273 cln->SetMesh ( myMeshModifTracer.GetMesh() );
4274 cln->myShape = myShape; // avoid creation of myClassifiers
4275 cln->SetShape ( myShape, myType );
4276 cln->myClassifiers.resize( myClassifiers.size() );
4277 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4278 cln->myClassifiers[ i ].Init( BRepBuilderAPI_Copy( myClassifiers[ i ].Shape()),
4279 myToler, myClassifiers[ i ].GetBndBox() );
4280 if ( myOctree ) // copy myOctree
4282 cln->myOctree = new OctreeClassifier( myOctree, myClassifiers, cln->myClassifiers );
4287 SMDSAbs_ElementType ElementsOnShape::GetType() const
4292 void ElementsOnShape::SetTolerance (const double theToler)
4294 if (myToler != theToler) {
4296 SetShape(myShape, myType);
4300 double ElementsOnShape::GetTolerance() const
4305 void ElementsOnShape::SetAllNodes (bool theAllNodes)
4307 myAllNodesFlag = theAllNodes;
4310 void ElementsOnShape::SetMesh (const SMDS_Mesh* theMesh)
4312 myMeshModifTracer.SetMesh( theMesh );
4313 if ( myMeshModifTracer.IsMeshModified())
4315 size_t nbNodes = theMesh ? theMesh->NbNodes() : 0;
4316 if ( myNodeIsChecked.size() == nbNodes )
4318 std::fill( myNodeIsChecked.begin(), myNodeIsChecked.end(), false );
4322 SMESHUtils::FreeVector( myNodeIsChecked );
4323 SMESHUtils::FreeVector( myNodeIsOut );
4324 myNodeIsChecked.resize( nbNodes, false );
4325 myNodeIsOut.resize( nbNodes );
4330 bool ElementsOnShape::getNodeIsOut( const SMDS_MeshNode* n, bool& isOut )
4332 if ( n->GetID() >= (int) myNodeIsChecked.size() ||
4333 !myNodeIsChecked[ n->GetID() ])
4336 isOut = myNodeIsOut[ n->GetID() ];
4340 void ElementsOnShape::setNodeIsOut( const SMDS_MeshNode* n, bool isOut )
4342 if ( n->GetID() < (int) myNodeIsChecked.size() )
4344 myNodeIsChecked[ n->GetID() ] = true;
4345 myNodeIsOut [ n->GetID() ] = isOut;
4349 void ElementsOnShape::SetShape (const TopoDS_Shape& theShape,
4350 const SMDSAbs_ElementType theType)
4352 bool shapeChanges = ( myShape != theShape );
4355 if ( myShape.IsNull() ) return;
4359 // find most complex shapes
4360 TopTools_IndexedMapOfShape shapesMap;
4361 TopAbs_ShapeEnum shapeTypes[4] = { TopAbs_SOLID, TopAbs_FACE, TopAbs_EDGE, TopAbs_VERTEX };
4362 TopExp_Explorer sub;
4363 for ( int i = 0; i < 4; ++i )
4365 if ( shapesMap.IsEmpty() )
4366 for ( sub.Init( myShape, shapeTypes[i] ); sub.More(); sub.Next() )
4367 shapesMap.Add( sub.Current() );
4369 for ( sub.Init( myShape, shapeTypes[i], shapeTypes[i-1] ); sub.More(); sub.Next() )
4370 shapesMap.Add( sub.Current() );
4374 myClassifiers.resize( shapesMap.Extent() );
4375 for ( int i = 0; i < shapesMap.Extent(); ++i )
4376 myClassifiers[ i ].Init( shapesMap( i+1 ), myToler );
4379 if ( theType == SMDSAbs_Node )
4381 SMESHUtils::FreeVector( myNodeIsChecked );
4382 SMESHUtils::FreeVector( myNodeIsOut );
4386 std::fill( myNodeIsChecked.begin(), myNodeIsChecked.end(), false );
4390 void ElementsOnShape::clearClassifiers()
4392 // for ( size_t i = 0; i < myClassifiers.size(); ++i )
4393 // delete myClassifiers[ i ];
4394 myClassifiers.clear();
4400 bool ElementsOnShape::IsSatisfy( long elemId )
4402 if ( myClassifiers.empty() )
4405 const SMDS_Mesh* mesh = myMeshModifTracer.GetMesh();
4406 if ( myType == SMDSAbs_Node )
4407 return IsSatisfy( mesh->FindNode( elemId ));
4408 return IsSatisfy( mesh->FindElement( elemId ));
4411 bool ElementsOnShape::IsSatisfy (const SMDS_MeshElement* elem)
4416 bool isSatisfy = myAllNodesFlag, isNodeOut;
4418 gp_XYZ centerXYZ (0, 0, 0);
4420 if ( !myOctree && myClassifiers.size() > 5 )
4422 myWorkClassifiers.resize( myClassifiers.size() );
4423 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4424 myWorkClassifiers[ i ] = & myClassifiers[ i ];
4425 myOctree = new OctreeClassifier( myWorkClassifiers );
4428 SMDS_ElemIteratorPtr aNodeItr = elem->nodesIterator();
4429 while (aNodeItr->more() && (isSatisfy == myAllNodesFlag))
4431 SMESH_TNodeXYZ aPnt( aNodeItr->next() );
4435 if ( !getNodeIsOut( aPnt._node, isNodeOut ))
4439 myWorkClassifiers.clear();
4440 myOctree->GetClassifiersAtPoint( aPnt, myWorkClassifiers );
4442 for ( size_t i = 0; i < myWorkClassifiers.size(); ++i )
4443 myWorkClassifiers[i]->SetChecked( false );
4445 for ( size_t i = 0; i < myWorkClassifiers.size() && isNodeOut; ++i )
4446 if ( !myWorkClassifiers[i]->IsChecked() )
4447 isNodeOut = myWorkClassifiers[i]->IsOut( aPnt );
4451 for ( size_t i = 0; i < myClassifiers.size() && isNodeOut; ++i )
4452 isNodeOut = myClassifiers[i].IsOut( aPnt );
4454 setNodeIsOut( aPnt._node, isNodeOut );
4456 isSatisfy = !isNodeOut;
4459 // Check the center point for volumes MantisBug 0020168
4462 myClassifiers[0].ShapeType() == TopAbs_SOLID )
4464 centerXYZ /= elem->NbNodes();
4467 for ( size_t i = 0; i < myWorkClassifiers.size() && !isSatisfy; ++i )
4468 isSatisfy = ! myWorkClassifiers[i]->IsOut( centerXYZ );
4470 for ( size_t i = 0; i < myClassifiers.size() && !isSatisfy; ++i )
4471 isSatisfy = ! myClassifiers[i].IsOut( centerXYZ );
4477 bool ElementsOnShape::IsSatisfy (const SMDS_MeshNode* node,
4478 TopoDS_Shape* okShape)
4483 if ( !myOctree && myClassifiers.size() > 5 )
4485 myWorkClassifiers.resize( myClassifiers.size() );
4486 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4487 myWorkClassifiers[ i ] = & myClassifiers[ i ];
4488 myOctree = new OctreeClassifier( myWorkClassifiers );
4491 bool isNodeOut = true;
4493 if ( okShape || !getNodeIsOut( node, isNodeOut ))
4495 SMESH_NodeXYZ aPnt = node;
4498 myWorkClassifiers.clear();
4499 myOctree->GetClassifiersAtPoint( aPnt, myWorkClassifiers );
4501 for ( size_t i = 0; i < myWorkClassifiers.size(); ++i )
4502 myWorkClassifiers[i]->SetChecked( false );
4504 for ( size_t i = 0; i < myWorkClassifiers.size(); ++i )
4505 if ( !myWorkClassifiers[i]->IsChecked() &&
4506 !myWorkClassifiers[i]->IsOut( aPnt ))
4510 *okShape = myWorkClassifiers[i]->Shape();
4516 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4517 if ( !myClassifiers[i].IsOut( aPnt ))
4521 *okShape = myWorkClassifiers[i]->Shape();
4525 setNodeIsOut( node, isNodeOut );
4531 void ElementsOnShape::Classifier::Init( const TopoDS_Shape& theShape,
4533 const Bnd_B3d* theBox )
4539 bool isShapeBox = false;
4540 switch ( myShape.ShapeType() )
4544 if (( isShapeBox = isBox( theShape )))
4546 myIsOutFun = & ElementsOnShape::Classifier::isOutOfBox;
4550 mySolidClfr = new BRepClass3d_SolidClassifier(theShape);
4551 myIsOutFun = & ElementsOnShape::Classifier::isOutOfSolid;
4557 Standard_Real u1,u2,v1,v2;
4558 Handle(Geom_Surface) surf = BRep_Tool::Surface( TopoDS::Face( theShape ));
4559 surf->Bounds( u1,u2,v1,v2 );
4560 myProjFace.Init(surf, u1,u2, v1,v2, myTol );
4561 myIsOutFun = & ElementsOnShape::Classifier::isOutOfFace;
4566 Standard_Real u1, u2;
4567 Handle(Geom_Curve) curve = BRep_Tool::Curve( TopoDS::Edge( theShape ), u1, u2);
4568 myProjEdge.Init(curve, u1, u2);
4569 myIsOutFun = & ElementsOnShape::Classifier::isOutOfEdge;
4574 myVertexXYZ = BRep_Tool::Pnt( TopoDS::Vertex( theShape ) );
4575 myIsOutFun = & ElementsOnShape::Classifier::isOutOfVertex;
4579 throw SALOME_Exception("Programmer error in usage of ElementsOnShape::Classifier");
4591 BRepBndLib::Add( myShape, box );
4593 myBox.Add( box.CornerMin() );
4594 myBox.Add( box.CornerMax() );
4595 gp_XYZ halfSize = 0.5 * ( box.CornerMax().XYZ() - box.CornerMin().XYZ() );
4596 for ( int iDim = 1; iDim <= 3; ++iDim )
4598 double x = halfSize.Coord( iDim );
4599 halfSize.SetCoord( iDim, x + Max( myTol, 1e-2 * x ));
4601 myBox.SetHSize( halfSize );
4606 ElementsOnShape::Classifier::~Classifier()
4608 delete mySolidClfr; mySolidClfr = 0;
4611 bool ElementsOnShape::Classifier::isOutOfSolid (const gp_Pnt& p)
4613 mySolidClfr->Perform( p, myTol );
4614 return ( mySolidClfr->State() != TopAbs_IN && mySolidClfr->State() != TopAbs_ON );
4617 bool ElementsOnShape::Classifier::isOutOfBox (const gp_Pnt& p)
4619 return myBox.IsOut( p.XYZ() );
4622 bool ElementsOnShape::Classifier::isOutOfFace (const gp_Pnt& p)
4624 myProjFace.Perform( p );
4625 if ( myProjFace.IsDone() && myProjFace.LowerDistance() <= myTol )
4627 // check relatively to the face
4629 myProjFace.LowerDistanceParameters(u, v);
4630 gp_Pnt2d aProjPnt (u, v);
4631 BRepClass_FaceClassifier aClsf ( TopoDS::Face( myShape ), aProjPnt, myTol );
4632 if ( aClsf.State() == TopAbs_IN || aClsf.State() == TopAbs_ON )
4638 bool ElementsOnShape::Classifier::isOutOfEdge (const gp_Pnt& p)
4640 myProjEdge.Perform( p );
4641 return ! ( myProjEdge.NbPoints() > 0 && myProjEdge.LowerDistance() <= myTol );
4644 bool ElementsOnShape::Classifier::isOutOfVertex(const gp_Pnt& p)
4646 return ( myVertexXYZ.Distance( p ) > myTol );
4649 bool ElementsOnShape::Classifier::isBox (const TopoDS_Shape& theShape)
4651 TopTools_IndexedMapOfShape vMap;
4652 TopExp::MapShapes( theShape, TopAbs_VERTEX, vMap );
4653 if ( vMap.Extent() != 8 )
4657 for ( int i = 1; i <= 8; ++i )
4658 myBox.Add( BRep_Tool::Pnt( TopoDS::Vertex( vMap( i ))).XYZ() );
4660 gp_XYZ pMin = myBox.CornerMin(), pMax = myBox.CornerMax();
4661 for ( int i = 1; i <= 8; ++i )
4663 gp_Pnt p = BRep_Tool::Pnt( TopoDS::Vertex( vMap( i )));
4664 for ( int iC = 1; iC <= 3; ++ iC )
4666 double d1 = Abs( pMin.Coord( iC ) - p.Coord( iC ));
4667 double d2 = Abs( pMax.Coord( iC ) - p.Coord( iC ));
4668 if ( Min( d1, d2 ) > myTol )
4672 myBox.Enlarge( myTol );
4677 OctreeClassifier::OctreeClassifier( const std::vector< ElementsOnShape::Classifier* >& classifiers )
4678 :SMESH_Octree( new SMESH_TreeLimit )
4680 myClassifiers = classifiers;
4685 OctreeClassifier::OctreeClassifier( const OctreeClassifier* otherTree,
4686 const std::vector< ElementsOnShape::Classifier >& clsOther,
4687 std::vector< ElementsOnShape::Classifier >& cls )
4688 :SMESH_Octree( new SMESH_TreeLimit )
4690 myBox = new Bnd_B3d( *otherTree->getBox() );
4692 if (( myIsLeaf = otherTree->isLeaf() ))
4694 myClassifiers.resize( otherTree->myClassifiers.size() );
4695 for ( size_t i = 0; i < otherTree->myClassifiers.size(); ++i )
4697 int ind = otherTree->myClassifiers[i] - & clsOther[0];
4698 myClassifiers[ i ] = & cls[ ind ];
4701 else if ( otherTree->myChildren )
4703 myChildren = new SMESH_Tree< Bnd_B3d, 8 > * [ 8 ];
4704 for ( int i = 0; i < nbChildren(); i++ )
4706 new OctreeClassifier( static_cast<const OctreeClassifier*>( otherTree->myChildren[i]),
4711 void ElementsOnShape::
4712 OctreeClassifier::GetClassifiersAtPoint( const gp_XYZ& point,
4713 std::vector< ElementsOnShape::Classifier* >& result )
4715 if ( getBox()->IsOut( point ))
4720 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4721 if ( !myClassifiers[i]->GetBndBox()->IsOut( point ))
4722 result.push_back( myClassifiers[i] );
4726 for (int i = 0; i < nbChildren(); i++)
4727 ((OctreeClassifier*) myChildren[i])->GetClassifiersAtPoint( point, result );
4731 void ElementsOnShape::OctreeClassifier::buildChildrenData()
4733 // distribute myClassifiers among myChildren
4735 const int childFlag[8] = { 0x0000001,
4743 int nbInChild[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
4745 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4747 for ( int j = 0; j < nbChildren(); j++ )
4749 if ( !myClassifiers[i]->GetBndBox()->IsOut( *myChildren[j]->getBox() ))
4751 myClassifiers[i]->SetFlag( childFlag[ j ]);
4757 for ( int j = 0; j < nbChildren(); j++ )
4759 OctreeClassifier* child = static_cast<OctreeClassifier*>( myChildren[ j ]);
4760 child->myClassifiers.resize( nbInChild[ j ]);
4761 for ( size_t i = 0; nbInChild[ j ] && i < myClassifiers.size(); ++i )
4763 if ( myClassifiers[ i ]->IsSetFlag( childFlag[ j ]))
4766 child->myClassifiers[ nbInChild[ j ]] = myClassifiers[ i ];
4767 myClassifiers[ i ]->UnsetFlag( childFlag[ j ]);
4771 SMESHUtils::FreeVector( myClassifiers );
4773 // define if a child isLeaf()
4774 for ( int i = 0; i < nbChildren(); i++ )
4776 OctreeClassifier* child = static_cast<OctreeClassifier*>( myChildren[ i ]);
4777 child->myIsLeaf = ( child->myClassifiers.size() <= 5 );
4781 Bnd_B3d* ElementsOnShape::OctreeClassifier::buildRootBox()
4783 Bnd_B3d* box = new Bnd_B3d;
4784 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4785 box->Add( *myClassifiers[i]->GetBndBox() );
4790 Class : BelongToGeom
4791 Description : Predicate for verifying whether entity belongs to
4792 specified geometrical support
4795 BelongToGeom::BelongToGeom()
4797 myType(SMDSAbs_NbElementTypes),
4798 myIsSubshape(false),
4799 myTolerance(Precision::Confusion())
4802 Predicate* BelongToGeom::clone() const
4804 BelongToGeom* cln = new BelongToGeom( *this );
4805 cln->myElementsOnShapePtr.reset( static_cast<ElementsOnShape*>( myElementsOnShapePtr->clone() ));
4809 void BelongToGeom::SetMesh( const SMDS_Mesh* theMesh )
4811 if ( myMeshDS != theMesh )
4813 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
4818 void BelongToGeom::SetGeom( const TopoDS_Shape& theShape )
4820 if ( myShape != theShape )
4827 static bool IsSubShape (const TopTools_IndexedMapOfShape& theMap,
4828 const TopoDS_Shape& theShape)
4830 if (theMap.Contains(theShape)) return true;
4832 if (theShape.ShapeType() == TopAbs_COMPOUND ||
4833 theShape.ShapeType() == TopAbs_COMPSOLID)
4835 TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
4836 for (; anIt.More(); anIt.Next())
4838 if (!IsSubShape(theMap, anIt.Value())) {
4848 void BelongToGeom::init()
4850 if ( !myMeshDS || myShape.IsNull() ) return;
4852 // is sub-shape of main shape?
4853 TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
4854 if (aMainShape.IsNull()) {
4855 myIsSubshape = false;
4858 TopTools_IndexedMapOfShape aMap;
4859 TopExp::MapShapes( aMainShape, aMap );
4860 myIsSubshape = IsSubShape( aMap, myShape );
4864 TopExp::MapShapes( myShape, aMap );
4865 mySubShapesIDs.Clear();
4866 for ( int i = 1; i <= aMap.Extent(); ++i )
4868 int subID = myMeshDS->ShapeToIndex( aMap( i ));
4870 mySubShapesIDs.Add( subID );
4875 //if (!myIsSubshape) // to be always ready to check an element not bound to geometry
4877 if ( !myElementsOnShapePtr )
4878 myElementsOnShapePtr.reset( new ElementsOnShape() );
4879 myElementsOnShapePtr->SetTolerance( myTolerance );
4880 myElementsOnShapePtr->SetAllNodes( true ); // "belong", while false means "lays on"
4881 myElementsOnShapePtr->SetMesh( myMeshDS );
4882 myElementsOnShapePtr->SetShape( myShape, myType );
4886 bool BelongToGeom::IsSatisfy (long theId)
4888 if (myMeshDS == 0 || myShape.IsNull())
4893 return myElementsOnShapePtr->IsSatisfy(theId);
4898 if (myType == SMDSAbs_Node)
4900 if ( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ))
4902 if ( aNode->getshapeId() < 1 )
4903 return myElementsOnShapePtr->IsSatisfy(theId);
4905 return mySubShapesIDs.Contains( aNode->getshapeId() );
4910 if ( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ))
4912 if ( anElem->GetType() == myType )
4914 if ( anElem->getshapeId() < 1 )
4915 return myElementsOnShapePtr->IsSatisfy(theId);
4917 return mySubShapesIDs.Contains( anElem->getshapeId() );
4925 void BelongToGeom::SetType (SMDSAbs_ElementType theType)
4927 if ( myType != theType )
4934 SMDSAbs_ElementType BelongToGeom::GetType() const
4939 TopoDS_Shape BelongToGeom::GetShape()
4944 const SMESHDS_Mesh* BelongToGeom::GetMeshDS() const
4949 void BelongToGeom::SetTolerance (double theTolerance)
4951 myTolerance = theTolerance;
4955 double BelongToGeom::GetTolerance()
4962 Description : Predicate for verifying whether entiy lying or partially lying on
4963 specified geometrical support
4966 LyingOnGeom::LyingOnGeom()
4968 myType(SMDSAbs_NbElementTypes),
4969 myIsSubshape(false),
4970 myTolerance(Precision::Confusion())
4973 Predicate* LyingOnGeom::clone() const
4975 LyingOnGeom* cln = new LyingOnGeom( *this );
4976 cln->myElementsOnShapePtr.reset( static_cast<ElementsOnShape*>( myElementsOnShapePtr->clone() ));
4980 void LyingOnGeom::SetMesh( const SMDS_Mesh* theMesh )
4982 if ( myMeshDS != theMesh )
4984 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
4989 void LyingOnGeom::SetGeom( const TopoDS_Shape& theShape )
4991 if ( myShape != theShape )
4998 void LyingOnGeom::init()
5000 if (!myMeshDS || myShape.IsNull()) return;
5002 // is sub-shape of main shape?
5003 TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
5004 if (aMainShape.IsNull()) {
5005 myIsSubshape = false;
5008 myIsSubshape = myMeshDS->IsGroupOfSubShapes( myShape );
5013 TopTools_IndexedMapOfShape shapes;
5014 TopExp::MapShapes( myShape, shapes );
5015 mySubShapesIDs.Clear();
5016 for ( int i = 1; i <= shapes.Extent(); ++i )
5018 int subID = myMeshDS->ShapeToIndex( shapes( i ));
5020 mySubShapesIDs.Add( subID );
5023 // else // to be always ready to check an element not bound to geometry
5025 if ( !myElementsOnShapePtr )
5026 myElementsOnShapePtr.reset( new ElementsOnShape() );
5027 myElementsOnShapePtr->SetTolerance( myTolerance );
5028 myElementsOnShapePtr->SetAllNodes( false ); // lays on, while true means "belong"
5029 myElementsOnShapePtr->SetMesh( myMeshDS );
5030 myElementsOnShapePtr->SetShape( myShape, myType );
5034 bool LyingOnGeom::IsSatisfy( long theId )
5036 if ( myMeshDS == 0 || myShape.IsNull() )
5041 return myElementsOnShapePtr->IsSatisfy(theId);
5046 const SMDS_MeshElement* elem =
5047 ( myType == SMDSAbs_Node ) ? myMeshDS->FindNode( theId ) : myMeshDS->FindElement( theId );
5049 if ( mySubShapesIDs.Contains( elem->getshapeId() ))
5052 if ( elem->GetType() != SMDSAbs_Node && elem->GetType() == myType )
5054 SMDS_ElemIteratorPtr nodeItr = elem->nodesIterator();
5055 while ( nodeItr->more() )
5057 const SMDS_MeshElement* aNode = nodeItr->next();
5058 if ( mySubShapesIDs.Contains( aNode->getshapeId() ))
5066 void LyingOnGeom::SetType( SMDSAbs_ElementType theType )
5068 if ( myType != theType )
5075 SMDSAbs_ElementType LyingOnGeom::GetType() const
5080 TopoDS_Shape LyingOnGeom::GetShape()
5085 const SMESHDS_Mesh* LyingOnGeom::GetMeshDS() const
5090 void LyingOnGeom::SetTolerance (double theTolerance)
5092 myTolerance = theTolerance;
5096 double LyingOnGeom::GetTolerance()
5101 TSequenceOfXYZ::TSequenceOfXYZ(): myElem(0)
5104 TSequenceOfXYZ::TSequenceOfXYZ(size_type n) : myArray(n), myElem(0)
5107 TSequenceOfXYZ::TSequenceOfXYZ(size_type n, const gp_XYZ& t) : myArray(n,t), myElem(0)
5110 TSequenceOfXYZ::TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ) : myArray(theSequenceOfXYZ.myArray), myElem(theSequenceOfXYZ.myElem)
5113 template <class InputIterator>
5114 TSequenceOfXYZ::TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd): myArray(theBegin,theEnd), myElem(0)
5117 TSequenceOfXYZ::~TSequenceOfXYZ()
5120 TSequenceOfXYZ& TSequenceOfXYZ::operator=(const TSequenceOfXYZ& theSequenceOfXYZ)
5122 myArray = theSequenceOfXYZ.myArray;
5123 myElem = theSequenceOfXYZ.myElem;
5127 gp_XYZ& TSequenceOfXYZ::operator()(size_type n)
5129 return myArray[n-1];
5132 const gp_XYZ& TSequenceOfXYZ::operator()(size_type n) const
5134 return myArray[n-1];
5137 void TSequenceOfXYZ::clear()
5142 void TSequenceOfXYZ::reserve(size_type n)
5147 void TSequenceOfXYZ::push_back(const gp_XYZ& v)
5149 myArray.push_back(v);
5152 TSequenceOfXYZ::size_type TSequenceOfXYZ::size() const
5154 return myArray.size();
5157 SMDSAbs_EntityType TSequenceOfXYZ::getElementEntity() const
5159 return myElem ? myElem->GetEntityType() : SMDSEntity_Last;
5162 TMeshModifTracer::TMeshModifTracer():
5163 myMeshModifTime(0), myMesh(0)
5166 void TMeshModifTracer::SetMesh( const SMDS_Mesh* theMesh )
5168 if ( theMesh != myMesh )
5169 myMeshModifTime = 0;
5172 bool TMeshModifTracer::IsMeshModified()
5174 bool modified = false;
5177 modified = ( myMeshModifTime != myMesh->GetMTime() );
5178 myMeshModifTime = myMesh->GetMTime();