Difference between revisions of "Documentation/Labs/VTK7"

From Slicer Wiki
Jump to: navigation, search
(Verified upstream VTK fixes incorrect clipping in volume rendering)
Line 85: Line 85:
** Volume Render MRHead.
** Volume Render MRHead.
** Rotate view with up arrow key. Observe incorrect clipping once rotated 90 degrees.
** Rotate view with up arrow key. Observe incorrect clipping once rotated 90 degrees.
* [http://www.na-mic.org/Mantis/view.php?id=3969 Issue 3969], OpenGL errors due to incorrect context active during cleanup, is still an issue. Should be fixed by [https://gitlab.kitware.com/vtk/vtk/merge_requests/1636 VTK 1636] (not yet in Slicer VTK branch), but that's unverified.
* [http://www.na-mic.org/Mantis/view.php?id=3969 Issue 3969], OpenGL errors due to incorrect context active during cleanup, may still be issue. The test case in the bug seems fixed, but additional problems are likely fixed by [https://gitlab.kitware.com/vtk/vtk/merge_requests/1636 VTK 1636] (Verified, but not yet in Slicer VTK branch).

Revision as of 18:13, 19 July 2016

Home < Documentation < Labs < VTK7

This page documents the update of Slicer to use VTK 7.1.


It is planned to update the version of VTK that Slicer uses from 6.3 to 7.1. Because VTK has deprecated various headers, classes, and methods, it may be necessary to update extension code to be compatible with the new version of VTK. Additionally, because VTK has expanded the scope of code that is Python-wrapped by default, it may be necessary to add new wrapping exclusions.

The following sections describe the status of the VTK update and specific issues that may impact extensions.


Merged in r25219 to r25227, or on GitHub, e0af614...929aed2.

Branches/Merge Requests



Outstanding VTK issues

Slicer-specific VTK commits

Slicer's VTK 7.1 branch includes fixes/changes that aren't in upstream:


This section lists test failures on each platform for Release builds.

Some commits that fix Slicer builds and tests have been merged upstream:



Test results:


Test results:

Rendering backend

Although VTK 7 changes the default setting of VTK_RENDERING_BACKEND to OpenGL2, Slicer still explicitly sets it to OpenGL. Using the OpenGL2 backend in Slicer is untested and may require updates to properly build and function. This rendering backend in Slicer is set using Slicer_VTK_RENDERING_BACKEND.

OpenGL2 backend known issues

  • Issue 2165 ("Volume rendering labelmap") regresses, because the fixes in Slicer's VTK branch apply only to the OpenGL backend. For an example program that demonstrates the volume rendering problem, see https://github.com/msmolens/GPUVolumeRenderLargeLUT.
    • VTK team is investigating a solution; see https://gitlab.kitware.com/vtk/vtk/merge_requests/1048.
    • There may be an additional problem (specific to Slicer?) volume rendering the brain atlas dataset besides the sampling issue. In Slicer, GPU volume rendering shows nothing visible.
  • Does code in VolumeRenderingReplacements need updates?
    • Some of these classes could be redundant anyway; vtkOpenGLRayCastImageDisplayHelper looks identical to the version in VTK, but without VTK's bug fixes.
  • py_RSNA2012ProstateDemo test crashes due to incorrect use of VTK classes. See https://github.com/Slicer/Slicer/pull/549.
  • OpenGL errors followed by an access violation occurs in some cases when initializing Volume Rendering module logic. OpenGL errors are seen in same workflow with OpenGL backend. To reproduce: start Slicer, select "3D Only" layout, restart Slicer, load MRHead, enter Volume Rendering module. See https://github.com/Slicer/Slicer/pull/552.
Fixed upstream
  • Incorrect clipping seen during volume rendering. Fixed by VTK 1655 (Verified, but not yet in Slicer VTK branch). To reproduce:
    • Download MRHead in Sample Data.
    • Volume Render MRHead.
    • Rotate view with up arrow key. Observe incorrect clipping once rotated 90 degrees.
  • Issue 3969, OpenGL errors due to incorrect context active during cleanup, may still be issue. The test case in the bug seems fixed, but additional problems are likely fixed by VTK 1636 (Verified, but not yet in Slicer VTK branch).


The transition plan was announced on the slicer-devel mailing list: http://massmail.spl.harvard.edu/public-archives/slicer-devel/2016/040450.html.

Migration guide

This section lists categories of code changes necessary to build Slicer with VTK 7.1. Each category has a short description, an example error message, a suggested upgrade path, and references to relevant commits.

Referencing this list might be helpful if Slicer extensions require updates to be compatible with VTK 7.1.

Deprecated the vtkStreamer class hierarchy

VTK has deprecated the vtkStreamer class hierarchy.

Error message similar to:

'VTK_INTEGRATE_FORWARD' : undeclared identifier


Replace lines like:

#include "vtkStreamer.h"


#include "vtkHyperStreamline.h"


Deprecated vtkMatrix4x4::operator[] method

VTK has deprecated the vtkMatrix4x4::operator[] method.

Error message similar to:

binary '[' : 'vtkMatrix4x4' does not define this operator or a conversion to a type acceptable to the predefined operator


Replace lines like:

(*mat)[i][j] = val;
val = (*mat)[i][j];


mat->SetElement(i, j, val);
val = mat->GetElement(i, j);


Removed vtksys/ios, vtksys/stl compatibility layers

VTK has removed the vtksys/ios and vtksys/stl compatibility layers.

Error message similar to:

Cannot open include file: 'vtksys/ios/iostream': No such file or directory


Replace lines like:

#include <vtksys/ios/iostream>
#include <vtksys/ios/sstream>

vtksys_ios::ofstream ofs;


#include <iostream>
#include <sstream>

std::ofstream ofs;

Replace lines like:

#include <vtksys/stl/string>
#include <vtksys/stl/vector>

vtksys_stl::string str;
vtksys_stl::vector<double> vec;


#include <string>
#include <vector>

std::string str;
std::vector<double> vec;


vtkDataArray refactored

VTK has refactored the vtkDataArray class hierarchy.

Error message similar to:

'class XXX’ has no member named ‘SetTupleValue’


Replace lines like:

array->GetTupleValue(0, val);
array->SetTupleValue(0, val);
array->InsertTupleValue(i, val);


array->GetTypedTuple(0, val);
array->SetTypedTuple(0, val);
array->InsertTypedTuple(i, val);

Replace lines like:

#include <vtkDataArrayTemplate.h>

<any reference to "vtkDataArrayTemplate">


#include <vtkAOSDataArrayTemplate.h>

<reference to "vtkAOSDataArrayTemplate">


Deprecated pipeline update methods

VTK has deprecated and replaced certain pipeline update methods.

Error message similar to:

'class XXX’ has no member named ‘SetUpdateExtent’


Follow suggestions in VTK changelog: https://github.com/Kitware/VTK/blob/master/Documentation/Doxygen/ChangesVTK-7-1.md#pipeline-update-methods


Updated Python wrapping

VTK has updated its Python wrapping to support Python 3 and to wrap more code by default.


Compile or link error while building a Python-wrapped class or library.

Solution 1:

In CMakeLists.txt, add the WRAP_EXCLUDE_PYTHON property anywhere that the WRAP_EXCLUDE property is defined on source files.

Solution 2:

Replace lines of code like:



#ifndef __VTK_WRAP__
#endif // __VTK_WRAP__


List of extensions that may require updates

By examining the source code of Slicer extensions, it is likely that some extensions will require changes to be compatible with VTK 7.1. This section lists categories of updates and specific files in extensions that may need to be updated.

Use https://github.com/jcfr/pys4ext to fetch the source code of all extensions in the extensions index.

A useful regular expression to help identify uses of the deprecated vtkMatrix4x4 operator[] is:


However, note that this results in many false positives, because that syntax is valid for many classes.


  • DTIAtlasFiberAnalyzer/Applications/dtitractstat/fiberprocessing.cxx
  • DTIProcess/PrivateLibrary/fiberio.cxx
  • MarginCalculator/MotionSimulatorDoubleArray/MRML/vtkMRMLMotionSimulatorDoubleArrayNode.cxx
  • SPHARM-PDM/Applications/MetaMeshTools/MeshMath.cxx

Python wrapping:

    • SlicerPathology/QuickTCGA/Logic/CMakeLists.txt
    • SlicerPathology/ShortCutCore/Logic/CMakeLists.txt
    • FacetedVisualizer/Logic/vtkSlicerFacetedVisualizerLogic.h
    • FacetedVisualizer/qSlicerFacetedVisualizerModuleWidget.h
    • LightWeightRobotIGT/LightWeightRobotIGT/MRML/vtkIGTLToMRMLString.h
    • LightWeightRobotIGT/LightWeightRobotIGT/MRML/vtkMRMLIGTLSessionManagerNode.h
    • ModelClip/vtkPlaneExtend.h
    • SlicerRT/DicomRtImportExport/Logic/vtkSlicerDicomRtReader.h
    • SlicerRT/DicomRtImportExport/Logic/vtkSlicerDicomRtWriter.h
    • SlicerRT/DicomSroImport/Logic/vtkSlicerDicomSroReader.h
    • SlicerRT/SegmentationCore/vtkSegmentation.h
    • SlicerRT/Segmentations/MRML/vtkMRMLSegmentationNode.h
    • SlicerRT/SlicerRtCommon/SlicerRtCommon.h
    • SlicerRT/SlicerRtCommon/vtkCollisionDetectionFilter.h

References to VTKv6:

  • DTIPrep/SuperBuild/External_VTK.cmake
  • DTIPrep/SuperBuild/External_VTK_patch.cmake
  • SPHARM-PDM/SuperBuild/External_VTK.cmake
  • SPHARM-PDM/SuperBuild/External_VTK_patch.cmake
  • DTIAtlasBuilder/SuperBuild/FindExternalTools.cmake
  • DTIProcess/SuperBuild/External_VTK.cmake
  • DTIProcess/SuperBuild/External_VTK_patch.cmake
  • ShapePopulationViewer/SuperBuild/External_VTK_patch.cmake
  • ShapePopulationViewer/SuperBuild/External_VTK.cmake
  • FiberViewerLight/SuperBuild/External_VTK.cmake
  • FiberViewerLight/SuperBuild/External_VTK_patch.cmake
  • DTIAtlasFiberAnalyzer/SuperBuild/External_VTK.cmake

Future work

Future work in Slicer related to VTK 7 could include:

  • Remove BTX/ETX markers.
  • Resolve build warnings for -Woverloaded-virtual in Slicer VTK classes.
  • Check that settings in External_VTKv7.cmake are all still necessary, specifically VTK_USE_PARALLEL, and anything related to Qt.
  • Test Slicer_VTK_RENDERING_BACKEND set to OpenGL2.