Skip to content

Commit

Permalink
add particle scatter ratio?
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Chen <[email protected]>
  • Loading branch information
iche033 committed Apr 26, 2021
1 parent f310d75 commit 81381f0
Show file tree
Hide file tree
Showing 6 changed files with 50 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 raito. This value should be > 0.
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
10 changes: 10 additions & 0 deletions sdf/1.7/particle_emitter.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@
</description>
</element>

<element name="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 making it
appear less dense. This value should be > 0.
</description>
</element>

<include filename="pose.sdf" required="0"/>
<include filename="material.sdf" required="0"/>
</element>
23 changes: 23 additions & 0 deletions src/ParticleEmitter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ 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 making it appear less dense. This value should be > 0.
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 +143,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 +280,9 @@ Errors ParticleEmitter::Load(ElementPtr _sdf)
this->dataPtr->topic = _sdf->Get<std::string>(
"topic", this->dataPtr->topic).first;

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

if (_sdf->HasElement("material"))
{
this->dataPtr->material.reset(new sdf::Material());
Expand Down Expand Up @@ -487,6 +498,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>
<scatter_ratio>0.2</scatter_ratio>
</particle_emitter>

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

0 comments on commit 81381f0

Please sign in to comment.