koide3 / small_gicp

Efficient and parallel algorithms for point cloud registration [C++, Python]
MIT License
419 stars 51 forks source link

small_gicp::RegistrationPCL<pcl::PointXYZ, pcl::PointXYZ> reg.getFitnessScore(); error... #88

Closed InguChoi closed 1 month ago

InguChoi commented 2 months ago

Describe the bug I used the function getFitnessScore(); in the small_gicp::RegistrationPCL<pcl::PointXYZ, pcl::PointXYZ> reg;. It can be builded successfully, but It can not be operated..

The error results is below in the terminal.

/usr/local/include/pcl-1.14/pcl/kdtree/impl/kdtree_flann.hpp:239: int pcl::KdTreeFLANN<PointT, Dist>::nearestKSearch(const PointT&, unsigned int, pcl::Indices&, std::vector&) const [with PointT = pcl::PointXYZ; Dist = flann::L2_Simple; pcl::Indices = std::vector]: Assertion `pointrepresentation->isValid (point) && "Invalid (NaN, Inf) point coordinates given to nearestKSearch!"' failed.

Environment (please complete the following information):

Xiangzhaohong commented 2 months ago

removeNAN for the input clouds first?

InguChoi commented 1 month ago

removeNAN for the input clouds first?

Your comment is right.

The point cloud data from my bag file is needed to pre-processing such as NAN, INFINITE.

inline void removeNaNAndInfinitePoints(pcl::PointCloud<pcl::PointXYZ>::Ptr& cloud)
{
    pcl::PointCloud<pcl::PointXYZ>::Ptr filtered_cloud(new pcl::PointCloud<pcl::PointXYZ>());
    int valid_points = 0;

    for (const auto& point : cloud->points) {
        if (std::isfinite(point.x) && std::isfinite(point.y) && std::isfinite(point.z)) {
            filtered_cloud->points.push_back(point); 
            valid_points++;
        }
    }
    cloud.swap(filtered_cloud);
}
koide3 commented 1 month ago

FYI: pcl::removeNaNFromPointCloud would be useful for this purpose. https://pointclouds.org/documentation/group__filters.html#ga9de762e05951938f074479c3bf8ae084