<div class="gmail_quote"><div>Thanks for the bug report. I just fixed it and it should go into the new vtk release.<br><br>Andy<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Message: 1<br>
Date: Thu, 25 Mar 2010 14:44:44 +0100<br>
From: xabi riobe <<a href="mailto:xabivtk@gmail.com">xabivtk@gmail.com</a>><br>
Subject: [vtkusers] FindClosestPointWithinRadius issue in vtkKdTree<br>
To: <a href="mailto:vtkusers@vtk.org">vtkusers@vtk.org</a><br>
Message-ID:<br>
<<a href="mailto:b38cd42e1003250644x1a70b70bm65234f02d22ef219@mail.gmail.com">b38cd42e1003250644x1a70b70bm65234f02d22ef219@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="iso-8859-1"<br>
<br>
Hi,<br>
<br>
I was trying to use vtkKdTreePointLocator to find closest points but from<br>
the results i obtain i'm wondering wheather there is an issue with the<br>
method FindClosestPointWithinRadius, because sometimes it returns some<br>
points with a distance bigger than the radius.<br>
<br>
This method calls vtkKdTree::FindClosestPointWithinRadius which calls<br>
vtkKdTree::FindClosestPointInSphere, but here the point returned can be out<br>
of the sphere.<br>
I think there must be an additional test in one of these two methods to<br>
compare the distance and the given radius.<br>
<br>
here is a program test, with a comparison with vtkPointLocator that works<br>
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" target="_blank">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" target="_blank">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>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="http://www.vtk.org/pipermail/vtkusers/attachments/20100325/597ae2ae/attachment-0001.htm" target="_blank">http://www.vtk.org/pipermail/vtkusers/attachments/20100325/597ae2ae/attachment-0001.htm</a>><br>
<br>
</blockquote></div><br>