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 
00048 OpenNIPassthrough::OpenNIPassthrough (pcl::OpenNIGrabber& grabber) 
00049   : vis_ ()
00050   , grabber_(grabber)
00051   , device_id_ ()
00052   , cloud_pass_()
00053   , pass_ ()
00054   , mtx_ ()
00055   , ui_ (new Ui::MainWindow)
00056   , vis_timer_ (new QTimer (this))
00057 {
00058   
00059   vis_timer_->start (5);
00060 
00061   connect (vis_timer_, SIGNAL (timeout ()), this, SLOT (timeoutSlot ()));
00062 
00063   ui_->setupUi (this);
00064 
00065   this->setWindowTitle ("PCL OpenNI PassThrough Viewer");
00066   vis_.reset (new pcl::visualization::PCLVisualizer ("", false));
00067   ui_->qvtk_widget->SetRenderWindow (vis_->getRenderWindow ());
00068   vis_->setupInteractor (ui_->qvtk_widget->GetInteractor (), ui_->qvtk_widget->GetRenderWindow ());
00069   vis_->getInteractorStyle ()->setKeyboardModifier (pcl::visualization::INTERACTOR_KB_MOD_SHIFT);
00070   ui_->qvtk_widget->update (); 
00071 
00072   
00073   boost::function<void (const CloudConstPtr&)> f = boost::bind (&OpenNIPassthrough::cloud_cb, this, _1);
00074   boost::signals2::connection c = grabber_.registerCallback (f);
00075 
00076   grabber_.start ();
00077 
00078   
00079   pass_.setFilterFieldName ("z");
00080   pass_.setFilterLimits (0.5, 5.0);
00081   
00082   ui_->fieldValueSlider->setRange (5, 50);
00083   ui_->fieldValueSlider->setValue (50);
00084   connect (ui_->fieldValueSlider, SIGNAL (valueChanged (int)), this, SLOT (adjustPassThroughValues (int)));
00085 }
00086 
00088 void
00089 OpenNIPassthrough::cloud_cb (const CloudConstPtr& cloud)
00090 {
00091   QMutexLocker locker (&mtx_);  
00092   FPS_CALC ("computation");
00093 
00094   
00095   cloud_pass_.reset (new Cloud);
00096   pass_.setInputCloud (cloud);
00097   pass_.filter (*cloud_pass_);
00098 }
00099 
00101 void
00102 OpenNIPassthrough::timeoutSlot ()
00103 {
00104   if (!cloud_pass_)
00105   {
00106     boost::this_thread::sleep (boost::posix_time::milliseconds (1));
00107     return;
00108   }
00109 
00110   CloudPtr temp_cloud;
00111   {
00112     QMutexLocker locker (&mtx_);
00113     temp_cloud.swap (cloud_pass_); 
00114   }
00115   
00116   if (!vis_->updatePointCloud (temp_cloud, "cloud_pass"))
00117   {
00118     vis_->addPointCloud (temp_cloud, "cloud_pass");
00119     vis_->resetCameraViewpoint ("cloud_pass");
00120   }
00121   FPS_CALC ("visualization");
00122   ui_->qvtk_widget->update ();
00123 }
00124 
00125 int 
00126 main (int argc, char ** argv)
00127 {
00128   
00129   QApplication app (argc, argv); 
00130 
00131   
00132   pcl::OpenNIGrabber grabber ("#1");
00133   
00134   if (!grabber.providesCallback<pcl::OpenNIGrabber::sig_cb_openni_point_cloud_rgb> ())
00135   {
00136     PCL_ERROR ("Device #1 does not provide an RGB stream!\n");
00137     return (-1);
00138   }
00139 
00140   OpenNIPassthrough v (grabber);
00141   v.show ();
00142   return (app.exec ());
00143 }