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
Intermediate class that handles relaying Qt events to VTK.
QQuickItem subclass that manages the vtkRenderWindow and, in turn, the OpenGL context of the QML appl...
vtkNew< vtkWindowToImageFilter > m_screenshotFilter
virtual vtkSmartPointer< vtkImageData > captureScreenshot(double *viewport)
Capture a screenshot of the window.
QPointer< QQuickVTKInteractorAdapter > interactorAdapter() const
Get access to the interactor adapter.
vtkSmartPointer< vtkGenericOpenGLRenderWindow > m_renderWindow
~QQuickVTKRenderWindow()
Destructor.
virtual void mapToViewport(const QRectF &rect, double viewport[4])
Map a Qt item rect to viewport coordinates.
void setRenderWindow(vtkRenderWindow *renWin)
Set/Get the vtkRenderWindow for the view.
void setRenderWindow(vtkGenericOpenGLRenderWindow *renWin)
Set/Get the vtkRenderWindow for the view.
virtual vtkSmartPointer< vtkImageData > captureScreenshot()
Capture a screenshot of the window.
bool checkGraphicsBackend()
Check the scenegraph backend and graphics API being used.
virtual void render()
Schedule a scenegraph update.
virtual bool isInitialized() const
Get whether the render window is initialized Used internally to determine if the OpenGL context,...
QQuickVTKRenderWindow(QQuickItem *parent=nullptr)
Constructor Creates a QQuickVTKRenderWindow with:
virtual void handleWindowChanged(QQuickWindow *w)
vtkRenderWindow * renderWindow() const
Set/Get the vtkRenderWindow for the view.
virtual void sync()
This is the function called on the QtQuick render thread before the scenegraph state is synchronized.
virtual void cleanup()
This is the function called on the QtQuick render thread when the scenegraph is invalidated.
QPointer< QQuickVTKInteractorAdapter > m_interactorAdapter
virtual void init()
Initialize the VTK render window for OpenGL based on the context created by QtQuick.
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
static void setupGraphicsBackend()
Set up the graphics surface format and api.
virtual void renderNow()
Convenience method that schedules a scenegraph update and waits for the update.
vtkNew< vtkRenderer > m_dummyRenderer
virtual void paint()
This is the function called on the QtQuick render thread right before the scenegraph is rendered.
platform independent render window
topologically and geometrically regular array of data
Definition: vtkImageData.h:48
create a window for renderers to draw into
abstract specification for renderers
Definition: vtkRenderer.h:73
Use a vtkWindow as input to image pipeline.