Skip to content

Commit

Permalink
Add Sky DOM (#397)
Browse files Browse the repository at this point in the history
* add sky dom

Signed-off-by: Ian Chen <ichen@osrfoundation.org>

* feedback changes

Signed-off-by: Ian Chen <ichen@osrfoundation.org>

* move sdf element check

Signed-off-by: Ian Chen <ichen@osrfoundation.org>

Co-authored-by: Louise Poubel <louise@openrobotics.org>
  • Loading branch information
2 people authored and brawner committed Dec 11, 2020
1 parent 4e4c255 commit 3363ce7
Show file tree
Hide file tree
Showing 11 changed files with 747 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/sdf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ set (headers
SDFImpl.hh
SemanticPose.hh
Sensor.hh
Sky.hh
Sphere.hh
Surface.hh
Types.hh
Expand Down
9 changes: 9 additions & 0 deletions include/sdf/Scene.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <ignition/math/Color.hh>

#include "sdf/Element.hh"
#include "sdf/Sky.hh"
#include "sdf/Types.hh"
#include "sdf/sdf_config.h"
#include "sdf/system_util.hh"
Expand Down Expand Up @@ -107,6 +108,14 @@ namespace sdf
/// \param[in] enabled True to enable shadows
public: void SetShadows(const bool _shadows);

/// \brief Set sky
/// \param[in] _sky Sky to set to
public: void SetSky(const Sky &_sky);

/// \brief Get sky
/// \return Sky
public: const sdf::Sky *Sky() const;

/// \brief Get a pointer to the SDF element that was used during
/// load.
/// \return SDF element pointer. The value will be nullptr if Load has
Expand Down
146 changes: 146 additions & 0 deletions include/sdf/Sky.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
* Copyright 2020 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#ifndef SDF_SKY_HH_
#define SDF_SKY_HH_

#include <ignition/math/Color.hh>

#include "sdf/Element.hh"
#include "sdf/Types.hh"
#include "sdf/sdf_config.h"
#include "sdf/system_util.hh"

namespace sdf
{
// Inline bracket to help doxygen filtering.
inline namespace SDF_VERSION_NAMESPACE {
//

// Forward declarations.
class SkyPrivate;

class SDFORMAT_VISIBLE Sky
{
/// \brief Default constructor
public: Sky();

/// \brief Copy constructor
/// \param[in] _sky Sky element to copy.
public: Sky(const Sky &_sky);

/// \brief Move constructor
/// \param[in] _sky Sky to move.
public: Sky(Sky &&_sky) noexcept;

/// \brief Destructor
public: ~Sky();

/// \brief Assignment operator.
/// \param[in] _sky The sky to set values from.
/// \return *this
public: Sky &operator=(const Sky &_sky);

/// \brief Move assignment operator.
/// \param[in] _workflow The sky to move from.
/// \return *this
public: Sky &operator=(Sky &&_sky);

/// \brief Get time of day [0..24]
/// \return Time of day
public: double Time() const;

/// \brief Set time of day
/// \param[in] _time Time of day [0..24]
public: void SetTime(double _time);

/// \brief Get sunrise time
/// \return sunrise time [0..24]
public: double Sunrise() const;

/// \brief Set Sunrise time
/// \param[in] _time Sunrise time [0..24]
public: void SetSunrise(double _time);

/// \brief Get sunset time
/// \return sunset time [0..24]
public: double Sunset() const;

/// \brief Set Sunset time
/// \param[in] _time Sunset time [0..24]
public: void SetSunset(double _time);

/// \brief Get cloud speed
/// \return cloud speed in meters per second
public: double CloudSpeed() const;

/// \brief Set cloud speed
/// \param[in] _speed cloud speed in meters per second.
public: void SetCloudSpeed(double _speed);

/// \brief Get cloud direction angle (angle around up axis)
/// \return cloud direction angle in world frame
public: ignition::math::Angle CloudDirection() const;

/// \brief Set cloud direction angle (angle around up axis)
/// \param[in] _angle Cloud direction angle in world frame.
public: void SetCloudDirection(const ignition::math::Angle &_angle);

/// \brief Get cloud humidity
/// \return cloud humidity [0..1]
public: double CloudHumidity() const;

/// \brief Set cloud humidity
/// \param[in] _humidity cloud humidity [0..1]
public: void SetCloudHumidity(double _humidity);

/// \brief Get cloud mean size
/// \return cloud mean size [0..1]
public: double CloudMeanSize() const;

/// \brief Set cloud mean siz
/// \param[in] _size cloud mean size [0..1]
public: void SetCloudMeanSize(double _size);

/// \brief Get cloud ambient color
/// \return cloud ambient color
public: ignition::math::Color CloudAmbient() const;

/// \brief Set cloud ambient color
/// \param[in] _ambient cloud ambient color
public: void SetCloudAmbient(const ignition::math::Color &_ambient);

/// \brief Load the sky based on a element pointer. This is *not* the
/// usual entry point. Typical usage of the SDF DOM is through the Root
/// object.
/// \param[in] _sdf The SDF Element pointer
/// \return Errors, which is a vector of Error objects. Each Error includes
/// an error code and message. An empty vector indicates no error.
public: Errors Load(ElementPtr _sdf);

/// \brief Get a pointer to the SDF element that was used during
/// load.
/// \return SDF element pointer. The value will be nullptr if Load has
/// not been called.
public: sdf::ElementPtr Element() const;

/// \brief Private data pointer.
private: SkyPrivate *dataPtr = nullptr;
};
}
}
#endif
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ set (sources
SDFExtension.cc
SemanticPose.cc
Sensor.cc
Sky.cc
Sphere.cc
Surface.cc
Types.cc
Expand Down Expand Up @@ -118,6 +119,7 @@ if (BUILD_SDF_TEST)
SemanticPose_TEST.cc
SDF_TEST.cc
Sensor_TEST.cc
Sky_TEST.cc
Sphere_TEST.cc
Surface_TEST.cc
Types_TEST.cc
Expand Down
49 changes: 49 additions & 0 deletions src/Scene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ using namespace sdf;
/// \brief Scene private data.
class sdf::ScenePrivate
{
/// \brief Default constructor
public: ScenePrivate() = default;

/// \brief Copy constructor
/// \param[in] _scenePrivate private data to copy
public: explicit ScenePrivate(const ScenePrivate &_scenePrivate);

// Delete copy assignment so it is not accidentally used
public: ScenePrivate &operator=(const ScenePrivate &) = delete;

/// \brief True if grid should be enabled
public: bool grid = true;

Expand All @@ -39,10 +49,29 @@ class sdf::ScenePrivate
public: ignition::math::Color background =
ignition::math::Color(0.7f, 0.7f, .7f);

/// \brief Pointer to the sky properties.
public: std::unique_ptr<Sky> sky;

/// \brief The SDF element pointer used during load.
public: sdf::ElementPtr sdf;
};

/////////////////////////////////////////////////
ScenePrivate::ScenePrivate(const ScenePrivate &_scenePrivate)
: grid(_scenePrivate.grid),
shadows(_scenePrivate.shadows),
originVisual(_scenePrivate.originVisual),
ambient(_scenePrivate.ambient),
background(_scenePrivate.background),
sdf(_scenePrivate.sdf)
{
if (_scenePrivate.sky)
{
this->sky =
std::make_unique<Sky>(*(_scenePrivate.sky));
}
}

/////////////////////////////////////////////////
Scene::Scene()
: dataPtr(new ScenePrivate)
Expand Down Expand Up @@ -118,6 +147,14 @@ Errors Scene::Load(ElementPtr _sdf)
this->dataPtr->originVisual = _sdf->Get<bool>("origin_visual",
this->dataPtr->originVisual).first;

// load sky
if (_sdf->HasElement("sky"))
{
this->dataPtr->sky = std::make_unique<sdf::Sky>();
Errors err = this->dataPtr->sky->Load(_sdf->GetElement("sky"));
errors.insert(errors.end(), err.begin(), err.end());
}

return errors;
}

Expand Down Expand Up @@ -180,6 +217,18 @@ void Scene::SetOriginVisual(const bool _enabled)
this->dataPtr->originVisual = _enabled;
}

/////////////////////////////////////////////////
void Scene::SetSky(const sdf::Sky &_sky)
{
this->dataPtr->sky = std::make_unique<sdf::Sky>(_sky);
}

/////////////////////////////////////////////////
const sdf::Sky *Scene::Sky() const
{
return this->dataPtr->sky.get();
}

/////////////////////////////////////////////////
sdf::ElementPtr Scene::Element() const
{
Expand Down
17 changes: 17 additions & 0 deletions src/Scene_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ TEST(DOMScene, Construction)
EXPECT_TRUE(scene.Grid());
EXPECT_TRUE(scene.Shadows());
EXPECT_TRUE(scene.OriginVisual());
EXPECT_EQ(nullptr, scene.Sky());
}

/////////////////////////////////////////////////
Expand All @@ -41,13 +42,16 @@ TEST(DOMScene, CopyConstruction)
scene.SetGrid(false);
scene.SetShadows(false);
scene.SetOriginVisual(false);
sdf::Sky sky;
scene.SetSky(sky);

sdf::Scene scene2(scene);
EXPECT_EQ(ignition::math::Color::Blue, scene2.Ambient());
EXPECT_EQ(ignition::math::Color::Red, scene2.Background());
EXPECT_FALSE(scene2.Grid());
EXPECT_FALSE(scene2.Shadows());
EXPECT_FALSE(scene2.OriginVisual());
EXPECT_NE(nullptr, scene2.Sky());

EXPECT_NE(nullptr, scene2.Element());
EXPECT_EQ(scene.Element(), scene2.Element());
Expand All @@ -62,13 +66,16 @@ TEST(DOMScene, MoveConstruction)
scene.SetGrid(false);
scene.SetShadows(false);
scene.SetOriginVisual(false);
sdf::Sky sky;
scene.SetSky(sky);

sdf::Scene scene2(std::move(scene));
EXPECT_EQ(ignition::math::Color::Blue, scene2.Ambient());
EXPECT_EQ(ignition::math::Color::Red, scene2.Background());
EXPECT_FALSE(scene2.Grid());
EXPECT_FALSE(scene2.Shadows());
EXPECT_FALSE(scene2.OriginVisual());
EXPECT_NE(nullptr, scene2.Sky());
}

/////////////////////////////////////////////////
Expand All @@ -80,6 +87,8 @@ TEST(DOMScene, MoveAssignmentOperator)
scene.SetGrid(false);
scene.SetShadows(false);
scene.SetOriginVisual(false);
sdf::Sky sky;
scene.SetSky(sky);

sdf::Scene scene2;
scene2 = std::move(scene);
Expand All @@ -88,6 +97,7 @@ TEST(DOMScene, MoveAssignmentOperator)
EXPECT_FALSE(scene2.Grid());
EXPECT_FALSE(scene2.Shadows());
EXPECT_FALSE(scene2.OriginVisual());
EXPECT_NE(nullptr, scene2.Sky());
}

/////////////////////////////////////////////////
Expand All @@ -99,6 +109,8 @@ TEST(DOMScene, AssignmentOperator)
scene.SetGrid(false);
scene.SetShadows(false);
scene.SetOriginVisual(false);
sdf::Sky sky;
scene.SetSky(sky);

sdf::Scene scene2;
scene2 = scene;
Expand All @@ -107,6 +119,7 @@ TEST(DOMScene, AssignmentOperator)
EXPECT_FALSE(scene2.Grid());
EXPECT_FALSE(scene2.Shadows());
EXPECT_FALSE(scene2.OriginVisual());
EXPECT_NE(nullptr, scene2.Sky());
}

/////////////////////////////////////////////////
Expand Down Expand Up @@ -152,4 +165,8 @@ TEST(DOMScene, Set)
EXPECT_TRUE(scene.OriginVisual());
scene.SetOriginVisual(false);
EXPECT_FALSE(scene.OriginVisual());

sdf::Sky sky;
scene.SetSky(sky);
EXPECT_NE(nullptr, scene.Sky());
}
Loading

0 comments on commit 3363ce7

Please sign in to comment.