VTK  9.3.20240327
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
QQuickVTKItem Class Reference

QQuickItem that manages a VTK rendering in the QML scenegraph. More...

#include <QQuickVTKItem.h>

Inherits QQuickItem.

Public Types

using vtkUserData = vtkSmartPointer< vtkObject >
 

Public Member Functions

 QQuickVTKItem (QQuickItem *parent=nullptr)
 
 ~QQuickVTKItem () override
 
void scheduleRender ()
 Schedules an update on the vtkRenderWindow encapsulated in this item. More...
 
virtual vtkUserData initializeVTK (vtkRenderWindow *renderWindow)
 This is where the VTK initialization should be done including creating a pipeline and attaching it to the window. More...
 
virtual void destroyingVTK (vtkRenderWindow *renderWindow, vtkUserData userData)
 At any moment the QML SceneGraph can decide to delete the underlying QSGNode. More...
 
void dispatch_async (std::function< void(vtkRenderWindow *renderWindow, vtkUserData userData)> f)
 This is the function that enqueues an async command that will be executed just before VTK renders. More...
 

Static Public Member Functions

static void setGraphicsApi ()
 Set up the graphics surface format and api. More...
 

Protected Member Functions

bool event (QEvent *) override
 
QSGNode * updatePaintNode (QSGNode *, UpdatePaintNodeData *) override
 
bool isTextureProvider () const override
 
QSGTextureProvider * textureProvider () const override
 
void releaseResources () override
 

Detailed Description

QQuickItem that manages a VTK rendering in the QML scenegraph.

Definition at line 26 of file QQuickVTKItem.h.

Member Typedef Documentation

◆ vtkUserData

Definition at line 34 of file QQuickVTKItem.h.

Constructor & Destructor Documentation

◆ QQuickVTKItem()

QQuickVTKItem::QQuickVTKItem ( QQuickItem *  parent = nullptr)
explicit

◆ ~QQuickVTKItem()

QQuickVTKItem::~QQuickVTKItem ( )
override

Member Function Documentation

◆ setGraphicsApi()

static void QQuickVTKItem::setGraphicsApi ( )
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 typically this will be in your main.cpp file.

◆ initializeVTK()

virtual vtkUserData QQuickVTKItem::initializeVTK ( vtkRenderWindow renderWindow)
inlinevirtual

This is where the VTK initialization should be done including creating a pipeline and attaching it to the window.

Note
All VTK objects are owned by and run on the QML render thread!! This means you CAN NOT touch any VTK state from any place other than in this method, in destroyingVTK or in your dispatch_async() functions!!
All VTK objects must be stored in the vtkUserData object returned from this method. They will be destroyed if the underlying QSGNode (which must contain all VTK objects) is destroyed.
At any moment the QML SceneGraph can decide to delete the underlying QSGNode. If this happens this method will be called again to (re)create all VTK objects used by this node
Because of this you must be prepared to reset all the VTK state associated with any QML property you have attached to this node during this execution of this method.
At the time of this method execution, the GUI thread is blocked. Hence, it is safe to perform state synchronization between the GUI elements and the VTK classes here.
Parameters
renderWindowThe VTK render window that creates this object's pixels for display
Returns
The vtkUserData object associated with the VTK render window

Definition at line 72 of file QQuickVTKItem.h.

◆ destroyingVTK()

virtual void QQuickVTKItem::destroyingVTK ( vtkRenderWindow renderWindow,
vtkUserData  userData 
)
inlinevirtual

At any moment the QML SceneGraph can decide to delete the underlying QSGNode.

If this happens this method will be called before the VTK objects used by this node are destroyed

Note
All VTK objects are owned by and run on the QML render thread!! This means you CAN NOT touch any VTK state from any place other than in this method, in initializeVTK, or in your dispatch_async() functions!!
At the time of this method execution, the GUI thread is blocked. Hence, it is safe to perform state synchronization between the GUI elements and the VTK classes here.
Parameters
renderWindowThe VTK render window that creates this object's pixels for display
userDataThe object associated with the VTK render window

Definition at line 95 of file QQuickVTKItem.h.

◆ dispatch_async()

void QQuickVTKItem::dispatch_async ( std::function< void(vtkRenderWindow *renderWindow, vtkUserData userData)>  f)

This is the function that enqueues an async command that will be executed just before VTK renders.

Note
All VTK objects are owned by and run on the QML render thread!! This means you CAN NOT touch any VTK state from any place other than in your function object passed as a parameter here in initializeVTK(), or in destroyingVTK() methods!!
This function most likely will only be called from the qt-gui-thread, eg. from a QML button click-handler, but may be called from a dispatch_async() function as well.
At the time of the async command execution, the GUI thread is blocked. Hence, it is safe to perform state synchronization between the GUI elements and the VTK classes in the async command function.
Parameters
fThe async command you want to execute. It's parameters are 1.) The VTK render window that creates this object's pixels for display 2.) userData An optional User Data object associated with the VTK render window

◆ scheduleRender()

void QQuickVTKItem::scheduleRender ( )

Schedules an update on the vtkRenderWindow encapsulated in this item.

This function triggers a render on the VTK render window and ensures that the render happens on the QML render thread.

Note
This public method can be invoked after updating a VTK pipeline parameter programmatically to update the item.

◆ event()

bool QQuickVTKItem::event ( QEvent *  )
overrideprotected

◆ updatePaintNode()

QSGNode* QQuickVTKItem::updatePaintNode ( QSGNode *  ,
UpdatePaintNodeData *   
)
overrideprotected

◆ isTextureProvider()

bool QQuickVTKItem::isTextureProvider ( ) const
overrideprotected

◆ textureProvider()

QSGTextureProvider* QQuickVTKItem::textureProvider ( ) const
overrideprotected

◆ releaseResources()

void QQuickVTKItem::releaseResources ( )
overrideprotected

The documentation for this class was generated from the following file: