1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "SMESH_ControlsDef.hxx"
25 #include "SMDS_BallElement.hxx"
26 #include "SMDS_FacePosition.hxx"
27 #include "SMDS_Iterator.hxx"
28 #include "SMDS_Mesh.hxx"
29 #include "SMDS_MeshElement.hxx"
30 #include "SMDS_MeshNode.hxx"
31 #include "SMDS_QuadraticEdge.hxx"
32 #include "SMDS_QuadraticFaceOfNodes.hxx"
33 #include "SMDS_VolumeTool.hxx"
34 #include "SMESHDS_GroupBase.hxx"
35 #include "SMESHDS_GroupOnFilter.hxx"
36 #include "SMESHDS_Mesh.hxx"
37 #include "SMESH_MeshAlgos.hxx"
38 #include "SMESH_OctreeNode.hxx"
40 #include <Basics_Utils.hxx>
42 #include <BRepAdaptor_Surface.hxx>
43 #include <BRepBndLib.hxx>
44 #include <BRepBuilderAPI_Copy.hxx>
45 #include <BRepClass3d_SolidClassifier.hxx>
46 #include <BRepClass_FaceClassifier.hxx>
47 #include <BRep_Tool.hxx>
48 #include <GeomLib_IsPlanarSurface.hxx>
49 #include <Geom_CylindricalSurface.hxx>
50 #include <Geom_Plane.hxx>
51 #include <Geom_Surface.hxx>
52 #include <NCollection_Map.hxx>
53 #include <Precision.hxx>
54 #include <ShapeAnalysis_Surface.hxx>
55 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
56 #include <TColStd_MapOfInteger.hxx>
57 #include <TColStd_SequenceOfAsciiString.hxx>
58 #include <TColgp_Array1OfXYZ.hxx>
62 #include <TopoDS_Edge.hxx>
63 #include <TopoDS_Face.hxx>
64 #include <TopoDS_Iterator.hxx>
65 #include <TopoDS_Shape.hxx>
66 #include <TopoDS_Vertex.hxx>
68 #include <gp_Cylinder.hxx>
75 #include <vtkMeshQuality.h>
86 const double theEps = 1e-100;
87 const double theInf = 1e+100;
89 inline gp_XYZ gpXYZ(const SMDS_MeshNode* aNode )
91 return gp_XYZ(aNode->X(), aNode->Y(), aNode->Z() );
94 inline double getAngle( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
96 gp_Vec v1( P1 - P2 ), v2( P3 - P2 );
98 return v1.Magnitude() < gp::Resolution() ||
99 v2.Magnitude() < gp::Resolution() ? 0 : v1.Angle( v2 );
102 inline double getCos2( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
104 gp_Vec v1( P1 - P2 ), v2( P3 - P2 );
105 double dot = v1 * v2, len1 = v1.SquareMagnitude(), len2 = v2.SquareMagnitude();
107 return ( dot < 0 || len1 < gp::Resolution() || len2 < gp::Resolution() ? -1 :
108 dot * dot / len1 / len2 );
111 inline double getArea( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
113 gp_Vec aVec1( P2 - P1 );
114 gp_Vec aVec2( P3 - P1 );
115 return ( aVec1 ^ aVec2 ).Magnitude() * 0.5;
118 inline double getArea( const gp_Pnt& P1, const gp_Pnt& P2, const gp_Pnt& P3 )
120 return getArea( P1.XYZ(), P2.XYZ(), P3.XYZ() );
125 inline double getDistance( const gp_XYZ& P1, const gp_XYZ& P2 )
127 double aDist = gp_Pnt( P1 ).Distance( gp_Pnt( P2 ) );
131 int getNbMultiConnection( const SMDS_Mesh* theMesh, const int theId )
136 const SMDS_MeshElement* anEdge = theMesh->FindElement( theId );
137 if ( anEdge == 0 || anEdge->GetType() != SMDSAbs_Edge/* || anEdge->NbNodes() != 2 */)
140 // for each pair of nodes in anEdge (there are 2 pairs in a quadratic edge)
141 // count elements containing both nodes of the pair.
142 // Note that there may be such cases for a quadratic edge (a horizontal line):
147 // +-----+------+ +-----+------+
150 // result should be 2 in both cases
152 int aResult0 = 0, aResult1 = 0;
153 // last node, it is a medium one in a quadratic edge
154 const SMDS_MeshNode* aLastNode = anEdge->GetNode( anEdge->NbNodes() - 1 );
155 const SMDS_MeshNode* aNode0 = anEdge->GetNode( 0 );
156 const SMDS_MeshNode* aNode1 = anEdge->GetNode( 1 );
157 if ( aNode1 == aLastNode ) aNode1 = 0;
159 SMDS_ElemIteratorPtr anElemIter = aLastNode->GetInverseElementIterator();
160 while( anElemIter->more() ) {
161 const SMDS_MeshElement* anElem = anElemIter->next();
162 if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) {
163 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
164 while ( anIter->more() ) {
165 if ( const SMDS_MeshElement* anElemNode = anIter->next() ) {
166 if ( anElemNode == aNode0 ) {
168 if ( !aNode1 ) break; // not a quadratic edge
170 else if ( anElemNode == aNode1 )
176 int aResult = std::max ( aResult0, aResult1 );
181 gp_XYZ getNormale( const SMDS_MeshFace* theFace, bool* ok=0 )
183 int aNbNode = theFace->NbNodes();
185 gp_XYZ q1 = gpXYZ( theFace->GetNode(1)) - gpXYZ( theFace->GetNode(0));
186 gp_XYZ q2 = gpXYZ( theFace->GetNode(2)) - gpXYZ( theFace->GetNode(0));
189 gp_XYZ q3 = gpXYZ( theFace->GetNode(3)) - gpXYZ( theFace->GetNode(0));
192 double len = n.Modulus();
193 bool zeroLen = ( len <= std::numeric_limits<double>::min());
197 if (ok) *ok = !zeroLen;
205 using namespace SMESH::Controls;
211 //================================================================================
213 Class : NumericalFunctor
214 Description : Base class for numerical functors
216 //================================================================================
218 NumericalFunctor::NumericalFunctor():
224 void NumericalFunctor::SetMesh( const SMDS_Mesh* theMesh )
229 bool NumericalFunctor::GetPoints(const int theId,
230 TSequenceOfXYZ& theRes ) const
237 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
238 if ( !anElem || anElem->GetType() != this->GetType() )
241 return GetPoints( anElem, theRes );
244 bool NumericalFunctor::GetPoints(const SMDS_MeshElement* anElem,
245 TSequenceOfXYZ& theRes )
252 theRes.reserve( anElem->NbNodes() );
253 theRes.setElement( anElem );
255 // Get nodes of the element
256 SMDS_ElemIteratorPtr anIter;
258 if ( anElem->IsQuadratic() ) {
259 switch ( anElem->GetType() ) {
261 anIter = dynamic_cast<const SMDS_VtkEdge*>
262 (anElem)->interlacedNodesElemIterator();
265 anIter = dynamic_cast<const SMDS_VtkFace*>
266 (anElem)->interlacedNodesElemIterator();
269 anIter = anElem->nodesIterator();
273 anIter = anElem->nodesIterator();
278 while( anIter->more() ) {
279 if ( p.Set( anIter->next() ))
280 theRes.push_back( p );
287 long NumericalFunctor::GetPrecision() const
292 void NumericalFunctor::SetPrecision( const long thePrecision )
294 myPrecision = thePrecision;
295 myPrecisionValue = pow( 10., (double)( myPrecision ) );
298 double NumericalFunctor::GetValue( long theId )
302 myCurrElement = myMesh->FindElement( theId );
305 if ( GetPoints( theId, P )) // elem type is checked here
306 aVal = Round( GetValue( P ));
311 double NumericalFunctor::Round( const double & aVal )
313 return ( myPrecision >= 0 ) ? floor( aVal * myPrecisionValue + 0.5 ) / myPrecisionValue : aVal;
316 //================================================================================
318 * \brief Return histogram of functor values
319 * \param nbIntervals - number of intervals
320 * \param nbEvents - number of mesh elements having values within i-th interval
321 * \param funValues - boundaries of intervals
322 * \param elements - elements to check vulue of; empty list means "of all"
323 * \param minmax - boundaries of diapason of values to divide into intervals
325 //================================================================================
327 void NumericalFunctor::GetHistogram(int nbIntervals,
328 std::vector<int>& nbEvents,
329 std::vector<double>& funValues,
330 const std::vector<int>& elements,
331 const double* minmax,
332 const bool isLogarithmic)
334 if ( nbIntervals < 1 ||
336 !myMesh->GetMeshInfo().NbElements( GetType() ))
338 nbEvents.resize( nbIntervals, 0 );
339 funValues.resize( nbIntervals+1 );
341 // get all values sorted
342 std::multiset< double > values;
343 if ( elements.empty() )
345 SMDS_ElemIteratorPtr elemIt = myMesh->elementsIterator( GetType() );
346 while ( elemIt->more() )
347 values.insert( GetValue( elemIt->next()->GetID() ));
351 std::vector<int>::const_iterator id = elements.begin();
352 for ( ; id != elements.end(); ++id )
353 values.insert( GetValue( *id ));
358 funValues[0] = minmax[0];
359 funValues[nbIntervals] = minmax[1];
363 funValues[0] = *values.begin();
364 funValues[nbIntervals] = *values.rbegin();
366 // case nbIntervals == 1
367 if ( nbIntervals == 1 )
369 nbEvents[0] = values.size();
373 if (funValues.front() == funValues.back())
375 nbEvents.resize( 1 );
376 nbEvents[0] = values.size();
377 funValues[1] = funValues.back();
378 funValues.resize( 2 );
381 std::multiset< double >::iterator min = values.begin(), max;
382 for ( int i = 0; i < nbIntervals; ++i )
384 // find end value of i-th interval
385 double r = (i+1) / double(nbIntervals);
386 if (isLogarithmic && funValues.front() > 1e-07 && funValues.back() > 1e-07) {
387 double logmin = log10(funValues.front());
388 double lval = logmin + r * (log10(funValues.back()) - logmin);
389 funValues[i+1] = pow(10.0, lval);
392 funValues[i+1] = funValues.front() * (1-r) + funValues.back() * r;
395 // count values in the i-th interval if there are any
396 if ( min != values.end() && *min <= funValues[i+1] )
398 // find the first value out of the interval
399 max = values.upper_bound( funValues[i+1] ); // max is greater than funValues[i+1], or end()
400 nbEvents[i] = std::distance( min, max );
404 // add values larger than minmax[1]
405 nbEvents.back() += std::distance( min, values.end() );
408 //=======================================================================
411 Description : Functor calculating volume of a 3D element
413 //================================================================================
415 double Volume::GetValue( long theElementId )
417 if ( theElementId && myMesh ) {
418 SMDS_VolumeTool aVolumeTool;
419 if ( aVolumeTool.Set( myMesh->FindElement( theElementId )))
420 return aVolumeTool.GetSize();
425 double Volume::GetBadRate( double Value, int /*nbNodes*/ ) const
430 SMDSAbs_ElementType Volume::GetType() const
432 return SMDSAbs_Volume;
435 //=======================================================================
437 Class : MaxElementLength2D
438 Description : Functor calculating maximum length of 2D element
440 //================================================================================
442 double MaxElementLength2D::GetValue( const TSequenceOfXYZ& P )
448 if( len == 3 ) { // triangles
449 double L1 = getDistance(P( 1 ),P( 2 ));
450 double L2 = getDistance(P( 2 ),P( 3 ));
451 double L3 = getDistance(P( 3 ),P( 1 ));
452 aVal = Max(L1,Max(L2,L3));
454 else if( len == 4 ) { // quadrangles
455 double L1 = getDistance(P( 1 ),P( 2 ));
456 double L2 = getDistance(P( 2 ),P( 3 ));
457 double L3 = getDistance(P( 3 ),P( 4 ));
458 double L4 = getDistance(P( 4 ),P( 1 ));
459 double D1 = getDistance(P( 1 ),P( 3 ));
460 double D2 = getDistance(P( 2 ),P( 4 ));
461 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(D1,D2));
463 else if( len == 6 ) { // quadratic triangles
464 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
465 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
466 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 1 ));
467 aVal = Max(L1,Max(L2,L3));
469 else if( len == 8 || len == 9 ) { // quadratic quadrangles
470 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
471 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
472 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 7 ));
473 double L4 = getDistance(P( 7 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
474 double D1 = getDistance(P( 1 ),P( 5 ));
475 double D2 = getDistance(P( 3 ),P( 7 ));
476 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(D1,D2));
478 // Diagonals are undefined for concave polygons
479 // else if ( P.getElementEntity() == SMDSEntity_Quad_Polygon && P.size() > 2 ) // quad polygon
482 // aVal = getDistance( P( 1 ), P( P.size() )) + getDistance( P( P.size() ), P( P.size()-1 ));
483 // for ( size_t i = 1; i < P.size()-1; i += 2 )
485 // double L = getDistance( P( i ), P( i+1 )) + getDistance( P( i+1 ), P( i+2 ));
486 // aVal = Max( aVal, L );
489 // for ( int i = P.size()-5; i > 0; i -= 2 )
490 // for ( int j = i + 4; j < P.size() + i - 2; i += 2 )
492 // double D = getDistance( P( i ), P( j ));
493 // aVal = Max( aVal, D );
500 if( myPrecision >= 0 )
502 double prec = pow( 10., (double)myPrecision );
503 aVal = floor( aVal * prec + 0.5 ) / prec;
508 double MaxElementLength2D::GetValue( long theElementId )
511 return GetPoints( theElementId, P ) ? GetValue(P) : 0.0;
514 double MaxElementLength2D::GetBadRate( double Value, int /*nbNodes*/ ) const
519 SMDSAbs_ElementType MaxElementLength2D::GetType() const
524 //=======================================================================
526 Class : MaxElementLength3D
527 Description : Functor calculating maximum length of 3D element
529 //================================================================================
531 double MaxElementLength3D::GetValue( long theElementId )
534 if( GetPoints( theElementId, P ) ) {
536 const SMDS_MeshElement* aElem = myMesh->FindElement( theElementId );
537 SMDSAbs_EntityType aType = aElem->GetEntityType();
540 case SMDSEntity_Tetra: { // tetras
541 double L1 = getDistance(P( 1 ),P( 2 ));
542 double L2 = getDistance(P( 2 ),P( 3 ));
543 double L3 = getDistance(P( 3 ),P( 1 ));
544 double L4 = getDistance(P( 1 ),P( 4 ));
545 double L5 = getDistance(P( 2 ),P( 4 ));
546 double L6 = getDistance(P( 3 ),P( 4 ));
547 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
550 case SMDSEntity_Pyramid: { // pyramids
551 double L1 = getDistance(P( 1 ),P( 2 ));
552 double L2 = getDistance(P( 2 ),P( 3 ));
553 double L3 = getDistance(P( 3 ),P( 4 ));
554 double L4 = getDistance(P( 4 ),P( 1 ));
555 double L5 = getDistance(P( 1 ),P( 5 ));
556 double L6 = getDistance(P( 2 ),P( 5 ));
557 double L7 = getDistance(P( 3 ),P( 5 ));
558 double L8 = getDistance(P( 4 ),P( 5 ));
559 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
560 aVal = Max(aVal,Max(L7,L8));
563 case SMDSEntity_Penta: { // pentas
564 double L1 = getDistance(P( 1 ),P( 2 ));
565 double L2 = getDistance(P( 2 ),P( 3 ));
566 double L3 = getDistance(P( 3 ),P( 1 ));
567 double L4 = getDistance(P( 4 ),P( 5 ));
568 double L5 = getDistance(P( 5 ),P( 6 ));
569 double L6 = getDistance(P( 6 ),P( 4 ));
570 double L7 = getDistance(P( 1 ),P( 4 ));
571 double L8 = getDistance(P( 2 ),P( 5 ));
572 double L9 = getDistance(P( 3 ),P( 6 ));
573 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
574 aVal = Max(aVal,Max(Max(L7,L8),L9));
577 case SMDSEntity_Hexa: { // hexas
578 double L1 = getDistance(P( 1 ),P( 2 ));
579 double L2 = getDistance(P( 2 ),P( 3 ));
580 double L3 = getDistance(P( 3 ),P( 4 ));
581 double L4 = getDistance(P( 4 ),P( 1 ));
582 double L5 = getDistance(P( 5 ),P( 6 ));
583 double L6 = getDistance(P( 6 ),P( 7 ));
584 double L7 = getDistance(P( 7 ),P( 8 ));
585 double L8 = getDistance(P( 8 ),P( 5 ));
586 double L9 = getDistance(P( 1 ),P( 5 ));
587 double L10= getDistance(P( 2 ),P( 6 ));
588 double L11= getDistance(P( 3 ),P( 7 ));
589 double L12= getDistance(P( 4 ),P( 8 ));
590 double D1 = getDistance(P( 1 ),P( 7 ));
591 double D2 = getDistance(P( 2 ),P( 8 ));
592 double D3 = getDistance(P( 3 ),P( 5 ));
593 double D4 = getDistance(P( 4 ),P( 6 ));
594 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
595 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
596 aVal = Max(aVal,Max(L11,L12));
597 aVal = Max(aVal,Max(Max(D1,D2),Max(D3,D4)));
600 case SMDSEntity_Hexagonal_Prism: { // hexagonal prism
601 for ( int i1 = 1; i1 < 12; ++i1 )
602 for ( int i2 = i1+1; i1 <= 12; ++i1 )
603 aVal = Max( aVal, getDistance(P( i1 ),P( i2 )));
606 case SMDSEntity_Quad_Tetra: { // quadratic tetras
607 double L1 = getDistance(P( 1 ),P( 5 )) + getDistance(P( 5 ),P( 2 ));
608 double L2 = getDistance(P( 2 ),P( 6 )) + getDistance(P( 6 ),P( 3 ));
609 double L3 = getDistance(P( 3 ),P( 7 )) + getDistance(P( 7 ),P( 1 ));
610 double L4 = getDistance(P( 1 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
611 double L5 = getDistance(P( 2 ),P( 9 )) + getDistance(P( 9 ),P( 4 ));
612 double L6 = getDistance(P( 3 ),P( 10 )) + getDistance(P( 10 ),P( 4 ));
613 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
616 case SMDSEntity_Quad_Pyramid: { // quadratic pyramids
617 double L1 = getDistance(P( 1 ),P( 6 )) + getDistance(P( 6 ),P( 2 ));
618 double L2 = getDistance(P( 2 ),P( 7 )) + getDistance(P( 7 ),P( 3 ));
619 double L3 = getDistance(P( 3 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
620 double L4 = getDistance(P( 4 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
621 double L5 = getDistance(P( 1 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
622 double L6 = getDistance(P( 2 ),P( 11 )) + getDistance(P( 11 ),P( 5 ));
623 double L7 = getDistance(P( 3 ),P( 12 )) + getDistance(P( 12 ),P( 5 ));
624 double L8 = getDistance(P( 4 ),P( 13 )) + getDistance(P( 13 ),P( 5 ));
625 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
626 aVal = Max(aVal,Max(L7,L8));
629 case SMDSEntity_Quad_Penta:
630 case SMDSEntity_BiQuad_Penta: { // quadratic pentas
631 double L1 = getDistance(P( 1 ),P( 7 )) + getDistance(P( 7 ),P( 2 ));
632 double L2 = getDistance(P( 2 ),P( 8 )) + getDistance(P( 8 ),P( 3 ));
633 double L3 = getDistance(P( 3 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
634 double L4 = getDistance(P( 4 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
635 double L5 = getDistance(P( 5 ),P( 11 )) + getDistance(P( 11 ),P( 6 ));
636 double L6 = getDistance(P( 6 ),P( 12 )) + getDistance(P( 12 ),P( 4 ));
637 double L7 = getDistance(P( 1 ),P( 13 )) + getDistance(P( 13 ),P( 4 ));
638 double L8 = getDistance(P( 2 ),P( 14 )) + getDistance(P( 14 ),P( 5 ));
639 double L9 = getDistance(P( 3 ),P( 15 )) + getDistance(P( 15 ),P( 6 ));
640 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
641 aVal = Max(aVal,Max(Max(L7,L8),L9));
644 case SMDSEntity_Quad_Hexa:
645 case SMDSEntity_TriQuad_Hexa: { // quadratic hexas
646 double L1 = getDistance(P( 1 ),P( 9 )) + getDistance(P( 9 ),P( 2 ));
647 double L2 = getDistance(P( 2 ),P( 10 )) + getDistance(P( 10 ),P( 3 ));
648 double L3 = getDistance(P( 3 ),P( 11 )) + getDistance(P( 11 ),P( 4 ));
649 double L4 = getDistance(P( 4 ),P( 12 )) + getDistance(P( 12 ),P( 1 ));
650 double L5 = getDistance(P( 5 ),P( 13 )) + getDistance(P( 13 ),P( 6 ));
651 double L6 = getDistance(P( 6 ),P( 14 )) + getDistance(P( 14 ),P( 7 ));
652 double L7 = getDistance(P( 7 ),P( 15 )) + getDistance(P( 15 ),P( 8 ));
653 double L8 = getDistance(P( 8 ),P( 16 )) + getDistance(P( 16 ),P( 5 ));
654 double L9 = getDistance(P( 1 ),P( 17 )) + getDistance(P( 17 ),P( 5 ));
655 double L10= getDistance(P( 2 ),P( 18 )) + getDistance(P( 18 ),P( 6 ));
656 double L11= getDistance(P( 3 ),P( 19 )) + getDistance(P( 19 ),P( 7 ));
657 double L12= getDistance(P( 4 ),P( 20 )) + getDistance(P( 20 ),P( 8 ));
658 double D1 = getDistance(P( 1 ),P( 7 ));
659 double D2 = getDistance(P( 2 ),P( 8 ));
660 double D3 = getDistance(P( 3 ),P( 5 ));
661 double D4 = getDistance(P( 4 ),P( 6 ));
662 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
663 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
664 aVal = Max(aVal,Max(L11,L12));
665 aVal = Max(aVal,Max(Max(D1,D2),Max(D3,D4)));
668 case SMDSEntity_Quad_Polyhedra:
669 case SMDSEntity_Polyhedra: { // polys
670 // get the maximum distance between all pairs of nodes
671 for( int i = 1; i <= len; i++ ) {
672 for( int j = 1; j <= len; j++ ) {
673 if( j > i ) { // optimization of the loop
674 double D = getDistance( P(i), P(j) );
675 aVal = Max( aVal, D );
681 case SMDSEntity_Node:
683 case SMDSEntity_Edge:
684 case SMDSEntity_Quad_Edge:
685 case SMDSEntity_Triangle:
686 case SMDSEntity_Quad_Triangle:
687 case SMDSEntity_BiQuad_Triangle:
688 case SMDSEntity_Quadrangle:
689 case SMDSEntity_Quad_Quadrangle:
690 case SMDSEntity_BiQuad_Quadrangle:
691 case SMDSEntity_Polygon:
692 case SMDSEntity_Quad_Polygon:
693 case SMDSEntity_Ball:
694 case SMDSEntity_Last: return 0;
695 } // switch ( aType )
697 if( myPrecision >= 0 )
699 double prec = pow( 10., (double)myPrecision );
700 aVal = floor( aVal * prec + 0.5 ) / prec;
707 double MaxElementLength3D::GetBadRate( double Value, int /*nbNodes*/ ) const
712 SMDSAbs_ElementType MaxElementLength3D::GetType() const
714 return SMDSAbs_Volume;
717 //=======================================================================
720 Description : Functor for calculation of minimum angle
722 //================================================================================
724 double MinimumAngle::GetValue( const TSequenceOfXYZ& P )
731 aMaxCos2 = getCos2( P( P.size() ), P( 1 ), P( 2 ));
732 aMaxCos2 = Max( aMaxCos2, getCos2( P( P.size()-1 ), P( P.size() ), P( 1 )));
734 for ( size_t i = 2; i < P.size(); i++ )
736 double A0 = getCos2( P( i-1 ), P( i ), P( i+1 ) );
737 aMaxCos2 = Max( aMaxCos2, A0 );
740 return 0; // all nodes coincide
742 double cos = sqrt( aMaxCos2 );
743 if ( cos >= 1 ) return 0;
744 return acos( cos ) * 180.0 / M_PI;
747 double MinimumAngle::GetBadRate( double Value, int nbNodes ) const
749 //const double aBestAngle = PI / nbNodes;
750 const double aBestAngle = 180.0 - ( 360.0 / double(nbNodes) );
751 return ( fabs( aBestAngle - Value ));
754 SMDSAbs_ElementType MinimumAngle::GetType() const
760 //================================================================================
763 Description : Functor for calculating aspect ratio
765 //================================================================================
767 double AspectRatio::GetValue( long theId )
770 myCurrElement = myMesh->FindElement( theId );
771 if ( myCurrElement && myCurrElement->GetVtkType() == VTK_QUAD )
774 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myCurrElement->getMeshId()]->getGrid();
775 if ( vtkCell* avtkCell = grid->GetCell( myCurrElement->getVtkId() ))
776 aVal = Round( vtkMeshQuality::QuadAspectRatio( avtkCell ));
781 if ( GetPoints( myCurrElement, P ))
782 aVal = Round( GetValue( P ));
787 double AspectRatio::GetValue( const TSequenceOfXYZ& P )
789 // According to "Mesh quality control" by Nadir Bouhamau referring to
790 // Pascal Jean Frey and Paul-Louis George. Maillages, applications aux elements finis.
791 // Hermes Science publications, Paris 1999 ISBN 2-7462-0024-4
794 int nbNodes = P.size();
799 // Compute aspect ratio
801 if ( nbNodes == 3 ) {
802 // Compute lengths of the sides
803 double aLen1 = getDistance( P( 1 ), P( 2 ));
804 double aLen2 = getDistance( P( 2 ), P( 3 ));
805 double aLen3 = getDistance( P( 3 ), P( 1 ));
806 // Q = alfa * h * p / S, where
808 // alfa = sqrt( 3 ) / 6
809 // h - length of the longest edge
810 // p - half perimeter
811 // S - triangle surface
812 const double alfa = sqrt( 3. ) / 6.;
813 double maxLen = Max( aLen1, Max( aLen2, aLen3 ));
814 double half_perimeter = ( aLen1 + aLen2 + aLen3 ) / 2.;
815 double anArea = getArea( P( 1 ), P( 2 ), P( 3 ));
816 if ( anArea <= theEps )
818 return alfa * maxLen * half_perimeter / anArea;
820 else if ( nbNodes == 6 ) { // quadratic triangles
821 // Compute lengths of the sides
822 double aLen1 = getDistance( P( 1 ), P( 3 ));
823 double aLen2 = getDistance( P( 3 ), P( 5 ));
824 double aLen3 = getDistance( P( 5 ), P( 1 ));
825 // algo same as for the linear triangle
826 const double alfa = sqrt( 3. ) / 6.;
827 double maxLen = Max( aLen1, Max( aLen2, aLen3 ));
828 double half_perimeter = ( aLen1 + aLen2 + aLen3 ) / 2.;
829 double anArea = getArea( P( 1 ), P( 3 ), P( 5 ));
830 if ( anArea <= theEps )
832 return alfa * maxLen * half_perimeter / anArea;
834 else if( nbNodes == 4 ) { // quadrangle
835 // Compute lengths of the sides
837 aLen[0] = getDistance( P(1), P(2) );
838 aLen[1] = getDistance( P(2), P(3) );
839 aLen[2] = getDistance( P(3), P(4) );
840 aLen[3] = getDistance( P(4), P(1) );
841 // Compute lengths of the diagonals
843 aDia[0] = getDistance( P(1), P(3) );
844 aDia[1] = getDistance( P(2), P(4) );
845 // Compute areas of all triangles which can be built
846 // taking three nodes of the quadrangle
848 anArea[0] = getArea( P(1), P(2), P(3) );
849 anArea[1] = getArea( P(1), P(2), P(4) );
850 anArea[2] = getArea( P(1), P(3), P(4) );
851 anArea[3] = getArea( P(2), P(3), P(4) );
852 // Q = alpha * L * C1 / C2, where
854 // alpha = sqrt( 1/32 )
855 // L = max( L1, L2, L3, L4, D1, D2 )
856 // C1 = sqrt( ( L1^2 + L1^2 + L1^2 + L1^2 ) / 4 )
857 // C2 = min( S1, S2, S3, S4 )
858 // Li - lengths of the edges
859 // Di - lengths of the diagonals
860 // Si - areas of the triangles
861 const double alpha = sqrt( 1 / 32. );
862 double L = Max( aLen[ 0 ],
866 Max( aDia[ 0 ], aDia[ 1 ] ) ) ) ) );
867 double C1 = sqrt( ( aLen[0] * aLen[0] +
870 aLen[3] * aLen[3] ) / 4. );
871 double C2 = Min( anArea[ 0 ],
873 Min( anArea[ 2 ], anArea[ 3 ] ) ) );
876 return alpha * L * C1 / C2;
878 else if( nbNodes == 8 || nbNodes == 9 ) { // nbNodes==8 - quadratic quadrangle
879 // Compute lengths of the sides
881 aLen[0] = getDistance( P(1), P(3) );
882 aLen[1] = getDistance( P(3), P(5) );
883 aLen[2] = getDistance( P(5), P(7) );
884 aLen[3] = getDistance( P(7), P(1) );
885 // Compute lengths of the diagonals
887 aDia[0] = getDistance( P(1), P(5) );
888 aDia[1] = getDistance( P(3), P(7) );
889 // Compute areas of all triangles which can be built
890 // taking three nodes of the quadrangle
892 anArea[0] = getArea( P(1), P(3), P(5) );
893 anArea[1] = getArea( P(1), P(3), P(7) );
894 anArea[2] = getArea( P(1), P(5), P(7) );
895 anArea[3] = getArea( P(3), P(5), P(7) );
896 // Q = alpha * L * C1 / C2, where
898 // alpha = sqrt( 1/32 )
899 // L = max( L1, L2, L3, L4, D1, D2 )
900 // C1 = sqrt( ( L1^2 + L1^2 + L1^2 + L1^2 ) / 4 )
901 // C2 = min( S1, S2, S3, S4 )
902 // Li - lengths of the edges
903 // Di - lengths of the diagonals
904 // Si - areas of the triangles
905 const double alpha = sqrt( 1 / 32. );
906 double L = Max( aLen[ 0 ],
910 Max( aDia[ 0 ], aDia[ 1 ] ) ) ) ) );
911 double C1 = sqrt( ( aLen[0] * aLen[0] +
914 aLen[3] * aLen[3] ) / 4. );
915 double C2 = Min( anArea[ 0 ],
917 Min( anArea[ 2 ], anArea[ 3 ] ) ) );
920 return alpha * L * C1 / C2;
925 double AspectRatio::GetBadRate( double Value, int /*nbNodes*/ ) const
927 // the aspect ratio is in the range [1.0,infinity]
928 // < 1.0 = very bad, zero area
931 return ( Value < 0.9 ) ? 1000 : Value / 1000.;
934 SMDSAbs_ElementType AspectRatio::GetType() const
940 //================================================================================
942 Class : AspectRatio3D
943 Description : Functor for calculating aspect ratio
945 //================================================================================
949 inline double getHalfPerimeter(double theTria[3]){
950 return (theTria[0] + theTria[1] + theTria[2])/2.0;
953 inline double getArea(double theHalfPerim, double theTria[3]){
954 return sqrt(theHalfPerim*
955 (theHalfPerim-theTria[0])*
956 (theHalfPerim-theTria[1])*
957 (theHalfPerim-theTria[2]));
960 inline double getVolume(double theLen[6]){
961 double a2 = theLen[0]*theLen[0];
962 double b2 = theLen[1]*theLen[1];
963 double c2 = theLen[2]*theLen[2];
964 double d2 = theLen[3]*theLen[3];
965 double e2 = theLen[4]*theLen[4];
966 double f2 = theLen[5]*theLen[5];
967 double P = 4.0*a2*b2*d2;
968 double Q = a2*(b2+d2-e2)-b2*(a2+d2-f2)-d2*(a2+b2-c2);
969 double R = (b2+d2-e2)*(a2+d2-f2)*(a2+d2-f2);
970 return sqrt(P-Q+R)/12.0;
973 inline double getVolume2(double theLen[6]){
974 double a2 = theLen[0]*theLen[0];
975 double b2 = theLen[1]*theLen[1];
976 double c2 = theLen[2]*theLen[2];
977 double d2 = theLen[3]*theLen[3];
978 double e2 = theLen[4]*theLen[4];
979 double f2 = theLen[5]*theLen[5];
981 double P = a2*e2*(b2+c2+d2+f2-a2-e2);
982 double Q = b2*f2*(a2+c2+d2+e2-b2-f2);
983 double R = c2*d2*(a2+b2+e2+f2-c2-d2);
984 double S = a2*b2*d2+b2*c2*e2+a2*c2*f2+d2*e2*f2;
986 return sqrt(P+Q+R-S)/12.0;
989 inline double getVolume(const TSequenceOfXYZ& P){
990 gp_Vec aVec1( P( 2 ) - P( 1 ) );
991 gp_Vec aVec2( P( 3 ) - P( 1 ) );
992 gp_Vec aVec3( P( 4 ) - P( 1 ) );
993 gp_Vec anAreaVec( aVec1 ^ aVec2 );
994 return fabs(aVec3 * anAreaVec) / 6.0;
997 inline double getMaxHeight(double theLen[6])
999 double aHeight = std::max(theLen[0],theLen[1]);
1000 aHeight = std::max(aHeight,theLen[2]);
1001 aHeight = std::max(aHeight,theLen[3]);
1002 aHeight = std::max(aHeight,theLen[4]);
1003 aHeight = std::max(aHeight,theLen[5]);
1009 double AspectRatio3D::GetValue( long theId )
1012 myCurrElement = myMesh->FindElement( theId );
1013 if ( myCurrElement && myCurrElement->GetVtkType() == VTK_TETRA )
1015 // Action from CoTech | ACTION 31.3:
1016 // EURIWARE BO: Homogenize the formulas used to calculate the Controls in SMESH to fit with
1017 // those of ParaView. The library used by ParaView for those calculations can be reused in SMESH.
1018 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myCurrElement->getMeshId()]->getGrid();
1019 if ( vtkCell* avtkCell = grid->GetCell( myCurrElement->getVtkId() ))
1020 aVal = Round( vtkMeshQuality::TetAspectRatio( avtkCell ));
1025 if ( GetPoints( myCurrElement, P ))
1026 aVal = Round( GetValue( P ));
1031 double AspectRatio3D::GetValue( const TSequenceOfXYZ& P )
1033 double aQuality = 0.0;
1034 if(myCurrElement->IsPoly()) return aQuality;
1036 int nbNodes = P.size();
1038 if(myCurrElement->IsQuadratic()) {
1039 if(nbNodes==10) nbNodes=4; // quadratic tetrahedron
1040 else if(nbNodes==13) nbNodes=5; // quadratic pyramid
1041 else if(nbNodes==15) nbNodes=6; // quadratic pentahedron
1042 else if(nbNodes==20) nbNodes=8; // quadratic hexahedron
1043 else if(nbNodes==27) nbNodes=8; // quadratic hexahedron
1044 else return aQuality;
1050 getDistance(P( 1 ),P( 2 )), // a
1051 getDistance(P( 2 ),P( 3 )), // b
1052 getDistance(P( 3 ),P( 1 )), // c
1053 getDistance(P( 2 ),P( 4 )), // d
1054 getDistance(P( 3 ),P( 4 )), // e
1055 getDistance(P( 1 ),P( 4 )) // f
1057 double aTria[4][3] = {
1058 {aLen[0],aLen[1],aLen[2]}, // abc
1059 {aLen[0],aLen[3],aLen[5]}, // adf
1060 {aLen[1],aLen[3],aLen[4]}, // bde
1061 {aLen[2],aLen[4],aLen[5]} // cef
1063 double aSumArea = 0.0;
1064 double aHalfPerimeter = getHalfPerimeter(aTria[0]);
1065 double anArea = getArea(aHalfPerimeter,aTria[0]);
1067 aHalfPerimeter = getHalfPerimeter(aTria[1]);
1068 anArea = getArea(aHalfPerimeter,aTria[1]);
1070 aHalfPerimeter = getHalfPerimeter(aTria[2]);
1071 anArea = getArea(aHalfPerimeter,aTria[2]);
1073 aHalfPerimeter = getHalfPerimeter(aTria[3]);
1074 anArea = getArea(aHalfPerimeter,aTria[3]);
1076 double aVolume = getVolume(P);
1077 //double aVolume = getVolume(aLen);
1078 double aHeight = getMaxHeight(aLen);
1079 static double aCoeff = sqrt(2.0)/12.0;
1080 if ( aVolume > DBL_MIN )
1081 aQuality = aCoeff*aHeight*aSumArea/aVolume;
1086 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 3 ),P( 5 )};
1087 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1090 gp_XYZ aXYZ[4] = {P( 1 ),P( 3 ),P( 4 ),P( 5 )};
1091 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1094 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 5 )};
1095 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1098 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 4 ),P( 5 )};
1099 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1105 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 6 )};
1106 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1109 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 3 )};
1110 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1113 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 6 )};
1114 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1117 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
1118 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1121 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 6 )};
1122 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1125 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 3 )};
1126 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1132 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
1133 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1136 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 4 )};
1137 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1140 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 7 )};
1141 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1144 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 8 )};
1145 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1148 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 3 )};
1149 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1152 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 4 )};
1153 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1156 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 7 )};
1157 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1160 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 8 )};
1161 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1164 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 3 )};
1165 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1168 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 4 )};
1169 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1172 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 7 )};
1173 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1176 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 8 )};
1177 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1180 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 1 )};
1181 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1184 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 2 )};
1185 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1188 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 5 )};
1189 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1192 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 6 )};
1193 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1196 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 1 )};
1197 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1200 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 2 )};
1201 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1204 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 5 )};
1205 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1208 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 6 )};
1209 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1212 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 1 )};
1213 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1216 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
1217 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1220 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 5 )};
1221 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1224 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 6 )};
1225 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1228 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
1229 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1232 gp_XYZ aXYZ[4] = {P( 4 ),P( 5 ),P( 8 ),P( 2 )};
1233 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1236 gp_XYZ aXYZ[4] = {P( 1 ),P( 4 ),P( 5 ),P( 3 )};
1237 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1240 gp_XYZ aXYZ[4] = {P( 3 ),P( 6 ),P( 7 ),P( 1 )};
1241 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1244 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 6 ),P( 4 )};
1245 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1248 gp_XYZ aXYZ[4] = {P( 5 ),P( 6 ),P( 8 ),P( 3 )};
1249 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1252 gp_XYZ aXYZ[4] = {P( 7 ),P( 8 ),P( 6 ),P( 1 )};
1253 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1256 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 7 )};
1257 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1260 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 2 ),P( 5 )};
1261 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1267 gp_XYZ aXYZ[8] = {P( 1 ),P( 2 ),P( 4 ),P( 5 ),P( 7 ),P( 8 ),P( 10 ),P( 11 )};
1268 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[8])),aQuality);
1271 gp_XYZ aXYZ[8] = {P( 2 ),P( 3 ),P( 5 ),P( 6 ),P( 8 ),P( 9 ),P( 11 ),P( 12 )};
1272 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[8])),aQuality);
1275 gp_XYZ aXYZ[8] = {P( 3 ),P( 4 ),P( 6 ),P( 1 ),P( 9 ),P( 10 ),P( 12 ),P( 7 )};
1276 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[8])),aQuality);
1279 } // switch(nbNodes)
1281 if ( nbNodes > 4 ) {
1282 // evaluate aspect ratio of quadrangle faces
1283 AspectRatio aspect2D;
1284 SMDS_VolumeTool::VolumeType type = SMDS_VolumeTool::GetType( nbNodes );
1285 int nbFaces = SMDS_VolumeTool::NbFaces( type );
1286 TSequenceOfXYZ points(4);
1287 for ( int i = 0; i < nbFaces; ++i ) { // loop on faces of a volume
1288 if ( SMDS_VolumeTool::NbFaceNodes( type, i ) != 4 )
1290 const int* pInd = SMDS_VolumeTool::GetFaceNodesIndices( type, i, true );
1291 for ( int p = 0; p < 4; ++p ) // loop on nodes of a quadrangle face
1292 points( p + 1 ) = P( pInd[ p ] + 1 );
1293 aQuality = std::max( aQuality, aspect2D.GetValue( points ));
1299 double AspectRatio3D::GetBadRate( double Value, int /*nbNodes*/ ) const
1301 // the aspect ratio is in the range [1.0,infinity]
1304 return Value / 1000.;
1307 SMDSAbs_ElementType AspectRatio3D::GetType() const
1309 return SMDSAbs_Volume;
1313 //================================================================================
1316 Description : Functor for calculating warping
1318 //================================================================================
1320 double Warping::GetValue( const TSequenceOfXYZ& P )
1322 if ( P.size() != 4 )
1325 gp_XYZ G = ( P( 1 ) + P( 2 ) + P( 3 ) + P( 4 ) ) / 4.;
1327 double A1 = ComputeA( P( 1 ), P( 2 ), P( 3 ), G );
1328 double A2 = ComputeA( P( 2 ), P( 3 ), P( 4 ), G );
1329 double A3 = ComputeA( P( 3 ), P( 4 ), P( 1 ), G );
1330 double A4 = ComputeA( P( 4 ), P( 1 ), P( 2 ), G );
1332 double val = Max( Max( A1, A2 ), Max( A3, A4 ) );
1334 const double eps = 0.1; // val is in degrees
1336 return val < eps ? 0. : val;
1339 double Warping::ComputeA( const gp_XYZ& thePnt1,
1340 const gp_XYZ& thePnt2,
1341 const gp_XYZ& thePnt3,
1342 const gp_XYZ& theG ) const
1344 double aLen1 = gp_Pnt( thePnt1 ).Distance( gp_Pnt( thePnt2 ) );
1345 double aLen2 = gp_Pnt( thePnt2 ).Distance( gp_Pnt( thePnt3 ) );
1346 double L = Min( aLen1, aLen2 ) * 0.5;
1350 gp_XYZ GI = ( thePnt2 + thePnt1 ) / 2. - theG;
1351 gp_XYZ GJ = ( thePnt3 + thePnt2 ) / 2. - theG;
1352 gp_XYZ N = GI.Crossed( GJ );
1354 if ( N.Modulus() < gp::Resolution() )
1359 double H = ( thePnt2 - theG ).Dot( N );
1360 return asin( fabs( H / L ) ) * 180. / M_PI;
1363 double Warping::GetBadRate( double Value, int /*nbNodes*/ ) const
1365 // the warp is in the range [0.0,PI/2]
1366 // 0.0 = good (no warp)
1367 // PI/2 = bad (face pliee)
1371 SMDSAbs_ElementType Warping::GetType() const
1373 return SMDSAbs_Face;
1377 //================================================================================
1380 Description : Functor for calculating taper
1382 //================================================================================
1384 double Taper::GetValue( const TSequenceOfXYZ& P )
1386 if ( P.size() != 4 )
1390 double J1 = getArea( P( 4 ), P( 1 ), P( 2 ) );
1391 double J2 = getArea( P( 3 ), P( 1 ), P( 2 ) );
1392 double J3 = getArea( P( 2 ), P( 3 ), P( 4 ) );
1393 double J4 = getArea( P( 3 ), P( 4 ), P( 1 ) );
1395 double JA = 0.25 * ( J1 + J2 + J3 + J4 );
1399 double T1 = fabs( ( J1 - JA ) / JA );
1400 double T2 = fabs( ( J2 - JA ) / JA );
1401 double T3 = fabs( ( J3 - JA ) / JA );
1402 double T4 = fabs( ( J4 - JA ) / JA );
1404 double val = Max( Max( T1, T2 ), Max( T3, T4 ) );
1406 const double eps = 0.01;
1408 return val < eps ? 0. : val;
1411 double Taper::GetBadRate( double Value, int /*nbNodes*/ ) const
1413 // the taper is in the range [0.0,1.0]
1414 // 0.0 = good (no taper)
1415 // 1.0 = bad (les cotes opposes sont allignes)
1419 SMDSAbs_ElementType Taper::GetType() const
1421 return SMDSAbs_Face;
1424 //================================================================================
1427 Description : Functor for calculating skew in degrees
1429 //================================================================================
1431 static inline double skewAngle( const gp_XYZ& p1, const gp_XYZ& p2, const gp_XYZ& p3 )
1433 gp_XYZ p12 = ( p2 + p1 ) / 2.;
1434 gp_XYZ p23 = ( p3 + p2 ) / 2.;
1435 gp_XYZ p31 = ( p3 + p1 ) / 2.;
1437 gp_Vec v1( p31 - p2 ), v2( p12 - p23 );
1439 return v1.Magnitude() < gp::Resolution() || v2.Magnitude() < gp::Resolution() ? 0. : v1.Angle( v2 );
1442 double Skew::GetValue( const TSequenceOfXYZ& P )
1444 if ( P.size() != 3 && P.size() != 4 )
1448 const double PI2 = M_PI / 2.;
1449 if ( P.size() == 3 )
1451 double A0 = fabs( PI2 - skewAngle( P( 3 ), P( 1 ), P( 2 ) ) );
1452 double A1 = fabs( PI2 - skewAngle( P( 1 ), P( 2 ), P( 3 ) ) );
1453 double A2 = fabs( PI2 - skewAngle( P( 2 ), P( 3 ), P( 1 ) ) );
1455 return Max( A0, Max( A1, A2 ) ) * 180. / M_PI;
1459 gp_XYZ p12 = ( P( 1 ) + P( 2 ) ) / 2.;
1460 gp_XYZ p23 = ( P( 2 ) + P( 3 ) ) / 2.;
1461 gp_XYZ p34 = ( P( 3 ) + P( 4 ) ) / 2.;
1462 gp_XYZ p41 = ( P( 4 ) + P( 1 ) ) / 2.;
1464 gp_Vec v1( p34 - p12 ), v2( p23 - p41 );
1465 double A = v1.Magnitude() <= gp::Resolution() || v2.Magnitude() <= gp::Resolution()
1466 ? 0. : fabs( PI2 - v1.Angle( v2 ) );
1468 double val = A * 180. / M_PI;
1470 const double eps = 0.1; // val is in degrees
1472 return val < eps ? 0. : val;
1476 double Skew::GetBadRate( double Value, int /*nbNodes*/ ) const
1478 // the skew is in the range [0.0,PI/2].
1484 SMDSAbs_ElementType Skew::GetType() const
1486 return SMDSAbs_Face;
1490 //================================================================================
1493 Description : Functor for calculating area
1495 //================================================================================
1497 double Area::GetValue( const TSequenceOfXYZ& P )
1502 gp_Vec aVec1( P(2) - P(1) );
1503 gp_Vec aVec2( P(3) - P(1) );
1504 gp_Vec SumVec = aVec1 ^ aVec2;
1506 for (size_t i=4; i<=P.size(); i++)
1508 gp_Vec aVec1( P(i-1) - P(1) );
1509 gp_Vec aVec2( P(i ) - P(1) );
1510 gp_Vec tmp = aVec1 ^ aVec2;
1513 val = SumVec.Magnitude() * 0.5;
1518 double Area::GetBadRate( double Value, int /*nbNodes*/ ) const
1520 // meaningless as it is not a quality control functor
1524 SMDSAbs_ElementType Area::GetType() const
1526 return SMDSAbs_Face;
1529 //================================================================================
1532 Description : Functor for calculating length of edge
1534 //================================================================================
1536 double Length::GetValue( const TSequenceOfXYZ& P )
1538 switch ( P.size() ) {
1539 case 2: return getDistance( P( 1 ), P( 2 ) );
1540 case 3: return getDistance( P( 1 ), P( 2 ) ) + getDistance( P( 2 ), P( 3 ) );
1545 double Length::GetBadRate( double Value, int /*nbNodes*/ ) const
1547 // meaningless as it is not quality control functor
1551 SMDSAbs_ElementType Length::GetType() const
1553 return SMDSAbs_Edge;
1556 //================================================================================
1559 Description : Functor for calculating minimal length of edge
1561 //================================================================================
1563 double Length2D::GetValue( const TSequenceOfXYZ& P )
1567 SMDSAbs_EntityType aType = P.getElementEntity();
1570 case SMDSEntity_Edge:
1572 aVal = getDistance( P( 1 ), P( 2 ) );
1574 case SMDSEntity_Quad_Edge:
1575 if (len == 3) // quadratic edge
1576 aVal = getDistance(P( 1 ),P( 3 )) + getDistance(P( 3 ),P( 2 ));
1578 case SMDSEntity_Triangle:
1579 if (len == 3){ // triangles
1580 double L1 = getDistance(P( 1 ),P( 2 ));
1581 double L2 = getDistance(P( 2 ),P( 3 ));
1582 double L3 = getDistance(P( 3 ),P( 1 ));
1583 aVal = Min(L1,Min(L2,L3));
1586 case SMDSEntity_Quadrangle:
1587 if (len == 4){ // quadrangles
1588 double L1 = getDistance(P( 1 ),P( 2 ));
1589 double L2 = getDistance(P( 2 ),P( 3 ));
1590 double L3 = getDistance(P( 3 ),P( 4 ));
1591 double L4 = getDistance(P( 4 ),P( 1 ));
1592 aVal = Min(Min(L1,L2),Min(L3,L4));
1595 case SMDSEntity_Quad_Triangle:
1596 case SMDSEntity_BiQuad_Triangle:
1597 if (len >= 6){ // quadratic triangles
1598 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1599 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1600 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 1 ));
1601 aVal = Min(L1,Min(L2,L3));
1604 case SMDSEntity_Quad_Quadrangle:
1605 case SMDSEntity_BiQuad_Quadrangle:
1606 if (len >= 8){ // quadratic quadrangles
1607 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1608 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1609 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 7 ));
1610 double L4 = getDistance(P( 7 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
1611 aVal = Min(Min(L1,L2),Min(L3,L4));
1614 case SMDSEntity_Tetra:
1615 if (len == 4){ // tetrahedra
1616 double L1 = getDistance(P( 1 ),P( 2 ));
1617 double L2 = getDistance(P( 2 ),P( 3 ));
1618 double L3 = getDistance(P( 3 ),P( 1 ));
1619 double L4 = getDistance(P( 1 ),P( 4 ));
1620 double L5 = getDistance(P( 2 ),P( 4 ));
1621 double L6 = getDistance(P( 3 ),P( 4 ));
1622 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1625 case SMDSEntity_Pyramid:
1626 if (len == 5){ // pyramid
1627 double L1 = getDistance(P( 1 ),P( 2 ));
1628 double L2 = getDistance(P( 2 ),P( 3 ));
1629 double L3 = getDistance(P( 3 ),P( 4 ));
1630 double L4 = getDistance(P( 4 ),P( 1 ));
1631 double L5 = getDistance(P( 1 ),P( 5 ));
1632 double L6 = getDistance(P( 2 ),P( 5 ));
1633 double L7 = getDistance(P( 3 ),P( 5 ));
1634 double L8 = getDistance(P( 4 ),P( 5 ));
1636 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1637 aVal = Min(aVal,Min(L7,L8));
1640 case SMDSEntity_Penta:
1641 if (len == 6) { // pentahedron
1642 double L1 = getDistance(P( 1 ),P( 2 ));
1643 double L2 = getDistance(P( 2 ),P( 3 ));
1644 double L3 = getDistance(P( 3 ),P( 1 ));
1645 double L4 = getDistance(P( 4 ),P( 5 ));
1646 double L5 = getDistance(P( 5 ),P( 6 ));
1647 double L6 = getDistance(P( 6 ),P( 4 ));
1648 double L7 = getDistance(P( 1 ),P( 4 ));
1649 double L8 = getDistance(P( 2 ),P( 5 ));
1650 double L9 = getDistance(P( 3 ),P( 6 ));
1652 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1653 aVal = Min(aVal,Min(Min(L7,L8),L9));
1656 case SMDSEntity_Hexa:
1657 if (len == 8){ // hexahedron
1658 double L1 = getDistance(P( 1 ),P( 2 ));
1659 double L2 = getDistance(P( 2 ),P( 3 ));
1660 double L3 = getDistance(P( 3 ),P( 4 ));
1661 double L4 = getDistance(P( 4 ),P( 1 ));
1662 double L5 = getDistance(P( 5 ),P( 6 ));
1663 double L6 = getDistance(P( 6 ),P( 7 ));
1664 double L7 = getDistance(P( 7 ),P( 8 ));
1665 double L8 = getDistance(P( 8 ),P( 5 ));
1666 double L9 = getDistance(P( 1 ),P( 5 ));
1667 double L10= getDistance(P( 2 ),P( 6 ));
1668 double L11= getDistance(P( 3 ),P( 7 ));
1669 double L12= getDistance(P( 4 ),P( 8 ));
1671 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1672 aVal = Min(aVal,Min(Min(L7,L8),Min(L9,L10)));
1673 aVal = Min(aVal,Min(L11,L12));
1676 case SMDSEntity_Quad_Tetra:
1677 if (len == 10){ // quadratic tetrahedron
1678 double L1 = getDistance(P( 1 ),P( 5 )) + getDistance(P( 5 ),P( 2 ));
1679 double L2 = getDistance(P( 2 ),P( 6 )) + getDistance(P( 6 ),P( 3 ));
1680 double L3 = getDistance(P( 3 ),P( 7 )) + getDistance(P( 7 ),P( 1 ));
1681 double L4 = getDistance(P( 1 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
1682 double L5 = getDistance(P( 2 ),P( 9 )) + getDistance(P( 9 ),P( 4 ));
1683 double L6 = getDistance(P( 3 ),P( 10 )) + getDistance(P( 10 ),P( 4 ));
1684 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1687 case SMDSEntity_Quad_Pyramid:
1688 if (len == 13){ // quadratic pyramid
1689 double L1 = getDistance(P( 1 ),P( 6 )) + getDistance(P( 6 ),P( 2 ));
1690 double L2 = getDistance(P( 2 ),P( 7 )) + getDistance(P( 7 ),P( 3 ));
1691 double L3 = getDistance(P( 3 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
1692 double L4 = getDistance(P( 4 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1693 double L5 = getDistance(P( 1 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1694 double L6 = getDistance(P( 2 ),P( 11 )) + getDistance(P( 11 ),P( 5 ));
1695 double L7 = getDistance(P( 3 ),P( 12 )) + getDistance(P( 12 ),P( 5 ));
1696 double L8 = getDistance(P( 4 ),P( 13 )) + getDistance(P( 13 ),P( 5 ));
1697 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1698 aVal = Min(aVal,Min(L7,L8));
1701 case SMDSEntity_Quad_Penta:
1702 case SMDSEntity_BiQuad_Penta:
1703 if (len >= 15){ // quadratic pentahedron
1704 double L1 = getDistance(P( 1 ),P( 7 )) + getDistance(P( 7 ),P( 2 ));
1705 double L2 = getDistance(P( 2 ),P( 8 )) + getDistance(P( 8 ),P( 3 ));
1706 double L3 = getDistance(P( 3 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1707 double L4 = getDistance(P( 4 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1708 double L5 = getDistance(P( 5 ),P( 11 )) + getDistance(P( 11 ),P( 6 ));
1709 double L6 = getDistance(P( 6 ),P( 12 )) + getDistance(P( 12 ),P( 4 ));
1710 double L7 = getDistance(P( 1 ),P( 13 )) + getDistance(P( 13 ),P( 4 ));
1711 double L8 = getDistance(P( 2 ),P( 14 )) + getDistance(P( 14 ),P( 5 ));
1712 double L9 = getDistance(P( 3 ),P( 15 )) + getDistance(P( 15 ),P( 6 ));
1713 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1714 aVal = Min(aVal,Min(Min(L7,L8),L9));
1717 case SMDSEntity_Quad_Hexa:
1718 case SMDSEntity_TriQuad_Hexa:
1719 if (len >= 20) { // quadratic hexahedron
1720 double L1 = getDistance(P( 1 ),P( 9 )) + getDistance(P( 9 ),P( 2 ));
1721 double L2 = getDistance(P( 2 ),P( 10 )) + getDistance(P( 10 ),P( 3 ));
1722 double L3 = getDistance(P( 3 ),P( 11 )) + getDistance(P( 11 ),P( 4 ));
1723 double L4 = getDistance(P( 4 ),P( 12 )) + getDistance(P( 12 ),P( 1 ));
1724 double L5 = getDistance(P( 5 ),P( 13 )) + getDistance(P( 13 ),P( 6 ));
1725 double L6 = getDistance(P( 6 ),P( 14 )) + getDistance(P( 14 ),P( 7 ));
1726 double L7 = getDistance(P( 7 ),P( 15 )) + getDistance(P( 15 ),P( 8 ));
1727 double L8 = getDistance(P( 8 ),P( 16 )) + getDistance(P( 16 ),P( 5 ));
1728 double L9 = getDistance(P( 1 ),P( 17 )) + getDistance(P( 17 ),P( 5 ));
1729 double L10= getDistance(P( 2 ),P( 18 )) + getDistance(P( 18 ),P( 6 ));
1730 double L11= getDistance(P( 3 ),P( 19 )) + getDistance(P( 19 ),P( 7 ));
1731 double L12= getDistance(P( 4 ),P( 20 )) + getDistance(P( 20 ),P( 8 ));
1732 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1733 aVal = Min(aVal,Min(Min(L7,L8),Min(L9,L10)));
1734 aVal = Min(aVal,Min(L11,L12));
1737 case SMDSEntity_Polygon:
1739 aVal = getDistance( P(1), P( P.size() ));
1740 for ( size_t i = 1; i < P.size(); ++i )
1741 aVal = Min( aVal, getDistance( P( i ), P( i+1 )));
1744 case SMDSEntity_Quad_Polygon:
1746 aVal = getDistance( P(1), P( P.size() )) + getDistance( P(P.size()), P( P.size()-1 ));
1747 for ( size_t i = 1; i < P.size()-1; i += 2 )
1748 aVal = Min( aVal, getDistance( P( i ), P( i+1 )) + getDistance( P( i+1 ), P( i+2 )));
1751 case SMDSEntity_Hexagonal_Prism:
1752 if (len == 12) { // hexagonal prism
1753 double L1 = getDistance(P( 1 ),P( 2 ));
1754 double L2 = getDistance(P( 2 ),P( 3 ));
1755 double L3 = getDistance(P( 3 ),P( 4 ));
1756 double L4 = getDistance(P( 4 ),P( 5 ));
1757 double L5 = getDistance(P( 5 ),P( 6 ));
1758 double L6 = getDistance(P( 6 ),P( 1 ));
1760 double L7 = getDistance(P( 7 ), P( 8 ));
1761 double L8 = getDistance(P( 8 ), P( 9 ));
1762 double L9 = getDistance(P( 9 ), P( 10 ));
1763 double L10= getDistance(P( 10 ),P( 11 ));
1764 double L11= getDistance(P( 11 ),P( 12 ));
1765 double L12= getDistance(P( 12 ),P( 7 ));
1767 double L13 = getDistance(P( 1 ),P( 7 ));
1768 double L14 = getDistance(P( 2 ),P( 8 ));
1769 double L15 = getDistance(P( 3 ),P( 9 ));
1770 double L16 = getDistance(P( 4 ),P( 10 ));
1771 double L17 = getDistance(P( 5 ),P( 11 ));
1772 double L18 = getDistance(P( 6 ),P( 12 ));
1773 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1774 aVal = Min(aVal, Min(Min(Min(L7,L8),Min(L9,L10)),Min(L11,L12)));
1775 aVal = Min(aVal, Min(Min(Min(L13,L14),Min(L15,L16)),Min(L17,L18)));
1778 case SMDSEntity_Polyhedra:
1790 if ( myPrecision >= 0 )
1792 double prec = pow( 10., (double)( myPrecision ) );
1793 aVal = floor( aVal * prec + 0.5 ) / prec;
1799 double Length2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1801 // meaningless as it is not a quality control functor
1805 SMDSAbs_ElementType Length2D::GetType() const
1807 return SMDSAbs_Face;
1810 Length2D::Value::Value(double theLength,long thePntId1, long thePntId2):
1813 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1814 if(thePntId1 > thePntId2){
1815 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1819 bool Length2D::Value::operator<(const Length2D::Value& x) const
1821 if(myPntId[0] < x.myPntId[0]) return true;
1822 if(myPntId[0] == x.myPntId[0])
1823 if(myPntId[1] < x.myPntId[1]) return true;
1827 void Length2D::GetValues(TValues& theValues)
1830 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1831 for(; anIter->more(); ){
1832 const SMDS_MeshFace* anElem = anIter->next();
1834 if(anElem->IsQuadratic()) {
1835 const SMDS_VtkFace* F =
1836 dynamic_cast<const SMDS_VtkFace*>(anElem);
1837 // use special nodes iterator
1838 SMDS_ElemIteratorPtr anIter = F->interlacedNodesElemIterator();
1839 long aNodeId[4] = { 0,0,0,0 };
1843 const SMDS_MeshElement* aNode;
1845 aNode = anIter->next();
1846 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1847 P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1848 aNodeId[0] = aNodeId[1] = aNode->GetID();
1851 for(; anIter->more(); ){
1852 const SMDS_MeshNode* N1 = static_cast<const SMDS_MeshNode*> (anIter->next());
1853 P[2] = gp_Pnt(N1->X(),N1->Y(),N1->Z());
1854 aNodeId[2] = N1->GetID();
1855 aLength = P[1].Distance(P[2]);
1856 if(!anIter->more()) break;
1857 const SMDS_MeshNode* N2 = static_cast<const SMDS_MeshNode*> (anIter->next());
1858 P[3] = gp_Pnt(N2->X(),N2->Y(),N2->Z());
1859 aNodeId[3] = N2->GetID();
1860 aLength += P[2].Distance(P[3]);
1861 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1862 Value aValue2(aLength,aNodeId[2],aNodeId[3]);
1864 aNodeId[1] = aNodeId[3];
1865 theValues.insert(aValue1);
1866 theValues.insert(aValue2);
1868 aLength += P[2].Distance(P[0]);
1869 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1870 Value aValue2(aLength,aNodeId[2],aNodeId[0]);
1871 theValues.insert(aValue1);
1872 theValues.insert(aValue2);
1875 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
1876 long aNodeId[2] = {0,0};
1880 const SMDS_MeshElement* aNode;
1881 if(aNodesIter->more()){
1882 aNode = aNodesIter->next();
1883 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1884 P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1885 aNodeId[0] = aNodeId[1] = aNode->GetID();
1888 for(; aNodesIter->more(); ){
1889 aNode = aNodesIter->next();
1890 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1891 long anId = aNode->GetID();
1893 P[2] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1895 aLength = P[1].Distance(P[2]);
1897 Value aValue(aLength,aNodeId[1],anId);
1900 theValues.insert(aValue);
1903 aLength = P[0].Distance(P[1]);
1905 Value aValue(aLength,aNodeId[0],aNodeId[1]);
1906 theValues.insert(aValue);
1911 //================================================================================
1913 Class : Deflection2D
1914 Description : Functor for calculating number of faces conneted to the edge
1916 //================================================================================
1918 double Deflection2D::GetValue( const TSequenceOfXYZ& P )
1920 if ( myMesh && P.getElement() )
1922 // get underlying surface
1923 if ( myShapeIndex != P.getElement()->getshapeId() )
1925 mySurface.Nullify();
1926 myShapeIndex = P.getElement()->getshapeId();
1927 const TopoDS_Shape& S =
1928 static_cast< const SMESHDS_Mesh* >( myMesh )->IndexToShape( myShapeIndex );
1929 if ( !S.IsNull() && S.ShapeType() == TopAbs_FACE )
1931 mySurface = new ShapeAnalysis_Surface( BRep_Tool::Surface( TopoDS::Face( S )));
1933 GeomLib_IsPlanarSurface isPlaneCheck( mySurface->Surface() );
1934 if ( isPlaneCheck.IsPlanar() )
1935 myPlane.reset( new gp_Pln( isPlaneCheck.Plan() ));
1940 // project gravity center to the surface
1941 if ( !mySurface.IsNull() )
1946 for ( size_t i = 0; i < P.size(); ++i )
1950 if ( const SMDS_FacePosition* fPos = dynamic_cast<const SMDS_FacePosition*>
1951 ( P.getElement()->GetNode( i )->GetPosition() ))
1953 uv.ChangeCoord(1) += fPos->GetUParameter();
1954 uv.ChangeCoord(2) += fPos->GetVParameter();
1959 if ( nbUV ) uv /= nbUV;
1961 double maxLen = MaxElementLength2D().GetValue( P );
1962 double tol = 1e-3 * maxLen;
1966 dist = myPlane->Distance( gc );
1972 if ( uv.X() != 0 && uv.Y() != 0 ) // faster way
1973 mySurface->NextValueOfUV( uv, gc, tol, 0.5 * maxLen );
1975 mySurface->ValueOfUV( gc, tol );
1976 dist = mySurface->Gap();
1978 return Round( dist );
1984 void Deflection2D::SetMesh( const SMDS_Mesh* theMesh )
1986 NumericalFunctor::SetMesh( dynamic_cast<const SMESHDS_Mesh* >( theMesh ));
1987 myShapeIndex = -100;
1991 SMDSAbs_ElementType Deflection2D::GetType() const
1993 return SMDSAbs_Face;
1996 double Deflection2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1998 // meaningless as it is not quality control functor
2002 //================================================================================
2004 Class : MultiConnection
2005 Description : Functor for calculating number of faces conneted to the edge
2007 //================================================================================
2009 double MultiConnection::GetValue( const TSequenceOfXYZ& P )
2013 double MultiConnection::GetValue( long theId )
2015 return getNbMultiConnection( myMesh, theId );
2018 double MultiConnection::GetBadRate( double Value, int /*nbNodes*/ ) const
2020 // meaningless as it is not quality control functor
2024 SMDSAbs_ElementType MultiConnection::GetType() const
2026 return SMDSAbs_Edge;
2029 //================================================================================
2031 Class : MultiConnection2D
2032 Description : Functor for calculating number of faces conneted to the edge
2034 //================================================================================
2036 double MultiConnection2D::GetValue( const TSequenceOfXYZ& P )
2041 double MultiConnection2D::GetValue( long theElementId )
2045 const SMDS_MeshElement* aFaceElem = myMesh->FindElement(theElementId);
2046 SMDSAbs_ElementType aType = aFaceElem->GetType();
2051 int i = 0, len = aFaceElem->NbNodes();
2052 SMDS_ElemIteratorPtr anIter = aFaceElem->nodesIterator();
2055 const SMDS_MeshNode *aNode, *aNode0 = 0;
2056 TColStd_MapOfInteger aMap, aMapPrev;
2058 for (i = 0; i <= len; i++) {
2063 if (anIter->more()) {
2064 aNode = (SMDS_MeshNode*)anIter->next();
2072 if (i == 0) aNode0 = aNode;
2074 SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator();
2075 while (anElemIter->more()) {
2076 const SMDS_MeshElement* anElem = anElemIter->next();
2077 if (anElem != 0 && anElem->GetType() == SMDSAbs_Face) {
2078 int anId = anElem->GetID();
2081 if (aMapPrev.Contains(anId)) {
2086 aResult = Max(aResult, aNb);
2097 double MultiConnection2D::GetBadRate( double Value, int /*nbNodes*/ ) const
2099 // meaningless as it is not quality control functor
2103 SMDSAbs_ElementType MultiConnection2D::GetType() const
2105 return SMDSAbs_Face;
2108 MultiConnection2D::Value::Value(long thePntId1, long thePntId2)
2110 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
2111 if(thePntId1 > thePntId2){
2112 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
2116 bool MultiConnection2D::Value::operator<(const MultiConnection2D::Value& x) const
2118 if(myPntId[0] < x.myPntId[0]) return true;
2119 if(myPntId[0] == x.myPntId[0])
2120 if(myPntId[1] < x.myPntId[1]) return true;
2124 void MultiConnection2D::GetValues(MValues& theValues)
2126 if ( !myMesh ) return;
2127 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
2128 for(; anIter->more(); ){
2129 const SMDS_MeshFace* anElem = anIter->next();
2130 SMDS_ElemIteratorPtr aNodesIter;
2131 if ( anElem->IsQuadratic() )
2132 aNodesIter = dynamic_cast<const SMDS_VtkFace*>
2133 (anElem)->interlacedNodesElemIterator();
2135 aNodesIter = anElem->nodesIterator();
2136 long aNodeId[3] = {0,0,0};
2138 //int aNbConnects=0;
2139 const SMDS_MeshNode* aNode0;
2140 const SMDS_MeshNode* aNode1;
2141 const SMDS_MeshNode* aNode2;
2142 if(aNodesIter->more()){
2143 aNode0 = (SMDS_MeshNode*) aNodesIter->next();
2145 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode1;
2146 aNodeId[0] = aNodeId[1] = aNodes->GetID();
2148 for(; aNodesIter->more(); ) {
2149 aNode2 = (SMDS_MeshNode*) aNodesIter->next();
2150 long anId = aNode2->GetID();
2153 Value aValue(aNodeId[1],aNodeId[2]);
2154 MValues::iterator aItr = theValues.find(aValue);
2155 if (aItr != theValues.end()){
2160 theValues[aValue] = 1;
2163 //cout << "NodeIds: "<<aNodeId[1]<<","<<aNodeId[2]<<" nbconn="<<aNbConnects<<endl;
2164 aNodeId[1] = aNodeId[2];
2167 Value aValue(aNodeId[0],aNodeId[2]);
2168 MValues::iterator aItr = theValues.find(aValue);
2169 if (aItr != theValues.end()) {
2174 theValues[aValue] = 1;
2177 //cout << "NodeIds: "<<aNodeId[0]<<","<<aNodeId[2]<<" nbconn="<<aNbConnects<<endl;
2182 //================================================================================
2184 Class : BallDiameter
2185 Description : Functor returning diameter of a ball element
2187 //================================================================================
2189 double BallDiameter::GetValue( long theId )
2191 double diameter = 0;
2193 if ( const SMDS_BallElement* ball =
2194 dynamic_cast<const SMDS_BallElement*>( myMesh->FindElement( theId )))
2196 diameter = ball->GetDiameter();
2201 double BallDiameter::GetBadRate( double Value, int /*nbNodes*/ ) const
2203 // meaningless as it is not a quality control functor
2207 SMDSAbs_ElementType BallDiameter::GetType() const
2209 return SMDSAbs_Ball;
2212 //================================================================================
2214 Class : NodeConnectivityNumber
2215 Description : Functor returning number of elements connected to a node
2217 //================================================================================
2219 double NodeConnectivityNumber::GetValue( long theId )
2223 if ( const SMDS_MeshNode* node = myMesh->FindNode( theId ))
2225 SMDSAbs_ElementType type;
2226 if ( myMesh->NbVolumes() > 0 )
2227 type = SMDSAbs_Volume;
2228 else if ( myMesh->NbFaces() > 0 )
2229 type = SMDSAbs_Face;
2230 else if ( myMesh->NbEdges() > 0 )
2231 type = SMDSAbs_Edge;
2234 nb = node->NbInverseElements( type );
2239 double NodeConnectivityNumber::GetBadRate( double Value, int /*nbNodes*/ ) const
2244 SMDSAbs_ElementType NodeConnectivityNumber::GetType() const
2246 return SMDSAbs_Node;
2253 //================================================================================
2255 Class : BadOrientedVolume
2256 Description : Predicate bad oriented volumes
2258 //================================================================================
2260 BadOrientedVolume::BadOrientedVolume()
2265 void BadOrientedVolume::SetMesh( const SMDS_Mesh* theMesh )
2270 bool BadOrientedVolume::IsSatisfy( long theId )
2275 SMDS_VolumeTool vTool( myMesh->FindElement( theId ));
2276 return !vTool.IsForward();
2279 SMDSAbs_ElementType BadOrientedVolume::GetType() const
2281 return SMDSAbs_Volume;
2285 Class : BareBorderVolume
2288 bool BareBorderVolume::IsSatisfy(long theElementId )
2290 SMDS_VolumeTool myTool;
2291 if ( myTool.Set( myMesh->FindElement(theElementId)))
2293 for ( int iF = 0; iF < myTool.NbFaces(); ++iF )
2294 if ( myTool.IsFreeFace( iF ))
2296 const SMDS_MeshNode** n = myTool.GetFaceNodes(iF);
2297 std::vector< const SMDS_MeshNode*> nodes( n, n+myTool.NbFaceNodes(iF));
2298 if ( !myMesh->FindElement( nodes, SMDSAbs_Face, /*Nomedium=*/false))
2305 //================================================================================
2307 Class : BareBorderFace
2309 //================================================================================
2311 bool BareBorderFace::IsSatisfy(long theElementId )
2314 if ( const SMDS_MeshElement* face = myMesh->FindElement(theElementId))
2316 if ( face->GetType() == SMDSAbs_Face )
2318 int nbN = face->NbCornerNodes();
2319 for ( int i = 0; i < nbN && !ok; ++i )
2321 // check if a link is shared by another face
2322 const SMDS_MeshNode* n1 = face->GetNode( i );
2323 const SMDS_MeshNode* n2 = face->GetNode( (i+1)%nbN );
2324 SMDS_ElemIteratorPtr fIt = n1->GetInverseElementIterator( SMDSAbs_Face );
2325 bool isShared = false;
2326 while ( !isShared && fIt->more() )
2328 const SMDS_MeshElement* f = fIt->next();
2329 isShared = ( f != face && f->GetNodeIndex(n2) != -1 );
2333 const int iQuad = face->IsQuadratic();
2334 myLinkNodes.resize( 2 + iQuad);
2335 myLinkNodes[0] = n1;
2336 myLinkNodes[1] = n2;
2338 myLinkNodes[2] = face->GetNode( i+nbN );
2339 ok = !myMesh->FindElement( myLinkNodes, SMDSAbs_Edge, /*noMedium=*/false);
2347 //================================================================================
2349 Class : OverConstrainedVolume
2351 //================================================================================
2353 bool OverConstrainedVolume::IsSatisfy(long theElementId )
2355 // An element is over-constrained if it has N-1 free borders where
2356 // N is the number of edges/faces for a 2D/3D element.
2357 SMDS_VolumeTool myTool;
2358 if ( myTool.Set( myMesh->FindElement(theElementId)))
2360 int nbSharedFaces = 0;
2361 for ( int iF = 0; iF < myTool.NbFaces(); ++iF )
2362 if ( !myTool.IsFreeFace( iF ) && ++nbSharedFaces > 1 )
2364 return ( nbSharedFaces == 1 );
2369 //================================================================================
2371 Class : OverConstrainedFace
2373 //================================================================================
2375 bool OverConstrainedFace::IsSatisfy(long theElementId )
2377 // An element is over-constrained if it has N-1 free borders where
2378 // N is the number of edges/faces for a 2D/3D element.
2379 if ( const SMDS_MeshElement* face = myMesh->FindElement(theElementId))
2380 if ( face->GetType() == SMDSAbs_Face )
2382 int nbSharedBorders = 0;
2383 int nbN = face->NbCornerNodes();
2384 for ( int i = 0; i < nbN; ++i )
2386 // check if a link is shared by another face
2387 const SMDS_MeshNode* n1 = face->GetNode( i );
2388 const SMDS_MeshNode* n2 = face->GetNode( (i+1)%nbN );
2389 SMDS_ElemIteratorPtr fIt = n1->GetInverseElementIterator( SMDSAbs_Face );
2390 bool isShared = false;
2391 while ( !isShared && fIt->more() )
2393 const SMDS_MeshElement* f = fIt->next();
2394 isShared = ( f != face && f->GetNodeIndex(n2) != -1 );
2396 if ( isShared && ++nbSharedBorders > 1 )
2399 return ( nbSharedBorders == 1 );
2404 //================================================================================
2406 Class : CoincidentNodes
2407 Description : Predicate of Coincident nodes
2409 //================================================================================
2411 CoincidentNodes::CoincidentNodes()
2416 bool CoincidentNodes::IsSatisfy( long theElementId )
2418 return myCoincidentIDs.Contains( theElementId );
2421 SMDSAbs_ElementType CoincidentNodes::GetType() const
2423 return SMDSAbs_Node;
2426 void CoincidentNodes::SetMesh( const SMDS_Mesh* theMesh )
2428 myMeshModifTracer.SetMesh( theMesh );
2429 if ( myMeshModifTracer.IsMeshModified() )
2431 TIDSortedNodeSet nodesToCheck;
2432 SMDS_NodeIteratorPtr nIt = theMesh->nodesIterator(/*idInceasingOrder=*/true);
2433 while ( nIt->more() )
2434 nodesToCheck.insert( nodesToCheck.end(), nIt->next() );
2436 std::list< std::list< const SMDS_MeshNode*> > nodeGroups;
2437 SMESH_OctreeNode::FindCoincidentNodes ( nodesToCheck, &nodeGroups, myToler );
2439 myCoincidentIDs.Clear();
2440 std::list< std::list< const SMDS_MeshNode*> >::iterator groupIt = nodeGroups.begin();
2441 for ( ; groupIt != nodeGroups.end(); ++groupIt )
2443 std::list< const SMDS_MeshNode*>& coincNodes = *groupIt;
2444 std::list< const SMDS_MeshNode*>::iterator n = coincNodes.begin();
2445 for ( ; n != coincNodes.end(); ++n )
2446 myCoincidentIDs.Add( (*n)->GetID() );
2451 //================================================================================
2453 Class : CoincidentElements
2454 Description : Predicate of Coincident Elements
2455 Note : This class is suitable only for visualization of Coincident Elements
2457 //================================================================================
2459 CoincidentElements::CoincidentElements()
2464 void CoincidentElements::SetMesh( const SMDS_Mesh* theMesh )
2469 bool CoincidentElements::IsSatisfy( long theElementId )
2471 if ( !myMesh ) return false;
2473 if ( const SMDS_MeshElement* e = myMesh->FindElement( theElementId ))
2475 if ( e->GetType() != GetType() ) return false;
2476 std::set< const SMDS_MeshNode* > elemNodes( e->begin_nodes(), e->end_nodes() );
2477 const int nbNodes = e->NbNodes();
2478 SMDS_ElemIteratorPtr invIt = (*elemNodes.begin())->GetInverseElementIterator( GetType() );
2479 while ( invIt->more() )
2481 const SMDS_MeshElement* e2 = invIt->next();
2482 if ( e2 == e || e2->NbNodes() != nbNodes ) continue;
2484 bool sameNodes = true;
2485 for ( size_t i = 0; i < elemNodes.size() && sameNodes; ++i )
2486 sameNodes = ( elemNodes.count( e2->GetNode( i )));
2494 SMDSAbs_ElementType CoincidentElements1D::GetType() const
2496 return SMDSAbs_Edge;
2498 SMDSAbs_ElementType CoincidentElements2D::GetType() const
2500 return SMDSAbs_Face;
2502 SMDSAbs_ElementType CoincidentElements3D::GetType() const
2504 return SMDSAbs_Volume;
2508 //================================================================================
2511 Description : Predicate for free borders
2513 //================================================================================
2515 FreeBorders::FreeBorders()
2520 void FreeBorders::SetMesh( const SMDS_Mesh* theMesh )
2525 bool FreeBorders::IsSatisfy( long theId )
2527 return getNbMultiConnection( myMesh, theId ) == 1;
2530 SMDSAbs_ElementType FreeBorders::GetType() const
2532 return SMDSAbs_Edge;
2536 //================================================================================
2539 Description : Predicate for free Edges
2541 //================================================================================
2543 FreeEdges::FreeEdges()
2548 void FreeEdges::SetMesh( const SMDS_Mesh* theMesh )
2553 bool FreeEdges::IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId )
2555 TColStd_MapOfInteger aMap;
2556 for ( int i = 0; i < 2; i++ )
2558 SMDS_ElemIteratorPtr anElemIter = theNodes[ i ]->GetInverseElementIterator(SMDSAbs_Face);
2559 while( anElemIter->more() )
2561 if ( const SMDS_MeshElement* anElem = anElemIter->next())
2563 const int anId = anElem->GetID();
2564 if ( anId != theFaceId && !aMap.Add( anId ))
2572 bool FreeEdges::IsSatisfy( long theId )
2577 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
2578 if ( aFace == 0 || aFace->GetType() != SMDSAbs_Face || aFace->NbNodes() < 3 )
2581 SMDS_NodeIteratorPtr anIter = aFace->interlacedNodesIterator();
2585 int i = 0, nbNodes = aFace->NbNodes();
2586 std::vector <const SMDS_MeshNode*> aNodes( nbNodes+1 );
2587 while( anIter->more() )
2588 if ( ! ( aNodes[ i++ ] = anIter->next() ))
2590 aNodes[ nbNodes ] = aNodes[ 0 ];
2592 for ( i = 0; i < nbNodes; i++ )
2593 if ( IsFreeEdge( &aNodes[ i ], theId ) )
2599 SMDSAbs_ElementType FreeEdges::GetType() const
2601 return SMDSAbs_Face;
2604 FreeEdges::Border::Border(long theElemId, long thePntId1, long thePntId2):
2607 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
2608 if(thePntId1 > thePntId2){
2609 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
2613 bool FreeEdges::Border::operator<(const FreeEdges::Border& x) const{
2614 if(myPntId[0] < x.myPntId[0]) return true;
2615 if(myPntId[0] == x.myPntId[0])
2616 if(myPntId[1] < x.myPntId[1]) return true;
2620 inline void UpdateBorders(const FreeEdges::Border& theBorder,
2621 FreeEdges::TBorders& theRegistry,
2622 FreeEdges::TBorders& theContainer)
2624 if(theRegistry.find(theBorder) == theRegistry.end()){
2625 theRegistry.insert(theBorder);
2626 theContainer.insert(theBorder);
2628 theContainer.erase(theBorder);
2632 void FreeEdges::GetBoreders(TBorders& theBorders)
2635 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
2636 for(; anIter->more(); ){
2637 const SMDS_MeshFace* anElem = anIter->next();
2638 long anElemId = anElem->GetID();
2639 SMDS_ElemIteratorPtr aNodesIter;
2640 if ( anElem->IsQuadratic() )
2641 aNodesIter = static_cast<const SMDS_VtkFace*>(anElem)->
2642 interlacedNodesElemIterator();
2644 aNodesIter = anElem->nodesIterator();
2645 long aNodeId[2] = {0,0};
2646 const SMDS_MeshElement* aNode;
2647 if(aNodesIter->more()){
2648 aNode = aNodesIter->next();
2649 aNodeId[0] = aNodeId[1] = aNode->GetID();
2651 for(; aNodesIter->more(); ){
2652 aNode = aNodesIter->next();
2653 long anId = aNode->GetID();
2654 Border aBorder(anElemId,aNodeId[1],anId);
2656 UpdateBorders(aBorder,aRegistry,theBorders);
2658 Border aBorder(anElemId,aNodeId[0],aNodeId[1]);
2659 UpdateBorders(aBorder,aRegistry,theBorders);
2663 //================================================================================
2666 Description : Predicate for free nodes
2668 //================================================================================
2670 FreeNodes::FreeNodes()
2675 void FreeNodes::SetMesh( const SMDS_Mesh* theMesh )
2680 bool FreeNodes::IsSatisfy( long theNodeId )
2682 const SMDS_MeshNode* aNode = myMesh->FindNode( theNodeId );
2686 return (aNode->NbInverseElements() < 1);
2689 SMDSAbs_ElementType FreeNodes::GetType() const
2691 return SMDSAbs_Node;
2695 //================================================================================
2698 Description : Predicate for free faces
2700 //================================================================================
2702 FreeFaces::FreeFaces()
2707 void FreeFaces::SetMesh( const SMDS_Mesh* theMesh )
2712 bool FreeFaces::IsSatisfy( long theId )
2714 if (!myMesh) return false;
2715 // check that faces nodes refers to less than two common volumes
2716 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
2717 if ( !aFace || aFace->GetType() != SMDSAbs_Face )
2720 int nbNode = aFace->NbNodes();
2722 // collect volumes to check that number of volumes with count equal nbNode not less than 2
2723 typedef std::map< SMDS_MeshElement*, int > TMapOfVolume; // map of volume counters
2724 typedef std::map< SMDS_MeshElement*, int >::iterator TItrMapOfVolume; // iterator
2725 TMapOfVolume mapOfVol;
2727 SMDS_ElemIteratorPtr nodeItr = aFace->nodesIterator();
2728 while ( nodeItr->more() )
2730 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(nodeItr->next());
2731 if ( !aNode ) continue;
2732 SMDS_ElemIteratorPtr volItr = aNode->GetInverseElementIterator(SMDSAbs_Volume);
2733 while ( volItr->more() )
2735 SMDS_MeshElement* aVol = (SMDS_MeshElement*)volItr->next();
2736 TItrMapOfVolume itr = mapOfVol.insert( std::make_pair( aVol, 0 )).first;
2741 TItrMapOfVolume volItr = mapOfVol.begin();
2742 TItrMapOfVolume volEnd = mapOfVol.end();
2743 for ( ; volItr != volEnd; ++volItr )
2744 if ( (*volItr).second >= nbNode )
2746 // face is not free if number of volumes constructed on their nodes more than one
2750 SMDSAbs_ElementType FreeFaces::GetType() const
2752 return SMDSAbs_Face;
2755 //================================================================================
2757 Class : LinearOrQuadratic
2758 Description : Predicate to verify whether a mesh element is linear
2760 //================================================================================
2762 LinearOrQuadratic::LinearOrQuadratic()
2767 void LinearOrQuadratic::SetMesh( const SMDS_Mesh* theMesh )
2772 bool LinearOrQuadratic::IsSatisfy( long theId )
2774 if (!myMesh) return false;
2775 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2776 if ( !anElem || (myType != SMDSAbs_All && anElem->GetType() != myType) )
2778 return (!anElem->IsQuadratic());
2781 void LinearOrQuadratic::SetType( SMDSAbs_ElementType theType )
2786 SMDSAbs_ElementType LinearOrQuadratic::GetType() const
2791 //================================================================================
2794 Description : Functor for check color of group to which mesh element belongs to
2796 //================================================================================
2798 GroupColor::GroupColor()
2802 bool GroupColor::IsSatisfy( long theId )
2804 return myIDs.count( theId );
2807 void GroupColor::SetType( SMDSAbs_ElementType theType )
2812 SMDSAbs_ElementType GroupColor::GetType() const
2817 static bool isEqual( const Quantity_Color& theColor1,
2818 const Quantity_Color& theColor2 )
2820 // tolerance to compare colors
2821 const double tol = 5*1e-3;
2822 return ( fabs( theColor1.Red() - theColor2.Red() ) < tol &&
2823 fabs( theColor1.Green() - theColor2.Green() ) < tol &&
2824 fabs( theColor1.Blue() - theColor2.Blue() ) < tol );
2827 void GroupColor::SetMesh( const SMDS_Mesh* theMesh )
2831 const SMESHDS_Mesh* aMesh = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
2835 int nbGrp = aMesh->GetNbGroups();
2839 // iterates on groups and find necessary elements ids
2840 const std::set<SMESHDS_GroupBase*>& aGroups = aMesh->GetGroups();
2841 std::set<SMESHDS_GroupBase*>::const_iterator GrIt = aGroups.begin();
2842 for (; GrIt != aGroups.end(); GrIt++)
2844 SMESHDS_GroupBase* aGrp = (*GrIt);
2847 // check type and color of group
2848 if ( !isEqual( myColor, aGrp->GetColor() ))
2851 // IPAL52867 (prevent infinite recursion via GroupOnFilter)
2852 if ( SMESHDS_GroupOnFilter * gof = dynamic_cast< SMESHDS_GroupOnFilter* >( aGrp ))
2853 if ( gof->GetPredicate().get() == this )
2856 SMDSAbs_ElementType aGrpElType = (SMDSAbs_ElementType)aGrp->GetType();
2857 if ( myType == aGrpElType || (myType == SMDSAbs_All && aGrpElType != SMDSAbs_Node) ) {
2858 // add elements IDS into control
2859 int aSize = aGrp->Extent();
2860 for (int i = 0; i < aSize; i++)
2861 myIDs.insert( aGrp->GetID(i+1) );
2866 void GroupColor::SetColorStr( const TCollection_AsciiString& theStr )
2868 Kernel_Utils::Localizer loc;
2869 TCollection_AsciiString aStr = theStr;
2870 aStr.RemoveAll( ' ' );
2871 aStr.RemoveAll( '\t' );
2872 for ( int aPos = aStr.Search( ";;" ); aPos != -1; aPos = aStr.Search( ";;" ) )
2873 aStr.Remove( aPos, 2 );
2874 Standard_Real clr[3];
2875 clr[0] = clr[1] = clr[2] = 0.;
2876 for ( int i = 0; i < 3; i++ ) {
2877 TCollection_AsciiString tmpStr = aStr.Token( ";", i+1 );
2878 if ( !tmpStr.IsEmpty() && tmpStr.IsRealValue() )
2879 clr[i] = tmpStr.RealValue();
2881 myColor = Quantity_Color( clr[0], clr[1], clr[2], Quantity_TOC_RGB );
2884 //=======================================================================
2885 // name : GetRangeStr
2886 // Purpose : Get range as a string.
2887 // Example: "1,2,3,50-60,63,67,70-"
2888 //=======================================================================
2890 void GroupColor::GetColorStr( TCollection_AsciiString& theResStr ) const
2893 theResStr += TCollection_AsciiString( myColor.Red() );
2894 theResStr += TCollection_AsciiString( ";" ) + TCollection_AsciiString( myColor.Green() );
2895 theResStr += TCollection_AsciiString( ";" ) + TCollection_AsciiString( myColor.Blue() );
2898 //================================================================================
2900 Class : ElemGeomType
2901 Description : Predicate to check element geometry type
2903 //================================================================================
2905 ElemGeomType::ElemGeomType()
2908 myType = SMDSAbs_All;
2909 myGeomType = SMDSGeom_TRIANGLE;
2912 void ElemGeomType::SetMesh( const SMDS_Mesh* theMesh )
2917 bool ElemGeomType::IsSatisfy( long theId )
2919 if (!myMesh) return false;
2920 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2923 const SMDSAbs_ElementType anElemType = anElem->GetType();
2924 if ( myType != SMDSAbs_All && anElemType != myType )
2926 bool isOk = ( anElem->GetGeomType() == myGeomType );
2930 void ElemGeomType::SetType( SMDSAbs_ElementType theType )
2935 SMDSAbs_ElementType ElemGeomType::GetType() const
2940 void ElemGeomType::SetGeomType( SMDSAbs_GeometryType theType )
2942 myGeomType = theType;
2945 SMDSAbs_GeometryType ElemGeomType::GetGeomType() const
2950 //================================================================================
2952 Class : ElemEntityType
2953 Description : Predicate to check element entity type
2955 //================================================================================
2957 ElemEntityType::ElemEntityType():
2959 myType( SMDSAbs_All ),
2960 myEntityType( SMDSEntity_0D )
2964 void ElemEntityType::SetMesh( const SMDS_Mesh* theMesh )
2969 bool ElemEntityType::IsSatisfy( long theId )
2971 if ( !myMesh ) return false;
2972 if ( myType == SMDSAbs_Node )
2973 return myMesh->FindNode( theId );
2974 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2976 myEntityType == anElem->GetEntityType() );
2979 void ElemEntityType::SetType( SMDSAbs_ElementType theType )
2984 SMDSAbs_ElementType ElemEntityType::GetType() const
2989 void ElemEntityType::SetElemEntityType( SMDSAbs_EntityType theEntityType )
2991 myEntityType = theEntityType;
2994 SMDSAbs_EntityType ElemEntityType::GetElemEntityType() const
2996 return myEntityType;
2999 //================================================================================
3001 * \brief Class ConnectedElements
3003 //================================================================================
3005 ConnectedElements::ConnectedElements():
3006 myNodeID(0), myType( SMDSAbs_All ), myOkIDsReady( false ) {}
3008 SMDSAbs_ElementType ConnectedElements::GetType() const
3011 int ConnectedElements::GetNode() const
3012 { return myXYZ.empty() ? myNodeID : 0; } // myNodeID can be found by myXYZ
3014 std::vector<double> ConnectedElements::GetPoint() const
3017 void ConnectedElements::clearOkIDs()
3018 { myOkIDsReady = false; myOkIDs.clear(); }
3020 void ConnectedElements::SetType( SMDSAbs_ElementType theType )
3022 if ( myType != theType || myMeshModifTracer.IsMeshModified() )
3027 void ConnectedElements::SetMesh( const SMDS_Mesh* theMesh )
3029 myMeshModifTracer.SetMesh( theMesh );
3030 if ( myMeshModifTracer.IsMeshModified() )
3033 if ( !myXYZ.empty() )
3034 SetPoint( myXYZ[0], myXYZ[1], myXYZ[2] ); // find a node near myXYZ it in a new mesh
3038 void ConnectedElements::SetNode( int nodeID )
3043 bool isSameDomain = false;
3044 if ( myOkIDsReady && myMeshModifTracer.GetMesh() && !myMeshModifTracer.IsMeshModified() )
3045 if ( const SMDS_MeshNode* n = myMeshModifTracer.GetMesh()->FindNode( myNodeID ))
3047 SMDS_ElemIteratorPtr eIt = n->GetInverseElementIterator( myType );
3048 while ( !isSameDomain && eIt->more() )
3049 isSameDomain = IsSatisfy( eIt->next()->GetID() );
3051 if ( !isSameDomain )
3055 void ConnectedElements::SetPoint( double x, double y, double z )
3063 bool isSameDomain = false;
3065 // find myNodeID by myXYZ if possible
3066 if ( myMeshModifTracer.GetMesh() )
3068 SMESHUtils::Deleter<SMESH_ElementSearcher> searcher
3069 ( SMESH_MeshAlgos::GetElementSearcher( (SMDS_Mesh&) *myMeshModifTracer.GetMesh() ));
3071 std::vector< const SMDS_MeshElement* > foundElems;
3072 searcher->FindElementsByPoint( gp_Pnt(x,y,z), SMDSAbs_All, foundElems );
3074 if ( !foundElems.empty() )
3076 myNodeID = foundElems[0]->GetNode(0)->GetID();
3077 if ( myOkIDsReady && !myMeshModifTracer.IsMeshModified() )
3078 isSameDomain = IsSatisfy( foundElems[0]->GetID() );
3081 if ( !isSameDomain )
3085 bool ConnectedElements::IsSatisfy( long theElementId )
3087 // Here we do NOT check if the mesh has changed, we do it in Set...() only!!!
3089 if ( !myOkIDsReady )
3091 if ( !myMeshModifTracer.GetMesh() )
3093 const SMDS_MeshNode* node0 = myMeshModifTracer.GetMesh()->FindNode( myNodeID );
3097 std::list< const SMDS_MeshNode* > nodeQueue( 1, node0 );
3098 std::set< int > checkedNodeIDs;
3100 // foreach node in nodeQueue:
3101 // foreach element sharing a node:
3102 // add ID of an element of myType to myOkIDs;
3103 // push all element nodes absent from checkedNodeIDs to nodeQueue;
3104 while ( !nodeQueue.empty() )
3106 const SMDS_MeshNode* node = nodeQueue.front();
3107 nodeQueue.pop_front();
3109 // loop on elements sharing the node
3110 SMDS_ElemIteratorPtr eIt = node->GetInverseElementIterator();
3111 while ( eIt->more() )
3113 // keep elements of myType
3114 const SMDS_MeshElement* element = eIt->next();
3115 if ( element->GetType() == myType )
3116 myOkIDs.insert( myOkIDs.end(), element->GetID() );
3118 // enqueue nodes of the element
3119 SMDS_ElemIteratorPtr nIt = element->nodesIterator();
3120 while ( nIt->more() )
3122 const SMDS_MeshNode* n = static_cast< const SMDS_MeshNode* >( nIt->next() );
3123 if ( checkedNodeIDs.insert( n->GetID() ).second )
3124 nodeQueue.push_back( n );
3128 if ( myType == SMDSAbs_Node )
3129 std::swap( myOkIDs, checkedNodeIDs );
3131 size_t totalNbElems = myMeshModifTracer.GetMesh()->GetMeshInfo().NbElements( myType );
3132 if ( myOkIDs.size() == totalNbElems )
3135 myOkIDsReady = true;
3138 return myOkIDs.empty() ? true : myOkIDs.count( theElementId );
3141 //================================================================================
3143 * \brief Class CoplanarFaces
3145 //================================================================================
3149 inline bool isLessAngle( const gp_Vec& v1, const gp_Vec& v2, const double cos )
3151 double dot = v1 * v2; // cos * |v1| * |v2|
3152 double l1 = v1.SquareMagnitude();
3153 double l2 = v2.SquareMagnitude();
3154 return (( dot * cos >= 0 ) &&
3155 ( dot * dot ) / l1 / l2 >= ( cos * cos ));
3158 CoplanarFaces::CoplanarFaces()
3159 : myFaceID(0), myToler(0)
3162 void CoplanarFaces::SetMesh( const SMDS_Mesh* theMesh )
3164 myMeshModifTracer.SetMesh( theMesh );
3165 if ( myMeshModifTracer.IsMeshModified() )
3167 // Build a set of coplanar face ids
3169 myCoplanarIDs.Clear();
3171 if ( !myMeshModifTracer.GetMesh() || !myFaceID || !myToler )
3174 const SMDS_MeshElement* face = myMeshModifTracer.GetMesh()->FindElement( myFaceID );
3175 if ( !face || face->GetType() != SMDSAbs_Face )
3179 gp_Vec myNorm = getNormale( static_cast<const SMDS_MeshFace*>(face), &normOK );
3183 const double cosTol = Cos( myToler * M_PI / 180. );
3184 NCollection_Map< SMESH_TLink, SMESH_TLink > checkedLinks;
3186 std::list< std::pair< const SMDS_MeshElement*, gp_Vec > > faceQueue;
3187 faceQueue.push_back( std::make_pair( face, myNorm ));
3188 while ( !faceQueue.empty() )
3190 face = faceQueue.front().first;
3191 myNorm = faceQueue.front().second;
3192 faceQueue.pop_front();
3194 for ( int i = 0, nbN = face->NbCornerNodes(); i < nbN; ++i )
3196 const SMDS_MeshNode* n1 = face->GetNode( i );
3197 const SMDS_MeshNode* n2 = face->GetNode(( i+1 )%nbN);
3198 if ( !checkedLinks.Add( SMESH_TLink( n1, n2 )))
3200 SMDS_ElemIteratorPtr fIt = n1->GetInverseElementIterator(SMDSAbs_Face);
3201 while ( fIt->more() )
3203 const SMDS_MeshElement* f = fIt->next();
3204 if ( f->GetNodeIndex( n2 ) > -1 )
3206 gp_Vec norm = getNormale( static_cast<const SMDS_MeshFace*>(f), &normOK );
3207 if (!normOK || isLessAngle( myNorm, norm, cosTol))
3209 myCoplanarIDs.Add( f->GetID() );
3210 faceQueue.push_back( std::make_pair( f, norm ));
3218 bool CoplanarFaces::IsSatisfy( long theElementId )
3220 return myCoplanarIDs.Contains( theElementId );
3225 *Description : Predicate for Range of Ids.
3226 * Range may be specified with two ways.
3227 * 1. Using AddToRange method
3228 * 2. With SetRangeStr method. Parameter of this method is a string
3229 * like as "1,2,3,50-60,63,67,70-"
3232 //=======================================================================
3233 // name : RangeOfIds
3234 // Purpose : Constructor
3235 //=======================================================================
3236 RangeOfIds::RangeOfIds()
3239 myType = SMDSAbs_All;
3242 //=======================================================================
3244 // Purpose : Set mesh
3245 //=======================================================================
3246 void RangeOfIds::SetMesh( const SMDS_Mesh* theMesh )
3251 //=======================================================================
3252 // name : AddToRange
3253 // Purpose : Add ID to the range
3254 //=======================================================================
3255 bool RangeOfIds::AddToRange( long theEntityId )
3257 myIds.Add( theEntityId );
3261 //=======================================================================
3262 // name : GetRangeStr
3263 // Purpose : Get range as a string.
3264 // Example: "1,2,3,50-60,63,67,70-"
3265 //=======================================================================
3266 void RangeOfIds::GetRangeStr( TCollection_AsciiString& theResStr )
3270 TColStd_SequenceOfInteger anIntSeq;
3271 TColStd_SequenceOfAsciiString aStrSeq;
3273 TColStd_MapIteratorOfMapOfInteger anIter( myIds );
3274 for ( ; anIter.More(); anIter.Next() )
3276 int anId = anIter.Key();
3277 TCollection_AsciiString aStr( anId );
3278 anIntSeq.Append( anId );
3279 aStrSeq.Append( aStr );
3282 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
3284 int aMinId = myMin( i );
3285 int aMaxId = myMax( i );
3287 TCollection_AsciiString aStr;
3288 if ( aMinId != IntegerFirst() )
3293 if ( aMaxId != IntegerLast() )
3296 // find position of the string in result sequence and insert string in it
3297 if ( anIntSeq.Length() == 0 )
3299 anIntSeq.Append( aMinId );
3300 aStrSeq.Append( aStr );
3304 if ( aMinId < anIntSeq.First() )
3306 anIntSeq.Prepend( aMinId );
3307 aStrSeq.Prepend( aStr );
3309 else if ( aMinId > anIntSeq.Last() )
3311 anIntSeq.Append( aMinId );
3312 aStrSeq.Append( aStr );
3315 for ( int j = 1, k = anIntSeq.Length(); j <= k; j++ )
3316 if ( aMinId < anIntSeq( j ) )
3318 anIntSeq.InsertBefore( j, aMinId );
3319 aStrSeq.InsertBefore( j, aStr );
3325 if ( aStrSeq.Length() == 0 )
3328 theResStr = aStrSeq( 1 );
3329 for ( int j = 2, k = aStrSeq.Length(); j <= k; j++ )
3332 theResStr += aStrSeq( j );
3336 //=======================================================================
3337 // name : SetRangeStr
3338 // Purpose : Define range with string
3339 // Example of entry string: "1,2,3,50-60,63,67,70-"
3340 //=======================================================================
3341 bool RangeOfIds::SetRangeStr( const TCollection_AsciiString& theStr )
3347 TCollection_AsciiString aStr = theStr;
3348 for ( int i = 1; i <= aStr.Length(); ++i )
3350 char c = aStr.Value( i );
3351 if ( !isdigit( c ) && c != ',' && c != '-' )
3352 aStr.SetValue( i, ',');
3354 aStr.RemoveAll( ' ' );
3356 TCollection_AsciiString tmpStr = aStr.Token( ",", 1 );
3358 while ( tmpStr != "" )
3360 tmpStr = aStr.Token( ",", i++ );
3361 int aPos = tmpStr.Search( '-' );
3365 if ( tmpStr.IsIntegerValue() )
3366 myIds.Add( tmpStr.IntegerValue() );
3372 TCollection_AsciiString aMaxStr = tmpStr.Split( aPos );
3373 TCollection_AsciiString aMinStr = tmpStr;
3375 while ( aMinStr.Search( "-" ) != -1 ) aMinStr.RemoveAll( '-' );
3376 while ( aMaxStr.Search( "-" ) != -1 ) aMaxStr.RemoveAll( '-' );
3378 if ( (!aMinStr.IsEmpty() && !aMinStr.IsIntegerValue()) ||
3379 (!aMaxStr.IsEmpty() && !aMaxStr.IsIntegerValue()) )
3382 myMin.Append( aMinStr.IsEmpty() ? IntegerFirst() : aMinStr.IntegerValue() );
3383 myMax.Append( aMaxStr.IsEmpty() ? IntegerLast() : aMaxStr.IntegerValue() );
3390 //=======================================================================
3392 // Purpose : Get type of supported entities
3393 //=======================================================================
3394 SMDSAbs_ElementType RangeOfIds::GetType() const
3399 //=======================================================================
3401 // Purpose : Set type of supported entities
3402 //=======================================================================
3403 void RangeOfIds::SetType( SMDSAbs_ElementType theType )
3408 //=======================================================================
3410 // Purpose : Verify whether entity satisfies to this rpedicate
3411 //=======================================================================
3412 bool RangeOfIds::IsSatisfy( long theId )
3417 if ( myType == SMDSAbs_Node )
3419 if ( myMesh->FindNode( theId ) == 0 )
3424 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
3425 if ( anElem == 0 || (myType != anElem->GetType() && myType != SMDSAbs_All ))
3429 if ( myIds.Contains( theId ) )
3432 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
3433 if ( theId >= myMin( i ) && theId <= myMax( i ) )
3441 Description : Base class for comparators
3443 Comparator::Comparator():
3447 Comparator::~Comparator()
3450 void Comparator::SetMesh( const SMDS_Mesh* theMesh )
3453 myFunctor->SetMesh( theMesh );
3456 void Comparator::SetMargin( double theValue )
3458 myMargin = theValue;
3461 void Comparator::SetNumFunctor( NumericalFunctorPtr theFunct )
3463 myFunctor = theFunct;
3466 SMDSAbs_ElementType Comparator::GetType() const
3468 return myFunctor ? myFunctor->GetType() : SMDSAbs_All;
3471 double Comparator::GetMargin()
3479 Description : Comparator "<"
3481 bool LessThan::IsSatisfy( long theId )
3483 return myFunctor && myFunctor->GetValue( theId ) < myMargin;
3489 Description : Comparator ">"
3491 bool MoreThan::IsSatisfy( long theId )
3493 return myFunctor && myFunctor->GetValue( theId ) > myMargin;
3499 Description : Comparator "="
3502 myToler(Precision::Confusion())
3505 bool EqualTo::IsSatisfy( long theId )
3507 return myFunctor && fabs( myFunctor->GetValue( theId ) - myMargin ) < myToler;
3510 void EqualTo::SetTolerance( double theToler )
3515 double EqualTo::GetTolerance()
3522 Description : Logical NOT predicate
3524 LogicalNOT::LogicalNOT()
3527 LogicalNOT::~LogicalNOT()
3530 bool LogicalNOT::IsSatisfy( long theId )
3532 return myPredicate && !myPredicate->IsSatisfy( theId );
3535 void LogicalNOT::SetMesh( const SMDS_Mesh* theMesh )
3538 myPredicate->SetMesh( theMesh );
3541 void LogicalNOT::SetPredicate( PredicatePtr thePred )
3543 myPredicate = thePred;
3546 SMDSAbs_ElementType LogicalNOT::GetType() const
3548 return myPredicate ? myPredicate->GetType() : SMDSAbs_All;
3553 Class : LogicalBinary
3554 Description : Base class for binary logical predicate
3556 LogicalBinary::LogicalBinary()
3559 LogicalBinary::~LogicalBinary()
3562 void LogicalBinary::SetMesh( const SMDS_Mesh* theMesh )
3565 myPredicate1->SetMesh( theMesh );
3568 myPredicate2->SetMesh( theMesh );
3571 void LogicalBinary::SetPredicate1( PredicatePtr thePredicate )
3573 myPredicate1 = thePredicate;
3576 void LogicalBinary::SetPredicate2( PredicatePtr thePredicate )
3578 myPredicate2 = thePredicate;
3581 SMDSAbs_ElementType LogicalBinary::GetType() const
3583 if ( !myPredicate1 || !myPredicate2 )
3586 SMDSAbs_ElementType aType1 = myPredicate1->GetType();
3587 SMDSAbs_ElementType aType2 = myPredicate2->GetType();
3589 return aType1 == aType2 ? aType1 : SMDSAbs_All;
3595 Description : Logical AND
3597 bool LogicalAND::IsSatisfy( long theId )
3602 myPredicate1->IsSatisfy( theId ) &&
3603 myPredicate2->IsSatisfy( theId );
3609 Description : Logical OR
3611 bool LogicalOR::IsSatisfy( long theId )
3616 (myPredicate1->IsSatisfy( theId ) ||
3617 myPredicate2->IsSatisfy( theId ));
3626 // #include <tbb/parallel_for.h>
3627 // #include <tbb/enumerable_thread_specific.h>
3629 // namespace Parallel
3631 // typedef tbb::enumerable_thread_specific< TIdSequence > TIdSeq;
3635 // const SMDS_Mesh* myMesh;
3636 // PredicatePtr myPredicate;
3637 // TIdSeq & myOKIds;
3638 // Predicate( const SMDS_Mesh* m, PredicatePtr p, TIdSeq & ids ):
3639 // myMesh(m), myPredicate(p->Duplicate()), myOKIds(ids) {}
3640 // void operator() ( const tbb::blocked_range<size_t>& r ) const
3642 // for ( size_t i = r.begin(); i != r.end(); ++i )
3643 // if ( myPredicate->IsSatisfy( i ))
3644 // myOKIds.local().push_back();
3656 void Filter::SetPredicate( PredicatePtr thePredicate )
3658 myPredicate = thePredicate;
3661 void Filter::GetElementsId( const SMDS_Mesh* theMesh,
3662 PredicatePtr thePredicate,
3663 TIdSequence& theSequence )
3665 theSequence.clear();
3667 if ( !theMesh || !thePredicate )
3670 thePredicate->SetMesh( theMesh );
3672 SMDS_ElemIteratorPtr elemIt = theMesh->elementsIterator( thePredicate->GetType() );
3674 while ( elemIt->more() ) {
3675 const SMDS_MeshElement* anElem = elemIt->next();
3676 long anId = anElem->GetID();
3677 if ( thePredicate->IsSatisfy( anId ) )
3678 theSequence.push_back( anId );
3683 void Filter::GetElementsId( const SMDS_Mesh* theMesh,
3684 Filter::TIdSequence& theSequence )
3686 GetElementsId(theMesh,myPredicate,theSequence);
3693 typedef std::set<SMDS_MeshFace*> TMapOfFacePtr;
3699 ManifoldPart::Link::Link( SMDS_MeshNode* theNode1,
3700 SMDS_MeshNode* theNode2 )
3706 ManifoldPart::Link::~Link()
3712 bool ManifoldPart::Link::IsEqual( const ManifoldPart::Link& theLink ) const
3714 if ( myNode1 == theLink.myNode1 &&
3715 myNode2 == theLink.myNode2 )
3717 else if ( myNode1 == theLink.myNode2 &&
3718 myNode2 == theLink.myNode1 )
3724 bool ManifoldPart::Link::operator<( const ManifoldPart::Link& x ) const
3726 if(myNode1 < x.myNode1) return true;
3727 if(myNode1 == x.myNode1)
3728 if(myNode2 < x.myNode2) return true;
3732 bool ManifoldPart::IsEqual( const ManifoldPart::Link& theLink1,
3733 const ManifoldPart::Link& theLink2 )
3735 return theLink1.IsEqual( theLink2 );
3738 ManifoldPart::ManifoldPart()
3741 myAngToler = Precision::Angular();
3742 myIsOnlyManifold = true;
3745 ManifoldPart::~ManifoldPart()
3750 void ManifoldPart::SetMesh( const SMDS_Mesh* theMesh )
3756 SMDSAbs_ElementType ManifoldPart::GetType() const
3757 { return SMDSAbs_Face; }
3759 bool ManifoldPart::IsSatisfy( long theElementId )
3761 return myMapIds.Contains( theElementId );
3764 void ManifoldPart::SetAngleTolerance( const double theAngToler )
3765 { myAngToler = theAngToler; }
3767 double ManifoldPart::GetAngleTolerance() const
3768 { return myAngToler; }
3770 void ManifoldPart::SetIsOnlyManifold( const bool theIsOnly )
3771 { myIsOnlyManifold = theIsOnly; }
3773 void ManifoldPart::SetStartElem( const long theStartId )
3774 { myStartElemId = theStartId; }
3776 bool ManifoldPart::process()
3779 myMapBadGeomIds.Clear();
3781 myAllFacePtr.clear();
3782 myAllFacePtrIntDMap.clear();
3786 // collect all faces into own map
3787 SMDS_FaceIteratorPtr anFaceItr = myMesh->facesIterator();
3788 for (; anFaceItr->more(); )
3790 SMDS_MeshFace* aFacePtr = (SMDS_MeshFace*)anFaceItr->next();
3791 myAllFacePtr.push_back( aFacePtr );
3792 myAllFacePtrIntDMap[aFacePtr] = myAllFacePtr.size()-1;
3795 SMDS_MeshFace* aStartFace = (SMDS_MeshFace*)myMesh->FindElement( myStartElemId );
3799 // the map of non manifold links and bad geometry
3800 TMapOfLink aMapOfNonManifold;
3801 TColStd_MapOfInteger aMapOfTreated;
3803 // begin cycle on faces from start index and run on vector till the end
3804 // and from begin to start index to cover whole vector
3805 const int aStartIndx = myAllFacePtrIntDMap[aStartFace];
3806 bool isStartTreat = false;
3807 for ( int fi = aStartIndx; !isStartTreat || fi != aStartIndx ; fi++ )
3809 if ( fi == aStartIndx )
3810 isStartTreat = true;
3811 // as result next time when fi will be equal to aStartIndx
3813 SMDS_MeshFace* aFacePtr = myAllFacePtr[ fi ];
3814 if ( aMapOfTreated.Contains( aFacePtr->GetID() ) )
3817 aMapOfTreated.Add( aFacePtr->GetID() );
3818 TColStd_MapOfInteger aResFaces;
3819 if ( !findConnected( myAllFacePtrIntDMap, aFacePtr,
3820 aMapOfNonManifold, aResFaces ) )
3822 TColStd_MapIteratorOfMapOfInteger anItr( aResFaces );
3823 for ( ; anItr.More(); anItr.Next() )
3825 int aFaceId = anItr.Key();
3826 aMapOfTreated.Add( aFaceId );
3827 myMapIds.Add( aFaceId );
3830 if ( fi == int( myAllFacePtr.size() - 1 ))
3832 } // end run on vector of faces
3833 return !myMapIds.IsEmpty();
3836 static void getLinks( const SMDS_MeshFace* theFace,
3837 ManifoldPart::TVectorOfLink& theLinks )
3839 int aNbNode = theFace->NbNodes();
3840 SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
3842 SMDS_MeshNode* aNode = 0;
3843 for ( ; aNodeItr->more() && i <= aNbNode; )
3846 SMDS_MeshNode* aN1 = (SMDS_MeshNode*)aNodeItr->next();
3850 SMDS_MeshNode* aN2 = ( i >= aNbNode ) ? aNode : (SMDS_MeshNode*)aNodeItr->next();
3852 ManifoldPart::Link aLink( aN1, aN2 );
3853 theLinks.push_back( aLink );
3857 bool ManifoldPart::findConnected
3858 ( const ManifoldPart::TDataMapFacePtrInt& theAllFacePtrInt,
3859 SMDS_MeshFace* theStartFace,
3860 ManifoldPart::TMapOfLink& theNonManifold,
3861 TColStd_MapOfInteger& theResFaces )
3863 theResFaces.Clear();
3864 if ( !theAllFacePtrInt.size() )
3867 if ( getNormale( theStartFace ).SquareModulus() <= gp::Resolution() )
3869 myMapBadGeomIds.Add( theStartFace->GetID() );
3873 ManifoldPart::TMapOfLink aMapOfBoundary, aMapToSkip;
3874 ManifoldPart::TVectorOfLink aSeqOfBoundary;
3875 theResFaces.Add( theStartFace->GetID() );
3876 ManifoldPart::TDataMapOfLinkFacePtr aDMapLinkFace;
3878 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
3879 aDMapLinkFace, theNonManifold, theStartFace );
3881 bool isDone = false;
3882 while ( !isDone && aMapOfBoundary.size() != 0 )
3884 bool isToReset = false;
3885 ManifoldPart::TVectorOfLink::iterator pLink = aSeqOfBoundary.begin();
3886 for ( ; !isToReset && pLink != aSeqOfBoundary.end(); ++pLink )
3888 ManifoldPart::Link aLink = *pLink;
3889 if ( aMapToSkip.find( aLink ) != aMapToSkip.end() )
3891 // each link could be treated only once
3892 aMapToSkip.insert( aLink );
3894 ManifoldPart::TVectorOfFacePtr aFaces;
3896 if ( myIsOnlyManifold &&
3897 (theNonManifold.find( aLink ) != theNonManifold.end()) )
3901 getFacesByLink( aLink, aFaces );
3902 // filter the element to keep only indicated elements
3903 ManifoldPart::TVectorOfFacePtr aFiltered;
3904 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
3905 for ( ; pFace != aFaces.end(); ++pFace )
3907 SMDS_MeshFace* aFace = *pFace;
3908 if ( myAllFacePtrIntDMap.find( aFace ) != myAllFacePtrIntDMap.end() )
3909 aFiltered.push_back( aFace );
3912 if ( aFaces.size() < 2 ) // no neihgbour faces
3914 else if ( myIsOnlyManifold && aFaces.size() > 2 ) // non manifold case
3916 theNonManifold.insert( aLink );
3921 // compare normal with normals of neighbor element
3922 SMDS_MeshFace* aPrevFace = aDMapLinkFace[ aLink ];
3923 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
3924 for ( ; pFace != aFaces.end(); ++pFace )
3926 SMDS_MeshFace* aNextFace = *pFace;
3927 if ( aPrevFace == aNextFace )
3929 int anNextFaceID = aNextFace->GetID();
3930 if ( myIsOnlyManifold && theResFaces.Contains( anNextFaceID ) )
3931 // should not be with non manifold restriction. probably bad topology
3933 // check if face was treated and skipped
3934 if ( myMapBadGeomIds.Contains( anNextFaceID ) ||
3935 !isInPlane( aPrevFace, aNextFace ) )
3937 // add new element to connected and extend the boundaries.
3938 theResFaces.Add( anNextFaceID );
3939 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
3940 aDMapLinkFace, theNonManifold, aNextFace );
3944 isDone = !isToReset;
3947 return !theResFaces.IsEmpty();
3950 bool ManifoldPart::isInPlane( const SMDS_MeshFace* theFace1,
3951 const SMDS_MeshFace* theFace2 )
3953 gp_Dir aNorm1 = gp_Dir( getNormale( theFace1 ) );
3954 gp_XYZ aNorm2XYZ = getNormale( theFace2 );
3955 if ( aNorm2XYZ.SquareModulus() <= gp::Resolution() )
3957 myMapBadGeomIds.Add( theFace2->GetID() );
3960 if ( aNorm1.IsParallel( gp_Dir( aNorm2XYZ ), myAngToler ) )
3966 void ManifoldPart::expandBoundary
3967 ( ManifoldPart::TMapOfLink& theMapOfBoundary,
3968 ManifoldPart::TVectorOfLink& theSeqOfBoundary,
3969 ManifoldPart::TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
3970 ManifoldPart::TMapOfLink& theNonManifold,
3971 SMDS_MeshFace* theNextFace ) const
3973 ManifoldPart::TVectorOfLink aLinks;
3974 getLinks( theNextFace, aLinks );
3975 int aNbLink = (int)aLinks.size();
3976 for ( int i = 0; i < aNbLink; i++ )
3978 ManifoldPart::Link aLink = aLinks[ i ];
3979 if ( myIsOnlyManifold && (theNonManifold.find( aLink ) != theNonManifold.end()) )
3981 if ( theMapOfBoundary.find( aLink ) != theMapOfBoundary.end() )
3983 if ( myIsOnlyManifold )
3985 // remove from boundary
3986 theMapOfBoundary.erase( aLink );
3987 ManifoldPart::TVectorOfLink::iterator pLink = theSeqOfBoundary.begin();
3988 for ( ; pLink != theSeqOfBoundary.end(); ++pLink )
3990 ManifoldPart::Link aBoundLink = *pLink;
3991 if ( aBoundLink.IsEqual( aLink ) )
3993 theSeqOfBoundary.erase( pLink );
4001 theMapOfBoundary.insert( aLink );
4002 theSeqOfBoundary.push_back( aLink );
4003 theDMapLinkFacePtr[ aLink ] = theNextFace;
4008 void ManifoldPart::getFacesByLink( const ManifoldPart::Link& theLink,
4009 ManifoldPart::TVectorOfFacePtr& theFaces ) const
4011 std::set<SMDS_MeshCell *> aSetOfFaces;
4012 // take all faces that shared first node
4013 SMDS_ElemIteratorPtr anItr = theLink.myNode1->facesIterator();
4014 for ( ; anItr->more(); )
4016 SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
4019 aSetOfFaces.insert( aFace );
4021 // take all faces that shared second node
4022 anItr = theLink.myNode2->facesIterator();
4023 // find the common part of two sets
4024 for ( ; anItr->more(); )
4026 SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
4027 if ( aSetOfFaces.count( aFace ) )
4028 theFaces.push_back( aFace );
4033 Class : BelongToMeshGroup
4034 Description : Verify whether a mesh element is included into a mesh group
4036 BelongToMeshGroup::BelongToMeshGroup(): myGroup( 0 )
4040 void BelongToMeshGroup::SetGroup( SMESHDS_GroupBase* g )
4045 void BelongToMeshGroup::SetStoreName( const std::string& sn )
4050 void BelongToMeshGroup::SetMesh( const SMDS_Mesh* theMesh )
4052 if ( myGroup && myGroup->GetMesh() != theMesh )
4056 if ( !myGroup && !myStoreName.empty() )
4058 if ( const SMESHDS_Mesh* aMesh = dynamic_cast<const SMESHDS_Mesh*>(theMesh))
4060 const std::set<SMESHDS_GroupBase*>& grps = aMesh->GetGroups();
4061 std::set<SMESHDS_GroupBase*>::const_iterator g = grps.begin();
4062 for ( ; g != grps.end() && !myGroup; ++g )
4063 if ( *g && myStoreName == (*g)->GetStoreName() )
4069 myGroup->IsEmpty(); // make GroupOnFilter update its predicate
4073 bool BelongToMeshGroup::IsSatisfy( long theElementId )
4075 return myGroup ? myGroup->Contains( theElementId ) : false;
4078 SMDSAbs_ElementType BelongToMeshGroup::GetType() const
4080 return myGroup ? myGroup->GetType() : SMDSAbs_All;
4083 //================================================================================
4084 // ElementsOnSurface
4085 //================================================================================
4087 ElementsOnSurface::ElementsOnSurface()
4090 myType = SMDSAbs_All;
4092 myToler = Precision::Confusion();
4093 myUseBoundaries = false;
4096 ElementsOnSurface::~ElementsOnSurface()
4100 void ElementsOnSurface::SetMesh( const SMDS_Mesh* theMesh )
4102 myMeshModifTracer.SetMesh( theMesh );
4103 if ( myMeshModifTracer.IsMeshModified())
4107 bool ElementsOnSurface::IsSatisfy( long theElementId )
4109 return myIds.Contains( theElementId );
4112 SMDSAbs_ElementType ElementsOnSurface::GetType() const
4115 void ElementsOnSurface::SetTolerance( const double theToler )
4117 if ( myToler != theToler )
4122 double ElementsOnSurface::GetTolerance() const
4125 void ElementsOnSurface::SetUseBoundaries( bool theUse )
4127 if ( myUseBoundaries != theUse ) {
4128 myUseBoundaries = theUse;
4129 SetSurface( mySurf, myType );
4133 void ElementsOnSurface::SetSurface( const TopoDS_Shape& theShape,
4134 const SMDSAbs_ElementType theType )
4139 if ( theShape.IsNull() || theShape.ShapeType() != TopAbs_FACE )
4141 mySurf = TopoDS::Face( theShape );
4142 BRepAdaptor_Surface SA( mySurf, myUseBoundaries );
4144 u1 = SA.FirstUParameter(),
4145 u2 = SA.LastUParameter(),
4146 v1 = SA.FirstVParameter(),
4147 v2 = SA.LastVParameter();
4148 Handle(Geom_Surface) surf = BRep_Tool::Surface( mySurf );
4149 myProjector.Init( surf, u1,u2, v1,v2 );
4153 void ElementsOnSurface::process()
4156 if ( mySurf.IsNull() )
4159 if ( !myMeshModifTracer.GetMesh() )
4162 myIds.ReSize( myMeshModifTracer.GetMesh()->GetMeshInfo().NbElements( myType ));
4164 SMDS_ElemIteratorPtr anIter = myMeshModifTracer.GetMesh()->elementsIterator( myType );
4165 for(; anIter->more(); )
4166 process( anIter->next() );
4169 void ElementsOnSurface::process( const SMDS_MeshElement* theElemPtr )
4171 SMDS_ElemIteratorPtr aNodeItr = theElemPtr->nodesIterator();
4172 bool isSatisfy = true;
4173 for ( ; aNodeItr->more(); )
4175 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
4176 if ( !isOnSurface( aNode ) )
4183 myIds.Add( theElemPtr->GetID() );
4186 bool ElementsOnSurface::isOnSurface( const SMDS_MeshNode* theNode )
4188 if ( mySurf.IsNull() )
4191 gp_Pnt aPnt( theNode->X(), theNode->Y(), theNode->Z() );
4192 // double aToler2 = myToler * myToler;
4193 // if ( mySurf->IsKind(STANDARD_TYPE(Geom_Plane)))
4195 // gp_Pln aPln = Handle(Geom_Plane)::DownCast(mySurf)->Pln();
4196 // if ( aPln.SquareDistance( aPnt ) > aToler2 )
4199 // else if ( mySurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)))
4201 // gp_Cylinder aCyl = Handle(Geom_CylindricalSurface)::DownCast(mySurf)->Cylinder();
4202 // double aRad = aCyl.Radius();
4203 // gp_Ax3 anAxis = aCyl.Position();
4204 // gp_XYZ aLoc = aCyl.Location().XYZ();
4205 // double aXDist = anAxis.XDirection().XYZ() * ( aPnt.XYZ() - aLoc );
4206 // double aYDist = anAxis.YDirection().XYZ() * ( aPnt.XYZ() - aLoc );
4207 // if ( fabs(aXDist*aXDist + aYDist*aYDist - aRad*aRad) > aToler2 )
4212 myProjector.Perform( aPnt );
4213 bool isOn = ( myProjector.IsDone() && myProjector.LowerDistance() <= myToler );
4219 //================================================================================
4221 //================================================================================
4224 const int theIsCheckedFlag = 0x0000100;
4227 struct ElementsOnShape::Classifier
4229 Classifier() { mySolidClfr = 0; myFlags = 0; }
4231 void Init(const TopoDS_Shape& s, double tol, const Bnd_B3d* box = 0 );
4232 bool IsOut(const gp_Pnt& p) { return SetChecked( true ), (this->*myIsOutFun)( p ); }
4233 TopAbs_ShapeEnum ShapeType() const { return myShape.ShapeType(); }
4234 const TopoDS_Shape& Shape() const { return myShape; }
4235 const Bnd_B3d* GetBndBox() const { return & myBox; }
4236 bool IsChecked() { return myFlags & theIsCheckedFlag; }
4237 bool IsSetFlag( int flag ) const { return myFlags & flag; }
4238 void SetChecked( bool is ) { is ? SetFlag( theIsCheckedFlag ) : UnsetFlag( theIsCheckedFlag ); }
4239 void SetFlag ( int flag ) { myFlags |= flag; }
4240 void UnsetFlag( int flag ) { myFlags &= ~flag; }
4243 bool isOutOfSolid (const gp_Pnt& p);
4244 bool isOutOfBox (const gp_Pnt& p);
4245 bool isOutOfFace (const gp_Pnt& p);
4246 bool isOutOfEdge (const gp_Pnt& p);
4247 bool isOutOfVertex(const gp_Pnt& p);
4248 bool isBox (const TopoDS_Shape& s);
4250 bool (Classifier::* myIsOutFun)(const gp_Pnt& p);
4251 BRepClass3d_SolidClassifier* mySolidClfr; // ptr because of a run-time forbidden copy-constructor
4253 GeomAPI_ProjectPointOnSurf myProjFace;
4254 GeomAPI_ProjectPointOnCurve myProjEdge;
4256 TopoDS_Shape myShape;
4261 struct ElementsOnShape::OctreeClassifier : public SMESH_Octree
4263 OctreeClassifier( const std::vector< ElementsOnShape::Classifier* >& classifiers );
4264 OctreeClassifier( const OctreeClassifier* otherTree,
4265 const std::vector< ElementsOnShape::Classifier >& clsOther,
4266 std::vector< ElementsOnShape::Classifier >& cls );
4267 void GetClassifiersAtPoint( const gp_XYZ& p,
4268 std::vector< ElementsOnShape::Classifier* >& classifiers );
4270 OctreeClassifier() {}
4271 SMESH_Octree* newChild() const { return new OctreeClassifier; }
4272 void buildChildrenData();
4273 Bnd_B3d* buildRootBox();
4275 std::vector< ElementsOnShape::Classifier* > myClassifiers;
4279 ElementsOnShape::ElementsOnShape():
4281 myType(SMDSAbs_All),
4282 myToler(Precision::Confusion()),
4283 myAllNodesFlag(false)
4287 ElementsOnShape::~ElementsOnShape()
4292 Predicate* ElementsOnShape::clone() const
4294 ElementsOnShape* cln = new ElementsOnShape();
4295 cln->SetAllNodes ( myAllNodesFlag );
4296 cln->SetTolerance( myToler );
4297 cln->SetMesh ( myMeshModifTracer.GetMesh() );
4298 cln->myShape = myShape; // avoid creation of myClassifiers
4299 cln->SetShape ( myShape, myType );
4300 cln->myClassifiers.resize( myClassifiers.size() );
4301 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4302 cln->myClassifiers[ i ].Init( BRepBuilderAPI_Copy( myClassifiers[ i ].Shape()),
4303 myToler, myClassifiers[ i ].GetBndBox() );
4304 if ( myOctree ) // copy myOctree
4306 cln->myOctree = new OctreeClassifier( myOctree, myClassifiers, cln->myClassifiers );
4311 SMDSAbs_ElementType ElementsOnShape::GetType() const
4316 void ElementsOnShape::SetTolerance (const double theToler)
4318 if (myToler != theToler) {
4320 SetShape(myShape, myType);
4324 double ElementsOnShape::GetTolerance() const
4329 void ElementsOnShape::SetAllNodes (bool theAllNodes)
4331 myAllNodesFlag = theAllNodes;
4334 void ElementsOnShape::SetMesh (const SMDS_Mesh* theMesh)
4336 myMeshModifTracer.SetMesh( theMesh );
4337 if ( myMeshModifTracer.IsMeshModified())
4339 size_t nbNodes = theMesh ? theMesh->NbNodes() : 0;
4340 if ( myNodeIsChecked.size() == nbNodes )
4342 std::fill( myNodeIsChecked.begin(), myNodeIsChecked.end(), false );
4346 SMESHUtils::FreeVector( myNodeIsChecked );
4347 SMESHUtils::FreeVector( myNodeIsOut );
4348 myNodeIsChecked.resize( nbNodes, false );
4349 myNodeIsOut.resize( nbNodes );
4354 bool ElementsOnShape::getNodeIsOut( const SMDS_MeshNode* n, bool& isOut )
4356 if ( n->GetID() >= (int) myNodeIsChecked.size() ||
4357 !myNodeIsChecked[ n->GetID() ])
4360 isOut = myNodeIsOut[ n->GetID() ];
4364 void ElementsOnShape::setNodeIsOut( const SMDS_MeshNode* n, bool isOut )
4366 if ( n->GetID() < (int) myNodeIsChecked.size() )
4368 myNodeIsChecked[ n->GetID() ] = true;
4369 myNodeIsOut [ n->GetID() ] = isOut;
4373 void ElementsOnShape::SetShape (const TopoDS_Shape& theShape,
4374 const SMDSAbs_ElementType theType)
4376 bool shapeChanges = ( myShape != theShape );
4379 if ( myShape.IsNull() ) return;
4383 // find most complex shapes
4384 TopTools_IndexedMapOfShape shapesMap;
4385 TopAbs_ShapeEnum shapeTypes[4] = { TopAbs_SOLID, TopAbs_FACE, TopAbs_EDGE, TopAbs_VERTEX };
4386 TopExp_Explorer sub;
4387 for ( int i = 0; i < 4; ++i )
4389 if ( shapesMap.IsEmpty() )
4390 for ( sub.Init( myShape, shapeTypes[i] ); sub.More(); sub.Next() )
4391 shapesMap.Add( sub.Current() );
4393 for ( sub.Init( myShape, shapeTypes[i], shapeTypes[i-1] ); sub.More(); sub.Next() )
4394 shapesMap.Add( sub.Current() );
4398 myClassifiers.resize( shapesMap.Extent() );
4399 for ( int i = 0; i < shapesMap.Extent(); ++i )
4400 myClassifiers[ i ].Init( shapesMap( i+1 ), myToler );
4403 if ( theType == SMDSAbs_Node )
4405 SMESHUtils::FreeVector( myNodeIsChecked );
4406 SMESHUtils::FreeVector( myNodeIsOut );
4410 std::fill( myNodeIsChecked.begin(), myNodeIsChecked.end(), false );
4414 void ElementsOnShape::clearClassifiers()
4416 // for ( size_t i = 0; i < myClassifiers.size(); ++i )
4417 // delete myClassifiers[ i ];
4418 myClassifiers.clear();
4424 bool ElementsOnShape::IsSatisfy( long elemId )
4426 if ( myClassifiers.empty() )
4429 const SMDS_Mesh* mesh = myMeshModifTracer.GetMesh();
4430 if ( myType == SMDSAbs_Node )
4431 return IsSatisfy( mesh->FindNode( elemId ));
4432 return IsSatisfy( mesh->FindElement( elemId ));
4435 bool ElementsOnShape::IsSatisfy (const SMDS_MeshElement* elem)
4440 bool isSatisfy = myAllNodesFlag, isNodeOut;
4442 gp_XYZ centerXYZ (0, 0, 0);
4444 if ( !myOctree && myClassifiers.size() > 5 )
4446 myWorkClassifiers.resize( myClassifiers.size() );
4447 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4448 myWorkClassifiers[ i ] = & myClassifiers[ i ];
4449 myOctree = new OctreeClassifier( myWorkClassifiers );
4452 SMDS_ElemIteratorPtr aNodeItr = elem->nodesIterator();
4453 while (aNodeItr->more() && (isSatisfy == myAllNodesFlag))
4455 SMESH_TNodeXYZ aPnt( aNodeItr->next() );
4459 if ( !getNodeIsOut( aPnt._node, isNodeOut ))
4463 myWorkClassifiers.clear();
4464 myOctree->GetClassifiersAtPoint( aPnt, myWorkClassifiers );
4466 for ( size_t i = 0; i < myWorkClassifiers.size(); ++i )
4467 myWorkClassifiers[i]->SetChecked( false );
4469 for ( size_t i = 0; i < myWorkClassifiers.size() && isNodeOut; ++i )
4470 if ( !myWorkClassifiers[i]->IsChecked() )
4471 isNodeOut = myWorkClassifiers[i]->IsOut( aPnt );
4475 for ( size_t i = 0; i < myClassifiers.size() && isNodeOut; ++i )
4476 isNodeOut = myClassifiers[i].IsOut( aPnt );
4478 setNodeIsOut( aPnt._node, isNodeOut );
4480 isSatisfy = !isNodeOut;
4483 // Check the center point for volumes MantisBug 0020168
4486 myClassifiers[0].ShapeType() == TopAbs_SOLID )
4488 centerXYZ /= elem->NbNodes();
4491 for ( size_t i = 0; i < myWorkClassifiers.size() && !isSatisfy; ++i )
4492 isSatisfy = ! myWorkClassifiers[i]->IsOut( centerXYZ );
4494 for ( size_t i = 0; i < myClassifiers.size() && !isSatisfy; ++i )
4495 isSatisfy = ! myClassifiers[i].IsOut( centerXYZ );
4501 bool ElementsOnShape::IsSatisfy (const SMDS_MeshNode* node,
4502 TopoDS_Shape* okShape)
4507 if ( !myOctree && myClassifiers.size() > 5 )
4509 myWorkClassifiers.resize( myClassifiers.size() );
4510 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4511 myWorkClassifiers[ i ] = & myClassifiers[ i ];
4512 myOctree = new OctreeClassifier( myWorkClassifiers );
4515 bool isNodeOut = true;
4517 if ( okShape || !getNodeIsOut( node, isNodeOut ))
4519 SMESH_NodeXYZ aPnt = node;
4522 myWorkClassifiers.clear();
4523 myOctree->GetClassifiersAtPoint( aPnt, myWorkClassifiers );
4525 for ( size_t i = 0; i < myWorkClassifiers.size(); ++i )
4526 myWorkClassifiers[i]->SetChecked( false );
4528 for ( size_t i = 0; i < myWorkClassifiers.size(); ++i )
4529 if ( !myWorkClassifiers[i]->IsChecked() &&
4530 !myWorkClassifiers[i]->IsOut( aPnt ))
4534 *okShape = myWorkClassifiers[i]->Shape();
4540 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4541 if ( !myClassifiers[i].IsOut( aPnt ))
4545 *okShape = myWorkClassifiers[i]->Shape();
4549 setNodeIsOut( node, isNodeOut );
4555 void ElementsOnShape::Classifier::Init( const TopoDS_Shape& theShape,
4557 const Bnd_B3d* theBox )
4563 bool isShapeBox = false;
4564 switch ( myShape.ShapeType() )
4568 if (( isShapeBox = isBox( theShape )))
4570 myIsOutFun = & ElementsOnShape::Classifier::isOutOfBox;
4574 mySolidClfr = new BRepClass3d_SolidClassifier(theShape);
4575 myIsOutFun = & ElementsOnShape::Classifier::isOutOfSolid;
4581 Standard_Real u1,u2,v1,v2;
4582 Handle(Geom_Surface) surf = BRep_Tool::Surface( TopoDS::Face( theShape ));
4583 surf->Bounds( u1,u2,v1,v2 );
4584 myProjFace.Init(surf, u1,u2, v1,v2, myTol );
4585 myIsOutFun = & ElementsOnShape::Classifier::isOutOfFace;
4590 Standard_Real u1, u2;
4591 Handle(Geom_Curve) curve = BRep_Tool::Curve( TopoDS::Edge( theShape ), u1, u2);
4592 myProjEdge.Init(curve, u1, u2);
4593 myIsOutFun = & ElementsOnShape::Classifier::isOutOfEdge;
4598 myVertexXYZ = BRep_Tool::Pnt( TopoDS::Vertex( theShape ) );
4599 myIsOutFun = & ElementsOnShape::Classifier::isOutOfVertex;
4603 throw SALOME_Exception("Programmer error in usage of ElementsOnShape::Classifier");
4615 BRepBndLib::Add( myShape, box );
4617 myBox.Add( box.CornerMin() );
4618 myBox.Add( box.CornerMax() );
4619 gp_XYZ halfSize = 0.5 * ( box.CornerMax().XYZ() - box.CornerMin().XYZ() );
4620 for ( int iDim = 1; iDim <= 3; ++iDim )
4622 double x = halfSize.Coord( iDim );
4623 halfSize.SetCoord( iDim, x + Max( myTol, 1e-2 * x ));
4625 myBox.SetHSize( halfSize );
4630 ElementsOnShape::Classifier::~Classifier()
4632 delete mySolidClfr; mySolidClfr = 0;
4635 bool ElementsOnShape::Classifier::isOutOfSolid (const gp_Pnt& p)
4637 mySolidClfr->Perform( p, myTol );
4638 return ( mySolidClfr->State() != TopAbs_IN && mySolidClfr->State() != TopAbs_ON );
4641 bool ElementsOnShape::Classifier::isOutOfBox (const gp_Pnt& p)
4643 return myBox.IsOut( p.XYZ() );
4646 bool ElementsOnShape::Classifier::isOutOfFace (const gp_Pnt& p)
4648 myProjFace.Perform( p );
4649 if ( myProjFace.IsDone() && myProjFace.LowerDistance() <= myTol )
4651 // check relatively to the face
4653 myProjFace.LowerDistanceParameters(u, v);
4654 gp_Pnt2d aProjPnt (u, v);
4655 BRepClass_FaceClassifier aClsf ( TopoDS::Face( myShape ), aProjPnt, myTol );
4656 if ( aClsf.State() == TopAbs_IN || aClsf.State() == TopAbs_ON )
4662 bool ElementsOnShape::Classifier::isOutOfEdge (const gp_Pnt& p)
4664 myProjEdge.Perform( p );
4665 return ! ( myProjEdge.NbPoints() > 0 && myProjEdge.LowerDistance() <= myTol );
4668 bool ElementsOnShape::Classifier::isOutOfVertex(const gp_Pnt& p)
4670 return ( myVertexXYZ.Distance( p ) > myTol );
4673 bool ElementsOnShape::Classifier::isBox (const TopoDS_Shape& theShape)
4675 TopTools_IndexedMapOfShape vMap;
4676 TopExp::MapShapes( theShape, TopAbs_VERTEX, vMap );
4677 if ( vMap.Extent() != 8 )
4681 for ( int i = 1; i <= 8; ++i )
4682 myBox.Add( BRep_Tool::Pnt( TopoDS::Vertex( vMap( i ))).XYZ() );
4684 gp_XYZ pMin = myBox.CornerMin(), pMax = myBox.CornerMax();
4685 for ( int i = 1; i <= 8; ++i )
4687 gp_Pnt p = BRep_Tool::Pnt( TopoDS::Vertex( vMap( i )));
4688 for ( int iC = 1; iC <= 3; ++ iC )
4690 double d1 = Abs( pMin.Coord( iC ) - p.Coord( iC ));
4691 double d2 = Abs( pMax.Coord( iC ) - p.Coord( iC ));
4692 if ( Min( d1, d2 ) > myTol )
4696 myBox.Enlarge( myTol );
4701 OctreeClassifier::OctreeClassifier( const std::vector< ElementsOnShape::Classifier* >& classifiers )
4702 :SMESH_Octree( new SMESH_TreeLimit )
4704 myClassifiers = classifiers;
4709 OctreeClassifier::OctreeClassifier( const OctreeClassifier* otherTree,
4710 const std::vector< ElementsOnShape::Classifier >& clsOther,
4711 std::vector< ElementsOnShape::Classifier >& cls )
4712 :SMESH_Octree( new SMESH_TreeLimit )
4714 myBox = new Bnd_B3d( *otherTree->getBox() );
4716 if (( myIsLeaf = otherTree->isLeaf() ))
4718 myClassifiers.resize( otherTree->myClassifiers.size() );
4719 for ( size_t i = 0; i < otherTree->myClassifiers.size(); ++i )
4721 int ind = otherTree->myClassifiers[i] - & clsOther[0];
4722 myClassifiers[ i ] = & cls[ ind ];
4725 else if ( otherTree->myChildren )
4727 myChildren = new SMESH_Tree< Bnd_B3d, 8 > * [ 8 ];
4728 for ( int i = 0; i < nbChildren(); i++ )
4730 new OctreeClassifier( static_cast<const OctreeClassifier*>( otherTree->myChildren[i]),
4735 void ElementsOnShape::
4736 OctreeClassifier::GetClassifiersAtPoint( const gp_XYZ& point,
4737 std::vector< ElementsOnShape::Classifier* >& result )
4739 if ( getBox()->IsOut( point ))
4744 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4745 if ( !myClassifiers[i]->GetBndBox()->IsOut( point ))
4746 result.push_back( myClassifiers[i] );
4750 for (int i = 0; i < nbChildren(); i++)
4751 ((OctreeClassifier*) myChildren[i])->GetClassifiersAtPoint( point, result );
4755 void ElementsOnShape::OctreeClassifier::buildChildrenData()
4757 // distribute myClassifiers among myChildren
4759 const int childFlag[8] = { 0x0000001,
4767 int nbInChild[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
4769 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4771 for ( int j = 0; j < nbChildren(); j++ )
4773 if ( !myClassifiers[i]->GetBndBox()->IsOut( *myChildren[j]->getBox() ))
4775 myClassifiers[i]->SetFlag( childFlag[ j ]);
4781 for ( int j = 0; j < nbChildren(); j++ )
4783 OctreeClassifier* child = static_cast<OctreeClassifier*>( myChildren[ j ]);
4784 child->myClassifiers.resize( nbInChild[ j ]);
4785 for ( size_t i = 0; nbInChild[ j ] && i < myClassifiers.size(); ++i )
4787 if ( myClassifiers[ i ]->IsSetFlag( childFlag[ j ]))
4790 child->myClassifiers[ nbInChild[ j ]] = myClassifiers[ i ];
4791 myClassifiers[ i ]->UnsetFlag( childFlag[ j ]);
4795 SMESHUtils::FreeVector( myClassifiers );
4797 // define if a child isLeaf()
4798 for ( int i = 0; i < nbChildren(); i++ )
4800 OctreeClassifier* child = static_cast<OctreeClassifier*>( myChildren[ i ]);
4801 child->myIsLeaf = ( child->myClassifiers.size() <= 5 );
4805 Bnd_B3d* ElementsOnShape::OctreeClassifier::buildRootBox()
4807 Bnd_B3d* box = new Bnd_B3d;
4808 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4809 box->Add( *myClassifiers[i]->GetBndBox() );
4814 Class : BelongToGeom
4815 Description : Predicate for verifying whether entity belongs to
4816 specified geometrical support
4819 BelongToGeom::BelongToGeom()
4821 myType(SMDSAbs_NbElementTypes),
4822 myIsSubshape(false),
4823 myTolerance(Precision::Confusion())
4826 Predicate* BelongToGeom::clone() const
4828 BelongToGeom* cln = new BelongToGeom( *this );
4829 cln->myElementsOnShapePtr.reset( static_cast<ElementsOnShape*>( myElementsOnShapePtr->clone() ));
4833 void BelongToGeom::SetMesh( const SMDS_Mesh* theMesh )
4835 if ( myMeshDS != theMesh )
4837 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
4842 void BelongToGeom::SetGeom( const TopoDS_Shape& theShape )
4844 if ( myShape != theShape )
4851 static bool IsSubShape (const TopTools_IndexedMapOfShape& theMap,
4852 const TopoDS_Shape& theShape)
4854 if (theMap.Contains(theShape)) return true;
4856 if (theShape.ShapeType() == TopAbs_COMPOUND ||
4857 theShape.ShapeType() == TopAbs_COMPSOLID)
4859 TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
4860 for (; anIt.More(); anIt.Next())
4862 if (!IsSubShape(theMap, anIt.Value())) {
4872 void BelongToGeom::init()
4874 if ( !myMeshDS || myShape.IsNull() ) return;
4876 // is sub-shape of main shape?
4877 TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
4878 if (aMainShape.IsNull()) {
4879 myIsSubshape = false;
4882 TopTools_IndexedMapOfShape aMap;
4883 TopExp::MapShapes( aMainShape, aMap );
4884 myIsSubshape = IsSubShape( aMap, myShape );
4888 TopExp::MapShapes( myShape, aMap );
4889 mySubShapesIDs.Clear();
4890 for ( int i = 1; i <= aMap.Extent(); ++i )
4892 int subID = myMeshDS->ShapeToIndex( aMap( i ));
4894 mySubShapesIDs.Add( subID );
4899 //if (!myIsSubshape) // to be always ready to check an element not bound to geometry
4901 if ( !myElementsOnShapePtr )
4902 myElementsOnShapePtr.reset( new ElementsOnShape() );
4903 myElementsOnShapePtr->SetTolerance( myTolerance );
4904 myElementsOnShapePtr->SetAllNodes( true ); // "belong", while false means "lays on"
4905 myElementsOnShapePtr->SetMesh( myMeshDS );
4906 myElementsOnShapePtr->SetShape( myShape, myType );
4910 bool BelongToGeom::IsSatisfy (long theId)
4912 if (myMeshDS == 0 || myShape.IsNull())
4917 return myElementsOnShapePtr->IsSatisfy(theId);
4922 if (myType == SMDSAbs_Node)
4924 if ( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ))
4926 if ( aNode->getshapeId() < 1 )
4927 return myElementsOnShapePtr->IsSatisfy(theId);
4929 return mySubShapesIDs.Contains( aNode->getshapeId() );
4934 if ( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ))
4936 if ( anElem->GetType() == myType )
4938 if ( anElem->getshapeId() < 1 )
4939 return myElementsOnShapePtr->IsSatisfy(theId);
4941 return mySubShapesIDs.Contains( anElem->getshapeId() );
4949 void BelongToGeom::SetType (SMDSAbs_ElementType theType)
4951 if ( myType != theType )
4958 SMDSAbs_ElementType BelongToGeom::GetType() const
4963 TopoDS_Shape BelongToGeom::GetShape()
4968 const SMESHDS_Mesh* BelongToGeom::GetMeshDS() const
4973 void BelongToGeom::SetTolerance (double theTolerance)
4975 myTolerance = theTolerance;
4979 double BelongToGeom::GetTolerance()
4986 Description : Predicate for verifying whether entiy lying or partially lying on
4987 specified geometrical support
4990 LyingOnGeom::LyingOnGeom()
4992 myType(SMDSAbs_NbElementTypes),
4993 myIsSubshape(false),
4994 myTolerance(Precision::Confusion())
4997 Predicate* LyingOnGeom::clone() const
4999 LyingOnGeom* cln = new LyingOnGeom( *this );
5000 cln->myElementsOnShapePtr.reset( static_cast<ElementsOnShape*>( myElementsOnShapePtr->clone() ));
5004 void LyingOnGeom::SetMesh( const SMDS_Mesh* theMesh )
5006 if ( myMeshDS != theMesh )
5008 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
5013 void LyingOnGeom::SetGeom( const TopoDS_Shape& theShape )
5015 if ( myShape != theShape )
5022 void LyingOnGeom::init()
5024 if (!myMeshDS || myShape.IsNull()) return;
5026 // is sub-shape of main shape?
5027 TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
5028 if (aMainShape.IsNull()) {
5029 myIsSubshape = false;
5032 myIsSubshape = myMeshDS->IsGroupOfSubShapes( myShape );
5037 TopTools_IndexedMapOfShape shapes;
5038 TopExp::MapShapes( myShape, shapes );
5039 mySubShapesIDs.Clear();
5040 for ( int i = 1; i <= shapes.Extent(); ++i )
5042 int subID = myMeshDS->ShapeToIndex( shapes( i ));
5044 mySubShapesIDs.Add( subID );
5047 // else // to be always ready to check an element not bound to geometry
5049 if ( !myElementsOnShapePtr )
5050 myElementsOnShapePtr.reset( new ElementsOnShape() );
5051 myElementsOnShapePtr->SetTolerance( myTolerance );
5052 myElementsOnShapePtr->SetAllNodes( false ); // lays on, while true means "belong"
5053 myElementsOnShapePtr->SetMesh( myMeshDS );
5054 myElementsOnShapePtr->SetShape( myShape, myType );
5058 bool LyingOnGeom::IsSatisfy( long theId )
5060 if ( myMeshDS == 0 || myShape.IsNull() )
5065 return myElementsOnShapePtr->IsSatisfy(theId);
5070 const SMDS_MeshElement* elem =
5071 ( myType == SMDSAbs_Node ) ? myMeshDS->FindNode( theId ) : myMeshDS->FindElement( theId );
5073 if ( mySubShapesIDs.Contains( elem->getshapeId() ))
5076 if ( elem->GetType() != SMDSAbs_Node && elem->GetType() == myType )
5078 SMDS_ElemIteratorPtr nodeItr = elem->nodesIterator();
5079 while ( nodeItr->more() )
5081 const SMDS_MeshElement* aNode = nodeItr->next();
5082 if ( mySubShapesIDs.Contains( aNode->getshapeId() ))
5090 void LyingOnGeom::SetType( SMDSAbs_ElementType theType )
5092 if ( myType != theType )
5099 SMDSAbs_ElementType LyingOnGeom::GetType() const
5104 TopoDS_Shape LyingOnGeom::GetShape()
5109 const SMESHDS_Mesh* LyingOnGeom::GetMeshDS() const
5114 void LyingOnGeom::SetTolerance (double theTolerance)
5116 myTolerance = theTolerance;
5120 double LyingOnGeom::GetTolerance()
5125 TSequenceOfXYZ::TSequenceOfXYZ(): myElem(0)
5128 TSequenceOfXYZ::TSequenceOfXYZ(size_type n) : myArray(n), myElem(0)
5131 TSequenceOfXYZ::TSequenceOfXYZ(size_type n, const gp_XYZ& t) : myArray(n,t), myElem(0)
5134 TSequenceOfXYZ::TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ) : myArray(theSequenceOfXYZ.myArray), myElem(theSequenceOfXYZ.myElem)
5137 template <class InputIterator>
5138 TSequenceOfXYZ::TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd): myArray(theBegin,theEnd), myElem(0)
5141 TSequenceOfXYZ::~TSequenceOfXYZ()
5144 TSequenceOfXYZ& TSequenceOfXYZ::operator=(const TSequenceOfXYZ& theSequenceOfXYZ)
5146 myArray = theSequenceOfXYZ.myArray;
5147 myElem = theSequenceOfXYZ.myElem;
5151 gp_XYZ& TSequenceOfXYZ::operator()(size_type n)
5153 return myArray[n-1];
5156 const gp_XYZ& TSequenceOfXYZ::operator()(size_type n) const
5158 return myArray[n-1];
5161 void TSequenceOfXYZ::clear()
5166 void TSequenceOfXYZ::reserve(size_type n)
5171 void TSequenceOfXYZ::push_back(const gp_XYZ& v)
5173 myArray.push_back(v);
5176 TSequenceOfXYZ::size_type TSequenceOfXYZ::size() const
5178 return myArray.size();
5181 SMDSAbs_EntityType TSequenceOfXYZ::getElementEntity() const
5183 return myElem ? myElem->GetEntityType() : SMDSEntity_Last;
5186 TMeshModifTracer::TMeshModifTracer():
5187 myMeshModifTime(0), myMesh(0)
5190 void TMeshModifTracer::SetMesh( const SMDS_Mesh* theMesh )
5192 if ( theMesh != myMesh )
5193 myMeshModifTime = 0;
5196 bool TMeshModifTracer::IsMeshModified()
5198 bool modified = false;
5201 modified = ( myMeshModifTime != myMesh->GetMTime() );
5202 myMeshModifTime = myMesh->GetMTime();