Skip to content

Commit

Permalink
Merge branch 'main' into ahcorde/is_light_off
Browse files Browse the repository at this point in the history
  • Loading branch information
ahcorde authored Apr 21, 2022
2 parents c554e81 + dceb67d commit 78eb1f8
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 92 deletions.
29 changes: 2 additions & 27 deletions src/Conversions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -571,15 +571,7 @@ msgs::Light ignition::gazebo::convert(const sdf::Light &_in)
out.set_spot_outer_angle(_in.SpotOuterAngle().Radian());
out.set_spot_falloff(_in.SpotFalloff());
out.set_is_light_off(!_in.LightOn());

{
// todo(ahcorde) Use the field visualize_visual in light.proto from
// Garden on.
auto header = out.mutable_header()->add_data();
header->set_key("visualizeVisual");
std::string *value = header->add_value();
*value = std::to_string(_in.Visualize());
}
out.set_visualize_visual(_in.Visualize());

if (_in.Type() == sdf::LightType::POINT)
out.set_type(msgs::Light_LightType_POINT);
Expand Down Expand Up @@ -611,24 +603,7 @@ sdf::Light ignition::gazebo::convert(const msgs::Light &_in)
out.SetSpotOuterAngle(math::Angle(_in.spot_outer_angle()));
out.SetSpotFalloff(_in.spot_falloff());
out.SetLightOn(!_in.is_light_off());

// todo(ahcorde) Use the field visualize_visual in light.proto from
// Garden on.
bool visualizeVisual = true;
for (int i = 0; i < _in.header().data_size(); ++i)
{
for (int j = 0;
j < _in.header().data(i).value_size(); ++j)
{
if (_in.header().data(i).key() ==
"visualizeVisual")
{
visualizeVisual = ignition::math::parseInt(
_in.header().data(i).value(0));
}
}
}
out.SetVisualize(visualizeVisual);
out.SetVisualize(_in.visualize_visual());

if (_in.type() == msgs::Light_LightType_POINT)
out.SetType(sdf::LightType::POINT);
Expand Down
3 changes: 3 additions & 0 deletions src/Conversions_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ TEST(Conversions, Light)
light.SetRawPose({3, 2, 1, 0, IGN_PI, 0});
light.SetPoseRelativeTo("world");
light.SetCastShadows(true);
light.SetVisualize(true);
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 @@ -78,6 +79,7 @@ TEST(Conversions, Light)
// EXPECT_EQ("world", lightMsg.pose_frame());
EXPECT_TRUE(lightMsg.cast_shadows());
EXPECT_FALSE(lightMsg.is_light_off());
EXPECT_TRUE(lightMsg.visualize_visual());
EXPECT_EQ(math::Color(0.4f, 0.5f, 0.6f, 1),
msgs::Convert(lightMsg.diffuse()));
EXPECT_EQ(math::Color(0.8f, 0.9f, 0.1f, 1),
Expand All @@ -99,6 +101,7 @@ TEST(Conversions, Light)
/// \todo(anyone) add pose frame fields in ign-msgs?
// EXPECT_EQ("world", newLight.PoseRelativeTo());
EXPECT_TRUE(newLight.CastShadows());
EXPECT_TRUE(newLight.Visualize());
EXPECT_EQ(math::Color(0.4f, 0.5f, 0.6f, 1.0f), newLight.Diffuse());
EXPECT_EQ(math::Color(0.8f, 0.9f, 0.1f, 1.0f), newLight.Specular());
EXPECT_FLOAT_EQ(3.2f, newLight.AttenuationRange());
Expand Down
27 changes: 2 additions & 25 deletions src/gui/plugins/component_inspector/ComponentInspector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,6 @@ void ignition::gazebo::setData(QStandardItem *_item, const msgs::Light &_data)
lightType = 2;
}

bool visualizeVisual = true;
for (int i = 0; i < _data.header().data_size(); ++i)
{
for (int j = 0;
j < _data.header().data(i).value_size(); ++j)
{
if (_data.header().data(i).key() ==
"visualizeVisual")
{
visualizeVisual = ignition::math::parseInt(
_data.header().data(i).value(0));
}
}
}

_item->setData(QString("Light"),
ComponentsModel::RoleNames().key("dataType"));
_item->setData(QList({
Expand All @@ -181,7 +166,7 @@ void ignition::gazebo::setData(QStandardItem *_item, const msgs::Light &_data)
QVariant(_data.intensity()),
QVariant(lightType),
QVariant(!_data.is_light_off()),
QVariant(visualizeVisual)
QVariant(_data.visualize_visual())
}), ComponentsModel::RoleNames().key("data"));
}

Expand Down Expand Up @@ -1015,15 +1000,6 @@ void ComponentInspector::OnLight(
};

ignition::msgs::Light req;
{
// todo(ahcorde) Use the field visualize_visual in light.proto from
// Garden on.
auto header = req.mutable_header()->add_data();
header->set_key("visualizeVisual");
std::string *value = header->add_value();
*value = std::to_string(_visualizeVisual);
}

req.set_name(this->dataPtr->entityName);
req.set_id(this->dataPtr->entity);
ignition::msgs::Set(req.mutable_diffuse(),
Expand All @@ -1037,6 +1013,7 @@ void ComponentInspector::OnLight(
req.set_cast_shadows(_castShadows);
req.set_intensity(_intensity);
req.set_is_light_off(!_isLightOn);
req.set_visualize_visual(_visualizeVisual);
if (_type == 0)
req.set_type(ignition::msgs::Light::POINT);
else if (_type == 1)
Expand Down
19 changes: 1 addition & 18 deletions src/rendering/RenderUtil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2855,28 +2855,11 @@ void RenderUtilPrivate::UpdateLights(
auto l = std::dynamic_pointer_cast<rendering::Light>(node);
if (l)
{
// todo(ahcorde) Use the field visualize_visual in light.proto from
// Garden on.
bool visualizeVisual = true;
for (int i = 0; i < light.second.header().data_size(); ++i)
{
for (int j = 0;
j < light.second.header().data(i).value_size(); ++j)
{
if (light.second.header().data(i).key() ==
"visualizeVisual")
{
visualizeVisual = ignition::math::parseInt(
light.second.header().data(i).value(0));
}
}
}

rendering::VisualPtr lightVisual =
this->sceneManager.VisualById(
this->matchLightWithVisuals[light.first]);
if (lightVisual)
lightVisual->SetVisible(visualizeVisual);
lightVisual->SetVisible(light.second.visualize_visual());

if (!light.second.is_light_off())
{
Expand Down
23 changes: 1 addition & 22 deletions src/systems/user_commands/UserCommands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -227,30 +227,9 @@ class LightCommand : public UserCommandBase
public: std::function<bool(const msgs::Light &, const msgs::Light &)>
lightEql { [](const msgs::Light &_a, const msgs::Light &_b)
{
// todo(ahcorde) Use the field visualize_visual in light.proto
// from Garden on.
auto getVisualizeVisual = [](const msgs::Light &_light) -> bool
{
bool visualizeVisual = true;
for (int i = 0; i < _light.header().data_size(); ++i)
{
for (int j = 0;
j < _light.header().data(i).value_size(); ++j)
{
if (_light.header().data(i).key() ==
"visualizeVisual")
{
visualizeVisual = ignition::math::parseInt(
_light.header().data(i).value(0));
}
}
}
return visualizeVisual;
};

return
getVisualizeVisual(_a) == getVisualizeVisual(_b) &&
_a.is_light_off() == _b.is_light_off() &&
_a.visualize_visual() == _b.visualize_visual() &&
_a.type() == _b.type() &&
_a.name() == _b.name() &&
math::equal(
Expand Down
9 changes: 9 additions & 0 deletions test/integration/user_commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,7 @@ TEST_F(UserCommandsTest, IGN_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Light))
EXPECT_NEAR(0.01, pointLightComp->Data().QuadraticAttenuationFactor(), 0.1);
EXPECT_FALSE(pointLightComp->Data().CastShadows());
EXPECT_TRUE(pointLightComp->Data().LightOn());
EXPECT_TRUE(pointLightComp->Data().Visualize());

req.Clear();
ignition::msgs::Set(req.mutable_diffuse(),
Expand All @@ -837,6 +838,7 @@ TEST_F(UserCommandsTest, IGN_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Light))
req.set_attenuation_quadratic(0.001f);
req.set_cast_shadows(true);
req.set_is_light_off(false);
req.set_visualize_visual(false);

EXPECT_TRUE(node.Request(service, req, timeout, res, result));
EXPECT_TRUE(result);
Expand All @@ -860,6 +862,7 @@ TEST_F(UserCommandsTest, IGN_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Light))
EXPECT_NEAR(0.001, pointLightComp->Data().QuadraticAttenuationFactor(), 0.1);
EXPECT_TRUE(pointLightComp->Data().CastShadows());
EXPECT_TRUE(pointLightComp->Data().LightOn());
EXPECT_FALSE(pointLightComp->Data().Visualize());
EXPECT_EQ(sdf::LightType::POINT, pointLightComp->Data().Type());

// Check directional light entity has not been edited yet - Initial values
Expand Down Expand Up @@ -888,6 +891,7 @@ TEST_F(UserCommandsTest, IGN_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Light))
math::Vector3d(0.5, 0.2, -0.9), directionalLightComp->Data().Direction());
EXPECT_TRUE(directionalLightComp->Data().CastShadows());
EXPECT_TRUE(directionalLightComp->Data().LightOn());
EXPECT_TRUE(directionalLightComp->Data().Visualize());
EXPECT_EQ(sdf::LightType::POINT, pointLightComp->Data().Type());

req.Clear();
Expand All @@ -903,6 +907,7 @@ TEST_F(UserCommandsTest, IGN_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Light))
req.set_attenuation_quadratic(1.0f);
req.set_cast_shadows(false);
req.set_is_light_off(false);
req.set_visualize_visual(false);
ignition::msgs::Set(req.mutable_direction(),
ignition::math::Vector3d(1, 2, 3));
EXPECT_TRUE(node.Request(service, req, timeout, res, result));
Expand Down Expand Up @@ -932,6 +937,7 @@ TEST_F(UserCommandsTest, IGN_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Light))
EXPECT_EQ(math::Vector3d(1, 2, 3), directionalLightComp->Data().Direction());
EXPECT_FALSE(directionalLightComp->Data().CastShadows());
EXPECT_TRUE(directionalLightComp->Data().LightOn());
EXPECT_FALSE(directionalLightComp->Data().Visualize());
EXPECT_EQ(sdf::LightType::DIRECTIONAL,
directionalLightComp->Data().Type());

Expand All @@ -957,6 +963,7 @@ TEST_F(UserCommandsTest, IGN_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Light))
0.001, spotLightComp->Data().QuadraticAttenuationFactor(), 0.001);
EXPECT_EQ(math::Vector3d(0, 0, -1), spotLightComp->Data().Direction());
EXPECT_FALSE(spotLightComp->Data().CastShadows());
EXPECT_TRUE(spotLightComp->Data().Visualize());
EXPECT_EQ(sdf::LightType::SPOT, spotLightComp->Data().Type());
EXPECT_NEAR(0.1, spotLightComp->Data().SpotInnerAngle().Radian(), 0.1);
EXPECT_NEAR(0.5, spotLightComp->Data().SpotOuterAngle().Radian(), 0.1);
Expand All @@ -975,6 +982,7 @@ TEST_F(UserCommandsTest, IGN_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Light))
req.set_attenuation_quadratic(1.0f);
req.set_cast_shadows(true);
req.set_is_light_off(true);
req.set_visualize_visual(true);
ignition::msgs::Set(req.mutable_direction(),
ignition::math::Vector3d(1, 2, 3));
req.set_spot_inner_angle(1.5f);
Expand Down Expand Up @@ -1004,6 +1012,7 @@ TEST_F(UserCommandsTest, IGN_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Light))
EXPECT_EQ(math::Vector3d(1, 2, 3), spotLightComp->Data().Direction());
EXPECT_TRUE(spotLightComp->Data().CastShadows());
EXPECT_FALSE(spotLightComp->Data().LightOn());
EXPECT_TRUE(spotLightComp->Data().Visualize());
EXPECT_EQ(sdf::LightType::SPOT, spotLightComp->Data().Type());
EXPECT_NEAR(1.5, spotLightComp->Data().SpotInnerAngle().Radian(), 0.1);
EXPECT_NEAR(0.3, spotLightComp->Data().SpotOuterAngle().Radian(), 0.1);
Expand Down

0 comments on commit 78eb1f8

Please sign in to comment.