cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
osaOSGCamera.h
Go to the documentation of this file.
1 
2 
3 #ifndef _osaOSGCamera_h
4 #define _osaOSGCamera_h
5 
7 
8 #include <sawOpenSceneGraph/sawOpenSceneGraphConfig.h>
9 
10 #ifdef SAW_OPENSCENEGRAPH_SUPPORTS_OPENCV
11 //#include <opencv2/opencv.hpp>
12 #include <opencv2/core/core.hpp>
13 #endif
14 
15 #include <osgViewer/Viewer>
16 
21 
23 
24 class mtsOSGCamera;
25 class osaOSGHUD;
26 
27 class CISST_EXPORT osaOSGCamera : public osgViewer::Viewer{
28 
29  friend class osaOSGHUD;
30 
31  public:
32 
33  enum Errno { ESUCCESS, EFAILURE };
34 
35  private:
36 
38  vctFrame4x4<double> Rtoffset;
39 
41  bool offscreenrendering;
42 
44 
49  virtual void UpdateTransform();
50  osg::Matrixd osgtransform;
51 
53  friend class mtsOSGCameraTask;
54 
55  protected:
56 
57  bool IsOffscreenRenderingEnabled() const {return offscreenrendering;}
58 
60 
65  class Data : public osg::Referenced {
66  private:
68  osg::ref_ptr<osaOSGCamera> camera;
69  public:
71  Data( osaOSGCamera* camera ) : camera( camera ){}
73  osaOSGCamera* GetCamera() { return camera; }
74  };
75 
76 
77 
78 
79 
80 
82 
86  class UpdateCallback : public osg::NodeCallback {
88 
93  void operator()( osg::Node* node, osg::NodeVisitor* );
94  };
95 
96 
97 
98 
99  // Only enable this if OpenCV2 is enabled
100 #ifdef SAW_OPENSCENEGRAPH_SUPPORTS_OPENCV
101 
103 
107  class FinalDrawCallback : public osg::Camera::DrawCallback {
108 
109  public:
110 
111  // Data for the final draw callback. This data is used to copy images
112  // outside the drawing traversal.
113  class Data : public osg::Referenced {
114 
115  private:
116 
117  bool rangerequest;
118  bool depthrequest;
119  bool colorrequest;
120 
122 
128  vctDynamicMatrix<double> rangedata;
129 
131 
135  cv::Mat depthimage;
136 
138  cv::Mat rgbimage;
139 
140  public:
141 
142  Data( size_t width, size_t height );
143  ~Data();
144 
145  void RequestRangeData() { rangerequest = true; }
146  void RequestDepthImage() { depthrequest = true; }
147  void RequestRGBImage() { colorrequest = true; }
148 
149  bool RangeDataRequested() const { return rangerequest; }
150  bool DepthImageRequested() const { return depthrequest; }
151  bool RGBImageRequested() const { return colorrequest; }
152 
153  vctDynamicMatrix<double> GetRangeData() const;
154  cv::Mat GetDepthImage() const;
155  cv::Mat GetRGBImage() const;
156 
157  void SetRangeData( const vctDynamicMatrix<double>& rangedata );
158  void SetDepthImage( const cv::Mat& depthimage );
159  void SetRGBImage( const cv::Mat& rgbimage );
160 
161  }; // Data
162 
163  private:
164 
166  osg::ref_ptr<osg::Image> depthbufferimg;
167 
169  osg::ref_ptr<osg::Image> colorbufferimg;
170 
172 
177  virtual void operator () ( osg::RenderInfo& ) const;
178 
180  void ComputeRangeData( osg::Camera* camera ) const;
181 
183  void ComputeDepthImage( osg::Camera* camera ) const;
184 
186  void ComputeRGBImage( osg::Camera* camera ) const;
187 
188  public:
189 
191 
198  FinalDrawCallback( osg::Camera* camera );
199 
200  ~FinalDrawCallback();
201 
202  }; // FinalDrawCallback
203 
204 #endif // SAW_OPENSCENEGRAPH_SUPPORTS_OPENCV
205 
206  std::vector< osg::ref_ptr< osaOSGHUD > > huds;
207  void AddHUD( osaOSGHUD* hud );
208 
209  public :
210 
212 
221  osaOSGCamera( osaOSGWorld* world,
222  bool trackball = true,
223  const vctFrame4x4<double>& Rtoffset = vctFrame4x4<double>(),
224  bool offscreenrendering = false );
225 
226  ~osaOSGCamera();
227 
228  virtual void Initialize( const std::string& CMN_UNUSED(name)=std::string() ){}
229 
230  void setCullMask( osg::Node::NodeMask mask )
231  { getCamera()->setCullMask( mask ); }
232 
233  void SetTransform( const vctFrm3& Rt );
234  void SetTransform( const vctFrame4x4<double>& Rt );
235  vctFrm3 GetTransform() const;
236 
237 };
238 
239 #endif
#define CISST_EXPORT
Definition: cmnExportMacros.h:50
Declaration of vctDynamicMatrix.
Portability across compilers and operating systems tools.
#define CMN_UNUSED(argument)
Definition: cmnPortability.h:479
bool IsOffscreenRenderingEnabled() const
Definition: osaOSGCamera.h:57
Definition: osaOSGCamera.h:33
Typedef for different transformations.
User data for the camera.
Definition: osaOSGCamera.h:65
Definition: mtsOSGCameraTask.h:28
Definition: osaOSGWorld.h:24
Definition: osaOSGHUD.h:15
Declaration of vctFrame4x4.
Errno
Definition: osaOSGCamera.h:33
osaOSGCamera * GetCamera()
Get the pointer to the camera.
Definition: osaOSGCamera.h:73
Update Callback.
Definition: osaOSGCamera.h:86
std::vector< osg::ref_ptr< osaOSGHUD > > huds
Definition: osaOSGCamera.h:206
std::string Mat
Definition: svlTypes.h:72
Data(osaOSGCamera *camera)
Default constructor.
Definition: osaOSGCamera.h:71
void setCullMask(osg::Node::NodeMask mask)
Definition: osaOSGCamera.h:230
virtual void Initialize(const std::string &CMN_UNUSED(name)=std::string())
Definition: osaOSGCamera.h:228
Definition: osaOSGCamera.h:27