[vtkusers] Adopt an example

Andy Bauer andy.bauer at kitware.com
Sun Aug 8 16:16:07 EDT 2010


Hi David,

I was checking out the broken vtkKdTree example at
http://www.vtk.org/Wiki/VTK/Examples/Broken/vtkKdTree_BuildLocator_ClosestPointand
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.

Andy

=========================

The BuildLocator() method in vtkKdTree can be used to order cells from a
viewing direction.  The vtkKdTree region Ids are returned
from the ViewOrderAllRegions() method sorted from front to back in the
specified direction.

==ClosestPoint.cxx==
<source lang="cpp">
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkIntArray.h>
#include <vtkKdTree.h>

int main(int argc, char *argv[])
{
  // Create a polydata source
  vtkSmartPointer<vtkSphereSource> sphere =
      vtkSmartPointer<vtkSphereSource>::New();
  sphere->SetThetaResolution(30);
  sphere->SetPhiResolution(40);

  //Create the tree
  vtkSmartPointer<vtkKdTree> kDTree =
      vtkSmartPointer<vtkKdTree>::New();
  //kDTree->SetNumberOfRegionsOrMore(3);
  kDTree->AddDataSet(sphere->GetOutput());
  kDTree->BuildLocator();

  // Order the cells based on a viewing direction
  double direction[3] = {2, 1, 0};
  vtkSmartPointer<vtkIntArray> cellOrder =
    vtkSmartPointer<vtkIntArray>::New();
  kDTree->ViewOrderAllRegionsInDirection(direction, cellOrder);
  cout << "Order of vtkKdTree regions is:\n";
  for(vtkIdType
i=0;i<cellOrder->GetNumberOfTuples()*cellOrder->GetNumberOfComponents();i++)
    {
    cout << cellOrder->GetValue(i) << endl;
    }

  return EXIT_SUCCESS;
}


</source>

==CMakeLists.txt==
<source lang="cmake">
cmake_minimum_required(VERSION 2.6)

PROJECT(KDTree)

FIND_PACKAGE(VTK REQUIRED)
INCLUDE(${VTK_USE_FILE})

ADD_EXECUTABLE(ClosestPoint ClosestPoint.cxx)
TARGET_LINK_LIBRARIES(ClosestPoint vtkHybrid)

</source>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100808/c7675e77/attachment.htm>


More information about the vtkusers mailing list