[vtkusers] Help with vtkImageData()

Elvis Stansvik elvis.stansvik at orexplore.com
Mon Oct 2 02:41:25 EDT 2017

Den 28 sep. 2017 11:07 em skrev "Nick Torenvliet" <natorenvliet at gmail.com>:

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 haven't looked in detail at the code, but it looks like you're trying to
use a vtkPolyDataMapper to visualize a vtkImageData. vtkPolyDataMapper is
for visualizing polygonal data. Normally to visualize a vtkImageData (a
volume) you'd use a volume mapper such as vtkSmartVolumeMapper or
vtkGPUVolumeRayCastMapper. Also, in order to do that I think the volume
needs to be > 1 in all dimensions, as VTK interpolates between datapoints
to form a visual voxel.

But I may of course be misunderstanding, I'm somewhat new to VTK myself.


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?



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(),

img_vtk = vtk.vtkImageData()
img_vtk.SetOrigin(minax, minrot, 0)
img_vtk.SetSpacing(bscan_adelta, bscan_rdelta, 1)

** 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()

actor = vtk.vtkActor()

renderer = vtk.vtkRenderer()

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

render_window = vtk.vtkRenderWindow()

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

render_window.SetSize(600, 600)

iren = vtk.vtkRenderWindowInteractor()

interactor_style = vtk.vtkInteractorStyleTrackballCamera()


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 <(561)%20877-0894>
data_matrix dimensions (396, 48, 1)

Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/

Please keep messages on-topic and check the VTK FAQ at:

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20171002/0e09cac7/attachment.html>

More information about the vtkusers mailing list