[vtkusers] Extracting cell connectivity from a vtk file
Berk Geveci
berk.geveci at kitware.com
Fri Sep 25 15:20:13 EDT 2009
npts = cell.GetNumberOfPoints()
for i in range(npts):
id = cell.GetPointId(i)
I recommend checking out the doxygen docs at
http://www.vtk.org/doc/release/5.4/html/classes.html. The Python API
is very close to the C++ one.
-berk
On Fri, Sep 25, 2009 at 3:02 PM, Eric Mark (CISD/CIV)
<emark at arl.army.mil> wrote:
> Thanks Berk,
>
> That does get me almost to what I'm shooting for. cell is now a vtkTetra
> and I would like the actual connection list is specified by the Point Id's
> so I can write them out as a string with an index in front of them. ie.
> 1 232 295 10 19 (index conn1 conn2 conn3 conn4)
>
> I was trying to do this just to see if I could get to the connection point
> ids:
>
> for i in xrange(numcells):
> cellobject = ug.GetCell(i)
> print "CellObject Methods: ", dir(cellobject)
> print " %d, %s " % (j + 1, cellobject.CellBoundry())
> j= j + 1
>
> Thanks,
>
> Eric
>
> Berk Geveci wrote:
>>
>> 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