Permalink
Browse files

Conditionally compile code that uses vtkVertexBufferObjectMapper

This mapper is a performance optimization that is only needed when
OpenGL backend is used. The modern OpenGL2 backend uses vertex buffer
objects transparently for us.
  • Loading branch information...
1 parent d0efc67 commit c50c65b042828cfa18765eef7876f896a40a6d1b @taketwo taketwo committed Feb 13, 2016
@@ -21,7 +21,10 @@
// PCL - visualziation
#include <pcl/visualization/common/common.h>
+
+#if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2
#include <pcl/visualization/vtk/vtkVertexBufferObjectMapper.h>
+#endif
// VTK
#include <vtkVersion.h>
@@ -251,11 +254,18 @@ OutofcoreCloud::render (vtkRenderer* renderer)
{
vtkSmartPointer<vtkActor> cloud_actor = vtkSmartPointer<vtkActor>::New ();
- vtkSmartPointer<vtkVertexBufferObjectMapper> mapper = vtkSmartPointer<vtkVertexBufferObjectMapper>::New ();
-
CloudDataCacheItem *cloud_data_cache_item = &cloud_data_cache.get(pcd_file);
+#if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2
+ vtkSmartPointer<vtkVertexBufferObjectMapper> mapper = vtkSmartPointer<vtkVertexBufferObjectMapper>::New ();
mapper->SetInput (cloud_data_cache_item->item);
+#else
+ vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New ();
+ // Usually we choose between SetInput and SetInputData based on VTK version. But OpenGL ≥ 2 automatically
+ // means VTK version is ≥ 6.3
+ mapper->SetInputData (cloud_data_cache_item->item);
+#endif
+
cloud_actor->SetMapper (mapper);
cloud_actor->GetProperty ()->SetColor (0.0, 0.0, 1.0);
cloud_actor->GetProperty ()->SetPointSize (1);
@@ -50,8 +50,6 @@ if(build)
src/common/float_image_utils.cpp
src/vtk/pcl_image_canvas_source_2d.cpp
src/vtk/pcl_context_item.cpp
- src/vtk/vtkVertexBufferObject.cxx
- src/vtk/vtkVertexBufferObjectMapper.cxx
src/vtk/vtkRenderWindowInteractorFix.cpp
)
if("${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}" VERSION_LESS "5.6")
@@ -67,6 +65,13 @@ if(build)
)
endif("${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}" VERSION_GREATER "5.6")
+ if(VTK_RENDERING_BACKEND_OPENGL_VERSION VERSION_LESS 2)
+ list(APPEND srcs
+ "src/vtk/vtkVertexBufferObject.cxx"
+ "src/vtk/vtkVertexBufferObjectMapper.cxx"
+ )
+ endif()
+
set(incs
"include/pcl/${SUBSYS_NAME}/eigen.h"
"include/pcl/${SUBSYS_NAME}/boost.h"
@@ -127,11 +132,16 @@ if(build)
set(vtk_incs
"include/pcl/${SUBSYS_NAME}/vtk/pcl_image_canvas_source_2d.h"
"include/pcl/${SUBSYS_NAME}/vtk/pcl_context_item.h"
- "include/pcl/${SUBSYS_NAME}/vtk/vtkVertexBufferObject.h"
"include/pcl/${SUBSYS_NAME}/vtk/vtkRenderWindowInteractorFix.h"
- "include/pcl/${SUBSYS_NAME}/vtk/vtkVertexBufferObjectMapper.h"
)
+ if(VTK_RENDERING_BACKEND_OPENGL_VERSION VERSION_LESS 2)
+ list(APPEND vtk_incs
+ "include/pcl/${SUBSYS_NAME}/vtk/vtkVertexBufferObject.h"
+ "include/pcl/${SUBSYS_NAME}/vtk/vtkVertexBufferObjectMapper.h"
+ )
+ endif()
+
# on apple, a workaround is used for the cocoa render window interactor
if(APPLE)
list(APPEND srcs
@@ -64,7 +64,9 @@
#include <vtkPointPicker.h>
#include <vtkAreaPicker.h>
+#if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2
#include <pcl/visualization/vtk/vtkVertexBufferObjectMapper.h>
+#endif
#define ORIENT_MODE 0
#define SELECT_MODE 1
@@ -660,6 +662,7 @@ pcl::visualization::PCLVisualizerInteractorStyle::OnKeyDown ()
data->SetPoints (points);
data->SetVerts (vertices);
// Modify the mapper
+#if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2
if (use_vbos_)
{
vtkVertexBufferObjectMapper* mapper = static_cast<vtkVertexBufferObjectMapper*>(act->actor->GetMapper ());
@@ -668,6 +671,7 @@ pcl::visualization::PCLVisualizerInteractorStyle::OnKeyDown ()
act->actor->SetMapper (mapper);
}
else
+#endif
{
vtkPolyDataMapper* mapper = static_cast<vtkPolyDataMapper*>(act->actor->GetMapper ());
#if VTK_MAJOR_VERSION < 6
@@ -704,6 +708,7 @@ pcl::visualization::PCLVisualizerInteractorStyle::OnKeyDown ()
vtkPolyData *data = static_cast<vtkPolyData*>(act->actor->GetMapper ()->GetInput ());
data->GetPointData ()->SetScalars (scalars);
// Modify the mapper
+#if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2
if (use_vbos_)
{
vtkVertexBufferObjectMapper* mapper = static_cast<vtkVertexBufferObjectMapper*>(act->actor->GetMapper ());
@@ -714,6 +719,7 @@ pcl::visualization::PCLVisualizerInteractorStyle::OnKeyDown ()
act->actor->SetMapper (mapper);
}
else
+#endif
{
vtkPolyDataMapper* mapper = static_cast<vtkPolyDataMapper*>(act->actor->GetMapper ());
mapper->SetScalarRange (minmax);
@@ -63,9 +63,12 @@
#include <vtkPointPicker.h>
#include <pcl/visualization/boost.h>
-#include <pcl/visualization/vtk/vtkVertexBufferObjectMapper.h>
#include <pcl/visualization/vtk/vtkRenderWindowInteractorFix.h>
+#if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2
+#include <pcl/visualization/vtk/vtkVertexBufferObjectMapper.h>
+#endif
+
#include <vtkPolyLine.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderWindow.h>
@@ -1079,6 +1082,7 @@ pcl::visualization::PCLVisualizer::createActorFromVTKDataSet (const vtkSmartPoin
if (!actor)
actor = vtkSmartPointer<vtkLODActor>::New ();
+#if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2
if (use_vbos_)
{
vtkSmartPointer<vtkVertexBufferObjectMapper> mapper = vtkSmartPointer<vtkVertexBufferObjectMapper>::New ();
@@ -1111,6 +1115,7 @@ pcl::visualization::PCLVisualizer::createActorFromVTKDataSet (const vtkSmartPoin
actor->SetMapper (mapper);
}
else
+#endif
{
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New ();
#if VTK_MAJOR_VERSION < 6
@@ -1157,6 +1162,7 @@ pcl::visualization::PCLVisualizer::createActorFromVTKDataSet (const vtkSmartPoin
if (!actor)
actor = vtkSmartPointer<vtkActor>::New ();
+#if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2
if (use_vbos_)
{
vtkSmartPointer<vtkVertexBufferObjectMapper> mapper = vtkSmartPointer<vtkVertexBufferObjectMapper>::New ();
@@ -1189,6 +1195,7 @@ pcl::visualization::PCLVisualizer::createActorFromVTKDataSet (const vtkSmartPoin
actor->SetMapper (mapper);
}
else
+#endif
{
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New ();
#if VTK_MAJOR_VERSION < 6
@@ -2771,6 +2778,7 @@ pcl::visualization::PCLVisualizer::updateColorHandlerIndex (const std::string &i
vtkPolyData *data = static_cast<vtkPolyData*>(am_it->second.actor->GetMapper ()->GetInput ());
data->GetPointData ()->SetScalars (scalars);
// Modify the mapper
+#if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2
if (use_vbos_)
{
vtkVertexBufferObjectMapper* mapper = static_cast<vtkVertexBufferObjectMapper*>(am_it->second.actor->GetMapper ());
@@ -2785,6 +2793,7 @@ pcl::visualization::PCLVisualizer::updateColorHandlerIndex (const std::string &i
//style_->setCloudActorMap (cloud_actor_map_);
}
else
+#endif
{
vtkPolyDataMapper* mapper = static_cast<vtkPolyDataMapper*>(am_it->second.actor->GetMapper ());
mapper->SetScalarRange (minmax);
@@ -4296,8 +4305,12 @@ pcl::visualization::PCLVisualizer::resetStoppedFlag ()
void
pcl::visualization::PCLVisualizer::setUseVbos (bool use_vbos)
{
+#if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2
use_vbos_ = use_vbos;
style_->setUseVbos (use_vbos_);
+#else
+ PCL_WARN ("[PCLVisualizer::setUseVbos] Has no effect when OpenGL version is ≥ 2\n");
+#endif
}
//////////////////////////////////////////////////////////////////////////////////////////////

0 comments on commit c50c65b

Please sign in to comment.