PointCloudLogViewer.cpp
Go to the documentation of this file.
00001 #include <pcl/io/pcd_io.h>
00002 #include <pcl/point_types.h>
00003 #include <pcl/visualization/cloud_viewer.h>
00004 #include <vtkRenderWindow.h>
00005 #include <vtkRendererCollection.h>
00006 #include <vtkCamera.h>
00007 
00008 std::vector<pcl::PointCloud<pcl::PointXYZRGB>::Ptr> clouds;
00009 int rank=0;
00010 
00011 void keyboardEventOccurred (const pcl::visualization::KeyboardEvent &event,
00012                             void* viewer_void)
00013 {
00014   pcl::visualization::PCLVisualizer *viewer = static_cast<pcl::visualization::PCLVisualizer *> (viewer_void);
00015   if (event.keyDown()){
00016     if (event.getKeySym () == "n" && rank+1 < clouds.size()){
00017       rank++;
00018       viewer->removePointCloud("test");
00019       viewer->addPointCloud(clouds[rank], "test");
00020     }else if (event.getKeySym() == "p" && rank-1 >= 0){
00021       rank--;
00022       viewer->removePointCloud("test");
00023       viewer->addPointCloud(clouds[rank], "test");
00024     }else if (event.getKeySym() == "r"){
00025       viewer->setCameraPosition(0,10,0,0,0,0,0,0,1);
00026     }
00027   }
00028   std::cout << rank+1 << "/" << clouds.size() << std::endl;
00029 }
00030 
00031 
00032 int main(int argc, char *argv[])
00033 {
00034   if (argc < 2){
00035     std::cerr << "Usage:" << argv[0] << "[point cloud log file]" << std::endl;
00036     return 1;
00037   }
00038 
00039   std::ifstream ifs(argv[1]);
00040   if (!ifs.is_open()){
00041     std::cerr << "can't open " << argv[1] << std::endl;
00042     return 2;
00043   }
00044 
00045   double tm;
00046   int w, h, npoint, r=255,g=255,b=255;
00047   std::string type;
00048   float x,y,z;
00049 
00050   ifs >> tm;
00051   while (!ifs.eof()){
00052     pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>);
00053 
00054     ifs >> w >> h >> type >> npoint;
00055     cloud->points.resize(npoint);
00056     for (int i=0; i<npoint; i++){
00057       ifs >> x >> y >> z;
00058       if (type == "xyzrgb"){
00059         ifs >> r >> g >> b;
00060       }
00061       cloud->points[i].x = x;
00062       cloud->points[i].y = y;
00063       cloud->points[i].z = z;
00064       cloud->points[i].r = r;
00065       cloud->points[i].g = g;
00066       cloud->points[i].b = b;
00067     } 
00068     clouds.push_back(cloud);
00069     ifs >> tm;
00070   }
00071   if (clouds.size()==0) return 3;
00072 
00073   pcl::visualization::PCLVisualizer viewer("Cloud Viewer");
00074   viewer.getRenderWindow()->GetRenderers()->GetFirstRenderer()->GetActiveCamera()->SetParallelProjection(1);
00075   viewer.registerKeyboardCallback (keyboardEventOccurred, (void*)&viewer);
00076   viewer.setCameraPosition(0, 10, 0, 0, 0, 0, 0, 0, 1);
00077   viewer.setCameraClipDistances(1, 100);
00078   viewer.addPointCloud(clouds[0], "test");
00079 
00080   while (!viewer.wasStopped ()){
00081     viewer.spinOnce (100);
00082     boost::this_thread::sleep (boost::posix_time::microseconds (100000));  
00083   }
00084 
00085   return 0;
00086 }


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Wed Sep 6 2017 02:35:55