point_cloud_compression.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/visualization/cloud_viewer.h>
00005 
00006 #include <pcl/compression/octree_pointcloud_compression.h>
00007 
00008 #include <stdio.h>
00009 #include <sstream>
00010 #include <stdlib.h>
00011 
00012 #ifdef WIN32
00013 # define sleep(x) Sleep((x)*1000)
00014 #endif
00015 
00016 class SimpleOpenNIViewer
00017 {
00018 public:
00019   SimpleOpenNIViewer () :
00020     viewer (" Point Cloud Compression Example")
00021   {
00022   }
00023 
00024   void
00025   cloud_cb_ (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr &cloud)
00026   {
00027     if (!viewer.wasStopped ())
00028     {
00029       // stringstream to store compressed point cloud
00030       std::stringstream compressedData;
00031       // output pointcloud
00032       pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloudOut (new pcl::PointCloud<pcl::PointXYZRGBA> ());
00033 
00034       // compress point cloud
00035       PointCloudEncoder->encodePointCloud (cloud, compressedData);
00036 
00037       // decompress point cloud
00038       PointCloudDecoder->decodePointCloud (compressedData, cloudOut);
00039 
00040 
00041       // show decompressed point cloud
00042       viewer.showCloud (cloudOut);
00043     }
00044   }
00045 
00046   void
00047   run ()
00048   {
00049 
00050     bool showStatistics = true;
00051 
00052     // for a full list of profiles see: /io/include/pcl/compression/compression_profiles.h
00053     pcl::octree::compression_Profiles_e compressionProfile = pcl::octree::MED_RES_ONLINE_COMPRESSION_WITH_COLOR;
00054 
00055     // instantiate point cloud compression for encoding and decoding
00056     PointCloudEncoder = new pcl::octree::PointCloudCompression<pcl::PointXYZRGBA> (compressionProfile, showStatistics);
00057     PointCloudDecoder = new pcl::octree::PointCloudCompression<pcl::PointXYZRGBA> ();
00058 
00059     // create a new grabber for OpenNI devices
00060     pcl::Grabber* interface = new pcl::OpenNIGrabber ();
00061 
00062     // make callback function from member function
00063     boost::function<void
00064     (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&)> f = boost::bind (&SimpleOpenNIViewer::cloud_cb_, this, _1);
00065 
00066     // connect callback function for desired signal. In this case its a point cloud with color values
00067     boost::signals2::connection c = interface->registerCallback (f);
00068 
00069     // start receiving point clouds
00070     interface->start ();
00071 
00072     while (!viewer.wasStopped ())
00073     {
00074       sleep (1);
00075     }
00076 
00077     interface->stop ();
00078 
00079     // delete point cloud compression instances
00080     delete (PointCloudEncoder);
00081     delete (PointCloudDecoder);
00082 
00083   }
00084 
00085   pcl::visualization::CloudViewer viewer;
00086 
00087   pcl::octree::PointCloudCompression<pcl::PointXYZRGBA>* PointCloudEncoder;
00088   pcl::octree::PointCloudCompression<pcl::PointXYZRGBA>* PointCloudDecoder;
00089 
00090 };
00091 
00092 int
00093 main (int argc, char **argv)
00094 {
00095   SimpleOpenNIViewer v;
00096   v.run ();
00097 
00098   return (0);
00099 }


pcl
Author(s): Open Perception
autogenerated on Mon Oct 6 2014 03:16:35