《PCL点云库学习&VS2010(X64)》Part 6 VTK6.2+VS2013+Qt5.5 测试VTK基于VS2013的Qt程序之PCLViewer

Part 6 VTK6.2+VS2013+Qt5.5 测试VTK基于VS2013的Qt程序之PCLViewer                                                  

          接着上一篇,为了简便,我自己重新编译了VTK6.2的源码库,因为PCL1.7.2自带的VTK版本为6.2,所以为了减少兼容性带来的一堆问题,我自己去CSDN下了源码,官网的只看到VTK6.3.0和VTK5.10.1的,没办法,github也没找到6.2版本的。

       其次,我在PCL1.8+Qt5+VS2013可视化点云这篇博文的评论链接资源中下载了他的源文件PCLVisualizer,其中较为有用的是属性表文件pcl1.props,通过修改他的环境属性表文件,让计算机的配置和PCL VTK QT VS2013这些路径集中起来,环境配置好了,以后的编程只需要拷贝过来,在解决方案资源管理器、类视图、属性管理器这行导航栏中的属性管理器中的debug|Win32中导入属性表(如果你属性表用的是VTK release版的库的话,你就在Release|Win32中加,因为编译的库分debug和release版,不然编译会报错,所以自己编译时最好做两个属性表,随时备用即可)。

           最后,把编译的VTK6.2中lib文件夹中debug里的库全部拷到C:\Windows\SysWOW64中(我电脑64位win7,32位的是system32哪个文件夹),这个和设置系统变量一样重要。

1、新建一个VS下的Qt程序,QApplication,命名为PCLViewer :


(1)配置属性->VC++目录->包含目录(类似于自己安装OpenNI后就应用安装的OpenNI目录,PCL自带的VTK目录就没有加了,下面的库目录同样如此):

D:\Qt\Qt5.5.0\5.5\msvc2013\include;$(PCL_ROOT)\include\pcl-1.7;$(PCL_ROOT)\3rdParty\Boost\include\boost-1_57;$(PCL_ROOT)\3rdParty\Eigen\eigen3;$(PCL_ROOT)\3rdParty\FLANN\include;$(PCL_ROOT)\3rdParty\QHull\include;D:\VTK6.2\include\vtk-6.2;D:\OpenNI\Include;$(IncludePath)

(2)配置属性->VC++目录->库目录(说明见上一条):

D:\Qt\Qt5.5.0\5.5\msvc2013\lib;$(PCL_ROOT)\lib;$(PCL_ROOT)\3rdParty\Boost\lib;$(PCL_ROOT)\3rdParty\FLANN\lib;$(PCL_ROOT)\3rdParty\QHull\lib;D:\VTK6.2\lib\Debug;D:\OpenNI\Lib;$(LibraryPath)

(3)C++->附加包含目录(其实这个是在环境变量中设置的,然后在每个新建的Qt项目中都会自动添加进来,具体设置见上一篇文章):

.\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtWidgets;%(AdditionalIncludeDirectories)

(4)链接器->常规->附加库目录(这个同上一条,说明环境变量很重要的,不能马虎):

$(QTDIR)\lib;%(AdditionalLibraryDirectories)

(5)链接器->常规->输入(主要是PCL 和其中的第三方库,VTK库没用PCL自带的,用的是自己编译的,这个要注意):

QVTKWidgetPlugin.lib;pcl_common_debug.lib;pcl_features_debug.lib;pcl_filters_debug.lib;pcl_io_debug.lib;pcl_io_ply_debug.lib;pcl_kdtree_debug.lib;pcl_keypoints_debug.lib;pcl_octree_debug.lib;pcl_outofcore_debug.lib;pcl_people_debug.lib;pcl_recognition_debug.lib;pcl_registration_debug.lib;pcl_sample_consensus_debug.lib;pcl_search_debug.lib;pcl_segmentation_debug.lib;pcl_surface_debug.lib;pcl_tracking_debug.lib;pcl_visualization_debug.lib;libboost_atomic-vc120-mt-gd-1_57.lib;libboost_chrono-vc120-mt-gd-1_57.lib;libboost_container-vc120-mt-gd-1_57.lib;libboost_context-vc120-mt-gd-1_57.lib;libboost_coroutine-vc120-mt-gd-1_57.lib;libboost_date_time-vc120-mt-gd-1_57.lib;libboost_exception-vc120-mt-gd-1_57.lib;libboost_filesystem-vc120-mt-gd-1_57.lib;libboost_graph-vc120-mt-gd-1_57.lib;libboost_iostreams-vc120-mt-gd-1_57.lib;libboost_locale-vc120-mt-gd-1_57.lib;libboost_log-vc120-mt-gd-1_57.lib;libboost_log_setup-vc120-mt-gd-1_57.lib;libboost_math_c99-vc120-mt-gd-1_57.lib;libboost_math_c99f-vc120-mt-gd-1_57.lib;libboost_math_c99l-vc120-mt-gd-1_57.lib;libboost_math_tr1-vc120-mt-gd-1_57.lib;libboost_math_tr1f-vc120-mt-gd-1_57.lib;libboost_math_tr1l-vc120-mt-gd-1_57.lib;libboost_mpi-vc120-mt-gd-1_57.lib;libboost_prg_exec_monitor-vc120-mt-gd-1_57.lib;libboost_program_options-vc120-mt-gd-1_57.lib;libboost_random-vc120-mt-gd-1_57.lib;libboost_regex-vc120-mt-gd-1_57.lib;libboost_serialization-vc120-mt-gd-1_57.lib;libboost_signals-vc120-mt-gd-1_57.lib;libboost_system-vc120-mt-gd-1_57.lib;libboost_test_exec_monitor-vc120-mt-gd-1_57.lib;libboost_thread-vc120-mt-gd-1_57.lib;libboost_timer-vc120-mt-gd-1_57.lib;libboost_unit_test_framework-vc120-mt-gd-1_57.lib;libboost_wave-vc120-mt-gd-1_57.lib;libboost_wserialization-vc120-mt-gd-1_57.lib;flann_cpp_s-gd.lib;flann_s-gd.lib;flann-gd.lib;qhull_d.lib;qhull_p_d.lib;qhullcpp_d.lib;qhullstatic_p_d.lib;qhullstatic_d.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;vtkalglib-6.2.lib;vtkChartsCore-6.2.lib;vtkCommonColor-6.2.lib;vtkCommonComputationalGeometry-6.2.lib;vtkCommonCore-6.2.lib;vtkCommonDataModel-6.2.lib;vtkCommonExecutionModel-6.2.lib;vtkCommonMath-6.2.lib;vtkCommonMisc-6.2.lib;vtkCommonSystem-6.2.lib;vtkCommonTransforms-6.2.lib;vtkDICOMParser-6.2.lib;vtkDomainsChemistry-6.2.lib;vtkexoIIc-6.2.lib;vtkexpat-6.2.lib;vtkFiltersAMR-6.2.lib;vtkFiltersCore-6.2.lib;vtkFiltersExtraction-6.2.lib;vtkFiltersFlowPaths-6.2.lib;vtkFiltersGeneral-6.2.lib;vtkFiltersGeneric-6.2.lib;vtkFiltersGeometry-6.2.lib;vtkFiltersHybrid-6.2.lib;vtkFiltersHyperTree-6.2.lib;vtkFiltersImaging-6.2.lib;vtkFiltersModeling-6.2.lib;vtkFiltersParallel-6.2.lib;vtkFiltersParallelImaging-6.2.lib;vtkFiltersProgrammable-6.2.lib;vtkFiltersSelection-6.2.lib;vtkFiltersSMP-6.2.lib;vtkFiltersSources-6.2.lib;vtkFiltersStatistics-6.2.lib;vtkFiltersTexture-6.2.lib;vtkFiltersVerdict-6.2.lib;vtkfreetype-6.2.lib;vtkftgl-6.2.lib;vtkGeovisCore-6.2.lib;vtkgl2ps-6.2.lib;vtkGUISupportQt-6.2.lib;vtkGUISupportQtOpenGL-6.2.lib;vtkGUISupportQtSQL-6.2.lib;vtkGUISupportQtWebkit-6.2.lib;vtkhdf5-6.2.lib;vtkhdf5_hl-6.2.lib;vtkImagingColor-6.2.lib;vtkImagingCore-6.2.lib;vtkImagingFourier-6.2.lib;vtkImagingGeneral-6.2.lib;vtkImagingHybrid-6.2.lib;vtkImagingMath-6.2.lib;vtkImagingMorphological-6.2.lib;vtkImagingSources-6.2.lib;vtkImagingStatistics-6.2.lib;vtkImagingStencil-6.2.lib;vtkInfovisCore-6.2.lib;vtkInfovisLayout-6.2.lib;vtkInteractionImage-6.2.lib;vtkInteractionStyle-6.2.lib;vtkInteractionWidgets-6.2.lib;vtkIOAMR-6.2.lib;vtkIOCore-6.2.lib;vtkIOEnSight-6.2.lib;vtkIOExodus-6.2.lib;vtkIOExport-6.2.lib;vtkIOGeometry-6.2.lib;vtkIOImage-6.2.lib;vtkIOImport-6.2.lib;vtkIOInfovis-6.2.lib;vtkIOLegacy-6.2.lib;vtkIOLSDyna-6.2.lib;vtkIOMINC-6.2.lib;vtkIOMovie-6.2.lib;vtkIONetCDF-6.2.lib;vtkIOParallel-6.2.lib;vtkIOParallelXML-6.2.lib;vtkIOPLY-6.2.lib;vtkIOSQL-6.2.lib;vtkIOVideo-6.2.lib;vtkIOXML-6.2.lib;vtkIOXMLParser-6.2.lib;vtkjpeg-6.2.lib;vtkjsoncpp-6.2.lib;vtklibxml2-6.2.lib;vtkmetaio-6.2.lib;vtkNetCDF-6.2.lib;vtkNetCDF_cxx-6.2.lib;vtkoggtheora-6.2.lib;vtkParallelCore-6.2.lib;vtkpng-6.2.lib;vtkproj4-6.2.lib;vtkRenderingAnnotation-6.2.lib;vtkRenderingContext2D-6.2.lib;vtkRenderingContextOpenGL-6.2.lib;vtkRenderingCore-6.2.lib;vtkRenderingFreeType-6.2.lib;vtkRenderingFreeTypeOpenGL-6.2.lib;vtkRenderingGL2PS-6.2.lib;vtkRenderingImage-6.2.lib;vtkRenderingLabel-6.2.lib;vtkRenderingLIC-6.2.lib;vtkRenderingLOD-6.2.lib;vtkRenderingOpenGL-6.2.lib;vtkRenderingQt-6.2.lib;vtkRenderingVolume-6.2.lib;vtkRenderingVolumeOpenGL-6.2.lib;vtksqlite-6.2.lib;vtksys-6.2.lib;vtktiff-6.2.lib;vtkverdict-6.2.lib;vtkViewsContext2D-6.2.lib;vtkViewsCore-6.2.lib;vtkViewsInfovis-6.2.lib;vtkViewsQt-6.2.lib;vtkzlib-6.2.lib;%(AdditionalDependencies)


2、PCLViewer程序调试,官网文章来源

(1)界面设计(注意信号与槽):


(2)pclviewer.h

///

注:

#include <vtkAutoInit.h>     
VTK_MODULE_INIT(vtkRenderingOpenGL);
VTK_MODULE_INIT(vtkInteractionStyle);
//VTK_MODULE_INIT(vtkRenderingFreeType);

这几句是VTK6版本以后需要带上的,不然编译出错。

///

#ifndef PCLVIEWER_H
#define PCLVIEWER_H

#include <vtkAutoInit.h>     
VTK_MODULE_INIT(vtkRenderingOpenGL);
VTK_MODULE_INIT(vtkInteractionStyle);
//VTK_MODULE_INIT(vtkRenderingFreeType);

#include <iostream>

// Qt
#include <QtWidgets/QMainWindow>
#include "ui_pclviewer.h"

// Point Cloud Library
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/visualization/pcl_visualizer.h>

// Visualization Toolkit (VTK)
#include <vtkRenderWindow.h>

typedef pcl::PointXYZRGBA PointT;
typedef pcl::PointCloud<PointT> PointCloudT;

namespace Ui
{
	class PCLViewer;
}

class PCLViewer : public QMainWindow
{
	Q_OBJECT

public:
	PCLViewer(QWidget *parent = 0);
	~PCLViewer();

public slots:
	void
		randomButtonPressed();

	void
		RGBsliderReleased();

	void
		pSliderValueChanged(int value);

	void
		redSliderValueChanged(int value);

	void
		greenSliderValueChanged(int value);

	void
		blueSliderValueChanged(int value);

protected:
	boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer;
	PointCloudT::Ptr cloud;

	unsigned int red;
	unsigned int green;
	unsigned int blue;

private:
	Ui::PCLViewerClass ui;
};

#endif // PCLVIEWER_H

(3)pclviewer.cpp

///

注:看到头文件中的Ui.PCLViewerClass ui;这句没,是没有指针的,这个是Qt5自己生成的,不需要改,我们只需要注意就好,官网给的是有指针的,那么在cpp文件中,所有的ui->都要替换成ui.了。

///

#include "pclviewer.h"

#include "ui_pclviewer.h"

PCLViewer::PCLViewer(QWidget *parent)
	: QMainWindow(parent)
{
	ui.setupUi(this);

	this->setWindowTitle("PCL viewer");

	// Setup the cloud pointer
	cloud.reset(new PointCloudT);
	// The number of points in the cloud
	cloud->points.resize(2000);

	// The default color
	red = 128;
	green = 128;
	blue = 128;

	// Fill the cloud with some points
	for (size_t i = 0; i < cloud->points.size(); ++i)
	{
		cloud->points[i].x = 1024 * rand() / (RAND_MAX + 1.0f);
		cloud->points[i].y = 1024 * rand() / (RAND_MAX + 1.0f);
		cloud->points[i].z = 1024 * rand() / (RAND_MAX + 1.0f);

		cloud->points[i].r = red;
		cloud->points[i].g = green;
		cloud->points[i].b = blue;
	}

	// Set up the QVTK window
	viewer.reset(new pcl::visualization::PCLVisualizer("viewer", false));
	ui.qvtkWidget->SetRenderWindow(viewer->getRenderWindow());
	viewer->setupInteractor(ui.qvtkWidget->GetInteractor(), ui.qvtkWidget->GetRenderWindow());
	ui.qvtkWidget->update();

	// Connect "random" button and the function
	connect(ui.pushButton_random, SIGNAL(clicked()), this, SLOT(randomButtonPressed()));

	// Connect R,G,B sliders and their functions
	connect(ui.horizontalSlider_R, SIGNAL(valueChanged(int)), this, SLOT(redSliderValueChanged(int)));
	connect(ui.horizontalSlider_G, SIGNAL(valueChanged(int)), this, SLOT(greenSliderValueChanged(int)));
	connect(ui.horizontalSlider_B, SIGNAL(valueChanged(int)), this, SLOT(blueSliderValueChanged(int)));
	connect(ui.horizontalSlider_R, SIGNAL(sliderReleased()), this, SLOT(RGBsliderReleased()));
	connect(ui.horizontalSlider_G, SIGNAL(sliderReleased()), this, SLOT(RGBsliderReleased()));
	connect(ui.horizontalSlider_B, SIGNAL(sliderReleased()), this, SLOT(RGBsliderReleased()));

	// Connect point size slider
	connect(ui.horizontalSlider_p, SIGNAL(valueChanged(int)), this, SLOT(pSliderValueChanged(int)));

	viewer->addPointCloud(cloud, "cloud");
	pSliderValueChanged(2);
	viewer->resetCamera();
	ui.qvtkWidget->update();
}

void
PCLViewer::randomButtonPressed()
{
	printf("Random button was pressed\n");

	// Set the new color
	for (size_t i = 0; i < cloud->size(); i++)
	{
		cloud->points[i].r = 255 * (1024 * rand() / (RAND_MAX + 1.0f));
		cloud->points[i].g = 255 * (1024 * rand() / (RAND_MAX + 1.0f));
		cloud->points[i].b = 255 * (1024 * rand() / (RAND_MAX + 1.0f));
	}

	viewer->updatePointCloud(cloud, "cloud");
	ui.qvtkWidget->update();
}

void
PCLViewer::RGBsliderReleased()
{
	// Set the new color
	for (size_t i = 0; i < cloud->size(); i++)
	{
		cloud->points[i].r = red;
		cloud->points[i].g = green;
		cloud->points[i].b = blue;
	}
	viewer->updatePointCloud(cloud, "cloud");
	ui.qvtkWidget->update();
}

void
PCLViewer::pSliderValueChanged(int value)
{
	viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, value, "cloud");
	ui.qvtkWidget->update();
}

void
PCLViewer::redSliderValueChanged(int value)
{
	red = value;
	printf("redSliderValueChanged: [%d|%d|%d]\n", red, green, blue);
}

void
PCLViewer::greenSliderValueChanged(int value)
{
	green = value;
	printf("greenSliderValueChanged: [%d|%d|%d]\n", red, green, blue);
}

void
PCLViewer::blueSliderValueChanged(int value)
{
	blue = value;
	printf("blueSliderValueChanged: [%d|%d|%d]\n", red, green, blue);
}

PCLViewer::~PCLViewer()
{

}

(4)mian.cpp

///

注:就加个头文件,貌似可以不加,其他的不变。

///


#include "pclviewer.h"
#include <QtWidgets/QApplication>

int main(int argc, char *argv[])
{
	QApplication a(argc, argv);
	PCLViewer w;
	w.show();
	return a.exec();
}

3、运行:


  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 22
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 22
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值