VTK/Examples/Cxx/PolyData/PointLocator Radius

From KitwarePublic

Jump to: navigation, search

PointLocatorRadius.cxx

#include <vtkSmartPointer.h>
#include <vtkIdList.h>
#include <vtkPolyDataMapper.h>
#include <vtkObjectFactory.h>
#include <vtkPointSource.h>
#include <vtkPolyData.h>
#include <vtkPointLocator.h>
 
int main(int, char *[])
{
  vtkSmartPointer<vtkPointSource> pointSource = 
    vtkSmartPointer<vtkPointSource>::New();
  pointSource->SetNumberOfPoints(400);
  pointSource->Update();
 
  // Create the tree
  vtkSmartPointer<vtkPointLocator> pointLocator = 
    vtkSmartPointer<vtkPointLocator>::New();
  pointLocator->SetDataSet(pointSource->GetOutput());
  pointLocator->AutomaticOn();
  pointLocator->SetNumberOfPointsPerBucket(2);
  pointLocator->BuildLocator();
 
  double radius = .1;
  double center[3] = {0.0, 0.0, 0.0};
  vtkSmartPointer<vtkIdList> result = 
    vtkSmartPointer<vtkIdList>::New();
  pointLocator->FindPointsWithinRadius (radius, center, result);
 
  for(vtkIdType i = 0; i < result->GetNumberOfIds(); i++)
    {
    unsigned int id = result->GetId(i);
    std::cout << "id of point " << i << " : " << id << std::endl;
    }
 
  return EXIT_SUCCESS;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)
 
PROJECT(PointLocatorRadius)
 
FIND_PACKAGE(VTK REQUIRED)
INCLUDE(${VTK_USE_FILE})
 
ADD_EXECUTABLE(PointLocatorRadius PointLocatorRadius.cxx)
TARGET_LINK_LIBRARIES(PointLocatorRadius vtkHybrid)

Color query point and points that are found to be neighbors.

Personal tools