VTK
Public Member Functions | Static Public Member Functions | List of all members
QVTKRenderWindowAdapter Class Reference

Helper to manage Qt context and other OpenGL components. More...

#include <QVTKRenderWindowAdapter.h>

Inherits QObject.

Public Member Functions

 QVTKRenderWindowAdapter (QOpenGLContext *cntxt, vtkGenericOpenGLRenderWindow *window, QWindow *parent)
 Constructor that makes vtkGenericOpenGLRenderWindow ready for subsequent render requests i.e. More...
 
 QVTKRenderWindowAdapter (QOpenGLContext *cntxt, vtkGenericOpenGLRenderWindow *window, QWidget *parent)
 
 ~QVTKRenderWindowAdapter () override
 
QOpenGLContext * context () const
 Get the context to use for rendering. More...
 
void paint ()
 Call this method in paintGL to request a render. More...
 
void resize (int width, int height)
 Call this method to resize the render window. More...
 
bool blit (unsigned int targetId, int targetAttachement, const QRect &targetRect, bool left=true)
 Convenience methods to blit the results rendered in the internal FBO to a target. More...
 
bool blitLeftEye (unsigned int targetId, int targetAttachement, const QRect &targetRect)
 
bool blitRightEye (unsigned int targetId, int targetAttachement, const QRect &targetRect)
 
bool handleEvent (QEvent *evt)
 Process the event and return true if the event have been processed successfully. More...
 
void setDefaultCursor (const QCursor &cursor)
 Get/set the default cursor. More...
 
const QCursor & defaultCursor () const
 
void setEnableHiDPI (bool value)
 Enable/disable DPI scaling. More...
 
void setUnscaledDPI (int value)
 Set the unscaled DPI to use when scaling DPI. More...
 

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...
 

Detailed Description

Helper to manage Qt context and other OpenGL components.

QVTKRenderWindowAdapter is an internal class that is used by QVTKOpenGLNativeWidget and QVTKOpenGLWindow to manage the rendering using vtkGenericOpenGLRenderWindow within a OpenGL context created via Qt.

QVTKRenderWindowAdapter is expected to be recreated anytime the context changes. In the constructor, QVTKRenderWindowAdapter will mark the vtkGenericOpenGLRenderWindow ready for rendering and call OpenGL context initialization API (vtkOpenGLRenderWindow::OpenGLInitContext).

By observing events on vtkGenericOpenGLRenderWindow, QVTKRenderWindowAdapter can then support rendering to an internally created FBO via VTK's rendering calls. Making sure that the rendering results are shown on the screen is handled by QVTKOpenGLWindow or QVTKOpenGLNativeWidget.

Definition at line 50 of file QVTKRenderWindowAdapter.h.

Constructor & Destructor Documentation

◆ QVTKRenderWindowAdapter() [1/2]

QVTKRenderWindowAdapter::QVTKRenderWindowAdapter ( QOpenGLContext *  cntxt,
vtkGenericOpenGLRenderWindow window,
QWindow *  parent 
)

Constructor that makes vtkGenericOpenGLRenderWindow ready for subsequent render requests i.e.

calls vtkGenericOpenGLRenderWindow::SetReadyForRendering(true). This also calls vtkOpenGLRenderWindow::OpenGLInitContext to ensure that the OpenGL context is ready for VTK rendering.

◆ QVTKRenderWindowAdapter() [2/2]

QVTKRenderWindowAdapter::QVTKRenderWindowAdapter ( QOpenGLContext *  cntxt,
vtkGenericOpenGLRenderWindow window,
QWidget *  parent 
)

◆ ~QVTKRenderWindowAdapter()

QVTKRenderWindowAdapter::~QVTKRenderWindowAdapter ( )
override

Member Function Documentation

◆ defaultFormat()

static QSurfaceFormat QVTKRenderWindowAdapter::defaultFormat ( bool  stereo_capable = false)
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().

◆ context()

QOpenGLContext* QVTKRenderWindowAdapter::context ( ) const

Get the context to use for rendering.

◆ paint()

void QVTKRenderWindowAdapter::paint ( )

Call this method in paintGL to request a render.

This may trigger a vtkRenderWindow::Render if this class determines the buffers may be obsolete.

◆ resize()

void QVTKRenderWindowAdapter::resize ( int  width,
int  height 
)

Call this method to resize the render window.

This simply calls vtkRenderWindow::SetSize taking device pixel ratio into consideration. This doesn't cause a render or resize of the FBO. That happens on a subsequent render request.

Besides widget resize, this method should also be called in cases when the devicePixelRatio for the parent window (or widget) changes. This is necessary since the internal FBO's pixel size is computed by scaling the widget and height provided by the window's (or widget's) devicePixelRatio.

◆ blit()

bool QVTKRenderWindowAdapter::blit ( unsigned int  targetId,
int  targetAttachement,
const QRect &  targetRect,
bool  left = true 
)

Convenience methods to blit the results rendered in the internal FBO to a target.

◆ blitLeftEye()

bool QVTKRenderWindowAdapter::blitLeftEye ( unsigned int  targetId,
int  targetAttachement,
const QRect &  targetRect 
)
inline

Definition at line 128 of file QVTKRenderWindowAdapter.h.

◆ blitRightEye()

bool QVTKRenderWindowAdapter::blitRightEye ( unsigned int  targetId,
int  targetAttachement,
const QRect &  targetRect 
)
inline

Definition at line 132 of file QVTKRenderWindowAdapter.h.

◆ handleEvent()

bool QVTKRenderWindowAdapter::handleEvent ( QEvent *  evt)

Process the event and return true if the event have been processed successfully.

◆ setDefaultCursor()

void QVTKRenderWindowAdapter::setDefaultCursor ( const QCursor &  cursor)
inline

Get/set the default cursor.

Definition at line 148 of file QVTKRenderWindowAdapter.h.

◆ defaultCursor()

const QCursor& QVTKRenderWindowAdapter::defaultCursor ( ) const
inline

Definition at line 149 of file QVTKRenderWindowAdapter.h.

◆ setEnableHiDPI()

void QVTKRenderWindowAdapter::setEnableHiDPI ( bool  value)

Enable/disable DPI scaling.

When enabled call to resize (which must happen any time the devicePixelRatio, in addition to the size may change), will result in updating the DPI on the vtkGenericOpenGLRenderWindow as well. The DPI change only happens in resize to enable applications to temporarily change DPI on the vtkGenericOpenGLRenderWindow and request an explicit render seamlessly. In such a case, it's the applications responsibility to restore DPI value or the changed value will linger until the next resize happens.

◆ setUnscaledDPI()

void QVTKRenderWindowAdapter::setUnscaledDPI ( int  value)

Set the unscaled DPI to use when scaling DPI.

It defaults to 72, which is same as the hard-coded default in vtkWindow.


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