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

Cory Quammen cory.quammen at kitware.com
Wed Aug 26 11:26:27 EDT 2015


Jaap,

There should be no need to append the different array components in this
scenario. It should be handled directly by the numpy_support.numpy_to_vtk
function.

Try this:

import vtk
import vtk.util.numpy_support as ns
import numpy as np

Array = np.empty([235,3])
vtkarr = ns.numpy_to_vtk(num_array=Array, deep=True,
array_type=vtk.VTK_DOUBLE)

>>> vtkarr.GetNumberOfTuples()
235L
>>> vtkarr.GetNumberOfComponents()
3

HTH,
Cory

On Tue, Aug 25, 2015 at 4:14 AM, Jaap Verheggen <jpmverheggen at gmail.com>
wrote:

> 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
>
>
> _______________________________________________
> 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
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
>


-- 
Cory Quammen
R&D Engineer
Kitware, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150826/3965aff4/attachment.html>


More information about the vtkusers mailing list