Generate VTK mesh from point and connectivity

Hello guys,
I have two dictionary in python with the same information:

  1. first dictionary at each key contains the informations about nodes of my mesh, so the node number and the (x,y,z) coordinate

  2. Second dictionary containing the elements and the connectivity, so the element number and the node i and j to define the line, or polyline ecc.

I tried to generate the vtk file containing this information, but without success, I did as follow:

import vtk
lineSource = vtk.vtkLineSource()
for e in int_p_connect:
    nodei = int_p_connect[e][1]
    nodej = int_p_connect[e][2]

when I display it only one line is shown

This loop overwrites the existing line every time. It sounds like you have many lines. You will need to construct a vtkPolyData of lines instead.

The vtkPolyData has a set of points and cells (connectivity). You can construct vtkPoints and a vtkCellArray, give them to a vtkPolyData. Then write that vtkPolyData to a file.

Here is an example with the construction of a cube:

In this example the pts is set to sets of quads (counter clockwise connectivity of 4 points). You will need sets of lines so yours would look more like:

pts = [(0, 1), (4, 5), (0, 1), (1, 2), (2, 3), (3, 0), ...]

This is just some fictitious example of connectivity.