38 #ifndef PCL_FILTERS_IMPL_NORMAL_SPACE_SAMPLE_H_
39 #define PCL_FILTERS_IMPL_NORMAL_SPACE_SAMPLE_H_
41 #include <pcl/filters/normal_space.h>
47 template<
typename Po
intT,
typename NormalT>
bool
54 if (sample_ >= input_->size ())
56 PCL_ERROR (
"[NormalSpaceSampling::initCompute] Requested more samples than the input cloud size: %d vs %lu\n",
57 sample_, input_->size ());
66 template<
typename Po
intT,
typename NormalT>
bool
68 unsigned int start_index,
72 for (
unsigned int i = start_index; i < start_index + length; i++)
74 status &= array.test (i);
80 template<
typename Po
intT,
typename NormalT>
unsigned int
83 const unsigned ix =
static_cast<unsigned> (std::round (0.5f * (binsx_ - 1.f) * (normal[0] + 1.f)));
84 const unsigned iy =
static_cast<unsigned> (std::round (0.5f * (binsy_ - 1.f) * (normal[1] + 1.f)));
85 const unsigned iz =
static_cast<unsigned> (std::round (0.5f * (binsz_ - 1.f) * (normal[2] + 1.f)));
86 return ix * (binsy_*binsz_) + iy * binsz_ + iz;
90 template<
typename Po
intT,
typename NormalT>
void
99 unsigned int max_values = (std::min) (sample_,
static_cast<unsigned int> (input_normals_->size ()));
101 indices.resize (max_values);
102 removed_indices_->resize (max_values);
105 unsigned int n_bins = binsx_ * binsy_ * binsz_;
108 std::vector<std::list <int> > normals_hg;
109 normals_hg.reserve (n_bins);
110 for (
unsigned int i = 0; i < n_bins; i++)
111 normals_hg.emplace_back();
113 for (
const auto index : *indices_)
115 unsigned int bin_number = findBin ((*input_normals_)[index].normal);
116 normals_hg[bin_number].push_back (index);
122 std::vector<std::vector<std::list<int>::iterator> > random_access (normals_hg.size ());
123 for (std::size_t i = 0; i < normals_hg.size (); i++)
125 random_access.emplace_back();
126 random_access[i].resize (normals_hg[i].size ());
129 for (std::list<int>::iterator itr = normals_hg[i].begin (); itr != normals_hg[i].end (); ++itr, ++j)
130 random_access[i][j] = itr;
132 std::vector<std::size_t> start_index (normals_hg.size ());
134 std::size_t prev_index = 0;
135 for (std::size_t i = 1; i < normals_hg.size (); i++)
137 start_index[i] = prev_index + normals_hg[i-1].size ();
138 prev_index = start_index[i];
142 boost::dynamic_bitset<> is_sampled_flag (input_normals_->size ());
144 boost::dynamic_bitset<> bin_empty_flag (normals_hg.size ());
149 for (std::size_t j = 0; j < normals_hg.size (); j++)
151 unsigned int M =
static_cast<unsigned int> (normals_hg[j].size ());
152 if (M == 0 || bin_empty_flag.test (j))
155 unsigned int pos = 0;
156 unsigned int random_index = 0;
157 std::uniform_int_distribution<unsigned> rng_uniform_distribution (0u, M - 1u);
162 random_index = rng_uniform_distribution (rng_);
163 pos = start_index[j] + random_index;
164 }
while (is_sampled_flag.test (pos));
166 is_sampled_flag.flip (start_index[j] + random_index);
169 if (isEntireBinSampled (is_sampled_flag, start_index[j],
static_cast<unsigned int> (normals_hg[j].size ())))
170 bin_empty_flag.flip (j);
172 unsigned int index = *(random_access[j][random_index]);
181 if (extract_removed_indices_)
183 Indices indices_temp = indices;
184 std::sort (indices_temp.begin (), indices_temp.end ());
186 Indices all_indices_temp = *indices_;
187 std::sort (all_indices_temp.begin (), all_indices_temp.end ());
188 set_difference (all_indices_temp.begin (), all_indices_temp.end (),
189 indices_temp.begin (), indices_temp.end (),
190 inserter (*removed_indices_, removed_indices_->begin ()));
194 #define PCL_INSTANTIATE_NormalSpaceSampling(T,NT) template class PCL_EXPORTS pcl::NormalSpaceSampling<T,NT>;
FilterIndices represents the base class for filters that are about binary point removal.
NormalSpaceSampling samples the input point cloud in the space of normal directions computed at every...
void applyFilter(Indices &indices) override
Sample of point indices.
IndicesAllocator<> Indices
Type used for indices in PCL.