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 
28 #include "gazebo/util/system.hh"
29 
30 namespace Ogre
31 {
32  class Material;
33  class Renderable;
34  class Pass;
35  class AutoParamDataSource;
36  class Matrix4;
37  class MovableObject;
38 }
39 
40 namespace gazebo
41 {
42  namespace common
43  {
44  class Mesh;
45  }
46 
47  namespace rendering
48  {
49  // Forward declare private data.
50  class GpuLaserPrivate;
51 
54 
57  class GZ_RENDERING_VISIBLE GpuLaser
58  : public Camera, public Ogre::RenderObjectListener
59  {
64  public: GpuLaser(const std::string &_namePrefix,
65  ScenePtr _scene, const bool _autoRender = true);
66 
68  public: virtual ~GpuLaser();
69 
70  // Documentation inherited
71  public: virtual void Load(sdf::ElementPtr _sdf);
72 
73  // Documentation inherited
74  public: virtual void Load();
75 
76  // Documentation inherited
77  public: virtual void Init();
78 
79  // Documentation inherited
80  public: virtual void Fini();
81 
84  public: void CreateLaserTexture(const std::string &_textureName);
85 
86  // Documentation inherited
87  public: virtual void PostRender();
88 
91  public: const float *LaserData() const;
92 
97  public: event::ConnectionPtr ConnectNewLaserFrame(
98  std::function<void (const float *_frame, unsigned int _width,
99  unsigned int _height, unsigned int _depth,
100  const std::string &_format)> _subscriber);
101 
105  public: void DisconnectNewLaserFrame(event::ConnectionPtr &_c)
106  GAZEBO_DEPRECATED(8.0);
107 
111  public: void SetRangeCount(const unsigned int _w,
112  const unsigned int _h = 1);
113 
116  public: virtual void notifyRenderSingleObject(Ogre::Renderable *_rend,
117  const Ogre::Pass *_p, const Ogre::AutoParamDataSource *_s,
118  const Ogre::LightList *_ll, bool _supp);
119 
122  public: double HorzHalfAngle() const;
123 
126  public: double VertHalfAngle() const;
127 
130  public: void SetHorzHalfAngle(const double _angle);
131 
134  public: void SetVertHalfAngle(const double _angle);
135 
138  public: void SetIsHorizontal(const bool _horizontal);
139 
142  public: bool IsHorizontal() const;
143 
146  public: double HorzFOV() const;
147 
150  public: double CosHorzFOV() const;
151 
154  public: void SetCosHorzFOV(const double _chfov);
155 
158  public: double VertFOV() const;
159 
162  public: double CosVertFOV() const;
163 
166  public: void SetCosVertFOV(const double _cvfov);
167 
170  public: double NearClip() const;
171 
174  public: double FarClip() const;
175 
178  public: void SetNearClip(const double _near);
179 
182  public: void SetFarClip(const double _far);
183 
186  public: void SetHorzFOV(const double _hfov);
187 
190  public: void SetVertFOV(const double _vfov);
191 
194  public: unsigned int CameraCount() const;
195 
199  public: void SetCameraCount(const unsigned int _cameraCount);
200 
203  public: double RayCountRatio() const;
204 
207  public: void SetRayCountRatio(const double _rayCountRatio);
208 
209  // Documentation inherited.
210  private: virtual void RenderImpl();
211 
217  private: void UpdateRenderTarget(Ogre::RenderTarget *_target,
218  Ogre::Material *_material,
219  Ogre::Camera *_cam,
220  const bool _updateTex = false);
221 
223  private: void CreateOrthoCam();
224 
226  private: void CreateMesh();
227 
229  private: void CreateCanvas();
230 
239  private: Ogre::Matrix4 BuildScaledOrthoMatrix(const float _left,
240  const float _right, const float _bottom, const float _top,
241  const float _near, const float _far);
242 
246  private: virtual void Set1stPassTarget(Ogre::RenderTarget *_target,
247  const unsigned int _index);
248 
251  private: virtual void Set2ndPassTarget(Ogre::RenderTarget *_target);
252 
254  protected: double horzHalfAngle;
255 
257  protected: double vertHalfAngle;
258 
260  protected: double rayCountRatio;
261 
263  protected: double hfov;
264 
266  protected: double vfov;
267 
269  protected: double chfov;
270 
272  protected: double cvfov;
273 
275  protected: double nearClip;
276 
278  protected: double farClip;
279 
281  protected: bool isHorizontal;
282 
284  protected: unsigned int cameraCount;
285 
288  private: std::unique_ptr<GpuLaserPrivate> dataPtr;
289  };
291  }
292 }
293 #endif
Basic camera sensor.
Definition: Camera.hh:85
double farClip
Far clip plane.
Definition: GpuLaser.hh:278
GPU based laser distance sensor.
Definition: GpuLaser.hh:57
double vertHalfAngle
Vertical half angle.
Definition: GpuLaser.hh:257
boost::shared_ptr< Scene > ScenePtr
Definition: RenderTypes.hh:81
double nearClip
Near clip plane.
Definition: GpuLaser.hh:275
bool isHorizontal
True if the sensor is horizontal only.
Definition: GpuLaser.hh:281
double hfov
Horizontal field-of-view.
Definition: GpuLaser.hh:263
double vfov
Vertical field-of-view.
Definition: GpuLaser.hh:266
boost::shared_ptr< Connection > ConnectionPtr
Definition: CommonTypes.hh:134
double chfov
Cos horizontal field-of-view.
Definition: GpuLaser.hh:269
#define GAZEBO_DEPRECATED(version)
Definition: system.hh:302
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
double rayCountRatio
Ray count ratio.
Definition: GpuLaser.hh:260
double horzHalfAngle
Horizontal half angle.
Definition: GpuLaser.hh:254
double cvfov
Cos vertical field-of-view.
Definition: GpuLaser.hh:272
unsigned int cameraCount
Number of cameras needed to generate the rays.
Definition: GpuLaser.hh:284