The source code is based on Nicanor Romero Venier's project
This project provides a solution to render VTK objects on QML-based UI.
Moreover, I re-organize the architecture of the code and make it simple and scalable.
The architecture can be described as below:
MVVM
architectural pattern is used.Model
is put insidesrc/model
folder.View
is put insidesrc/view
folder.ViewModel
is put insidesrc/ctrls
folder.- Data/Variables which are cached/stored the app states should be saved in
Model
which is implementedSingleton
design pattern. - The
Model
will emit aSignal
if data is changed. - The
ViewModel
will catch thatSignal
and pass the data along with theSignal
as the parameter. - The
ViewModel
also exposes the methods to theView
. ViewModel
's methods will be called through theView
.
Fbo
andFboRenderer
classes support graphical rendering process.src/graphics/vtkModel
folder has VTK-related model which support the creation of VTK objects.ProcessingEngine
class support VTK-related model managing.
- Every graphical actions should be done inside Render Thread.
Command pattern
is used to make sure those actions will be done correctly.
The code was tested by using Anaconda3 and the following combinations:
- Python 3.6.6 + PySide2 5.13.2 + VTK 8.1.1/8.1.2/8.2.0 (built from source) + Ubuntu 16.04/Windows 10
- Python 3.7.5 + PySide2 5.13.1 + VTK 8.2 Thanks szmurlor
- Python 3.7.10 + PySide2 5.13.2/5.15.2 + VTK 8.1.2 (from pypi) Thanks Senthil
conda create --name QmlVtk python=3.7
conda activate QmlVtk
conda install -c conda-forge pyside2=5.13.2 # Linux
pip install PySide2==5.13.2 # Windows
pip install vtk==8.1.2 # check compatibility section
If you want to use vtkGPUVolumeRayCastMapper
, you have to use vtkExternalOpenGLRenderWindow
instead of vtkGenericOpenGLRenderWindow
(in FboRenderer
class). vtkExternalOpenGLRenderWindow
will require VTK to be built with vtkRenderingExternal
option. It means you have to rebuild VTK from source.