Skip to content

Commit df3af0a

Browse files
committed
Faster organized radius search
By checking the finite-ness of all points once, before doing any searches. This avoids calling isFinite repeatedly on the same points in radiusSearch. Benchmark: NormalEstimation with OrganizedNeighbor and radius search now takes 89 percent of the time it took before (so 11 percent faster).
1 parent 56a3172 commit df3af0a

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

search/include/pcl/search/impl/organized.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pcl::search::OrganizedNeighbor<PointT>::radiusSearch (const PointT
8282
{
8383
for (; idx < xEnd; ++idx)
8484
{
85-
if (!mask_[idx] || !isFinite ((*input_)[idx]))
85+
if (!mask_[idx])
8686
continue;
8787

8888
float dist_x = (*input_)[idx].x - query.x;

search/include/pcl/search/organized.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include <pcl/memory.h>
4343
#include <pcl/pcl_macros.h>
4444
#include <pcl/point_cloud.h>
45+
#include <pcl/common/point_tests.h> // for pcl::isFinite
4546
#include <pcl/search/search.h>
4647
#include <pcl/common/eigen.h>
4748

@@ -138,10 +139,16 @@ namespace pcl
138139
{
139140
mask_.assign (input_->size (), 0);
140141
for (const auto& idx : *indices_)
141-
mask_[idx] = 1;
142+
if (pcl::isFinite((*input_)[idx]))
143+
mask_[idx] = 1;
142144
}
143145
else
144-
mask_.assign (input_->size (), 1);
146+
{
147+
mask_.assign (input_->size (), 0);
148+
for (std::size_t idx=0; idx<input_->size(); ++idx)
149+
if (pcl::isFinite((*input_)[idx]))
150+
mask_[idx] = 1;
151+
}
145152

146153
return estimateProjectionMatrix () && isValid ();
147154
}
@@ -216,7 +223,7 @@ namespace pcl
216223
testPoint (const PointT& query, unsigned k, std::vector<Entry>& queue, index_t index) const
217224
{
218225
const PointT& point = input_->points [index];
219-
if (mask_ [index] && std::isfinite (point.x))
226+
if (mask_ [index])
220227
{
221228
//float squared_distance = (point.getVector3fMap () - query.getVector3fMap ()).squaredNorm ();
222229
float dist_x = point.x - query.x;
@@ -278,7 +285,7 @@ namespace pcl
278285
/** \brief using only a subsample of points to calculate the projection matrix. pyramid_level_ = use down sampled cloud given by pyramid_level_*/
279286
const unsigned pyramid_level_;
280287

281-
/** \brief mask, indicating whether the point was in the indices list or not.*/
288+
/** \brief mask, indicating whether the point was in the indices list or not, and whether it is finite.*/
282289
std::vector<unsigned char> mask_;
283290
public:
284291
PCL_MAKE_ALIGNED_OPERATOR_NEW

0 commit comments

Comments
 (0)