[vtkusers] method to remove points in a polydata
David Doria
daviddoria at gmail.com
Thu Jun 23 09:19:59 EDT 2011
On Thu, Jun 23, 2011 at 9:13 AM, nuno.jf <nunofernandes7 at gmail.com> wrote:
> Hi David, thank you for your help.
> I used the example you had shown me, and changed it to read a polydata and
> use it as input the methods described:
>
> //Read a polydata
> vtkPolyDataReader * imp = vtkPolyDataReader::New();
> imp -> SetFileName(argv[1]);
> imp -> Update();
>
> //Create the tree
> vtkSmartPointer<vtkKdTreePointLocator> pointTree =
> vtkSmartPointer<vtkKdTreePointLocator>::New();
> pointTree->SetDataSet(imp->GetOutput());
> pointTree->BuildLocator();
>
> // Find the k closest points to (0,0,0)
> int k = 1;
> double testPoint[3] = {0.0, 0.0, 0.0};
> vtkSmartPointer<vtkIdList> result =
> vtkSmartPointer<vtkIdList>::New();
>
> pointTree->FindPointsWithinRadius(5.0, testPoint, result);
>
> for(vtkIdType i = 0; i < k; i++)
> {
> vtkIdType point_ind = result->GetId(i);
> double p[3];
> imp->GetOutput()->GetPoint(point_ind, p);
> std::cout << "Closest point " << i << ": Point "
> << point_ind << ": (" << p[0] << ", " << p[1] << ", " << p[2] << ")"
> << std::endl;
> }
>
> The problem is that the application stops responding and I got nothing in
> the output. Could you please help me to see what is wrong? What I need to do
> is to create a new polydata and set the resulting points as its input
> points.
I suggest you use synthetic data as the input so we can more easily
help you debug. That is, use a vtkPointSource or something instead of
a vtkPolyDataReader with an actual file. Also, is there a reason
you're using vtkPolyDataReader instead of vtkXMLPolyDataReader?
To create the output polydata from points, you would create a
vtkPoints, use InsertNextPoint, and then add it to a polydata with
SetPoints. You can see this done here:
http://www.itk.org/Wiki/VTK/Examples/Cxx/IO/ReadPlainText
David
More information about the vtkusers
mailing list