[vtkusers] importing unstructured grid data from numpy array

Eric E. Monson emonson at cs.duke.edu
Tue May 25 09:31:45 EDT 2010


Hey Florian,

There are pretty easy ways to do it, but I haven't used tvtk for a while, so I don't remember the comparison. You can do something like this:

# ===================================
from vtk.util import numpy_support as VN
import vtk
import numpy as N

ug = vtk.vtkUnstructuredGrid()
pts = vtk.vtkPoints()

# Create the points array and set the UG to use them
pp = N.random.rand(10,3)
ppV = VN.numpy_to_vtk(pp, deep=True)
pts.SetData(ppV)
ug.SetPoints(pts)

# Add an attribute array (scalars) to the UG
aa = N.random.rand(10)
aaV = VN.numpy_to_vtk(aa,deep=True)
aaV.SetName('Attribute1')
ug.GetPointData().AddArray(aaV)
# ===================================

So it's not too bad. Also, note that there is a vtk_to_numpy() and a numpy_to_vtkIdTypeArray(), which often comes in quite handy for me.

Talk to you later,
-Eric

------------------------------------------------------
Eric E Monson
Duke Visualization Technology Group


On May 25, 2010, at 5:44 AM, Florian Bruckner wrote:

> hello,
> 
> I would need a method to read unstructured grid data from a numpy array.
> Does anyone know a function like vtkImageInputFrom/ExportToArray.py that
> also handles unstructured grids? or is there a possibility to transform
> image data to unstructured grids?
> 
> i only found the tvtk library, but in order to use it I will have to
> install the whole ETS project. In addition the documentation of this
> library mention that it is more 'pytonic' to use tvtk but that it should
> also be possible to do the same things with pure vtk.
> 
> thanks 
> FloB
> 
> 
> _______________________________________________
> 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