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 std::vector<pcl::PCLPointField> fields;
61 std::vector<size_t> offsets;
62 for (
size_t i = 0; i < fields.size (); ++i)
64 if (fields[i].name ==
"x" ||
65 fields[i].name ==
"y" ||
66 fields[i].name ==
"z")
67 offsets.push_back (fields[i].offset);
70 const static float user_filter_value = user_filter_value_;
71 for (
size_t rii = 0; rii < removed_indices_->size (); ++rii)
73 uint8_t* pt_data =
reinterpret_cast<uint8_t*
> (&output[(*removed_indices_)[rii]]);
74 for (
size_t i = 0; i < offsets.size (); ++i)
76 memcpy (pt_data + offsets[i], &user_filter_value,
sizeof (
float));
78 if (!pcl_isfinite (user_filter_value_))
85 applyFilter (indices);
91 template<
typename Po
intT>
95 unsigned N =
static_cast<unsigned> (indices_->size ());
97 unsigned int sample_size = negative_ ? N - sample_ : sample_;
100 if (sample_size >= N)
103 removed_indices_->clear ();
108 indices.resize (static_cast<size_t> (sample_size));
109 if (extract_removed_indices_)
110 removed_indices_->resize (static_cast<size_t> (N - sample_size));
116 unsigned top = N - sample_size;
119 std::vector<bool> added;
120 if (extract_removed_indices_)
121 added.resize (indices_->size (),
false);
122 for (
size_t n = sample_size; n >= 2; n--)
124 float V = unifRand ();
126 float quot =
static_cast<float> (top) / static_cast<float> (N);
132 quot = quot *
static_cast<float> (top) / static_cast<float> (N);
135 if (extract_removed_indices_)
137 indices[i++] = (*indices_)[index++];
141 index += N *
static_cast<unsigned> (unifRand ());
142 if (extract_removed_indices_)
144 indices[i++] = (*indices_)[index++];
147 if (extract_removed_indices_)
150 for (
size_t i = 0; i < added.size (); i++)
154 (*removed_indices_)[ri++] = (*indices_)[i];
161 #define PCL_INSTANTIATE_RandomSample(T) template class PCL_EXPORTS pcl::RandomSample<T>;
163 #endif // PCL_FILTERS_IMPL_RANDOM_SAMPLE_H_
PCL_EXPORTS void copyPointCloud(const pcl::PCLPointCloud2 &cloud_in, const std::vector< int > &indices, pcl::PCLPointCloud2 &cloud_out)
Extract the indices of a given point cloud as a new point cloud.
void getFields(const pcl::PointCloud< PointT > &cloud, std::vector< pcl::PCLPointField > &fields)
Get the list of available fields (i.e., dimension/channel)
bool is_dense
True if no points are invalid (e.g., have NaN or Inf values).
void applyFilter(PointCloud &output)
Sample of point indices into a separate PointCloud.