How to get the name or id of a pcl_visualizer
I need to get the name or id of a pcl::visulization::PCLvisualizer because I need to show three visualizers at the same time for comparision and I use a set of shortcuts to save them. My C++ code is as follows(I have marked the place where the code needs to be added)and I'm very appreciated for your help.
#include <pcl/visualization/pcl_visualizer.h>
void keyboardEventOccurred (const pcl::visualization::KeyboardEvent &event,
void* viewer_void)
{
pcl::visualization::PCLVisualizer *viewer = static_cast<pcl::visualization::PCLVisualizer *> (viewer_void);
std::string saved_name = "/home/ouni/Code/pcl_test/" ;
if (event.getKeySym () == "s" && event.keyDown () && event.isCtrlPressed()) // Ctrl+S -> save the screen shot
{
std::cout << "Ctrl + S was pressed => saving screen shot..." << std::endl;
//saved_name += *********************add code here***************************
viewer->saveScreenshot(saved_name);
std::cout << "screen shot saved!" << std::endl;
}
}
pcl::visualization::PCLVisualizer::Ptr
DrawPC(const pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_ptr, std::string viewer_name="3D Viewer") {
pcl::visualization::PCLVisualizer::Ptr viewer(
new pcl::visualization::PCLVisualizer(viewer_name));
viewer->setBackgroundColor(0, 0, 0);
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> single_color(
cloud_ptr, 255, 255, 255);
viewer->addPointCloud<pcl::PointXYZ>(cloud_ptr, single_color, "total PC");
viewer->setPointCloudRenderingProperties(
pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 3, "total PC");
viewer->addCoordinateSystem(1.0);
viewer->initCameraParameters();
viewer->registerKeyboardCallback (keyboardEventOccurred, (void*)viewer.get ());
return (viewer);
}
...
int main(){
viewer1 = DrawPC(cloud, "initial_points"); // **set window name here,but how to get it?**
while(!viewer1->wasStopped()){
viewer1->spinOnce(100);
}
}