+ anIntSeq.Prepend( aMinId );
+ aStrSeq.Prepend( aStr );
+ }
+ else if ( aMinId > anIntSeq.Last() )
+ {
+ anIntSeq.Append( aMinId );
+ aStrSeq.Append( aStr );
+ }
+ else
+ for ( int j = 1, k = anIntSeq.Length(); j <= k; j++ )
+ if ( aMinId < anIntSeq( j ) )
+ {
+ anIntSeq.InsertBefore( j, aMinId );
+ aStrSeq.InsertBefore( j, aStr );
+ break;
+ }
+ }
+ }
+
+ if ( aStrSeq.Length() == 0 )
+ return;
+
+ theResStr = aStrSeq( 1 );
+ for ( int j = 2, k = aStrSeq.Length(); j <= k; j++ )
+ {
+ theResStr += ",";
+ theResStr += aStrSeq( j );
+ }
+}
+
+//=======================================================================
+// name : SetRangeStr
+// Purpose : Define range with string
+// Example of entry string: "1,2,3,50-60,63,67,70-"
+//=======================================================================
+bool RangeOfIds::SetRangeStr( const TCollection_AsciiString& theStr )
+{
+ myMin.Clear();
+ myMax.Clear();
+ myIds.Clear();
+
+ TCollection_AsciiString aStr = theStr;
+ for ( int i = 1; i <= aStr.Length(); ++i )
+ {
+ char c = aStr.Value( i );
+ if ( !isdigit( c ) && c != ',' && c != '-' )
+ aStr.SetValue( i, ',');
+ }
+ aStr.RemoveAll( ' ' );
+
+ TCollection_AsciiString tmpStr = aStr.Token( ",", 1 );
+ int i = 1;
+ while ( tmpStr != "" )
+ {
+ tmpStr = aStr.Token( ",", i++ );
+ int aPos = tmpStr.Search( '-' );
+
+ if ( aPos == -1 )
+ {
+ if ( tmpStr.IsIntegerValue() )
+ myIds.Add( tmpStr.IntegerValue() );
+ else
+ return false;
+ }
+ else
+ {
+ TCollection_AsciiString aMaxStr = tmpStr.Split( aPos );
+ TCollection_AsciiString aMinStr = tmpStr;
+
+ while ( aMinStr.Search( "-" ) != -1 ) aMinStr.RemoveAll( '-' );
+ while ( aMaxStr.Search( "-" ) != -1 ) aMaxStr.RemoveAll( '-' );
+
+ if ( (!aMinStr.IsEmpty() && !aMinStr.IsIntegerValue()) ||
+ (!aMaxStr.IsEmpty() && !aMaxStr.IsIntegerValue()) )
+ return false;
+
+ myMin.Append( aMinStr.IsEmpty() ? IntegerFirst() : aMinStr.IntegerValue() );
+ myMax.Append( aMaxStr.IsEmpty() ? IntegerLast() : aMaxStr.IntegerValue() );
+ }
+ }
+
+ return true;
+}
+
+//=======================================================================
+// name : GetType
+// Purpose : Get type of supported entities
+//=======================================================================
+SMDSAbs_ElementType RangeOfIds::GetType() const
+{
+ return myType;
+}
+
+//=======================================================================
+// name : SetType
+// Purpose : Set type of supported entities
+//=======================================================================
+void RangeOfIds::SetType( SMDSAbs_ElementType theType )
+{
+ myType = theType;
+}
+
+//=======================================================================
+// name : IsSatisfy
+// Purpose : Verify whether entity satisfies to this rpedicate
+//=======================================================================
+bool RangeOfIds::IsSatisfy( long theId )
+{
+ if ( !myMesh )
+ return false;
+
+ if ( myType == SMDSAbs_Node )
+ {
+ if ( myMesh->FindNode( theId ) == 0 )
+ return false;
+ }
+ else
+ {
+ const SMDS_MeshElement* anElem = myMesh->FindElement( theId );
+ if ( anElem == 0 || (myType != anElem->GetType() && myType != SMDSAbs_All ))
+ return false;
+ }
+
+ if ( myIds.Contains( theId ) )
+ return true;
+
+ for ( int i = 1, n = myMin.Length(); i <= n; i++ )
+ if ( theId >= myMin( i ) && theId <= myMax( i ) )
+ return true;
+
+ return false;
+}
+
+/*
+ Class : Comparator
+ Description : Base class for comparators
+*/
+Comparator::Comparator():
+ myMargin(0)
+{}
+
+Comparator::~Comparator()
+{}
+
+void Comparator::SetMesh( const SMDS_Mesh* theMesh )
+{
+ if ( myFunctor )
+ myFunctor->SetMesh( theMesh );
+}
+
+void Comparator::SetMargin( double theValue )
+{
+ myMargin = theValue;
+}
+
+void Comparator::SetNumFunctor( NumericalFunctorPtr theFunct )
+{
+ myFunctor = theFunct;
+}
+
+SMDSAbs_ElementType Comparator::GetType() const
+{
+ return myFunctor ? myFunctor->GetType() : SMDSAbs_All;
+}
+
+double Comparator::GetMargin()
+{
+ return myMargin;
+}
+
+
+/*
+ Class : LessThan
+ Description : Comparator "<"
+*/
+bool LessThan::IsSatisfy( long theId )
+{
+ return myFunctor && myFunctor->GetValue( theId ) < myMargin;
+}
+
+
+/*
+ Class : MoreThan
+ Description : Comparator ">"
+*/
+bool MoreThan::IsSatisfy( long theId )
+{
+ return myFunctor && myFunctor->GetValue( theId ) > myMargin;
+}
+
+
+/*
+ Class : EqualTo
+ Description : Comparator "="
+*/
+EqualTo::EqualTo():
+ myToler(Precision::Confusion())
+{}
+
+bool EqualTo::IsSatisfy( long theId )
+{
+ return myFunctor && fabs( myFunctor->GetValue( theId ) - myMargin ) < myToler;
+}
+
+void EqualTo::SetTolerance( double theToler )
+{
+ myToler = theToler;
+}
+
+double EqualTo::GetTolerance()
+{
+ return myToler;
+}
+
+/*
+ Class : LogicalNOT
+ Description : Logical NOT predicate
+*/
+LogicalNOT::LogicalNOT()
+{}
+
+LogicalNOT::~LogicalNOT()
+{}
+
+bool LogicalNOT::IsSatisfy( long theId )
+{
+ return myPredicate && !myPredicate->IsSatisfy( theId );
+}
+
+void LogicalNOT::SetMesh( const SMDS_Mesh* theMesh )
+{
+ if ( myPredicate )
+ myPredicate->SetMesh( theMesh );
+}
+
+void LogicalNOT::SetPredicate( PredicatePtr thePred )
+{
+ myPredicate = thePred;
+}
+
+SMDSAbs_ElementType LogicalNOT::GetType() const
+{
+ return myPredicate ? myPredicate->GetType() : SMDSAbs_All;
+}
+
+
+/*
+ Class : LogicalBinary
+ Description : Base class for binary logical predicate
+*/
+LogicalBinary::LogicalBinary()
+{}
+
+LogicalBinary::~LogicalBinary()
+{}
+
+void LogicalBinary::SetMesh( const SMDS_Mesh* theMesh )
+{
+ if ( myPredicate1 )
+ myPredicate1->SetMesh( theMesh );
+
+ if ( myPredicate2 )
+ myPredicate2->SetMesh( theMesh );
+}
+
+void LogicalBinary::SetPredicate1( PredicatePtr thePredicate )
+{
+ myPredicate1 = thePredicate;
+}
+
+void LogicalBinary::SetPredicate2( PredicatePtr thePredicate )
+{
+ myPredicate2 = thePredicate;
+}
+
+SMDSAbs_ElementType LogicalBinary::GetType() const
+{
+ if ( !myPredicate1 || !myPredicate2 )
+ return SMDSAbs_All;
+
+ SMDSAbs_ElementType aType1 = myPredicate1->GetType();
+ SMDSAbs_ElementType aType2 = myPredicate2->GetType();
+
+ return aType1 == aType2 ? aType1 : SMDSAbs_All;
+}
+
+
+/*
+ Class : LogicalAND
+ Description : Logical AND
+*/
+bool LogicalAND::IsSatisfy( long theId )
+{
+ return
+ myPredicate1 &&
+ myPredicate2 &&
+ myPredicate1->IsSatisfy( theId ) &&
+ myPredicate2->IsSatisfy( theId );
+}
+
+
+/*
+ Class : LogicalOR
+ Description : Logical OR
+*/
+bool LogicalOR::IsSatisfy( long theId )
+{
+ return
+ myPredicate1 &&
+ myPredicate2 &&
+ (myPredicate1->IsSatisfy( theId ) ||
+ myPredicate2->IsSatisfy( theId ));
+}
+
+
+/*
+ FILTER
+*/
+
+// #ifdef WITH_TBB
+// #include <tbb/parallel_for.h>
+// #include <tbb/enumerable_thread_specific.h>
+
+// namespace Parallel
+// {
+// typedef tbb::enumerable_thread_specific< TIdSequence > TIdSeq;
+
+// struct Predicate
+// {
+// const SMDS_Mesh* myMesh;
+// PredicatePtr myPredicate;
+// TIdSeq & myOKIds;
+// Predicate( const SMDS_Mesh* m, PredicatePtr p, TIdSeq & ids ):
+// myMesh(m), myPredicate(p->Duplicate()), myOKIds(ids) {}
+// void operator() ( const tbb::blocked_range<size_t>& r ) const
+// {
+// for ( size_t i = r.begin(); i != r.end(); ++i )
+// if ( myPredicate->IsSatisfy( i ))
+// myOKIds.local().push_back();
+// }
+// }
+// }
+// #endif
+
+Filter::Filter()
+{}
+
+Filter::~Filter()
+{}
+
+void Filter::SetPredicate( PredicatePtr thePredicate )
+{
+ myPredicate = thePredicate;
+}
+
+void Filter::GetElementsId( const SMDS_Mesh* theMesh,
+ PredicatePtr thePredicate,
+ TIdSequence& theSequence,
+ SMDS_ElemIteratorPtr theElements )
+{
+ theSequence.clear();
+
+ if ( !theMesh || !thePredicate )
+ return;
+
+ thePredicate->SetMesh( theMesh );
+
+ if ( !theElements )
+ theElements = theMesh->elementsIterator( thePredicate->GetType() );
+
+ if ( theElements ) {
+ while ( theElements->more() ) {
+ const SMDS_MeshElement* anElem = theElements->next();
+ if ( thePredicate->GetType() == SMDSAbs_All ||
+ thePredicate->GetType() == anElem->GetType() )
+ {
+ long anId = anElem->GetID();
+ if ( thePredicate->IsSatisfy( anId ) )
+ theSequence.push_back( anId );
+ }
+ }
+ }
+}
+
+void Filter::GetElementsId( const SMDS_Mesh* theMesh,
+ Filter::TIdSequence& theSequence,
+ SMDS_ElemIteratorPtr theElements )
+{
+ GetElementsId(theMesh,myPredicate,theSequence,theElements);
+}
+
+/*
+ ManifoldPart
+*/
+
+typedef std::set<SMDS_MeshFace*> TMapOfFacePtr;
+
+/*
+ Internal class Link
+*/
+
+ManifoldPart::Link::Link( SMDS_MeshNode* theNode1,
+ SMDS_MeshNode* theNode2 )
+{
+ myNode1 = theNode1;
+ myNode2 = theNode2;
+}
+
+ManifoldPart::Link::~Link()
+{
+ myNode1 = 0;
+ myNode2 = 0;
+}
+
+bool ManifoldPart::Link::IsEqual( const ManifoldPart::Link& theLink ) const
+{
+ if ( myNode1 == theLink.myNode1 &&
+ myNode2 == theLink.myNode2 )
+ return true;
+ else if ( myNode1 == theLink.myNode2 &&
+ myNode2 == theLink.myNode1 )
+ return true;
+ else
+ return false;
+}
+
+bool ManifoldPart::Link::operator<( const ManifoldPart::Link& x ) const
+{
+ if(myNode1 < x.myNode1) return true;
+ if(myNode1 == x.myNode1)
+ if(myNode2 < x.myNode2) return true;
+ return false;
+}
+
+bool ManifoldPart::IsEqual( const ManifoldPart::Link& theLink1,
+ const ManifoldPart::Link& theLink2 )
+{
+ return theLink1.IsEqual( theLink2 );
+}
+
+ManifoldPart::ManifoldPart()
+{
+ myMesh = 0;
+ myAngToler = Precision::Angular();
+ myIsOnlyManifold = true;
+}
+
+ManifoldPart::~ManifoldPart()
+{
+ myMesh = 0;
+}
+
+void ManifoldPart::SetMesh( const SMDS_Mesh* theMesh )
+{
+ myMesh = theMesh;
+ process();
+}
+
+SMDSAbs_ElementType ManifoldPart::GetType() const
+{ return SMDSAbs_Face; }
+
+bool ManifoldPart::IsSatisfy( long theElementId )
+{
+ return myMapIds.Contains( theElementId );
+}
+
+void ManifoldPart::SetAngleTolerance( const double theAngToler )
+{ myAngToler = theAngToler; }
+
+double ManifoldPart::GetAngleTolerance() const
+{ return myAngToler; }
+
+void ManifoldPart::SetIsOnlyManifold( const bool theIsOnly )
+{ myIsOnlyManifold = theIsOnly; }
+
+void ManifoldPart::SetStartElem( const long theStartId )
+{ myStartElemId = theStartId; }
+
+bool ManifoldPart::process()
+{
+ myMapIds.Clear();
+ myMapBadGeomIds.Clear();
+
+ myAllFacePtr.clear();
+ myAllFacePtrIntDMap.clear();
+ if ( !myMesh )
+ return false;
+
+ // collect all faces into own map
+ SMDS_FaceIteratorPtr anFaceItr = myMesh->facesIterator();
+ for (; anFaceItr->more(); )
+ {
+ SMDS_MeshFace* aFacePtr = (SMDS_MeshFace*)anFaceItr->next();
+ myAllFacePtr.push_back( aFacePtr );
+ myAllFacePtrIntDMap[aFacePtr] = myAllFacePtr.size()-1;
+ }
+
+ SMDS_MeshFace* aStartFace = (SMDS_MeshFace*)myMesh->FindElement( myStartElemId );
+ if ( !aStartFace )
+ return false;
+
+ // the map of non manifold links and bad geometry
+ TMapOfLink aMapOfNonManifold;
+ TColStd_MapOfInteger aMapOfTreated;
+
+ // begin cycle on faces from start index and run on vector till the end
+ // and from begin to start index to cover whole vector
+ const int aStartIndx = myAllFacePtrIntDMap[aStartFace];
+ bool isStartTreat = false;
+ for ( int fi = aStartIndx; !isStartTreat || fi != aStartIndx ; fi++ )
+ {
+ if ( fi == aStartIndx )
+ isStartTreat = true;
+ // as result next time when fi will be equal to aStartIndx
+
+ SMDS_MeshFace* aFacePtr = myAllFacePtr[ fi ];
+ if ( aMapOfTreated.Contains( aFacePtr->GetID() ) )
+ continue;
+
+ aMapOfTreated.Add( aFacePtr->GetID() );
+ TColStd_MapOfInteger aResFaces;
+ if ( !findConnected( myAllFacePtrIntDMap, aFacePtr,
+ aMapOfNonManifold, aResFaces ) )
+ continue;
+ TColStd_MapIteratorOfMapOfInteger anItr( aResFaces );
+ for ( ; anItr.More(); anItr.Next() )
+ {
+ int aFaceId = anItr.Key();
+ aMapOfTreated.Add( aFaceId );
+ myMapIds.Add( aFaceId );
+ }
+
+ if ( fi == int( myAllFacePtr.size() - 1 ))
+ fi = 0;
+ } // end run on vector of faces
+ return !myMapIds.IsEmpty();
+}
+
+static void getLinks( const SMDS_MeshFace* theFace,
+ ManifoldPart::TVectorOfLink& theLinks )
+{
+ int aNbNode = theFace->NbNodes();
+ SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
+ int i = 1;
+ SMDS_MeshNode* aNode = 0;
+ for ( ; aNodeItr->more() && i <= aNbNode; )
+ {
+
+ SMDS_MeshNode* aN1 = (SMDS_MeshNode*)aNodeItr->next();
+ if ( i == 1 )
+ aNode = aN1;
+ i++;
+ SMDS_MeshNode* aN2 = ( i >= aNbNode ) ? aNode : (SMDS_MeshNode*)aNodeItr->next();
+ i++;
+ ManifoldPart::Link aLink( aN1, aN2 );
+ theLinks.push_back( aLink );
+ }
+}
+
+bool ManifoldPart::findConnected
+ ( const ManifoldPart::TDataMapFacePtrInt& theAllFacePtrInt,
+ SMDS_MeshFace* theStartFace,
+ ManifoldPart::TMapOfLink& theNonManifold,
+ TColStd_MapOfInteger& theResFaces )
+{
+ theResFaces.Clear();
+ if ( !theAllFacePtrInt.size() )
+ return false;
+
+ if ( getNormale( theStartFace ).SquareModulus() <= gp::Resolution() )
+ {
+ myMapBadGeomIds.Add( theStartFace->GetID() );
+ return false;
+ }
+
+ ManifoldPart::TMapOfLink aMapOfBoundary, aMapToSkip;
+ ManifoldPart::TVectorOfLink aSeqOfBoundary;
+ theResFaces.Add( theStartFace->GetID() );
+ ManifoldPart::TDataMapOfLinkFacePtr aDMapLinkFace;
+
+ expandBoundary( aMapOfBoundary, aSeqOfBoundary,
+ aDMapLinkFace, theNonManifold, theStartFace );
+
+ bool isDone = false;
+ while ( !isDone && aMapOfBoundary.size() != 0 )
+ {
+ bool isToReset = false;
+ ManifoldPart::TVectorOfLink::iterator pLink = aSeqOfBoundary.begin();
+ for ( ; !isToReset && pLink != aSeqOfBoundary.end(); ++pLink )
+ {
+ ManifoldPart::Link aLink = *pLink;
+ if ( aMapToSkip.find( aLink ) != aMapToSkip.end() )
+ continue;
+ // each link could be treated only once
+ aMapToSkip.insert( aLink );
+
+ ManifoldPart::TVectorOfFacePtr aFaces;
+ // find next
+ if ( myIsOnlyManifold &&
+ (theNonManifold.find( aLink ) != theNonManifold.end()) )
+ continue;
+ else
+ {
+ getFacesByLink( aLink, aFaces );
+ // filter the element to keep only indicated elements
+ ManifoldPart::TVectorOfFacePtr aFiltered;
+ ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
+ for ( ; pFace != aFaces.end(); ++pFace )
+ {
+ SMDS_MeshFace* aFace = *pFace;
+ if ( myAllFacePtrIntDMap.find( aFace ) != myAllFacePtrIntDMap.end() )
+ aFiltered.push_back( aFace );
+ }
+ aFaces = aFiltered;
+ if ( aFaces.size() < 2 ) // no neihgbour faces
+ continue;
+ else if ( myIsOnlyManifold && aFaces.size() > 2 ) // non manifold case
+ {
+ theNonManifold.insert( aLink );
+ continue;
+ }
+ }
+
+ // compare normal with normals of neighbor element
+ SMDS_MeshFace* aPrevFace = aDMapLinkFace[ aLink ];
+ ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
+ for ( ; pFace != aFaces.end(); ++pFace )
+ {
+ SMDS_MeshFace* aNextFace = *pFace;
+ if ( aPrevFace == aNextFace )
+ continue;
+ int anNextFaceID = aNextFace->GetID();
+ if ( myIsOnlyManifold && theResFaces.Contains( anNextFaceID ) )
+ // should not be with non manifold restriction. probably bad topology
+ continue;
+ // check if face was treated and skipped
+ if ( myMapBadGeomIds.Contains( anNextFaceID ) ||
+ !isInPlane( aPrevFace, aNextFace ) )
+ continue;
+ // add new element to connected and extend the boundaries.
+ theResFaces.Add( anNextFaceID );
+ expandBoundary( aMapOfBoundary, aSeqOfBoundary,
+ aDMapLinkFace, theNonManifold, aNextFace );
+ isToReset = true;
+ }
+ }
+ isDone = !isToReset;
+ }
+
+ return !theResFaces.IsEmpty();
+}
+
+bool ManifoldPart::isInPlane( const SMDS_MeshFace* theFace1,
+ const SMDS_MeshFace* theFace2 )
+{
+ gp_Dir aNorm1 = gp_Dir( getNormale( theFace1 ) );
+ gp_XYZ aNorm2XYZ = getNormale( theFace2 );
+ if ( aNorm2XYZ.SquareModulus() <= gp::Resolution() )
+ {
+ myMapBadGeomIds.Add( theFace2->GetID() );
+ return false;
+ }
+ if ( aNorm1.IsParallel( gp_Dir( aNorm2XYZ ), myAngToler ) )
+ return true;
+
+ return false;
+}
+
+void ManifoldPart::expandBoundary
+ ( ManifoldPart::TMapOfLink& theMapOfBoundary,
+ ManifoldPart::TVectorOfLink& theSeqOfBoundary,
+ ManifoldPart::TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
+ ManifoldPart::TMapOfLink& theNonManifold,
+ SMDS_MeshFace* theNextFace ) const
+{
+ ManifoldPart::TVectorOfLink aLinks;
+ getLinks( theNextFace, aLinks );
+ int aNbLink = (int)aLinks.size();
+ for ( int i = 0; i < aNbLink; i++ )
+ {
+ ManifoldPart::Link aLink = aLinks[ i ];
+ if ( myIsOnlyManifold && (theNonManifold.find( aLink ) != theNonManifold.end()) )
+ continue;
+ if ( theMapOfBoundary.find( aLink ) != theMapOfBoundary.end() )
+ {
+ if ( myIsOnlyManifold )
+ {
+ // remove from boundary
+ theMapOfBoundary.erase( aLink );
+ ManifoldPart::TVectorOfLink::iterator pLink = theSeqOfBoundary.begin();
+ for ( ; pLink != theSeqOfBoundary.end(); ++pLink )
+ {
+ ManifoldPart::Link aBoundLink = *pLink;
+ if ( aBoundLink.IsEqual( aLink ) )
+ {
+ theSeqOfBoundary.erase( pLink );
+ break;
+ }
+ }
+ }
+ }
+ else
+ {
+ theMapOfBoundary.insert( aLink );
+ theSeqOfBoundary.push_back( aLink );
+ theDMapLinkFacePtr[ aLink ] = theNextFace;
+ }
+ }
+}
+
+void ManifoldPart::getFacesByLink( const ManifoldPart::Link& theLink,
+ ManifoldPart::TVectorOfFacePtr& theFaces ) const
+{
+
+ // take all faces that shared first node
+ SMDS_ElemIteratorPtr anItr = theLink.myNode1->GetInverseElementIterator( SMDSAbs_Face );
+ SMDS_StdIterator< const SMDS_MeshElement*, SMDS_ElemIteratorPtr > faces( anItr ), facesEnd;
+ std::set<const SMDS_MeshElement *> aSetOfFaces( faces, facesEnd );
+
+ // take all faces that shared second node
+ anItr = theLink.myNode2->GetInverseElementIterator( SMDSAbs_Face );
+ // find the common part of two sets
+ for ( ; anItr->more(); )
+ {
+ const SMDS_MeshElement* aFace = anItr->next();
+ if ( aSetOfFaces.count( aFace ))
+ theFaces.push_back( (SMDS_MeshFace*) aFace );
+ }
+}
+
+/*
+ Class : BelongToMeshGroup
+ Description : Verify whether a mesh element is included into a mesh group
+*/
+BelongToMeshGroup::BelongToMeshGroup(): myGroup( 0 )
+{
+}
+
+void BelongToMeshGroup::SetGroup( SMESHDS_GroupBase* g )
+{
+ myGroup = g;
+}
+
+void BelongToMeshGroup::SetStoreName( const std::string& sn )
+{
+ myStoreName = sn;
+}
+
+void BelongToMeshGroup::SetMesh( const SMDS_Mesh* theMesh )
+{
+ if ( myGroup && myGroup->GetMesh() != theMesh )
+ {
+ myGroup = 0;
+ }
+ if ( !myGroup && !myStoreName.empty() )
+ {
+ if ( const SMESHDS_Mesh* aMesh = dynamic_cast<const SMESHDS_Mesh*>(theMesh))
+ {
+ const std::set<SMESHDS_GroupBase*>& grps = aMesh->GetGroups();
+ std::set<SMESHDS_GroupBase*>::const_iterator g = grps.begin();
+ for ( ; g != grps.end() && !myGroup; ++g )
+ if ( *g && myStoreName == (*g)->GetStoreName() )
+ myGroup = *g;
+ }
+ }
+ if ( myGroup )
+ {
+ myGroup->IsEmpty(); // make GroupOnFilter update its predicate
+ }
+}
+
+bool BelongToMeshGroup::IsSatisfy( long theElementId )
+{
+ return myGroup ? myGroup->Contains( theElementId ) : false;
+}
+
+SMDSAbs_ElementType BelongToMeshGroup::GetType() const
+{
+ return myGroup ? myGroup->GetType() : SMDSAbs_All;
+}
+
+//================================================================================
+// ElementsOnSurface
+//================================================================================
+
+ElementsOnSurface::ElementsOnSurface()
+{
+ myIds.Clear();
+ myType = SMDSAbs_All;
+ mySurf.Nullify();
+ myToler = Precision::Confusion();
+ myUseBoundaries = false;
+}
+
+ElementsOnSurface::~ElementsOnSurface()
+{
+}
+
+void ElementsOnSurface::SetMesh( const SMDS_Mesh* theMesh )
+{
+ myMeshModifTracer.SetMesh( theMesh );
+ if ( myMeshModifTracer.IsMeshModified())
+ process();
+}
+
+bool ElementsOnSurface::IsSatisfy( long theElementId )
+{
+ return myIds.Contains( theElementId );
+}
+
+SMDSAbs_ElementType ElementsOnSurface::GetType() const
+{ return myType; }
+
+void ElementsOnSurface::SetTolerance( const double theToler )
+{
+ if ( myToler != theToler )
+ {
+ myToler = theToler;
+ process();
+ }
+}
+
+double ElementsOnSurface::GetTolerance() const
+{ return myToler; }
+
+void ElementsOnSurface::SetUseBoundaries( bool theUse )
+{
+ if ( myUseBoundaries != theUse ) {
+ myUseBoundaries = theUse;
+ SetSurface( mySurf, myType );
+ }
+}
+
+void ElementsOnSurface::SetSurface( const TopoDS_Shape& theShape,
+ const SMDSAbs_ElementType theType )
+{
+ myIds.Clear();
+ myType = theType;
+ mySurf.Nullify();
+ if ( theShape.IsNull() || theShape.ShapeType() != TopAbs_FACE )
+ return;
+ mySurf = TopoDS::Face( theShape );
+ BRepAdaptor_Surface SA( mySurf, myUseBoundaries );
+ Standard_Real
+ u1 = SA.FirstUParameter(),
+ u2 = SA.LastUParameter(),
+ v1 = SA.FirstVParameter(),
+ v2 = SA.LastVParameter();
+ Handle(Geom_Surface) surf = BRep_Tool::Surface( mySurf );
+ myProjector.Init( surf, u1,u2, v1,v2 );
+ process();
+}
+
+void ElementsOnSurface::process()
+{
+ myIds.Clear();
+ if ( mySurf.IsNull() )
+ return;
+
+ if ( !myMeshModifTracer.GetMesh() )
+ return;
+
+ myIds.ReSize( myMeshModifTracer.GetMesh()->GetMeshInfo().NbElements( myType ));
+
+ SMDS_ElemIteratorPtr anIter = myMeshModifTracer.GetMesh()->elementsIterator( myType );
+ for(; anIter->more(); )
+ process( anIter->next() );
+}
+
+void ElementsOnSurface::process( const SMDS_MeshElement* theElemPtr )
+{
+ SMDS_ElemIteratorPtr aNodeItr = theElemPtr->nodesIterator();
+ bool isSatisfy = true;
+ for ( ; aNodeItr->more(); )
+ {
+ SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
+ if ( !isOnSurface( aNode ) )
+ {
+ isSatisfy = false;
+ break;
+ }
+ }
+ if ( isSatisfy )
+ myIds.Add( theElemPtr->GetID() );
+}
+
+bool ElementsOnSurface::isOnSurface( const SMDS_MeshNode* theNode )
+{
+ if ( mySurf.IsNull() )
+ return false;
+
+ gp_Pnt aPnt( theNode->X(), theNode->Y(), theNode->Z() );
+ // double aToler2 = myToler * myToler;
+// if ( mySurf->IsKind(STANDARD_TYPE(Geom_Plane)))
+// {
+// gp_Pln aPln = Handle(Geom_Plane)::DownCast(mySurf)->Pln();
+// if ( aPln.SquareDistance( aPnt ) > aToler2 )
+// return false;
+// }
+// else if ( mySurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)))
+// {
+// gp_Cylinder aCyl = Handle(Geom_CylindricalSurface)::DownCast(mySurf)->Cylinder();
+// double aRad = aCyl.Radius();
+// gp_Ax3 anAxis = aCyl.Position();
+// gp_XYZ aLoc = aCyl.Location().XYZ();
+// double aXDist = anAxis.XDirection().XYZ() * ( aPnt.XYZ() - aLoc );
+// double aYDist = anAxis.YDirection().XYZ() * ( aPnt.XYZ() - aLoc );
+// if ( fabs(aXDist*aXDist + aYDist*aYDist - aRad*aRad) > aToler2 )
+// return false;
+// }
+// else
+// return false;
+ myProjector.Perform( aPnt );
+ bool isOn = ( myProjector.IsDone() && myProjector.LowerDistance() <= myToler );
+
+ return isOn;
+}
+
+
+//================================================================================
+// ElementsOnShape
+//================================================================================
+
+namespace {
+ const int theIsCheckedFlag = 0x0000100;
+}
+
+struct ElementsOnShape::Classifier
+{
+ Classifier() { mySolidClfr = 0; myFlags = 0; }
+ ~Classifier();
+ void Init(const TopoDS_Shape& s, double tol, const Bnd_B3d* box = 0 );
+ bool IsOut(const gp_Pnt& p) { return SetChecked( true ), (this->*myIsOutFun)( p ); }
+ TopAbs_ShapeEnum ShapeType() const { return myShape.ShapeType(); }
+ const TopoDS_Shape& Shape() const { return myShape; }
+ const Bnd_B3d* GetBndBox() const { return & myBox; }
+ double Tolerance() const { return myTol; }
+ bool IsChecked() { return myFlags & theIsCheckedFlag; }
+ bool IsSetFlag( int flag ) const { return myFlags & flag; }
+ void SetChecked( bool is ) { is ? SetFlag( theIsCheckedFlag ) : UnsetFlag( theIsCheckedFlag ); }
+ void SetFlag ( int flag ) { myFlags |= flag; }
+ void UnsetFlag( int flag ) { myFlags &= ~flag; }
+
+private:
+ bool isOutOfSolid (const gp_Pnt& p);
+ bool isOutOfBox (const gp_Pnt& p);
+ bool isOutOfFace (const gp_Pnt& p);
+ bool isOutOfEdge (const gp_Pnt& p);
+ bool isOutOfVertex(const gp_Pnt& p);
+ bool isBox (const TopoDS_Shape& s);
+
+ bool (Classifier::* myIsOutFun)(const gp_Pnt& p);
+ BRepClass3d_SolidClassifier* mySolidClfr; // ptr because of a run-time forbidden copy-constructor
+ Bnd_B3d myBox;
+ GeomAPI_ProjectPointOnSurf myProjFace;
+ GeomAPI_ProjectPointOnCurve myProjEdge;
+ gp_Pnt myVertexXYZ;
+ TopoDS_Shape myShape;
+ double myTol;
+ int myFlags;
+};
+
+struct ElementsOnShape::OctreeClassifier : public SMESH_Octree
+{
+ OctreeClassifier( const std::vector< ElementsOnShape::Classifier* >& classifiers );
+ OctreeClassifier( const OctreeClassifier* otherTree,
+ const std::vector< ElementsOnShape::Classifier >& clsOther,
+ std::vector< ElementsOnShape::Classifier >& cls );
+ void GetClassifiersAtPoint( const gp_XYZ& p,
+ std::vector< ElementsOnShape::Classifier* >& classifiers );
+protected:
+ OctreeClassifier() {}
+ SMESH_Octree* newChild() const { return new OctreeClassifier; }
+ void buildChildrenData();
+ Bnd_B3d* buildRootBox();
+
+ std::vector< ElementsOnShape::Classifier* > myClassifiers;
+};
+
+
+ElementsOnShape::ElementsOnShape():
+ myOctree(0),
+ myType(SMDSAbs_All),
+ myToler(Precision::Confusion()),
+ myAllNodesFlag(false)
+{
+}
+
+ElementsOnShape::~ElementsOnShape()
+{
+ clearClassifiers();
+}
+
+Predicate* ElementsOnShape::clone() const
+{
+ ElementsOnShape* cln = new ElementsOnShape();
+ cln->SetAllNodes ( myAllNodesFlag );
+ cln->SetTolerance( myToler );
+ cln->SetMesh ( myMeshModifTracer.GetMesh() );
+ cln->myShape = myShape; // avoid creation of myClassifiers
+ cln->SetShape ( myShape, myType );
+ cln->myClassifiers.resize( myClassifiers.size() );
+ for ( size_t i = 0; i < myClassifiers.size(); ++i )
+ cln->myClassifiers[ i ].Init( BRepBuilderAPI_Copy( myClassifiers[ i ].Shape()),
+ myToler, myClassifiers[ i ].GetBndBox() );
+ if ( myOctree ) // copy myOctree
+ {
+ cln->myOctree = new OctreeClassifier( myOctree, myClassifiers, cln->myClassifiers );
+ }
+ return cln;
+}
+
+SMDSAbs_ElementType ElementsOnShape::GetType() const
+{
+ return myType;
+}
+
+void ElementsOnShape::SetTolerance (const double theToler)
+{
+ if (myToler != theToler) {
+ myToler = theToler;
+ SetShape(myShape, myType);
+ }
+}
+
+double ElementsOnShape::GetTolerance() const
+{
+ return myToler;
+}
+
+void ElementsOnShape::SetAllNodes (bool theAllNodes)
+{
+ myAllNodesFlag = theAllNodes;
+}
+
+void ElementsOnShape::SetMesh (const SMDS_Mesh* theMesh)
+{
+ myMeshModifTracer.SetMesh( theMesh );
+ if ( myMeshModifTracer.IsMeshModified())
+ {
+ size_t nbNodes = theMesh ? theMesh->NbNodes() : 0;
+ if ( myNodeIsChecked.size() == nbNodes )
+ {
+ std::fill( myNodeIsChecked.begin(), myNodeIsChecked.end(), false );
+ }
+ else
+ {
+ SMESHUtils::FreeVector( myNodeIsChecked );
+ SMESHUtils::FreeVector( myNodeIsOut );
+ myNodeIsChecked.resize( nbNodes, false );
+ myNodeIsOut.resize( nbNodes );
+ }
+ }
+}
+
+bool ElementsOnShape::getNodeIsOut( const SMDS_MeshNode* n, bool& isOut )
+{
+ if ( n->GetID() >= (int) myNodeIsChecked.size() ||
+ !myNodeIsChecked[ n->GetID() ])
+ return false;
+
+ isOut = myNodeIsOut[ n->GetID() ];
+ return true;
+}
+
+void ElementsOnShape::setNodeIsOut( const SMDS_MeshNode* n, bool isOut )
+{
+ if ( n->GetID() < (int) myNodeIsChecked.size() )
+ {
+ myNodeIsChecked[ n->GetID() ] = true;
+ myNodeIsOut [ n->GetID() ] = isOut;
+ }
+}
+
+void ElementsOnShape::SetShape (const TopoDS_Shape& theShape,
+ const SMDSAbs_ElementType theType)
+{
+ bool shapeChanges = ( myShape != theShape );
+ myType = theType;
+ myShape = theShape;
+ if ( myShape.IsNull() ) return;
+
+ if ( shapeChanges )
+ {
+ // find most complex shapes
+ TopTools_IndexedMapOfShape shapesMap;
+ TopAbs_ShapeEnum shapeTypes[4] = { TopAbs_SOLID, TopAbs_FACE, TopAbs_EDGE, TopAbs_VERTEX };
+ TopExp_Explorer sub;
+ for ( int i = 0; i < 4; ++i )
+ {
+ if ( shapesMap.IsEmpty() )
+ for ( sub.Init( myShape, shapeTypes[i] ); sub.More(); sub.Next() )
+ shapesMap.Add( sub.Current() );
+ if ( i > 0 )
+ for ( sub.Init( myShape, shapeTypes[i], shapeTypes[i-1] ); sub.More(); sub.Next() )
+ shapesMap.Add( sub.Current() );
+ }
+
+ clearClassifiers();
+ myClassifiers.resize( shapesMap.Extent() );
+ for ( int i = 0; i < shapesMap.Extent(); ++i )
+ myClassifiers[ i ].Init( shapesMap( i+1 ), myToler );
+ }
+
+ if ( theType == SMDSAbs_Node )
+ {
+ SMESHUtils::FreeVector( myNodeIsChecked );
+ SMESHUtils::FreeVector( myNodeIsOut );
+ }
+ else
+ {
+ std::fill( myNodeIsChecked.begin(), myNodeIsChecked.end(), false );
+ }
+}
+
+void ElementsOnShape::clearClassifiers()
+{
+ // for ( size_t i = 0; i < myClassifiers.size(); ++i )
+ // delete myClassifiers[ i ];
+ myClassifiers.clear();
+
+ delete myOctree;
+ myOctree = 0;
+}
+
+bool ElementsOnShape::IsSatisfy( long elemId )
+{
+ if ( myClassifiers.empty() )
+ return false;
+
+ const SMDS_Mesh* mesh = myMeshModifTracer.GetMesh();
+ if ( myType == SMDSAbs_Node )
+ return IsSatisfy( mesh->FindNode( elemId ));
+ return IsSatisfy( mesh->FindElement( elemId ));
+}
+
+bool ElementsOnShape::IsSatisfy (const SMDS_MeshElement* elem)
+{
+ if ( !elem )
+ return false;
+
+ bool isSatisfy = myAllNodesFlag, isNodeOut;
+
+ gp_XYZ centerXYZ (0, 0, 0);
+
+ if ( !myOctree && myClassifiers.size() > 5 )
+ {
+ myWorkClassifiers.resize( myClassifiers.size() );
+ for ( size_t i = 0; i < myClassifiers.size(); ++i )
+ myWorkClassifiers[ i ] = & myClassifiers[ i ];
+ myOctree = new OctreeClassifier( myWorkClassifiers );
+ }
+
+ for ( int i = 0, nb = elem->NbNodes(); i < nb && (isSatisfy == myAllNodesFlag); ++i )
+ {
+ SMESH_TNodeXYZ aPnt( elem->GetNode( i ));
+ centerXYZ += aPnt;
+
+ isNodeOut = true;
+ if ( !getNodeIsOut( aPnt._node, isNodeOut ))
+ {
+ if ( myOctree )
+ {
+ myWorkClassifiers.clear();
+ myOctree->GetClassifiersAtPoint( aPnt, myWorkClassifiers );
+
+ for ( size_t i = 0; i < myWorkClassifiers.size(); ++i )
+ myWorkClassifiers[i]->SetChecked( false );
+
+ for ( size_t i = 0; i < myWorkClassifiers.size() && isNodeOut; ++i )
+ if ( !myWorkClassifiers[i]->IsChecked() )
+ isNodeOut = myWorkClassifiers[i]->IsOut( aPnt );
+ }
+ else
+ {
+ for ( size_t i = 0; i < myClassifiers.size() && isNodeOut; ++i )
+ isNodeOut = myClassifiers[i].IsOut( aPnt );
+ }
+ setNodeIsOut( aPnt._node, isNodeOut );
+ }
+ isSatisfy = !isNodeOut;
+ }
+
+ // Check the center point for volumes MantisBug 0020168
+ if ( isSatisfy &&
+ myAllNodesFlag &&
+ myClassifiers[0].ShapeType() == TopAbs_SOLID )
+ {
+ centerXYZ /= elem->NbNodes();
+ isSatisfy = false;
+ if ( myOctree )
+ for ( size_t i = 0; i < myWorkClassifiers.size() && !isSatisfy; ++i )
+ isSatisfy = ! myWorkClassifiers[i]->IsOut( centerXYZ );
+ else
+ for ( size_t i = 0; i < myClassifiers.size() && !isSatisfy; ++i )
+ isSatisfy = ! myClassifiers[i].IsOut( centerXYZ );
+ }
+
+ return isSatisfy;
+}
+
+//================================================================================
+/*!
+ * \brief Check and optionally return a satisfying shape
+ */
+//================================================================================
+
+bool ElementsOnShape::IsSatisfy (const SMDS_MeshNode* node,
+ TopoDS_Shape* okShape)
+{
+ if ( !node )
+ return false;
+
+ if ( !myOctree && myClassifiers.size() > 5 )
+ {
+ myWorkClassifiers.resize( myClassifiers.size() );
+ for ( size_t i = 0; i < myClassifiers.size(); ++i )
+ myWorkClassifiers[ i ] = & myClassifiers[ i ];
+ myOctree = new OctreeClassifier( myWorkClassifiers );
+ }
+
+ bool isNodeOut = true;
+
+ if ( okShape || !getNodeIsOut( node, isNodeOut ))
+ {
+ SMESH_NodeXYZ aPnt = node;
+ if ( myOctree )
+ {
+ myWorkClassifiers.clear();
+ myOctree->GetClassifiersAtPoint( aPnt, myWorkClassifiers );
+
+ for ( size_t i = 0; i < myWorkClassifiers.size(); ++i )
+ myWorkClassifiers[i]->SetChecked( false );
+
+ for ( size_t i = 0; i < myWorkClassifiers.size(); ++i )
+ if ( !myWorkClassifiers[i]->IsChecked() &&
+ !myWorkClassifiers[i]->IsOut( aPnt ))
+ {
+ isNodeOut = false;
+ if ( okShape )
+ *okShape = myWorkClassifiers[i]->Shape();
+ break;
+ }
+ }
+ else
+ {
+ for ( size_t i = 0; i < myClassifiers.size(); ++i )
+ if ( !myClassifiers[i].IsOut( aPnt ))
+ {
+ isNodeOut = false;
+ if ( okShape )
+ *okShape = myWorkClassifiers[i]->Shape();
+ break;
+ }
+ }
+ setNodeIsOut( node, isNodeOut );
+ }
+
+ return !isNodeOut;
+}
+
+void ElementsOnShape::Classifier::Init( const TopoDS_Shape& theShape,
+ double theTol,
+ const Bnd_B3d* theBox )
+{
+ myShape = theShape;
+ myTol = theTol;
+ myFlags = 0;
+
+ bool isShapeBox = false;
+ switch ( myShape.ShapeType() )
+ {
+ case TopAbs_SOLID:
+ {
+ if (( isShapeBox = isBox( theShape )))
+ {
+ myIsOutFun = & ElementsOnShape::Classifier::isOutOfBox;
+ }
+ else
+ {
+ mySolidClfr = new BRepClass3d_SolidClassifier(theShape);
+ myIsOutFun = & ElementsOnShape::Classifier::isOutOfSolid;
+ }
+ break;
+ }
+ case TopAbs_FACE:
+ {
+ Standard_Real u1,u2,v1,v2;
+ Handle(Geom_Surface) surf = BRep_Tool::Surface( TopoDS::Face( theShape ));
+ surf->Bounds( u1,u2,v1,v2 );
+ myProjFace.Init(surf, u1,u2, v1,v2, myTol );
+ myIsOutFun = & ElementsOnShape::Classifier::isOutOfFace;
+ break;
+ }
+ case TopAbs_EDGE:
+ {
+ Standard_Real u1, u2;
+ Handle(Geom_Curve) curve = BRep_Tool::Curve( TopoDS::Edge( theShape ), u1, u2);
+ myProjEdge.Init(curve, u1, u2);
+ myIsOutFun = & ElementsOnShape::Classifier::isOutOfEdge;
+ break;
+ }
+ case TopAbs_VERTEX:
+ {
+ myVertexXYZ = BRep_Tool::Pnt( TopoDS::Vertex( theShape ) );
+ myIsOutFun = & ElementsOnShape::Classifier::isOutOfVertex;
+ break;
+ }
+ default:
+ throw SALOME_Exception("Programmer error in usage of ElementsOnShape::Classifier");
+ }
+
+ if ( !isShapeBox )
+ {
+ if ( theBox )
+ {
+ myBox = *theBox;
+ }
+ else
+ {
+ Bnd_Box box;
+ BRepBndLib::Add( myShape, box );
+ myBox.Clear();
+ myBox.Add( box.CornerMin() );
+ myBox.Add( box.CornerMax() );
+ gp_XYZ halfSize = 0.5 * ( box.CornerMax().XYZ() - box.CornerMin().XYZ() );
+ for ( int iDim = 1; iDim <= 3; ++iDim )
+ {
+ double x = halfSize.Coord( iDim );
+ halfSize.SetCoord( iDim, x + Max( myTol, 1e-2 * x ));
+ }
+ myBox.SetHSize( halfSize );
+ }
+ }
+}
+
+ElementsOnShape::Classifier::~Classifier()
+{
+ delete mySolidClfr; mySolidClfr = 0;
+}
+
+bool ElementsOnShape::Classifier::isOutOfSolid (const gp_Pnt& p)
+{
+ if ( isOutOfBox( p )) return true;
+ mySolidClfr->Perform( p, myTol );
+ return ( mySolidClfr->State() != TopAbs_IN && mySolidClfr->State() != TopAbs_ON );
+}
+
+bool ElementsOnShape::Classifier::isOutOfBox (const gp_Pnt& p)
+{
+ return myBox.IsOut( p.XYZ() );
+}
+
+bool ElementsOnShape::Classifier::isOutOfFace (const gp_Pnt& p)
+{
+ if ( isOutOfBox( p )) return true;
+ myProjFace.Perform( p );
+ if ( myProjFace.IsDone() && myProjFace.LowerDistance() <= myTol )
+ {
+ // check relatively to the face
+ Standard_Real u, v;
+ myProjFace.LowerDistanceParameters(u, v);
+ gp_Pnt2d aProjPnt (u, v);
+ BRepClass_FaceClassifier aClsf ( TopoDS::Face( myShape ), aProjPnt, myTol );
+ if ( aClsf.State() == TopAbs_IN || aClsf.State() == TopAbs_ON )
+ return false;
+ }
+ return true;
+}
+
+bool ElementsOnShape::Classifier::isOutOfEdge (const gp_Pnt& p)
+{
+ if ( isOutOfBox( p )) return true;
+ myProjEdge.Perform( p );
+ return ! ( myProjEdge.NbPoints() > 0 && myProjEdge.LowerDistance() <= myTol );
+}
+
+bool ElementsOnShape::Classifier::isOutOfVertex(const gp_Pnt& p)
+{
+ return ( myVertexXYZ.Distance( p ) > myTol );
+}
+
+bool ElementsOnShape::Classifier::isBox (const TopoDS_Shape& theShape)
+{
+ TopTools_IndexedMapOfShape vMap;
+ TopExp::MapShapes( theShape, TopAbs_VERTEX, vMap );
+ if ( vMap.Extent() != 8 )
+ return false;
+
+ myBox.Clear();
+ for ( int i = 1; i <= 8; ++i )
+ myBox.Add( BRep_Tool::Pnt( TopoDS::Vertex( vMap( i ))).XYZ() );
+
+ gp_XYZ pMin = myBox.CornerMin(), pMax = myBox.CornerMax();
+ for ( int i = 1; i <= 8; ++i )
+ {
+ gp_Pnt p = BRep_Tool::Pnt( TopoDS::Vertex( vMap( i )));
+ for ( int iC = 1; iC <= 3; ++ iC )
+ {
+ double d1 = Abs( pMin.Coord( iC ) - p.Coord( iC ));
+ double d2 = Abs( pMax.Coord( iC ) - p.Coord( iC ));
+ if ( Min( d1, d2 ) > myTol )
+ return false;
+ }
+ }
+ myBox.Enlarge( myTol );
+ return true;
+}
+
+ElementsOnShape::
+OctreeClassifier::OctreeClassifier( const std::vector< ElementsOnShape::Classifier* >& classifiers )
+ :SMESH_Octree( new SMESH_TreeLimit )
+{
+ myClassifiers = classifiers;
+ compute();
+}
+
+ElementsOnShape::
+OctreeClassifier::OctreeClassifier( const OctreeClassifier* otherTree,
+ const std::vector< ElementsOnShape::Classifier >& clsOther,
+ std::vector< ElementsOnShape::Classifier >& cls )
+ :SMESH_Octree( new SMESH_TreeLimit )
+{
+ myBox = new Bnd_B3d( *otherTree->getBox() );
+
+ if (( myIsLeaf = otherTree->isLeaf() ))
+ {
+ myClassifiers.resize( otherTree->myClassifiers.size() );
+ for ( size_t i = 0; i < otherTree->myClassifiers.size(); ++i )
+ {
+ int ind = otherTree->myClassifiers[i] - & clsOther[0];
+ myClassifiers[ i ] = & cls[ ind ];
+ }
+ }
+ else if ( otherTree->myChildren )
+ {
+ myChildren = new SMESH_Tree< Bnd_B3d, 8 > * [ 8 ];
+ for ( int i = 0; i < nbChildren(); i++ )
+ myChildren[i] =
+ new OctreeClassifier( static_cast<const OctreeClassifier*>( otherTree->myChildren[i]),
+ clsOther, cls );
+ }
+}
+
+void ElementsOnShape::
+OctreeClassifier::GetClassifiersAtPoint( const gp_XYZ& point,
+ std::vector< ElementsOnShape::Classifier* >& result )
+{
+ if ( getBox()->IsOut( point ))
+ return;
+
+ if ( isLeaf() )
+ {
+ for ( size_t i = 0; i < myClassifiers.size(); ++i )
+ if ( !myClassifiers[i]->GetBndBox()->IsOut( point ))
+ result.push_back( myClassifiers[i] );
+ }
+ else
+ {
+ for (int i = 0; i < nbChildren(); i++)
+ ((OctreeClassifier*) myChildren[i])->GetClassifiersAtPoint( point, result );
+ }
+}
+
+void ElementsOnShape::OctreeClassifier::buildChildrenData()
+{
+ // distribute myClassifiers among myChildren
+
+ const int childFlag[8] = { 0x0000001,
+ 0x0000002,
+ 0x0000004,
+ 0x0000008,
+ 0x0000010,
+ 0x0000020,
+ 0x0000040,
+ 0x0000080 };
+ int nbInChild[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
+
+ for ( size_t i = 0; i < myClassifiers.size(); ++i )
+ {
+ for ( int j = 0; j < nbChildren(); j++ )
+ {
+ if ( !myClassifiers[i]->GetBndBox()->IsOut( *myChildren[j]->getBox() ))
+ {
+ myClassifiers[i]->SetFlag( childFlag[ j ]);
+ ++nbInChild[ j ];