28
28
#include < vector>
29
29
30
30
#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>
33
34
#include < ignition/rendering.hh>
34
35
35
36
#include " example_config.hh"
@@ -42,7 +43,178 @@ const std::string RESOURCE_PATH =
42
43
common::joinPaths (std::string(PROJECT_BINARY_PATH), "media");
43
44
44
45
// ////////////////////////////////////////////////
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)
46
218
{
47
219
// initialize _scene
48
220
_scene->SetAmbientLight (0.3 , 0.3 , 0.3 );
@@ -68,97 +240,10 @@ void buildScene(ScenePtr _scene)
68
240
light1->SetCastShadows (true );
69
241
root->AddChild (light1);
70
242
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);
162
247
163
248
// create gray material
164
249
MaterialPtr gray = _scene->CreateMaterial ();
@@ -193,7 +278,8 @@ void buildScene(ScenePtr _scene)
193
278
194
279
// ////////////////////////////////////////////////
195
280
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)
197
283
{
198
284
// create and populate scene
199
285
RenderEngine *engine = rendering::engine (_engineName, _params);
@@ -204,7 +290,7 @@ CameraPtr createCamera(const std::string &_engineName,
204
290
return CameraPtr ();
205
291
}
206
292
ScenePtr scene = engine->CreateScene (" scene" );
207
- buildScene (scene);
293
+ buildScene (scene, _buildDemScene );
208
294
209
295
// return camera sensor
210
296
SensorPtr sensor = scene->SensorByName (" camera" );
@@ -220,16 +306,26 @@ int main(int _argc, char** _argv)
220
306
std::vector<std::string> engineNames;
221
307
std::vector<CameraPtr> cameras;
222
308
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
+
223
319
// Expose engine name to command line because we can't instantiate both
224
320
// ogre and ogre2 at the same time
225
321
std::string ogreEngineName (" ogre2" );
226
- if (_argc > 1 )
322
+ if (_argc > 1 && buildDemScene != 1 )
227
323
{
228
324
ogreEngineName = _argv[1 ];
229
325
}
230
326
231
327
GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
232
- if (_argc > 2 )
328
+ if (_argc > 2 && buildDemScene != 2 )
233
329
{
234
330
graphicsApi = GraphicsAPIUtils::Set (std::string (_argv[2 ]));
235
331
}
@@ -247,7 +343,7 @@ int main(int _argc, char** _argv)
247
343
params[" metal" ] = " 1" ;
248
344
}
249
345
250
- CameraPtr camera = createCamera (engineName, params);
346
+ CameraPtr camera = createCamera (engineName, params, buildDemScene );
251
347
if (camera)
252
348
{
253
349
cameras.push_back (camera);
0 commit comments