Skip to content

Commit

Permalink
Address a couple of todos in Conversion.cc
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Chen <[email protected]>
  • Loading branch information
iche033 committed Jul 1, 2024
1 parent 5641ef2 commit 65ea9da
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 51 deletions.
49 changes: 6 additions & 43 deletions src/Conversions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ msgs::Atmosphere gz::sim::convert(const sdf::Atmosphere &_in)
out.set_type(msgs::Atmosphere::ADIABATIC);
}
// todo(anyone) add mass density to sdf::Atmosphere?
// out.set_mass_density(_in.MassDensity());k
// out.set_mass_density(_in.MassDensity());

return out;
}
Expand Down Expand Up @@ -1703,15 +1703,7 @@ msgs::ParticleEmitter gz::sim::convert(const sdf::ParticleEmitter &_in)
}
}

/// \todo(nkoenig) Modify the particle_emitter.proto file to
/// have a topic field.
if (!_in.Topic().empty())
{
auto header = out.mutable_header()->add_data();
header->set_key("topic");
header->add_value(_in.Topic());
}

out.mutable_topic()->set_data(_in.Topic());
out.mutable_particle_scatter_ratio()->set_data(_in.ScatterRatio());
return out;
}
Expand Down Expand Up @@ -1766,15 +1758,8 @@ sdf::ParticleEmitter gz::sim::convert(const msgs::ParticleEmitter &_in)
out.SetColorRangeImage(_in.color_range_image().data());
if (_in.has_particle_scatter_ratio())
out.SetScatterRatio(_in.particle_scatter_ratio().data());

for (int i = 0; i < _in.header().data_size(); ++i)
{
auto data = _in.header().data(i);
if (data.key() == "topic" && data.value_size() > 0)
{
out.SetTopic(data.value(0));
}
}
if (_in.has_topic())
out.SetTopic(_in.topic().data());

return out;
}
Expand All @@ -1792,10 +1777,7 @@ msgs::Projector gz::sim::convert(const sdf::Projector &_in)
out.set_fov(_in.HorizontalFov().Radian());
out.set_texture(_in.Texture().empty() ? "" :
asFullPath(_in.Texture(), _in.FilePath()));

auto header = out.mutable_header()->add_data();
header->set_key("visibility_flags");
header->add_value(std::to_string(_in.VisibilityFlags()));
out.set_visibility_flags(_in.VisibilityFlags());

return out;
}
Expand All @@ -1812,26 +1794,7 @@ sdf::Projector gz::sim::convert(const msgs::Projector &_in)
out.SetHorizontalFov(math::Angle(_in.fov()));
out.SetTexture(_in.texture());
out.SetRawPose(msgs::Convert(_in.pose()));

/// \todo(anyone) add "visibility_flags" field to projector.proto
for (int i = 0; i < _in.header().data_size(); ++i)
{
auto data = _in.header().data(i);
if (data.key() == "visibility_flags" && data.value_size() > 0)
{
try
{
out.SetVisibilityFlags(std::stoul(data.value(0)));
}
catch (...)
{
gzerr << "Failed to parse projector <visibility_flags>: "
<< data.value(0) << ". Using default value: 0xFFFFFFFF."
<< std::endl;
out.SetVisibilityFlags(0xFFFFFFFF);
}
}
}
out.SetVisibilityFlags(_in.visibility_flags());

return out;
}
Expand Down
10 changes: 2 additions & 8 deletions src/Conversions_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1041,10 +1041,7 @@ TEST(Conversions, ParticleEmitter)
EXPECT_EQ(math::Color(0.4f, 0.5f, 0.6f),
msgs::Convert(emitterMsg.color_end()));
EXPECT_EQ("range_image", emitterMsg.color_range_image().data());

auto header = emitterMsg.header().data(0);
EXPECT_EQ("topic", header.key());
EXPECT_EQ("my_topic", header.value(0));
EXPECT_EQ("my_topic", emitterMsg.topic().data());

EXPECT_FLOAT_EQ(0.9f, emitterMsg.particle_scatter_ratio().data());

Expand Down Expand Up @@ -1094,10 +1091,7 @@ TEST(Conversions, Projector)
EXPECT_NEAR(30, projectorMsg.far_clip(), 1e-3);
EXPECT_NEAR(0.4, projectorMsg.fov(), 1e-3);
EXPECT_EQ("projector.png", projectorMsg.texture());

auto header = projectorMsg.header().data(0);
EXPECT_EQ("visibility_flags", header.key());
EXPECT_EQ(0xFF, std::stoul(header.value(0)));
EXPECT_EQ(0xFF, projectorMsg.visibility_flags());

// Convert the message back to SDF.
sdf::Projector projector2 = convert<sdf::Projector>(projectorMsg);
Expand Down

0 comments on commit 65ea9da

Please sign in to comment.