for loop - How to iterate over points in VTK while finding the Nearest Neighbors of each point? -


I am using VTK for a project, which is not able to understand one section of it. I'm trying to iterate through several thousand points and I get every point in the 5 nearest points. Looks simple for the loop operation but my problem is that for some reason, I am being told that the 5 points are the closest points for every point in my data ... which I know is not true . I am describing the following code:

  // test vtkSmartPointer & lt; VtkPointSource & gt; PointSource = vtkSmartPointer & lt; VtkPointSource & gt; :: new (); PointSource-> Settler of Points (Output-> GetNumberOfPoints ()); PointSource-> Updates (); VtkSmartPointer & LT; VtkKdTreePointLocator & gt; Tree = vtkSmartPointer & lt; VtkKdTreePointLocator & gt; :: new (); Tree-> setdataset (point-source- gt; gate-output ()); Tree-> BuildLocator (); Unsigned int k = 5; Double test point [3]; VtkSmartPointer & LT; VtkIdList & gt; Results = vtkSmartPointer & lt; VtkIdList & gt; :: new (); (VtkIdType n = 0; n & lt; Output-> GetNumberOfPoints (); n ++) for (Result-> Reset); Output-> GetPoint (n, test point); Tree-> Updates (); Std :: cout & lt; & Lt; "Point:" & lt; & Lt; Test point [0] & lt; & Lt; "," & Lt; & Lt; Test point [1] & lt; & Lt; "," & Lt; & Lt; Test point [2] & lt; & Lt; ":" & Lt; & Lt; Endl; Tree-> FindClosestNPoints (K, test point, result); (VtkIdType i = 0; i & lt; k; i ++) for {vtkIdType point_ind = result-> GetId (i); Double p [3]; PointSource-> GetOutput () - & gt; Gate point (point_ind, p); Std :: cout & lt; & Lt; "Closest point" & lt; & Lt; I + 1 & lt; & Lt; ": Point" & lt; & Lt; Point_in & lt; & Lt; ": (" & Lt; <[[]] <   

[1] << ","

This is what I am trying to do ... it is printing 5 closest points at a point of interest, but of interest Regardless of the point, 5 closest points remain the same. I'm assuming that I'm just passing through a small detail in my code, but I can be wrong. If you need more information to help, just ask

thanks for your time and help, Luke H

I got the problem ... I was using / vtkPointSource which generates random numbers and I was feeding at my point at that point. I'm not sure why, But this result has become very difficult, but once I gave the correct information and point id array and the result Put a reset () on the ID array, it works like a winner, hoping that it would be the same problem to others because I had spent a few hours on it.

Luke H

  vtkSmartPointer & lt; VtkKdTreePointLocator & gt; Tree = vtkSmartPointer & lt; VtkKdTreePointLocator & gt; :: new (); Tree-> setdataet (output); Tree-> BuildLocator (); VtkSmartPointer & LT; VtkIdList & gt; Results = vtkSmartPointer & lt; VtkIdList & gt; :: new (); VtkSmartPointer & LT; VtkIdList & gt; Point_ind = vtkSmartPointer & lt; VtkIdList & gt; :: new (); Unsigned int k = 5; Double test point [3]; (VtkIdType n = 0; n & lt; Output-> GetNumberOfPoints (); n ++) {Output-> GetPoint (n, test point); Std :: cout & lt; & Lt; "Point:" & lt; & Lt; Test point [0] & lt; & Lt; "," & Lt; & Lt; Test point [1] & lt; & Lt; "," & Lt; & Lt; Test point [2] & lt; & Lt; ":" & Lt; & Lt; Endl; Tree-> FindClosestNPoints (K, test point, result); (VtkIdType i = 0; i & lt; k; i ++) for {vtkIdType point_ind = result-> GetId (i); Double p [3]; Output-> GetPoint (point_in, p); Std :: cout & lt; & Lt; "Closest point" & lt; & Lt; I + 1 & lt; & Lt; ": Point" & lt; & Lt; Point_in & lt; & Lt; ": (" & Lt; <[[]] <   

[1] << "," please reset (); Point_ind-> Reset (); }

Comments