[vtkusers] How to Copy vtkCell and Associated Data

Mike Jackson maillist at bluequartz.net
Wed Nov 30 23:30:23 EST 2005


I am trying to create a new vtkPolyData Object that contains a subset  
of vtkCell objects from another vtkPolyData object. How I am picking  
the cells I need hopefully isn't pertinent. What I am failing at is  
getting the data copied from the large vtkPolyData object to the  
small vtkPolyData object.

I am looping on the cell data of the vtkPolyData object like so:

vtkPolyData  *output = vtkPolyData::New();
vtkPointData *outputPD=output->GetPointData();
vtkCellData *outputCD=output->GetCellData();
vtkIdType cellId, newCellId, numCells;
vtkIdType *cells, *pts, npts, id, n;
this->Mesh = vtkPolyData::New();
this->Mesh->CopyStructure(input);
this->Mesh->BuildLinks();;
.
.
.
for (cellId=0; cellId < numCells; cellId++)
{
if (someCondition == true)
  {
  this->Mesh->GetCellPoints(cellId, npts, pts);
  this->PointIds->Reset ();
  for (i=0; i < npts; i++)
  {
    id = this->PointMap[pts[i]];
    this->PointIds->InsertId(i,id);
  }
  newCellId = output->InsertNextCell(this->Mesh->GetCellType 
(cellId),this->PointIds);
  outputCD->CopyData(cd,cellId,newCellId);
}

} //End Loop

This pretty much straight out of vtkPolyDataConnectivityFilter.cxx.

Now when I run this it looks like I get the Cells copied over, but  
not the associated Points? What would be the proper way to copy the  
points over also? Is the connectivity retained? Do I have to run the  
buildLinks method?


thanks for the help
---
Mike Jackson
mike _at_ bluequartz dot net





More information about the vtkusers mailing list