0%

Part-2: Install and Configure VTK 8.1.0 from source with Qt5 on Ubuntu 16.04

Series

Guide

  • qt: 5.7.0
  • qmake: 3.0
  • qtcreator: 3.5.1
  • vtk: 8.1.0 (from source)

install qt57

see Part-1: Install and Configure Qt5 on Ubuntu 16.04

install qt57 and qtcreator.

install vtk

download source

Download vtk source

1
2
wget https://www.vtk.org/files/release/8.1/VTK-8.1.0.tar.gz
wget https://www.vtk.org/files/release/8.1/VTKData-8.1.0.tar.gz

integrate VTK with Qt for a pretty graphical user interface, we need to turn on some options.

configure vtk with qt

1
2
3
4
cd VTK-8.1.0
mkdir build
cd build
cmake-gui ..

with options:

VTK_Group_Qt       ON
VTK_QT_VERSION     5 # default
QT5_DIR            /opt/qt/5.7/gcc_64/lib/cmake/Qt5

VTK_RENDERING_BACKEND OpenGL2 # default
BUILD_SHARED_LIBS  ON
CMAKE_BUILD_TYPE   Release
CMAKE_INSTALL_PREFIX /usr/local

set QT5_Dir to /opt/qt/5.7/gcc_64/lib/cmake/Qt5

download MD5 VTKData

tar VTKData-8.1.0.tar.gz and copy MD5 to VTK-8.1.0/build/ExternalData/Objects/MD5

make and install

1
2
make -j8
sudo make -j8 install

install to /usr/local/include/vtk-8.1 and /usr/local/lib/cmake/vtk-8.1

install QVTKWidget plugin

  1. copy libQVTKWidgetPlugin.so to
    install path: /usr/lib/x86_64-linux-gnu/qt5/plugins/designer
1
2
3
4
5
cd build/lib
ls -al libQVTKWidgetPlugin.so

# copy to qt creator
sudo cp libQVTKWidgetPlugin.so /usr/lib/x86_64-linux-gnu/qt5/plugins/designer
  1. now list designer plugins
1
2
ls /usr/lib/x86_64-linux-gnu/qt5/plugins/designer
libqquickwidget.so libQVTKWidgetPlugin.so libqwebview.so
  1. if we start qtcreator we will see an QVTKWidget at the bottom of VTK container of Design layout.

QVTKWidget for qtcreator

VTK Example

CylinderRenderingProperties.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <vtkCylinderSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkProperty.h>
#include <vtkCamera.h>
#include <vtkSmartPointer.h>

int main(int, char *[])
{
// This creates a polygonal cylinder model with eight circumferential facets
// (i.e, in practice an octagonal prism).
vtkSmartPointer<vtkCylinderSource> cylinder =
vtkSmartPointer<vtkCylinderSource>::New();
cylinder->SetResolution(8);

// The mapper is responsible for pushing the geometry into the graphics library.
// It may also do color mapping, if scalars or other attributes are defined.
vtkSmartPointer<vtkPolyDataMapper> cylinderMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
cylinderMapper->SetInputConnection(cylinder->GetOutputPort());

// The actor is a grouping mechanism: besides the geometry (mapper), it
// also has a property, transformation matrix, and/or texture map.
// Here we set its color and rotate it around the X and Y axes.
vtkSmartPointer<vtkActor> cylinderActor =
vtkSmartPointer<vtkActor>::New();
cylinderActor->SetMapper(cylinderMapper);
cylinderActor->GetProperty()->SetColor(1.0000, 0.3882, 0.2784);
cylinderActor->RotateX(30.0);
cylinderActor->RotateY(-45.0);

// The renderer generates the image
// which is then displayed on the render window.
// It can be thought of as a scene to which the actor is added
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(cylinderActor);
renderer->SetBackground(0.1, 0.2, 0.4);
// Zoom in a little by accessing the camera and invoking its "Zoom" method.
renderer->ResetCamera();
renderer->GetActiveCamera()->Zoom(1.5);

// The render window is the actual GUI window
// that appears on the computer screen
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->SetSize(200, 200);
renderWindow->AddRenderer(renderer);

// The render window interactor captures mouse events
// and will perform appropriate camera or actor manipulation
// depending on the nature of the events.
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);

// This starts the event loop and as a side effect causes an initial render.
renderWindowInteractor->Start();

return EXIT_SUCCESS;
}

CMakeLists.txt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
cmake_minimum_required(VERSION 2.8)

PROJECT(CylinderRenderingProperties)

find_package(VTK REQUIRED)
include(${VTK_USE_FILE})

# /usr/local/lib/cmake/vtk-8.0/UseVTK.cmake
# C:/Program Files/PCL 1.8.1/3rdParty/VTK/lib/cmake/vtk-8.0/UseVTK.cmake

message ([vtk] ${VTK_LIBRARIES})

add_executable(CylinderRenderingProperties MACOSX_BUNDLE CylinderRenderingProperties.cxx )

target_link_libraries(CylinderRenderingProperties ${VTK_LIBRARIES})

compile

mkdir build && cd build && cmake-gui ..
make -j8

Reference

History

  • 20180108: created.