Volume Rendering

Necessary Files

Your own files, or:

Optional Files (premade Model files use example files above)

The purpose of this tutorial is to teach you how to perform a volume rendering of a given .vtk file. In this tutorial, we will be using the previously created and newly registered MR volume. This workflow is complex, much like the registration workflow, so it is strongly suggested that the screenshot provided be followed to ensure proper connection.

Below is a list of the required blocks and the libraries in which they reside.

  • Simulink Commonly Used Blocks Library:
    • 3 x Constant
  • SimvtkFilteringLibrary.mdl Library:
    • 1 x vtkColorTransferFunction
    • 2 x vtkPiecewiseFunction
  • SimvtkGraphicsLibrary.mdl Library:
    • 1 x vtkOutlineFilter
  • SimvtkImagingLibrary.mdl Library:
    • 1 x vtkImageShiftScale
  • SimvtkIOLibrary.mdl Library:
    • 1 x vtkDataSetReader
  • SimvtkRenderingLibrary.mdl Library:
    • 1 x vtkActor
    • 1 x vtkPolyDataMapper
    • 1 x vtkRenderer
    • 1 x vtkRendererWindow
    • 1 x vtkRenderWindowInteractor
    • 1 x vtkVolume
    • 1 x vtkVolumeProperty
  • SimvtkVolumeRenderingLibrary.mdl Library:
    • 1 x vtkVolumeRayCastCompositeFunction
    • 1 x vtkVolumeRayCastMapper

Connect the blocks as seen below (click to enlarge). These blocks will be
explained further below in order from left to right, top to bottom.

Very few parameters will need to be set in this workflow. The primary focus is on inputs and outputs so that the blocks can communicate properly and generate the result. Almost all the SimVTK blocks that will be used have the same default configuration and will need adjustment. Note that all of the blocks are clickable in the above workflow to provide verification of the values set for each block.

vtkDataSetReader

Only one parameter will need to be set for this block, and that is the FileName Parameter. Set this to “As Parameter” and enter the path (encased by single quotes) to the volume you wish to use in the FileName Value text-entry field that appears.

vtkImageShiftScale

This block is necessary as the RayCast Functions require unsigned values in order to perform. The volume used in this tutorial is a .vtk volume which is composed of “short” values and not “unsigned short” values. This block will perform a shift that will convert all the values within the file to “unsigned short” values while retaining the integrity and quality of the file (i.e. this will not affect the volume).

First, connect the vtkDataSetMapper to this block. Following this, double-click the block to configure it. Two parameters will need to be set: ClampOverflow and OutputScalarType. Set these both to “As Parameter” and set their corresponding Values to 1 and 5, respectively.


Note: we will be using the 5 as the OutputScalarType Value because it is
the necessary conversion needed for this workflow. There are several other options as
defined by the header file vtkType.h, found in VTK.

Other possibilities are:

  • #define VTK_CHAR 2
  • #define VTK_SIGNED_CHAR 15
  • #define VTK_UNSIGNED_CHAR 3
  • #define VTK_SHORT 4
  • #define VTK_UNSIGNED_SHORT 5
  • #define VTK_INT 6
  • #define VTK_UNSIGNED_INT 7
  • #define VTK_LONG 8
  • #define VTK_UNSIGNED_LONG 9
  • #define VTK_FLOAT 10
  • #define VTK_DOUBLE 11

This block will need to be connected to two blocks: vtkOutlineFilter and vtkVolumeRayCastMapper. Should you have difficulty connecting the second block, click on the input of the second block and drag back to the wire connecting the other two blocks. You will notice the wires become fused and the block will be connected to both blocks.

vtkOutlineFilter

This block comes configured to do what we need for the purposes of this tutorial. No further configuration is necessary.

vtkPolyDataMapper

As this block already has an input, an output needs to be defined. Double-click the block and scroll down to the bottom of the configuration window and click the Self as Output checkbox and click OK. With an output configured, connect the vtkOutlineFilter to this block to complete the configuration of this block.

vtkActor

This block comes pre-configured with an output, but lacks an input. Double-click the block and select the Mapper as Input checkbox near the top of the configuration window. Click OK and connect the vtkPolyDataMapper to this block.

vtkRenderer

The purpose of this block is to render the Actor and Volume blocks together. The pre-defined output is ideal for our workflow but inputs need to be specified. One vtkActor block and one vtkVolume block will end up being connected to this block, so a Value of 1 is necessary in the Actor and Volume Inputs. Following this, the vtkActor and vtkVolume blocks can be connected to the vtkRenderer.

vtkRenderWindow

With the Renderer in place, it needs to be contained in a window, hence this block. As the Self as Output parameter is pre-set, enter a value of 1 into the Renderer Inputs parameter and connect the vtkRenderer to complete configuration of this block.

vtkRenderWindowInteractor

Also, the window needs to be interactive as the initial view will, most likely, not be the ideal view for the volume. This block will allow for rotation of the volume to get an ideal angle for viewing. For this block, uncheck the Self as Output parameter as this will be the final block in the workflow. Check the RenderWindow as Input parameter and connect the vtkRenderWindow block to complete configuration of this block.

vtkVolumeRayCastMapper

With this block having an input be default, one more input and an output need to be defined for the block to function as we need. Double-click the block and check the VolumeRayCastFunction as Input and Self as Output parameters. This will allow for the next block, the vtkVolumeRayCastCompositeFunction to be connected as well as this block being connected to the vtkVolume block.

vtkVolumeRayCastCompositeFunction

This block comes configured as needed for this workflow. Connect it to the VolumeRayCastFunction input on the vtkVolumeRayCastMapper block to complete configuration of this block.

vtkVolume

This block is preset to use Self as Output, so only the inputs need be set. We will be needing Mapper and Property Inputs, so double-click the block and click the appropriate checkboxes. Following this, the vtkVolumeRayCastMapper and vtkVolumeProperty blocks can be properly connected to their respective inputs.

vtkVolumeProperty

Three inputs will be needed for this block: Color, GradientOpacity, and ScalarOpacity. Double-click the block, and click the three appropriate checkboxes to enable these inputs.

Constant1 (upper)

This is a constant that will be connected to the vtkColorTransferFunction block that acts to add an RGBPoint in the format of (x, r, g, b). For this workflow, we are using a 3×4 matrix of values to define three values of intensity found in the MR to be represented by the rendering. R, G, and B are percentage values, meaning they will be a value between 0 and 1.

The matrix used in the example model was:

  • [300 0 0 0; 225 1.0 0.7 0.6; 150 1.0 1.0 0.9].

vtkColorTransferFunction

Currently, this block functions strictly as provided, so no configuration is necessary. Connect it to the Color input on the vtkVolumeProperty block.

Constant2 (middle)

This constant will be connected to the vtkPiecewiseFunction block that will be connected to the GradientOpacity input on the vtkVolumeProperty block. This constant serves to add points, in the form of (x, y), for use with the vtkPiecewiseFunction.

The matrix used in the example model was:

  • [150 0.5; 5 1.0; 0 2.0]

vtkPiecewiseFunction (upper)

Currently, this block functions strictly as provided, so no configuration is necessary. Connect it to the GradientOpacity input on the vtkVolumeProperty block.

Constant3 (lower)

This constant will be connected to the vtkPiecewiseFunction block that will be connected to the GradientOpacity input on the vtkVolumeProperty block. This constant serves to add points, in the form of (x, y), for use with the vtkPiecewiseFunction.

The matrix used in the example model was:

  • [300 0.0; 225 0.02; 150 0.8]

vtkPiecewiseFunction (lower)

Currently, this block functions strictly as provided, so no configuration is necessary. Connect it to the ScalarOpacity input on the vtkVolumeProperty block.

Once these are all connected with the proper outputs, press run and you should see something similar to this:

Congratulations! You have completed the tutorial!

> Continue onto the Surface Model and Volume Rendering Overlay tutorial.

Comments are closed.