[vtkusers] Help with vtkImageData()

Nick Torenvliet natorenvliet at gmail.com
Thu Sep 28 17:06:54 EDT 2017


Hi there,

I've attached a python script and a small pickle with associated data.

A code snippet, from the file, is found below and some debug output is
found below.

My code is a quick hack of a working use of vtkImageData() from the mailing
list archives.

I've taken out the original author's (thanks quentan) data source and put
in place my pickle file.

When I run the script I get a window, but nothing visible in it except a
black back-ground.

I'm not sure if its data representation issues,  viewport/camera issues, or
pipeline issues; I'm open to all three actually - but I think its probably
pipeline... the full extent of which is in the attached script.

The original author has an (n1, n2, n3) matrix generated with a bunch of
trig, but I am using an (n1, n2, 1) matrix that I can view in matplotlib as
an image.  My data numpy array on a grid generated by mlab.griddata.

bscan_grid graphs well, as an image, in other packages, so I believe the
issue is somewhere in the block below(with the missing pipeline).

I was hoping to get a surface plot, or height map of my bscan_grid, with z
mapped onto xy

The attached script has a bunch of debug statements, the output when used
on the attached pickle is underneath the code snippet.

I've stripped the code out and put a subsection below to illustrate my
question, which is how do I get my lovely vtkImdateData objectto chain over
and into the mapper and render my surface?

Thanks,

Nick




data_matrix = bscan_grid   #bscan_grid comes from the attached pickle and
is 997x148x1

vtk_data_array = numpy_support.numpy_to_vtk(num_array=data_matrix.ravel(),
                                            deep=True,
                                            array_type=vtk.VTK_FLOAT
                                            )

img_vtk = vtk.vtkImageData()
img_vtk.SetOrigin(minax, minrot, 0)
img_vtk.SetSpacing(bscan_adelta, bscan_rdelta, 1)
img_vtk.SetDimensions(data_matrix.shape)
img_vtk.GetPointData().SetScalars(vtk_data_array)

** Insert the magic filter widget view or transfrom thingy that connects a
vtkImage to a mapper here **
** Or alternatively, is there something wrong with the line below ***

mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(magic.GetOutputPort())
mapper.SetScalarVisibility(0)

actor = vtk.vtkActor()
actor.SetMapper(mapper)

actor.SetMapper(mapper)
renderer = vtk.vtkRenderer()
renderer.AddActor(actor)

xmins = [8830]
xmaxs = [8930]
ymins = [34]
ymaxs = [50]

render_window = vtk.vtkRenderWindow()
render_window.AddRenderer(renderer)
renderer.ResetCamera()

renderer.SetViewport(xmins[0], ymins[0], xmaxs[0], ymaxs[0])

render_window.SetSize(600, 600)

iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(render_window)

interactor_style = vtk.vtkInteractorStyleTrackballCamera()
iren.SetInteractorStyle(interactor_style)

iren.Initialize()
iren.Start()




####DEBUG STATEMENTS####
data_matrix intended x axis length 396
data_matrix intended x axis structured grid delta 0.100386432911
data_matrix intended x axis lower bound 8839.26083655
data_matrix intended x axis upper bound 8878.91347755

data_matrix intended y axis length 48
data_matrix intended y axis structured grid delta 0.104253241356
data_matrix intended y axis lower bound 34.1994628906
data_matrix intended y axis upper bound 39.0993652344

data_matrix intended z/scalar min -9.41352769373
data_matrix intended z/scalar max 19.5618770894
data_matrix dimensions (396, 48, 1)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170928/d83ac8e2/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: user_list_post.py
Type: text/x-python
Size: 2733 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170928/d83ac8e2/attachment-0001.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: data.pickle
Type: application/octet-stream
Size: 155984 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170928/d83ac8e2/attachment-0001.obj>


More information about the vtkusers mailing list