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 SetRangeCount(const unsigned int _w,
106  const unsigned int _h = 1);
107 
110  public: virtual void notifyRenderSingleObject(Ogre::Renderable *_rend,
111  const Ogre::Pass *_p, const Ogre::AutoParamDataSource *_s,
112  const Ogre::LightList *_ll, bool _supp);
113 
116  public: double HorzHalfAngle() const;
117 
120  public: double VertHalfAngle() const;
121 
124  public: void SetHorzHalfAngle(const double _angle);
125 
128  public: void SetVertHalfAngle(const double _angle);
129 
132  public: void SetIsHorizontal(const bool _horizontal);
133 
136  public: bool IsHorizontal() const;
137 
140  public: double HorzFOV() const;
141 
144  public: double CosHorzFOV() const;
145 
148  public: void SetCosHorzFOV(const double _chfov);
149 
152  public: double VertFOV() const;
153 
156  public: double CosVertFOV() const;
157 
160  public: void SetCosVertFOV(const double _cvfov);
161 
164  public: double NearClip() const;
165 
168  public: double FarClip() const;
169 
172  public: void SetNearClip(const double _near);
173 
176  public: void SetFarClip(const double _far);
177 
180  public: void SetHorzFOV(const double _hfov);
181 
184  public: void SetVertFOV(const double _vfov);
185 
188  public: unsigned int CameraCount() const;
189 
193  public: void SetCameraCount(const unsigned int _cameraCount);
194 
197  public: double RayCountRatio() const;
198 
201  public: void SetRayCountRatio(const double _rayCountRatio);
202 
203  // Documentation inherited.
204  private: virtual void RenderImpl();
205 
211  private: void UpdateRenderTarget(Ogre::RenderTarget *_target,
212  Ogre::Material *_material,
213  Ogre::Camera *_cam,
214  const bool _updateTex = false);
215 
217  private: void CreateOrthoCam();
218 
220  private: void CreateMesh();
221 
223  private: void CreateCanvas();
224 
233  private: Ogre::Matrix4 BuildScaledOrthoMatrix(const float _left,
234  const float _right, const float _bottom, const float _top,
235  const float _near, const float _far);
236 
240  private: virtual void Set1stPassTarget(Ogre::RenderTarget *_target,
241  const unsigned int _index);
242 
245  private: virtual void Set2ndPassTarget(Ogre::RenderTarget *_target);
246 
248  protected: double horzHalfAngle;
249 
251  protected: double vertHalfAngle;
252 
254  protected: double rayCountRatio;
255 
257  protected: double hfov;
258 
260  protected: double vfov;
261 
263  protected: double chfov;
264 
266  protected: double cvfov;
267 
269  protected: double nearClip;
270 
272  protected: double farClip;
273 
275  protected: bool isHorizontal;
276 
278  protected: unsigned int cameraCount;
279 
282  private: std::unique_ptr<GpuLaserPrivate> dataPtr;
283  };
285  }
286 }
287 #endif
Basic camera sensor.
Definition: Camera.hh:80
double farClip
Far clip plane.
Definition: GpuLaser.hh:272
GPU based laser distance sensor.
Definition: GpuLaser.hh:57
Forward declarations for the common classes.
Definition: Animation.hh:33
double vertHalfAngle
Vertical half angle.
Definition: GpuLaser.hh:251
boost::shared_ptr< Scene > ScenePtr
Definition: RenderTypes.hh:81
double nearClip
Near clip plane.
Definition: GpuLaser.hh:269
bool isHorizontal
True if the sensor is horizontal only.
Definition: GpuLaser.hh:275
double hfov
Horizontal field-of-view.
Definition: GpuLaser.hh:257
double vfov
Vertical field-of-view.
Definition: GpuLaser.hh:260
boost::shared_ptr< Connection > ConnectionPtr
Definition: CommonTypes.hh:134
double chfov
Cos horizontal field-of-view.
Definition: GpuLaser.hh:263
Definition: JointMaker.hh:39
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
double rayCountRatio
Ray count ratio.
Definition: GpuLaser.hh:254
double horzHalfAngle
Horizontal half angle.
Definition: GpuLaser.hh:248
double cvfov
Cos vertical field-of-view.
Definition: GpuLaser.hh:266
unsigned int cameraCount
Number of cameras needed to generate the rays.
Definition: GpuLaser.hh:278