ros_openni_view.cpp
Go to the documentation of this file.
00001 #include <ros/ros.h>
00002 #include <image_transport/image_transport.h>
00003 #include <sensor_msgs/image_encodings.h>
00004 
00005 //#include "IronPalette.h"
00006 
00007 #include <QtGui/QApplication>
00008 #include <QtGui/QLabel>
00009 #include <QtCore/QBasicTimer>
00010 #include <QtGui/QPainter>
00011 #include <QtGui/QDialog>
00012 #include <QtGui/QMainWindow>
00013 //#include <QtGui/QMessageBox>
00014 #include <QtGui/QKeyEvent>
00015 
00016 #include <stdio.h>
00017 #include "openni_view.h"
00018 #include "openni_cam.h"
00019 
00020 class myApp : public QApplication {
00021 public:
00022     QView view;
00023     openni_cam::openni_cam cam;
00024 public:
00025     myApp(int & argc, char **argv):QApplication(argc,argv){
00026         startTimer(1000/100);
00027     };
00028     //
00029     ~myApp() {
00030     };
00031     //
00032     void imageCallback1(const sensor_msgs::ImageConstPtr & msg) {//rgb
00033         //
00034         ++view.count;
00035         cam.rgb.resize(exttype::mint3(3,msg->width,msg->height));
00036         memcpy(cam.rgb.begin(),&msg->data[0],cam.rgb.byte_size());
00037     };
00038     void imageCallback2(const sensor_msgs::ImageConstPtr & msg) {//depth
00039         //
00040         cam.depth.resize(exttype::mint2(msg->width,msg->height));
00041         memcpy(cam.depth.begin(),&msg->data[0],cam.depth.byte_size());
00042     };
00043     //
00044     void timerEvent(QTimerEvent * event) {
00045         if(!ros::ok()) {
00046             //ros::shutdown();
00047             printf("openni_node quitting");
00048             fflush(stdout);
00049             exit(0);
00050         };
00051         if(!cam.depth.is_empty() && !cam.rgb.is_empty()){
00052             view.show(cam);
00053         };
00054         ros::spinOnce();
00055     };
00056     bool notify( QObject * receiver, QEvent * ev) {
00057         if (ev->type() == QEvent::KeyPress) {
00058             QKeyEvent *e = static_cast<QKeyEvent *>(ev);
00059             //QMessageBox* box = new QMessageBox();
00060             //box->setWindowTitle(QString("Hello"));
00061             //box->setText(QString("You Pressed: ")+ e->text());
00062             //box->show();
00063             if(e->key() == Qt::Key_Space) {
00064                 return true;
00065             } else if (e->key() == Qt::Key_Escape) {
00066                 exit(0);
00067                 return true;
00068             };
00069         };
00070         return QApplication::notify(receiver,ev);
00071     };
00072 };
00073 
00074 myApp *a;
00075 
00076 void imageCallback1(const sensor_msgs::ImageConstPtr & msg) {
00077     //fprintf(stderr,"!");
00078     a->imageCallback1(msg);
00079 };
00080 
00081 void imageCallback2(const sensor_msgs::ImageConstPtr & msg) {
00082     //fprintf(stderr,"!");
00083     a->imageCallback2(msg);
00084 };
00085 
00086 int main(int argc, char **argv) {
00087     ros::init(argc, argv, "openni_view");
00088     ros::NodeHandle nh;
00089     //
00090     image_transport::ImageTransport it1(nh);
00091     image_transport::Subscriber sub1 = it1.subscribe("openni_camera/rgb", 1,imageCallback1);
00092     image_transport::Subscriber sub2 = it1.subscribe("openni_camera/depth", 1,imageCallback2);
00093     //
00094     a = new myApp(argc, argv);
00095     a->exec();
00096     delete a;
00097 };
 All Classes Namespaces Files Functions Variables Typedefs Defines


openni_cam
Author(s): Alexander Shekhovtsov
autogenerated on Sun Dec 1 2013 17:19:20