Skip to content

Commit

Permalink
Integrate VTK 8 OpenGL2 backend and use QVTKOpenGLWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
sankhesh committed Jun 28, 2017
1 parent 4109097 commit dd4ee5d
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 29 deletions.
4 changes: 2 additions & 2 deletions distro/superbuild/cmake/externals.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -367,15 +367,15 @@ 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}
${qt_args}
-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
Expand Down
11 changes: 11 additions & 0 deletions src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,19 @@ include_directories(${PYTHON_INCLUDE_DIRS})

set(decorator_file ${CMAKE_CURRENT_BINARY_DIR}/ddPythonQtDecorators.h)

if(DD_QT_VERSION EQUAL 4)
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
Expand Down
59 changes: 36 additions & 23 deletions src/app/ddQVTKWidgetView.cpp
Original file line number Diff line number Diff line change
@@ -1,33 +1,39 @@
#include "ddQVTKWidgetView.h"
#include "ddFPSCounter.h"

#include "vtkTDxInteractorStyleCallback.h"
#include "vtkSimpleActorInteractor.h"
#include "vtkTDxInteractorStyleCallback.h"

#include <vtkActor.h>
#include <vtkAxesActor.h>
#include <vtkBoundingBox.h>
#include <vtkSmartPointer.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkCaptionActor2D.h>
#include <vtkConeSource.h>
#include <vtkEventQtSlotConnect.h>
#include <vtkGenericOpenGLRenderWindow.h>
#include <vtkInteractorStyle.h>
#include <vtkInteractorStyleRubberBand3D.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkLight.h>
#include <vtkLightKit.h>
#include <vtkLightCollection.h>
#include <vtkLightKit.h>
#include <vtkObjectFactory.h>
#include <vtkActor.h>
#include <vtkPolyDataMapper.h>
#include <vtkConeSource.h>
#include <vtkOrientationMarkerWidget.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkInteractorStyleRubberBand3D.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkAxesActor.h>
#include <vtkEventQtSlotConnect.h>
#include <vtkCaptionActor2D.h>
#include <vtkRenderer.h>
#include <vtkSmartPointer.h>
#include <vtkTextProperty.h>

#include <QVTKWidget.h>
#include <QVBoxLayout>
#include <QTimer>
#include <QVBoxLayout>

#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
#include <QVTKOpenGLWidget.h>
#else
#include <QVTKWidget.h>
#endif

//-----------------------------------------------------------------------------
class vtkCustomRubberBandStyle : public vtkInteractorStyleRubberBand3D
Expand All @@ -43,7 +49,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);
}
Expand All @@ -69,7 +75,7 @@ class ddQVTKWidgetView::ddInternal
this->RenderTimer.setInterval(1000/timerFramesPerSeconds);
}

QVTKWidget* VTKWidget;
QVTKOpenGLWidget* VTKWidget;

vtkSmartPointer<vtkRenderer> Renderer;
vtkSmartPointer<vtkRenderer> RendererBase;
Expand Down Expand Up @@ -98,25 +104,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<vtkGenericOpenGLRenderWindow>::New();
#else
this->Internal->VTKWidget->SetUseTDx(true);

this->Internal->RenderWindow = vtkSmartPointer<vtkRenderWindow>::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<vtkLightKit>::New();
this->Internal->LightKit->SetKeyLightWarmth(0.5);
this->Internal->LightKit->SetFillLightWarmth(0.5);

this->Internal->TDxInteractor = vtkSmartPointer<vtkTDxInteractorStyleCallback>::New();
vtkInteractorStyle::SafeDownCast(this->Internal->RenderWindow->GetInteractor()->GetInteractorStyle())->SetTDxStyle(this->Internal->TDxInteractor);
this->Internal->TDxInteractor =
vtkSmartPointer<vtkTDxInteractorStyleCallback>::New();
vtkInteractorStyle::SafeDownCast(this->Internal->RenderWindow->GetInteractor(
)->GetInteractorStyle())->SetTDxStyle(this->Internal->TDxInteractor);

//this->Internal->RenderWindow->SetNumberOfLayers(2);

Expand Down Expand Up @@ -192,7 +205,7 @@ vtkLightKit* ddQVTKWidgetView::lightKit() const
}

//-----------------------------------------------------------------------------
QVTKWidget* ddQVTKWidgetView::vtkWidget() const
QVTKOpenGLWidget* ddQVTKWidgetView::vtkWidget() const
{
return this->Internal->VTKWidget;
}
Expand Down
9 changes: 7 additions & 2 deletions src/app/ddQVTKWidgetView.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ class vtkOrientationMarkerWidget;
class vtkRenderer;
class vtkRenderWindow;
class vtkLightKit;
class QVTKWidget;
#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
class QVTKOpenGLWidget;
#else
class QVTKWidget;
using QVTKOpenGLWidget = QVTKWidget;
#endif

class DD_APP_EXPORT ddQVTKWidgetView : public ddViewBase
{
Expand All @@ -29,7 +34,7 @@ class DD_APP_EXPORT ddQVTKWidgetView : public ddViewBase

QList<double> lastTDxMotion() const;

QVTKWidget* vtkWidget() const;
QVTKOpenGLWidget* vtkWidget() const;
vtkOrientationMarkerWidget* orientationMarkerWidget() const;

void installImageInteractor();
Expand Down
15 changes: 14 additions & 1 deletion src/app/drakeVisualizerApp.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
#include <PythonQt.h>
// Qt includes
#include <QApplication>

// director includes
#include <PythonQt.h>
#include "ddPythonManager.h"

// VTK includes
#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
#include <QSurfaceFormat>
#include <QVTKOpenGLWidget.h>
#endif

int main(int argc, char **argv)
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
// Set the default surface format for the OpenGL view
QSurfaceFormat::setDefaultFormat(QVTKOpenGLWidget::defaultFormat());
#endif
QApplication app(argc, argv);
ddPythonManager* pythonManager = new ddPythonManager;
pythonManager->setSysArgv(QApplication::instance()->arguments());
Expand Down
1 change: 0 additions & 1 deletion src/app/wrapped_methods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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<double> ddQVTKWidgetView::lastTDxMotion() const;
void ddQVTKWidgetView::installImageInteractor();
Expand Down

0 comments on commit dd4ee5d

Please sign in to comment.