Skip to content

Commit

Permalink
Add scatter ratio parameter to Particle Emitter DOM (#547)
Browse files Browse the repository at this point in the history
* add particle scatter ratio?

Signed-off-by: Ian Chen <[email protected]>

* update field name

Signed-off-by: Ian Chen <[email protected]>

* update doc

Signed-off-by: Ian Chen <[email protected]>
  • Loading branch information
iche033 authored May 6, 2021
1 parent 1b49119 commit 12e6897
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 0 deletions.
11 changes: 11 additions & 0 deletions include/sdf/ParticleEmitter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,17 @@ namespace sdf
/// \param[in] _topic The topic used to update the particle emitter.
public: void SetTopic(const std::string &_topic);

/// \brief Get the particle scatter ratio. This is used to determine the
/// ratio of particles that will be detected by sensors.
/// \return Particle scatter ratio
/// \sa SetScatterRatio
public: float ScatterRatio() const;

/// \brief Set the particle scatter ratio. This is used to determine the
/// ratio of particles that will be detected by sensors.
/// \param[in] _ratio Scatter ratio.
public: void SetScatterRatio(float _ratio);

/// \brief Get the pose of the particle emitter. This is the pose of the
/// emitter as specified in SDF
/// (<particle_emitter><pose> ... </pose></particle_emitter>).
Expand Down
11 changes: 11 additions & 0 deletions sdf/1.7/particle_emitter.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@
</description>
</element>

<element name="particle_scatter_ratio" type="float" default="0.65" required="0">
<description>
This is used to determine the ratio of particles that will be detected
by sensors. Increasing the ratio means there is a higher chance of
particles reflecting and interfering with depth sensing, making the
emitter appear more dense. Decreasing the ratio decreases the chance
of particles reflecting and interfering with depth sensing, making it
appear less dense.
</description>
</element>

<include filename="pose.sdf" required="0"/>
<include filename="material.sdf" required="0"/>
</element>
24 changes: 24 additions & 0 deletions src/ParticleEmitter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ class sdf::ParticleEmitterPrivate
/// \brief Topic used to update particle emitter properties at runtime.
public: std::string topic = "";

/// \brief Particle scatter ratio. This is used to determine the ratio of
/// particles that will be detected by sensors. Increasing the ratio
/// means there is a higher chance of particles reflecting and interfering
/// with depth sensing, making the emitter appear more dense. Decreasing
/// the ratio decreases the chance of particles reflecting and interfering
/// with depth sensing, making it appear less dense.
public: float scatterRatio = 0.65f;

/// \brief Pose of the emitter
public: ignition::math::Pose3d pose = ignition::math::Pose3d::Zero;

Expand Down Expand Up @@ -136,6 +144,7 @@ ParticleEmitterPrivate::ParticleEmitterPrivate(
colorEnd(_private.colorEnd),
colorRangeImage(_private.colorRangeImage),
topic(_private.topic),
scatterRatio(_private.scatterRatio),
pose(_private.pose),
poseRelativeTo(_private.poseRelativeTo),
xmlParentName(_private.xmlParentName),
Expand Down Expand Up @@ -272,6 +281,9 @@ Errors ParticleEmitter::Load(ElementPtr _sdf)
this->dataPtr->topic = _sdf->Get<std::string>(
"topic", this->dataPtr->topic).first;

this->dataPtr->scatterRatio = _sdf->Get<float>(
"particle_scatter_ratio", this->dataPtr->scatterRatio).first;

if (_sdf->HasElement("material"))
{
this->dataPtr->material.reset(new sdf::Material());
Expand Down Expand Up @@ -487,6 +499,18 @@ void ParticleEmitter::SetTopic(const std::string &_topic)
this->dataPtr->topic = _topic;
}

/////////////////////////////////////////////////
void ParticleEmitter::SetScatterRatio(float _ratio)
{
this->dataPtr->scatterRatio = _ratio;
}

/////////////////////////////////////////////////
float ParticleEmitter::ScatterRatio() const
{
return this->dataPtr->scatterRatio;
}

/////////////////////////////////////////////////
const ignition::math::Pose3d &ParticleEmitter::RawPose() const
{
Expand Down
4 changes: 4 additions & 0 deletions src/ParticleEmitter_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ TEST(DOMParticleEmitter, Construction)
emitter.SetTopic("/test/topic");
EXPECT_EQ("/test/topic", emitter.Topic());

EXPECT_FLOAT_EQ(0.65f, emitter.ScatterRatio());
emitter.SetScatterRatio(0.5f);
EXPECT_FLOAT_EQ(0.5f, emitter.ScatterRatio());

EXPECT_EQ(ignition::math::Pose3d::Zero, emitter.RawPose());
emitter.SetRawPose(ignition::math::Pose3d(1, 2, 3, 0, 0, 1.5707));
EXPECT_EQ(ignition::math::Pose3d(1, 2, 3, 0, 0, 1.5707), emitter.RawPose());
Expand Down
1 change: 1 addition & 0 deletions test/integration/particle_emitter_dom.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ TEST(DOMWorld, LoadParticleEmitter)
EXPECT_DOUBLE_EQ(0.2, linkEmitter->MaxVelocity());
EXPECT_DOUBLE_EQ(0.5, linkEmitter->ScaleRate());
EXPECT_DOUBLE_EQ(5, linkEmitter->Rate());
EXPECT_FLOAT_EQ(0.2f, linkEmitter->ScatterRatio());

sdf::Material *mat = linkEmitter->Material();
ASSERT_NE(nullptr, mat);
Expand Down
1 change: 1 addition & 0 deletions test/sdf/world_complete.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
</pbr>
</material>
<color_range_image>materials/textures/fogcolors.png</color_range_image>
<particle_scatter_ratio>0.2</particle_scatter_ratio>
</particle_emitter>

<light name="spot_light" type="spot">
Expand Down

0 comments on commit 12e6897

Please sign in to comment.