VTK
9.0.2
|
QOpenGLWidget subclass to house a vtkGenericOpenGLRenderWindow in a Qt application. More...
#include <QVTKOpenGLNativeWidget.h>
Inherits QOpenGLWidget.
Public Member Functions | |
QVTKOpenGLNativeWidget (QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags()) | |
QVTKOpenGLNativeWidget (vtkGenericOpenGLRenderWindow *window, QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags()) | |
~QVTKOpenGLNativeWidget () override | |
void | setRenderWindow (vtkGenericOpenGLRenderWindow *win) |
Set a render window to use. More... | |
void | setRenderWindow (vtkRenderWindow *win) |
vtkRenderWindow * | renderWindow () const |
Returns the render window that is being shown in this widget. More... | |
QVTKInteractor * | interactor () const |
Get the QVTKInteractor that was either created by default or set by the user. More... | |
void | setEnableHiDPI (bool enable) |
Enable or disable support for HiDPI displays. More... | |
bool | enableHiDPI () const |
void | setUnscaledDPI (int) |
Set/Get unscaled DPI value. More... | |
int | unscaledDPI () const |
void | setDefaultCursor (const QCursor &cursor) |
Set/get the default cursor to use for this widget. More... | |
const QCursor & | defaultCursor () const |
void | SetRenderWindow (vtkGenericOpenGLRenderWindow *win) |
void | SetRenderWindow (vtkRenderWindow *win) |
vtkRenderWindow * | GetRenderWindow () |
These methods have be deprecated to fix naming style. More... | |
QVTKInteractor * | GetInteractor () |
QVTKInteractorAdapter * | GetInteractorAdapter () |
void | setQVTKCursor (const QCursor &cursor) |
void | setDefaultQVTKCursor (const QCursor &cursor) |
Static Public Member Functions | |
static QSurfaceFormat | defaultFormat (bool stereo_capable=false) |
Returns a QSurfaceFormat suitable for surfaces that intend to be used for VTK rendering. More... | |
Protected Slots | |
virtual void | cleanupContext () |
Called as a response to QOpenGLContext::aboutToBeDestroyed . More... | |
void | updateSize () |
Protected Member Functions | |
bool | event (QEvent *evt) override |
void | initializeGL () override |
void | paintGL () override |
Protected Attributes | |
vtkSmartPointer< vtkGenericOpenGLRenderWindow > | RenderWindow |
QScopedPointer< QVTKRenderWindowAdapter > | RenderWindowAdapter |
QOpenGLWidget subclass to house a vtkGenericOpenGLRenderWindow in a Qt application.
QVTKOpenGLNativeWidget extends QOpenGLWidget to make it work with a vtkGenericOpenGLRenderWindow.
Please note that QVTKOpenGLNativeWidget only works with vtkGenericOpenGLRenderWindow. This is necessary since QOpenGLWidget wants to take over the window management as well as the OpenGL context creation. Getting that to work reliably with vtkXRenderWindow or vtkWin32RenderWindow (and other platform specific vtkRenderWindow subclasses) was tricky and fraught with issues.
Since QVTKOpenGLNativeWidget uses QOpenGLWidget to create the OpenGL context, it uses QSurfaceFormat (set using QOpenGLWidget::setFormat
or QSurfaceFormat::setDefaultFormat
) to create appropriate window and context. You can use QVTKOpenGLNativeWidget::copyToFormat
to obtain a QSurfaceFormat appropriate for a vtkRenderWindow.
A typical usage for QVTKOpenGLNativeWidget is as follows:
In QOpenGLWidget (superclass for QVTKOpenGLNativeWidget), all rendering happens in a framebuffer object. Thus, care must be taken in the rendering code to never directly re-bind the default framebuffer i.e. ID 0.
QVTKOpenGLNativeWidget creates an internal QOpenGLFramebufferObject, independent of the one created by superclass, for vtkRenderWindow to do the rendering in. This explicit double-buffering is useful in avoiding temporary back-buffer only renders done in VTK (e.g. when making selections) from destroying the results composed on screen.
QWidget subclasses (including QOpenGLWidget
and QVTKOpenGLNativeWidget
) display their contents on the screen in QWidget::paint
in response to a paint event. QOpenGLWidget
subclasses are expected to do OpenGL rendering in QOpenGLWidget::paintGL
. QWidget can receive paint events for various reasons including widget getting focus/losing focus, some other widget on the UI e.g. QProgressBar in status bar updating, etc.
In VTK applications, any time the vtkRenderWindow needs to be updated to render a new result, one call vtkRenderWindow::Render
on it. vtkRenderWindowInteractor set on the render window ensures that as interactions happen that affect the rendered result, it calls Render
on the render window.
Since paint in Qt can be called more often then needed, we avoid potentially expensive vtkRenderWindow::Render
calls each time that happens. Instead, QVTKOpenGLNativeWidget relies on the VTK application calling vtkRenderWindow::Render
on the render window when it needs to update the rendering. paintGL
simply passes on the result rendered by the most render vtkRenderWindow::Render to Qt windowing system for composing on-screen.
There may still be occasions when we may have to render in paint
for example if the window was resized or Qt had to recreate the OpenGL context. In those cases, QVTKOpenGLNativeWidget::paintGL
can request a render by calling QVTKOpenGLNativeWidget::renderVTK
.
QVTKOpenGLNativeWidget does not support stereo, please use QVTKOpenGLStereoWidget if you need support for stereo rendering
QVTKOpenGLNativeWidget is targeted for Qt version 5.5 and above.
Definition at line 119 of file QVTKOpenGLNativeWidget.h.
QVTKOpenGLNativeWidget::QVTKOpenGLNativeWidget | ( | QWidget * | parent = nullptr , |
Qt::WindowFlags | f = Qt::WindowFlags() |
||
) |
QVTKOpenGLNativeWidget::QVTKOpenGLNativeWidget | ( | vtkGenericOpenGLRenderWindow * | window, |
QWidget * | parent = nullptr , |
||
Qt::WindowFlags | f = Qt::WindowFlags() |
||
) |
|
override |
void QVTKOpenGLNativeWidget::setRenderWindow | ( | vtkGenericOpenGLRenderWindow * | win | ) |
Set a render window to use.
It a render window was already set, it will be finalized and all of its OpenGL resource released. If the win
is non-null and it has no interactor set, then a QVTKInteractor instance will be created as set on the render window as the interactor.
void QVTKOpenGLNativeWidget::setRenderWindow | ( | vtkRenderWindow * | win | ) |
vtkRenderWindow* QVTKOpenGLNativeWidget::renderWindow | ( | ) | const |
Returns the render window that is being shown in this widget.
QVTKInteractor* QVTKOpenGLNativeWidget::interactor | ( | ) | const |
Get the QVTKInteractor that was either created by default or set by the user.
|
static |
Returns a QSurfaceFormat suitable for surfaces that intend to be used for VTK rendering.
If your applications plans on using QVTKOpenGLNativeWidget
, then this format (or similar) must be set as the default format on QSurfaceFormat before any widgets are created.
Note this returns a QSurfaceFormat required to support the OpenGL rendering capabilities in a vtkRenderWindow. Whether those features, e.g. multi sampling, is actually used for rendering is determined by values specified on the vtkRenderWindow instance itself through appropriate API.
Passing stereo_capable=true
is same as calling QSurfaceFormat::setStereo(true)
. This is necessary if you want to use quad-buffer based stereo in your application.
Refer to Qt docs for QOpenGLWidget and QOpenGLWindow for appropriate locations in your application where to the format may be provided e.g. either on the instance of QOpenGLWindow or QOpenGLWidget subclasses or as default format for the application using QSurfaceFormat::setDefaultFormat()
.
void QVTKOpenGLNativeWidget::setEnableHiDPI | ( | bool | enable | ) |
Enable or disable support for HiDPI displays.
When enabled, this enabled DPI scaling i.e. vtkWindow::SetDPI
will be called with a DPI value scaled by the device pixel ratio every time the widget is resized. The unscaled DPI value can be specified by using setUnscaledDPI
.
|
inline |
Definition at line 164 of file QVTKOpenGLNativeWidget.h.
void QVTKOpenGLNativeWidget::setUnscaledDPI | ( | int | ) |
Set/Get unscaled DPI value.
Defaults to 72, which is also the default value in vtkWindow.
|
inline |
Definition at line 173 of file QVTKOpenGLNativeWidget.h.
void QVTKOpenGLNativeWidget::setDefaultCursor | ( | const QCursor & | cursor | ) |
Set/get the default cursor to use for this widget.
|
inline |
Definition at line 181 of file QVTKOpenGLNativeWidget.h.
void QVTKOpenGLNativeWidget::SetRenderWindow | ( | vtkGenericOpenGLRenderWindow * | win | ) |
void QVTKOpenGLNativeWidget::SetRenderWindow | ( | vtkRenderWindow * | win | ) |
vtkRenderWindow* QVTKOpenGLNativeWidget::GetRenderWindow | ( | ) |
These methods have be deprecated to fix naming style.
Since QVTKOpenGLNativeWidget is QObject subclass, we follow Qt naming conventions rather than VTK's.
QVTKInteractor* QVTKOpenGLNativeWidget::GetInteractor | ( | ) |
QVTKInteractorAdapter* QVTKOpenGLNativeWidget::GetInteractorAdapter | ( | ) |
Hence the API was removed.
void QVTKOpenGLNativeWidget::setQVTKCursor | ( | const QCursor & | cursor | ) |
Simply use QWidget::setCursor
API to change cursor.
void QVTKOpenGLNativeWidget::setDefaultQVTKCursor | ( | const QCursor & | cursor | ) |
Use setDefaultCursor
instead.
|
protectedvirtualslot |
Called as a response to QOpenGLContext::aboutToBeDestroyed
.
This may be called anytime during the widget lifecycle. We need to release any OpenGL resources allocated in VTK work in this method.
|
protectedslot |
|
overrideprotected |
|
overrideprotected |
|
overrideprotected |
|
protected |
Definition at line 235 of file QVTKOpenGLNativeWidget.h.
|
protected |
Definition at line 236 of file QVTKOpenGLNativeWidget.h.