[vtkusers] Fwd: Request help on Python VTK setCells error

Aso agile aso.agile at gmail.com
Wed Apr 10 09:23:51 EDT 2013


Hi ,

I am having problem with VTK's setCell for creating unstructured grid from
a numpy array. I used following two methods to create cells:
        - using numpy_to_vtkIdTypeArray, which result in cell
        - using vtkCellArray and filling it with individual cell's poit
list. Results stored in cells2 in the code
But both method return following error:

        # Create points
        grid_array = ...
        grid_array = grid_array.reshape(8*Nz*Ny*Nx,3)
        vtk_points = vtk.vtkPoints()
        grid = vtk.vtkUnstructuredGrid()
        points = VN.numpy_to_vtk(grid_array, deep=True)
        vtk_points.SetData(points)
        grid.SetPoints(vtk_points)


        # Create cells
        cell_ids = np.arange(0,8*Nx*Ny*Nz,
dtype=np.int64).reshape(Nx*Ny*Nz, 8)
        cells = VN.numpy_to_vtkIdTypeArray(cell_ids, deep=True)
        cells2 = vtk.vtkCellArray()
        for cell in cell_ids:
            pids = vtk.vtkIdList()
            for p in cell:
                pids.InsertNextId(p)
            cells2.InsertNextCell(pids)
        print cells
        print cells2
        # Assign cells to grid and create unstructured grid. Error comes
after this:
        grid.setCells(vtk.VTK_HEXAHEDRON, cells2)    #
12==vtk.VTK_HEXAHEDRON

AttributeError: setCells


I really appriciate your help. I spent 2 days on this problem googled it
but couldn't find anything useful.

Regards,

Aso
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130410/458337eb/attachment.htm>


More information about the vtkusers mailing list