openni_grabber.cpp
Go to the documentation of this file.
00001 #include <pcl/point_cloud.h>
00002 #include <pcl/point_types.h>
00003 #include <pcl/io/openni_grabber.h>
00004 #include <pcl/common/time.h>
00005 
00006 class SimpleOpenNIProcessor
00007 {
00008 public:
00009   void cloud_cb_ (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr &cloud)
00010   {
00011     static unsigned count = 0;
00012     static double last = pcl::getTime ();
00013     if (++count == 30)
00014     {
00015       double now = pcl::getTime ();
00016       std::cout << "distance of center pixel :" << cloud->points [(cloud->width >> 1) * (cloud->height + 1)].z << " mm. Average framerate: " << double(count)/double(now - last) << " Hz" <<  std::endl;
00017       count = 0;
00018       last = now;
00019     }
00020   }
00021   
00022   void run ()
00023   {
00024     // create a new grabber for OpenNI devices
00025     pcl::Grabber* interface = new pcl::OpenNIGrabber();
00026 
00027     // make callback function from member function
00028     boost::function<void (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&)> f =
00029       boost::bind (&SimpleOpenNIProcessor::cloud_cb_, this, _1);
00030 
00031     // connect callback function for desired signal. In this case its a point cloud with color values
00032     boost::signals2::connection c = interface->registerCallback (f);
00033 
00034     // start receiving point clouds
00035     interface->start ();
00036 
00037     // wait until user quits program with Ctrl-C, but no busy-waiting -> sleep (1);
00038     while (true)
00039       boost::this_thread::sleep (boost::posix_time::seconds (1));
00040 
00041     // stop the grabber
00042     interface->stop ();
00043   }
00044 };
00045 
00046 int main ()
00047 {
00048   SimpleOpenNIProcessor v;
00049   v.run ();
00050   return (0);
00051 }


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:26:29