4444// ////////////////////////////////////////////////////////////////////////
4545template <typename PointT> void
4646pcl::getPointCloudDifference (
47- const pcl::PointCloud<PointT> &src,
48- const pcl::PointCloud<PointT> &,
49- double threshold, const boost::shared_ptr<pcl::search::Search<PointT> > &tree,
47+ const pcl::PointCloud<PointT> &src,
48+ double threshold,
49+ const boost::shared_ptr<pcl::search::Search<PointT> > &tree,
5050 pcl::PointCloud<PointT> &output)
5151{
5252 // We're interested in a single nearest neighbor only
5353 std::vector<int > nn_indices (1 );
5454 std::vector<float > nn_distances (1 );
5555
56- // The src indices that do not have a neighbor in tgt
56+ // The input cloud indices that do not have a neighbor in the target cloud
5757 std::vector<int > src_indices;
5858
5959 // Iterate through the source data set
6060 for (int i = 0 ; i < static_cast <int > (src.points .size ()); ++i)
6161 {
62+ // Ignore invalid points in the inpout cloud
6263 if (!isFinite (src.points [i]))
6364 continue ;
6465 // Search for the closest point in the target data set (number of neighbors to find = 1)
@@ -67,25 +68,16 @@ pcl::getPointCloudDifference (
6768 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 );
6869 continue ;
6970 }
70-
71+ // Add points without a corresponding point in the target cloud to the output cloud
7172 if (nn_distances[0 ] > threshold)
7273 src_indices.push_back (i);
7374 }
74-
75- // Allocate enough space and copy the basics
76- output.points .resize (src_indices.size ());
77- output.header = src.header ;
78- output.width = static_cast <uint32_t > (src_indices.size ());
79- output.height = 1 ;
80- // if (src.is_dense)
81- output.is_dense = true ;
82- // else
83- // It's not necessarily true that is_dense is false if cloud_in.is_dense is false
84- // To verify this, we would need to iterate over all points and check for NaNs
85- // output.is_dense = false;
8675
8776 // Copy all the data fields from the input cloud to the output one
8877 copyPointCloud (src, src_indices, output);
78+
79+ // Output is always dense, as invalid points in the input cloud are ignored
80+ output.is_dense = true ;
8981}
9082
9183// ////////////////////////////////////////////////////////////////////////
@@ -121,13 +113,12 @@ pcl::SegmentDifferences<PointT>::segment (PointCloud &output)
121113 // Send the input dataset to the spatial locator
122114 tree_->setInputCloud (target_);
123115
124- getPointCloudDifference (*input_, *target_, distance_threshold_, tree_, output);
116+ getPointCloudDifference (*input_, distance_threshold_, tree_, output);
125117
126118 deinitCompute ();
127119}
128120
129121#define PCL_INSTANTIATE_SegmentDifferences (T ) template class PCL_EXPORTS pcl::SegmentDifferences<T>;
130- #define PCL_INSTANTIATE_getPointCloudDifference (T ) template PCL_EXPORTS void pcl::getPointCloudDifference<T>(const pcl::PointCloud<T> &, const pcl::PointCloud<T> &, double , const boost::shared_ptr<pcl::search::Search<T> > &, pcl::PointCloud<T> &);
122+ #define PCL_INSTANTIATE_getPointCloudDifference (T ) template PCL_EXPORTS void pcl::getPointCloudDifference<T>(const pcl::PointCloud<T> &, double , const boost::shared_ptr<pcl::search::Search<T> > &, pcl::PointCloud<T> &);
131123
132124#endif // PCL_SEGMENTATION_IMPL_SEGMENT_DIFFERENCES_H_
133-
0 commit comments