Difference between using PointCloud and PointCloudPtr?

asked 2020-05-02 15:41:45 -0500

rosberrypi gravatar image

Hi all, I know that this question is more or less a generic C++ question but since I am getting familiar with PointCloud library lately, I am trying to figure out which data types would be suitable for what type of usage.

For example, to convert a LaserScan to PointCloud2 and then PointCloud<PointXYZ> I'm doing the following:

void laserCallback(const sensor_msgs::LaserScan::ConstPtr& laser_scan)
{   
     // Convert scan to PointCloud2
     laser_geometry::LaserProjection projector; 
     sensor_msgs::PointCloud2 ros_cloud; 
     projector.projectLaser(*laser_scan, ros_cloud);

    // Convert PointCloud2 to PointCloud<PointXYZ>
     pcl::PointCloud<pcl::PointXYZ> pcl_cloud;
     pcl::fromROSMsg (ros_cloud, pcl_cloud);    
}

But this also works by defining the variables PointCloud2::Ptr and PointCloud<PointXYZ>::Ptr such as:

void laserCallback(const sensor_msgs::LaserScan::ConstPtr& laser_scan)
{
     // Convert Scan to PointCloud2
     laser_geometry::LaserProjection projector;
     sensor_msgs::PointCloud2::Ptr ros_cloud (new sensor_msgs::PointCloud2);
     projector.projectLaser(*laser_scan, *ros_cloud);

     // Convert PointCloud2 to PointCloud<PointXYZ>
     pcl::PointCloud<pcl::PointXYZ>::Ptr pcl_cloud  (new pcl::PointCloud<pcl::PointXYZ>);
     pcl::fromROSMsg (*ros_cloud, *pcl_cloud);
}

Could someone please explain me, what is the fundamental difference between these two usages? Thank you.

edit retag flag offensive close merge delete