# How can I construct convex hull from point cloud?

I want to construct convex hull from point cloud, but it gave error. I am new in PCL. Below my sample code is given. The line where error message is given indicated by error message.

int main(.......)
{
..................
pcl::PointCloud<pcl::PointXYZ> cloud;

// Fill in the cloud data
cloud.width    = 5;
cloud.height   = 1;
cloud.is_dense = false;
cloud.points.resize (cloud.width * cloud.height);

for (size_t i = 0; i < cloud.points.size (); ++i)
{
cloud.points[i].x = 1024 * rand () / (RAND_MAX + 1.0f);
cloud.points[i].y = 1024 * rand () / (RAND_MAX + 1.0f);
cloud.points[i].z = 1024 * rand () / (RAND_MAX + 1.0f);

}

std::cerr << "Saved " << cloud.points.size () << " data points to test_pcd.pcd." << std::endl;

for (size_t i = 0; i < cloud.points.size (); ++i)
std::cerr << "    " << cloud.points[i].x << " " << cloud.points[i].y << " " << cloud.points[i].z << std::endl;

pcl::ConvexHull< pcl::PointXYZ >::reconstruct(cloud);  // error message

..................
}


Originally posted by Nihad on ROS Answers with karma: 22 on 2013-03-28

Post score: 0

You need to call the pcl::ConvexHull::reconstruct() function as a member function, not a static function. See the example here.

pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
... do some stuff to fill cloud with data ...

pcl::ConvexHull<pcl::PointXYZ> cHull;
pcl::PointCloud<pcl::PointXYZ> cHull_points;
cHull.setInputCloud(cloud);
cHull.reconstruct (cHull_points);


Originally posted by Jeremy Zoss with karma: 4976 on 2013-03-28

This answer was ACCEPTED on the original site

Post score: 2

I wrote pcl::PointCloudpcl::PointXYZ cloud instead of pcl::PointCloudpcl::PointXYZ::Ptr cloud(new pcl::PointCloudpcl::PointXYZ). Now it gave error on cHull.setInputCloud(cloud). What is the difference between pcl::PointCloudpcl::PointXYZ cloud and your point cloud declaration?

Comment by Jeremy Zoss on 2013-03-28:
cHull.setInputCloud() requires a boost::shared_ptr to the original point cloud. If you don't want to change your declaration to a shared_ptr (as I showed above), you can keep your original declaration and change this line: cHull.setInputCloud(cloud.makeShared()). Beware: this makes a COPY of data!

Thnx for ur help. Now it gives linker error like error LNK2019: unresolved external symbol "public: void __thiscall pcl::ConvexHull::reconstruct(class pcl::PointCloud &)" (?reconstruct@?$$ConvexHull@UPointXYZ@pcl@@@pcl@@QAEXAAV?$$PointCloud@UPointXYZ@pcl@@@2

Moreover, if I only declare pcl::ConvexHullpcl::PointXYZ cHull and omitting last three lines, it also gives error.

Comment by Jeremy Zoss on 2013-03-28:
The linker error means that you have not linked in the required PCL libraries. You'll need to update your question with more details: how are you compiling (e.g. relevant lines from CMakeLists.txt), how is PCL installed, etc. Make sure you have "pcl" as a package dependency to auto-link the libs.