Error in building point cloud using PointCloud2
I've been trying to build a point cloud using pcl function as in the code. It seems to work as the point cloud gets accumulated over time as I monitor ROS_INFO output from rxconsole. The variable "cloud" in the code is a cloud that is gathered over time while "c_tmp" is a temporary cloud that is stored in.
The problem I'm currently having is that I couldn't be able to visualize it via rviz. As I click on the /cloud topic, it warns that "No messages received". As for /c_tmp topic, no surprise, it just works out the box. Any idea, how do I fix this? Is the point cloud building correctly coded?
sensor_msgs::PointCloud2 cloud; //Class variable
// In a callback function
{
sensor_msgs::PointCloud2 c_tmp;
static tf::TransformBroadcaster tfb;
tf::Transform xform;
xform.setOrigin(tf::Vector3(pose3D_LDD.pose.position.x, pose3D_LDD.pose.position.y, pose3D_LDD.pose.position.z));
xform.setRotation(tf::Quaternion(pose3D_LDD.pose.orientation.x, pose3D_LDD.pose.orientation.y, pose3D_LDD.pose.orientation.z, pose3D_LDD.pose.orientation.w));
tfb.sendTransform(tf::StampedTransform(xform, ros::Time(pose3D_LDD.header.stamp), "base_link", "laser"));
tfListener_.waitForTransform("base_link", "laser", previous_scan_.header.stamp, ros::Duration(1.0));
try
{
projector_.transformLaserScanToPointCloud("base_link", previous_scan_, c_tmp, tfListener_);
if (!initialized_cloud_)
{
cloud = c_tmp;
initialized_cloud_ = true;
}
else
{
pcl::concatenatePointCloud(cloud, c_tmp, cloud);
ROS_INFO("From c_tmp: Got cloud with %u of width and %u of height", c_tmp.width, c_tmp.height);
ROS_INFO("From cloud: Got cloud with %u of width and %u of height", cloud.width, cloud.height);
}
}
EDIT
if (!initialized_cloud_)
{
cloud = c_tmp;
initialized_cloud_ = true;
}
else
{
pcl::concatenatePointCloud(cloud, c_tmp, temp_cloud);
cloud = temp_cloud;
ROS_INFO("From c_tmp: Got cloud with %u of width and %u of height", c_tmp.width, c_tmp.height);
ROS_INFO("From cloud: Got cloud with %u of width and %u of height", cloud.width, cloud.height);
}