-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support VTK7 with OpenGL2 backend #1534
Conversation
I'm building against VTK trunk:
|
What hardware are you testing on? Here is a VTK test code, use this big mesh (8 M point clouds) #include <vtkSmartPointer.h>
#include <vtkCallbackCommand.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkRenderWindow.h>
#include <vtkTimerLog.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkPLYReader.h>
#include <vtkProperty.h>
#include <iostream>
static void CallbackFunction(vtkObject* caller, long unsigned int eventId, void* clientData, void* callData);
int main(int, char *argv[])
{
vtkSmartPointer<vtkPLYReader> reader = vtkSmartPointer<vtkPLYReader>::New();
reader->SetFileName(argv[1]);
reader->Update();
vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
polydata = reader->GetOutput();
std::cout << "Mesh points: " << polydata->GetPoints()->GetNumberOfPoints() << std::endl;
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputData(polydata);
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
actor->GetProperty ()->SetColor (0.9, 0.1, 0.2);
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(actor);
vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkInteractorStyleTrackballCamera> imageStyle =
vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetInteractorStyle(imageStyle);
renderWindowInteractor->SetRenderWindow(renderWindow);
vtkSmartPointer<vtkCallbackCommand> callback = vtkSmartPointer<vtkCallbackCommand>::New();
callback->SetCallback(CallbackFunction);
renderer->AddObserver(vtkCommand::EndEvent, callback);
// Render and interact
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
void CallbackFunction(vtkObject* caller, long unsigned int vtkNotUsed(eventId), void* vtkNotUsed(clientData),
void* vtkNotUsed(callData))
{
vtkRenderer* renderer = static_cast<vtkRenderer*>(caller);
double timeInSeconds = renderer->GetLastRenderTimeInSeconds();
double fps = 1.0 / timeInSeconds;
std::cout << "FPS: " << fps << std::endl;
} cmake_minimum_required(VERSION 2.8)
PROJECT(vtk_ply_loader)
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
add_executable(test_vtk_1 MACOSX_BUNDLE test_vtk_1)
if(VTK_LIBRARIES)
target_link_libraries(test_vtk_1 ${VTK_LIBRARIES})
else()
target_link_libraries(test_vtk_1 vtkHybrid)
endif() I see a big improvement between VTK OpenGL and OpenGL2. |
Ok, for now I simply disabled the I'll give your example a try. |
I did not manage to get the FPS counter below 116, mostly it reports numbers between 1k and 3k. However still for me the motions are not super-smooth. Maybe I'm subjective, so please give a try to |
@@ -15,7 +15,7 @@ else(NOT VTK_FOUND) | |||
include("${VTK_USE_FILE}") | |||
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include") | |||
|
|||
if("${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}" VERSION_GREATER "5.8") | |||
if("${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}" VERSION_GREATER "5.8" AND "${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}" VERSION_LESS "7.0") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather check VTK_RENDERING_BACKEND
so that it allows people with OpenGL backend to still use pcl_outofcore_viewer
.
Well, it's not meant to be the final solution. I should have clarified, this pull request is more like a hack to make PCL compile with latest VTK. Eventually we will need to figure out how to substitute PCL's custom |
The new OpenGL2 backend does not have vktOpenGLHardwareSupport class which was used before.
8523721
to
8f51a52
Compare
These can be used at configuration and compilation times to adjust for the currently used backend.
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.
Ok, now it's supposed to be the final solution. Vertex buffer objects are used ubiquitously by the new backend, transparently for us. Therefore there is no need in the custom This pull request introduces a couple of variables and macros that are checked in scripts and code to conditionally compile the custom mapper only when the old backend is used. They are based on the I think it's a safe change and should probably be included in 1.8.0, though of course it would be nice to hear back from someone who tried this patch first. |
It would really be great, this is a huge improvement! I will compile, test and benchmark this code on several machines (at least 3) with different hardware configurations and get back with the results 👍 |
Great, thanks! |
I has confirmed that PCL with this fix can build on MSVC14.
|
Did you also try to run |
Where is the test code and test data? |
I did not have any specific code or data in mind. Just the standard |
Test program#include <pcl/console/parse.h>
#include <pcl/io/vtk_lib_io.h>
#include <pcl/visualization/pcl_visualizer.h>
int main(int argc, char *argv[])
{
std::vector<int> ply_files = pcl::console::parse_file_extension_argument(argc, argv, ".ply");
if (ply_files.empty())
{
PCL_ERROR("Please provide a PLY mesh to be visualized!\n");
return (-1);
}
pcl::PolygonMesh mesh;
pcl::io::loadPolygonFilePLY(argv[ply_files[0]], mesh);
pcl::visualization::PCLVisualizer viewer;
viewer.addPolygonMesh(mesh);
viewer.addCoordinateSystem();
viewer.resetCamera();
viewer.spin();
return (0);
} Test file (8 millions points mesh). |
I was tested in the following environments.
|
Brilliant! Thanks for giving it a try. I think we can merge this as soon as Victor reports his results. |
Results will be available on Monday. I have 3 configurations at home but two of them crashes with OpenGL2 backend (GLXBadFBConfig), its not PCL related. At work I know the OpenGL2 back-end works so I will test there. |
If you're looking for additional benchmarks, my specs:
On Victors last test program and the suzanne_hd.ply mesh I got:
Edit: On the first programm with vtk directly even my onboard went over 1000fps (./main suzanne_hd.ply |
Setup
Hardware
Results
I tested two machines where the VTK OpenGL2 backend simly doesn't work (GLXBadFBConfig), I did not manage to fix that, it's most probably a driver issue. In a general way, the gain is very good when using only VTK. When using PCL the gain is not as big. |
Can you please try to call |
With |
Hah, so it was broken anyway. |
Support VTK7 with OpenGL2 backend
This is a work-in-progress to support the new default backend in VTK. Addresses #1275.
Compiles and works on my Arch with VTK7, however I observe very low frame-rates (~15fps) when rotating and panning moderately sized (~300k) point clouds.