Heightmap.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_HEIGHTMAP_HH_
18 #define GAZEBO_RENDERING_HEIGHTMAP_HH_
19 
20 #include <vector>
21 #include <string>
22 
23 #include <ignition/math/Vector3.hh>
24 #include <ignition/math/Vector2.hh>
25 
26 #include "gazebo/msgs/MessageTypes.hh"
29 #include "gazebo/util/system.hh"
30 
31 namespace boost
32 {
33  namespace filesystem
34  {
35  class path;
36  }
37 }
38 
39 namespace Ogre
40 {
41  class TerrainGroup;
42  class Terrain;
43 }
44 
45 namespace gazebo
46 {
47  namespace common
48  {
49  class Image;
50  }
51 
52  namespace rendering
53  {
54  // Forward declare private data.
55  class HeightmapPrivate;
56 
59 
62  class GZ_RENDERING_VISIBLE Heightmap
63  {
66  public: explicit Heightmap(ScenePtr _scene);
67 
69  public: virtual ~Heightmap();
70 
72  public: void Load();
73 
76  public: void LoadFromMsg(ConstVisualPtr &_msg);
77 
83  public: double Height(const double _x, const double _y,
84  const double _z = 1000) const;
85 
95  public: bool Flatten(CameraPtr _camera,
96  const ignition::math::Vector2i &_mousePos,
97  const double _outsideRadius,
98  const double _insideRadius,
99  const double _weight = 0.1);
100 
110  public: bool Smooth(CameraPtr _camera,
111  const ignition::math::Vector2i &_mousePos,
112  const double _outsideRadius,
113  const double _insideRadius,
114  const double _weight = 0.1);
115 
125  public: bool Raise(CameraPtr _camera,
126  const ignition::math::Vector2i &_mousePos,
127  const double _outsideRadius,
128  const double _insideRadius,
129  const double _weight = 0.1);
130 
140  public: bool Lower(CameraPtr _camera,
141  const ignition::math::Vector2i &_mousePos,
142  const double _outsideRadius,
143  const double _insideRadius,
144  const double _weight = 0.1);
145 
149  public: double AvgHeight(const ignition::math::Vector3d &_pos,
150  const double _brushSize) const;
151 
154  public: void SetWireframe(const bool _show);
155 
158  public: Ogre::TerrainGroup *OgreTerrain() const;
159 
162  public: common::Image Image() const;
163 
169  public: Ogre::TerrainGroup::RayResult MouseHit(CameraPtr _camera,
170  const ignition::math::Vector2i &_mousePos) const;
171 
176  public: void SplitHeights(const std::vector<float> &_heightmap,
177  const int _n, std::vector<std::vector<float> > &_v);
178 
182  public: unsigned int TerrainSubdivisionCount() const;
183 
186  public: void SetMaterial(const std::string &_materialName);
187 
190  public: std::string MaterialName() const;
191 
199  public: void SetLOD(const unsigned int _value);
200 
203  public: unsigned int LOD() const;
204 
208  public: void SetSkirtLength(const double _value);
209 
212  public: double SkirtLength() const;
213 
216  public: void SetCastShadows(const bool _value);
217 
220  public: bool CastShadows() const;
221 
226  private: void CreateMaterial();
227 
235  private: void ModifyTerrain(Ogre::Vector3 _pos,
236  const double _outsideRadius, const double _insideRadius,
237  const double _weight, const std::string &_op);
238 
241  private: bool InitBlendMaps(Ogre::Terrain *_terrain);
242 
244  private: void ConfigureTerrainDefaults();
245 
249  private: void DefineTerrain(const int _x, const int _y);
250 
253  private: void SetupShadows(const bool _enabled);
254 
262  private: void UpdateTerrainHash(const std::string &_hash,
263  const boost::filesystem::path &_terrainDir);
264 
270  private: bool PrepareTerrain(
271  const boost::filesystem::path &_terrainDirPath);
272 
274  private: void SaveHeightmap();
275 
278  private: std::unique_ptr<HeightmapPrivate> dataPtr;
279  };
281  }
282 }
283 #endif
Ogre::TerrainGroup * OgreTerrain() const
Get a pointer to the OGRE terrain group object.
void Load()
Load the heightmap.
void SetMaterial(const std::string &_materialName)
Set custom material for the terrain.
Definition: JointMaker.hh:39
virtual ~Heightmap()
Destructor.
Ogre::TerrainGroup::RayResult MouseHit(CameraPtr _camera, const ignition::math::Vector2i &_mousePos) const
Calculate a mouse ray hit on the terrain.
Forward declarations for the common classes.
Definition: Animation.hh:26
void LoadFromMsg(ConstVisualPtr &_msg)
Load the heightmap from a visual message.
bool Smooth(CameraPtr _camera, const ignition::math::Vector2i &_mousePos, const double _outsideRadius, const double _insideRadius, const double _weight=0.1)
Smooth the terrain based on a mouse press.
Rendering a terrain using heightmap information.
Definition: Heightmap.hh:62
void SetSkirtLength(const double _value)
Set the skirt length for the heightmap LOD tiles.
common
Definition: FuelModelDatabase.hh:37
Heightmap(ScenePtr _scene)
Constructor.
Definition: JointMaker.hh:44
double Height(const double _x, const double _y, const double _z=1000) const
Get the height at a location.
bool Flatten(CameraPtr _camera, const ignition::math::Vector2i &_mousePos, const double _outsideRadius, const double _insideRadius, const double _weight=0.1)
Flatten the terrain based on a mouse press.
Encapsulates an image.
Definition: Image.hh:65
void SplitHeights(const std::vector< float > &_heightmap, const int _n, std::vector< std::vector< float > > &_v)
Split a terrain into subterrains.
boost::shared_ptr< Scene > ScenePtr
Definition: RenderTypes.hh:82
rendering
Definition: RenderEngine.hh:31
bool Raise(CameraPtr _camera, const ignition::math::Vector2i &_mousePos, const double _outsideRadius, const double _insideRadius, const double _weight=0.1)
Raise the terrain based on a mouse press.
void SetCastShadows(const bool _value)
Set the heightmap terrain to cast shadows.
common::Image Image() const
Get the heightmap as an image.
std::string MaterialName() const
Get the custom material name used for the terrain.
double AvgHeight(const ignition::math::Vector3d &_pos, const double _brushSize) const
Get the average height around a point.
void SetWireframe(const bool _show)
Set the heightmap to render in wireframe mode.
unsigned int TerrainSubdivisionCount() const
Get the number of subdivision the terrain will be split into.
double SkirtLength() const
Get the skirt length of LOD tiles.
bool CastShadows() const
Get whether the heightmap terrain casts shadows.
boost::shared_ptr< Camera > CameraPtr
Definition: RenderTypes.hh:90
bool Lower(CameraPtr _camera, const ignition::math::Vector2i &_mousePos, const double _outsideRadius, const double _insideRadius, const double _weight=0.1)
Lower the terrain based on a mouse press.
unsigned int LOD() const
Get the heightmap Level of Detail (LOD) value.
void SetLOD(const unsigned int _value)
Set the Level Of Detail (LOD) for the heightmap.