I have two point cloud, which I want to visualise in the same window.
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/cloud_viewer.h>
int main ()
{
pcl::visualization::CloudViewer viewer("Cloud Viewer");
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr body (new pcl::PointCloud<pcl::PointXYZRGBA>);
pcl::io::loadPCDFile ("body.pcd", *body);
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr head (new pcl::PointCloud<pcl::PointXYZRGBA>);
pcl::io::loadPCDFile ("head.pcd", *head);
viewer.showCloud (body);
viewer.showCloud (head);
while (!viewer.wasStopped ())
{
}
return 0;
}
I can see only the last PCD file.
Please note that I don't want to use pcd_viewer tool since I need to do some other processing on this data.
As per the pcl documentation, you can provide a name for the display point cloud.
If you provide the same name it overwrites the existing cloud.
This basically means changing the following calls:
With:
of course you can use whatever names you want.
Regarding the comment
"Okay. I will check it soon. Can you tell me to set camera parameters and background color using cloud_viewer API?"
I am not 100% sure if you can do this using
pcl::visualization::CloudViewer
. However, if you move your code topcl::visualization::PCLVisualizer
you can doviewer.setBackgroundColor(double red,double green,double blue)
(where the values range 0..1. To set a camera). For the camera, you can usepcl::visualization::PCLVisualizer::setCameraPosition
. Moving your code from CloudViewer to PCLVisualizer is preatty easy.EDIT Ther is acutally a way to do this. By looking into here, you can see that you can run any of the function of the
pcl::visualization::PCLVisualizer
using thepcl::visualization::CloudViewer::runOnVisualizationThreadOnce
orpcl::visualization::CloudViewer::runOnVisualizationThread
functions. For this, you will need to create a function that does all the part that usespcl::visualization::PCLVisualizer
and pass it to theCloudViewer::runOnVisualizationThreadOnce
orCloudViewer::runOnVisualizationThread
.For example
The only issue is that I do not see how you could potentially pass arguments to the
pcl::visualization::PCLVisualizer
function that you want to use in the function we crated (in the previous examplepcl::visualization::PCLVisualizer::setBackgroundColor
insetBackground
. For this, I think using directlypcl::visualization::PCLVisualizer
is much better.