[vtkusers] Determine which points are inside of a cell

David Doria daviddoria+vtk at gmail.com
Mon Apr 12 12:10:26 EDT 2010


I have a vtkImageData (named 'grid') superimposed on a vtkPolyData
(named 'polydata').

I can determine which cell a particular point is in like this:

  vtkSmartPointer<vtkCellLocator> cellLocator =
      vtkSmartPointer<vtkCellLocator>::New();
  cellLocator->SetDataSet(grid);
  cellLocator->BuildLocator();

  //determine which cell each point is in
  cout << "Which cell does each point belong to?" << endl;
  for(vtkIdType i = 0; i < polydata->GetNumberOfPoints(); i++)
    {
    double p[3];
    polydata->GetPoint(i,p);
    int cellId = cellLocator->FindCell(p);
    cout << "Point " << i << " is in cell " << cellId << endl;
    }

Now I'd like to do the reverse - determine which points are in a
particular cell. Is there a good way to do this? Or would I have to
determine which cell every point is in and construct a table, then use
that table for this second type of query? I could also make a new
polydata from the single cell and then use vtkSelectEnclosedPoints,
but that also seems awkward.

Thanks,

David



More information about the vtkusers mailing list