diff --git a/include/ignition/rendering/Node.hh b/include/ignition/rendering/Node.hh index 4f2999dfa..0fbe9d2c6 100644 --- a/include/ignition/rendering/Node.hh +++ b/include/ignition/rendering/Node.hh @@ -17,7 +17,10 @@ #ifndef IGNITION_RENDERING_NODE_HH_ #define IGNITION_RENDERING_NODE_HH_ +#include #include +#include + #include #include @@ -32,6 +35,9 @@ namespace ignition { inline namespace IGNITION_RENDERING_VERSION_NAMESPACE { // + using Variant = + std::variant; + /// \class Node Node.hh ignition/rendering/Node.hh /// \brief Represents a single posable node in the scene graph class IGNITION_RENDERING_VISIBLE Node : @@ -302,6 +308,17 @@ 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 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 + /// \return Value in any type + public: virtual Variant UserData(const std::string &_key) const = 0; }; } } diff --git a/include/ignition/rendering/Visual.hh b/include/ignition/rendering/Visual.hh index ea23be50f..c9ec0b635 100644 --- a/include/ignition/rendering/Visual.hh +++ b/include/ignition/rendering/Visual.hh @@ -17,7 +17,6 @@ #ifndef IGNITION_RENDERING_VISUAL_HH_ #define IGNITION_RENDERING_VISUAL_HH_ -#include #include #include #include "ignition/rendering/config.hh" @@ -28,9 +27,6 @@ namespace ignition namespace rendering { inline namespace IGNITION_RENDERING_VERSION_NAMESPACE { - // - using Variant = std::variant; - /// \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. @@ -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; diff --git a/include/ignition/rendering/base/BaseNode.hh b/include/ignition/rendering/base/BaseNode.hh index eb76ba456..84b37b33f 100644 --- a/include/ignition/rendering/base/BaseNode.hh +++ b/include/ignition/rendering/base/BaseNode.hh @@ -17,7 +17,9 @@ #ifndef IGNITION_RENDERING_BASE_BASENODE_HH_ #define IGNITION_RENDERING_BASE_BASENODE_HH_ +#include #include + #include "ignition/rendering/Node.hh" #include "ignition/rendering/Storage.hh" #include "ignition/rendering/base/BaseStorage.hh" @@ -168,6 +170,13 @@ namespace ignition public: virtual void PreRender() 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; + protected: virtual void PreRenderChildren(); protected: virtual math::Pose3d RawLocalPose() const = 0; @@ -186,6 +195,9 @@ namespace ignition const math::Vector3d &_scale) = 0; protected: math::Vector3d origin; + + /// \brief A map of custom key value data + protected: std::map userData; }; ////////////////////////////////////////////////// @@ -572,8 +584,6 @@ namespace ignition this->SetLocalScale(_scale * this->LocalScale()); } - - ////////////////////////////////////////////////// template void BaseNode::Destroy() @@ -631,6 +641,22 @@ namespace ignition return this->Children()->GetByIndex(_index); } } + + template + void BaseNode::SetUserData(const std::string &_key, Variant _value) + { + this->userData[_key] = _value; + } + + template + Variant BaseNode::UserData(const std::string &_key) const + { + Variant value; + auto it = this->userData.find(_key); + if (it != this->userData.end()) + value = it->second; + return value; + } } } #endif diff --git a/include/ignition/rendering/base/BaseVisual.hh b/include/ignition/rendering/base/BaseVisual.hh index 03c49ddfa..a7e53d488 100644 --- a/include/ignition/rendering/base/BaseVisual.hh +++ b/include/ignition/rendering/base/BaseVisual.hh @@ -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; @@ -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 userData; - /// \brief Visual's visibility flags protected: uint32_t visibilityFlags = IGN_VISIBILITY_ALL; @@ -481,24 +471,6 @@ namespace ignition { return this->visibilityFlags; } - - ////////////////////////////////////////////////// - template - void BaseVisual::SetUserData(const std::string &_key, Variant _value) - { - this->userData[_key] = _value; - } - - ////////////////////////////////////////////////// - template - Variant BaseVisual::UserData(const std::string &_key) const - { - Variant value; - auto it = this->userData.find(_key); - if (it != this->userData.end()) - value = it->second; - return value; - } } } }