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 2011 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 
28 #include "rendering/ogre_gazebo.h"
29 #include "rendering/Camera.hh"
30 #include "sensors/SensorTypes.hh"
31 
32 #include "common/Event.hh"
33 #include "common/Time.hh"
34 
35 #include "math/Angle.hh"
36 #include "math/Pose.hh"
37 #include "math/Vector2i.hh"
38 
39 #include "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 
69  class GpuLaser : public Camera, public Ogre::RenderObjectListener
70  {
75  public: GpuLaser(const std::string &_namePrefix,
76  Scene *_scene, bool _autoRender = true);
77 
79  public: virtual ~GpuLaser();
80 
83  public: void Load(sdf::ElementPtr &_sdf);
84 
86  public: void Load();
87 
89  public: void Init();
90 
92  public: void Fini();
93 
96  public: void CreateLaserTexture(const std::string &_textureName);
97 
99  public: virtual void PostRender();
100 
103  public: virtual const float *GetLaserData();
104 
109  public: template<typename T>
111  { return newLaserFrame.Connect(_subscriber); }
112 
116  { newLaserFrame.Disconnect(_c); }
117 
121  public: void SetRangeCount(unsigned int _w, unsigned int _h = 1);
122 
125  public: void SetParentSensor(sensors::GpuRaySensor *_parent);
126 
129  public: virtual void notifyRenderSingleObject(Ogre::Renderable *_rend,
130  const Ogre::Pass *_p, const Ogre::AutoParamDataSource *_s,
131  const Ogre::LightList *_ll, bool _supp);
132 
134  private: virtual void RenderImpl();
135 
136  private: void UpdateRenderTarget(Ogre::RenderTarget *target,
137  Ogre::Material *material,
138  Ogre::Camera *cam,
139  bool updateTex = false);
140 
141  private: void CreateOrthoCam();
142 
143  private: void CreateMesh();
144 
145  private: void CreateCanvas();
146 
147  private: Ogre::Matrix4 BuildScaledOrthoMatrix(float left, float right,
148  float bottom, float top, float near, float far);
149 
150  private: virtual void Set1stPassTarget(Ogre::RenderTarget *target,
151  unsigned int index);
152 
153  private: virtual void Set2ndPassTarget(Ogre::RenderTarget *target);
154 
155  private: event::EventT<void(const float *, unsigned int, unsigned int,
156  unsigned int, const std::string &)> newLaserFrame;
157 
158  private: float *laserBuffer;
159  private: float *laserScan;
160  private: Ogre::Material *mat_1st_pass;
161  private: Ogre::Material *mat_2nd_pass;
162 
163  private: Ogre::Texture *_1stPassTextures[3];
164  private: Ogre::Texture *_2ndPassTexture;
165  private: Ogre::RenderTarget *_1stPassTargets[3];
166  private: Ogre::RenderTarget *_2ndPassTarget;
167  private: Ogre::Viewport *_1stPassViewports[3];
168  private: Ogre::Viewport *_2ndPassViewport;
169 
170  private: unsigned int _textureCount;
171  private: double cameraYaws[4];
172 
173  private: Ogre::RenderTarget *current_target;
174  private: Ogre::Material *current_mat;
175 
176  private: Ogre::Camera *orthoCam;
177 
178  private: Ogre::SceneNode *origParentNode_ortho;
179  private: Ogre::SceneNode *pitchNode_ortho;
180 
181  private: common::Mesh *undist_mesh;
182 
183  private: Ogre::MovableObject *object;
184 
185  private: VisualPtr visual;
186 
187  private: unsigned int w2nd;
188  private: unsigned int h2nd;
189 
190  private: sensors::GpuRaySensor *parent_sensor;
191  private: double lastRenderDuration;
192 
193  private: std::vector<int> texIdx;
194  private: static int texCount;
195  };
197  }
198 }
199 #endif