0
$\begingroup$

Rosanswers logo

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

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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


Original comments

Comment by Nihad on 2013-03-28:
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!

Comment by Nihad on 2013-03-28:
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

Comment by Nihad on 2013-03-28:
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.

Comment by Nihad on 2013-03-28:
@Jeremy zoss Step 1: I follow this youtube link for installation http://www.youtube.com/watch?v=lyPpbZUXfLA

Step 2: For .cpp & CMakeLists.txt, I follow the link: http://pointclouds.org/documentation/tutorials/using_pcl_pcl_config.php

Comment by Jeremy Zoss on 2013-03-29:
Oh! You're using Windows? At this point, it sounds like you're only using PCL (not ROS). Maybe the folks at http://www.pcl-users.org/ could help you better. If you plan on using ROS, know that running ROS under windows is experimental. See http://www.ros.org/wiki/win_ros/Tutorials.

Comment by Jeremy Zoss on 2013-03-29:
In particular, the setup of CMakeLists.txt and how you go about linking in the required libraries to your executable will be different depending on whether you use "pure PCL" or PCL in ROS". If you want to use ROS, you may have an easier time working in Linux (Ubuntu) rather than Windows.

Comment by Nihad on 2013-03-31:
@Jeremy Zoss, Thnx. Now it works fine. Moreover, I included two more lines for calculating area and volume, but output gave 0 & 0. Regarding input, I mention in my first post.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.