[vtkusers] Please help!

Richard A Rowe rar109 at york.ac.uk
Wed May 16 06:26:36 EDT 2007


Thank you Fred for the example. I see that my information has to be passed 
into an array imported from sciPy instead of a standard python list [] for 
it to work with the SetVoidArray() method. Hopefully this will solve some 
problems in my code.

I was looking at the 5. x (nightly) manual instead of the 5.0 manual so 
missed SetVoidArray()

Thank you for your help and guidance.

Regards,

Richard.

----- Original Message ----- 
From: "fred" <fredmfp at gmail.com>
To: "vtkusers" <vtkusers at vtk.org>
Sent: Tuesday, May 15, 2007 3:15 PM
Subject: Re: [vtkusers] Please help!


> Richard A Rowe a écrit :
>> Hi Fred,
>>
> Hi Richard,
>
> "Please keep the discussion on the vtkusers list rather than emailing me
> directly. That way the discussion is archived and other people can
> contribute to finding a solution to your problem."
> (A.M. ©)
>
>> Thanks for that! Yes I am a Python user. Why is it SetVoidArray()? I
>> tried SetArray() as it is stated on the vtk online documentation, but
>> this didn't work... Is it something that you learn from experience? Or
>> is there a list of method alterations available for language wrappers?
>> I noticed that the SetVoidArray method only takes a string, I've tried
>> changing a list of values into a string in the example below. However,
>> will the vtkIntArray contain int values of the list or the string
>> information? i.e. will it be possible to set the scalars of
>> vtkPointData using the .SetScalars() method with the vtkIntArray?
>>
> Please look at the complete example in the attached file to write a
> vtkImageData
> file format.
>
> HTH.
>
> -- 
> http://scipy.org/FredericPetit
>
>


--------------------------------------------------------------------------------


> #! /usr/bin/env python
>
> import vtk
>
> from scipy import array
>
> nx, ny, nz = 2, 3, 4
> x0, y0, z0 = 0, 0, 0
> dx, dy, dz = 1, 1, 1
>
> data = array([range(nx*ny*nz)]).reshape(nx, ny, nz)
>
> vtkdata = vtk.vtkIntArray()
> vtkdata.SetVoidArray(data, (nx*ny*nz), 1)
>
> id = vtk.vtkImageData()
> id.SetExtent(0, nx-1, 0, ny-1, 0, nz-1)
> id.SetOrigin(x0, y0, z0)
> id.SetSpacing(dx, dy, dz)
>
> # if you have more than one array, you have to use AddArray()
> if (id.GetPointData().GetNumberOfArrays() == 0):
>   id.GetPointData().SetScalars(vtkdata)
> else:
>   id.GetPointData().AddArray(vtkdata)
>
> fd = vtk.vtkXMLImageDataWriter()
> # if you want your file to be written as ascii format instead of base64
> fd.SetDataModeToAscii()
> fd.SetFileName('foo.vti')
> fd.SetInput(id)
> fd.Write()
>


--------------------------------------------------------------------------------


> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the 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