问题
I'm trying to use QVTKOpenGLWidget
in QTDesigner with vtkGenericOpenGlRenderWindow
but I obtain a black window. When I use PCLVizualizer
of PointCloud Library (PCL) with vtkGenericOpenGlRenderWindow
, everything works fine. I'm trying to create a custom viewer the same way as PCL.
QMainPanel::QMainPanel( HWND hWnd ) :
QWinWidget( hWnd ),
ui(new Ui::QMainPanel)
{
ui->setupUi(this);
rendererTest = vtkSmartPointer<vtkRenderer>::New();
rendererTest->GradientBackgroundOn();
rendererTest->SetBackground(0.27,0.27,0.27);
rendererTest->SetBackground2(0.44,0.44,0.44);
windowTest = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
windowTest->AddRenderer(rendererTest);
interactorTest = vtkSmartPointer<vtkRenderWindowInteractor>::New();
interactorTest->SetRenderWindow( windowTest );
ui->openGLWidget->SetRenderWindow( windowTest ); // QVTKOpenGLWidget *openGLWidget;
}
Thank you
Edit : Remove "Interactor" solved my problem.
回答1:
You will need to get the master version of PCL form https://github.com/PointCloudLibrary/pcl. This will give a PCLVisualizer with more constructors. So, you can use a custom widget like this:
VideoQVTKOpenGLWidget.h
#ifndef VIDEOQVKTOPENGLWIDGET_H
#define VIDEOQVKTOPENGLWIDGET_H
#include <QWidget>
#include <QVTKOpenGLWidget.h>
#include <pcl/visualization/pcl_visualizer.h>
using namespace pcl::visualization;
class VideoQVTKOpenGLWidget : public QVTKOpenGLWidget
{
public:
explicit VideoQVTKOpenGLWidget(QWidget *parent = 0);
void populateCloud(pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud);
private:
boost::shared_ptr<PCLVisualizer> _viewer;
vtkSmartPointer<vtkGenericOpenGLRenderWindow> _renderWindow;
};
#endif // VIDEOQVKTOPENGLWIDGET_H
VideoQVTKOpenGLWidget.cpp
#include "VideoQVTKOpenGLWidget.h"
#include <vtkPointPicker.h>
#include <vtkGenericOpenGLRenderWindow.h>
VideoQVTKOpenGLWidget::VideoQVTKOpenGLWidget(QWidget *parent)
: QVTKOpenGLWidget(parent)
{
auto renderer = vtkSmartPointer<vtkRenderer>::New();
_renderWindow = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
_renderWindow->AddRenderer(renderer);
_viewer.reset(new PCLVisualizer(renderer, _renderWindow, "viewer", false));
this->SetRenderWindow(_viewer->getRenderWindow());
this->update();
}
void VideoQVTKOpenGLWidget::populateCloud(pcl::PointCloud <pcl::PointXYZRGBA>::Ptr cloud)
{
if(!_viewer->updatePointCloud(cloud, "cloud")) {
_viewer->addPointCloud(cloud, "cloud");
}
_renderWindow->Render();
}
来源:https://stackoverflow.com/questions/43498363/qvtkopenglwidget-and-vtkgenericopenglrenderwindow-with-qtdesigner