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

kent williams nkwmailinglists at gmail.com
Thu Dec 13 14:07:39 EST 2007


Hmmm.  Thanks Mike -- your solution seems to be working just fine.

But another question -- I don't get why my code below doesn't work.
I'm attaching the XML file I'm trying to read.  My assumption is that
since the XML file indicates that the only features are 3 lines, I
need to just grab the lines, and then use those to initialize new
instances of vtkPolyData from them.

The Problem I'm seeing is this: The first line I get with
lines->GetCell(0,npts,pts) is valid.  But the next call
lines->GetCell(1,npts,pts), returns zero for npts.

Maybe I'm misunderstanding what the hell I'm supposed to do with the
Cell pointer returned from vtkPolyData::GetLines().

  vtkXMLPolyDataReader *reader = vtkXMLPolyDataReader::New();
  reader->SetFileName(filename);
  reader->Update();
  vtkPolyData *pd = reader->GetOutput();
  vtkPoints *points = pd->GetPoints();
  vtkCellArray *lines = pd->GetLines();

  int size = lines->GetNumberOfCells();
  int curslice;
  //
  // need to create a vtkPolyData for each line
  // in the file.
  for(unsigned i = 0; i < size; i++)
    {
    double zval;
    vtkIdType npts;
    vtkIdType *pts;
    lines->GetCell(i,npts,pts);
    vtkPoints *newpts = vtkPoints::New();
    newpts->SetDataTypeToDouble();
    for(unsigned j = 0; j < npts; j++)
      {
      //
      // don't close the line, it screws up
      // restoring the polydata
      if(j == npts - 1 && pts[j] == 0)
        break;
      double thePoint[3];
      points->GetPoint(pts[j],thePoint);
      zval = thePoint[2];
      //  newpts->SetPoint(j,thePoint);
      newpts->InsertNextPoint(thePoint);
      }
    vtkPolyData *newPd = vtkPolyData::New();
    ConvertPointSequenceToPolyData(newpts,1,newPd);
    }
  reader->Delete();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: xxx.xml
Type: text/xml
Size: 2073 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20071213/8a4e99f3/attachment.bin>


More information about the vtkusers mailing list