Vtk9 support (#722)

* Fixed build with VTK9

* Fixed VTK9 build with OctoMap dependency (vtkRenderingVolumeOpenGL2 missing)
This commit is contained in:
matlabbe
2021-05-15 19:43:47 -04:00
committed by GitHub
parent 8c336e1e39
commit e9d7fcd7ae
3 changed files with 86 additions and 22 deletions
+26 -14
View File
@@ -301,11 +301,15 @@ IF(WITH_QT)
IF("${VTK_MAJOR_VERSION}" EQUAL 5)
FIND_PACKAGE(QVTK REQUIRED) # only for VTK 5
ELSE()
list(FIND PCL_LIBRARIES vtkGUISupportQt value)
IF(value EQUAL -1)
SET(PCL_LIBRARIES "${PCL_LIBRARIES};vtkGUISupportQt")
SET(ADD_VTK_GUI_SUPPORT_QT_TO_CONF TRUE)
ENDIF(value EQUAL -1)
list(FIND PCL_LIBRARIES VTK::GUISupportQt value)
IF(value EQUAL -1)
list(FIND PCL_LIBRARIES vtkGUISupportQt value)
IF(value EQUAL -1)
SET(PCL_LIBRARIES "${PCL_LIBRARIES};vtkGUISupportQt")
SET(ADD_VTK_GUI_SUPPORT_QT_TO_CONF TRUE)
ENDIF(value EQUAL -1)
ENDIF(value EQUAL -1)
MESSAGE(STATUS "VTK_RENDERING_BACKEND=${VTK_RENDERING_BACKEND}")
IF(VTK_RENDERING_BACKEND STREQUAL "OpenGL2")
@@ -321,6 +325,14 @@ IF(WITH_QT)
IF(value EQUAL -1)
SET(PCL_LIBRARIES "${PCL_LIBRARIES};vtkRenderingVolumeOpenGL")
ENDIF(value EQUAL -1)
ELSEIF("${VTK_MAJOR_VERSION}" EQUAL 9)
list(FIND PCL_LIBRARIES VTK::RenderingOpenGL2 value)
IF(NOT value EQUAL -1)
list(FIND PCL_LIBRARIES VTK::RenderingVolumeOpenGL2 value)
IF(value EQUAL -1)
SET(PCL_LIBRARIES "${PCL_LIBRARIES};VTK::RenderingVolumeOpenGL2")
ENDIF(value EQUAL -1)
ENDIF(NOT value EQUAL -1)
ENDIF()
ENDIF()
@@ -412,16 +424,16 @@ IF(WITH_DC1394)
ENDIF(WITH_DC1394)
IF(WITH_G2O)
FIND_PACKAGE(G2O QUIET)
IF(G2O_FOUND)
MESSAGE(STATUS "Found g2o: ${G2O_INCLUDE_DIRS}")
FIND_PACKAGE(g2o QUIET NO_MODULE)
IF(g2o_FOUND)
MESSAGE(STATUS "Found g2o (targets)")
SET(G2O_FOUND ${g2o_FOUND})
SET(G2O_CPP11 1)
ELSE()
FIND_PACKAGE(g2o QUIET)
IF(g2o_FOUND)
SET(G2O_FOUND ${g2o_FOUND})
SET(G2O_CPP11 1)
MESSAGE(STATUS "Found g2o (targets)")
ENDIF(g2o_FOUND)
FIND_PACKAGE(G2O QUIET)
IF(G2O_FOUND)
MESSAGE(STATUS "Found g2o: ${G2O_INCLUDE_DIRS}")
ENDIF(G2O_FOUND)
ENDIF()
ENDIF(WITH_G2O)
+10 -1
View File
@@ -34,7 +34,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "rtabmap/core/StereoCameraModel.h"
#include "rtabmap/gui/CloudViewerInteractorStyle.h"
#if VTK_MAJOR_VERSION > 8
#ifndef slots
#define slots Q_SLOTS
#endif
#include <QVTKOpenGLNativeWidget.h>
using PCLQVTKWidget = QVTKOpenGLNativeWidget;
#else
#include <QVTKWidget.h>
using PCLQVTKWidget = QVTKWidget;
#endif
#include <pcl/pcl_base.h>
#include <pcl/point_types.h>
#include <pcl/point_cloud.h>
@@ -66,7 +75,7 @@ namespace rtabmap {
class OctoMap;
class RTABMAPGUI_EXP CloudViewer : public QVTKWidget
class RTABMAPGUI_EXP CloudViewer : public PCLQVTKWidget
{
Q_OBJECT
+50 -7
View File
@@ -81,6 +81,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <vtkOpenGLRenderer.h>
#endif
#if VTK_MAJOR_VERSION >= 8
#include <vtkGenericOpenGLRenderWindow.h>
#endif
#ifdef RTABMAP_OCTOMAP
#include <rtabmap/core/OctoMap.h>
#endif
@@ -88,7 +93,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace rtabmap {
CloudViewer::CloudViewer(QWidget *parent, CloudViewerInteractorStyle * style) :
QVTKWidget(parent),
PCLQVTKWidget(parent),
_aLockCamera(0),
_aFollowCamera(0),
_aResetCamera(0),
@@ -144,12 +149,26 @@ CloudViewer::CloudViewer(QWidget *parent, CloudViewerInteractorStyle * style) :
UASSERT(style!=0);
style->setCloudViewer(this);
style->AutoAdjustCameraClippingRangeOff();
#if VTK_MAJOR_VERSION > 8
auto renderer1 = vtkSmartPointer<vtkRenderer>::New();
auto renderWindow1 = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
renderWindow1->AddRenderer(renderer1);
_visualizer = new pcl::visualization::PCLVisualizer(
argc,
0,
renderer1,
renderWindow1,
"PCLVisualizer",
style,
false);
#else
_visualizer = new pcl::visualization::PCLVisualizer(
argc,
0,
"PCLVisualizer",
style,
false);
#endif
_visualizer->setShowFPS(false);
@@ -183,17 +202,29 @@ CloudViewer::CloudViewer(QWidget *parent, CloudViewerInteractorStyle * style) :
}
_visualizer->getRenderWindow()->SetNumberOfLayers(4);
#if VTK_MAJOR_VERSION > 8
this->setRenderWindow(_visualizer->getRenderWindow());
#else
this->SetRenderWindow(_visualizer->getRenderWindow());
#endif
// Replaced by the second line, to avoid a crash in Mac OS X on close, as well as
// the "Invalid drawable" warning when the view is not visible.
//_visualizer->setupInteractor(this->GetInteractor(), this->GetRenderWindow());
#if VTK_MAJOR_VERSION > 8
this->interactor()->SetInteractorStyle (_visualizer->getInteractorStyle());
#else
this->GetInteractor()->SetInteractorStyle (_visualizer->getInteractorStyle());
#endif
// setup a simple point picker
vtkSmartPointer<vtkPointPicker> pp = vtkSmartPointer<vtkPointPicker>::New ();
UDEBUG("pick tolerance=%f", pp->GetTolerance());
pp->SetTolerance (pp->GetTolerance()/2.0);
#if VTK_MAJOR_VERSION > 8
this->interactor()->SetPicker (pp);
#else
this->GetInteractor()->SetPicker (pp);
#endif
setRenderingRate(_renderingRate);
@@ -1254,7 +1285,7 @@ bool CloudViewer::addOctomap(const OctoMap * octomap, unsigned int treeDepth, bo
renderer->AddViewProp(volume);
// 3D texture mode. For coverage.
#if !defined(VTK_LEGACY_REMOVE) && !defined(VTK_OPENGL2)
#if !defined(VTK_LEGACY_REMOVE) && !defined(VTK_OPENGL2) && VTK_MAJOR_VERSION < 9
volumeMapper->SetRequestedRenderModeToRayCastAndTexture();
#endif // VTK_LEGACY_REMOVE
@@ -2587,14 +2618,22 @@ void CloudViewer::setPolygonPicking(bool enabled)
{
vtkSmartPointer<vtkPointPicker> pp = vtkSmartPointer<vtkPointPicker>::New ();
pp->SetTolerance (pp->GetTolerance());
#if VTK_MAJOR_VERSION > 8
this->interactor()->SetPicker (pp);
#else
this->GetInteractor()->SetPicker (pp);
#endif
setMouseTracking(false);
}
else
{
vtkSmartPointer<CloudViewerCellPicker> pp = vtkSmartPointer<CloudViewerCellPicker>::New ();
pp->SetTolerance (pp->GetTolerance());
#if VTK_MAJOR_VERSION > 8
this->interactor()->SetPicker (pp);
#else
this->GetInteractor()->SetPicker (pp);
#endif
setMouseTracking(true);
}
}
@@ -3120,7 +3159,11 @@ void CloudViewer::setCameraLockZ(bool enabled)
void CloudViewer::setCameraOrtho(bool enabled)
{
_lastCameraOrientation= _lastCameraPose = cv::Vec3f(0,0,0);
#if VTK_MAJOR_VERSION > 8
CloudViewerInteractorStyle * interactor = CloudViewerInteractorStyle::SafeDownCast(this->interactor()->GetInteractorStyle());
#else
CloudViewerInteractorStyle * interactor = CloudViewerInteractorStyle::SafeDownCast(this->GetInteractor()->GetInteractorStyle());
#endif
if(interactor)
{
interactor->setOrthoMode(enabled);
@@ -3425,7 +3468,7 @@ void CloudViewer::keyReleaseEvent(QKeyEvent * event) {
}
else
{
QVTKWidget::keyPressEvent(event);
PCLQVTKWidget::keyPressEvent(event);
}
}
@@ -3523,7 +3566,7 @@ void CloudViewer::keyPressEvent(QKeyEvent * event)
}
else
{
QVTKWidget::keyPressEvent(event);
PCLQVTKWidget::keyPressEvent(event);
}
}
@@ -3535,13 +3578,13 @@ void CloudViewer::mousePressEvent(QMouseEvent * event)
}
else
{
QVTKWidget::mousePressEvent(event);
PCLQVTKWidget::mousePressEvent(event);
}
}
void CloudViewer::mouseMoveEvent(QMouseEvent * event)
{
QVTKWidget::mouseMoveEvent(event);
PCLQVTKWidget::mouseMoveEvent(event);
std::vector<pcl::visualization::Camera> cameras;
_visualizer->getCameras(cameras);
@@ -3592,7 +3635,7 @@ void CloudViewer::mouseMoveEvent(QMouseEvent * event)
void CloudViewer::wheelEvent(QWheelEvent * event)
{
QVTKWidget::wheelEvent(event);
PCLQVTKWidget::wheelEvent(event);
std::vector<pcl::visualization::Camera> cameras;
_visualizer->getCameras(cameras);