All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GpuLaser.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2012 Nate Koenig
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 /* Desc: A laser sensor using OpenGL
18  * Author: Mihai Emanuel Dolha
19  * Date: 29 March 2012
20  */
21 
22 #ifndef _GPULASER_HH_
23 #define _GPULASER_HH_
24 
25 #include <string>
26 #include <vector>
27 
31 
32 #include "gazebo/common/Event.hh"
33 #include "gazebo/common/Time.hh"
34 
35 #include "gazebo/math/Angle.hh"
36 #include "gazebo/math/Pose.hh"
37 #include "gazebo/math/Vector2i.hh"
38 
39 #include "gazebo/sdf/sdf.hh"
40 
41 namespace Ogre
42 {
43  class Material;
44  class Renderable;
45  class Pass;
46  class AutoParamDataSource;
47  class Matrix4;
48  class MovableObject;
49 }
50 
51 namespace gazebo
52 {
53  namespace common
54  {
55  class Mesh;
56  }
57 
58  namespace rendering
59  {
60  class Scene;
61 
64 
67  class GpuLaser : public Camera, public Ogre::RenderObjectListener
68  {
73  public: GpuLaser(const std::string &_namePrefix,
74  Scene *_scene, bool _autoRender = true);
75 
77  public: virtual ~GpuLaser();
78 
79  // Documentation inherited
80  public: virtual void Load(sdf::ElementPtr &_sdf);
81 
82  // Documentation inherited
83  public: virtual void Load();
84 
85  // Documentation inherited
86  public: virtual void Init();
87 
88  // Documentation inherited
89  public: virtual void Fini();
90 
93  public: void CreateLaserTexture(const std::string &_textureName);
94 
95  // Documentation inherited
96  public: virtual void PostRender();
97 
100  public: const float *GetLaserData();
101 
106  public: template<typename T>
108  { return newLaserFrame.Connect(_subscriber); }
109 
113  { newLaserFrame.Disconnect(_c); }
114 
118  public: void SetRangeCount(unsigned int _w, unsigned int _h = 1);
119 
122  public: void SetParentSensor(sensors::GpuRaySensor *_parent);
123 
126  public: virtual void notifyRenderSingleObject(Ogre::Renderable *_rend,
127  const Ogre::Pass *_p, const Ogre::AutoParamDataSource *_s,
128  const Ogre::LightList *_ll, bool _supp);
129 
130  // Documentation inherited.
131  private: virtual void RenderImpl();
132 
138  private: void UpdateRenderTarget(Ogre::RenderTarget *_target,
139  Ogre::Material *_material,
140  Ogre::Camera *_cam,
141  bool _updateTex = false);
142 
144  private: void CreateOrthoCam();
145 
147  private: void CreateMesh();
148 
150  private: void CreateCanvas();
151 
160  private: Ogre::Matrix4 BuildScaledOrthoMatrix(float _left, float _right,
161  float _bottom, float _top, float _near, float _far);
162 
166  private: virtual void Set1stPassTarget(Ogre::RenderTarget *_target,
167  unsigned int _index);
168 
171  private: virtual void Set2ndPassTarget(Ogre::RenderTarget *_target);
172 
173  private: event::EventT<void(const float *, unsigned int, unsigned int,
174  unsigned int, const std::string &)> newLaserFrame;
175 
176  private: float *laserBuffer;
177  private: float *laserScan;
178  private: Ogre::Material *mat_1st_pass;
179  private: Ogre::Material *mat_2nd_pass;
180 
181  private: Ogre::Texture *_1stPassTextures[3];
182  private: Ogre::Texture *_2ndPassTexture;
183  private: Ogre::RenderTarget *_1stPassTargets[3];
184  private: Ogre::RenderTarget *_2ndPassTarget;
185  private: Ogre::Viewport *_1stPassViewports[3];
186  private: Ogre::Viewport *_2ndPassViewport;
187 
188  private: unsigned int _textureCount;
189  private: double cameraYaws[4];
190 
191  private: Ogre::RenderTarget *current_target;
192  private: Ogre::Material *current_mat;
193 
194  private: Ogre::Camera *orthoCam;
195 
196  private: Ogre::SceneNode *origParentNode_ortho;
197  private: Ogre::SceneNode *pitchNode_ortho;
198 
199  private: common::Mesh *undist_mesh;
200 
201  private: Ogre::MovableObject *object;
202 
203  private: VisualPtr visual;
204 
205  private: unsigned int w2nd;
206  private: unsigned int h2nd;
207 
208  private: sensors::GpuRaySensor *parent_sensor;
209  private: double lastRenderDuration;
210 
211  private: std::vector<int> texIdx;
212  private: static int texCount;
213  };
215  }
216 }
217 #endif