Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added method to get point indices from convex_hull #1213

Merged
merged 1 commit into from
Apr 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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. */
pcl::PointIndices hull_indices_;
};
}

Expand Down
11 changes: 11 additions & 0 deletions surface/include/pcl/surface/convex_hull.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ namespace pcl
return (dimension_);
}

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

protected:
/** \brief The actual reconstruction method.
*
Expand Down Expand Up @@ -255,6 +263,9 @@ namespace pcl
/* \brief z-axis - for checking valid projections. */
const Eigen::Vector3d z_axis_;

/* \brief vector containing the point cloud indices of the convex hull points. */
pcl::PointIndices hull_indices_;

public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};
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,18 @@ 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_.header = input_->header;
hull_indices_.indices.clear ();
hull_indices_.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_.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_.indices, alpha_shape);
}
}
#ifdef __GNUC__
Expand All @@ -617,6 +617,12 @@ 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 = hull_indices_;
}

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

Expand Down
20 changes: 18 additions & 2 deletions surface/include/pcl/surface/impl/convex_hull.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,13 @@ pcl::ConvexHull<PointInT>::performReconstruction2D (PointCloud &hull, std::vecto
polygons.resize (1);
polygons[0].vertices.resize (hull.points.size ());

hull_indices_.header = input_->header;
hull_indices_.indices.clear ();
hull_indices_.indices.reserve (hull.points.size ());

for (int j = 0; j < static_cast<int> (hull.points.size ()); j++)
{
hull_indices_.indices.push_back ((*indices_)[idx_points[j].first]);
hull.points[j] = input_->points[(*indices_)[idx_points[j].first]];
polygons[0].vertices[j] = static_cast<unsigned int> (j);
}
Expand Down Expand Up @@ -357,10 +362,15 @@ pcl::ConvexHull<PointInT>::performReconstruction3D (
++max_vertex_id;
std::vector<int> qhid_to_pcidx (max_vertex_id);

hull_indices_.header = input_->header;
hull_indices_.indices.clear ();
hull_indices_.indices.reserve (num_vertices);

FORALLvertices
{
// Add vertices to hull point_cloud
hull.points[i] = input_->points[(*indices_)[qh_pointid (vertex->point)]];
// Add vertices to hull point_cloud and store index
hull_indices_.indices.push_back ((*indices_)[qh_pointid (vertex->point)]);
hull.points[i] = input_->points[(*indices_)[hull_indices_.indices.back ()]];

qhid_to_pcidx[vertex->id] = i; // map the vertex id of qhull to the point cloud index
++i;
Expand Down Expand Up @@ -481,6 +491,12 @@ pcl::ConvexHull<PointInT>::reconstruct (PointCloud &points, std::vector<pcl::Ver

deinitCompute ();
}
//////////////////////////////////////////////////////////////////////////
template <typename PointInT> void
pcl::ConvexHull<PointInT>::getHullPointIndices (pcl::PointIndices &hull_point_indices) const
{
hull_point_indices = hull_indices_;
}

#define PCL_INSTANTIATE_ConvexHull(T) template class PCL_EXPORTS pcl::ConvexHull<T>;

Expand Down