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 
93  public: const float *LaserData() const GAZEBO_DEPRECATED(9.0);
94 
97 
99  public: DataIter LaserDataBegin() const;
100 
102  public: DataIter LaserDataEnd() const;
103 
108  public: event::ConnectionPtr ConnectNewLaserFrame(
109  std::function<void (const float *_frame, unsigned int _width,
110  unsigned int _height, unsigned int _depth,
111  const std::string &_format)> _subscriber);
112 
116  public: void SetRangeCount(const unsigned int _w,
117  const unsigned int _h = 1);
118 
121  public: virtual void notifyRenderSingleObject(Ogre::Renderable *_rend,
122  const Ogre::Pass *_p, const Ogre::AutoParamDataSource *_s,
123  const Ogre::LightList *_ll, bool _supp);
124 
127  public: double HorzHalfAngle() const;
128 
131  public: double VertHalfAngle() const;
132 
135  public: void SetHorzHalfAngle(const double _angle);
136 
139  public: void SetVertHalfAngle(const double _angle);
140 
143  public: void SetIsHorizontal(const bool _horizontal);
144 
147  public: bool IsHorizontal() const;
148 
151  public: double HorzFOV() const;
152 
155  public: double CosHorzFOV() const;
156 
159  public: void SetCosHorzFOV(const double _chfov);
160 
163  public: double VertFOV() const;
164 
167  public: double CosVertFOV() const;
168 
171  public: void SetCosVertFOV(const double _cvfov);
172 
175  public: double NearClip() const;
176 
179  public: double FarClip() const;
180 
183  public: void SetNearClip(const double _near);
184 
187  public: void SetFarClip(const double _far);
188 
191  public: void SetHorzFOV(const double _hfov);
192 
195  public: void SetVertFOV(const double _vfov);
196 
199  public: unsigned int CameraCount() const;
200 
204  public: void SetCameraCount(const unsigned int _cameraCount);
205 
208  public: double RayCountRatio() const;
209 
212  public: void SetRayCountRatio(const double _rayCountRatio);
213 
214  // Documentation inherited.
215  private: virtual void RenderImpl();
216 
222  private: void UpdateRenderTarget(Ogre::RenderTarget *_target,
223  Ogre::Material *_material,
224  Ogre::Camera *_cam,
225  const bool _updateTex = false);
226 
228  private: void CreateOrthoCam();
229 
231  private: void CreateMesh();
232 
234  private: void CreateCanvas();
235 
244  private: Ogre::Matrix4 BuildScaledOrthoMatrix(const float _left,
245  const float _right, const float _bottom, const float _top,
246  const float _near, const float _far);
247 
251  private: virtual void Set1stPassTarget(Ogre::RenderTarget *_target,
252  const unsigned int _index);
253 
256  private: virtual void Set2ndPassTarget(Ogre::RenderTarget *_target);
257 
259  protected: double horzHalfAngle;
260 
262  protected: double vertHalfAngle;
263 
265  protected: double rayCountRatio;
266 
268  protected: double hfov;
269 
271  protected: double vfov;
272 
274  protected: double chfov;
275 
277  protected: double cvfov;
278 
280  protected: double nearClip;
281 
283  protected: double farClip;
284 
286  protected: bool isHorizontal;
287 
289  protected: unsigned int cameraCount;
290 
293  private: std::unique_ptr<GpuLaserPrivate> dataPtr;
294  };
296  }
297 }
298 #endif
Basic camera sensor.
Definition: Camera.hh:81
double farClip
Far clip plane.
Definition: GpuLaser.hh:283
GPU based laser distance sensor.
Definition: GpuLaser.hh:58
double vertHalfAngle
Vertical half angle.
Definition: GpuLaser.hh:262
boost::shared_ptr< Scene > ScenePtr
Definition: RenderTypes.hh:82
double nearClip
Near clip plane.
Definition: GpuLaser.hh:280
GpuLaserDataIterator< GpuLaser > DataIter
Constant iterator to access laser data.
Definition: GpuLaser.hh:96
bool isHorizontal
True if the sensor is horizontal only.
Definition: GpuLaser.hh:286
double hfov
Horizontal field-of-view.
Definition: GpuLaser.hh:268
double vfov
Vertical field-of-view.
Definition: GpuLaser.hh:271
const Bidirectional iterator for laser data
Definition: GpuLaserDataIterator.hh:53
boost::shared_ptr< Connection > ConnectionPtr
Definition: CommonTypes.hh:134
double chfov
Cos horizontal field-of-view.
Definition: GpuLaser.hh:274
#define GAZEBO_DEPRECATED(version)
Definition: system.hh:328
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
double rayCountRatio
Ray count ratio.
Definition: GpuLaser.hh:265
double horzHalfAngle
Horizontal half angle.
Definition: GpuLaser.hh:259
double cvfov
Cos vertical field-of-view.
Definition: GpuLaser.hh:277
unsigned int cameraCount
Number of cameras needed to generate the rays.
Definition: GpuLaser.hh:289