Skip to content

Commit

Permalink
Merge pull request #109 from sdmiller/fix_clustering
Browse files Browse the repository at this point in the history
Fixed clustering logic
  • Loading branch information
rbrusu committed Jun 2, 2013
2 parents 9692990 + 80b699d commit 850652f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
7 changes: 7 additions & 0 deletions search/include/pcl/search/impl/search.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ pcl::search::Search<PointT>::setSortedResults (bool sorted)
{
sorted_results_ = sorted;
}

///////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> bool
pcl::search::Search<PointT>::getSortedResults ()
{
return (sorted_results_);
}

///////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> void
Expand Down
7 changes: 7 additions & 0 deletions search/include/pcl/search/search.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ namespace pcl
*/
virtual void
setSortedResults (bool sorted);

/** \brief Gets whether the results should be sorted (ascending in the distance) or not
* Otherwise the results may be returned in any order.
*/
virtual bool
getSortedResults ();


/** \brief Pass the input dataset that the search will be performed on.
* \param[in] cloud a const pointer to the PointCloud data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ pcl::extractEuclideanClusters (const PointCloud<PointT> &cloud,
PCL_ERROR ("[pcl::extractEuclideanClusters] Tree built for a different point cloud dataset (%zu) than the input cloud (%zu)!\n", tree->getInputCloud ()->points.size (), cloud.points.size ());
return;
}
// Check if the tree is sorted -- if it is we don't need to check the first element
int nn_start_idx = tree->getSortedResults () ? 1 : 0;
// Create a bool vector of processed point indices, and initialize it to false
std::vector<bool> processed (cloud.points.size (), false);

Expand All @@ -79,7 +81,7 @@ pcl::extractEuclideanClusters (const PointCloud<PointT> &cloud,
continue;
}

for (size_t j = 1; j < nn_indices.size (); ++j) // nn_indices[0] should be sq_idx
for (size_t j = nn_start_idx; j < nn_indices.size (); ++j) // can't assume sorted (default isn't!)
{
if (nn_indices[j] == -1 || processed[nn_indices[j]]) // Has this point been processed before ?
continue;
Expand Down Expand Up @@ -132,6 +134,8 @@ pcl::extractEuclideanClusters (const PointCloud<PointT> &cloud,
PCL_ERROR ("[pcl::extractEuclideanClusters] Tree built for a different set of indices (%zu) than the input set (%zu)!\n", tree->getIndices ()->size (), indices.size ());
return;
}
// Check if the tree is sorted -- if it is we don't need to check the first element
int nn_start_idx = tree->getSortedResults () ? 1 : 0;

// Create a bool vector of processed point indices, and initialize it to false
std::vector<bool> processed (cloud.points.size (), false);
Expand Down Expand Up @@ -165,7 +169,7 @@ pcl::extractEuclideanClusters (const PointCloud<PointT> &cloud,
continue;
}

for (size_t j = 1; j < nn_indices.size (); ++j) // nn_indices[0] should be sq_idx
for (size_t j = nn_start_idx; j < nn_indices.size (); ++j) // can't assume sorted (default isn't!)
{
if (nn_indices[j] == -1 || processed[nn_indices[j]]) // Has this point been processed before ?
continue;
Expand Down

0 comments on commit 850652f

Please sign in to comment.