1 // Copyright (C) 2007-2012 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.
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
22 #include "SMESH_ControlsDef.hxx"
24 #include "SMDS_BallElement.hxx"
25 #include "SMDS_Iterator.hxx"
26 #include "SMDS_Mesh.hxx"
27 #include "SMDS_MeshElement.hxx"
28 #include "SMDS_MeshNode.hxx"
29 #include "SMDS_QuadraticEdge.hxx"
30 #include "SMDS_QuadraticFaceOfNodes.hxx"
31 #include "SMDS_VolumeTool.hxx"
32 #include "SMESHDS_GroupBase.hxx"
33 #include "SMESHDS_Mesh.hxx"
34 #include "SMESH_OctreeNode.hxx"
36 #include <BRepAdaptor_Surface.hxx>
37 #include <BRepClass_FaceClassifier.hxx>
38 #include <BRep_Tool.hxx>
39 #include <Geom_CylindricalSurface.hxx>
40 #include <Geom_Plane.hxx>
41 #include <Geom_Surface.hxx>
42 #include <Precision.hxx>
43 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
44 #include <TColStd_MapOfInteger.hxx>
45 #include <TColStd_SequenceOfAsciiString.hxx>
46 #include <TColgp_Array1OfXYZ.hxx>
49 #include <TopoDS_Edge.hxx>
50 #include <TopoDS_Face.hxx>
51 #include <TopoDS_Iterator.hxx>
52 #include <TopoDS_Shape.hxx>
53 #include <TopoDS_Vertex.hxx>
55 #include <gp_Cylinder.hxx>
62 #include <vtkMeshQuality.h>
74 const double theEps = 1e-100;
75 const double theInf = 1e+100;
77 inline gp_XYZ gpXYZ(const SMDS_MeshNode* aNode )
79 return gp_XYZ(aNode->X(), aNode->Y(), aNode->Z() );
82 inline double getAngle( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
84 gp_Vec v1( P1 - P2 ), v2( P3 - P2 );
86 return v1.Magnitude() < gp::Resolution() ||
87 v2.Magnitude() < gp::Resolution() ? 0 : v1.Angle( v2 );
90 inline double getArea( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
92 gp_Vec aVec1( P2 - P1 );
93 gp_Vec aVec2( P3 - P1 );
94 return ( aVec1 ^ aVec2 ).Magnitude() * 0.5;
97 inline double getArea( const gp_Pnt& P1, const gp_Pnt& P2, const gp_Pnt& P3 )
99 return getArea( P1.XYZ(), P2.XYZ(), P3.XYZ() );
104 inline double getDistance( const gp_XYZ& P1, const gp_XYZ& P2 )
106 double aDist = gp_Pnt( P1 ).Distance( gp_Pnt( P2 ) );
110 int getNbMultiConnection( const SMDS_Mesh* theMesh, const int theId )
115 const SMDS_MeshElement* anEdge = theMesh->FindElement( theId );
116 if ( anEdge == 0 || anEdge->GetType() != SMDSAbs_Edge/* || anEdge->NbNodes() != 2 */)
119 // for each pair of nodes in anEdge (there are 2 pairs in a quadratic edge)
120 // count elements containing both nodes of the pair.
121 // Note that there may be such cases for a quadratic edge (a horizontal line):
126 // +-----+------+ +-----+------+
129 // result sould be 2 in both cases
131 int aResult0 = 0, aResult1 = 0;
132 // last node, it is a medium one in a quadratic edge
133 const SMDS_MeshNode* aLastNode = anEdge->GetNode( anEdge->NbNodes() - 1 );
134 const SMDS_MeshNode* aNode0 = anEdge->GetNode( 0 );
135 const SMDS_MeshNode* aNode1 = anEdge->GetNode( 1 );
136 if ( aNode1 == aLastNode ) aNode1 = 0;
138 SMDS_ElemIteratorPtr anElemIter = aLastNode->GetInverseElementIterator();
139 while( anElemIter->more() ) {
140 const SMDS_MeshElement* anElem = anElemIter->next();
141 if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) {
142 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
143 while ( anIter->more() ) {
144 if ( const SMDS_MeshElement* anElemNode = anIter->next() ) {
145 if ( anElemNode == aNode0 ) {
147 if ( !aNode1 ) break; // not a quadratic edge
149 else if ( anElemNode == aNode1 )
155 int aResult = std::max ( aResult0, aResult1 );
157 // TColStd_MapOfInteger aMap;
159 // SMDS_ElemIteratorPtr anIter = anEdge->nodesIterator();
160 // if ( anIter != 0 ) {
161 // while( anIter->more() ) {
162 // const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next();
165 // SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator();
166 // while( anElemIter->more() ) {
167 // const SMDS_MeshElement* anElem = anElemIter->next();
168 // if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) {
169 // int anId = anElem->GetID();
171 // if ( anIter->more() ) // i.e. first node
173 // else if ( aMap.Contains( anId ) )
183 gp_XYZ getNormale( const SMDS_MeshFace* theFace, bool* ok=0 )
185 int aNbNode = theFace->NbNodes();
187 gp_XYZ q1 = gpXYZ( theFace->GetNode(1)) - gpXYZ( theFace->GetNode(0));
188 gp_XYZ q2 = gpXYZ( theFace->GetNode(2)) - gpXYZ( theFace->GetNode(0));
191 gp_XYZ q3 = gpXYZ( theFace->GetNode(3)) - gpXYZ( theFace->GetNode(0));
194 double len = n.Modulus();
195 bool zeroLen = ( len <= numeric_limits<double>::min());
199 if (ok) *ok = !zeroLen;
207 using namespace SMESH::Controls;
214 Class : NumericalFunctor
215 Description : Base class for numerical functors
217 NumericalFunctor::NumericalFunctor():
223 void NumericalFunctor::SetMesh( const SMDS_Mesh* theMesh )
228 bool NumericalFunctor::GetPoints(const int theId,
229 TSequenceOfXYZ& theRes ) const
236 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
237 if ( !anElem || anElem->GetType() != this->GetType() )
240 return GetPoints( anElem, theRes );
243 bool NumericalFunctor::GetPoints(const SMDS_MeshElement* anElem,
244 TSequenceOfXYZ& theRes )
251 theRes.reserve( anElem->NbNodes() );
253 // Get nodes of the element
254 SMDS_ElemIteratorPtr anIter;
256 if ( anElem->IsQuadratic() ) {
257 switch ( anElem->GetType() ) {
259 anIter = dynamic_cast<const SMDS_VtkEdge*>
260 (anElem)->interlacedNodesElemIterator();
263 anIter = dynamic_cast<const SMDS_VtkFace*>
264 (anElem)->interlacedNodesElemIterator();
267 anIter = anElem->nodesIterator();
272 anIter = anElem->nodesIterator();
276 while( anIter->more() ) {
277 if ( const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>( anIter->next() ))
278 theRes.push_back( gp_XYZ( aNode->X(), aNode->Y(), aNode->Z() ) );
285 long NumericalFunctor::GetPrecision() const
290 void NumericalFunctor::SetPrecision( const long thePrecision )
292 myPrecision = thePrecision;
293 myPrecisionValue = pow( 10., (double)( myPrecision ) );
296 double NumericalFunctor::GetValue( long theId )
300 myCurrElement = myMesh->FindElement( theId );
303 if ( GetPoints( theId, P ))
304 aVal = Round( GetValue( P ));
309 double NumericalFunctor::Round( const double & aVal )
311 return ( myPrecision >= 0 ) ? floor( aVal * myPrecisionValue + 0.5 ) / myPrecisionValue : aVal;
314 //================================================================================
316 * \brief Return histogram of functor values
317 * \param nbIntervals - number of intervals
318 * \param nbEvents - number of mesh elements having values within i-th interval
319 * \param funValues - boundaries of intervals
320 * \param elements - elements to check vulue of; empty list means "of all"
321 * \param minmax - boundaries of diapason of values to divide into intervals
323 //================================================================================
324 void NumericalFunctor::GetHistogram(int nbIntervals,
325 std::vector<int>& nbEvents,
326 std::vector<double>& funValues,
327 const vector<int>& elements,
328 const double* minmax,
329 const bool isLogarithmic)
331 if ( nbIntervals < 1 ||
333 !myMesh->GetMeshInfo().NbElements( GetType() ))
335 nbEvents.resize( nbIntervals, 0 );
336 funValues.resize( nbIntervals+1 );
338 // get all values sorted
339 std::multiset< double > values;
340 if ( elements.empty() )
342 SMDS_ElemIteratorPtr elemIt = myMesh->elementsIterator(GetType());
343 while ( elemIt->more() )
344 values.insert( GetValue( elemIt->next()->GetID() ));
348 vector<int>::const_iterator id = elements.begin();
349 for ( ; id != elements.end(); ++id )
350 values.insert( GetValue( *id ));
355 funValues[0] = minmax[0];
356 funValues[nbIntervals] = minmax[1];
360 funValues[0] = *values.begin();
361 funValues[nbIntervals] = *values.rbegin();
363 // case nbIntervals == 1
364 if ( nbIntervals == 1 )
366 nbEvents[0] = values.size();
370 if (funValues.front() == funValues.back())
372 nbEvents.resize( 1 );
373 nbEvents[0] = values.size();
374 funValues[1] = funValues.back();
375 funValues.resize( 2 );
378 std::multiset< double >::iterator min = values.begin(), max;
379 for ( int i = 0; i < nbIntervals; ++i )
381 // find end value of i-th interval
382 double r = (i+1) / double(nbIntervals);
383 if (isLogarithmic && funValues.front() > 1e-07 && funValues.back() > 1e-07) {
384 double logmin = log10(funValues.front());
385 double lval = logmin + r * (log10(funValues.back()) - logmin);
386 funValues[i+1] = pow(10.0, lval);
389 funValues[i+1] = funValues.front() * (1-r) + funValues.back() * r;
392 // count values in the i-th interval if there are any
393 if ( min != values.end() && *min <= funValues[i+1] )
395 // find the first value out of the interval
396 max = values.upper_bound( funValues[i+1] ); // max is greater than funValues[i+1], or end()
397 nbEvents[i] = std::distance( min, max );
401 // add values larger than minmax[1]
402 nbEvents.back() += std::distance( min, values.end() );
405 //=======================================================================
406 //function : GetValue
408 //=======================================================================
410 double Volume::GetValue( long theElementId )
412 if ( theElementId && myMesh ) {
413 SMDS_VolumeTool aVolumeTool;
414 if ( aVolumeTool.Set( myMesh->FindElement( theElementId )))
415 return aVolumeTool.GetSize();
420 //=======================================================================
421 //function : GetBadRate
422 //purpose : meaningless as it is not quality control functor
423 //=======================================================================
425 double Volume::GetBadRate( double Value, int /*nbNodes*/ ) const
430 //=======================================================================
433 //=======================================================================
435 SMDSAbs_ElementType Volume::GetType() const
437 return SMDSAbs_Volume;
440 //=======================================================================
442 Class : MaxElementLength2D
443 Description : Functor calculating maximum length of 2D element
445 double MaxElementLength2D::GetValue( const TSequenceOfXYZ& P )
451 if( len == 3 ) { // triangles
452 double L1 = getDistance(P( 1 ),P( 2 ));
453 double L2 = getDistance(P( 2 ),P( 3 ));
454 double L3 = getDistance(P( 3 ),P( 1 ));
455 aVal = Max(L1,Max(L2,L3));
457 else if( len == 4 ) { // quadrangles
458 double L1 = getDistance(P( 1 ),P( 2 ));
459 double L2 = getDistance(P( 2 ),P( 3 ));
460 double L3 = getDistance(P( 3 ),P( 4 ));
461 double L4 = getDistance(P( 4 ),P( 1 ));
462 double D1 = getDistance(P( 1 ),P( 3 ));
463 double D2 = getDistance(P( 2 ),P( 4 ));
464 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(D1,D2));
466 else if( len == 6 ) { // quadratic triangles
467 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
468 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
469 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 1 ));
470 aVal = Max(L1,Max(L2,L3));
472 else if( len == 8 || len == 9 ) { // quadratic quadrangles
473 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
474 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
475 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 7 ));
476 double L4 = getDistance(P( 7 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
477 double D1 = getDistance(P( 1 ),P( 5 ));
478 double D2 = getDistance(P( 3 ),P( 7 ));
479 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(D1,D2));
482 if( myPrecision >= 0 )
484 double prec = pow( 10., (double)myPrecision );
485 aVal = floor( aVal * prec + 0.5 ) / prec;
490 double MaxElementLength2D::GetValue( long theElementId )
493 return GetPoints( theElementId, P ) ? GetValue(P) : 0.0;
496 double MaxElementLength2D::GetBadRate( double Value, int /*nbNodes*/ ) const
501 SMDSAbs_ElementType MaxElementLength2D::GetType() const
506 //=======================================================================
508 Class : MaxElementLength3D
509 Description : Functor calculating maximum length of 3D element
512 double MaxElementLength3D::GetValue( long theElementId )
515 if( GetPoints( theElementId, P ) ) {
517 const SMDS_MeshElement* aElem = myMesh->FindElement( theElementId );
518 SMDSAbs_ElementType aType = aElem->GetType();
522 if( len == 4 ) { // tetras
523 double L1 = getDistance(P( 1 ),P( 2 ));
524 double L2 = getDistance(P( 2 ),P( 3 ));
525 double L3 = getDistance(P( 3 ),P( 1 ));
526 double L4 = getDistance(P( 1 ),P( 4 ));
527 double L5 = getDistance(P( 2 ),P( 4 ));
528 double L6 = getDistance(P( 3 ),P( 4 ));
529 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
532 else if( len == 5 ) { // pyramids
533 double L1 = getDistance(P( 1 ),P( 2 ));
534 double L2 = getDistance(P( 2 ),P( 3 ));
535 double L3 = getDistance(P( 3 ),P( 4 ));
536 double L4 = getDistance(P( 4 ),P( 1 ));
537 double L5 = getDistance(P( 1 ),P( 5 ));
538 double L6 = getDistance(P( 2 ),P( 5 ));
539 double L7 = getDistance(P( 3 ),P( 5 ));
540 double L8 = getDistance(P( 4 ),P( 5 ));
541 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
542 aVal = Max(aVal,Max(L7,L8));
545 else if( len == 6 ) { // pentas
546 double L1 = getDistance(P( 1 ),P( 2 ));
547 double L2 = getDistance(P( 2 ),P( 3 ));
548 double L3 = getDistance(P( 3 ),P( 1 ));
549 double L4 = getDistance(P( 4 ),P( 5 ));
550 double L5 = getDistance(P( 5 ),P( 6 ));
551 double L6 = getDistance(P( 6 ),P( 4 ));
552 double L7 = getDistance(P( 1 ),P( 4 ));
553 double L8 = getDistance(P( 2 ),P( 5 ));
554 double L9 = getDistance(P( 3 ),P( 6 ));
555 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
556 aVal = Max(aVal,Max(Max(L7,L8),L9));
559 else if( len == 8 ) { // hexas
560 double L1 = getDistance(P( 1 ),P( 2 ));
561 double L2 = getDistance(P( 2 ),P( 3 ));
562 double L3 = getDistance(P( 3 ),P( 4 ));
563 double L4 = getDistance(P( 4 ),P( 1 ));
564 double L5 = getDistance(P( 5 ),P( 6 ));
565 double L6 = getDistance(P( 6 ),P( 7 ));
566 double L7 = getDistance(P( 7 ),P( 8 ));
567 double L8 = getDistance(P( 8 ),P( 5 ));
568 double L9 = getDistance(P( 1 ),P( 5 ));
569 double L10= getDistance(P( 2 ),P( 6 ));
570 double L11= getDistance(P( 3 ),P( 7 ));
571 double L12= getDistance(P( 4 ),P( 8 ));
572 double D1 = getDistance(P( 1 ),P( 7 ));
573 double D2 = getDistance(P( 2 ),P( 8 ));
574 double D3 = getDistance(P( 3 ),P( 5 ));
575 double D4 = getDistance(P( 4 ),P( 6 ));
576 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
577 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
578 aVal = Max(aVal,Max(L11,L12));
579 aVal = Max(aVal,Max(Max(D1,D2),Max(D3,D4)));
582 else if( len == 12 ) { // hexagonal prism
583 for ( int i1 = 1; i1 < 12; ++i1 )
584 for ( int i2 = i1+1; i1 <= 12; ++i1 )
585 aVal = Max( aVal, getDistance(P( i1 ),P( i2 )));
588 else if( len == 10 ) { // quadratic tetras
589 double L1 = getDistance(P( 1 ),P( 5 )) + getDistance(P( 5 ),P( 2 ));
590 double L2 = getDistance(P( 2 ),P( 6 )) + getDistance(P( 6 ),P( 3 ));
591 double L3 = getDistance(P( 3 ),P( 7 )) + getDistance(P( 7 ),P( 1 ));
592 double L4 = getDistance(P( 1 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
593 double L5 = getDistance(P( 2 ),P( 9 )) + getDistance(P( 9 ),P( 4 ));
594 double L6 = getDistance(P( 3 ),P( 10 )) + getDistance(P( 10 ),P( 4 ));
595 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
598 else if( len == 13 ) { // quadratic pyramids
599 double L1 = getDistance(P( 1 ),P( 6 )) + getDistance(P( 6 ),P( 2 ));
600 double L2 = getDistance(P( 2 ),P( 7 )) + getDistance(P( 7 ),P( 3 ));
601 double L3 = getDistance(P( 3 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
602 double L4 = getDistance(P( 4 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
603 double L5 = getDistance(P( 1 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
604 double L6 = getDistance(P( 2 ),P( 11 )) + getDistance(P( 11 ),P( 5 ));
605 double L7 = getDistance(P( 3 ),P( 12 )) + getDistance(P( 12 ),P( 5 ));
606 double L8 = getDistance(P( 4 ),P( 13 )) + getDistance(P( 13 ),P( 5 ));
607 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
608 aVal = Max(aVal,Max(L7,L8));
611 else if( len == 15 ) { // quadratic pentas
612 double L1 = getDistance(P( 1 ),P( 7 )) + getDistance(P( 7 ),P( 2 ));
613 double L2 = getDistance(P( 2 ),P( 8 )) + getDistance(P( 8 ),P( 3 ));
614 double L3 = getDistance(P( 3 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
615 double L4 = getDistance(P( 4 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
616 double L5 = getDistance(P( 5 ),P( 11 )) + getDistance(P( 11 ),P( 6 ));
617 double L6 = getDistance(P( 6 ),P( 12 )) + getDistance(P( 12 ),P( 4 ));
618 double L7 = getDistance(P( 1 ),P( 13 )) + getDistance(P( 13 ),P( 4 ));
619 double L8 = getDistance(P( 2 ),P( 14 )) + getDistance(P( 14 ),P( 5 ));
620 double L9 = getDistance(P( 3 ),P( 15 )) + getDistance(P( 15 ),P( 6 ));
621 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
622 aVal = Max(aVal,Max(Max(L7,L8),L9));
625 else if( len == 20 || len == 27 ) { // quadratic hexas
626 double L1 = getDistance(P( 1 ),P( 9 )) + getDistance(P( 9 ),P( 2 ));
627 double L2 = getDistance(P( 2 ),P( 10 )) + getDistance(P( 10 ),P( 3 ));
628 double L3 = getDistance(P( 3 ),P( 11 )) + getDistance(P( 11 ),P( 4 ));
629 double L4 = getDistance(P( 4 ),P( 12 )) + getDistance(P( 12 ),P( 1 ));
630 double L5 = getDistance(P( 5 ),P( 13 )) + getDistance(P( 13 ),P( 6 ));
631 double L6 = getDistance(P( 6 ),P( 14 )) + getDistance(P( 14 ),P( 7 ));
632 double L7 = getDistance(P( 7 ),P( 15 )) + getDistance(P( 15 ),P( 8 ));
633 double L8 = getDistance(P( 8 ),P( 16 )) + getDistance(P( 16 ),P( 5 ));
634 double L9 = getDistance(P( 1 ),P( 17 )) + getDistance(P( 17 ),P( 5 ));
635 double L10= getDistance(P( 2 ),P( 18 )) + getDistance(P( 18 ),P( 6 ));
636 double L11= getDistance(P( 3 ),P( 19 )) + getDistance(P( 19 ),P( 7 ));
637 double L12= getDistance(P( 4 ),P( 20 )) + getDistance(P( 20 ),P( 8 ));
638 double D1 = getDistance(P( 1 ),P( 7 ));
639 double D2 = getDistance(P( 2 ),P( 8 ));
640 double D3 = getDistance(P( 3 ),P( 5 ));
641 double D4 = getDistance(P( 4 ),P( 6 ));
642 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
643 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
644 aVal = Max(aVal,Max(L11,L12));
645 aVal = Max(aVal,Max(Max(D1,D2),Max(D3,D4)));
648 else if( len > 1 && aElem->IsPoly() ) { // polys
649 // get the maximum distance between all pairs of nodes
650 for( int i = 1; i <= len; i++ ) {
651 for( int j = 1; j <= len; j++ ) {
652 if( j > i ) { // optimization of the loop
653 double D = getDistance( P(i), P(j) );
654 aVal = Max( aVal, D );
661 if( myPrecision >= 0 )
663 double prec = pow( 10., (double)myPrecision );
664 aVal = floor( aVal * prec + 0.5 ) / prec;
671 double MaxElementLength3D::GetBadRate( double Value, int /*nbNodes*/ ) const
676 SMDSAbs_ElementType MaxElementLength3D::GetType() const
678 return SMDSAbs_Volume;
681 //=======================================================================
684 Description : Functor for calculation of minimum angle
687 double MinimumAngle::GetValue( const TSequenceOfXYZ& P )
694 aMin = getAngle(P( P.size() ), P( 1 ), P( 2 ));
695 aMin = Min(aMin,getAngle(P( P.size()-1 ), P( P.size() ), P( 1 )));
697 for (int i=2; i<P.size();i++){
698 double A0 = getAngle( P( i-1 ), P( i ), P( i+1 ) );
702 return aMin * 180.0 / M_PI;
705 double MinimumAngle::GetBadRate( double Value, int nbNodes ) const
707 //const double aBestAngle = PI / nbNodes;
708 const double aBestAngle = 180.0 - ( 360.0 / double(nbNodes) );
709 return ( fabs( aBestAngle - Value ));
712 SMDSAbs_ElementType MinimumAngle::GetType() const
720 Description : Functor for calculating aspect ratio
722 double AspectRatio::GetValue( long theId )
725 myCurrElement = myMesh->FindElement( theId );
726 if ( myCurrElement && myCurrElement->GetVtkType() == VTK_QUAD )
729 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myCurrElement->getMeshId()]->getGrid();
730 if ( vtkCell* avtkCell = grid->GetCell( myCurrElement->getVtkId() ))
731 aVal = Round( vtkMeshQuality::QuadAspectRatio( avtkCell ));
736 if ( GetPoints( myCurrElement, P ))
737 aVal = Round( GetValue( P ));
742 double AspectRatio::GetValue( const TSequenceOfXYZ& P )
744 // According to "Mesh quality control" by Nadir Bouhamau referring to
745 // Pascal Jean Frey and Paul-Louis George. Maillages, applications aux elements finis.
746 // Hermes Science publications, Paris 1999 ISBN 2-7462-0024-4
749 int nbNodes = P.size();
754 // Compute aspect ratio
756 if ( nbNodes == 3 ) {
757 // Compute lengths of the sides
758 std::vector< double > aLen (nbNodes);
759 for ( int i = 0; i < nbNodes - 1; i++ )
760 aLen[ i ] = getDistance( P( i + 1 ), P( i + 2 ) );
761 aLen[ nbNodes - 1 ] = getDistance( P( 1 ), P( nbNodes ) );
762 // Q = alfa * h * p / S, where
764 // alfa = sqrt( 3 ) / 6
765 // h - length of the longest edge
766 // p - half perimeter
767 // S - triangle surface
768 const double alfa = sqrt( 3. ) / 6.;
769 double maxLen = Max( aLen[ 0 ], Max( aLen[ 1 ], aLen[ 2 ] ) );
770 double half_perimeter = ( aLen[0] + aLen[1] + aLen[2] ) / 2.;
771 double anArea = getArea( P( 1 ), P( 2 ), P( 3 ) );
772 if ( anArea <= theEps )
774 return alfa * maxLen * half_perimeter / anArea;
776 else if ( nbNodes == 6 ) { // quadratic triangles
777 // Compute lengths of the sides
778 std::vector< double > aLen (3);
779 aLen[0] = getDistance( P(1), P(3) );
780 aLen[1] = getDistance( P(3), P(5) );
781 aLen[2] = getDistance( P(5), P(1) );
782 // Q = alfa * h * p / S, where
784 // alfa = sqrt( 3 ) / 6
785 // h - length of the longest edge
786 // p - half perimeter
787 // S - triangle surface
788 const double alfa = sqrt( 3. ) / 6.;
789 double maxLen = Max( aLen[ 0 ], Max( aLen[ 1 ], aLen[ 2 ] ) );
790 double half_perimeter = ( aLen[0] + aLen[1] + aLen[2] ) / 2.;
791 double anArea = getArea( P(1), P(3), P(5) );
792 if ( anArea <= theEps )
794 return alfa * maxLen * half_perimeter / anArea;
796 else if( nbNodes == 4 ) { // quadrangle
797 // Compute lengths of the sides
798 std::vector< double > aLen (4);
799 aLen[0] = getDistance( P(1), P(2) );
800 aLen[1] = getDistance( P(2), P(3) );
801 aLen[2] = getDistance( P(3), P(4) );
802 aLen[3] = getDistance( P(4), P(1) );
803 // Compute lengths of the diagonals
804 std::vector< double > aDia (2);
805 aDia[0] = getDistance( P(1), P(3) );
806 aDia[1] = getDistance( P(2), P(4) );
807 // Compute areas of all triangles which can be built
808 // taking three nodes of the quadrangle
809 std::vector< double > anArea (4);
810 anArea[0] = getArea( P(1), P(2), P(3) );
811 anArea[1] = getArea( P(1), P(2), P(4) );
812 anArea[2] = getArea( P(1), P(3), P(4) );
813 anArea[3] = getArea( P(2), P(3), P(4) );
814 // Q = alpha * L * C1 / C2, where
816 // alpha = sqrt( 1/32 )
817 // L = max( L1, L2, L3, L4, D1, D2 )
818 // C1 = sqrt( ( L1^2 + L1^2 + L1^2 + L1^2 ) / 4 )
819 // C2 = min( S1, S2, S3, S4 )
820 // Li - lengths of the edges
821 // Di - lengths of the diagonals
822 // Si - areas of the triangles
823 const double alpha = sqrt( 1 / 32. );
824 double L = Max( aLen[ 0 ],
828 Max( aDia[ 0 ], aDia[ 1 ] ) ) ) ) );
829 double C1 = sqrt( ( aLen[0] * aLen[0] +
832 aLen[3] * aLen[3] ) / 4. );
833 double C2 = Min( anArea[ 0 ],
835 Min( anArea[ 2 ], anArea[ 3 ] ) ) );
838 return alpha * L * C1 / C2;
840 else if( nbNodes == 8 || nbNodes == 9 ) { // nbNodes==8 - quadratic quadrangle
841 // Compute lengths of the sides
842 std::vector< double > aLen (4);
843 aLen[0] = getDistance( P(1), P(3) );
844 aLen[1] = getDistance( P(3), P(5) );
845 aLen[2] = getDistance( P(5), P(7) );
846 aLen[3] = getDistance( P(7), P(1) );
847 // Compute lengths of the diagonals
848 std::vector< double > aDia (2);
849 aDia[0] = getDistance( P(1), P(5) );
850 aDia[1] = getDistance( P(3), P(7) );
851 // Compute areas of all triangles which can be built
852 // taking three nodes of the quadrangle
853 std::vector< double > anArea (4);
854 anArea[0] = getArea( P(1), P(3), P(5) );
855 anArea[1] = getArea( P(1), P(3), P(7) );
856 anArea[2] = getArea( P(1), P(5), P(7) );
857 anArea[3] = getArea( P(3), P(5), P(7) );
858 // Q = alpha * L * C1 / C2, where
860 // alpha = sqrt( 1/32 )
861 // L = max( L1, L2, L3, L4, D1, D2 )
862 // C1 = sqrt( ( L1^2 + L1^2 + L1^2 + L1^2 ) / 4 )
863 // C2 = min( S1, S2, S3, S4 )
864 // Li - lengths of the edges
865 // Di - lengths of the diagonals
866 // Si - areas of the triangles
867 const double alpha = sqrt( 1 / 32. );
868 double L = Max( aLen[ 0 ],
872 Max( aDia[ 0 ], aDia[ 1 ] ) ) ) ) );
873 double C1 = sqrt( ( aLen[0] * aLen[0] +
876 aLen[3] * aLen[3] ) / 4. );
877 double C2 = Min( anArea[ 0 ],
879 Min( anArea[ 2 ], anArea[ 3 ] ) ) );
882 return alpha * L * C1 / C2;
887 double AspectRatio::GetBadRate( double Value, int /*nbNodes*/ ) const
889 // the aspect ratio is in the range [1.0,infinity]
890 // < 1.0 = very bad, zero area
893 return ( Value < 0.9 ) ? 1000 : Value / 1000.;
896 SMDSAbs_ElementType AspectRatio::GetType() const
903 Class : AspectRatio3D
904 Description : Functor for calculating aspect ratio
908 inline double getHalfPerimeter(double theTria[3]){
909 return (theTria[0] + theTria[1] + theTria[2])/2.0;
912 inline double getArea(double theHalfPerim, double theTria[3]){
913 return sqrt(theHalfPerim*
914 (theHalfPerim-theTria[0])*
915 (theHalfPerim-theTria[1])*
916 (theHalfPerim-theTria[2]));
919 inline double getVolume(double theLen[6]){
920 double a2 = theLen[0]*theLen[0];
921 double b2 = theLen[1]*theLen[1];
922 double c2 = theLen[2]*theLen[2];
923 double d2 = theLen[3]*theLen[3];
924 double e2 = theLen[4]*theLen[4];
925 double f2 = theLen[5]*theLen[5];
926 double P = 4.0*a2*b2*d2;
927 double Q = a2*(b2+d2-e2)-b2*(a2+d2-f2)-d2*(a2+b2-c2);
928 double R = (b2+d2-e2)*(a2+d2-f2)*(a2+d2-f2);
929 return sqrt(P-Q+R)/12.0;
932 inline double getVolume2(double theLen[6]){
933 double a2 = theLen[0]*theLen[0];
934 double b2 = theLen[1]*theLen[1];
935 double c2 = theLen[2]*theLen[2];
936 double d2 = theLen[3]*theLen[3];
937 double e2 = theLen[4]*theLen[4];
938 double f2 = theLen[5]*theLen[5];
940 double P = a2*e2*(b2+c2+d2+f2-a2-e2);
941 double Q = b2*f2*(a2+c2+d2+e2-b2-f2);
942 double R = c2*d2*(a2+b2+e2+f2-c2-d2);
943 double S = a2*b2*d2+b2*c2*e2+a2*c2*f2+d2*e2*f2;
945 return sqrt(P+Q+R-S)/12.0;
948 inline double getVolume(const TSequenceOfXYZ& P){
949 gp_Vec aVec1( P( 2 ) - P( 1 ) );
950 gp_Vec aVec2( P( 3 ) - P( 1 ) );
951 gp_Vec aVec3( P( 4 ) - P( 1 ) );
952 gp_Vec anAreaVec( aVec1 ^ aVec2 );
953 return fabs(aVec3 * anAreaVec) / 6.0;
956 inline double getMaxHeight(double theLen[6])
958 double aHeight = std::max(theLen[0],theLen[1]);
959 aHeight = std::max(aHeight,theLen[2]);
960 aHeight = std::max(aHeight,theLen[3]);
961 aHeight = std::max(aHeight,theLen[4]);
962 aHeight = std::max(aHeight,theLen[5]);
968 double AspectRatio3D::GetValue( long theId )
971 myCurrElement = myMesh->FindElement( theId );
972 if ( myCurrElement && myCurrElement->GetVtkType() == VTK_TETRA )
974 // Action from CoTech | ACTION 31.3:
975 // EURIWARE BO: Homogenize the formulas used to calculate the Controls in SMESH to fit with
976 // those of ParaView. The library used by ParaView for those calculations can be reused in SMESH.
977 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myCurrElement->getMeshId()]->getGrid();
978 if ( vtkCell* avtkCell = grid->GetCell( myCurrElement->getVtkId() ))
979 aVal = Round( vtkMeshQuality::TetAspectRatio( avtkCell ));
984 if ( GetPoints( myCurrElement, P ))
985 aVal = Round( GetValue( P ));
990 double AspectRatio3D::GetValue( const TSequenceOfXYZ& P )
992 double aQuality = 0.0;
993 if(myCurrElement->IsPoly()) return aQuality;
995 int nbNodes = P.size();
997 if(myCurrElement->IsQuadratic()) {
998 if(nbNodes==10) nbNodes=4; // quadratic tetrahedron
999 else if(nbNodes==13) nbNodes=5; // quadratic pyramid
1000 else if(nbNodes==15) nbNodes=6; // quadratic pentahedron
1001 else if(nbNodes==20) nbNodes=8; // quadratic hexahedron
1002 else if(nbNodes==27) nbNodes=8; // quadratic hexahedron
1003 else return aQuality;
1009 getDistance(P( 1 ),P( 2 )), // a
1010 getDistance(P( 2 ),P( 3 )), // b
1011 getDistance(P( 3 ),P( 1 )), // c
1012 getDistance(P( 2 ),P( 4 )), // d
1013 getDistance(P( 3 ),P( 4 )), // e
1014 getDistance(P( 1 ),P( 4 )) // f
1016 double aTria[4][3] = {
1017 {aLen[0],aLen[1],aLen[2]}, // abc
1018 {aLen[0],aLen[3],aLen[5]}, // adf
1019 {aLen[1],aLen[3],aLen[4]}, // bde
1020 {aLen[2],aLen[4],aLen[5]} // cef
1022 double aSumArea = 0.0;
1023 double aHalfPerimeter = getHalfPerimeter(aTria[0]);
1024 double anArea = getArea(aHalfPerimeter,aTria[0]);
1026 aHalfPerimeter = getHalfPerimeter(aTria[1]);
1027 anArea = getArea(aHalfPerimeter,aTria[1]);
1029 aHalfPerimeter = getHalfPerimeter(aTria[2]);
1030 anArea = getArea(aHalfPerimeter,aTria[2]);
1032 aHalfPerimeter = getHalfPerimeter(aTria[3]);
1033 anArea = getArea(aHalfPerimeter,aTria[3]);
1035 double aVolume = getVolume(P);
1036 //double aVolume = getVolume(aLen);
1037 double aHeight = getMaxHeight(aLen);
1038 static double aCoeff = sqrt(2.0)/12.0;
1039 if ( aVolume > DBL_MIN )
1040 aQuality = aCoeff*aHeight*aSumArea/aVolume;
1045 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 3 ),P( 5 )};
1046 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1049 gp_XYZ aXYZ[4] = {P( 1 ),P( 3 ),P( 4 ),P( 5 )};
1050 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1053 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 5 )};
1054 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1057 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 4 ),P( 5 )};
1058 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1064 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 6 )};
1065 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1068 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 3 )};
1069 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1072 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 6 )};
1073 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1076 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
1077 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1080 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 6 )};
1081 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1084 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 3 )};
1085 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1091 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
1092 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1095 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 4 )};
1096 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1099 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 7 )};
1100 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1103 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 8 )};
1104 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1107 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 3 )};
1108 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1111 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 4 )};
1112 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1115 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 7 )};
1116 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1119 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 8 )};
1120 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1123 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 3 )};
1124 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1127 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 4 )};
1128 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1131 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 7 )};
1132 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1135 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 8 )};
1136 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1139 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 1 )};
1140 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1143 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 2 )};
1144 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1147 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 5 )};
1148 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1151 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 6 )};
1152 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1155 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 1 )};
1156 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1159 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 2 )};
1160 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1163 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 5 )};
1164 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1167 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 6 )};
1168 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1171 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 1 )};
1172 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1175 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
1176 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1179 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 5 )};
1180 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1183 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 6 )};
1184 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1187 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
1188 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1191 gp_XYZ aXYZ[4] = {P( 4 ),P( 5 ),P( 8 ),P( 2 )};
1192 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1195 gp_XYZ aXYZ[4] = {P( 1 ),P( 4 ),P( 5 ),P( 3 )};
1196 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1199 gp_XYZ aXYZ[4] = {P( 3 ),P( 6 ),P( 7 ),P( 1 )};
1200 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1203 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 6 ),P( 4 )};
1204 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1207 gp_XYZ aXYZ[4] = {P( 5 ),P( 6 ),P( 8 ),P( 3 )};
1208 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1211 gp_XYZ aXYZ[4] = {P( 7 ),P( 8 ),P( 6 ),P( 1 )};
1212 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1215 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 7 )};
1216 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1219 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 2 ),P( 5 )};
1220 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1226 gp_XYZ aXYZ[8] = {P( 1 ),P( 2 ),P( 4 ),P( 5 ),P( 7 ),P( 8 ),P( 10 ),P( 11 )};
1227 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[8])),aQuality);
1230 gp_XYZ aXYZ[8] = {P( 2 ),P( 3 ),P( 5 ),P( 6 ),P( 8 ),P( 9 ),P( 11 ),P( 12 )};
1231 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[8])),aQuality);
1234 gp_XYZ aXYZ[8] = {P( 3 ),P( 4 ),P( 6 ),P( 1 ),P( 9 ),P( 10 ),P( 12 ),P( 7 )};
1235 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[8])),aQuality);
1238 } // switch(nbNodes)
1240 if ( nbNodes > 4 ) {
1241 // avaluate aspect ratio of quadranle faces
1242 AspectRatio aspect2D;
1243 SMDS_VolumeTool::VolumeType type = SMDS_VolumeTool::GetType( nbNodes );
1244 int nbFaces = SMDS_VolumeTool::NbFaces( type );
1245 TSequenceOfXYZ points(4);
1246 for ( int i = 0; i < nbFaces; ++i ) { // loop on faces of a volume
1247 if ( SMDS_VolumeTool::NbFaceNodes( type, i ) != 4 )
1249 const int* pInd = SMDS_VolumeTool::GetFaceNodesIndices( type, i, true );
1250 for ( int p = 0; p < 4; ++p ) // loop on nodes of a quadranle face
1251 points( p + 1 ) = P( pInd[ p ] + 1 );
1252 aQuality = std::max( aQuality, aspect2D.GetValue( points ));
1258 double AspectRatio3D::GetBadRate( double Value, int /*nbNodes*/ ) const
1260 // the aspect ratio is in the range [1.0,infinity]
1263 return Value / 1000.;
1266 SMDSAbs_ElementType AspectRatio3D::GetType() const
1268 return SMDSAbs_Volume;
1274 Description : Functor for calculating warping
1276 double Warping::GetValue( const TSequenceOfXYZ& P )
1278 if ( P.size() != 4 )
1281 gp_XYZ G = ( P( 1 ) + P( 2 ) + P( 3 ) + P( 4 ) ) / 4.;
1283 double A1 = ComputeA( P( 1 ), P( 2 ), P( 3 ), G );
1284 double A2 = ComputeA( P( 2 ), P( 3 ), P( 4 ), G );
1285 double A3 = ComputeA( P( 3 ), P( 4 ), P( 1 ), G );
1286 double A4 = ComputeA( P( 4 ), P( 1 ), P( 2 ), G );
1288 return Max( Max( A1, A2 ), Max( A3, A4 ) );
1291 double Warping::ComputeA( const gp_XYZ& thePnt1,
1292 const gp_XYZ& thePnt2,
1293 const gp_XYZ& thePnt3,
1294 const gp_XYZ& theG ) const
1296 double aLen1 = gp_Pnt( thePnt1 ).Distance( gp_Pnt( thePnt2 ) );
1297 double aLen2 = gp_Pnt( thePnt2 ).Distance( gp_Pnt( thePnt3 ) );
1298 double L = Min( aLen1, aLen2 ) * 0.5;
1302 gp_XYZ GI = ( thePnt2 + thePnt1 ) / 2. - theG;
1303 gp_XYZ GJ = ( thePnt3 + thePnt2 ) / 2. - theG;
1304 gp_XYZ N = GI.Crossed( GJ );
1306 if ( N.Modulus() < gp::Resolution() )
1311 double H = ( thePnt2 - theG ).Dot( N );
1312 return asin( fabs( H / L ) ) * 180. / M_PI;
1315 double Warping::GetBadRate( double Value, int /*nbNodes*/ ) const
1317 // the warp is in the range [0.0,PI/2]
1318 // 0.0 = good (no warp)
1319 // PI/2 = bad (face pliee)
1323 SMDSAbs_ElementType Warping::GetType() const
1325 return SMDSAbs_Face;
1331 Description : Functor for calculating taper
1333 double Taper::GetValue( const TSequenceOfXYZ& P )
1335 if ( P.size() != 4 )
1339 double J1 = getArea( P( 4 ), P( 1 ), P( 2 ) ) / 2.;
1340 double J2 = getArea( P( 3 ), P( 1 ), P( 2 ) ) / 2.;
1341 double J3 = getArea( P( 2 ), P( 3 ), P( 4 ) ) / 2.;
1342 double J4 = getArea( P( 3 ), P( 4 ), P( 1 ) ) / 2.;
1344 double JA = 0.25 * ( J1 + J2 + J3 + J4 );
1348 double T1 = fabs( ( J1 - JA ) / JA );
1349 double T2 = fabs( ( J2 - JA ) / JA );
1350 double T3 = fabs( ( J3 - JA ) / JA );
1351 double T4 = fabs( ( J4 - JA ) / JA );
1353 return Max( Max( T1, T2 ), Max( T3, T4 ) );
1356 double Taper::GetBadRate( double Value, int /*nbNodes*/ ) const
1358 // the taper is in the range [0.0,1.0]
1359 // 0.0 = good (no taper)
1360 // 1.0 = bad (les cotes opposes sont allignes)
1364 SMDSAbs_ElementType Taper::GetType() const
1366 return SMDSAbs_Face;
1372 Description : Functor for calculating skew in degrees
1374 static inline double skewAngle( const gp_XYZ& p1, const gp_XYZ& p2, const gp_XYZ& p3 )
1376 gp_XYZ p12 = ( p2 + p1 ) / 2.;
1377 gp_XYZ p23 = ( p3 + p2 ) / 2.;
1378 gp_XYZ p31 = ( p3 + p1 ) / 2.;
1380 gp_Vec v1( p31 - p2 ), v2( p12 - p23 );
1382 return v1.Magnitude() < gp::Resolution() || v2.Magnitude() < gp::Resolution() ? 0. : v1.Angle( v2 );
1385 double Skew::GetValue( const TSequenceOfXYZ& P )
1387 if ( P.size() != 3 && P.size() != 4 )
1391 static double PI2 = M_PI / 2.;
1392 if ( P.size() == 3 )
1394 double A0 = fabs( PI2 - skewAngle( P( 3 ), P( 1 ), P( 2 ) ) );
1395 double A1 = fabs( PI2 - skewAngle( P( 1 ), P( 2 ), P( 3 ) ) );
1396 double A2 = fabs( PI2 - skewAngle( P( 2 ), P( 3 ), P( 1 ) ) );
1398 return Max( A0, Max( A1, A2 ) ) * 180. / M_PI;
1402 gp_XYZ p12 = ( P( 1 ) + P( 2 ) ) / 2.;
1403 gp_XYZ p23 = ( P( 2 ) + P( 3 ) ) / 2.;
1404 gp_XYZ p34 = ( P( 3 ) + P( 4 ) ) / 2.;
1405 gp_XYZ p41 = ( P( 4 ) + P( 1 ) ) / 2.;
1407 gp_Vec v1( p34 - p12 ), v2( p23 - p41 );
1408 double A = v1.Magnitude() <= gp::Resolution() || v2.Magnitude() <= gp::Resolution()
1409 ? 0. : fabs( PI2 - v1.Angle( v2 ) );
1415 return A * 180. / M_PI;
1419 double Skew::GetBadRate( double Value, int /*nbNodes*/ ) const
1421 // the skew is in the range [0.0,PI/2].
1427 SMDSAbs_ElementType Skew::GetType() const
1429 return SMDSAbs_Face;
1435 Description : Functor for calculating area
1437 double Area::GetValue( const TSequenceOfXYZ& P )
1440 if ( P.size() > 2 ) {
1441 gp_Vec aVec1( P(2) - P(1) );
1442 gp_Vec aVec2( P(3) - P(1) );
1443 gp_Vec SumVec = aVec1 ^ aVec2;
1444 for (int i=4; i<=P.size(); i++) {
1445 gp_Vec aVec1( P(i-1) - P(1) );
1446 gp_Vec aVec2( P(i) - P(1) );
1447 gp_Vec tmp = aVec1 ^ aVec2;
1450 val = SumVec.Magnitude() * 0.5;
1455 double Area::GetBadRate( double Value, int /*nbNodes*/ ) const
1457 // meaningless as it is not a quality control functor
1461 SMDSAbs_ElementType Area::GetType() const
1463 return SMDSAbs_Face;
1469 Description : Functor for calculating length of edge
1471 double Length::GetValue( const TSequenceOfXYZ& P )
1473 switch ( P.size() ) {
1474 case 2: return getDistance( P( 1 ), P( 2 ) );
1475 case 3: return getDistance( P( 1 ), P( 2 ) ) + getDistance( P( 2 ), P( 3 ) );
1480 double Length::GetBadRate( double Value, int /*nbNodes*/ ) const
1482 // meaningless as it is not quality control functor
1486 SMDSAbs_ElementType Length::GetType() const
1488 return SMDSAbs_Edge;
1493 Description : Functor for calculating length of edge
1496 double Length2D::GetValue( long theElementId)
1500 //cout<<"Length2D::GetValue"<<endl;
1501 if (GetPoints(theElementId,P)){
1502 //for(int jj=1; jj<=P.size(); jj++)
1503 // cout<<"jj="<<jj<<" P("<<P(jj).X()<<","<<P(jj).Y()<<","<<P(jj).Z()<<")"<<endl;
1505 double aVal;// = GetValue( P );
1506 const SMDS_MeshElement* aElem = myMesh->FindElement( theElementId );
1507 SMDSAbs_ElementType aType = aElem->GetType();
1516 aVal = getDistance( P( 1 ), P( 2 ) );
1519 else if (len == 3){ // quadratic edge
1520 aVal = getDistance(P( 1 ),P( 3 )) + getDistance(P( 3 ),P( 2 ));
1524 if (len == 3){ // triangles
1525 double L1 = getDistance(P( 1 ),P( 2 ));
1526 double L2 = getDistance(P( 2 ),P( 3 ));
1527 double L3 = getDistance(P( 3 ),P( 1 ));
1528 aVal = Max(L1,Max(L2,L3));
1531 else if (len == 4){ // quadrangles
1532 double L1 = getDistance(P( 1 ),P( 2 ));
1533 double L2 = getDistance(P( 2 ),P( 3 ));
1534 double L3 = getDistance(P( 3 ),P( 4 ));
1535 double L4 = getDistance(P( 4 ),P( 1 ));
1536 aVal = Max(Max(L1,L2),Max(L3,L4));
1539 if (len == 6){ // quadratic triangles
1540 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1541 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1542 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 1 ));
1543 aVal = Max(L1,Max(L2,L3));
1544 //cout<<"L1="<<L1<<" L2="<<L2<<"L3="<<L3<<" aVal="<<aVal<<endl;
1547 else if (len == 8){ // quadratic quadrangles
1548 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1549 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1550 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 7 ));
1551 double L4 = getDistance(P( 7 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
1552 aVal = Max(Max(L1,L2),Max(L3,L4));
1555 case SMDSAbs_Volume:
1556 if (len == 4){ // tetraidrs
1557 double L1 = getDistance(P( 1 ),P( 2 ));
1558 double L2 = getDistance(P( 2 ),P( 3 ));
1559 double L3 = getDistance(P( 3 ),P( 1 ));
1560 double L4 = getDistance(P( 1 ),P( 4 ));
1561 double L5 = getDistance(P( 2 ),P( 4 ));
1562 double L6 = getDistance(P( 3 ),P( 4 ));
1563 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1566 else if (len == 5){ // piramids
1567 double L1 = getDistance(P( 1 ),P( 2 ));
1568 double L2 = getDistance(P( 2 ),P( 3 ));
1569 double L3 = getDistance(P( 3 ),P( 4 ));
1570 double L4 = getDistance(P( 4 ),P( 1 ));
1571 double L5 = getDistance(P( 1 ),P( 5 ));
1572 double L6 = getDistance(P( 2 ),P( 5 ));
1573 double L7 = getDistance(P( 3 ),P( 5 ));
1574 double L8 = getDistance(P( 4 ),P( 5 ));
1576 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1577 aVal = Max(aVal,Max(L7,L8));
1580 else if (len == 6){ // pentaidres
1581 double L1 = getDistance(P( 1 ),P( 2 ));
1582 double L2 = getDistance(P( 2 ),P( 3 ));
1583 double L3 = getDistance(P( 3 ),P( 1 ));
1584 double L4 = getDistance(P( 4 ),P( 5 ));
1585 double L5 = getDistance(P( 5 ),P( 6 ));
1586 double L6 = getDistance(P( 6 ),P( 4 ));
1587 double L7 = getDistance(P( 1 ),P( 4 ));
1588 double L8 = getDistance(P( 2 ),P( 5 ));
1589 double L9 = getDistance(P( 3 ),P( 6 ));
1591 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1592 aVal = Max(aVal,Max(Max(L7,L8),L9));
1595 else if (len == 8){ // hexaider
1596 double L1 = getDistance(P( 1 ),P( 2 ));
1597 double L2 = getDistance(P( 2 ),P( 3 ));
1598 double L3 = getDistance(P( 3 ),P( 4 ));
1599 double L4 = getDistance(P( 4 ),P( 1 ));
1600 double L5 = getDistance(P( 5 ),P( 6 ));
1601 double L6 = getDistance(P( 6 ),P( 7 ));
1602 double L7 = getDistance(P( 7 ),P( 8 ));
1603 double L8 = getDistance(P( 8 ),P( 5 ));
1604 double L9 = getDistance(P( 1 ),P( 5 ));
1605 double L10= getDistance(P( 2 ),P( 6 ));
1606 double L11= getDistance(P( 3 ),P( 7 ));
1607 double L12= getDistance(P( 4 ),P( 8 ));
1609 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1610 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
1611 aVal = Max(aVal,Max(L11,L12));
1616 if (len == 10){ // quadratic tetraidrs
1617 double L1 = getDistance(P( 1 ),P( 5 )) + getDistance(P( 5 ),P( 2 ));
1618 double L2 = getDistance(P( 2 ),P( 6 )) + getDistance(P( 6 ),P( 3 ));
1619 double L3 = getDistance(P( 3 ),P( 7 )) + getDistance(P( 7 ),P( 1 ));
1620 double L4 = getDistance(P( 1 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
1621 double L5 = getDistance(P( 2 ),P( 9 )) + getDistance(P( 9 ),P( 4 ));
1622 double L6 = getDistance(P( 3 ),P( 10 )) + getDistance(P( 10 ),P( 4 ));
1623 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1626 else if (len == 13){ // quadratic piramids
1627 double L1 = getDistance(P( 1 ),P( 6 )) + getDistance(P( 6 ),P( 2 ));
1628 double L2 = getDistance(P( 2 ),P( 7 )) + getDistance(P( 7 ),P( 3 ));
1629 double L3 = getDistance(P( 3 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
1630 double L4 = getDistance(P( 4 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1631 double L5 = getDistance(P( 1 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1632 double L6 = getDistance(P( 2 ),P( 11 )) + getDistance(P( 11 ),P( 5 ));
1633 double L7 = getDistance(P( 3 ),P( 12 )) + getDistance(P( 12 ),P( 5 ));
1634 double L8 = getDistance(P( 4 ),P( 13 )) + getDistance(P( 13 ),P( 5 ));
1635 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1636 aVal = Max(aVal,Max(L7,L8));
1639 else if (len == 15){ // quadratic pentaidres
1640 double L1 = getDistance(P( 1 ),P( 7 )) + getDistance(P( 7 ),P( 2 ));
1641 double L2 = getDistance(P( 2 ),P( 8 )) + getDistance(P( 8 ),P( 3 ));
1642 double L3 = getDistance(P( 3 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1643 double L4 = getDistance(P( 4 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1644 double L5 = getDistance(P( 5 ),P( 11 )) + getDistance(P( 11 ),P( 6 ));
1645 double L6 = getDistance(P( 6 ),P( 12 )) + getDistance(P( 12 ),P( 4 ));
1646 double L7 = getDistance(P( 1 ),P( 13 )) + getDistance(P( 13 ),P( 4 ));
1647 double L8 = getDistance(P( 2 ),P( 14 )) + getDistance(P( 14 ),P( 5 ));
1648 double L9 = getDistance(P( 3 ),P( 15 )) + getDistance(P( 15 ),P( 6 ));
1649 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1650 aVal = Max(aVal,Max(Max(L7,L8),L9));
1653 else if (len == 20){ // quadratic hexaider
1654 double L1 = getDistance(P( 1 ),P( 9 )) + getDistance(P( 9 ),P( 2 ));
1655 double L2 = getDistance(P( 2 ),P( 10 )) + getDistance(P( 10 ),P( 3 ));
1656 double L3 = getDistance(P( 3 ),P( 11 )) + getDistance(P( 11 ),P( 4 ));
1657 double L4 = getDistance(P( 4 ),P( 12 )) + getDistance(P( 12 ),P( 1 ));
1658 double L5 = getDistance(P( 5 ),P( 13 )) + getDistance(P( 13 ),P( 6 ));
1659 double L6 = getDistance(P( 6 ),P( 14 )) + getDistance(P( 14 ),P( 7 ));
1660 double L7 = getDistance(P( 7 ),P( 15 )) + getDistance(P( 15 ),P( 8 ));
1661 double L8 = getDistance(P( 8 ),P( 16 )) + getDistance(P( 16 ),P( 5 ));
1662 double L9 = getDistance(P( 1 ),P( 17 )) + getDistance(P( 17 ),P( 5 ));
1663 double L10= getDistance(P( 2 ),P( 18 )) + getDistance(P( 18 ),P( 6 ));
1664 double L11= getDistance(P( 3 ),P( 19 )) + getDistance(P( 19 ),P( 7 ));
1665 double L12= getDistance(P( 4 ),P( 20 )) + getDistance(P( 20 ),P( 8 ));
1666 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1667 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
1668 aVal = Max(aVal,Max(L11,L12));
1680 if ( myPrecision >= 0 )
1682 double prec = pow( 10., (double)( myPrecision ) );
1683 aVal = floor( aVal * prec + 0.5 ) / prec;
1692 double Length2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1694 // meaningless as it is not quality control functor
1698 SMDSAbs_ElementType Length2D::GetType() const
1700 return SMDSAbs_Face;
1703 Length2D::Value::Value(double theLength,long thePntId1, long thePntId2):
1706 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1707 if(thePntId1 > thePntId2){
1708 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1712 bool Length2D::Value::operator<(const Length2D::Value& x) const{
1713 if(myPntId[0] < x.myPntId[0]) return true;
1714 if(myPntId[0] == x.myPntId[0])
1715 if(myPntId[1] < x.myPntId[1]) return true;
1719 void Length2D::GetValues(TValues& theValues){
1721 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1722 for(; anIter->more(); ){
1723 const SMDS_MeshFace* anElem = anIter->next();
1725 if(anElem->IsQuadratic()) {
1726 const SMDS_VtkFace* F =
1727 dynamic_cast<const SMDS_VtkFace*>(anElem);
1728 // use special nodes iterator
1729 SMDS_ElemIteratorPtr anIter = F->interlacedNodesElemIterator();
1734 const SMDS_MeshElement* aNode;
1736 aNode = anIter->next();
1737 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1738 P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1739 aNodeId[0] = aNodeId[1] = aNode->GetID();
1742 for(; anIter->more(); ){
1743 const SMDS_MeshNode* N1 = static_cast<const SMDS_MeshNode*> (anIter->next());
1744 P[2] = gp_Pnt(N1->X(),N1->Y(),N1->Z());
1745 aNodeId[2] = N1->GetID();
1746 aLength = P[1].Distance(P[2]);
1747 if(!anIter->more()) break;
1748 const SMDS_MeshNode* N2 = static_cast<const SMDS_MeshNode*> (anIter->next());
1749 P[3] = gp_Pnt(N2->X(),N2->Y(),N2->Z());
1750 aNodeId[3] = N2->GetID();
1751 aLength += P[2].Distance(P[3]);
1752 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1753 Value aValue2(aLength,aNodeId[2],aNodeId[3]);
1755 aNodeId[1] = aNodeId[3];
1756 theValues.insert(aValue1);
1757 theValues.insert(aValue2);
1759 aLength += P[2].Distance(P[0]);
1760 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1761 Value aValue2(aLength,aNodeId[2],aNodeId[0]);
1762 theValues.insert(aValue1);
1763 theValues.insert(aValue2);
1766 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
1771 const SMDS_MeshElement* aNode;
1772 if(aNodesIter->more()){
1773 aNode = aNodesIter->next();
1774 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1775 P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1776 aNodeId[0] = aNodeId[1] = aNode->GetID();
1779 for(; aNodesIter->more(); ){
1780 aNode = aNodesIter->next();
1781 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1782 long anId = aNode->GetID();
1784 P[2] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1786 aLength = P[1].Distance(P[2]);
1788 Value aValue(aLength,aNodeId[1],anId);
1791 theValues.insert(aValue);
1794 aLength = P[0].Distance(P[1]);
1796 Value aValue(aLength,aNodeId[0],aNodeId[1]);
1797 theValues.insert(aValue);
1803 Class : MultiConnection
1804 Description : Functor for calculating number of faces conneted to the edge
1806 double MultiConnection::GetValue( const TSequenceOfXYZ& P )
1810 double MultiConnection::GetValue( long theId )
1812 return getNbMultiConnection( myMesh, theId );
1815 double MultiConnection::GetBadRate( double Value, int /*nbNodes*/ ) const
1817 // meaningless as it is not quality control functor
1821 SMDSAbs_ElementType MultiConnection::GetType() const
1823 return SMDSAbs_Edge;
1827 Class : MultiConnection2D
1828 Description : Functor for calculating number of faces conneted to the edge
1830 double MultiConnection2D::GetValue( const TSequenceOfXYZ& P )
1835 double MultiConnection2D::GetValue( long theElementId )
1839 const SMDS_MeshElement* aFaceElem = myMesh->FindElement(theElementId);
1840 SMDSAbs_ElementType aType = aFaceElem->GetType();
1845 int i = 0, len = aFaceElem->NbNodes();
1846 SMDS_ElemIteratorPtr anIter = aFaceElem->nodesIterator();
1849 const SMDS_MeshNode *aNode, *aNode0;
1850 TColStd_MapOfInteger aMap, aMapPrev;
1852 for (i = 0; i <= len; i++) {
1857 if (anIter->more()) {
1858 aNode = (SMDS_MeshNode*)anIter->next();
1866 if (i == 0) aNode0 = aNode;
1868 SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator();
1869 while (anElemIter->more()) {
1870 const SMDS_MeshElement* anElem = anElemIter->next();
1871 if (anElem != 0 && anElem->GetType() == SMDSAbs_Face) {
1872 int anId = anElem->GetID();
1875 if (aMapPrev.Contains(anId)) {
1880 aResult = Max(aResult, aNb);
1891 double MultiConnection2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1893 // meaningless as it is not quality control functor
1897 SMDSAbs_ElementType MultiConnection2D::GetType() const
1899 return SMDSAbs_Face;
1902 MultiConnection2D::Value::Value(long thePntId1, long thePntId2)
1904 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1905 if(thePntId1 > thePntId2){
1906 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1910 bool MultiConnection2D::Value::operator<(const MultiConnection2D::Value& x) const{
1911 if(myPntId[0] < x.myPntId[0]) return true;
1912 if(myPntId[0] == x.myPntId[0])
1913 if(myPntId[1] < x.myPntId[1]) return true;
1917 void MultiConnection2D::GetValues(MValues& theValues){
1918 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1919 for(; anIter->more(); ){
1920 const SMDS_MeshFace* anElem = anIter->next();
1921 SMDS_ElemIteratorPtr aNodesIter;
1922 if ( anElem->IsQuadratic() )
1923 aNodesIter = dynamic_cast<const SMDS_VtkFace*>
1924 (anElem)->interlacedNodesElemIterator();
1926 aNodesIter = anElem->nodesIterator();
1929 //int aNbConnects=0;
1930 const SMDS_MeshNode* aNode0;
1931 const SMDS_MeshNode* aNode1;
1932 const SMDS_MeshNode* aNode2;
1933 if(aNodesIter->more()){
1934 aNode0 = (SMDS_MeshNode*) aNodesIter->next();
1936 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode1;
1937 aNodeId[0] = aNodeId[1] = aNodes->GetID();
1939 for(; aNodesIter->more(); ) {
1940 aNode2 = (SMDS_MeshNode*) aNodesIter->next();
1941 long anId = aNode2->GetID();
1944 Value aValue(aNodeId[1],aNodeId[2]);
1945 MValues::iterator aItr = theValues.find(aValue);
1946 if (aItr != theValues.end()){
1951 theValues[aValue] = 1;
1954 //cout << "NodeIds: "<<aNodeId[1]<<","<<aNodeId[2]<<" nbconn="<<aNbConnects<<endl;
1955 aNodeId[1] = aNodeId[2];
1958 Value aValue(aNodeId[0],aNodeId[2]);
1959 MValues::iterator aItr = theValues.find(aValue);
1960 if (aItr != theValues.end()) {
1965 theValues[aValue] = 1;
1968 //cout << "NodeIds: "<<aNodeId[0]<<","<<aNodeId[2]<<" nbconn="<<aNbConnects<<endl;
1974 Class : BallDiameter
1975 Description : Functor returning diameter of a ball element
1977 double BallDiameter::GetValue( long theId )
1979 double diameter = 0;
1981 if ( const SMDS_BallElement* ball =
1982 dynamic_cast<const SMDS_BallElement*>( myMesh->FindElement( theId )))
1984 diameter = ball->GetDiameter();
1989 double BallDiameter::GetBadRate( double Value, int /*nbNodes*/ ) const
1991 // meaningless as it is not a quality control functor
1995 SMDSAbs_ElementType BallDiameter::GetType() const
1997 return SMDSAbs_Ball;
2006 Class : BadOrientedVolume
2007 Description : Predicate bad oriented volumes
2010 BadOrientedVolume::BadOrientedVolume()
2015 void BadOrientedVolume::SetMesh( const SMDS_Mesh* theMesh )
2020 bool BadOrientedVolume::IsSatisfy( long theId )
2025 SMDS_VolumeTool vTool( myMesh->FindElement( theId ));
2026 return !vTool.IsForward();
2029 SMDSAbs_ElementType BadOrientedVolume::GetType() const
2031 return SMDSAbs_Volume;
2035 Class : BareBorderVolume
2038 bool BareBorderVolume::IsSatisfy(long theElementId )
2040 SMDS_VolumeTool myTool;
2041 if ( myTool.Set( myMesh->FindElement(theElementId)))
2043 for ( int iF = 0; iF < myTool.NbFaces(); ++iF )
2044 if ( myTool.IsFreeFace( iF ))
2046 const SMDS_MeshNode** n = myTool.GetFaceNodes(iF);
2047 vector< const SMDS_MeshNode*> nodes( n, n+myTool.NbFaceNodes(iF));
2048 if ( !myMesh->FindElement( nodes, SMDSAbs_Face, /*Nomedium=*/false))
2056 Class : BareBorderFace
2059 bool BareBorderFace::IsSatisfy(long theElementId )
2062 if ( const SMDS_MeshElement* face = myMesh->FindElement(theElementId))
2064 if ( face->GetType() == SMDSAbs_Face )
2066 int nbN = face->NbCornerNodes();
2067 for ( int i = 0; i < nbN && !ok; ++i )
2069 // check if a link is shared by another face
2070 const SMDS_MeshNode* n1 = face->GetNode( i );
2071 const SMDS_MeshNode* n2 = face->GetNode( (i+1)%nbN );
2072 SMDS_ElemIteratorPtr fIt = n1->GetInverseElementIterator( SMDSAbs_Face );
2073 bool isShared = false;
2074 while ( !isShared && fIt->more() )
2076 const SMDS_MeshElement* f = fIt->next();
2077 isShared = ( f != face && f->GetNodeIndex(n2) != -1 );
2081 const int iQuad = face->IsQuadratic();
2082 myLinkNodes.resize( 2 + iQuad);
2083 myLinkNodes[0] = n1;
2084 myLinkNodes[1] = n2;
2086 myLinkNodes[2] = face->GetNode( i+nbN );
2087 ok = !myMesh->FindElement( myLinkNodes, SMDSAbs_Edge, /*noMedium=*/false);
2096 Class : OverConstrainedVolume
2099 bool OverConstrainedVolume::IsSatisfy(long theElementId )
2101 // An element is over-constrained if it has N-1 free borders where
2102 // N is the number of edges/faces for a 2D/3D element.
2103 SMDS_VolumeTool myTool;
2104 if ( myTool.Set( myMesh->FindElement(theElementId)))
2106 int nbSharedFaces = 0;
2107 for ( int iF = 0; iF < myTool.NbFaces(); ++iF )
2108 if ( !myTool.IsFreeFace( iF ) && ++nbSharedFaces > 1 )
2110 return ( nbSharedFaces == 1 );
2116 Class : OverConstrainedFace
2119 bool OverConstrainedFace::IsSatisfy(long theElementId )
2121 // An element is over-constrained if it has N-1 free borders where
2122 // N is the number of edges/faces for a 2D/3D element.
2123 if ( const SMDS_MeshElement* face = myMesh->FindElement(theElementId))
2124 if ( face->GetType() == SMDSAbs_Face )
2126 int nbSharedBorders = 0;
2127 int nbN = face->NbCornerNodes();
2128 for ( int i = 0; i < nbN; ++i )
2130 // check if a link is shared by another face
2131 const SMDS_MeshNode* n1 = face->GetNode( i );
2132 const SMDS_MeshNode* n2 = face->GetNode( (i+1)%nbN );
2133 SMDS_ElemIteratorPtr fIt = n1->GetInverseElementIterator( SMDSAbs_Face );
2134 bool isShared = false;
2135 while ( !isShared && fIt->more() )
2137 const SMDS_MeshElement* f = fIt->next();
2138 isShared = ( f != face && f->GetNodeIndex(n2) != -1 );
2140 if ( isShared && ++nbSharedBorders > 1 )
2143 return ( nbSharedBorders == 1 );
2149 Class : CoincidentNodes
2150 Description : Predicate of Coincident nodes
2153 CoincidentNodes::CoincidentNodes()
2158 bool CoincidentNodes::IsSatisfy( long theElementId )
2160 return myCoincidentIDs.Contains( theElementId );
2163 SMDSAbs_ElementType CoincidentNodes::GetType() const
2165 return SMDSAbs_Node;
2168 void CoincidentNodes::SetMesh( const SMDS_Mesh* theMesh )
2170 myMeshModifTracer.SetMesh( theMesh );
2171 if ( myMeshModifTracer.IsMeshModified() )
2173 TIDSortedNodeSet nodesToCheck;
2174 SMDS_NodeIteratorPtr nIt = theMesh->nodesIterator(/*idInceasingOrder=*/true);
2175 while ( nIt->more() )
2176 nodesToCheck.insert( nodesToCheck.end(), nIt->next() );
2178 list< list< const SMDS_MeshNode*> > nodeGroups;
2179 SMESH_OctreeNode::FindCoincidentNodes ( nodesToCheck, &nodeGroups, myToler );
2181 myCoincidentIDs.Clear();
2182 list< list< const SMDS_MeshNode*> >::iterator groupIt = nodeGroups.begin();
2183 for ( ; groupIt != nodeGroups.end(); ++groupIt )
2185 list< const SMDS_MeshNode*>& coincNodes = *groupIt;
2186 list< const SMDS_MeshNode*>::iterator n = coincNodes.begin();
2187 for ( ; n != coincNodes.end(); ++n )
2188 myCoincidentIDs.Add( (*n)->GetID() );
2194 Class : CoincidentElements
2195 Description : Predicate of Coincident Elements
2196 Note : This class is suitable only for visualization of Coincident Elements
2199 CoincidentElements::CoincidentElements()
2204 void CoincidentElements::SetMesh( const SMDS_Mesh* theMesh )
2209 bool CoincidentElements::IsSatisfy( long theElementId )
2211 if ( !myMesh ) return false;
2213 if ( const SMDS_MeshElement* e = myMesh->FindElement( theElementId ))
2215 if ( e->GetType() != GetType() ) return false;
2216 set< const SMDS_MeshNode* > elemNodes( e->begin_nodes(), e->end_nodes() );
2217 const int nbNodes = e->NbNodes();
2218 SMDS_ElemIteratorPtr invIt = (*elemNodes.begin())->GetInverseElementIterator( GetType() );
2219 while ( invIt->more() )
2221 const SMDS_MeshElement* e2 = invIt->next();
2222 if ( e2 == e || e2->NbNodes() != nbNodes ) continue;
2224 bool sameNodes = true;
2225 for ( size_t i = 0; i < elemNodes.size() && sameNodes; ++i )
2226 sameNodes = ( elemNodes.count( e2->GetNode( i )));
2234 SMDSAbs_ElementType CoincidentElements1D::GetType() const
2236 return SMDSAbs_Edge;
2238 SMDSAbs_ElementType CoincidentElements2D::GetType() const
2240 return SMDSAbs_Face;
2242 SMDSAbs_ElementType CoincidentElements3D::GetType() const
2244 return SMDSAbs_Volume;
2250 Description : Predicate for free borders
2253 FreeBorders::FreeBorders()
2258 void FreeBorders::SetMesh( const SMDS_Mesh* theMesh )
2263 bool FreeBorders::IsSatisfy( long theId )
2265 return getNbMultiConnection( myMesh, theId ) == 1;
2268 SMDSAbs_ElementType FreeBorders::GetType() const
2270 return SMDSAbs_Edge;
2276 Description : Predicate for free Edges
2278 FreeEdges::FreeEdges()
2283 void FreeEdges::SetMesh( const SMDS_Mesh* theMesh )
2288 bool FreeEdges::IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId )
2290 TColStd_MapOfInteger aMap;
2291 for ( int i = 0; i < 2; i++ )
2293 SMDS_ElemIteratorPtr anElemIter = theNodes[ i ]->GetInverseElementIterator(SMDSAbs_Face);
2294 while( anElemIter->more() )
2296 if ( const SMDS_MeshElement* anElem = anElemIter->next())
2298 const int anId = anElem->GetID();
2299 if ( anId != theFaceId && !aMap.Add( anId ))
2307 bool FreeEdges::IsSatisfy( long theId )
2312 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
2313 if ( aFace == 0 || aFace->GetType() != SMDSAbs_Face || aFace->NbNodes() < 3 )
2316 SMDS_ElemIteratorPtr anIter;
2317 if ( aFace->IsQuadratic() ) {
2318 anIter = dynamic_cast<const SMDS_VtkFace*>
2319 (aFace)->interlacedNodesElemIterator();
2322 anIter = aFace->nodesIterator();
2327 int i = 0, nbNodes = aFace->NbNodes();
2328 std::vector <const SMDS_MeshNode*> aNodes( nbNodes+1 );
2329 while( anIter->more() )
2331 const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next();
2334 aNodes[ i++ ] = aNode;
2336 aNodes[ nbNodes ] = aNodes[ 0 ];
2338 for ( i = 0; i < nbNodes; i++ )
2339 if ( IsFreeEdge( &aNodes[ i ], theId ) )
2345 SMDSAbs_ElementType FreeEdges::GetType() const
2347 return SMDSAbs_Face;
2350 FreeEdges::Border::Border(long theElemId, long thePntId1, long thePntId2):
2353 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
2354 if(thePntId1 > thePntId2){
2355 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
2359 bool FreeEdges::Border::operator<(const FreeEdges::Border& x) const{
2360 if(myPntId[0] < x.myPntId[0]) return true;
2361 if(myPntId[0] == x.myPntId[0])
2362 if(myPntId[1] < x.myPntId[1]) return true;
2366 inline void UpdateBorders(const FreeEdges::Border& theBorder,
2367 FreeEdges::TBorders& theRegistry,
2368 FreeEdges::TBorders& theContainer)
2370 if(theRegistry.find(theBorder) == theRegistry.end()){
2371 theRegistry.insert(theBorder);
2372 theContainer.insert(theBorder);
2374 theContainer.erase(theBorder);
2378 void FreeEdges::GetBoreders(TBorders& theBorders)
2381 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
2382 for(; anIter->more(); ){
2383 const SMDS_MeshFace* anElem = anIter->next();
2384 long anElemId = anElem->GetID();
2385 SMDS_ElemIteratorPtr aNodesIter;
2386 if ( anElem->IsQuadratic() )
2387 aNodesIter = static_cast<const SMDS_VtkFace*>(anElem)->
2388 interlacedNodesElemIterator();
2390 aNodesIter = anElem->nodesIterator();
2392 const SMDS_MeshElement* aNode;
2393 if(aNodesIter->more()){
2394 aNode = aNodesIter->next();
2395 aNodeId[0] = aNodeId[1] = aNode->GetID();
2397 for(; aNodesIter->more(); ){
2398 aNode = aNodesIter->next();
2399 long anId = aNode->GetID();
2400 Border aBorder(anElemId,aNodeId[1],anId);
2402 UpdateBorders(aBorder,aRegistry,theBorders);
2404 Border aBorder(anElemId,aNodeId[0],aNodeId[1]);
2405 UpdateBorders(aBorder,aRegistry,theBorders);
2412 Description : Predicate for free nodes
2415 FreeNodes::FreeNodes()
2420 void FreeNodes::SetMesh( const SMDS_Mesh* theMesh )
2425 bool FreeNodes::IsSatisfy( long theNodeId )
2427 const SMDS_MeshNode* aNode = myMesh->FindNode( theNodeId );
2431 return (aNode->NbInverseElements() < 1);
2434 SMDSAbs_ElementType FreeNodes::GetType() const
2436 return SMDSAbs_Node;
2442 Description : Predicate for free faces
2445 FreeFaces::FreeFaces()
2450 void FreeFaces::SetMesh( const SMDS_Mesh* theMesh )
2455 bool FreeFaces::IsSatisfy( long theId )
2457 if (!myMesh) return false;
2458 // check that faces nodes refers to less than two common volumes
2459 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
2460 if ( !aFace || aFace->GetType() != SMDSAbs_Face )
2463 int nbNode = aFace->NbNodes();
2465 // collect volumes check that number of volumss with count equal nbNode not less than 2
2466 typedef map< SMDS_MeshElement*, int > TMapOfVolume; // map of volume counters
2467 typedef map< SMDS_MeshElement*, int >::iterator TItrMapOfVolume; // iterator
2468 TMapOfVolume mapOfVol;
2470 SMDS_ElemIteratorPtr nodeItr = aFace->nodesIterator();
2471 while ( nodeItr->more() ) {
2472 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(nodeItr->next());
2473 if ( !aNode ) continue;
2474 SMDS_ElemIteratorPtr volItr = aNode->GetInverseElementIterator(SMDSAbs_Volume);
2475 while ( volItr->more() ) {
2476 SMDS_MeshElement* aVol = (SMDS_MeshElement*)volItr->next();
2477 TItrMapOfVolume itr = mapOfVol.insert(make_pair(aVol, 0)).first;
2482 TItrMapOfVolume volItr = mapOfVol.begin();
2483 TItrMapOfVolume volEnd = mapOfVol.end();
2484 for ( ; volItr != volEnd; ++volItr )
2485 if ( (*volItr).second >= nbNode )
2487 // face is not free if number of volumes constructed on thier nodes more than one
2491 SMDSAbs_ElementType FreeFaces::GetType() const
2493 return SMDSAbs_Face;
2497 Class : LinearOrQuadratic
2498 Description : Predicate to verify whether a mesh element is linear
2501 LinearOrQuadratic::LinearOrQuadratic()
2506 void LinearOrQuadratic::SetMesh( const SMDS_Mesh* theMesh )
2511 bool LinearOrQuadratic::IsSatisfy( long theId )
2513 if (!myMesh) return false;
2514 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2515 if ( !anElem || (myType != SMDSAbs_All && anElem->GetType() != myType) )
2517 return (!anElem->IsQuadratic());
2520 void LinearOrQuadratic::SetType( SMDSAbs_ElementType theType )
2525 SMDSAbs_ElementType LinearOrQuadratic::GetType() const
2532 Description : Functor for check color of group to whic mesh element belongs to
2535 GroupColor::GroupColor()
2539 bool GroupColor::IsSatisfy( long theId )
2541 return (myIDs.find( theId ) != myIDs.end());
2544 void GroupColor::SetType( SMDSAbs_ElementType theType )
2549 SMDSAbs_ElementType GroupColor::GetType() const
2554 static bool isEqual( const Quantity_Color& theColor1,
2555 const Quantity_Color& theColor2 )
2557 // tolerance to compare colors
2558 const double tol = 5*1e-3;
2559 return ( fabs( theColor1.Red() - theColor2.Red() ) < tol &&
2560 fabs( theColor1.Green() - theColor2.Green() ) < tol &&
2561 fabs( theColor1.Blue() - theColor2.Blue() ) < tol );
2565 void GroupColor::SetMesh( const SMDS_Mesh* theMesh )
2569 const SMESHDS_Mesh* aMesh = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
2573 int nbGrp = aMesh->GetNbGroups();
2577 // iterates on groups and find necessary elements ids
2578 const std::set<SMESHDS_GroupBase*>& aGroups = aMesh->GetGroups();
2579 set<SMESHDS_GroupBase*>::const_iterator GrIt = aGroups.begin();
2580 for (; GrIt != aGroups.end(); GrIt++) {
2581 SMESHDS_GroupBase* aGrp = (*GrIt);
2584 // check type and color of group
2585 if ( !isEqual( myColor, aGrp->GetColor() ) )
2587 if ( myType != SMDSAbs_All && myType != (SMDSAbs_ElementType)aGrp->GetType() )
2590 SMDSAbs_ElementType aGrpElType = (SMDSAbs_ElementType)aGrp->GetType();
2591 if ( myType == aGrpElType || (myType == SMDSAbs_All && aGrpElType != SMDSAbs_Node) ) {
2592 // add elements IDS into control
2593 int aSize = aGrp->Extent();
2594 for (int i = 0; i < aSize; i++)
2595 myIDs.insert( aGrp->GetID(i+1) );
2600 void GroupColor::SetColorStr( const TCollection_AsciiString& theStr )
2602 TCollection_AsciiString aStr = theStr;
2603 aStr.RemoveAll( ' ' );
2604 aStr.RemoveAll( '\t' );
2605 for ( int aPos = aStr.Search( ";;" ); aPos != -1; aPos = aStr.Search( ";;" ) )
2606 aStr.Remove( aPos, 2 );
2607 Standard_Real clr[3];
2608 clr[0] = clr[1] = clr[2] = 0.;
2609 for ( int i = 0; i < 3; i++ ) {
2610 TCollection_AsciiString tmpStr = aStr.Token( ";", i+1 );
2611 if ( !tmpStr.IsEmpty() && tmpStr.IsRealValue() )
2612 clr[i] = tmpStr.RealValue();
2614 myColor = Quantity_Color( clr[0], clr[1], clr[2], Quantity_TOC_RGB );
2617 //=======================================================================
2618 // name : GetRangeStr
2619 // Purpose : Get range as a string.
2620 // Example: "1,2,3,50-60,63,67,70-"
2621 //=======================================================================
2622 void GroupColor::GetColorStr( TCollection_AsciiString& theResStr ) const
2625 theResStr += TCollection_AsciiString( myColor.Red() );
2626 theResStr += TCollection_AsciiString( ";" ) + TCollection_AsciiString( myColor.Green() );
2627 theResStr += TCollection_AsciiString( ";" ) + TCollection_AsciiString( myColor.Blue() );
2631 Class : ElemGeomType
2632 Description : Predicate to check element geometry type
2635 ElemGeomType::ElemGeomType()
2638 myType = SMDSAbs_All;
2639 myGeomType = SMDSGeom_TRIANGLE;
2642 void ElemGeomType::SetMesh( const SMDS_Mesh* theMesh )
2647 bool ElemGeomType::IsSatisfy( long theId )
2649 if (!myMesh) return false;
2650 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2653 const SMDSAbs_ElementType anElemType = anElem->GetType();
2654 if ( myType != SMDSAbs_All && anElemType != myType )
2656 bool isOk = ( anElem->GetGeomType() == myGeomType );
2660 void ElemGeomType::SetType( SMDSAbs_ElementType theType )
2665 SMDSAbs_ElementType ElemGeomType::GetType() const
2670 void ElemGeomType::SetGeomType( SMDSAbs_GeometryType theType )
2672 myGeomType = theType;
2675 SMDSAbs_GeometryType ElemGeomType::GetGeomType() const
2680 //================================================================================
2682 * \brief Class CoplanarFaces
2684 //================================================================================
2686 CoplanarFaces::CoplanarFaces()
2687 : myFaceID(0), myToler(0)
2690 void CoplanarFaces::SetMesh( const SMDS_Mesh* theMesh )
2692 myMeshModifTracer.SetMesh( theMesh );
2693 if ( myMeshModifTracer.IsMeshModified() )
2695 // Build a set of coplanar face ids
2697 myCoplanarIDs.clear();
2699 if ( !myMeshModifTracer.GetMesh() || !myFaceID || !myToler )
2702 const SMDS_MeshElement* face = myMeshModifTracer.GetMesh()->FindElement( myFaceID );
2703 if ( !face || face->GetType() != SMDSAbs_Face )
2707 gp_Vec myNorm = getNormale( static_cast<const SMDS_MeshFace*>(face), &normOK );
2711 const double radianTol = myToler * M_PI / 180.;
2712 std::set< SMESH_TLink > checkedLinks;
2714 std::list< pair< const SMDS_MeshElement*, gp_Vec > > faceQueue;
2715 faceQueue.push_back( make_pair( face, myNorm ));
2716 while ( !faceQueue.empty() )
2718 face = faceQueue.front().first;
2719 myNorm = faceQueue.front().second;
2720 faceQueue.pop_front();
2722 for ( int i = 0, nbN = face->NbCornerNodes(); i < nbN; ++i )
2724 const SMDS_MeshNode* n1 = face->GetNode( i );
2725 const SMDS_MeshNode* n2 = face->GetNode(( i+1 )%nbN);
2726 if ( !checkedLinks.insert( SMESH_TLink( n1, n2 )).second )
2728 SMDS_ElemIteratorPtr fIt = n1->GetInverseElementIterator(SMDSAbs_Face);
2729 while ( fIt->more() )
2731 const SMDS_MeshElement* f = fIt->next();
2732 if ( f->GetNodeIndex( n2 ) > -1 )
2734 gp_Vec norm = getNormale( static_cast<const SMDS_MeshFace*>(f), &normOK );
2735 if (!normOK || myNorm.Angle( norm ) <= radianTol)
2737 myCoplanarIDs.insert( f->GetID() );
2738 faceQueue.push_back( make_pair( f, norm ));
2746 bool CoplanarFaces::IsSatisfy( long theElementId )
2748 return myCoplanarIDs.count( theElementId );
2753 *Description : Predicate for Range of Ids.
2754 * Range may be specified with two ways.
2755 * 1. Using AddToRange method
2756 * 2. With SetRangeStr method. Parameter of this method is a string
2757 * like as "1,2,3,50-60,63,67,70-"
2760 //=======================================================================
2761 // name : RangeOfIds
2762 // Purpose : Constructor
2763 //=======================================================================
2764 RangeOfIds::RangeOfIds()
2767 myType = SMDSAbs_All;
2770 //=======================================================================
2772 // Purpose : Set mesh
2773 //=======================================================================
2774 void RangeOfIds::SetMesh( const SMDS_Mesh* theMesh )
2779 //=======================================================================
2780 // name : AddToRange
2781 // Purpose : Add ID to the range
2782 //=======================================================================
2783 bool RangeOfIds::AddToRange( long theEntityId )
2785 myIds.Add( theEntityId );
2789 //=======================================================================
2790 // name : GetRangeStr
2791 // Purpose : Get range as a string.
2792 // Example: "1,2,3,50-60,63,67,70-"
2793 //=======================================================================
2794 void RangeOfIds::GetRangeStr( TCollection_AsciiString& theResStr )
2798 TColStd_SequenceOfInteger anIntSeq;
2799 TColStd_SequenceOfAsciiString aStrSeq;
2801 TColStd_MapIteratorOfMapOfInteger anIter( myIds );
2802 for ( ; anIter.More(); anIter.Next() )
2804 int anId = anIter.Key();
2805 TCollection_AsciiString aStr( anId );
2806 anIntSeq.Append( anId );
2807 aStrSeq.Append( aStr );
2810 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
2812 int aMinId = myMin( i );
2813 int aMaxId = myMax( i );
2815 TCollection_AsciiString aStr;
2816 if ( aMinId != IntegerFirst() )
2821 if ( aMaxId != IntegerLast() )
2824 // find position of the string in result sequence and insert string in it
2825 if ( anIntSeq.Length() == 0 )
2827 anIntSeq.Append( aMinId );
2828 aStrSeq.Append( aStr );
2832 if ( aMinId < anIntSeq.First() )
2834 anIntSeq.Prepend( aMinId );
2835 aStrSeq.Prepend( aStr );
2837 else if ( aMinId > anIntSeq.Last() )
2839 anIntSeq.Append( aMinId );
2840 aStrSeq.Append( aStr );
2843 for ( int j = 1, k = anIntSeq.Length(); j <= k; j++ )
2844 if ( aMinId < anIntSeq( j ) )
2846 anIntSeq.InsertBefore( j, aMinId );
2847 aStrSeq.InsertBefore( j, aStr );
2853 if ( aStrSeq.Length() == 0 )
2856 theResStr = aStrSeq( 1 );
2857 for ( int j = 2, k = aStrSeq.Length(); j <= k; j++ )
2860 theResStr += aStrSeq( j );
2864 //=======================================================================
2865 // name : SetRangeStr
2866 // Purpose : Define range with string
2867 // Example of entry string: "1,2,3,50-60,63,67,70-"
2868 //=======================================================================
2869 bool RangeOfIds::SetRangeStr( const TCollection_AsciiString& theStr )
2875 TCollection_AsciiString aStr = theStr;
2876 aStr.RemoveAll( ' ' );
2877 aStr.RemoveAll( '\t' );
2879 for ( int aPos = aStr.Search( ",," ); aPos != -1; aPos = aStr.Search( ",," ) )
2880 aStr.Remove( aPos, 2 );
2882 TCollection_AsciiString tmpStr = aStr.Token( ",", 1 );
2884 while ( tmpStr != "" )
2886 tmpStr = aStr.Token( ",", i++ );
2887 int aPos = tmpStr.Search( '-' );
2891 if ( tmpStr.IsIntegerValue() )
2892 myIds.Add( tmpStr.IntegerValue() );
2898 TCollection_AsciiString aMaxStr = tmpStr.Split( aPos );
2899 TCollection_AsciiString aMinStr = tmpStr;
2901 while ( aMinStr.Search( "-" ) != -1 ) aMinStr.RemoveAll( '-' );
2902 while ( aMaxStr.Search( "-" ) != -1 ) aMaxStr.RemoveAll( '-' );
2904 if ( (!aMinStr.IsEmpty() && !aMinStr.IsIntegerValue()) ||
2905 (!aMaxStr.IsEmpty() && !aMaxStr.IsIntegerValue()) )
2908 myMin.Append( aMinStr.IsEmpty() ? IntegerFirst() : aMinStr.IntegerValue() );
2909 myMax.Append( aMaxStr.IsEmpty() ? IntegerLast() : aMaxStr.IntegerValue() );
2916 //=======================================================================
2918 // Purpose : Get type of supported entities
2919 //=======================================================================
2920 SMDSAbs_ElementType RangeOfIds::GetType() const
2925 //=======================================================================
2927 // Purpose : Set type of supported entities
2928 //=======================================================================
2929 void RangeOfIds::SetType( SMDSAbs_ElementType theType )
2934 //=======================================================================
2936 // Purpose : Verify whether entity satisfies to this rpedicate
2937 //=======================================================================
2938 bool RangeOfIds::IsSatisfy( long theId )
2943 if ( myType == SMDSAbs_Node )
2945 if ( myMesh->FindNode( theId ) == 0 )
2950 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2951 if ( anElem == 0 || (myType != anElem->GetType() && myType != SMDSAbs_All ))
2955 if ( myIds.Contains( theId ) )
2958 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
2959 if ( theId >= myMin( i ) && theId <= myMax( i ) )
2967 Description : Base class for comparators
2969 Comparator::Comparator():
2973 Comparator::~Comparator()
2976 void Comparator::SetMesh( const SMDS_Mesh* theMesh )
2979 myFunctor->SetMesh( theMesh );
2982 void Comparator::SetMargin( double theValue )
2984 myMargin = theValue;
2987 void Comparator::SetNumFunctor( NumericalFunctorPtr theFunct )
2989 myFunctor = theFunct;
2992 SMDSAbs_ElementType Comparator::GetType() const
2994 return myFunctor ? myFunctor->GetType() : SMDSAbs_All;
2997 double Comparator::GetMargin()
3005 Description : Comparator "<"
3007 bool LessThan::IsSatisfy( long theId )
3009 return myFunctor && myFunctor->GetValue( theId ) < myMargin;
3015 Description : Comparator ">"
3017 bool MoreThan::IsSatisfy( long theId )
3019 return myFunctor && myFunctor->GetValue( theId ) > myMargin;
3025 Description : Comparator "="
3028 myToler(Precision::Confusion())
3031 bool EqualTo::IsSatisfy( long theId )
3033 return myFunctor && fabs( myFunctor->GetValue( theId ) - myMargin ) < myToler;
3036 void EqualTo::SetTolerance( double theToler )
3041 double EqualTo::GetTolerance()
3048 Description : Logical NOT predicate
3050 LogicalNOT::LogicalNOT()
3053 LogicalNOT::~LogicalNOT()
3056 bool LogicalNOT::IsSatisfy( long theId )
3058 return myPredicate && !myPredicate->IsSatisfy( theId );
3061 void LogicalNOT::SetMesh( const SMDS_Mesh* theMesh )
3064 myPredicate->SetMesh( theMesh );
3067 void LogicalNOT::SetPredicate( PredicatePtr thePred )
3069 myPredicate = thePred;
3072 SMDSAbs_ElementType LogicalNOT::GetType() const
3074 return myPredicate ? myPredicate->GetType() : SMDSAbs_All;
3079 Class : LogicalBinary
3080 Description : Base class for binary logical predicate
3082 LogicalBinary::LogicalBinary()
3085 LogicalBinary::~LogicalBinary()
3088 void LogicalBinary::SetMesh( const SMDS_Mesh* theMesh )
3091 myPredicate1->SetMesh( theMesh );
3094 myPredicate2->SetMesh( theMesh );
3097 void LogicalBinary::SetPredicate1( PredicatePtr thePredicate )
3099 myPredicate1 = thePredicate;
3102 void LogicalBinary::SetPredicate2( PredicatePtr thePredicate )
3104 myPredicate2 = thePredicate;
3107 SMDSAbs_ElementType LogicalBinary::GetType() const
3109 if ( !myPredicate1 || !myPredicate2 )
3112 SMDSAbs_ElementType aType1 = myPredicate1->GetType();
3113 SMDSAbs_ElementType aType2 = myPredicate2->GetType();
3115 return aType1 == aType2 ? aType1 : SMDSAbs_All;
3121 Description : Logical AND
3123 bool LogicalAND::IsSatisfy( long theId )
3128 myPredicate1->IsSatisfy( theId ) &&
3129 myPredicate2->IsSatisfy( theId );
3135 Description : Logical OR
3137 bool LogicalOR::IsSatisfy( long theId )
3142 (myPredicate1->IsSatisfy( theId ) ||
3143 myPredicate2->IsSatisfy( theId ));
3157 void Filter::SetPredicate( PredicatePtr thePredicate )
3159 myPredicate = thePredicate;
3162 void Filter::GetElementsId( const SMDS_Mesh* theMesh,
3163 PredicatePtr thePredicate,
3164 TIdSequence& theSequence )
3166 theSequence.clear();
3168 if ( !theMesh || !thePredicate )
3171 thePredicate->SetMesh( theMesh );
3173 SMDS_ElemIteratorPtr elemIt = theMesh->elementsIterator( thePredicate->GetType() );
3175 while ( elemIt->more() ) {
3176 const SMDS_MeshElement* anElem = elemIt->next();
3177 long anId = anElem->GetID();
3178 if ( thePredicate->IsSatisfy( anId ) )
3179 theSequence.push_back( anId );
3184 void Filter::GetElementsId( const SMDS_Mesh* theMesh,
3185 Filter::TIdSequence& theSequence )
3187 GetElementsId(theMesh,myPredicate,theSequence);
3194 typedef std::set<SMDS_MeshFace*> TMapOfFacePtr;
3200 ManifoldPart::Link::Link( SMDS_MeshNode* theNode1,
3201 SMDS_MeshNode* theNode2 )
3207 ManifoldPart::Link::~Link()
3213 bool ManifoldPart::Link::IsEqual( const ManifoldPart::Link& theLink ) const
3215 if ( myNode1 == theLink.myNode1 &&
3216 myNode2 == theLink.myNode2 )
3218 else if ( myNode1 == theLink.myNode2 &&
3219 myNode2 == theLink.myNode1 )
3225 bool ManifoldPart::Link::operator<( const ManifoldPart::Link& x ) const
3227 if(myNode1 < x.myNode1) return true;
3228 if(myNode1 == x.myNode1)
3229 if(myNode2 < x.myNode2) return true;
3233 bool ManifoldPart::IsEqual( const ManifoldPart::Link& theLink1,
3234 const ManifoldPart::Link& theLink2 )
3236 return theLink1.IsEqual( theLink2 );
3239 ManifoldPart::ManifoldPart()
3242 myAngToler = Precision::Angular();
3243 myIsOnlyManifold = true;
3246 ManifoldPart::~ManifoldPart()
3251 void ManifoldPart::SetMesh( const SMDS_Mesh* theMesh )
3257 SMDSAbs_ElementType ManifoldPart::GetType() const
3258 { return SMDSAbs_Face; }
3260 bool ManifoldPart::IsSatisfy( long theElementId )
3262 return myMapIds.Contains( theElementId );
3265 void ManifoldPart::SetAngleTolerance( const double theAngToler )
3266 { myAngToler = theAngToler; }
3268 double ManifoldPart::GetAngleTolerance() const
3269 { return myAngToler; }
3271 void ManifoldPart::SetIsOnlyManifold( const bool theIsOnly )
3272 { myIsOnlyManifold = theIsOnly; }
3274 void ManifoldPart::SetStartElem( const long theStartId )
3275 { myStartElemId = theStartId; }
3277 bool ManifoldPart::process()
3280 myMapBadGeomIds.Clear();
3282 myAllFacePtr.clear();
3283 myAllFacePtrIntDMap.clear();
3287 // collect all faces into own map
3288 SMDS_FaceIteratorPtr anFaceItr = myMesh->facesIterator();
3289 for (; anFaceItr->more(); )
3291 SMDS_MeshFace* aFacePtr = (SMDS_MeshFace*)anFaceItr->next();
3292 myAllFacePtr.push_back( aFacePtr );
3293 myAllFacePtrIntDMap[aFacePtr] = myAllFacePtr.size()-1;
3296 SMDS_MeshFace* aStartFace = (SMDS_MeshFace*)myMesh->FindElement( myStartElemId );
3300 // the map of non manifold links and bad geometry
3301 TMapOfLink aMapOfNonManifold;
3302 TColStd_MapOfInteger aMapOfTreated;
3304 // begin cycle on faces from start index and run on vector till the end
3305 // and from begin to start index to cover whole vector
3306 const int aStartIndx = myAllFacePtrIntDMap[aStartFace];
3307 bool isStartTreat = false;
3308 for ( int fi = aStartIndx; !isStartTreat || fi != aStartIndx ; fi++ )
3310 if ( fi == aStartIndx )
3311 isStartTreat = true;
3312 // as result next time when fi will be equal to aStartIndx
3314 SMDS_MeshFace* aFacePtr = myAllFacePtr[ fi ];
3315 if ( aMapOfTreated.Contains( aFacePtr->GetID() ) )
3318 aMapOfTreated.Add( aFacePtr->GetID() );
3319 TColStd_MapOfInteger aResFaces;
3320 if ( !findConnected( myAllFacePtrIntDMap, aFacePtr,
3321 aMapOfNonManifold, aResFaces ) )
3323 TColStd_MapIteratorOfMapOfInteger anItr( aResFaces );
3324 for ( ; anItr.More(); anItr.Next() )
3326 int aFaceId = anItr.Key();
3327 aMapOfTreated.Add( aFaceId );
3328 myMapIds.Add( aFaceId );
3331 if ( fi == ( myAllFacePtr.size() - 1 ) )
3333 } // end run on vector of faces
3334 return !myMapIds.IsEmpty();
3337 static void getLinks( const SMDS_MeshFace* theFace,
3338 ManifoldPart::TVectorOfLink& theLinks )
3340 int aNbNode = theFace->NbNodes();
3341 SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
3343 SMDS_MeshNode* aNode = 0;
3344 for ( ; aNodeItr->more() && i <= aNbNode; )
3347 SMDS_MeshNode* aN1 = (SMDS_MeshNode*)aNodeItr->next();
3351 SMDS_MeshNode* aN2 = ( i >= aNbNode ) ? aNode : (SMDS_MeshNode*)aNodeItr->next();
3353 ManifoldPart::Link aLink( aN1, aN2 );
3354 theLinks.push_back( aLink );
3358 bool ManifoldPart::findConnected
3359 ( const ManifoldPart::TDataMapFacePtrInt& theAllFacePtrInt,
3360 SMDS_MeshFace* theStartFace,
3361 ManifoldPart::TMapOfLink& theNonManifold,
3362 TColStd_MapOfInteger& theResFaces )
3364 theResFaces.Clear();
3365 if ( !theAllFacePtrInt.size() )
3368 if ( getNormale( theStartFace ).SquareModulus() <= gp::Resolution() )
3370 myMapBadGeomIds.Add( theStartFace->GetID() );
3374 ManifoldPart::TMapOfLink aMapOfBoundary, aMapToSkip;
3375 ManifoldPart::TVectorOfLink aSeqOfBoundary;
3376 theResFaces.Add( theStartFace->GetID() );
3377 ManifoldPart::TDataMapOfLinkFacePtr aDMapLinkFace;
3379 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
3380 aDMapLinkFace, theNonManifold, theStartFace );
3382 bool isDone = false;
3383 while ( !isDone && aMapOfBoundary.size() != 0 )
3385 bool isToReset = false;
3386 ManifoldPart::TVectorOfLink::iterator pLink = aSeqOfBoundary.begin();
3387 for ( ; !isToReset && pLink != aSeqOfBoundary.end(); ++pLink )
3389 ManifoldPart::Link aLink = *pLink;
3390 if ( aMapToSkip.find( aLink ) != aMapToSkip.end() )
3392 // each link could be treated only once
3393 aMapToSkip.insert( aLink );
3395 ManifoldPart::TVectorOfFacePtr aFaces;
3397 if ( myIsOnlyManifold &&
3398 (theNonManifold.find( aLink ) != theNonManifold.end()) )
3402 getFacesByLink( aLink, aFaces );
3403 // filter the element to keep only indicated elements
3404 ManifoldPart::TVectorOfFacePtr aFiltered;
3405 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
3406 for ( ; pFace != aFaces.end(); ++pFace )
3408 SMDS_MeshFace* aFace = *pFace;
3409 if ( myAllFacePtrIntDMap.find( aFace ) != myAllFacePtrIntDMap.end() )
3410 aFiltered.push_back( aFace );
3413 if ( aFaces.size() < 2 ) // no neihgbour faces
3415 else if ( myIsOnlyManifold && aFaces.size() > 2 ) // non manifold case
3417 theNonManifold.insert( aLink );
3422 // compare normal with normals of neighbor element
3423 SMDS_MeshFace* aPrevFace = aDMapLinkFace[ aLink ];
3424 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
3425 for ( ; pFace != aFaces.end(); ++pFace )
3427 SMDS_MeshFace* aNextFace = *pFace;
3428 if ( aPrevFace == aNextFace )
3430 int anNextFaceID = aNextFace->GetID();
3431 if ( myIsOnlyManifold && theResFaces.Contains( anNextFaceID ) )
3432 // should not be with non manifold restriction. probably bad topology
3434 // check if face was treated and skipped
3435 if ( myMapBadGeomIds.Contains( anNextFaceID ) ||
3436 !isInPlane( aPrevFace, aNextFace ) )
3438 // add new element to connected and extend the boundaries.
3439 theResFaces.Add( anNextFaceID );
3440 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
3441 aDMapLinkFace, theNonManifold, aNextFace );
3445 isDone = !isToReset;
3448 return !theResFaces.IsEmpty();
3451 bool ManifoldPart::isInPlane( const SMDS_MeshFace* theFace1,
3452 const SMDS_MeshFace* theFace2 )
3454 gp_Dir aNorm1 = gp_Dir( getNormale( theFace1 ) );
3455 gp_XYZ aNorm2XYZ = getNormale( theFace2 );
3456 if ( aNorm2XYZ.SquareModulus() <= gp::Resolution() )
3458 myMapBadGeomIds.Add( theFace2->GetID() );
3461 if ( aNorm1.IsParallel( gp_Dir( aNorm2XYZ ), myAngToler ) )
3467 void ManifoldPart::expandBoundary
3468 ( ManifoldPart::TMapOfLink& theMapOfBoundary,
3469 ManifoldPart::TVectorOfLink& theSeqOfBoundary,
3470 ManifoldPart::TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
3471 ManifoldPart::TMapOfLink& theNonManifold,
3472 SMDS_MeshFace* theNextFace ) const
3474 ManifoldPart::TVectorOfLink aLinks;
3475 getLinks( theNextFace, aLinks );
3476 int aNbLink = (int)aLinks.size();
3477 for ( int i = 0; i < aNbLink; i++ )
3479 ManifoldPart::Link aLink = aLinks[ i ];
3480 if ( myIsOnlyManifold && (theNonManifold.find( aLink ) != theNonManifold.end()) )
3482 if ( theMapOfBoundary.find( aLink ) != theMapOfBoundary.end() )
3484 if ( myIsOnlyManifold )
3486 // remove from boundary
3487 theMapOfBoundary.erase( aLink );
3488 ManifoldPart::TVectorOfLink::iterator pLink = theSeqOfBoundary.begin();
3489 for ( ; pLink != theSeqOfBoundary.end(); ++pLink )
3491 ManifoldPart::Link aBoundLink = *pLink;
3492 if ( aBoundLink.IsEqual( aLink ) )
3494 theSeqOfBoundary.erase( pLink );
3502 theMapOfBoundary.insert( aLink );
3503 theSeqOfBoundary.push_back( aLink );
3504 theDMapLinkFacePtr[ aLink ] = theNextFace;
3509 void ManifoldPart::getFacesByLink( const ManifoldPart::Link& theLink,
3510 ManifoldPart::TVectorOfFacePtr& theFaces ) const
3512 std::set<SMDS_MeshCell *> aSetOfFaces;
3513 // take all faces that shared first node
3514 SMDS_ElemIteratorPtr anItr = theLink.myNode1->facesIterator();
3515 for ( ; anItr->more(); )
3517 SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
3520 aSetOfFaces.insert( aFace );
3522 // take all faces that shared second node
3523 anItr = theLink.myNode2->facesIterator();
3524 // find the common part of two sets
3525 for ( ; anItr->more(); )
3527 SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
3528 if ( aSetOfFaces.count( aFace ) )
3529 theFaces.push_back( aFace );
3538 ElementsOnSurface::ElementsOnSurface()
3541 myType = SMDSAbs_All;
3543 myToler = Precision::Confusion();
3544 myUseBoundaries = false;
3547 ElementsOnSurface::~ElementsOnSurface()
3551 void ElementsOnSurface::SetMesh( const SMDS_Mesh* theMesh )
3553 myMeshModifTracer.SetMesh( theMesh );
3554 if ( myMeshModifTracer.IsMeshModified())
3558 bool ElementsOnSurface::IsSatisfy( long theElementId )
3560 return myIds.Contains( theElementId );
3563 SMDSAbs_ElementType ElementsOnSurface::GetType() const
3566 void ElementsOnSurface::SetTolerance( const double theToler )
3568 if ( myToler != theToler )
3573 double ElementsOnSurface::GetTolerance() const
3576 void ElementsOnSurface::SetUseBoundaries( bool theUse )
3578 if ( myUseBoundaries != theUse ) {
3579 myUseBoundaries = theUse;
3580 SetSurface( mySurf, myType );
3584 void ElementsOnSurface::SetSurface( const TopoDS_Shape& theShape,
3585 const SMDSAbs_ElementType theType )
3590 if ( theShape.IsNull() || theShape.ShapeType() != TopAbs_FACE )
3592 mySurf = TopoDS::Face( theShape );
3593 BRepAdaptor_Surface SA( mySurf, myUseBoundaries );
3595 u1 = SA.FirstUParameter(),
3596 u2 = SA.LastUParameter(),
3597 v1 = SA.FirstVParameter(),
3598 v2 = SA.LastVParameter();
3599 Handle(Geom_Surface) surf = BRep_Tool::Surface( mySurf );
3600 myProjector.Init( surf, u1,u2, v1,v2 );
3604 void ElementsOnSurface::process()
3607 if ( mySurf.IsNull() )
3610 if ( !myMeshModifTracer.GetMesh() )
3613 myIds.ReSize( myMeshModifTracer.GetMesh()->GetMeshInfo().NbElements( myType ));
3615 SMDS_ElemIteratorPtr anIter = myMeshModifTracer.GetMesh()->elementsIterator( myType );
3616 for(; anIter->more(); )
3617 process( anIter->next() );
3620 void ElementsOnSurface::process( const SMDS_MeshElement* theElemPtr )
3622 SMDS_ElemIteratorPtr aNodeItr = theElemPtr->nodesIterator();
3623 bool isSatisfy = true;
3624 for ( ; aNodeItr->more(); )
3626 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
3627 if ( !isOnSurface( aNode ) )
3634 myIds.Add( theElemPtr->GetID() );
3637 bool ElementsOnSurface::isOnSurface( const SMDS_MeshNode* theNode )
3639 if ( mySurf.IsNull() )
3642 gp_Pnt aPnt( theNode->X(), theNode->Y(), theNode->Z() );
3643 // double aToler2 = myToler * myToler;
3644 // if ( mySurf->IsKind(STANDARD_TYPE(Geom_Plane)))
3646 // gp_Pln aPln = Handle(Geom_Plane)::DownCast(mySurf)->Pln();
3647 // if ( aPln.SquareDistance( aPnt ) > aToler2 )
3650 // else if ( mySurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)))
3652 // gp_Cylinder aCyl = Handle(Geom_CylindricalSurface)::DownCast(mySurf)->Cylinder();
3653 // double aRad = aCyl.Radius();
3654 // gp_Ax3 anAxis = aCyl.Position();
3655 // gp_XYZ aLoc = aCyl.Location().XYZ();
3656 // double aXDist = anAxis.XDirection().XYZ() * ( aPnt.XYZ() - aLoc );
3657 // double aYDist = anAxis.YDirection().XYZ() * ( aPnt.XYZ() - aLoc );
3658 // if ( fabs(aXDist*aXDist + aYDist*aYDist - aRad*aRad) > aToler2 )
3663 myProjector.Perform( aPnt );
3664 bool isOn = ( myProjector.IsDone() && myProjector.LowerDistance() <= myToler );
3674 ElementsOnShape::ElementsOnShape()
3676 myType(SMDSAbs_All),
3677 myToler(Precision::Confusion()),
3678 myAllNodesFlag(false)
3682 ElementsOnShape::~ElementsOnShape()
3687 SMDSAbs_ElementType ElementsOnShape::GetType() const
3692 void ElementsOnShape::SetTolerance (const double theToler)
3694 if (myToler != theToler) {
3696 SetShape(myShape, myType);
3700 double ElementsOnShape::GetTolerance() const
3705 void ElementsOnShape::SetAllNodes (bool theAllNodes)
3707 myAllNodesFlag = theAllNodes;
3710 void ElementsOnShape::SetMesh (const SMDS_Mesh* theMesh)
3715 void ElementsOnShape::SetShape (const TopoDS_Shape& theShape,
3716 const SMDSAbs_ElementType theType)
3720 if ( myShape.IsNull() ) return;
3722 TopTools_IndexedMapOfShape shapesMap;
3723 TopAbs_ShapeEnum shapeTypes[4] = { TopAbs_SOLID, TopAbs_FACE, TopAbs_EDGE, TopAbs_VERTEX };
3724 TopExp_Explorer sub;
3725 for ( int i = 0; i < 4; ++i )
3727 if ( shapesMap.IsEmpty() )
3728 for ( sub.Init( myShape, shapeTypes[i] ); sub.More(); sub.Next() )
3729 shapesMap.Add( sub.Current() );
3731 for ( sub.Init( myShape, shapeTypes[i], shapeTypes[i-1] ); sub.More(); sub.Next() )
3732 shapesMap.Add( sub.Current() );
3736 myClassifiers.resize( shapesMap.Extent() );
3737 for ( int i = 0; i < shapesMap.Extent(); ++i )
3738 myClassifiers[ i ] = new TClassifier( shapesMap( i+1 ), myToler );
3741 void ElementsOnShape::clearClassifiers()
3743 for ( size_t i = 0; i < myClassifiers.size(); ++i )
3744 delete myClassifiers[ i ];
3745 myClassifiers.clear();
3748 bool ElementsOnShape::IsSatisfy (long elemId)
3750 const SMDS_MeshElement* elem =
3751 ( myType == SMDSAbs_Node ? myMesh->FindNode( elemId ) : myMesh->FindElement( elemId ));
3752 if ( !elem || myClassifiers.empty() )
3755 for ( size_t i = 0; i < myClassifiers.size(); ++i )
3757 SMDS_ElemIteratorPtr aNodeItr = elem->nodesIterator();
3758 bool isSatisfy = myAllNodesFlag;
3760 gp_XYZ centerXYZ (0, 0, 0);
3762 while (aNodeItr->more() && (isSatisfy == myAllNodesFlag))
3764 SMESH_TNodeXYZ aPnt ( aNodeItr->next() );
3766 isSatisfy = ! myClassifiers[i]->IsOut( aPnt );
3769 // Check the center point for volumes MantisBug 0020168
3772 myClassifiers[i]->ShapeType() == TopAbs_SOLID)
3774 centerXYZ /= elem->NbNodes();
3775 isSatisfy = ! myClassifiers[i]->IsOut( centerXYZ );
3784 TopAbs_ShapeEnum ElementsOnShape::TClassifier::ShapeType() const
3786 return myShape.ShapeType();
3789 bool ElementsOnShape::TClassifier::IsOut(const gp_Pnt& p)
3791 return (this->*myIsOutFun)( p );
3794 void ElementsOnShape::TClassifier::Init (const TopoDS_Shape& theShape, double theTol)
3798 switch ( myShape.ShapeType() )
3800 case TopAbs_SOLID: {
3801 mySolidClfr.Load(theShape);
3802 myIsOutFun = & ElementsOnShape::TClassifier::isOutOfSolid;
3806 Standard_Real u1,u2,v1,v2;
3807 Handle(Geom_Surface) surf = BRep_Tool::Surface( TopoDS::Face( theShape ));
3808 surf->Bounds( u1,u2,v1,v2 );
3809 myProjFace.Init(surf, u1,u2, v1,v2, myTol );
3810 myIsOutFun = & ElementsOnShape::TClassifier::isOutOfFace;
3814 Standard_Real u1, u2;
3815 Handle(Geom_Curve) curve = BRep_Tool::Curve( TopoDS::Edge(theShape), u1, u2);
3816 myProjEdge.Init(curve, u1, u2);
3817 myIsOutFun = & ElementsOnShape::TClassifier::isOutOfEdge;
3820 case TopAbs_VERTEX:{
3821 myVertexXYZ = BRep_Tool::Pnt( TopoDS::Vertex( theShape ) );
3822 myIsOutFun = & ElementsOnShape::TClassifier::isOutOfVertex;
3826 throw SALOME_Exception("Programmer error in usage of ElementsOnShape::TClassifier");
3830 bool ElementsOnShape::TClassifier::isOutOfSolid (const gp_Pnt& p)
3832 mySolidClfr.Perform( p, myTol );
3833 return ( mySolidClfr.State() != TopAbs_IN && mySolidClfr.State() != TopAbs_ON );
3836 bool ElementsOnShape::TClassifier::isOutOfFace (const gp_Pnt& p)
3838 myProjFace.Perform( p );
3839 if ( myProjFace.IsDone() && myProjFace.LowerDistance() <= myTol )
3841 // check relatively to the face
3842 Quantity_Parameter u, v;
3843 myProjFace.LowerDistanceParameters(u, v);
3844 gp_Pnt2d aProjPnt (u, v);
3845 BRepClass_FaceClassifier aClsf ( TopoDS::Face( myShape ), aProjPnt, myTol );
3846 if ( aClsf.State() == TopAbs_IN || aClsf.State() == TopAbs_ON )
3852 bool ElementsOnShape::TClassifier::isOutOfEdge (const gp_Pnt& p)
3854 myProjEdge.Perform( p );
3855 return ! ( myProjEdge.NbPoints() > 0 && myProjEdge.LowerDistance() <= myTol );
3858 bool ElementsOnShape::TClassifier::isOutOfVertex(const gp_Pnt& p)
3860 return ( myVertexXYZ.Distance( p ) > myTol );
3864 TSequenceOfXYZ::TSequenceOfXYZ()
3867 TSequenceOfXYZ::TSequenceOfXYZ(size_type n) : myArray(n)
3870 TSequenceOfXYZ::TSequenceOfXYZ(size_type n, const gp_XYZ& t) : myArray(n,t)
3873 TSequenceOfXYZ::TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ) : myArray(theSequenceOfXYZ.myArray)
3876 template <class InputIterator>
3877 TSequenceOfXYZ::TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd): myArray(theBegin,theEnd)
3880 TSequenceOfXYZ::~TSequenceOfXYZ()
3883 TSequenceOfXYZ& TSequenceOfXYZ::operator=(const TSequenceOfXYZ& theSequenceOfXYZ)
3885 myArray = theSequenceOfXYZ.myArray;
3889 gp_XYZ& TSequenceOfXYZ::operator()(size_type n)
3891 return myArray[n-1];
3894 const gp_XYZ& TSequenceOfXYZ::operator()(size_type n) const
3896 return myArray[n-1];
3899 void TSequenceOfXYZ::clear()
3904 void TSequenceOfXYZ::reserve(size_type n)
3909 void TSequenceOfXYZ::push_back(const gp_XYZ& v)
3911 myArray.push_back(v);
3914 TSequenceOfXYZ::size_type TSequenceOfXYZ::size() const
3916 return myArray.size();
3919 TMeshModifTracer::TMeshModifTracer():
3920 myMeshModifTime(0), myMesh(0)
3923 void TMeshModifTracer::SetMesh( const SMDS_Mesh* theMesh )
3925 if ( theMesh != myMesh )
3926 myMeshModifTime = 0;
3929 bool TMeshModifTracer::IsMeshModified()
3931 bool modified = false;
3934 modified = ( myMeshModifTime != myMesh->GetMTime() );
3935 myMeshModifTime = myMesh->GetMTime();