+ _elementType = type;
+ ElementBndBoxTree*& ebbTree = _ebbTree[ type ];
+ if ( !ebbTree )
+ ebbTree = new ElementBndBoxTree( *_mesh, _elementType, _meshPartIt );
+
+ ElementBndBoxTree::TElemSeq elems;
+ ebbTree->getElementsInSphere( center, radius, elems );
+
+ foundElems.insert( foundElems.end(), elems.begin(), elems.end() );
+}
+
+//=======================================================================
+/*
+ * Return elements whose bounding box intersects a given bounding box
+ */
+//=======================================================================
+
+void SMESH_ElementSearcherImpl::
+GetElementsInBox( const Bnd_B3d& box,
+ SMDSAbs_ElementType type,
+ std::vector< const SMDS_MeshElement* >& foundElems)
+{
+ _elementType = type;
+ ElementBndBoxTree*& ebbTree = _ebbTree[ type ];
+ if ( !ebbTree )
+ ebbTree = new ElementBndBoxTree( *_mesh, _elementType, _meshPartIt, getTolerance() );
+
+ ElementBndBoxTree::TElemSeq elems;
+ ebbTree->getElementsInBox( box, elems );
+
+ foundElems.insert( foundElems.end(), elems.begin(), elems.end() );
+}
+
+//=======================================================================
+/*
+ * \brief Return a projection of a given point to a mesh.
+ * Optionally return the closest element
+ */
+//=======================================================================
+
+gp_XYZ SMESH_ElementSearcherImpl::Project(const gp_Pnt& point,
+ SMDSAbs_ElementType type,
+ const SMDS_MeshElement** closestElem)
+{
+ _elementType = type;
+ if ( _mesh->GetMeshInfo().NbElements( _elementType ) == 0 )
+ throw SALOME_Exception( LOCALIZED( "No elements of given type in the mesh" ));
+
+ ElementBndBoxTree*& ebbTree = _ebbTree[ _elementType ];
+ if ( !ebbTree )
+ ebbTree = new ElementBndBoxTree( *_mesh, _elementType );
+
+ gp_XYZ p = point.XYZ();
+ ElementBndBoxTree* ebbLeaf = ebbTree->getLeafAtPoint( p );
+ const Bnd_B3d* box = ebbLeaf->getBox();
+ double radius = ( box->CornerMax() - box->CornerMin() ).Modulus();
+
+ ElementBndBoxTree::TElemSeq elems;
+ ebbTree->getElementsInSphere( p, radius, elems );
+ while ( elems.empty() )
+ {
+ radius *= 1.5;
+ ebbTree->getElementsInSphere( p, radius, elems );
+ }
+ gp_XYZ proj, bestProj;
+ const SMDS_MeshElement* elem = 0;
+ double minDist = 2 * radius;
+ ElementBndBoxTree::TElemSeq::iterator e = elems.begin();
+ for ( ; e != elems.end(); ++e )