worldsim/include/wcamera.h

00001 /********************************************************************************
00002  *  WorldSim -- library for robot simulations                                   *
00003  *  Copyright (C) 2008-2011 Gianluca Massera <emmegian@yahoo.it>                *
00004  *                                                                              *
00005  *  This program is free software; you can redistribute it and/or modify        *
00006  *  it under the terms of the GNU General Public License as published by        *
00007  *  the Free Software Foundation; either version 2 of the License, or           *
00008  *  (at your option) any later version.                                         *
00009  *                                                                              *
00010  *  This program is distributed in the hope that it will be useful,             *
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of              *
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               *
00013  *  GNU General Public License for more details.                                *
00014  *                                                                              *
00015  *  You should have received a copy of the GNU General Public License           *
00016  *  along with this program; if not, write to the Free Software                 *
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA  *
00018  ********************************************************************************/
00019 
00020 #ifdef FARSA_USE_YARP_AND_ICUB
00021 
00022 #ifndef WCAMERA_H
00023 #define WCAMERA_H
00024 
00025 #include "worldsimconfig.h"
00026 #include "wvector.h"
00027 #include "wmatrix.h"
00028 #include "wquaternion.h"
00029 #include "world.h"
00030 #include "yarpobject.h"
00031 #include "renderworld.h"
00032 #include <QImage>
00033 #include <QMutex>
00034 
00035 class QGLPixelBuffer;
00036 
00037 namespace farsa {
00038 
00039 class WCamera;
00040 
00052 class FARSA_WSIM_API RenderCamera : public QObject, public RenderWObjectContainer, public yarp::dev::DeviceDriver, public yarp::dev::IFrameGrabberImage {
00053     Q_OBJECT
00054 public:
00055     RenderCamera( WCamera* wcamera, WObject* attachTo, unsigned int width, unsigned int height );
00056     ~RenderCamera();
00058     void moveRotatePointOfView( const wMatrix& tm );
00060     void initializeGL();
00062     void paintGL();
00066     virtual bool open( yarp::os::Searchable &config );
00068     virtual bool close( );
00070     virtual bool configure( yarp::os::Searchable &config );
00072 
00074     virtual bool getImage( yarp::sig::ImageOf<yarp::sig::PixelRgb>& image );
00075     virtual int height() const;
00076     virtual int width() const;
00078 private slots:
00079     void slotRemoveObject( WObject* w );
00080     void slotAddObject( WObject* w );
00081 private:
00082     float aspectRatio;
00083     wVector eyep;
00084     wVector atp;
00085     wVector upv;
00086     int widthv;
00087     int heightv;
00088     WCamera* wcamera;
00090     WObject* attachTo;
00092     QGLPixelBuffer* pbuffer;
00094     unsigned char* frameBuffer;
00096     yarp::sig::ImageOf<yarp::sig::PixelRgb> frameImage;
00097 };
00098 
00109 class FARSA_WSIM_API WCamera : public YarpObject {
00110     Q_OBJECT
00111 public:
00120     WCamera( World* world, QString name, WObject* attachTo, unsigned int width=200, unsigned int height=200 );
00129     WCamera( World* world, QString name, unsigned int width=200, unsigned int height=200, const wMatrix& tm = wMatrix::identity() );
00131     ~WCamera();
00133     virtual void preUpdate();
00139     virtual void postUpdate();
00141     WObject* attachedTo() {
00142         return attachTo;
00143     };
00145     yarp::dev::IFrameGrabberImage* getFrameGrabber() {
00146         return images;
00147     }
00148 private:
00150     RenderCamera* images;
00152     WObject* attachTo;
00154     yarp::os::BufferedPort<yarp::sig::ImageOf<yarp::sig::PixelRgb> > porty;
00155 };
00156 
00157 } // end namespace farsa
00158 
00159 #endif
00160 
00161 #endif // FARSA_USE_YARP_AND_ICUB