PointCloudLogViewer.cpp
Go to the documentation of this file.
1 #include <pcl/io/pcd_io.h>
2 #include <pcl/point_types.h>
3 #include <pcl/visualization/cloud_viewer.h>
4 #include <vtkRenderWindow.h>
5 #include <vtkRendererCollection.h>
6 #include <vtkCamera.h>
7 
8 std::vector<pcl::PointCloud<pcl::PointXYZRGB>::Ptr> clouds;
9 int rank=0;
10 
11 void keyboardEventOccurred (const pcl::visualization::KeyboardEvent &event,
12  void* viewer_void)
13 {
14  pcl::visualization::PCLVisualizer *viewer = static_cast<pcl::visualization::PCLVisualizer *> (viewer_void);
15  if (event.keyDown()){
16  if (event.getKeySym () == "n" && rank+1 < clouds.size()){
17  rank++;
18  viewer->removePointCloud("test");
19  viewer->addPointCloud(clouds[rank], "test");
20  }else if (event.getKeySym() == "p" && rank-1 >= 0){
21  rank--;
22  viewer->removePointCloud("test");
23  viewer->addPointCloud(clouds[rank], "test");
24  }else if (event.getKeySym() == "r"){
25  viewer->setCameraPosition(0,10,0,0,0,0,0,0,1);
26  }
27  }
28  std::cout << rank+1 << "/" << clouds.size() << std::endl;
29 }
30 
31 
32 int main(int argc, char *argv[])
33 {
34  if (argc < 2){
35  std::cerr << "Usage:" << argv[0] << "[point cloud log file]" << std::endl;
36  return 1;
37  }
38 
39  std::ifstream ifs(argv[1]);
40  if (!ifs.is_open()){
41  std::cerr << "can't open " << argv[1] << std::endl;
42  return 2;
43  }
44 
45  double tm;
46  int w, h, npoint, r=255,g=255,b=255;
47  std::string type;
48  float x,y,z;
49 
50  ifs >> tm;
51  while (!ifs.eof()){
52  pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>);
53 
54  ifs >> w >> h >> type >> npoint;
55  cloud->points.resize(npoint);
56  for (int i=0; i<npoint; i++){
57  ifs >> x >> y >> z;
58  if (type == "xyzrgb"){
59  ifs >> r >> g >> b;
60  }
61  cloud->points[i].x = x;
62  cloud->points[i].y = y;
63  cloud->points[i].z = z;
64  cloud->points[i].r = r;
65  cloud->points[i].g = g;
66  cloud->points[i].b = b;
67  }
68  clouds.push_back(cloud);
69  ifs >> tm;
70  }
71  if (clouds.size()==0) return 3;
72 
73  pcl::visualization::PCLVisualizer viewer("Cloud Viewer");
74  viewer.getRenderWindow()->GetRenderers()->GetFirstRenderer()->GetActiveCamera()->SetParallelProjection(1);
75  viewer.registerKeyboardCallback (keyboardEventOccurred, (void*)&viewer);
76  viewer.setCameraPosition(0, 10, 0, 0, 0, 0, 0, 0, 1);
77  viewer.setCameraClipDistances(1, 100);
78  viewer.addPointCloud(clouds[0], "test");
79 
80  while (!viewer.wasStopped ()){
81  viewer.spinOnce (100);
82  boost::this_thread::sleep (boost::posix_time::microseconds (100000));
83  }
84 
85  return 0;
86 }
std::vector< pcl::PointCloud< pcl::PointXYZRGB >::Ptr > clouds
png_infop png_charp png_int_32 png_int_32 int * type
int rank
ifs
w
png_uint_32 i
int main(int argc, char *argv[])
void keyboardEventOccurred(const pcl::visualization::KeyboardEvent &event, void *viewer_void)


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Sat Dec 17 2022 03:52:20