Hi,<br><br>I was trying to use vtkKdTreePointLocator to find closest points but from the results i obtain i'm wondering wheather there is an issue with the method FindClosestPointWithinRadius, because sometimes it returns some points with a distance bigger than the radius.<br>
<br>This method calls vtkKdTree::FindClosestPointWithinRadius which calls vtkKdTree::FindClosestPointInSphere, but here the point returned can be out of the sphere.<br>I think there must be an additional test in one of these two methods to compare the distance and the given radius.<br>
<br>here is a program test, with a comparison with vtkPointLocator that works well.<br><br>PS: i also want to bring back this problem:<br><a href="http://old.nabble.com/vtkCellLocator-precision-issue-td27453637.html#a27453637">http://old.nabble.com/vtkCellLocator-precision-issue-td27453637.html#a27453637</a><br>
which can maybe solve this one<br><a href="http://old.nabble.com/vtkCell::IntersectWithLine-issues-td18225442.html#a18234362">http://old.nabble.com/vtkCell::IntersectWithLine-issues-td18225442.html#a18234362</a><br><br><br>
#include <vtk/vtkActor.h><br>#include <vtk/vtkCleanPolyData.h><br>#include <vtk/vtkCubeSource.h><br>#include <vtk/vtkPolyData.h><br>#include <vtk/vtkPolyDataMapper.h><br>#include <vtk/vtkProperty.h><br>
#include <vtk/vtkRenderer.h><br>#include <vtk/vtkRenderWindow.h><br>#include <vtk/vtkRenderWindowInteractor.h><br>#include <vtk/vtkSmartPointer.h><br><br>#define MY_SP(class, variable)\<br> vtkSmartPointer<class> variable = vtkSmartPointer<class>::New();<br>
<br>const double cst_dRadius = 1.2;<br><br>#include <vtk/vtkKdTreePointLocator.h><br>#include <vtk/vtkPointLocator.h><br><br>bool ComputePointDistances(vtkKdTreePointLocator *locator, vtkPolyData *in)<br>{<br>
int num = in->GetNumberOfPoints();<br> cout << "number of input points : " << num << endl;<br> vtkPoints *pPoints = in->GetPoints();<br> double pt[3];<br> int cpt = 0;<br> double dDist2 = 0;<br>
<br> int bad = 0;<br> int id = -1;<br> for(int i=0; i<num; ++i)<br> {<br> pPoints->GetPoint(i, pt);<br> id = locator->FindClosestPointWithinRadius(cst_dRadius, pt, dDist2);<br> if(-1 != id)<br>
{<br> if(sqrt(dDist2) > cst_dRadius)<br> ++bad;<br> ++cpt;<br> }<br> }<br> cout << "should not be tested : " << bad << endl;<br> cout << "number of distances computed : " << cpt << endl;<br>
<br> return true;<br>}<br>bool ComputePointDistances(vtkPointLocator *locator, vtkPolyData *in)<br>{<br> int num = in->GetNumberOfPoints();<br> cout << "number of input points : " << num << endl;<br>
vtkPoints *pPoints = in->GetPoints();<br> double pt[3];<br> int cpt = 0;<br> double dDist2 = 0;<br><br> int bad = 0;<br> int id = -1;<br> for(int i=0; i<num; ++i)<br> {<br> pPoints->GetPoint(i, pt);<br>
id = locator->FindClosestPointWithinRadius(cst_dRadius, pt, dDist2);<br> if(-1 != id)<br> {<br> if(sqrt(dDist2) > cst_dRadius)<br> ++bad;<br> ++cpt;<br> }<br> }<br> cout << "should not be tested : " << bad << endl;<br>
cout << "number of distances computed : " << cpt << endl;<br><br> return true;<br>}<br><br>int main(int argc, char* argv[])<br>{<br> /////////////////////////////////////////////////////////<br>
MY_SP(vtkRenderer, ren1);<br> ren1->SetBackground(0.2, 0.2, 0.2);<br> MY_SP(vtkRenderWindow, renWin);<br> renWin->SetSize( 512, 512 );<br> renWin->AddRenderer(ren1);<br> MY_SP(vtkRenderWindowInteractor, iren);<br>
iren->SetRenderWindow(renWin);<br><br> /////////////////////////////////////////////////////////<br> MY_SP(vtkCubeSource, src);<br> src->SetBounds(-1,1,-1,1,-1,1);<br> src->Update();<br><br> MY_SP(vtkCleanPolyData, clean);<br>
clean->SetInputConnection(src->GetOutputPort());<br> clean->Update();<br> vtkPolyData *cube = clean->GetOutput();<br><br> MY_SP(vtkPolyDataMapper, Map);<br> Map->SetInput(cube);<br><br> MY_SP(vtkActor, act);<br>
act->SetMapper(Map);<br> act->GetProperty()->SetInterpolationToFlat();<br> act->GetProperty()->SetColor(1.0, 0.0, 0.0);<br><br> ren1->AddActor(act);<br><br><br> MY_SP(vtkCubeSource, src2);<br>
src2->SetBounds(0,2,0,2,0,2);<br> src2->Update();<br><br> MY_SP(vtkCleanPolyData, clean2);<br> clean2->SetInputConnection(src2->GetOutputPort());<br> clean2->Update();<br> vtkPolyData *cube2 = clean2->GetOutput();<br>
<br> MY_SP(vtkPolyDataMapper, Map2);<br> Map2->SetInput(cube2);<br><br> MY_SP(vtkActor, act2);<br> act2->SetMapper(Map2);<br> act2->GetProperty()->SetInterpolationToFlat();<br> act2->GetProperty()->SetColor(0.0, 1.0, 0.0);<br>
<br> ren1->AddActor(act2);<br><br> /////////////////////////////////////////////////////////<br> MY_SP(vtkPointLocator, locator);<br> locator->SetTolerance(0.0);<br> locator->SetDataSet(cube2);<br> locator->BuildLocator();<br>
<br> ComputePointDistances(locator, cube);<br><br> MY_SP(vtkKdTreePointLocator, locator2);<br> locator2->SetTolerance(0.0);<br> locator2->SetDataSet(cube2);<br> locator2->BuildLocator();<br><br> ComputePointDistances(locator2, cube);<br>
<br> /////////////////////////////////////////////////////////<br> ren1->ResetCamera();<br> renWin->Render();<br> iren->Start();<br><br> /////////////////////////////////////////////////////////<br> return 0;<br>
}<br><br>