Hi, I'm trying to build a class, that allows simple access to a point cloud published in ROS by a Kinect device.
It subscribes to a sensor_msgs Point Cloud, converts it to a PCL Point Cloud (which should be accessible through the object instance).
My System
My code
Includes
#include <ros/ros.h>
#include <ros/package.h>
#include <image_transport/image_transport.h>
#include <sensor_msgs/image_encodings.h>
#include <iostream>
// PCL specific includes
#include <pcl_conversions/pcl_conversions.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/point_types.h>
#include <pcl_ros/point_cloud.h>
My connector class.
The currently received point cloud should be accessible through the public pointer "pc".
class CameraConnector
{
private:
ros::NodeHandle nh_;
// point cloud
ros::Subscriber pc_sub_;
public:
// point cloud pointer
pcl::PointCloud<pcl::PointXYZ>::Ptr pc;
CameraConnector(bool flag);
~CameraConnector();
/* message callbacks */
void pc_callback ( const sensor_msgs::PointCloud2ConstPtr& msg );
};
/* ========================================== *\
* CONSTRUCTOR/DESTRUCTOR
\* ========================================== */
/* constructor */
CameraConnector::CameraConnector(bool flag):
nh_("~")
{
// Subscribe to depth point cloud
pc_sub_ = nh_.subscribe ("/camera/depth/points", 1, &CameraConnector::pc_callback, this);
}
CameraConnector::~CameraConnector(){}
/* ========================================== *\
* MESSAGE CALLBACKS
\* ========================================== */
void CameraConnector::pc_callback ( const sensor_msgs::PointCloud2ConstPtr& msg )
{
// convert to XYZ PC
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::fromROSMsg(*msg, *cloud);
// Do some filtering ...
// set class pointer, so the point cloud can be accessed from outside the class
pc = &cloud;
}
The main function:
int main(int argc, char** argv)
{
/* ROS stuff */
ros::init(argc, argv, "dyn_3d_modeling");
ros::start();
ros::Rate r(10);
CameraConnector cam(true);
pcl::visualization::CloudViewer viewer_("Cloud Viewer");
while (ros::ok())
{
/* visualize point cloud at a framerate of 10/sec */
//viewer_.showCloud(cam.pc);
ros::spinOnce();
r.sleep();
}
return 0;
}
}
The problem:
I'm not sure how to save a pointer to the current point cloud in the class attribute ptr. I tried it this way:
// set class pointer, so the point cloud can be accessed from outside the class
pc = &cloud;
And then access the point cloud in the main() function through:
CameraConnector cam(true); // init
cam.pc; // access the point cloud
But when I compile, the following message shows up:
error: no match for ‘operator=’ in ‘((CameraConnector*)this)->CameraConnector::pc = & cloud’
note: boost::shared_ptr<T>& boost::shared_ptr<T>::operator=(const boost::shared_ptr<T>&) [with T = pcl::PointCloud<pcl::PointXYZ>; boost::shared_ptr<T> = boost::shared_ptr<pcl::PointCloud<pcl::PointXYZ> >]
/usr/include/boost/smart_ptr/shared_ptr.hpp:309:18: note: no known conversion for argument 1 from ‘pcl::PointCloud<pcl::PointXYZ>::Ptr* {aka boost::shared_ptr<pcl::PointCloud<pcl::PointXYZ> >*}’ to ‘const boost::shared_ptr<pcl::PointCloud<pcl::PointXYZ> >&’
/usr/include/boost/smart_ptr/shared_ptr.hpp:318:18: note: template<class Y> boost::shared_ptr& boost::shared_ptr::operator=(const boost::shared_ptr<Y>&) [with Y = Y; T = pcl::PointCloud<pcl::PointXYZ>]
/usr/include/boost/smart_ptr/shared_ptr.hpp:318:18: note: template argument deduction/substitution failed:
/home/mat/ros_workspace/dyn_3d_mod/src/pcl_test.cpp:63:8: note: mismatched types ‘const boost::shared_ptr<X>’ and ‘pcl::PointCloud<pcl::PointXYZ>::Ptr* {aka boost::shared_ptr<pcl::PointCloud<pcl::PointXYZ> >*}’
I would appreciate any help very much.