[vtkusers] vtk and python for large amout of data

Marcus Stojek stojek at part-gmbh.de
Tue Dec 3 10:51:13 EST 2002


Hi,
I am using Python and vtk for a viewer that shows
unstructured Grids. These grids can become quite large
(300000 cells and above). So far I know two methods to
get the cells into the mapper:

1. Use the vtkUnstructuredGridReader
I have to write a vtk file and then read it. The reading
process is fast enough for me. But as my database is changing
all the time, using vtk files is a little bit complicated and
writing the files takes time.

2. something like:
         bla..bla..bla..
         for e in elist:
            if e[-1] in ("TRI","TRI2"):
                Tri.GetPointIds().SetNumberOfIds(3)
                Tri.GetPointIds().SetId(0,e[1])
                Tri.GetPointIds().SetId(1,e[2])
                Tri.GetPointIds().SetId(2,e[3])
                Grid.InsertNextCell(Tri.GetCellType(),Tri.GetPointIds())
            elif e[-1] in ("QUAD","QUAD8"):
                Quad.GetPointIds().SetNumberOfIds(4)
                Quad.GetPointIds().SetId(0,e[1])
                Quad.GetPointIds().SetId(1,e[2])
                Quad.GetPointIds().SetId(2,e[3])
                Quad.GetPointIds().SetId(3,e[4])
                Grid.InsertNextCell(Quad.GetCellType(),Quad.GetPointIds())
            else:
                print "ERROR IN VTK_MODULE"
This is veerrrrry slow.

Now I would like to move the data as complete blocks of array, for example
something like:

from vtk import *
import Numeric

    list1=[3,2,3,4,3,5,2,8,3,9,1,5]
    enumber=3
    earray=Numeric.array(list1)
    list2=[5,5,5]
    ctarray=Numeric.array(list2,'int')

    grid=vtkUnstructuredGrid()
    IdTArray=vtkIdTypeArray()
    IdTArray.SetVoidArray(earray,enumber,1)
    vtkCArray=vtkCellArray()
    vtkCArray.SetCells(enumber,IdTArray)
    grid.SetCells(ctarray,vtkCArray)

Of course this doesn't work because SetVoidArray and SetCells are expecting
pointers
which I can't give them (in Python).

Can anybody tell me how I can work efficiently with large amount of data in
python?

Thanks in advance
marcus





More information about the vtkusers mailing list