Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2015
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <array>
  3. #include <string>
  4.  
  5. // Disable Error C4996 that occur when using Boost.Signals2.
  6. #ifdef _DEBUG
  7. #define _SCL_SECURE_NO_WARNINGS
  8. #endif
  9.  
  10. #include "kinect2_grabber.h"
  11. #include <pcl/visualization/pcl_visualizer.h>
  12.  
  13.  
  14. boost::mutex mutex;
  15.  
  16. int _tmain( int argc, _TCHAR* argv[] )
  17. {
  18. std::array<std::shared_ptr<pcl::visualization::PCLVisualizer>, 2> viewer;
  19. for( int count = 0; count < viewer.size(); count++ ){
  20. viewer[count] = std::make_shared<pcl::visualization::PCLVisualizer>();
  21. std::string name = "Viewer" + std::to_string( count + 1 );
  22. viewer[count]->setWindowName( name.c_str() );
  23. }
  24.  
  25. pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr cloud;
  26. boost::function<void( const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr& )> function =
  27. [&cloud]( const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr &ptr ){
  28. boost::mutex::scoped_lock lock( mutex );
  29. cloud = ptr;
  30. };
  31.  
  32. pcl::Grabber* grabber = new pcl::Kinect2Grabber();
  33.  
  34. boost::signals2::connection connection = grabber->registerCallback( function );
  35.  
  36. grabber->start();
  37.  
  38. bool stop = false;
  39. while( 1 ){
  40. for( int count = 0; count < viewer.size(); count++ ){
  41. if( viewer[count]->wasStopped() ){
  42. stop = true;
  43. break;
  44. }
  45.  
  46. viewer[count]->spinOnce();
  47.  
  48. if( cloud ){
  49. if( !viewer[count]->updatePointCloud( cloud, "cloud" ) ){
  50. viewer[count]->addPointCloud( cloud, "cloud" );
  51. viewer[count]->resetCameraViewpoint( "cloud" );
  52. }
  53. }
  54. }
  55.  
  56. if( GetKeyState( VK_ESCAPE ) < 0 || stop ){
  57. break;
  58. }
  59. }
  60.  
  61. grabber->stop();
  62.  
  63. return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement