<div class="gmail_quote">On Sun, Sep 18, 2011 at 9:42 AM, nuno.jf <span dir="ltr"><<a href="mailto:nunofernandes7@gmail.com">nunofernandes7@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Dear Users,<br>
<br>
I need to find the minimum distance between points from the same dataset.<br>
So, considering one point P, I need to find the closest point to it (other<br>
than P itself).<br>
I began by using the following code in the examples:<br>
<a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/DataStructures/KdTreePointLocator/ClosestPoint" target="_blank">http://www.vtk.org/Wiki/VTK/Examples/Cxx/DataStructures/KdTreePointLocator/ClosestPoint</a><br>
<br>
And I changed it to find the closest point to each point of my dataset:<br>
<br>
int N = polydata -> GetNumberOfPoints();<br>
double P[3];<br>
for(double n = 0; n < N; n++)<br>
{<br>
<br>
polydata -> GetPoint( static_cast<vtkIdType>(n), P);<br>
<br>
// Find the closest points to TestPoint<br>
vtkIdType iD = kDTree->FindClosestPoint(P);<br>
std::cout << "The closest point is point " << iD << std::endl;<br>
<br>
//Get the coordinates of the closest point<br>
double closestPoint[3];<br>
kDTree->GetDataSet()->GetPoint(iD, closestPoint);<br>
std::cout << "Coordinates: " << closestPoint[0] << " " << closestPoint[1]<br>
<< " " << closestPoint[2] << std::endl;<br>
<br>
}<br>
<br>
The issue here is that the closest point I get corresponds to the point P (<br>
that is, the point for which I want to calculate the distance).<br>
How can I find the real closest point to a given point P without getting the<br>
same point as a result?<br>
Thank you in advance.<br>
<br>
Nuno<br></blockquote><div><br></div>You have to use FindClosestNPoints and take the second one:</div><div class="gmail_quote"><br></div><div class="gmail_quote"><a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/DataStructures/vtkKdTree_BuildLocatorFromPoints_ClosestKPoints">http://www.vtk.org/Wiki/VTK/Examples/Cxx/DataStructures/vtkKdTree_BuildLocatorFromPoints_ClosestKPoints</a></div>
<div class="gmail_quote"><br></div><div class="gmail_quote">I wrote functions to do exactly what you are saying, as they are very very common operations to want to perform:</div><div class="gmail_quote"><a href="http://review.source.kitware.com/#change,1862">http://review.source.kitware.com/#change,1862</a></div>
<div class="gmail_quote"><br></div><div class="gmail_quote">but they were not approved.</div><div class="gmail_quote"><br><div>David</div></div>