VTK
9.1.0
|
QQuickItem subclass that manages the vtkRenderWindow and, in turn, the OpenGL context of the QML application More...
#include <QQuickVTKRenderWindow.h>
Inherits QQuickItem, and QOpenGLFunctions.
Public Slots | |
virtual void | sync () |
This is the function called on the QtQuick render thread before the scenegraph state is synchronized. More... | |
virtual void | init () |
Initialize the VTK render window for OpenGL based on the context created by QtQuick. More... | |
virtual void | paint () |
This is the function called on the QtQuick render thread right before the scenegraph is rendered. More... | |
virtual void | cleanup () |
This is the function called on the QtQuick render thread when the scenegraph is invalidated. More... | |
virtual void | renderNow () |
Convenience method that schedules a scenegraph update and waits for the update. More... | |
virtual void | render () |
Schedule a scenegraph update. More... | |
Public Member Functions | |
QQuickVTKRenderWindow (QQuickItem *parent=nullptr) | |
Constructor Creates a QQuickVTKRenderWindow with: More... | |
~QQuickVTKRenderWindow () | |
Destructor. More... | |
virtual void | mapToViewport (const QRectF &rect, double viewport[4]) |
Map a Qt item rect to viewport coordinates. More... | |
QPointer< QQuickVTKInteractorAdapter > | interactorAdapter () const |
Get access to the interactor adapter. More... | |
virtual bool | isInitialized () const |
Get whether the render window is initialized Used internally to determine if the OpenGL context, QQuickWindow, children items and viewports have been initialized. More... | |
void | setRenderWindow (vtkRenderWindow *renWin) |
Set/Get the vtkRenderWindow for the view. More... | |
void | setRenderWindow (vtkGenericOpenGLRenderWindow *renWin) |
Set/Get the vtkRenderWindow for the view. More... | |
vtkRenderWindow * | renderWindow () const |
Set/Get the vtkRenderWindow for the view. More... | |
virtual vtkSmartPointer< vtkImageData > | captureScreenshot () |
Capture a screenshot of the window. More... | |
virtual vtkSmartPointer< vtkImageData > | captureScreenshot (double *viewport) |
Capture a screenshot of the window. More... | |
Static Public Member Functions | |
static void | setupGraphicsBackend () |
Set up the graphics surface format and api. More... | |
Protected Slots | |
virtual void | handleWindowChanged (QQuickWindow *w) |
Protected Member Functions | |
void | geometryChange (const QRectF &newGeometry, const QRectF &oldGeometry) override |
bool | checkGraphicsBackend () |
Check the scenegraph backend and graphics API being used. More... | |
Protected Attributes | |
QPointer< QQuickVTKInteractorAdapter > | m_interactorAdapter |
vtkSmartPointer< vtkGenericOpenGLRenderWindow > | m_renderWindow |
bool | m_initialized = false |
bool | m_screenshotScheduled = false |
vtkNew< vtkWindowToImageFilter > | m_screenshotFilter |
vtkNew< vtkRenderer > | m_dummyRenderer |
QQuickItem subclass that manages the vtkRenderWindow and, in turn, the OpenGL context of the QML application
QQuickVTKRenderWindow extends QQuickItem in a way that allows for VTK to get a handle to, and draw inside of the QtQuick scenegraph, using OpenGL draw calls.
This item is exported to the QML layer via the QQmlVTKPlugin under the module VTK. It is registered as a type VTKRenderWindow. Since, this class is intended to manage an OpenGL context in the window, a single instance would be needed for most QML applications.
Typical usage for QQuickVTKRenderWindow in a Qml application is as follows:
To ensure that the graphics backend set up by QtQuick matches that expected by VTK, use the method QQuickVTKRenderWindow::setupGraphicsBackend() before a QApplication/QGuiApplication is instantiated in the main method of the application.
The VTK pipeline can be then set up for each VTKRenderItem in the C++ code.
QtQuick/QML scenegraph rendering is done via private API inside the QQuickWindow class. For details on QtQuick's render loop, see QtQuick Scenegraph Rendering. Qt automatically decides between a threaded and basic render loop for most applications. QQuickVTKRenderWindow and QQuickVTKRenderItem support both these variants of the QtQuick render loop.
When the scenegraph render loop is threaded, i.e. there is a dedicated rendering thread, vtk sticks to doing all rendering on this render thread. This means that all the vtk classes, pipelines etc. can be set up on the main thread but vtkRenderWindow::Render should only be invoked on the render thread. Care must be taken not to call Render on the main thread because the OpenGL context would not be valid on the main thread.
Definition at line 140 of file QQuickVTKRenderWindow.h.
QQuickVTKRenderWindow::QQuickVTKRenderWindow | ( | QQuickItem * | parent = nullptr | ) |
Constructor Creates a QQuickVTKRenderWindow with:
QQuickVTKRenderWindow::~QQuickVTKRenderWindow | ( | ) |
Destructor.
|
static |
Set up the graphics surface format and api.
This method sets the graphics API to OpenGLRhi and sets up the surface format for intermixed VTK and QtQuick rendering. Use this method before instantiating a QApplication/QGuiApplication in a QtQuick/QML app with a VTK render view like QQuickVTKRenderItem.
void QQuickVTKRenderWindow::setRenderWindow | ( | vtkRenderWindow * | renWin | ) |
Set/Get the vtkRenderWindow for the view.
Note that this render window should be of type vtkGenericOpenGLRenderWindow. This is necessary since that would allow vtk's opengl draw calls to work seamlessly inside the QtQuick created scenegraph and OpenGL context.
By default, a vtkGenericOpenGLRenderWindow is created and set on this item at construction time.
void QQuickVTKRenderWindow::setRenderWindow | ( | vtkGenericOpenGLRenderWindow * | renWin | ) |
Set/Get the vtkRenderWindow for the view.
Note that this render window should be of type vtkGenericOpenGLRenderWindow. This is necessary since that would allow vtk's opengl draw calls to work seamlessly inside the QtQuick created scenegraph and OpenGL context.
By default, a vtkGenericOpenGLRenderWindow is created and set on this item at construction time.
vtkRenderWindow * QQuickVTKRenderWindow::renderWindow | ( | ) | const |
Set/Get the vtkRenderWindow for the view.
Note that this render window should be of type vtkGenericOpenGLRenderWindow. This is necessary since that would allow vtk's opengl draw calls to work seamlessly inside the QtQuick created scenegraph and OpenGL context.
By default, a vtkGenericOpenGLRenderWindow is created and set on this item at construction time.
|
virtual |
Map a Qt item rect to viewport coordinates.
QPointer< QQuickVTKInteractorAdapter > QQuickVTKRenderWindow::interactorAdapter | ( | ) | const |
Get access to the interactor adapter.
|
virtual |
Capture a screenshot of the window.
viewport | area to capture. |
|
virtual |
Capture a screenshot of the window.
viewport | area to capture. |
|
virtual |
Get whether the render window is initialized Used internally to determine if the OpenGL context, QQuickWindow, children items and viewports have been initialized.
|
virtualslot |
This is the function called on the QtQuick render thread before the scenegraph state is synchronized.
This is where most of the pipeline updates, camera manipulations, etc. and other pre-render steps can be performed.
|
virtualslot |
Initialize the VTK render window for OpenGL based on the context created by QtQuick.
|
virtualslot |
This is the function called on the QtQuick render thread right before the scenegraph is rendered.
This is the stage where all the vtk rendering is performed. Applications would rarely need to override this method.
|
virtualslot |
This is the function called on the QtQuick render thread when the scenegraph is invalidated.
This is where all graphics resources allocated by vtk are released.
|
virtualslot |
Convenience method that schedules a scenegraph update and waits for the update.
|
virtualslot |
Schedule a scenegraph update.
|
protectedvirtualslot |
|
overrideprotected |
|
protected |
Check the scenegraph backend and graphics API being used.
|
protected |
Definition at line 269 of file QQuickVTKRenderWindow.h.
|
protected |
Definition at line 270 of file QQuickVTKRenderWindow.h.
|
protected |
Definition at line 271 of file QQuickVTKRenderWindow.h.
|
protected |
Definition at line 274 of file QQuickVTKRenderWindow.h.
|
protected |
Definition at line 275 of file QQuickVTKRenderWindow.h.
|
protected |
Definition at line 276 of file QQuickVTKRenderWindow.h.