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

UserData methods moved from Visual to Node #358

Merged
merged 6 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
29 changes: 29 additions & 0 deletions include/ignition/rendering/Node.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
#ifndef IGNITION_RENDERING_NODE_HH_
#define IGNITION_RENDERING_NODE_HH_

#include <map>
#include <string>
#include <variant>

#include <ignition/math/Pose3.hh>
#include <ignition/math/Quaternion.hh>

Expand All @@ -32,6 +35,9 @@ namespace ignition
{
inline namespace IGNITION_RENDERING_VERSION_NAMESPACE {
//
using Variant =
std::variant<int, float, double, std::string, bool, unsigned int>;

/// \class Node Node.hh ignition/rendering/Node.hh
/// \brief Represents a single posable node in the scene graph
class IGNITION_RENDERING_VISIBLE Node :
Expand Down Expand Up @@ -302,6 +308,29 @@ namespace ignition
/// \brief Remove all child nodes from this node
/// This detaches all the child nodes but does not destroy them
public: virtual void RemoveChildren() = 0;

/// \brief A map of custom key value data
protected: std::map<std::string, Variant> userData;
ahcorde marked this conversation as resolved.
Show resolved Hide resolved

/// \brief Store any custom data associated with this visual
/// \param[in] _key Unique key
/// \param[in] _value Value in any type
public: virtual void SetUserData(const std::string &_key, Variant _value)
{
this->userData[_key] = _value;
}

/// \brief Get custom data stored in this visual
/// \param[in] _key Unique key
/// \param[in] _value Value in any type
ahcorde marked this conversation as resolved.
Show resolved Hide resolved
public: virtual Variant UserData(const std::string &_key) const
{
Variant value;
auto it = this->userData.find(_key);
if (it != this->userData.end())
value = it->second;
return value;
}
};
}
}
Expand Down
15 changes: 0 additions & 15 deletions include/ignition/rendering/Visual.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#ifndef IGNITION_RENDERING_VISUAL_HH_
#define IGNITION_RENDERING_VISUAL_HH_

#include <variant>
#include <string>
#include <ignition/math/AxisAlignedBox.hh>
#include "ignition/rendering/config.hh"
Expand All @@ -28,9 +27,6 @@ namespace ignition
namespace rendering
{
inline namespace IGNITION_RENDERING_VERSION_NAMESPACE {
//
using Variant = std::variant<int, float, double, std::string>;

/// \class Visual Visual.hh ignition/rendering/Visual.hh
/// \brief Represents a visual node in a scene graph. A Visual is the only
/// node that can have Geometry and other Visual children.
Expand Down Expand Up @@ -138,17 +134,6 @@ namespace ignition
/// \param[in] _visibility flags
public: virtual void RemoveVisibilityFlags(uint32_t _flags) = 0;

/// \brief Store any custom data associated with this visual
/// \param[in] _key Unique key
/// \param[in] _value Value in any type
public: virtual void SetUserData(const std::string &_key,
Variant _value) = 0;

/// \brief Get custom data stored in this visual
/// \param[in] _key Unique key
/// \param[in] _value Value in any type
public: virtual Variant UserData(const std::string &_key) const = 0;

/// \brief Get the bounding box in world frame coordinates.
/// \return The axis aligned bounding box
public: virtual ignition::math::AxisAlignedBox BoundingBox() const = 0;
Expand Down
28 changes: 0 additions & 28 deletions include/ignition/rendering/base/BaseVisual.hh
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,6 @@ namespace ignition
// Documentation inherited
public: virtual void Destroy() override;

// Documentation inherited.
public: virtual void SetUserData(const std::string &_key,
Variant _value) override;

// Documentation inherited.
public: virtual Variant UserData(const std::string &_key) const override;

// Documentation inherited.
public: virtual ignition::math::AxisAlignedBox BoundingBox()
const override;
Expand All @@ -134,9 +127,6 @@ namespace ignition
/// \brief Pointer to material assigned to this visual
protected: MaterialPtr material;

/// \brief A map of custom key value data
protected: std::map<std::string, Variant> userData;

/// \brief Visual's visibility flags
protected: uint32_t visibilityFlags = IGN_VISIBILITY_ALL;

Expand Down Expand Up @@ -481,24 +471,6 @@ namespace ignition
{
return this->visibilityFlags;
}

//////////////////////////////////////////////////
template <class T>
void BaseVisual<T>::SetUserData(const std::string &_key, Variant _value)
{
this->userData[_key] = _value;
}

//////////////////////////////////////////////////
template <class T>
Variant BaseVisual<T>::UserData(const std::string &_key) const
{
Variant value;
auto it = this->userData.find(_key);
if (it != this->userData.end())
value = it->second;
return value;
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/base/BaseScene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,7 @@ CameraPtr BaseScene::CreateCamera(const std::string &_name)
CameraPtr BaseScene::CreateCamera(unsigned int _id, const std::string &_name)
{
CameraPtr camera = this->CreateCameraImpl(_id, _name);
camera->SetUserData("user-camera", false);
ahcorde marked this conversation as resolved.
Show resolved Hide resolved
bool result = this->RegisterSensor(camera);
return (result) ? camera : nullptr;
}
Expand Down