]>
Commit | Line | Data |
---|---|---|
d7780b5d JR |
1 | From d0efc67fa0d5f3fb3fb99990a6b2a1967a93c229 Mon Sep 17 00:00:00 2001 |
2 | From: Sergey Alexandrov <alexandrov88@gmail.com> | |
3 | Date: Sat, 13 Feb 2016 13:31:54 +0100 | |
4 | Subject: [PATCH] Add CMake variable and C++ macro | |
5 | VTK_RENDERING_BACKEND_OPENGL_VERSION | |
6 | ||
7 | These can be used at configuration and compilation times to adjust for | |
8 | the currently used backend. | |
9 | --- | |
10 | CMakeLists.txt | 12 +++++++++++- | |
11 | pcl_config.h.in | 4 ++++ | |
12 | 2 files changed, 15 insertions(+), 1 deletion(-) | |
13 | ||
14 | diff --git a/CMakeLists.txt b/CMakeLists.txt | |
15 | index 36fc4c9..e5fd763 100644 | |
16 | --- a/CMakeLists.txt | |
17 | +++ b/CMakeLists.txt | |
18 | @@ -361,7 +361,12 @@ option(WITH_VTK "Build VTK-Visualizations" TRUE) | |
19 | if(WITH_VTK AND NOT ANDROID) | |
20 | find_package(VTK) | |
21 | if(VTK_FOUND) | |
22 | - message(STATUS "VTK_MAJOR_VERSION ${VTK_MAJOR_VERSION}") | |
23 | + if(NOT DEFINED VTK_RENDERING_BACKEND) | |
24 | + # On old VTK versions this variable does not exist. In this case it is | |
25 | + # safe to assume OpenGL backend | |
26 | + set(VTK_RENDERING_BACKEND "OpenGL") | |
27 | + endif() | |
28 | + message(STATUS "VTK_MAJOR_VERSION ${VTK_MAJOR_VERSION}, rendering backend: ${VTK_RENDERING_BACKEND}") | |
29 | if (PCL_SHARED_LIBS OR | |
30 | (NOT (PCL_SHARED_LIBS) AND NOT (VTK_BUILD_SHARED_LIBS))) | |
31 | set(VTK_FOUND TRUE) | |
32 | @@ -377,6 +382,11 @@ if(WITH_VTK AND NOT ANDROID) | |
33 | option (VTK_USE_COCOA "Use Cocoa for VTK render windows" ON) | |
34 | MARK_AS_ADVANCED (VTK_USE_COCOA) | |
35 | endif (APPLE) | |
36 | + if(${VTK_RENDERING_BACKEND} STREQUAL "OpenGL") | |
37 | + set(VTK_RENDERING_BACKEND_OPENGL_VERSION "1") | |
38 | + elseif(${VTK_RENDERING_BACKEND} STREQUAL "OpenGL2") | |
39 | + set(VTK_RENDERING_BACKEND_OPENGL_VERSION "2") | |
40 | + endif() | |
41 | set(HAVE_VTK ON) | |
42 | else () | |
43 | set(VTK_FOUND OFF) | |
44 | diff --git a/pcl_config.h.in b/pcl_config.h.in | |
45 | index e4b10b0..3c25a06 100644 | |
46 | --- a/pcl_config.h.in | |
47 | +++ b/pcl_config.h.in | |
48 | @@ -71,3 +71,7 @@ | |
49 | /* Address the cases where on MacOS and OpenGL and GLUT are not frameworks */ | |
50 | #cmakedefine OPENGL_IS_A_FRAMEWORK | |
51 | #cmakedefine GLUT_IS_A_FRAMEWORK | |
52 | + | |
53 | +/* Version of OpenGL used by VTK as rendering backend */ | |
54 | +#define VTK_RENDERING_BACKEND_OPENGL_VERSION ${VTK_RENDERING_BACKEND_OPENGL_VERSION} | |
55 | + | |
2b7743ff JR |
56 | From 9cfb00970f7d46f1732149d4c50ba3646f038b6c Mon Sep 17 00:00:00 2001 |
57 | From: Sergey Alexandrov <alexandrov88@gmail.com> | |
58 | Date: Thu, 11 Feb 2016 22:19:01 +0100 | |
59 | Subject: [PATCH] Use vtkTextureUnitManager to query the number of available | |
60 | texture units | |
61 | ||
62 | The new OpenGL2 backend does not have vktOpenGLHardwareSupport class | |
63 | which was used before. | |
64 | --- | |
65 | visualization/src/pcl_visualizer.cpp | 15 +++++++-------- | |
66 | 1 file changed, 7 insertions(+), 8 deletions(-) | |
67 | ||
68 | diff --git a/visualization/src/pcl_visualizer.cpp b/visualization/src/pcl_visualizer.cpp | |
69 | index dc91674..007c251 100644 | |
70 | --- a/visualization/src/pcl_visualizer.cpp | |
71 | +++ b/visualization/src/pcl_visualizer.cpp | |
72 | @@ -84,7 +84,6 @@ | |
73 | #include <vtkRenderWindowInteractor.h> | |
74 | #include <vtkAreaPicker.h> | |
75 | #include <vtkXYPlotActor.h> | |
76 | -#include <vtkOpenGLHardwareSupport.h> | |
77 | #include <vtkOpenGLRenderWindow.h> | |
78 | #include <vtkJPEGReader.h> | |
79 | #include <vtkBMPReader.h> | |
80 | @@ -92,6 +91,7 @@ | |
81 | #include <vtkPNMReader.h> | |
82 | #include <vtkPNGReader.h> | |
83 | #include <vtkTIFFReader.h> | |
84 | +#include <vtkTextureUnitManager.h> | |
85 | ||
86 | #include <pcl/visualization/common/shapes.h> | |
87 | #include <pcl/visualization/pcl_visualizer.h> | |
88 | @@ -3223,17 +3223,18 @@ pcl::visualization::PCLVisualizer::addTextureMesh (const pcl::TextureMesh &mesh, | |
89 | #endif | |
90 | ||
91 | vtkSmartPointer<vtkLODActor> actor = vtkSmartPointer<vtkLODActor>::New (); | |
92 | - vtkOpenGLHardwareSupport* hardware = vtkOpenGLRenderWindow::SafeDownCast (win_)->GetHardwareSupport (); | |
93 | + vtkTextureUnitManager* tex_manager = vtkOpenGLRenderWindow::SafeDownCast (win_)->GetTextureUnitManager (); | |
94 | + if (!tex_manager) | |
95 | + return (false); | |
96 | - bool supported = hardware->GetSupportsMultiTexturing (); | |
97 | // Check if hardware support multi texture | |
98 | - std::size_t texture_units (hardware->GetNumberOfFixedTextureUnits ()); | |
99 | - if ((mesh.tex_materials.size () > 1) && supported && (texture_units > 1)) | |
100 | + int texture_units = tex_manager->GetNumberOfTextureUnits (); | |
101 | + if ((mesh.tex_materials.size () > 1) && (texture_units > 1)) | |
102 | { | |
103 | if (texture_units < mesh.tex_materials.size ()) | |
104 | PCL_WARN ("[PCLVisualizer::addTextureMesh] GPU texture units %d < mesh textures %d!\n", | |
105 | texture_units, mesh.tex_materials.size ()); | |
106 | // Load textures | |
107 | - std::size_t last_tex_id = std::min (mesh.tex_materials.size (), texture_units); | |
108 | + std::size_t last_tex_id = std::min (static_cast<int> (mesh.tex_materials.size ()), texture_units); | |
109 | int tu = vtkProperty::VTK_TEXTURE_UNIT_0; | |
110 | std::size_t tex_id = 0; | |
111 | while (tex_id < last_tex_id) | |
112 | @@ -3279,7 +3278,7 @@ pcl::visualization::PCLVisualizer::addTextureMesh (const pcl::TextureMesh &mesh, | |
113 | } // end of multi texturing | |
114 | else | |
115 | { | |
116 | - if (!supported || texture_units < 2) | |
117 | + if ((mesh.tex_materials.size () > 1) && (texture_units < 2)) | |
118 | PCL_WARN ("[PCLVisualizer::addTextureMesh] Your GPU doesn't support multi texturing. " | |
119 | "Will use first one only!\n"); | |
120 | ||
d7780b5d JR |
121 | From c50c65b042828cfa18765eef7876f896a40a6d1b Mon Sep 17 00:00:00 2001 |
122 | From: Sergey Alexandrov <alexandrov88@gmail.com> | |
123 | Date: Sat, 13 Feb 2016 13:59:47 +0100 | |
124 | Subject: [PATCH] Conditionally compile code that uses | |
125 | vtkVertexBufferObjectMapper | |
126 | ||
127 | This mapper is a performance optimization that is only needed when | |
128 | OpenGL backend is used. The modern OpenGL2 backend uses vertex buffer | |
129 | objects transparently for us. | |
130 | --- | |
131 | outofcore/src/visualization/outofcore_cloud.cpp | 14 ++++++++++++-- | |
132 | visualization/CMakeLists.txt | 18 ++++++++++++++---- | |
133 | visualization/src/interactor_style.cpp | 6 ++++++ | |
134 | visualization/src/pcl_visualizer.cpp | 15 ++++++++++++++- | |
135 | 4 files changed, 46 insertions(+), 7 deletions(-) | |
136 | ||
137 | diff --git a/outofcore/src/visualization/outofcore_cloud.cpp b/outofcore/src/visualization/outofcore_cloud.cpp | |
138 | index eaf490c..b08d30e 100644 | |
139 | --- a/outofcore/src/visualization/outofcore_cloud.cpp | |
140 | +++ b/outofcore/src/visualization/outofcore_cloud.cpp | |
141 | @@ -21,7 +21,10 @@ | |
142 | ||
143 | // PCL - visualziation | |
144 | #include <pcl/visualization/common/common.h> | |
145 | + | |
146 | +#if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2 | |
147 | #include <pcl/visualization/vtk/vtkVertexBufferObjectMapper.h> | |
148 | +#endif | |
149 | ||
150 | // VTK | |
151 | #include <vtkVersion.h> | |
152 | @@ -251,11 +254,18 @@ OutofcoreCloud::render (vtkRenderer* renderer) | |
153 | { | |
154 | ||
155 | vtkSmartPointer<vtkActor> cloud_actor = vtkSmartPointer<vtkActor>::New (); | |
156 | - vtkSmartPointer<vtkVertexBufferObjectMapper> mapper = vtkSmartPointer<vtkVertexBufferObjectMapper>::New (); | |
157 | - | |
158 | CloudDataCacheItem *cloud_data_cache_item = &cloud_data_cache.get(pcd_file); | |
159 | ||
160 | +#if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2 | |
161 | + vtkSmartPointer<vtkVertexBufferObjectMapper> mapper = vtkSmartPointer<vtkVertexBufferObjectMapper>::New (); | |
162 | mapper->SetInput (cloud_data_cache_item->item); | |
163 | +#else | |
164 | + vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New (); | |
165 | + // Usually we choose between SetInput and SetInputData based on VTK version. But OpenGL ≥ 2 automatically | |
166 | + // means VTK version is ≥ 6.3 | |
167 | + mapper->SetInputData (cloud_data_cache_item->item); | |
168 | +#endif | |
169 | + | |
170 | cloud_actor->SetMapper (mapper); | |
171 | cloud_actor->GetProperty ()->SetColor (0.0, 0.0, 1.0); | |
172 | cloud_actor->GetProperty ()->SetPointSize (1); | |
173 | diff --git a/visualization/CMakeLists.txt b/visualization/CMakeLists.txt | |
174 | index 26bfd7c..940fc8e 100644 | |
175 | --- a/visualization/CMakeLists.txt | |
176 | +++ b/visualization/CMakeLists.txt | |
177 | @@ -50,8 +50,6 @@ if(build) | |
178 | src/common/float_image_utils.cpp | |
179 | src/vtk/pcl_image_canvas_source_2d.cpp | |
180 | src/vtk/pcl_context_item.cpp | |
181 | - src/vtk/vtkVertexBufferObject.cxx | |
182 | - src/vtk/vtkVertexBufferObjectMapper.cxx | |
183 | src/vtk/vtkRenderWindowInteractorFix.cpp | |
184 | ) | |
185 | if("${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}" VERSION_LESS "5.6") | |
186 | @@ -67,6 +65,13 @@ if(build) | |
187 | ) | |
188 | endif("${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}" VERSION_GREATER "5.6") | |
189 | ||
190 | + if(VTK_RENDERING_BACKEND_OPENGL_VERSION VERSION_LESS 2) | |
191 | + list(APPEND srcs | |
192 | + "src/vtk/vtkVertexBufferObject.cxx" | |
193 | + "src/vtk/vtkVertexBufferObjectMapper.cxx" | |
194 | + ) | |
195 | + endif() | |
196 | + | |
197 | set(incs | |
198 | "include/pcl/${SUBSYS_NAME}/eigen.h" | |
199 | "include/pcl/${SUBSYS_NAME}/boost.h" | |
200 | @@ -127,11 +132,16 @@ if(build) | |
201 | set(vtk_incs | |
202 | "include/pcl/${SUBSYS_NAME}/vtk/pcl_image_canvas_source_2d.h" | |
203 | "include/pcl/${SUBSYS_NAME}/vtk/pcl_context_item.h" | |
204 | - "include/pcl/${SUBSYS_NAME}/vtk/vtkVertexBufferObject.h" | |
205 | "include/pcl/${SUBSYS_NAME}/vtk/vtkRenderWindowInteractorFix.h" | |
206 | - "include/pcl/${SUBSYS_NAME}/vtk/vtkVertexBufferObjectMapper.h" | |
207 | ) | |
208 | ||
209 | + if(VTK_RENDERING_BACKEND_OPENGL_VERSION VERSION_LESS 2) | |
210 | + list(APPEND vtk_incs | |
211 | + "include/pcl/${SUBSYS_NAME}/vtk/vtkVertexBufferObject.h" | |
212 | + "include/pcl/${SUBSYS_NAME}/vtk/vtkVertexBufferObjectMapper.h" | |
213 | + ) | |
214 | + endif() | |
215 | + | |
216 | # on apple, a workaround is used for the cocoa render window interactor | |
217 | if(APPLE) | |
218 | list(APPEND srcs | |
219 | diff --git a/visualization/src/interactor_style.cpp b/visualization/src/interactor_style.cpp | |
220 | index 9e9fdaf..f443b6b 100644 | |
221 | --- a/visualization/src/interactor_style.cpp | |
222 | +++ b/visualization/src/interactor_style.cpp | |
223 | @@ -64,7 +64,9 @@ | |
224 | #include <vtkPointPicker.h> | |
225 | #include <vtkAreaPicker.h> | |
226 | ||
227 | +#if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2 | |
228 | #include <pcl/visualization/vtk/vtkVertexBufferObjectMapper.h> | |
229 | +#endif | |
230 | ||
231 | #define ORIENT_MODE 0 | |
232 | #define SELECT_MODE 1 | |
233 | @@ -660,6 +662,7 @@ pcl::visualization::PCLVisualizerInteractorStyle::OnKeyDown () | |
234 | data->SetPoints (points); | |
235 | data->SetVerts (vertices); | |
236 | // Modify the mapper | |
237 | +#if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2 | |
238 | if (use_vbos_) | |
239 | { | |
240 | vtkVertexBufferObjectMapper* mapper = static_cast<vtkVertexBufferObjectMapper*>(act->actor->GetMapper ()); | |
241 | @@ -668,6 +671,7 @@ pcl::visualization::PCLVisualizerInteractorStyle::OnKeyDown () | |
242 | act->actor->SetMapper (mapper); | |
243 | } | |
244 | else | |
245 | +#endif | |
246 | { | |
247 | vtkPolyDataMapper* mapper = static_cast<vtkPolyDataMapper*>(act->actor->GetMapper ()); | |
248 | #if VTK_MAJOR_VERSION < 6 | |
249 | @@ -704,6 +708,7 @@ pcl::visualization::PCLVisualizerInteractorStyle::OnKeyDown () | |
250 | vtkPolyData *data = static_cast<vtkPolyData*>(act->actor->GetMapper ()->GetInput ()); | |
251 | data->GetPointData ()->SetScalars (scalars); | |
252 | // Modify the mapper | |
253 | +#if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2 | |
254 | if (use_vbos_) | |
255 | { | |
256 | vtkVertexBufferObjectMapper* mapper = static_cast<vtkVertexBufferObjectMapper*>(act->actor->GetMapper ()); | |
257 | @@ -714,6 +719,7 @@ pcl::visualization::PCLVisualizerInteractorStyle::OnKeyDown () | |
258 | act->actor->SetMapper (mapper); | |
259 | } | |
260 | else | |
261 | +#endif | |
262 | { | |
263 | vtkPolyDataMapper* mapper = static_cast<vtkPolyDataMapper*>(act->actor->GetMapper ()); | |
264 | mapper->SetScalarRange (minmax); | |
265 | diff --git a/visualization/src/pcl_visualizer.cpp b/visualization/src/pcl_visualizer.cpp | |
266 | index 007c251..40e516c 100644 | |
267 | --- a/visualization/src/pcl_visualizer.cpp | |
268 | +++ b/visualization/src/pcl_visualizer.cpp | |
269 | @@ -63,9 +63,12 @@ | |
270 | #include <vtkPointPicker.h> | |
271 | ||
272 | #include <pcl/visualization/boost.h> | |
273 | -#include <pcl/visualization/vtk/vtkVertexBufferObjectMapper.h> | |
274 | #include <pcl/visualization/vtk/vtkRenderWindowInteractorFix.h> | |
275 | ||
276 | +#if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2 | |
277 | +#include <pcl/visualization/vtk/vtkVertexBufferObjectMapper.h> | |
278 | +#endif | |
279 | + | |
280 | #include <vtkPolyLine.h> | |
281 | #include <vtkPolyDataMapper.h> | |
282 | #include <vtkRenderWindow.h> | |
283 | @@ -1079,6 +1082,7 @@ pcl::visualization::PCLVisualizer::createActorFromVTKDataSet (const vtkSmartPoin | |
284 | if (!actor) | |
285 | actor = vtkSmartPointer<vtkLODActor>::New (); | |
286 | ||
287 | +#if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2 | |
288 | if (use_vbos_) | |
289 | { | |
290 | vtkSmartPointer<vtkVertexBufferObjectMapper> mapper = vtkSmartPointer<vtkVertexBufferObjectMapper>::New (); | |
291 | @@ -1111,6 +1115,7 @@ pcl::visualization::PCLVisualizer::createActorFromVTKDataSet (const vtkSmartPoin | |
292 | actor->SetMapper (mapper); | |
293 | } | |
294 | else | |
295 | +#endif | |
296 | { | |
297 | vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New (); | |
298 | #if VTK_MAJOR_VERSION < 6 | |
299 | @@ -1157,6 +1162,7 @@ pcl::visualization::PCLVisualizer::createActorFromVTKDataSet (const vtkSmartPoin | |
300 | if (!actor) | |
301 | actor = vtkSmartPointer<vtkActor>::New (); | |
302 | ||
303 | +#if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2 | |
304 | if (use_vbos_) | |
305 | { | |
306 | vtkSmartPointer<vtkVertexBufferObjectMapper> mapper = vtkSmartPointer<vtkVertexBufferObjectMapper>::New (); | |
307 | @@ -1189,6 +1195,7 @@ pcl::visualization::PCLVisualizer::createActorFromVTKDataSet (const vtkSmartPoin | |
308 | actor->SetMapper (mapper); | |
309 | } | |
310 | else | |
311 | +#endif | |
312 | { | |
313 | vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New (); | |
314 | #if VTK_MAJOR_VERSION < 6 | |
315 | @@ -2771,6 +2778,7 @@ pcl::visualization::PCLVisualizer::updateColorHandlerIndex (const std::string &i | |
316 | vtkPolyData *data = static_cast<vtkPolyData*>(am_it->second.actor->GetMapper ()->GetInput ()); | |
317 | data->GetPointData ()->SetScalars (scalars); | |
318 | // Modify the mapper | |
319 | +#if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2 | |
320 | if (use_vbos_) | |
321 | { | |
322 | vtkVertexBufferObjectMapper* mapper = static_cast<vtkVertexBufferObjectMapper*>(am_it->second.actor->GetMapper ()); | |
323 | @@ -2785,6 +2793,7 @@ pcl::visualization::PCLVisualizer::updateColorHandlerIndex (const std::string &i | |
324 | //style_->setCloudActorMap (cloud_actor_map_); | |
325 | } | |
326 | else | |
327 | +#endif | |
328 | { | |
329 | vtkPolyDataMapper* mapper = static_cast<vtkPolyDataMapper*>(am_it->second.actor->GetMapper ()); | |
330 | mapper->SetScalarRange (minmax); | |
331 | @@ -4296,8 +4305,12 @@ pcl::visualization::PCLVisualizer::resetStoppedFlag () | |
332 | void | |
333 | pcl::visualization::PCLVisualizer::setUseVbos (bool use_vbos) | |
334 | { | |
335 | +#if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2 | |
336 | use_vbos_ = use_vbos; | |
337 | style_->setUseVbos (use_vbos_); | |
338 | +#else | |
339 | + PCL_WARN ("[PCLVisualizer::setUseVbos] Has no effect when OpenGL version is ≥ 2\n"); | |
340 | +#endif | |
341 | } | |
342 | ||
343 | ////////////////////////////////////////////////////////////////////////////////////////////// |