1 // Copyright (C) 2007-2020 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"
37 #include "SMESH_Comment.hxx"
39 #include <GEOMUtils.hxx>
40 #include <Basics_Utils.hxx>
42 #include <BRepAdaptor_Surface.hxx>
43 #include <BRepBndLib.hxx>
44 #include <BRepBuilderAPI_Copy.hxx>
45 #include <BRepClass3d_SolidClassifier.hxx>
46 #include <BRepClass_FaceClassifier.hxx>
47 #include <BRep_Tool.hxx>
48 #include <GeomLib_IsPlanarSurface.hxx>
49 #include <Geom_CylindricalSurface.hxx>
50 #include <Geom_Plane.hxx>
51 #include <Geom_Surface.hxx>
52 #include <NCollection_Map.hxx>
53 #include <Precision.hxx>
54 #include <ShapeAnalysis_Surface.hxx>
55 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
56 #include <TColStd_MapOfInteger.hxx>
57 #include <TColStd_SequenceOfAsciiString.hxx>
58 #include <TColgp_Array1OfXYZ.hxx>
62 #include <TopoDS_Edge.hxx>
63 #include <TopoDS_Face.hxx>
64 #include <TopoDS_Iterator.hxx>
65 #include <TopoDS_Shape.hxx>
66 #include <TopoDS_Vertex.hxx>
68 #include <gp_Cylinder.hxx>
75 #include <vtkMeshQuality.h>
86 const double theEps = 1e-100;
87 const double theInf = 1e+100;
89 inline gp_XYZ gpXYZ(const SMDS_MeshNode* aNode )
91 return gp_XYZ(aNode->X(), aNode->Y(), aNode->Z() );
94 inline double getAngle( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
96 gp_Vec v1( P1 - P2 ), v2( P3 - P2 );
98 return v1.Magnitude() < gp::Resolution() ||
99 v2.Magnitude() < gp::Resolution() ? 0 : v1.Angle( v2 );
102 inline double getCos2( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
104 gp_Vec v1( P1 - P2 ), v2( P3 - P2 );
105 double dot = v1 * v2, len1 = v1.SquareMagnitude(), len2 = v2.SquareMagnitude();
107 return ( dot < 0 || len1 < gp::Resolution() || len2 < gp::Resolution() ? -1 :
108 dot * dot / len1 / len2 );
111 inline double getArea( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
113 gp_Vec aVec1( P2 - P1 );
114 gp_Vec aVec2( P3 - P1 );
115 return ( aVec1 ^ aVec2 ).Magnitude() * 0.5;
118 inline double getArea( const gp_Pnt& P1, const gp_Pnt& P2, const gp_Pnt& P3 )
120 return getArea( P1.XYZ(), P2.XYZ(), P3.XYZ() );
125 inline double getDistance( const gp_XYZ& P1, const gp_XYZ& P2 )
127 double aDist = gp_Pnt( P1 ).Distance( gp_Pnt( P2 ) );
131 int getNbMultiConnection( const SMDS_Mesh* theMesh, const smIdType theId )
136 const SMDS_MeshElement* anEdge = theMesh->FindElement( theId );
137 if ( anEdge == 0 || anEdge->GetType() != SMDSAbs_Edge/* || anEdge->NbNodes() != 2 */)
140 // for each pair of nodes in anEdge (there are 2 pairs in a quadratic edge)
141 // count elements containing both nodes of the pair.
142 // Note that there may be such cases for a quadratic edge (a horizontal line):
147 // +-----+------+ +-----+------+
150 // result should be 2 in both cases
152 int aResult0 = 0, aResult1 = 0;
153 // last node, it is a medium one in a quadratic edge
154 const SMDS_MeshNode* aLastNode = anEdge->GetNode( anEdge->NbNodes() - 1 );
155 const SMDS_MeshNode* aNode0 = anEdge->GetNode( 0 );
156 const SMDS_MeshNode* aNode1 = anEdge->GetNode( 1 );
157 if ( aNode1 == aLastNode ) aNode1 = 0;
159 SMDS_ElemIteratorPtr anElemIter = aLastNode->GetInverseElementIterator();
160 while( anElemIter->more() ) {
161 const SMDS_MeshElement* anElem = anElemIter->next();
162 if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) {
163 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
164 while ( anIter->more() ) {
165 if ( const SMDS_MeshElement* anElemNode = anIter->next() ) {
166 if ( anElemNode == aNode0 ) {
168 if ( !aNode1 ) break; // not a quadratic edge
170 else if ( anElemNode == aNode1 )
176 int aResult = std::max ( aResult0, aResult1 );
181 gp_XYZ getNormale( const SMDS_MeshFace* theFace, bool* ok=0 )
183 int aNbNode = theFace->NbNodes();
185 gp_XYZ q1 = gpXYZ( theFace->GetNode(1)) - gpXYZ( theFace->GetNode(0));
186 gp_XYZ q2 = gpXYZ( theFace->GetNode(2)) - gpXYZ( theFace->GetNode(0));
189 gp_XYZ q3 = gpXYZ( theFace->GetNode(3)) - gpXYZ( theFace->GetNode(0));
192 double len = n.Modulus();
193 bool zeroLen = ( len <= std::numeric_limits<double>::min());
197 if (ok) *ok = !zeroLen;
205 using namespace SMESH::Controls;
211 //================================================================================
213 Class : NumericalFunctor
214 Description : Base class for numerical functors
216 //================================================================================
218 NumericalFunctor::NumericalFunctor():
224 void NumericalFunctor::SetMesh( const SMDS_Mesh* theMesh )
229 bool NumericalFunctor::GetPoints(const smIdType theId,
230 TSequenceOfXYZ& theRes ) const
237 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
238 if ( !IsApplicable( anElem ))
241 return GetPoints( anElem, theRes );
244 bool NumericalFunctor::GetPoints(const SMDS_MeshElement* anElem,
245 TSequenceOfXYZ& theRes )
252 theRes.reserve( anElem->NbNodes() );
253 theRes.setElement( anElem );
255 // Get nodes of the element
256 SMDS_NodeIteratorPtr anIter= anElem->interlacedNodesIterator();
259 while( anIter->more() ) {
260 if ( p.Set( anIter->next() ))
261 theRes.push_back( p );
268 long NumericalFunctor::GetPrecision() const
273 void NumericalFunctor::SetPrecision( const long thePrecision )
275 myPrecision = thePrecision;
276 myPrecisionValue = pow( 10., (double)( myPrecision ) );
279 double NumericalFunctor::GetValue( long theId )
283 myCurrElement = myMesh->FindElement( theId );
286 if ( GetPoints( theId, P )) // elem type is checked here
287 aVal = Round( GetValue( P ));
292 double NumericalFunctor::Round( const double & aVal )
294 return ( myPrecision >= 0 ) ? floor( aVal * myPrecisionValue + 0.5 ) / myPrecisionValue : aVal;
297 //================================================================================
299 * \brief Return true if a value can be computed for a given element.
300 * Some NumericalFunctor's are meaningful for elements of a certain
303 //================================================================================
305 bool NumericalFunctor::IsApplicable( const SMDS_MeshElement* element ) const
307 return element && element->GetType() == this->GetType();
310 bool NumericalFunctor::IsApplicable( long theElementId ) const
312 return IsApplicable( myMesh->FindElement( theElementId ));
315 //================================================================================
317 * \brief Return histogram of functor values
318 * \param nbIntervals - number of intervals
319 * \param nbEvents - number of mesh elements having values within i-th interval
320 * \param funValues - boundaries of intervals
321 * \param elements - elements to check vulue of; empty list means "of all"
322 * \param minmax - boundaries of diapason of values to divide into intervals
324 //================================================================================
326 void NumericalFunctor::GetHistogram(int nbIntervals,
327 std::vector<int>& nbEvents,
328 std::vector<double>& funValues,
329 const std::vector<smIdType>& elements,
330 const double* minmax,
331 const bool isLogarithmic)
333 if ( nbIntervals < 1 ||
335 !myMesh->GetMeshInfo().NbElements( GetType() ))
337 nbEvents.resize( nbIntervals, 0 );
338 funValues.resize( nbIntervals+1 );
340 // get all values sorted
341 std::multiset< double > values;
342 if ( elements.empty() )
344 SMDS_ElemIteratorPtr elemIt = myMesh->elementsIterator( GetType() );
345 while ( elemIt->more() )
346 values.insert( GetValue( elemIt->next()->GetID() ));
350 std::vector<smIdType>::const_iterator id = elements.begin();
351 for ( ; id != elements.end(); ++id )
352 values.insert( GetValue( *id ));
357 funValues[0] = minmax[0];
358 funValues[nbIntervals] = minmax[1];
362 funValues[0] = *values.begin();
363 funValues[nbIntervals] = *values.rbegin();
365 // case nbIntervals == 1
366 if ( nbIntervals == 1 )
368 nbEvents[0] = values.size();
372 if (funValues.front() == funValues.back())
374 nbEvents.resize( 1 );
375 nbEvents[0] = values.size();
376 funValues[1] = funValues.back();
377 funValues.resize( 2 );
380 std::multiset< double >::iterator min = values.begin(), max;
381 for ( int i = 0; i < nbIntervals; ++i )
383 // find end value of i-th interval
384 double r = (i+1) / double(nbIntervals);
385 if (isLogarithmic && funValues.front() > 1e-07 && funValues.back() > 1e-07) {
386 double logmin = log10(funValues.front());
387 double lval = logmin + r * (log10(funValues.back()) - logmin);
388 funValues[i+1] = pow(10.0, lval);
391 funValues[i+1] = funValues.front() * (1-r) + funValues.back() * r;
394 // count values in the i-th interval if there are any
395 if ( min != values.end() && *min <= funValues[i+1] )
397 // find the first value out of the interval
398 max = values.upper_bound( funValues[i+1] ); // max is greater than funValues[i+1], or end()
399 nbEvents[i] = std::distance( min, max );
403 // add values larger than minmax[1]
404 nbEvents.back() += std::distance( min, values.end() );
407 //=======================================================================
410 Description : Functor calculating volume of a 3D element
412 //================================================================================
414 double Volume::GetValue( long theElementId )
416 if ( theElementId && myMesh ) {
417 SMDS_VolumeTool aVolumeTool;
418 if ( aVolumeTool.Set( myMesh->FindElement( theElementId )))
419 return aVolumeTool.GetSize();
424 double Volume::GetBadRate( double Value, int /*nbNodes*/ ) const
429 SMDSAbs_ElementType Volume::GetType() const
431 return SMDSAbs_Volume;
434 //=======================================================================
436 Class : MaxElementLength2D
437 Description : Functor calculating maximum length of 2D element
439 //================================================================================
441 double MaxElementLength2D::GetValue( const TSequenceOfXYZ& P )
447 if( len == 3 ) { // triangles
448 double L1 = getDistance(P( 1 ),P( 2 ));
449 double L2 = getDistance(P( 2 ),P( 3 ));
450 double L3 = getDistance(P( 3 ),P( 1 ));
451 aVal = Max(L1,Max(L2,L3));
453 else if( len == 4 ) { // quadrangles
454 double L1 = getDistance(P( 1 ),P( 2 ));
455 double L2 = getDistance(P( 2 ),P( 3 ));
456 double L3 = getDistance(P( 3 ),P( 4 ));
457 double L4 = getDistance(P( 4 ),P( 1 ));
458 double D1 = getDistance(P( 1 ),P( 3 ));
459 double D2 = getDistance(P( 2 ),P( 4 ));
460 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(D1,D2));
462 else if( len == 6 ) { // quadratic triangles
463 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
464 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
465 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 1 ));
466 aVal = Max(L1,Max(L2,L3));
468 else if( len == 8 || len == 9 ) { // quadratic quadrangles
469 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
470 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
471 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 7 ));
472 double L4 = getDistance(P( 7 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
473 double D1 = getDistance(P( 1 ),P( 5 ));
474 double D2 = getDistance(P( 3 ),P( 7 ));
475 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(D1,D2));
477 // Diagonals are undefined for concave polygons
478 // else if ( P.getElementEntity() == SMDSEntity_Quad_Polygon && P.size() > 2 ) // quad polygon
481 // aVal = getDistance( P( 1 ), P( P.size() )) + getDistance( P( P.size() ), P( P.size()-1 ));
482 // for ( size_t i = 1; i < P.size()-1; i += 2 )
484 // double L = getDistance( P( i ), P( i+1 )) + getDistance( P( i+1 ), P( i+2 ));
485 // aVal = Max( aVal, L );
488 // for ( int i = P.size()-5; i > 0; i -= 2 )
489 // for ( int j = i + 4; j < P.size() + i - 2; i += 2 )
491 // double D = getDistance( P( i ), P( j ));
492 // aVal = Max( aVal, D );
499 if( myPrecision >= 0 )
501 double prec = pow( 10., (double)myPrecision );
502 aVal = floor( aVal * prec + 0.5 ) / prec;
507 double MaxElementLength2D::GetValue( long theElementId )
510 return GetPoints( theElementId, P ) ? GetValue(P) : 0.0;
513 double MaxElementLength2D::GetBadRate( double Value, int /*nbNodes*/ ) const
518 SMDSAbs_ElementType MaxElementLength2D::GetType() const
523 //=======================================================================
525 Class : MaxElementLength3D
526 Description : Functor calculating maximum length of 3D element
528 //================================================================================
530 double MaxElementLength3D::GetValue( long theElementId )
533 if( GetPoints( theElementId, P ) ) {
535 const SMDS_MeshElement* aElem = myMesh->FindElement( theElementId );
536 SMDSAbs_EntityType aType = aElem->GetEntityType();
539 case SMDSEntity_Tetra: { // tetras
540 double L1 = getDistance(P( 1 ),P( 2 ));
541 double L2 = getDistance(P( 2 ),P( 3 ));
542 double L3 = getDistance(P( 3 ),P( 1 ));
543 double L4 = getDistance(P( 1 ),P( 4 ));
544 double L5 = getDistance(P( 2 ),P( 4 ));
545 double L6 = getDistance(P( 3 ),P( 4 ));
546 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
549 case SMDSEntity_Pyramid: { // pyramids
550 double L1 = getDistance(P( 1 ),P( 2 ));
551 double L2 = getDistance(P( 2 ),P( 3 ));
552 double L3 = getDistance(P( 3 ),P( 4 ));
553 double L4 = getDistance(P( 4 ),P( 1 ));
554 double L5 = getDistance(P( 1 ),P( 5 ));
555 double L6 = getDistance(P( 2 ),P( 5 ));
556 double L7 = getDistance(P( 3 ),P( 5 ));
557 double L8 = getDistance(P( 4 ),P( 5 ));
558 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
559 aVal = Max(aVal,Max(L7,L8));
562 case SMDSEntity_Penta: { // pentas
563 double L1 = getDistance(P( 1 ),P( 2 ));
564 double L2 = getDistance(P( 2 ),P( 3 ));
565 double L3 = getDistance(P( 3 ),P( 1 ));
566 double L4 = getDistance(P( 4 ),P( 5 ));
567 double L5 = getDistance(P( 5 ),P( 6 ));
568 double L6 = getDistance(P( 6 ),P( 4 ));
569 double L7 = getDistance(P( 1 ),P( 4 ));
570 double L8 = getDistance(P( 2 ),P( 5 ));
571 double L9 = getDistance(P( 3 ),P( 6 ));
572 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
573 aVal = Max(aVal,Max(Max(L7,L8),L9));
576 case SMDSEntity_Hexa: { // hexas
577 double L1 = getDistance(P( 1 ),P( 2 ));
578 double L2 = getDistance(P( 2 ),P( 3 ));
579 double L3 = getDistance(P( 3 ),P( 4 ));
580 double L4 = getDistance(P( 4 ),P( 1 ));
581 double L5 = getDistance(P( 5 ),P( 6 ));
582 double L6 = getDistance(P( 6 ),P( 7 ));
583 double L7 = getDistance(P( 7 ),P( 8 ));
584 double L8 = getDistance(P( 8 ),P( 5 ));
585 double L9 = getDistance(P( 1 ),P( 5 ));
586 double L10= getDistance(P( 2 ),P( 6 ));
587 double L11= getDistance(P( 3 ),P( 7 ));
588 double L12= getDistance(P( 4 ),P( 8 ));
589 double D1 = getDistance(P( 1 ),P( 7 ));
590 double D2 = getDistance(P( 2 ),P( 8 ));
591 double D3 = getDistance(P( 3 ),P( 5 ));
592 double D4 = getDistance(P( 4 ),P( 6 ));
593 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
594 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
595 aVal = Max(aVal,Max(L11,L12));
596 aVal = Max(aVal,Max(Max(D1,D2),Max(D3,D4)));
599 case SMDSEntity_Hexagonal_Prism: { // hexagonal prism
600 for ( int i1 = 1; i1 < 12; ++i1 )
601 for ( int i2 = i1+1; i1 <= 12; ++i1 )
602 aVal = Max( aVal, getDistance(P( i1 ),P( i2 )));
605 case SMDSEntity_Quad_Tetra: { // quadratic tetras
606 double L1 = getDistance(P( 1 ),P( 5 )) + getDistance(P( 5 ),P( 2 ));
607 double L2 = getDistance(P( 2 ),P( 6 )) + getDistance(P( 6 ),P( 3 ));
608 double L3 = getDistance(P( 3 ),P( 7 )) + getDistance(P( 7 ),P( 1 ));
609 double L4 = getDistance(P( 1 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
610 double L5 = getDistance(P( 2 ),P( 9 )) + getDistance(P( 9 ),P( 4 ));
611 double L6 = getDistance(P( 3 ),P( 10 )) + getDistance(P( 10 ),P( 4 ));
612 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
615 case SMDSEntity_Quad_Pyramid: { // quadratic pyramids
616 double L1 = getDistance(P( 1 ),P( 6 )) + getDistance(P( 6 ),P( 2 ));
617 double L2 = getDistance(P( 2 ),P( 7 )) + getDistance(P( 7 ),P( 3 ));
618 double L3 = getDistance(P( 3 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
619 double L4 = getDistance(P( 4 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
620 double L5 = getDistance(P( 1 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
621 double L6 = getDistance(P( 2 ),P( 11 )) + getDistance(P( 11 ),P( 5 ));
622 double L7 = getDistance(P( 3 ),P( 12 )) + getDistance(P( 12 ),P( 5 ));
623 double L8 = getDistance(P( 4 ),P( 13 )) + getDistance(P( 13 ),P( 5 ));
624 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
625 aVal = Max(aVal,Max(L7,L8));
628 case SMDSEntity_Quad_Penta:
629 case SMDSEntity_BiQuad_Penta: { // quadratic pentas
630 double L1 = getDistance(P( 1 ),P( 7 )) + getDistance(P( 7 ),P( 2 ));
631 double L2 = getDistance(P( 2 ),P( 8 )) + getDistance(P( 8 ),P( 3 ));
632 double L3 = getDistance(P( 3 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
633 double L4 = getDistance(P( 4 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
634 double L5 = getDistance(P( 5 ),P( 11 )) + getDistance(P( 11 ),P( 6 ));
635 double L6 = getDistance(P( 6 ),P( 12 )) + getDistance(P( 12 ),P( 4 ));
636 double L7 = getDistance(P( 1 ),P( 13 )) + getDistance(P( 13 ),P( 4 ));
637 double L8 = getDistance(P( 2 ),P( 14 )) + getDistance(P( 14 ),P( 5 ));
638 double L9 = getDistance(P( 3 ),P( 15 )) + getDistance(P( 15 ),P( 6 ));
639 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
640 aVal = Max(aVal,Max(Max(L7,L8),L9));
643 case SMDSEntity_Quad_Hexa:
644 case SMDSEntity_TriQuad_Hexa: { // quadratic hexas
645 double L1 = getDistance(P( 1 ),P( 9 )) + getDistance(P( 9 ),P( 2 ));
646 double L2 = getDistance(P( 2 ),P( 10 )) + getDistance(P( 10 ),P( 3 ));
647 double L3 = getDistance(P( 3 ),P( 11 )) + getDistance(P( 11 ),P( 4 ));
648 double L4 = getDistance(P( 4 ),P( 12 )) + getDistance(P( 12 ),P( 1 ));
649 double L5 = getDistance(P( 5 ),P( 13 )) + getDistance(P( 13 ),P( 6 ));
650 double L6 = getDistance(P( 6 ),P( 14 )) + getDistance(P( 14 ),P( 7 ));
651 double L7 = getDistance(P( 7 ),P( 15 )) + getDistance(P( 15 ),P( 8 ));
652 double L8 = getDistance(P( 8 ),P( 16 )) + getDistance(P( 16 ),P( 5 ));
653 double L9 = getDistance(P( 1 ),P( 17 )) + getDistance(P( 17 ),P( 5 ));
654 double L10= getDistance(P( 2 ),P( 18 )) + getDistance(P( 18 ),P( 6 ));
655 double L11= getDistance(P( 3 ),P( 19 )) + getDistance(P( 19 ),P( 7 ));
656 double L12= getDistance(P( 4 ),P( 20 )) + getDistance(P( 20 ),P( 8 ));
657 double D1 = getDistance(P( 1 ),P( 7 ));
658 double D2 = getDistance(P( 2 ),P( 8 ));
659 double D3 = getDistance(P( 3 ),P( 5 ));
660 double D4 = getDistance(P( 4 ),P( 6 ));
661 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
662 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
663 aVal = Max(aVal,Max(L11,L12));
664 aVal = Max(aVal,Max(Max(D1,D2),Max(D3,D4)));
667 case SMDSEntity_Quad_Polyhedra:
668 case SMDSEntity_Polyhedra: { // polys
669 // get the maximum distance between all pairs of nodes
670 for( int i = 1; i <= len; i++ ) {
671 for( int j = 1; j <= len; j++ ) {
672 if( j > i ) { // optimization of the loop
673 double D = getDistance( P(i), P(j) );
674 aVal = Max( aVal, D );
680 case SMDSEntity_Node:
682 case SMDSEntity_Edge:
683 case SMDSEntity_Quad_Edge:
684 case SMDSEntity_Triangle:
685 case SMDSEntity_Quad_Triangle:
686 case SMDSEntity_BiQuad_Triangle:
687 case SMDSEntity_Quadrangle:
688 case SMDSEntity_Quad_Quadrangle:
689 case SMDSEntity_BiQuad_Quadrangle:
690 case SMDSEntity_Polygon:
691 case SMDSEntity_Quad_Polygon:
692 case SMDSEntity_Ball:
693 case SMDSEntity_Last: return 0;
694 } // switch ( aType )
696 if( myPrecision >= 0 )
698 double prec = pow( 10., (double)myPrecision );
699 aVal = floor( aVal * prec + 0.5 ) / prec;
706 double MaxElementLength3D::GetBadRate( double Value, int /*nbNodes*/ ) const
711 SMDSAbs_ElementType MaxElementLength3D::GetType() const
713 return SMDSAbs_Volume;
716 //=======================================================================
719 Description : Functor for calculation of minimum angle
721 //================================================================================
723 double MinimumAngle::GetValue( const TSequenceOfXYZ& P )
730 aMaxCos2 = getCos2( P( P.size() ), P( 1 ), P( 2 ));
731 aMaxCos2 = Max( aMaxCos2, getCos2( P( P.size()-1 ), P( P.size() ), P( 1 )));
733 for ( size_t i = 2; i < P.size(); i++ )
735 double A0 = getCos2( P( i-1 ), P( i ), P( i+1 ) );
736 aMaxCos2 = Max( aMaxCos2, A0 );
739 return 0; // all nodes coincide
741 double cos = sqrt( aMaxCos2 );
742 if ( cos >= 1 ) return 0;
743 return acos( cos ) * 180.0 / M_PI;
746 double MinimumAngle::GetBadRate( double Value, int nbNodes ) const
748 //const double aBestAngle = PI / nbNodes;
749 const double aBestAngle = 180.0 - ( 360.0 / double(nbNodes) );
750 return ( fabs( aBestAngle - Value ));
753 SMDSAbs_ElementType MinimumAngle::GetType() const
759 //================================================================================
762 Description : Functor for calculating aspect ratio
764 //================================================================================
766 double AspectRatio::GetValue( long theId )
769 myCurrElement = myMesh->FindElement( theId );
771 if ( GetPoints( myCurrElement, P ))
772 aVal = Round( GetValue( P ));
776 double AspectRatio::GetValue( const TSequenceOfXYZ& P )
778 // According to "Mesh quality control" by Nadir Bouhamau referring to
779 // Pascal Jean Frey and Paul-Louis George. Maillages, applications aux elements finis.
780 // Hermes Science publications, Paris 1999 ISBN 2-7462-0024-4
783 int nbNodes = P.size();
788 // Compute aspect ratio
790 if ( nbNodes == 3 ) {
791 // Compute lengths of the sides
792 double aLen1 = getDistance( P( 1 ), P( 2 ));
793 double aLen2 = getDistance( P( 2 ), P( 3 ));
794 double aLen3 = getDistance( P( 3 ), P( 1 ));
795 // Q = alfa * h * p / S, where
797 // alfa = sqrt( 3 ) / 6
798 // h - length of the longest edge
799 // p - half perimeter
800 // S - triangle surface
801 const double alfa = sqrt( 3. ) / 6.;
802 double maxLen = Max( aLen1, Max( aLen2, aLen3 ));
803 double half_perimeter = ( aLen1 + aLen2 + aLen3 ) / 2.;
804 double anArea = getArea( P( 1 ), P( 2 ), P( 3 ));
805 if ( anArea <= theEps )
807 return alfa * maxLen * half_perimeter / anArea;
809 else if ( nbNodes == 6 ) { // quadratic triangles
810 // Compute lengths of the sides
811 double aLen1 = getDistance( P( 1 ), P( 3 ));
812 double aLen2 = getDistance( P( 3 ), P( 5 ));
813 double aLen3 = getDistance( P( 5 ), P( 1 ));
814 // algo same as for the linear triangle
815 const double alfa = sqrt( 3. ) / 6.;
816 double maxLen = Max( aLen1, Max( aLen2, aLen3 ));
817 double half_perimeter = ( aLen1 + aLen2 + aLen3 ) / 2.;
818 double anArea = getArea( P( 1 ), P( 3 ), P( 5 ));
819 if ( anArea <= theEps )
821 return alfa * maxLen * half_perimeter / anArea;
823 else if( nbNodes == 4 ) { // quadrangle
824 // Compute lengths of the sides
826 aLen[0] = getDistance( P(1), P(2) );
827 aLen[1] = getDistance( P(2), P(3) );
828 aLen[2] = getDistance( P(3), P(4) );
829 aLen[3] = getDistance( P(4), P(1) );
830 // Compute lengths of the diagonals
832 aDia[0] = getDistance( P(1), P(3) );
833 aDia[1] = getDistance( P(2), P(4) );
834 // Compute areas of all triangles which can be built
835 // taking three nodes of the quadrangle
837 anArea[0] = getArea( P(1), P(2), P(3) );
838 anArea[1] = getArea( P(1), P(2), P(4) );
839 anArea[2] = getArea( P(1), P(3), P(4) );
840 anArea[3] = getArea( P(2), P(3), P(4) );
841 // Q = alpha * L * C1 / C2, where
843 // alpha = sqrt( 1/32 )
844 // L = max( L1, L2, L3, L4, D1, D2 )
845 // C1 = sqrt( L1^2 + L1^2 + L1^2 + L1^2 )
846 // C2 = min( S1, S2, S3, S4 )
847 // Li - lengths of the edges
848 // Di - lengths of the diagonals
849 // Si - areas of the triangles
850 const double alpha = sqrt( 1 / 32. );
851 double L = Max( aLen[ 0 ],
855 Max( aDia[ 0 ], aDia[ 1 ] ) ) ) ) );
856 double C1 = sqrt( aLen[0] * aLen[0] +
860 double C2 = Min( anArea[ 0 ],
862 Min( anArea[ 2 ], anArea[ 3 ] ) ) );
865 return alpha * L * C1 / C2;
867 else if( nbNodes == 8 || nbNodes == 9 ) { // nbNodes==8 - quadratic quadrangle
868 // Compute lengths of the sides
870 aLen[0] = getDistance( P(1), P(3) );
871 aLen[1] = getDistance( P(3), P(5) );
872 aLen[2] = getDistance( P(5), P(7) );
873 aLen[3] = getDistance( P(7), P(1) );
874 // Compute lengths of the diagonals
876 aDia[0] = getDistance( P(1), P(5) );
877 aDia[1] = getDistance( P(3), P(7) );
878 // Compute areas of all triangles which can be built
879 // taking three nodes of the quadrangle
881 anArea[0] = getArea( P(1), P(3), P(5) );
882 anArea[1] = getArea( P(1), P(3), P(7) );
883 anArea[2] = getArea( P(1), P(5), P(7) );
884 anArea[3] = getArea( P(3), P(5), P(7) );
885 // Q = alpha * L * C1 / C2, where
887 // alpha = sqrt( 1/32 )
888 // L = max( L1, L2, L3, L4, D1, D2 )
889 // C1 = sqrt( L1^2 + L1^2 + L1^2 + L1^2 )
890 // C2 = min( S1, S2, S3, S4 )
891 // Li - lengths of the edges
892 // Di - lengths of the diagonals
893 // Si - areas of the triangles
894 const double alpha = sqrt( 1 / 32. );
895 double L = Max( aLen[ 0 ],
899 Max( aDia[ 0 ], aDia[ 1 ] ) ) ) ) );
900 double C1 = sqrt( aLen[0] * aLen[0] +
904 double C2 = Min( anArea[ 0 ],
906 Min( anArea[ 2 ], anArea[ 3 ] ) ) );
909 return alpha * L * C1 / C2;
914 bool AspectRatio::IsApplicable( const SMDS_MeshElement* element ) const
916 return ( NumericalFunctor::IsApplicable( element ) && !element->IsPoly() );
919 double AspectRatio::GetBadRate( double Value, int /*nbNodes*/ ) const
921 // the aspect ratio is in the range [1.0,infinity]
922 // < 1.0 = very bad, zero area
925 return ( Value < 0.9 ) ? 1000 : Value / 1000.;
928 SMDSAbs_ElementType AspectRatio::GetType() const
934 //================================================================================
936 Class : AspectRatio3D
937 Description : Functor for calculating aspect ratio
939 //================================================================================
943 inline double getHalfPerimeter(double theTria[3]){
944 return (theTria[0] + theTria[1] + theTria[2])/2.0;
947 inline double getArea(double theHalfPerim, double theTria[3]){
948 return sqrt(theHalfPerim*
949 (theHalfPerim-theTria[0])*
950 (theHalfPerim-theTria[1])*
951 (theHalfPerim-theTria[2]));
954 inline double getVolume(double theLen[6]){
955 double a2 = theLen[0]*theLen[0];
956 double b2 = theLen[1]*theLen[1];
957 double c2 = theLen[2]*theLen[2];
958 double d2 = theLen[3]*theLen[3];
959 double e2 = theLen[4]*theLen[4];
960 double f2 = theLen[5]*theLen[5];
961 double P = 4.0*a2*b2*d2;
962 double Q = a2*(b2+d2-e2)-b2*(a2+d2-f2)-d2*(a2+b2-c2);
963 double R = (b2+d2-e2)*(a2+d2-f2)*(a2+d2-f2);
964 return sqrt(P-Q+R)/12.0;
967 inline double getVolume2(double theLen[6]){
968 double a2 = theLen[0]*theLen[0];
969 double b2 = theLen[1]*theLen[1];
970 double c2 = theLen[2]*theLen[2];
971 double d2 = theLen[3]*theLen[3];
972 double e2 = theLen[4]*theLen[4];
973 double f2 = theLen[5]*theLen[5];
975 double P = a2*e2*(b2+c2+d2+f2-a2-e2);
976 double Q = b2*f2*(a2+c2+d2+e2-b2-f2);
977 double R = c2*d2*(a2+b2+e2+f2-c2-d2);
978 double S = a2*b2*d2+b2*c2*e2+a2*c2*f2+d2*e2*f2;
980 return sqrt(P+Q+R-S)/12.0;
983 inline double getVolume(const TSequenceOfXYZ& P){
984 gp_Vec aVec1( P( 2 ) - P( 1 ) );
985 gp_Vec aVec2( P( 3 ) - P( 1 ) );
986 gp_Vec aVec3( P( 4 ) - P( 1 ) );
987 gp_Vec anAreaVec( aVec1 ^ aVec2 );
988 return fabs(aVec3 * anAreaVec) / 6.0;
991 inline double getMaxHeight(double theLen[6])
993 double aHeight = std::max(theLen[0],theLen[1]);
994 aHeight = std::max(aHeight,theLen[2]);
995 aHeight = std::max(aHeight,theLen[3]);
996 aHeight = std::max(aHeight,theLen[4]);
997 aHeight = std::max(aHeight,theLen[5]);
1003 double AspectRatio3D::GetValue( long theId )
1006 myCurrElement = myMesh->FindElement( theId );
1007 if ( myCurrElement && myCurrElement->GetVtkType() == VTK_TETRA )
1009 // Action from CoTech | ACTION 31.3:
1010 // EURIWARE BO: Homogenize the formulas used to calculate the Controls in SMESH to fit with
1011 // those of ParaView. The library used by ParaView for those calculations can be reused in SMESH.
1012 vtkUnstructuredGrid* grid = const_cast<SMDS_Mesh*>( myMesh )->GetGrid();
1013 if ( vtkCell* avtkCell = grid->GetCell( myCurrElement->GetVtkID() ))
1014 aVal = Round( vtkMeshQuality::TetAspectRatio( avtkCell ));
1019 if ( GetPoints( myCurrElement, P ))
1020 aVal = Round( GetValue( P ));
1025 bool AspectRatio3D::IsApplicable( const SMDS_MeshElement* element ) const
1027 return ( NumericalFunctor::IsApplicable( element ) && !element->IsPoly() );
1030 double AspectRatio3D::GetValue( const TSequenceOfXYZ& P )
1032 double aQuality = 0.0;
1033 if(myCurrElement->IsPoly()) return aQuality;
1035 int nbNodes = P.size();
1037 if( myCurrElement->IsQuadratic() ) {
1038 if (nbNodes==10) nbNodes=4; // quadratic tetrahedron
1039 else if(nbNodes==13) nbNodes=5; // quadratic pyramid
1040 else if(nbNodes==15) nbNodes=6; // quadratic pentahedron
1041 else if(nbNodes==20) nbNodes=8; // quadratic hexahedron
1042 else if(nbNodes==27) nbNodes=8; // tri-quadratic hexahedron
1043 else return aQuality;
1049 getDistance(P( 1 ),P( 2 )), // a
1050 getDistance(P( 2 ),P( 3 )), // b
1051 getDistance(P( 3 ),P( 1 )), // c
1052 getDistance(P( 2 ),P( 4 )), // d
1053 getDistance(P( 3 ),P( 4 )), // e
1054 getDistance(P( 1 ),P( 4 )) // f
1056 double aTria[4][3] = {
1057 {aLen[0],aLen[1],aLen[2]}, // abc
1058 {aLen[0],aLen[3],aLen[5]}, // adf
1059 {aLen[1],aLen[3],aLen[4]}, // bde
1060 {aLen[2],aLen[4],aLen[5]} // cef
1062 double aSumArea = 0.0;
1063 double aHalfPerimeter = getHalfPerimeter(aTria[0]);
1064 double anArea = getArea(aHalfPerimeter,aTria[0]);
1066 aHalfPerimeter = getHalfPerimeter(aTria[1]);
1067 anArea = getArea(aHalfPerimeter,aTria[1]);
1069 aHalfPerimeter = getHalfPerimeter(aTria[2]);
1070 anArea = getArea(aHalfPerimeter,aTria[2]);
1072 aHalfPerimeter = getHalfPerimeter(aTria[3]);
1073 anArea = getArea(aHalfPerimeter,aTria[3]);
1075 double aVolume = getVolume(P);
1076 //double aVolume = getVolume(aLen);
1077 double aHeight = getMaxHeight(aLen);
1078 static double aCoeff = sqrt(2.0)/12.0;
1079 if ( aVolume > DBL_MIN )
1080 aQuality = aCoeff*aHeight*aSumArea/aVolume;
1085 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 3 ),P( 5 )};
1086 aQuality = GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4]));
1089 gp_XYZ aXYZ[4] = {P( 1 ),P( 3 ),P( 4 ),P( 5 )};
1090 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1093 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 5 )};
1094 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1097 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 4 ),P( 5 )};
1098 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1104 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 6 )};
1105 aQuality = GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4]));
1108 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 3 )};
1109 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1112 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 6 )};
1113 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1116 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
1117 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1120 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 6 )};
1121 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1124 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 3 )};
1125 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1131 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
1132 aQuality = GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4]));
1135 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 4 )};
1136 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1139 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 7 )};
1140 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1143 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 8 )};
1144 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1147 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 3 )};
1148 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1151 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 4 )};
1152 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1155 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 7 )};
1156 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1159 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 8 )};
1160 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1163 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 3 )};
1164 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1167 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 4 )};
1168 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1171 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 7 )};
1172 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1175 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 8 )};
1176 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1179 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 1 )};
1180 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1183 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 2 )};
1184 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1187 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 5 )};
1188 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1191 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 6 )};
1192 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1195 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 1 )};
1196 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1199 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 2 )};
1200 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1203 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 5 )};
1204 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1207 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 6 )};
1208 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1211 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 1 )};
1212 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1215 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
1216 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1219 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 5 )};
1220 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1223 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 6 )};
1224 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1227 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
1228 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1231 gp_XYZ aXYZ[4] = {P( 4 ),P( 5 ),P( 8 ),P( 2 )};
1232 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1235 gp_XYZ aXYZ[4] = {P( 1 ),P( 4 ),P( 5 ),P( 3 )};
1236 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1239 gp_XYZ aXYZ[4] = {P( 3 ),P( 6 ),P( 7 ),P( 1 )};
1240 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1243 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 6 ),P( 4 )};
1244 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1247 gp_XYZ aXYZ[4] = {P( 5 ),P( 6 ),P( 8 ),P( 3 )};
1248 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1251 gp_XYZ aXYZ[4] = {P( 7 ),P( 8 ),P( 6 ),P( 1 )};
1252 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1255 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 7 )};
1256 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1259 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 2 ),P( 5 )};
1260 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1266 gp_XYZ aXYZ[8] = {P( 1 ),P( 2 ),P( 4 ),P( 5 ),P( 7 ),P( 8 ),P( 10 ),P( 11 )};
1267 aQuality = GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[8]));
1270 gp_XYZ aXYZ[8] = {P( 2 ),P( 3 ),P( 5 ),P( 6 ),P( 8 ),P( 9 ),P( 11 ),P( 12 )};
1271 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[8])),aQuality);
1274 gp_XYZ aXYZ[8] = {P( 3 ),P( 4 ),P( 6 ),P( 1 ),P( 9 ),P( 10 ),P( 12 ),P( 7 )};
1275 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[8])),aQuality);
1278 } // switch(nbNodes)
1280 if ( nbNodes > 4 ) {
1281 // evaluate aspect ratio of quadrangle faces
1282 AspectRatio aspect2D;
1283 SMDS_VolumeTool::VolumeType type = SMDS_VolumeTool::GetType( nbNodes );
1284 int nbFaces = SMDS_VolumeTool::NbFaces( type );
1285 TSequenceOfXYZ points(4);
1286 for ( int i = 0; i < nbFaces; ++i ) { // loop on faces of a volume
1287 if ( SMDS_VolumeTool::NbFaceNodes( type, i ) != 4 )
1289 const int* pInd = SMDS_VolumeTool::GetFaceNodesIndices( type, i, true );
1290 for ( int p = 0; p < 4; ++p ) // loop on nodes of a quadrangle face
1291 points( p + 1 ) = P( pInd[ p ] + 1 );
1292 aQuality = std::max( aQuality, aspect2D.GetValue( points ));
1298 double AspectRatio3D::GetBadRate( double Value, int /*nbNodes*/ ) const
1300 // the aspect ratio is in the range [1.0,infinity]
1303 return Value / 1000.;
1306 SMDSAbs_ElementType AspectRatio3D::GetType() const
1308 return SMDSAbs_Volume;
1312 //================================================================================
1315 Description : Functor for calculating warping
1317 //================================================================================
1319 bool Warping::IsApplicable( const SMDS_MeshElement* element ) const
1321 return NumericalFunctor::IsApplicable( element ) && element->NbNodes() == 4;
1324 double Warping::GetValue( const TSequenceOfXYZ& P )
1326 if ( P.size() != 4 )
1329 gp_XYZ G = ( P( 1 ) + P( 2 ) + P( 3 ) + P( 4 ) ) / 4.;
1331 double A1 = ComputeA( P( 1 ), P( 2 ), P( 3 ), G );
1332 double A2 = ComputeA( P( 2 ), P( 3 ), P( 4 ), G );
1333 double A3 = ComputeA( P( 3 ), P( 4 ), P( 1 ), G );
1334 double A4 = ComputeA( P( 4 ), P( 1 ), P( 2 ), G );
1336 double val = Max( Max( A1, A2 ), Max( A3, A4 ) );
1338 const double eps = 0.1; // val is in degrees
1340 return val < eps ? 0. : val;
1343 double Warping::ComputeA( const gp_XYZ& thePnt1,
1344 const gp_XYZ& thePnt2,
1345 const gp_XYZ& thePnt3,
1346 const gp_XYZ& theG ) const
1348 double aLen1 = gp_Pnt( thePnt1 ).Distance( gp_Pnt( thePnt2 ) );
1349 double aLen2 = gp_Pnt( thePnt2 ).Distance( gp_Pnt( thePnt3 ) );
1350 double L = Min( aLen1, aLen2 ) * 0.5;
1354 gp_XYZ GI = ( thePnt2 + thePnt1 ) / 2. - theG;
1355 gp_XYZ GJ = ( thePnt3 + thePnt2 ) / 2. - theG;
1356 gp_XYZ N = GI.Crossed( GJ );
1358 if ( N.Modulus() < gp::Resolution() )
1363 double H = ( thePnt2 - theG ).Dot( N );
1364 return asin( fabs( H / L ) ) * 180. / M_PI;
1367 double Warping::GetBadRate( double Value, int /*nbNodes*/ ) const
1369 // the warp is in the range [0.0,PI/2]
1370 // 0.0 = good (no warp)
1371 // PI/2 = bad (face pliee)
1375 SMDSAbs_ElementType Warping::GetType() const
1377 return SMDSAbs_Face;
1381 //================================================================================
1384 Description : Functor for calculating taper
1386 //================================================================================
1388 bool Taper::IsApplicable( const SMDS_MeshElement* element ) const
1390 return ( NumericalFunctor::IsApplicable( element ) && element->NbNodes() == 4 );
1393 double Taper::GetValue( const TSequenceOfXYZ& P )
1395 if ( P.size() != 4 )
1399 double J1 = getArea( P( 4 ), P( 1 ), P( 2 ) );
1400 double J2 = getArea( P( 3 ), P( 1 ), P( 2 ) );
1401 double J3 = getArea( P( 2 ), P( 3 ), P( 4 ) );
1402 double J4 = getArea( P( 3 ), P( 4 ), P( 1 ) );
1404 double JA = 0.25 * ( J1 + J2 + J3 + J4 );
1408 double T1 = fabs( ( J1 - JA ) / JA );
1409 double T2 = fabs( ( J2 - JA ) / JA );
1410 double T3 = fabs( ( J3 - JA ) / JA );
1411 double T4 = fabs( ( J4 - JA ) / JA );
1413 double val = Max( Max( T1, T2 ), Max( T3, T4 ) );
1415 const double eps = 0.01;
1417 return val < eps ? 0. : val;
1420 double Taper::GetBadRate( double Value, int /*nbNodes*/ ) const
1422 // the taper is in the range [0.0,1.0]
1423 // 0.0 = good (no taper)
1424 // 1.0 = bad (les cotes opposes sont allignes)
1428 SMDSAbs_ElementType Taper::GetType() const
1430 return SMDSAbs_Face;
1433 //================================================================================
1436 Description : Functor for calculating skew in degrees
1438 //================================================================================
1440 static inline double skewAngle( const gp_XYZ& p1, const gp_XYZ& p2, const gp_XYZ& p3 )
1442 gp_XYZ p12 = ( p2 + p1 ) / 2.;
1443 gp_XYZ p23 = ( p3 + p2 ) / 2.;
1444 gp_XYZ p31 = ( p3 + p1 ) / 2.;
1446 gp_Vec v1( p31 - p2 ), v2( p12 - p23 );
1448 return v1.Magnitude() < gp::Resolution() || v2.Magnitude() < gp::Resolution() ? 0. : v1.Angle( v2 );
1451 bool Skew::IsApplicable( const SMDS_MeshElement* element ) const
1453 return ( NumericalFunctor::IsApplicable( element ) && element->NbNodes() <= 4 );
1456 double Skew::GetValue( const TSequenceOfXYZ& P )
1458 if ( P.size() != 3 && P.size() != 4 )
1462 const double PI2 = M_PI / 2.;
1463 if ( P.size() == 3 )
1465 double A0 = fabs( PI2 - skewAngle( P( 3 ), P( 1 ), P( 2 ) ) );
1466 double A1 = fabs( PI2 - skewAngle( P( 1 ), P( 2 ), P( 3 ) ) );
1467 double A2 = fabs( PI2 - skewAngle( P( 2 ), P( 3 ), P( 1 ) ) );
1469 return Max( A0, Max( A1, A2 ) ) * 180. / M_PI;
1473 gp_XYZ p12 = ( P( 1 ) + P( 2 ) ) / 2.;
1474 gp_XYZ p23 = ( P( 2 ) + P( 3 ) ) / 2.;
1475 gp_XYZ p34 = ( P( 3 ) + P( 4 ) ) / 2.;
1476 gp_XYZ p41 = ( P( 4 ) + P( 1 ) ) / 2.;
1478 gp_Vec v1( p34 - p12 ), v2( p23 - p41 );
1479 double A = v1.Magnitude() <= gp::Resolution() || v2.Magnitude() <= gp::Resolution()
1480 ? 0. : fabs( PI2 - v1.Angle( v2 ) );
1482 double val = A * 180. / M_PI;
1484 const double eps = 0.1; // val is in degrees
1486 return val < eps ? 0. : val;
1490 double Skew::GetBadRate( double Value, int /*nbNodes*/ ) const
1492 // the skew is in the range [0.0,PI/2].
1498 SMDSAbs_ElementType Skew::GetType() const
1500 return SMDSAbs_Face;
1504 //================================================================================
1507 Description : Functor for calculating area
1509 //================================================================================
1511 double Area::GetValue( const TSequenceOfXYZ& P )
1516 gp_Vec aVec1( P(2) - P(1) );
1517 gp_Vec aVec2( P(3) - P(1) );
1518 gp_Vec SumVec = aVec1 ^ aVec2;
1520 for (size_t i=4; i<=P.size(); i++)
1522 gp_Vec aVec1( P(i-1) - P(1) );
1523 gp_Vec aVec2( P(i ) - P(1) );
1524 gp_Vec tmp = aVec1 ^ aVec2;
1527 val = SumVec.Magnitude() * 0.5;
1532 double Area::GetBadRate( double Value, int /*nbNodes*/ ) const
1534 // meaningless as it is not a quality control functor
1538 SMDSAbs_ElementType Area::GetType() const
1540 return SMDSAbs_Face;
1543 //================================================================================
1546 Description : Functor for calculating length of edge
1548 //================================================================================
1550 double Length::GetValue( const TSequenceOfXYZ& P )
1552 switch ( P.size() ) {
1553 case 2: return getDistance( P( 1 ), P( 2 ) );
1554 case 3: return getDistance( P( 1 ), P( 2 ) ) + getDistance( P( 2 ), P( 3 ) );
1559 double Length::GetBadRate( double Value, int /*nbNodes*/ ) const
1561 // meaningless as it is not quality control functor
1565 SMDSAbs_ElementType Length::GetType() const
1567 return SMDSAbs_Edge;
1570 //================================================================================
1573 Description : Functor for calculating minimal length of element edge
1575 //================================================================================
1577 Length3D::Length3D():
1578 Length2D ( SMDSAbs_Volume )
1582 //================================================================================
1585 Description : Functor for calculating minimal length of element edge
1587 //================================================================================
1589 Length2D::Length2D( SMDSAbs_ElementType type ):
1594 bool Length2D::IsApplicable( const SMDS_MeshElement* element ) const
1596 return ( NumericalFunctor::IsApplicable( element ) &&
1597 element->GetEntityType() != SMDSEntity_Polyhedra );
1600 double Length2D::GetValue( const TSequenceOfXYZ& P )
1604 SMDSAbs_EntityType aType = P.getElementEntity();
1607 case SMDSEntity_Edge:
1609 aVal = getDistance( P( 1 ), P( 2 ) );
1611 case SMDSEntity_Quad_Edge:
1612 if (len == 3) // quadratic edge
1613 aVal = getDistance(P( 1 ),P( 3 )) + getDistance(P( 3 ),P( 2 ));
1615 case SMDSEntity_Triangle:
1616 if (len == 3){ // triangles
1617 double L1 = getDistance(P( 1 ),P( 2 ));
1618 double L2 = getDistance(P( 2 ),P( 3 ));
1619 double L3 = getDistance(P( 3 ),P( 1 ));
1620 aVal = Min(L1,Min(L2,L3));
1623 case SMDSEntity_Quadrangle:
1624 if (len == 4){ // quadrangles
1625 double L1 = getDistance(P( 1 ),P( 2 ));
1626 double L2 = getDistance(P( 2 ),P( 3 ));
1627 double L3 = getDistance(P( 3 ),P( 4 ));
1628 double L4 = getDistance(P( 4 ),P( 1 ));
1629 aVal = Min(Min(L1,L2),Min(L3,L4));
1632 case SMDSEntity_Quad_Triangle:
1633 case SMDSEntity_BiQuad_Triangle:
1634 if (len >= 6){ // quadratic triangles
1635 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1636 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1637 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 1 ));
1638 aVal = Min(L1,Min(L2,L3));
1641 case SMDSEntity_Quad_Quadrangle:
1642 case SMDSEntity_BiQuad_Quadrangle:
1643 if (len >= 8){ // quadratic quadrangles
1644 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1645 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1646 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 7 ));
1647 double L4 = getDistance(P( 7 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
1648 aVal = Min(Min(L1,L2),Min(L3,L4));
1651 case SMDSEntity_Tetra:
1652 if (len == 4){ // tetrahedra
1653 double L1 = getDistance(P( 1 ),P( 2 ));
1654 double L2 = getDistance(P( 2 ),P( 3 ));
1655 double L3 = getDistance(P( 3 ),P( 1 ));
1656 double L4 = getDistance(P( 1 ),P( 4 ));
1657 double L5 = getDistance(P( 2 ),P( 4 ));
1658 double L6 = getDistance(P( 3 ),P( 4 ));
1659 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1662 case SMDSEntity_Pyramid:
1663 if (len == 5){ // pyramid
1664 double L1 = getDistance(P( 1 ),P( 2 ));
1665 double L2 = getDistance(P( 2 ),P( 3 ));
1666 double L3 = getDistance(P( 3 ),P( 4 ));
1667 double L4 = getDistance(P( 4 ),P( 1 ));
1668 double L5 = getDistance(P( 1 ),P( 5 ));
1669 double L6 = getDistance(P( 2 ),P( 5 ));
1670 double L7 = getDistance(P( 3 ),P( 5 ));
1671 double L8 = getDistance(P( 4 ),P( 5 ));
1673 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1674 aVal = Min(aVal,Min(L7,L8));
1677 case SMDSEntity_Penta:
1678 if (len == 6) { // pentahedron
1679 double L1 = getDistance(P( 1 ),P( 2 ));
1680 double L2 = getDistance(P( 2 ),P( 3 ));
1681 double L3 = getDistance(P( 3 ),P( 1 ));
1682 double L4 = getDistance(P( 4 ),P( 5 ));
1683 double L5 = getDistance(P( 5 ),P( 6 ));
1684 double L6 = getDistance(P( 6 ),P( 4 ));
1685 double L7 = getDistance(P( 1 ),P( 4 ));
1686 double L8 = getDistance(P( 2 ),P( 5 ));
1687 double L9 = getDistance(P( 3 ),P( 6 ));
1689 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1690 aVal = Min(aVal,Min(Min(L7,L8),L9));
1693 case SMDSEntity_Hexa:
1694 if (len == 8){ // hexahedron
1695 double L1 = getDistance(P( 1 ),P( 2 ));
1696 double L2 = getDistance(P( 2 ),P( 3 ));
1697 double L3 = getDistance(P( 3 ),P( 4 ));
1698 double L4 = getDistance(P( 4 ),P( 1 ));
1699 double L5 = getDistance(P( 5 ),P( 6 ));
1700 double L6 = getDistance(P( 6 ),P( 7 ));
1701 double L7 = getDistance(P( 7 ),P( 8 ));
1702 double L8 = getDistance(P( 8 ),P( 5 ));
1703 double L9 = getDistance(P( 1 ),P( 5 ));
1704 double L10= getDistance(P( 2 ),P( 6 ));
1705 double L11= getDistance(P( 3 ),P( 7 ));
1706 double L12= getDistance(P( 4 ),P( 8 ));
1708 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1709 aVal = Min(aVal,Min(Min(L7,L8),Min(L9,L10)));
1710 aVal = Min(aVal,Min(L11,L12));
1713 case SMDSEntity_Quad_Tetra:
1714 if (len == 10){ // quadratic tetrahedron
1715 double L1 = getDistance(P( 1 ),P( 5 )) + getDistance(P( 5 ),P( 2 ));
1716 double L2 = getDistance(P( 2 ),P( 6 )) + getDistance(P( 6 ),P( 3 ));
1717 double L3 = getDistance(P( 3 ),P( 7 )) + getDistance(P( 7 ),P( 1 ));
1718 double L4 = getDistance(P( 1 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
1719 double L5 = getDistance(P( 2 ),P( 9 )) + getDistance(P( 9 ),P( 4 ));
1720 double L6 = getDistance(P( 3 ),P( 10 )) + getDistance(P( 10 ),P( 4 ));
1721 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1724 case SMDSEntity_Quad_Pyramid:
1725 if (len == 13){ // quadratic pyramid
1726 double L1 = getDistance(P( 1 ),P( 6 )) + getDistance(P( 6 ),P( 2 ));
1727 double L2 = getDistance(P( 2 ),P( 7 )) + getDistance(P( 7 ),P( 3 ));
1728 double L3 = getDistance(P( 3 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
1729 double L4 = getDistance(P( 4 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1730 double L5 = getDistance(P( 1 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1731 double L6 = getDistance(P( 2 ),P( 11 )) + getDistance(P( 11 ),P( 5 ));
1732 double L7 = getDistance(P( 3 ),P( 12 )) + getDistance(P( 12 ),P( 5 ));
1733 double L8 = getDistance(P( 4 ),P( 13 )) + getDistance(P( 13 ),P( 5 ));
1734 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1735 aVal = Min(aVal,Min(L7,L8));
1738 case SMDSEntity_Quad_Penta:
1739 case SMDSEntity_BiQuad_Penta:
1740 if (len >= 15){ // quadratic pentahedron
1741 double L1 = getDistance(P( 1 ),P( 7 )) + getDistance(P( 7 ),P( 2 ));
1742 double L2 = getDistance(P( 2 ),P( 8 )) + getDistance(P( 8 ),P( 3 ));
1743 double L3 = getDistance(P( 3 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1744 double L4 = getDistance(P( 4 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1745 double L5 = getDistance(P( 5 ),P( 11 )) + getDistance(P( 11 ),P( 6 ));
1746 double L6 = getDistance(P( 6 ),P( 12 )) + getDistance(P( 12 ),P( 4 ));
1747 double L7 = getDistance(P( 1 ),P( 13 )) + getDistance(P( 13 ),P( 4 ));
1748 double L8 = getDistance(P( 2 ),P( 14 )) + getDistance(P( 14 ),P( 5 ));
1749 double L9 = getDistance(P( 3 ),P( 15 )) + getDistance(P( 15 ),P( 6 ));
1750 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1751 aVal = Min(aVal,Min(Min(L7,L8),L9));
1754 case SMDSEntity_Quad_Hexa:
1755 case SMDSEntity_TriQuad_Hexa:
1756 if (len >= 20) { // quadratic hexahedron
1757 double L1 = getDistance(P( 1 ),P( 9 )) + getDistance(P( 9 ),P( 2 ));
1758 double L2 = getDistance(P( 2 ),P( 10 )) + getDistance(P( 10 ),P( 3 ));
1759 double L3 = getDistance(P( 3 ),P( 11 )) + getDistance(P( 11 ),P( 4 ));
1760 double L4 = getDistance(P( 4 ),P( 12 )) + getDistance(P( 12 ),P( 1 ));
1761 double L5 = getDistance(P( 5 ),P( 13 )) + getDistance(P( 13 ),P( 6 ));
1762 double L6 = getDistance(P( 6 ),P( 14 )) + getDistance(P( 14 ),P( 7 ));
1763 double L7 = getDistance(P( 7 ),P( 15 )) + getDistance(P( 15 ),P( 8 ));
1764 double L8 = getDistance(P( 8 ),P( 16 )) + getDistance(P( 16 ),P( 5 ));
1765 double L9 = getDistance(P( 1 ),P( 17 )) + getDistance(P( 17 ),P( 5 ));
1766 double L10= getDistance(P( 2 ),P( 18 )) + getDistance(P( 18 ),P( 6 ));
1767 double L11= getDistance(P( 3 ),P( 19 )) + getDistance(P( 19 ),P( 7 ));
1768 double L12= getDistance(P( 4 ),P( 20 )) + getDistance(P( 20 ),P( 8 ));
1769 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1770 aVal = Min(aVal,Min(Min(L7,L8),Min(L9,L10)));
1771 aVal = Min(aVal,Min(L11,L12));
1774 case SMDSEntity_Polygon:
1776 aVal = getDistance( P(1), P( P.size() ));
1777 for ( size_t i = 1; i < P.size(); ++i )
1778 aVal = Min( aVal, getDistance( P( i ), P( i+1 )));
1781 case SMDSEntity_Quad_Polygon:
1783 aVal = getDistance( P(1), P( P.size() )) + getDistance( P(P.size()), P( P.size()-1 ));
1784 for ( size_t i = 1; i < P.size()-1; i += 2 )
1785 aVal = Min( aVal, getDistance( P( i ), P( i+1 )) + getDistance( P( i+1 ), P( i+2 )));
1788 case SMDSEntity_Hexagonal_Prism:
1789 if (len == 12) { // hexagonal prism
1790 double L1 = getDistance(P( 1 ),P( 2 ));
1791 double L2 = getDistance(P( 2 ),P( 3 ));
1792 double L3 = getDistance(P( 3 ),P( 4 ));
1793 double L4 = getDistance(P( 4 ),P( 5 ));
1794 double L5 = getDistance(P( 5 ),P( 6 ));
1795 double L6 = getDistance(P( 6 ),P( 1 ));
1797 double L7 = getDistance(P( 7 ), P( 8 ));
1798 double L8 = getDistance(P( 8 ), P( 9 ));
1799 double L9 = getDistance(P( 9 ), P( 10 ));
1800 double L10= getDistance(P( 10 ),P( 11 ));
1801 double L11= getDistance(P( 11 ),P( 12 ));
1802 double L12= getDistance(P( 12 ),P( 7 ));
1804 double L13 = getDistance(P( 1 ),P( 7 ));
1805 double L14 = getDistance(P( 2 ),P( 8 ));
1806 double L15 = getDistance(P( 3 ),P( 9 ));
1807 double L16 = getDistance(P( 4 ),P( 10 ));
1808 double L17 = getDistance(P( 5 ),P( 11 ));
1809 double L18 = getDistance(P( 6 ),P( 12 ));
1810 aVal = Min(Min(Min(L1,L2),Min(L3,L4)),Min(L5,L6));
1811 aVal = Min(aVal, Min(Min(Min(L7,L8),Min(L9,L10)),Min(L11,L12)));
1812 aVal = Min(aVal, Min(Min(Min(L13,L14),Min(L15,L16)),Min(L17,L18)));
1815 case SMDSEntity_Polyhedra:
1827 if ( myPrecision >= 0 )
1829 double prec = pow( 10., (double)( myPrecision ) );
1830 aVal = floor( aVal * prec + 0.5 ) / prec;
1836 double Length2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1838 // meaningless as it is not a quality control functor
1842 SMDSAbs_ElementType Length2D::GetType() const
1847 Length2D::Value::Value(double theLength,long thePntId1, long thePntId2):
1850 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1851 if(thePntId1 > thePntId2){
1852 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1856 bool Length2D::Value::operator<(const Length2D::Value& x) const
1858 if(myPntId[0] < x.myPntId[0]) return true;
1859 if(myPntId[0] == x.myPntId[0])
1860 if(myPntId[1] < x.myPntId[1]) return true;
1864 void Length2D::GetValues(TValues& theValues)
1866 if ( myType == SMDSAbs_Face )
1868 for ( SMDS_FaceIteratorPtr anIter = myMesh->facesIterator(); anIter->more(); )
1870 const SMDS_MeshFace* anElem = anIter->next();
1871 if ( anElem->IsQuadratic() )
1873 // use special nodes iterator
1874 SMDS_NodeIteratorPtr anIter = anElem->interlacedNodesIterator();
1875 smIdType aNodeId[4] = { 0,0,0,0 };
1879 if ( anIter->more() )
1881 const SMDS_MeshNode* aNode = anIter->next();
1882 P[0] = P[1] = SMESH_NodeXYZ( aNode );
1883 aNodeId[0] = aNodeId[1] = aNode->GetID();
1886 for ( ; anIter->more(); )
1888 const SMDS_MeshNode* N1 = anIter->next();
1889 P[2] = SMESH_NodeXYZ( N1 );
1890 aNodeId[2] = N1->GetID();
1891 aLength = P[1].Distance(P[2]);
1892 if(!anIter->more()) break;
1893 const SMDS_MeshNode* N2 = anIter->next();
1894 P[3] = SMESH_NodeXYZ( N2 );
1895 aNodeId[3] = N2->GetID();
1896 aLength += P[2].Distance(P[3]);
1897 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1898 Value aValue2(aLength,aNodeId[2],aNodeId[3]);
1900 aNodeId[1] = aNodeId[3];
1901 theValues.insert(aValue1);
1902 theValues.insert(aValue2);
1904 aLength += P[2].Distance(P[0]);
1905 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1906 Value aValue2(aLength,aNodeId[2],aNodeId[0]);
1907 theValues.insert(aValue1);
1908 theValues.insert(aValue2);
1911 SMDS_NodeIteratorPtr aNodesIter = anElem->nodeIterator();
1912 smIdType aNodeId[2] = {0,0};
1916 const SMDS_MeshElement* aNode;
1917 if ( aNodesIter->more())
1919 aNode = aNodesIter->next();
1920 P[0] = P[1] = SMESH_NodeXYZ( aNode );
1921 aNodeId[0] = aNodeId[1] = aNode->GetID();
1924 for( ; aNodesIter->more(); )
1926 aNode = aNodesIter->next();
1927 smIdType anId = aNode->GetID();
1929 P[2] = SMESH_NodeXYZ( aNode );
1931 aLength = P[1].Distance(P[2]);
1933 Value aValue(aLength,aNodeId[1],anId);
1936 theValues.insert(aValue);
1939 aLength = P[0].Distance(P[1]);
1941 Value aValue(aLength,aNodeId[0],aNodeId[1]);
1942 theValues.insert(aValue);
1952 //================================================================================
1954 Class : Deflection2D
1955 Description : computes distance between a face center and an underlying surface
1957 //================================================================================
1959 double Deflection2D::GetValue( const TSequenceOfXYZ& P )
1961 if ( myMesh && P.getElement() )
1963 // get underlying surface
1964 if ( myShapeIndex != P.getElement()->getshapeId() )
1966 mySurface.Nullify();
1967 myShapeIndex = P.getElement()->getshapeId();
1968 const TopoDS_Shape& S =
1969 static_cast< const SMESHDS_Mesh* >( myMesh )->IndexToShape( myShapeIndex );
1970 if ( !S.IsNull() && S.ShapeType() == TopAbs_FACE )
1972 mySurface = new ShapeAnalysis_Surface( BRep_Tool::Surface( TopoDS::Face( S )));
1974 GeomLib_IsPlanarSurface isPlaneCheck( mySurface->Surface() );
1975 if ( isPlaneCheck.IsPlanar() )
1976 myPlane.reset( new gp_Pln( isPlaneCheck.Plan() ));
1981 // project gravity center to the surface
1982 if ( !mySurface.IsNull() )
1987 for ( size_t i = 0; i < P.size(); ++i )
1991 if ( SMDS_FacePositionPtr fPos = P.getElement()->GetNode( i )->GetPosition() )
1993 uv.ChangeCoord(1) += fPos->GetUParameter();
1994 uv.ChangeCoord(2) += fPos->GetVParameter();
1999 if ( nbUV ) uv /= nbUV;
2001 double maxLen = MaxElementLength2D().GetValue( P );
2002 double tol = 1e-3 * maxLen;
2006 dist = myPlane->Distance( gc );
2012 if ( uv.X() != 0 && uv.Y() != 0 ) // faster way
2013 mySurface->NextValueOfUV( uv, gc, tol, 0.5 * maxLen );
2015 mySurface->ValueOfUV( gc, tol );
2016 dist = mySurface->Gap();
2018 return Round( dist );
2024 void Deflection2D::SetMesh( const SMDS_Mesh* theMesh )
2026 NumericalFunctor::SetMesh( dynamic_cast<const SMESHDS_Mesh* >( theMesh ));
2027 myShapeIndex = -100;
2031 SMDSAbs_ElementType Deflection2D::GetType() const
2033 return SMDSAbs_Face;
2036 double Deflection2D::GetBadRate( double Value, int /*nbNodes*/ ) const
2038 // meaningless as it is not quality control functor
2042 //================================================================================
2044 Class : MultiConnection
2045 Description : Functor for calculating number of faces conneted to the edge
2047 //================================================================================
2049 double MultiConnection::GetValue( const TSequenceOfXYZ& /*P*/ )
2053 double MultiConnection::GetValue( long theId )
2055 return getNbMultiConnection( myMesh, theId );
2058 double MultiConnection::GetBadRate( double Value, int /*nbNodes*/ ) const
2060 // meaningless as it is not quality control functor
2064 SMDSAbs_ElementType MultiConnection::GetType() const
2066 return SMDSAbs_Edge;
2069 //================================================================================
2071 Class : MultiConnection2D
2072 Description : Functor for calculating number of faces conneted to the edge
2074 //================================================================================
2076 double MultiConnection2D::GetValue( const TSequenceOfXYZ& /*P*/ )
2081 double MultiConnection2D::GetValue( long theElementId )
2085 const SMDS_MeshElement* aFaceElem = myMesh->FindElement(theElementId);
2086 SMDSAbs_ElementType aType = aFaceElem->GetType();
2091 int i = 0, len = aFaceElem->NbNodes();
2092 SMDS_ElemIteratorPtr anIter = aFaceElem->nodesIterator();
2095 const SMDS_MeshNode *aNode, *aNode0 = 0;
2096 NCollection_Map< smIdType, smIdHasher > aMap, aMapPrev;
2098 for (i = 0; i <= len; i++) {
2103 if (anIter->more()) {
2104 aNode = (SMDS_MeshNode*)anIter->next();
2112 if (i == 0) aNode0 = aNode;
2114 SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator();
2115 while (anElemIter->more()) {
2116 const SMDS_MeshElement* anElem = anElemIter->next();
2117 if (anElem != 0 && anElem->GetType() == SMDSAbs_Face) {
2118 smIdType anId = anElem->GetID();
2121 if (aMapPrev.Contains(anId)) {
2126 aResult = Max(aResult, aNb);
2137 double MultiConnection2D::GetBadRate( double Value, int /*nbNodes*/ ) const
2139 // meaningless as it is not quality control functor
2143 SMDSAbs_ElementType MultiConnection2D::GetType() const
2145 return SMDSAbs_Face;
2148 MultiConnection2D::Value::Value(long thePntId1, long thePntId2)
2150 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
2151 if(thePntId1 > thePntId2){
2152 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
2156 bool MultiConnection2D::Value::operator<(const MultiConnection2D::Value& x) const
2158 if(myPntId[0] < x.myPntId[0]) return true;
2159 if(myPntId[0] == x.myPntId[0])
2160 if(myPntId[1] < x.myPntId[1]) return true;
2164 void MultiConnection2D::GetValues(MValues& theValues)
2166 if ( !myMesh ) return;
2167 for ( SMDS_FaceIteratorPtr anIter = myMesh->facesIterator(); anIter->more(); )
2169 const SMDS_MeshFace* anElem = anIter->next();
2170 SMDS_NodeIteratorPtr aNodesIter = anElem->interlacedNodesIterator();
2172 const SMDS_MeshNode* aNode1 = anElem->GetNode( anElem->NbNodes() - 1 );
2173 const SMDS_MeshNode* aNode2;
2174 for ( ; aNodesIter->more(); )
2176 aNode2 = aNodesIter->next();
2178 Value aValue ( aNode1->GetID(), aNode2->GetID() );
2179 MValues::iterator aItr = theValues.insert( std::make_pair( aValue, 0 )).first;
2187 //================================================================================
2189 Class : BallDiameter
2190 Description : Functor returning diameter of a ball element
2192 //================================================================================
2194 double BallDiameter::GetValue( long theId )
2196 double diameter = 0;
2198 if ( const SMDS_BallElement* ball =
2199 myMesh->DownCast< SMDS_BallElement >( myMesh->FindElement( theId )))
2201 diameter = ball->GetDiameter();
2206 double BallDiameter::GetBadRate( double Value, int /*nbNodes*/ ) const
2208 // meaningless as it is not a quality control functor
2212 SMDSAbs_ElementType BallDiameter::GetType() const
2214 return SMDSAbs_Ball;
2217 //================================================================================
2219 Class : NodeConnectivityNumber
2220 Description : Functor returning number of elements connected to a node
2222 //================================================================================
2224 double NodeConnectivityNumber::GetValue( long theId )
2228 if ( const SMDS_MeshNode* node = myMesh->FindNode( theId ))
2230 SMDSAbs_ElementType type;
2231 if ( myMesh->NbVolumes() > 0 )
2232 type = SMDSAbs_Volume;
2233 else if ( myMesh->NbFaces() > 0 )
2234 type = SMDSAbs_Face;
2235 else if ( myMesh->NbEdges() > 0 )
2236 type = SMDSAbs_Edge;
2239 nb = node->NbInverseElements( type );
2244 double NodeConnectivityNumber::GetBadRate( double Value, int /*nbNodes*/ ) const
2249 SMDSAbs_ElementType NodeConnectivityNumber::GetType() const
2251 return SMDSAbs_Node;
2258 //================================================================================
2260 Class : BadOrientedVolume
2261 Description : Predicate bad oriented volumes
2263 //================================================================================
2265 BadOrientedVolume::BadOrientedVolume()
2270 void BadOrientedVolume::SetMesh( const SMDS_Mesh* theMesh )
2275 bool BadOrientedVolume::IsSatisfy( long theId )
2280 SMDS_VolumeTool vTool( myMesh->FindElement( theId ));
2283 if ( vTool.IsPoly() )
2286 for ( int i = 0; i < vTool.NbFaces() && isOk; ++i )
2287 isOk = vTool.IsFaceExternal( i );
2291 isOk = vTool.IsForward();
2296 SMDSAbs_ElementType BadOrientedVolume::GetType() const
2298 return SMDSAbs_Volume;
2302 Class : BareBorderVolume
2305 bool BareBorderVolume::IsSatisfy(long theElementId )
2307 SMDS_VolumeTool myTool;
2308 if ( myTool.Set( myMesh->FindElement(theElementId)))
2310 for ( int iF = 0; iF < myTool.NbFaces(); ++iF )
2311 if ( myTool.IsFreeFace( iF ))
2313 const SMDS_MeshNode** n = myTool.GetFaceNodes(iF);
2314 std::vector< const SMDS_MeshNode*> nodes( n, n+myTool.NbFaceNodes(iF));
2315 if ( !myMesh->FindElement( nodes, SMDSAbs_Face, /*Nomedium=*/false))
2322 //================================================================================
2324 Class : BareBorderFace
2326 //================================================================================
2328 bool BareBorderFace::IsSatisfy(long theElementId )
2331 if ( const SMDS_MeshElement* face = myMesh->FindElement(theElementId))
2333 if ( face->GetType() == SMDSAbs_Face )
2335 int nbN = face->NbCornerNodes();
2336 for ( int i = 0; i < nbN && !ok; ++i )
2338 // check if a link is shared by another face
2339 const SMDS_MeshNode* n1 = face->GetNode( i );
2340 const SMDS_MeshNode* n2 = face->GetNode( (i+1)%nbN );
2341 SMDS_ElemIteratorPtr fIt = n1->GetInverseElementIterator( SMDSAbs_Face );
2342 bool isShared = false;
2343 while ( !isShared && fIt->more() )
2345 const SMDS_MeshElement* f = fIt->next();
2346 isShared = ( f != face && f->GetNodeIndex(n2) != -1 );
2350 const int iQuad = face->IsQuadratic();
2351 myLinkNodes.resize( 2 + iQuad);
2352 myLinkNodes[0] = n1;
2353 myLinkNodes[1] = n2;
2355 myLinkNodes[2] = face->GetNode( i+nbN );
2356 ok = !myMesh->FindElement( myLinkNodes, SMDSAbs_Edge, /*noMedium=*/false);
2364 //================================================================================
2366 Class : OverConstrainedVolume
2368 //================================================================================
2370 bool OverConstrainedVolume::IsSatisfy(long theElementId )
2372 // An element is over-constrained if it has N-1 free borders where
2373 // N is the number of edges/faces for a 2D/3D element.
2374 SMDS_VolumeTool myTool;
2375 if ( myTool.Set( myMesh->FindElement(theElementId)))
2377 int nbSharedFaces = 0;
2378 for ( int iF = 0; iF < myTool.NbFaces(); ++iF )
2379 if ( !myTool.IsFreeFace( iF ) && ++nbSharedFaces > 1 )
2381 return ( nbSharedFaces == 1 );
2386 //================================================================================
2388 Class : OverConstrainedFace
2390 //================================================================================
2392 bool OverConstrainedFace::IsSatisfy(long theElementId )
2394 // An element is over-constrained if it has N-1 free borders where
2395 // N is the number of edges/faces for a 2D/3D element.
2396 if ( const SMDS_MeshElement* face = myMesh->FindElement(theElementId))
2397 if ( face->GetType() == SMDSAbs_Face )
2399 int nbSharedBorders = 0;
2400 int nbN = face->NbCornerNodes();
2401 for ( int i = 0; i < nbN; ++i )
2403 // check if a link is shared by another face
2404 const SMDS_MeshNode* n1 = face->GetNode( i );
2405 const SMDS_MeshNode* n2 = face->GetNode( (i+1)%nbN );
2406 SMDS_ElemIteratorPtr fIt = n1->GetInverseElementIterator( SMDSAbs_Face );
2407 bool isShared = false;
2408 while ( !isShared && fIt->more() )
2410 const SMDS_MeshElement* f = fIt->next();
2411 isShared = ( f != face && f->GetNodeIndex(n2) != -1 );
2413 if ( isShared && ++nbSharedBorders > 1 )
2416 return ( nbSharedBorders == 1 );
2421 //================================================================================
2423 Class : CoincidentNodes
2424 Description : Predicate of Coincident nodes
2426 //================================================================================
2428 CoincidentNodes::CoincidentNodes()
2433 bool CoincidentNodes::IsSatisfy( long theElementId )
2435 return myCoincidentIDs.Contains( theElementId );
2438 SMDSAbs_ElementType CoincidentNodes::GetType() const
2440 return SMDSAbs_Node;
2443 void CoincidentNodes::SetTolerance( const double theToler )
2445 if ( myToler != theToler )
2452 void CoincidentNodes::SetMesh( const SMDS_Mesh* theMesh )
2454 myMeshModifTracer.SetMesh( theMesh );
2455 if ( myMeshModifTracer.IsMeshModified() )
2457 TIDSortedNodeSet nodesToCheck;
2458 SMDS_NodeIteratorPtr nIt = theMesh->nodesIterator();
2459 while ( nIt->more() )
2460 nodesToCheck.insert( nodesToCheck.end(), nIt->next() );
2462 std::list< std::list< const SMDS_MeshNode*> > nodeGroups;
2463 SMESH_OctreeNode::FindCoincidentNodes ( nodesToCheck, &nodeGroups, myToler );
2465 myCoincidentIDs.Clear();
2466 std::list< std::list< const SMDS_MeshNode*> >::iterator groupIt = nodeGroups.begin();
2467 for ( ; groupIt != nodeGroups.end(); ++groupIt )
2469 std::list< const SMDS_MeshNode*>& coincNodes = *groupIt;
2470 std::list< const SMDS_MeshNode*>::iterator n = coincNodes.begin();
2471 for ( ; n != coincNodes.end(); ++n )
2472 myCoincidentIDs.Add( (*n)->GetID() );
2477 //================================================================================
2479 Class : CoincidentElements
2480 Description : Predicate of Coincident Elements
2481 Note : This class is suitable only for visualization of Coincident Elements
2483 //================================================================================
2485 CoincidentElements::CoincidentElements()
2490 void CoincidentElements::SetMesh( const SMDS_Mesh* theMesh )
2495 bool CoincidentElements::IsSatisfy( long theElementId )
2497 if ( !myMesh ) return false;
2499 if ( const SMDS_MeshElement* e = myMesh->FindElement( theElementId ))
2501 if ( e->GetType() != GetType() ) return false;
2502 std::set< const SMDS_MeshNode* > elemNodes( e->begin_nodes(), e->end_nodes() );
2503 const int nbNodes = e->NbNodes();
2504 SMDS_ElemIteratorPtr invIt = (*elemNodes.begin())->GetInverseElementIterator( GetType() );
2505 while ( invIt->more() )
2507 const SMDS_MeshElement* e2 = invIt->next();
2508 if ( e2 == e || e2->NbNodes() != nbNodes ) continue;
2510 bool sameNodes = true;
2511 for ( size_t i = 0; i < elemNodes.size() && sameNodes; ++i )
2512 sameNodes = ( elemNodes.count( e2->GetNode( i )));
2520 SMDSAbs_ElementType CoincidentElements1D::GetType() const
2522 return SMDSAbs_Edge;
2524 SMDSAbs_ElementType CoincidentElements2D::GetType() const
2526 return SMDSAbs_Face;
2528 SMDSAbs_ElementType CoincidentElements3D::GetType() const
2530 return SMDSAbs_Volume;
2534 //================================================================================
2537 Description : Predicate for free borders
2539 //================================================================================
2541 FreeBorders::FreeBorders()
2546 void FreeBorders::SetMesh( const SMDS_Mesh* theMesh )
2551 bool FreeBorders::IsSatisfy( long theId )
2553 return getNbMultiConnection( myMesh, theId ) == 1;
2556 SMDSAbs_ElementType FreeBorders::GetType() const
2558 return SMDSAbs_Edge;
2562 //================================================================================
2565 Description : Predicate for free Edges
2567 //================================================================================
2569 FreeEdges::FreeEdges()
2574 void FreeEdges::SetMesh( const SMDS_Mesh* theMesh )
2579 bool FreeEdges::IsFreeEdge( const SMDS_MeshNode** theNodes, const smIdType theFaceId )
2581 SMDS_ElemIteratorPtr anElemIter = theNodes[ 0 ]->GetInverseElementIterator(SMDSAbs_Face);
2582 while( anElemIter->more() )
2584 if ( const SMDS_MeshElement* anElem = anElemIter->next())
2586 const smIdType anId = anElem->GetID();
2587 if ( anId != theFaceId && anElem->GetNodeIndex( theNodes[1] ) >= 0 )
2594 bool FreeEdges::IsSatisfy( long theId )
2599 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
2600 if ( aFace == 0 || aFace->GetType() != SMDSAbs_Face || aFace->NbNodes() < 3 )
2603 SMDS_NodeIteratorPtr anIter = aFace->interlacedNodesIterator();
2607 int i = 0, nbNodes = aFace->NbNodes();
2608 std::vector <const SMDS_MeshNode*> aNodes( nbNodes+1 );
2609 while( anIter->more() )
2610 if ( ! ( aNodes[ i++ ] = anIter->next() ))
2612 aNodes[ nbNodes ] = aNodes[ 0 ];
2614 for ( i = 0; i < nbNodes; i++ )
2615 if ( IsFreeEdge( &aNodes[ i ], theId ) )
2621 SMDSAbs_ElementType FreeEdges::GetType() const
2623 return SMDSAbs_Face;
2626 FreeEdges::Border::Border(long theElemId, long thePntId1, long thePntId2):
2629 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
2630 if(thePntId1 > thePntId2){
2631 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
2635 bool FreeEdges::Border::operator<(const FreeEdges::Border& x) const{
2636 if(myPntId[0] < x.myPntId[0]) return true;
2637 if(myPntId[0] == x.myPntId[0])
2638 if(myPntId[1] < x.myPntId[1]) return true;
2642 inline void UpdateBorders(const FreeEdges::Border& theBorder,
2643 FreeEdges::TBorders& theRegistry,
2644 FreeEdges::TBorders& theContainer)
2646 if(theRegistry.find(theBorder) == theRegistry.end()){
2647 theRegistry.insert(theBorder);
2648 theContainer.insert(theBorder);
2650 theContainer.erase(theBorder);
2654 void FreeEdges::GetBoreders(TBorders& theBorders)
2657 for ( SMDS_FaceIteratorPtr anIter = myMesh->facesIterator(); anIter->more(); )
2659 const SMDS_MeshFace* anElem = anIter->next();
2660 long anElemId = anElem->GetID();
2661 SMDS_NodeIteratorPtr aNodesIter = anElem->interlacedNodesIterator();
2662 if ( !aNodesIter->more() ) continue;
2663 long aNodeId[2] = {0,0};
2664 aNodeId[0] = anElem->GetNode( anElem->NbNodes()-1 )->GetID();
2665 for ( ; aNodesIter->more(); )
2667 aNodeId[1] = aNodesIter->next()->GetID();
2668 Border aBorder( anElemId, aNodeId[0], aNodeId[1] );
2669 UpdateBorders( aBorder, aRegistry, theBorders );
2670 aNodeId[0] = aNodeId[1];
2675 //================================================================================
2678 Description : Predicate for free nodes
2680 //================================================================================
2682 FreeNodes::FreeNodes()
2687 void FreeNodes::SetMesh( const SMDS_Mesh* theMesh )
2692 bool FreeNodes::IsSatisfy( long theNodeId )
2694 const SMDS_MeshNode* aNode = myMesh->FindNode( theNodeId );
2698 return (aNode->NbInverseElements() < 1);
2701 SMDSAbs_ElementType FreeNodes::GetType() const
2703 return SMDSAbs_Node;
2707 //================================================================================
2710 Description : Predicate for free faces
2712 //================================================================================
2714 FreeFaces::FreeFaces()
2719 void FreeFaces::SetMesh( const SMDS_Mesh* theMesh )
2724 bool FreeFaces::IsSatisfy( long theId )
2726 if (!myMesh) return false;
2727 // check that faces nodes refers to less than two common volumes
2728 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
2729 if ( !aFace || aFace->GetType() != SMDSAbs_Face )
2732 int nbNode = aFace->NbNodes();
2734 // collect volumes to check that number of volumes with count equal nbNode not less than 2
2735 typedef std::map< SMDS_MeshElement*, int > TMapOfVolume; // map of volume counters
2736 typedef std::map< SMDS_MeshElement*, int >::iterator TItrMapOfVolume; // iterator
2737 TMapOfVolume mapOfVol;
2739 SMDS_ElemIteratorPtr nodeItr = aFace->nodesIterator();
2740 while ( nodeItr->more() )
2742 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(nodeItr->next());
2743 if ( !aNode ) continue;
2744 SMDS_ElemIteratorPtr volItr = aNode->GetInverseElementIterator(SMDSAbs_Volume);
2745 while ( volItr->more() )
2747 SMDS_MeshElement* aVol = (SMDS_MeshElement*)volItr->next();
2748 TItrMapOfVolume itr = mapOfVol.insert( std::make_pair( aVol, 0 )).first;
2753 TItrMapOfVolume volItr = mapOfVol.begin();
2754 TItrMapOfVolume volEnd = mapOfVol.end();
2755 for ( ; volItr != volEnd; ++volItr )
2756 if ( (*volItr).second >= nbNode )
2758 // face is not free if number of volumes constructed on their nodes more than one
2762 SMDSAbs_ElementType FreeFaces::GetType() const
2764 return SMDSAbs_Face;
2767 //================================================================================
2769 Class : LinearOrQuadratic
2770 Description : Predicate to verify whether a mesh element is linear
2772 //================================================================================
2774 LinearOrQuadratic::LinearOrQuadratic()
2779 void LinearOrQuadratic::SetMesh( const SMDS_Mesh* theMesh )
2784 bool LinearOrQuadratic::IsSatisfy( long theId )
2786 if (!myMesh) return false;
2787 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2788 if ( !anElem || (myType != SMDSAbs_All && anElem->GetType() != myType) )
2790 return (!anElem->IsQuadratic());
2793 void LinearOrQuadratic::SetType( SMDSAbs_ElementType theType )
2798 SMDSAbs_ElementType LinearOrQuadratic::GetType() const
2803 //================================================================================
2806 Description : Functor for check color of group to which mesh element belongs to
2808 //================================================================================
2810 GroupColor::GroupColor()
2814 bool GroupColor::IsSatisfy( long theId )
2816 return myIDs.count( theId );
2819 void GroupColor::SetType( SMDSAbs_ElementType theType )
2824 SMDSAbs_ElementType GroupColor::GetType() const
2829 static bool isEqual( const Quantity_Color& theColor1,
2830 const Quantity_Color& theColor2 )
2832 // tolerance to compare colors
2833 const double tol = 5*1e-3;
2834 return ( fabs( theColor1.Red() - theColor2.Red() ) < tol &&
2835 fabs( theColor1.Green() - theColor2.Green() ) < tol &&
2836 fabs( theColor1.Blue() - theColor2.Blue() ) < tol );
2839 void GroupColor::SetMesh( const SMDS_Mesh* theMesh )
2843 const SMESHDS_Mesh* aMesh = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
2847 int nbGrp = aMesh->GetNbGroups();
2851 // iterates on groups and find necessary elements ids
2852 const std::set<SMESHDS_GroupBase*>& aGroups = aMesh->GetGroups();
2853 std::set<SMESHDS_GroupBase*>::const_iterator GrIt = aGroups.begin();
2854 for (; GrIt != aGroups.end(); GrIt++)
2856 SMESHDS_GroupBase* aGrp = (*GrIt);
2859 // check type and color of group
2860 if ( !isEqual( myColor, aGrp->GetColor() ))
2863 // IPAL52867 (prevent infinite recursion via GroupOnFilter)
2864 if ( SMESHDS_GroupOnFilter * gof = dynamic_cast< SMESHDS_GroupOnFilter* >( aGrp ))
2865 if ( gof->GetPredicate().get() == this )
2868 SMDSAbs_ElementType aGrpElType = (SMDSAbs_ElementType)aGrp->GetType();
2869 if ( myType == aGrpElType || (myType == SMDSAbs_All && aGrpElType != SMDSAbs_Node) ) {
2870 // add elements IDS into control
2871 smIdType aSize = aGrp->Extent();
2872 for (smIdType i = 0; i < aSize; i++)
2873 myIDs.insert( aGrp->GetID(i+1) );
2878 void GroupColor::SetColorStr( const TCollection_AsciiString& theStr )
2880 Kernel_Utils::Localizer loc;
2881 TCollection_AsciiString aStr = theStr;
2882 aStr.RemoveAll( ' ' );
2883 aStr.RemoveAll( '\t' );
2884 for ( int aPos = aStr.Search( ";;" ); aPos != -1; aPos = aStr.Search( ";;" ) )
2885 aStr.Remove( aPos, 2 );
2886 Standard_Real clr[3];
2887 clr[0] = clr[1] = clr[2] = 0.;
2888 for ( int i = 0; i < 3; i++ ) {
2889 TCollection_AsciiString tmpStr = aStr.Token( ";", i+1 );
2890 if ( !tmpStr.IsEmpty() && tmpStr.IsRealValue() )
2891 clr[i] = tmpStr.RealValue();
2893 myColor = Quantity_Color( clr[0], clr[1], clr[2], Quantity_TOC_RGB );
2896 //=======================================================================
2897 // name : GetRangeStr
2898 // Purpose : Get range as a string.
2899 // Example: "1,2,3,50-60,63,67,70-"
2900 //=======================================================================
2902 void GroupColor::GetColorStr( TCollection_AsciiString& theResStr ) const
2905 theResStr += TCollection_AsciiString( myColor.Red() );
2906 theResStr += TCollection_AsciiString( ";" ) + TCollection_AsciiString( myColor.Green() );
2907 theResStr += TCollection_AsciiString( ";" ) + TCollection_AsciiString( myColor.Blue() );
2910 //================================================================================
2912 Class : ElemGeomType
2913 Description : Predicate to check element geometry type
2915 //================================================================================
2917 ElemGeomType::ElemGeomType()
2920 myType = SMDSAbs_All;
2921 myGeomType = SMDSGeom_TRIANGLE;
2924 void ElemGeomType::SetMesh( const SMDS_Mesh* theMesh )
2929 bool ElemGeomType::IsSatisfy( long theId )
2931 if (!myMesh) return false;
2932 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2935 const SMDSAbs_ElementType anElemType = anElem->GetType();
2936 if ( myType != SMDSAbs_All && anElemType != myType )
2938 bool isOk = ( anElem->GetGeomType() == myGeomType );
2942 void ElemGeomType::SetType( SMDSAbs_ElementType theType )
2947 SMDSAbs_ElementType ElemGeomType::GetType() const
2952 void ElemGeomType::SetGeomType( SMDSAbs_GeometryType theType )
2954 myGeomType = theType;
2957 SMDSAbs_GeometryType ElemGeomType::GetGeomType() const
2962 //================================================================================
2964 Class : ElemEntityType
2965 Description : Predicate to check element entity type
2967 //================================================================================
2969 ElemEntityType::ElemEntityType():
2971 myType( SMDSAbs_All ),
2972 myEntityType( SMDSEntity_0D )
2976 void ElemEntityType::SetMesh( const SMDS_Mesh* theMesh )
2981 bool ElemEntityType::IsSatisfy( long theId )
2983 if ( !myMesh ) return false;
2984 if ( myType == SMDSAbs_Node )
2985 return myMesh->FindNode( theId );
2986 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2988 myEntityType == anElem->GetEntityType() );
2991 void ElemEntityType::SetType( SMDSAbs_ElementType theType )
2996 SMDSAbs_ElementType ElemEntityType::GetType() const
3001 void ElemEntityType::SetElemEntityType( SMDSAbs_EntityType theEntityType )
3003 myEntityType = theEntityType;
3006 SMDSAbs_EntityType ElemEntityType::GetElemEntityType() const
3008 return myEntityType;
3011 //================================================================================
3013 * \brief Class ConnectedElements
3015 //================================================================================
3017 ConnectedElements::ConnectedElements():
3018 myNodeID(0), myType( SMDSAbs_All ), myOkIDsReady( false ) {}
3020 SMDSAbs_ElementType ConnectedElements::GetType() const
3023 smIdType ConnectedElements::GetNode() const
3024 { return myXYZ.empty() ? myNodeID : 0; } // myNodeID can be found by myXYZ
3026 std::vector<double> ConnectedElements::GetPoint() const
3029 void ConnectedElements::clearOkIDs()
3030 { myOkIDsReady = false; myOkIDs.clear(); }
3032 void ConnectedElements::SetType( SMDSAbs_ElementType theType )
3034 if ( myType != theType || myMeshModifTracer.IsMeshModified() )
3039 void ConnectedElements::SetMesh( const SMDS_Mesh* theMesh )
3041 myMeshModifTracer.SetMesh( theMesh );
3042 if ( myMeshModifTracer.IsMeshModified() )
3045 if ( !myXYZ.empty() )
3046 SetPoint( myXYZ[0], myXYZ[1], myXYZ[2] ); // find a node near myXYZ it in a new mesh
3050 void ConnectedElements::SetNode( smIdType nodeID )
3055 bool isSameDomain = false;
3056 if ( myOkIDsReady && myMeshModifTracer.GetMesh() && !myMeshModifTracer.IsMeshModified() )
3057 if ( const SMDS_MeshNode* n = myMeshModifTracer.GetMesh()->FindNode( myNodeID ))
3059 SMDS_ElemIteratorPtr eIt = n->GetInverseElementIterator( myType );
3060 while ( !isSameDomain && eIt->more() )
3061 isSameDomain = IsSatisfy( eIt->next()->GetID() );
3063 if ( !isSameDomain )
3067 void ConnectedElements::SetPoint( double x, double y, double z )
3075 bool isSameDomain = false;
3077 // find myNodeID by myXYZ if possible
3078 if ( myMeshModifTracer.GetMesh() )
3080 SMESHUtils::Deleter<SMESH_ElementSearcher> searcher
3081 ( SMESH_MeshAlgos::GetElementSearcher( (SMDS_Mesh&) *myMeshModifTracer.GetMesh() ));
3083 std::vector< const SMDS_MeshElement* > foundElems;
3084 searcher->FindElementsByPoint( gp_Pnt(x,y,z), SMDSAbs_All, foundElems );
3086 if ( !foundElems.empty() )
3088 myNodeID = foundElems[0]->GetNode(0)->GetID();
3089 if ( myOkIDsReady && !myMeshModifTracer.IsMeshModified() )
3090 isSameDomain = IsSatisfy( foundElems[0]->GetID() );
3093 if ( !isSameDomain )
3097 bool ConnectedElements::IsSatisfy( long theElementId )
3099 // Here we do NOT check if the mesh has changed, we do it in Set...() only!!!
3101 if ( !myOkIDsReady )
3103 if ( !myMeshModifTracer.GetMesh() )
3105 const SMDS_MeshNode* node0 = myMeshModifTracer.GetMesh()->FindNode( myNodeID );
3109 std::list< const SMDS_MeshNode* > nodeQueue( 1, node0 );
3110 std::set< smIdType > checkedNodeIDs;
3112 // foreach node in nodeQueue:
3113 // foreach element sharing a node:
3114 // add ID of an element of myType to myOkIDs;
3115 // push all element nodes absent from checkedNodeIDs to nodeQueue;
3116 while ( !nodeQueue.empty() )
3118 const SMDS_MeshNode* node = nodeQueue.front();
3119 nodeQueue.pop_front();
3121 // loop on elements sharing the node
3122 SMDS_ElemIteratorPtr eIt = node->GetInverseElementIterator();
3123 while ( eIt->more() )
3125 // keep elements of myType
3126 const SMDS_MeshElement* element = eIt->next();
3127 if ( myType == SMDSAbs_All || element->GetType() == myType )
3128 myOkIDs.insert( myOkIDs.end(), element->GetID() );
3130 // enqueue nodes of the element
3131 SMDS_ElemIteratorPtr nIt = element->nodesIterator();
3132 while ( nIt->more() )
3134 const SMDS_MeshNode* n = static_cast< const SMDS_MeshNode* >( nIt->next() );
3135 if ( checkedNodeIDs.insert( n->GetID()).second )
3136 nodeQueue.push_back( n );
3140 if ( myType == SMDSAbs_Node )
3141 std::swap( myOkIDs, checkedNodeIDs );
3143 size_t totalNbElems = myMeshModifTracer.GetMesh()->GetMeshInfo().NbElements( myType );
3144 if ( myOkIDs.size() == totalNbElems )
3147 myOkIDsReady = true;
3150 return myOkIDs.empty() ? true : myOkIDs.count( theElementId );
3153 //================================================================================
3155 * \brief Class CoplanarFaces
3157 //================================================================================
3161 inline bool isLessAngle( const gp_Vec& v1, const gp_Vec& v2, const double cos )
3163 double dot = v1 * v2; // cos * |v1| * |v2|
3164 double l1 = v1.SquareMagnitude();
3165 double l2 = v2.SquareMagnitude();
3166 return (( dot * cos >= 0 ) &&
3167 ( dot * dot ) / l1 / l2 >= ( cos * cos ));
3170 CoplanarFaces::CoplanarFaces()
3171 : myFaceID(0), myToler(0)
3174 void CoplanarFaces::SetMesh( const SMDS_Mesh* theMesh )
3176 myMeshModifTracer.SetMesh( theMesh );
3177 if ( myMeshModifTracer.IsMeshModified() )
3179 // Build a set of coplanar face ids
3181 myCoplanarIDs.Clear();
3183 if ( !myMeshModifTracer.GetMesh() || !myFaceID || !myToler )
3186 const SMDS_MeshElement* face = myMeshModifTracer.GetMesh()->FindElement( myFaceID );
3187 if ( !face || face->GetType() != SMDSAbs_Face )
3191 gp_Vec myNorm = getNormale( static_cast<const SMDS_MeshFace*>(face), &normOK );
3195 const double cosTol = Cos( myToler * M_PI / 180. );
3196 NCollection_Map< SMESH_TLink, SMESH_TLink > checkedLinks;
3198 std::list< std::pair< const SMDS_MeshElement*, gp_Vec > > faceQueue;
3199 faceQueue.push_back( std::make_pair( face, myNorm ));
3200 while ( !faceQueue.empty() )
3202 face = faceQueue.front().first;
3203 myNorm = faceQueue.front().second;
3204 faceQueue.pop_front();
3206 for ( int i = 0, nbN = face->NbCornerNodes(); i < nbN; ++i )
3208 const SMDS_MeshNode* n1 = face->GetNode( i );
3209 const SMDS_MeshNode* n2 = face->GetNode(( i+1 )%nbN);
3210 if ( !checkedLinks.Add( SMESH_TLink( n1, n2 )))
3212 SMDS_ElemIteratorPtr fIt = n1->GetInverseElementIterator(SMDSAbs_Face);
3213 while ( fIt->more() )
3215 const SMDS_MeshElement* f = fIt->next();
3216 if ( f->GetNodeIndex( n2 ) > -1 )
3218 gp_Vec norm = getNormale( static_cast<const SMDS_MeshFace*>(f), &normOK );
3219 if (!normOK || isLessAngle( myNorm, norm, cosTol))
3221 myCoplanarIDs.Add( f->GetID() );
3222 faceQueue.push_back( std::make_pair( f, norm ));
3230 bool CoplanarFaces::IsSatisfy( long theElementId )
3232 return myCoplanarIDs.Contains( theElementId );
3237 *Description : Predicate for Range of Ids.
3238 * Range may be specified with two ways.
3239 * 1. Using AddToRange method
3240 * 2. With SetRangeStr method. Parameter of this method is a string
3241 * like as "1,2,3,50-60,63,67,70-"
3244 //=======================================================================
3245 // name : RangeOfIds
3246 // Purpose : Constructor
3247 //=======================================================================
3248 RangeOfIds::RangeOfIds()
3251 myType = SMDSAbs_All;
3254 //=======================================================================
3256 // Purpose : Set mesh
3257 //=======================================================================
3258 void RangeOfIds::SetMesh( const SMDS_Mesh* theMesh )
3263 //=======================================================================
3264 // name : AddToRange
3265 // Purpose : Add ID to the range
3266 //=======================================================================
3267 bool RangeOfIds::AddToRange( long theEntityId )
3269 myIds.Add( theEntityId );
3273 //=======================================================================
3274 // name : GetRangeStr
3275 // Purpose : Get range as a string.
3276 // Example: "1,2,3,50-60,63,67,70-"
3277 //=======================================================================
3278 void RangeOfIds::GetRangeStr( TCollection_AsciiString& theResStr )
3283 TColStd_SequenceOfAsciiString aStrSeq;
3285 TIDsMap::Iterator anIter( myIds );
3286 for ( ; anIter.More(); anIter.Next() )
3288 smIdType anId = anIter.Key();
3289 TCollection_AsciiString aStr( FromIdType<int>(anId) );
3290 anIntSeq.Append( anId );
3291 aStrSeq.Append( aStr );
3294 for ( smIdType i = 1, n = myMin.size(); i <= n; i++ )
3296 smIdType aMinId = myMin[i];
3297 smIdType aMaxId = myMax[i];
3300 if ( aMinId != IntegerFirst() )
3305 if ( aMaxId != std::numeric_limits<smIdType>::max() )
3308 // find position of the string in result sequence and insert string in it
3309 if ( anIntSeq.Length() == 0 )
3311 anIntSeq.Append( aMinId );
3312 aStrSeq.Append( (const char*)aStr );
3316 if ( aMinId < anIntSeq.First() )
3318 anIntSeq.Prepend( aMinId );
3319 aStrSeq.Prepend( (const char*)aStr );
3321 else if ( aMinId > anIntSeq.Last() )
3323 anIntSeq.Append( aMinId );
3324 aStrSeq.Append( (const char*)aStr );
3327 for ( int j = 1, k = anIntSeq.Length(); j <= k; j++ )
3328 if ( aMinId < anIntSeq( j ) )
3330 anIntSeq.InsertBefore( j, aMinId );
3331 aStrSeq.InsertBefore( j, (const char*)aStr );
3337 if ( aStrSeq.Length() == 0 )
3340 theResStr = aStrSeq( 1 );
3341 for ( int j = 2, k = aStrSeq.Length(); j <= k; j++ )
3344 theResStr += aStrSeq( j );
3348 //=======================================================================
3349 // name : SetRangeStr
3350 // Purpose : Define range with string
3351 // Example of entry string: "1,2,3,50-60,63,67,70-"
3352 //=======================================================================
3353 bool RangeOfIds::SetRangeStr( const TCollection_AsciiString& theStr )
3359 TCollection_AsciiString aStr = theStr;
3360 for ( int i = 1; i <= aStr.Length(); ++i )
3362 char c = aStr.Value( i );
3363 if ( !isdigit( c ) && c != ',' && c != '-' )
3364 aStr.SetValue( i, ',');
3366 aStr.RemoveAll( ' ' );
3368 TCollection_AsciiString tmpStr = aStr.Token( ",", 1 );
3370 while ( tmpStr != "" )
3372 tmpStr = aStr.Token( ",", i++ );
3373 int aPos = tmpStr.Search( '-' );
3377 if ( tmpStr.IsIntegerValue() )
3378 myIds.Add( tmpStr.IntegerValue() );
3384 TCollection_AsciiString aMaxStr = tmpStr.Split( aPos );
3385 TCollection_AsciiString aMinStr = tmpStr;
3387 while ( aMinStr.Search( "-" ) != -1 ) aMinStr.RemoveAll( '-' );
3388 while ( aMaxStr.Search( "-" ) != -1 ) aMaxStr.RemoveAll( '-' );
3390 if ( (!aMinStr.IsEmpty() && !aMinStr.IsIntegerValue()) ||
3391 (!aMaxStr.IsEmpty() && !aMaxStr.IsIntegerValue()) )
3394 myMin.push_back( aMinStr.IsEmpty() ? IntegerFirst() : aMinStr.IntegerValue() );
3395 myMax.push_back( aMaxStr.IsEmpty() ? IntegerLast() : aMaxStr.IntegerValue() );
3402 //=======================================================================
3404 // Purpose : Get type of supported entities
3405 //=======================================================================
3406 SMDSAbs_ElementType RangeOfIds::GetType() const
3411 //=======================================================================
3413 // Purpose : Set type of supported entities
3414 //=======================================================================
3415 void RangeOfIds::SetType( SMDSAbs_ElementType theType )
3420 //=======================================================================
3422 // Purpose : Verify whether entity satisfies to this rpedicate
3423 //=======================================================================
3424 bool RangeOfIds::IsSatisfy( long theId )
3429 if ( myType == SMDSAbs_Node )
3431 if ( myMesh->FindNode( theId ) == 0 )
3436 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
3437 if ( anElem == 0 || (myType != anElem->GetType() && myType != SMDSAbs_All ))
3441 if ( myIds.Contains( theId ) )
3444 for ( int i = 1, n = myMin.size(); i <= n; i++ )
3445 if ( theId >= myMin[i] && theId <= myMax[i] )
3453 Description : Base class for comparators
3455 Comparator::Comparator():
3459 Comparator::~Comparator()
3462 void Comparator::SetMesh( const SMDS_Mesh* theMesh )
3465 myFunctor->SetMesh( theMesh );
3468 void Comparator::SetMargin( double theValue )
3470 myMargin = theValue;
3473 void Comparator::SetNumFunctor( NumericalFunctorPtr theFunct )
3475 myFunctor = theFunct;
3478 SMDSAbs_ElementType Comparator::GetType() const
3480 return myFunctor ? myFunctor->GetType() : SMDSAbs_All;
3483 double Comparator::GetMargin()
3491 Description : Comparator "<"
3493 bool LessThan::IsSatisfy( long theId )
3495 return myFunctor && myFunctor->GetValue( theId ) < myMargin;
3501 Description : Comparator ">"
3503 bool MoreThan::IsSatisfy( long theId )
3505 return myFunctor && myFunctor->GetValue( theId ) > myMargin;
3511 Description : Comparator "="
3514 myToler(Precision::Confusion())
3517 bool EqualTo::IsSatisfy( long theId )
3519 return myFunctor && fabs( myFunctor->GetValue( theId ) - myMargin ) < myToler;
3522 void EqualTo::SetTolerance( double theToler )
3527 double EqualTo::GetTolerance()
3534 Description : Logical NOT predicate
3536 LogicalNOT::LogicalNOT()
3539 LogicalNOT::~LogicalNOT()
3542 bool LogicalNOT::IsSatisfy( long theId )
3544 return myPredicate && !myPredicate->IsSatisfy( theId );
3547 void LogicalNOT::SetMesh( const SMDS_Mesh* theMesh )
3550 myPredicate->SetMesh( theMesh );
3553 void LogicalNOT::SetPredicate( PredicatePtr thePred )
3555 myPredicate = thePred;
3558 SMDSAbs_ElementType LogicalNOT::GetType() const
3560 return myPredicate ? myPredicate->GetType() : SMDSAbs_All;
3565 Class : LogicalBinary
3566 Description : Base class for binary logical predicate
3568 LogicalBinary::LogicalBinary()
3571 LogicalBinary::~LogicalBinary()
3574 void LogicalBinary::SetMesh( const SMDS_Mesh* theMesh )
3577 myPredicate1->SetMesh( theMesh );
3580 myPredicate2->SetMesh( theMesh );
3583 void LogicalBinary::SetPredicate1( PredicatePtr thePredicate )
3585 myPredicate1 = thePredicate;
3588 void LogicalBinary::SetPredicate2( PredicatePtr thePredicate )
3590 myPredicate2 = thePredicate;
3593 SMDSAbs_ElementType LogicalBinary::GetType() const
3595 if ( !myPredicate1 || !myPredicate2 )
3598 SMDSAbs_ElementType aType1 = myPredicate1->GetType();
3599 SMDSAbs_ElementType aType2 = myPredicate2->GetType();
3601 return aType1 == aType2 ? aType1 : SMDSAbs_All;
3607 Description : Logical AND
3609 bool LogicalAND::IsSatisfy( long theId )
3614 myPredicate1->IsSatisfy( theId ) &&
3615 myPredicate2->IsSatisfy( theId );
3621 Description : Logical OR
3623 bool LogicalOR::IsSatisfy( long theId )
3628 (myPredicate1->IsSatisfy( theId ) ||
3629 myPredicate2->IsSatisfy( theId ));
3638 // #include <tbb/parallel_for.h>
3639 // #include <tbb/enumerable_thread_specific.h>
3641 // namespace Parallel
3643 // typedef tbb::enumerable_thread_specific< TIdSequence > TIdSeq;
3647 // const SMDS_Mesh* myMesh;
3648 // PredicatePtr myPredicate;
3649 // TIdSeq & myOKIds;
3650 // Predicate( const SMDS_Mesh* m, PredicatePtr p, TIdSeq & ids ):
3651 // myMesh(m), myPredicate(p->Duplicate()), myOKIds(ids) {}
3652 // void operator() ( const tbb::blocked_range<size_t>& r ) const
3654 // for ( size_t i = r.begin(); i != r.end(); ++i )
3655 // if ( myPredicate->IsSatisfy( i ))
3656 // myOKIds.local().push_back();
3668 void Filter::SetPredicate( PredicatePtr thePredicate )
3670 myPredicate = thePredicate;
3673 void Filter::GetElementsId( const SMDS_Mesh* theMesh,
3674 PredicatePtr thePredicate,
3675 TIdSequence& theSequence,
3676 SMDS_ElemIteratorPtr theElements )
3678 theSequence.clear();
3680 if ( !theMesh || !thePredicate )
3683 thePredicate->SetMesh( theMesh );
3686 theElements = theMesh->elementsIterator( thePredicate->GetType() );
3688 if ( theElements ) {
3689 while ( theElements->more() ) {
3690 const SMDS_MeshElement* anElem = theElements->next();
3691 if ( thePredicate->GetType() == SMDSAbs_All ||
3692 thePredicate->GetType() == anElem->GetType() )
3694 long anId = anElem->GetID();
3695 if ( thePredicate->IsSatisfy( anId ) )
3696 theSequence.push_back( anId );
3702 void Filter::GetElementsId( const SMDS_Mesh* theMesh,
3703 Filter::TIdSequence& theSequence,
3704 SMDS_ElemIteratorPtr theElements )
3706 GetElementsId(theMesh,myPredicate,theSequence,theElements);
3713 typedef std::set<SMDS_MeshFace*> TMapOfFacePtr;
3719 ManifoldPart::Link::Link( SMDS_MeshNode* theNode1,
3720 SMDS_MeshNode* theNode2 )
3726 ManifoldPart::Link::~Link()
3732 bool ManifoldPart::Link::IsEqual( const ManifoldPart::Link& theLink ) const
3734 if ( myNode1 == theLink.myNode1 &&
3735 myNode2 == theLink.myNode2 )
3737 else if ( myNode1 == theLink.myNode2 &&
3738 myNode2 == theLink.myNode1 )
3744 bool ManifoldPart::Link::operator<( const ManifoldPart::Link& x ) const
3746 if(myNode1 < x.myNode1) return true;
3747 if(myNode1 == x.myNode1)
3748 if(myNode2 < x.myNode2) return true;
3752 bool ManifoldPart::IsEqual( const ManifoldPart::Link& theLink1,
3753 const ManifoldPart::Link& theLink2 )
3755 return theLink1.IsEqual( theLink2 );
3758 ManifoldPart::ManifoldPart()
3761 myAngToler = Precision::Angular();
3762 myIsOnlyManifold = true;
3765 ManifoldPart::~ManifoldPart()
3770 void ManifoldPart::SetMesh( const SMDS_Mesh* theMesh )
3776 SMDSAbs_ElementType ManifoldPart::GetType() const
3777 { return SMDSAbs_Face; }
3779 bool ManifoldPart::IsSatisfy( long theElementId )
3781 return myMapIds.Contains( theElementId );
3784 void ManifoldPart::SetAngleTolerance( const double theAngToler )
3785 { myAngToler = theAngToler; }
3787 double ManifoldPart::GetAngleTolerance() const
3788 { return myAngToler; }
3790 void ManifoldPart::SetIsOnlyManifold( const bool theIsOnly )
3791 { myIsOnlyManifold = theIsOnly; }
3793 void ManifoldPart::SetStartElem( const long theStartId )
3794 { myStartElemId = theStartId; }
3796 bool ManifoldPart::process()
3799 myMapBadGeomIds.Clear();
3801 myAllFacePtr.clear();
3802 myAllFacePtrIntDMap.clear();
3806 // collect all faces into own map
3807 SMDS_FaceIteratorPtr anFaceItr = myMesh->facesIterator();
3808 for (; anFaceItr->more(); )
3810 SMDS_MeshFace* aFacePtr = (SMDS_MeshFace*)anFaceItr->next();
3811 myAllFacePtr.push_back( aFacePtr );
3812 myAllFacePtrIntDMap[aFacePtr] = myAllFacePtr.size()-1;
3815 SMDS_MeshFace* aStartFace = (SMDS_MeshFace*)myMesh->FindElement( myStartElemId );
3819 // the map of non manifold links and bad geometry
3820 TMapOfLink aMapOfNonManifold;
3821 TIDsMap aMapOfTreated;
3823 // begin cycle on faces from start index and run on vector till the end
3824 // and from begin to start index to cover whole vector
3825 const int aStartIndx = myAllFacePtrIntDMap[aStartFace];
3826 bool isStartTreat = false;
3827 for ( int fi = aStartIndx; !isStartTreat || fi != aStartIndx ; fi++ )
3829 if ( fi == aStartIndx )
3830 isStartTreat = true;
3831 // as result next time when fi will be equal to aStartIndx
3833 SMDS_MeshFace* aFacePtr = myAllFacePtr[ fi ];
3834 if ( aMapOfTreated.Contains( aFacePtr->GetID()) )
3837 aMapOfTreated.Add( aFacePtr->GetID() );
3839 if ( !findConnected( myAllFacePtrIntDMap, aFacePtr,
3840 aMapOfNonManifold, aResFaces ) )
3842 TIDsMap::Iterator anItr( aResFaces );
3843 for ( ; anItr.More(); anItr.Next() )
3845 smIdType aFaceId = anItr.Key();
3846 aMapOfTreated.Add( aFaceId );
3847 myMapIds.Add( aFaceId );
3850 if ( fi == int( myAllFacePtr.size() - 1 ))
3852 } // end run on vector of faces
3853 return !myMapIds.IsEmpty();
3856 static void getLinks( const SMDS_MeshFace* theFace,
3857 ManifoldPart::TVectorOfLink& theLinks )
3859 int aNbNode = theFace->NbNodes();
3860 SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
3862 SMDS_MeshNode* aNode = 0;
3863 for ( ; aNodeItr->more() && i <= aNbNode; )
3866 SMDS_MeshNode* aN1 = (SMDS_MeshNode*)aNodeItr->next();
3870 SMDS_MeshNode* aN2 = ( i >= aNbNode ) ? aNode : (SMDS_MeshNode*)aNodeItr->next();
3872 ManifoldPart::Link aLink( aN1, aN2 );
3873 theLinks.push_back( aLink );
3877 bool ManifoldPart::findConnected
3878 ( const ManifoldPart::TDataMapFacePtrInt& theAllFacePtrInt,
3879 SMDS_MeshFace* theStartFace,
3880 ManifoldPart::TMapOfLink& theNonManifold,
3881 TIDsMap& theResFaces )
3883 theResFaces.Clear();
3884 if ( !theAllFacePtrInt.size() )
3887 if ( getNormale( theStartFace ).SquareModulus() <= gp::Resolution() )
3889 myMapBadGeomIds.Add( theStartFace->GetID() );
3893 ManifoldPart::TMapOfLink aMapOfBoundary, aMapToSkip;
3894 ManifoldPart::TVectorOfLink aSeqOfBoundary;
3895 theResFaces.Add( theStartFace->GetID() );
3896 ManifoldPart::TDataMapOfLinkFacePtr aDMapLinkFace;
3898 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
3899 aDMapLinkFace, theNonManifold, theStartFace );
3901 bool isDone = false;
3902 while ( !isDone && aMapOfBoundary.size() != 0 )
3904 bool isToReset = false;
3905 ManifoldPart::TVectorOfLink::iterator pLink = aSeqOfBoundary.begin();
3906 for ( ; !isToReset && pLink != aSeqOfBoundary.end(); ++pLink )
3908 ManifoldPart::Link aLink = *pLink;
3909 if ( aMapToSkip.find( aLink ) != aMapToSkip.end() )
3911 // each link could be treated only once
3912 aMapToSkip.insert( aLink );
3914 ManifoldPart::TVectorOfFacePtr aFaces;
3916 if ( myIsOnlyManifold &&
3917 (theNonManifold.find( aLink ) != theNonManifold.end()) )
3921 getFacesByLink( aLink, aFaces );
3922 // filter the element to keep only indicated elements
3923 ManifoldPart::TVectorOfFacePtr aFiltered;
3924 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
3925 for ( ; pFace != aFaces.end(); ++pFace )
3927 SMDS_MeshFace* aFace = *pFace;
3928 if ( myAllFacePtrIntDMap.find( aFace ) != myAllFacePtrIntDMap.end() )
3929 aFiltered.push_back( aFace );
3932 if ( aFaces.size() < 2 ) // no neihgbour faces
3934 else if ( myIsOnlyManifold && aFaces.size() > 2 ) // non manifold case
3936 theNonManifold.insert( aLink );
3941 // compare normal with normals of neighbor element
3942 SMDS_MeshFace* aPrevFace = aDMapLinkFace[ aLink ];
3943 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
3944 for ( ; pFace != aFaces.end(); ++pFace )
3946 SMDS_MeshFace* aNextFace = *pFace;
3947 if ( aPrevFace == aNextFace )
3949 smIdType anNextFaceID = aNextFace->GetID();
3950 if ( myIsOnlyManifold && theResFaces.Contains( anNextFaceID ) )
3951 // should not be with non manifold restriction. probably bad topology
3953 // check if face was treated and skipped
3954 if ( myMapBadGeomIds.Contains( anNextFaceID ) ||
3955 !isInPlane( aPrevFace, aNextFace ) )
3957 // add new element to connected and extend the boundaries.
3958 theResFaces.Add( anNextFaceID );
3959 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
3960 aDMapLinkFace, theNonManifold, aNextFace );
3964 isDone = !isToReset;
3967 return !theResFaces.IsEmpty();
3970 bool ManifoldPart::isInPlane( const SMDS_MeshFace* theFace1,
3971 const SMDS_MeshFace* theFace2 )
3973 gp_Dir aNorm1 = gp_Dir( getNormale( theFace1 ) );
3974 gp_XYZ aNorm2XYZ = getNormale( theFace2 );
3975 if ( aNorm2XYZ.SquareModulus() <= gp::Resolution() )
3977 myMapBadGeomIds.Add( theFace2->GetID() );
3980 if ( aNorm1.IsParallel( gp_Dir( aNorm2XYZ ), myAngToler ) )
3986 void ManifoldPart::expandBoundary
3987 ( ManifoldPart::TMapOfLink& theMapOfBoundary,
3988 ManifoldPart::TVectorOfLink& theSeqOfBoundary,
3989 ManifoldPart::TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
3990 ManifoldPart::TMapOfLink& theNonManifold,
3991 SMDS_MeshFace* theNextFace ) const
3993 ManifoldPart::TVectorOfLink aLinks;
3994 getLinks( theNextFace, aLinks );
3995 int aNbLink = (int)aLinks.size();
3996 for ( int i = 0; i < aNbLink; i++ )
3998 ManifoldPart::Link aLink = aLinks[ i ];
3999 if ( myIsOnlyManifold && (theNonManifold.find( aLink ) != theNonManifold.end()) )
4001 if ( theMapOfBoundary.find( aLink ) != theMapOfBoundary.end() )
4003 if ( myIsOnlyManifold )
4005 // remove from boundary
4006 theMapOfBoundary.erase( aLink );
4007 ManifoldPart::TVectorOfLink::iterator pLink = theSeqOfBoundary.begin();
4008 for ( ; pLink != theSeqOfBoundary.end(); ++pLink )
4010 ManifoldPart::Link aBoundLink = *pLink;
4011 if ( aBoundLink.IsEqual( aLink ) )
4013 theSeqOfBoundary.erase( pLink );
4021 theMapOfBoundary.insert( aLink );
4022 theSeqOfBoundary.push_back( aLink );
4023 theDMapLinkFacePtr[ aLink ] = theNextFace;
4028 void ManifoldPart::getFacesByLink( const ManifoldPart::Link& theLink,
4029 ManifoldPart::TVectorOfFacePtr& theFaces ) const
4032 // take all faces that shared first node
4033 SMDS_ElemIteratorPtr anItr = theLink.myNode1->GetInverseElementIterator( SMDSAbs_Face );
4034 SMDS_StdIterator< const SMDS_MeshElement*, SMDS_ElemIteratorPtr > faces( anItr ), facesEnd;
4035 std::set<const SMDS_MeshElement *> aSetOfFaces( faces, facesEnd );
4037 // take all faces that shared second node
4038 anItr = theLink.myNode2->GetInverseElementIterator( SMDSAbs_Face );
4039 // find the common part of two sets
4040 for ( ; anItr->more(); )
4042 const SMDS_MeshElement* aFace = anItr->next();
4043 if ( aSetOfFaces.count( aFace ))
4044 theFaces.push_back( (SMDS_MeshFace*) aFace );
4049 Class : BelongToMeshGroup
4050 Description : Verify whether a mesh element is included into a mesh group
4052 BelongToMeshGroup::BelongToMeshGroup(): myGroup( 0 )
4056 void BelongToMeshGroup::SetGroup( SMESHDS_GroupBase* g )
4061 void BelongToMeshGroup::SetStoreName( const std::string& sn )
4066 void BelongToMeshGroup::SetMesh( const SMDS_Mesh* theMesh )
4068 if ( myGroup && myGroup->GetMesh() != theMesh )
4072 if ( !myGroup && !myStoreName.empty() )
4074 if ( const SMESHDS_Mesh* aMesh = dynamic_cast<const SMESHDS_Mesh*>(theMesh))
4076 const std::set<SMESHDS_GroupBase*>& grps = aMesh->GetGroups();
4077 std::set<SMESHDS_GroupBase*>::const_iterator g = grps.begin();
4078 for ( ; g != grps.end() && !myGroup; ++g )
4079 if ( *g && myStoreName == (*g)->GetStoreName() )
4085 myGroup->IsEmpty(); // make GroupOnFilter update its predicate
4089 bool BelongToMeshGroup::IsSatisfy( long theElementId )
4091 return myGroup ? myGroup->Contains( theElementId ) : false;
4094 SMDSAbs_ElementType BelongToMeshGroup::GetType() const
4096 return myGroup ? myGroup->GetType() : SMDSAbs_All;
4099 //================================================================================
4100 // ElementsOnSurface
4101 //================================================================================
4103 ElementsOnSurface::ElementsOnSurface()
4106 myType = SMDSAbs_All;
4108 myToler = Precision::Confusion();
4109 myUseBoundaries = false;
4112 ElementsOnSurface::~ElementsOnSurface()
4116 void ElementsOnSurface::SetMesh( const SMDS_Mesh* theMesh )
4118 myMeshModifTracer.SetMesh( theMesh );
4119 if ( myMeshModifTracer.IsMeshModified())
4123 bool ElementsOnSurface::IsSatisfy( long theElementId )
4125 return myIds.Contains( theElementId );
4128 SMDSAbs_ElementType ElementsOnSurface::GetType() const
4131 void ElementsOnSurface::SetTolerance( const double theToler )
4133 if ( myToler != theToler )
4140 double ElementsOnSurface::GetTolerance() const
4143 void ElementsOnSurface::SetUseBoundaries( bool theUse )
4145 if ( myUseBoundaries != theUse ) {
4146 myUseBoundaries = theUse;
4147 SetSurface( mySurf, myType );
4151 void ElementsOnSurface::SetSurface( const TopoDS_Shape& theShape,
4152 const SMDSAbs_ElementType theType )
4157 if ( theShape.IsNull() || theShape.ShapeType() != TopAbs_FACE )
4159 mySurf = TopoDS::Face( theShape );
4160 BRepAdaptor_Surface SA( mySurf, myUseBoundaries );
4162 u1 = SA.FirstUParameter(),
4163 u2 = SA.LastUParameter(),
4164 v1 = SA.FirstVParameter(),
4165 v2 = SA.LastVParameter();
4166 Handle(Geom_Surface) surf = BRep_Tool::Surface( mySurf );
4167 myProjector.Init( surf, u1,u2, v1,v2 );
4171 void ElementsOnSurface::process()
4174 if ( mySurf.IsNull() )
4177 if ( !myMeshModifTracer.GetMesh() )
4180 int nbElems = FromIdType<int>( myMeshModifTracer.GetMesh()->GetMeshInfo().NbElements( myType ));
4182 myIds.ReSize( nbElems );
4184 SMDS_ElemIteratorPtr anIter = myMeshModifTracer.GetMesh()->elementsIterator( myType );
4185 for(; anIter->more(); )
4186 process( anIter->next() );
4189 void ElementsOnSurface::process( const SMDS_MeshElement* theElemPtr )
4191 SMDS_ElemIteratorPtr aNodeItr = theElemPtr->nodesIterator();
4192 bool isSatisfy = true;
4193 for ( ; aNodeItr->more(); )
4195 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
4196 if ( !isOnSurface( aNode ) )
4203 myIds.Add( theElemPtr->GetID() );
4206 bool ElementsOnSurface::isOnSurface( const SMDS_MeshNode* theNode )
4208 if ( mySurf.IsNull() )
4211 gp_Pnt aPnt( theNode->X(), theNode->Y(), theNode->Z() );
4212 // double aToler2 = myToler * myToler;
4213 // if ( mySurf->IsKind(STANDARD_TYPE(Geom_Plane)))
4215 // gp_Pln aPln = Handle(Geom_Plane)::DownCast(mySurf)->Pln();
4216 // if ( aPln.SquareDistance( aPnt ) > aToler2 )
4219 // else if ( mySurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)))
4221 // gp_Cylinder aCyl = Handle(Geom_CylindricalSurface)::DownCast(mySurf)->Cylinder();
4222 // double aRad = aCyl.Radius();
4223 // gp_Ax3 anAxis = aCyl.Position();
4224 // gp_XYZ aLoc = aCyl.Location().XYZ();
4225 // double aXDist = anAxis.XDirection().XYZ() * ( aPnt.XYZ() - aLoc );
4226 // double aYDist = anAxis.YDirection().XYZ() * ( aPnt.XYZ() - aLoc );
4227 // if ( fabs(aXDist*aXDist + aYDist*aYDist - aRad*aRad) > aToler2 )
4232 myProjector.Perform( aPnt );
4233 bool isOn = ( myProjector.IsDone() && myProjector.LowerDistance() <= myToler );
4239 //================================================================================
4241 //================================================================================
4244 const int theIsCheckedFlag = 0x0000100;
4247 struct ElementsOnShape::Classifier
4249 Classifier() { mySolidClfr = 0; myFlags = 0; }
4251 void Init(const TopoDS_Shape& s, double tol, const Bnd_B3d* box = 0 );
4252 bool IsOut(const gp_Pnt& p) { return SetChecked( true ), (this->*myIsOutFun)( p ); }
4253 TopAbs_ShapeEnum ShapeType() const { return myShape.ShapeType(); }
4254 const TopoDS_Shape& Shape() const { return myShape; }
4255 const Bnd_B3d* GetBndBox() const { return & myBox; }
4256 double Tolerance() const { return myTol; }
4257 bool IsChecked() { return myFlags & theIsCheckedFlag; }
4258 bool IsSetFlag( int flag ) const { return myFlags & flag; }
4259 void SetChecked( bool is ) { is ? SetFlag( theIsCheckedFlag ) : UnsetFlag( theIsCheckedFlag ); }
4260 void SetFlag ( int flag ) { myFlags |= flag; }
4261 void UnsetFlag( int flag ) { myFlags &= ~flag; }
4264 bool isOutOfSolid (const gp_Pnt& p);
4265 bool isOutOfBox (const gp_Pnt& p);
4266 bool isOutOfFace (const gp_Pnt& p);
4267 bool isOutOfEdge (const gp_Pnt& p);
4268 bool isOutOfVertex(const gp_Pnt& p);
4269 bool isOutOfNone (const gp_Pnt& /*p*/) { return true; }
4270 bool isBox (const TopoDS_Shape& s);
4272 TopoDS_Shape prepareSolid( const TopoDS_Shape& theSolid );
4274 bool (Classifier::* myIsOutFun)(const gp_Pnt& p);
4275 BRepClass3d_SolidClassifier* mySolidClfr; // ptr because of a run-time forbidden copy-constructor
4277 GeomAPI_ProjectPointOnSurf myProjFace;
4278 GeomAPI_ProjectPointOnCurve myProjEdge;
4280 TopoDS_Shape myShape;
4285 struct ElementsOnShape::OctreeClassifier : public SMESH_Octree
4287 OctreeClassifier( const std::vector< ElementsOnShape::Classifier* >& classifiers );
4288 OctreeClassifier( const OctreeClassifier* otherTree,
4289 const std::vector< ElementsOnShape::Classifier >& clsOther,
4290 std::vector< ElementsOnShape::Classifier >& cls );
4291 void GetClassifiersAtPoint( const gp_XYZ& p,
4292 std::vector< ElementsOnShape::Classifier* >& classifiers );
4296 OctreeClassifier() {}
4297 SMESH_Octree* newChild() const { return new OctreeClassifier; }
4298 void buildChildrenData();
4299 Bnd_B3d* buildRootBox();
4301 std::vector< ElementsOnShape::Classifier* > myClassifiers;
4305 ElementsOnShape::ElementsOnShape():
4307 myType(SMDSAbs_All),
4308 myToler(Precision::Confusion()),
4309 myAllNodesFlag(false)
4313 ElementsOnShape::~ElementsOnShape()
4318 Predicate* ElementsOnShape::clone() const
4320 size_t size = sizeof( *this );
4322 size += myOctree->GetSize();
4323 if ( !myClassifiers.empty() )
4324 size += sizeof( myClassifiers[0] ) * myClassifiers.size();
4325 if ( !myWorkClassifiers.empty() )
4326 size += sizeof( myWorkClassifiers[0] ) * myWorkClassifiers.size();
4327 if ( size > 1e+9 ) // 1G
4330 std::cout << "Avoid ElementsOnShape::clone(), too large: " << size << " bytes " << std::endl;
4335 ElementsOnShape* cln = new ElementsOnShape();
4336 cln->SetAllNodes ( myAllNodesFlag );
4337 cln->SetTolerance( myToler );
4338 cln->SetMesh ( myMeshModifTracer.GetMesh() );
4339 cln->myShape = myShape; // avoid creation of myClassifiers
4340 cln->SetShape ( myShape, myType );
4341 cln->myClassifiers.resize( myClassifiers.size() );
4342 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4343 cln->myClassifiers[ i ].Init( BRepBuilderAPI_Copy( myClassifiers[ i ].Shape()),
4344 myToler, myClassifiers[ i ].GetBndBox() );
4345 if ( myOctree ) // copy myOctree
4347 cln->myOctree = new OctreeClassifier( myOctree, myClassifiers, cln->myClassifiers );
4352 SMDSAbs_ElementType ElementsOnShape::GetType() const
4357 void ElementsOnShape::SetTolerance (const double theToler)
4359 if (myToler != theToler) {
4361 SetShape(myShape, myType);
4365 double ElementsOnShape::GetTolerance() const
4370 void ElementsOnShape::SetAllNodes (bool theAllNodes)
4372 myAllNodesFlag = theAllNodes;
4375 void ElementsOnShape::SetMesh (const SMDS_Mesh* theMesh)
4377 myMeshModifTracer.SetMesh( theMesh );
4378 if ( myMeshModifTracer.IsMeshModified())
4380 size_t nbNodes = theMesh ? theMesh->NbNodes() : 0;
4381 if ( myNodeIsChecked.size() == nbNodes )
4383 std::fill( myNodeIsChecked.begin(), myNodeIsChecked.end(), false );
4387 SMESHUtils::FreeVector( myNodeIsChecked );
4388 SMESHUtils::FreeVector( myNodeIsOut );
4389 myNodeIsChecked.resize( nbNodes, false );
4390 myNodeIsOut.resize( nbNodes );
4395 bool ElementsOnShape::getNodeIsOut( const SMDS_MeshNode* n, bool& isOut )
4397 if ( n->GetID() >= (int) myNodeIsChecked.size() ||
4398 !myNodeIsChecked[ n->GetID() ])
4401 isOut = myNodeIsOut[ n->GetID() ];
4405 void ElementsOnShape::setNodeIsOut( const SMDS_MeshNode* n, bool isOut )
4407 if ( n->GetID() < (int) myNodeIsChecked.size() )
4409 myNodeIsChecked[ n->GetID() ] = true;
4410 myNodeIsOut [ n->GetID() ] = isOut;
4414 void ElementsOnShape::SetShape (const TopoDS_Shape& theShape,
4415 const SMDSAbs_ElementType theType)
4417 bool shapeChanges = ( myShape != theShape );
4420 if ( myShape.IsNull() ) return;
4424 // find most complex shapes
4425 TopTools_IndexedMapOfShape shapesMap;
4426 TopAbs_ShapeEnum shapeTypes[4] = { TopAbs_SOLID, TopAbs_FACE, TopAbs_EDGE, TopAbs_VERTEX };
4427 TopExp_Explorer sub;
4428 for ( int i = 0; i < 4; ++i )
4430 if ( shapesMap.IsEmpty() )
4431 for ( sub.Init( myShape, shapeTypes[i] ); sub.More(); sub.Next() )
4432 shapesMap.Add( sub.Current() );
4434 for ( sub.Init( myShape, shapeTypes[i], shapeTypes[i-1] ); sub.More(); sub.Next() )
4435 shapesMap.Add( sub.Current() );
4439 myClassifiers.resize( shapesMap.Extent() );
4440 for ( int i = 0; i < shapesMap.Extent(); ++i )
4441 myClassifiers[ i ].Init( shapesMap( i+1 ), myToler );
4444 if ( theType == SMDSAbs_Node )
4446 SMESHUtils::FreeVector( myNodeIsChecked );
4447 SMESHUtils::FreeVector( myNodeIsOut );
4451 std::fill( myNodeIsChecked.begin(), myNodeIsChecked.end(), false );
4455 void ElementsOnShape::clearClassifiers()
4457 // for ( size_t i = 0; i < myClassifiers.size(); ++i )
4458 // delete myClassifiers[ i ];
4459 myClassifiers.clear();
4465 bool ElementsOnShape::IsSatisfy( long elemId )
4467 if ( myClassifiers.empty() )
4470 const SMDS_Mesh* mesh = myMeshModifTracer.GetMesh();
4471 if ( myType == SMDSAbs_Node )
4472 return IsSatisfy( mesh->FindNode( elemId ));
4473 return IsSatisfy( mesh->FindElement( elemId ));
4476 bool ElementsOnShape::IsSatisfy (const SMDS_MeshElement* elem)
4481 bool isSatisfy = myAllNodesFlag, isNodeOut;
4483 gp_XYZ centerXYZ (0, 0, 0);
4485 if ( !myOctree && myClassifiers.size() > 5 )
4487 myWorkClassifiers.resize( myClassifiers.size() );
4488 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4489 myWorkClassifiers[ i ] = & myClassifiers[ i ];
4490 myOctree = new OctreeClassifier( myWorkClassifiers );
4492 SMESHUtils::FreeVector( myWorkClassifiers );
4495 for ( int i = 0, nb = elem->NbNodes(); i < nb && (isSatisfy == myAllNodesFlag); ++i )
4497 SMESH_TNodeXYZ aPnt( elem->GetNode( i ));
4501 if ( !getNodeIsOut( aPnt._node, isNodeOut ))
4505 myWorkClassifiers.clear();
4506 myOctree->GetClassifiersAtPoint( aPnt, myWorkClassifiers );
4508 for ( size_t i = 0; i < myWorkClassifiers.size(); ++i )
4509 myWorkClassifiers[i]->SetChecked( false );
4511 for ( size_t i = 0; i < myWorkClassifiers.size() && isNodeOut; ++i )
4512 if ( !myWorkClassifiers[i]->IsChecked() )
4513 isNodeOut = myWorkClassifiers[i]->IsOut( aPnt );
4517 for ( size_t i = 0; i < myClassifiers.size() && isNodeOut; ++i )
4518 isNodeOut = myClassifiers[i].IsOut( aPnt );
4520 setNodeIsOut( aPnt._node, isNodeOut );
4522 isSatisfy = !isNodeOut;
4525 // Check the center point for volumes MantisBug 0020168
4528 myClassifiers[0].ShapeType() == TopAbs_SOLID )
4530 centerXYZ /= elem->NbNodes();
4534 myWorkClassifiers.clear();
4535 myOctree->GetClassifiersAtPoint( centerXYZ, myWorkClassifiers );
4536 for ( size_t i = 0; i < myWorkClassifiers.size() && !isSatisfy; ++i )
4537 isSatisfy = ! myWorkClassifiers[i]->IsOut( centerXYZ );
4541 for ( size_t i = 0; i < myClassifiers.size() && !isSatisfy; ++i )
4542 isSatisfy = ! myClassifiers[i].IsOut( centerXYZ );
4549 //================================================================================
4551 * \brief Check and optionally return a satisfying shape
4553 //================================================================================
4555 bool ElementsOnShape::IsSatisfy (const SMDS_MeshNode* node,
4556 TopoDS_Shape* okShape)
4561 if ( !myOctree && myClassifiers.size() > 5 )
4563 myWorkClassifiers.resize( myClassifiers.size() );
4564 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4565 myWorkClassifiers[ i ] = & myClassifiers[ i ];
4566 myOctree = new OctreeClassifier( myWorkClassifiers );
4569 bool isNodeOut = true;
4571 if ( okShape || !getNodeIsOut( node, isNodeOut ))
4573 SMESH_NodeXYZ aPnt = node;
4576 myWorkClassifiers.clear();
4577 myOctree->GetClassifiersAtPoint( aPnt, myWorkClassifiers );
4579 for ( size_t i = 0; i < myWorkClassifiers.size(); ++i )
4580 myWorkClassifiers[i]->SetChecked( false );
4582 for ( size_t i = 0; i < myWorkClassifiers.size(); ++i )
4583 if ( !myWorkClassifiers[i]->IsChecked() &&
4584 !myWorkClassifiers[i]->IsOut( aPnt ))
4588 *okShape = myWorkClassifiers[i]->Shape();
4594 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4595 if ( !myClassifiers[i].IsOut( aPnt ))
4599 *okShape = myClassifiers[i].Shape();
4603 setNodeIsOut( node, isNodeOut );
4609 void ElementsOnShape::Classifier::Init( const TopoDS_Shape& theShape,
4611 const Bnd_B3d* theBox )
4617 bool isShapeBox = false;
4618 switch ( myShape.ShapeType() )
4622 if (( isShapeBox = isBox( theShape )))
4624 myIsOutFun = & ElementsOnShape::Classifier::isOutOfBox;
4628 mySolidClfr = new BRepClass3d_SolidClassifier( prepareSolid( theShape ));
4629 myIsOutFun = & ElementsOnShape::Classifier::isOutOfSolid;
4635 Standard_Real u1,u2,v1,v2;
4636 Handle(Geom_Surface) surf = BRep_Tool::Surface( TopoDS::Face( theShape ));
4637 if ( surf.IsNull() )
4638 myIsOutFun = & ElementsOnShape::Classifier::isOutOfNone;
4641 surf->Bounds( u1,u2,v1,v2 );
4642 myProjFace.Init(surf, u1,u2, v1,v2, myTol );
4643 myIsOutFun = & ElementsOnShape::Classifier::isOutOfFace;
4649 Standard_Real u1, u2;
4650 Handle(Geom_Curve) curve = BRep_Tool::Curve( TopoDS::Edge( theShape ), u1, u2);
4651 if ( curve.IsNull() )
4652 myIsOutFun = & ElementsOnShape::Classifier::isOutOfNone;
4655 myProjEdge.Init(curve, u1, u2);
4656 myIsOutFun = & ElementsOnShape::Classifier::isOutOfEdge;
4662 myVertexXYZ = BRep_Tool::Pnt( TopoDS::Vertex( theShape ) );
4663 myIsOutFun = & ElementsOnShape::Classifier::isOutOfVertex;
4667 throw SALOME_Exception("Programmer error in usage of ElementsOnShape::Classifier");
4679 if ( myShape.ShapeType() == TopAbs_FACE )
4681 BRepAdaptor_Surface SA( TopoDS::Face( myShape ), /*useBoundaries=*/false );
4682 if ( SA.GetType() == GeomAbs_BSplineSurface )
4683 BRepBndLib::AddOptimal( myShape, box,
4684 /*useTriangulation=*/true, /*useShapeTolerance=*/true );
4687 BRepBndLib::Add( myShape, box );
4689 myBox.Add( box.CornerMin() );
4690 myBox.Add( box.CornerMax() );
4691 gp_XYZ halfSize = 0.5 * ( box.CornerMax().XYZ() - box.CornerMin().XYZ() );
4692 for ( int iDim = 1; iDim <= 3; ++iDim )
4694 double x = halfSize.Coord( iDim );
4695 halfSize.SetCoord( iDim, x + Max( myTol, 1e-2 * x ));
4697 myBox.SetHSize( halfSize );
4702 ElementsOnShape::Classifier::~Classifier()
4704 delete mySolidClfr; mySolidClfr = 0;
4707 TopoDS_Shape ElementsOnShape::Classifier::prepareSolid( const TopoDS_Shape& theSolid )
4709 // try to limit tolerance of theSolid down to myTol (issue #19026)
4711 // check if tolerance of theSolid is more than myTol
4712 bool tolIsOk = true; // max tolerance is at VERTEXes
4713 for ( TopExp_Explorer exp( theSolid, TopAbs_VERTEX ); exp.More() && tolIsOk; exp.Next() )
4714 tolIsOk = ( myTol >= BRep_Tool::Tolerance( TopoDS::Vertex( exp.Current() )));
4718 // make a copy to prevent the original shape from changes
4719 TopoDS_Shape resultShape = BRepBuilderAPI_Copy( theSolid );
4721 if ( !GEOMUtils::FixShapeTolerance( resultShape, TopAbs_SHAPE, myTol ))
4726 bool ElementsOnShape::Classifier::isOutOfSolid( const gp_Pnt& p )
4728 if ( isOutOfBox( p )) return true;
4729 mySolidClfr->Perform( p, myTol );
4730 return ( mySolidClfr->State() != TopAbs_IN && mySolidClfr->State() != TopAbs_ON );
4733 bool ElementsOnShape::Classifier::isOutOfBox( const gp_Pnt& p )
4735 return myBox.IsOut( p.XYZ() );
4738 bool ElementsOnShape::Classifier::isOutOfFace( const gp_Pnt& p )
4740 if ( isOutOfBox( p )) return true;
4741 myProjFace.Perform( p );
4742 if ( myProjFace.IsDone() && myProjFace.LowerDistance() <= myTol )
4744 // check relatively to the face
4746 myProjFace.LowerDistanceParameters(u, v);
4747 gp_Pnt2d aProjPnt (u, v);
4748 BRepClass_FaceClassifier aClsf ( TopoDS::Face( myShape ), aProjPnt, myTol );
4749 if ( aClsf.State() == TopAbs_IN || aClsf.State() == TopAbs_ON )
4755 bool ElementsOnShape::Classifier::isOutOfEdge( const gp_Pnt& p )
4757 if ( isOutOfBox( p )) return true;
4758 myProjEdge.Perform( p );
4759 return ! ( myProjEdge.NbPoints() > 0 && myProjEdge.LowerDistance() <= myTol );
4762 bool ElementsOnShape::Classifier::isOutOfVertex( const gp_Pnt& p )
4764 return ( myVertexXYZ.Distance( p ) > myTol );
4767 bool ElementsOnShape::Classifier::isBox(const TopoDS_Shape& theShape )
4769 TopTools_IndexedMapOfShape vMap;
4770 TopExp::MapShapes( theShape, TopAbs_VERTEX, vMap );
4771 if ( vMap.Extent() != 8 )
4775 for ( int i = 1; i <= 8; ++i )
4776 myBox.Add( BRep_Tool::Pnt( TopoDS::Vertex( vMap( i ))).XYZ() );
4778 gp_XYZ pMin = myBox.CornerMin(), pMax = myBox.CornerMax();
4779 for ( int i = 1; i <= 8; ++i )
4781 gp_Pnt p = BRep_Tool::Pnt( TopoDS::Vertex( vMap( i )));
4782 for ( int iC = 1; iC <= 3; ++ iC )
4784 double d1 = Abs( pMin.Coord( iC ) - p.Coord( iC ));
4785 double d2 = Abs( pMax.Coord( iC ) - p.Coord( iC ));
4786 if ( Min( d1, d2 ) > myTol )
4790 myBox.Enlarge( myTol );
4795 OctreeClassifier::OctreeClassifier( const std::vector< ElementsOnShape::Classifier* >& classifiers )
4796 :SMESH_Octree( new SMESH_TreeLimit )
4798 myClassifiers = classifiers;
4803 OctreeClassifier::OctreeClassifier( const OctreeClassifier* otherTree,
4804 const std::vector< ElementsOnShape::Classifier >& clsOther,
4805 std::vector< ElementsOnShape::Classifier >& cls )
4806 :SMESH_Octree( new SMESH_TreeLimit )
4808 myBox = new Bnd_B3d( *otherTree->getBox() );
4810 if (( myIsLeaf = otherTree->isLeaf() ))
4812 myClassifiers.resize( otherTree->myClassifiers.size() );
4813 for ( size_t i = 0; i < otherTree->myClassifiers.size(); ++i )
4815 int ind = otherTree->myClassifiers[i] - & clsOther[0];
4816 myClassifiers[ i ] = & cls[ ind ];
4819 else if ( otherTree->myChildren )
4821 myChildren = new SMESH_Tree< Bnd_B3d, 8 > * [ 8 ];
4822 for ( int i = 0; i < nbChildren(); i++ )
4824 new OctreeClassifier( static_cast<const OctreeClassifier*>( otherTree->myChildren[i]),
4829 void ElementsOnShape::
4830 OctreeClassifier::GetClassifiersAtPoint( const gp_XYZ& point,
4831 std::vector< ElementsOnShape::Classifier* >& result )
4833 if ( getBox()->IsOut( point ))
4838 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4839 if ( !myClassifiers[i]->GetBndBox()->IsOut( point ))
4840 result.push_back( myClassifiers[i] );
4844 for (int i = 0; i < nbChildren(); i++)
4845 ((OctreeClassifier*) myChildren[i])->GetClassifiersAtPoint( point, result );
4849 size_t ElementsOnShape::OctreeClassifier::GetSize()
4851 size_t res = sizeof( *this );
4852 if ( !myClassifiers.empty() )
4853 res += sizeof( myClassifiers[0] ) * myClassifiers.size();
4856 for (int i = 0; i < nbChildren(); i++)
4857 res += ((OctreeClassifier*) myChildren[i])->GetSize();
4862 void ElementsOnShape::OctreeClassifier::buildChildrenData()
4864 // distribute myClassifiers among myChildren
4866 const int childFlag[8] = { 0x0000001,
4874 int nbInChild[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
4876 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4878 for ( int j = 0; j < nbChildren(); j++ )
4880 if ( !myClassifiers[i]->GetBndBox()->IsOut( *myChildren[j]->getBox() ))
4882 myClassifiers[i]->SetFlag( childFlag[ j ]);
4888 for ( int j = 0; j < nbChildren(); j++ )
4890 OctreeClassifier* child = static_cast<OctreeClassifier*>( myChildren[ j ]);
4891 child->myClassifiers.resize( nbInChild[ j ]);
4892 for ( size_t i = 0; nbInChild[ j ] && i < myClassifiers.size(); ++i )
4894 if ( myClassifiers[ i ]->IsSetFlag( childFlag[ j ]))
4897 child->myClassifiers[ nbInChild[ j ]] = myClassifiers[ i ];
4898 myClassifiers[ i ]->UnsetFlag( childFlag[ j ]);
4902 SMESHUtils::FreeVector( myClassifiers );
4904 // define if a child isLeaf()
4905 for ( int i = 0; i < nbChildren(); i++ )
4907 OctreeClassifier* child = static_cast<OctreeClassifier*>( myChildren[ i ]);
4908 child->myIsLeaf = ( child->myClassifiers.size() <= 5 ||
4909 child->maxSize() < child->myClassifiers[0]->Tolerance() );
4913 Bnd_B3d* ElementsOnShape::OctreeClassifier::buildRootBox()
4915 Bnd_B3d* box = new Bnd_B3d;
4916 for ( size_t i = 0; i < myClassifiers.size(); ++i )
4917 box->Add( *myClassifiers[i]->GetBndBox() );
4922 Class : BelongToGeom
4923 Description : Predicate for verifying whether entity belongs to
4924 specified geometrical support
4927 BelongToGeom::BelongToGeom()
4929 myType(SMDSAbs_NbElementTypes),
4930 myIsSubshape(false),
4931 myTolerance(Precision::Confusion())
4934 Predicate* BelongToGeom::clone() const
4936 BelongToGeom* cln = 0;
4937 if ( myElementsOnShapePtr )
4938 if ( ElementsOnShape* eos = static_cast<ElementsOnShape*>( myElementsOnShapePtr->clone() ))
4940 cln = new BelongToGeom( *this );
4941 cln->myElementsOnShapePtr.reset( eos );
4946 void BelongToGeom::SetMesh( const SMDS_Mesh* theMesh )
4948 if ( myMeshDS != theMesh )
4950 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
4953 if ( myElementsOnShapePtr )
4954 myElementsOnShapePtr->SetMesh( myMeshDS );
4957 void BelongToGeom::SetGeom( const TopoDS_Shape& theShape )
4959 if ( myShape != theShape )
4966 static bool IsSubShape (const TopTools_IndexedMapOfShape& theMap,
4967 const TopoDS_Shape& theShape)
4969 if (theMap.Contains(theShape)) return true;
4971 if (theShape.ShapeType() == TopAbs_COMPOUND ||
4972 theShape.ShapeType() == TopAbs_COMPSOLID)
4974 TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
4975 for (; anIt.More(); anIt.Next())
4977 if (!IsSubShape(theMap, anIt.Value())) {
4987 void BelongToGeom::init()
4989 if ( !myMeshDS || myShape.IsNull() ) return;
4991 // is sub-shape of main shape?
4992 TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
4993 if (aMainShape.IsNull()) {
4994 myIsSubshape = false;
4997 TopTools_IndexedMapOfShape aMap;
4998 TopExp::MapShapes( aMainShape, aMap );
4999 myIsSubshape = IsSubShape( aMap, myShape );
5003 TopExp::MapShapes( myShape, aMap );
5004 mySubShapesIDs.Clear();
5005 for ( int i = 1; i <= aMap.Extent(); ++i )
5007 int subID = myMeshDS->ShapeToIndex( aMap( i ));
5009 mySubShapesIDs.Add( subID );
5014 //if (!myIsSubshape) // to be always ready to check an element not bound to geometry
5016 if ( !myElementsOnShapePtr )
5017 myElementsOnShapePtr.reset( new ElementsOnShape() );
5018 myElementsOnShapePtr->SetTolerance( myTolerance );
5019 myElementsOnShapePtr->SetAllNodes( true ); // "belong", while false means "lays on"
5020 myElementsOnShapePtr->SetMesh( myMeshDS );
5021 myElementsOnShapePtr->SetShape( myShape, myType );
5025 bool BelongToGeom::IsSatisfy (long theId)
5027 if (myMeshDS == 0 || myShape.IsNull())
5032 return myElementsOnShapePtr->IsSatisfy(theId);
5037 if (myType == SMDSAbs_Node)
5039 if ( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ))
5041 if ( aNode->getshapeId() < 1 )
5042 return myElementsOnShapePtr->IsSatisfy(theId);
5044 return mySubShapesIDs.Contains( aNode->getshapeId() );
5049 if ( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ))
5051 if ( myType == SMDSAbs_All || anElem->GetType() == myType )
5053 if ( anElem->getshapeId() < 1 )
5054 return myElementsOnShapePtr->IsSatisfy(theId);
5056 return mySubShapesIDs.Contains( anElem->getshapeId() );
5064 void BelongToGeom::SetType (SMDSAbs_ElementType theType)
5066 if ( myType != theType )
5073 SMDSAbs_ElementType BelongToGeom::GetType() const
5078 TopoDS_Shape BelongToGeom::GetShape()
5083 const SMESHDS_Mesh* BelongToGeom::GetMeshDS() const
5088 void BelongToGeom::SetTolerance (double theTolerance)
5090 myTolerance = theTolerance;
5094 double BelongToGeom::GetTolerance()
5101 Description : Predicate for verifying whether entiy lying or partially lying on
5102 specified geometrical support
5105 LyingOnGeom::LyingOnGeom()
5107 myType(SMDSAbs_NbElementTypes),
5108 myIsSubshape(false),
5109 myTolerance(Precision::Confusion())
5112 Predicate* LyingOnGeom::clone() const
5114 LyingOnGeom* cln = 0;
5115 if ( myElementsOnShapePtr )
5116 if ( ElementsOnShape* eos = static_cast<ElementsOnShape*>( myElementsOnShapePtr->clone() ))
5118 cln = new LyingOnGeom( *this );
5119 cln->myElementsOnShapePtr.reset( eos );
5124 void LyingOnGeom::SetMesh( const SMDS_Mesh* theMesh )
5126 if ( myMeshDS != theMesh )
5128 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
5131 if ( myElementsOnShapePtr )
5132 myElementsOnShapePtr->SetMesh( myMeshDS );
5135 void LyingOnGeom::SetGeom( const TopoDS_Shape& theShape )
5137 if ( myShape != theShape )
5144 void LyingOnGeom::init()
5146 if (!myMeshDS || myShape.IsNull()) return;
5148 // is sub-shape of main shape?
5149 TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
5150 if (aMainShape.IsNull()) {
5151 myIsSubshape = false;
5154 myIsSubshape = myMeshDS->IsGroupOfSubShapes( myShape );
5159 TopTools_IndexedMapOfShape shapes;
5160 TopExp::MapShapes( myShape, shapes );
5161 mySubShapesIDs.Clear();
5162 for ( int i = 1; i <= shapes.Extent(); ++i )
5164 int subID = myMeshDS->ShapeToIndex( shapes( i ));
5166 mySubShapesIDs.Add( subID );
5169 // else // to be always ready to check an element not bound to geometry
5171 if ( !myElementsOnShapePtr )
5172 myElementsOnShapePtr.reset( new ElementsOnShape() );
5173 myElementsOnShapePtr->SetTolerance( myTolerance );
5174 myElementsOnShapePtr->SetAllNodes( false ); // lays on, while true means "belong"
5175 myElementsOnShapePtr->SetMesh( myMeshDS );
5176 myElementsOnShapePtr->SetShape( myShape, myType );
5180 bool LyingOnGeom::IsSatisfy( long theId )
5182 if ( myMeshDS == 0 || myShape.IsNull() )
5187 return myElementsOnShapePtr->IsSatisfy(theId);
5192 const SMDS_MeshElement* elem =
5193 ( myType == SMDSAbs_Node ) ? myMeshDS->FindNode( theId ) : myMeshDS->FindElement( theId );
5195 if ( mySubShapesIDs.Contains( elem->getshapeId() ))
5198 if (( elem->GetType() != SMDSAbs_Node ) &&
5199 ( myType == SMDSAbs_All || elem->GetType() == myType ))
5201 SMDS_ElemIteratorPtr nodeItr = elem->nodesIterator();
5202 while ( nodeItr->more() )
5204 const SMDS_MeshElement* aNode = nodeItr->next();
5205 if ( mySubShapesIDs.Contains( aNode->getshapeId() ))
5213 void LyingOnGeom::SetType( SMDSAbs_ElementType theType )
5215 if ( myType != theType )
5222 SMDSAbs_ElementType LyingOnGeom::GetType() const
5227 TopoDS_Shape LyingOnGeom::GetShape()
5232 const SMESHDS_Mesh* LyingOnGeom::GetMeshDS() const
5237 void LyingOnGeom::SetTolerance (double theTolerance)
5239 myTolerance = theTolerance;
5243 double LyingOnGeom::GetTolerance()
5248 TSequenceOfXYZ::TSequenceOfXYZ(): myElem(0)
5251 TSequenceOfXYZ::TSequenceOfXYZ(size_type n) : myArray(n), myElem(0)
5254 TSequenceOfXYZ::TSequenceOfXYZ(size_type n, const gp_XYZ& t) : myArray(n,t), myElem(0)
5257 TSequenceOfXYZ::TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ) : myArray(theSequenceOfXYZ.myArray), myElem(theSequenceOfXYZ.myElem)
5260 template <class InputIterator>
5261 TSequenceOfXYZ::TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd): myArray(theBegin,theEnd), myElem(0)
5264 TSequenceOfXYZ::~TSequenceOfXYZ()
5267 TSequenceOfXYZ& TSequenceOfXYZ::operator=(const TSequenceOfXYZ& theSequenceOfXYZ)
5269 myArray = theSequenceOfXYZ.myArray;
5270 myElem = theSequenceOfXYZ.myElem;
5274 gp_XYZ& TSequenceOfXYZ::operator()(size_type n)
5276 return myArray[n-1];
5279 const gp_XYZ& TSequenceOfXYZ::operator()(size_type n) const
5281 return myArray[n-1];
5284 void TSequenceOfXYZ::clear()
5289 void TSequenceOfXYZ::reserve(size_type n)
5294 void TSequenceOfXYZ::push_back(const gp_XYZ& v)
5296 myArray.push_back(v);
5299 TSequenceOfXYZ::size_type TSequenceOfXYZ::size() const
5301 return myArray.size();
5304 SMDSAbs_EntityType TSequenceOfXYZ::getElementEntity() const
5306 return myElem ? myElem->GetEntityType() : SMDSEntity_Last;
5309 TMeshModifTracer::TMeshModifTracer():
5310 myMeshModifTime(0), myMesh(0)
5313 void TMeshModifTracer::SetMesh( const SMDS_Mesh* theMesh )
5315 if ( theMesh != myMesh )
5316 myMeshModifTime = 0;
5319 bool TMeshModifTracer::IsMeshModified()
5321 bool modified = false;
5324 modified = ( myMeshModifTime != myMesh->GetMTime() );
5325 myMeshModifTime = myMesh->GetMTime();