GpuLaser.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2015 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef _GAZEBO_RENDERING_GPULASER_HH_
18 #define _GAZEBO_RENDERING_GPULASER_HH_
19 
20 #include <string>
21 #include <vector>
22 
23 #include <sdf/sdf.hh>
24 
28 
29 #include "gazebo/common/Event.hh"
30 #include "gazebo/common/Time.hh"
31 
32 #include "gazebo/math/Angle.hh"
33 #include "gazebo/math/Pose.hh"
34 #include "gazebo/math/Vector2i.hh"
35 #include "gazebo/util/system.hh"
36 
37 namespace Ogre
38 {
39  class Material;
40  class Renderable;
41  class Pass;
42  class AutoParamDataSource;
43  class Matrix4;
44  class MovableObject;
45 }
46 
47 namespace gazebo
48 {
49  namespace common
50  {
51  class Mesh;
52  }
53 
54  namespace rendering
55  {
56  class Scene;
57 
60 
64  : public Camera, public Ogre::RenderObjectListener
65  {
70  public: GpuLaser(const std::string &_namePrefix,
71  ScenePtr _scene, bool _autoRender = true);
72 
74  public: virtual ~GpuLaser();
75 
76  // Documentation inherited
77  public: virtual void Load(sdf::ElementPtr _sdf);
78 
79  // Documentation inherited
80  public: virtual void Load();
81 
82  // Documentation inherited
83  public: virtual void Init();
84 
85  // Documentation inherited
86  public: virtual void Fini();
87 
90  public: void CreateLaserTexture(const std::string &_textureName);
91 
92  // Documentation inherited
93  public: virtual void PostRender();
94 
97  public: const float *GetLaserData();
98 
103  public: template<typename T>
105  { return newLaserFrame.Connect(_subscriber); }
106 
110  { newLaserFrame.Disconnect(_c); }
111 
115  public: void SetRangeCount(unsigned int _w, unsigned int _h = 1);
116 
119  public: virtual void notifyRenderSingleObject(Ogre::Renderable *_rend,
120  const Ogre::Pass *_p, const Ogre::AutoParamDataSource *_s,
121  const Ogre::LightList *_ll, bool _supp);
122 
125  public: double GetHorzHalfAngle() const;
126 
129  public: double GetVertHalfAngle() const;
130 
133  public: void SetHorzHalfAngle(double _angle);
134 
137  public: void SetVertHalfAngle(double _angle);
138 
141  public: void SetIsHorizontal(bool _horizontal);
142 
145  public: bool IsHorizontal() const;
146 
149  public: double GetHorzFOV() const;
150 
153  public: double GetCosHorzFOV() const;
154 
157  public: void SetCosHorzFOV(double _chfov);
158 
161  public: double GetVertFOV() const;
162 
165  public: double GetCosVertFOV() const;
166 
169  public: void SetCosVertFOV(double _cvfov);
170 
173  public: double GetNearClip() const;
174 
177  public: double GetFarClip() const;
178 
181  public: void SetNearClip(double _near);
182 
185  public: void SetFarClip(double _far);
186 
189  public: void SetHorzFOV(double _hfov);
190 
193  public: void SetVertFOV(double _vfov);
194 
197  public: double GetCameraCount() const;
198 
202  public: void SetCameraCount(double _cameraCount);
203 
206  public: double GetRayCountRatio() const;
207 
210  public: void SetRayCountRatio(double _rayCountRatio);
211 
212  // Documentation inherited.
213  private: virtual void RenderImpl();
214 
220  private: void UpdateRenderTarget(Ogre::RenderTarget *_target,
221  Ogre::Material *_material,
222  Ogre::Camera *_cam,
223  bool _updateTex = false);
224 
226  private: void CreateOrthoCam();
227 
229  private: void CreateMesh();
230 
232  private: void CreateCanvas();
233 
242  private: Ogre::Matrix4 BuildScaledOrthoMatrix(float _left, float _right,
243  float _bottom, float _top, float _near, float _far);
244 
248  private: virtual void Set1stPassTarget(Ogre::RenderTarget *_target,
249  unsigned int _index);
250 
253  private: virtual void Set2ndPassTarget(Ogre::RenderTarget *_target);
254 
256  protected: double horzHalfAngle;
257 
259  protected: double vertHalfAngle;
260 
262  protected: double rayCountRatio;
263 
265  protected: double hfov;
266 
268  protected: double vfov;
269 
271  protected: double chfov;
272 
274  protected: double cvfov;
275 
277  protected: double nearClip;
278 
280  protected: double farClip;
281 
283  protected: bool isHorizontal;
284 
286  protected: unsigned int cameraCount;
287 
294  private: event::EventT<void(const float *_frame, unsigned int _width,
295  unsigned int _height, unsigned int _depth,
296  const std::string &_format)> newLaserFrame;
297 
299  private: float *laserBuffer;
300 
302  private: float *laserScan;
303 
305  private: Ogre::Material *matFirstPass;
306 
308  private: Ogre::Material *matSecondPass;
309 
311  private: Ogre::Texture *firstPassTextures[3];
312 
314  private: Ogre::Texture *secondPassTexture;
315 
317  private: Ogre::RenderTarget *firstPassTargets[3];
318 
320  private: Ogre::RenderTarget *secondPassTarget;
321 
323  private: Ogre::Viewport *firstPassViewports[3];
324 
326  private: Ogre::Viewport *secondPassViewport;
327 
329  private: unsigned int textureCount;
330 
332  private: double cameraYaws[4];
333 
335  private: Ogre::RenderTarget *currentTarget;
336 
338  private: Ogre::Material *currentMat;
339 
342  private: Ogre::Camera *orthoCam;
343 
345  private: Ogre::SceneNode *pitchNodeOrtho;
346 
349  private: common::Mesh *undistMesh;
350 
352  private: Ogre::MovableObject *object;
353 
355  private: VisualPtr visual;
356 
358  private: unsigned int w2nd;
359 
361  private: unsigned int h2nd;
362 
364  private: double lastRenderDuration;
365 
368  private: std::vector<int> texIdx;
369 
371  private: static int texCount;
372  };
374  }
375 }
376 #endif
A 3D mesh.
Definition: Mesh.hh:44
void DisconnectNewLaserFrame(event::ConnectionPtr &_c)
Disconnect from a laser frame signal.
Definition: GpuLaser.hh:109
Basic camera sensor.
Definition: Camera.hh:78
boost::shared_ptr< Connection > ConnectionPtr
Definition: CommonTypes.hh:147
GPU based laser distance sensor.
Definition: GpuLaser.hh:63
double rayCountRatio
Ray count ratio.
Definition: GpuLaser.hh:262
double vertHalfAngle
Vertical half angle.
Definition: GpuLaser.hh:259
unsigned int cameraCount
Number of cameras needed to generate the rays.
Definition: GpuLaser.hh:286
double farClip
Far clip plane.
Definition: GpuLaser.hh:280
double nearClip
Near clip plane.
Definition: GpuLaser.hh:277
#define GZ_RENDERING_VISIBLE
Definition: system.hh:241
double hfov
Horizontal field-of-view.
Definition: GpuLaser.hh:265
event::ConnectionPtr ConnectNewLaserFrame(T _subscriber)
Connect to a laser frame signal.
Definition: GpuLaser.hh:104
double horzHalfAngle
Horizontal half angle.
Definition: GpuLaser.hh:256
double cvfov
Cos vertical field-of-view.
Definition: GpuLaser.hh:274
double chfov
Cos horizontal field-of-view.
Definition: GpuLaser.hh:271
boost::shared_ptr< Scene > ScenePtr
Definition: RenderTypes.hh:79
bool isHorizontal
True if the sensor is horizontal only.
Definition: GpuLaser.hh:283
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
A class for event processing.
Definition: Event.hh:178
boost::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:107
double vfov
Vertical field-of-view.
Definition: GpuLaser.hh:268