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 #include "pcl/impl/instantiate.hpp"
00039 #include "pcl/point_types.h"
00040 #include "pcl/filters/extract_indices.h"
00041 #include "pcl/filters/impl/extract_indices.hpp"
00042
00044 void
00045 pcl::ExtractIndices<sensor_msgs::PointCloud2>::applyFilter (PointCloud2 &output)
00046 {
00047 if (indices_->empty ())
00048 {
00049 output.width = output.height = 0;
00050 output.data.clear ();
00051
00052 if (negative_)
00053 output = *input_;
00054 return;
00055 }
00056 if (indices_->size () == (input_->width * input_->height))
00057 {
00058 output = *input_;
00059 return;
00060 }
00061
00062
00063 output.is_bigendian = input_->is_bigendian;
00064 output.point_step = input_->point_step;
00065 output.height = 1;
00066
00067 output.is_dense = false;
00068
00069 if (negative_)
00070 {
00071
00072 std::vector<int> all_indices (input_->width * input_->height);
00073 for (size_t i = 0; i < all_indices.size (); ++i)
00074 all_indices[i] = i;
00075
00076 std::vector<int> indices = *indices_;
00077 std::sort (indices.begin (), indices.end ());
00078
00079
00080 std::vector<int> remaining_indices;
00081 set_difference (all_indices.begin (), all_indices.end (), indices.begin (), indices.end (),
00082 inserter (remaining_indices, remaining_indices.begin ()));
00083
00084
00085 output.width = remaining_indices.size ();
00086 output.data.resize (remaining_indices.size () * output.point_step);
00087 for (size_t i = 0; i < remaining_indices.size (); ++i)
00088 memcpy (&output.data[i * output.point_step], &input_->data[remaining_indices[i] * output.point_step], output.point_step);
00089 }
00090 else
00091 {
00092
00093 output.width = indices_->size ();
00094 output.data.resize (indices_->size () * output.point_step);
00095 for (size_t i = 0; i < indices_->size (); ++i)
00096 memcpy (&output.data[i * output.point_step], &input_->data[(*indices_)[i] * output.point_step], output.point_step);
00097 }
00098 output.row_step = output.point_step * output.width;
00099 }
00100
00101 PCL_INSTANTIATE(ExtractIndices, PCL_XYZ_POINT_TYPES);
00102 PCL_INSTANTIATE(ExtractIndices, (pcl::Normal));
00103 PCL_INSTANTIATE(ExtractIndices, (pcl::MomentInvariants)(pcl::Boundary)(pcl::PrincipalCurvatures)(pcl::IntensityGradient));
00104
00105
00106
00107
00108
00109
00110
00111
00112