00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef PCL_SEGMENTATION_IMPL_SEGMENT_DIFFERENCES_H_
00039 #define PCL_SEGMENTATION_IMPL_SEGMENT_DIFFERENCES_H_
00040
00041 #include "pcl/segmentation/segment_differences.h"
00042 #include "pcl/io/io.h"
00043
00045 template <typename PointT> void
00046 pcl::getPointCloudDifference (
00047 const pcl::PointCloud<PointT> &src,
00048 const pcl::PointCloud<PointT> &tgt,
00049 double threshold, const boost::shared_ptr<pcl::KdTree<PointT> > &tree,
00050 pcl::PointCloud<PointT> &output)
00051 {
00052
00053 std::vector<int> nn_indices (1);
00054 std::vector<float> nn_distances (1);
00055
00056
00057 std::vector<int> src_indices;
00058
00059
00060 for (size_t i = 0; i < src.points.size (); ++i)
00061 {
00062
00063 if (!tree->nearestKSearch (src.points[i], 1, nn_indices, nn_distances))
00064 {
00065 ROS_WARN ("No neighbor found for point %zu (%f %f %f)!", i, src.points[i].x, src.points[i].y, src.points[i].z);
00066 continue;
00067 }
00068
00069 if (nn_distances[0] > threshold)
00070 src_indices.push_back (i);
00071 }
00072
00073 copyPointCloud (src, src_indices, output);
00074 }
00075
00079 template <typename PointT> void
00080 pcl::SegmentDifferences<PointT>::segment (PointCloud &output)
00081 {
00082 output.header = input_->header;
00083
00084 if (!initCompute ())
00085 {
00086 output.width = output.height = 0;
00087 output.points.clear ();
00088 return;
00089 }
00090
00091
00092 if (target_->points.empty ())
00093 {
00094 output = *input_;
00095 return;
00096 }
00097
00098
00099 initTree (spatial_locator_, tree_);
00100
00101 tree_->setInputCloud (target_);
00102
00103 getPointCloudDifference (*input_, *target_, distance_threshold_, tree_, output);
00104
00105 deinitCompute ();
00106 }
00107
00108 #define PCL_INSTANTIATE_SegmentDifferences(T) template class pcl::SegmentDifferences<T>;
00109 #define PCL_INSTANTIATE_getPointCloudDifference(T) template void pcl::getPointCloudDifference<T>(const pcl::PointCloud<T> &, const pcl::PointCloud<T> &, double, const boost::shared_ptr<pcl::KdTree<T> > &, pcl::PointCloud<T> &);
00110
00111 #endif // PCL_SEGMENTATION_IMPL_SEGMENT_DIFFERENCES_H_
00112