[vtkusers] Python-VTK : Defining the cells of a vtkUnstructuredGrid

Aurélien Marsan aur.marsan at gmail.com
Wed Jul 30 17:07:46 EDT 2014


Hi all,

I am still facing some issues in order to build a vtkUnstructuredGrid from
numpy arrays.

I have read the example, that shows how to build a vtkUnstructuredGrid cell
by cell :
http://vtk.org/gitweb?p=VTK.git;a=blob;f=Examples/DataManipulation/Python/pointToCellData.py

But in my case, I have large numpy arrays which contains
- the points coordinates
- the cell types
- the definition of cells (npts,p0,p1,...p(npts-1)

and I would like to avoid any loops in the python code.

Then, I tried the following code, where

   - <cells> contains the definition of the cells (npts,p0,p1,...p(npts-1)
   - <cellslocations> contains the index of the cells in the <cells> array
   - <cellstype> is an array of integer that describes the types of the
   cells

    bloc = vtk.vtkUnstructuredGrid()
>
>
>     vtkArray = numpy_support.numpy_to_vtk(numpy.ascontiguousarray(coords),
> deep = 1)
>     points = vtk.vtkPoints()
>     points.SetData(vtkArray)
>
>     bloc.SetPoints(points)
>
>     vtkCells = vtk.vtkCellArray()
>     vtkCells.SetCells(number_of_cells, numpy_support.numpy_to_vtk(cells,
> deep = 1, array_type = vtk.vtkIdTypeArray().GetDataType()))

    bloc.SetCells(
>         numpy_support.numpy_to_vtk(cellslocations, deep = 1, array_type =
> vtk.vtkUnsignedCharArray().GetDataType()),
>         numpy_support.numpy_to_vtk(cellstypes, deep = 1, array_type =
> vtk.vtkIdTypeArray().GetDataType()),
>         vtkCells
>         )
>     bloc.Update()
>     bloc.UpdateData()
>     print bloc
>     return bloc
>

This code works. But when I am trying to cut the resulting block using a
VTKCutter, I have the following error message:

> Generic Warning: In
> /home/builder/pisi/tmp/VTK-5.6.0-2/work/VTK/Graphics/vtkContourGrid.cxx,
> line 195
> Unknown cell type 171
>

It is obvious that I do something wrong.... But I can not find where.
Do you have some advice ?
is it really possible to define an unstructured grid like this, avoiding
any python loop ?

Many thanks in advance,

Regards,

Aurélien
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20140730/d4aaa230/attachment.html>


More information about the vtkusers mailing list