HeightmapPrivate.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015-2016 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_HEIGHTMAPPRIVATE_HH_
18 #define _GAZEBO_RENDERING_HEIGHTMAPPRIVATE_HH_
19 
20 #include <string>
21 #include <vector>
22 #include <boost/filesystem.hpp>
23 
24 #include <ignition/math/Vector3.hh>
25 
27 
28 namespace Ogre
29 {
30  class PageManager;
31  class PagedWorld;
32  class TerrainGlobalOptions;
33  class TerrainGroup;
34  class TerrainPaging;
35 }
36 
37 namespace gazebo
38 {
39  namespace rendering
40  {
46  class GzTerrainMatGen : public Ogre::TerrainMaterialGeneratorA
47  {
49  public: GzTerrainMatGen();
50 
52  public: virtual ~GzTerrainMatGen();
53 
55  public: class SM2Profile :
56  public Ogre::TerrainMaterialGeneratorA::SM2Profile
57  {
59  public: SM2Profile(Ogre::TerrainMaterialGenerator *_parent,
60  const Ogre::String &_name, const Ogre::String &_desc);
61 
63  public: virtual ~SM2Profile();
64 
65  public: Ogre::MaterialPtr generate(const Ogre::Terrain *_terrain);
66 
67  public: Ogre::MaterialPtr generateForCompositeMap(
68  const Ogre::Terrain *_terrain);
69 
70  public: void UpdateParams(const Ogre::MaterialPtr &_mat,
71  const Ogre::Terrain *_terrain);
72 
73  public: void UpdateParamsForCompositeMap(const Ogre::MaterialPtr &_mat,
74  const Ogre::Terrain *_terrain);
75 
76  protected: virtual void addTechnique(const Ogre::MaterialPtr &_mat,
77  const Ogre::Terrain *_terrain, TechniqueType _tt);
78 
79 #ifdef __clang__
80 #pragma clang diagnostic push
81 #pragma clang diagnostic ignored "-Woverloaded-virtual"
82 #endif // ifdef __clang__
83  protected: class ShaderHelperGLSL :
88  public Ogre::TerrainMaterialGeneratorA::SM2Profile::ShaderHelperGLSL
89  {
90  public: virtual Ogre::HighLevelGpuProgramPtr generateVertexProgram(
91  const SM2Profile *_prof, const Ogre::Terrain *_terrain,
92  TechniqueType _tt);
93 
94  public: virtual Ogre::HighLevelGpuProgramPtr generateFragmentProgram(
95  const SM2Profile *_prof, const Ogre::Terrain *_terrain,
96  TechniqueType _tt);
97 
98  public: virtual void updateParams(const SM2Profile *_prof,
99  const Ogre::MaterialPtr &_mat,
100  const Ogre::Terrain *_terrain, bool _compositeMap);
101 
102  protected: virtual void generateVpHeader(const SM2Profile *_prof,
103  const Ogre::Terrain *_terrain, TechniqueType _tt,
104  Ogre::StringStream &_outStream);
105 
106  protected: virtual void generateVpFooter(const SM2Profile *_prof,
107  const Ogre::Terrain *_terrain, TechniqueType _tt,
108  Ogre::StringStream &_outStream);
109 
110  protected: virtual void generateVertexProgramSource(
111  const SM2Profile *_prof, const Ogre::Terrain *_terrain,
112  TechniqueType _tt,
113  Ogre::StringStream &_outStream);
114 
115  protected: virtual void defaultVpParams(const SM2Profile *_prof,
116  const Ogre::Terrain *_terrain, TechniqueType _tt,
117  const Ogre::HighLevelGpuProgramPtr &_prog);
118 
119  protected: virtual unsigned int generateVpDynamicShadowsParams(
120  unsigned int _texCoordStart, const SM2Profile *_prof,
121  const Ogre::Terrain *_terrain, TechniqueType _tt,
122  Ogre::StringStream &_outStream);
123 
124  protected: virtual void generateVpDynamicShadows(
125  const SM2Profile *_prof, const Ogre::Terrain *_terrain,
126  TechniqueType _tt,
127  Ogre::StringStream &_outStream);
128 
129  protected: virtual void generateFpHeader(const SM2Profile *_prof,
130  const Ogre::Terrain *_terrain,
131  TechniqueType tt,
132  Ogre::StringStream &_outStream);
133 
134  protected: virtual void generateFpLayer(const SM2Profile *_prof,
135  const Ogre::Terrain *_terrain, TechniqueType tt,
136  Ogre::uint _layer,
137  Ogre::StringStream &_outStream);
138 
139  protected: virtual void generateFpFooter(const SM2Profile *_prof,
140  const Ogre::Terrain *_terrain,
141  TechniqueType tt,
142  Ogre::StringStream &_outStream);
143 
144  protected: virtual void generateFpDynamicShadowsParams(
145  Ogre::uint *_texCoord, Ogre::uint *_sampler,
146  const SM2Profile *_prof, const Ogre::Terrain *_terrain,
147  TechniqueType _tt,
148  Ogre::StringStream &_outStream);
149 
150  protected: virtual void generateFpDynamicShadowsHelpers(
151  const SM2Profile *_prof,
152  const Ogre::Terrain *_terrain,
153  TechniqueType tt,
154  Ogre::StringStream &_outStream);
155 
156  protected: void generateFpDynamicShadows(const SM2Profile *_prof,
157  const Ogre::Terrain *_terrain, TechniqueType _tt,
158  Ogre::StringStream &_outStream);
159 
160  protected: virtual void generateFragmentProgramSource(
161  const SM2Profile *_prof,
162  const Ogre::Terrain *_terrain,
163  TechniqueType _tt,
164  Ogre::StringStream &_outStream);
165 
166  protected: virtual void updateVpParams(const SM2Profile *_prof,
167  const Ogre::Terrain *_terrain, TechniqueType _tt,
168  const Ogre::GpuProgramParametersSharedPtr &_params);
169 
170  private: Ogre::String GetChannel(Ogre::uint _idx);
171  };
172 
173  // Needed to allow access from ShaderHelperGLSL to protected members
174  // of SM2Profile.
176 
180  protected: class ShaderHelperCg :
181  public Ogre::TerrainMaterialGeneratorA::SM2Profile::ShaderHelperCg
182  {
183  public: virtual Ogre::HighLevelGpuProgramPtr generateFragmentProgram(
184  const SM2Profile *_prof, const Ogre::Terrain *_terrain,
185  TechniqueType _tt);
186 
187  public: virtual Ogre::HighLevelGpuProgramPtr generateVertexProgram(
188  const SM2Profile *_prof, const Ogre::Terrain *_terrain,
189  TechniqueType _tt);
190 
191  protected: virtual void generateVpHeader(const SM2Profile *_prof,
192  const Ogre::Terrain *_terrain, TechniqueType _tt,
193  Ogre::StringStream &_outStream);
194 
195  protected: virtual void generateVpFooter(const SM2Profile *_prof,
196  const Ogre::Terrain *_terrain, TechniqueType _tt,
197  Ogre::StringStream &_outStream);
198 
199  protected: virtual void generateVertexProgramSource(
200  const SM2Profile *_prof, const Ogre::Terrain *_terrain,
201  TechniqueType _tt,
202  Ogre::StringStream &_outStream);
203 
204  protected: virtual void defaultVpParams(const SM2Profile *_prof,
205  const Ogre::Terrain *_terrain, TechniqueType _tt,
206  const Ogre::HighLevelGpuProgramPtr &_prog);
207 
208  protected: virtual unsigned int generateVpDynamicShadowsParams(
209  unsigned int _texCoordStart, const SM2Profile *_prof,
210  const Ogre::Terrain *_terrain, TechniqueType _tt,
211  Ogre::StringStream &_outStream);
212 
213  protected: virtual void generateVpDynamicShadows(
214  const SM2Profile *_prof, const Ogre::Terrain *_terrain,
215  TechniqueType _tt,
216  Ogre::StringStream &_outStream);
217  };
218 
219  // Needed to allow access from ShaderHelperCg to protected members
220  // of SM2Profile.
222 
223 #ifdef __clang__
224 #pragma clang diagnostic pop
225 
226 // ifdef __clang__
227 #endif
228  };
229  };
230 
233  class DummyPageProvider : public Ogre::PageProvider
234  {
237  public: bool prepareProceduralPage(Ogre::Page*, Ogre::PagedWorldSection*)
238  {
239  return true;
240  }
241 
244  public: bool loadProceduralPage(Ogre::Page*, Ogre::PagedWorldSection*)
245  {
246  return true;
247  }
248 
251  public: bool unloadProceduralPage(Ogre::Page*, Ogre::PagedWorldSection*)
252  {
253  return true;
254  }
255 
258  public:
259  bool unprepareProceduralPage(Ogre::Page*, Ogre::PagedWorldSection*)
260  {
261  return true;
262  }
263  };
264 
268  {
270  public: static const unsigned int numTerrainSubdivisions;
271 
276  public: static const double loadRadiusFactor;
277 
283  public: static const double holdRadiusFactor;
284 
287  public: static const boost::filesystem::path hashFilename;
288 
291  public: static const boost::filesystem::path pagingDirname;
292 
296  public: boost::filesystem::path gzPagingDir;
297 
299  public: ScenePtr scene;
300 
302  public: ignition::math::Vector3d terrainSize;
303 
305  public: unsigned int dataSize;
306 
308  public: ignition::math::Vector3d terrainOrigin;
309 
311  public: Ogre::TerrainGlobalOptions *terrainGlobals;
312 
314  public: Ogre::TerrainGroup *terrainGroup;
315 
317  public: bool terrainsImported;
318 
320  public: std::vector<std::string> diffuseTextures;
321 
323  public: std::vector<std::string> normalTextures;
324 
326  public: std::vector<double> worldSizes;
327 
329  public: std::vector<double> blendHeight;
330 
332  public: std::vector<double> blendFade;
333 
335  public: std::vector<float> heights;
336 
339 
342 
345  public: Ogre::PageManager *pageManager;
346 
348  public: Ogre::TerrainPaging *terrainPaging;
349 
351  public: Ogre::PagedWorld *world;
352 
354  public: std::vector<std::vector<float> > subTerrains;
355 
357  public: int terrainIdx;
358 
360  public: bool useTerrainPaging;
361 
363  public: bool terrainHashChanged;
364  };
365  }
366 }
367 #endif
bool terrainsImported
True if the terrain was imported.
Definition: HeightmapPrivate.hh:317
bool useTerrainPaging
Flag that enables/disables the terrain paging.
Definition: HeightmapPrivate.hh:360
virtual void generateVertexProgramSource(const SM2Profile *_prof, const Ogre::Terrain *_terrain, TechniqueType _tt, Ogre::StringStream &_outStream)
int terrainIdx
Used to iterate over all the terrains.
Definition: HeightmapPrivate.hh:357
virtual Ogre::HighLevelGpuProgramPtr generateVertexProgram(const SM2Profile *_prof, const Ogre::Terrain *_terrain, TechniqueType _tt)
Definition: HeightmapPrivate.hh:267
bool unloadProceduralPage(Ogre::Page *, Ogre::PagedWorldSection *)
Give a provider the opportunity to unload page content procedurally.
Definition: HeightmapPrivate.hh:251
std::vector< std::string > diffuseTextures
The diffuse textures.
Definition: HeightmapPrivate.hh:320
virtual void generateVpHeader(const SM2Profile *_prof, const Ogre::Terrain *_terrain, TechniqueType _tt, Ogre::StringStream &_outStream)
Ogre::TerrainPaging * terrainPaging
Type of paging applied.
Definition: HeightmapPrivate.hh:348
static const double loadRadiusFactor
The terrain pages are loaded if the distance from the camera is within the loadRadius.
Definition: HeightmapPrivate.hh:276
void UpdateParamsForCompositeMap(const Ogre::MaterialPtr &_mat, const Ogre::Terrain *_terrain)
static const boost::filesystem::path hashFilename
Hash file name that should be present for every terrain file loaded using paging. ...
Definition: HeightmapPrivate.hh:287
std::vector< std::string > normalTextures
The normal textures.
Definition: HeightmapPrivate.hh:323
virtual void generateVpFooter(const SM2Profile *_prof, const Ogre::Terrain *_terrain, TechniqueType _tt, Ogre::StringStream &_outStream)
void UpdateParams(const Ogre::MaterialPtr &_mat, const Ogre::Terrain *_terrain)
std::vector< double > blendHeight
The material blending heights.
Definition: HeightmapPrivate.hh:329
std::vector< double > worldSizes
The size of the world sections.
Definition: HeightmapPrivate.hh:326
static const unsigned int numTerrainSubdivisions
Number of pieces in which a terrain is subdivided for paging.
Definition: HeightmapPrivate.hh:270
unsigned int dataSize
Size of the heightmap data.
Definition: HeightmapPrivate.hh:305
ScenePtr scene
The scene.
Definition: HeightmapPrivate.hh:299
std::vector< std::vector< float > > subTerrains
Collection of terrains. Every terrain might be paged.
Definition: HeightmapPrivate.hh:354
Shader model 2 profile target.
Definition: HeightmapPrivate.hh:55
virtual void updateVpParams(const SM2Profile *_prof, const Ogre::Terrain *_terrain, TechniqueType _tt, const Ogre::GpuProgramParametersSharedPtr &_params)
virtual ~GzTerrainMatGen()
Destructor.
Ogre::MaterialPtr generate(const Ogre::Terrain *_terrain)
virtual void generateFpDynamicShadowsParams(Ogre::uint *_texCoord, Ogre::uint *_sampler, const SM2Profile *_prof, const Ogre::Terrain *_terrain, TechniqueType _tt, Ogre::StringStream &_outStream)
virtual void generateVpFooter(const SM2Profile *_prof, const Ogre::Terrain *_terrain, TechniqueType _tt, Ogre::StringStream &_outStream)
virtual void defaultVpParams(const SM2Profile *_prof, const Ogre::Terrain *_terrain, TechniqueType _tt, const Ogre::HighLevelGpuProgramPtr &_prog)
virtual void generateVpHeader(const SM2Profile *_prof, const Ogre::Terrain *_terrain, TechniqueType _tt, Ogre::StringStream &_outStream)
std::vector< float > heights
The raw height values received from physics.
Definition: HeightmapPrivate.hh:335
Ogre::TerrainGroup * terrainGroup
Group of terrains.
Definition: HeightmapPrivate.hh:314
Ogre::TerrainGlobalOptions * terrainGlobals
Global options.
Definition: HeightmapPrivate.hh:311
virtual void generateFpLayer(const SM2Profile *_prof, const Ogre::Terrain *_terrain, TechniqueType tt, Ogre::uint _layer, Ogre::StringStream &_outStream)
DummyPageProvider dummyPageProvider
A page provider is needed to use the paging system.
Definition: HeightmapPrivate.hh:341
friend ShaderHelperGLSL
Definition: HeightmapPrivate.hh:175
virtual void generateFpFooter(const SM2Profile *_prof, const Ogre::Terrain *_terrain, TechniqueType tt, Ogre::StringStream &_outStream)
bool terrainHashChanged
True if the terrain's hash does not match the image's hash.
Definition: HeightmapPrivate.hh:363
void generateFpDynamicShadows(const SM2Profile *_prof, const Ogre::Terrain *_terrain, TechniqueType _tt, Ogre::StringStream &_outStream)
bool loadProceduralPage(Ogre::Page *, Ogre::PagedWorldSection *)
Give a provider the opportunity to load page content procedurally.
Definition: HeightmapPrivate.hh:244
SM2Profile(Ogre::TerrainMaterialGenerator *_parent, const Ogre::String &_name, const Ogre::String &_desc)
Constructor.
virtual void generateVertexProgramSource(const SM2Profile *_prof, const Ogre::Terrain *_terrain, TechniqueType _tt, Ogre::StringStream &_outStream)
virtual void generateVpDynamicShadows(const SM2Profile *_prof, const Ogre::Terrain *_terrain, TechniqueType _tt, Ogre::StringStream &_outStream)
virtual unsigned int generateVpDynamicShadowsParams(unsigned int _texCoordStart, const SM2Profile *_prof, const Ogre::Terrain *_terrain, TechniqueType _tt, Ogre::StringStream &_outStream)
virtual Ogre::HighLevelGpuProgramPtr generateFragmentProgram(const SM2Profile *_prof, const Ogre::Terrain *_terrain, TechniqueType _tt)
static const double holdRadiusFactor
The terrain pages are held in memory but not loaded if they are not ready when the camera is within h...
Definition: HeightmapPrivate.hh:283
virtual void generateVpDynamicShadows(const SM2Profile *_prof, const Ogre::Terrain *_terrain, TechniqueType _tt, Ogre::StringStream &_outStream)
GzTerrainMatGen * gzMatGen
Pointer to the terrain material generator.
Definition: HeightmapPrivate.hh:338
bool prepareProceduralPage(Ogre::Page *, Ogre::PagedWorldSection *)
Give a provider the opportunity to prepare page content procedurally.
Definition: HeightmapPrivate.hh:237
virtual void generateFpHeader(const SM2Profile *_prof, const Ogre::Terrain *_terrain, TechniqueType tt, Ogre::StringStream &_outStream)
virtual void generateFpDynamicShadowsHelpers(const SM2Profile *_prof, const Ogre::Terrain *_terrain, TechniqueType tt, Ogre::StringStream &_outStream)
ignition::math::Vector3d terrainSize
Size of the terrain.
Definition: HeightmapPrivate.hh:302
virtual Ogre::HighLevelGpuProgramPtr generateVertexProgram(const SM2Profile *_prof, const Ogre::Terrain *_terrain, TechniqueType _tt)
static const boost::filesystem::path pagingDirname
Name of the top level directory where all the paging info is stored.
Definition: HeightmapPrivate.hh:291
Ogre::MaterialPtr generateForCompositeMap(const Ogre::Terrain *_terrain)
Ogre::PageManager * pageManager
Central registration point for extension classes, such as the PageStrategy, PageContentFactory.
Definition: HeightmapPrivate.hh:345
boost::shared_ptr< Scene > ScenePtr
Definition: RenderTypes.hh:80
std::vector< double > blendFade
Material blend fade distances.
Definition: HeightmapPrivate.hh:332
friend ShaderHelperCg
Definition: HeightmapPrivate.hh:221
ignition::math::Vector3d terrainOrigin
Origin of the terrain.
Definition: HeightmapPrivate.hh:308
Utility class to help with generating shaders for GLSL.
Definition: HeightmapPrivate.hh:87
virtual void updateParams(const SM2Profile *_prof, const Ogre::MaterialPtr &_mat, const Ogre::Terrain *_terrain, bool _compositeMap)
virtual Ogre::HighLevelGpuProgramPtr generateFragmentProgram(const SM2Profile *_prof, const Ogre::Terrain *_terrain, TechniqueType _tt)
virtual unsigned int generateVpDynamicShadowsParams(unsigned int _texCoordStart, const SM2Profile *_prof, const Ogre::Terrain *_terrain, TechniqueType _tt, Ogre::StringStream &_outStream)
virtual void defaultVpParams(const SM2Profile *_prof, const Ogre::Terrain *_terrain, TechniqueType _tt, const Ogre::HighLevelGpuProgramPtr &_prog)
Definition: HeightmapPrivate.hh:46
virtual void addTechnique(const Ogre::MaterialPtr &_mat, const Ogre::Terrain *_terrain, TechniqueType _tt)
Keeping the CG shader for reference.
Definition: HeightmapPrivate.hh:180
boost::filesystem::path gzPagingDir
When the terrain paging is enabled, the terrain information for every piece of terrain is stored in d...
Definition: HeightmapPrivate.hh:296
virtual void generateFragmentProgramSource(const SM2Profile *_prof, const Ogre::Terrain *_terrain, TechniqueType _tt, Ogre::StringStream &_outStream)
Definition: HeightmapPrivate.hh:233
Ogre::PagedWorld * world
Collection of world content.
Definition: HeightmapPrivate.hh:351
bool unprepareProceduralPage(Ogre::Page *, Ogre::PagedWorldSection *)
Give a provider the opportunity to unprepare page content procedurally.
Definition: HeightmapPrivate.hh:259