文章目录
- 0.引言
- 1.修改两个CMakeLists.txt文件
- 2.源码编译
- 3.测试PCL
0.引言
因笔者课题涉及点云处理,需要通过PCL进行点云数据分析处理,查阅现有网络资料,实现了VisualStudio2015(x86)配置PCL1.8.1点云库(见:VisualStudio如何配置PCL点云库?)。而笔者对CloudCompare二次开发较为熟悉,希望在CloudCompare中使用PCL进行点云处理,所以本文在VS配置PCL成功的基础上,实现CloudCompare-2.10.x对PCL的配置,并记录了实现配置的过程。
1.修改两个CMakeLists.txt文件
(1)修改CloudCompare-2.10.x源文件目录下的CMakeLists.txt

# PCL
option( OPTION_BUILD_PCL "Check to add PCL 3rdParty" ON )
if ( OPTION_BUILD_PCL )
find_package(PCL REQUIRED)
include_directories( ${PCL_INCLUDE_DIRS} )
message(${PCL_INCLUDE_DIRS})
link_directories( ${PCL_LIBRARY_DIRS} )
message(${PCL_LIBRARY_DIRS})
add_definitions( ${PCL_DEFINITIONS} )
endif()(2)修改CloudCompare-2.10.x源文件的CC目录下的CMakeLists.txt
①找到CMakeLists.txt,并打开

②添加PCL配置

option( COMPILE_CC_CORE_LIB_WITH_PCL "Check to compile CC_CORE_LIB with PCL" ON) # 添加PCL配置 ③添加PCL环境

# PCL环境
if(COMPILE_CC_CORE_LIB_WITH_PCL)
find_package(PCL REQUIRED)
include_directories( ${PCL_INCLUDE_DIRS} )
#define the PCL_VER_1_8_OR_OLDER preprocessor to compile qPCL with older versions of PCL
if ( PCL_VERSION VERSION_LESS 1.8 ) # VERSION_GREATER Works just like "greater or equal"
set_property( TARGET ${PROJECT_NAME} APPEND PROPERTY COMPILE_DEFINITIONS PCL_VER_1_8_OR_OLDER )
endif()
# Luca's PCL patch support
if( PCL_VERSION VERSION_GREATER 1.7 ) #from 1.7 the patch was merged
set_property( TARGET ${PROJECT_NAME} APPEND PROPERTY COMPILE_DEFINITIONS LP_PCL_PATCH_ENABLED )
endif()
link_directories( ${PCL_LIBRARY_DIRS} )
add_definitions( ${PCL_DEFINITIONS} )
target_link_libraries( ${PROJECT_NAME} ${PCL_LIBRARIES}) #指定目标在运行时要寻找的链接库
endif()2.源码编译
在Cmake中进行配置,会生成PCL相关的文件,并勾选COMPILE_CC_CORE_LIB_WITH_PCL。


3.测试PCL
(1)修改mainwindow.ui文件
①设计按钮

②编译.ui

(2)修改mainwindow.h文件

//点云滤波
void doActionPCLUniformSample(); // 均匀采样(3)修改mainwindow.cpp文件
①添加均匀采样头文件

#include <pcl/keypoints/uniform_sampling.h> // 均匀采样②添加均匀采样实现代码

// 均匀采样
void MainWindow::doActionPCLUniformSample()
{
if (getSelectedEntities().size() != 1)
{
ccLog::Print(QStringLiteral("只能选择一个点云实体"));
return;
}
ccHObject* entity = getSelectedEntities()[0];
ccPointCloud* ccCloud = ccHObjectCaster::ToPointCloud(entity);
// ---------------------------读取数据到PCL----------------------------------
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
cloud->resize(ccCloud->size());
for (int i = 0; i < cloud->size(); ++i)
{
const CCVector3* point = ccCloud->getPoint(i);
cloud->points[i].x = point->x;
cloud->points[i].y = point->y;
cloud->points[i].z = point->z;
}
// -----------------------------对话框---------------------------------------
float radius = QInputDialog::getDouble(this, QStringLiteral("参数设置"), QStringLiteral("搜索半径: "), 0.005, 0, 100, 4);
// ----------------------------均匀采样--------------------------------------
pcl::PointCloud<pcl::PointXYZ>::Ptr filtered(new pcl::PointCloud<pcl::PointXYZ>);
pcl::UniformSampling<pcl::PointXYZ> us;
us.setInputCloud(cloud);
us.setRadiusSearch(radius);
us.filter(*filtered);
// ------------------------PCL->CloudCompare--------------------------------
if (!filtered->empty())
{
ccPointCloud* newPointCloud = new ccPointCloud(QString("UniformSample"));
for (int i = 0; i < filtered->size(); ++i)
{
double x = filtered->points[i].x;
double y = filtered->points[i].y;
double z = filtered->points[i].z;
newPointCloud->addPoint(CCVector3(x, y, z));
}
newPointCloud->setRGBColor(ccColor::Rgba(rand() % 255, rand() % 255, 0, 255));
newPointCloud->showColors(true);
if (ccCloud->getParent())
{
ccCloud->getParent()->addChild(newPointCloud);
}
ccCloud->setEnabled(false);
addToDB(newPointCloud);
refreshAll();
updateUI();
}
else
{
ccCloud->setEnabled(true);
// Display a warning message in the console
dispToConsole("Warning: example shouldn't be used as is", ccMainAppInterface::WRN_CONSOLE_MESSAGE);
}
}③添加信号槽函数

connect(m_UI->actionsample, &QAction::triggered, this, &MainWindow::doActionPCLUniformSample);(4)生成

(5)结果展示
①原始点云

②采样后的点云(相比原始点云,变稀了)

















