Skip to content

Commit

Permalink
Added option to visualize light in GUI (#877)
Browse files Browse the repository at this point in the history
Signed-off-by: ahcorde <[email protected]>
Signed-off-by: Louise Poubel <[email protected]>

Co-authored-by: Louise Poubel <[email protected]>
  • Loading branch information
ahcorde and chapulina authored Mar 12, 2022
1 parent 82ba371 commit a5b7a19
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
8 changes: 8 additions & 0 deletions include/sdf/Light.hh
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ namespace sdf
/// \param[in] _cast True to indicate that the light is on, False otherwise.
public: void SetLightOn(const bool _isLightOn);

/// \brief Whether light visualization in the GUI is enabled.
/// \return True if visualization is enabled.
public: bool Visualize() const;

/// \brief Set whether light visualization in the GUI is enabled.
/// \param[in] _visualize True to view the light on the GUI.
public: void SetVisualize(const bool _visualize);

/// \brief Get the light intensity
/// \return The light intensity
public: double Intensity() const;
Expand Down
4 changes: 4 additions & 0 deletions sdf/1.8/light.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<description>When true, the light is on.</description>
</element>

<element name="visualize" type="bool" default="true" required="0">
<description>If true, the light is visualized in the GUI</description>
</element>

<element name="intensity" type="double" default="1" required="0">
<description>Scale factor to set the relative power of a light.</description>
</element>
Expand Down
18 changes: 18 additions & 0 deletions src/Light.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ class sdf::Light::Implementation

/// \brief Is light on ?
public: bool isLightOn = true;

/// \brief is visual light enabled ?
public: bool visualize = true;
};

/////////////////////////////////////////////////
Expand Down Expand Up @@ -147,6 +150,9 @@ Errors Light::Load(ElementPtr _sdf)
this->dataPtr->isLightOn = _sdf->Get<bool>("light_on",
this->dataPtr->isLightOn).first;

this->dataPtr->visualize = _sdf->Get<bool>("visualize",
this->dataPtr->visualize).first;

this->dataPtr->castShadows = _sdf->Get<bool>("cast_shadows",
this->dataPtr->castShadows).first;

Expand Down Expand Up @@ -334,6 +340,18 @@ void Light::SetLightOn(const bool _isLightOn)
this->dataPtr->isLightOn = _isLightOn;
}

/////////////////////////////////////////////////
bool Light::Visualize() const
{
return this->dataPtr->visualize;
}

/////////////////////////////////////////////////
void Light::SetVisualize(const bool _visualize)
{
this->dataPtr->visualize = _visualize;
}

/////////////////////////////////////////////////
ignition::math::Color Light::Diffuse() const
{
Expand Down
12 changes: 12 additions & 0 deletions src/Light_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ TEST(DOMLight, DefaultConstruction)
light.SetLightOn(false);
EXPECT_FALSE(light.LightOn());

EXPECT_TRUE(light.Visualize());
light.SetVisualize(false);
EXPECT_FALSE(light.Visualize());

EXPECT_FALSE(light.CastShadows());
light.SetCastShadows(true);
EXPECT_TRUE(light.CastShadows());
Expand Down Expand Up @@ -118,6 +122,7 @@ TEST(DOMLight, CopyConstructor)
light.SetPoseRelativeTo("ground_plane");
light.SetCastShadows(true);
light.SetLightOn(false);
light.SetVisualize(false);
light.SetDiffuse(ignition::math::Color(0.4f, 0.5f, 0.6f, 1.0));
light.SetSpecular(ignition::math::Color(0.8f, 0.9f, 0.1f, 1.0));
light.SetAttenuationRange(3.2);
Expand All @@ -137,6 +142,7 @@ TEST(DOMLight, CopyConstructor)
EXPECT_EQ("ground_plane", light2.PoseRelativeTo());
EXPECT_TRUE(light2.CastShadows());
EXPECT_FALSE(light2.LightOn());
EXPECT_FALSE(light2.Visualize());
EXPECT_EQ(ignition::math::Color(0.4f, 0.5f, 0.6f, 1), light2.Diffuse());
EXPECT_EQ(ignition::math::Color(0.8f, 0.9f, 0.1f, 1), light2.Specular());
EXPECT_DOUBLE_EQ(3.2, light2.AttenuationRange());
Expand All @@ -160,6 +166,7 @@ TEST(DOMLight, CopyAssignmentOperator)
light.SetPoseRelativeTo("ground_plane");
light.SetCastShadows(true);
light.SetLightOn(false);
light.SetVisualize(false);
light.SetDiffuse(ignition::math::Color(0.4f, 0.5f, 0.6f, 1.0));
light.SetSpecular(ignition::math::Color(0.8f, 0.9f, 0.1f, 1.0));
light.SetAttenuationRange(3.2);
Expand All @@ -180,6 +187,7 @@ TEST(DOMLight, CopyAssignmentOperator)
EXPECT_EQ("ground_plane", light2.PoseRelativeTo());
EXPECT_TRUE(light2.CastShadows());
EXPECT_FALSE(light2.LightOn());
EXPECT_FALSE(light2.Visualize());
EXPECT_EQ(ignition::math::Color(0.4f, 0.5f, 0.6f, 1), light2.Diffuse());
EXPECT_EQ(ignition::math::Color(0.8f, 0.9f, 0.1f, 1), light2.Specular());
EXPECT_DOUBLE_EQ(3.2, light2.AttenuationRange());
Expand All @@ -203,6 +211,7 @@ TEST(DOMLight, MoveConstructor)
light.SetPoseRelativeTo("ground_plane");
light.SetCastShadows(true);
light.SetLightOn(false);
light.SetVisualize(false);
light.SetDiffuse(ignition::math::Color(0.4f, 0.5f, 0.6f, 1.0));
light.SetSpecular(ignition::math::Color(0.8f, 0.9f, 0.1f, 1.0));
light.SetAttenuationRange(3.2);
Expand All @@ -222,6 +231,7 @@ TEST(DOMLight, MoveConstructor)
EXPECT_EQ("ground_plane", light2.PoseRelativeTo());
EXPECT_TRUE(light2.CastShadows());
EXPECT_FALSE(light2.LightOn());
EXPECT_FALSE(light2.Visualize());
EXPECT_EQ(ignition::math::Color(0.4f, 0.5f, 0.6f, 1), light2.Diffuse());
EXPECT_EQ(ignition::math::Color(0.8f, 0.9f, 0.1f, 1), light2.Specular());
EXPECT_DOUBLE_EQ(3.2, light2.AttenuationRange());
Expand All @@ -245,6 +255,7 @@ TEST(DOMLight, MoveAssignment)
light.SetPoseRelativeTo("ground_plane");
light.SetCastShadows(true);
light.SetLightOn(false);
light.SetVisualize(false);
light.SetDiffuse(ignition::math::Color(0.4f, 0.5f, 0.6f, 1.0));
light.SetSpecular(ignition::math::Color(0.8f, 0.9f, 0.1f, 1.0));
light.SetAttenuationRange(3.2);
Expand All @@ -265,6 +276,7 @@ TEST(DOMLight, MoveAssignment)
EXPECT_EQ("ground_plane", light2.PoseRelativeTo());
EXPECT_TRUE(light2.CastShadows());
EXPECT_FALSE(light2.LightOn());
EXPECT_FALSE(light2.Visualize());
EXPECT_EQ(ignition::math::Color(0.4f, 0.5f, 0.6f, 1), light2.Diffuse());
EXPECT_EQ(ignition::math::Color(0.8f, 0.9f, 0.1f, 1), light2.Specular());
EXPECT_DOUBLE_EQ(3.2, light2.AttenuationRange());
Expand Down

0 comments on commit a5b7a19

Please sign in to comment.