Installation of VTK 6 in Ubuntu

Download VTK 6 source from download site into a local directory and unzip it. Suppose the unzipped source directory is /home/me/Downloads/VTK-6.2.0.

Create a separate build directory, eg., /opt/VTK-build.:

   sudo su
   mkdir /opt/VTK-build
   cd /opt/VTK-build
   ccmake /home/me/Downloads/VTK-6.2.0


In ccmake, type "c" to configure. Then, select the options you like, e.g., turning on

   BUILD_EXAMPLES
   BUILD_SHARED_LIBS
   VTK_Group_Qt
   VTK_Group_Rendering
   VTK_Group_StandAlone


You can also change the install prefix, which defaults to /usr/local.

Type "c" one or more times until no errors occur. If you need to install doxygen, do

   sudo apt-get install doxygen

Then, type "g" to generate.

Then, create a release directory, e.g., /opt/VTK-6.2, and, generate the Makefile:

   mkdir /opt/VTK6.2
   cd /opt/VTK6.2
   cmake -DCMAKE_BUILD_TYPE:STRING=Release /home/me/Downloads/VTK-6.2.0

To use VTK 6 with Qt 5, do

   cd /opt/VTK6.2
   cmake -DVTK_QT_VERSION:STRING=5 \
         -DQT_QMAKE_EXECUTABLE:PATH=/opt/Qt5.4.1/5.4/gcc_64/bin/qmake \
         -DVTK_Group_Qt:BOOL=ON \
         -DCMAKE_PREFIX_PATH:PATH=/opt/Qt5.4.1/5.4/gcc_64/lib/cmake \
         -DBUILD_SHARED_LIBS:BOOL=ON /opt/VTK6.2

Then, run

   make -j4
   make install


By default, the .h files are installed in /usr/local/include/vtk-6.2 and the library files are installed in /usr/local/lib. To be consistent, you can create a directory /usr/local/lib/vtk-6.2 and move the library files into this directory.

The libraries are named as libvtk*-6.2.so.1. This naming convention is inconvenient to use. A more convenient naming convetion is simply libvtk*.so. To generate symbolic links of the convenient names to the library files, download this script and run it in the folder that contains the library files.
 

Migration of VTK 5 to VTK 6
Factory Initialisation

If your VTK 6.2 code is not compiled with cmake, it may get the error "no override found for ..." and a NULL pointer when it calls New() function of a module. This is because the factory methods of VTK 6 require explicit initialisation. To resolve this problem, add the following at the top of main.cpp, the file that contains main():

   #include <vtkAutoInit.h>
   VTK_MODULE_INIT(vtkRenderingOpenGL);


This will initialise vtkRenderingOpenGL object factories.

If you are using VTK 6.0 or 6.1, then inlcude the following before including any VTK header files:

   #define vtkRenderingCore_AUTOINIT \
      4(vtkInteractionStyle,vtkRenderingFreeType,vtkRenderingFreeTypeOpenGL,vtkRenderingOpenGL)
   #define vtkRenderingVolume_AUTOINIT 1(vtkRenderingVolumeOpenGL)


Unknown Libraries

VTK 6 also requires explicit linking of additional libraries that are not necessary in VTK 5 such as libvtkCommonColor.so, libvtkCommonSystem.so, etc.

To identify the library file that contains a class, e.g., vtkActor, search vtkActor.h in the VTK source folders. The name of the folder that contains vtkActor.h is the name of the library, in this case, .../Rendering/Core, which corresponds to libvtkRenderingCore.so.

To identify the library file that contains a class function, e.g., vtkColorTransferFunction, download this script file, save it, e.g., as findlib and change its mode to executable:

   chmod +x findlib

Then, run the script file as follows:

   findlib <path of library folder> <function name>

For more information, refer to VTK 6 Migration Guide.
 
Installation of VTK 5 in Ubuntu
To use VTK 5 together with Qt 4, do

   sudo apt-get install libvtk5-qt4-dev
 
Compiling VTK Programs
To compile VTK with Qt, refer to Compiling Qt and VTK. This method can also be used to compile VTK programs without Qt.

Another way to compile VTK program by itself is as follows. Go to the directory that contains the program, create the file CMakeLists.txt. This file contains information that tells cmake how to generate the required make file. For example,

   CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

   PROJECT (test1)

   IF(NOT VTK_BINARY_DIR)
   FIND_PACKAGE(VTK REQUIRED)
   INCLUDE(${VTK_USE_FILE})
   ENDIF(NOT VTK_BINARY_DIR)

   ADD_EXECUTABLE(test1 test1.cpp)
   TARGET_LINK_LIBRARIES(test1 vtkRendering)


In this example, the name of the source file is test1.cpp and the names of the project and the executable are test1.

After creating CMakeLists.txt, compile the program as follows:

   cmake .
   make


The first command invokes cmake to create the makefile which make uses to compile the program.

For more information about cmake, refer to Kitware's online page.
  
Documentation
For online documentation, browse VTK online documentation.

For offline documentation, download the html documentation from VTK website. Note that this documentation contains many, many files.