Building VTK 9 using Visual Studio

Visual Studio 2019 + CMake + VTK source code = VTK binaries and libraries

I am a VTK fan! VTK contains algorithms for visualization using scalar, vector, tensor, texture, and volumetric methods; and advanced modeling techniques like implicit modeling, polygon reduction, mesh smoothing, cutting, contouring, and Delaunay triangulation 🤓

The Visualization Toolkit (VTK) is an open-source software system for 3D computer graphics, image processing and scientific visualization. VTK is composed of C++ classes (the core) and several interpreted interface layers including Tcl/Tk, Java, and Python.

A dragon lit with a ambient occlusion technique
Taken from Kitware blog, where a screen-space technique is shown

In any case, the evolution of VTK since its conception in 1993 has been enormous. There are versions to speed-up and parallelize certain computationally intensive tasks using accelerators such as GPGPU (VTK-m), or the scientific visualization in your browser using VTK.js.

Well, VTK is cross-platform and runs on Linux, Windows, Mac and Unix platforms. Then, it offers the source code to be compiled that could be downloaded from or from its GitHub repo

Building VTK in Windows

The goal of this process is to compile and build the binaries and libraries of VTK to be used in our projects. Then, we need to use a C++ compiler to generate the .lib and .dll files for our machine/version 👻

First, you need to download VTK source code from the webpage and unzipped it into a favorite location. I used to copy into a folder in the root folder C:/VTK, and copy inside it because I can have different versions.

The next step is to download and install CMake. CMake allows a software compilation process with a simple platform and GUI being compiler independent with configuration files (i.e. CMakeLists.txt).

After, open CMake (cmake-gui) and in the text field Where is the source have to set where the code is unzipped (in my case c:/VTK/VTK-9.0.1), and in the text field Where to build the binaries you should put the location where compiled/built code should be placed. I chose the folder build/, but it could be x64/ or binaries/, any name that you want. Just to avoid conflicts, I avoid create the bin/ folder inside the VTK source code folder, you can put outside that folder.

Then, you should click on the Configure button where you should select the compiler for the code. For this, you might ensure the existence of those compilers in your machine 🎃

Once you press Finish, the process has started and you will see something like:

At this point, you need to wait until it finishes which can take 10-20 minutes (depending on your machine' setup of course), and after you might select the different options provided for the compilation step. There are several options for compilation focused on features to activate in our VTK library:

You can change your options according to your configuration also the expected features in VTK, or just the documentation and examples. Notice that you can check the Advanced option in the CMake' windows to explore in-depth the offered options. Then, according to your options, maybe you need to select some paths of libraries or software to continue. In any case, the next step is to press the Configure button again until appearing the message Configuring done in the bottom output window.

Then, it comes the final step: the generation of files. For this, just press the Generate button and later the output is already done. For instance, the image below shows a part of the files generated in your build output folder chosen:

Following, using the Visual Studio, we need opening the solution called VTK.sln and you will see something like this:

You have several projects to build, and you can build each one in different configurations: Debug, Minimum Size Release, Release or Release with Debugging Info. There is a project called ALL_BUILD to compile all projects. This compilation process might take several minutes.

All these steps are available in the official wiki of VTK, maybe a little out-of-date but still maintains the main goal of the process. There you can explore how to install VTK on your computer:

  • Copying files into the classic System32 (or in SysWOW64 in this case)
  • Using the project INSTALL inside the Visual Studio solution
  • Copying the .lib and .dll files directly to your project
  • Add the bin folder to the PATH. In fact, inside the build/ folder there are each .bat file for each building process (e.g. for Debug there is windows_path.Debug.bat)

All the modules could be found on the file modules.json also located in the build/ folder. This file looks like:

	"modules": {
		"VTK::zlib": {
			"library_name": "vtkzlib",
			"description": "",
			"enabled": true,
			"implementable": false,
			"third_party": true,
			"wrap_exclude": false,
			"kit": null,
			"depends": [],
			"optional_depends": [],
			"private_depends": [],
			"implements": [],
			"headers": ["vtkzlib/zconf.h", "vtkzlib/zlib.h"]

Note that for new projects, you need the headers file, lib files and dll files to execute them properly. Particularly, I used a Makefile in my project and set folders where VTK built is.

Now, you can use VTK on your code 😎, enjoy it!

From a geeks to geek

Share Tweet Send
You've successfully subscribed to The ecode.DEV repository
Great! Next, complete checkout for full access to The ecode.DEV repository
Welcome back! You've successfully signed in
Success! Your account is fully activated, you now have access to all content.