[vtkusers] Create a grid made of a bunch of lines

Frederic Perez fredericperez1 at gmail.com
Wed Mar 1 03:37:28 EST 2017


Hello VTK experts,

I would like to create a grid consisting of several disconnected
lines, each line having a bunch of points. I'm using python.

My first step is to make a vtkUnstructuredGrid containing many vtkPoints:

        points = self.vtk.vtkPoints()
        points.SetData(pcoords)              # pcoords is a (3 x npoints) array

        grid = self.vtk.vtkUnstructuredGrid()
        grid.SetPoints(points)

        writer = self.vtk.vtkUnstructuredGridWriter()
        writer.SetFileName(file)
        writer.SetInputData(grid)
        writer.Write()

This works, but does not make any connection between points. I was
hoping I could define the connectivity between points using a
vtkCellArray:

        id = self.vtk.vtkIdTypeArray()
        id.SetNumberOfTuples(npoints)
        id.SetNumberOfComponents(1)
        id.SetVoidArray(connectivity, npoints, 1)

        connec = self.vtk.vtkCellArray()
        connec.SetCells(ncel, id)

        grid.SetCells(self.vtk.VTK_POLY_LINE, connec)

In the lines above, "connectivity" is a list containing the
connections between points, in the format:
[
N0, 0, ..., N0-1,                # This is supposed to represent the first line
N1, N0, ..., N0+N1-1,      # The second line
N2, ...,                              # The third line
...                                      # etc.
]

The writer seems happy, as I do not get any errors, but ParaView
crashes upon opening the file. Am I doing something wrong?

Thanks for your help.


More information about the vtkusers mailing list