[vtkusers] Help creating a vtkImageData object using Python

Prabhu Ramachandran prabhu_r at users.sf.net
Sat Sep 10 14:53:47 EDT 2005


>>>>> "Chris" == "Pieper, Chris" <cpieper at kcc.com> writes:

    Chris> I am a beginner vtk user and would like to generate a
    Chris> vtkImageData object using Python code.  I have the data
    Chris> that I want to insert into the object available as Python
    Chris> objects, but don't know how to insert them into the
    Chris> vtkImageData object.  I saw something in the archives about
    Chris> using vtkImageImport to do this, but I don't understand the
    Chris> implementation...
[...]
    Chris> This much works, but I don't know how to insert the
    Chris> scalars... The example uses a C++ pointer to do this, can
    Chris> it be done within Python?

You need to create a vtkDataArray object, populate it with your scalar
data and then set in your point or cell data.  You should consider
studying the examples inside Examples/DataManipulation/Python.
Specifically look at marching.py.  Once you understand how that works
you should be in a position to do it more efficiently by using
vtkImageImport etc.

    Chris> Also, my image data is a structured volume with RGB values
    Chris> at each location.  Since the space represents different
    Chris> colors (I'm visualizing colors), each location has a unique
    Chris> RGB value.  Can I use a 3 component scalar value at each
    Chris> volume coordinate or do I need to create a LUT?

If you associate a scalar array having 4 components (RGBA) of type
unsigned char then the mapper will (by default) treat the scalars as
color without passing it through a LUT.

cheers,
prabhu



More information about the vtkusers mailing list