- newGroup->Add( *resElemIt );
- }
- }
- } // loop on created elements
- }// loop on nodes and elements
-
- return newGroupIDs;
-}
-
-//================================================================================
-/*!
- * \brief Return list of group of nodes close to each other within theTolerance
- * Search among theNodes or in the whole mesh if theNodes is empty using
- * an Octree algorithm
- */
-//================================================================================
-
-void SMESH_MeshEditor::FindCoincidentNodes (TIDSortedNodeSet & theNodes,
- const double theTolerance,
- TListOfListOfNodes & theGroupsOfNodes)
-{
- myLastCreatedElems.Clear();
- myLastCreatedNodes.Clear();
-
- if ( theNodes.empty() )
- { // get all nodes in the mesh
- SMDS_NodeIteratorPtr nIt = GetMeshDS()->nodesIterator(/*idInceasingOrder=*/true);
- while ( nIt->more() )
- theNodes.insert( theNodes.end(),nIt->next());
- }
-
- SMESH_OctreeNode::FindCoincidentNodes ( theNodes, &theGroupsOfNodes, theTolerance);
-}
-
-
-//=======================================================================
-/*!
- * \brief Implementation of search for the node closest to point
- */
-//=======================================================================
-
-struct SMESH_NodeSearcherImpl: public SMESH_NodeSearcher
-{
- //---------------------------------------------------------------------
- /*!
- * \brief Constructor
- */
- SMESH_NodeSearcherImpl( const SMESHDS_Mesh* theMesh )
- {
- myMesh = ( SMESHDS_Mesh* ) theMesh;
-
- TIDSortedNodeSet nodes;
- if ( theMesh ) {
- SMDS_NodeIteratorPtr nIt = theMesh->nodesIterator(/*idInceasingOrder=*/true);
- while ( nIt->more() )
- nodes.insert( nodes.end(), nIt->next() );
- }
- myOctreeNode = new SMESH_OctreeNode(nodes) ;
-
- // get max size of a leaf box
- SMESH_OctreeNode* tree = myOctreeNode;
- while ( !tree->isLeaf() )
- {
- SMESH_OctreeNodeIteratorPtr cIt = tree->GetChildrenIterator();
- if ( cIt->more() )
- tree = cIt->next();
- }
- myHalfLeafSize = tree->maxSize() / 2.;
- }
-
- //---------------------------------------------------------------------
- /*!
- * \brief Move node and update myOctreeNode accordingly
- */
- void MoveNode( const SMDS_MeshNode* node, const gp_Pnt& toPnt )
- {
- myOctreeNode->UpdateByMoveNode( node, toPnt );
- myMesh->MoveNode( node, toPnt.X(), toPnt.Y(), toPnt.Z() );
- }
-
- //---------------------------------------------------------------------
- /*!
- * \brief Do it's job
- */
- const SMDS_MeshNode* FindClosestTo( const gp_Pnt& thePnt )
- {
- map<double, const SMDS_MeshNode*> dist2Nodes;
- myOctreeNode->NodesAround( thePnt.Coord(), dist2Nodes, myHalfLeafSize );
- if ( !dist2Nodes.empty() )
- return dist2Nodes.begin()->second;
- list<const SMDS_MeshNode*> nodes;
- //myOctreeNode->NodesAround( &tgtNode, &nodes, myHalfLeafSize );
-
- double minSqDist = DBL_MAX;
- if ( nodes.empty() ) // get all nodes of OctreeNode's closest to thePnt
- {
- // sort leafs by their distance from thePnt
- typedef map< double, SMESH_OctreeNode* > TDistTreeMap;
- TDistTreeMap treeMap;
- list< SMESH_OctreeNode* > treeList;
- list< SMESH_OctreeNode* >::iterator trIt;
- treeList.push_back( myOctreeNode );
-
- gp_XYZ pointNode( thePnt.X(), thePnt.Y(), thePnt.Z() );
- bool pointInside = myOctreeNode->isInside( pointNode, myHalfLeafSize );
- for ( trIt = treeList.begin(); trIt != treeList.end(); ++trIt)
- {
- SMESH_OctreeNode* tree = *trIt;
- if ( !tree->isLeaf() ) // put children to the queue
- {
- if ( pointInside && !tree->isInside( pointNode, myHalfLeafSize )) continue;
- SMESH_OctreeNodeIteratorPtr cIt = tree->GetChildrenIterator();
- while ( cIt->more() )
- treeList.push_back( cIt->next() );
- }
- else if ( tree->NbNodes() ) // put a tree to the treeMap
- {
- const Bnd_B3d& box = tree->getBox();
- double sqDist = thePnt.SquareDistance( 0.5 * ( box.CornerMin() + box.CornerMax() ));
- pair<TDistTreeMap::iterator,bool> it_in = treeMap.insert( make_pair( sqDist, tree ));
- if ( !it_in.second ) // not unique distance to box center
- treeMap.insert( it_in.first, make_pair( sqDist + 1e-13*treeMap.size(), tree ));
- }
- }
- // find distance after which there is no sense to check tree's
- double sqLimit = DBL_MAX;
- TDistTreeMap::iterator sqDist_tree = treeMap.begin();
- if ( treeMap.size() > 5 ) {
- SMESH_OctreeNode* closestTree = sqDist_tree->second;
- const Bnd_B3d& box = closestTree->getBox();
- double limit = sqrt( sqDist_tree->first ) + sqrt ( box.SquareExtent() );
- sqLimit = limit * limit;
- }
- // get all nodes from trees
- for ( ; sqDist_tree != treeMap.end(); ++sqDist_tree) {
- if ( sqDist_tree->first > sqLimit )
- break;
- SMESH_OctreeNode* tree = sqDist_tree->second;
- tree->NodesAround( tree->GetNodeIterator()->next(), &nodes );
- }
- }
- // find closest among nodes
- minSqDist = DBL_MAX;
- const SMDS_MeshNode* closestNode = 0;
- list<const SMDS_MeshNode*>::iterator nIt = nodes.begin();
- for ( ; nIt != nodes.end(); ++nIt ) {
- double sqDist = thePnt.SquareDistance( SMESH_TNodeXYZ( *nIt ) );
- if ( minSqDist > sqDist ) {
- closestNode = *nIt;
- minSqDist = sqDist;
- }
- }
- return closestNode;
- }
-
- //---------------------------------------------------------------------
- /*!
- * \brief Destructor
- */
- ~SMESH_NodeSearcherImpl() { delete myOctreeNode; }
-
- //---------------------------------------------------------------------
- /*!
- * \brief Return the node tree
- */
- const SMESH_OctreeNode* getTree() const { return myOctreeNode; }
-
-private:
- SMESH_OctreeNode* myOctreeNode;
- SMESHDS_Mesh* myMesh;
- double myHalfLeafSize; // max size of a leaf box
-};
-
-//=======================================================================
-/*!
- * \brief Return SMESH_NodeSearcher
- */
-//=======================================================================
-
-SMESH_NodeSearcher* SMESH_MeshEditor::GetNodeSearcher()
-{
- return new SMESH_NodeSearcherImpl( GetMeshDS() );
-}
-
-// ========================================================================
-namespace // Utils used in SMESH_ElementSearcherImpl::FindElementsByPoint()
-{
- const int MaxNbElemsInLeaf = 10; // maximal number of elements in a leaf of tree
- const int MaxLevel = 7; // maximal tree height -> nb terminal boxes: 8^7 = 2097152
- const double NodeRadius = 1e-9; // to enlarge bnd box of element
-
- //=======================================================================
- /*!
- * \brief Octal tree of bounding boxes of elements
- */
- //=======================================================================
-
- class ElementBndBoxTree : public SMESH_Octree
- {
- public:
-
- ElementBndBoxTree(const SMDS_Mesh& mesh,
- SMDSAbs_ElementType elemType,
- SMDS_ElemIteratorPtr theElemIt = SMDS_ElemIteratorPtr(),
- double tolerance = NodeRadius );
- void getElementsNearPoint( const gp_Pnt& point, TIDSortedElemSet& foundElems );
- void getElementsNearLine ( const gp_Ax1& line, TIDSortedElemSet& foundElems);
- void getElementsInSphere ( const gp_XYZ& center,
- const double radius, TIDSortedElemSet& foundElems);
- size_t getSize() { return std::max( _size, _elements.size() ); }
- ~ElementBndBoxTree();
-
- protected:
- ElementBndBoxTree():_size(0) {}
- SMESH_Octree* allocateOctreeChild() const { return new ElementBndBoxTree; }
- void buildChildrenData();
- Bnd_B3d* buildRootBox();
- private:
- //!< Bounding box of element
- struct ElementBox : public Bnd_B3d
- {
- const SMDS_MeshElement* _element;
- int _refCount; // an ElementBox can be included in several tree branches
- ElementBox(const SMDS_MeshElement* elem, double tolerance);
- };
- vector< ElementBox* > _elements;
- size_t _size;
- };
-
- //================================================================================
- /*!
- * \brief ElementBndBoxTree creation
- */
- //================================================================================
-
- ElementBndBoxTree::ElementBndBoxTree(const SMDS_Mesh& mesh, SMDSAbs_ElementType elemType, SMDS_ElemIteratorPtr theElemIt, double tolerance)
- :SMESH_Octree( new SMESH_Octree::Limit( MaxLevel, /*minSize=*/0. ))
- {
- int nbElems = mesh.GetMeshInfo().NbElements( elemType );
- _elements.reserve( nbElems );
-
- SMDS_ElemIteratorPtr elemIt = theElemIt ? theElemIt : mesh.elementsIterator( elemType );
- while ( elemIt->more() )
- _elements.push_back( new ElementBox( elemIt->next(),tolerance ));
-
- compute();
- }
-
- //================================================================================
- /*!
- * \brief Destructor
- */
- //================================================================================
-
- ElementBndBoxTree::~ElementBndBoxTree()
- {
- for ( int i = 0; i < _elements.size(); ++i )
- if ( --_elements[i]->_refCount <= 0 )
- delete _elements[i];
- }
-
- //================================================================================
- /*!
- * \brief Return the maximal box
- */
- //================================================================================
-
- Bnd_B3d* ElementBndBoxTree::buildRootBox()
- {
- Bnd_B3d* box = new Bnd_B3d;
- for ( int i = 0; i < _elements.size(); ++i )
- box->Add( *_elements[i] );
- return box;
- }
-
- //================================================================================
- /*!
- * \brief Redistrubute element boxes among children
- */
- //================================================================================
-
- void ElementBndBoxTree::buildChildrenData()
- {
- for ( int i = 0; i < _elements.size(); ++i )
- {
- for (int j = 0; j < 8; j++)
- {
- if ( !_elements[i]->IsOut( myChildren[j]->getBox() ))
- {
- _elements[i]->_refCount++;
- ((ElementBndBoxTree*)myChildren[j])->_elements.push_back( _elements[i]);
- }
- }
- _elements[i]->_refCount--;
- }
- _size = _elements.size();
- SMESHUtils::FreeVector( _elements ); // = _elements.clear() + free memory
-
- for (int j = 0; j < 8; j++)
- {
- ElementBndBoxTree* child = static_cast<ElementBndBoxTree*>( myChildren[j]);
- if ( child->_elements.size() <= MaxNbElemsInLeaf )
- child->myIsLeaf = true;
-
- if ( child->_elements.capacity() - child->_elements.size() > 1000 )
- SMESHUtils::CompactVector( child->_elements );
- }
- }
-
- //================================================================================
- /*!
- * \brief Return elements which can include the point
- */
- //================================================================================
-
- void ElementBndBoxTree::getElementsNearPoint( const gp_Pnt& point,
- TIDSortedElemSet& foundElems)
- {
- if ( getBox().IsOut( point.XYZ() ))
- return;
-
- if ( isLeaf() )
- {
- for ( int i = 0; i < _elements.size(); ++i )
- if ( !_elements[i]->IsOut( point.XYZ() ))
- foundElems.insert( _elements[i]->_element );
- }
- else
- {
- for (int i = 0; i < 8; i++)
- ((ElementBndBoxTree*) myChildren[i])->getElementsNearPoint( point, foundElems );
- }
- }
-
- //================================================================================
- /*!
- * \brief Return elements which can be intersected by the line
- */
- //================================================================================
-
- void ElementBndBoxTree::getElementsNearLine( const gp_Ax1& line,
- TIDSortedElemSet& foundElems)
- {
- if ( getBox().IsOut( line ))
- return;
-
- if ( isLeaf() )
- {
- for ( int i = 0; i < _elements.size(); ++i )
- if ( !_elements[i]->IsOut( line ))
- foundElems.insert( _elements[i]->_element );
- }
- else
- {
- for (int i = 0; i < 8; i++)
- ((ElementBndBoxTree*) myChildren[i])->getElementsNearLine( line, foundElems );
- }
- }
-
- //================================================================================
- /*!
- * \brief Return elements from leaves intersecting the sphere
- */
- //================================================================================
-
- void ElementBndBoxTree::getElementsInSphere ( const gp_XYZ& center,
- const double radius,
- TIDSortedElemSet& foundElems)
- {
- if ( getBox().IsOut( center, radius ))
- return;
-
- if ( isLeaf() )
- {
- for ( int i = 0; i < _elements.size(); ++i )
- if ( !_elements[i]->IsOut( center, radius ))
- foundElems.insert( _elements[i]->_element );
- }
- else
- {
- for (int i = 0; i < 8; i++)
- ((ElementBndBoxTree*) myChildren[i])->getElementsInSphere( center, radius, foundElems );
- }
- }
-
- //================================================================================
- /*!
- * \brief Construct the element box
- */
- //================================================================================
-
- ElementBndBoxTree::ElementBox::ElementBox(const SMDS_MeshElement* elem, double tolerance)
- {
- _element = elem;
- _refCount = 1;
- SMDS_ElemIteratorPtr nIt = elem->nodesIterator();
- while ( nIt->more() )
- Add( SMESH_TNodeXYZ( nIt->next() ));
- Enlarge( tolerance );
- }
-
-} // namespace
-
-//=======================================================================
-/*!
- * \brief Implementation of search for the elements by point and
- * of classification of point in 2D mesh
- */
-//=======================================================================
-
-struct SMESH_ElementSearcherImpl: public SMESH_ElementSearcher
-{
- SMESHDS_Mesh* _mesh;
- SMDS_ElemIteratorPtr _meshPartIt;
- ElementBndBoxTree* _ebbTree;
- SMESH_NodeSearcherImpl* _nodeSearcher;
- SMDSAbs_ElementType _elementType;
- double _tolerance;
- bool _outerFacesFound;
- set<const SMDS_MeshElement*> _outerFaces; // empty means "no internal faces at all"
-
- SMESH_ElementSearcherImpl( SMESHDS_Mesh& mesh, SMDS_ElemIteratorPtr elemIt=SMDS_ElemIteratorPtr())
- : _mesh(&mesh),_meshPartIt(elemIt),_ebbTree(0),_nodeSearcher(0),_tolerance(-1),_outerFacesFound(false) {}
- ~SMESH_ElementSearcherImpl()
- {
- if ( _ebbTree ) delete _ebbTree; _ebbTree = 0;
- if ( _nodeSearcher ) delete _nodeSearcher; _nodeSearcher = 0;
- }
- virtual int FindElementsByPoint(const gp_Pnt& point,
- SMDSAbs_ElementType type,
- vector< const SMDS_MeshElement* >& foundElements);
- virtual TopAbs_State GetPointState(const gp_Pnt& point);
- virtual const SMDS_MeshElement* FindClosestTo( const gp_Pnt& point,
- SMDSAbs_ElementType type );
-
- void GetElementsNearLine( const gp_Ax1& line,
- SMDSAbs_ElementType type,
- vector< const SMDS_MeshElement* >& foundElems);
- double getTolerance();
- bool getIntersParamOnLine(const gp_Lin& line, const SMDS_MeshElement* face,
- const double tolerance, double & param);
- void findOuterBoundary(const SMDS_MeshElement* anyOuterFace);
- bool isOuterBoundary(const SMDS_MeshElement* face) const
- {
- return _outerFaces.empty() || _outerFaces.count(face);
- }
- struct TInters //!< data of intersection of the line and the mesh face (used in GetPointState())
- {
- const SMDS_MeshElement* _face;
- gp_Vec _faceNorm;
- bool _coincides; //!< the line lays in face plane
- TInters(const SMDS_MeshElement* face, const gp_Vec& faceNorm, bool coinc=false)
- : _face(face), _faceNorm( faceNorm ), _coincides( coinc ) {}
- };
- struct TFaceLink //!< link and faces sharing it (used in findOuterBoundary())
- {
- SMESH_TLink _link;
- TIDSortedElemSet _faces;
- TFaceLink( const SMDS_MeshNode* n1, const SMDS_MeshNode* n2, const SMDS_MeshElement* face)
- : _link( n1, n2 ), _faces( &face, &face + 1) {}
- };
-};
-
-ostream& operator<< (ostream& out, const SMESH_ElementSearcherImpl::TInters& i)
-{
- return out << "TInters(face=" << ( i._face ? i._face->GetID() : 0)
- << ", _coincides="<<i._coincides << ")";
-}
-
-//=======================================================================
-/*!
- * \brief define tolerance for search
- */
-//=======================================================================
-
-double SMESH_ElementSearcherImpl::getTolerance()
-{
- if ( _tolerance < 0 )
- {
- const SMDS_MeshInfo& meshInfo = _mesh->GetMeshInfo();
-
- _tolerance = 0;
- if ( _nodeSearcher && meshInfo.NbNodes() > 1 )
- {
- double boxSize = _nodeSearcher->getTree()->maxSize();
- _tolerance = 1e-8 * boxSize/* / meshInfo.NbNodes()*/;
- }
- else if ( _ebbTree && meshInfo.NbElements() > 0 )
- {
- double boxSize = _ebbTree->maxSize();
- _tolerance = 1e-8 * boxSize/* / meshInfo.NbElements()*/;
- }
- if ( _tolerance == 0 )
- {
- // define tolerance by size of a most complex element
- int complexType = SMDSAbs_Volume;
- while ( complexType > SMDSAbs_All &&
- meshInfo.NbElements( SMDSAbs_ElementType( complexType )) < 1 )
- --complexType;
- if ( complexType == SMDSAbs_All ) return 0; // empty mesh
- double elemSize;
- if ( complexType == int( SMDSAbs_Node ))
- {
- SMDS_NodeIteratorPtr nodeIt = _mesh->nodesIterator();
- elemSize = 1;
- if ( meshInfo.NbNodes() > 2 )
- elemSize = SMESH_TNodeXYZ( nodeIt->next() ).Distance( nodeIt->next() );
- }
- else
- {
- SMDS_ElemIteratorPtr elemIt =
- _mesh->elementsIterator( SMDSAbs_ElementType( complexType ));
- const SMDS_MeshElement* elem = elemIt->next();
- SMDS_ElemIteratorPtr nodeIt = elem->nodesIterator();
- SMESH_TNodeXYZ n1( cast2Node( nodeIt->next() ));
- elemSize = 0;
- while ( nodeIt->more() )
- {
- double dist = n1.Distance( cast2Node( nodeIt->next() ));
- elemSize = max( dist, elemSize );
- }
- }
- _tolerance = 1e-4 * elemSize;
- }
- }
- return _tolerance;
-}
-
-//================================================================================
-/*!
- * \brief Find intersection of the line and an edge of face and return parameter on line
- */
-//================================================================================
-
-bool SMESH_ElementSearcherImpl::getIntersParamOnLine(const gp_Lin& line,
- const SMDS_MeshElement* face,
- const double tol,
- double & param)
-{
- int nbInts = 0;
- param = 0;
-
- GeomAPI_ExtremaCurveCurve anExtCC;
- Handle(Geom_Curve) lineCurve = new Geom_Line( line );
-
- int nbNodes = face->IsQuadratic() ? face->NbNodes()/2 : face->NbNodes();
- for ( int i = 0; i < nbNodes && nbInts < 2; ++i )
- {
- GC_MakeSegment edge( SMESH_TNodeXYZ( face->GetNode( i )),
- SMESH_TNodeXYZ( face->GetNode( (i+1)%nbNodes) ));
- anExtCC.Init( lineCurve, edge);
- if ( anExtCC.NbExtrema() > 0 && anExtCC.LowerDistance() <= tol)
- {
- Quantity_Parameter pl, pe;
- anExtCC.LowerDistanceParameters( pl, pe );
- param += pl;
- if ( ++nbInts == 2 )
- break;
- }
- }
- if ( nbInts > 0 ) param /= nbInts;
- return nbInts > 0;
-}
-//================================================================================
-/*!
- * \brief Find all faces belonging to the outer boundary of mesh
- */
-//================================================================================
-
-void SMESH_ElementSearcherImpl::findOuterBoundary(const SMDS_MeshElement* outerFace)
-{
- if ( _outerFacesFound ) return;
-
- // Collect all outer faces by passing from one outer face to another via their links
- // and BTW find out if there are internal faces at all.
-
- // checked links and links where outer boundary meets internal one
- set< SMESH_TLink > visitedLinks, seamLinks;
-
- // links to treat with already visited faces sharing them
- list < TFaceLink > startLinks;
-
- // load startLinks with the first outerFace
- startLinks.push_back( TFaceLink( outerFace->GetNode(0), outerFace->GetNode(1), outerFace));
- _outerFaces.insert( outerFace );
-
- TIDSortedElemSet emptySet;
- while ( !startLinks.empty() )
- {
- const SMESH_TLink& link = startLinks.front()._link;
- TIDSortedElemSet& faces = startLinks.front()._faces;
-
- outerFace = *faces.begin();
- // find other faces sharing the link
- const SMDS_MeshElement* f;
- while (( f = SMESH_MeshEditor::FindFaceInSet(link.node1(), link.node2(), emptySet, faces )))
- faces.insert( f );
-
- // select another outer face among the found
- const SMDS_MeshElement* outerFace2 = 0;
- if ( faces.size() == 2 )
- {
- outerFace2 = (outerFace == *faces.begin() ? *faces.rbegin() : *faces.begin());
- }
- else if ( faces.size() > 2 )
- {
- seamLinks.insert( link );
-
- // link direction within the outerFace
- gp_Vec n1n2( SMESH_TNodeXYZ( link.node1()),
- SMESH_TNodeXYZ( link.node2()));
- int i1 = outerFace->GetNodeIndex( link.node1() );
- int i2 = outerFace->GetNodeIndex( link.node2() );
- bool rev = ( abs(i2-i1) == 1 ? i1 > i2 : i2 > i1 );
- if ( rev ) n1n2.Reverse();
- // outerFace normal
- gp_XYZ ofNorm, fNorm;
- if ( SMESH_Algo::FaceNormal( outerFace, ofNorm, /*normalized=*/false ))
- {
- // direction from the link inside outerFace
- gp_Vec dirInOF = gp_Vec( ofNorm ) ^ n1n2;
- // sort all other faces by angle with the dirInOF
- map< double, const SMDS_MeshElement* > angle2Face;
- set< const SMDS_MeshElement*, TIDCompare >::const_iterator face = faces.begin();
- for ( ; face != faces.end(); ++face )
- {
- if ( !SMESH_Algo::FaceNormal( *face, fNorm, /*normalized=*/false ))
- continue;
- gp_Vec dirInF = gp_Vec( fNorm ) ^ n1n2;
- double angle = dirInOF.AngleWithRef( dirInF, n1n2 );
- if ( angle < 0 ) angle += 2. * M_PI;
- angle2Face.insert( make_pair( angle, *face ));
- }
- if ( !angle2Face.empty() )
- outerFace2 = angle2Face.begin()->second;
- }
- }
- // store the found outer face and add its links to continue seaching from
- if ( outerFace2 )
- {
- _outerFaces.insert( outerFace );
- int nbNodes = outerFace2->NbNodes()/( outerFace2->IsQuadratic() ? 2 : 1 );
- for ( int i = 0; i < nbNodes; ++i )
- {
- SMESH_TLink link2( outerFace2->GetNode(i), outerFace2->GetNode((i+1)%nbNodes));
- if ( visitedLinks.insert( link2 ).second )
- startLinks.push_back( TFaceLink( link2.node1(), link2.node2(), outerFace2 ));
- }
- }
- startLinks.pop_front();
- }
- _outerFacesFound = true;
-
- if ( !seamLinks.empty() )
- {
- // There are internal boundaries touching the outher one,
- // find all faces of internal boundaries in order to find
- // faces of boundaries of holes, if any.
-
- }
- else
- {
- _outerFaces.clear();
- }
-}
-
-//=======================================================================
-/*!
- * \brief Find elements of given type where the given point is IN or ON.
- * Returns nb of found elements and elements them-selves.
- *
- * 'ALL' type means elements of any type excluding nodes, balls and 0D elements
- */
-//=======================================================================
-
-int SMESH_ElementSearcherImpl::
-FindElementsByPoint(const gp_Pnt& point,
- SMDSAbs_ElementType type,
- vector< const SMDS_MeshElement* >& foundElements)
-{
- foundElements.clear();
-
- double tolerance = getTolerance();
-
- // =================================================================================
- if ( type == SMDSAbs_Node || type == SMDSAbs_0DElement || type == SMDSAbs_Ball)
- {
- if ( !_nodeSearcher )
- _nodeSearcher = new SMESH_NodeSearcherImpl( _mesh );
-
- const SMDS_MeshNode* closeNode = _nodeSearcher->FindClosestTo( point );
- if ( !closeNode ) return foundElements.size();
-
- if ( point.Distance( SMESH_TNodeXYZ( closeNode )) > tolerance )
- return foundElements.size(); // to far from any node
-
- if ( type == SMDSAbs_Node )
- {
- foundElements.push_back( closeNode );
- }
- else
- {
- SMDS_ElemIteratorPtr elemIt = closeNode->GetInverseElementIterator( type );
- while ( elemIt->more() )
- foundElements.push_back( elemIt->next() );
- }
- }
- // =================================================================================
- else // elements more complex than 0D
- {
- if ( !_ebbTree || _elementType != type )
- {
- if ( _ebbTree ) delete _ebbTree;
- _ebbTree = new ElementBndBoxTree( *_mesh, _elementType = type, _meshPartIt, tolerance );
- }
- TIDSortedElemSet suspectElems;
- _ebbTree->getElementsNearPoint( point, suspectElems );
- TIDSortedElemSet::iterator elem = suspectElems.begin();
- for ( ; elem != suspectElems.end(); ++elem )
- if ( !SMESH_MeshEditor::IsOut( *elem, point, tolerance ))
- foundElements.push_back( *elem );
- }
- return foundElements.size();
-}