Commit d279544a authored by Emmanuel Promayon's avatar Emmanuel Promayon
Browse files

NEW RendererWidget using non-native OpenGL viewer

tested on buster + VTK 8.2 (there is still a bug: missing automatic refresh
of the 3D viewers, to be investigated)
parent c6719363
......@@ -78,6 +78,7 @@
#include <vtkExtractSelectedFrustum.h>
#include <vtkPointData.h>
namespace camitk {
// ---------------------- singleton ----------------------------
/// the register containing all the viewers (static instantiation, global variable, but global only for this file)
......
......@@ -32,7 +32,7 @@
// // -- QT stuff
#include <QApplication>
#include <QKeyEvent>
// -- VTK stuff
// ---- Interactor
#include <vtkInteractorStyleTrackballCamera.h>
......@@ -90,8 +90,9 @@
// Extra classes are required for VTK8
#elif VTK_MAJOR_VERSION == 8
#include <QVTKOpenGLNativeWidget.h>
#include <QVTKOpenGLWidget.h>
#include <vtkGenericOpenGLRenderWindow.h>
#include <QSurfaceFormat>
// On some OpenGL drivers (e.g. Mesa 13), the OpenGL context has to be requested before hand
//#include <QOpenGLContext>
......@@ -106,19 +107,32 @@ static void initialize() {
format.setProfile(QSurfaceFormat::CompatibilityProfile);
QSurfaceFormat::setDefaultFormat(format);
*/
// needed to ensure appropriate OpenGL context is created for VTK rendering.
QSurfaceFormat::setDefaultFormat(QVTKOpenGLNativeWidget::defaultFormat());
QSurfaceFormat::setDefaultFormat(QVTKOpenGLWidget::defaultFormat());
}
// recommended: disable multisampling for older version of OpenGL ES
// vtkOpenGLRenderWindow::SetGlobalMaximumNumberOfMultiSamples(0);
//
// auto defaultFormat = QVTKOpenGLWidget::defaultFormat();
// defaultFormat.setSamples(0);
// QSurfaceFormat::setDefaultFormat(defaultFormat);
//
// #ifdef Q_OS_OSX
// QCoreApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
// #endif
//
// QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
}
//
// QGLFormat glFormat;
// glFormat.setVersion(3, 2);
// glFormat.setProfile(QGLFormat::NoProfile);
// glFormat.setSampleBuffers(true);
// glFormat.setDefaultFormat(glFormat);
// glFormat.setSwapInterval(1);
//
//
// glFormat.setDepthBufferSize(8);
// glFormat.setSamples(8);
// glFormat.setAlphaBufferSize(8);
......@@ -128,7 +142,7 @@ static void initialize() {
// */
// /*
// auto window = windowHandle();
//
//
// if (window != nullptr) {
// QSurfaceFormat surfaceFormat = window->format();
// surfaceFormat.setDepthBufferSize(8);
......@@ -141,33 +155,33 @@ static void initialize() {
// else {
// qWarning("Can't set surface format: No associated QWindow");
// }
//
//
// const QGLContext *context = widget.context();
//
//
// glewExperimental = GL_TRUE;
// if (glewInit() != GLEW_OK) {
// qWarning("Failed to initialize GLEW\n");
// }
// */
//
//
// QSurfaceFormat surfaceFormat;
// surfaceFormat.setVersion(3,2);
// surfaceFormat.setDepthBufferSize(8);
// surfaceFormat.setSamples(8);
// surfaceFormat.setAlphaBufferSize(8);
// surfaceFormat.setStencilBufferSize(8);
//
//
// QOpenGLContext context;
// context.setFormat(surfaceFormat);
// context.create();
//
//
// qDebug() << "Context valid: " << context.isValid();
// qDebug() << "Really used OpenGl: " << context.format().majorVersion() << "." << context.format().minorVersion();
// qDebug() << "OpenGl information: VENDOR: " << (const char*)glGetString(GL_VENDOR);
// qDebug() << " RENDERDER: " << (const char*)glGetString(GL_RENDERER);
// qDebug() << " VERSION: " << (const char*)glGetString(GL_VERSION);
// qDebug() << " GLSL VERSION: " << (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION);
//
//
// }
Q_COREAPP_STARTUP_FUNCTION(initialize)
......@@ -187,7 +201,7 @@ RendererWidget::RendererWidget(QWidget* parent, ControlMode mode) : QVTKWidget2(
RendererWidget::RendererWidget(QWidget * parent, ControlMode mode) : QVTKWidget(parent) {
#elif VTK_MAJOR_VERSION == 8
RendererWidget::RendererWidget(QWidget * parent, ControlMode mode) : QVTKOpenGLNativeWidget(parent) {
RendererWidget::RendererWidget(QWidget * parent, ControlMode mode) : QVTKOpenGLWidget(parent) {
#else
#error "Invalid VTK version: not (yet) supported."
......@@ -290,38 +304,38 @@ RendererWidget::RendererWidget(QWidget * parent, ControlMode mode) : QVTKOpenGLN
// fmt.setStencilBufferSize(8);
// QSurfaceFormat::setDefaultFormat(fmt);
#elif VTK_MAJOR_VERSION == 8
/*
CAMITK_INFO_ALT("Initializing OpenGL Context...");*/
/*
auto window = windowHandle();
if (window != nullptr) {
QSurfaceFormat surfaceFormat = window->format();
surfaceFormat.setVersion(3,2);
surfaceFormat.setDepthBufferSize(8);
surfaceFormat.setSamples(8);
surfaceFormat.setAlphaBufferSize(8);
surfaceFormat.setStencilBufferSize(8);
//surfaceFormat.setStereo(1);
window->setFormat(surfaceFormat);
}
else {
CAMITK_WARNING("Can't set surface format: No associated QWindow");
}
*/
/*
QGLFormat glFormat;
glFormat.setVersion(3, 2);
glFormat.setProfile(QGLFormat::NoProfile);
glFormat.setSampleBuffers(true);
glFormat.setDefaultFormat(glFormat);
glFormat.setSwapInterval(1);
glFormat.setDepthBufferSize(8);
glFormat.setSamples(8);
glFormat.setAlphaBufferSize(8);
glFormat.setStencilBufferSize(8);
*/
/*
CAMITK_INFO_ALT("Initializing OpenGL Context...");*/
/*
auto window = windowHandle();
if (window != nullptr) {
QSurfaceFormat surfaceFormat = window->format();
surfaceFormat.setVersion(3,2);
surfaceFormat.setDepthBufferSize(8);
surfaceFormat.setSamples(8);
surfaceFormat.setAlphaBufferSize(8);
surfaceFormat.setStencilBufferSize(8);
//surfaceFormat.setStereo(1);
window->setFormat(surfaceFormat);
}
else {
CAMITK_WARNING("Can't set surface format: No associated QWindow");
}
*/
/*
QGLFormat glFormat;
glFormat.setVersion(3, 2);
glFormat.setProfile(QGLFormat::NoProfile);
glFormat.setSampleBuffers(true);
glFormat.setDefaultFormat(glFormat);
glFormat.setSwapInterval(1);
glFormat.setDepthBufferSize(8);
glFormat.setSamples(8);
glFormat.setAlphaBufferSize(8);
glFormat.setStencilBufferSize(8);
*/
/*QGLWidget widget(glFormat);
widget.makeCurrent();
*/
......@@ -348,63 +362,88 @@ RendererWidget::RendererWidget(QWidget * parent, ControlMode mode) : QVTKOpenGLN
qWarning("Failed to initialize GLEW\n");
}
*/
/*
QSurfaceFormat glSurfaceFormat;
glSurfaceFormat.setVersion(4,4);
glSurfaceFormat.setDepthBufferSize(8);
glSurfaceFormat.setSamples(8);
glSurfaceFormat.setAlphaBufferSize(8);
glSurfaceFormat.setStencilBufferSize(8);
glSurfaceFormat.setProfile(QSurfaceFormat::CompatibilityProfile);
QOpenGLContext context;
context.setFormat(glSurfaceFormat);
context.create();*/
/*
qDebug() << "Context valid: " << context.isValid();
qDebug() << "Really used OpenGl: " << context.format().majorVersion() << "." << context.format().minorVersion();
qDebug() << "OpenGl information: VENDOR: " << (const char*)glGetString(GL_VENDOR);
qDebug() << " RENDERDER: " << (const char*)glGetString(GL_RENDERER);
qDebug() << " VERSION: " << (const char*)glGetString(GL_VERSION);
qDebug() << " GLSL VERSION: " << (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION);
/*
QSurfaceFormat glSurfaceFormat;
glSurfaceFormat.setVersion(4,4);
glSurfaceFormat.setDepthBufferSize(8);
glSurfaceFormat.setSamples(8);
glSurfaceFormat.setAlphaBufferSize(8);
glSurfaceFormat.setStencilBufferSize(8);
glSurfaceFormat.setProfile(QSurfaceFormat::CompatibilityProfile);
QOpenGLContext context;
context.setFormat(glSurfaceFormat);
context.create();*/
/*
qDebug() << "Context valid: " << context.isValid();
qDebug() << "Really used OpenGl: " << context.format().majorVersion() << "." << context.format().minorVersion();
qDebug() << "OpenGl information: VENDOR: " << (const char*)glGetString(GL_VENDOR);
qDebug() << " RENDERDER: " << (const char*)glGetString(GL_RENDERER);
qDebug() << " VERSION: " << (const char*)glGetString(GL_VERSION);
qDebug() << " GLSL VERSION: " << (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION);
*/
/*
CAMITK_INFO("------------------------ OpenGL information -------------------------")
CAMITK_INFO("OpenGL Versions Supported: " + QString::number(QGLFormat::openGLVersionFlags()));
CAMITK_INFO("Context valid: " + QString::number(context.isValid()));
//CAMITK_TRACE("Direct rendering: " + context.format().directRendering())
CAMITK_INFO(QString("Context OpenGL Version: %1.%2").arg(context.format().majorVersion()).arg(context.format().minorVersion()));
CAMITK_INFO("Vendor: " + QString((const char*)glGetString(GL_VENDOR)));
CAMITK_INFO("Renderer: " + QString((const char*)glGetString(GL_RENDERER)));
CAMITK_INFO("Version: " + QString((const char*)glGetString(GL_VERSION)));
CAMITK_INFO("GLSL version: " + QString((const char*)glGetString(GL_SHADING_LANGUAGE_VERSION)));
CAMITK_INFO("---------------------------------------------------------------------\n");*/
/* // disable multisampling.
vtkOpenGLRenderWindow::SetGlobalMaximumNumberOfMultiSamples(0);
//QSurfaceFormat::setDefaultFormat(QVTKOpenGLWidget::defaultFormat());
auto defaultFormat = QVTKOpenGLWidget::defaultFormat();
defaultFormat.setSamples(0);
QSurfaceFormat::setDefaultFormat(defaultFormat);
*/
/*
CAMITK_INFO("------------------------ OpenGL information -------------------------")
CAMITK_INFO("OpenGL Versions Supported: " + QString::number(QGLFormat::openGLVersionFlags()));
CAMITK_INFO("Context valid: " + QString::number(context.isValid()));
//CAMITK_TRACE("Direct rendering: " + context.format().directRendering())
CAMITK_INFO(QString("Context OpenGL Version: %1.%2").arg(context.format().majorVersion()).arg(context.format().minorVersion()));
CAMITK_INFO("Vendor: " + QString((const char*)glGetString(GL_VENDOR)));
CAMITK_INFO("Renderer: " + QString((const char*)glGetString(GL_RENDERER)));
CAMITK_INFO("Version: " + QString((const char*)glGetString(GL_VERSION)));
CAMITK_INFO("GLSL version: " + QString((const char*)glGetString(GL_SHADING_LANGUAGE_VERSION)));
CAMITK_INFO("---------------------------------------------------------------------\n");*/
/* // disable multisampling.
vtkOpenGLRenderWindow::SetGlobalMaximumNumberOfMultiSamples(0);
//QSurfaceFormat::setDefaultFormat(QVTKOpenGLWidget::defaultFormat());
auto defaultFormat = QVTKOpenGLWidget::defaultFormat();
defaultFormat.setSamples(0);
QSurfaceFormat::setDefaultFormat(defaultFormat);
*/
/*
/*
#ifdef Q_OS_OSX
QCoreApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
QCoreApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
#endif
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
// create renderer
vtkSmartPointer<vtkGenericOpenGLRenderWindow> internalRenderWindow = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
internalRenderWindow->SetMultiSamples(0);
internalRenderWindow->SetAlphaBitPlanes(0);
// create renderer
vtkSmartPointer<vtkGenericOpenGLRenderWindow> internalRenderWindow = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
internalRenderWindow->SetMultiSamples(0);
internalRenderWindow->SetAlphaBitPlanes(0);
SetRenderWindow(internalRenderWindow);
*/
SetRenderWindow(internalRenderWindow);
*/
/*
vtkSmartPointer<vtkGenericOpenGLRenderWindow> internalRenderWindow = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
SetRenderWindow(internalRenderWindow);
*/
// disable multisampling.
//QSurfaceFormat::setDefaultFormat(QVTKOpenGLWidget::defaultFormat());
/*auto defaultFormat = QVTKOpenGLWidget::defaultFormat();
defaultFormat.setSamples(0);
setFormat(defaultFormat);
*/
// QSurfaceFormat::setDefaultFormat(defaultFormat);
/*
auto defaultFormat = QVTKOpenGLWidget::defaultFormat();
defaultFormat.setDepthBufferSize(8);
defaultFormat.setSamples(8);
defaultFormat.setAlphaBufferSize(8);
defaultFormat.setStencilBufferSize(8);
//surfaceFormat.setStereo(1);
setFormat(defaultFormat);
*/
// setFormat(QVTKOpenGLWidget::defaultFormat());
/*
vtkNew<vtkGenericOpenGLRenderWindow> initRenderWindow;
SetRenderWindow(initRenderWindow);
*/
#else
#error "Invalid VTK version: not (yet) supported."
#endif
......@@ -581,31 +620,31 @@ RendererWidget::RendererWidget(QWidget * parent, ControlMode mode) : QVTKOpenGLN
copyrightTextActor = nullptr;
/*
// -- text in background
vtkSmartPointer<vtkTextProperty> copyrightTextProp = vtkSmartPointer<vtkTextProperty>::New();
copyrightTextProp->ShallowCopy(axeXTextProp);
copyrightTextProp->SetFontSize(12);
copyrightTextProp->ShadowOn();
vtkSmartPointer<vtkTextMapper> copyrightTextMapper = vtkSmartPointer<vtkTextMapper>::New();
copyrightTextMapper->SetInput(" CamiTK\n(c) TIMC - IMAG");
copyrightTextMapper->GetTextProperty()->ShallowCopy(copyrightTextProp);
// copyrightTextMapper->SetConstrainedFontSize(viewport, targetWidth, targetHeight);
copyrightTextActor = vtkSmartPointer<vtkActor2D>::New();
copyrightTextActor->SetMapper(copyrightTextMapper);
copyrightTextActor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
// y ^
// |
// |
// (0,0) +-----------> x
copyrightTextActor->GetPositionCoordinate()->SetValue(0.85, 0.1);
// by default the copyright actor is there!
addProp(copyrightTextActor);
*/
/*
// -- text in background
vtkSmartPointer<vtkTextProperty> copyrightTextProp = vtkSmartPointer<vtkTextProperty>::New();
copyrightTextProp->ShallowCopy(axeXTextProp);
copyrightTextProp->SetFontSize(12);
copyrightTextProp->ShadowOn();
vtkSmartPointer<vtkTextMapper> copyrightTextMapper = vtkSmartPointer<vtkTextMapper>::New();
copyrightTextMapper->SetInput(" CamiTK\n(c) TIMC - IMAG");
copyrightTextMapper->GetTextProperty()->ShallowCopy(copyrightTextProp);
// copyrightTextMapper->SetConstrainedFontSize(viewport, targetWidth, targetHeight);
copyrightTextActor = vtkSmartPointer<vtkActor2D>::New();
copyrightTextActor->SetMapper(copyrightTextMapper);
copyrightTextActor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
// y ^
// |
// |
// (0,0) +-----------> x
copyrightTextActor->GetPositionCoordinate()->SetValue(0.85, 0.1);
// by default the copyright actor is there!
addProp(copyrightTextActor);
*/
//-- color scale widget
// create an inversed the lut
......@@ -1341,7 +1380,7 @@ void RendererWidget::mousePressEvent(QMouseEvent* event) {
QVTKWidget::mousePressEvent(event);
#elif VTK_MAJOR_VERSION == 8
QVTKOpenGLNativeWidget::mousePressEvent(event);
QVTKOpenGLWidget::mousePressEvent(event);
#else
#error "Invalid VTK version: not (yet) supported."
#endif
......@@ -1357,7 +1396,7 @@ void RendererWidget::mouseReleaseEvent(QMouseEvent* event) {
QVTKWidget::mouseReleaseEvent(event);
#elif VTK_MAJOR_VERSION == 8
QVTKOpenGLNativeWidget::mouseReleaseEvent(event);
QVTKOpenGLWidget::mouseReleaseEvent(event);
#else
#error "Invalid VTK version: not (yet) supported."
#endif
......@@ -1380,7 +1419,7 @@ void RendererWidget::mouseMoveEvent(QMouseEvent* event) {
QVTKWidget::mouseMoveEvent(event);
#elif VTK_MAJOR_VERSION == 8
QVTKOpenGLNativeWidget::mouseMoveEvent(event);
QVTKOpenGLWidget::mouseMoveEvent(event);
#else
#error "Invalid VTK version: not (yet) supported."
......
......@@ -35,6 +35,7 @@
// -- VTK stuff
#include <vtkVersion.h>
#include <QVTKInteractor.h>
#if VTK_MAJOR_VERSION == 6
#include <QVTKWidget2.h>
......@@ -46,7 +47,8 @@
#elif VTK_MAJOR_VERSION == 8
#include <QVTKOpenGLNativeWidget.h>
#include <QVTKOpenGLWidget.h>
#include <vtkSmartPointer.h>
#else
#error "Invalid VTK version: not (yet) supported."
......@@ -68,6 +70,8 @@ class vtkAxesActor;
class vtkAnnotatedCubeActor;
class vtkScalarBarWidget;
class vtkTextMapper;
class vtkAbstractPropPicker;
namespace camitk {
......@@ -98,7 +102,7 @@ class CAMITK_API RendererWidget : public QVTKWidget2 {
class CAMITK_API RendererWidget : public QVTKWidget {
#elif VTK_MAJOR_VERSION == 8
class CAMITK_API RendererWidget : public QVTKOpenGLNativeWidget {
class CAMITK_API RendererWidget : public QVTKOpenGLWidget {
#else
#error "Invalid VTK version: not (yet) supported."
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment