<div class="gmail_quote">On Sun, Sep 18, 2011 at 9:42 AM, nuno.jf <span dir="ltr">&lt;<a href="mailto:nunofernandes7@gmail.com">nunofernandes7@gmail.com</a>&gt;</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 -&gt; GetNumberOfPoints();<br>
        double P[3];<br>
        for(double n = 0; n &lt; N; n++)<br>
        {<br>
<br>
        polydata -&gt; GetPoint( static_cast&lt;vtkIdType&gt;(n), P);<br>
<br>
        // Find the closest points to TestPoint<br>
        vtkIdType iD = kDTree-&gt;FindClosestPoint(P);<br>
        std::cout &lt;&lt; &quot;The closest point is point &quot; &lt;&lt; iD &lt;&lt; std::endl;<br>
<br>
        //Get the coordinates of the closest point<br>
        double closestPoint[3];<br>
        kDTree-&gt;GetDataSet()-&gt;GetPoint(iD, closestPoint);<br>
        std::cout &lt;&lt; &quot;Coordinates: &quot; &lt;&lt; closestPoint[0] &lt;&lt; &quot; &quot; &lt;&lt; closestPoint[1]<br>
&lt;&lt; &quot; &quot; &lt;&lt; closestPoint[2] &lt;&lt; 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>