[vtkusers] Combine three single component arrays into one three component array (python)

Jaap Verheggen jpmverheggen at gmail.com
Tue Aug 25 04:14:14 EDT 2015


Hello,

I am Looking for an easy way to create my point data with Python. I can 
make three single component arrays, but do not know how to combine that 
into one three component array which I can feed into a vtkpoints container.

# Let's say I have an array of point data, large enough that a loop 
should be avoided
Array = np.empty([235, 3])
#I can deconstruct the array in x, y and z
VTK_datax = numpy_support.numpy_to_vtk(num_array=Array[:,0].ravel(), 
deep=True, array_type=vtk.VTK_DOUBLE)
VTK_datay = numpy_support.numpy_to_vtk(num_array=Array[:,1].ravel(), 
deep=True, array_type=vtk.VTK_DOUBLE)
VTK_dataz = numpy_support.numpy_to_vtk(num_array=Array[:,2].ravel(), 
deep=True, array_type=vtk.VTK_DOUBLE)
# Maybe I will need a VTK ID array (0..235) Lets just make one
VTK_ID = 
numpy_support.numpy_to_vtk(num_array=np.arange(shape(Array)[0]).ravel(), 
deep=True, array_type=vtk.VTK_ID_TYPE)
# Now I would like to combine x, y and z data into a single array
VTK_data = vtk.vtkDoubleArray()
VTK_data.SetNumberOfComponents(3)
VTK_data.SetNumberOfTuples(235)
# However, I do not know how to do this, it could be something like 
this, VTK_data.SetTuple3(VTK_ID, VTK_datax, VTK_datay, VTK_dataz ) but 
that doesn't work with arrays.
# Afterwards, I would like to fill the data array into a points container
points = vtk.vtkPoints()
points.SetData(pcoords)

Is there a way to combine three single component arrays into a three 
component array?

Thanks in advance,






-- 
---------------------------
Jaap Verheggen

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150825/c5fdc4f2/attachment.html>


More information about the vtkusers mailing list