Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
24 changes: 23 additions & 1 deletion src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -74,8 +95,9 @@ set(srcs
${ui_srcs}
${resource_srcs}

ddLumberSelection.cpp
QVTKOpenGLInit.cpp
ddGLWidgetView.cpp
ddLumberSelection.cpp
ddMacrosManager.cpp
ddMainWindow.cpp
ddObjectTree.cpp
Expand Down
25 changes: 25 additions & 0 deletions src/app/QVTKOpenGLInit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "QVTKOpenGLInit.h"

// Qt includes
#include <QtGlobal>

// VTK includes
#include <vtkVersionMacros.h>
#include <vtkRenderingOpenGLConfigure.h>

#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) && VTK_MAJOR_VERSION >= 8
# ifdef VTK_OPENGL2
#include <QSurfaceFormat>
#include <QVTKOpenGLWidget.h>
# 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
}
35 changes: 35 additions & 0 deletions src/app/QVTKOpenGLInit.h
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions src/app/consoleApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
#include <PythonQt.h>
#include <QApplication>
#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());
Expand Down
22 changes: 22 additions & 0 deletions src/app/ddQVTKOpenGLWidgetConfigure.h.in
Original file line number Diff line number Diff line change
@@ -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 <QVTKWidget.h>
using QVTKOpenGLWidget = QVTKWidget;
#else
#include <QVTKOpenGLWidget.h>
#endif

#endif
53 changes: 30 additions & 23 deletions src/app/ddQVTKWidgetView.cpp
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
#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>

//-----------------------------------------------------------------------------
class vtkCustomRubberBandStyle : public vtkInteractorStyleRubberBand3D
Expand All @@ -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);
}
Expand All @@ -69,7 +69,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 +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<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 +199,7 @@ vtkLightKit* ddQVTKWidgetView::lightKit() const
}

//-----------------------------------------------------------------------------
QVTKWidget* ddQVTKWidgetView::vtkWidget() const
QVTKOpenGLWidget* ddQVTKWidgetView::vtkWidget() const
{
return this->Internal->VTKWidget;
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/ddQVTKWidgetView.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

#include "ddViewBase.h"
#include "ddAppConfigure.h"
#include "ddQVTKOpenGLWidgetConfigure.h"


class vtkCamera;
class vtkOrientationMarkerWidget;
class vtkRenderer;
class vtkRenderWindow;
class vtkLightKit;
class QVTKWidget;

class DD_APP_EXPORT ddQVTKWidgetView : public ddViewBase
{
Expand All @@ -29,7 +29,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
7 changes: 6 additions & 1 deletion src/app/drakeVisualizerApp.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#include <PythonQt.h>
// Qt includes
#include <QApplication>

// director includes
#include <PythonQt.h>
#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());
Expand Down
2 changes: 2 additions & 0 deletions src/app/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <QApplication>
#include "ddMainWindow.h"
#include "ddPythonManager.h"
#include "QVTKOpenGLInit.h"

#define USE_TDX 0
#if USE_TDX
Expand All @@ -9,6 +10,7 @@

int main(int argc, char **argv)
{
QVTKOpenGLInit init;
#if USE_TDX
QVTKApplication app(argc, argv);
#else
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