template <typename PointT> void pcl::getPointCloudDifference ( const pcl::PointCloud<PointT> &src, const pcl::PointCloud<PointT> &, double threshold, const boost::shared_ptr<pcl::search::Search<PointT> > &tree, pcl::PointCloud<PointT> &output) { // We're interested in a single nearest neighbor only std::vector<int> nn_indices (1); std::vector<float> nn_distances (1); // The src indices that do not have a neighbor in tgt std::vector<int> src_indices; // Iterate through the source data set for (int i = 0; i < static_cast<int> (src.points.size ()); ++i) { if (!isFinite (src.points[i])) continue; // Search for the closest point in the target data set (number of neighbors to find = 1) if (!tree->nearestKSearch (src.points[i], 1, nn_indices, nn_distances)) { PCL_WARN ("No neighbor found for point %zu (%f %f %f)!\n", i, src.points[i].x, src.points[i].y, src.points[i].z); continue; } if (nn_distances[0] > threshold) src_indices.push_back (i); } // Allocate enough space and copy the basics output.points.resize (src_indices.size ()); output.header = src.header; output.width = static_cast<uint32_t> (src_indices.size ()); output.height = 1; //if (src.is_dense) output.is_dense = true; //else // It's not necessarily true that is_dense is false if cloud_in.is_dense is false // To verify this, we would need to iterate over all points and check for NaNs //output.is_dense = false; // Copy all the data fields from the input cloud to the output one typedef typename pcl::traits::fieldList<PointT>::type FieldList; // Iterate over each point for (size_t i = 0; i < src_indices.size (); ++i) // Iterate over each dimension pcl::for_each_type <FieldList> (NdConcatenateFunctor <PointT, PointT> (src.points[src_indices[i]], output.points[i])); }
template <typename PointSource, typename PointTarget, typename FeatureT> void pcl::SampleConsensusInitialAlignment<PointSource, PointTarget, FeatureT>::findSimilarFeatures ( const FeatureCloud &input_features, const std::vector<int> &sample_indices, std::vector<int> &corresponding_indices) { std::vector<int> nn_indices (k_correspondences_); std::vector<float> nn_distances (k_correspondences_); corresponding_indices.resize (sample_indices.size ()); for (size_t i = 0; i < sample_indices.size (); ++i) { // Find the k features nearest to input_features.points[sample_indices[i]] feature_tree_->nearestKSearch (input_features, sample_indices[i], k_correspondences_, nn_indices, nn_distances); // Select one at random and add it to corresponding_indices int random_correspondence = getRandomIndex (k_correspondences_); corresponding_indices[i] = nn_indices[random_correspondence]; } }
template <typename PointT> void pcl::getPointCloudDifference ( const pcl::PointCloud<PointT> &src, double threshold, const typename pcl::search::Search<PointT>::Ptr &tree, pcl::PointCloud<PointT> &output) { // We're interested in a single nearest neighbor only std::vector<int> nn_indices (1); std::vector<float> nn_distances (1); // The input cloud indices that do not have a neighbor in the target cloud std::vector<int> src_indices; // Iterate through the source data set for (int i = 0; i < static_cast<int> (src.points.size ()); ++i) { // Ignore invalid points in the inpout cloud if (!isFinite (src.points[i])) continue; // Search for the closest point in the target data set (number of neighbors to find = 1) if (!tree->nearestKSearch (src.points[i], 1, nn_indices, nn_distances)) { PCL_WARN ("No neighbor found for point %lu (%f %f %f)!\n", i, src.points[i].x, src.points[i].y, src.points[i].z); continue; } // Add points without a corresponding point in the target cloud to the output cloud if (nn_distances[0] > threshold) src_indices.push_back (i); } // Copy all the data fields from the input cloud to the output one copyPointCloud (src, src_indices, output); // Output is always dense, as invalid points in the input cloud are ignored output.is_dense = true; }