I try to visualize the LiDAR point cloud in QVTKOpenGLWidget. In real time visualization, the program crash immediately after the widget appear.
Is it possible to visualize the point cloud in QVTKOpenGLWidget?
The main reason is that “to embed the pcl viewer in the Qt GUI and interact the viewer with mouse etc.,”.
My environment is ;
Ubuntu 18.04
VTK 8.2.0
Qt Creator 5.9.5
PCL 1.12.1
Please share your initial code and then we will see what can be done about it. You need to recheck qmake as it can be the source of problem.
1 Like
Hello,
Take a look at this minimal working VTK/Qt/PCL example: PCL Viewer with Qt GUI minimal code · GitHub to have an idea of what you’re missing or doing wrong. If you’ve done everything right and if you’re building with QMake, then you may need to add these to the top of the .cpp
files that are making VTK calls:
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2) // VTK was built with vtkRenderingOpenGL2
VTK_MODULE_INIT(vtkInteractionStyle)
VTK_MODULE_INIT(vtkRenderingFreeType)
regards,
Paulo
1 Like
Hello Greg,
I am sorry for late reply. I run in Cmake. I will share my code.
CMakeLists.txt
cmake_minimum_required(VERSION 3.1.0)
project(gui VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
if(CMAKE_VERSION VERSION_LESS "3.7.0")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
endif()
#////QT5 start
find_package(Qt5 COMPONENTS Widgets Core REQUIRED)
include_directories(${Qt5Widgets_INCLUDE_DIRS})
#///Qt ended
#////PCL
find_package(PCL 1.12 REQUIRED)
if( PCL_FOUND )
include_directories( ${PCL_INCLUDE_DIRS} )
add_definitions( ${PCL_DEFINITIONS} )
link_directories( ${PCL_LIBRARY_DIRS} )
#///PCL ended
#///VTK
set(/usr/local/lib/cmake/vtk-8.2/lib)
find_package(VTK 8.2.0 REQUIRED COMPONENTS
vtkGUISupportQt
vtkInteractionStyle
vtkRenderingCore
vtkRenderingOpenGL2
)
#find_package(VTK REQUIRED)
include_directories(${VTK_INCLUDE_DIRS})
include(${VTK_USE_FILE})
#///VTK ended
find_package(Boost REQUIRED)
INCLUDE_DIRECTORIES(${BOOST_INCLUDE_DIRS})
add_executable(${PROJECT_NAME}
mainwindow.ui
mainwindow.cpp
main.cpp
)
target_link_libraries(${PROJECT_NAME} Qt5::Widgets ${EXTERNAL_LIBS} ${rs_driver_LIBRARIES} ${PCL_LIBRARIES} ${VTK_LIBRARIES} ${BOOST_LIBRARIES} vtkGUISupportQt
vtkInteractionStyle
vtkRenderingCore
vtkRenderingOpenGL2
)
else()
message("PCL Not found! Can not compile rs_driver_viewer!")
endif()
install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION /usr/bin
)
The constructor is ;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ren_= vtkSmartPointer<vtkRenderer>::New();
renWin = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
ren_->SetGradientBackground(1);
ren_->SetBackground2(0.7, 0.7, 0.7);
renWin -> AddRenderer(ren_.Get());
pcl_viewer.reset(new pcl::visualization::PCLVisualizer(ren_.Get(),renWin.Get(),"viewer",false));
ui->widget->SetRenderWindow(pcl_viewer->getRenderWindow());
ui->widget->update();
renWin->Render();
}
void MainWindow::on_lidar_btn_clicked()
{
qDebug()<<"Clicked the button\n";
RS_TITLE << "------------------------------------------------------" << RS_REND;
RS_TITLE << " RS_Driver Viewer Version: v" << RSLIDAR_VERSION_MAJOR << "." << RSLIDAR_VERSION_MINOR << "."
<< RSLIDAR_VERSION_PATCH << RS_REND;
RS_TITLE << "------------------------------------------------------" << RS_REND;
if (sizeof(infoarray) < 2)
{
RS_INFOL << "Use 'rs_driver_viewer -h/--help' to check the argument menu..." << RS_REND;
}
if (checkKeywordExist(infosize, infoarray, "-h") || checkKeywordExist(infosize, infoarray, "--help"))
{
printHelpMenu();
}
pcl::PointCloud<pcl::PointXYZI>::Ptr pcl_pointcloud(new pcl::PointCloud<pcl::PointXYZI>);
pcl_viewer->addPointCloud<pcl::PointXYZI>(pcl_pointcloud, "rslidar");
qDebug()<<"initial Points"<<QString::number(pcl_pointcloud->points.size());
pcl_viewer->setPointCloudRenderingProperties(PCL_VISUALIZER_POINT_SIZE, 1, "rslidar");
LidarDriver<pcl::PointXYZI> driver; ///< Declare the driver object
RSDriverParam param; ///< Create a parameter object
parseParam(infosize,infoarray,param);
printParam(param);
driver.regExceptionCallback(exceptionCallback); ///< Register the exception callback function into the driver
driver.regRecvCallback(pointCloudCallback); ///< Register the point cloud callback function into the driver
if (!driver.init(param)) ///< Call the init function and pass the parameter
{
RS_ERROR << "Driver Initialize Error..." << RS_REND;
// return -1;
}
driver.start(); ///< The driver thread will start
while(next_point_cloud_flag==false)
{
{
renWin->Render();
ui->widget->update();
}
}
}
regards,
Aye Moh
Hello Paulo,
I am sorry for my late reply.
I add these three lines in .h file before. According to your suggestion, I copy at the top of the .cpp file, but the result is the same.
When I load .pcd file (not real time point cloud) , it is loaded but the program is unexpectedly finished after mouse click and rotate for about 5 or 6 times.
I also have a question, is it necessary to check Module_vtkGUISupportQtOpenGL , when build VTK with Cmake? I got the build error when I checked this.
Bear with my English because it is not my first language either.
regards,
Aye Moh
@Panda12197 Hi, Have you followed the instructions given by @Paulo_Carvalho . I think they should work.
1 Like
No, I don’t use that module.
1 Like
It is not recommended to add them to header files. Only to the files that are compiled to object code (normally .cpp
/.cxx
files).
1 Like
Hello Greg,
I try with the instructions given by @Paulo_Carvalho . But the result is the same.
Hello Paulo,
I add them to the .cpp file and run the code. But the result is the same.
I will show my code. Please check this!!
In this program, I load .pcd file(not the real time).
main.cpp
int main(int argc, char *argv[])
{
QSurfaceFormat::setDefaultFormat(QVTKOpenGLWidget::defaultFormat());
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
vtkSmartPointer<vtkRenderer> ren_;
vtkSmartPointer<vtkGenericOpenGLRenderWindow> renWin;
pcl::visualization::PCLVisualizer::Ptr viewer;
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2)
VTK_MODULE_INIT(vtkInteractionStyle)
VTK_MODULE_INIT(vtkRenderingFreeType)
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ren_= vtkSmartPointer<vtkRenderer>::New();
renWin = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
renWin -> AddRenderer(ren_.Get());
viewer.reset(new pcl::visualization::PCLVisualizer(ren_,renWin,"viewer",false));
ui->widget->SetRenderWindow(viewer->getRenderWindow());
ui->widget->update();
renWin->Render();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_load_btn_clicked()
{
std::string name = "/home/gui_test/bunny.pcd";
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
pcl::io::loadPCDFile(name,*cloud);
qDebug()<<"Bunny Points"<<QString::number(cloud->points.size());
viewer->addPointCloud<pcl::PointXYZ>(cloud,"cloud");
viewer->resetCamera();
ui->widget->update();
renWin->Render();
}
mainwindow.ui
Promote QWidget to QVTKOpenGLWidget
When I click the load_btn, bunny.pcd file is loaded to the widget. But the program is finished when I zoom or rotate the point cloud for about 5 times.
Now,I am using Jetson Nano board.
Is it possible that Jetson Nano is not enough for VTK and OpenGL?
Hello,
How many points are there in your LDAR samples? Jetson Nano is physically small but it is fairly capable of handling VTK. On the other hand, you can exhaust GPU memory even in high-end hardware if you shove too much data into the graphics card.
regards,
Paulo
1 Like
Hello,
@Paulo_Carvalho ,Thank you for your suggestion.
This sample point cloud has 397 points and real time point cloud has 57600 points . Now, I am testing with the bunny.pcd that has 397 point, but the program crashed. And I try the following VTK tutorials.
●PointSource ,it render the point cloud without any error. But when I embed this render window to the Qt main window using QVTKOpenGLWidget , the program crashed after zoom or rotate the point cloud.
●I also try vtk-8.2.0/GUISupport/Qt/Testing/Cxx/TestQVTKOpenGLWidget.cxx
and vtk-8.2.0/GUISupport/Qt/Testing/Cxx/TestQVTKOpenGLNativeWidget.cxx
.
In TestQVTKOpenGLWidget ->Program crashed after interacting the window for about a few seconds.
In TestQVTKOpenGLNativeWidget → Nothing is displayed.
regards,
Aye_Moh
Hi,
57k points is not that much. Then I suggest you to:
a) Make sure you have the latest graphics card drivers installed;
b) Make sure your OS is updated to the latest version;
If these don’t solve the problem, then:
c) Get the debug versions of VTK, Qt and PCL;
d) Compile your program in debug mode;
e) Run the program in debug mode in Qt Creator. The debugger will likely intercept the crash and stop the program at the offending instruction. Perhaps you’re using some uninitialized or null pointer.
take care,
Paulo
1 Like
Hello,@Paulo_Carvalho
I got the debug version of VTK, Qt and PCL and compiled the program in debug mode.
I run this vtk-example in debug mode and there is no error. But when I embed the render window of this example into the Qt main window and run in debug mode, I got the following error.
The inferior stopped because it received a signal from the operating system.
Signal name : SIGSEGV
Signal meaning : Segmentation fault
I also got the same error when I run the above bunny program.
regards,
AyeMoh
Have you tried with the regular standford bunny mesh? What happens then?
Also the camera maybe being set up wrong transformations that could explaing some kind of crash.
Why don’t you set up a docker with vnc an try to run your vgl application there, here is a link to get you started:
opened 06:22PM - 20 May 22 UTC
Dear dcommander
I tried [this branch](https://github.com/dcommander/virtualgl… _docker_examples/tree/vgl_slicer_turbovnc_novnc-eglbackend) and I couldn't make it work.
[Here](https://discourse.slicer.org/t/using-slicer-via-vnc-virtualgl/11702/12?u=mau_igna_06) is how I made Slicer work inside Docker with novnc + TurboVNC + VirtualGL with EGL backend and no window manager.
Hope it is helpful for you.
Mauro
I have not tried yet.
Now, I am trying to visualize the point cloud of 3D LiDAR in the Qt GUI using VTK (with QVTKOpenGLWidget).
Also you can try your app in docker with this isntructions:
opened 06:22PM - 20 May 22 UTC
Dear dcommander
I tried [this branch](https://github.com/dcommander/virtualgl… _docker_examples/tree/vgl_slicer_turbovnc_novnc-eglbackend) and I couldn't make it work.
[Here](https://discourse.slicer.org/t/using-slicer-via-vnc-virtualgl/11702/12?u=mau_igna_06) is how I made Slicer work inside Docker with novnc + TurboVNC + VirtualGL with EGL backend and no window manager.
Hope it is helpful for you.
Mauro
With virtual gpu accelerated rendering
@mau_igna_06 Thanks you for your suggestion .
I will try.
Hello,
Are you debugging in Qt Creator? If so, you can see the stack trace when the crash ensues. What does it read? You can also navigate through the several nested calling contexts and inspect the contents of the variables of each one.
regards,
Paulo
I debug the program and I get the following stack trace.
Generic Warning: In /home/vtk-v8.2.0/Rendering/OpenGL2/vtkOpenGLState.cxx, line 401
Error glClearDepth1 OpenGL errors detected
0 : (1282) Invalid operation
with stack trace of
0x7fb504536c : vtksys::SystemInformationImplementation::GetProgramStack[abi:cxx11](int, int) [(libvtksys-8.2.so.1) ???:-1]
0x7fb503fe44 : vtksys::SystemInformation::GetProgramStack[abi:cxx11](int, int) [(libvtksys-8.2.so.1) ???:-1]
0x7fb685b1ec : ??? [(???) ???:-1]
0x7fb685ba0c : vtkOpenGLState::vtkglClearDepth(double) [(libvtkRenderingOpenGL2-8.2.so.1) ???:-1]
0x7fb68445dc : vtkOpenGLRenderer::Clear() [(libvtkRenderingOpenGL2-8.2.so.1) ???:-1]
0x7fb678a850 : vtkOpenGLCamera::Render(vtkRenderer*) [(libvtkRenderingOpenGL2-8.2.so.1) ???:-1]
0x7fb632ebc0 : vtkRenderer::UpdateCamera() [(libvtkRenderingCore-8.2.so.1) ???:-1]
0x7fb68424f0 : vtkOpenGLRenderer::DeviceRender() [(libvtkRenderingOpenGL2-8.2.so.1) ???:-1]
0x7fb632e540 : vtkRenderer::Render() [(libvtkRenderingCore-8.2.so.1) ???:-1]
0x7fb632bc58 : vtkRendererCollection::Render() [(libvtkRenderingCore-8.2.so.1) ???:-1]
0x7fb6349704 : vtkRenderWindow::DoStereoRender() [(libvtkRenderingCore-8.2.so.1) ???:-1]
0x7fb63494fc : vtkRenderWindow::Render() [(libvtkRenderingCore-8.2.so.1) ???:-1]
0x7fb683e390 : vtkOpenGLRenderWindow::Render() [(libvtkRenderingOpenGL2-8.2.so.1) ???:-1]
0x7fb6775014 : vtkGenericOpenGLRenderWindow::Render() [(libvtkRenderingOpenGL2-8.2.so.1) ???:-1]
0x7fb63569a0 : vtkRenderWindowInteractor::Render() [(libvtkRenderingCore-8.2.so.1) ???:-1]
0x7fb65ba148 : vtkInteractorStyleTrackballCamera::Rotate() [(libvtkInteractionStyle-8.2.so.1) ???:-1]
0x7fb65b9690 : vtkInteractorStyleTrackballCamera::OnMouseMove() [(libvtkInteractionStyle-8.2.so.1) ???:-1]
0x7fb65b05f0 : vtkInteractorStyleRubberBandPick::OnMouseMove() [(libvtkInteractionStyle-8.2.so.1) ???:-1]
0x7fb7e119d8 : pcl::visualization::PCLVisualizerInteractorStyle::OnMouseMove() [(libpcl_visualization.so.1.12) ???:-1]
0x7fb63bb024 : vtkInteractorStyle::ProcessEvents(vtkObject*, unsigned long, void*, void*) [(libvtkRenderingCore-8.2.so.1) ???:-1]
0x7fb545f564 : vtkCallbackCommand::Execute(vtkObject*, unsigned long, void*) [(libvtkCommonCore-8.2.so.1) ???:-1]
0x7fb56abbdc : ??? [(???) ???:-1]
0x7fb56ac31c : vtkObject::InvokeEvent(unsigned long, void*) [(libvtkCommonCore-8.2.so.1) ???:-1]
0x7fb79b5870 : QVTKInteractorAdapter::ProcessEvent(QEvent*, vtkRenderWindowInteractor*) [(libvtkGUISupportQt-8.2.so.1) ???:-1]
0x7fb79e07d0 : QVTKOpenGLWindow::ProcessEvent(QEvent*) [(libvtkGUISupportQt-8.2.so.1) ???:-1]
0x7fb79e062c : QVTKOpenGLWindow::mouseMoveEvent(QMouseEvent*) [(libvtkGUISupportQt-8.2.so.1) ???:-1]
0x7fb704ece8 : QWindow::event(QEvent*) [(libQt5Gui.so.5) ???:-1]
In debugger;
1 ??
2 vtkOpenGLRenderTimer::ReusableStart vtkOpenGLRenderTimer.cxx 292 0x7fb682a644
3 vtkOpenGLPolyDataMapper::RenderPieceStart vtkOpenGLPolyDataMapper.cxx 2434 0x7fb680320c
4 vtkOpenGLPolyDataMapper::RenderPiece vtkOpenGLPolyDataMapper.cxx 2629 0x7fb6803c40
5 vtkPolyDataMapper::Render vtkPolyDataMapper.cxx 68 0x7fb6312cc0
6 vtkDataSetMapper::Render vtkDataSetMapper.cxx 159 0x7fb625e404
7 vtkOpenGLActor::Render vtkOpenGLActor.cxx 105 0x7fb67838e8
8 vtkLODActor::Render vtkLODActor.cxx 187 0x7fb488b7a4
9 vtkLODActor::RenderOpaqueGeometry vtkLODActor.cxx 226 0x7fb488b99c
10 vtkRenderer::UpdateOpaquePolygonalGeometry vtkRenderer.cxx 742 0x7fb632fb20
11 vtkRenderer::DeviceRenderOpaqueGeometry vtkRenderer.cxx 431 0x7fb632e908
12 vtkOpenGLRenderer::DeviceRenderOpaqueGeometry vtkOpenGLRenderer.cxx 433 0x7fb68437f0
13 vtkOpenGLRenderer::UpdateGeometry vtkOpenGLRenderer.cxx 322 0x7fb6842e20
14 vtkOpenGLRenderer::DeviceRender vtkOpenGLRenderer.cxx 234 0x7fb684253c
15 vtkRenderer::Render vtkRenderer.cxx 371 0x7fb632e540
16 vtkRendererCollection::Render vtkRendererCollection.cxx 51 0x7fb632bc58
17 vtkRenderWindow::DoStereoRender vtkRenderWindow.cxx 330 0x7fb6349704
18 vtkRenderWindow::Render vtkRenderWindow.cxx 291 0x7fb63494fc
19 vtkOpenGLRenderWindow::Render vtkOpenGLRenderWindow.cxx 2564 0x7fb683e390
20 vtkGenericOpenGLRenderWindow::Render vtkGenericOpenGLRenderWindow.cxx 242 0x7fb6775014
21 vtkRenderWindowInteractor::Render vtkRenderWindowInteractor.cxx 185 0x7fb63569a0
22 vtkInteractorStyleTrackballCamera::Rotate vtkInteractorStyleTrackballCamera.cxx 264 0x7fb65ba148
23 vtkInteractorStyleTrackballCamera::OnMouseMove vtkInteractorStyleTrackballCamera.cxx 46 0x7fb65b9690
24 vtkInteractorStyleRubberBandPick::OnMouseMove vtkInteractorStyleRubberBandPick.cxx 131 0x7fb65b05f0
25 pcl::visualization::PCLVisualizerInteractorStyle::OnMouseMove interactor_style.cpp 1312 0x7fb7e119d8
26 vtkInteractorStyle::ProcessEvents vtkInteractorStyle.cxx 1081 0x7fb63bb024
27 vtkCallbackCommand::Execute vtkCallbackCommand.cxx 42 0x7fb545f564
28 vtkSubjectHelper::InvokeEvent vtkObject.cxx 569 0x7fb56abbdc
29 vtkObject::InvokeEvent vtkObject.cxx 785 0x7fb56ac31c
30 QVTKInteractorAdapter::ProcessEvent QVTKInteractorAdapter.cxx 147 0x7fb79b5870
31 QVTKOpenGLWindow::ProcessEvent QVTKOpenGLWindow.cxx 452 0x7fb79e07d0
32 QVTKOpenGLWindow::mouseMoveEvent QVTKOpenGLWindow.cxx 408 0x7fb79e062c
33 QWindow::event(QEvent *) 0x7fb704ece8
34 QPaintDeviceWindow::event(QEvent *) 0x7fb7078798
35 QVTKOpenGLWindow::event QVTKOpenGLWindow.cxx 384 0x7fb79e052c 0x1
regards,
Aye Moh