Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 #include <pcl/apps/openni_passthrough.h>
00039 
00040 #include <QApplication>
00041 #include <QMutexLocker>
00042 #include <QEvent>
00043 #include <QObject>
00044 
00045 #include <pcl/console/parse.h>
00046 
00047 #include <vtkRenderWindow.h>
00048 
00050 OpenNIPassthrough::OpenNIPassthrough (pcl::OpenNIGrabber& grabber) 
00051   : vis_ ()
00052   , grabber_(grabber)
00053   , device_id_ ()
00054   , cloud_pass_()
00055   , pass_ ()
00056   , mtx_ ()
00057   , ui_ (new Ui::MainWindow)
00058   , vis_timer_ (new QTimer (this))
00059 {
00060   
00061   vis_timer_->start (5);
00062 
00063   connect (vis_timer_, SIGNAL (timeout ()), this, SLOT (timeoutSlot ()));
00064 
00065   ui_->setupUi (this);
00066 
00067   this->setWindowTitle ("PCL OpenNI PassThrough Viewer");
00068   vis_.reset (new pcl::visualization::PCLVisualizer ("", false));
00069   ui_->qvtk_widget->SetRenderWindow (vis_->getRenderWindow ());
00070   vis_->setupInteractor (ui_->qvtk_widget->GetInteractor (), ui_->qvtk_widget->GetRenderWindow ());
00071   vis_->getInteractorStyle ()->setKeyboardModifier (pcl::visualization::INTERACTOR_KB_MOD_SHIFT);
00072   ui_->qvtk_widget->update (); 
00073 
00074   
00075   boost::function<void (const CloudConstPtr&)> f = boost::bind (&OpenNIPassthrough::cloud_cb, this, _1);
00076   boost::signals2::connection c = grabber_.registerCallback (f);
00077 
00078   grabber_.start ();
00079 
00080   
00081   pass_.setFilterFieldName ("z");
00082   pass_.setFilterLimits (0.5, 5.0);
00083   
00084   ui_->fieldValueSlider->setRange (5, 50);
00085   ui_->fieldValueSlider->setValue (50);
00086   connect (ui_->fieldValueSlider, SIGNAL (valueChanged (int)), this, SLOT (adjustPassThroughValues (int)));
00087 }
00088 
00090 void
00091 OpenNIPassthrough::cloud_cb (const CloudConstPtr& cloud)
00092 {
00093   QMutexLocker locker (&mtx_);  
00094   FPS_CALC ("computation");
00095 
00096   
00097   cloud_pass_.reset (new Cloud);
00098   pass_.setInputCloud (cloud);
00099   pass_.filter (*cloud_pass_);
00100 }
00101 
00103 void
00104 OpenNIPassthrough::timeoutSlot ()
00105 {
00106   if (!cloud_pass_)
00107   {
00108     boost::this_thread::sleep (boost::posix_time::milliseconds (1));
00109     return;
00110   }
00111 
00112   CloudPtr temp_cloud;
00113   {
00114     QMutexLocker locker (&mtx_);
00115     temp_cloud.swap (cloud_pass_); 
00116   }
00117   
00118   if (!vis_->updatePointCloud (temp_cloud, "cloud_pass"))
00119   {
00120     vis_->addPointCloud (temp_cloud, "cloud_pass");
00121     vis_->resetCameraViewpoint ("cloud_pass");
00122   }
00123   FPS_CALC ("visualization");
00124   ui_->qvtk_widget->update ();
00125 }
00126 
00127 int 
00128 main (int argc, char ** argv)
00129 {
00130   
00131   QApplication app (argc, argv); 
00132 
00133   
00134   pcl::OpenNIGrabber grabber ("#1");
00135   
00136   if (!grabber.providesCallback<pcl::OpenNIGrabber::sig_cb_openni_point_cloud_rgb> ())
00137   {
00138     PCL_ERROR ("Device #1 does not provide an RGB stream!\n");
00139     return (-1);
00140   }
00141 
00142   OpenNIPassthrough v (grabber);
00143   v.show ();
00144   return (app.exec ());
00145 }