38 #ifndef PCL_FILTERS_IMPL_RANDOM_SAMPLE_H_
39 #define PCL_FILTERS_IMPL_RANDOM_SAMPLE_H_
41 #include <pcl/filters/random_sample.h>
42 #include <pcl/common/io.h>
43 #include <pcl/point_traits.h>
47 template<
typename Po
intT>
void
50 std::vector<int> indices;
53 bool temp = extract_removed_indices_;
54 extract_removed_indices_ =
true;
55 applyFilter (indices);
56 extract_removed_indices_ = temp;
59 const auto fields = pcl::getFields<PointT> ();
60 std::vector<std::size_t> offsets;
61 for (
const auto &field : fields)
63 if (field.name ==
"x" ||
66 offsets.push_back (field.offset);
69 const static float user_filter_value = user_filter_value_;
70 for (
const auto ri : *removed_indices_)
73 for (
const unsigned long &offset : offsets)
75 memcpy (pt_data + offset, &user_filter_value,
sizeof (
float));
78 if (!std::isfinite (user_filter_value_))
84 applyFilter (indices);
90 template<
typename Po
intT>
94 std::size_t N = indices_->size ();
95 std::size_t sample_size = negative_ ? N - sample_ : sample_;
101 removed_indices_->clear ();
106 indices.resize (sample_size);
107 if (extract_removed_indices_)
108 removed_indices_->resize (N - sample_size);
115 std::size_t index = 0;
116 std::vector<bool> added;
117 if (extract_removed_indices_)
118 added.resize (indices_->size (),
false);
119 std::size_t n = sample_size;
123 const float U = unifRand ();
128 if (extract_removed_indices_)
130 indices[i++] = (*indices_)[index];
141 if (extract_removed_indices_)
144 for (std::size_t i = 0; i < added.size (); i++)
148 (*removed_indices_)[ri++] = (*indices_)[i];
155 #define PCL_INSTANTIATE_RandomSample(T) template class PCL_EXPORTS pcl::RandomSample<T>;
157 #endif // PCL_FILTERS_IMPL_RANDOM_SAMPLE_H_