qvtkWidget的点云显示使用实例(在QT中显示点云)

头文件QVTK.h

#pragma once
#include 
#include "ui_QVTK.h"
#include 
#include 
#include
#include
#include

class QVTK : public QWidget
{
	Q_OBJECT
public:
	QVTK(QWidget *parent = Q_NULLPTR);
	~QVTK();
private:
	Ui::QVTK ui;
	pcl::PointCloud::Ptr cloud;
	boost::shared_ptr viewer;
	void initialVtkWidget();
private slots:
	void onOpen();

};

 源文件QVTK.cpp

#include "QVTK.h"
using namespace std;
QVTK::QVTK(QWidget *parent)
	: QWidget(parent)
{
	ui.setupUi(this);
	initialVtkWidget();
}

QVTK::~QVTK()
{
}

void QVTK::initialVtkWidget()
{
	cloud.reset(new pcl::PointCloud);
	viewer.reset(new pcl::visualization::PCLVisualizer("viewer", false));
	viewer->addPointCloud(cloud, "cloud");
	ui.qvtkWidget->SetRenderWindow(viewer->getRenderWindow());
	viewer->setupInteractor(ui.qvtkWidget->GetInteractor(), ui.qvtkWidget->GetRenderWindow());
	ui.qvtkWidget->update();

}


void QVTK::onOpen()
{
	QString fileName = QFileDialog::getOpenFileName(this, "Open PointCloud", ".", "Open PCD files(*.pcd)");
	pcl::io::loadPCDFile(fileName.toStdString(), *cloud);
	viewer->updatePointCloud(cloud, "cloud");
	viewer->resetCamera();
	ui.qvtkWidget->update();
}




QT中ui界面

qvtkWidget的点云显示使用实例(在QT中显示点云)_第1张图片

实现:

qvtkWidget的点云显示使用实例(在QT中显示点云)_第2张图片

你可能感兴趣的:(c++,开发语言)