Skip to content

Latest commit

 

History

History
132 lines (95 loc) · 4.45 KB

getting_started_linux.md

File metadata and controls

132 lines (95 loc) · 4.45 KB

Getting Started Using Linux

Table of Contents

  1. Introduction
  2. Tools Needed
  3. Build VTK
    1. Using the VTK master
    2. Using a VTK release
  4. Verification

Introduction

These instructions will will lead you step by step through the process of setting up VTK in your home folder.

The instructions are based on Debian versions of Linux implementations. However work-arounds for other implementations are easily achieved.

After completing these instructions, you will have a basic VTK build with Python wrappings. From this base you can then add more options and build settings as outlined in the full documentation Building VTK.

We are assuming that you are working in your home folder and the directory structure in your home folder will be:

|-- dev
  |-- vtk
    |-- build  - where vtk will be built
    |-- src    - the vtk source files
  |-- my-tests - a place to put some test files

This folder structure assumes that the VTK master will be checked out. If you use a VTK release instead of the master, src will be replaced with the release name.

Tools Needed

Make sure we have the tools needed to build VTK, also some Python tools:

sudo apt install build-essential cmake mesa-common-dev mesa-utils freeglut3-dev python3-dev python3-venv git-core ninja-build

The Python tools are optional but may be needed if you decide to use a virtual environment in future.

We will use ninja as a replacement for make.

For CMake, the latest version is available from CMake's download page, otherwise:

sudo apt-get install cmake cmake-gui

These instructions are using the system Python. If you use a different Python implementation or a virtual environment make sure the environment you use is activated.

Build VTK

Here we create the folder structure, get the VTK source and build it.

Using the VTK master

cd ~
mkdir -p ~/dev/{vtk/{src,build},my-tests}
cd ~/dev/vtk/
git clone --recursive https://gitlab.kitware.com/vtk/vtk.git src
cd ~/dev/vtk/build
cmake ../src -DVTK_WRAP_PYTHON=ON -GNinja
# Build using the generator specified in cmake.
cmake --build .

Using a VTK release

We recommend using the latest release.

cd ~
mkdir -p ~/dev/{vtk/build,my-tests}

Now download the VTK source from VTK Releases, untar it into ~/dev/vtk/. The resultant folder will have a name similar to VTK-x.y.z e.g. VTK-9.2.0. Remember to substitute VTK-x.y.z with the untarred folder name in the following steps.

cd ~/dev/vtk/build
cmake ../VTK-x.y.z -DVTK_WRAP_PYTHON=ON -GNinja
# Build using the generator specified in cmake.
cmake --build .

Verification

Download a C++ and Python example and verify that your build of VTK works on them.

Go to the C++ CylinderExample and download the tarball, extract it in to ~/dev/my-tests

In the same folder, ~/dev/my-tests, create a file called CylinderExample.py and mark it executable. Go to Python CylinderExample and copy it into your CylinderExample.py and save it.

Now test using vtkpython, python3 and then build and test the C++ version:

cd ~/dev/my-tests
# Set your environment.
export VTK_DIR=$HOME/dev/vtk/build
export PYTHONPATH=~/dev/vtk/build/lib/python3.9/site-packages:$PYTHONPATH
alias vtkpython=~/dev/vtk/build/bin/vtkpython
# Test vtkpython.
vtkpython CylinderExample.py
# Test Python.
python3 CylinderExample.py
# Build the C++ version.
cd ~/dev/my-tests/CylinderExample/build
cmake .. -GNinja
# Build using the generator specified in cmake.
cmake --build .
# Test the C++ build.
./CylinderExample

Note:

  • PYTHONPATH is only needed if you are using the python executable e.g. python3. It is not needed if vtkpython is used.

  • With respect to PYTHONPATH you may have a different Python version so check your path.

  • VTK_DIR allows cmake to find where VTK is. When you develop your own code you can just use:

    -DVTK_DIR="<path to my vtk build>"
    

    as a cmake option.