All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Heightmap.hh
Go to the documentation of this file.
1 /*
2  * Copyright 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 /* Desc: Heightmap geometry
18  * Author: Nate Koenig
19  * Date: 12 May 2009
20  */
21 
22 #ifndef _HEIGHTMAP_HH_
23 #define _HEIGHTMAP_HH_
24 
25 #include <string>
26 #include <vector>
27 
29 
30 #include "common/Image.hh"
31 #include "math/Vector3.hh"
32 #include "math/Vector2d.hh"
33 #include "rendering/Scene.hh"
34 
35 namespace Ogre
36 {
37  class TerrainGlobalOptions;
38  class TerrainGroup;
39  class Terrain;
40 }
41 
42 namespace gazebo
43 {
44  namespace rendering
45  {
48 
51  class Heightmap
52  {
55  public: Heightmap(ScenePtr _scene);
56 
58  public: virtual ~Heightmap();
59 
61  public: void Load();
62 
65  public: void LoadFromMsg(ConstVisualPtr &_msg);
66 
72  public: double GetHeight(double _x, double _y, double _z = 1000);
73 
76  public: Ogre::TerrainGroup *GetOgreTerrain() const;
77 
80  private: bool InitBlendMaps(Ogre::Terrain *_terrain);
81 
83  private: void ConfigureTerrainDefaults();
84 
88  private: void DefineTerrain(int _x, int _y);
89 
92  private: void SetupShadows(bool _enabled);
93 
95  private: ScenePtr scene;
96 
98  private: common::Image heightImage;
99 
101  private: math::Vector3 terrainSize;
102 
104  private: unsigned int imageSize;
105 
107  private: double maxPixel;
108 
110  private: math::Vector3 terrainOrigin;
111 
113  private: Ogre::TerrainGlobalOptions *terrainGlobals;
114 
116  private: Ogre::TerrainGroup *terrainGroup;
117 
119  private: bool terrainsImported;
120 
122  private: std::vector<std::string> diffuseTextures;
123 
125  private: std::vector<std::string> normalTextures;
126 
128  private: std::vector<double> worldSizes;
129 
131  private: std::vector<double> blendHeight;
132 
134  private: std::vector<double> blendFade;
135  };
137 
140  class GzTerrainMatGen : public Ogre::TerrainMaterialGeneratorA
141  {
143  public: GzTerrainMatGen();
144 
146  public: virtual ~GzTerrainMatGen();
147 
149  public: class SM2Profile :
150  public Ogre::TerrainMaterialGeneratorA::SM2Profile
151  {
153  public: SM2Profile(Ogre::TerrainMaterialGenerator *_parent,
154  const Ogre::String &_name, const Ogre::String &_desc);
155 
157  public: virtual ~SM2Profile();
158 
159  public: Ogre::MaterialPtr generate(const Ogre::Terrain *_terrain);
160 
161  public: Ogre::MaterialPtr generateForCompositeMap(
162  const Ogre::Terrain *_terrain);
163 
164  public: void UpdateParams(const Ogre::MaterialPtr &_mat,
165  const Ogre::Terrain *_terrain);
166 
167  public: void UpdateParamsForCompositeMap(const Ogre::MaterialPtr &_mat,
168  const Ogre::Terrain *_terrain);
169 
170  protected: virtual void addTechnique(const Ogre::MaterialPtr &_mat,
171  const Ogre::Terrain *_terrain, TechniqueType _tt);
172 
174  protected: class ShaderHelperGLSL :
175  public Ogre::TerrainMaterialGeneratorA::SM2Profile::ShaderHelperGLSL
176  {
177  public: virtual Ogre::HighLevelGpuProgramPtr generateVertexProgram(
178  const SM2Profile *_prof, const Ogre::Terrain *_terrain,
179  TechniqueType _tt);
180 
181  public: virtual Ogre::HighLevelGpuProgramPtr generateFragmentProgram(
182  const SM2Profile *_prof, const Ogre::Terrain *_terrain,
183  TechniqueType _tt);
184 
185  public: virtual void updateParams(const SM2Profile *_prof,
186  const Ogre::MaterialPtr &_mat,
187  const Ogre::Terrain *_terrain, bool _compositeMap);
188 
189  protected: virtual void generateVpHeader(const SM2Profile *_prof,
190  const Ogre::Terrain *_terrain, TechniqueType _tt,
191  Ogre::StringUtil::StrStreamType &_outStream);
192 
193  protected: virtual void generateVpFooter(const SM2Profile *_prof,
194  const Ogre::Terrain *_terrain, TechniqueType _tt,
195  Ogre::StringUtil::StrStreamType &_outStream);
196 
197  protected: virtual void generateVertexProgramSource(
198  const SM2Profile *_prof, const Ogre::Terrain *_terrain,
199  TechniqueType _tt,
200  Ogre::StringUtil::StrStreamType &_outStream);
201 
202  protected: virtual void defaultVpParams(const SM2Profile *_prof,
203  const Ogre::Terrain *_terrain, TechniqueType _tt,
204  const Ogre::HighLevelGpuProgramPtr &_prog);
205 
206  protected: virtual unsigned int generateVpDynamicShadowsParams(
207  unsigned int _texCoordStart, const SM2Profile *_prof,
208  const Ogre::Terrain *_terrain, TechniqueType _tt,
209  Ogre::StringUtil::StrStreamType &_outStream);
210 
211  protected: virtual void generateVpDynamicShadows(
212  const SM2Profile *_prof, const Ogre::Terrain *_terrain,
213  TechniqueType _tt,
214  Ogre::StringUtil::StrStreamType &_outStream);
215 
216  protected: virtual void generateFpHeader(const SM2Profile *_prof,
217  const Ogre::Terrain *_terrain,
218  TechniqueType tt,
219  Ogre::StringUtil::StrStreamType &_outStream);
220 
221  protected: virtual void generateFpLayer(const SM2Profile *_prof,
222  const Ogre::Terrain *_terrain, TechniqueType tt,
223  Ogre::uint _layer,
224  Ogre::StringUtil::StrStreamType &_outStream);
225 
226  protected: virtual void generateFpFooter(const SM2Profile *_prof,
227  const Ogre::Terrain *_terrain,
228  TechniqueType tt,
229  Ogre::StringUtil::StrStreamType &_outStream);
230 
231  protected: virtual void generateFpDynamicShadowsParams(
232  Ogre::uint *_texCoord, Ogre::uint *_sampler,
233  const SM2Profile *_prof, const Ogre::Terrain *_terrain,
234  TechniqueType _tt,
235  Ogre::StringUtil::StrStreamType &_outStream);
236 
237  protected: virtual void generateFpDynamicShadowsHelpers(
238  const SM2Profile *_prof,
239  const Ogre::Terrain *_terrain,
240  TechniqueType tt,
241  Ogre::StringUtil::StrStreamType &_outStream);
242 
243  protected: void generateFpDynamicShadows(const SM2Profile *_prof,
244  const Ogre::Terrain *_terrain, TechniqueType _tt,
245  Ogre::StringUtil::StrStreamType &_outStream);
246 
247  protected: virtual void generateFragmentProgramSource(
248  const SM2Profile *_prof,
249  const Ogre::Terrain *_terrain,
250  TechniqueType _tt,
251  Ogre::StringUtil::StrStreamType &_outStream);
252 
253  protected: virtual void updateVpParams(const SM2Profile *_prof,
254  const Ogre::Terrain *_terrain, TechniqueType _tt,
255  const Ogre::GpuProgramParametersSharedPtr &_params);
256 
257  private: Ogre::String GetChannel(Ogre::uint _idx);
258  };
259 
262  protected: class ShaderHelperCg :
263  public Ogre::TerrainMaterialGeneratorA::SM2Profile::ShaderHelperCg
264  {
265  public: virtual Ogre::HighLevelGpuProgramPtr generateFragmentProgram(
266  const SM2Profile *_prof, const Ogre::Terrain *_terrain,
267  TechniqueType _tt);
268 
269  public: virtual Ogre::HighLevelGpuProgramPtr generateVertexProgram(
270  const SM2Profile *_prof, const Ogre::Terrain *_terrain,
271  TechniqueType _tt);
272 
273  protected: virtual void generateVpHeader(const SM2Profile *_prof,
274  const Ogre::Terrain *_terrain, TechniqueType _tt,
275  Ogre::StringUtil::StrStreamType &_outStream);
276 
277  protected: virtual void generateVpFooter(const SM2Profile *_prof,
278  const Ogre::Terrain *_terrain, TechniqueType _tt,
279  Ogre::StringUtil::StrStreamType &_outStream);
280 
281  protected: virtual void generateVertexProgramSource(
282  const SM2Profile *_prof, const Ogre::Terrain *_terrain,
283  TechniqueType _tt,
284  Ogre::StringUtil::StrStreamType &_outStream);
285 
286  protected: virtual void defaultVpParams(const SM2Profile *_prof,
287  const Ogre::Terrain *_terrain, TechniqueType _tt,
288  const Ogre::HighLevelGpuProgramPtr &_prog);
289 
290  protected: virtual unsigned int generateVpDynamicShadowsParams(
291  unsigned int _texCoordStart, const SM2Profile *_prof,
292  const Ogre::Terrain *_terrain, TechniqueType _tt,
293  Ogre::StringUtil::StrStreamType &_outStream);
294 
295  protected: virtual void generateVpDynamicShadows(
296  const SM2Profile *_prof, const Ogre::Terrain *_terrain,
297  TechniqueType _tt,
298  Ogre::StringUtil::StrStreamType &_outStream);
299  };
300  };
301  };
302  }
303 }
304 #endif