@@ -88,15 +88,16 @@ struct bfs_functor {
8888};
8989
9090struct set_label_functor {
91- set_label_functor (const int *xa, int cluster, int *clusters, int *visited)
92- : xa_(xa), cluster_(cluster), clusters_(clusters), visited_(visited){};
91+ set_label_functor (const int *xa, int cluster, int *clusters, int *visited, bool is_noise )
92+ : xa_(xa), cluster_(cluster), clusters_(clusters), visited_(visited), is_noise_(is_noise) {};
9393 const int *xa_;
9494 const int cluster_;
9595 int *clusters_;
9696 int *visited_;
97+ bool is_noise_;
9798 __device__ void operator ()(size_t idx) const {
9899 if (xa_[idx] == 1 ) {
99- clusters_[idx] = cluster_;
100+ clusters_[idx] = is_noise_ ? - 1 : cluster_;
100101 visited_[idx] = 1 ;
101102 }
102103 }
@@ -146,9 +147,6 @@ std::unique_ptr<utility::device_vector<int>> PointCloud::ClusterDBSCAN(float eps
146147 for (int i = 0 ; i < n_pt; i++) {
147148 ++progress_bar;
148149 if (h_visited[i] != 1 ) {
149- thrust::fill_n (make_tuple_iterator (visited.begin () + i,
150- clusters->begin () + i),
151- 1 , thrust::make_tuple (1 , cluster));
152150 thrust::fill (make_tuple_begin (xa, fa), make_tuple_end (xa, fa),
153151 thrust::make_tuple (0 , 0 ));
154152 fa[i] = 1 ;
@@ -163,15 +161,19 @@ std::unique_ptr<utility::device_vector<int>> PointCloud::ClusterDBSCAN(float eps
163161 thrust::make_counting_iterator (n_pt),
164162 bfs_func);
165163 }
164+ const int xa_count = thrust::reduce (utility::exec_policy (0 ), xa.begin (), xa.end (),
165+ 0 , thrust::plus<int >());
166+ const bool is_noise = xa_count < min_points;
166167 set_label_functor sl_func (thrust::raw_pointer_cast (xa.data ()),
167168 cluster,
168169 thrust::raw_pointer_cast (clusters->data ()),
169- thrust::raw_pointer_cast (visited.data ()));
170+ thrust::raw_pointer_cast (visited.data ()),
171+ is_noise);
170172 thrust::for_each (thrust::make_counting_iterator<size_t >(0 ),
171173 thrust::make_counting_iterator (n_pt), sl_func);
172174 copy_device_to_host (visited, h_visited);
173175 cudaSafeCall (cudaDeviceSynchronize ());
174- cluster++;
176+ if (!is_noise) cluster++;
175177 }
176178 }
177179 return clusters;
0 commit comments