From 12e68974e77e6499f00a00a48cbec445e4388988 Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Wed, 5 May 2021 20:36:59 -0700 Subject: [PATCH] Add scatter ratio parameter to Particle Emitter DOM (#547) * add particle scatter ratio? Signed-off-by: Ian Chen * update field name Signed-off-by: Ian Chen * update doc Signed-off-by: Ian Chen --- include/sdf/ParticleEmitter.hh | 11 +++++++++++ sdf/1.7/particle_emitter.sdf | 11 +++++++++++ src/ParticleEmitter.cc | 24 ++++++++++++++++++++++++ src/ParticleEmitter_TEST.cc | 4 ++++ test/integration/particle_emitter_dom.cc | 1 + test/sdf/world_complete.sdf | 1 + 6 files changed, 52 insertions(+) diff --git a/include/sdf/ParticleEmitter.hh b/include/sdf/ParticleEmitter.hh index 251b4ff60..ae1dae9a8 100644 --- a/include/sdf/ParticleEmitter.hh +++ b/include/sdf/ParticleEmitter.hh @@ -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 /// ( ... ). diff --git a/sdf/1.7/particle_emitter.sdf b/sdf/1.7/particle_emitter.sdf index 428ed251e..d6a2fdf7e 100644 --- a/sdf/1.7/particle_emitter.sdf +++ b/sdf/1.7/particle_emitter.sdf @@ -104,6 +104,17 @@ + + + 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. + + + diff --git a/src/ParticleEmitter.cc b/src/ParticleEmitter.cc index e343077e3..195bd09ae 100644 --- a/src/ParticleEmitter.cc +++ b/src/ParticleEmitter.cc @@ -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; @@ -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), @@ -272,6 +281,9 @@ Errors ParticleEmitter::Load(ElementPtr _sdf) this->dataPtr->topic = _sdf->Get( "topic", this->dataPtr->topic).first; + this->dataPtr->scatterRatio = _sdf->Get( + "particle_scatter_ratio", this->dataPtr->scatterRatio).first; + if (_sdf->HasElement("material")) { this->dataPtr->material.reset(new sdf::Material()); @@ -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 { diff --git a/src/ParticleEmitter_TEST.cc b/src/ParticleEmitter_TEST.cc index 8dc350de3..3cc03c85c 100644 --- a/src/ParticleEmitter_TEST.cc +++ b/src/ParticleEmitter_TEST.cc @@ -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()); diff --git a/test/integration/particle_emitter_dom.cc b/test/integration/particle_emitter_dom.cc index 6071ac184..4590a84cb 100644 --- a/test/integration/particle_emitter_dom.cc +++ b/test/integration/particle_emitter_dom.cc @@ -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); diff --git a/test/sdf/world_complete.sdf b/test/sdf/world_complete.sdf index 955b4268d..211c7f148 100644 --- a/test/sdf/world_complete.sdf +++ b/test/sdf/world_complete.sdf @@ -90,6 +90,7 @@ materials/textures/fogcolors.png + 0.2