[vtkusers] Extracting cell connectivity from a vtk file

Eric Mark (CISD/CIV) emark at arl.army.mil
Fri Sep 25 11:37:21 EDT 2009


Hello all,

I'm using python with vtk 5.2.1 and am trying to read the connectivity 
list from a vtk file and write it back out in a different format.    I'm 
able to read the point data but I'm not having any success in reading 
the connectivity data.    I would like to be able to print out a 
connectivity list in the same manner that I'm using below to print the 
points.  However it seems that GetCell or GetNextCell methods are not 
available from Python.  Am I doing something wrong or is there an 
alternate way of doing this?

Thanks,

Eric

Here's the code:

fn = "test.vtk"
r = vtkUnstructuredGridReader()

r.SetFileName(fn)
r.Update()
points = r.GetOutput().GetPoints()

print "Number of Points: " ,  points.GetNumberOfPoints()
i = 0
while(i < points.GetNumberOfPoints()) :
     print "Next Point : %d, %s " % (i + 1, points.GetPoint(i))
     i = i + 1

numcells = r.GetOutput().GetNumberOfCells()
print "Number Of Cells: ", numcells
cells = r.GetOutput().GetCells()
print "Cells Var contains: ", cells
print "Cells.GetSize : ", cells.GetSize()
print "Cells.GetSize : ", cells.GetNumberOfConnectivityEntries()
print "What Can I Do With Cells? :", dir(cells)
j = 0
cells.SetTraversalLocation(j)
print "NextCell", cells.GetOutput().GetCell(j)
#print "Check Array: ",  r.GetOutput().GetCells()
while(j < cells ):
     #print " %d, %s " % (j + 1, cells.GetNextCell())
     j = j + 1




More information about the vtkusers mailing list