[vtkusers] VTK Query regarding volume rendering

shaleen jain anuj6491 at gmail.com
Mon Jan 16 01:23:59 EST 2017

Why the output of the following code is just a box?

import vtkimport picklefrom numpy import *

data_matrix = Ilog
dataImporter = vtk.vtkImageImport()# The preaviusly created array is
converted to a string of chars and imported.
data_string = data_matrix.tostring()
dataImporter.CopyImportVoidPointer(data_string, len(data_string))# The
type of the newly imported data is set to unsigned char (uint8)
# must be told this is the case.
dataImporter.SetNumberOfScalarComponents(1)# The following two
functions describe how the data is stored and the dimensions of the
array it is stored in. For this# simple case, all axes are of length
75 and begins with the first element. For other data, this is probably
not the case.# I have to admit however, that I honestly don't know the
difference between SetDataExtent() and SetWholeExtent() although# VTK
complains if not both are used.
dataImporter.SetDataExtent(0, 727, 0, 727, 0, 24)
dataImporter.SetWholeExtent(0, 727, 0, 727, 0, 24)
# The following class is used to store transparency-values for later
retrieval. In our case, we want the value 0 to be# completely opaque
whereas the three different cubes are given different
transparency-values to show how it works.
alphaChannelFunc = vtk.vtkPiecewiseFunction()
alphaChannelFunc.AddPoint(0, 1)

alphaChannelFunc.AddPoint(0.5, 0.9)
alphaChannelFunc.AddPoint(0.7, 0.9)
alphaChannelFunc.AddPoint(1, 0)

colorFunc = vtk.vtkColorTransferFunction()
colorFunc.AddRGBPoint(0, 1,1,1)

colorFunc.AddRGBPoint(0.2, 0.9, 0.9, 0.9)
colorFunc.AddRGBPoint(0.7, 0.2, 0.2, 0.2)
colorFunc.AddRGBPoint(1, 0, 0, 0)
# The preavius two classes stored properties. Because we want to apply
these properties to the volume we want to render,# we have to store
them in a class that stores volume properties.
volumeProperty = vtk.vtkVolumeProperty()
# This class describes how the volume is rendered (through ray tracing).
compositeFunction = vtk.vtkVolumeRayCastCompositeFunction()# We can
finally create our volume. We also have to specify the data for it, as
well as how the data will be rendered.
volumeMapper = vtk.vtkVolumeRayCastMapper()
# The class vtkVolume is used to pair the previously declared volume
as well as the properties to be used when rendering that volume.
volume = vtk.vtkVolume()
# With almost everything else ready, its time to initialize the
renderer and window, as well as creating a method for exiting the
renderer = vtk.vtkRenderer()

 renderWin = vtk.vtkRenderWindow()
 renderInteractor = vtk.vtkRenderWindowInteractor()

 # We add the volume to the renderer ...
 # ... set background color to white ...
 # ... and set window size.

 # A simple function to be called when the user decides to quit the
application.def exitCheck(obj, event):
    if obj.GetEventPending() != 0:
# Tell the application to use the function as an exit check.
renderWin.AddObserver("AbortCheckEvent", exitCheck)

renderInteractor.Initialize()# Because nothing will be rendered
without any input, we order the first render manually before control
is handed over to the main-loop.

Ilog is logical matrix of size 728x728x25 whose cross-section looks like

[image: enter image description here] <https://i.stack.imgur.com/Z8qCP.png>

In this image the red color signifies the value 1 and the blue color
signifies the value 0.

but when the above code is compiled the output is always a box like

[image: enter image description here] <https://i.stack.imgur.com/Q6ESB.png>.

The matrix contains values just zeros and ones. Using that logic the value
with zeros have given full transparency and the values with zero have full

The question can also be found on: http://stackoverflow.com/

Thanking you

Best Regards,
Shaleen Jain
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170116/4f5dfb9e/attachment.html>

More information about the vtkusers mailing list