Advertisement
karanjthakkar

RGBD Visualizer

Sep 18th, 2012
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.90 KB | None | 0 0
  1. #include <pcl/visualization/cloud_viewer.h>
  2. #include <iostream>
  3. #include <pcl/io/io.h>
  4. #include <pcl/io/pcd_io.h>
  5. #include <pcl/point_cloud.h>
  6. #include <pcl/point_types.h>
  7.  
  8. /*
  9.  * Sample code for reading point clouds in the RGB-D Object Dataset using the Point Cloud Library
  10.  *
  11.  * Author: Kevin Lai
  12.  */
  13.  
  14. int user_data;
  15.  
  16. void
  17. viewerOneOff (pcl::visualization::PCLVisualizer& viewer)
  18. {
  19.     viewer.setBackgroundColor (1.0, 0.5, 1.0);
  20.     pcl::PointXYZRGBIM o;
  21.     o.x = 1.0;
  22.     o.y = 0;
  23.     o.z = 0;
  24.     viewer.addSphere (o, 0.25, "sphere", 0);
  25.     std::cout << "i only run once" << std::endl;
  26.    
  27. }
  28.  
  29. void
  30. viewerPsycho (pcl::visualization::PCLVisualizer& viewer)
  31. {
  32.     static unsigned count = 0;
  33.     std::stringstream ss;
  34.     ss << "Once per viewer loop: " << count++;
  35.     viewer.removeShape ("text", 0);
  36.     viewer.addText (ss.str(), 200, 300, "text", 0);
  37.    
  38.     //FIXME: possible race condition here:
  39.     user_data++;
  40. }
  41.  
  42. struct PointXYZRGBIM
  43. {
  44.   union
  45.   {
  46.     struct
  47.     {
  48.       float x;
  49.       float y;
  50.       float z;
  51.       float rgb;
  52.       float imX;
  53.       float imY;
  54.     };
  55.     float data[6];
  56.   };
  57.   EIGEN_MAKE_ALIGNED_OPERATOR_NEW
  58. } EIGEN_ALIGN16;
  59.  
  60. POINT_CLOUD_REGISTER_POINT_STRUCT (PointXYZRGBIM,
  61.                                     (float, x, x)
  62.                                     (float, y, y)
  63.                                     (float, z, z)
  64.                                     (float, rgb, rgb)
  65.                                     (float, imX, imX)
  66.                                     (float, imY, imY)
  67. )
  68.  
  69. int
  70. main (int argc, char** argv)
  71. {
  72.   pcl::PointCloud<PointXYZRGBIM>::Ptr cloud (new pcl::PointCloud<PointXYZRGBIM>);
  73.  
  74.   if (pcl::io::loadPCDFile<PointXYZRGBIM> ("/home/karan/bowl_1_1_1.pcd", *cloud) == -1) //* load the file
  75.   {
  76.     printf ("Couldn't read file test_pcd.pcd \n");
  77.     return (-1);
  78.   }
  79.   std::cout << "Loaded "
  80.             << cloud->width * cloud->height
  81.             << " data points from test_pcd.pcd with the following fields: "
  82.             << std::endl;
  83.  
  84.     pcl::visualization::CloudViewer viewer("Cloud Viewer");
  85.  
  86.     viewer.showCloud(cloud);
  87.  
  88.     viewer.runOnVisualizationThreadOnce(viewerOneOff);
  89.  
  90.     viewer.runOnVisualizationThreadOnce(viewerPsycho);
  91.  
  92.     while (!viewer.wasStopped())   
  93.     {
  94.         user_data++;
  95.     }
  96.    
  97.     return 0;
  98.  
  99.  
  100.   /*for (size_t i = 0; i < cloud->points.size (); ++i){
  101.     uint32_t rgb = *reinterpret_cast<int*>(&cloud->points[i].rgb);
  102.     uint8_t r = (rgb >> 16) & 0x0000ff;
  103.     uint8_t g = (rgb >> 8)  & 0x0000ff;
  104.     uint8_t b = (rgb)       & 0x0000ff;
  105.     std::cout << "    " << cloud->points[i].x
  106.               << " "    << cloud->points[i].y
  107.               << " "    << cloud->points[i].z
  108.               << " "    << (int)r
  109.               << " "    << (int)g
  110.               << " "    << (int)b
  111.               << " "    << cloud->points[i].imX
  112.               << " "    << cloud->points[i].imY << std::endl;
  113.   }*/
  114.  
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement