[vtkusers] Request help on Python VTK setCells error
Aso agile
aso.agile at gmail.com
Fri Apr 12 05:47:25 EDT 2013
Thanks Gil for reminding me of my silly mistake! SetCells is correct not
setCells (capital S..).
Now my code works fine with 'cells2' which is created as follow:
cell_ids = np.arange(0,8*Nx*Ny*Nz,
dtype=np.int64).reshape(Nx*Ny*Nz, 8)
cells2 = vtk.vtkCellArray()
for cell in cell_ids:
pids = vtk.vtkIdList()
for p in cell:
pids.InsertNextId(p)
cells2.InsertNextCell(pids)
grid.SetCells(vtk.VTK_HEXAHEDRON, cells2)
but it doesn't work with 'cells' as in follow:
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)
grid.SetCells(vtk.VTK_HEXAHEDRON, cells)
#Returns error:
TypeError: function takes exactly 3 arguments (2 given).
Any help is appreciated.
Thanks,
Asaad
On Wed, Apr 10, 2013 at 2:23 PM, Aso agile <aso.agile at gmail.com> wrote:
> 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/20130412/d8e364bc/attachment.htm>
More information about the vtkusers
mailing list