Volume Render DICOM Dataset
Written by Mark Wyszomierski   
Monday, 27 August 2007
ImageDownload article attachment: DevSample_RenderVolume.zip(28.2kb)


This article offers a simple wrapper class which can be used to render a DICOM dataset composed of individual 2D images. The attached application can render greyscale and true color DICOM datasets.

Some notes before continuing:

  1. The attached application was created and compiled using visual studio 2005, but the source files should be cross platform (let me know if not).
  2. You'll have to set the VTK header and library include paths to where they reside on your own machine. In the attached application, they are located at C:\libs\vtk\vtk-5.0.3\VTK.
  3. The attached application uses the latest stable version of VTK (5.0.3).
All VTK rendering code has been placed into one wrapper class called WrapperVtkRenderVolume. It handles setting up the rendering pipeline, loading the DICOM images from the requested directory, and rendering the final result. A few support classes are also included in the application (which are not necessary) but add window/level support, text information etc.

Here in main.cpp, an instance of WrapperVtkRenderVolume is created with a default window size, it is passed a path to a folder containing DICOM images, and if successful, starts the interactor embedded in the wrapper class:
Usage
  1. // Create the wrapper and load the volume from DICOM files.
  2. WrapperVtkRenderVolume w(640, 480);
  3. if (w.LoadVolumeFromFolder(strFolderPath)) {
  4.     w.Start();
  5. }
  6. else {
  7.     cout << "Error:" << endl;
  8.     cout << w.GetDetails() << endl << endl;
  9. }


When the wrapper has finished loading the volume, it will automatically pick a VTK mapper class for rendering. If the DICOM images are greyscale, it will use

vtkFixedPointVolumeRayCastMapper for software rendering. This mapper supports window/leveling which has been added to the application (hold the shift key down + left mouse button then move the mouse). If the dataset is true color, the wrapper class will use vtkVolumeTextureMapper3D, which is a very fast hardware renderer. This mapper does not support window/leveling.

The wrapper is quite short (276 lines) and is heavily commented. Here is a listing of the other support files:

  1. InteractorStyle3dWindowLevel - an interactor style derived from

    vtkInteractorStyleTrackballCamera. This class invokes window/level events which can be observed to support window/level of greyscale datasets.

  2. VtkObserverWindowLevel - observes window/level events generated by InteractorStyle3dWindowLevel. This observer actually does the window/level work.

  3. VtkObserverErrorWarning - observes errors and warnings while the DICOM files are being loaded from disk.

  4. VtkObserverFileLoad - observes load progress while the DICOM dataset is being loaded from disk so the end user has some idea of how long loading will take.

  5. WrapperVtkText - wraps a vtkTextMapper and vtkActor2D to provide a simple information text layer.

The above support files are not necessary for rendering, so you can disregard them if you just want to know how to render a DICOM dataset.

vtkDICOMImageReader
is used to read the DICOM files from the chosen directory. I would not recommend using this class for release code. If it encounters a non-DICOM file in the passed directory, it will invoke an error event. It also will not recursively search into sub folders for DICOM files. I used it in this example to keep everything within VTK. Normally I would use
dcmtk to make a more sophisticated directory reader for DICOM files.

Download the attached application to see the source code. The wrapper class and all the support files can be used outside a command line application, in other samples I show how to use the same code in a win32 MDI project.

If there are any questions or comments, please send them in.