[vtkusers] Obtaining point coordinates and indices from vtkPolyData

Finegan Thomas-QTF001 T.Finegan at motorola.com
Wed Mar 17 17:46:06 EST 2004


I have a vtkPolyData which I've configured using the following code:

vtkPolyData *polyData = vtkPolyData::New();
vtkCellArray *polys = vtkCellArray::New();
vtkPoints *points = vtkPoints::New();

for ()
{
  points->InsertNextPoint(x, y, z);
}

for ()
{
  nodes[0] = n1; // values of n1-n3 are known valid indices into vtkPoints
  nodes[1] = n2;
  nodes[2] = n3;
  polys->InsertNextCell(3, nodes);
}

polyData->SetPoints(points);
polyData->SetPolys(polys);

Now, at a different point in the program I want to retrieve the vtkPoints indices and coordinates of the points defining a polygon at a known cell ID and I'm using the following code:

vtkIdType cellID = valid_cell_ID_obtained_thru_pick_operation;
vtkIdType *nodes = 0;
vtkIdType cNodes = 0;
polyData->GetPolys()->GetCell(cellID, cNodes, nodes);

This doesn't work correctly though - I often get a value of cNodes that I know is incorrect (e.g. all my polygons are triangles yet cNodes == 10). My question is, what is the best way to obtain the point coordinates and indices, given a valid cell ID for the polydata? Thanks!





More information about the vtkusers mailing list