Skip to content

Commit

Permalink
Added method to get point indices from ConcaveHull
Browse files Browse the repository at this point in the history
- Added method 'getHullPointIndices ()' to retrieve the indices of the
  input point cloud that form its convex hull. In some cases it is
  more convenient to work with convex hull in form of the points from
  the input point cloud (for example when it is organized) than with a
  new point cloud containing only the geometric information, but not
  the organization.
  • Loading branch information
SvenAlbrecht committed Apr 23, 2015
1 parent de5b113 commit 044b7ed
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
13 changes: 13 additions & 0 deletions surface/include/pcl/surface/concave_hull.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ namespace pcl
PCL_ERROR ("[pcl::%s::setDimension] Invalid input dimension specified!\n", getClassName ().c_str ());
}

/** \brief Retrieve the indices of the input point cloud that for the convex hull.
*
* \note Should only be called after reconstruction was performed and if the ConcaveHull is
* set to preserve information via setKeepInformation ().
*
* \param[out] hull_point_indices The indices of the points forming the point cloud
*/
void
getHullPointIndices (pcl::PointIndices &hull_point_indices) const;

protected:
/** \brief Class get name method. */
std::string
Expand Down Expand Up @@ -197,6 +207,9 @@ namespace pcl

/** \brief the dimensionality of the concave hull */
int dim_;

/** \brief vector containing the point cloud indices of the convex hull points. */
std::vector<int> hull_indices_;
};
}

Expand Down
16 changes: 11 additions & 5 deletions surface/include/pcl/surface/impl/concave_hull.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,18 +579,16 @@ pcl::ConcaveHull<PointInT>::performReconstruction (PointCloud &alpha_shape, std:
distances.resize (1);

// for each point in the concave hull, search for the nearest neighbor in the original point cloud

std::vector<int> indices;
indices.resize (alpha_shape.points.size ());
hull_indices_.reserve (alpha_shape.points.size ());

for (size_t i = 0; i < alpha_shape.points.size (); i++)
{
tree.nearestKSearch (alpha_shape.points[i], 1, neighbor, distances);
indices[i] = neighbor[0];
hull_indices_.push_back (neighbor[0]);
}

// replace point with the closest neighbor in the original point cloud
pcl::copyPointCloud (*input_, indices, alpha_shape);
pcl::copyPointCloud (*input_, hull_indices_, alpha_shape);
}
}
#ifdef __GNUC__
Expand All @@ -617,6 +615,14 @@ pcl::ConcaveHull<PointInT>::performReconstruction (std::vector<pcl::Vertices> &p
performReconstruction (hull_points, polygons);
}

//////////////////////////////////////////////////////////////////////////////////////////
template <typename PointInT> void
pcl::ConcaveHull<PointInT>::getHullPointIndices (pcl::PointIndices &hull_point_indices) const
{
hull_point_indices.indices.clear ();
hull_point_indices.indices.insert (hull_point_indices.indices.end (),
hull_indices_.begin (), hull_indices_.end ());
}

#define PCL_INSTANTIATE_ConcaveHull(T) template class PCL_EXPORTS pcl::ConcaveHull<T>;

Expand Down

0 comments on commit 044b7ed

Please sign in to comment.