Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aded ToElement conversion for shapes #772

Merged
merged 3 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/sdf/Box.hh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ namespace sdf
/// \return A reference to an ignition::math::Boxd object.
public: ignition::math::Boxd &Shape();

/// \brief Create and return an SDF element filled with data from this
/// box.
/// \return SDF element pointer with updated box values.
public: sdf::ElementPtr ToElement() const;

/// \brief Private data pointer.
IGN_UTILS_IMPL_PTR(dataPtr)
};
Expand Down
5 changes: 5 additions & 0 deletions include/sdf/Capsule.hh
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ namespace sdf
/// \return A reference to an ignition::math::Capsuled object.
public: ignition::math::Capsuled &Shape();

/// \brief Create and return an SDF element filled with data from this
/// capsule.
/// \return SDF element pointer with updated capsule values.
public: sdf::ElementPtr ToElement() const;

/// \brief Private data pointer.
IGN_UTILS_IMPL_PTR(dataPtr)
};
Expand Down
5 changes: 5 additions & 0 deletions include/sdf/Cylinder.hh
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ namespace sdf
/// \return A reference to an ignition::math::Cylinderd object.
public: ignition::math::Cylinderd &Shape();

/// \brief Create and return an SDF element filled with data from this
/// cylinder.
/// \return SDF element pointer with updated cylinder values.
public: sdf::ElementPtr ToElement() const;

/// \brief Private data pointer.
IGN_UTILS_IMPL_PTR(dataPtr)
};
Expand Down
5 changes: 5 additions & 0 deletions include/sdf/Ellipsoid.hh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ namespace sdf
/// \return A reference to an ignition::math::Ellipsoidd object.
public: ignition::math::Ellipsoidd &Shape();

/// \brief Create and return an SDF element filled with data from this
/// ellipsoid.
/// \return SDF element pointer with updated ellipsoid values.
public: sdf::ElementPtr ToElement() const;

/// \brief Private data pointer.
IGN_UTILS_IMPL_PTR(dataPtr)
};
Expand Down
9 changes: 7 additions & 2 deletions include/sdf/Heightmap.hh
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ namespace sdf
public: double Size() const;

/// \brief Set the size of the texture in meters.
/// \param[in] _uri The size of the texture in meters.
public: void SetSize(double _uri);
/// \param[in] _size The size of the texture in meters.
public: void SetSize(double _size);

/// \brief Get the heightmap texture's diffuse map.
/// \return The diffuse map of the heightmap texture.
Expand Down Expand Up @@ -214,6 +214,11 @@ namespace sdf
/// not been called.
public: sdf::ElementPtr Element() const;

/// \brief Create and return an SDF element filled with data from this
/// heightmap.
/// \return SDF element pointer with updated heightmap values.
public: sdf::ElementPtr ToElement() const;

/// \brief Private data pointer.
IGN_UTILS_IMPL_PTR(dataPtr)
};
Expand Down
5 changes: 5 additions & 0 deletions include/sdf/Mesh.hh
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ namespace sdf
/// not been called.
public: sdf::ElementPtr Element() const;

/// \brief Create and return an SDF element filled with data from this
/// mesh.
/// \return SDF element pointer with updated mesh values.
public: sdf::ElementPtr ToElement() const;

/// \brief Private data pointer.
IGN_UTILS_IMPL_PTR(dataPtr)
};
Expand Down
5 changes: 5 additions & 0 deletions include/sdf/Plane.hh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ namespace sdf
/// \return A reference to an ignition::math::Planed object.
public: ignition::math::Planed &Shape();

/// \brief Create and return an SDF element filled with data from this
/// plane.
/// \return SDF element pointer with updated plane values.
public: sdf::ElementPtr ToElement() const;

/// \brief Private data pointer.
IGN_UTILS_IMPL_PTR(dataPtr)
};
Expand Down
5 changes: 5 additions & 0 deletions include/sdf/Sphere.hh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ namespace sdf
/// not been called.
public: sdf::ElementPtr Element() const;

/// \brief Create and return an SDF element filled with data from this
/// sphere.
/// \return SDF element pointer with updated sphere values.
public: sdf::ElementPtr ToElement() const;

/// \brief Private data pointer.
IGN_UTILS_IMPL_PTR(dataPtr)
};
Expand Down
13 changes: 13 additions & 0 deletions src/Box.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
#include <ignition/math/Vector3.hh>
#include "sdf/Box.hh"
#include "sdf/parser.hh"

using namespace sdf;

Expand Down Expand Up @@ -112,3 +113,15 @@ ignition::math::Boxd &Box::Shape()
{
return this->dataPtr->box;
}

/////////////////////////////////////////////////
sdf::ElementPtr Box::ToElement() const
{
sdf::ElementPtr elem(new sdf::Element);
sdf::initFile("box_shape.sdf", elem);

sdf::ElementPtr sizeElem = elem->GetElement("size");
sizeElem->Set(this->Size());

return elem;
}
16 changes: 16 additions & 0 deletions src/Box_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,19 @@ TEST(DOMBox, Shape)
box.Shape().SetSize(ignition::math::Vector3d(1, 2, 3));
EXPECT_EQ(ignition::math::Vector3d(1, 2, 3), box.Size());
}

/////////////////////////////////////////////////
TEST(DOMBox, ToElement)
{
sdf::Box box;

box.SetSize(ignition::math::Vector3d(1, 2, 3));

sdf::ElementPtr elem = box.ToElement();
ASSERT_NE(nullptr, elem);

sdf::Box box2;
box2.Load(elem);

EXPECT_EQ(box.Size(), box2.Size());
}
16 changes: 16 additions & 0 deletions src/Capsule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
#include <sstream>
#include "sdf/Capsule.hh"
#include "sdf/parser.hh"

using namespace sdf;

Expand Down Expand Up @@ -134,3 +135,18 @@ ignition::math::Capsuled &Capsule::Shape()
{
return this->dataPtr->capsule;
}

/////////////////////////////////////////////////
sdf::ElementPtr Capsule::ToElement() const
{
sdf::ElementPtr elem(new sdf::Element);
sdf::initFile("capsule_shape.sdf", elem);

sdf::ElementPtr radiusElem = elem->GetElement("radius");
radiusElem->Set(this->Radius());

sdf::ElementPtr lengthElem = elem->GetElement("length");
lengthElem->Set(this->Length());

return elem;
}
18 changes: 18 additions & 0 deletions src/Capsule_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,21 @@ TEST(DOMCapsule, Shape)
EXPECT_DOUBLE_EQ(0.123, capsule.Radius());
EXPECT_DOUBLE_EQ(0.456, capsule.Length());
}

/////////////////////////////////////////////////
TEST(DOMCapsule, ToElement)
{
sdf::Capsule capsule;

capsule.SetRadius(1.2);
capsule.SetLength(0.5);

sdf::ElementPtr elem = capsule.ToElement();
ASSERT_NE(nullptr, elem);

sdf::Capsule capsule2;
capsule2.Load(elem);

EXPECT_DOUBLE_EQ(capsule.Radius(), capsule2.Radius());
EXPECT_DOUBLE_EQ(capsule.Length(), capsule2.Length());
}
16 changes: 16 additions & 0 deletions src/Cylinder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
#include <sstream>
#include "sdf/Cylinder.hh"
#include "sdf/parser.hh"

using namespace sdf;

Expand Down Expand Up @@ -134,3 +135,18 @@ ignition::math::Cylinderd &Cylinder::Shape()
{
return this->dataPtr->cylinder;
}

/////////////////////////////////////////////////
sdf::ElementPtr Cylinder::ToElement() const
{
sdf::ElementPtr elem(new sdf::Element);
sdf::initFile("cylinder_shape.sdf", elem);

sdf::ElementPtr radiusElem = elem->GetElement("radius");
radiusElem->Set<double>(this->Radius());

sdf::ElementPtr lengthElem = elem->GetElement("length");
lengthElem->Set<double>(this->Length());

return elem;
}
18 changes: 18 additions & 0 deletions src/Cylinder_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,21 @@ TEST(DOMCylinder, Shape)
EXPECT_DOUBLE_EQ(0.123, cylinder.Radius());
EXPECT_DOUBLE_EQ(0.456, cylinder.Length());
}

/////////////////////////////////////////////////
TEST(DOMCylinder, ToElement)
{
sdf::Cylinder cylinder;

cylinder.SetRadius(1.2);
cylinder.SetLength(0.5);

sdf::ElementPtr elem = cylinder.ToElement();
ASSERT_NE(nullptr, elem);

sdf::Cylinder cylinder2;
cylinder2.Load(elem);

EXPECT_DOUBLE_EQ(cylinder.Radius(), cylinder2.Radius());
EXPECT_DOUBLE_EQ(cylinder.Length(), cylinder2.Length());
}
13 changes: 13 additions & 0 deletions src/Ellipsoid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
#include <sstream>
#include "sdf/Ellipsoid.hh"
#include "sdf/parser.hh"

using namespace sdf;

Expand Down Expand Up @@ -113,3 +114,15 @@ ignition::math::Ellipsoidd &Ellipsoid::Shape()
{
return this->dataPtr->ellipsoid;
}

/////////////////////////////////////////////////
sdf::ElementPtr Ellipsoid::ToElement() const
{
sdf::ElementPtr elem(new sdf::Element);
sdf::initFile("ellipsoid_shape.sdf", elem);

sdf::ElementPtr radiiElem = elem->GetElement("radii");
radiiElem->Set(this->Radii());

return elem;
}
16 changes: 16 additions & 0 deletions src/Ellipsoid_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,19 @@ TEST(DOMEllipsoid, Shape)
ellipsoid.Shape().SetRadii(expectedRadii);
EXPECT_EQ(expectedRadii, ellipsoid.Radii());
}

/////////////////////////////////////////////////
TEST(DOMEllipsoid, ToElement)
{
sdf::Ellipsoid ellipsoid;

ellipsoid.SetRadii(ignition::math::Vector3d(0.1, 1.2, 3.4));

sdf::ElementPtr elem = ellipsoid.ToElement();
ASSERT_NE(nullptr, elem);

sdf::Ellipsoid ellipsoid2;
ellipsoid2.Load(elem);

EXPECT_EQ(ellipsoid.Radii(), ellipsoid2.Radii());
}
47 changes: 47 additions & 0 deletions src/Heightmap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "Utils.hh"
#include "sdf/Heightmap.hh"
#include "sdf/parser.hh"

using namespace sdf;

Expand Down Expand Up @@ -459,3 +460,49 @@ void Heightmap::AddBlend(const HeightmapBlend &_blend)
{
this->dataPtr->blends.push_back(_blend);
}

/////////////////////////////////////////////////
sdf::ElementPtr Heightmap::ToElement() const
{
sdf::ElementPtr elem(new sdf::Element);
sdf::initFile("heightmap_shape.sdf", elem);

// Uri
sdf::ElementPtr uriElem = elem->GetElement("uri");
uriElem->Set(this->Uri());

// Size
sdf::ElementPtr sizeElem = elem->GetElement("size");
sizeElem->Set(this->Size());

// Position
sdf::ElementPtr posElem = elem->GetElement("pos");
posElem->Set(this->Position());

// Terrain paging
sdf::ElementPtr pagingElem = elem->GetElement("use_terrain_paging");
pagingElem->Set(this->UseTerrainPaging());

// Sampling
sdf::ElementPtr samplingElem = elem->GetElement("sampling");
samplingElem->Set(this->Sampling());

// Textures
for (const HeightmapTexture &tex : this->dataPtr->textures)
{
sdf::ElementPtr texElem = elem->AddElement("texture");
texElem->GetElement("size")->Set(tex.Size());
texElem->GetElement("diffuse")->Set(tex.Diffuse());
texElem->GetElement("normal")->Set(tex.Normal());
}

// Blends
for (const HeightmapBlend &blend : this->dataPtr->blends)
{
sdf::ElementPtr blendElem = elem->AddElement("blend");
blendElem->GetElement("min_height")->Set(blend.MinHeight());
blendElem->GetElement("fade_dist")->Set(blend.FadeDistance());
}

return elem;
}
Loading