我正在尝试在QVTKOpenGLWidget
的QTDesigner中使用vtkGenericOpenGlRenderWindow
,但我获得了一个黑色窗口。当我使用PCLVizualizer
PointCloud Library(PCL)和vtkGenericOpenGlRenderWindow
时,一切正常。我正在尝试以与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;
}
谢谢
编辑: 删除“Interactor”解决了我的问题。
答案 0 :(得分:4)
您需要获取PCL的主版本https://github.com/PointCloudLibrary/pcl。这将为PCLVisualizer提供更多构造函数。因此,您可以使用这样的自定义小部件:
<强> 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();
}