Go to the documentation of this file.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
00039
00040 #ifndef PCL_FILTERS_IMPL_EXTRACT_INDICES_HPP_
00041 #define PCL_FILTERS_IMPL_EXTRACT_INDICES_HPP_
00042
00043 #include <pcl/filters/extract_indices.h>
00044 #include <pcl/common/io.h>
00045
00047 template <typename PointT> void
00048 pcl::ExtractIndices<PointT>::filterDirectly (PointCloudPtr &cloud)
00049 {
00050 std::vector<int> indices;
00051 bool temp = extract_removed_indices_;
00052 extract_removed_indices_ = true;
00053 this->setInputCloud (cloud);
00054 applyFilterIndices (indices);
00055 extract_removed_indices_ = temp;
00056
00057 std::vector<sensor_msgs::PointField> fields;
00058 pcl::for_each_type<FieldList> (pcl::detail::FieldAdder<PointT> (fields));
00059 for (int rii = 0; rii < static_cast<int> (removed_indices_->size ()); ++rii)
00060 {
00061 uint8_t* pt_data = reinterpret_cast<uint8_t*> (&cloud->points[(*removed_indices_)[rii]]);
00062 for (int fi = 0; fi < static_cast<int> (fields.size ()); ++fi)
00063 memcpy (pt_data + fields[fi].offset, &user_filter_value_, sizeof (float));
00064 }
00065 if (!pcl_isfinite (user_filter_value_))
00066 cloud->is_dense = false;
00067 }
00068
00070 template <typename PointT> void
00071 pcl::ExtractIndices<PointT>::applyFilter (PointCloud &output)
00072 {
00073 std::vector<int> indices;
00074 if (keep_organized_)
00075 {
00076 bool temp = extract_removed_indices_;
00077 extract_removed_indices_ = true;
00078 applyFilterIndices (indices);
00079 extract_removed_indices_ = temp;
00080
00081 output = *input_;
00082 std::vector<sensor_msgs::PointField> fields;
00083 pcl::for_each_type<FieldList> (pcl::detail::FieldAdder<PointT> (fields));
00084 for (int rii = 0; rii < static_cast<int> (removed_indices_->size ()); ++rii)
00085 {
00086 uint8_t* pt_data = reinterpret_cast<uint8_t*> (&output.points[(*removed_indices_)[rii]]);
00087 for (int fi = 0; fi < static_cast<int> (fields.size ()); ++fi)
00088 memcpy (pt_data + fields[fi].offset, &user_filter_value_, sizeof (float));
00089 }
00090 if (!pcl_isfinite (user_filter_value_))
00091 output.is_dense = false;
00092 }
00093 else
00094 {
00095 applyFilterIndices (indices);
00096 copyPointCloud (*input_, indices, output);
00097 }
00098 }
00099
00101 template <typename PointT> void
00102 pcl::ExtractIndices<PointT>::applyFilterIndices (std::vector<int> &indices)
00103 {
00104 if (indices_->size () > input_->points.size ())
00105 {
00106 PCL_ERROR ("[pcl::%s::applyFilter] The indices size exceeds the size of the input.\n", getClassName ().c_str ());
00107 indices.clear ();
00108 removed_indices_->clear ();
00109 return;
00110 }
00111
00112 if (!negative_)
00113 {
00114 indices = *indices_;
00115
00116 if (extract_removed_indices_)
00117 {
00118
00119 std::vector<int> full_indices (input_->points.size ());
00120 for (int fii = 0; fii < static_cast<int> (full_indices.size ()); ++fii)
00121 full_indices[fii] = fii;
00122
00123
00124 std::vector<int> sorted_input_indices = *indices_;
00125 std::sort (sorted_input_indices.begin (), sorted_input_indices.end ());
00126
00127
00128 removed_indices_->clear ();
00129 set_difference (full_indices.begin (), full_indices.end (), sorted_input_indices.begin (), sorted_input_indices.end (), inserter (*removed_indices_, removed_indices_->begin ()));
00130 }
00131 }
00132 else
00133 {
00134
00135 std::vector<int> full_indices (input_->points.size ());
00136 for (int fii = 0; fii < static_cast<int> (full_indices.size ()); ++fii)
00137 full_indices[fii] = fii;
00138
00139
00140 std::vector<int> sorted_input_indices = *indices_;
00141 std::sort (sorted_input_indices.begin (), sorted_input_indices.end ());
00142
00143
00144 indices.clear ();
00145 set_difference (full_indices.begin (), full_indices.end (), sorted_input_indices.begin (), sorted_input_indices.end (), inserter (indices, indices.begin ()));
00146
00147 if (extract_removed_indices_)
00148 removed_indices_ = indices_;
00149 }
00150 }
00151
00152 #define PCL_INSTANTIATE_ExtractIndices(T) template class PCL_EXPORTS pcl::ExtractIndices<T>;
00153
00154 #endif // PCL_FILTERS_IMPL_EXTRACT_INDICES_HPP_
00155