[vtkusers] How do I extract multiple vtkPolyData from a single vtkPolyData read from an XML file.

kent williams nkwmailinglists at gmail.com
Wed Dec 12 16:22:10 EST 2007


Code example below but here is what I'm trying to do: I load a 3D
volume and use vtkContourWidget to trace contours on different slices.
 Then, I need to write out a file that contains all those contours.
To write the file out is easy: my code is below.  Basically I use a
vtkAppendPolyData object to stick all the contours (which I save as
vtkPolyData) into a single vtkPolyData, and then write that out.

But there really isn't the opposite of a vtkAppendPolyData.  I assume
I'll have to do some sort of traversal to pull my contours back out of
the reader's output.  Does anyone have an example of that?

void
vtkKWImageViewerWidget::
SaveROI(const char *filename)
{
  vtkAppendPolyData *pd = vtkAppendPolyData::New();
  for(TraceMap::iterator tmIt = this->m_SliceTraces.begin();
      tmIt != this->m_SliceTraces.end(); ++tmIt)
    {
    for(PolyDataList::iterator polyIt = tmIt->second.begin();
        polyIt != tmIt->second.end(); ++polyIt)
      {
      pd->AddInput(*polyIt);
      }
    }
  pd->Update();
  vtkXMLPolyDataWriter *writer = vtkXMLPolyDataWriter::New();
  writer->SetInput(pd->GetOutput());
  writer->SetDataModeToAscii();
  writer->SetFileName(filename);
  writer->Write();
  writer->Delete();
  pd->Delete();
}



More information about the vtkusers mailing list