diff --git a/distro/superbuild/cmake/externals.cmake b/distro/superbuild/cmake/externals.cmake index f45688007..b2bffb711 100644 --- a/distro/superbuild/cmake/externals.cmake +++ b/distro/superbuild/cmake/externals.cmake @@ -367,7 +367,7 @@ else() ExternalProject_Add(vtk GIT_REPOSITORY git://vtk.org/VTK.git - GIT_TAG v7.1.1 + GIT_TAG v8.0.0 CMAKE_CACHE_ARGS ${default_cmake_args} ${python_args} @@ -375,7 +375,7 @@ else() -DBUILD_SHARED_LIBS:BOOL=ON -DBUILD_TESTING:BOOL=OFF -DBUILD_EXAMPLES:BOOL=OFF - -DVTK_RENDERING_BACKEND:STRING=OpenGL + -DVTK_RENDERING_BACKEND:STRING=OpenGL2 -DVTK_QT_VERSION:STRING=${DD_QT_VERSION} -DVTK_PYTHON_VERSION=2 -DModule_vtkGUISupportQt:BOOL=ON diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 62a831675..c535102a0 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -34,8 +34,29 @@ include_directories(${PYTHON_INCLUDE_DIRS}) set(decorator_file ${CMAKE_CURRENT_BINARY_DIR}/ddPythonQtDecorators.h) +# Configure whether to use the QVTKWidget or the QVTKOpenGLWidget +set(USE_QVTKWIDGET TRUE) +if((${Qt5Core_VERSION} VERSION_GREATER "5.4.0") AND + (NOT ${VTK_VERSION} VERSION_LESS "8.0.0") AND + (${VTK_RENDERING_BACKEND} STREQUAL "OpenGL2")) + set(USE_QVTKWIDGET FALSE) +endif() +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/ddQVTKOpenGLWidgetConfigure.h.in + ${CMAKE_CURRENT_BINARY_DIR}/ddQVTKOpenGLWidgetConfigure.h) + +if(USE_QVTKWIDGET) + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/wrapped_methods_qvtk.txt + "QVTKWidget* ddQVTKWidgetView::vtkWidget() const;" + ) +else() + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/wrapped_methods_qvtk.txt + "QVTKOpenGLWidget* ddQVTKWidgetView::vtkWidget() const;" + ) +endif() + set(wrap_files wrapped_methods.txt + ${CMAKE_CURRENT_BINARY_DIR}/wrapped_methods_qvtk.txt ) qt_wrap_cpp(moc_srcs @@ -74,8 +95,9 @@ set(srcs ${ui_srcs} ${resource_srcs} - ddLumberSelection.cpp + QVTKOpenGLInit.cpp ddGLWidgetView.cpp + ddLumberSelection.cpp ddMacrosManager.cpp ddMainWindow.cpp ddObjectTree.cpp diff --git a/src/app/QVTKOpenGLInit.cpp b/src/app/QVTKOpenGLInit.cpp new file mode 100644 index 000000000..ccea11ed1 --- /dev/null +++ b/src/app/QVTKOpenGLInit.cpp @@ -0,0 +1,25 @@ +#include "QVTKOpenGLInit.h" + +// Qt includes +#include + +// VTK includes +#include +#include + +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) && VTK_MAJOR_VERSION >= 8 +# ifdef VTK_OPENGL2 + #include + #include +# endif +#endif + +QVTKOpenGLInit::QVTKOpenGLInit() +{ +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) && VTK_MAJOR_VERSION >= 8 +# ifdef VTK_OPENGL2 + // Set the default surface format for the OpenGL view + QSurfaceFormat::setDefaultFormat(QVTKOpenGLWidget::defaultFormat()); +# endif +#endif +} diff --git a/src/app/QVTKOpenGLInit.h b/src/app/QVTKOpenGLInit.h new file mode 100644 index 000000000..1ea30f090 --- /dev/null +++ b/src/app/QVTKOpenGLInit.h @@ -0,0 +1,35 @@ +#ifndef __QVTKOpenGLInit_h +#define __QVTKOpenGLInit_h + +/* + * Initialization class that creates a valid QSurfaceFormat i.e. OpenGL context + * with the expected parameters for the QVTKOpenGLWidget. + * Typical use case is to construct the class before constructing a + * QApplication object in the main function. + * + * Typical usage for QVTKOpenGLInit is as follows: + * @code{.cpp} + * + * int main(int argc, char* argv[]) + * { + * // Initialize before constructing the QApplication + * QVTKOpenGLInit init; + * // Construct the QApplication + * QApplication app(argc, argv); + * // Show the application (that uses QVTKOpenGLWidget) + * app.exec(); + * return 0; + * } + * + * @endcode + */ + +#include "ddAppConfigure.h" + +class DD_APP_EXPORT QVTKOpenGLInit +{ +public: + QVTKOpenGLInit(); +}; + +#endif //__QVTKOpenGLInit_h diff --git a/src/app/consoleApp.cpp b/src/app/consoleApp.cpp index 030a4d475..c6e3f851c 100644 --- a/src/app/consoleApp.cpp +++ b/src/app/consoleApp.cpp @@ -2,9 +2,11 @@ #include #include #include "ddPythonManager.h" +#include "QVTKOpenGLInit.h" int main(int argc, char **argv) { + QVTKOpenGLInit init; QApplication app(argc, argv); ddPythonManager* pythonManager = new ddPythonManager; PythonQt::self()->addVariable(PythonQt::self()->importModule("sys"), "executable", QCoreApplication::applicationFilePath()); diff --git a/src/app/ddQVTKOpenGLWidgetConfigure.h.in b/src/app/ddQVTKOpenGLWidgetConfigure.h.in new file mode 100644 index 000000000..a49870c52 --- /dev/null +++ b/src/app/ddQVTKOpenGLWidgetConfigure.h.in @@ -0,0 +1,22 @@ +#ifndef __ddQVTKOpenGLWidgetConfigure_h +#define __ddQVTKOpenGLWidgetConfigure_h + +/* + * Including QVTKOpenGLWidgetConfigure.h before using QVTKOpenGLWidget + * would automatically decide whether to use the old QVTKWidget or the + * QVTKOpenGLWidget based on the Qt and VTK versions used. + * It typedefs QVTKWidget as QVTKOpenGLWidget if the + * former is used so that the application code can keep using + * QVTKOpenGLWidget. + */ + +#cmakedefine01 USE_QVTKWIDGET + +#if USE_QVTKWIDGET + #include + using QVTKOpenGLWidget = QVTKWidget; +#else + #include +#endif + +#endif diff --git a/src/app/ddQVTKWidgetView.cpp b/src/app/ddQVTKWidgetView.cpp index c1cc69225..2fbe41528 100644 --- a/src/app/ddQVTKWidgetView.cpp +++ b/src/app/ddQVTKWidgetView.cpp @@ -1,33 +1,33 @@ #include "ddQVTKWidgetView.h" #include "ddFPSCounter.h" -#include "vtkTDxInteractorStyleCallback.h" #include "vtkSimpleActorInteractor.h" +#include "vtkTDxInteractorStyleCallback.h" +#include +#include #include -#include -#include -#include +#include +#include +#include +#include #include +#include +#include #include -#include #include +#include #include -#include -#include -#include #include -#include -#include +#include +#include #include -#include -#include -#include +#include +#include #include -#include -#include #include +#include //----------------------------------------------------------------------------- class vtkCustomRubberBandStyle : public vtkInteractorStyleRubberBand3D @@ -43,7 +43,7 @@ class vtkCustomRubberBandStyle : public vtkInteractorStyleRubberBand3D { this->Interaction = ZOOMING; this->FindPokedRenderer( - this->Interactor->GetEventPosition()[0], + this->Interactor->GetEventPosition()[0], this->Interactor->GetEventPosition()[1]); this->InvokeEvent(vtkCommand::StartInteractionEvent); } @@ -69,7 +69,7 @@ class ddQVTKWidgetView::ddInternal this->RenderTimer.setInterval(1000/timerFramesPerSeconds); } - QVTKWidget* VTKWidget; + QVTKOpenGLWidget* VTKWidget; vtkSmartPointer Renderer; vtkSmartPointer RendererBase; @@ -98,25 +98,32 @@ ddQVTKWidgetView::ddQVTKWidgetView(QWidget* parent) : ddViewBase(parent) QVBoxLayout* layout = new QVBoxLayout(this); layout->setMargin(0); - this->Internal->VTKWidget = new QVTKWidget; + this->Internal->VTKWidget = new QVTKOpenGLWidget; layout->addWidget(this->Internal->VTKWidget); +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) + this->Internal->RenderWindow = + vtkSmartPointer::New(); +#else this->Internal->VTKWidget->SetUseTDx(true); - this->Internal->RenderWindow = vtkSmartPointer::New(); + this->Internal->VTKWidget->SetRenderWindow(this->Internal->RenderWindow); +#endif + this->Internal->VTKWidget->SetRenderWindow(this->Internal->RenderWindow); this->Internal->RenderWindow->SetMultiSamples(8); this->Internal->RenderWindow->StereoCapableWindowOn(); this->Internal->RenderWindow->SetStereoTypeToRedBlue(); this->Internal->RenderWindow->StereoRenderOff(); this->Internal->RenderWindow->StereoUpdate(); - this->Internal->VTKWidget->SetRenderWindow(this->Internal->RenderWindow); this->Internal->LightKit = vtkSmartPointer::New(); this->Internal->LightKit->SetKeyLightWarmth(0.5); this->Internal->LightKit->SetFillLightWarmth(0.5); - this->Internal->TDxInteractor = vtkSmartPointer::New(); - vtkInteractorStyle::SafeDownCast(this->Internal->RenderWindow->GetInteractor()->GetInteractorStyle())->SetTDxStyle(this->Internal->TDxInteractor); + this->Internal->TDxInteractor = + vtkSmartPointer::New(); + vtkInteractorStyle::SafeDownCast(this->Internal->RenderWindow->GetInteractor( + )->GetInteractorStyle())->SetTDxStyle(this->Internal->TDxInteractor); //this->Internal->RenderWindow->SetNumberOfLayers(2); @@ -192,7 +199,7 @@ vtkLightKit* ddQVTKWidgetView::lightKit() const } //----------------------------------------------------------------------------- -QVTKWidget* ddQVTKWidgetView::vtkWidget() const +QVTKOpenGLWidget* ddQVTKWidgetView::vtkWidget() const { return this->Internal->VTKWidget; } diff --git a/src/app/ddQVTKWidgetView.h b/src/app/ddQVTKWidgetView.h index d3da6642c..c5d18264e 100644 --- a/src/app/ddQVTKWidgetView.h +++ b/src/app/ddQVTKWidgetView.h @@ -3,6 +3,7 @@ #include "ddViewBase.h" #include "ddAppConfigure.h" +#include "ddQVTKOpenGLWidgetConfigure.h" class vtkCamera; @@ -10,7 +11,6 @@ class vtkOrientationMarkerWidget; class vtkRenderer; class vtkRenderWindow; class vtkLightKit; -class QVTKWidget; class DD_APP_EXPORT ddQVTKWidgetView : public ddViewBase { @@ -29,7 +29,7 @@ class DD_APP_EXPORT ddQVTKWidgetView : public ddViewBase QList lastTDxMotion() const; - QVTKWidget* vtkWidget() const; + QVTKOpenGLWidget* vtkWidget() const; vtkOrientationMarkerWidget* orientationMarkerWidget() const; void installImageInteractor(); diff --git a/src/app/drakeVisualizerApp.cpp b/src/app/drakeVisualizerApp.cpp index ede7d8074..c3a2f4475 100644 --- a/src/app/drakeVisualizerApp.cpp +++ b/src/app/drakeVisualizerApp.cpp @@ -1,9 +1,14 @@ -#include +// Qt includes #include + +// director includes +#include #include "ddPythonManager.h" +#include "QVTKOpenGLInit.h" int main(int argc, char **argv) { + QVTKOpenGLInit init; QApplication app(argc, argv); ddPythonManager* pythonManager = new ddPythonManager; pythonManager->setSysArgv(QApplication::instance()->arguments()); diff --git a/src/app/main.cpp b/src/app/main.cpp index 6226f12b7..c32a49ee4 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -1,6 +1,7 @@ #include #include "ddMainWindow.h" #include "ddPythonManager.h" +#include "QVTKOpenGLInit.h" #define USE_TDX 0 #if USE_TDX @@ -9,6 +10,7 @@ int main(int argc, char **argv) { + QVTKOpenGLInit init; #if USE_TDX QVTKApplication app(argc, argv); #else diff --git a/src/app/wrapped_methods.txt b/src/app/wrapped_methods.txt index 5a12057bd..925ce4bfd 100644 --- a/src/app/wrapped_methods.txt +++ b/src/app/wrapped_methods.txt @@ -9,7 +9,6 @@ vtkRenderWindow* ddQVTKWidgetView::renderWindow() const; vtkRenderer* ddQVTKWidgetView::renderer() const; vtkRenderer* ddQVTKWidgetView::backgroundRenderer() const; vtkLightKit* ddQVTKWidgetView::lightKit() const; -QVTKWidget* ddQVTKWidgetView::vtkWidget() const; vtkOrientationMarkerWidget* ddQVTKWidgetView::orientationMarkerWidget() const; QList ddQVTKWidgetView::lastTDxMotion() const; void ddQVTKWidgetView::installImageInteractor();