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());
130  ~QVTKOpenGLNativeWidget() override;
131 
133 
138  void SetRenderWindow(vtkGenericOpenGLRenderWindow* win);
139  void SetRenderWindow(vtkRenderWindow* win);
140  virtual vtkRenderWindow* GetRenderWindow();
142 
146  virtual QVTKInteractorAdapter* GetInteractorAdapter() { return this->InteractorAdapter; }
147 
151  virtual QVTKInteractor* GetInteractor();
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:
258 
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;
277  friend class QVTKOpenGLNativeWidgetObserver;
278  QOpenGLDebugLogger* Logger;
279 };
280 
281 #endif
vtkSmartPointer< vtkGenericOpenGLRenderWindow > RenderWindow
virtual QVTKInteractorAdapter * GetInteractorAdapter()
Get the QEvent to VTK events translator.
abstract base class for most VTK objects
Definition: vtkObject.h:59
static const double DevicePixelRatioTolerance
an interactor for QVTKOpenGLNativeWidget (and QVTKWiget).
QOpenGLWidget subclass to house a vtkGenericOpenGLRenderWindow in a Qt application.
platform independent render window
create a window for renderers to draw into
QVTKInteractorAdapter * InteractorAdapter