1 // Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "SMESH_ControlsDef.hxx"
25 #include "SMDS_BallElement.hxx"
26 #include "SMDS_FacePosition.hxx"
27 #include "SMDS_Iterator.hxx"
28 #include "SMDS_Mesh.hxx"
29 #include "SMDS_MeshElement.hxx"
30 #include "SMDS_MeshNode.hxx"
31 #include "SMDS_VolumeTool.hxx"
32 #include "SMESHDS_GroupBase.hxx"
33 #include "SMESHDS_GroupOnFilter.hxx"
34 #include "SMESHDS_Mesh.hxx"
35 #include "SMESH_MeshAlgos.hxx"
36 #include "SMESH_OctreeNode.hxx"
38 #include <Basics_Utils.hxx>
40 #include <BRepAdaptor_Surface.hxx>
41 #include <BRepBndLib.hxx>
42 #include <BRepBuilderAPI_Copy.hxx>
43 #include <BRepClass3d_SolidClassifier.hxx>
44 #include <BRepClass_FaceClassifier.hxx>
45 #include <BRep_Tool.hxx>
46 #include <GeomLib_IsPlanarSurface.hxx>
47 #include <Geom_CylindricalSurface.hxx>
48 #include <Geom_Plane.hxx>
49 #include <Geom_Surface.hxx>
50 #include <NCollection_Map.hxx>
51 #include <Precision.hxx>
52 #include <ShapeAnalysis_Surface.hxx>
53 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
54 #include <TColStd_MapOfInteger.hxx>
55 #include <TColStd_SequenceOfAsciiString.hxx>
56 #include <TColgp_Array1OfXYZ.hxx>
60 #include <TopoDS_Edge.hxx>
61 #include <TopoDS_Face.hxx>
62 #include <TopoDS_Iterator.hxx>
63 #include <TopoDS_Shape.hxx>
64 #include <TopoDS_Vertex.hxx>
66 #include <gp_Cylinder.hxx>
73 #include <vtkMeshQuality.h>
84 const double theEps = 1e-100;
85 const double theInf = 1e+100;
87 inline gp_XYZ gpXYZ(const SMDS_MeshNode* aNode )
89 return gp_XYZ(aNode->X(), aNode->Y(), aNode->Z() );
92 inline double getAngle( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
94 gp_Vec v1( P1 - P2 ), v2( P3 - P2 );
96 return v1.Magnitude() < gp::Resolution() ||
97 v2.Magnitude() < gp::Resolution() ? 0 : v1.Angle( v2 );
100 inline double getCos2( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
102 gp_Vec v1( P1 - P2 ), v2( P3 - P2 );
103 double dot = v1 * v2, len1 = v1.SquareMagnitude(), len2 = v2.SquareMagnitude();
105 return ( dot < 0 || len1 < gp::Resolution() || len2 < gp::Resolution() ? -1 :
106 dot * dot / len1 / len2 );
109 inline double getArea( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
111 gp_Vec aVec1( P2 - P1 );
112 gp_Vec aVec2( P3 - P1 );
113 return ( aVec1 ^ aVec2 ).Magnitude() * 0.5;
116 inline double getArea( const gp_Pnt& P1, const gp_Pnt& P2, const gp_Pnt& P3 )
118 return getArea( P1.XYZ(), P2.XYZ(), P3.XYZ() );
123 inline double getDistance( const gp_XYZ& P1, const gp_XYZ& P2 )
125 double aDist = gp_Pnt( P1 ).Distance( gp_Pnt( P2 ) );
129 int getNbMultiConnection( const SMDS_Mesh* theMesh, const int theId )
134 const SMDS_MeshElement* anEdge = theMesh->FindElement( theId );
135 if ( anEdge == 0 || anEdge->GetType() != SMDSAbs_Edge/* || anEdge->NbNodes() != 2 */)
138 // for each pair of nodes in anEdge (there are 2 pairs in a quadratic edge)
139 // count elements containing both nodes of the pair.
140 // Note that there may be such cases for a quadratic edge (a horizontal line):
145 // +-----+------+ +-----+------+
148 // result should be 2 in both cases
150 int aResult0 = 0, aResult1 = 0;
151 // last node, it is a medium one in a quadratic edge
152 const SMDS_MeshNode* aLastNode = anEdge->GetNode( anEdge->NbNodes() - 1 );
153 const SMDS_MeshNode* aNode0 = anEdge->GetNode( 0 );
154 const SMDS_MeshNode* aNode1 = anEdge->GetNode( 1 );
155 if ( aNode1 == aLastNode ) aNode1 = 0;
157 SMDS_ElemIteratorPtr anElemIter = aLastNode->GetInverseElementIterator();
158 while( anElemIter->more() ) {
159 const SMDS_MeshElement* anElem = anElemIter->next();
160 if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) {
161 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
162 while ( anIter->more() ) {
163 if ( const SMDS_MeshElement* anElemNode = anIter->next() ) {
164 if ( anElemNode == aNode0 ) {
166 if ( !aNode1 ) break; // not a quadratic edge
168 else if ( anElemNode == aNode1 )
174 int aResult = std::max ( aResult0, aResult1 );
179 gp_XYZ getNormale( const SMDS_MeshFace* theFace, bool* ok=0 )
181 int aNbNode = theFace->NbNodes();
183 gp_XYZ q1 = gpXYZ( theFace->GetNode(1)) - gpXYZ( theFace->GetNode(0));
184 gp_XYZ q2 = gpXYZ( theFace->GetNode(2)) - gpXYZ( theFace->GetNode(0));
187 gp_XYZ q3 = gpXYZ( theFace->GetNode(3)) - gpXYZ( theFace->GetNode(0));
190 double len = n.Modulus();
191 bool zeroLen = ( len <= std::numeric_limits<double>::min());
195 if (ok) *ok = !zeroLen;
203 using namespace SMESH::Controls;
209 //================================================================================
211 Class : NumericalFunctor
212 Description : Base class for numerical functors
214 //================================================================================
216 NumericalFunctor::NumericalFunctor():
222 void NumericalFunctor::SetMesh( const SMDS_Mesh* theMesh )
227 bool NumericalFunctor::GetPoints(const int theId,
228 TSequenceOfXYZ& theRes ) const
235 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
236 if ( !IsApplicable( anElem ))
239 return GetPoints( anElem, theRes );
242 bool NumericalFunctor::GetPoints(const SMDS_MeshElement* anElem,
243 TSequenceOfXYZ& theRes )
250 theRes.reserve( anElem->NbNodes() );
251 theRes.setElement( anElem );
253 // Get nodes of the element
254 SMDS_NodeIteratorPtr anIter= anElem->interlacedNodesIterator();
257 while( anIter->more() ) {
258 if ( p.Set( anIter->next() ))
259 theRes.push_back( p );
266 long NumericalFunctor::GetPrecision() const
271 void NumericalFunctor::SetPrecision( const long thePrecision )
273 myPrecision = thePrecision;
274 myPrecisionValue = pow( 10., (double)( myPrecision ) );
277 double NumericalFunctor::GetValue( long theId )
281 myCurrElement = myMesh->FindElement( theId );
284 if ( GetPoints( theId, P )) // elem type is checked here
285 aVal = Round( GetValue( P ));
290 double NumericalFunctor::Round( const double & aVal )
292 return ( myPrecision >= 0 ) ? floor( aVal * myPrecisionValue + 0.5 ) / myPrecisionValue : aVal;
295 //================================================================================
297 * \brief Return true if a value can be computed for a given element.
298 * Some NumericalFunctor's are meaningful for elements of a certain
301 //================================================================================
303 bool NumericalFunctor::IsApplicable( const SMDS_MeshElement* element ) const
305 return element && element->GetType() == this->GetType();
308 bool NumericalFunctor::IsApplicable( long theElementId ) const
310 return IsApplicable( myMesh->FindElement( theElementId ));
313 //================================================================================
315 * \brief Return histogram of functor values
316 * \param nbIntervals - number of intervals
317 * \param nbEvents - number of mesh elements having values within i-th interval
318 * \param funValues - boundaries of intervals
319 * \param elements - elements to check vulue of; empty list means "of all"
320 * \param minmax - boundaries of diapason of values to divide into intervals
322 //================================================================================
324 void NumericalFunctor::GetHistogram(int nbIntervals,
325 std::vector<int>& nbEvents,
326 std::vector<double>& funValues,
327 const std::vector<int>& elements,
328 const double* minmax,
329 const bool isLogarithmic)
331 if ( nbIntervals < 1 ||
333 !myMesh->GetMeshInfo().NbElements( GetType() ))
335 nbEvents.resize( nbIntervals, 0 );
336 funValues.resize( nbIntervals+1 );
338 // get all values sorted
339 std::multiset< double > values;
340 if ( elements.empty() )
342 SMDS_ElemIteratorPtr elemIt = myMesh->elementsIterator( GetType() );
343 while ( elemIt->more() )
344 values.insert( GetValue( elemIt->next()->GetID() ));
348 std::vector<int>::const_iterator id = elements.begin();
349 for ( ; id != elements.end(); ++id )
350 values.insert( GetValue( *id ));
355 funValues[0] = minmax[0];
356 funValues[nbIntervals] = minmax[1];
360 funValues[0] = *values.begin();
361 funValues[nbIntervals] = *values.rbegin();
363 // case nbIntervals == 1
364 if ( nbIntervals == 1 )
366 nbEvents[0] = values.size();
370 if (funValues.front() == funValues.back())
372 nbEvents.resize( 1 );
373 nbEvents[0] = values.size();
374 funValues[1] = funValues.back();
375 funValues.resize( 2 );
378 std::multiset< double >::iterator min = values.begin(), max;
379 for ( int i = 0; i < nbIntervals; ++i )
381 // find end value of i-th interval
382 double r = (i+1) / double(nbIntervals);
383 if (isLogarithmic && funValues.front() > 1e-07 && funValues.back() > 1e-07) {
384 double logmin = log10(funValues.front());
385 double lval = logmin + r * (log10(funValues.back()) - logmin);
386 funValues[i+1] = pow(10.0, lval);
389 funValues[i+1] = funValues.front() * (1-r) + funValues.back() * r;
392 // count values in the i-th interval if there are any
393 if ( min != values.end() && *min <= funValues[i+1] )
395 // find the first value out of the interval
396 max = values.upper_bound( funValues[i+1] ); // max is greater than funValues[i+1], or end()
397 nbEvents[i] = std::distance( min, max );
401 // add values larger than minmax[1]
402 nbEvents.back() += std::distance( min, values.end() );
405 //=======================================================================
408 Description : Functor calculating volume of a 3D element
410 //================================================================================
412 double Volume::GetValue( long theElementId )
414 if ( theElementId && myMesh ) {
415 SMDS_VolumeTool aVolumeTool;
416 if ( aVolumeTool.Set( myMesh->FindElement( theElementId )))
417 return aVolumeTool.GetSize();
422 double Volume::GetBadRate( double Value, int /*nbNodes*/ ) const
427 SMDSAbs_ElementType Volume::GetType() const
429 return SMDSAbs_Volume;
432 //=======================================================================
434 Class : MaxElementLength2D
435 Description : Functor calculating maximum length of 2D element
437 //================================================================================
439 double MaxElementLength2D::GetValue( const TSequenceOfXYZ& P )
445 if( len == 3 ) { // triangles
446 double L1 = getDistance(P( 1 ),P( 2 ));
447 double L2 = getDistance(P( 2 ),P( 3 ));
448 double L3 = getDistance(P( 3 ),P( 1 ));
449 aVal = Max(L1,Max(L2,L3));
451 else if( len == 4 ) { // quadrangles
452 double L1 = getDistance(P( 1 ),P( 2 ));
453 double L2 = getDistance(P( 2 ),P( 3 ));
454 double L3 = getDistance(P( 3 ),P( 4 ));
455 double L4 = getDistance(P( 4 ),P( 1 ));
456 double D1 = getDistance(P( 1 ),P( 3 ));
457 double D2 = getDistance(P( 2 ),P( 4 ));
458 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(D1,D2));
460 else if( len == 6 ) { // quadratic triangles
461 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
462 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
463 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 1 ));
464 aVal = Max(L1,Max(L2,L3));
466 else if( len == 8 || len == 9 ) { // quadratic quadrangles
467 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
468 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
469 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 7 ));
470 double L4 = getDistance(P( 7 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
471 double D1 = getDistance(P( 1 ),P( 5 ));
472 double D2 = getDistance(P( 3 ),P( 7 ));
473 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(D1,D2));
475 // Diagonals are undefined for concave polygons
476 // else if ( P.getElementEntity() == SMDSEntity_Quad_Polygon && P.size() > 2 ) // quad polygon
479 // aVal = getDistance( P( 1 ), P( P.size() )) + getDistance( P( P.size() ), P( P.size()-1 ));
480 // for ( size_t i = 1; i < P.size()-1; i += 2 )
482 // double L = getDistance( P( i ), P( i+1 )) + getDistance( P( i+1 ), P( i+2 ));
483 // aVal = Max( aVal, L );
486 // for ( int i = P.size()-5; i > 0; i -= 2 )
487 // for ( int j = i + 4; j < P.size() + i - 2; i += 2 )
489 // double D = getDistance( P( i ), P( j ));
490 // aVal = Max( aVal, D );
497 if( myPrecision >= 0 )
499 double prec = pow( 10., (double)myPrecision );
500 aVal = floor( aVal * prec + 0.5 ) / prec;
505 double MaxElementLength2D::GetValue( long theElementId )
508 return GetPoints( theElementId, P ) ? GetValue(P) : 0.0;
511 double MaxElementLength2D::GetBadRate( double Value, int /*nbNodes*/ ) const
516 SMDSAbs_ElementType MaxElementLength2D::GetType() const
521 //=======================================================================
523 Class : MaxElementLength3D
524 Description : Functor calculating maximum length of 3D element
526 //================================================================================
528 double MaxElementLength3D::GetValue( long theElementId )
531 if( GetPoints( theElementId, P ) ) {
533 const SMDS_MeshElement* aElem = myMesh->FindElement( theElementId );
534 SMDSAbs_EntityType aType = aElem->GetEntityType();
537 case SMDSEntity_Tetra: { // tetras
538 double L1 = getDistance(P( 1 ),P( 2 ));
539 double L2 = getDistance(P( 2 ),P( 3 ));
540 double L3 = getDistance(P( 3 ),P( 1 ));
541 double L4 = getDistance(P( 1 ),P( 4 ));
542 double L5 = getDistance(P( 2 ),P( 4 ));
543 double L6 = getDistance(P( 3 ),P( 4 ));
544 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
547 case SMDSEntity_Pyramid: { // pyramids
548 double L1 = getDistance(P( 1 ),P( 2 ));
549 double L2 = getDistance(P( 2 ),P( 3 ));
550 double L3 = getDistance(P( 3 ),P( 4 ));
551 double L4 = getDistance(P( 4 ),P( 1 ));
552 double L5 = getDistance(P( 1 ),P( 5 ));
553 double L6 = getDistance(P( 2 ),P( 5 ));
554 double L7 = getDistance(P( 3 ),P( 5 ));
555 double L8 = getDistance(P( 4 ),P( 5 ));
556 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
557 aVal = Max(aVal,Max(L7,L8));
560 case SMDSEntity_Penta: { // pentas
561 double L1 = getDistance(P( 1 ),P( 2 ));
562 double L2 = getDistance(P( 2 ),P( 3 ));
563 double L3 = getDistance(P( 3 ),P( 1 ));
564 double L4 = getDistance(P( 4 ),P( 5 ));
565 double L5 = getDistance(P( 5 ),P( 6 ));
566 double L6 = getDistance(P( 6 ),P( 4 ));
567 double L7 = getDistance(P( 1 ),P( 4 ));
568 double L8 = getDistance(P( 2 ),P( 5 ));
569 double L9 = getDistance(P( 3 ),P( 6 ));
570 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
571 aVal = Max(aVal,Max(Max(L7,L8),L9));
574 case SMDSEntity_Hexa: { // hexas
575 double L1 = getDistance(P( 1 ),P( 2 ));
576 double L2 = getDistance(P( 2 ),P( 3 ));
577 double L3 = getDistance(P( 3 ),P( 4 ));
578 double L4 = getDistance(P( 4 ),P( 1 ));
579 double L5 = getDistance(P( 5 ),P( 6 ));
580 double L6 = getDistance(P( 6 ),P( 7 ));
581 double L7 = getDistance(P( 7 ),P( 8 ));
582 double L8 = getDistance(P( 8 ),P( 5 ));
583 double L9 = getDistance(P( 1 ),P( 5 ));
584 double L10= getDistance(P( 2 ),P( 6 ));
585 double L11= getDistance(P( 3 ),P( 7 ));
586 double L12= getDistance(P( 4 ),P( 8 ));
587 double D1 = getDistance(P( 1 ),P( 7 ));
588 double D2 = getDistance(P( 2 ),P( 8 ));
589 double D3 = getDistance(P( 3 ),P( 5 ));
590 double D4 = getDistance(P( 4 ),P( 6 ));
591 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
592 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
593 aVal = Max(aVal,Max(L11,L12));
594 aVal = Max(aVal,Max(Max(D1,D2),Max(D3,D4)));
597 case SMDSEntity_Hexagonal_Prism: { // hexagonal prism
598 for ( int i1 = 1; i1 < 12; ++i1 )
599 for ( int i2 = i1+1; i1 <= 12; ++i1 )
600 aVal = Max( aVal, getDistance(P( i1 ),P( i2 )));
603 case SMDSEntity_Quad_Tetra: { // quadratic tetras
604 double L1 = getDistance(P( 1 ),P( 5 )) + getDistance(P( 5 ),P( 2 ));
605 double L2 = getDistance(P( 2 ),P( 6 )) + getDistance(P( 6 ),P( 3 ));
606 double L3 = getDistance(P( 3 ),P( 7 )) + getDistance(P( 7 ),P( 1 ));
607 double L4 = getDistance(P( 1 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
608 double L5 = getDistance(P( 2 ),P( 9 )) + getDistance(P( 9 ),P( 4 ));
609 double L6 = getDistance(P( 3 ),P( 10 )) + getDistance(P( 10 ),P( 4 ));
610 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
613 case SMDSEntity_Quad_Pyramid: { // quadratic pyramids
614 double L1 = getDistance(P( 1 ),P( 6 )) + getDistance(P( 6 ),P( 2 ));
615 double L2 = getDistance(P( 2 ),P( 7 )) + getDistance(P( 7 ),P( 3 ));
616 double L3 = getDistance(P( 3 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
617 double L4 = getDistance(P( 4 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
618 double L5 = getDistance(P( 1 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
619 double L6 = getDistance(P( 2 ),P( 11 )) + getDistance(P( 11 ),P( 5 ));
620 double L7 = getDistance(P( 3 ),P( 12 )) + getDistance(P( 12 ),P( 5 ));
621 double L8 = getDistance(P( 4 ),P( 13 )) + getDistance(P( 13 ),P( 5 ));
622 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
623 aVal = Max(aVal,Max(L7,L8));
626 case SMDSEntity_Quad_Penta:
627 case SMDSEntity_BiQuad_Penta: { // quadratic pentas
628 double L1 = getDistance(P( 1 ),P( 7 )) + getDistance(P( 7 ),P( 2 ));
629 double L2 = getDistance(P( 2 ),P( 8 )) + getDistance(P( 8 ),P( 3 ));
630 double L3 = getDistance(P( 3 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
631 double L4 = getDistance(P( 4 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
632 double L5 = getDistance(P( 5 ),P( 11 )) + getDistance(P( 11 ),P( 6 ));
633 double L6 = getDistance(P( 6 ),P( 12 )) + getDistance(P( 12 ),P( 4 ));
634 double L7 = getDistance(P( 1 ),P( 13 )) + getDistance(P( 13 ),P( 4 ));
635 double L8 = getDistance(P( 2 ),P( 14 )) + getDistance(P( 14 ),P( 5 ));
636 double L9 = getDistance(P( 3 ),P( 15 )) + getDistance(P( 15 ),P( 6 ));
637 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
638 aVal = Max(aVal,Max(Max(L7,L8),L9));
641 case SMDSEntity_Quad_Hexa:
642 case SMDSEntity_TriQuad_Hexa: { // quadratic hexas
643 double L1 = getDistance(P( 1 ),P( 9 )) + getDistance(P( 9 ),P( 2 ));
644 double L2 = getDistance(P( 2 ),P( 10 )) + getDistance(P( 10 ),P( 3 ));
645 double L3 = getDistance(P( 3 ),P( 11 )) + getDistance(P( 11 ),P( 4 ));
646 double L4 = getDistance(P( 4 ),P( 12 )) + getDistance(P( 12 ),P( 1 ));
647 double L5 = getDistance(P( 5 ),P( 13 )) + getDistance(P( 13 ),P( 6 ));
648 double L6 = getDistance(P( 6 ),P( 14 )) + getDistance(P( 14 ),P( 7 ));
649 double L7 = getDistance(P( 7 ),P( 15 )) + getDistance(P( 15 ),P( 8 ));
650 double L8 = getDistance(P( 8 ),P( 16 )) + getDistance(P( 16 ),P( 5 ));
651 double L9 = getDistance(P( 1 ),P( 17 )) + getDistance(P( 17 ),P( 5 ));
652 double L10= getDistance(P( 2 ),P( 18 )) + getDistance(P( 18 ),P( 6 ));
653 double L11= getDistance(P( 3 ),P( 19 )) + getDistance(P( 19 ),P( 7 ));
654 double L12= getDistance(P( 4 ),P( 20 )) + getDistance(P( 20 ),P( 8 ));
655 double D1 = getDistance(P( 1 ),P( 7 ));
656 double D2 = getDistance(P( 2 ),P( 8 ));
657 double D3 = getDistance(P( 3 ),P( 5 ));
658 double D4 = getDistance(P( 4 ),P( 6 ));
659 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
660 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
661 aVal = Max(aVal,Max(L11,L12));
662 aVal = Max(aVal,Max(Max(D1,D2),Max(D3,D4)));
665 case SMDSEntity_Quad_Polyhedra:
666 case SMDSEntity_Polyhedra: { // polys
667 // get the maximum distance between all pairs of nodes
668 for( int i = 1; i <= len; i++ ) {
669 for( int j = 1; j <= len; j++ ) {
670 if( j > i ) { // optimization of the loop
671 double D = getDistance( P(i), P(j) );
672 aVal = Max( aVal, D );
678 case SMDSEntity_Node:
680 case SMDSEntity_Edge:
681 case SMDSEntity_Quad_Edge:
682 case SMDSEntity_Triangle:
683 case SMDSEntity_Quad_Triangle:
684 case SMDSEntity_BiQuad_Triangle:
685 case SMDSEntity_Quadrangle:
686 case SMDSEntity_Quad_Quadrangle:
687 case SMDSEntity_BiQuad_Quadrangle:
688 case SMDSEntity_Polygon:
689 case SMDSEntity_Quad_Polygon:
690 case SMDSEntity_Ball:
691 case SMDSEntity_Last: return 0;
692 } // switch ( aType )
694 if( myPrecision >= 0 )
696 double prec = pow( 10., (double)myPrecision );
697 aVal = floor( aVal * prec + 0.5 ) / prec;
704 double MaxElementLength3D::GetBadRate( double Value, int /*nbNodes*/ ) const
709 SMDSAbs_ElementType MaxElementLength3D::GetType() const
711 return SMDSAbs_Volume;
714 //=======================================================================
717 Description : Functor for calculation of minimum angle
719 //================================================================================
721 double MinimumAngle::GetValue( const TSequenceOfXYZ& P )
728 aMaxCos2 = getCos2( P( P.size() ), P( 1 ), P( 2 ));
729 aMaxCos2 = Max( aMaxCos2, getCos2( P( P.size()-1 ), P( P.size() ), P( 1 )));
731 for ( size_t i = 2; i < P.size(); i++ )
733 double A0 = getCos2( P( i-1 ), P( i ), P( i+1 ) );
734 aMaxCos2 = Max( aMaxCos2, A0 );
737 return 0; // all nodes coincide
739 double cos = sqrt( aMaxCos2 );
740 if ( cos >= 1 ) return 0;
741 return acos( cos ) * 180.0 / M_PI;
744 double MinimumAngle::GetBadRate( double Value, int nbNodes ) const
746 //const double aBestAngle = PI / nbNodes;
747 const double aBestAngle = 180.0 - ( 360.0 / double(nbNodes) );
748 return ( fabs( aBestAngle - Value ));
751 SMDSAbs_ElementType MinimumAngle::GetType() const
757 //================================================================================
760 Description : Functor for calculating aspect ratio
762 //================================================================================
764 double AspectRatio::GetValue( long theId )
767 myCurrElement = myMesh->FindElement( theId );
769 if ( GetPoints( myCurrElement, P ))
770 aVal = Round( GetValue( P ));
774 double AspectRatio::GetValue( const TSequenceOfXYZ& P )
776 // According to "Mesh quality control" by Nadir Bouhamau referring to
777 // Pascal Jean Frey and Paul-Louis George. Maillages, applications aux elements finis.
778 // Hermes Science publications, Paris 1999 ISBN 2-7462-0024-4
781 int nbNodes = P.size();
786 // Compute aspect ratio
788 if ( nbNodes == 3 ) {
789 // Compute lengths of the sides
790 double aLen1 = getDistance( P( 1 ), P( 2 ));
791 double aLen2 = getDistance( P( 2 ), P( 3 ));
792 double aLen3 = getDistance( P( 3 ), P( 1 ));
793 // Q = alfa * h * p / S, where
795 // alfa = sqrt( 3 ) / 6
796 // h - length of the longest edge
797 // p - half perimeter
798 // S - triangle surface
799 const double alfa = sqrt( 3. ) / 6.;
800 double maxLen = Max( aLen1, Max( aLen2, aLen3 ));
801 double half_perimeter = ( aLen1 + aLen2 + aLen3 ) / 2.;
802 double anArea = getArea( P( 1 ), P( 2 ), P( 3 ));
803 if ( anArea <= theEps )
805 return alfa * maxLen * half_perimeter / anArea;
807 else if ( nbNodes == 6 ) { // quadratic triangles
808 // Compute lengths of the sides
809 double aLen1 = getDistance( P( 1 ), P( 3 ));
810 double aLen2 = getDistance( P( 3 ), P( 5 ));
811 double aLen3 = getDistance( P( 5 ), P( 1 ));
812 // algo same as for the linear triangle
813 const double alfa = sqrt( 3. ) / 6.;
814 double maxLen = Max( aLen1, Max( aLen2, aLen3 ));
815 double half_perimeter = ( aLen1 + aLen2 + aLen3 ) / 2.;
816 double anArea = getArea( P( 1 ), P( 3 ), P( 5 ));
817 if ( anArea <= theEps )
819 return alfa * maxLen * half_perimeter / anArea;
821 else if( nbNodes == 4 ) { // quadrangle
822 // Compute lengths of the sides
824 aLen[0] = getDistance( P(1), P(2) );
825 aLen[1] = getDistance( P(2), P(3) );
826 aLen[2] = getDistance( P(3), P(4) );
827 aLen[3] = getDistance( P(4), P(1) );
828 // Compute lengths of the diagonals
830 aDia[0] = getDistance( P(1), P(3) );
831 aDia[1] = getDistance( P(2), P(4) );
832 // Compute areas of all triangles which can be built
833 // taking three nodes of the quadrangle
835 anArea[0] = getArea( P(1), P(2), P(3) );
836 anArea[1] = getArea( P(1), P(2), P(4) );
837 anArea[2] = getArea( P(1), P(3), P(4) );
838 anArea[3] = getArea( P(2), P(3), P(4) );
839 // Q = alpha * L * C1 / C2, where
841 // alpha = sqrt( 1/32 )
842 // L = max( L1, L2, L3, L4, D1, D2 )
843 // C1 = sqrt( L1^2 + L1^2 + L1^2 + L1^2 )
844 // C2 = min( S1, S2, S3, S4 )
845 // Li - lengths of the edges
846 // Di - lengths of the diagonals
847 // Si - areas of the triangles
848 const double alpha = sqrt( 1 / 32. );
849 double L = Max( aLen[ 0 ],
853 Max( aDia[ 0 ], aDia[ 1 ] ) ) ) ) );
854 double C1 = sqrt( aLen[0] * aLen[0] +
858 double C2 = Min( anArea[ 0 ],
860 Min( anArea[ 2 ], anArea[ 3 ] ) ) );
863 return alpha * L * C1 / C2;
865 else if( nbNodes == 8 || nbNodes == 9 ) { // nbNodes==8 - quadratic quadrangle
866 // Compute lengths of the sides
868 aLen[0] = getDistance( P(1), P(3) );
869 aLen[1] = getDistance( P(3), P(5) );
870 aLen[2] = getDistance( P(5), P(7) );
871 aLen[3] = getDistance( P(7), P(1) );
872 // Compute lengths of the diagonals
874 aDia[0] = getDistance( P(1), P(5) );
875 aDia[1] = getDistance( P(3), P(7) );
876 // Compute areas of all triangles which can be built
877 // taking three nodes of the quadrangle
879 anArea[0] = getArea( P(1), P(3), P(5) );
880 anArea[1] = getArea( P(1), P(3), P(7) );
881 anArea[2] = getArea( P(1), P(5), P(7) );
882 anArea[3] = getArea( P(3), P(5), P(7) );
883 // Q = alpha * L * C1 / C2, where
885 // alpha = sqrt( 1/32 )
886 // L = max( L1, L2, L3, L4, D1, D2 )
887 // C1 = sqrt( L1^2 + L1^2 + L1^2 + L1^2 )
888 // C2 = min( S1, S2, S3, S4 )
889 // Li - lengths of the edges
890 // Di - lengths of the diagonals
891 // Si - areas of the triangles
892 const double alpha = sqrt( 1 / 32. );
893 double L = Max( aLen[ 0 ],
897 Max( aDia[ 0 ], aDia[ 1 ] ) ) ) ) );
898 double C1 = sqrt( aLen[0] * aLen[0] +
902 double C2 = Min( anArea[ 0 ],
904 Min( anArea[ 2 ], anArea[ 3 ] ) ) );
907 return alpha * L * C1 / C2;
912 bool AspectRatio::IsApplicable( const SMDS_MeshElement* element ) const
914 return ( NumericalFunctor::IsApplicable( element ) && !element->IsPoly() );
917 double AspectRatio::GetBadRate( double Value, int /*nbNodes*/ ) const
919 // the aspect ratio is in the range [1.0,infinity]
920 // < 1.0 = very bad, zero area
923 return ( Value < 0.9 ) ? 1000 : Value / 1000.;
926 SMDSAbs_ElementType AspectRatio::GetType() const
932 //================================================================================
934 Class : AspectRatio3D
935 Description : Functor for calculating aspect ratio
937 //================================================================================
941 inline double getHalfPerimeter(double theTria[3]){
942 return (theTria[0] + theTria[1] + theTria[2])/2.0;
945 inline double getArea(double theHalfPerim, double theTria[3]){
946 return sqrt(theHalfPerim*
947 (theHalfPerim-theTria[0])*
948 (theHalfPerim-theTria[1])*
949 (theHalfPerim-theTria[2]));
952 inline double getVolume(double theLen[6]){
953 double a2 = theLen[0]*theLen[0];
954 double b2 = theLen[1]*theLen[1];
955 double c2 = theLen[2]*theLen[2];
956 double d2 = theLen[3]*theLen[3];
957 double e2 = theLen[4]*theLen[4];
958 double f2 = theLen[5]*theLen[5];
959 double P = 4.0*a2*b2*d2;
960 double Q = a2*(b2+d2-e2)-b2*(a2+d2-f2)-d2*(a2+b2-c2);
961 double R = (b2+d2-e2)*(a2+d2-f2)*(a2+d2-f2);
962 return sqrt(P-Q+R)/12.0;
965 inline double getVolume2(double theLen[6]){
966 double a2 = theLen[0]*theLen[0];
967 double b2 = theLen[1]*theLen[1];
968 double c2 = theLen[2]*theLen[2];
969 double d2 = theLen[3]*theLen[3];
970 double e2 = theLen[4]*theLen[4];
971 double f2 = theLen[5]*theLen[5];
973 double P = a2*e2*(b2+c2+d2+f2-a2-e2);
974 double Q = b2*f2*(a2+c2+d2+e2-b2-f2);
975 double R = c2*d2*(a2+b2+e2+f2-c2-d2);
976 double S = a2*b2*d2+b2*c2*e2+a2*c2*f2+d2*e2*f2;
978 return sqrt(P+Q+R-S)/12.0;
981 inline double getVolume(const TSequenceOfXYZ& P){
982 gp_Vec aVec1( P( 2 ) - P( 1 ) );
983 gp_Vec aVec2( P( 3 ) - P( 1 ) );
984 gp_Vec aVec3( P( 4 ) - P( 1 ) );
985 gp_Vec anAreaVec( aVec1 ^ aVec2 );
986 return fabs(aVec3 * anAreaVec) / 6.0;
989 inline double getMaxHeight(double theLen[6])
991 double aHeight = std::max(theLen[0],theLen[1]);
992 aHeight = std::max(aHeight,theLen[2]);
993 aHeight = std::max(aHeight,theLen[3]);
994 aHeight = std::max(aHeight,theLen[4]);
995 aHeight = std::max(aHeight,theLen[5]);
1001 double AspectRatio3D::GetValue( long theId )
1004 myCurrElement = myMesh->FindElement( theId );
1005 if ( myCurrElement && myCurrElement->GetVtkType() == VTK_TETRA )
1007 // Action from CoTech | ACTION 31.3:
1008 // EURIWARE BO: Homogenize the formulas used to calculate the Controls in SMESH to fit with
1009 // those of ParaView. The library used by ParaView for those calculations can be reused in SMESH.
1010 vtkUnstructuredGrid* grid = const_cast<SMDS_Mesh*>( myMesh )->GetGrid();
1011 if ( vtkCell* avtkCell = grid->GetCell( myCurrElement->GetVtkID() ))
1012 aVal = Round( vtkMeshQuality::TetAspectRatio( avtkCell ));
1017 if ( GetPoints( myCurrElement, P ))
1018 aVal = Round( GetValue( P ));
1023 bool AspectRatio3D::IsApplicable( const SMDS_MeshElement* element ) const
1025 return ( NumericalFunctor::IsApplicable( element ) && !element->IsPoly() );
1028 double AspectRatio3D::GetValue( const TSequenceOfXYZ& P )
1030 double aQuality = 0.0;
1031 if(myCurrElement->IsPoly()) return aQuality;
1033 int nbNodes = P.size();
1035 if( myCurrElement->IsQuadratic() ) {
1036 if (nbNodes==10) nbNodes=4; // quadratic tetrahedron
1037 else if(nbNodes==13) nbNodes=5; // quadratic pyramid
1038 else if(nbNodes==15) nbNodes=6; // quadratic pentahedron
1039 else if(nbNodes==20) nbNodes=8; // quadratic hexahedron
1040 else if(nbNodes==27) nbNodes=8; // tri-quadratic hexahedron
1041 else return aQuality;
1047 getDistance(P( 1 ),P( 2 )), // a
1048 getDistance(P( 2 ),P( 3 )), // b
1049 getDistance(P( 3 ),P( 1 )), // c
1050 getDistance(P( 2 ),P( 4 )), // d
1051 getDistance(P( 3 ),P( 4 )), // e
1052 getDistance(P( 1 ),P( 4 )) // f
1054 double aTria[4][3] = {
1055 {aLen[0],aLen[1],aLen[2]}, // abc
1056 {aLen[0],aLen[3],aLen[5]}, // adf
1057 {aLen[1],aLen[3],aLen[4]}, // bde
1058 {aLen[2],aLen[4],aLen[5]} // cef
1060 double aSumArea = 0.0;
1061 double aHalfPerimeter = getHalfPerimeter(aTria[0]);
1062 double anArea = getArea(aHalfPerimeter,aTria[0]);
1064 aHalfPerimeter = getHalfPerimeter(aTria[1]);
1065 anArea = getArea(aHalfPerimeter,aTria[1]);
1067 aHalfPerimeter = getHalfPerimeter(aTria[2]);
1068 anArea = getArea(aHalfPerimeter,aTria[2]);
1070 aHalfPerimeter = getHalfPerimeter(aTria[3]);
1071 anArea = getArea(aHalfPerimeter,aTria[3]);
1073 double aVolume = getVolume(P);
1074 //double aVolume = getVolume(aLen);
1075 double aHeight = getMaxHeight(aLen);
1076 static double aCoeff = sqrt(2.0)/12.0;
1077 if ( aVolume > DBL_MIN )
1078 aQuality = aCoeff*aHeight*aSumArea/aVolume;
1083 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 3 ),P( 5 )};
1084 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1087 gp_XYZ aXYZ[4] = {P( 1 ),P( 3 ),P( 4 ),P( 5 )};
1088 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1091 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 5 )};
1092 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1095 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 4 ),P( 5 )};
1096 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1102 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 6 )};
1103 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1106 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 3 )};
1107 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1110 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 6 )};
1111 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1114 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
1115 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1118 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 6 )};
1119 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1122 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 3 )};
1123 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1129 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
1130 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1133 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 4 )};
1134 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1137 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 7 )};
1138 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1141 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 8 )};
1142 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1145 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 3 )};
1146 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1149 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 4 )};
1150 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1153 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 7 )};
1154 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1157 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 8 )};
1158 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1161 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 3 )};
1162 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1165 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 4 )};
1166 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1169 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 7 )};
1170 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1173 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 8 )};
1174 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1177 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 1 )};
1178 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1181 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 2 )};
1182 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1185 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 5 )};
1186 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1189 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 6 )};
1190 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1193 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 1 )};
1194 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1197 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 2 )};
1198 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1201 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 5 )};
1202 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1205 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 6 )};
1206 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1209 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 1 )};
1210 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1213 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
1214 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1217 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 5 )};
1218 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1221 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 6 )};
1222 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1225 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
1226 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1229 gp_XYZ aXYZ[4] = {P( 4 ),P( 5 ),P( 8 ),P( 2 )};
1230 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1233 gp_XYZ aXYZ[4] = {P( 1 ),P( 4 ),P( 5 ),P( 3 )};
1234 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1237 gp_XYZ aXYZ[4] = {P( 3 ),P( 6 ),P( 7 ),P( 1 )};
1238 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1241 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 6 ),P( 4 )};
1242 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1245 gp_XYZ aXYZ[4] = {P( 5 ),P( 6 ),P( 8 ),P( 3 )};
1246 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1249 gp_XYZ aXYZ[4] = {P( 7 ),P( 8 ),P( 6 ),P( 1 )};
1250 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1253 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 7 )};
1254 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1257 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 2 ),P( 5 )};
1258 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1264 gp_XYZ aXYZ[8] = {P( 1 ),P( 2 ),P( 4 ),P( 5 ),P( 7 ),P( 8 ),P( 10 ),P( 11 )};
1265 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[8])),aQuality);
1268 gp_XYZ aXYZ[8] = {P( 2 ),P( 3 ),P( 5 ),P( 6 ),P( 8 ),P( 9 ),P( 11 ),P( 12 )};
1269 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[8])),aQuality);
1272 gp_XYZ aXYZ[8] = {P( 3 ),P( 4 ),P( 6 ),P( 1 ),P( 9 ),P( 10 ),P( 12 ),P( 7 )};
1273 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[8])),aQuality);
1276 } // switch(nbNodes)
1278 if ( nbNodes > 4 ) {
1279 // evaluate aspect ratio of quadrangle faces
1280 AspectRatio aspect2D;
1281 SMDS_VolumeTool::VolumeType type = SMDS_VolumeTool::GetType( nbNodes );
1282 int nbFaces = SMDS_VolumeTool::NbFaces( type );
1283 TSequenceOfXYZ points(4);
1284 for ( int i = 0; i < nbFaces; ++i ) { // loop on faces of a volume
1285 if ( SMDS_VolumeTool::NbFaceNodes( type, i ) != 4 )
1287 const int* pInd = SMDS_VolumeTool::GetFaceNodesIndices( type, i, true );
1288 for ( int p = 0; p < 4; ++p ) // loop on nodes of a quadrangle face
1289 points( p + 1 ) = P( pInd[ p ] + 1 );
1290 aQuality = std::max( aQuality, aspect2D.GetValue( points ));
1296 double AspectRatio3D::GetBadRate( double Value, int /*nbNodes*/ ) const
1298 // the aspect ratio is in the range [1.0,infinity]
1301 return Value / 1000.;
1304 SMDSAbs_ElementType AspectRatio3D::GetType() const
1306 return SMDSAbs_Volume;
1310 //================================================================================
1313 Description : Functor for calculating warping
1315 //================================================================================
1317 bool Warping::IsApplicable( const SMDS_MeshElement* element ) const
1319 return NumericalFunctor::IsApplicable( element ) && element->NbNodes() == 4;
1322 double Warping::GetValue( const TSequenceOfXYZ& P )
1324 if ( P.size() != 4 )
1327 gp_XYZ G = ( P( 1 ) + P( 2 ) + P( 3 ) + P( 4 ) ) / 4.;
1329 double A1 = ComputeA( P( 1 ), P( 2 ), P( 3 ), G );
1330 double A2 = ComputeA( P( 2 ), P( 3 ), P( 4 ), G );
1331 double A3 = ComputeA( P( 3 ), P( 4 ), P( 1 ), G );
1332 double A4 = ComputeA( P( 4 ), P( 1 ), P( 2 ), G );
1334 double val = Max( Max( A1, A2 ), Max( A3, A4 ) );
1336 const double eps = 0.1; // val is in degrees
1338 return val < eps ? 0. : val;
1341 double Warping::ComputeA( const gp_XYZ& thePnt1,
1342 const gp_XYZ& thePnt2,
1343 const gp_XYZ& thePnt3,
1344 const gp_XYZ& theG ) const
1346 double aLen1 = gp_Pnt( thePnt1 ).Distance( gp_Pnt( thePnt2 ) );
1347 double aLen2 = gp_Pnt( thePnt2 ).Distance( gp_Pnt( thePnt3 ) );
1348 double L = Min( aLen1, aLen2 ) * 0.5;
1352 gp_XYZ GI = ( thePnt2 + thePnt1 ) / 2. - theG;
1353 gp_XYZ GJ = ( thePnt3 + thePnt2 ) / 2. - theG;
1354 gp_XYZ N = GI.Crossed( GJ );
1356 if ( N.Modulus() < gp::Resolution() )
1361 double H = ( thePnt2 - theG ).Dot( N );
1362 return asin( fabs( H / L ) ) * 180. / M_PI;
1365 double Warping::GetBadRate( double Value, int /*nbNodes*/ ) const
1367 // the warp is in the range [0.0,PI/2]
1368 // 0.0 = good (no warp)
1369 // PI/2 = bad (face pliee)
1373 SMDSAbs_ElementType Warping::GetType() const
1375 return SMDSAbs_Face;
1379 //================================================================================
1382 Description : Functor for calculating taper
1384 //================================================================================
1386 bool Taper::IsApplicable( const SMDS_MeshElement* element ) const
1388 return ( NumericalFunctor::IsApplicable( element ) && element->NbNodes() == 4 );
1391 double Taper::GetValue( const TSequenceOfXYZ& P )
1393 if ( P.size() != 4 )
1397 double J1 = getArea( P( 4 ), P( 1 ), P( 2 ) );
1398 double J2 = getArea( P( 3 ), P( 1 ), P( 2 ) );
1399 double J3 = getArea( P( 2 ), P( 3 ), P( 4 ) );
1400 double J4 = getArea( P( 3 ), P( 4 ), P( 1 ) );
1402 double JA = 0.25 * ( J1 + J2 + J3 + J4 );
1406 double T1 = fabs( ( J1 - JA ) / JA );
1407 double T2 = fabs( ( J2 - JA ) / JA );
1408 double T3 = fabs( ( J3 - JA ) / JA );
1409 double T4 = fabs( ( J4 - JA ) / JA );
1411 double val = Max( Max( T1, T2 ), Max( T3, T4 ) );
1413 const double eps = 0.01;
1415 return val < eps ? 0. : val;
1418 double Taper::GetBadRate( double Value, int /*nbNodes*/ ) const
1420 // the taper is in the range [0.0,1.0]
1421 // 0.0 = good (no taper)
1422 // 1.0 = bad (les cotes opposes sont allignes)
1426 SMDSAbs_ElementType Taper::GetType() const
1428 return SMDSAbs_Face;
1431 //================================================================================
1434 Description : Functor for calculating skew in degrees
1436 //================================================================================
1438 static inline double skewAngle( const gp_XYZ& p1, const gp_XYZ& p2, const gp_XYZ& p3 )
1440 gp_XYZ p12 = ( p2 + p1 ) / 2.;
1441 gp_XYZ p23 = ( p3 + p2 ) / 2.;
1442 gp_XYZ p31 = ( p3 + p1 ) / 2.;
1444 gp_Vec v1( p31 - p2 ), v2( p12 - p23 );
1446 return v1.Magnitude() < gp::Resolution() || v2.Magnitude() < gp::Resolution() ? 0. : v1.Angle( v2 );
1449 bool Skew::IsApplicable( const SMDS_MeshElement* element ) const
1451 return ( NumericalFunctor::IsApplicable( element ) && element->NbNodes() <= 4 );
1454 double Skew::GetValue( const TSequenceOfXYZ& P )
1456 if ( P.size() != 3 && P.size() != 4 )
1460 const double PI2 = M_PI / 2.;
1461 if ( P.size() == 3 )
1463 double A0 = fabs( PI2 - skewAngle( P( 3 ), P( 1 ), P( 2 ) ) );
1464 double A1 = fabs( PI2 - skewAngle( P( 1 ), P( 2 ), P( 3 ) ) );
1465 double A2 = fabs( PI2 - skewAngle( P( 2 ), P( 3 ), P( 1 ) ) );
1467 return Max( A0, Max( A1, A2 ) ) * 180. / M_PI;
1471 gp_XYZ p12 = ( P( 1 ) + P( 2 ) ) / 2.;
1472 gp_XYZ p23 = ( P( 2 ) + P( 3 ) ) / 2.;
1473 gp_XYZ p34 = ( P( 3 ) + P( 4 ) ) / 2.;
1474 gp_XYZ p41 = ( P( 4 ) + P( 1 ) ) / 2.;
1476 gp_Vec v1( p34 - p12 ), v2( p23 - p41 );
1477 double A = v1.Magnitude() <= gp::Resolution() || v2.Magnitude() <= gp::Resolution()
1478 ? 0. : fabs( PI2 - v1.Angle( v2 ) );
1480 double val = A * 180. / M_PI;
1482 const double eps = 0.1; // val is in degrees
1484 return val < eps ? 0. : val;
1488 double Skew::GetBadRate( double Value, int /*nbNodes*/ ) const
1490 // the skew is in the range [0.0,PI/2].
1496 SMDSAbs_ElementType Skew::GetType() const
1498 return SMDSAbs_Face;
1502 //================================================================================
1505 Description : Functor for calculating area
1507 //================================================================================
1509 double Area::GetValue( const TSequenceOfXYZ& P )
1514 gp_Vec aVec1( P(2) - P(1) );
1515 gp_Vec aVec2( P(3) - P(1) );
1516 gp_Vec SumVec = aVec1 ^ aVec2;
1518 for (size_t i=4; i<=P.size(); i++)
1520 gp_Vec aVec1( P(i-1) - P(1) );
1521 gp_Vec aVec2( P(i ) - P(1) );
1522 gp_Vec tmp = aVec1 ^ aVec2;
1525 val = SumVec.Magnitude() * 0.5;
1530 double Area::GetBadRate( double Value, int /*nbNodes*/ ) const
1532 // meaningless as it is not a quality control functor
1536 SMDSAbs_ElementType Area::GetType() const
1538 return SMDSAbs_Face;
1541 //================================================================================
1544 Description : Functor for calculating length of edge
1546 //================================================================================
1548 double Length::GetValue( const TSequenceOfXYZ& P )
1550 switch ( P.size() ) {
1551 case 2: return getDistance( P( 1 ), P( 2 ) );
1552 case 3: return getDistance( P( 1 ), P( 2 ) ) + getDistance( P( 2 ), P( 3 ) );
1557 double Length::GetBadRate( double Value, int /*nbNodes*/ ) const
1559 // meaningless as it is not quality control functor
1563 SMDSAbs_ElementType Length::GetType() const
1565 return SMDSAbs_Edge;
1568 //================================================================================
1571 Description : Functor for calculating minimal length of element edge
1573 //================================================================================
1575 Length3D::Length3D():
1576 Length2D ( SMDSAbs_Volume )
1580 //================================================================================
1583 Description : Functor for calculating minimal length of element edge
1585 //================================================================================
1587 Length2D::Length2D( SMDSAbs_ElementType type ):
1592 bool Length2D::IsApplicable( const SMDS_MeshElement* element ) const
1594 return ( NumericalFunctor::IsApplicable( element ) &&
1595 element->GetEntityType() != SMDSEntity_Polyhedra );
1598 double Length2D::GetValue( const TSequenceOfXYZ& P )
1602 SMDSAbs_EntityType aType = P.getElementEntity();
1605 case SMDSEntity_Edge:
1607 aVal = getDistance( P( 1 ), P( 2 ) );
1609 case SMDSEntity_Quad_Edge:
1610 if (len == 3) // quadratic edge
1611 aVal = getDistance(P( 1 ),P( 3 )) + getDistance(P( 3 ),P( 2 ));
1613 case SMDSEntity_Triangle:
1614 if (len == 3){ // triangles
1615 double L1 = getDistance(P( 1 ),P( 2 ));
1616 double L2 = getDistance(P( 2 ),P( 3 ));
1617 double L3 = getDistance(P( 3 ),P( 1 ));
1618 aVal = Min(L1,Min(L2,L3));
1621 case SMDSEntity_Quadrangle:
1622 if (len == 4){ // quadrangles
1623 double L1 = getDistance(P( 1 ),P( 2 ));
1624 double L2 = getDistance(P( 2 ),P( 3 ));
1625 double L3 = getDistance(P( 3 ),P( 4 ));
1626 double L4 = getDistance(P( 4 ),P( 1 ));
1627 aVal = Min(Min(L1,L2),Min(L3,L4));
1630 case SMDSEntity_Quad_Triangle:
1631 case SMDSEntity_BiQuad_Triangle:
1632 if (len >= 6){ // quadratic triangles
1633 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1634 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1635 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 1 ));
1636 aVal = Min(L1,Min(L2,L3));
1639 case SMDSEntity_Quad_Quadrangle:
1640 case SMDSEntity_BiQuad_Quadrangle:
1641 if (len >= 8){ // quadratic quadrangles
1642 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1643 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1644 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 7 ));
1645 double L4 = getDistance(P( 7 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
1646 aVal = Min(Min(L1,L2),Min(L3,L4));
1649 case SMDSEntity_Tetra:
1650 if (len == 4){ // tetrahedra
1651 double L1 = getDistance(P( 1 ),P( 2 ));
1652 double L2 = getDistance(P( 2 ),P( 3 ));
1653 double L3 = getDistance(P( 3 ),P( 1 ));
1654 double L4 = getDistance(P( 1 ),P( 4 ));
1655 double L5 = getDistance(P( 2 ),P( 4 ));
1656 double L6 = getDistance(P( 3 ),P( 4 ));
1657 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1660 case SMDSEntity_Pyramid:
1661 if (len == 5){ // pyramid
1662 double L1 = getDistance(P( 1 ),P( 2 ));
1663 double L2 = getDistance(P( 2 ),P( 3 ));
1664 double L3 = getDistance(P( 3 ),P( 4 ));
1665 double L4 = getDistance(P( 4 ),P( 1 ));
1666 double L5 = getDistance(P( 1 ),P( 5 ));
1667 double L6 = getDistance(P( 2 ),P( 5 ));
1668 double L7 = getDistance(P( 3 ),P( 5 ));
1669 double L8 = getDistance(P( 4 ),P( 5 ));
1671 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1672 aVal = Min(aVal,Min(L7,L8));
1675 case SMDSEntity_Penta:
1676 if (len == 6) { // pentahedron
1677 double L1 = getDistance(P( 1 ),P( 2 ));
1678 double L2 = getDistance(P( 2 ),P( 3 ));
1679 double L3 = getDistance(P( 3 ),P( 1 ));
1680 double L4 = getDistance(P( 4 ),P( 5 ));
1681 double L5 = getDistance(P( 5 ),P( 6 ));
1682 double L6 = getDistance(P( 6 ),P( 4 ));
1683 double L7 = getDistance(P( 1 ),P( 4 ));
1684 double L8 = getDistance(P( 2 ),P( 5 ));
1685 double L9 = getDistance(P( 3 ),P( 6 ));
1687 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1688 aVal = Min(aVal,Min(Min(L7,L8),L9));
1691 case SMDSEntity_Hexa:
1692 if (len == 8){ // hexahedron
1693 double L1 = getDistance(P( 1 ),P( 2 ));
1694 double L2 = getDistance(P( 2 ),P( 3 ));
1695 double L3 = getDistance(P( 3 ),P( 4 ));
1696 double L4 = getDistance(P( 4 ),P( 1 ));
1697 double L5 = getDistance(P( 5 ),P( 6 ));
1698 double L6 = getDistance(P( 6 ),P( 7 ));
1699 double L7 = getDistance(P( 7 ),P( 8 ));
1700 double L8 = getDistance(P( 8 ),P( 5 ));
1701 double L9 = getDistance(P( 1 ),P( 5 ));
1702 double L10= getDistance(P( 2 ),P( 6 ));
1703 double L11= getDistance(P( 3 ),P( 7 ));
1704 double L12= getDistance(P( 4 ),P( 8 ));
1706 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1707 aVal = Min(aVal,Min(Min(L7,L8),Min(L9,L10)));
1708 aVal = Min(aVal,Min(L11,L12));
1711 case SMDSEntity_Quad_Tetra:
1712 if (len == 10){ // quadratic tetrahedron
1713 double L1 = getDistance(P( 1 ),P( 5 )) + getDistance(P( 5 ),P( 2 ));
1714 double L2 = getDistance(P( 2 ),P( 6 )) + getDistance(P( 6 ),P( 3 ));
1715 double L3 = getDistance(P( 3 ),P( 7 )) + getDistance(P( 7 ),P( 1 ));
1716 double L4 = getDistance(P( 1 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
1717 double L5 = getDistance(P( 2 ),P( 9 )) + getDistance(P( 9 ),P( 4 ));
1718 double L6 = getDistance(P( 3 ),P( 10 )) + getDistance(P( 10 ),P( 4 ));
1719 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1722 case SMDSEntity_Quad_Pyramid:
1723 if (len == 13){ // quadratic pyramid
1724 double L1 = getDistance(P( 1 ),P( 6 )) + getDistance(P( 6 ),P( 2 ));
1725 double L2 = getDistance(P( 2 ),P( 7 )) + getDistance(P( 7 ),P( 3 ));
1726 double L3 = getDistance(P( 3 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
1727 double L4 = getDistance(P( 4 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1728 double L5 = getDistance(P( 1 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1729 double L6 = getDistance(P( 2 ),P( 11 )) + getDistance(P( 11 ),P( 5 ));
1730 double L7 = getDistance(P( 3 ),P( 12 )) + getDistance(P( 12 ),P( 5 ));
1731 double L8 = getDistance(P( 4 ),P( 13 )) + getDistance(P( 13 ),P( 5 ));
1732 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1733 aVal = Min(aVal,Min(L7,L8));
1736 case SMDSEntity_Quad_Penta:
1737 case SMDSEntity_BiQuad_Penta:
1738 if (len >= 15){ // quadratic pentahedron
1739 double L1 = getDistance(P( 1 ),P( 7 )) + getDistance(P( 7 ),P( 2 ));
1740 double L2 = getDistance(P( 2 ),P( 8 )) + getDistance(P( 8 ),P( 3 ));
1741 double L3 = getDistance(P( 3 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1742 double L4 = getDistance(P( 4 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1743 double L5 = getDistance(P( 5 ),P( 11 )) + getDistance(P( 11 ),P( 6 ));
1744 double L6 = getDistance(P( 6 ),P( 12 )) + getDistance(P( 12 ),P( 4 ));
1745 double L7 = getDistance(P( 1 ),P( 13 )) + getDistance(P( 13 ),P( 4 ));
1746 double L8 = getDistance(P( 2 ),P( 14 )) + getDistance(P( 14 ),P( 5 ));
1747 double L9 = getDistance(P( 3 ),P( 15 )) + getDistance(P( 15 ),P( 6 ));
1748 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1749 aVal = Min(aVal,Min(Min(L7,L8),L9));
1752 case SMDSEntity_Quad_Hexa:
1753 case SMDSEntity_TriQuad_Hexa:
1754 if (len >= 20) { // quadratic hexahedron
1755 double L1 = getDistance(P( 1 ),P( 9 )) + getDistance(P( 9 ),P( 2 ));
1756 double L2 = getDistance(P( 2 ),P( 10 )) + getDistance(P( 10 ),P( 3 ));
1757 double L3 = getDistance(P( 3 ),P( 11 )) + getDistance(P( 11 ),P( 4 ));
1758 double L4 = getDistance(P( 4 ),P( 12 )) + getDistance(P( 12 ),P( 1 ));
1759 double L5 = getDistance(P( 5 ),P( 13 )) + getDistance(P( 13 ),P( 6 ));
1760 double L6 = getDistance(P( 6 ),P( 14 )) + getDistance(P( 14 ),P( 7 ));
1761 double L7 = getDistance(P( 7 ),P( 15 )) + getDistance(P( 15 ),P( 8 ));
1762 double L8 = getDistance(P( 8 ),P( 16 )) + getDistance(P( 16 ),P( 5 ));
1763 double L9 = getDistance(P( 1 ),P( 17 )) + getDistance(P( 17 ),P( 5 ));
1764 double L10= getDistance(P( 2 ),P( 18 )) + getDistance(P( 18 ),P( 6 ));
1765 double L11= getDistance(P( 3 ),P( 19 )) + getDistance(P( 19 ),P( 7 ));
1766 double L12= getDistance(P( 4 ),P( 20 )) + getDistance(P( 20 ),P( 8 ));
1767 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1768 aVal = Min(aVal,Min(Min(L7,L8),Min(L9,L10)));
1769 aVal = Min(aVal,Min(L11,L12));
1772 case SMDSEntity_Polygon:
1774 aVal = getDistance( P(1), P( P.size() ));
1775 for ( size_t i = 1; i < P.size(); ++i )
1776 aVal = Min( aVal, getDistance( P( i ), P( i+1 )));
1779 case SMDSEntity_Quad_Polygon:
1781 aVal = getDistance( P(1), P( P.size() )) + getDistance( P(P.size()), P( P.size()-1 ));
1782 for ( size_t i = 1; i < P.size()-1; i += 2 )
1783 aVal = Min( aVal, getDistance( P( i ), P( i+1 )) + getDistance( P( i+1 ), P( i+2 )));
1786 case SMDSEntity_Hexagonal_Prism:
1787 if (len == 12) { // hexagonal prism
1788 double L1 = getDistance(P( 1 ),P( 2 ));
1789 double L2 = getDistance(P( 2 ),P( 3 ));
1790 double L3 = getDistance(P( 3 ),P( 4 ));
1791 double L4 = getDistance(P( 4 ),P( 5 ));
1792 double L5 = getDistance(P( 5 ),P( 6 ));
1793 double L6 = getDistance(P( 6 ),P( 1 ));
1795 double L7 = getDistance(P( 7 ), P( 8 ));
1796 double L8 = getDistance(P( 8 ), P( 9 ));
1797 double L9 = getDistance(P( 9 ), P( 10 ));
1798 double L10= getDistance(P( 10 ),P( 11 ));
1799 double L11= getDistance(P( 11 ),P( 12 ));
1800 double L12= getDistance(P( 12 ),P( 7 ));
1802 double L13 = getDistance(P( 1 ),P( 7 ));
1803 double L14 = getDistance(P( 2 ),P( 8 ));
1804 double L15 = getDistance(P( 3 ),P( 9 ));
1805 double L16 = getDistance(P( 4 ),P( 10 ));
1806 double L17 = getDistance(P( 5 ),P( 11 ));
1807 double L18 = getDistance(P( 6 ),P( 12 ));
1808 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1809 aVal = Min(aVal, Min(Min(Min(L7,L8),Min(L9,L10)),Min(L11,L12)));
1810 aVal = Min(aVal, Min(Min(Min(L13,L14),Min(L15,L16)),Min(L17,L18)));
1813 case SMDSEntity_Polyhedra:
1825 if ( myPrecision >= 0 )
1827 double prec = pow( 10., (double)( myPrecision ) );
1828 aVal = floor( aVal * prec + 0.5 ) / prec;
1834 double Length2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1836 // meaningless as it is not a quality control functor
1840 SMDSAbs_ElementType Length2D::GetType() const
1845 Length2D::Value::Value(double theLength,long thePntId1, long thePntId2):
1848 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1849 if(thePntId1 > thePntId2){
1850 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1854 bool Length2D::Value::operator<(const Length2D::Value& x) const
1856 if(myPntId[0] < x.myPntId[0]) return true;
1857 if(myPntId[0] == x.myPntId[0])
1858 if(myPntId[1] < x.myPntId[1]) return true;
1862 void Length2D::GetValues(TValues& theValues)
1864 if ( myType == SMDSAbs_Face )
1866 for ( SMDS_FaceIteratorPtr anIter = myMesh->facesIterator(); anIter->more(); )
1868 const SMDS_MeshFace* anElem = anIter->next();
1869 if ( anElem->IsQuadratic() )
1871 // use special nodes iterator
1872 SMDS_NodeIteratorPtr anIter = anElem->interlacedNodesIterator();
1873 long aNodeId[4] = { 0,0,0,0 };
1877 if ( anIter->more() )
1879 const SMDS_MeshNode* aNode = anIter->next();
1880 P[0] = P[1] = SMESH_NodeXYZ( aNode );
1881 aNodeId[0] = aNodeId[1] = aNode->GetID();
1884 for ( ; anIter->more(); )
1886 const SMDS_MeshNode* N1 = anIter->next();
1887 P[2] = SMESH_NodeXYZ( N1 );
1888 aNodeId[2] = N1->GetID();
1889 aLength = P[1].Distance(P[2]);
1890 if(!anIter->more()) break;
1891 const SMDS_MeshNode* N2 = anIter->next();
1892 P[3] = SMESH_NodeXYZ( N2 );
1893 aNodeId[3] = N2->GetID();
1894 aLength += P[2].Distance(P[3]);
1895 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1896 Value aValue2(aLength,aNodeId[2],aNodeId[3]);
1898 aNodeId[1] = aNodeId[3];
1899 theValues.insert(aValue1);
1900 theValues.insert(aValue2);
1902 aLength += P[2].Distance(P[0]);
1903 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1904 Value aValue2(aLength,aNodeId[2],aNodeId[0]);
1905 theValues.insert(aValue1);
1906 theValues.insert(aValue2);
1909 SMDS_NodeIteratorPtr aNodesIter = anElem->nodeIterator();
1910 long aNodeId[2] = {0,0};
1914 const SMDS_MeshElement* aNode;
1915 if ( aNodesIter->more())
1917 aNode = aNodesIter->next();
1918 P[0] = P[1] = SMESH_NodeXYZ( aNode );
1919 aNodeId[0] = aNodeId[1] = aNode->GetID();
1922 for( ; aNodesIter->more(); )
1924 aNode = aNodesIter->next();
1925 long anId = aNode->GetID();
1927 P[2] = SMESH_NodeXYZ( aNode );
1929 aLength = P[1].Distance(P[2]);
1931 Value aValue(aLength,aNodeId[1],anId);
1934 theValues.insert(aValue);
1937 aLength = P[0].Distance(P[1]);
1939 Value aValue(aLength,aNodeId[0],aNodeId[1]);
1940 theValues.insert(aValue);
1950 //================================================================================
1952 Class : Deflection2D
1953 Description : computes distance between a face center and an underlying surface
1955 //================================================================================
1957 double Deflection2D::GetValue( const TSequenceOfXYZ& P )
1959 if ( myMesh && P.getElement() )
1961 // get underlying surface
1962 if ( myShapeIndex != P.getElement()->getshapeId() )
1964 mySurface.Nullify();
1965 myShapeIndex = P.getElement()->getshapeId();
1966 const TopoDS_Shape& S =
1967 static_cast< const SMESHDS_Mesh* >( myMesh )->IndexToShape( myShapeIndex );
1968 if ( !S.IsNull() && S.ShapeType() == TopAbs_FACE )
1970 mySurface = new ShapeAnalysis_Surface( BRep_Tool::Surface( TopoDS::Face( S )));
1972 GeomLib_IsPlanarSurface isPlaneCheck( mySurface->Surface() );
1973 if ( isPlaneCheck.IsPlanar() )
1974 myPlane.reset( new gp_Pln( isPlaneCheck.Plan() ));
1979 // project gravity center to the surface
1980 if ( !mySurface.IsNull() )
1985 for ( size_t i = 0; i < P.size(); ++i )
1989 if ( SMDS_FacePositionPtr fPos = P.getElement()->GetNode( i )->GetPosition() )
1991 uv.ChangeCoord(1) += fPos->GetUParameter();
1992 uv.ChangeCoord(2) += fPos->GetVParameter();
1997 if ( nbUV ) uv /= nbUV;
1999 double maxLen = MaxElementLength2D().GetValue( P );
2000 double tol = 1e-3 * maxLen;
2004 dist = myPlane->Distance( gc );
2010 if ( uv.X() != 0 && uv.Y() != 0 ) // faster way
2011 mySurface->NextValueOfUV( uv, gc, tol, 0.5 * maxLen );
2013 mySurface->ValueOfUV( gc, tol );
2014 dist = mySurface->Gap();
2016 return Round( dist );
2022 void Deflection2D::SetMesh( const SMDS_Mesh* theMesh )
2024 NumericalFunctor::SetMesh( dynamic_cast<const SMESHDS_Mesh* >( theMesh ));
2025 myShapeIndex = -100;
2029 SMDSAbs_ElementType Deflection2D::GetType() const
2031 return SMDSAbs_Face;
2034 double Deflection2D::GetBadRate( double Value, int /*nbNodes*/ ) const
2036 // meaningless as it is not quality control functor
2040 //================================================================================
2042 Class : MultiConnection
2043 Description : Functor for calculating number of faces conneted to the edge
2045 //================================================================================
2047 double MultiConnection::GetValue( const TSequenceOfXYZ& P )
2051 double MultiConnection::GetValue( long theId )
2053 return getNbMultiConnection( myMesh, theId );
2056 double MultiConnection::GetBadRate( double Value, int /*nbNodes*/ ) const
2058 // meaningless as it is not quality control functor
2062 SMDSAbs_ElementType MultiConnection::GetType() const
2064 return SMDSAbs_Edge;
2067 //================================================================================
2069 Class : MultiConnection2D
2070 Description : Functor for calculating number of faces conneted to the edge
2072 //================================================================================
2074 double MultiConnection2D::GetValue( const TSequenceOfXYZ& P )
2079 double MultiConnection2D::GetValue( long theElementId )
2083 const SMDS_MeshElement* aFaceElem = myMesh->FindElement(theElementId);
2084 SMDSAbs_ElementType aType = aFaceElem->GetType();
2089 int i = 0, len = aFaceElem->NbNodes();
2090 SMDS_ElemIteratorPtr anIter = aFaceElem->nodesIterator();
2093 const SMDS_MeshNode *aNode, *aNode0 = 0;
2094 TColStd_MapOfInteger aMap, aMapPrev;
2096 for (i = 0; i <= len; i++) {
2101 if (anIter->more()) {
2102 aNode = (SMDS_MeshNode*)anIter->next();
2110 if (i == 0) aNode0 = aNode;
2112 SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator();
2113 while (anElemIter->more()) {
2114 const SMDS_MeshElement* anElem = anElemIter->next();
2115 if (anElem != 0 && anElem->GetType() == SMDSAbs_Face) {
2116 int anId = anElem->GetID();
2119 if (aMapPrev.Contains(anId)) {
2124 aResult = Max(aResult, aNb);
2135 double MultiConnection2D::GetBadRate( double Value, int /*nbNodes*/ ) const
2137 // meaningless as it is not quality control functor
2141 SMDSAbs_ElementType MultiConnection2D::GetType() const
2143 return SMDSAbs_Face;
2146 MultiConnection2D::Value::Value(long thePntId1, long thePntId2)
2148 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
2149 if(thePntId1 > thePntId2){
2150 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
2154 bool MultiConnection2D::Value::operator<(const MultiConnection2D::Value& x) const
2156 if(myPntId[0] < x.myPntId[0]) return true;
2157 if(myPntId[0] == x.myPntId[0])
2158 if(myPntId[1] < x.myPntId[1]) return true;
2162 void MultiConnection2D::GetValues(MValues& theValues)
2164 if ( !myMesh ) return;
2165 for ( SMDS_FaceIteratorPtr anIter = myMesh->facesIterator(); anIter->more(); )
2167 const SMDS_MeshFace* anElem = anIter->next();
2168 SMDS_NodeIteratorPtr aNodesIter = anElem->interlacedNodesIterator();
2170 const SMDS_MeshNode* aNode1 = anElem->GetNode( anElem->NbNodes() - 1 );
2171 const SMDS_MeshNode* aNode2;
2172 for ( ; aNodesIter->more(); )
2174 aNode2 = aNodesIter->next();
2176 Value aValue ( aNode1->GetID(), aNode2->GetID() );
2177 MValues::iterator aItr = theValues.insert( std::make_pair( aValue, 0 )).first;
2185 //================================================================================
2187 Class : BallDiameter
2188 Description : Functor returning diameter of a ball element
2190 //================================================================================
2192 double BallDiameter::GetValue( long theId )
2194 double diameter = 0;
2196 if ( const SMDS_BallElement* ball =
2197 myMesh->DownCast< SMDS_BallElement >( myMesh->FindElement( theId )))
2199 diameter = ball->GetDiameter();
2204 double BallDiameter::GetBadRate( double Value, int /*nbNodes*/ ) const
2206 // meaningless as it is not a quality control functor
2210 SMDSAbs_ElementType BallDiameter::GetType() const
2212 return SMDSAbs_Ball;
2215 //================================================================================
2217 Class : NodeConnectivityNumber
2218 Description : Functor returning number of elements connected to a node
2220 //================================================================================
2222 double NodeConnectivityNumber::GetValue( long theId )
2226 if ( const SMDS_MeshNode* node = myMesh->FindNode( theId ))
2228 SMDSAbs_ElementType type;
2229 if ( myMesh->NbVolumes() > 0 )
2230 type = SMDSAbs_Volume;
2231 else if ( myMesh->NbFaces() > 0 )
2232 type = SMDSAbs_Face;
2233 else if ( myMesh->NbEdges() > 0 )
2234 type = SMDSAbs_Edge;
2237 nb = node->NbInverseElements( type );
2242 double NodeConnectivityNumber::GetBadRate( double Value, int /*nbNodes*/ ) const
2247 SMDSAbs_ElementType NodeConnectivityNumber::GetType() const
2249 return SMDSAbs_Node;
2256 //================================================================================
2258 Class : BadOrientedVolume
2259 Description : Predicate bad oriented volumes
2261 //================================================================================
2263 BadOrientedVolume::BadOrientedVolume()
2268 void BadOrientedVolume::SetMesh( const SMDS_Mesh* theMesh )
2273 bool BadOrientedVolume::IsSatisfy( long theId )
2278 SMDS_VolumeTool vTool( myMesh->FindElement( theId ));
2281 if ( vTool.IsPoly() )
2284 for ( int i = 0; i < vTool.NbFaces() && isOk; ++i )
2285 isOk = vTool.IsFaceExternal( i );
2289 isOk = vTool.IsForward();
2294 SMDSAbs_ElementType BadOrientedVolume::GetType() const
2296 return SMDSAbs_Volume;
2300 Class : BareBorderVolume
2303 bool BareBorderVolume::IsSatisfy(long theElementId )
2305 SMDS_VolumeTool myTool;
2306 if ( myTool.Set( myMesh->FindElement(theElementId)))
2308 for ( int iF = 0; iF < myTool.NbFaces(); ++iF )
2309 if ( myTool.IsFreeFace( iF ))
2311 const SMDS_MeshNode** n = myTool.GetFaceNodes(iF);
2312 std::vector< const SMDS_MeshNode*> nodes( n, n+myTool.NbFaceNodes(iF));
2313 if ( !myMesh->FindElement( nodes, SMDSAbs_Face, /*Nomedium=*/false))
2320 //================================================================================
2322 Class : BareBorderFace
2324 //================================================================================
2326 bool BareBorderFace::IsSatisfy(long theElementId )
2329 if ( const SMDS_MeshElement* face = myMesh->FindElement(theElementId))
2331 if ( face->GetType() == SMDSAbs_Face )
2333 int nbN = face->NbCornerNodes();
2334 for ( int i = 0; i < nbN && !ok; ++i )
2336 // check if a link is shared by another face
2337 const SMDS_MeshNode* n1 = face->GetNode( i );
2338 const SMDS_MeshNode* n2 = face->GetNode( (i+1)%nbN );
2339 SMDS_ElemIteratorPtr fIt = n1->GetInverseElementIterator( SMDSAbs_Face );
2340 bool isShared = false;
2341 while ( !isShared && fIt->more() )
2343 const SMDS_MeshElement* f = fIt->next();
2344 isShared = ( f != face && f->GetNodeIndex(n2) != -1 );
2348 const int iQuad = face->IsQuadratic();
2349 myLinkNodes.resize( 2 + iQuad);
2350 myLinkNodes[0] = n1;
2351 myLinkNodes[1] = n2;
2353 myLinkNodes[2] = face->GetNode( i+nbN );
2354 ok = !myMesh->FindElement( myLinkNodes, SMDSAbs_Edge, /*noMedium=*/false);
2362 //================================================================================
2364 Class : OverConstrainedVolume
2366 //================================================================================
2368 bool OverConstrainedVolume::IsSatisfy(long theElementId )
2370 // An element is over-constrained if it has N-1 free borders where
2371 // N is the number of edges/faces for a 2D/3D element.
2372 SMDS_VolumeTool myTool;
2373 if ( myTool.Set( myMesh->FindElement(theElementId)))
2375 int nbSharedFaces = 0;
2376 for ( int iF = 0; iF < myTool.NbFaces(); ++iF )
2377 if ( !myTool.IsFreeFace( iF ) && ++nbSharedFaces > 1 )
2379 return ( nbSharedFaces == 1 );
2384 //================================================================================
2386 Class : OverConstrainedFace
2388 //================================================================================
2390 bool OverConstrainedFace::IsSatisfy(long theElementId )
2392 // An element is over-constrained if it has N-1 free borders where
2393 // N is the number of edges/faces for a 2D/3D element.
2394 if ( const SMDS_MeshElement* face = myMesh->FindElement(theElementId))
2395 if ( face->GetType() == SMDSAbs_Face )
2397 int nbSharedBorders = 0;
2398 int nbN = face->NbCornerNodes();
2399 for ( int i = 0; i < nbN; ++i )
2401 // check if a link is shared by another face
2402 const SMDS_MeshNode* n1 = face->GetNode( i );
2403 const SMDS_MeshNode* n2 = face->GetNode( (i+1)%nbN );
2404 SMDS_ElemIteratorPtr fIt = n1->GetInverseElementIterator( SMDSAbs_Face );
2405 bool isShared = false;
2406 while ( !isShared && fIt->more() )
2408 const SMDS_MeshElement* f = fIt->next();
2409 isShared = ( f != face && f->GetNodeIndex(n2) != -1 );
2411 if ( isShared && ++nbSharedBorders > 1 )
2414 return ( nbSharedBorders == 1 );
2419 //================================================================================
2421 Class : CoincidentNodes
2422 Description : Predicate of Coincident nodes
2424 //================================================================================
2426 CoincidentNodes::CoincidentNodes()
2431 bool CoincidentNodes::IsSatisfy( long theElementId )
2433 return myCoincidentIDs.Contains( theElementId );
2436 SMDSAbs_ElementType CoincidentNodes::GetType() const
2438 return SMDSAbs_Node;
2441 void CoincidentNodes::SetTolerance( const double theToler )
2443 if ( myToler != theToler )
2450 void CoincidentNodes::SetMesh( const SMDS_Mesh* theMesh )
2452 myMeshModifTracer.SetMesh( theMesh );
2453 if ( myMeshModifTracer.IsMeshModified() )
2455 TIDSortedNodeSet nodesToCheck;
2456 SMDS_NodeIteratorPtr nIt = theMesh->nodesIterator();
2457 while ( nIt->more() )
2458 nodesToCheck.insert( nodesToCheck.end(), nIt->next() );
2460 std::list< std::list< const SMDS_MeshNode*> > nodeGroups;
2461 SMESH_OctreeNode::FindCoincidentNodes ( nodesToCheck, &nodeGroups, myToler );
2463 myCoincidentIDs.Clear();
2464 std::list< std::list< const SMDS_MeshNode*> >::iterator groupIt = nodeGroups.begin();
2465 for ( ; groupIt != nodeGroups.end(); ++groupIt )
2467 std::list< const SMDS_MeshNode*>& coincNodes = *groupIt;
2468 std::list< const SMDS_MeshNode*>::iterator n = coincNodes.begin();
2469 for ( ; n != coincNodes.end(); ++n )
2470 myCoincidentIDs.Add( (*n)->GetID() );
2475 //================================================================================
2477 Class : CoincidentElements
2478 Description : Predicate of Coincident Elements
2479 Note : This class is suitable only for visualization of Coincident Elements
2481 //================================================================================
2483 CoincidentElements::CoincidentElements()
2488 void CoincidentElements::SetMesh( const SMDS_Mesh* theMesh )
2493 bool CoincidentElements::IsSatisfy( long theElementId )
2495 if ( !myMesh ) return false;
2497 if ( const SMDS_MeshElement* e = myMesh->FindElement( theElementId ))
2499 if ( e->GetType() != GetType() ) return false;
2500 std::set< const SMDS_MeshNode* > elemNodes( e->begin_nodes(), e->end_nodes() );
2501 const int nbNodes = e->NbNodes();
2502 SMDS_ElemIteratorPtr invIt = (*elemNodes.begin())->GetInverseElementIterator( GetType() );
2503 while ( invIt->more() )
2505 const SMDS_MeshElement* e2 = invIt->next();
2506 if ( e2 == e || e2->NbNodes() != nbNodes ) continue;
2508 bool sameNodes = true;
2509 for ( size_t i = 0; i < elemNodes.size() && sameNodes; ++i )
2510 sameNodes = ( elemNodes.count( e2->GetNode( i )));
2518 SMDSAbs_ElementType CoincidentElements1D::GetType() const
2520 return SMDSAbs_Edge;
2522 SMDSAbs_ElementType CoincidentElements2D::GetType() const
2524 return SMDSAbs_Face;
2526 SMDSAbs_ElementType CoincidentElements3D::GetType() const
2528 return SMDSAbs_Volume;
2532 //================================================================================
2535 Description : Predicate for free borders
2537 //================================================================================
2539 FreeBorders::FreeBorders()
2544 void FreeBorders::SetMesh( const SMDS_Mesh* theMesh )
2549 bool FreeBorders::IsSatisfy( long theId )
2551 return getNbMultiConnection( myMesh, theId ) == 1;
2554 SMDSAbs_ElementType FreeBorders::GetType() const
2556 return SMDSAbs_Edge;
2560 //================================================================================
2563 Description : Predicate for free Edges
2565 //================================================================================
2567 FreeEdges::FreeEdges()
2572 void FreeEdges::SetMesh( const SMDS_Mesh* theMesh )
2577 bool FreeEdges::IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId )
2579 SMDS_ElemIteratorPtr anElemIter = theNodes[ 0 ]->GetInverseElementIterator(SMDSAbs_Face);
2580 while( anElemIter->more() )
2582 if ( const SMDS_MeshElement* anElem = anElemIter->next())
2584 const int anId = anElem->GetID();
2585 if ( anId != theFaceId && anElem->GetNodeIndex( theNodes[1] ) >= 0 )
2592 bool FreeEdges::IsSatisfy( long theId )
2597 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
2598 if ( aFace == 0 || aFace->GetType() != SMDSAbs_Face || aFace->NbNodes() < 3 )
2601 SMDS_NodeIteratorPtr anIter = aFace->interlacedNodesIterator();
2605 int i = 0, nbNodes = aFace->NbNodes();
2606 std::vector <const SMDS_MeshNode*> aNodes( nbNodes+1 );
2607 while( anIter->more() )
2608 if ( ! ( aNodes[ i++ ] = anIter->next() ))
2610 aNodes[ nbNodes ] = aNodes[ 0 ];
2612 for ( i = 0; i < nbNodes; i++ )
2613 if ( IsFreeEdge( &aNodes[ i ], theId ) )
2619 SMDSAbs_ElementType FreeEdges::GetType() const
2621 return SMDSAbs_Face;
2624 FreeEdges::Border::Border(long theElemId, long thePntId1, long thePntId2):
2627 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
2628 if(thePntId1 > thePntId2){
2629 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
2633 bool FreeEdges::Border::operator<(const FreeEdges::Border& x) const{
2634 if(myPntId[0] < x.myPntId[0]) return true;
2635 if(myPntId[0] == x.myPntId[0])
2636 if(myPntId[1] < x.myPntId[1]) return true;
2640 inline void UpdateBorders(const FreeEdges::Border& theBorder,
2641 FreeEdges::TBorders& theRegistry,
2642 FreeEdges::TBorders& theContainer)
2644 if(theRegistry.find(theBorder) == theRegistry.end()){
2645 theRegistry.insert(theBorder);
2646 theContainer.insert(theBorder);
2648 theContainer.erase(theBorder);
2652 void FreeEdges::GetBoreders(TBorders& theBorders)
2655 for ( SMDS_FaceIteratorPtr anIter = myMesh->facesIterator(); anIter->more(); )
2657 const SMDS_MeshFace* anElem = anIter->next();
2658 long anElemId = anElem->GetID();
2659 SMDS_NodeIteratorPtr aNodesIter = anElem->interlacedNodesIterator();
2660 if ( !aNodesIter->more() ) continue;
2661 long aNodeId[2] = {0,0};
2662 aNodeId[0] = anElem->GetNode( anElem->NbNodes()-1 )->GetID();
2663 for ( ; aNodesIter->more(); )
2665 aNodeId[1] = aNodesIter->next()->GetID();
2666 Border aBorder( anElemId, aNodeId[0], aNodeId[1] );
2667 UpdateBorders( aBorder, aRegistry, theBorders );
2668 aNodeId[0] = aNodeId[1];
2673 //================================================================================
2676 Description : Predicate for free nodes
2678 //================================================================================
2680 FreeNodes::FreeNodes()
2685 void FreeNodes::SetMesh( const SMDS_Mesh* theMesh )
2690 bool FreeNodes::IsSatisfy( long theNodeId )
2692 const SMDS_MeshNode* aNode = myMesh->FindNode( theNodeId );
2696 return (aNode->NbInverseElements() < 1);
2699 SMDSAbs_ElementType FreeNodes::GetType() const
2701 return SMDSAbs_Node;
2705 //================================================================================
2708 Description : Predicate for free faces
2710 //================================================================================
2712 FreeFaces::FreeFaces()
2717 void FreeFaces::SetMesh( const SMDS_Mesh* theMesh )
2722 bool FreeFaces::IsSatisfy( long theId )
2724 if (!myMesh) return false;
2725 // check that faces nodes refers to less than two common volumes
2726 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
2727 if ( !aFace || aFace->GetType() != SMDSAbs_Face )
2730 int nbNode = aFace->NbNodes();
2732 // collect volumes to check that number of volumes with count equal nbNode not less than 2
2733 typedef std::map< SMDS_MeshElement*, int > TMapOfVolume; // map of volume counters
2734 typedef std::map< SMDS_MeshElement*, int >::iterator TItrMapOfVolume; // iterator
2735 TMapOfVolume mapOfVol;
2737 SMDS_ElemIteratorPtr nodeItr = aFace->nodesIterator();
2738 while ( nodeItr->more() )
2740 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(nodeItr->next());
2741 if ( !aNode ) continue;
2742 SMDS_ElemIteratorPtr volItr = aNode->GetInverseElementIterator(SMDSAbs_Volume);
2743 while ( volItr->more() )
2745 SMDS_MeshElement* aVol = (SMDS_MeshElement*)volItr->next();
2746 TItrMapOfVolume itr = mapOfVol.insert( std::make_pair( aVol, 0 )).first;
2751 TItrMapOfVolume volItr = mapOfVol.begin();
2752 TItrMapOfVolume volEnd = mapOfVol.end();
2753 for ( ; volItr != volEnd; ++volItr )
2754 if ( (*volItr).second >= nbNode )
2756 // face is not free if number of volumes constructed on their nodes more than one
2760 SMDSAbs_ElementType FreeFaces::GetType() const
2762 return SMDSAbs_Face;
2765 //================================================================================
2767 Class : LinearOrQuadratic
2768 Description : Predicate to verify whether a mesh element is linear
2770 //================================================================================
2772 LinearOrQuadratic::LinearOrQuadratic()
2777 void LinearOrQuadratic::SetMesh( const SMDS_Mesh* theMesh )
2782 bool LinearOrQuadratic::IsSatisfy( long theId )
2784 if (!myMesh) return false;
2785 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2786 if ( !anElem || (myType != SMDSAbs_All && anElem->GetType() != myType) )
2788 return (!anElem->IsQuadratic());
2791 void LinearOrQuadratic::SetType( SMDSAbs_ElementType theType )
2796 SMDSAbs_ElementType LinearOrQuadratic::GetType() const
2801 //================================================================================
2804 Description : Functor for check color of group to which mesh element belongs to
2806 //================================================================================
2808 GroupColor::GroupColor()
2812 bool GroupColor::IsSatisfy( long theId )
2814 return myIDs.count( theId );
2817 void GroupColor::SetType( SMDSAbs_ElementType theType )
2822 SMDSAbs_ElementType GroupColor::GetType() const
2827 static bool isEqual( const Quantity_Color& theColor1,
2828 const Quantity_Color& theColor2 )
2830 // tolerance to compare colors
2831 const double tol = 5*1e-3;
2832 return ( fabs( theColor1.Red() - theColor2.Red() ) < tol &&
2833 fabs( theColor1.Green() - theColor2.Green() ) < tol &&
2834 fabs( theColor1.Blue() - theColor2.Blue() ) < tol );
2837 void GroupColor::SetMesh( const SMDS_Mesh* theMesh )
2841 const SMESHDS_Mesh* aMesh = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
2845 int nbGrp = aMesh->GetNbGroups();
2849 // iterates on groups and find necessary elements ids
2850 const std::set<SMESHDS_GroupBase*>& aGroups = aMesh->GetGroups();
2851 std::set<SMESHDS_GroupBase*>::const_iterator GrIt = aGroups.begin();
2852 for (; GrIt != aGroups.end(); GrIt++)
2854 SMESHDS_GroupBase* aGrp = (*GrIt);
2857 // check type and color of group
2858 if ( !isEqual( myColor, aGrp->GetColor() ))
2861 // IPAL52867 (prevent infinite recursion via GroupOnFilter)
2862 if ( SMESHDS_GroupOnFilter * gof = dynamic_cast< SMESHDS_GroupOnFilter* >( aGrp ))
2863 if ( gof->GetPredicate().get() == this )
2866 SMDSAbs_ElementType aGrpElType = (SMDSAbs_ElementType)aGrp->GetType();
2867 if ( myType == aGrpElType || (myType == SMDSAbs_All && aGrpElType != SMDSAbs_Node) ) {
2868 // add elements IDS into control
2869 int aSize = aGrp->Extent();
2870 for (int i = 0; i < aSize; i++)
2871 myIDs.insert( aGrp->GetID(i+1) );
2876 void GroupColor::SetColorStr( const TCollection_AsciiString& theStr )
2878 Kernel_Utils::Localizer loc;
2879 TCollection_AsciiString aStr = theStr;
2880 aStr.RemoveAll( ' ' );
2881 aStr.RemoveAll( '\t' );
2882 for ( int aPos = aStr.Search( ";;" ); aPos != -1; aPos = aStr.Search( ";;" ) )
2883 aStr.Remove( aPos, 2 );
2884 Standard_Real clr[3];
2885 clr[0] = clr[1] = clr[2] = 0.;
2886 for ( int i = 0; i < 3; i++ ) {
2887 TCollection_AsciiString tmpStr = aStr.Token( ";", i+1 );
2888 if ( !tmpStr.IsEmpty() && tmpStr.IsRealValue() )
2889 clr[i] = tmpStr.RealValue();
2891 myColor = Quantity_Color( clr[0], clr[1], clr[2], Quantity_TOC_RGB );
2894 //=======================================================================
2895 // name : GetRangeStr
2896 // Purpose : Get range as a string.
2897 // Example: "1,2,3,50-60,63,67,70-"
2898 //=======================================================================
2900 void GroupColor::GetColorStr( TCollection_AsciiString& theResStr ) const
2903 theResStr += TCollection_AsciiString( myColor.Red() );
2904 theResStr += TCollection_AsciiString( ";" ) + TCollection_AsciiString( myColor.Green() );
2905 theResStr += TCollection_AsciiString( ";" ) + TCollection_AsciiString( myColor.Blue() );
2908 //================================================================================
2910 Class : ElemGeomType
2911 Description : Predicate to check element geometry type
2913 //================================================================================
2915 ElemGeomType::ElemGeomType()
2918 myType = SMDSAbs_All;
2919 myGeomType = SMDSGeom_TRIANGLE;
2922 void ElemGeomType::SetMesh( const SMDS_Mesh* theMesh )
2927 bool ElemGeomType::IsSatisfy( long theId )
2929 if (!myMesh) return false;
2930 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2933 const SMDSAbs_ElementType anElemType = anElem->GetType();
2934 if ( myType != SMDSAbs_All && anElemType != myType )
2936 bool isOk = ( anElem->GetGeomType() == myGeomType );
2940 void ElemGeomType::SetType( SMDSAbs_ElementType theType )
2945 SMDSAbs_ElementType ElemGeomType::GetType() const
2950 void ElemGeomType::SetGeomType( SMDSAbs_GeometryType theType )
2952 myGeomType = theType;
2955 SMDSAbs_GeometryType ElemGeomType::GetGeomType() const
2960 //================================================================================
2962 Class : ElemEntityType
2963 Description : Predicate to check element entity type
2965 //================================================================================
2967 ElemEntityType::ElemEntityType():
2969 myType( SMDSAbs_All ),
2970 myEntityType( SMDSEntity_0D )
2974 void ElemEntityType::SetMesh( const SMDS_Mesh* theMesh )
2979 bool ElemEntityType::IsSatisfy( long theId )
2981 if ( !myMesh ) return false;
2982 if ( myType == SMDSAbs_Node )
2983 return myMesh->FindNode( theId );
2984 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2986 myEntityType == anElem->GetEntityType() );
2989 void ElemEntityType::SetType( SMDSAbs_ElementType theType )
2994 SMDSAbs_ElementType ElemEntityType::GetType() const
2999 void ElemEntityType::SetElemEntityType( SMDSAbs_EntityType theEntityType )
3001 myEntityType = theEntityType;
3004 SMDSAbs_EntityType ElemEntityType::GetElemEntityType() const
3006 return myEntityType;
3009 //================================================================================
3011 * \brief Class ConnectedElements
3013 //================================================================================
3015 ConnectedElements::ConnectedElements():
3016 myNodeID(0), myType( SMDSAbs_All ), myOkIDsReady( false ) {}
3018 SMDSAbs_ElementType ConnectedElements::GetType() const
3021 int ConnectedElements::GetNode() const
3022 { return myXYZ.empty() ? myNodeID : 0; } // myNodeID can be found by myXYZ
3024 std::vector<double> ConnectedElements::GetPoint() const
3027 void ConnectedElements::clearOkIDs()
3028 { myOkIDsReady = false; myOkIDs.clear(); }
3030 void ConnectedElements::SetType( SMDSAbs_ElementType theType )
3032 if ( myType != theType || myMeshModifTracer.IsMeshModified() )
3037 void ConnectedElements::SetMesh( const SMDS_Mesh* theMesh )
3039 myMeshModifTracer.SetMesh( theMesh );
3040 if ( myMeshModifTracer.IsMeshModified() )
3043 if ( !myXYZ.empty() )
3044 SetPoint( myXYZ[0], myXYZ[1], myXYZ[2] ); // find a node near myXYZ it in a new mesh
3048 void ConnectedElements::SetNode( int nodeID )
3053 bool isSameDomain = false;
3054 if ( myOkIDsReady && myMeshModifTracer.GetMesh() && !myMeshModifTracer.IsMeshModified() )
3055 if ( const SMDS_MeshNode* n = myMeshModifTracer.GetMesh()->FindNode( myNodeID ))
3057 SMDS_ElemIteratorPtr eIt = n->GetInverseElementIterator( myType );
3058 while ( !isSameDomain && eIt->more() )
3059 isSameDomain = IsSatisfy( eIt->next()->GetID() );
3061 if ( !isSameDomain )
3065 void ConnectedElements::SetPoint( double x, double y, double z )
3073 bool isSameDomain = false;
3075 // find myNodeID by myXYZ if possible
3076 if ( myMeshModifTracer.GetMesh() )
3078 SMESHUtils::Deleter<SMESH_ElementSearcher> searcher
3079 ( SMESH_MeshAlgos::GetElementSearcher( (SMDS_Mesh&) *myMeshModifTracer.GetMesh() ));
3081 std::vector< const SMDS_MeshElement* > foundElems;
3082 searcher->FindElementsByPoint( gp_Pnt(x,y,z), SMDSAbs_All, foundElems );
3084 if ( !foundElems.empty() )
3086 myNodeID = foundElems[0]->GetNode(0)->GetID();
3087 if ( myOkIDsReady && !myMeshModifTracer.IsMeshModified() )
3088 isSameDomain = IsSatisfy( foundElems[0]->GetID() );
3091 if ( !isSameDomain )
3095 bool ConnectedElements::IsSatisfy( long theElementId )
3097 // Here we do NOT check if the mesh has changed, we do it in Set...() only!!!
3099 if ( !myOkIDsReady )
3101 if ( !myMeshModifTracer.GetMesh() )
3103 const SMDS_MeshNode* node0 = myMeshModifTracer.GetMesh()->FindNode( myNodeID );
3107 std::list< const SMDS_MeshNode* > nodeQueue( 1, node0 );
3108 std::set< int > checkedNodeIDs;
3110 // foreach node in nodeQueue:
3111 // foreach element sharing a node:
3112 // add ID of an element of myType to myOkIDs;
3113 // push all element nodes absent from checkedNodeIDs to nodeQueue;
3114 while ( !nodeQueue.empty() )
3116 const SMDS_MeshNode* node = nodeQueue.front();
3117 nodeQueue.pop_front();
3119 // loop on elements sharing the node
3120 SMDS_ElemIteratorPtr eIt = node->GetInverseElementIterator();
3121 while ( eIt->more() )
3123 // keep elements of myType
3124 const SMDS_MeshElement* element = eIt->next();
3125 if ( myType == SMDSAbs_All || element->GetType() == myType )
3126 myOkIDs.insert( myOkIDs.end(), element->GetID() );
3128 // enqueue nodes of the element
3129 SMDS_ElemIteratorPtr nIt = element->nodesIterator();
3130 while ( nIt->more() )
3132 const SMDS_MeshNode* n = static_cast< const SMDS_MeshNode* >( nIt->next() );
3133 if ( checkedNodeIDs.insert( n->GetID() ).second )
3134 nodeQueue.push_back( n );
3138 if ( myType == SMDSAbs_Node )
3139 std::swap( myOkIDs, checkedNodeIDs );
3141 size_t totalNbElems = myMeshModifTracer.GetMesh()->GetMeshInfo().NbElements( myType );
3142 if ( myOkIDs.size() == totalNbElems )
3145 myOkIDsReady = true;
3148 return myOkIDs.empty() ? true : myOkIDs.count( theElementId );
3151 //================================================================================
3153 * \brief Class CoplanarFaces
3155 //================================================================================
3159 inline bool isLessAngle( const gp_Vec& v1, const gp_Vec& v2, const double cos )
3161 double dot = v1 * v2; // cos * |v1| * |v2|
3162 double l1 = v1.SquareMagnitude();
3163 double l2 = v2.SquareMagnitude();
3164 return (( dot * cos >= 0 ) &&
3165 ( dot * dot ) / l1 / l2 >= ( cos * cos ));
3168 CoplanarFaces::CoplanarFaces()
3169 : myFaceID(0), myToler(0)
3172 void CoplanarFaces::SetMesh( const SMDS_Mesh* theMesh )
3174 myMeshModifTracer.SetMesh( theMesh );
3175 if ( myMeshModifTracer.IsMeshModified() )
3177 // Build a set of coplanar face ids
3179 myCoplanarIDs.Clear();
3181 if ( !myMeshModifTracer.GetMesh() || !myFaceID || !myToler )
3184 const SMDS_MeshElement* face = myMeshModifTracer.GetMesh()->FindElement( myFaceID );
3185 if ( !face || face->GetType() != SMDSAbs_Face )
3189 gp_Vec myNorm = getNormale( static_cast<const SMDS_MeshFace*>(face), &normOK );
3193 const double cosTol = Cos( myToler * M_PI / 180. );
3194 NCollection_Map< SMESH_TLink, SMESH_TLink > checkedLinks;
3196 std::list< std::pair< const SMDS_MeshElement*, gp_Vec > > faceQueue;
3197 faceQueue.push_back( std::make_pair( face, myNorm ));
3198 while ( !faceQueue.empty() )
3200 face = faceQueue.front().first;
3201 myNorm = faceQueue.front().second;
3202 faceQueue.pop_front();
3204 for ( int i = 0, nbN = face->NbCornerNodes(); i < nbN; ++i )
3206 const SMDS_MeshNode* n1 = face->GetNode( i );
3207 const SMDS_MeshNode* n2 = face->GetNode(( i+1 )%nbN);
3208 if ( !checkedLinks.Add( SMESH_TLink( n1, n2 )))
3210 SMDS_ElemIteratorPtr fIt = n1->GetInverseElementIterator(SMDSAbs_Face);
3211 while ( fIt->more() )
3213 const SMDS_MeshElement* f = fIt->next();
3214 if ( f->GetNodeIndex( n2 ) > -1 )
3216 gp_Vec norm = getNormale( static_cast<const SMDS_MeshFace*>(f), &normOK );
3217 if (!normOK || isLessAngle( myNorm, norm, cosTol))
3219 myCoplanarIDs.Add( f->GetID() );
3220 faceQueue.push_back( std::make_pair( f, norm ));
3228 bool CoplanarFaces::IsSatisfy( long theElementId )
3230 return myCoplanarIDs.Contains( theElementId );
3235 *Description : Predicate for Range of Ids.
3236 * Range may be specified with two ways.
3237 * 1. Using AddToRange method
3238 * 2. With SetRangeStr method. Parameter of this method is a string
3239 * like as "1,2,3,50-60,63,67,70-"
3242 //=======================================================================
3243 // name : RangeOfIds
3244 // Purpose : Constructor
3245 //=======================================================================
3246 RangeOfIds::RangeOfIds()
3249 myType = SMDSAbs_All;
3252 //=======================================================================
3254 // Purpose : Set mesh
3255 //=======================================================================
3256 void RangeOfIds::SetMesh( const SMDS_Mesh* theMesh )
3261 //=======================================================================
3262 // name : AddToRange
3263 // Purpose : Add ID to the range
3264 //=======================================================================
3265 bool RangeOfIds::AddToRange( long theEntityId )
3267 myIds.Add( theEntityId );
3271 //=======================================================================
3272 // name : GetRangeStr
3273 // Purpose : Get range as a string.
3274 // Example: "1,2,3,50-60,63,67,70-"
3275 //=======================================================================
3276 void RangeOfIds::GetRangeStr( TCollection_AsciiString& theResStr )
3280 TColStd_SequenceOfInteger anIntSeq;
3281 TColStd_SequenceOfAsciiString aStrSeq;
3283 TColStd_MapIteratorOfMapOfInteger anIter( myIds );
3284 for ( ; anIter.More(); anIter.Next() )
3286 int anId = anIter.Key();
3287 TCollection_AsciiString aStr( anId );
3288 anIntSeq.Append( anId );
3289 aStrSeq.Append( aStr );
3292 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
3294 int aMinId = myMin( i );
3295 int aMaxId = myMax( i );
3297 TCollection_AsciiString aStr;
3298 if ( aMinId != IntegerFirst() )
3303 if ( aMaxId != IntegerLast() )
3306 // find position of the string in result sequence and insert string in it
3307 if ( anIntSeq.Length() == 0 )
3309 anIntSeq.Append( aMinId );
3310 aStrSeq.Append( aStr );
3314 if ( aMinId < anIntSeq.First() )
3316 anIntSeq.Prepend( aMinId );
3317 aStrSeq.Prepend( aStr );
3319 else if ( aMinId > anIntSeq.Last() )
3321 anIntSeq.Append( aMinId );
3322 aStrSeq.Append( aStr );
3325 for ( int j = 1, k = anIntSeq.Length(); j <= k; j++ )
3326 if ( aMinId < anIntSeq( j ) )
3328 anIntSeq.InsertBefore( j, aMinId );
3329 aStrSeq.InsertBefore( j, aStr );
3335 if ( aStrSeq.Length() == 0 )
3338 theResStr = aStrSeq( 1 );
3339 for ( int j = 2, k = aStrSeq.Length(); j <= k; j++ )
3342 theResStr += aStrSeq( j );
3346 //=======================================================================
3347 // name : SetRangeStr
3348 // Purpose : Define range with string
3349 // Example of entry string: "1,2,3,50-60,63,67,70-"
3350 //=======================================================================
3351 bool RangeOfIds::SetRangeStr( const TCollection_AsciiString& theStr )
3357 TCollection_AsciiString aStr = theStr;
3358 for ( int i = 1; i <= aStr.Length(); ++i )
3360 char c = aStr.Value( i );
3361 if ( !isdigit( c ) && c != ',' && c != '-' )
3362 aStr.SetValue( i, ',');
3364 aStr.RemoveAll( ' ' );
3366 TCollection_AsciiString tmpStr = aStr.Token( ",", 1 );
3368 while ( tmpStr != "" )
3370 tmpStr = aStr.Token( ",", i++ );
3371 int aPos = tmpStr.Search( '-' );
3375 if ( tmpStr.IsIntegerValue() )
3376 myIds.Add( tmpStr.IntegerValue() );
3382 TCollection_AsciiString aMaxStr = tmpStr.Split( aPos );
3383 TCollection_AsciiString aMinStr = tmpStr;
3385 while ( aMinStr.Search( "-" ) != -1 ) aMinStr.RemoveAll( '-' );
3386 while ( aMaxStr.Search( "-" ) != -1 ) aMaxStr.RemoveAll( '-' );
3388 if ( (!aMinStr.IsEmpty() && !aMinStr.IsIntegerValue()) ||
3389 (!aMaxStr.IsEmpty() && !aMaxStr.IsIntegerValue()) )
3392 myMin.Append( aMinStr.IsEmpty() ? IntegerFirst() : aMinStr.IntegerValue() );
3393 myMax.Append( aMaxStr.IsEmpty() ? IntegerLast() : aMaxStr.IntegerValue() );
3400 //=======================================================================
3402 // Purpose : Get type of supported entities
3403 //=======================================================================
3404 SMDSAbs_ElementType RangeOfIds::GetType() const
3409 //=======================================================================
3411 // Purpose : Set type of supported entities
3412 //=======================================================================
3413 void RangeOfIds::SetType( SMDSAbs_ElementType theType )
3418 //=======================================================================
3420 // Purpose : Verify whether entity satisfies to this rpedicate
3421 //=======================================================================
3422 bool RangeOfIds::IsSatisfy( long theId )
3427 if ( myType == SMDSAbs_Node )
3429 if ( myMesh->FindNode( theId ) == 0 )
3434 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
3435 if ( anElem == 0 || (myType != anElem->GetType() && myType != SMDSAbs_All ))
3439 if ( myIds.Contains( theId ) )
3442 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
3443 if ( theId >= myMin( i ) && theId <= myMax( i ) )
3451 Description : Base class for comparators
3453 Comparator::Comparator():
3457 Comparator::~Comparator()
3460 void Comparator::SetMesh( const SMDS_Mesh* theMesh )
3463 myFunctor->SetMesh( theMesh );
3466 void Comparator::SetMargin( double theValue )
3468 myMargin = theValue;
3471 void Comparator::SetNumFunctor( NumericalFunctorPtr theFunct )
3473 myFunctor = theFunct;
3476 SMDSAbs_ElementType Comparator::GetType() const
3478 return myFunctor ? myFunctor->GetType() : SMDSAbs_All;
3481 double Comparator::GetMargin()
3489 Description : Comparator "<"
3491 bool LessThan::IsSatisfy( long theId )
3493 return myFunctor && myFunctor->GetValue( theId ) < myMargin;
3499 Description : Comparator ">"
3501 bool MoreThan::IsSatisfy( long theId )
3503 return myFunctor && myFunctor->GetValue( theId ) > myMargin;
3509 Description : Comparator "="
3512 myToler(Precision::Confusion())
3515 bool EqualTo::IsSatisfy( long theId )
3517 return myFunctor && fabs( myFunctor->GetValue( theId ) - myMargin ) < myToler;
3520 void EqualTo::SetTolerance( double theToler )
3525 double EqualTo::GetTolerance()
3532 Description : Logical NOT predicate
3534 LogicalNOT::LogicalNOT()
3537 LogicalNOT::~LogicalNOT()
3540 bool LogicalNOT::IsSatisfy( long theId )
3542 return myPredicate && !myPredicate->IsSatisfy( theId );
3545 void LogicalNOT::SetMesh( const SMDS_Mesh* theMesh )
3548 myPredicate->SetMesh( theMesh );
3551 void LogicalNOT::SetPredicate( PredicatePtr thePred )
3553 myPredicate = thePred;
3556 SMDSAbs_ElementType LogicalNOT::GetType() const
3558 return myPredicate ? myPredicate->GetType() : SMDSAbs_All;
3563 Class : LogicalBinary
3564 Description : Base class for binary logical predicate
3566 LogicalBinary::LogicalBinary()
3569 LogicalBinary::~LogicalBinary()
3572 void LogicalBinary::SetMesh( const SMDS_Mesh* theMesh )
3575 myPredicate1->SetMesh( theMesh );
3578 myPredicate2->SetMesh( theMesh );
3581 void LogicalBinary::SetPredicate1( PredicatePtr thePredicate )
3583 myPredicate1 = thePredicate;
3586 void LogicalBinary::SetPredicate2( PredicatePtr thePredicate )
3588 myPredicate2 = thePredicate;
3591 SMDSAbs_ElementType LogicalBinary::GetType() const
3593 if ( !myPredicate1 || !myPredicate2 )
3596 SMDSAbs_ElementType aType1 = myPredicate1->GetType();
3597 SMDSAbs_ElementType aType2 = myPredicate2->GetType();
3599 return aType1 == aType2 ? aType1 : SMDSAbs_All;
3605 Description : Logical AND
3607 bool LogicalAND::IsSatisfy( long theId )
3612 myPredicate1->IsSatisfy( theId ) &&
3613 myPredicate2->IsSatisfy( theId );
3619 Description : Logical OR
3621 bool LogicalOR::IsSatisfy( long theId )
3626 (myPredicate1->IsSatisfy( theId ) ||
3627 myPredicate2->IsSatisfy( theId ));
3636 // #include <tbb/parallel_for.h>
3637 // #include <tbb/enumerable_thread_specific.h>
3639 // namespace Parallel
3641 // typedef tbb::enumerable_thread_specific< TIdSequence > TIdSeq;
3645 // const SMDS_Mesh* myMesh;
3646 // PredicatePtr myPredicate;
3647 // TIdSeq & myOKIds;
3648 // Predicate( const SMDS_Mesh* m, PredicatePtr p, TIdSeq & ids ):
3649 // myMesh(m), myPredicate(p->Duplicate()), myOKIds(ids) {}
3650 // void operator() ( const tbb::blocked_range<size_t>& r ) const
3652 // for ( size_t i = r.begin(); i != r.end(); ++i )
3653 // if ( myPredicate->IsSatisfy( i ))
3654 // myOKIds.local().push_back();
3666 void Filter::SetPredicate( PredicatePtr thePredicate )
3668 myPredicate = thePredicate;
3671 void Filter::GetElementsId( const SMDS_Mesh* theMesh,
3672 PredicatePtr thePredicate,
3673 TIdSequence& theSequence,
3674 SMDS_ElemIteratorPtr theElements )
3676 theSequence.clear();
3678 if ( !theMesh || !thePredicate )
3681 thePredicate->SetMesh( theMesh );
3684 theElements = theMesh->elementsIterator( thePredicate->GetType() );
3686 if ( theElements ) {
3687 while ( theElements->more() ) {
3688 const SMDS_MeshElement* anElem = theElements->next();
3689 if ( thePredicate->GetType() == SMDSAbs_All ||
3690 thePredicate->GetType() == anElem->GetType() )
3692 long anId = anElem->GetID();
3693 if ( thePredicate->IsSatisfy( anId ) )
3694 theSequence.push_back( anId );
3700 void Filter::GetElementsId( const SMDS_Mesh* theMesh,
3701 Filter::TIdSequence& theSequence,
3702 SMDS_ElemIteratorPtr theElements )
3704 GetElementsId(theMesh,myPredicate,theSequence,theElements);
3711 typedef std::set<SMDS_MeshFace*> TMapOfFacePtr;
3717 ManifoldPart::Link::Link( SMDS_MeshNode* theNode1,
3718 SMDS_MeshNode* theNode2 )
3724 ManifoldPart::Link::~Link()
3730 bool ManifoldPart::Link::IsEqual( const ManifoldPart::Link& theLink ) const
3732 if ( myNode1 == theLink.myNode1 &&
3733 myNode2 == theLink.myNode2 )
3735 else if ( myNode1 == theLink.myNode2 &&
3736 myNode2 == theLink.myNode1 )
3742 bool ManifoldPart::Link::operator<( const ManifoldPart::Link& x ) const
3744 if(myNode1 < x.myNode1) return true;
3745 if(myNode1 == x.myNode1)
3746 if(myNode2 < x.myNode2) return true;
3750 bool ManifoldPart::IsEqual( const ManifoldPart::Link& theLink1,
3751 const ManifoldPart::Link& theLink2 )
3753 return theLink1.IsEqual( theLink2 );
3756 ManifoldPart::ManifoldPart()
3759 myAngToler = Precision::Angular();
3760 myIsOnlyManifold = true;
3763 ManifoldPart::~ManifoldPart()
3768 void ManifoldPart::SetMesh( const SMDS_Mesh* theMesh )
3774 SMDSAbs_ElementType ManifoldPart::GetType() const
3775 { return SMDSAbs_Face; }
3777 bool ManifoldPart::IsSatisfy( long theElementId )
3779 return myMapIds.Contains( theElementId );
3782 void ManifoldPart::SetAngleTolerance( const double theAngToler )
3783 { myAngToler = theAngToler; }
3785 double ManifoldPart::GetAngleTolerance() const
3786 { return myAngToler; }
3788 void ManifoldPart::SetIsOnlyManifold( const bool theIsOnly )
3789 { myIsOnlyManifold = theIsOnly; }
3791 void ManifoldPart::SetStartElem( const long theStartId )
3792 { myStartElemId = theStartId; }
3794 bool ManifoldPart::process()
3797 myMapBadGeomIds.Clear();
3799 myAllFacePtr.clear();
3800 myAllFacePtrIntDMap.clear();
3804 // collect all faces into own map
3805 SMDS_FaceIteratorPtr anFaceItr = myMesh->facesIterator();
3806 for (; anFaceItr->more(); )
3808 SMDS_MeshFace* aFacePtr = (SMDS_MeshFace*)anFaceItr->next();
3809 myAllFacePtr.push_back( aFacePtr );
3810 myAllFacePtrIntDMap[aFacePtr] = myAllFacePtr.size()-1;
3813 SMDS_MeshFace* aStartFace = (SMDS_MeshFace*)myMesh->FindElement( myStartElemId );
3817 // the map of non manifold links and bad geometry
3818 TMapOfLink aMapOfNonManifold;
3819 TColStd_MapOfInteger aMapOfTreated;
3821 // begin cycle on faces from start index and run on vector till the end
3822 // and from begin to start index to cover whole vector
3823 const int aStartIndx = myAllFacePtrIntDMap[aStartFace];
3824 bool isStartTreat = false;
3825 for ( int fi = aStartIndx; !isStartTreat || fi != aStartIndx ; fi++ )
3827 if ( fi == aStartIndx )
3828 isStartTreat = true;
3829 // as result next time when fi will be equal to aStartIndx
3831 SMDS_MeshFace* aFacePtr = myAllFacePtr[ fi ];
3832 if ( aMapOfTreated.Contains( aFacePtr->GetID() ) )
3835 aMapOfTreated.Add( aFacePtr->GetID() );
3836 TColStd_MapOfInteger aResFaces;
3837 if ( !findConnected( myAllFacePtrIntDMap, aFacePtr,
3838 aMapOfNonManifold, aResFaces ) )
3840 TColStd_MapIteratorOfMapOfInteger anItr( aResFaces );
3841 for ( ; anItr.More(); anItr.Next() )
3843 int aFaceId = anItr.Key();
3844 aMapOfTreated.Add( aFaceId );
3845 myMapIds.Add( aFaceId );
3848 if ( fi == int( myAllFacePtr.size() - 1 ))
3850 } // end run on vector of faces
3851 return !myMapIds.IsEmpty();
3854 static void getLinks( const SMDS_MeshFace* theFace,
3855 ManifoldPart::TVectorOfLink& theLinks )
3857 int aNbNode = theFace->NbNodes();
3858 SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
3860 SMDS_MeshNode* aNode = 0;
3861 for ( ; aNodeItr->more() && i <= aNbNode; )
3864 SMDS_MeshNode* aN1 = (SMDS_MeshNode*)aNodeItr->next();
3868 SMDS_MeshNode* aN2 = ( i >= aNbNode ) ? aNode : (SMDS_MeshNode*)aNodeItr->next();
3870 ManifoldPart::Link aLink( aN1, aN2 );
3871 theLinks.push_back( aLink );
3875 bool ManifoldPart::findConnected
3876 ( const ManifoldPart::TDataMapFacePtrInt& theAllFacePtrInt,
3877 SMDS_MeshFace* theStartFace,
3878 ManifoldPart::TMapOfLink& theNonManifold,
3879 TColStd_MapOfInteger& theResFaces )
3881 theResFaces.Clear();
3882 if ( !theAllFacePtrInt.size() )
3885 if ( getNormale( theStartFace ).SquareModulus() <= gp::Resolution() )
3887 myMapBadGeomIds.Add( theStartFace->GetID() );
3891 ManifoldPart::TMapOfLink aMapOfBoundary, aMapToSkip;
3892 ManifoldPart::TVectorOfLink aSeqOfBoundary;
3893 theResFaces.Add( theStartFace->GetID() );
3894 ManifoldPart::TDataMapOfLinkFacePtr aDMapLinkFace;
3896 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
3897 aDMapLinkFace, theNonManifold, theStartFace );
3899 bool isDone = false;
3900 while ( !isDone && aMapOfBoundary.size() != 0 )
3902 bool isToReset = false;
3903 ManifoldPart::TVectorOfLink::iterator pLink = aSeqOfBoundary.begin();
3904 for ( ; !isToReset && pLink != aSeqOfBoundary.end(); ++pLink )
3906 ManifoldPart::Link aLink = *pLink;
3907 if ( aMapToSkip.find( aLink ) != aMapToSkip.end() )
3909 // each link could be treated only once
3910 aMapToSkip.insert( aLink );
3912 ManifoldPart::TVectorOfFacePtr aFaces;
3914 if ( myIsOnlyManifold &&
3915 (theNonManifold.find( aLink ) != theNonManifold.end()) )
3919 getFacesByLink( aLink, aFaces );
3920 // filter the element to keep only indicated elements
3921 ManifoldPart::TVectorOfFacePtr aFiltered;
3922 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
3923 for ( ; pFace != aFaces.end(); ++pFace )
3925 SMDS_MeshFace* aFace = *pFace;
3926 if ( myAllFacePtrIntDMap.find( aFace ) != myAllFacePtrIntDMap.end() )
3927 aFiltered.push_back( aFace );
3930 if ( aFaces.size() < 2 ) // no neihgbour faces
3932 else if ( myIsOnlyManifold && aFaces.size() > 2 ) // non manifold case
3934 theNonManifold.insert( aLink );
3939 // compare normal with normals of neighbor element
3940 SMDS_MeshFace* aPrevFace = aDMapLinkFace[ aLink ];
3941 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
3942 for ( ; pFace != aFaces.end(); ++pFace )
3944 SMDS_MeshFace* aNextFace = *pFace;
3945 if ( aPrevFace == aNextFace )
3947 int anNextFaceID = aNextFace->GetID();
3948 if ( myIsOnlyManifold && theResFaces.Contains( anNextFaceID ) )
3949 // should not be with non manifold restriction. probably bad topology
3951 // check if face was treated and skipped
3952 if ( myMapBadGeomIds.Contains( anNextFaceID ) ||
3953 !isInPlane( aPrevFace, aNextFace ) )
3955 // add new element to connected and extend the boundaries.
3956 theResFaces.Add( anNextFaceID );
3957 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
3958 aDMapLinkFace, theNonManifold, aNextFace );
3962 isDone = !isToReset;
3965 return !theResFaces.IsEmpty();
3968 bool ManifoldPart::isInPlane( const SMDS_MeshFace* theFace1,
3969 const SMDS_MeshFace* theFace2 )
3971 gp_Dir aNorm1 = gp_Dir( getNormale( theFace1 ) );
3972 gp_XYZ aNorm2XYZ = getNormale( theFace2 );
3973 if ( aNorm2XYZ.SquareModulus() <= gp::Resolution() )
3975 myMapBadGeomIds.Add( theFace2->GetID() );
3978 if ( aNorm1.IsParallel( gp_Dir( aNorm2XYZ ), myAngToler ) )
3984 void ManifoldPart::expandBoundary
3985 ( ManifoldPart::TMapOfLink& theMapOfBoundary,
3986 ManifoldPart::TVectorOfLink& theSeqOfBoundary,
3987 ManifoldPart::TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
3988 ManifoldPart::TMapOfLink& theNonManifold,
3989 SMDS_MeshFace* theNextFace ) const
3991 ManifoldPart::TVectorOfLink aLinks;
3992 getLinks( theNextFace, aLinks );
3993 int aNbLink = (int)aLinks.size();
3994 for ( int i = 0; i < aNbLink; i++ )
3996 ManifoldPart::Link aLink = aLinks[ i ];
3997 if ( myIsOnlyManifold && (theNonManifold.find( aLink ) != theNonManifold.end()) )
3999 if ( theMapOfBoundary.find( aLink ) != theMapOfBoundary.end() )
4001 if ( myIsOnlyManifold )
4003 // remove from boundary
4004 theMapOfBoundary.erase( aLink );
4005 ManifoldPart::TVectorOfLink::iterator pLink = theSeqOfBoundary.begin();
4006 for ( ; pLink != theSeqOfBoundary.end(); ++pLink )
4008 ManifoldPart::Link aBoundLink = *pLink;
4009 if ( aBoundLink.IsEqual( aLink ) )
4011 theSeqOfBoundary.erase( pLink );
4019 theMapOfBoundary.insert( aLink );
4020 theSeqOfBoundary.push_back( aLink );
4021 theDMapLinkFacePtr[ aLink ] = theNextFace;
4026 void ManifoldPart::getFacesByLink( const ManifoldPart::Link& theLink,
4027 ManifoldPart::TVectorOfFacePtr& theFaces ) const
4030 // take all faces that shared first node
4031 SMDS_ElemIteratorPtr anItr = theLink.myNode1->GetInverseElementIterator( SMDSAbs_Face );
4032 SMDS_StdIterator< const SMDS_MeshElement*, SMDS_ElemIteratorPtr > faces( anItr ), facesEnd;
4033 std::set<const SMDS_MeshElement *> aSetOfFaces( faces, facesEnd );
4035 // take all faces that shared second node
4036 anItr = theLink.myNode2->GetInverseElementIterator( SMDSAbs_Face );
4037 // find the common part of two sets
4038 for ( ; anItr->more(); )
4040 const SMDS_MeshElement* aFace = anItr->next();
4041 if ( aSetOfFaces.count( aFace ))
4042 theFaces.push_back( (SMDS_MeshFace*) aFace );
4047 Class : BelongToMeshGroup
4048 Description : Verify whether a mesh element is included into a mesh group
4050 BelongToMeshGroup::BelongToMeshGroup(): myGroup( 0 )
4054 void BelongToMeshGroup::SetGroup( SMESHDS_GroupBase* g )
4059 void BelongToMeshGroup::SetStoreName( const std::string& sn )
4064 void BelongToMeshGroup::SetMesh( const SMDS_Mesh* theMesh )
4066 if ( myGroup && myGroup->GetMesh() != theMesh )
4070 if ( !myGroup && !myStoreName.empty() )
4072 if ( const SMESHDS_Mesh* aMesh = dynamic_cast<const SMESHDS_Mesh*>(theMesh))
4074 const std::set<SMESHDS_GroupBase*>& grps = aMesh->GetGroups();
4075 std::set<SMESHDS_GroupBase*>::const_iterator g = grps.begin();
4076 for ( ; g != grps.end() && !myGroup; ++g )
4077 if ( *g && myStoreName == (*g)->GetStoreName() )
4083 myGroup->IsEmpty(); // make GroupOnFilter update its predicate
4087 bool BelongToMeshGroup::IsSatisfy( long theElementId )
4089 return myGroup ? myGroup->Contains( theElementId ) : false;
4092 SMDSAbs_ElementType BelongToMeshGroup::GetType() const
4094 return myGroup ? myGroup->GetType() : SMDSAbs_All;
4097 //================================================================================
4098 // ElementsOnSurface
4099 //================================================================================
4101 ElementsOnSurface::ElementsOnSurface()
4104 myType = SMDSAbs_All;
4106 myToler = Precision::Confusion();
4107 myUseBoundaries = false;
4110 ElementsOnSurface::~ElementsOnSurface()
4114 void ElementsOnSurface::SetMesh( const SMDS_Mesh* theMesh )
4116 myMeshModifTracer.SetMesh( theMesh );
4117 if ( myMeshModifTracer.IsMeshModified())
4121 bool ElementsOnSurface::IsSatisfy( long theElementId )
4123 return myIds.Contains( theElementId );
4126 SMDSAbs_ElementType ElementsOnSurface::GetType() const
4129 void ElementsOnSurface::SetTolerance( const double theToler )
4131 if ( myToler != theToler )
4138 double ElementsOnSurface::GetTolerance() const
4141 void ElementsOnSurface::SetUseBoundaries( bool theUse )
4143 if ( myUseBoundaries != theUse ) {
4144 myUseBoundaries = theUse;
4145 SetSurface( mySurf, myType );
4149 void ElementsOnSurface::SetSurface( const TopoDS_Shape& theShape,
4150 const SMDSAbs_ElementType theType )
4155 if ( theShape.IsNull() || theShape.ShapeType() != TopAbs_FACE )
4157 mySurf = TopoDS::Face( theShape );
4158 BRepAdaptor_Surface SA( mySurf, myUseBoundaries );
4160 u1 = SA.FirstUParameter(),
4161 u2 = SA.LastUParameter(),
4162 v1 = SA.FirstVParameter(),
4163 v2 = SA.LastVParameter();
4164 Handle(Geom_Surface) surf = BRep_Tool::Surface( mySurf );
4165 myProjector.Init( surf, u1,u2, v1,v2 );
4169 void ElementsOnSurface::process()
4172 if ( mySurf.IsNull() )
4175 if ( !myMeshModifTracer.GetMesh() )
4178 myIds.ReSize( myMeshModifTracer.GetMesh()->GetMeshInfo().NbElements( myType ));
4180 SMDS_ElemIteratorPtr anIter = myMeshModifTracer.GetMesh()->elementsIterator( myType );
4181 for(; anIter->more(); )
4182 process( anIter->next() );
4185 void ElementsOnSurface::process( const SMDS_MeshElement* theElemPtr )
4187 SMDS_ElemIteratorPtr aNodeItr = theElemPtr->nodesIterator();
4188 bool isSatisfy = true;
4189 for ( ; aNodeItr->more(); )
4191 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
4192 if ( !isOnSurface( aNode ) )
4199 myIds.Add( theElemPtr->GetID() );
4202 bool ElementsOnSurface::isOnSurface( const SMDS_MeshNode* theNode )
4204 if ( mySurf.IsNull() )
4207 gp_Pnt aPnt( theNode->X(), theNode->Y(), theNode->Z() );
4208 // double aToler2 = myToler * myToler;
4209 // if ( mySurf->IsKind(STANDARD_TYPE(Geom_Plane)))
4211 // gp_Pln aPln = Handle(Geom_Plane)::DownCast(mySurf)->Pln();
4212 // if ( aPln.SquareDistance( aPnt ) > aToler2 )
4215 // else if ( mySurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)))
4217 // gp_Cylinder aCyl = Handle(Geom_CylindricalSurface)::DownCast(mySurf)->Cylinder();
4218 // double aRad = aCyl.Radius();
4219 // gp_Ax3 anAxis = aCyl.Position();
4220 // gp_XYZ aLoc = aCyl.Location().XYZ();
4221 // double aXDist = anAxis.XDirection().XYZ() * ( aPnt.XYZ() - aLoc );
4222 // double aYDist = anAxis.YDirection().XYZ() * ( aPnt.XYZ() - aLoc );
4223 // if ( fabs(aXDist*aXDist + aYDist*aYDist - aRad*aRad) > aToler2 )
4228 myProjector.Perform( aPnt );
4229 bool isOn = ( myProjector.IsDone() && myProjector.LowerDistance() <= myToler );
4235 //================================================================================
4237 //================================================================================
4240 const int theIsCheckedFlag = 0x0000100;
4243 struct ElementsOnShape::Classifier
4245 Classifier() { mySolidClfr = 0; myFlags = 0; }
4247 void Init(const TopoDS_Shape& s, double tol, const Bnd_B3d* box = 0 );
4248 bool IsOut(const gp_Pnt& p) { return SetChecked( true ), (this->*myIsOutFun)( p ); }
4249 TopAbs_ShapeEnum ShapeType() const { return myShape.ShapeType(); }
4250 const TopoDS_Shape& Shape() const { return myShape; }
4251 const Bnd_B3d* GetBndBox() const { return & myBox; }
4252 double Tolerance() const { return myTol; }
4253 bool IsChecked() { return myFlags & theIsCheckedFlag; }
4254 bool IsSetFlag( int flag ) const { return myFlags & flag; }
4255 void SetChecked( bool is ) { is ? SetFlag( theIsCheckedFlag ) : UnsetFlag( theIsCheckedFlag ); }
4256 void SetFlag ( int flag ) { myFlags |= flag; }
4257 void UnsetFlag( int flag ) { myFlags &= ~flag; }
4260 bool isOutOfSolid (const gp_Pnt& p);
4261 bool isOutOfBox (const gp_Pnt& p);
4262 bool isOutOfFace (const gp_Pnt& p);
4263 bool isOutOfEdge (const gp_Pnt& p);
4264 bool isOutOfVertex(const gp_Pnt& p);
4265 bool isOutOfNone (const gp_Pnt& p) { return true; }
4266 bool isBox (const TopoDS_Shape& s);
4268 bool (Classifier::* myIsOutFun)(const gp_Pnt& p);
4269 BRepClass3d_SolidClassifier* mySolidClfr; // ptr because of a run-time forbidden copy-constructor
4271 GeomAPI_ProjectPointOnSurf myProjFace;
4272 GeomAPI_ProjectPointOnCurve myProjEdge;
4274 TopoDS_Shape myShape;
4279 struct ElementsOnShape::OctreeClassifier : public SMESH_Octree
4281 OctreeClassifier( const std::vector< ElementsOnShape::Classifier* >& classifiers );
4282 OctreeClassifier( const OctreeClassifier* otherTree,
4283 const std::vector< ElementsOnShape::Classifier >& clsOther,
4284 std::vector< ElementsOnShape::Classifier >& cls );
4285 void GetClassifiersAtPoint( const gp_XYZ& p,
4286 std::vector< ElementsOnShape::Classifier* >& classifiers );
4290 OctreeClassifier() {}
4291 SMESH_Octree* newChild() const { return new OctreeClassifier; }
4292 void buildChildrenData();
4293 Bnd_B3d* buildRootBox();
4295 std::vector< ElementsOnShape::Classifier* > myClassifiers;
4299 ElementsOnShape::ElementsOnShape():
4301 myType(SMDSAbs_All),
4302 myToler(Precision::Confusion()),
4303 myAllNodesFlag(false)
4307 ElementsOnShape::~ElementsOnShape()
4312 Predicate* ElementsOnShape::clone() const
4314 size_t size = sizeof( *this );
4316 size += myOctree->GetSize();
4317 if ( !myClassifiers.empty() )
4318 size += sizeof( myClassifiers[0] ) * myClassifiers.size();
4319 if ( !myWorkClassifiers.empty() )
4320 size += sizeof( myWorkClassifiers[0] ) * myWorkClassifiers.size();
4321 if ( size > 1e+9 ) // 1G
4324 std::cout << "Avoid ElementsOnShape::clone(), too large: " << size << " bytes " << std::endl;
4329 ElementsOnShape* cln = new ElementsOnShape();
4330 cln->SetAllNodes ( myAllNodesFlag );
4331 cln->SetTolerance( myToler );
4332 cln->SetMesh ( myMeshModifTracer.GetMesh() );
4333 cln->myShape = myShape; // avoid creation of myClassifiers
4334 cln->SetShape ( myShape, myType );
4335 cln->myClassifiers.resize( myClassifiers.size() );
4336 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4337 cln->myClassifiers[ i ].Init( BRepBuilderAPI_Copy( myClassifiers[ i ].Shape()),
4338 myToler, myClassifiers[ i ].GetBndBox() );
4339 if ( myOctree ) // copy myOctree
4341 cln->myOctree = new OctreeClassifier( myOctree, myClassifiers, cln->myClassifiers );
4346 SMDSAbs_ElementType ElementsOnShape::GetType() const
4351 void ElementsOnShape::SetTolerance (const double theToler)
4353 if (myToler != theToler) {
4355 SetShape(myShape, myType);
4359 double ElementsOnShape::GetTolerance() const
4364 void ElementsOnShape::SetAllNodes (bool theAllNodes)
4366 myAllNodesFlag = theAllNodes;
4369 void ElementsOnShape::SetMesh (const SMDS_Mesh* theMesh)
4371 myMeshModifTracer.SetMesh( theMesh );
4372 if ( myMeshModifTracer.IsMeshModified())
4374 size_t nbNodes = theMesh ? theMesh->NbNodes() : 0;
4375 if ( myNodeIsChecked.size() == nbNodes )
4377 std::fill( myNodeIsChecked.begin(), myNodeIsChecked.end(), false );
4381 SMESHUtils::FreeVector( myNodeIsChecked );
4382 SMESHUtils::FreeVector( myNodeIsOut );
4383 myNodeIsChecked.resize( nbNodes, false );
4384 myNodeIsOut.resize( nbNodes );
4389 bool ElementsOnShape::getNodeIsOut( const SMDS_MeshNode* n, bool& isOut )
4391 if ( n->GetID() >= (int) myNodeIsChecked.size() ||
4392 !myNodeIsChecked[ n->GetID() ])
4395 isOut = myNodeIsOut[ n->GetID() ];
4399 void ElementsOnShape::setNodeIsOut( const SMDS_MeshNode* n, bool isOut )
4401 if ( n->GetID() < (int) myNodeIsChecked.size() )
4403 myNodeIsChecked[ n->GetID() ] = true;
4404 myNodeIsOut [ n->GetID() ] = isOut;
4408 void ElementsOnShape::SetShape (const TopoDS_Shape& theShape,
4409 const SMDSAbs_ElementType theType)
4411 bool shapeChanges = ( myShape != theShape );
4414 if ( myShape.IsNull() ) return;
4418 // find most complex shapes
4419 TopTools_IndexedMapOfShape shapesMap;
4420 TopAbs_ShapeEnum shapeTypes[4] = { TopAbs_SOLID, TopAbs_FACE, TopAbs_EDGE, TopAbs_VERTEX };
4421 TopExp_Explorer sub;
4422 for ( int i = 0; i < 4; ++i )
4424 if ( shapesMap.IsEmpty() )
4425 for ( sub.Init( myShape, shapeTypes[i] ); sub.More(); sub.Next() )
4426 shapesMap.Add( sub.Current() );
4428 for ( sub.Init( myShape, shapeTypes[i], shapeTypes[i-1] ); sub.More(); sub.Next() )
4429 shapesMap.Add( sub.Current() );
4433 myClassifiers.resize( shapesMap.Extent() );
4434 for ( int i = 0; i < shapesMap.Extent(); ++i )
4435 myClassifiers[ i ].Init( shapesMap( i+1 ), myToler );
4438 if ( theType == SMDSAbs_Node )
4440 SMESHUtils::FreeVector( myNodeIsChecked );
4441 SMESHUtils::FreeVector( myNodeIsOut );
4445 std::fill( myNodeIsChecked.begin(), myNodeIsChecked.end(), false );
4449 void ElementsOnShape::clearClassifiers()
4451 // for ( size_t i = 0; i < myClassifiers.size(); ++i )
4452 // delete myClassifiers[ i ];
4453 myClassifiers.clear();
4459 bool ElementsOnShape::IsSatisfy( long elemId )
4461 if ( myClassifiers.empty() )
4464 const SMDS_Mesh* mesh = myMeshModifTracer.GetMesh();
4465 if ( myType == SMDSAbs_Node )
4466 return IsSatisfy( mesh->FindNode( elemId ));
4467 return IsSatisfy( mesh->FindElement( elemId ));
4470 bool ElementsOnShape::IsSatisfy (const SMDS_MeshElement* elem)
4475 bool isSatisfy = myAllNodesFlag, isNodeOut;
4477 gp_XYZ centerXYZ (0, 0, 0);
4479 if ( !myOctree && myClassifiers.size() > 5 )
4481 myWorkClassifiers.resize( myClassifiers.size() );
4482 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4483 myWorkClassifiers[ i ] = & myClassifiers[ i ];
4484 myOctree = new OctreeClassifier( myWorkClassifiers );
4486 SMESHUtils::FreeVector( myWorkClassifiers );
4489 for ( int i = 0, nb = elem->NbNodes(); i < nb && (isSatisfy == myAllNodesFlag); ++i )
4491 SMESH_TNodeXYZ aPnt( elem->GetNode( i ));
4495 if ( !getNodeIsOut( aPnt._node, isNodeOut ))
4499 myWorkClassifiers.clear();
4500 myOctree->GetClassifiersAtPoint( aPnt, myWorkClassifiers );
4502 for ( size_t i = 0; i < myWorkClassifiers.size(); ++i )
4503 myWorkClassifiers[i]->SetChecked( false );
4505 for ( size_t i = 0; i < myWorkClassifiers.size() && isNodeOut; ++i )
4506 if ( !myWorkClassifiers[i]->IsChecked() )
4507 isNodeOut = myWorkClassifiers[i]->IsOut( aPnt );
4511 for ( size_t i = 0; i < myClassifiers.size() && isNodeOut; ++i )
4512 isNodeOut = myClassifiers[i].IsOut( aPnt );
4514 setNodeIsOut( aPnt._node, isNodeOut );
4516 isSatisfy = !isNodeOut;
4519 // Check the center point for volumes MantisBug 0020168
4522 myClassifiers[0].ShapeType() == TopAbs_SOLID )
4524 centerXYZ /= elem->NbNodes();
4527 for ( size_t i = 0; i < myWorkClassifiers.size() && !isSatisfy; ++i )
4528 isSatisfy = ! myWorkClassifiers[i]->IsOut( centerXYZ );
4530 for ( size_t i = 0; i < myClassifiers.size() && !isSatisfy; ++i )
4531 isSatisfy = ! myClassifiers[i].IsOut( centerXYZ );
4537 //================================================================================
4539 * \brief Check and optionally return a satisfying shape
4541 //================================================================================
4543 bool ElementsOnShape::IsSatisfy (const SMDS_MeshNode* node,
4544 TopoDS_Shape* okShape)
4549 if ( !myOctree && myClassifiers.size() > 5 )
4551 myWorkClassifiers.resize( myClassifiers.size() );
4552 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4553 myWorkClassifiers[ i ] = & myClassifiers[ i ];
4554 myOctree = new OctreeClassifier( myWorkClassifiers );
4557 bool isNodeOut = true;
4559 if ( okShape || !getNodeIsOut( node, isNodeOut ))
4561 SMESH_NodeXYZ aPnt = node;
4564 myWorkClassifiers.clear();
4565 myOctree->GetClassifiersAtPoint( aPnt, myWorkClassifiers );
4567 for ( size_t i = 0; i < myWorkClassifiers.size(); ++i )
4568 myWorkClassifiers[i]->SetChecked( false );
4570 for ( size_t i = 0; i < myWorkClassifiers.size(); ++i )
4571 if ( !myWorkClassifiers[i]->IsChecked() &&
4572 !myWorkClassifiers[i]->IsOut( aPnt ))
4576 *okShape = myWorkClassifiers[i]->Shape();
4582 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4583 if ( !myClassifiers[i].IsOut( aPnt ))
4587 *okShape = myClassifiers[i].Shape();
4591 setNodeIsOut( node, isNodeOut );
4597 void ElementsOnShape::Classifier::Init( const TopoDS_Shape& theShape,
4599 const Bnd_B3d* theBox )
4605 bool isShapeBox = false;
4606 switch ( myShape.ShapeType() )
4610 if (( isShapeBox = isBox( theShape )))
4612 myIsOutFun = & ElementsOnShape::Classifier::isOutOfBox;
4616 mySolidClfr = new BRepClass3d_SolidClassifier(theShape);
4617 myIsOutFun = & ElementsOnShape::Classifier::isOutOfSolid;
4623 Standard_Real u1,u2,v1,v2;
4624 Handle(Geom_Surface) surf = BRep_Tool::Surface( TopoDS::Face( theShape ));
4625 if ( surf.IsNull() )
4626 myIsOutFun = & ElementsOnShape::Classifier::isOutOfNone;
4629 surf->Bounds( u1,u2,v1,v2 );
4630 myProjFace.Init(surf, u1,u2, v1,v2, myTol );
4631 myIsOutFun = & ElementsOnShape::Classifier::isOutOfFace;
4637 Standard_Real u1, u2;
4638 Handle(Geom_Curve) curve = BRep_Tool::Curve( TopoDS::Edge( theShape ), u1, u2);
4639 if ( curve.IsNull() )
4640 myIsOutFun = & ElementsOnShape::Classifier::isOutOfNone;
4643 myProjEdge.Init(curve, u1, u2);
4644 myIsOutFun = & ElementsOnShape::Classifier::isOutOfEdge;
4650 myVertexXYZ = BRep_Tool::Pnt( TopoDS::Vertex( theShape ) );
4651 myIsOutFun = & ElementsOnShape::Classifier::isOutOfVertex;
4655 throw SALOME_Exception("Programmer error in usage of ElementsOnShape::Classifier");
4667 if ( myShape.ShapeType() == TopAbs_FACE )
4669 BRepAdaptor_Surface SA( TopoDS::Face( myShape ), /*useBoundaries=*/false );
4670 if ( SA.GetType() == GeomAbs_BSplineSurface )
4671 BRepBndLib::AddOptimal( myShape, box,
4672 /*useTriangulation=*/true, /*useShapeTolerance=*/true );
4675 BRepBndLib::Add( myShape, box );
4677 myBox.Add( box.CornerMin() );
4678 myBox.Add( box.CornerMax() );
4679 gp_XYZ halfSize = 0.5 * ( box.CornerMax().XYZ() - box.CornerMin().XYZ() );
4680 for ( int iDim = 1; iDim <= 3; ++iDim )
4682 double x = halfSize.Coord( iDim );
4683 halfSize.SetCoord( iDim, x + Max( myTol, 1e-2 * x ));
4685 myBox.SetHSize( halfSize );
4690 ElementsOnShape::Classifier::~Classifier()
4692 delete mySolidClfr; mySolidClfr = 0;
4695 bool ElementsOnShape::Classifier::isOutOfSolid( const gp_Pnt& p )
4697 if ( isOutOfBox( p )) return true;
4698 mySolidClfr->Perform( p, myTol );
4699 return ( mySolidClfr->State() != TopAbs_IN && mySolidClfr->State() != TopAbs_ON );
4702 bool ElementsOnShape::Classifier::isOutOfBox( const gp_Pnt& p )
4704 return myBox.IsOut( p.XYZ() );
4707 bool ElementsOnShape::Classifier::isOutOfFace( const gp_Pnt& p )
4709 if ( isOutOfBox( p )) return true;
4710 myProjFace.Perform( p );
4711 if ( myProjFace.IsDone() && myProjFace.LowerDistance() <= myTol )
4713 // check relatively to the face
4715 myProjFace.LowerDistanceParameters(u, v);
4716 gp_Pnt2d aProjPnt (u, v);
4717 BRepClass_FaceClassifier aClsf ( TopoDS::Face( myShape ), aProjPnt, myTol );
4718 if ( aClsf.State() == TopAbs_IN || aClsf.State() == TopAbs_ON )
4724 bool ElementsOnShape::Classifier::isOutOfEdge( const gp_Pnt& p )
4726 if ( isOutOfBox( p )) return true;
4727 myProjEdge.Perform( p );
4728 return ! ( myProjEdge.NbPoints() > 0 && myProjEdge.LowerDistance() <= myTol );
4731 bool ElementsOnShape::Classifier::isOutOfVertex( const gp_Pnt& p )
4733 return ( myVertexXYZ.Distance( p ) > myTol );
4736 bool ElementsOnShape::Classifier::isBox(const TopoDS_Shape& theShape )
4738 TopTools_IndexedMapOfShape vMap;
4739 TopExp::MapShapes( theShape, TopAbs_VERTEX, vMap );
4740 if ( vMap.Extent() != 8 )
4744 for ( int i = 1; i <= 8; ++i )
4745 myBox.Add( BRep_Tool::Pnt( TopoDS::Vertex( vMap( i ))).XYZ() );
4747 gp_XYZ pMin = myBox.CornerMin(), pMax = myBox.CornerMax();
4748 for ( int i = 1; i <= 8; ++i )
4750 gp_Pnt p = BRep_Tool::Pnt( TopoDS::Vertex( vMap( i )));
4751 for ( int iC = 1; iC <= 3; ++ iC )
4753 double d1 = Abs( pMin.Coord( iC ) - p.Coord( iC ));
4754 double d2 = Abs( pMax.Coord( iC ) - p.Coord( iC ));
4755 if ( Min( d1, d2 ) > myTol )
4759 myBox.Enlarge( myTol );
4764 OctreeClassifier::OctreeClassifier( const std::vector< ElementsOnShape::Classifier* >& classifiers )
4765 :SMESH_Octree( new SMESH_TreeLimit )
4767 myClassifiers = classifiers;
4772 OctreeClassifier::OctreeClassifier( const OctreeClassifier* otherTree,
4773 const std::vector< ElementsOnShape::Classifier >& clsOther,
4774 std::vector< ElementsOnShape::Classifier >& cls )
4775 :SMESH_Octree( new SMESH_TreeLimit )
4777 myBox = new Bnd_B3d( *otherTree->getBox() );
4779 if (( myIsLeaf = otherTree->isLeaf() ))
4781 myClassifiers.resize( otherTree->myClassifiers.size() );
4782 for ( size_t i = 0; i < otherTree->myClassifiers.size(); ++i )
4784 int ind = otherTree->myClassifiers[i] - & clsOther[0];
4785 myClassifiers[ i ] = & cls[ ind ];
4788 else if ( otherTree->myChildren )
4790 myChildren = new SMESH_Tree< Bnd_B3d, 8 > * [ 8 ];
4791 for ( int i = 0; i < nbChildren(); i++ )
4793 new OctreeClassifier( static_cast<const OctreeClassifier*>( otherTree->myChildren[i]),
4798 void ElementsOnShape::
4799 OctreeClassifier::GetClassifiersAtPoint( const gp_XYZ& point,
4800 std::vector< ElementsOnShape::Classifier* >& result )
4802 if ( getBox()->IsOut( point ))
4807 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4808 if ( !myClassifiers[i]->GetBndBox()->IsOut( point ))
4809 result.push_back( myClassifiers[i] );
4813 for (int i = 0; i < nbChildren(); i++)
4814 ((OctreeClassifier*) myChildren[i])->GetClassifiersAtPoint( point, result );
4818 size_t ElementsOnShape::OctreeClassifier::GetSize()
4820 size_t res = sizeof( *this );
4821 if ( !myClassifiers.empty() )
4822 res += sizeof( myClassifiers[0] ) * myClassifiers.size();
4825 for (int i = 0; i < nbChildren(); i++)
4826 res += ((OctreeClassifier*) myChildren[i])->GetSize();
4831 void ElementsOnShape::OctreeClassifier::buildChildrenData()
4833 // distribute myClassifiers among myChildren
4835 const int childFlag[8] = { 0x0000001,
4843 int nbInChild[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
4845 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4847 for ( int j = 0; j < nbChildren(); j++ )
4849 if ( !myClassifiers[i]->GetBndBox()->IsOut( *myChildren[j]->getBox() ))
4851 myClassifiers[i]->SetFlag( childFlag[ j ]);
4857 for ( int j = 0; j < nbChildren(); j++ )
4859 OctreeClassifier* child = static_cast<OctreeClassifier*>( myChildren[ j ]);
4860 child->myClassifiers.resize( nbInChild[ j ]);
4861 for ( size_t i = 0; nbInChild[ j ] && i < myClassifiers.size(); ++i )
4863 if ( myClassifiers[ i ]->IsSetFlag( childFlag[ j ]))
4866 child->myClassifiers[ nbInChild[ j ]] = myClassifiers[ i ];
4867 myClassifiers[ i ]->UnsetFlag( childFlag[ j ]);
4871 SMESHUtils::FreeVector( myClassifiers );
4873 // define if a child isLeaf()
4874 for ( int i = 0; i < nbChildren(); i++ )
4876 OctreeClassifier* child = static_cast<OctreeClassifier*>( myChildren[ i ]);
4877 child->myIsLeaf = ( child->myClassifiers.size() <= 5 ||
4878 child->maxSize() < child->myClassifiers[0]->Tolerance() );
4882 Bnd_B3d* ElementsOnShape::OctreeClassifier::buildRootBox()
4884 Bnd_B3d* box = new Bnd_B3d;
4885 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4886 box->Add( *myClassifiers[i]->GetBndBox() );
4891 Class : BelongToGeom
4892 Description : Predicate for verifying whether entity belongs to
4893 specified geometrical support
4896 BelongToGeom::BelongToGeom()
4898 myType(SMDSAbs_NbElementTypes),
4899 myIsSubshape(false),
4900 myTolerance(Precision::Confusion())
4903 Predicate* BelongToGeom::clone() const
4905 BelongToGeom* cln = 0;
4906 if ( myElementsOnShapePtr )
4907 if ( ElementsOnShape* eos = static_cast<ElementsOnShape*>( myElementsOnShapePtr->clone() ))
4909 cln = new BelongToGeom( *this );
4910 cln->myElementsOnShapePtr.reset( eos );
4915 void BelongToGeom::SetMesh( const SMDS_Mesh* theMesh )
4917 if ( myMeshDS != theMesh )
4919 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
4922 if ( myElementsOnShapePtr )
4923 myElementsOnShapePtr->SetMesh( myMeshDS );
4926 void BelongToGeom::SetGeom( const TopoDS_Shape& theShape )
4928 if ( myShape != theShape )
4935 static bool IsSubShape (const TopTools_IndexedMapOfShape& theMap,
4936 const TopoDS_Shape& theShape)
4938 if (theMap.Contains(theShape)) return true;
4940 if (theShape.ShapeType() == TopAbs_COMPOUND ||
4941 theShape.ShapeType() == TopAbs_COMPSOLID)
4943 TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
4944 for (; anIt.More(); anIt.Next())
4946 if (!IsSubShape(theMap, anIt.Value())) {
4956 void BelongToGeom::init()
4958 if ( !myMeshDS || myShape.IsNull() ) return;
4960 // is sub-shape of main shape?
4961 TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
4962 if (aMainShape.IsNull()) {
4963 myIsSubshape = false;
4966 TopTools_IndexedMapOfShape aMap;
4967 TopExp::MapShapes( aMainShape, aMap );
4968 myIsSubshape = IsSubShape( aMap, myShape );
4972 TopExp::MapShapes( myShape, aMap );
4973 mySubShapesIDs.Clear();
4974 for ( int i = 1; i <= aMap.Extent(); ++i )
4976 int subID = myMeshDS->ShapeToIndex( aMap( i ));
4978 mySubShapesIDs.Add( subID );
4983 //if (!myIsSubshape) // to be always ready to check an element not bound to geometry
4985 if ( !myElementsOnShapePtr )
4986 myElementsOnShapePtr.reset( new ElementsOnShape() );
4987 myElementsOnShapePtr->SetTolerance( myTolerance );
4988 myElementsOnShapePtr->SetAllNodes( true ); // "belong", while false means "lays on"
4989 myElementsOnShapePtr->SetMesh( myMeshDS );
4990 myElementsOnShapePtr->SetShape( myShape, myType );
4994 bool BelongToGeom::IsSatisfy (long theId)
4996 if (myMeshDS == 0 || myShape.IsNull())
5001 return myElementsOnShapePtr->IsSatisfy(theId);
5006 if (myType == SMDSAbs_Node)
5008 if ( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ))
5010 if ( aNode->getshapeId() < 1 )
5011 return myElementsOnShapePtr->IsSatisfy(theId);
5013 return mySubShapesIDs.Contains( aNode->getshapeId() );
5018 if ( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ))
5020 if ( myType == SMDSAbs_All || anElem->GetType() == myType )
5022 if ( anElem->getshapeId() < 1 )
5023 return myElementsOnShapePtr->IsSatisfy(theId);
5025 return mySubShapesIDs.Contains( anElem->getshapeId() );
5033 void BelongToGeom::SetType (SMDSAbs_ElementType theType)
5035 if ( myType != theType )
5042 SMDSAbs_ElementType BelongToGeom::GetType() const
5047 TopoDS_Shape BelongToGeom::GetShape()
5052 const SMESHDS_Mesh* BelongToGeom::GetMeshDS() const
5057 void BelongToGeom::SetTolerance (double theTolerance)
5059 myTolerance = theTolerance;
5063 double BelongToGeom::GetTolerance()
5070 Description : Predicate for verifying whether entiy lying or partially lying on
5071 specified geometrical support
5074 LyingOnGeom::LyingOnGeom()
5076 myType(SMDSAbs_NbElementTypes),
5077 myIsSubshape(false),
5078 myTolerance(Precision::Confusion())
5081 Predicate* LyingOnGeom::clone() const
5083 LyingOnGeom* cln = 0;
5084 if ( myElementsOnShapePtr )
5085 if ( ElementsOnShape* eos = static_cast<ElementsOnShape*>( myElementsOnShapePtr->clone() ))
5087 cln = new LyingOnGeom( *this );
5088 cln->myElementsOnShapePtr.reset( eos );
5093 void LyingOnGeom::SetMesh( const SMDS_Mesh* theMesh )
5095 if ( myMeshDS != theMesh )
5097 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
5100 if ( myElementsOnShapePtr )
5101 myElementsOnShapePtr->SetMesh( myMeshDS );
5104 void LyingOnGeom::SetGeom( const TopoDS_Shape& theShape )
5106 if ( myShape != theShape )
5113 void LyingOnGeom::init()
5115 if (!myMeshDS || myShape.IsNull()) return;
5117 // is sub-shape of main shape?
5118 TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
5119 if (aMainShape.IsNull()) {
5120 myIsSubshape = false;
5123 myIsSubshape = myMeshDS->IsGroupOfSubShapes( myShape );
5128 TopTools_IndexedMapOfShape shapes;
5129 TopExp::MapShapes( myShape, shapes );
5130 mySubShapesIDs.Clear();
5131 for ( int i = 1; i <= shapes.Extent(); ++i )
5133 int subID = myMeshDS->ShapeToIndex( shapes( i ));
5135 mySubShapesIDs.Add( subID );
5138 // else // to be always ready to check an element not bound to geometry
5140 if ( !myElementsOnShapePtr )
5141 myElementsOnShapePtr.reset( new ElementsOnShape() );
5142 myElementsOnShapePtr->SetTolerance( myTolerance );
5143 myElementsOnShapePtr->SetAllNodes( false ); // lays on, while true means "belong"
5144 myElementsOnShapePtr->SetMesh( myMeshDS );
5145 myElementsOnShapePtr->SetShape( myShape, myType );
5149 bool LyingOnGeom::IsSatisfy( long theId )
5151 if ( myMeshDS == 0 || myShape.IsNull() )
5156 return myElementsOnShapePtr->IsSatisfy(theId);
5161 const SMDS_MeshElement* elem =
5162 ( myType == SMDSAbs_Node ) ? myMeshDS->FindNode( theId ) : myMeshDS->FindElement( theId );
5164 if ( mySubShapesIDs.Contains( elem->getshapeId() ))
5167 if (( elem->GetType() != SMDSAbs_Node ) &&
5168 ( myType == SMDSAbs_All || elem->GetType() == myType ))
5170 SMDS_ElemIteratorPtr nodeItr = elem->nodesIterator();
5171 while ( nodeItr->more() )
5173 const SMDS_MeshElement* aNode = nodeItr->next();
5174 if ( mySubShapesIDs.Contains( aNode->getshapeId() ))
5182 void LyingOnGeom::SetType( SMDSAbs_ElementType theType )
5184 if ( myType != theType )
5191 SMDSAbs_ElementType LyingOnGeom::GetType() const
5196 TopoDS_Shape LyingOnGeom::GetShape()
5201 const SMESHDS_Mesh* LyingOnGeom::GetMeshDS() const
5206 void LyingOnGeom::SetTolerance (double theTolerance)
5208 myTolerance = theTolerance;
5212 double LyingOnGeom::GetTolerance()
5217 TSequenceOfXYZ::TSequenceOfXYZ(): myElem(0)
5220 TSequenceOfXYZ::TSequenceOfXYZ(size_type n) : myArray(n), myElem(0)
5223 TSequenceOfXYZ::TSequenceOfXYZ(size_type n, const gp_XYZ& t) : myArray(n,t), myElem(0)
5226 TSequenceOfXYZ::TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ) : myArray(theSequenceOfXYZ.myArray), myElem(theSequenceOfXYZ.myElem)
5229 template <class InputIterator>
5230 TSequenceOfXYZ::TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd): myArray(theBegin,theEnd), myElem(0)
5233 TSequenceOfXYZ::~TSequenceOfXYZ()
5236 TSequenceOfXYZ& TSequenceOfXYZ::operator=(const TSequenceOfXYZ& theSequenceOfXYZ)
5238 myArray = theSequenceOfXYZ.myArray;
5239 myElem = theSequenceOfXYZ.myElem;
5243 gp_XYZ& TSequenceOfXYZ::operator()(size_type n)
5245 return myArray[n-1];
5248 const gp_XYZ& TSequenceOfXYZ::operator()(size_type n) const
5250 return myArray[n-1];
5253 void TSequenceOfXYZ::clear()
5258 void TSequenceOfXYZ::reserve(size_type n)
5263 void TSequenceOfXYZ::push_back(const gp_XYZ& v)
5265 myArray.push_back(v);
5268 TSequenceOfXYZ::size_type TSequenceOfXYZ::size() const
5270 return myArray.size();
5273 SMDSAbs_EntityType TSequenceOfXYZ::getElementEntity() const
5275 return myElem ? myElem->GetEntityType() : SMDSEntity_Last;
5278 TMeshModifTracer::TMeshModifTracer():
5279 myMeshModifTime(0), myMesh(0)
5282 void TMeshModifTracer::SetMesh( const SMDS_Mesh* theMesh )
5284 if ( theMesh != myMesh )
5285 myMeshModifTime = 0;
5288 bool TMeshModifTracer::IsMeshModified()
5290 bool modified = false;
5293 modified = ( myMeshModifTime != myMesh->GetMTime() );
5294 myMeshModifTime = myMesh->GetMTime();