[vtkusers] Find closest point
David Doria
daviddoria at gmail.com
Sun Sep 18 10:29:08 EDT 2011
On Sun, Sep 18, 2011 at 9:42 AM, nuno.jf <nunofernandes7 at gmail.com> wrote:
> Dear Users,
>
> I need to find the minimum distance between points from the same dataset.
> So, considering one point P, I need to find the closest point to it (other
> than P itself).
> I began by using the following code in the examples:
>
> http://www.vtk.org/Wiki/VTK/Examples/Cxx/DataStructures/KdTreePointLocator/ClosestPoint
>
> And I changed it to find the closest point to each point of my dataset:
>
> int N = polydata -> GetNumberOfPoints();
> double P[3];
> for(double n = 0; n < N; n++)
> {
>
> polydata -> GetPoint( static_cast<vtkIdType>(n), P);
>
> // Find the closest points to TestPoint
> vtkIdType iD = kDTree->FindClosestPoint(P);
> std::cout << "The closest point is point " << iD << std::endl;
>
> //Get the coordinates of the closest point
> double closestPoint[3];
> kDTree->GetDataSet()->GetPoint(iD, closestPoint);
> std::cout << "Coordinates: " << closestPoint[0] << " " <<
> closestPoint[1]
> << " " << closestPoint[2] << std::endl;
>
> }
>
> The issue here is that the closest point I get corresponds to the point P (
> that is, the point for which I want to calculate the distance).
> How can I find the real closest point to a given point P without getting
> the
> same point as a result?
> Thank you in advance.
>
> Nuno
>
You have to use FindClosestNPoints and take the second one:
http://www.vtk.org/Wiki/VTK/Examples/Cxx/DataStructures/vtkKdTree_BuildLocatorFromPoints_ClosestKPoints
I wrote functions to do exactly what you are saying, as they are very very
common operations to want to perform:
http://review.source.kitware.com/#change,1862
but they were not approved.
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110918/4e90409b/attachment.htm>
More information about the vtkusers
mailing list