删除给定框内的点云

Removing point clouds inside a given box

我想实现一个代码,我可以在其中删除给定框内点云的某些点。这是我目前所拥有的:

void removePoints(){

    pcl::CropBox<pcl::PointXYZI> boxFilter;
    float x_min = -0.15, y_min = -0.5, z_min = -0.7;
    float x_max = +1, y_max = +2, z_max = +5;
    boxFilter.setMin(Eigen::Vector4f(x_min, y_min, z_min, 1.0));
    boxFilter.setMax(Eigen::Vector4f(x_max, y_max, z_max, 1.0));

    boxFilter.setInputCloud(cloud);
    boxFilter.filter(*newCloud);

    viewer->removeAllPointClouds();

    cloudLabel=new int[newCloud->size()];
    memset(cloudLabel, 0, newCloud->size()*sizeof(int));

    ui->label_filename->setText(QString::fromStdString(pointcloudFileName));
    colorHandler.setInputCloud(newCloud);
    colorHandler.setLabel(cloudLabel);
    viewer->addPointCloud<PointT>(newCloud,colorHandler,"cloud",0);


    viewer->resetCamera();
    viewer->updatePointCloud<PointT>(newCloud,"cloud");

    ui->qvtkWidget->update();


    std::cout<<"Removal done"<<std::endl;
    viewer->addCube(x_min, x_max, y_min, y_max, z_min, z_max, 1, 0, 0, "cube");
    viewer->setShapeRenderingProperties(pcl::visualization::PCL_VISUALIZER_COLOR,
    0.7, 0.7, 0, "cube");
     viewer->setRepresentationToWireframeForAllActors();
}

此代码删除框外的点而不是框内的点。有没有办法反转 pcl::CropBox 过程?

PCL中几乎所有的过滤器都继承pcl::FilterIndices,这里暴露了函数setNegative
使用boxFilter.setNegative(true)过滤框内的点.