Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require geospatial component #539

Merged
merged 6 commits into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ set(IGN_MATH_VER ${ignition-math7_VERSION_MAJOR})
#--------------------------------------
# Find ignition-common
ign_find_package(ignition-common5 REQUIRED
COMPONENTS graphics events)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The geospatial component in ign-common is optional, while geospatial is required here. Is that intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm if we make the geospatial component optional here, we will need to make heightmaps in ign-rendering optional as well and only build it if the geospatial component is available. We'll likely need to do the same in ign-gazebo.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we revert the ign-common PR for now while we sort this out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok that sounds good as this will require a bigger change

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a previous f2f meeting with @chapulina , we decided against making GDAL an optional component because it was going to add a layer of difficulty managing

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I remember also discussing this at the weekly meeting. GDAL will be required for heightmaps. Ignition Physics already has a separate heightmap component, so only that component needs to depend on geopspatial. But Ignition Rendering doesn't have that separation and with the current architecture I think it may be difficult to break that apart.

COMPONENTS graphics events geospatial)
set(IGN_COMMON_VER ${ignition-common5_VERSION_MAJOR})

#--------------------------------------
Expand Down
294 changes: 195 additions & 99 deletions examples/heightmap/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
#include <vector>

#include <ignition/common/Console.hh>
#include <ignition/common/HeightmapData.hh>
#include <ignition/common/ImageHeightmap.hh>
#include <ignition/common/geospatial/Dem.hh>
#include <ignition/common/geospatial/HeightmapData.hh>
#include <ignition/common/geospatial/ImageHeightmap.hh>
#include <ignition/rendering.hh>

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

//////////////////////////////////////////////////
void buildScene(ScenePtr _scene)
void createImageHeightmaps(const ScenePtr _scene, VisualPtr _root)
{
//! [create an image heightmap]
auto data = std::make_shared<common::ImageHeightmap>();
data->Load(common::joinPaths(RESOURCE_PATH, "heightmap_bowl.png"));

HeightmapDescriptor desc;
desc.SetName("example_bowl");
desc.SetData(data);
desc.SetSize({17, 17, 10});
desc.SetSampling(2u);
desc.SetUseTerrainPaging(false);

HeightmapTexture textureA;
textureA.SetSize(1.0);
textureA.SetDiffuse("../media/dirt_diffusespecular.png");
textureA.SetNormal("../media/flat_normal.png");
desc.AddTexture(textureA);

HeightmapBlend blendA;
blendA.SetMinHeight(2.0);
blendA.SetFadeDistance(5.0);
desc.AddBlend(blendA);

HeightmapTexture textureB;
textureB.SetSize(1.0);
textureB.SetDiffuse("../media/grass_diffusespecular.png");
textureB.SetNormal("../media/flat_normal.png");
desc.AddTexture(textureB);

HeightmapBlend blendB;
blendB.SetMinHeight(4.0);
blendB.SetFadeDistance(5.0);
desc.AddBlend(blendB);

HeightmapTexture textureC;
textureC.SetSize(1.0);
textureC.SetDiffuse("../media/fungus_diffusespecular.png");
textureC.SetNormal("../media/flat_normal.png");
desc.AddTexture(textureC);

auto heightmapGeom = _scene->CreateHeightmap(desc);

auto vis = _scene->CreateVisual();
vis->AddGeometry(heightmapGeom);
_root->AddChild(vis);
//! [create an image heightmap]

//! [create another image heightmap]
auto data2 = std::make_shared<common::ImageHeightmap>();
data2->Load(common::joinPaths(RESOURCE_PATH, "city_terrain.jpg"));

HeightmapDescriptor desc2;
desc2.SetName("example_city");
desc2.SetData(data2);
desc2.SetSize({26, 26, 20});
desc2.SetSampling(2u);
desc2.SetUseTerrainPaging(true);

HeightmapTexture textureA2;
textureA2.SetSize(1.0);
textureA2.SetDiffuse("../media/fungus_diffusespecular.png");
textureA2.SetNormal("../media/flat_normal.png");
desc2.AddTexture(textureA2);

HeightmapBlend blendA2;
blendA2.SetMinHeight(2.0);
blendA2.SetFadeDistance(5.0);
desc2.AddBlend(blendA2);

HeightmapTexture textureB2;
textureB2.SetSize(1.0);
textureB2.SetDiffuse("../media/grass_diffusespecular.png");
textureB2.SetNormal("../media/flat_normal.png");
desc2.AddTexture(textureB2);

HeightmapBlend blendB2;
blendB2.SetMinHeight(8.0);
blendB2.SetFadeDistance(5.0);
desc2.AddBlend(blendB2);

HeightmapTexture textureC2;
textureC2.SetSize(1.0);
textureC2.SetDiffuse("../media/dirt_diffusespecular.png");
textureC2.SetNormal("../media/flat_normal.png");
desc2.AddTexture(textureC2);
desc2.SetPosition({30, 0, 0});
auto heightmapGeom2 = _scene->CreateHeightmap(desc2);

auto vis2 = _scene->CreateVisual();
vis2->AddGeometry(heightmapGeom2);
_root->AddChild(vis2);
//! [create another image heightmap]
}

//////////////////////////////////////////////////
void createDemHeightmaps(const ScenePtr _scene, VisualPtr _root)
{
//! [create a dem heightmap]
auto data = std::make_shared<common::Dem>();
data->Load(common::joinPaths(RESOURCE_PATH, "volcano.tif"));

HeightmapDescriptor desc;
desc.SetName("example_volcano");
desc.SetData(data);
desc.SetSize({20, 20, 18});
desc.SetSampling(2u);
desc.SetUseTerrainPaging(true);

HeightmapTexture textureA;
textureA.SetSize(1.0);
textureA.SetDiffuse("../media/dirt_diffusespecular.png");
textureA.SetNormal("../media/flat_normal.png");
desc.AddTexture(textureA);

HeightmapBlend blendA;
blendA.SetMinHeight(2.0);
blendA.SetFadeDistance(5.0);
desc.AddBlend(blendA);

HeightmapTexture textureB;
textureB.SetSize(1.0);
textureB.SetDiffuse("../media/grass_diffusespecular.png");
textureB.SetNormal("../media/flat_normal.png");
desc.AddTexture(textureB);

HeightmapBlend blendB;
blendB.SetMinHeight(4.0);
blendB.SetFadeDistance(5.0);
desc.AddBlend(blendB);

HeightmapTexture textureC;
textureC.SetSize(1.0);
textureC.SetDiffuse("../media/fungus_diffusespecular.png");
textureC.SetNormal("../media/flat_normal.png");
desc.AddTexture(textureC);
desc.SetPosition({30, 0, 0});

auto heightmapGeom = _scene->CreateHeightmap(desc);

auto vis = _scene->CreateVisual();
vis->AddGeometry(heightmapGeom);
_root->AddChild(vis);
//! [create a dem heightmap]

//! [create another dem heightmap]
auto data2 = std::make_shared<common::Dem>();
data2->Load(common::joinPaths(RESOURCE_PATH, "moon.tif"));

HeightmapDescriptor desc2;
desc2.SetName("example_moon");
desc2.SetData(data2);
desc2.SetSize({20, 20, 6.85});
desc2.SetSampling(2u);
desc2.SetUseTerrainPaging(false);

HeightmapTexture textureA2;
textureA2.SetSize(20.0);
textureA2.SetDiffuse("../media/moon_diffuse.png");
textureA2.SetNormal("../media/moon_normal.png");
desc2.AddTexture(textureA2);
desc2.SetPosition({0, 0, std::abs(data2->MinElevation())});
auto heightmapGeom2 = _scene->CreateHeightmap(desc2);

auto vis2 = _scene->CreateVisual();
vis2->AddGeometry(heightmapGeom2);
_root->AddChild(vis2);
//! [create another dem heightmap]
}

//////////////////////////////////////////////////
void buildScene(ScenePtr _scene, bool _buildDemScene)
{
// initialize _scene
_scene->SetAmbientLight(0.3, 0.3, 0.3);
Expand All @@ -68,97 +240,10 @@ void buildScene(ScenePtr _scene)
light1->SetCastShadows(true);
root->AddChild(light1);

//! [create a heightmap]
auto data = std::make_shared<common::ImageHeightmap>();
data->Load(common::joinPaths(RESOURCE_PATH, "heightmap_bowl.png"));

HeightmapDescriptor desc;
desc.SetName("example_bowl");
desc.SetData(data);
desc.SetSize({17, 17, 10});
desc.SetSampling(2u);
desc.SetUseTerrainPaging(false);

HeightmapTexture textureA;
textureA.SetSize(1.0);
textureA.SetDiffuse("../media/dirt_diffusespecular.png");
textureA.SetNormal("../media/flat_normal.png");
desc.AddTexture(textureA);

HeightmapBlend blendA;
blendA.SetMinHeight(2.0);
blendA.SetFadeDistance(5.0);
desc.AddBlend(blendA);

HeightmapTexture textureB;
textureB.SetSize(1.0);
textureB.SetDiffuse("../media/grass_diffusespecular.png");
textureB.SetNormal("../media/flat_normal.png");
desc.AddTexture(textureB);

HeightmapBlend blendB;
blendB.SetMinHeight(4.0);
blendB.SetFadeDistance(5.0);
desc.AddBlend(blendB);

HeightmapTexture textureC;
textureC.SetSize(1.0);
textureC.SetDiffuse("../media/fungus_diffusespecular.png");
textureC.SetNormal("../media/flat_normal.png");
desc.AddTexture(textureC);

auto heightmapGeom = _scene->CreateHeightmap(desc);

auto vis = _scene->CreateVisual();
vis->AddGeometry(heightmapGeom);
root->AddChild(vis);
//! [create a heightmap]

//! [create another heightmap]
auto data2 = std::make_shared<common::ImageHeightmap>();
data2->Load(common::joinPaths(RESOURCE_PATH, "city_terrain.jpg"));

HeightmapDescriptor desc2;
desc2.SetName("example_city");
desc2.SetData(data2);
desc2.SetSize({26, 26, 20});
desc2.SetSampling(2u);
desc2.SetUseTerrainPaging(true);

HeightmapTexture textureA2;
textureA2.SetSize(1.0);
textureA2.SetDiffuse("../media/fungus_diffusespecular.png");
textureA2.SetNormal("../media/flat_normal.png");
desc2.AddTexture(textureA2);

HeightmapBlend blendA2;
blendA2.SetMinHeight(2.0);
blendA2.SetFadeDistance(5.0);
desc2.AddBlend(blendA2);

HeightmapTexture textureB2;
textureB2.SetSize(1.0);
textureB2.SetDiffuse("../media/grass_diffusespecular.png");
textureB2.SetNormal("../media/flat_normal.png");
desc2.AddTexture(textureB2);

HeightmapBlend blendB2;
blendB2.SetMinHeight(8.0);
blendB2.SetFadeDistance(5.0);
desc2.AddBlend(blendB2);

HeightmapTexture textureC2;
textureC2.SetSize(1.0);
textureC2.SetDiffuse("../media/dirt_diffusespecular.png");
textureC2.SetNormal("../media/flat_normal.png");
desc2.AddTexture(textureC2);
desc2.SetPosition({30, 0, 0});
auto heightmapGeom2 = _scene->CreateHeightmap(desc2);

auto vis2 = _scene->CreateVisual();
vis2->AddGeometry(heightmapGeom2);
root->AddChild(vis2);
//! [create another heightmap]
if (_buildDemScene)
createDemHeightmaps(_scene, root);
else
createImageHeightmaps(_scene, root);

// create gray material
MaterialPtr gray = _scene->CreateMaterial();
Expand Down Expand Up @@ -193,7 +278,8 @@ void buildScene(ScenePtr _scene)

//////////////////////////////////////////////////
CameraPtr createCamera(const std::string &_engineName,
const std::map<std::string, std::string>& _params)
const std::map<std::string, std::string>& _params,
bool _buildDemScene)
{
// create and populate scene
RenderEngine *engine = rendering::engine(_engineName, _params);
Expand All @@ -204,7 +290,7 @@ CameraPtr createCamera(const std::string &_engineName,
return CameraPtr();
}
ScenePtr scene = engine->CreateScene("scene");
buildScene(scene);
buildScene(scene, _buildDemScene);

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

int buildDemScene = 0;
for (int i = 1; i < _argc; ++i)
{
if (std::string(_argv[i]) == "--dem")
{
buildDemScene = i;
break;
}
}

// Expose engine name to command line because we can't instantiate both
// ogre and ogre2 at the same time
std::string ogreEngineName("ogre2");
if (_argc > 1)
if (_argc > 1 && buildDemScene != 1)
{
ogreEngineName = _argv[1];
}

GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
if (_argc > 2)
if (_argc > 2 && buildDemScene != 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
}
Expand All @@ -247,7 +343,7 @@ int main(int _argc, char** _argv)
params["metal"] = "1";
}

CameraPtr camera = createCamera(engineName, params);
CameraPtr camera = createCamera(engineName, params, buildDemScene);
if (camera)
{
cameras.push_back(camera);
Expand Down
Binary file added examples/heightmap/media/moon.tif
Binary file not shown.
Binary file added examples/heightmap/media/moon_diffuse.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/heightmap/media/moon_normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/heightmap/media/volcano.tif
Binary file not shown.
6 changes: 3 additions & 3 deletions include/ignition/rendering/HeightmapDescriptor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include <memory>
#include <string>
#include <ignition/common/HeightmapData.hh>
#include <ignition/common/geospatial/HeightmapData.hh>
#include <ignition/utils/SuppressWarning.hh>

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

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

/// \brief Set the heightmap's scaling factor. Defaults to 1x1x1.
/// \brief Set the heightmap's final size in world units. Defaults to 1x1x1.
/// \return The heightmap's size factor.
public: void SetSize(const ignition::math::Vector3d &_size);

Expand Down
8 changes: 3 additions & 5 deletions ogre/src/OgreHeightmap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,9 @@ void OgreHeightmap::Init()
// There is an issue with OGRE terrain LOD if heights are not relative to 0.
// So we move the heightmap so that its min elevation = 0 before feeding to
// ogre. It is later translated back by the setOrigin call.
double minElevation = 0.0;

// TODO(chapulina) add a virtual HeightmapData::MinElevation function to
// avoid the ifdef check. i.e. heightmapSizeZ = MaxElevation - MinElevation
double heightmapSizeZ = this->descriptor.Data()->MaxElevation();
double minElevation = this->descriptor.Data()->MinElevation();
double heightmapSizeZ =
this->descriptor.Data()->MaxElevation() - minElevation;

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