我有巨大的点云,我想在其上应用体素网格。但是由于点云太大,我有错误,例如 [pcl::VoxelGrid::applyFilter] Leaf size is too small for the input dataset. Integer indices would overflow"
。所以我想先从我的点云构建一个八叉树,然后在每个叶子上应用过滤器(即在具有良好索引的点云上应用过滤器)
问题出现在这里,当我应用过滤器时,PCL 要我选择一个将保存它的点云,并将原始点云替换为过滤器的结果。我想知道是否可以修改过滤器,使其不删除点,而只将必须删除的点云中索引处的点放入 (0,0,0)?
我的代码:
void Octree::applyExample(float x, float y, float z) {
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
// Fill in the cloud data
cloud->width = 100000;
cloud->height = 1;
cloud->is_dense = false;
cloud->points.resize(cloud->width * cloud->height);
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);
}
octree.setInputCloud(cloud);
octree.addPointsFromInputCloud();
pcl::octree::OctreePointCloud<pcl::PointXYZRGB>::LeafNodeIterator it;
pcl::octree::OctreePointCloud<pcl::PointXYZRGB>::LeafNodeIterator it_end = octree.leaf_end();
for (it = octree.leaf_begin(); it != it_end; ++it)
{
pcl::IndicesPtr indexVector(new vector<int>);
pcl::octree::OctreeContainerPointIndices& container = it.getLeafContainer();
container.getPointIndices(*indexVector);
FILTREexample(cloud, indexVector, x, y, z);
}
}
和过滤器:
void FILTREexample(pcl::PointCloud<pcl::PointXYZ>::Ptr pointcloud, pcl::IndicesPtr indices, float x, float y, float z) {
pcl::VoxelGrid<pcl::PointXYZ> sor;
sor.setInputCloud(pointcloud);
sor.setIndices(indices);
sor.setLeafSize(x, y, z);
sor.filter(*pointcloud); //The problem occurs here
//Everytime, the pointcloud is substituted with the result of the filter, but I'd like to still have my "entire" pointcloud, but either with the filtered point deleted, or the filtered point put to 0,0,0.
}
有没有可能做这样的事情?
最佳答案
您的原始点云正在被替换,因为它正是您通过编写“告诉”PCL 执行的操作:sor.filter(*pointcloud);
过滤方法的参数是“输出云”。您可以传递一个空云,过滤结果将保存到其中。 (输入已通过 setInputCloud
定义)
因此您可以将 FILTERExamples 重写为:
pcl::PointCloud<pcl::PointXYZ>::Ptr FILTREexample(pcl::PointCloud<pcl::PointXYZ>::Ptr pointcloud, pcl::IndicesPtr indices, float x, float y, float z) {
pcl::PointCloud<pcl::PointXYZ>::Ptr filtered_pointcloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::VoxelGrid<pcl::PointXYZ> sor;
sor.setInputCloud(pointcloud);
sor.setIndices(indices);
sor.setLeafSize(x, y, z);
sor.filter(*filtered_pointcloud); // No problem :)
return filtered_pointcloud;
}
applyExample 只会连接 clouds :
void Octree::applyExample(float x, float y, float z) {
... // no change
pcl::PointCloud<pcl::PointXYZ>::Ptr filtered_cloud(new pcl::PointCloud<pcl::PointXYZ>);
for (it = octree.leaf_begin(); it != it_end; ++it)
{
pcl::IndicesPtr indexVector(new vector<int>);
pcl::octree::OctreeContainerPointIndices& container = it.getLeafContainer();
container.getPointIndices(*indexVector);
*filtered_cloud += *FILTREexample(cloud, indexVector, x,y,z);
}
}
关于c++ - PCL 在没有云复制的情况下对八叉树应用过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53265873/