pcl::ProjectInliers

类ProjectInliers使用一个模型和一组内点索引,将内点投影到模型形成一个新的独立点云。

#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/ModelCoefficients.h>
#include <pcl/filters/project_inliers.h>

int
main(int argc, char** argv)
{
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
    pcl::PointCloud<pcl::PointXYZ>::Ptr
// 投影滤波器 void MainWindow::doActionPCLProjectInliers() { 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.1, 0, 100, 4); // ----------------------------投影滤波器-------------------------------------- //创建 x+y+z=0 平面 pcl::ModelCoefficients::Ptr coefficients(new pcl::ModelCoefficients()); coefficients->values.resize(4); //设置模型系数的大小 coefficients->values[0] = 1.0; //x系数 coefficients->values[1] = 1.0; //y系数 coefficients->values[2] = 1.0; //z系数 coefficients->values[3] = 0.0; //常数项 //投影滤波 pcl::PointCloud<pcl::PointXYZ>::Ptr filtered(new pcl::PointCloud<pcl::PointXYZ>); pcl::ProjectInliers<pcl::PointXYZ> us; us.setModelType(pcl::SACMODEL_PLANE); //设置对象对应的投影模型 us.setInputCloud(cloud); //设置输入点云 us.setModelCoefficients(coefficients);//设置模型对应的系数 us.filter(*filtered); // ------------------------PCL->CloudCompare-------------------------------- if (!filtered->empty()) { ccPointCloud* newPointCloud = new ccPointCloud(QString("ProjectInliers")); 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(255, 255, 255, 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); } } 提供代码绘制的关键函数关系图,图中使用中文注释关键步骤和函数调用关系
07-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值