Skip to content

Commit

Permalink
10 ➡️ 11 (#598)
Browse files Browse the repository at this point in the history
Signed-off-by: Louise Poubel <[email protected]>
  • Loading branch information
chapulina authored Jun 23, 2021
2 parents 85ebd9b + 5480d5f commit d811185
Show file tree
Hide file tree
Showing 15 changed files with 399 additions and 1 deletion.
11 changes: 11 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,17 @@

## libsdformat 10.X

### libsdformat 10.5.0 (2021-05-17)

1. Add scatter ratio parameter to Particle Emitter DOM.
+ [Pull request 547](https://github.com/osrf/sdformat/pull/547)

1. Methods for removing attributes from an element.
+ [Pull request 555](https://github.com/osrf/sdformat/pull/555)

1. Improve docs of collision bitmask.
+ [Pull request 521](https://github.com/osrf/sdformat/pull/521)

### libsdformat 10.4.0 (2021-04-06)

1. Added particle emitter.
Expand Down
14 changes: 14 additions & 0 deletions include/sdf/Element.hh
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ namespace sdf
/// \sa Element::SetRequired
public: const std::string &GetRequired() const;

/// \brief Set if the element and children where set or default
/// in the original file. This is meant to be used by the parser to
/// indicate whether the element was set by the user in the original
/// file or added by default during parsing.
/// \param[in] _value True if the element was set
public: void SetExplicitlySetInFile(const bool _value);

/// \brief Return if the element was been explicitly set in the file
/// \return True if the element was set in the file
public: bool GetExplicitlySetInFile() const;

/// \brief Set whether this element should copy its child elements
/// during parsing.
/// \param[in] _value True to copy Element's children.
Expand Down Expand Up @@ -508,6 +519,9 @@ namespace sdf
/// \brief True if element is required
public: std::string required;

/// \brief True if the element was set in the SDF file.
public: bool explicitlySetInFile;

/// \brief Element description
public: std::string description;

Expand Down
11 changes: 11 additions & 0 deletions include/sdf/ParticleEmitter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,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>
22 changes: 22 additions & 0 deletions src/Element.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Element::Element()
{
this->dataPtr->copyChildren = false;
this->dataPtr->referenceSDF = "";
this->dataPtr->explicitlySetInFile = true;
}

/////////////////////////////////////////////////
Expand Down Expand Up @@ -93,6 +94,25 @@ void Element::SetCopyChildren(bool _value)
this->dataPtr->copyChildren = _value;
}

/////////////////////////////////////////////////
void Element::SetExplicitlySetInFile(const bool _value)
{
this->dataPtr->explicitlySetInFile = _value;

ElementPtr_V::const_iterator eiter;
for (eiter = this->dataPtr->elements.begin();
eiter != this->dataPtr->elements.end(); ++eiter)
{
(*eiter)->SetExplicitlySetInFile(_value);
}
}

/////////////////////////////////////////////////
bool Element::GetExplicitlySetInFile() const
{
return this->dataPtr->explicitlySetInFile;
}

/////////////////////////////////////////////////
bool Element::GetCopyChildren() const
{
Expand Down Expand Up @@ -170,6 +190,7 @@ ElementPtr Element::Clone() const
clone->dataPtr->lineNumber = this->dataPtr->lineNumber;
clone->dataPtr->xmlPath = this->dataPtr->xmlPath;
clone->dataPtr->originalVersion = this->dataPtr->originalVersion;
clone->dataPtr->explicitlySetInFile = this->dataPtr->explicitlySetInFile;

Param_V::const_iterator aiter;
for (aiter = this->dataPtr->attributes.begin();
Expand Down Expand Up @@ -218,6 +239,7 @@ void Element::Copy(const ElementPtr _elem)
this->dataPtr->path = _elem->FilePath();
this->dataPtr->lineNumber = _elem->LineNumber();
this->dataPtr->xmlPath = _elem->XmlPath();
this->dataPtr->explicitlySetInFile = _elem->GetExplicitlySetInFile();

for (Param_V::iterator iter = _elem->dataPtr->attributes.begin();
iter != _elem->dataPtr->attributes.end(); ++iter)
Expand Down
94 changes: 94 additions & 0 deletions src/Element_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,98 @@ TEST(Element, Required)
ASSERT_EQ(elem.GetRequired(), "1");
}

/////////////////////////////////////////////////
TEST(Element, SetExplicitlySetInFile)
{
// The heirarchy in xml:
// <parent>
// <elem>
// <child>
// <child2>
// <grandChild/>
// <child2>
// </child>
// <sibling/>
// <sibling2/>
// </elem>
// <elem2/>
// </parent>

sdf::ElementPtr parent = std::make_shared<sdf::Element>();
sdf::ElementPtr elem = std::make_shared<sdf::Element>();
elem->SetParent(parent);
parent->InsertElement(elem);
sdf::ElementPtr elem2 = std::make_shared<sdf::Element>();
elem2->SetParent(parent);
parent->InsertElement(elem2);

EXPECT_TRUE(elem->GetExplicitlySetInFile());

elem->SetExplicitlySetInFile(false);

EXPECT_FALSE(elem->GetExplicitlySetInFile());

elem->SetExplicitlySetInFile(true);

EXPECT_TRUE(elem->GetExplicitlySetInFile());

// the childs and siblings of the element should all be
// set to the same value when using this function
sdf::ElementPtr child = std::make_shared<sdf::Element>();
child->SetParent(elem);
elem->InsertElement(child);

sdf::ElementPtr sibling = std::make_shared<sdf::Element>();
sibling->SetParent(elem);
elem->InsertElement(sibling);

sdf::ElementPtr sibling2 = std::make_shared<sdf::Element>();
sibling2->SetParent(elem);
elem->InsertElement(sibling2);

sdf::ElementPtr child2 = std::make_shared<sdf::Element>();
child2->SetParent(child);
child->InsertElement(child2);

sdf::ElementPtr grandChild = std::make_shared<sdf::Element>();
grandChild->SetParent(child);
child->InsertElement(grandChild);

EXPECT_TRUE(elem->GetExplicitlySetInFile());
EXPECT_TRUE(child->GetExplicitlySetInFile());
EXPECT_TRUE(sibling->GetExplicitlySetInFile());
EXPECT_TRUE(sibling2->GetExplicitlySetInFile());
EXPECT_TRUE(child2->GetExplicitlySetInFile());
EXPECT_TRUE(grandChild->GetExplicitlySetInFile());
EXPECT_TRUE(elem2->GetExplicitlySetInFile());

elem->SetExplicitlySetInFile(false);
EXPECT_FALSE(elem->GetExplicitlySetInFile());
EXPECT_FALSE(child->GetExplicitlySetInFile());
EXPECT_FALSE(sibling->GetExplicitlySetInFile());
EXPECT_FALSE(sibling2->GetExplicitlySetInFile());
EXPECT_FALSE(child2->GetExplicitlySetInFile());
EXPECT_FALSE(grandChild->GetExplicitlySetInFile());

// SetExplicitlySetInFile(false) is be called only on `elem`. We expect
// GetExplicitlySetInFile() to be false for all children and grandchildren of
// `elem`, but true for `elem2`, which is a sibling of `elem`.
EXPECT_TRUE(elem2->GetExplicitlySetInFile());
}

/////////////////////////////////////////////////
TEST(Element, SetExplicitlySetInFileWithInsert)
{
sdf::ElementPtr parent = std::make_shared<sdf::Element>();
parent->SetExplicitlySetInFile(false);
sdf::ElementPtr child = std::make_shared<sdf::Element>();
child->SetParent(parent);
parent->InsertElement(child);

EXPECT_FALSE(parent->GetExplicitlySetInFile());
EXPECT_TRUE(child->GetExplicitlySetInFile());
}

/////////////////////////////////////////////////
TEST(Element, CopyChildren)
{
Expand Down Expand Up @@ -345,6 +437,7 @@ TEST(Element, Clone)
ASSERT_EQ(newelem->GetAttributeCount(), 1UL);
ASSERT_NE(newelem->GetIncludeElement(), nullptr);
EXPECT_EQ("include", newelem->GetIncludeElement()->GetName());
ASSERT_TRUE(newelem->GetExplicitlySetInFile());
}

/////////////////////////////////////////////////
Expand Down Expand Up @@ -647,6 +740,7 @@ TEST(Element, Copy)
ASSERT_EQ(param->GetDescription(), "val description");

ASSERT_EQ(dest->GetAttributeCount(), 1UL);
ASSERT_TRUE(dest->GetExplicitlySetInFile());
param = dest->GetAttribute("test");
ASSERT_TRUE(param->IsType<std::string>());
ASSERT_EQ(param->GetKey(), "test");
Expand Down
23 changes: 23 additions & 0 deletions src/ParticleEmitter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ class sdf::ParticleEmitter::Implementation
/// \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 @@ -201,6 +209,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.emplace();
Expand Down Expand Up @@ -416,6 +427,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
3 changes: 2 additions & 1 deletion src/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1507,7 +1507,8 @@ bool readXml(tinyxml2::XMLElement *_xml, ElementPtr _sdf,
else
{
// Add default element
_sdf->AddElement(elemDesc->GetName());
ElementPtr defaultElement = _sdf->AddElement(elemDesc->GetName());
defaultElement->SetExplicitlySetInFile(false);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions test/integration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set(tests
cfm_damping_implicit_spring_damper.cc
collision_dom.cc
converter.cc
default_elements.cc
deprecated_specs.cc
disable_fixed_joint_reduction.cc
element_tracing.cc
Expand Down
Loading

0 comments on commit d811185

Please sign in to comment.