Series
- Part-1: Install and Configure Qt5 on Ubuntu 16.04
- Part-2: Install and Configure VTK 8.1.0 from source with Qt5 on Ubuntu 16.04
- Part-3: Install and Configure PCL 1.8.1 with vtk qt support on Ubuntu 16.04 from source
- Part-4: Install and Configure PCL 1.8.1 with vtk qt support on windows 10 from source
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
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
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
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
copy
libQVTKWidgetPlugin.so
to
install path:/usr/lib/x86_64-linux-gnu/qt5/plugins/designer
cd build/lib ls -al libQVTKWidgetPlugin.so # copy to qt creator sudo cp libQVTKWidgetPlugin.so /usr/lib/x86_64-linux-gnu/qt5/plugins/designer
now list designer plugins
ls /usr/lib/x86_64-linux-gnu/qt5/plugins/designer libqquickwidget.so libQVTKWidgetPlugin.so libqwebview.so
if we start
qtcreator
we will see anQVTKWidget
at the bottom ofVTK
container ofDesign
layout.
VTK Example
CylinderRenderingProperties.cpp
#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
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.