VTK
QVTKOpenGLNativeWidget.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: QVTKOpenGLNativeWidget.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 =========================================================================*/
107 #ifndef QVTKOpenGLNativeWidget_h
108 #define QVTKOpenGLNativeWidget_h
109 
110 #include <QOpenGLWidget>
111 
112 #include "QVTKInteractor.h" // needed for QVTKInteractor
113 #include "vtkGUISupportQtModule.h" // for export macro
114 #include "vtkNew.h" // needed for vtkNew
115 #include "vtkSmartPointer.h" // needed for vtkSmartPointer
116 
117 class QOpenGLDebugLogger;
118 class QOpenGLFramebufferObject;
119 class QVTKInteractor;
121 class QVTKOpenGLNativeWidgetObserver;
123 
124 class VTKGUISUPPORTQT_EXPORT QVTKOpenGLNativeWidget : public QOpenGLWidget
125 {
126  Q_OBJECT
127  typedef QOpenGLWidget Superclass;
128 public:
129  QVTKOpenGLNativeWidget(QWidget* parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags());
131 
133 
142 
146  virtual QVTKInteractorAdapter* GetInteractorAdapter() { return this->InteractorAdapter; }
147 
152 
156  static void copyFromFormat(const QSurfaceFormat& format, vtkRenderWindow* win);
157 
161  static void copyToFormat(vtkRenderWindow* win, QSurfaceFormat& format);
162 
168  static QSurfaceFormat defaultFormat();
169 
173  virtual void setEnableHiDPI(bool enable);
174  virtual bool enableHiDPI() { return this->EnableHiDPI; }
175 
179  void setQVTKCursor(const QCursor &cursor);
180 
181 signals:
185  void mouseEvent(QMouseEvent* event);
186 
187 protected slots:
193  virtual void cleanupContext();
194 
195 private slots:
199  void recreateFBO();
200 
205  void startEventCallback();
206 
211  void cursorChangedCallback(vtkObject* caller, unsigned long vtk_event,
212  void* client_data, void* call_data);
213 
214 protected:
215  bool event(QEvent* evt) Q_DECL_OVERRIDE;
216  void initializeGL() Q_DECL_OVERRIDE;
217  void resizeGL(int w, int h) Q_DECL_OVERRIDE;
218  void paintGL() Q_DECL_OVERRIDE;
219 
220  void mousePressEvent(QMouseEvent* event) Q_DECL_OVERRIDE;
221  void mouseMoveEvent(QMouseEvent* event) Q_DECL_OVERRIDE;
222  void mouseReleaseEvent(QMouseEvent* event) Q_DECL_OVERRIDE;
223  void mouseDoubleClickEvent(QMouseEvent* event) Q_DECL_OVERRIDE;
224 
231  void requireRenderWindowInitialization();
232 
253  virtual bool renderVTK();
254 
255 protected:
257  QVTKInteractorAdapter* InteractorAdapter;
258 
259  bool EnableHiDPI;
260  int OriginalDPI;
261 
262  static const double DevicePixelRatioTolerance;
263 
264 private:
265  Q_DISABLE_COPY(QVTKOpenGLNativeWidget);
266 
271  void windowFrameEventCallback();
272 
273  QOpenGLFramebufferObject* FBO;
274  bool InPaintGL;
275  bool DoVTKRenderInPaintGL;
276  vtkNew<QVTKOpenGLNativeWidgetObserver> Observer;
277  friend class QVTKOpenGLNativeWidgetObserver;
278  QOpenGLDebugLogger* Logger;
279 };
280 
281 #endif
QVTKOpenGLNativeWidget::enableHiDPI
virtual bool enableHiDPI()
Definition: QVTKOpenGLNativeWidget.h:174
QVTKOpenGLNativeWidget::copyToFormat
static void copyToFormat(vtkRenderWindow *win, QSurfaceFormat &format)
Using the vtkRenderWindow, setup QSurfaceFormat.
QVTKOpenGLNativeWidget::copyFromFormat
static void copyFromFormat(const QSurfaceFormat &format, vtkRenderWindow *win)
Sets up vtkRenderWindow ivars using QSurfaceFormat.
vtkGenericOpenGLRenderWindow
platform independent render window
Definition: vtkGenericOpenGLRenderWindow.h:41
vtkSmartPointer
Hold a reference to a vtkObjectBase instance.
Definition: vtkSmartPointer.h:37
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:60
QVTKOpenGLNativeWidget::cleanupContext
virtual void cleanupContext()
Called as a response to QOpenGLContext::aboutToBeDestroyed.
QVTKOpenGLNativeWidget::GetInteractorAdapter
virtual QVTKInteractorAdapter * GetInteractorAdapter()
Get the QEvent to VTK events translator.
Definition: QVTKOpenGLNativeWidget.h:146
QVTKOpenGLNativeWidget::~QVTKOpenGLNativeWidget
~QVTKOpenGLNativeWidget() override
QVTKInteractorAdapter
Definition: QVTKInteractorAdapter.h:51
QVTKOpenGLNativeWidget::setEnableHiDPI
virtual void setEnableHiDPI(bool enable)
Enable or disable support for HiDPI displays.
QVTKOpenGLNativeWidget::QVTKOpenGLNativeWidget
QVTKOpenGLNativeWidget(QWidget *parent=Q_NULLPTR, Qt::WindowFlags f=Qt::WindowFlags())
QVTKOpenGLNativeWidget::defaultFormat
static QSurfaceFormat defaultFormat()
Returns a typical QSurfaceFormat suitable for most applications using QVTKOpenGLNativeWidget.
vtkSmartPointer.h
vtkNew
Allocate and hold a VTK object.
Definition: vtkNew.h:59
QVTKOpenGLNativeWidget::SetRenderWindow
void SetRenderWindow(vtkGenericOpenGLRenderWindow *win)
Get/Set the currently used vtkGenericOpenGLRenderWindow.
QVTKOpenGLNativeWidget::GetInteractor
virtual QVTKInteractor * GetInteractor()
Get the QVTKInteractor that was either created by default or set by the user.
QVTKOpenGLNativeWidget::GetRenderWindow
virtual vtkRenderWindow * GetRenderWindow()
vtkNew.h
QVTKOpenGLNativeWidget::SetRenderWindow
void SetRenderWindow(vtkRenderWindow *win)
QVTKOpenGLNativeWidget
QOpenGLWidget subclass to house a vtkGenericOpenGLRenderWindow in a Qt application.
Definition: QVTKOpenGLNativeWidget.h:125
QVTKInteractor.h
QVTKOpenGLNativeWidget::initializeGL
void initializeGL() Q_DECL_OVERRIDE
vtkRenderWindow
create a window for renderers to draw into
Definition: vtkRenderWindow.h:88
QVTKOpenGLNativeWidget::setQVTKCursor
void setQVTKCursor(const QCursor &cursor)
Set the cursor on this widget.
QVTKInteractor
an interactor for QVTKOpenGLNativeWidget (and QVTKWiget).
Definition: QVTKInteractor.h:60
QVTKOpenGLNativeWidget::mouseEvent
void mouseEvent(QMouseEvent *event)
This signal will be emitted whenever a mouse event occurs within the QVTK window.
QVTKOpenGLNativeWidget::event
bool event(QEvent *evt) Q_DECL_OVERRIDE
h