wcamera.h
1 /********************************************************************************
2  * WorldSim -- library for robot simulations *
3  * Copyright (C) 2008-2011 Gianluca Massera <emmegian@yahoo.it> *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the Free Software *
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
18  ********************************************************************************/
19 
20 #ifdef FARSA_USE_YARP_AND_ICUB
21 
22 #ifndef WCAMERA_H
23 #define WCAMERA_H
24 
25 #include "worldsimconfig.h"
26 #include "wvector.h"
27 #include "wmatrix.h"
28 #include "wquaternion.h"
29 #include "world.h"
30 #include "yarpobject.h"
31 #include "renderworld.h"
32 #include <QImage>
33 #include <QMutex>
34 
35 class QGLPixelBuffer;
36 
37 namespace farsa {
38 
39 class WCamera;
40 
52 class FARSA_WSIM_API RenderCamera : public QObject, public RenderWObjectContainer, public yarp::dev::DeviceDriver, public yarp::dev::IFrameGrabberImage {
53  Q_OBJECT
54 public:
55  RenderCamera( WCamera* wcamera, WObject* attachTo, unsigned int width, unsigned int height );
56  ~RenderCamera();
58  void moveRotatePointOfView( const wMatrix& tm );
60  void initializeGL();
62  void paintGL();
66  virtual bool open( yarp::os::Searchable &config );
68  virtual bool close( );
70  virtual bool configure( yarp::os::Searchable &config );
72 
74  virtual bool getImage( yarp::sig::ImageOf<yarp::sig::PixelRgb>& image );
75  virtual int height() const;
76  virtual int width() const;
78 private slots:
79  void slotRemoveObject( WObject* w );
80  void slotAddObject( WObject* w );
81 private:
82  float aspectRatio;
83  wVector eyep;
84  wVector atp;
85  wVector upv;
86  int widthv;
87  int heightv;
88  WCamera* wcamera;
90  WObject* attachTo;
92  QGLPixelBuffer* pbuffer;
94  unsigned char* frameBuffer;
96  yarp::sig::ImageOf<yarp::sig::PixelRgb> frameImage;
97 };
98 
109 class FARSA_WSIM_API WCamera : public YarpObject {
110  Q_OBJECT
111 public:
120  WCamera( World* world, QString name, WObject* attachTo, unsigned int width=200, unsigned int height=200 );
129  WCamera( World* world, QString name, unsigned int width=200, unsigned int height=200, const wMatrix& tm = wMatrix::identity() );
131  ~WCamera();
133  virtual void preUpdate();
139  virtual void postUpdate();
142  return attachTo;
143  };
145  yarp::dev::IFrameGrabberImage* getFrameGrabber() {
146  return images;
147  }
148 private:
150  RenderCamera* images;
152  WObject* attachTo;
154  yarp::os::BufferedPort<yarp::sig::ImageOf<yarp::sig::PixelRgb> > porty;
155 };
156 
157 } // end namespace farsa
158 
159 #endif
160 
161 #endif // FARSA_USE_YARP_AND_ICUB