| 65 | } |
| 66 | |
| 67 | void |
| 68 | compute (const pcl::PCLPointCloud2::ConstPtr &cloud_source, const pcl::PCLPointCloud2::ConstPtr &cloud_target, |
| 69 | pcl::PCLPointCloud2 &output, const std::string &correspondence_type) |
| 70 | { |
| 71 | PointCloud<PointXYZ>::Ptr xyz_source (new PointCloud<PointXYZ> ()); |
| 72 | fromPCLPointCloud2 (*cloud_source, *xyz_source); |
| 73 | PointCloud<PointXYZ>::Ptr xyz_target (new PointCloud<PointXYZ> ()); |
| 74 | fromPCLPointCloud2 (*cloud_target, *xyz_target); |
| 75 | |
| 76 | PointCloud<PointXYZI>::Ptr output_xyzi (new PointCloud<PointXYZI> ()); |
| 77 | output_xyzi->points.resize (xyz_source->size ()); |
| 78 | output_xyzi->height = cloud_source->height; |
| 79 | output_xyzi->width = cloud_source->width; |
| 80 | |
| 81 | float rmse = 0.0f; |
| 82 | |
| 83 | if (correspondence_type == "index") |
| 84 | { |
| 85 | // print_highlight (stderr, "Computing using the equal indices correspondence heuristic.\n"); |
| 86 | |
| 87 | if (xyz_source->size () != xyz_target->size ()) |
| 88 | { |
| 89 | print_error ("Source and target clouds do not have the same number of points.\n"); |
| 90 | return; |
| 91 | } |
| 92 | |
| 93 | for (std::size_t point_i = 0; point_i < xyz_source->size (); ++point_i) |
| 94 | { |
| 95 | if (!std::isfinite ((*xyz_source)[point_i].x) || !std::isfinite ((*xyz_source)[point_i].y) || !std::isfinite ((*xyz_source)[point_i].z)) |
| 96 | continue; |
| 97 | if (!std::isfinite ((*xyz_target)[point_i].x) || !std::isfinite ((*xyz_target)[point_i].y) || !std::isfinite ((*xyz_target)[point_i].z)) |
| 98 | continue; |
| 99 | |
| 100 | |
| 101 | float dist = squaredEuclideanDistance ((*xyz_source)[point_i], (*xyz_target)[point_i]); |
| 102 | rmse += dist; |
| 103 | |
| 104 | (*output_xyzi)[point_i].x = (*xyz_source)[point_i].x; |
| 105 | (*output_xyzi)[point_i].y = (*xyz_source)[point_i].y; |
| 106 | (*output_xyzi)[point_i].z = (*xyz_source)[point_i].z; |
| 107 | (*output_xyzi)[point_i].intensity = dist; |
| 108 | } |
| 109 | rmse = std::sqrt (rmse / static_cast<float> (xyz_source->size ())); |
| 110 | } |
| 111 | else if (correspondence_type == "nn") |
| 112 | { |
| 113 | // print_highlight (stderr, "Computing using the nearest neighbor correspondence heuristic.\n"); |
| 114 | |
| 115 | KdTreeFLANN<PointXYZ>::Ptr tree (new KdTreeFLANN<PointXYZ> ()); |
| 116 | tree->setInputCloud (xyz_target); |
| 117 | |
| 118 | for (std::size_t point_i = 0; point_i < xyz_source->size (); ++ point_i) |
| 119 | { |
| 120 | if (!std::isfinite ((*xyz_source)[point_i].x) || !std::isfinite ((*xyz_source)[point_i].y) || !std::isfinite ((*xyz_source)[point_i].z)) |
| 121 | continue; |
| 122 | |
| 123 | pcl::Indices nn_indices (1); |
| 124 | std::vector<float> nn_distances (1); |
no test coverage detected