Skip to content

Commit fa9d6ad

Browse files
authored
Merge pull request #5997 from mvieth/radius_search_sorted_results
Only skip first result of radiusSearch if results are sorted
2 parents 0ed704a + cc9bcfc commit fa9d6ad

File tree

8 files changed

+38
-13
lines changed

8 files changed

+38
-13
lines changed

features/include/pcl/features/impl/cvfh.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ pcl::CVFHEstimation<PointInT, PointNT, PointOutT>::extractEuclideanClustersSmoot
9696
static_cast<std::size_t>(normals.size()));
9797
return;
9898
}
99+
// If tree gives sorted results, we can skip the first one because it is the query point itself
100+
const std::size_t nn_start_idx = tree->getSortedResults () ? 1 : 0;
99101

100102
// Create a bool vector of processed point indices, and initialize it to false
101103
std::vector<bool> processed (cloud.size (), false);
@@ -124,8 +126,7 @@ pcl::CVFHEstimation<PointInT, PointNT, PointOutT>::extractEuclideanClustersSmoot
124126
continue;
125127
}
126128

127-
// skip index 0, since nn_indices[0] == idx, worth it?
128-
for (std::size_t j = 1; j < nn_indices.size (); ++j)
129+
for (std::size_t j = nn_start_idx; j < nn_indices.size (); ++j)
129130
{
130131
if (processed[nn_indices[j]]) // Has this point been processed before ?
131132
continue;

features/include/pcl/features/impl/our_cvfh.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ pcl::OURCVFHEstimation<PointInT, PointNT, PointOutT>::extractEuclideanClustersSm
9797
static_cast<std::size_t>(normals.size()));
9898
return;
9999
}
100+
// If tree gives sorted results, we can skip the first one because it is the query point itself
101+
const std::size_t nn_start_idx = tree->getSortedResults () ? 1 : 0;
100102

101103
// Create a bool vector of processed point indices, and initialize it to false
102104
std::vector<bool> processed (cloud.size (), false);
@@ -124,7 +126,7 @@ pcl::OURCVFHEstimation<PointInT, PointNT, PointOutT>::extractEuclideanClustersSm
124126
continue;
125127
}
126128

127-
for (std::size_t j = 1; j < nn_indices.size (); ++j) // nn_indices[0] should be sq_idx
129+
for (std::size_t j = nn_start_idx; j < nn_indices.size (); ++j)
128130
{
129131
if (processed[nn_indices[j]]) // Has this point been processed before ?
130132
continue;

kdtree/include/pcl/kdtree/kdtree.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,15 @@ namespace pcl
332332
return (min_pts_);
333333
}
334334

335+
/** \brief Gets whether the results should be sorted (ascending in the distance) or not
336+
* Otherwise the results may be returned in any order.
337+
*/
338+
inline bool
339+
getSortedResults () const
340+
{
341+
return (sorted_);
342+
}
343+
335344
protected:
336345
/** \brief The input point cloud dataset containing the points we need to use. */
337346
PointCloudConstPtr input_;

recognition/include/pcl/recognition/impl/hv/hv_go.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ inline void extractEuclideanClustersSmooth(const typename pcl::PointCloud<PointT
6161
PCL_ERROR("[pcl::extractEuclideanClusters] Number of points in the input point cloud different than normals!\n");
6262
return;
6363
}
64+
// If tree gives sorted results, we can skip the first one because it is the query point itself
65+
const std::size_t nn_start_idx = tree->getSortedResults () ? 1 : 0;
6466

6567
// Create a bool vector of processed point indices, and initialize it to false
6668
std::vector<bool> processed (cloud.size (), false);
@@ -96,7 +98,7 @@ inline void extractEuclideanClustersSmooth(const typename pcl::PointCloud<PointT
9698
continue;
9799
}
98100

99-
for (std::size_t j = 1; j < nn_indices.size (); ++j) // nn_indices[0] should be sq_idx
101+
for (std::size_t j = nn_start_idx; j < nn_indices.size (); ++j)
100102
{
101103
if (processed[nn_indices[j]]) // Has this point been processed before ?
102104
continue;

segmentation/include/pcl/segmentation/extract_clusters.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ namespace pcl
123123
static_cast<std::size_t>(normals.size()));
124124
return;
125125
}
126+
// If tree gives sorted results, we can skip the first one because it is the query point itself
127+
const std::size_t nn_start_idx = tree->getSortedResults () ? 1 : 0;
126128
const double cos_eps_angle = std::cos (eps_angle); // compute this once instead of acos many times (faster)
127129

128130
// Create a bool vector of processed point indices, and initialize it to false
@@ -151,7 +153,7 @@ namespace pcl
151153
continue;
152154
}
153155

154-
for (std::size_t j = 1; j < nn_indices.size (); ++j) // nn_indices[0] should be sq_idx
156+
for (std::size_t j = nn_start_idx; j < nn_indices.size (); ++j)
155157
{
156158
if (processed[nn_indices[j]]) // Has this point been processed before ?
157159
continue;
@@ -243,6 +245,8 @@ namespace pcl
243245
static_cast<std::size_t>(normals.size()));
244246
return;
245247
}
248+
// If tree gives sorted results, we can skip the first one because it is the query point itself
249+
const std::size_t nn_start_idx = tree->getSortedResults () ? 1 : 0;
246250
const double cos_eps_angle = std::cos (eps_angle); // compute this once instead of acos many times (faster)
247251
// Create a bool vector of processed point indices, and initialize it to false
248252
std::vector<bool> processed (cloud.size (), false);
@@ -270,7 +274,7 @@ namespace pcl
270274
continue;
271275
}
272276

273-
for (std::size_t j = 1; j < nn_indices.size (); ++j) // nn_indices[0] should be sq_idx
277+
for (std::size_t j = nn_start_idx; j < nn_indices.size (); ++j)
274278
{
275279
if (processed[nn_indices[j]]) // Has this point been processed before ?
276280
continue;

segmentation/include/pcl/segmentation/impl/conditional_euclidean_clustering.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,13 @@ pcl::ConditionalEuclideanClustering<PointT>::segment (pcl::IndicesClusters &clus
6060
if (!searcher_)
6161
{
6262
if (input_->isOrganized ())
63-
searcher_.reset (new pcl::search::OrganizedNeighbor<PointT> ());
63+
searcher_.reset (new pcl::search::OrganizedNeighbor<PointT> (false)); // not requiring sorted results is much faster
6464
else
65-
searcher_.reset (new pcl::search::KdTree<PointT> ());
65+
searcher_.reset (new pcl::search::KdTree<PointT> (false)); // not requiring sorted results is much faster
6666
}
6767
searcher_->setInputCloud (input_, indices_);
68+
// If searcher_ gives sorted results, we can skip the first one because it is the query point itself
69+
const int nn_start_idx = searcher_->getSortedResults () ? 1 : 0;
6870

6971
// Temp variables used by search class
7072
Indices nn_indices;
@@ -100,7 +102,7 @@ pcl::ConditionalEuclideanClustering<PointT>::segment (pcl::IndicesClusters &clus
100102
}
101103

102104
// Process the neighbors
103-
for (int nii = 1; nii < static_cast<int> (nn_indices.size ()); ++nii) // nii = neighbor indices iterator
105+
for (int nii = nn_start_idx; nii < static_cast<int> (nn_indices.size ()); ++nii) // nii = neighbor indices iterator
104106
{
105107
// Has this point been processed before?
106108
if (nn_indices[nii] == UNAVAILABLE || processed[nn_indices[nii]])

segmentation/include/pcl/segmentation/impl/extract_labeled_clusters.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ pcl::extractLabeledEuclideanClusters(
5757
cloud.size());
5858
return;
5959
}
60+
// If tree gives sorted results, we can skip the first one because it is the query point itself
61+
const std::size_t nn_start_idx = tree->getSortedResults () ? 1 : 0;
6062
// Create a bool vector of processed point indices, and initialize it to false
6163
std::vector<bool> processed(cloud.size(), false);
6264

@@ -88,8 +90,7 @@ pcl::extractLabeledEuclideanClusters(
8890
continue;
8991
}
9092

91-
for (std::size_t j = 1; j < nn_indices.size();
92-
++j) // nn_indices[0] should be sq_idx
93+
for (std::size_t j = nn_start_idx; j < nn_indices.size(); ++j)
9394
{
9495
if (processed[nn_indices[j]]) // Has this point been processed before ?
9596
continue;

segmentation/include/pcl/segmentation/impl/seeded_hue_segmentation.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ pcl::seededHueSegmentation (const PointCloud<PointXYZRGB> &cloud,
6161
static_cast<std::size_t>(cloud.size()));
6262
return;
6363
}
64+
// If tree gives sorted results, we can skip the first one because it is the query point itself
65+
const std::size_t nn_start_idx = tree->getSortedResults () ? 1 : 0;
6466
// Create a bool vector of processed point indices, and initialize it to false
6567
std::vector<bool> processed (cloud.size (), false);
6668

@@ -96,7 +98,7 @@ pcl::seededHueSegmentation (const PointCloud<PointXYZRGB> &cloud,
9698
continue;
9799
}
98100

99-
for (std::size_t j = 1; j < nn_indices.size (); ++j) // nn_indices[0] should be sq_idx
101+
for (std::size_t j = nn_start_idx; j < nn_indices.size (); ++j)
100102
{
101103
if (processed[nn_indices[j]]) // Has this point been processed before ?
102104
continue;
@@ -139,6 +141,8 @@ pcl::seededHueSegmentation (const PointCloud<PointXYZRGB> &cloud,
139141
static_cast<std::size_t>(cloud.size()));
140142
return;
141143
}
144+
// If tree gives sorted results, we can skip the first one because it is the query point itself
145+
const std::size_t nn_start_idx = tree->getSortedResults () ? 1 : 0;
142146
// Create a bool vector of processed point indices, and initialize it to false
143147
std::vector<bool> processed (cloud.size (), false);
144148

@@ -173,7 +177,7 @@ pcl::seededHueSegmentation (const PointCloud<PointXYZRGB> &cloud,
173177
sq_idx++;
174178
continue;
175179
}
176-
for (std::size_t j = 1; j < nn_indices.size (); ++j) // nn_indices[0] should be sq_idx
180+
for (std::size_t j = nn_start_idx; j < nn_indices.size (); ++j)
177181
{
178182
if (processed[nn_indices[j]]) // Has this point been processed before ?
179183
continue;

0 commit comments

Comments
 (0)