PointCloudLibrary / pcl

Point Cloud Library (PCL)
https://pointclouds.org/
Other
10.04k stars 4.62k forks source link

Why not use CropBox inside CropHull? #3875

Open DaniilSNikulin opened 4 years ago

DaniilSNikulin commented 4 years ago

CropHull<PointT>::filter Ω (n * m) CropBox<PointT>::filter O (n)

Where n - size of filtered point cloud, m - size of hull cloud. To find bounding box for CropBox need O (m) time.

In my practical case using CropBox before CropHull significantly reduces runtime. So why not always use CropBox inside CropHull?

This function is a template, which could be embed in CropHull.

template <class PointT>
std::vector<int>
filter(pcl::CropHull<PointT> & cropHullFilter, pcl::PointCloud<PointT>::ConstPtr bigCloudPtr, bool cropOutside = true)
{
    // just because pcl::CropHull haven't got getCropOutside() function
    cropHullFilter.setCropOutside(cropOutside);
    // cropOutside = cropHullFilter.getCropOutside();

    std::vector<int> cropInlierIndices;
    Eigen::Vector4f minPt, maxPt;
    pcl::getMinMax3D(*cropHullFilter.getHullCloud(), minPt, maxPt);
    pcl::CropBox<pcl::PointXYZ> cropBoxFilter(true);
    cropBoxFilter.setMin(minPt);
    cropBoxFilter.setMax(maxPt);
    cropBoxFilter.setInputCloud(bigCloudPtr);
    cropBoxFilter.filter(cropInlierIndices);
    pcl::PointCloud<PointT>::Ptr croppedCloudPtr(new pcl::PointCloud<PointT>);
    pcl::copyPointCloud(*rootCloudPtr, cropInlierIndices, *croppedCloudPtr);

    std::vector<int> filteredInlierIndices;
    cropHullFilter.setInputCloud(croppedCloudPtr);
    cropHullFilter.filter(filteredInlierIndices);

    std::vector<int> inlierIndices;
    if (!cropOutside) {
        for (int idx : cropBoxFilter.getRemovedIndices()) {
            inlierIndices.push_back(idx);
        }
    }
    for (int idx : filteredInlierIndices) {
        inlierIndices.push_back(cropInlierIndices[idx]);
    }
    return inlierIndices;
}
SergioRAgostinho commented 4 years ago

Interesting suggestion and worth looking into.

stale[bot] commented 4 years ago

Marking this as stale due to 30 days of inactivity. It will be closed in 7 days if no further activity occurs.