NifTK  16.4.1 - 0798f20
CMIC's Translational Medical Imaging Platform
niftkVLWidget.h
Go to the documentation of this file.
1 /*=============================================================================
2 
3  NifTK: A software platform for medical image computing.
4 
5  Copyright (c) University College London (UCL). All rights reserved.
6 
7  This software is distributed WITHOUT ANY WARRANTY; without even
8  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9  PURPOSE.
10 
11  See LICENSE.txt in the top level directory for details.
12 
13 =============================================================================*/
14 
15 #ifndef niftkVLWidget_h
16 #define niftkVLWidget_h
17 
18 #include <QtGlobal>
19 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
20 #include <vlQt5/Qt5Widget.hpp>
21 #else
22 #include <vlQt4/Qt4Widget.hpp>
23 #endif
24 
25 #include <niftkVLExports.h>
26 #include <niftkVLMapper.h>
27 #include <niftkVLSceneView.h>
28 
29 namespace niftk
30 {
31 
32 class VLSceneView;
33 
47 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
48 class NIFTKVL_EXPORT VLWidget : public vlQt5::Qt5Widget {
49 public:
50  VLWidget(QWidget* parent = NULL, const QGLWidget* shareWidget = NULL, Qt::WindowFlags f = 0)
51  : Qt5Widget(parent, shareWidget, f) {
52 #else
53 class NIFTKVL_EXPORT VLWidget : public vlQt4::Qt4Widget {
54 public:
55  VLWidget(QWidget* parent = NULL, const QGLWidget* shareWidget = NULL, Qt::WindowFlags f = 0)
56  : Qt4Widget(parent, shareWidget, f) {
57 #endif
58  m_VLSceneView = new VLSceneView( this );
59  addEventListener(m_VLSceneView.get());
60  setRefreshRate(1000 / 30); // 30 fps in milliseconds
61  setContinuousUpdate(false);
62  setMouseTracking(true);
63  setAutoBufferSwap(false);
64  setAcceptDrops(false);
65 
66  // Explicitly request OpenGL 3.2 Compatibility profile.
67  QGLContext* glctx = new QGLContext(this->context()->format(), this);
68  QGLFormat fmt = this->context()->format();
69  fmt.setDoubleBuffer( true );
70  #if QT_VERSION >= 0x040700
71  fmt.setProfile(QGLFormat::CompatibilityProfile);
72  fmt.setVersion(3, 2);
73  #endif
74  glctx->setFormat(fmt);
75  glctx->create(NULL);
76  this->setContext(glctx);
77  makeCurrent();
78  MITK_INFO << "niftk::VLWidget: created OpenGL context version: " << glGetString(GL_VERSION) << "\n";
79  }
80 
81  VLSceneView* vlSceneView() { return m_VLSceneView.get(); }
82 
83  const VLSceneView* vlSceneView() const { return m_VLSceneView.get(); }
84 
85  bool contextIsCurrent() { return QGLContext::currentContext() == QGLWidget::context(); }
86 
87 protected:
88  vl::ref<VLSceneView> m_VLSceneView;
89 };
90 
91 }
92 
93 #endif
vl::ref< VLSceneView > m_VLSceneView
Definition: niftkVLWidget.h:88
bool contextIsCurrent()
Definition: niftkVLWidget.h:85
A vl::UIEventListener bound to a QGLWidget (niftk::VLWidget) managing all VL/Vivid rendering and opti...
Definition: niftkVLSceneView.h:70
VLSceneView * vlSceneView()
Definition: niftkVLWidget.h:81
VLWidget(QWidget *parent=NULL, const QGLWidget *shareWidget=NULL, Qt::WindowFlags f=0)
Definition: niftkVLWidget.h:50
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: glew.h:1238
A QGLWidget containing a niftk::VLSceneView.
Definition: niftkVLWidget.h:48
GLAPI const GLubyte *GLAPIENTRY glGetString(GLenum name)
#define GL_VERSION
Definition: glew.h:688
Definition: niftkExceptionObject.h:21
const VLSceneView * vlSceneView() const
Definition: niftkVLWidget.h:83
GLclampf f
Definition: glew.h:3136