GpuLaser.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 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 <memory>
21 #include <string>
22 
23 #include <sdf/sdf.hh>
24 
29 #include "gazebo/util/system.hh"
30 
31 namespace Ogre
32 {
33  class Material;
34  class Renderable;
35  class Pass;
36  class AutoParamDataSource;
37  class Matrix4;
38  class MovableObject;
39 }
40 
41 namespace gazebo
42 {
43  namespace common
44  {
45  class Mesh;
46  }
47 
48  namespace rendering
49  {
50  // Forward declare private data.
51  class GpuLaserPrivate;
52 
55 
58  class GZ_RENDERING_VISIBLE GpuLaser
59  : public Camera, public Ogre::RenderObjectListener
60  {
65  public: GpuLaser(const std::string &_namePrefix,
66  ScenePtr _scene, const bool _autoRender = true);
67 
69  public: virtual ~GpuLaser();
70 
71  // Documentation inherited
72  public: virtual void Load(sdf::ElementPtr _sdf);
73 
74  // Documentation inherited
75  public: virtual void Load();
76 
77  // Documentation inherited
78  public: virtual void Init();
79 
80  // Documentation inherited
81  public: virtual void Fini();
82 
85  public: void CreateLaserTexture(const std::string &_textureName);
86 
87  // Documentation inherited
88  public: virtual void PostRender();
89 
92 
94  public: DataIter LaserDataBegin() const;
95 
97  public: DataIter LaserDataEnd() const;
98 
104  std::function<void (const float *_frame, unsigned int _width,
105  unsigned int _height, unsigned int _depth,
106  const std::string &_format)> _subscriber);
107 
112  public: void SetRangeCount(const unsigned int _w,
113  const unsigned int _h = 1);
114 
117  public: virtual void notifyRenderSingleObject(Ogre::Renderable *_rend,
118  const Ogre::Pass *_p, const Ogre::AutoParamDataSource *_s,
119  const Ogre::LightList *_ll, bool _supp);
120 
123  public: double HorzHalfAngle() const;
124 
127  public: double VertHalfAngle() const;
128 
131  public: void SetHorzHalfAngle(const double _angle);
132 
135  public: void SetVertHalfAngle(const double _angle);
136 
139  public: void SetIsHorizontal(const bool _horizontal);
140 
143  public: bool IsHorizontal() const;
144 
147  public: double HorzFOV() const;
148 
151  public: double CosHorzFOV() const;
152 
155  public: void SetCosHorzFOV(const double _chfov);
156 
159  public: double VertFOV() const;
160 
163  public: double CosVertFOV() const;
164 
167  public: void SetCosVertFOV(const double _cvfov);
168 
171  public: double NearClip() const;
172 
175  public: double FarClip() const;
176 
179  public: void SetNearClip(const double _near);
180 
183  public: void SetFarClip(const double _far);
184 
187  public: void SetHorzFOV(const double _hfov);
188 
191  public: void SetVertFOV(const double _vfov);
192 
195  public: unsigned int CameraCount() const;
196 
200  public: void SetCameraCount(const unsigned int _cameraCount);
201 
204  public: double RayCountRatio() const;
205 
208  public: void SetRayCountRatio(const double _rayCountRatio);
209 
210  // Documentation inherited.
211  private: virtual void RenderImpl();
212 
218  private: void UpdateRenderTarget(Ogre::RenderTarget *_target,
219  Ogre::Material *_material,
220  Ogre::Camera *_cam,
221  const bool _updateTex = false);
222 
224  private: void CreateOrthoCam();
225 
227  private: void CreateMesh();
228 
230  private: void CreateCanvas();
231 
240  private: Ogre::Matrix4 BuildScaledOrthoMatrix(const float _left,
241  const float _right, const float _bottom, const float _top,
242  const float _near, const float _far);
243 
247  private: virtual void Set1stPassTarget(Ogre::RenderTarget *_target,
248  const unsigned int _index);
249 
252  private: virtual void Set2ndPassTarget(Ogre::RenderTarget *_target);
253 
255  protected: double horzHalfAngle;
256 
258  protected: double vertHalfAngle;
259 
261  protected: double rayCountRatio;
262 
264  protected: double hfov;
265 
267  protected: double vfov;
268 
270  protected: double chfov;
271 
273  protected: double cvfov;
274 
276  protected: double nearClip;
277 
279  protected: double farClip;
280 
282  protected: bool isHorizontal;
283 
285  protected: unsigned int cameraCount;
286 
289  private: std::unique_ptr<GpuLaserPrivate> dataPtr;
290  };
292  }
293 }
294 #endif
double vfov
Vertical field-of-view.
Definition: GpuLaser.hh:267
Definition: JointMaker.hh:40
void SetVertFOV(const double _vfov)
Set the vertical fov.
virtual void Load()
Load the camera with default parameters.
double horzHalfAngle
Horizontal half angle.
Definition: GpuLaser.hh:255
Forward declarations for the common classes.
Definition: Animation.hh:27
virtual ~GpuLaser()
Destructor.
double CosVertFOV() const
Get Cos Vert field-of-view.
void SetCosVertFOV(const double _cvfov)
Set the Cos Horz FOV.
void SetIsHorizontal(const bool _horizontal)
Set sensor horizontal or vertical.
void SetHorzFOV(const double _hfov)
Set the horizontal fov.
common
Definition: FuelModelDatabase.hh:37
double NearClip() const
Get near clip.
void SetRangeCount(const unsigned int _w, const unsigned int _h=1)
Set the number of samples in the width and height for the first pass texture.
double hfov
Horizontal field-of-view.
Definition: GpuLaser.hh:264
bool IsHorizontal() const
Gets if sensor is horizontal.
virtual void notifyRenderSingleObject(Ogre::Renderable *_rend, const Ogre::Pass *_p, const Ogre::AutoParamDataSource *_s, const Ogre::LightList *_ll, bool _supp)
void SetNearClip(const double _near)
Set the near clip distance.
void CreateLaserTexture(const std::string &_textureName)
Create the texture which is used to render laser data.
GpuLaser(const std::string &_namePrefix, ScenePtr _scene, const bool _autoRender=true)
Constructor.
double chfov
Cos horizontal field-of-view.
Definition: GpuLaser.hh:270
event::ConnectionPtr ConnectNewLaserFrame(std::function< void(const float *_frame, unsigned int _width, unsigned int _height, unsigned int _depth, const std::string &_format)> _subscriber)
Connect to a laser frame signal.
boost::shared_ptr< Scene > ScenePtr
Definition: RenderTypes.hh:82
unsigned int CameraCount() const
Get the number of cameras required.
double vertHalfAngle
Vertical half angle.
Definition: GpuLaser.hh:258
rendering
Definition: RenderEngine.hh:31
double VertFOV() const
Get the vertical field-of-view.
double HorzFOV() const
Get the horizontal field of view of the laser sensor.
GpuLaserDataIterator< GpuLaser > DataIter
Constant iterator to access laser data.
Definition: GpuLaser.hh:91
double VertHalfAngle() const
Get (vertical_max_angle + vertical_min_angle) * 0.5.
void SetVertHalfAngle(const double _angle)
Set the vertical half angle.
virtual void Fini()
Finalize the camera.
virtual void PostRender()
Post render.
boost::shared_ptr< Connection > ConnectionPtr
Definition: CommonTypes.hh:134
void SetHorzHalfAngle(const double _angle)
Set the horizontal half angle.
double nearClip
Near clip plane.
Definition: GpuLaser.hh:276
void SetRayCountRatio(const double _rayCountRatio)
Sets the ray count ratio (equivalent to aspect ratio)
bool isHorizontal
True if the sensor is horizontal only.
Definition: GpuLaser.hh:282
double rayCountRatio
Ray count ratio.
Definition: GpuLaser.hh:261
double RayCountRatio() const
Get the ray count ratio (equivalent to aspect ratio)
double HorzHalfAngle() const
Get (horizontal_max_angle + horizontal_min_angle) * 0.5.
void SetCosHorzFOV(const double _chfov)
Set the Cos Horz FOV.
virtual void Init()
Initialize the camera.
DataIter LaserDataEnd() const
Return an iterator to one past the end of the laser data.
double CosHorzFOV() const
Get Cos Horz field-of-view.
double farClip
Far clip plane.
Definition: GpuLaser.hh:279
Basic camera sensor.
Definition: Camera.hh:86
DataIter LaserDataBegin() const
Return an iterator to the begining of the laser data.
double cvfov
Cos vertical field-of-view.
Definition: GpuLaser.hh:273
const Bidirectional iterator for laser data
Definition: GpuLaserDataIterator.hh:54
double FarClip() const
Get far clip.
void SetCameraCount(const unsigned int _cameraCount)
Set the number of cameras required.
unsigned int cameraCount
Number of cameras needed to generate the rays.
Definition: GpuLaser.hh:285
GPU based laser distance sensor.
Definition: GpuLaser.hh:60
virtual void Load(sdf::ElementPtr _sdf)
Load the camera with a set of parameters.
void SetFarClip(const double _far)
Set the far clip distance.