[vtkusers] Extracting cell connectivity from a vtk file
Berk Geveci
berk.geveci at kitware.com
Fri Sep 25 14:20:51 EDT 2009
You should be able to do:
ug = r.GetOutput()
ncells = ug.GetNumberOfCells()
for i in xrange(ncells):
cell = ug.GetCell(i)
The key is to call GetCell() on the unstructured grid not the cell
array returned by GetCells().
-berk
On Fri, Sep 25, 2009 at 11:37 AM, Eric Mark (CISD/CIV)
<emark at arl.army.mil> wrote:
> 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
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
More information about the vtkusers
mailing list