Skip to content

Commit 20511d6

Browse files
committed
Merge branch 'main' into chapulina/main/rm/bionic
2 parents 897fad9 + 8cc48ac commit 20511d6

17 files changed

+452
-163
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ set(IGN_MATH_VER ${ignition-math7_VERSION_MAJOR})
3636
#--------------------------------------
3737
# Find ignition-common
3838
ign_find_package(ignition-common5 REQUIRED
39-
COMPONENTS graphics events)
39+
COMPONENTS graphics events geospatial)
4040
set(IGN_COMMON_VER ${ignition-common5_VERSION_MAJOR})
4141

4242
#--------------------------------------

examples/heightmap/Main.cc

+195-99
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
#include <vector>
2929

3030
#include <ignition/common/Console.hh>
31-
#include <ignition/common/HeightmapData.hh>
32-
#include <ignition/common/ImageHeightmap.hh>
31+
#include <ignition/common/geospatial/Dem.hh>
32+
#include <ignition/common/geospatial/HeightmapData.hh>
33+
#include <ignition/common/geospatial/ImageHeightmap.hh>
3334
#include <ignition/rendering.hh>
3435

3536
#include "example_config.hh"
@@ -42,7 +43,178 @@ const std::string RESOURCE_PATH =
4243
common::joinPaths(std::string(PROJECT_BINARY_PATH), "media");
4344

4445
//////////////////////////////////////////////////
45-
void buildScene(ScenePtr _scene)
46+
void createImageHeightmaps(const ScenePtr _scene, VisualPtr _root)
47+
{
48+
//! [create an image heightmap]
49+
auto data = std::make_shared<common::ImageHeightmap>();
50+
data->Load(common::joinPaths(RESOURCE_PATH, "heightmap_bowl.png"));
51+
52+
HeightmapDescriptor desc;
53+
desc.SetName("example_bowl");
54+
desc.SetData(data);
55+
desc.SetSize({17, 17, 10});
56+
desc.SetSampling(2u);
57+
desc.SetUseTerrainPaging(false);
58+
59+
HeightmapTexture textureA;
60+
textureA.SetSize(1.0);
61+
textureA.SetDiffuse("../media/dirt_diffusespecular.png");
62+
textureA.SetNormal("../media/flat_normal.png");
63+
desc.AddTexture(textureA);
64+
65+
HeightmapBlend blendA;
66+
blendA.SetMinHeight(2.0);
67+
blendA.SetFadeDistance(5.0);
68+
desc.AddBlend(blendA);
69+
70+
HeightmapTexture textureB;
71+
textureB.SetSize(1.0);
72+
textureB.SetDiffuse("../media/grass_diffusespecular.png");
73+
textureB.SetNormal("../media/flat_normal.png");
74+
desc.AddTexture(textureB);
75+
76+
HeightmapBlend blendB;
77+
blendB.SetMinHeight(4.0);
78+
blendB.SetFadeDistance(5.0);
79+
desc.AddBlend(blendB);
80+
81+
HeightmapTexture textureC;
82+
textureC.SetSize(1.0);
83+
textureC.SetDiffuse("../media/fungus_diffusespecular.png");
84+
textureC.SetNormal("../media/flat_normal.png");
85+
desc.AddTexture(textureC);
86+
87+
auto heightmapGeom = _scene->CreateHeightmap(desc);
88+
89+
auto vis = _scene->CreateVisual();
90+
vis->AddGeometry(heightmapGeom);
91+
_root->AddChild(vis);
92+
//! [create an image heightmap]
93+
94+
//! [create another image heightmap]
95+
auto data2 = std::make_shared<common::ImageHeightmap>();
96+
data2->Load(common::joinPaths(RESOURCE_PATH, "city_terrain.jpg"));
97+
98+
HeightmapDescriptor desc2;
99+
desc2.SetName("example_city");
100+
desc2.SetData(data2);
101+
desc2.SetSize({26, 26, 20});
102+
desc2.SetSampling(2u);
103+
desc2.SetUseTerrainPaging(true);
104+
105+
HeightmapTexture textureA2;
106+
textureA2.SetSize(1.0);
107+
textureA2.SetDiffuse("../media/fungus_diffusespecular.png");
108+
textureA2.SetNormal("../media/flat_normal.png");
109+
desc2.AddTexture(textureA2);
110+
111+
HeightmapBlend blendA2;
112+
blendA2.SetMinHeight(2.0);
113+
blendA2.SetFadeDistance(5.0);
114+
desc2.AddBlend(blendA2);
115+
116+
HeightmapTexture textureB2;
117+
textureB2.SetSize(1.0);
118+
textureB2.SetDiffuse("../media/grass_diffusespecular.png");
119+
textureB2.SetNormal("../media/flat_normal.png");
120+
desc2.AddTexture(textureB2);
121+
122+
HeightmapBlend blendB2;
123+
blendB2.SetMinHeight(8.0);
124+
blendB2.SetFadeDistance(5.0);
125+
desc2.AddBlend(blendB2);
126+
127+
HeightmapTexture textureC2;
128+
textureC2.SetSize(1.0);
129+
textureC2.SetDiffuse("../media/dirt_diffusespecular.png");
130+
textureC2.SetNormal("../media/flat_normal.png");
131+
desc2.AddTexture(textureC2);
132+
desc2.SetPosition({30, 0, 0});
133+
auto heightmapGeom2 = _scene->CreateHeightmap(desc2);
134+
135+
auto vis2 = _scene->CreateVisual();
136+
vis2->AddGeometry(heightmapGeom2);
137+
_root->AddChild(vis2);
138+
//! [create another image heightmap]
139+
}
140+
141+
//////////////////////////////////////////////////
142+
void createDemHeightmaps(const ScenePtr _scene, VisualPtr _root)
143+
{
144+
//! [create a dem heightmap]
145+
auto data = std::make_shared<common::Dem>();
146+
data->Load(common::joinPaths(RESOURCE_PATH, "volcano.tif"));
147+
148+
HeightmapDescriptor desc;
149+
desc.SetName("example_volcano");
150+
desc.SetData(data);
151+
desc.SetSize({20, 20, 18});
152+
desc.SetSampling(2u);
153+
desc.SetUseTerrainPaging(true);
154+
155+
HeightmapTexture textureA;
156+
textureA.SetSize(1.0);
157+
textureA.SetDiffuse("../media/dirt_diffusespecular.png");
158+
textureA.SetNormal("../media/flat_normal.png");
159+
desc.AddTexture(textureA);
160+
161+
HeightmapBlend blendA;
162+
blendA.SetMinHeight(2.0);
163+
blendA.SetFadeDistance(5.0);
164+
desc.AddBlend(blendA);
165+
166+
HeightmapTexture textureB;
167+
textureB.SetSize(1.0);
168+
textureB.SetDiffuse("../media/grass_diffusespecular.png");
169+
textureB.SetNormal("../media/flat_normal.png");
170+
desc.AddTexture(textureB);
171+
172+
HeightmapBlend blendB;
173+
blendB.SetMinHeight(4.0);
174+
blendB.SetFadeDistance(5.0);
175+
desc.AddBlend(blendB);
176+
177+
HeightmapTexture textureC;
178+
textureC.SetSize(1.0);
179+
textureC.SetDiffuse("../media/fungus_diffusespecular.png");
180+
textureC.SetNormal("../media/flat_normal.png");
181+
desc.AddTexture(textureC);
182+
desc.SetPosition({30, 0, 0});
183+
184+
auto heightmapGeom = _scene->CreateHeightmap(desc);
185+
186+
auto vis = _scene->CreateVisual();
187+
vis->AddGeometry(heightmapGeom);
188+
_root->AddChild(vis);
189+
//! [create a dem heightmap]
190+
191+
//! [create another dem heightmap]
192+
auto data2 = std::make_shared<common::Dem>();
193+
data2->Load(common::joinPaths(RESOURCE_PATH, "moon.tif"));
194+
195+
HeightmapDescriptor desc2;
196+
desc2.SetName("example_moon");
197+
desc2.SetData(data2);
198+
desc2.SetSize({20, 20, 6.85});
199+
desc2.SetSampling(2u);
200+
desc2.SetUseTerrainPaging(false);
201+
202+
HeightmapTexture textureA2;
203+
textureA2.SetSize(20.0);
204+
textureA2.SetDiffuse("../media/moon_diffuse.png");
205+
textureA2.SetNormal("../media/moon_normal.png");
206+
desc2.AddTexture(textureA2);
207+
desc2.SetPosition({0, 0, std::abs(data2->MinElevation())});
208+
auto heightmapGeom2 = _scene->CreateHeightmap(desc2);
209+
210+
auto vis2 = _scene->CreateVisual();
211+
vis2->AddGeometry(heightmapGeom2);
212+
_root->AddChild(vis2);
213+
//! [create another dem heightmap]
214+
}
215+
216+
//////////////////////////////////////////////////
217+
void buildScene(ScenePtr _scene, bool _buildDemScene)
46218
{
47219
// initialize _scene
48220
_scene->SetAmbientLight(0.3, 0.3, 0.3);
@@ -68,97 +240,10 @@ void buildScene(ScenePtr _scene)
68240
light1->SetCastShadows(true);
69241
root->AddChild(light1);
70242

71-
//! [create a heightmap]
72-
auto data = std::make_shared<common::ImageHeightmap>();
73-
data->Load(common::joinPaths(RESOURCE_PATH, "heightmap_bowl.png"));
74-
75-
HeightmapDescriptor desc;
76-
desc.SetName("example_bowl");
77-
desc.SetData(data);
78-
desc.SetSize({17, 17, 10});
79-
desc.SetSampling(2u);
80-
desc.SetUseTerrainPaging(false);
81-
82-
HeightmapTexture textureA;
83-
textureA.SetSize(1.0);
84-
textureA.SetDiffuse("../media/dirt_diffusespecular.png");
85-
textureA.SetNormal("../media/flat_normal.png");
86-
desc.AddTexture(textureA);
87-
88-
HeightmapBlend blendA;
89-
blendA.SetMinHeight(2.0);
90-
blendA.SetFadeDistance(5.0);
91-
desc.AddBlend(blendA);
92-
93-
HeightmapTexture textureB;
94-
textureB.SetSize(1.0);
95-
textureB.SetDiffuse("../media/grass_diffusespecular.png");
96-
textureB.SetNormal("../media/flat_normal.png");
97-
desc.AddTexture(textureB);
98-
99-
HeightmapBlend blendB;
100-
blendB.SetMinHeight(4.0);
101-
blendB.SetFadeDistance(5.0);
102-
desc.AddBlend(blendB);
103-
104-
HeightmapTexture textureC;
105-
textureC.SetSize(1.0);
106-
textureC.SetDiffuse("../media/fungus_diffusespecular.png");
107-
textureC.SetNormal("../media/flat_normal.png");
108-
desc.AddTexture(textureC);
109-
110-
auto heightmapGeom = _scene->CreateHeightmap(desc);
111-
112-
auto vis = _scene->CreateVisual();
113-
vis->AddGeometry(heightmapGeom);
114-
root->AddChild(vis);
115-
//! [create a heightmap]
116-
117-
//! [create another heightmap]
118-
auto data2 = std::make_shared<common::ImageHeightmap>();
119-
data2->Load(common::joinPaths(RESOURCE_PATH, "city_terrain.jpg"));
120-
121-
HeightmapDescriptor desc2;
122-
desc2.SetName("example_city");
123-
desc2.SetData(data2);
124-
desc2.SetSize({26, 26, 20});
125-
desc2.SetSampling(2u);
126-
desc2.SetUseTerrainPaging(true);
127-
128-
HeightmapTexture textureA2;
129-
textureA2.SetSize(1.0);
130-
textureA2.SetDiffuse("../media/fungus_diffusespecular.png");
131-
textureA2.SetNormal("../media/flat_normal.png");
132-
desc2.AddTexture(textureA2);
133-
134-
HeightmapBlend blendA2;
135-
blendA2.SetMinHeight(2.0);
136-
blendA2.SetFadeDistance(5.0);
137-
desc2.AddBlend(blendA2);
138-
139-
HeightmapTexture textureB2;
140-
textureB2.SetSize(1.0);
141-
textureB2.SetDiffuse("../media/grass_diffusespecular.png");
142-
textureB2.SetNormal("../media/flat_normal.png");
143-
desc2.AddTexture(textureB2);
144-
145-
HeightmapBlend blendB2;
146-
blendB2.SetMinHeight(8.0);
147-
blendB2.SetFadeDistance(5.0);
148-
desc2.AddBlend(blendB2);
149-
150-
HeightmapTexture textureC2;
151-
textureC2.SetSize(1.0);
152-
textureC2.SetDiffuse("../media/dirt_diffusespecular.png");
153-
textureC2.SetNormal("../media/flat_normal.png");
154-
desc2.AddTexture(textureC2);
155-
desc2.SetPosition({30, 0, 0});
156-
auto heightmapGeom2 = _scene->CreateHeightmap(desc2);
157-
158-
auto vis2 = _scene->CreateVisual();
159-
vis2->AddGeometry(heightmapGeom2);
160-
root->AddChild(vis2);
161-
//! [create another heightmap]
243+
if (_buildDemScene)
244+
createDemHeightmaps(_scene, root);
245+
else
246+
createImageHeightmaps(_scene, root);
162247

163248
// create gray material
164249
MaterialPtr gray = _scene->CreateMaterial();
@@ -193,7 +278,8 @@ void buildScene(ScenePtr _scene)
193278

194279
//////////////////////////////////////////////////
195280
CameraPtr createCamera(const std::string &_engineName,
196-
const std::map<std::string, std::string>& _params)
281+
const std::map<std::string, std::string>& _params,
282+
bool _buildDemScene)
197283
{
198284
// create and populate scene
199285
RenderEngine *engine = rendering::engine(_engineName, _params);
@@ -204,7 +290,7 @@ CameraPtr createCamera(const std::string &_engineName,
204290
return CameraPtr();
205291
}
206292
ScenePtr scene = engine->CreateScene("scene");
207-
buildScene(scene);
293+
buildScene(scene, _buildDemScene);
208294

209295
// return camera sensor
210296
SensorPtr sensor = scene->SensorByName("camera");
@@ -220,16 +306,26 @@ int main(int _argc, char** _argv)
220306
std::vector<std::string> engineNames;
221307
std::vector<CameraPtr> cameras;
222308

309+
int buildDemScene = 0;
310+
for (int i = 1; i < _argc; ++i)
311+
{
312+
if (std::string(_argv[i]) == "--dem")
313+
{
314+
buildDemScene = i;
315+
break;
316+
}
317+
}
318+
223319
// Expose engine name to command line because we can't instantiate both
224320
// ogre and ogre2 at the same time
225321
std::string ogreEngineName("ogre2");
226-
if (_argc > 1)
322+
if (_argc > 1 && buildDemScene != 1)
227323
{
228324
ogreEngineName = _argv[1];
229325
}
230326

231327
GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
232-
if (_argc > 2)
328+
if (_argc > 2 && buildDemScene != 2)
233329
{
234330
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
235331
}
@@ -247,7 +343,7 @@ int main(int _argc, char** _argv)
247343
params["metal"] = "1";
248344
}
249345

250-
CameraPtr camera = createCamera(engineName, params);
346+
CameraPtr camera = createCamera(engineName, params, buildDemScene);
251347
if (camera)
252348
{
253349
cameras.push_back(camera);

examples/heightmap/media/moon.tif

4.87 KB
Binary file not shown.
2.96 MB
Loading
22 MB
Loading

examples/heightmap/media/volcano.tif

65.4 KB
Binary file not shown.

include/ignition/rendering/HeightmapDescriptor.hh

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#include <memory>
2121
#include <string>
22-
#include <ignition/common/HeightmapData.hh>
22+
#include <ignition/common/geospatial/HeightmapData.hh>
2323
#include <ignition/utils/SuppressWarning.hh>
2424

2525
#include "ignition/rendering/config.hh"
@@ -186,12 +186,12 @@ inline namespace IGNITION_RENDERING_VERSION_NAMESPACE {
186186
/// \param[in] _data New data.
187187
public: void SetData(const std::shared_ptr<common::HeightmapData> &_data);
188188

189-
/// \brief Get the heightmap's scaling factor.
189+
/// \brief Get the heightmap's final size in world units.
190190
/// \return The heightmap's size.
191191
public: ignition::math::Vector3d Size() const;
192192

193-
/// \brief Set the heightmap's size. Defaults to 1x1x1.
194-
/// \param[in] _size The heightmap's size.
193+
/// \brief Set the heightmap's final size in world units. Defaults to 1x1x1.
194+
/// \return The heightmap's size factor.
195195
public: void SetSize(const ignition::math::Vector3d &_size);
196196

197197
/// \brief Get the heightmap's position offset.

ogre/src/OgreHeightmap.cc

+3-5
Original file line numberDiff line numberDiff line change
@@ -459,11 +459,9 @@ void OgreHeightmap::Init()
459459
// There is an issue with OGRE terrain LOD if heights are not relative to 0.
460460
// So we move the heightmap so that its min elevation = 0 before feeding to
461461
// ogre. It is later translated back by the setOrigin call.
462-
double minElevation = 0.0;
463-
464-
// TODO(chapulina) add a virtual HeightmapData::MinElevation function to
465-
// avoid the ifdef check. i.e. heightmapSizeZ = MaxElevation - MinElevation
466-
double heightmapSizeZ = this->descriptor.Data()->MaxElevation();
462+
double minElevation = this->descriptor.Data()->MinElevation();
463+
double heightmapSizeZ =
464+
this->descriptor.Data()->MaxElevation() - minElevation;
467465

468466
// \todo These parameters shouldn't be hardcoded, and instead parametrized so
469467
// that they can be made consistent across different libraries (like

0 commit comments

Comments
 (0)