[vtkusers] KdTree Problem - must build locator first

David Doria daviddoria at gmail.com
Tue Feb 10 13:34:26 EST 2009


I am trying to put points into a KdTree...
------------------------------
	vtkSmartPointer<vtkPoints> Points3d = vtkSmartPointer<vtkPoints>::New();
	vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
	vtkSmartPointer<vtkCellArray> Vertices = vtkSmartPointer<vtkCellArray>::New();
	vtkIdType pid[1];
	for(int i = 0; i < Model.NumPoints(); i++)
	{
		vgl_point_3d<double> Point = Model.getPoint(i);
		pid[0] = Points3d->InsertNextPoint(Point.x(), Point.y(), Point.z());
		Vertices->InsertNextCell(1,pid);
	}
	
	polydata->SetPoints(Points3d);
	polydata->SetVerts(Vertices);
	
	vtkSmartPointer<vtkKdTree> PointTree = vtkSmartPointer<vtkKdTree>::New();
	PointTree->SetDataSet(polydata);

	double TestPoint[3] = {1,2,3};
	vtkSmartPointer<vtkIdList> Result = vtkSmartPointer<vtkIdList>::New();
	
	PointTree->BuildLocator();

	int N = 5;
	PointTree->FindClosestNPoints(N, TestPoint, Result);

------------------------------
But I get this error:
vtkKdTree (0x9f38408): vtkKdTree::FindClosestNPoints - must build locator first

As you can see I have called BuildLocator prior to calling
FindClosestNPoints.  What else is wrong?
-- 
Thanks,

David



More information about the vtkusers mailing list