Hi David,<br><br>I was checking out the broken vtkKdTree example at <a href="http://www.vtk.org/Wiki/VTK/Examples/Broken/vtkKdTree_BuildLocator_ClosestPoint">http://www.vtk.org/Wiki/VTK/Examples/Broken/vtkKdTree_BuildLocator_ClosestPoint</a> and it seems that the BuildLocator() method was more intended for use as an ordering of cells by centroid so that they can be order by a viewing direction. I'm not sure what was intended for this example but it shouldn't be used as an example of a point locator. In any case, below is something you may want to put on the wiki. I'll leave it up to you to decide how it should go in.<br>
<br>Andy<br><br>=========================<br><br>The BuildLocator() method in vtkKdTree can be used to order cells from a viewing direction. The vtkKdTree region Ids are returned<br>from the ViewOrderAllRegions() method sorted from front to back in the specified direction.<br>
<br>==ClosestPoint.cxx==<br><source lang="cpp"><br>#include <vtkSmartPointer.h><br>#include <vtkSphereSource.h><br>#include <vtkIntArray.h><br>#include <vtkKdTree.h><br><br>int main(int argc, char *argv[])<br>
{<br> // Create a polydata source<br> vtkSmartPointer<vtkSphereSource> sphere =<br> vtkSmartPointer<vtkSphereSource>::New();<br> sphere->SetThetaResolution(30);<br> sphere->SetPhiResolution(40);<br>
<br> //Create the tree<br> vtkSmartPointer<vtkKdTree> kDTree =<br> vtkSmartPointer<vtkKdTree>::New();<br> //kDTree->SetNumberOfRegionsOrMore(3);<br> kDTree->AddDataSet(sphere->GetOutput());<br>
kDTree->BuildLocator();<br><br> // Order the cells based on a viewing direction<br> double direction[3] = {2, 1, 0};<br> vtkSmartPointer<vtkIntArray> cellOrder =<br> vtkSmartPointer<vtkIntArray>::New();<br>
kDTree->ViewOrderAllRegionsInDirection(direction, cellOrder);<br> cout << "Order of vtkKdTree regions is:\n";<br> for(vtkIdType i=0;i<cellOrder->GetNumberOfTuples()*cellOrder->GetNumberOfComponents();i++)<br>
{<br> cout << cellOrder->GetValue(i) << endl;<br> }<br><br> return EXIT_SUCCESS;<br>}<br><br><br></source><br><br>==CMakeLists.txt==<br><source lang="cmake"><br>cmake_minimum_required(VERSION 2.6)<br>
<br>PROJECT(KDTree)<br><br>FIND_PACKAGE(VTK REQUIRED)<br>INCLUDE(${VTK_USE_FILE})<br><br>ADD_EXECUTABLE(ClosestPoint ClosestPoint.cxx)<br>TARGET_LINK_LIBRARIES(ClosestPoint vtkHybrid)<br><br></source><br><br>