1 // Copyright (C) 2007-2010 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
23 #include "SMESH_ControlsDef.hxx"
28 #include <BRepAdaptor_Surface.hxx>
29 #include <BRepClass_FaceClassifier.hxx>
30 #include <BRep_Tool.hxx>
34 #include <TopoDS_Edge.hxx>
35 #include <TopoDS_Face.hxx>
36 #include <TopoDS_Shape.hxx>
37 #include <TopoDS_Vertex.hxx>
38 #include <TopoDS_Iterator.hxx>
40 #include <Geom_CylindricalSurface.hxx>
41 #include <Geom_Plane.hxx>
42 #include <Geom_Surface.hxx>
44 #include <Precision.hxx>
45 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
46 #include <TColStd_MapOfInteger.hxx>
47 #include <TColStd_SequenceOfAsciiString.hxx>
48 #include <TColgp_Array1OfXYZ.hxx>
51 #include <gp_Cylinder.hxx>
58 #include "SMDS_Mesh.hxx"
59 #include "SMDS_Iterator.hxx"
60 #include "SMDS_MeshElement.hxx"
61 #include "SMDS_MeshNode.hxx"
62 #include "SMDS_VolumeTool.hxx"
63 #include "SMDS_QuadraticFaceOfNodes.hxx"
64 #include "SMDS_QuadraticEdge.hxx"
66 #include "SMESHDS_Mesh.hxx"
67 #include "SMESHDS_GroupBase.hxx"
75 inline gp_XYZ gpXYZ(const SMDS_MeshNode* aNode )
77 return gp_XYZ(aNode->X(), aNode->Y(), aNode->Z() );
80 inline double getAngle( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
82 gp_Vec v1( P1 - P2 ), v2( P3 - P2 );
84 return v1.Magnitude() < gp::Resolution() ||
85 v2.Magnitude() < gp::Resolution() ? 0 : v1.Angle( v2 );
88 inline double getArea( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 )
90 gp_Vec aVec1( P2 - P1 );
91 gp_Vec aVec2( P3 - P1 );
92 return ( aVec1 ^ aVec2 ).Magnitude() * 0.5;
95 inline double getArea( const gp_Pnt& P1, const gp_Pnt& P2, const gp_Pnt& P3 )
97 return getArea( P1.XYZ(), P2.XYZ(), P3.XYZ() );
102 inline double getDistance( const gp_XYZ& P1, const gp_XYZ& P2 )
104 double aDist = gp_Pnt( P1 ).Distance( gp_Pnt( P2 ) );
108 int getNbMultiConnection( const SMDS_Mesh* theMesh, const int theId )
113 const SMDS_MeshElement* anEdge = theMesh->FindElement( theId );
114 if ( anEdge == 0 || anEdge->GetType() != SMDSAbs_Edge/* || anEdge->NbNodes() != 2 */)
117 // for each pair of nodes in anEdge (there are 2 pairs in a quadratic edge)
118 // count elements containing both nodes of the pair.
119 // Note that there may be such cases for a quadratic edge (a horizontal line):
124 // +-----+------+ +-----+------+
127 // result sould be 2 in both cases
129 int aResult0 = 0, aResult1 = 0;
130 // last node, it is a medium one in a quadratic edge
131 const SMDS_MeshNode* aLastNode = anEdge->GetNode( anEdge->NbNodes() - 1 );
132 const SMDS_MeshNode* aNode0 = anEdge->GetNode( 0 );
133 const SMDS_MeshNode* aNode1 = anEdge->GetNode( 1 );
134 if ( aNode1 == aLastNode ) aNode1 = 0;
136 SMDS_ElemIteratorPtr anElemIter = aLastNode->GetInverseElementIterator();
137 while( anElemIter->more() ) {
138 const SMDS_MeshElement* anElem = anElemIter->next();
139 if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) {
140 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
141 while ( anIter->more() ) {
142 if ( const SMDS_MeshElement* anElemNode = anIter->next() ) {
143 if ( anElemNode == aNode0 ) {
145 if ( !aNode1 ) break; // not a quadratic edge
147 else if ( anElemNode == aNode1 )
153 int aResult = std::max ( aResult0, aResult1 );
155 // TColStd_MapOfInteger aMap;
157 // SMDS_ElemIteratorPtr anIter = anEdge->nodesIterator();
158 // if ( anIter != 0 ) {
159 // while( anIter->more() ) {
160 // const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next();
163 // SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator();
164 // while( anElemIter->more() ) {
165 // const SMDS_MeshElement* anElem = anElemIter->next();
166 // if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) {
167 // int anId = anElem->GetID();
169 // if ( anIter->more() ) // i.e. first node
171 // else if ( aMap.Contains( anId ) )
181 gp_XYZ getNormale( const SMDS_MeshFace* theFace, bool* ok=0 )
183 int aNbNode = theFace->NbNodes();
185 gp_XYZ q1 = gpXYZ( theFace->GetNode(1)) - gpXYZ( theFace->GetNode(0));
186 gp_XYZ q2 = gpXYZ( theFace->GetNode(2)) - gpXYZ( theFace->GetNode(0));
189 gp_XYZ q3 = gpXYZ( theFace->GetNode(3)) - gpXYZ( theFace->GetNode(0));
192 double len = n.Modulus();
193 bool zeroLen = ( len <= numeric_limits<double>::min());
197 if (ok) *ok = !zeroLen;
205 using namespace SMESH::Controls;
212 Class : NumericalFunctor
213 Description : Base class for numerical functors
215 NumericalFunctor::NumericalFunctor():
221 void NumericalFunctor::SetMesh( const SMDS_Mesh* theMesh )
226 bool NumericalFunctor::GetPoints(const int theId,
227 TSequenceOfXYZ& theRes ) const
234 return GetPoints( myMesh->FindElement( theId ), theRes );
237 bool NumericalFunctor::GetPoints(const SMDS_MeshElement* anElem,
238 TSequenceOfXYZ& theRes )
245 theRes.reserve( anElem->NbNodes() );
247 // Get nodes of the element
248 SMDS_ElemIteratorPtr anIter;
250 if ( anElem->IsQuadratic() ) {
251 switch ( anElem->GetType() ) {
253 anIter = dynamic_cast<const SMDS_VtkEdge*>
254 (anElem)->interlacedNodesElemIterator();
257 anIter = dynamic_cast<const SMDS_VtkFace*>
258 (anElem)->interlacedNodesElemIterator();
261 anIter = anElem->nodesIterator();
266 anIter = anElem->nodesIterator();
270 while( anIter->more() ) {
271 if ( const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>( anIter->next() ))
272 theRes.push_back( gp_XYZ( aNode->X(), aNode->Y(), aNode->Z() ) );
279 long NumericalFunctor::GetPrecision() const
284 void NumericalFunctor::SetPrecision( const long thePrecision )
286 myPrecision = thePrecision;
289 double NumericalFunctor::GetValue( long theId )
291 myCurrElement = myMesh->FindElement( theId );
293 if ( GetPoints( theId, P ))
295 double aVal = GetValue( P );
296 if ( myPrecision >= 0 )
298 double prec = pow( 10., (double)( myPrecision ) );
299 aVal = floor( aVal * prec + 0.5 ) / prec;
307 //================================================================================
309 * \brief Return histogram of functor values
310 * \param nbIntervals - number of intervals
311 * \param nbEvents - number of mesh elements having values within i-th interval
312 * \param funValues - boundaries of intervals
313 * \param elements - elements to check vulue of; empty list means "of all"
314 * \param minmax - boundaries of diapason of values to divide into intervals
316 //================================================================================
318 void NumericalFunctor::GetHistogram(int nbIntervals,
319 std::vector<int>& nbEvents,
320 std::vector<double>& funValues,
321 const vector<int>& elements,
322 const double* minmax)
324 if ( nbIntervals < 1 ||
326 !myMesh->GetMeshInfo().NbElements( GetType() ))
328 nbEvents.resize( nbIntervals, 0 );
329 funValues.resize( nbIntervals+1 );
331 // get all values sorted
332 std::multiset< double > values;
333 if ( elements.empty() )
335 SMDS_ElemIteratorPtr elemIt = myMesh->elementsIterator(GetType());
336 while ( elemIt->more() )
337 values.insert( GetValue( elemIt->next()->GetID() ));
341 vector<int>::const_iterator id = elements.begin();
342 for ( ; id != elements.end(); ++id )
343 values.insert( GetValue( *id ));
348 funValues[0] = minmax[0];
349 funValues[nbIntervals] = minmax[1];
353 funValues[0] = *values.begin();
354 funValues[nbIntervals] = *values.rbegin();
356 // case nbIntervals == 1
357 if ( nbIntervals == 1 )
359 nbEvents[0] = values.size();
363 if (funValues.front() == funValues.back())
365 nbEvents.resize( 1 );
366 nbEvents[0] = values.size();
367 funValues[1] = funValues.back();
368 funValues.resize( 2 );
371 std::multiset< double >::iterator min = values.begin(), max;
372 for ( int i = 0; i < nbIntervals; ++i )
374 // find end value of i-th interval
375 double r = (i+1) / double( nbIntervals );
376 funValues[i+1] = funValues.front() * (1-r) + funValues.back() * r;
378 // count values in the i-th interval if there are any
379 if ( min != values.end() && *min <= funValues[i+1] )
381 // find the first value out of the interval
382 max = values.upper_bound( funValues[i+1] ); // max is greater than funValues[i+1], or end()
383 nbEvents[i] = std::distance( min, max );
387 // add values larger than minmax[1]
388 nbEvents.back() += std::distance( min, values.end() );
391 //=======================================================================
392 //function : GetValue
394 //=======================================================================
396 double Volume::GetValue( long theElementId )
398 if ( theElementId && myMesh ) {
399 SMDS_VolumeTool aVolumeTool;
400 if ( aVolumeTool.Set( myMesh->FindElement( theElementId )))
401 return aVolumeTool.GetSize();
406 //=======================================================================
407 //function : GetBadRate
408 //purpose : meaningless as it is not quality control functor
409 //=======================================================================
411 double Volume::GetBadRate( double Value, int /*nbNodes*/ ) const
416 //=======================================================================
419 //=======================================================================
421 SMDSAbs_ElementType Volume::GetType() const
423 return SMDSAbs_Volume;
428 Class : MaxElementLength2D
429 Description : Functor calculating maximum length of 2D element
432 double MaxElementLength2D::GetValue( long theElementId )
435 if( GetPoints( theElementId, P ) ) {
437 const SMDS_MeshElement* aElem = myMesh->FindElement( theElementId );
438 SMDSAbs_ElementType aType = aElem->GetType();
442 if( len == 3 ) { // triangles
443 double L1 = getDistance(P( 1 ),P( 2 ));
444 double L2 = getDistance(P( 2 ),P( 3 ));
445 double L3 = getDistance(P( 3 ),P( 1 ));
446 aVal = Max(L1,Max(L2,L3));
449 else if( len == 4 ) { // quadrangles
450 double L1 = getDistance(P( 1 ),P( 2 ));
451 double L2 = getDistance(P( 2 ),P( 3 ));
452 double L3 = getDistance(P( 3 ),P( 4 ));
453 double L4 = getDistance(P( 4 ),P( 1 ));
454 double D1 = getDistance(P( 1 ),P( 3 ));
455 double D2 = getDistance(P( 2 ),P( 4 ));
456 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(D1,D2));
459 else if( len == 6 ) { // quadratic triangles
460 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
461 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
462 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 1 ));
463 aVal = Max(L1,Max(L2,L3));
466 else if( len == 8 ) { // quadratic quadrangles
467 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
468 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
469 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 7 ));
470 double L4 = getDistance(P( 7 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
471 double D1 = getDistance(P( 1 ),P( 5 ));
472 double D2 = getDistance(P( 3 ),P( 7 ));
473 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(D1,D2));
478 if( myPrecision >= 0 )
480 double prec = pow( 10., (double)myPrecision );
481 aVal = floor( aVal * prec + 0.5 ) / prec;
488 double MaxElementLength2D::GetBadRate( double Value, int /*nbNodes*/ ) const
493 SMDSAbs_ElementType MaxElementLength2D::GetType() const
499 Class : MaxElementLength3D
500 Description : Functor calculating maximum length of 3D element
503 double MaxElementLength3D::GetValue( long theElementId )
506 if( GetPoints( theElementId, P ) ) {
508 const SMDS_MeshElement* aElem = myMesh->FindElement( theElementId );
509 SMDSAbs_ElementType aType = aElem->GetType();
513 if( len == 4 ) { // tetras
514 double L1 = getDistance(P( 1 ),P( 2 ));
515 double L2 = getDistance(P( 2 ),P( 3 ));
516 double L3 = getDistance(P( 3 ),P( 1 ));
517 double L4 = getDistance(P( 1 ),P( 4 ));
518 double L5 = getDistance(P( 2 ),P( 4 ));
519 double L6 = getDistance(P( 3 ),P( 4 ));
520 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
523 else if( len == 5 ) { // pyramids
524 double L1 = getDistance(P( 1 ),P( 2 ));
525 double L2 = getDistance(P( 2 ),P( 3 ));
526 double L3 = getDistance(P( 3 ),P( 4 ));
527 double L4 = getDistance(P( 4 ),P( 1 ));
528 double L5 = getDistance(P( 1 ),P( 5 ));
529 double L6 = getDistance(P( 2 ),P( 5 ));
530 double L7 = getDistance(P( 3 ),P( 5 ));
531 double L8 = getDistance(P( 4 ),P( 5 ));
532 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
533 aVal = Max(aVal,Max(L7,L8));
536 else if( len == 6 ) { // pentas
537 double L1 = getDistance(P( 1 ),P( 2 ));
538 double L2 = getDistance(P( 2 ),P( 3 ));
539 double L3 = getDistance(P( 3 ),P( 1 ));
540 double L4 = getDistance(P( 4 ),P( 5 ));
541 double L5 = getDistance(P( 5 ),P( 6 ));
542 double L6 = getDistance(P( 6 ),P( 4 ));
543 double L7 = getDistance(P( 1 ),P( 4 ));
544 double L8 = getDistance(P( 2 ),P( 5 ));
545 double L9 = getDistance(P( 3 ),P( 6 ));
546 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
547 aVal = Max(aVal,Max(Max(L7,L8),L9));
550 else if( len == 8 ) { // hexas
551 double L1 = getDistance(P( 1 ),P( 2 ));
552 double L2 = getDistance(P( 2 ),P( 3 ));
553 double L3 = getDistance(P( 3 ),P( 4 ));
554 double L4 = getDistance(P( 4 ),P( 1 ));
555 double L5 = getDistance(P( 5 ),P( 6 ));
556 double L6 = getDistance(P( 6 ),P( 7 ));
557 double L7 = getDistance(P( 7 ),P( 8 ));
558 double L8 = getDistance(P( 8 ),P( 5 ));
559 double L9 = getDistance(P( 1 ),P( 5 ));
560 double L10= getDistance(P( 2 ),P( 6 ));
561 double L11= getDistance(P( 3 ),P( 7 ));
562 double L12= getDistance(P( 4 ),P( 8 ));
563 double D1 = getDistance(P( 1 ),P( 7 ));
564 double D2 = getDistance(P( 2 ),P( 8 ));
565 double D3 = getDistance(P( 3 ),P( 5 ));
566 double D4 = getDistance(P( 4 ),P( 6 ));
567 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
568 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
569 aVal = Max(aVal,Max(L11,L12));
570 aVal = Max(aVal,Max(Max(D1,D2),Max(D3,D4)));
573 else if( len == 10 ) { // quadratic tetras
574 double L1 = getDistance(P( 1 ),P( 5 )) + getDistance(P( 5 ),P( 2 ));
575 double L2 = getDistance(P( 2 ),P( 6 )) + getDistance(P( 6 ),P( 3 ));
576 double L3 = getDistance(P( 3 ),P( 7 )) + getDistance(P( 7 ),P( 1 ));
577 double L4 = getDistance(P( 1 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
578 double L5 = getDistance(P( 2 ),P( 9 )) + getDistance(P( 9 ),P( 4 ));
579 double L6 = getDistance(P( 3 ),P( 10 )) + getDistance(P( 10 ),P( 4 ));
580 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
583 else if( len == 13 ) { // quadratic pyramids
584 double L1 = getDistance(P( 1 ),P( 6 )) + getDistance(P( 6 ),P( 2 ));
585 double L2 = getDistance(P( 2 ),P( 7 )) + getDistance(P( 7 ),P( 3 ));
586 double L3 = getDistance(P( 3 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
587 double L4 = getDistance(P( 4 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
588 double L5 = getDistance(P( 1 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
589 double L6 = getDistance(P( 2 ),P( 11 )) + getDistance(P( 11 ),P( 5 ));
590 double L7 = getDistance(P( 3 ),P( 12 )) + getDistance(P( 12 ),P( 5 ));
591 double L8 = getDistance(P( 4 ),P( 13 )) + getDistance(P( 13 ),P( 5 ));
592 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
593 aVal = Max(aVal,Max(L7,L8));
596 else if( len == 15 ) { // quadratic pentas
597 double L1 = getDistance(P( 1 ),P( 7 )) + getDistance(P( 7 ),P( 2 ));
598 double L2 = getDistance(P( 2 ),P( 8 )) + getDistance(P( 8 ),P( 3 ));
599 double L3 = getDistance(P( 3 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
600 double L4 = getDistance(P( 4 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
601 double L5 = getDistance(P( 5 ),P( 11 )) + getDistance(P( 11 ),P( 6 ));
602 double L6 = getDistance(P( 6 ),P( 12 )) + getDistance(P( 12 ),P( 4 ));
603 double L7 = getDistance(P( 1 ),P( 13 )) + getDistance(P( 13 ),P( 4 ));
604 double L8 = getDistance(P( 2 ),P( 14 )) + getDistance(P( 14 ),P( 5 ));
605 double L9 = getDistance(P( 3 ),P( 15 )) + getDistance(P( 15 ),P( 6 ));
606 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
607 aVal = Max(aVal,Max(Max(L7,L8),L9));
610 else if( len == 20 ) { // quadratic hexas
611 double L1 = getDistance(P( 1 ),P( 9 )) + getDistance(P( 9 ),P( 2 ));
612 double L2 = getDistance(P( 2 ),P( 10 )) + getDistance(P( 10 ),P( 3 ));
613 double L3 = getDistance(P( 3 ),P( 11 )) + getDistance(P( 11 ),P( 4 ));
614 double L4 = getDistance(P( 4 ),P( 12 )) + getDistance(P( 12 ),P( 1 ));
615 double L5 = getDistance(P( 5 ),P( 13 )) + getDistance(P( 13 ),P( 6 ));
616 double L6 = getDistance(P( 6 ),P( 14 )) + getDistance(P( 14 ),P( 7 ));
617 double L7 = getDistance(P( 7 ),P( 15 )) + getDistance(P( 15 ),P( 8 ));
618 double L8 = getDistance(P( 8 ),P( 16 )) + getDistance(P( 16 ),P( 5 ));
619 double L9 = getDistance(P( 1 ),P( 17 )) + getDistance(P( 17 ),P( 5 ));
620 double L10= getDistance(P( 2 ),P( 18 )) + getDistance(P( 18 ),P( 6 ));
621 double L11= getDistance(P( 3 ),P( 19 )) + getDistance(P( 19 ),P( 7 ));
622 double L12= getDistance(P( 4 ),P( 20 )) + getDistance(P( 20 ),P( 8 ));
623 double D1 = getDistance(P( 1 ),P( 7 ));
624 double D2 = getDistance(P( 2 ),P( 8 ));
625 double D3 = getDistance(P( 3 ),P( 5 ));
626 double D4 = getDistance(P( 4 ),P( 6 ));
627 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
628 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
629 aVal = Max(aVal,Max(L11,L12));
630 aVal = Max(aVal,Max(Max(D1,D2),Max(D3,D4)));
633 else if( len > 1 && aElem->IsPoly() ) { // polys
634 // get the maximum distance between all pairs of nodes
635 for( int i = 1; i <= len; i++ ) {
636 for( int j = 1; j <= len; j++ ) {
637 if( j > i ) { // optimization of the loop
638 double D = getDistance( P(i), P(j) );
639 aVal = Max( aVal, D );
646 if( myPrecision >= 0 )
648 double prec = pow( 10., (double)myPrecision );
649 aVal = floor( aVal * prec + 0.5 ) / prec;
656 double MaxElementLength3D::GetBadRate( double Value, int /*nbNodes*/ ) const
661 SMDSAbs_ElementType MaxElementLength3D::GetType() const
663 return SMDSAbs_Volume;
669 Description : Functor for calculation of minimum angle
672 double MinimumAngle::GetValue( const TSequenceOfXYZ& P )
679 aMin = getAngle(P( P.size() ), P( 1 ), P( 2 ));
680 aMin = Min(aMin,getAngle(P( P.size()-1 ), P( P.size() ), P( 1 )));
682 for (int i=2; i<P.size();i++){
683 double A0 = getAngle( P( i-1 ), P( i ), P( i+1 ) );
687 return aMin * 180.0 / PI;
690 double MinimumAngle::GetBadRate( double Value, int nbNodes ) const
692 //const double aBestAngle = PI / nbNodes;
693 const double aBestAngle = 180.0 - ( 360.0 / double(nbNodes) );
694 return ( fabs( aBestAngle - Value ));
697 SMDSAbs_ElementType MinimumAngle::GetType() const
705 Description : Functor for calculating aspect ratio
707 double AspectRatio::GetValue( const TSequenceOfXYZ& P )
709 // According to "Mesh quality control" by Nadir Bouhamau referring to
710 // Pascal Jean Frey and Paul-Louis George. Maillages, applications aux elements finis.
711 // Hermes Science publications, Paris 1999 ISBN 2-7462-0024-4
714 int nbNodes = P.size();
719 // Compute aspect ratio
721 if ( nbNodes == 3 ) {
722 // Compute lengths of the sides
723 std::vector< double > aLen (nbNodes);
724 for ( int i = 0; i < nbNodes - 1; i++ )
725 aLen[ i ] = getDistance( P( i + 1 ), P( i + 2 ) );
726 aLen[ nbNodes - 1 ] = getDistance( P( 1 ), P( nbNodes ) );
727 // Q = alfa * h * p / S, where
729 // alfa = sqrt( 3 ) / 6
730 // h - length of the longest edge
731 // p - half perimeter
732 // S - triangle surface
733 const double alfa = sqrt( 3. ) / 6.;
734 double maxLen = Max( aLen[ 0 ], Max( aLen[ 1 ], aLen[ 2 ] ) );
735 double half_perimeter = ( aLen[0] + aLen[1] + aLen[2] ) / 2.;
736 double anArea = getArea( P( 1 ), P( 2 ), P( 3 ) );
737 if ( anArea <= Precision::Confusion() )
739 return alfa * maxLen * half_perimeter / anArea;
741 else if ( nbNodes == 6 ) { // quadratic triangles
742 // Compute lengths of the sides
743 std::vector< double > aLen (3);
744 aLen[0] = getDistance( P(1), P(3) );
745 aLen[1] = getDistance( P(3), P(5) );
746 aLen[2] = getDistance( P(5), P(1) );
747 // Q = alfa * h * p / S, where
749 // alfa = sqrt( 3 ) / 6
750 // h - length of the longest edge
751 // p - half perimeter
752 // S - triangle surface
753 const double alfa = sqrt( 3. ) / 6.;
754 double maxLen = Max( aLen[ 0 ], Max( aLen[ 1 ], aLen[ 2 ] ) );
755 double half_perimeter = ( aLen[0] + aLen[1] + aLen[2] ) / 2.;
756 double anArea = getArea( P(1), P(3), P(5) );
757 if ( anArea <= Precision::Confusion() )
759 return alfa * maxLen * half_perimeter / anArea;
761 else if( nbNodes == 4 ) { // quadrangle
762 // Compute lengths of the sides
763 std::vector< double > aLen (4);
764 aLen[0] = getDistance( P(1), P(2) );
765 aLen[1] = getDistance( P(2), P(3) );
766 aLen[2] = getDistance( P(3), P(4) );
767 aLen[3] = getDistance( P(4), P(1) );
768 // Compute lengths of the diagonals
769 std::vector< double > aDia (2);
770 aDia[0] = getDistance( P(1), P(3) );
771 aDia[1] = getDistance( P(2), P(4) );
772 // Compute areas of all triangles which can be built
773 // taking three nodes of the quadrangle
774 std::vector< double > anArea (4);
775 anArea[0] = getArea( P(1), P(2), P(3) );
776 anArea[1] = getArea( P(1), P(2), P(4) );
777 anArea[2] = getArea( P(1), P(3), P(4) );
778 anArea[3] = getArea( P(2), P(3), P(4) );
779 // Q = alpha * L * C1 / C2, where
781 // alpha = sqrt( 1/32 )
782 // L = max( L1, L2, L3, L4, D1, D2 )
783 // C1 = sqrt( ( L1^2 + L1^2 + L1^2 + L1^2 ) / 4 )
784 // C2 = min( S1, S2, S3, S4 )
785 // Li - lengths of the edges
786 // Di - lengths of the diagonals
787 // Si - areas of the triangles
788 const double alpha = sqrt( 1 / 32. );
789 double L = Max( aLen[ 0 ],
793 Max( aDia[ 0 ], aDia[ 1 ] ) ) ) ) );
794 double C1 = sqrt( ( aLen[0] * aLen[0] +
797 aLen[3] * aLen[3] ) / 4. );
798 double C2 = Min( anArea[ 0 ],
800 Min( anArea[ 2 ], anArea[ 3 ] ) ) );
801 if ( C2 <= Precision::Confusion() )
803 return alpha * L * C1 / C2;
805 else if( nbNodes == 8 ){ // nbNodes==8 - quadratic quadrangle
806 // Compute lengths of the sides
807 std::vector< double > aLen (4);
808 aLen[0] = getDistance( P(1), P(3) );
809 aLen[1] = getDistance( P(3), P(5) );
810 aLen[2] = getDistance( P(5), P(7) );
811 aLen[3] = getDistance( P(7), P(1) );
812 // Compute lengths of the diagonals
813 std::vector< double > aDia (2);
814 aDia[0] = getDistance( P(1), P(5) );
815 aDia[1] = getDistance( P(3), P(7) );
816 // Compute areas of all triangles which can be built
817 // taking three nodes of the quadrangle
818 std::vector< double > anArea (4);
819 anArea[0] = getArea( P(1), P(3), P(5) );
820 anArea[1] = getArea( P(1), P(3), P(7) );
821 anArea[2] = getArea( P(1), P(5), P(7) );
822 anArea[3] = getArea( P(3), P(5), P(7) );
823 // Q = alpha * L * C1 / C2, where
825 // alpha = sqrt( 1/32 )
826 // L = max( L1, L2, L3, L4, D1, D2 )
827 // C1 = sqrt( ( L1^2 + L1^2 + L1^2 + L1^2 ) / 4 )
828 // C2 = min( S1, S2, S3, S4 )
829 // Li - lengths of the edges
830 // Di - lengths of the diagonals
831 // Si - areas of the triangles
832 const double alpha = sqrt( 1 / 32. );
833 double L = Max( aLen[ 0 ],
837 Max( aDia[ 0 ], aDia[ 1 ] ) ) ) ) );
838 double C1 = sqrt( ( aLen[0] * aLen[0] +
841 aLen[3] * aLen[3] ) / 4. );
842 double C2 = Min( anArea[ 0 ],
844 Min( anArea[ 2 ], anArea[ 3 ] ) ) );
845 if ( C2 <= Precision::Confusion() )
847 return alpha * L * C1 / C2;
852 double AspectRatio::GetBadRate( double Value, int /*nbNodes*/ ) const
854 // the aspect ratio is in the range [1.0,infinity]
857 return Value / 1000.;
860 SMDSAbs_ElementType AspectRatio::GetType() const
867 Class : AspectRatio3D
868 Description : Functor for calculating aspect ratio
872 inline double getHalfPerimeter(double theTria[3]){
873 return (theTria[0] + theTria[1] + theTria[2])/2.0;
876 inline double getArea(double theHalfPerim, double theTria[3]){
877 return sqrt(theHalfPerim*
878 (theHalfPerim-theTria[0])*
879 (theHalfPerim-theTria[1])*
880 (theHalfPerim-theTria[2]));
883 inline double getVolume(double theLen[6]){
884 double a2 = theLen[0]*theLen[0];
885 double b2 = theLen[1]*theLen[1];
886 double c2 = theLen[2]*theLen[2];
887 double d2 = theLen[3]*theLen[3];
888 double e2 = theLen[4]*theLen[4];
889 double f2 = theLen[5]*theLen[5];
890 double P = 4.0*a2*b2*d2;
891 double Q = a2*(b2+d2-e2)-b2*(a2+d2-f2)-d2*(a2+b2-c2);
892 double R = (b2+d2-e2)*(a2+d2-f2)*(a2+d2-f2);
893 return sqrt(P-Q+R)/12.0;
896 inline double getVolume2(double theLen[6]){
897 double a2 = theLen[0]*theLen[0];
898 double b2 = theLen[1]*theLen[1];
899 double c2 = theLen[2]*theLen[2];
900 double d2 = theLen[3]*theLen[3];
901 double e2 = theLen[4]*theLen[4];
902 double f2 = theLen[5]*theLen[5];
904 double P = a2*e2*(b2+c2+d2+f2-a2-e2);
905 double Q = b2*f2*(a2+c2+d2+e2-b2-f2);
906 double R = c2*d2*(a2+b2+e2+f2-c2-d2);
907 double S = a2*b2*d2+b2*c2*e2+a2*c2*f2+d2*e2*f2;
909 return sqrt(P+Q+R-S)/12.0;
912 inline double getVolume(const TSequenceOfXYZ& P){
913 gp_Vec aVec1( P( 2 ) - P( 1 ) );
914 gp_Vec aVec2( P( 3 ) - P( 1 ) );
915 gp_Vec aVec3( P( 4 ) - P( 1 ) );
916 gp_Vec anAreaVec( aVec1 ^ aVec2 );
917 return fabs(aVec3 * anAreaVec) / 6.0;
920 inline double getMaxHeight(double theLen[6])
922 double aHeight = std::max(theLen[0],theLen[1]);
923 aHeight = std::max(aHeight,theLen[2]);
924 aHeight = std::max(aHeight,theLen[3]);
925 aHeight = std::max(aHeight,theLen[4]);
926 aHeight = std::max(aHeight,theLen[5]);
932 double AspectRatio3D::GetValue( const TSequenceOfXYZ& P )
934 double aQuality = 0.0;
935 if(myCurrElement->IsPoly()) return aQuality;
937 int nbNodes = P.size();
939 if(myCurrElement->IsQuadratic()) {
940 if(nbNodes==10) nbNodes=4; // quadratic tetrahedron
941 else if(nbNodes==13) nbNodes=5; // quadratic pyramid
942 else if(nbNodes==15) nbNodes=6; // quadratic pentahedron
943 else if(nbNodes==20) nbNodes=8; // quadratic hexahedron
944 else return aQuality;
950 getDistance(P( 1 ),P( 2 )), // a
951 getDistance(P( 2 ),P( 3 )), // b
952 getDistance(P( 3 ),P( 1 )), // c
953 getDistance(P( 2 ),P( 4 )), // d
954 getDistance(P( 3 ),P( 4 )), // e
955 getDistance(P( 1 ),P( 4 )) // f
957 double aTria[4][3] = {
958 {aLen[0],aLen[1],aLen[2]}, // abc
959 {aLen[0],aLen[3],aLen[5]}, // adf
960 {aLen[1],aLen[3],aLen[4]}, // bde
961 {aLen[2],aLen[4],aLen[5]} // cef
963 double aSumArea = 0.0;
964 double aHalfPerimeter = getHalfPerimeter(aTria[0]);
965 double anArea = getArea(aHalfPerimeter,aTria[0]);
967 aHalfPerimeter = getHalfPerimeter(aTria[1]);
968 anArea = getArea(aHalfPerimeter,aTria[1]);
970 aHalfPerimeter = getHalfPerimeter(aTria[2]);
971 anArea = getArea(aHalfPerimeter,aTria[2]);
973 aHalfPerimeter = getHalfPerimeter(aTria[3]);
974 anArea = getArea(aHalfPerimeter,aTria[3]);
976 double aVolume = getVolume(P);
977 //double aVolume = getVolume(aLen);
978 double aHeight = getMaxHeight(aLen);
979 static double aCoeff = sqrt(2.0)/12.0;
980 if ( aVolume > DBL_MIN )
981 aQuality = aCoeff*aHeight*aSumArea/aVolume;
986 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 3 ),P( 5 )};
987 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
990 gp_XYZ aXYZ[4] = {P( 1 ),P( 3 ),P( 4 ),P( 5 )};
991 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
994 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 5 )};
995 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
998 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 4 ),P( 5 )};
999 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1005 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 6 )};
1006 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1009 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 3 )};
1010 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1013 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 6 )};
1014 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1017 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
1018 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1021 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 6 )};
1022 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1025 gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 3 )};
1026 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1032 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )};
1033 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1036 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 4 )};
1037 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1040 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 7 )};
1041 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1044 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 8 )};
1045 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1048 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 3 )};
1049 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1052 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 4 )};
1053 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1056 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 7 )};
1057 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1060 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 8 )};
1061 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1064 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 3 )};
1065 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1068 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 4 )};
1069 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1072 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 7 )};
1073 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1076 gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 8 )};
1077 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1080 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 1 )};
1081 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1084 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 2 )};
1085 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1088 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 5 )};
1089 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1092 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 6 )};
1093 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1096 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 1 )};
1097 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1100 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 2 )};
1101 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1104 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 5 )};
1105 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1108 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 6 )};
1109 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1112 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 1 )};
1113 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1116 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
1117 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1120 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 5 )};
1121 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1124 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 6 )};
1125 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1128 gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )};
1129 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1132 gp_XYZ aXYZ[4] = {P( 4 ),P( 5 ),P( 8 ),P( 2 )};
1133 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1136 gp_XYZ aXYZ[4] = {P( 1 ),P( 4 ),P( 5 ),P( 3 )};
1137 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1140 gp_XYZ aXYZ[4] = {P( 3 ),P( 6 ),P( 7 ),P( 1 )};
1141 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1144 gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 6 ),P( 4 )};
1145 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1148 gp_XYZ aXYZ[4] = {P( 5 ),P( 6 ),P( 8 ),P( 3 )};
1149 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1152 gp_XYZ aXYZ[4] = {P( 7 ),P( 8 ),P( 6 ),P( 1 )};
1153 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1156 gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 7 )};
1157 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1160 gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 2 ),P( 5 )};
1161 aQuality = std::max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality);
1166 if ( nbNodes > 4 ) {
1167 // avaluate aspect ratio of quadranle faces
1168 AspectRatio aspect2D;
1169 SMDS_VolumeTool::VolumeType type = SMDS_VolumeTool::GetType( nbNodes );
1170 int nbFaces = SMDS_VolumeTool::NbFaces( type );
1171 TSequenceOfXYZ points(4);
1172 for ( int i = 0; i < nbFaces; ++i ) { // loop on faces of a volume
1173 if ( SMDS_VolumeTool::NbFaceNodes( type, i ) != 4 )
1175 const int* pInd = SMDS_VolumeTool::GetFaceNodesIndices( type, i, true );
1176 for ( int p = 0; p < 4; ++p ) // loop on nodes of a quadranle face
1177 points( p + 1 ) = P( pInd[ p ] + 1 );
1178 aQuality = std::max( aQuality, aspect2D.GetValue( points ));
1184 double AspectRatio3D::GetBadRate( double Value, int /*nbNodes*/ ) const
1186 // the aspect ratio is in the range [1.0,infinity]
1189 return Value / 1000.;
1192 SMDSAbs_ElementType AspectRatio3D::GetType() const
1194 return SMDSAbs_Volume;
1200 Description : Functor for calculating warping
1202 double Warping::GetValue( const TSequenceOfXYZ& P )
1204 if ( P.size() != 4 )
1207 gp_XYZ G = ( P( 1 ) + P( 2 ) + P( 3 ) + P( 4 ) ) / 4.;
1209 double A1 = ComputeA( P( 1 ), P( 2 ), P( 3 ), G );
1210 double A2 = ComputeA( P( 2 ), P( 3 ), P( 4 ), G );
1211 double A3 = ComputeA( P( 3 ), P( 4 ), P( 1 ), G );
1212 double A4 = ComputeA( P( 4 ), P( 1 ), P( 2 ), G );
1214 return Max( Max( A1, A2 ), Max( A3, A4 ) );
1217 double Warping::ComputeA( const gp_XYZ& thePnt1,
1218 const gp_XYZ& thePnt2,
1219 const gp_XYZ& thePnt3,
1220 const gp_XYZ& theG ) const
1222 double aLen1 = gp_Pnt( thePnt1 ).Distance( gp_Pnt( thePnt2 ) );
1223 double aLen2 = gp_Pnt( thePnt2 ).Distance( gp_Pnt( thePnt3 ) );
1224 double L = Min( aLen1, aLen2 ) * 0.5;
1225 if ( L < Precision::Confusion())
1228 gp_XYZ GI = ( thePnt2 + thePnt1 ) / 2. - theG;
1229 gp_XYZ GJ = ( thePnt3 + thePnt2 ) / 2. - theG;
1230 gp_XYZ N = GI.Crossed( GJ );
1232 if ( N.Modulus() < gp::Resolution() )
1237 double H = ( thePnt2 - theG ).Dot( N );
1238 return asin( fabs( H / L ) ) * 180. / PI;
1241 double Warping::GetBadRate( double Value, int /*nbNodes*/ ) const
1243 // the warp is in the range [0.0,PI/2]
1244 // 0.0 = good (no warp)
1245 // PI/2 = bad (face pliee)
1249 SMDSAbs_ElementType Warping::GetType() const
1251 return SMDSAbs_Face;
1257 Description : Functor for calculating taper
1259 double Taper::GetValue( const TSequenceOfXYZ& P )
1261 if ( P.size() != 4 )
1265 double J1 = getArea( P( 4 ), P( 1 ), P( 2 ) ) / 2.;
1266 double J2 = getArea( P( 3 ), P( 1 ), P( 2 ) ) / 2.;
1267 double J3 = getArea( P( 2 ), P( 3 ), P( 4 ) ) / 2.;
1268 double J4 = getArea( P( 3 ), P( 4 ), P( 1 ) ) / 2.;
1270 double JA = 0.25 * ( J1 + J2 + J3 + J4 );
1271 if ( JA <= Precision::Confusion() )
1274 double T1 = fabs( ( J1 - JA ) / JA );
1275 double T2 = fabs( ( J2 - JA ) / JA );
1276 double T3 = fabs( ( J3 - JA ) / JA );
1277 double T4 = fabs( ( J4 - JA ) / JA );
1279 return Max( Max( T1, T2 ), Max( T3, T4 ) );
1282 double Taper::GetBadRate( double Value, int /*nbNodes*/ ) const
1284 // the taper is in the range [0.0,1.0]
1285 // 0.0 = good (no taper)
1286 // 1.0 = bad (les cotes opposes sont allignes)
1290 SMDSAbs_ElementType Taper::GetType() const
1292 return SMDSAbs_Face;
1298 Description : Functor for calculating skew in degrees
1300 static inline double skewAngle( const gp_XYZ& p1, const gp_XYZ& p2, const gp_XYZ& p3 )
1302 gp_XYZ p12 = ( p2 + p1 ) / 2.;
1303 gp_XYZ p23 = ( p3 + p2 ) / 2.;
1304 gp_XYZ p31 = ( p3 + p1 ) / 2.;
1306 gp_Vec v1( p31 - p2 ), v2( p12 - p23 );
1308 return v1.Magnitude() < gp::Resolution() || v2.Magnitude() < gp::Resolution() ? 0. : v1.Angle( v2 );
1311 double Skew::GetValue( const TSequenceOfXYZ& P )
1313 if ( P.size() != 3 && P.size() != 4 )
1317 static double PI2 = PI / 2.;
1318 if ( P.size() == 3 )
1320 double A0 = fabs( PI2 - skewAngle( P( 3 ), P( 1 ), P( 2 ) ) );
1321 double A1 = fabs( PI2 - skewAngle( P( 1 ), P( 2 ), P( 3 ) ) );
1322 double A2 = fabs( PI2 - skewAngle( P( 2 ), P( 3 ), P( 1 ) ) );
1324 return Max( A0, Max( A1, A2 ) ) * 180. / PI;
1328 gp_XYZ p12 = ( P( 1 ) + P( 2 ) ) / 2.;
1329 gp_XYZ p23 = ( P( 2 ) + P( 3 ) ) / 2.;
1330 gp_XYZ p34 = ( P( 3 ) + P( 4 ) ) / 2.;
1331 gp_XYZ p41 = ( P( 4 ) + P( 1 ) ) / 2.;
1333 gp_Vec v1( p34 - p12 ), v2( p23 - p41 );
1334 double A = v1.Magnitude() <= gp::Resolution() || v2.Magnitude() <= gp::Resolution()
1335 ? 0. : fabs( PI2 - v1.Angle( v2 ) );
1338 if ( A < Precision::Angular() )
1341 return A * 180. / PI;
1345 double Skew::GetBadRate( double Value, int /*nbNodes*/ ) const
1347 // the skew is in the range [0.0,PI/2].
1353 SMDSAbs_ElementType Skew::GetType() const
1355 return SMDSAbs_Face;
1361 Description : Functor for calculating area
1363 double Area::GetValue( const TSequenceOfXYZ& P )
1366 if ( P.size() > 2 ) {
1367 gp_Vec aVec1( P(2) - P(1) );
1368 gp_Vec aVec2( P(3) - P(1) );
1369 gp_Vec SumVec = aVec1 ^ aVec2;
1370 for (int i=4; i<=P.size(); i++) {
1371 gp_Vec aVec1( P(i-1) - P(1) );
1372 gp_Vec aVec2( P(i) - P(1) );
1373 gp_Vec tmp = aVec1 ^ aVec2;
1376 val = SumVec.Magnitude() * 0.5;
1381 double Area::GetBadRate( double Value, int /*nbNodes*/ ) const
1383 // meaningless as it is not a quality control functor
1387 SMDSAbs_ElementType Area::GetType() const
1389 return SMDSAbs_Face;
1395 Description : Functor for calculating length off edge
1397 double Length::GetValue( const TSequenceOfXYZ& P )
1399 switch ( P.size() ) {
1400 case 2: return getDistance( P( 1 ), P( 2 ) );
1401 case 3: return getDistance( P( 1 ), P( 2 ) ) + getDistance( P( 2 ), P( 3 ) );
1406 double Length::GetBadRate( double Value, int /*nbNodes*/ ) const
1408 // meaningless as it is not quality control functor
1412 SMDSAbs_ElementType Length::GetType() const
1414 return SMDSAbs_Edge;
1419 Description : Functor for calculating length of edge
1422 double Length2D::GetValue( long theElementId)
1426 //cout<<"Length2D::GetValue"<<endl;
1427 if (GetPoints(theElementId,P)){
1428 //for(int jj=1; jj<=P.size(); jj++)
1429 // cout<<"jj="<<jj<<" P("<<P(jj).X()<<","<<P(jj).Y()<<","<<P(jj).Z()<<")"<<endl;
1431 double aVal;// = GetValue( P );
1432 const SMDS_MeshElement* aElem = myMesh->FindElement( theElementId );
1433 SMDSAbs_ElementType aType = aElem->GetType();
1442 aVal = getDistance( P( 1 ), P( 2 ) );
1445 else if (len == 3){ // quadratic edge
1446 aVal = getDistance(P( 1 ),P( 3 )) + getDistance(P( 3 ),P( 2 ));
1450 if (len == 3){ // triangles
1451 double L1 = getDistance(P( 1 ),P( 2 ));
1452 double L2 = getDistance(P( 2 ),P( 3 ));
1453 double L3 = getDistance(P( 3 ),P( 1 ));
1454 aVal = Max(L1,Max(L2,L3));
1457 else if (len == 4){ // quadrangles
1458 double L1 = getDistance(P( 1 ),P( 2 ));
1459 double L2 = getDistance(P( 2 ),P( 3 ));
1460 double L3 = getDistance(P( 3 ),P( 4 ));
1461 double L4 = getDistance(P( 4 ),P( 1 ));
1462 aVal = Max(Max(L1,L2),Max(L3,L4));
1465 if (len == 6){ // quadratic triangles
1466 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1467 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1468 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 1 ));
1469 aVal = Max(L1,Max(L2,L3));
1470 //cout<<"L1="<<L1<<" L2="<<L2<<"L3="<<L3<<" aVal="<<aVal<<endl;
1473 else if (len == 8){ // quadratic quadrangles
1474 double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 ));
1475 double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 ));
1476 double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 7 ));
1477 double L4 = getDistance(P( 7 ),P( 8 )) + getDistance(P( 8 ),P( 1 ));
1478 aVal = Max(Max(L1,L2),Max(L3,L4));
1481 case SMDSAbs_Volume:
1482 if (len == 4){ // tetraidrs
1483 double L1 = getDistance(P( 1 ),P( 2 ));
1484 double L2 = getDistance(P( 2 ),P( 3 ));
1485 double L3 = getDistance(P( 3 ),P( 1 ));
1486 double L4 = getDistance(P( 1 ),P( 4 ));
1487 double L5 = getDistance(P( 2 ),P( 4 ));
1488 double L6 = getDistance(P( 3 ),P( 4 ));
1489 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1492 else if (len == 5){ // piramids
1493 double L1 = getDistance(P( 1 ),P( 2 ));
1494 double L2 = getDistance(P( 2 ),P( 3 ));
1495 double L3 = getDistance(P( 3 ),P( 4 ));
1496 double L4 = getDistance(P( 4 ),P( 1 ));
1497 double L5 = getDistance(P( 1 ),P( 5 ));
1498 double L6 = getDistance(P( 2 ),P( 5 ));
1499 double L7 = getDistance(P( 3 ),P( 5 ));
1500 double L8 = getDistance(P( 4 ),P( 5 ));
1502 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1503 aVal = Max(aVal,Max(L7,L8));
1506 else if (len == 6){ // pentaidres
1507 double L1 = getDistance(P( 1 ),P( 2 ));
1508 double L2 = getDistance(P( 2 ),P( 3 ));
1509 double L3 = getDistance(P( 3 ),P( 1 ));
1510 double L4 = getDistance(P( 4 ),P( 5 ));
1511 double L5 = getDistance(P( 5 ),P( 6 ));
1512 double L6 = getDistance(P( 6 ),P( 4 ));
1513 double L7 = getDistance(P( 1 ),P( 4 ));
1514 double L8 = getDistance(P( 2 ),P( 5 ));
1515 double L9 = getDistance(P( 3 ),P( 6 ));
1517 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1518 aVal = Max(aVal,Max(Max(L7,L8),L9));
1521 else if (len == 8){ // hexaider
1522 double L1 = getDistance(P( 1 ),P( 2 ));
1523 double L2 = getDistance(P( 2 ),P( 3 ));
1524 double L3 = getDistance(P( 3 ),P( 4 ));
1525 double L4 = getDistance(P( 4 ),P( 1 ));
1526 double L5 = getDistance(P( 5 ),P( 6 ));
1527 double L6 = getDistance(P( 6 ),P( 7 ));
1528 double L7 = getDistance(P( 7 ),P( 8 ));
1529 double L8 = getDistance(P( 8 ),P( 5 ));
1530 double L9 = getDistance(P( 1 ),P( 5 ));
1531 double L10= getDistance(P( 2 ),P( 6 ));
1532 double L11= getDistance(P( 3 ),P( 7 ));
1533 double L12= getDistance(P( 4 ),P( 8 ));
1535 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1536 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
1537 aVal = Max(aVal,Max(L11,L12));
1542 if (len == 10){ // quadratic tetraidrs
1543 double L1 = getDistance(P( 1 ),P( 5 )) + getDistance(P( 5 ),P( 2 ));
1544 double L2 = getDistance(P( 2 ),P( 6 )) + getDistance(P( 6 ),P( 3 ));
1545 double L3 = getDistance(P( 3 ),P( 7 )) + getDistance(P( 7 ),P( 1 ));
1546 double L4 = getDistance(P( 1 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
1547 double L5 = getDistance(P( 2 ),P( 9 )) + getDistance(P( 9 ),P( 4 ));
1548 double L6 = getDistance(P( 3 ),P( 10 )) + getDistance(P( 10 ),P( 4 ));
1549 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1552 else if (len == 13){ // quadratic piramids
1553 double L1 = getDistance(P( 1 ),P( 6 )) + getDistance(P( 6 ),P( 2 ));
1554 double L2 = getDistance(P( 2 ),P( 7 )) + getDistance(P( 7 ),P( 3 ));
1555 double L3 = getDistance(P( 3 ),P( 8 )) + getDistance(P( 8 ),P( 4 ));
1556 double L4 = getDistance(P( 4 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1557 double L5 = getDistance(P( 1 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1558 double L6 = getDistance(P( 2 ),P( 11 )) + getDistance(P( 11 ),P( 5 ));
1559 double L7 = getDistance(P( 3 ),P( 12 )) + getDistance(P( 12 ),P( 5 ));
1560 double L8 = getDistance(P( 4 ),P( 13 )) + getDistance(P( 13 ),P( 5 ));
1561 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1562 aVal = Max(aVal,Max(L7,L8));
1565 else if (len == 15){ // quadratic pentaidres
1566 double L1 = getDistance(P( 1 ),P( 7 )) + getDistance(P( 7 ),P( 2 ));
1567 double L2 = getDistance(P( 2 ),P( 8 )) + getDistance(P( 8 ),P( 3 ));
1568 double L3 = getDistance(P( 3 ),P( 9 )) + getDistance(P( 9 ),P( 1 ));
1569 double L4 = getDistance(P( 4 ),P( 10 )) + getDistance(P( 10 ),P( 5 ));
1570 double L5 = getDistance(P( 5 ),P( 11 )) + getDistance(P( 11 ),P( 6 ));
1571 double L6 = getDistance(P( 6 ),P( 12 )) + getDistance(P( 12 ),P( 4 ));
1572 double L7 = getDistance(P( 1 ),P( 13 )) + getDistance(P( 13 ),P( 4 ));
1573 double L8 = getDistance(P( 2 ),P( 14 )) + getDistance(P( 14 ),P( 5 ));
1574 double L9 = getDistance(P( 3 ),P( 15 )) + getDistance(P( 15 ),P( 6 ));
1575 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1576 aVal = Max(aVal,Max(Max(L7,L8),L9));
1579 else if (len == 20){ // quadratic hexaider
1580 double L1 = getDistance(P( 1 ),P( 9 )) + getDistance(P( 9 ),P( 2 ));
1581 double L2 = getDistance(P( 2 ),P( 10 )) + getDistance(P( 10 ),P( 3 ));
1582 double L3 = getDistance(P( 3 ),P( 11 )) + getDistance(P( 11 ),P( 4 ));
1583 double L4 = getDistance(P( 4 ),P( 12 )) + getDistance(P( 12 ),P( 1 ));
1584 double L5 = getDistance(P( 5 ),P( 13 )) + getDistance(P( 13 ),P( 6 ));
1585 double L6 = getDistance(P( 6 ),P( 14 )) + getDistance(P( 14 ),P( 7 ));
1586 double L7 = getDistance(P( 7 ),P( 15 )) + getDistance(P( 15 ),P( 8 ));
1587 double L8 = getDistance(P( 8 ),P( 16 )) + getDistance(P( 16 ),P( 5 ));
1588 double L9 = getDistance(P( 1 ),P( 17 )) + getDistance(P( 17 ),P( 5 ));
1589 double L10= getDistance(P( 2 ),P( 18 )) + getDistance(P( 18 ),P( 6 ));
1590 double L11= getDistance(P( 3 ),P( 19 )) + getDistance(P( 19 ),P( 7 ));
1591 double L12= getDistance(P( 4 ),P( 20 )) + getDistance(P( 20 ),P( 8 ));
1592 aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6));
1593 aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10)));
1594 aVal = Max(aVal,Max(L11,L12));
1606 if ( myPrecision >= 0 )
1608 double prec = pow( 10., (double)( myPrecision ) );
1609 aVal = floor( aVal * prec + 0.5 ) / prec;
1618 double Length2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1620 // meaningless as it is not quality control functor
1624 SMDSAbs_ElementType Length2D::GetType() const
1626 return SMDSAbs_Face;
1629 Length2D::Value::Value(double theLength,long thePntId1, long thePntId2):
1632 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1633 if(thePntId1 > thePntId2){
1634 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1638 bool Length2D::Value::operator<(const Length2D::Value& x) const{
1639 if(myPntId[0] < x.myPntId[0]) return true;
1640 if(myPntId[0] == x.myPntId[0])
1641 if(myPntId[1] < x.myPntId[1]) return true;
1645 void Length2D::GetValues(TValues& theValues){
1647 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1648 for(; anIter->more(); ){
1649 const SMDS_MeshFace* anElem = anIter->next();
1651 if(anElem->IsQuadratic()) {
1652 const SMDS_VtkFace* F =
1653 dynamic_cast<const SMDS_VtkFace*>(anElem);
1654 // use special nodes iterator
1655 SMDS_ElemIteratorPtr anIter = F->interlacedNodesElemIterator();
1660 const SMDS_MeshElement* aNode;
1662 aNode = anIter->next();
1663 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1664 P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1665 aNodeId[0] = aNodeId[1] = aNode->GetID();
1668 for(; anIter->more(); ){
1669 const SMDS_MeshNode* N1 = static_cast<const SMDS_MeshNode*> (anIter->next());
1670 P[2] = gp_Pnt(N1->X(),N1->Y(),N1->Z());
1671 aNodeId[2] = N1->GetID();
1672 aLength = P[1].Distance(P[2]);
1673 if(!anIter->more()) break;
1674 const SMDS_MeshNode* N2 = static_cast<const SMDS_MeshNode*> (anIter->next());
1675 P[3] = gp_Pnt(N2->X(),N2->Y(),N2->Z());
1676 aNodeId[3] = N2->GetID();
1677 aLength += P[2].Distance(P[3]);
1678 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1679 Value aValue2(aLength,aNodeId[2],aNodeId[3]);
1681 aNodeId[1] = aNodeId[3];
1682 theValues.insert(aValue1);
1683 theValues.insert(aValue2);
1685 aLength += P[2].Distance(P[0]);
1686 Value aValue1(aLength,aNodeId[1],aNodeId[2]);
1687 Value aValue2(aLength,aNodeId[2],aNodeId[0]);
1688 theValues.insert(aValue1);
1689 theValues.insert(aValue2);
1692 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
1697 const SMDS_MeshElement* aNode;
1698 if(aNodesIter->more()){
1699 aNode = aNodesIter->next();
1700 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1701 P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1702 aNodeId[0] = aNodeId[1] = aNode->GetID();
1705 for(; aNodesIter->more(); ){
1706 aNode = aNodesIter->next();
1707 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode;
1708 long anId = aNode->GetID();
1710 P[2] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z());
1712 aLength = P[1].Distance(P[2]);
1714 Value aValue(aLength,aNodeId[1],anId);
1717 theValues.insert(aValue);
1720 aLength = P[0].Distance(P[1]);
1722 Value aValue(aLength,aNodeId[0],aNodeId[1]);
1723 theValues.insert(aValue);
1729 Class : MultiConnection
1730 Description : Functor for calculating number of faces conneted to the edge
1732 double MultiConnection::GetValue( const TSequenceOfXYZ& P )
1736 double MultiConnection::GetValue( long theId )
1738 return getNbMultiConnection( myMesh, theId );
1741 double MultiConnection::GetBadRate( double Value, int /*nbNodes*/ ) const
1743 // meaningless as it is not quality control functor
1747 SMDSAbs_ElementType MultiConnection::GetType() const
1749 return SMDSAbs_Edge;
1753 Class : MultiConnection2D
1754 Description : Functor for calculating number of faces conneted to the edge
1756 double MultiConnection2D::GetValue( const TSequenceOfXYZ& P )
1761 double MultiConnection2D::GetValue( long theElementId )
1765 const SMDS_MeshElement* aFaceElem = myMesh->FindElement(theElementId);
1766 SMDSAbs_ElementType aType = aFaceElem->GetType();
1771 int i = 0, len = aFaceElem->NbNodes();
1772 SMDS_ElemIteratorPtr anIter = aFaceElem->nodesIterator();
1775 const SMDS_MeshNode *aNode, *aNode0;
1776 TColStd_MapOfInteger aMap, aMapPrev;
1778 for (i = 0; i <= len; i++) {
1783 if (anIter->more()) {
1784 aNode = (SMDS_MeshNode*)anIter->next();
1792 if (i == 0) aNode0 = aNode;
1794 SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator();
1795 while (anElemIter->more()) {
1796 const SMDS_MeshElement* anElem = anElemIter->next();
1797 if (anElem != 0 && anElem->GetType() == SMDSAbs_Face) {
1798 int anId = anElem->GetID();
1801 if (aMapPrev.Contains(anId)) {
1806 aResult = Max(aResult, aNb);
1817 double MultiConnection2D::GetBadRate( double Value, int /*nbNodes*/ ) const
1819 // meaningless as it is not quality control functor
1823 SMDSAbs_ElementType MultiConnection2D::GetType() const
1825 return SMDSAbs_Face;
1828 MultiConnection2D::Value::Value(long thePntId1, long thePntId2)
1830 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
1831 if(thePntId1 > thePntId2){
1832 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
1836 bool MultiConnection2D::Value::operator<(const MultiConnection2D::Value& x) const{
1837 if(myPntId[0] < x.myPntId[0]) return true;
1838 if(myPntId[0] == x.myPntId[0])
1839 if(myPntId[1] < x.myPntId[1]) return true;
1843 void MultiConnection2D::GetValues(MValues& theValues){
1844 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1845 for(; anIter->more(); ){
1846 const SMDS_MeshFace* anElem = anIter->next();
1847 SMDS_ElemIteratorPtr aNodesIter;
1848 if ( anElem->IsQuadratic() )
1849 aNodesIter = dynamic_cast<const SMDS_VtkFace*>
1850 (anElem)->interlacedNodesElemIterator();
1852 aNodesIter = anElem->nodesIterator();
1855 //int aNbConnects=0;
1856 const SMDS_MeshNode* aNode0;
1857 const SMDS_MeshNode* aNode1;
1858 const SMDS_MeshNode* aNode2;
1859 if(aNodesIter->more()){
1860 aNode0 = (SMDS_MeshNode*) aNodesIter->next();
1862 const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode1;
1863 aNodeId[0] = aNodeId[1] = aNodes->GetID();
1865 for(; aNodesIter->more(); ) {
1866 aNode2 = (SMDS_MeshNode*) aNodesIter->next();
1867 long anId = aNode2->GetID();
1870 Value aValue(aNodeId[1],aNodeId[2]);
1871 MValues::iterator aItr = theValues.find(aValue);
1872 if (aItr != theValues.end()){
1877 theValues[aValue] = 1;
1880 //cout << "NodeIds: "<<aNodeId[1]<<","<<aNodeId[2]<<" nbconn="<<aNbConnects<<endl;
1881 aNodeId[1] = aNodeId[2];
1884 Value aValue(aNodeId[0],aNodeId[2]);
1885 MValues::iterator aItr = theValues.find(aValue);
1886 if (aItr != theValues.end()) {
1891 theValues[aValue] = 1;
1894 //cout << "NodeIds: "<<aNodeId[0]<<","<<aNodeId[2]<<" nbconn="<<aNbConnects<<endl;
1904 Class : BadOrientedVolume
1905 Description : Predicate bad oriented volumes
1908 BadOrientedVolume::BadOrientedVolume()
1913 void BadOrientedVolume::SetMesh( const SMDS_Mesh* theMesh )
1918 bool BadOrientedVolume::IsSatisfy( long theId )
1923 SMDS_VolumeTool vTool( myMesh->FindElement( theId ));
1924 return !vTool.IsForward();
1927 SMDSAbs_ElementType BadOrientedVolume::GetType() const
1929 return SMDSAbs_Volume;
1933 Class : BareBorderVolume
1936 bool BareBorderVolume::IsSatisfy(long theElementId )
1938 SMDS_VolumeTool myTool;
1939 if ( myTool.Set( myMesh->FindElement(theElementId)))
1941 for ( int iF = 0; iF < myTool.NbFaces(); ++iF )
1942 if ( myTool.IsFreeFace( iF ))
1944 const SMDS_MeshNode** n = myTool.GetFaceNodes(iF);
1945 vector< const SMDS_MeshNode*> nodes( n, n+myTool.NbFaceNodes(iF));
1946 if ( !myMesh->FindElement( nodes, SMDSAbs_Face, /*Nomedium=*/false))
1954 Class : BareBorderFace
1957 bool BareBorderFace::IsSatisfy(long theElementId )
1960 if ( const SMDS_MeshElement* face = myMesh->FindElement(theElementId))
1962 if ( face->GetType() == SMDSAbs_Face )
1964 int nbN = face->NbCornerNodes();
1965 for ( int i = 0; i < nbN && !ok; ++i )
1967 // check if a link is shared by another face
1968 const SMDS_MeshNode* n1 = face->GetNode( i );
1969 const SMDS_MeshNode* n2 = face->GetNode( (i+1)%nbN );
1970 SMDS_ElemIteratorPtr fIt = n1->GetInverseElementIterator( SMDSAbs_Face );
1971 bool isShared = false;
1972 while ( !isShared && fIt->more() )
1974 const SMDS_MeshElement* f = fIt->next();
1975 isShared = ( f != face && f->GetNodeIndex(n2) != -1 );
1979 myLinkNodes.resize( 2 + face->IsQuadratic());
1980 myLinkNodes[0] = n1;
1981 myLinkNodes[1] = n2;
1982 if ( face->IsQuadratic() )
1983 myLinkNodes[2] = face->GetNode( i+nbN );
1984 ok = !myMesh->FindElement( myLinkNodes, SMDSAbs_Edge, /*noMedium=*/false);
1993 Class : OverConstrainedVolume
1996 bool OverConstrainedVolume::IsSatisfy(long theElementId )
1998 // An element is over-constrained if it has N-1 free borders where
1999 // N is the number of edges/faces for a 2D/3D element.
2000 SMDS_VolumeTool myTool;
2001 if ( myTool.Set( myMesh->FindElement(theElementId)))
2003 int nbSharedFaces = 0;
2004 for ( int iF = 0; iF < myTool.NbFaces(); ++iF )
2005 if ( !myTool.IsFreeFace( iF ) && ++nbSharedFaces > 1 )
2007 return ( nbSharedFaces == 1 );
2013 Class : OverConstrainedFace
2016 bool OverConstrainedFace::IsSatisfy(long theElementId )
2018 // An element is over-constrained if it has N-1 free borders where
2019 // N is the number of edges/faces for a 2D/3D element.
2020 if ( const SMDS_MeshElement* face = myMesh->FindElement(theElementId))
2021 if ( face->GetType() == SMDSAbs_Face )
2023 int nbSharedBorders = 0;
2024 int nbN = face->NbCornerNodes();
2025 for ( int i = 0; i < nbN; ++i )
2027 // check if a link is shared by another face
2028 const SMDS_MeshNode* n1 = face->GetNode( i );
2029 const SMDS_MeshNode* n2 = face->GetNode( (i+1)%nbN );
2030 SMDS_ElemIteratorPtr fIt = n1->GetInverseElementIterator( SMDSAbs_Face );
2031 bool isShared = false;
2032 while ( !isShared && fIt->more() )
2034 const SMDS_MeshElement* f = fIt->next();
2035 isShared = ( f != face && f->GetNodeIndex(n2) != -1 );
2037 if ( isShared && ++nbSharedBorders > 1 )
2040 return ( nbSharedBorders == 1 );
2047 Description : Predicate for free borders
2050 FreeBorders::FreeBorders()
2055 void FreeBorders::SetMesh( const SMDS_Mesh* theMesh )
2060 bool FreeBorders::IsSatisfy( long theId )
2062 return getNbMultiConnection( myMesh, theId ) == 1;
2065 SMDSAbs_ElementType FreeBorders::GetType() const
2067 return SMDSAbs_Edge;
2073 Description : Predicate for free Edges
2075 FreeEdges::FreeEdges()
2080 void FreeEdges::SetMesh( const SMDS_Mesh* theMesh )
2085 bool FreeEdges::IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId )
2087 TColStd_MapOfInteger aMap;
2088 for ( int i = 0; i < 2; i++ )
2090 SMDS_ElemIteratorPtr anElemIter = theNodes[ i ]->GetInverseElementIterator();
2091 while( anElemIter->more() )
2093 const SMDS_MeshElement* anElem = anElemIter->next();
2094 if ( anElem != 0 && anElem->GetType() == SMDSAbs_Face )
2096 int anId = anElem->GetID();
2100 else if ( aMap.Contains( anId ) && anId != theFaceId )
2108 bool FreeEdges::IsSatisfy( long theId )
2113 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
2114 if ( aFace == 0 || aFace->GetType() != SMDSAbs_Face || aFace->NbNodes() < 3 )
2117 SMDS_ElemIteratorPtr anIter;
2118 if ( aFace->IsQuadratic() ) {
2119 anIter = dynamic_cast<const SMDS_VtkFace*>
2120 (aFace)->interlacedNodesElemIterator();
2123 anIter = aFace->nodesIterator();
2128 int i = 0, nbNodes = aFace->NbNodes();
2129 std::vector <const SMDS_MeshNode*> aNodes( nbNodes+1 );
2130 while( anIter->more() )
2132 const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next();
2135 aNodes[ i++ ] = aNode;
2137 aNodes[ nbNodes ] = aNodes[ 0 ];
2139 for ( i = 0; i < nbNodes; i++ )
2140 if ( IsFreeEdge( &aNodes[ i ], theId ) )
2146 SMDSAbs_ElementType FreeEdges::GetType() const
2148 return SMDSAbs_Face;
2151 FreeEdges::Border::Border(long theElemId, long thePntId1, long thePntId2):
2154 myPntId[0] = thePntId1; myPntId[1] = thePntId2;
2155 if(thePntId1 > thePntId2){
2156 myPntId[1] = thePntId1; myPntId[0] = thePntId2;
2160 bool FreeEdges::Border::operator<(const FreeEdges::Border& x) const{
2161 if(myPntId[0] < x.myPntId[0]) return true;
2162 if(myPntId[0] == x.myPntId[0])
2163 if(myPntId[1] < x.myPntId[1]) return true;
2167 inline void UpdateBorders(const FreeEdges::Border& theBorder,
2168 FreeEdges::TBorders& theRegistry,
2169 FreeEdges::TBorders& theContainer)
2171 if(theRegistry.find(theBorder) == theRegistry.end()){
2172 theRegistry.insert(theBorder);
2173 theContainer.insert(theBorder);
2175 theContainer.erase(theBorder);
2179 void FreeEdges::GetBoreders(TBorders& theBorders)
2182 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
2183 for(; anIter->more(); ){
2184 const SMDS_MeshFace* anElem = anIter->next();
2185 long anElemId = anElem->GetID();
2186 SMDS_ElemIteratorPtr aNodesIter;
2187 if ( anElem->IsQuadratic() )
2188 aNodesIter = static_cast<const SMDS_VtkFace*>(anElem)->
2189 interlacedNodesElemIterator();
2191 aNodesIter = anElem->nodesIterator();
2193 const SMDS_MeshElement* aNode;
2194 if(aNodesIter->more()){
2195 aNode = aNodesIter->next();
2196 aNodeId[0] = aNodeId[1] = aNode->GetID();
2198 for(; aNodesIter->more(); ){
2199 aNode = aNodesIter->next();
2200 long anId = aNode->GetID();
2201 Border aBorder(anElemId,aNodeId[1],anId);
2203 //std::cout<<aBorder.myPntId[0]<<"; "<<aBorder.myPntId[1]<<"; "<<aBorder.myElemId<<endl;
2204 UpdateBorders(aBorder,aRegistry,theBorders);
2206 Border aBorder(anElemId,aNodeId[0],aNodeId[1]);
2207 //std::cout<<aBorder.myPntId[0]<<"; "<<aBorder.myPntId[1]<<"; "<<aBorder.myElemId<<endl;
2208 UpdateBorders(aBorder,aRegistry,theBorders);
2210 //std::cout<<"theBorders.size() = "<<theBorders.size()<<endl;
2216 Description : Predicate for free nodes
2219 FreeNodes::FreeNodes()
2224 void FreeNodes::SetMesh( const SMDS_Mesh* theMesh )
2229 bool FreeNodes::IsSatisfy( long theNodeId )
2231 const SMDS_MeshNode* aNode = myMesh->FindNode( theNodeId );
2235 return (aNode->NbInverseElements() < 1);
2238 SMDSAbs_ElementType FreeNodes::GetType() const
2240 return SMDSAbs_Node;
2246 Description : Predicate for free faces
2249 FreeFaces::FreeFaces()
2254 void FreeFaces::SetMesh( const SMDS_Mesh* theMesh )
2259 bool FreeFaces::IsSatisfy( long theId )
2261 if (!myMesh) return false;
2262 // check that faces nodes refers to less than two common volumes
2263 const SMDS_MeshElement* aFace = myMesh->FindElement( theId );
2264 if ( !aFace || aFace->GetType() != SMDSAbs_Face )
2267 int nbNode = aFace->NbNodes();
2269 // collect volumes check that number of volumss with count equal nbNode not less than 2
2270 typedef map< SMDS_MeshElement*, int > TMapOfVolume; // map of volume counters
2271 typedef map< SMDS_MeshElement*, int >::iterator TItrMapOfVolume; // iterator
2272 TMapOfVolume mapOfVol;
2274 SMDS_ElemIteratorPtr nodeItr = aFace->nodesIterator();
2275 while ( nodeItr->more() ) {
2276 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(nodeItr->next());
2277 if ( !aNode ) continue;
2278 SMDS_ElemIteratorPtr volItr = aNode->GetInverseElementIterator(SMDSAbs_Volume);
2279 while ( volItr->more() ) {
2280 SMDS_MeshElement* aVol = (SMDS_MeshElement*)volItr->next();
2281 TItrMapOfVolume itr = mapOfVol.insert(make_pair(aVol, 0)).first;
2286 TItrMapOfVolume volItr = mapOfVol.begin();
2287 TItrMapOfVolume volEnd = mapOfVol.end();
2288 for ( ; volItr != volEnd; ++volItr )
2289 if ( (*volItr).second >= nbNode )
2291 // face is not free if number of volumes constructed on thier nodes more than one
2295 SMDSAbs_ElementType FreeFaces::GetType() const
2297 return SMDSAbs_Face;
2301 Class : LinearOrQuadratic
2302 Description : Predicate to verify whether a mesh element is linear
2305 LinearOrQuadratic::LinearOrQuadratic()
2310 void LinearOrQuadratic::SetMesh( const SMDS_Mesh* theMesh )
2315 bool LinearOrQuadratic::IsSatisfy( long theId )
2317 if (!myMesh) return false;
2318 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2319 if ( !anElem || (myType != SMDSAbs_All && anElem->GetType() != myType) )
2321 return (!anElem->IsQuadratic());
2324 void LinearOrQuadratic::SetType( SMDSAbs_ElementType theType )
2329 SMDSAbs_ElementType LinearOrQuadratic::GetType() const
2336 Description : Functor for check color of group to whic mesh element belongs to
2339 GroupColor::GroupColor()
2343 bool GroupColor::IsSatisfy( long theId )
2345 return (myIDs.find( theId ) != myIDs.end());
2348 void GroupColor::SetType( SMDSAbs_ElementType theType )
2353 SMDSAbs_ElementType GroupColor::GetType() const
2358 static bool isEqual( const Quantity_Color& theColor1,
2359 const Quantity_Color& theColor2 )
2361 // tolerance to compare colors
2362 const double tol = 5*1e-3;
2363 return ( fabs( theColor1.Red() - theColor2.Red() ) < tol &&
2364 fabs( theColor1.Green() - theColor2.Green() ) < tol &&
2365 fabs( theColor1.Blue() - theColor2.Blue() ) < tol );
2369 void GroupColor::SetMesh( const SMDS_Mesh* theMesh )
2373 const SMESHDS_Mesh* aMesh = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
2377 int nbGrp = aMesh->GetNbGroups();
2381 // iterates on groups and find necessary elements ids
2382 const std::set<SMESHDS_GroupBase*>& aGroups = aMesh->GetGroups();
2383 set<SMESHDS_GroupBase*>::const_iterator GrIt = aGroups.begin();
2384 for (; GrIt != aGroups.end(); GrIt++) {
2385 SMESHDS_GroupBase* aGrp = (*GrIt);
2388 // check type and color of group
2389 if ( !isEqual( myColor, aGrp->GetColor() ) )
2391 if ( myType != SMDSAbs_All && myType != (SMDSAbs_ElementType)aGrp->GetType() )
2394 SMDSAbs_ElementType aGrpElType = (SMDSAbs_ElementType)aGrp->GetType();
2395 if ( myType == aGrpElType || (myType == SMDSAbs_All && aGrpElType != SMDSAbs_Node) ) {
2396 // add elements IDS into control
2397 int aSize = aGrp->Extent();
2398 for (int i = 0; i < aSize; i++)
2399 myIDs.insert( aGrp->GetID(i+1) );
2404 void GroupColor::SetColorStr( const TCollection_AsciiString& theStr )
2406 TCollection_AsciiString aStr = theStr;
2407 aStr.RemoveAll( ' ' );
2408 aStr.RemoveAll( '\t' );
2409 for ( int aPos = aStr.Search( ";;" ); aPos != -1; aPos = aStr.Search( ";;" ) )
2410 aStr.Remove( aPos, 2 );
2411 Standard_Real clr[3];
2412 clr[0] = clr[1] = clr[2] = 0.;
2413 for ( int i = 0; i < 3; i++ ) {
2414 TCollection_AsciiString tmpStr = aStr.Token( ";", i+1 );
2415 if ( !tmpStr.IsEmpty() && tmpStr.IsRealValue() )
2416 clr[i] = tmpStr.RealValue();
2418 myColor = Quantity_Color( clr[0], clr[1], clr[2], Quantity_TOC_RGB );
2421 //=======================================================================
2422 // name : GetRangeStr
2423 // Purpose : Get range as a string.
2424 // Example: "1,2,3,50-60,63,67,70-"
2425 //=======================================================================
2426 void GroupColor::GetColorStr( TCollection_AsciiString& theResStr ) const
2429 theResStr += TCollection_AsciiString( myColor.Red() );
2430 theResStr += TCollection_AsciiString( ";" ) + TCollection_AsciiString( myColor.Green() );
2431 theResStr += TCollection_AsciiString( ";" ) + TCollection_AsciiString( myColor.Blue() );
2435 Class : ElemGeomType
2436 Description : Predicate to check element geometry type
2439 ElemGeomType::ElemGeomType()
2442 myType = SMDSAbs_All;
2443 myGeomType = SMDSGeom_TRIANGLE;
2446 void ElemGeomType::SetMesh( const SMDS_Mesh* theMesh )
2451 bool ElemGeomType::IsSatisfy( long theId )
2453 if (!myMesh) return false;
2454 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2457 const SMDSAbs_ElementType anElemType = anElem->GetType();
2458 if ( myType != SMDSAbs_All && anElemType != myType )
2460 const int aNbNode = anElem->NbNodes();
2462 switch( anElemType )
2465 isOk = (myGeomType == SMDSGeom_POINT);
2469 isOk = (myGeomType == SMDSGeom_EDGE);
2473 if ( myGeomType == SMDSGeom_TRIANGLE )
2474 isOk = (!anElem->IsPoly() && (anElem->IsQuadratic() ? aNbNode == 6 : aNbNode == 3));
2475 else if ( myGeomType == SMDSGeom_QUADRANGLE )
2476 isOk = (!anElem->IsPoly() && (anElem->IsQuadratic() ? aNbNode == 8 : aNbNode == 4));
2477 else if ( myGeomType == SMDSGeom_POLYGON )
2478 isOk = anElem->IsPoly();
2481 case SMDSAbs_Volume:
2482 if ( myGeomType == SMDSGeom_TETRA )
2483 isOk = (!anElem->IsPoly() && (anElem->IsQuadratic() ? aNbNode == 10 : aNbNode == 4));
2484 else if ( myGeomType == SMDSGeom_PYRAMID )
2485 isOk = (!anElem->IsPoly() && (anElem->IsQuadratic() ? aNbNode == 13 : aNbNode == 5));
2486 else if ( myGeomType == SMDSGeom_PENTA )
2487 isOk = (!anElem->IsPoly() && (anElem->IsQuadratic() ? aNbNode == 15 : aNbNode == 6));
2488 else if ( myGeomType == SMDSGeom_HEXA )
2489 isOk = (!anElem->IsPoly() && (anElem->IsQuadratic() ? aNbNode == 20 : aNbNode == 8));
2490 else if ( myGeomType == SMDSGeom_POLYHEDRA )
2491 isOk = anElem->IsPoly();
2498 void ElemGeomType::SetType( SMDSAbs_ElementType theType )
2503 SMDSAbs_ElementType ElemGeomType::GetType() const
2508 void ElemGeomType::SetGeomType( SMDSAbs_GeometryType theType )
2510 myGeomType = theType;
2513 SMDSAbs_GeometryType ElemGeomType::GetGeomType() const
2518 //================================================================================
2520 * \brief Class CoplanarFaces
2522 //================================================================================
2524 CoplanarFaces::CoplanarFaces()
2525 : myMesh(0), myFaceID(0), myToler(0)
2528 bool CoplanarFaces::IsSatisfy( long theElementId )
2530 if ( myCoplanarIDs.empty() )
2532 // Build a set of coplanar face ids
2534 if ( !myMesh || !myFaceID || !myToler )
2537 const SMDS_MeshElement* face = myMesh->FindElement( myFaceID );
2538 if ( !face || face->GetType() != SMDSAbs_Face )
2542 gp_Vec myNorm = getNormale( static_cast<const SMDS_MeshFace*>(face), &normOK );
2546 const double radianTol = myToler * PI180;
2547 typedef SMDS_StdIterator< const SMDS_MeshElement*, SMDS_ElemIteratorPtr > TFaceIt;
2548 std::set<const SMDS_MeshElement*> checkedFaces, checkedNodes;
2549 std::list<const SMDS_MeshElement*> faceQueue( 1, face );
2550 while ( !faceQueue.empty() )
2552 face = faceQueue.front();
2553 if ( checkedFaces.insert( face ).second )
2555 gp_Vec norm = getNormale( static_cast<const SMDS_MeshFace*>(face), &normOK );
2556 if (!normOK || myNorm.Angle( norm ) <= radianTol)
2558 myCoplanarIDs.insert( face->GetID() );
2559 std::set<const SMDS_MeshElement*> neighborFaces;
2560 for ( int i = 0; i < face->NbCornerNodes(); ++i )
2562 const SMDS_MeshNode* n = face->GetNode( i );
2563 if ( checkedNodes.insert( n ).second )
2564 neighborFaces.insert( TFaceIt( n->GetInverseElementIterator(SMDSAbs_Face)),
2567 faceQueue.insert( faceQueue.end(), neighborFaces.begin(), neighborFaces.end() );
2570 faceQueue.pop_front();
2573 return myCoplanarIDs.count( theElementId );
2578 *Description : Predicate for Range of Ids.
2579 * Range may be specified with two ways.
2580 * 1. Using AddToRange method
2581 * 2. With SetRangeStr method. Parameter of this method is a string
2582 * like as "1,2,3,50-60,63,67,70-"
2585 //=======================================================================
2586 // name : RangeOfIds
2587 // Purpose : Constructor
2588 //=======================================================================
2589 RangeOfIds::RangeOfIds()
2592 myType = SMDSAbs_All;
2595 //=======================================================================
2597 // Purpose : Set mesh
2598 //=======================================================================
2599 void RangeOfIds::SetMesh( const SMDS_Mesh* theMesh )
2604 //=======================================================================
2605 // name : AddToRange
2606 // Purpose : Add ID to the range
2607 //=======================================================================
2608 bool RangeOfIds::AddToRange( long theEntityId )
2610 myIds.Add( theEntityId );
2614 //=======================================================================
2615 // name : GetRangeStr
2616 // Purpose : Get range as a string.
2617 // Example: "1,2,3,50-60,63,67,70-"
2618 //=======================================================================
2619 void RangeOfIds::GetRangeStr( TCollection_AsciiString& theResStr )
2623 TColStd_SequenceOfInteger anIntSeq;
2624 TColStd_SequenceOfAsciiString aStrSeq;
2626 TColStd_MapIteratorOfMapOfInteger anIter( myIds );
2627 for ( ; anIter.More(); anIter.Next() )
2629 int anId = anIter.Key();
2630 TCollection_AsciiString aStr( anId );
2631 anIntSeq.Append( anId );
2632 aStrSeq.Append( aStr );
2635 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
2637 int aMinId = myMin( i );
2638 int aMaxId = myMax( i );
2640 TCollection_AsciiString aStr;
2641 if ( aMinId != IntegerFirst() )
2646 if ( aMaxId != IntegerLast() )
2649 // find position of the string in result sequence and insert string in it
2650 if ( anIntSeq.Length() == 0 )
2652 anIntSeq.Append( aMinId );
2653 aStrSeq.Append( aStr );
2657 if ( aMinId < anIntSeq.First() )
2659 anIntSeq.Prepend( aMinId );
2660 aStrSeq.Prepend( aStr );
2662 else if ( aMinId > anIntSeq.Last() )
2664 anIntSeq.Append( aMinId );
2665 aStrSeq.Append( aStr );
2668 for ( int j = 1, k = anIntSeq.Length(); j <= k; j++ )
2669 if ( aMinId < anIntSeq( j ) )
2671 anIntSeq.InsertBefore( j, aMinId );
2672 aStrSeq.InsertBefore( j, aStr );
2678 if ( aStrSeq.Length() == 0 )
2681 theResStr = aStrSeq( 1 );
2682 for ( int j = 2, k = aStrSeq.Length(); j <= k; j++ )
2685 theResStr += aStrSeq( j );
2689 //=======================================================================
2690 // name : SetRangeStr
2691 // Purpose : Define range with string
2692 // Example of entry string: "1,2,3,50-60,63,67,70-"
2693 //=======================================================================
2694 bool RangeOfIds::SetRangeStr( const TCollection_AsciiString& theStr )
2700 TCollection_AsciiString aStr = theStr;
2701 aStr.RemoveAll( ' ' );
2702 aStr.RemoveAll( '\t' );
2704 for ( int aPos = aStr.Search( ",," ); aPos != -1; aPos = aStr.Search( ",," ) )
2705 aStr.Remove( aPos, 2 );
2707 TCollection_AsciiString tmpStr = aStr.Token( ",", 1 );
2709 while ( tmpStr != "" )
2711 tmpStr = aStr.Token( ",", i++ );
2712 int aPos = tmpStr.Search( '-' );
2716 if ( tmpStr.IsIntegerValue() )
2717 myIds.Add( tmpStr.IntegerValue() );
2723 TCollection_AsciiString aMaxStr = tmpStr.Split( aPos );
2724 TCollection_AsciiString aMinStr = tmpStr;
2726 while ( aMinStr.Search( "-" ) != -1 ) aMinStr.RemoveAll( '-' );
2727 while ( aMaxStr.Search( "-" ) != -1 ) aMaxStr.RemoveAll( '-' );
2729 if ( (!aMinStr.IsEmpty() && !aMinStr.IsIntegerValue()) ||
2730 (!aMaxStr.IsEmpty() && !aMaxStr.IsIntegerValue()) )
2733 myMin.Append( aMinStr.IsEmpty() ? IntegerFirst() : aMinStr.IntegerValue() );
2734 myMax.Append( aMaxStr.IsEmpty() ? IntegerLast() : aMaxStr.IntegerValue() );
2741 //=======================================================================
2743 // Purpose : Get type of supported entities
2744 //=======================================================================
2745 SMDSAbs_ElementType RangeOfIds::GetType() const
2750 //=======================================================================
2752 // Purpose : Set type of supported entities
2753 //=======================================================================
2754 void RangeOfIds::SetType( SMDSAbs_ElementType theType )
2759 //=======================================================================
2761 // Purpose : Verify whether entity satisfies to this rpedicate
2762 //=======================================================================
2763 bool RangeOfIds::IsSatisfy( long theId )
2768 if ( myType == SMDSAbs_Node )
2770 if ( myMesh->FindNode( theId ) == 0 )
2775 const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
2776 if ( anElem == 0 || (myType != anElem->GetType() && myType != SMDSAbs_All ))
2780 if ( myIds.Contains( theId ) )
2783 for ( int i = 1, n = myMin.Length(); i <= n; i++ )
2784 if ( theId >= myMin( i ) && theId <= myMax( i ) )
2792 Description : Base class for comparators
2794 Comparator::Comparator():
2798 Comparator::~Comparator()
2801 void Comparator::SetMesh( const SMDS_Mesh* theMesh )
2804 myFunctor->SetMesh( theMesh );
2807 void Comparator::SetMargin( double theValue )
2809 myMargin = theValue;
2812 void Comparator::SetNumFunctor( NumericalFunctorPtr theFunct )
2814 myFunctor = theFunct;
2817 SMDSAbs_ElementType Comparator::GetType() const
2819 return myFunctor ? myFunctor->GetType() : SMDSAbs_All;
2822 double Comparator::GetMargin()
2830 Description : Comparator "<"
2832 bool LessThan::IsSatisfy( long theId )
2834 return myFunctor && myFunctor->GetValue( theId ) < myMargin;
2840 Description : Comparator ">"
2842 bool MoreThan::IsSatisfy( long theId )
2844 return myFunctor && myFunctor->GetValue( theId ) > myMargin;
2850 Description : Comparator "="
2853 myToler(Precision::Confusion())
2856 bool EqualTo::IsSatisfy( long theId )
2858 return myFunctor && fabs( myFunctor->GetValue( theId ) - myMargin ) < myToler;
2861 void EqualTo::SetTolerance( double theToler )
2866 double EqualTo::GetTolerance()
2873 Description : Logical NOT predicate
2875 LogicalNOT::LogicalNOT()
2878 LogicalNOT::~LogicalNOT()
2881 bool LogicalNOT::IsSatisfy( long theId )
2883 return myPredicate && !myPredicate->IsSatisfy( theId );
2886 void LogicalNOT::SetMesh( const SMDS_Mesh* theMesh )
2889 myPredicate->SetMesh( theMesh );
2892 void LogicalNOT::SetPredicate( PredicatePtr thePred )
2894 myPredicate = thePred;
2897 SMDSAbs_ElementType LogicalNOT::GetType() const
2899 return myPredicate ? myPredicate->GetType() : SMDSAbs_All;
2904 Class : LogicalBinary
2905 Description : Base class for binary logical predicate
2907 LogicalBinary::LogicalBinary()
2910 LogicalBinary::~LogicalBinary()
2913 void LogicalBinary::SetMesh( const SMDS_Mesh* theMesh )
2916 myPredicate1->SetMesh( theMesh );
2919 myPredicate2->SetMesh( theMesh );
2922 void LogicalBinary::SetPredicate1( PredicatePtr thePredicate )
2924 myPredicate1 = thePredicate;
2927 void LogicalBinary::SetPredicate2( PredicatePtr thePredicate )
2929 myPredicate2 = thePredicate;
2932 SMDSAbs_ElementType LogicalBinary::GetType() const
2934 if ( !myPredicate1 || !myPredicate2 )
2937 SMDSAbs_ElementType aType1 = myPredicate1->GetType();
2938 SMDSAbs_ElementType aType2 = myPredicate2->GetType();
2940 return aType1 == aType2 ? aType1 : SMDSAbs_All;
2946 Description : Logical AND
2948 bool LogicalAND::IsSatisfy( long theId )
2953 myPredicate1->IsSatisfy( theId ) &&
2954 myPredicate2->IsSatisfy( theId );
2960 Description : Logical OR
2962 bool LogicalOR::IsSatisfy( long theId )
2967 (myPredicate1->IsSatisfy( theId ) ||
2968 myPredicate2->IsSatisfy( theId ));
2982 void Filter::SetPredicate( PredicatePtr thePredicate )
2984 myPredicate = thePredicate;
2987 template<class TElement, class TIterator, class TPredicate>
2988 inline void FillSequence(const TIterator& theIterator,
2989 TPredicate& thePredicate,
2990 Filter::TIdSequence& theSequence)
2992 if ( theIterator ) {
2993 while( theIterator->more() ) {
2994 TElement anElem = theIterator->next();
2995 long anId = anElem->GetID();
2996 if ( thePredicate->IsSatisfy( anId ) )
2997 theSequence.push_back( anId );
3004 GetElementsId( const SMDS_Mesh* theMesh,
3005 PredicatePtr thePredicate,
3006 TIdSequence& theSequence )
3008 theSequence.clear();
3010 if ( !theMesh || !thePredicate )
3013 thePredicate->SetMesh( theMesh );
3015 SMDSAbs_ElementType aType = thePredicate->GetType();
3018 FillSequence<const SMDS_MeshNode*>(theMesh->nodesIterator(),thePredicate,theSequence);
3021 FillSequence<const SMDS_MeshElement*>(theMesh->edgesIterator(),thePredicate,theSequence);
3024 FillSequence<const SMDS_MeshElement*>(theMesh->facesIterator(),thePredicate,theSequence);
3026 case SMDSAbs_Volume:
3027 FillSequence<const SMDS_MeshElement*>(theMesh->volumesIterator(),thePredicate,theSequence);
3030 FillSequence<const SMDS_MeshElement*>(theMesh->edgesIterator(),thePredicate,theSequence);
3031 FillSequence<const SMDS_MeshElement*>(theMesh->facesIterator(),thePredicate,theSequence);
3032 FillSequence<const SMDS_MeshElement*>(theMesh->volumesIterator(),thePredicate,theSequence);
3038 Filter::GetElementsId( const SMDS_Mesh* theMesh,
3039 Filter::TIdSequence& theSequence )
3041 GetElementsId(theMesh,myPredicate,theSequence);
3048 typedef std::set<SMDS_MeshFace*> TMapOfFacePtr;
3054 ManifoldPart::Link::Link( SMDS_MeshNode* theNode1,
3055 SMDS_MeshNode* theNode2 )
3061 ManifoldPart::Link::~Link()
3067 bool ManifoldPart::Link::IsEqual( const ManifoldPart::Link& theLink ) const
3069 if ( myNode1 == theLink.myNode1 &&
3070 myNode2 == theLink.myNode2 )
3072 else if ( myNode1 == theLink.myNode2 &&
3073 myNode2 == theLink.myNode1 )
3079 bool ManifoldPart::Link::operator<( const ManifoldPart::Link& x ) const
3081 if(myNode1 < x.myNode1) return true;
3082 if(myNode1 == x.myNode1)
3083 if(myNode2 < x.myNode2) return true;
3087 bool ManifoldPart::IsEqual( const ManifoldPart::Link& theLink1,
3088 const ManifoldPart::Link& theLink2 )
3090 return theLink1.IsEqual( theLink2 );
3093 ManifoldPart::ManifoldPart()
3096 myAngToler = Precision::Angular();
3097 myIsOnlyManifold = true;
3100 ManifoldPart::~ManifoldPart()
3105 void ManifoldPart::SetMesh( const SMDS_Mesh* theMesh )
3111 SMDSAbs_ElementType ManifoldPart::GetType() const
3112 { return SMDSAbs_Face; }
3114 bool ManifoldPart::IsSatisfy( long theElementId )
3116 return myMapIds.Contains( theElementId );
3119 void ManifoldPart::SetAngleTolerance( const double theAngToler )
3120 { myAngToler = theAngToler; }
3122 double ManifoldPart::GetAngleTolerance() const
3123 { return myAngToler; }
3125 void ManifoldPart::SetIsOnlyManifold( const bool theIsOnly )
3126 { myIsOnlyManifold = theIsOnly; }
3128 void ManifoldPart::SetStartElem( const long theStartId )
3129 { myStartElemId = theStartId; }
3131 bool ManifoldPart::process()
3134 myMapBadGeomIds.Clear();
3136 myAllFacePtr.clear();
3137 myAllFacePtrIntDMap.clear();
3141 // collect all faces into own map
3142 SMDS_FaceIteratorPtr anFaceItr = myMesh->facesIterator();
3143 for (; anFaceItr->more(); )
3145 SMDS_MeshFace* aFacePtr = (SMDS_MeshFace*)anFaceItr->next();
3146 myAllFacePtr.push_back( aFacePtr );
3147 myAllFacePtrIntDMap[aFacePtr] = myAllFacePtr.size()-1;
3150 SMDS_MeshFace* aStartFace = (SMDS_MeshFace*)myMesh->FindElement( myStartElemId );
3154 // the map of non manifold links and bad geometry
3155 TMapOfLink aMapOfNonManifold;
3156 TColStd_MapOfInteger aMapOfTreated;
3158 // begin cycle on faces from start index and run on vector till the end
3159 // and from begin to start index to cover whole vector
3160 const int aStartIndx = myAllFacePtrIntDMap[aStartFace];
3161 bool isStartTreat = false;
3162 for ( int fi = aStartIndx; !isStartTreat || fi != aStartIndx ; fi++ )
3164 if ( fi == aStartIndx )
3165 isStartTreat = true;
3166 // as result next time when fi will be equal to aStartIndx
3168 SMDS_MeshFace* aFacePtr = myAllFacePtr[ fi ];
3169 if ( aMapOfTreated.Contains( aFacePtr->GetID() ) )
3172 aMapOfTreated.Add( aFacePtr->GetID() );
3173 TColStd_MapOfInteger aResFaces;
3174 if ( !findConnected( myAllFacePtrIntDMap, aFacePtr,
3175 aMapOfNonManifold, aResFaces ) )
3177 TColStd_MapIteratorOfMapOfInteger anItr( aResFaces );
3178 for ( ; anItr.More(); anItr.Next() )
3180 int aFaceId = anItr.Key();
3181 aMapOfTreated.Add( aFaceId );
3182 myMapIds.Add( aFaceId );
3185 if ( fi == ( myAllFacePtr.size() - 1 ) )
3187 } // end run on vector of faces
3188 return !myMapIds.IsEmpty();
3191 static void getLinks( const SMDS_MeshFace* theFace,
3192 ManifoldPart::TVectorOfLink& theLinks )
3194 int aNbNode = theFace->NbNodes();
3195 SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
3197 SMDS_MeshNode* aNode = 0;
3198 for ( ; aNodeItr->more() && i <= aNbNode; )
3201 SMDS_MeshNode* aN1 = (SMDS_MeshNode*)aNodeItr->next();
3205 SMDS_MeshNode* aN2 = ( i >= aNbNode ) ? aNode : (SMDS_MeshNode*)aNodeItr->next();
3207 ManifoldPart::Link aLink( aN1, aN2 );
3208 theLinks.push_back( aLink );
3212 bool ManifoldPart::findConnected
3213 ( const ManifoldPart::TDataMapFacePtrInt& theAllFacePtrInt,
3214 SMDS_MeshFace* theStartFace,
3215 ManifoldPart::TMapOfLink& theNonManifold,
3216 TColStd_MapOfInteger& theResFaces )
3218 theResFaces.Clear();
3219 if ( !theAllFacePtrInt.size() )
3222 if ( getNormale( theStartFace ).SquareModulus() <= gp::Resolution() )
3224 myMapBadGeomIds.Add( theStartFace->GetID() );
3228 ManifoldPart::TMapOfLink aMapOfBoundary, aMapToSkip;
3229 ManifoldPart::TVectorOfLink aSeqOfBoundary;
3230 theResFaces.Add( theStartFace->GetID() );
3231 ManifoldPart::TDataMapOfLinkFacePtr aDMapLinkFace;
3233 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
3234 aDMapLinkFace, theNonManifold, theStartFace );
3236 bool isDone = false;
3237 while ( !isDone && aMapOfBoundary.size() != 0 )
3239 bool isToReset = false;
3240 ManifoldPart::TVectorOfLink::iterator pLink = aSeqOfBoundary.begin();
3241 for ( ; !isToReset && pLink != aSeqOfBoundary.end(); ++pLink )
3243 ManifoldPart::Link aLink = *pLink;
3244 if ( aMapToSkip.find( aLink ) != aMapToSkip.end() )
3246 // each link could be treated only once
3247 aMapToSkip.insert( aLink );
3249 ManifoldPart::TVectorOfFacePtr aFaces;
3251 if ( myIsOnlyManifold &&
3252 (theNonManifold.find( aLink ) != theNonManifold.end()) )
3256 getFacesByLink( aLink, aFaces );
3257 // filter the element to keep only indicated elements
3258 ManifoldPart::TVectorOfFacePtr aFiltered;
3259 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
3260 for ( ; pFace != aFaces.end(); ++pFace )
3262 SMDS_MeshFace* aFace = *pFace;
3263 if ( myAllFacePtrIntDMap.find( aFace ) != myAllFacePtrIntDMap.end() )
3264 aFiltered.push_back( aFace );
3267 if ( aFaces.size() < 2 ) // no neihgbour faces
3269 else if ( myIsOnlyManifold && aFaces.size() > 2 ) // non manifold case
3271 theNonManifold.insert( aLink );
3276 // compare normal with normals of neighbor element
3277 SMDS_MeshFace* aPrevFace = aDMapLinkFace[ aLink ];
3278 ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
3279 for ( ; pFace != aFaces.end(); ++pFace )
3281 SMDS_MeshFace* aNextFace = *pFace;
3282 if ( aPrevFace == aNextFace )
3284 int anNextFaceID = aNextFace->GetID();
3285 if ( myIsOnlyManifold && theResFaces.Contains( anNextFaceID ) )
3286 // should not be with non manifold restriction. probably bad topology
3288 // check if face was treated and skipped
3289 if ( myMapBadGeomIds.Contains( anNextFaceID ) ||
3290 !isInPlane( aPrevFace, aNextFace ) )
3292 // add new element to connected and extend the boundaries.
3293 theResFaces.Add( anNextFaceID );
3294 expandBoundary( aMapOfBoundary, aSeqOfBoundary,
3295 aDMapLinkFace, theNonManifold, aNextFace );
3299 isDone = !isToReset;
3302 return !theResFaces.IsEmpty();
3305 bool ManifoldPart::isInPlane( const SMDS_MeshFace* theFace1,
3306 const SMDS_MeshFace* theFace2 )
3308 gp_Dir aNorm1 = gp_Dir( getNormale( theFace1 ) );
3309 gp_XYZ aNorm2XYZ = getNormale( theFace2 );
3310 if ( aNorm2XYZ.SquareModulus() <= gp::Resolution() )
3312 myMapBadGeomIds.Add( theFace2->GetID() );
3315 if ( aNorm1.IsParallel( gp_Dir( aNorm2XYZ ), myAngToler ) )
3321 void ManifoldPart::expandBoundary
3322 ( ManifoldPart::TMapOfLink& theMapOfBoundary,
3323 ManifoldPart::TVectorOfLink& theSeqOfBoundary,
3324 ManifoldPart::TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
3325 ManifoldPart::TMapOfLink& theNonManifold,
3326 SMDS_MeshFace* theNextFace ) const
3328 ManifoldPart::TVectorOfLink aLinks;
3329 getLinks( theNextFace, aLinks );
3330 int aNbLink = (int)aLinks.size();
3331 for ( int i = 0; i < aNbLink; i++ )
3333 ManifoldPart::Link aLink = aLinks[ i ];
3334 if ( myIsOnlyManifold && (theNonManifold.find( aLink ) != theNonManifold.end()) )
3336 if ( theMapOfBoundary.find( aLink ) != theMapOfBoundary.end() )
3338 if ( myIsOnlyManifold )
3340 // remove from boundary
3341 theMapOfBoundary.erase( aLink );
3342 ManifoldPart::TVectorOfLink::iterator pLink = theSeqOfBoundary.begin();
3343 for ( ; pLink != theSeqOfBoundary.end(); ++pLink )
3345 ManifoldPart::Link aBoundLink = *pLink;
3346 if ( aBoundLink.IsEqual( aLink ) )
3348 theSeqOfBoundary.erase( pLink );
3356 theMapOfBoundary.insert( aLink );
3357 theSeqOfBoundary.push_back( aLink );
3358 theDMapLinkFacePtr[ aLink ] = theNextFace;
3363 void ManifoldPart::getFacesByLink( const ManifoldPart::Link& theLink,
3364 ManifoldPart::TVectorOfFacePtr& theFaces ) const
3366 std::set<SMDS_MeshCell *> aSetOfFaces;
3367 // take all faces that shared first node
3368 SMDS_ElemIteratorPtr anItr = theLink.myNode1->facesIterator();
3369 for ( ; anItr->more(); )
3371 SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
3374 aSetOfFaces.insert( aFace );
3376 // take all faces that shared second node
3377 anItr = theLink.myNode2->facesIterator();
3378 // find the common part of two sets
3379 for ( ; anItr->more(); )
3381 SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
3382 if ( aSetOfFaces.count( aFace ) )
3383 theFaces.push_back( aFace );
3392 ElementsOnSurface::ElementsOnSurface()
3396 myType = SMDSAbs_All;
3398 myToler = Precision::Confusion();
3399 myUseBoundaries = false;
3402 ElementsOnSurface::~ElementsOnSurface()
3407 void ElementsOnSurface::SetMesh( const SMDS_Mesh* theMesh )
3409 if ( myMesh == theMesh )
3415 bool ElementsOnSurface::IsSatisfy( long theElementId )
3417 return myIds.Contains( theElementId );
3420 SMDSAbs_ElementType ElementsOnSurface::GetType() const
3423 void ElementsOnSurface::SetTolerance( const double theToler )
3425 if ( myToler != theToler )
3430 double ElementsOnSurface::GetTolerance() const
3433 void ElementsOnSurface::SetUseBoundaries( bool theUse )
3435 if ( myUseBoundaries != theUse ) {
3436 myUseBoundaries = theUse;
3437 SetSurface( mySurf, myType );
3441 void ElementsOnSurface::SetSurface( const TopoDS_Shape& theShape,
3442 const SMDSAbs_ElementType theType )
3447 if ( theShape.IsNull() || theShape.ShapeType() != TopAbs_FACE )
3449 mySurf = TopoDS::Face( theShape );
3450 BRepAdaptor_Surface SA( mySurf, myUseBoundaries );
3452 u1 = SA.FirstUParameter(),
3453 u2 = SA.LastUParameter(),
3454 v1 = SA.FirstVParameter(),
3455 v2 = SA.LastVParameter();
3456 Handle(Geom_Surface) surf = BRep_Tool::Surface( mySurf );
3457 myProjector.Init( surf, u1,u2, v1,v2 );
3461 void ElementsOnSurface::process()
3464 if ( mySurf.IsNull() )
3470 if ( myType == SMDSAbs_Face || myType == SMDSAbs_All )
3472 myIds.ReSize( myMesh->NbFaces() );
3473 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
3474 for(; anIter->more(); )
3475 process( anIter->next() );
3478 if ( myType == SMDSAbs_Edge || myType == SMDSAbs_All )
3480 myIds.ReSize( myIds.Extent() + myMesh->NbEdges() );
3481 SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
3482 for(; anIter->more(); )
3483 process( anIter->next() );
3486 if ( myType == SMDSAbs_Node )
3488 myIds.ReSize( myMesh->NbNodes() );
3489 SMDS_NodeIteratorPtr anIter = myMesh->nodesIterator();
3490 for(; anIter->more(); )
3491 process( anIter->next() );
3495 void ElementsOnSurface::process( const SMDS_MeshElement* theElemPtr )
3497 SMDS_ElemIteratorPtr aNodeItr = theElemPtr->nodesIterator();
3498 bool isSatisfy = true;
3499 for ( ; aNodeItr->more(); )
3501 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
3502 if ( !isOnSurface( aNode ) )
3509 myIds.Add( theElemPtr->GetID() );
3512 bool ElementsOnSurface::isOnSurface( const SMDS_MeshNode* theNode )
3514 if ( mySurf.IsNull() )
3517 gp_Pnt aPnt( theNode->X(), theNode->Y(), theNode->Z() );
3518 // double aToler2 = myToler * myToler;
3519 // if ( mySurf->IsKind(STANDARD_TYPE(Geom_Plane)))
3521 // gp_Pln aPln = Handle(Geom_Plane)::DownCast(mySurf)->Pln();
3522 // if ( aPln.SquareDistance( aPnt ) > aToler2 )
3525 // else if ( mySurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)))
3527 // gp_Cylinder aCyl = Handle(Geom_CylindricalSurface)::DownCast(mySurf)->Cylinder();
3528 // double aRad = aCyl.Radius();
3529 // gp_Ax3 anAxis = aCyl.Position();
3530 // gp_XYZ aLoc = aCyl.Location().XYZ();
3531 // double aXDist = anAxis.XDirection().XYZ() * ( aPnt.XYZ() - aLoc );
3532 // double aYDist = anAxis.YDirection().XYZ() * ( aPnt.XYZ() - aLoc );
3533 // if ( fabs(aXDist*aXDist + aYDist*aYDist - aRad*aRad) > aToler2 )
3538 myProjector.Perform( aPnt );
3539 bool isOn = ( myProjector.IsDone() && myProjector.LowerDistance() <= myToler );
3549 ElementsOnShape::ElementsOnShape()
3551 myType(SMDSAbs_All),
3552 myToler(Precision::Confusion()),
3553 myAllNodesFlag(false)
3555 myCurShapeType = TopAbs_SHAPE;
3558 ElementsOnShape::~ElementsOnShape()
3562 void ElementsOnShape::SetMesh (const SMDS_Mesh* theMesh)
3564 if (myMesh != theMesh) {
3566 SetShape(myShape, myType);
3570 bool ElementsOnShape::IsSatisfy (long theElementId)
3572 return myIds.Contains(theElementId);
3575 SMDSAbs_ElementType ElementsOnShape::GetType() const
3580 void ElementsOnShape::SetTolerance (const double theToler)
3582 if (myToler != theToler) {
3584 SetShape(myShape, myType);
3588 double ElementsOnShape::GetTolerance() const
3593 void ElementsOnShape::SetAllNodes (bool theAllNodes)
3595 if (myAllNodesFlag != theAllNodes) {
3596 myAllNodesFlag = theAllNodes;
3597 SetShape(myShape, myType);
3601 void ElementsOnShape::SetShape (const TopoDS_Shape& theShape,
3602 const SMDSAbs_ElementType theType)
3608 if (myMesh == 0) return;
3613 myIds.ReSize(myMesh->NbEdges() + myMesh->NbFaces() + myMesh->NbVolumes());
3616 myIds.ReSize(myMesh->NbNodes());
3619 myIds.ReSize(myMesh->NbEdges());
3622 myIds.ReSize(myMesh->NbFaces());
3624 case SMDSAbs_Volume:
3625 myIds.ReSize(myMesh->NbVolumes());
3631 myShapesMap.Clear();
3635 void ElementsOnShape::addShape (const TopoDS_Shape& theShape)
3637 if (theShape.IsNull() || myMesh == 0)
3640 if (!myShapesMap.Add(theShape)) return;
3642 myCurShapeType = theShape.ShapeType();
3643 switch (myCurShapeType)
3645 case TopAbs_COMPOUND:
3646 case TopAbs_COMPSOLID:
3650 TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
3651 for (; anIt.More(); anIt.Next()) addShape(anIt.Value());
3656 myCurSC.Load(theShape);
3662 TopoDS_Face aFace = TopoDS::Face(theShape);
3663 BRepAdaptor_Surface SA (aFace, true);
3665 u1 = SA.FirstUParameter(),
3666 u2 = SA.LastUParameter(),
3667 v1 = SA.FirstVParameter(),
3668 v2 = SA.LastVParameter();
3669 Handle(Geom_Surface) surf = BRep_Tool::Surface(aFace);
3670 myCurProjFace.Init(surf, u1,u2, v1,v2);
3677 TopoDS_Edge anEdge = TopoDS::Edge(theShape);
3678 Standard_Real u1, u2;
3679 Handle(Geom_Curve) curve = BRep_Tool::Curve(anEdge, u1, u2);
3680 myCurProjEdge.Init(curve, u1, u2);
3686 TopoDS_Vertex aV = TopoDS::Vertex(theShape);
3687 myCurPnt = BRep_Tool::Pnt(aV);
3696 void ElementsOnShape::process()
3698 if (myShape.IsNull() || myMesh == 0)
3701 if (myType == SMDSAbs_Node)
3703 SMDS_NodeIteratorPtr anIter = myMesh->nodesIterator();
3704 while (anIter->more())
3705 process(anIter->next());
3709 if (myType == SMDSAbs_Edge || myType == SMDSAbs_All)
3711 SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
3712 while (anIter->more())
3713 process(anIter->next());
3716 if (myType == SMDSAbs_Face || myType == SMDSAbs_All)
3718 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
3719 while (anIter->more()) {
3720 process(anIter->next());
3724 if (myType == SMDSAbs_Volume || myType == SMDSAbs_All)
3726 SMDS_VolumeIteratorPtr anIter = myMesh->volumesIterator();
3727 while (anIter->more())
3728 process(anIter->next());
3733 void ElementsOnShape::process (const SMDS_MeshElement* theElemPtr)
3735 if (myShape.IsNull())
3738 SMDS_ElemIteratorPtr aNodeItr = theElemPtr->nodesIterator();
3739 bool isSatisfy = myAllNodesFlag;
3741 gp_XYZ centerXYZ (0, 0, 0);
3743 while (aNodeItr->more() && (isSatisfy == myAllNodesFlag))
3745 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
3746 gp_Pnt aPnt (aNode->X(), aNode->Y(), aNode->Z());
3747 centerXYZ += aPnt.XYZ();
3749 switch (myCurShapeType)
3753 myCurSC.Perform(aPnt, myToler);
3754 isSatisfy = (myCurSC.State() == TopAbs_IN || myCurSC.State() == TopAbs_ON);
3759 myCurProjFace.Perform(aPnt);
3760 isSatisfy = (myCurProjFace.IsDone() && myCurProjFace.LowerDistance() <= myToler);
3763 // check relatively the face
3764 Quantity_Parameter u, v;
3765 myCurProjFace.LowerDistanceParameters(u, v);
3766 gp_Pnt2d aProjPnt (u, v);
3767 BRepClass_FaceClassifier aClsf (myCurFace, aProjPnt, myToler);
3768 isSatisfy = (aClsf.State() == TopAbs_IN || aClsf.State() == TopAbs_ON);
3774 myCurProjEdge.Perform(aPnt);
3775 isSatisfy = (myCurProjEdge.NbPoints() > 0 && myCurProjEdge.LowerDistance() <= myToler);
3780 isSatisfy = (aPnt.Distance(myCurPnt) <= myToler);
3790 if (isSatisfy && myCurShapeType == TopAbs_SOLID) { // Check the center point for volumes MantisBug 0020168
3791 centerXYZ /= theElemPtr->NbNodes();
3792 gp_Pnt aCenterPnt (centerXYZ);
3793 myCurSC.Perform(aCenterPnt, myToler);
3794 if ( !(myCurSC.State() == TopAbs_IN || myCurSC.State() == TopAbs_ON))
3799 myIds.Add(theElemPtr->GetID());
3802 TSequenceOfXYZ::TSequenceOfXYZ()
3805 TSequenceOfXYZ::TSequenceOfXYZ(size_type n) : myArray(n)
3808 TSequenceOfXYZ::TSequenceOfXYZ(size_type n, const gp_XYZ& t) : myArray(n,t)
3811 TSequenceOfXYZ::TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ) : myArray(theSequenceOfXYZ.myArray)
3814 template <class InputIterator>
3815 TSequenceOfXYZ::TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd): myArray(theBegin,theEnd)
3818 TSequenceOfXYZ::~TSequenceOfXYZ()
3821 TSequenceOfXYZ& TSequenceOfXYZ::operator=(const TSequenceOfXYZ& theSequenceOfXYZ)
3823 myArray = theSequenceOfXYZ.myArray;
3827 gp_XYZ& TSequenceOfXYZ::operator()(size_type n)
3829 return myArray[n-1];
3832 const gp_XYZ& TSequenceOfXYZ::operator()(size_type n) const
3834 return myArray[n-1];
3837 void TSequenceOfXYZ::clear()
3842 void TSequenceOfXYZ::reserve(size_type n)
3847 void TSequenceOfXYZ::push_back(const gp_XYZ& v)
3849 myArray.push_back(v);
3852 TSequenceOfXYZ::size_type TSequenceOfXYZ::size() const
3854 return myArray.size();