VTK  9.1.0
QQuickVTKRenderWindow.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: QQuickVTKRenderWindow.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
116 #ifndef QQuickVTKRenderWindow_h
117 #define QQuickVTKRenderWindow_h
118 
119 // vtk includes
120 #include "vtkSmartPointer.h" // For vtkSmartPointer
121 
122 // Qt includes
123 #include <QOpenGLFunctions> // For QOpenGLFunctions
124 #include <QPointer> // For QPointer
125 #include <QQuickItem>
126 
127 #include "vtkGUISupportQtQuickModule.h" // for export macro
128 
129 // Forward declarations
130 class QEvent;
132 class QQuickWindow;
133 class QWheelEvent;
135 class vtkImageData;
136 class vtkRenderWindow;
137 class vtkRenderer;
139 
140 class VTKGUISUPPORTQTQUICK_EXPORT QQuickVTKRenderWindow
141  : public QQuickItem
142  , protected QOpenGLFunctions
143 {
144  Q_OBJECT
145  typedef QQuickItem Superclass;
146 
147 public:
154  QQuickVTKRenderWindow(QQuickItem* parent = nullptr);
155 
160 
169  static void setupGraphicsBackend();
170 
172 
185 
189  virtual void mapToViewport(const QRectF& rect, double viewport[4]);
190 
194  QPointer<QQuickVTKInteractorAdapter> interactorAdapter() const;
195 
197 
207 
213  virtual bool isInitialized() const;
214 
215 public Q_SLOTS:
224  virtual void sync();
225 
232  virtual void init();
233 
242  virtual void paint();
243 
248  virtual void cleanup();
249 
254  virtual void renderNow();
255 
263  virtual void render();
264 
265 protected Q_SLOTS:
266  virtual void handleWindowChanged(QQuickWindow* w);
267 
268 protected:
269  QPointer<QQuickVTKInteractorAdapter> m_interactorAdapter;
271  bool m_initialized = false;
272 
273  // Screenshot stuff
274  bool m_screenshotScheduled = false;
277 
278  // Event handlers
279 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
280  void geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry) override;
281 #else
282  void geometryChange(const QRectF& newGeometry, const QRectF& oldGeometry) override;
283 #endif
284 
289 
290 private:
292  void operator=(const QQuickVTKRenderWindow) = delete;
293 };
294 
295 #endif // QQuickVTKRenderWindow_h
QQuickVTKRenderWindow::m_renderWindow
vtkSmartPointer< vtkGenericOpenGLRenderWindow > m_renderWindow
Definition: QQuickVTKRenderWindow.h:270
QQuickVTKRenderWindow::render
virtual void render()
Schedule a scenegraph update.
QQuickVTKRenderWindow::renderWindow
vtkRenderWindow * renderWindow() const
Set/Get the vtkRenderWindow for the view.
QQuickVTKRenderWindow::~QQuickVTKRenderWindow
~QQuickVTKRenderWindow()
Destructor.
QQuickVTKRenderWindow::cleanup
virtual void cleanup()
This is the function called on the QtQuick render thread when the scenegraph is invalidated.
QQuickVTKRenderWindow::QQuickVTKRenderWindow
QQuickVTKRenderWindow(QQuickItem *parent=nullptr)
Constructor Creates a QQuickVTKRenderWindow with:
QQuickVTKRenderWindow::isInitialized
virtual bool isInitialized() const
Get whether the render window is initialized Used internally to determine if the OpenGL context,...
QQuickVTKRenderWindow::sync
virtual void sync()
This is the function called on the QtQuick render thread before the scenegraph state is synchronized.
QQuickVTKRenderWindow::setRenderWindow
void setRenderWindow(vtkGenericOpenGLRenderWindow *renWin)
Set/Get the vtkRenderWindow for the view.
vtkWindowToImageFilter
Use a vtkWindow as input to image pipeline.
Definition: vtkWindowToImageFilter.h:181
vtkGenericOpenGLRenderWindow
platform independent render window
Definition: vtkGenericOpenGLRenderWindow.h:122
vtkSmartPointer< vtkImageData >
QQuickVTKRenderWindow::mapToViewport
virtual void mapToViewport(const QRectF &rect, double viewport[4])
Map a Qt item rect to viewport coordinates.
QQuickVTKInteractorAdapter
Intermediate class that handles relaying Qt events to VTK.
Definition: QQuickVTKInteractorAdapter.h:44
QQuickVTKRenderWindow::interactorAdapter
QPointer< QQuickVTKInteractorAdapter > interactorAdapter() const
Get access to the interactor adapter.
QQuickVTKRenderWindow::captureScreenshot
virtual vtkSmartPointer< vtkImageData > captureScreenshot(double *viewport)
Capture a screenshot of the window.
QQuickVTKRenderWindow::geometryChange
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
QQuickVTKRenderWindow
QQuickItem subclass that manages the vtkRenderWindow and, in turn, the OpenGL context of the QML appl...
Definition: QQuickVTKRenderWindow.h:143
QQuickVTKRenderWindow::handleWindowChanged
virtual void handleWindowChanged(QQuickWindow *w)
QQuickVTKRenderWindow::checkGraphicsBackend
bool checkGraphicsBackend()
Check the scenegraph backend and graphics API being used.
vtkImageData
topologically and geometrically regular array of data
Definition: vtkImageData.h:157
QQuickVTKRenderWindow::m_interactorAdapter
QPointer< QQuickVTKInteractorAdapter > m_interactorAdapter
Definition: QQuickVTKRenderWindow.h:269
vtkSmartPointer.h
vtkNew< vtkWindowToImageFilter >
QQuickVTKRenderWindow::captureScreenshot
virtual vtkSmartPointer< vtkImageData > captureScreenshot()
Capture a screenshot of the window.
QQuickVTKRenderWindow::renderNow
virtual void renderNow()
Convenience method that schedules a scenegraph update and waits for the update.
QQuickVTKRenderWindow::m_dummyRenderer
vtkNew< vtkRenderer > m_dummyRenderer
Definition: QQuickVTKRenderWindow.h:276
QQuickVTKRenderWindow::paint
virtual void paint()
This is the function called on the QtQuick render thread right before the scenegraph is rendered.
vtkRenderer
abstract specification for renderers
Definition: vtkRenderer.h:182
QQuickVTKRenderWindow::init
virtual void init()
Initialize the VTK render window for OpenGL based on the context created by QtQuick.
vtkRenderWindow
create a window for renderers to draw into
Definition: vtkRenderWindow.h:205
QQuickVTKRenderWindow::m_screenshotFilter
vtkNew< vtkWindowToImageFilter > m_screenshotFilter
Definition: QQuickVTKRenderWindow.h:275
QQuickVTKRenderWindow::setupGraphicsBackend
static void setupGraphicsBackend()
Set up the graphics surface format and api.
QQuickVTKRenderWindow::setRenderWindow
void setRenderWindow(vtkRenderWindow *renWin)
Set/Get the vtkRenderWindow for the view.