From 388d994704830c0de832688893c6020eb191d199 Mon Sep 17 00:00:00 2001 From: John Turner <7strbass@gmail.com> Date: Thu, 25 Apr 2024 12:56:00 -0400 Subject: [PATCH] --Add MarkerSets.h; Specialize interaction to be MarkerSets class --- src/esp/bindings/AttributesBindings.cpp | 19 ++++ src/esp/metadata/CMakeLists.txt | 1 + .../attributes/AbstractObjectAttributes.h | 9 +- .../attributes/ArticulatedObjectAttributes.h | 9 +- src/esp/metadata/attributes/MarkerSets.h | 99 ++++++++++++++++++- src/tests/AttributesConfigsTest.cpp | 4 +- 6 files changed, 127 insertions(+), 14 deletions(-) diff --git a/src/esp/bindings/AttributesBindings.cpp b/src/esp/bindings/AttributesBindings.cpp index 0e501abe26..d8ca44cc3f 100644 --- a/src/esp/bindings/AttributesBindings.cpp +++ b/src/esp/bindings/AttributesBindings.cpp @@ -11,6 +11,7 @@ #include "esp/metadata/attributes/ArticulatedObjectAttributes.h" #include "esp/metadata/attributes/AttributesBase.h" #include "esp/metadata/attributes/LightLayoutAttributes.h" +#include "esp/metadata/attributes/MarkerSets.h" #include "esp/metadata/attributes/ObjectAttributes.h" #include "esp/metadata/attributes/PbrShaderAttributes.h" #include "esp/metadata/attributes/PhysicsManagerAttributes.h" @@ -33,6 +34,10 @@ using Attrs::CylinderPrimitiveAttributes; using Attrs::IcospherePrimitiveAttributes; using Attrs::LightInstanceAttributes; using Attrs::LightLayoutAttributes; +using Attrs::LinkMarkerSets; +using Attrs::LinkMarkerSubset; +using Attrs::MarkerSet; +using Attrs::MarkerSets; using Attrs::ObjectAttributes; using Attrs::PbrShaderAttributes; using Attrs::PhysicsManagerAttributes; @@ -229,6 +234,20 @@ void initAttributesBindings(py::module& m) { .value("TREE_TRAVERSAL", metadata::attributes::ArticulatedObjectLinkOrder::TreeTraversal); + // ==== Markersets and subordinate classes === + + py::class_(m, "LinkMarkerSubset") + .def(py::init(&LinkMarkerSubset::create<>)); + + py::class_(m, "LinkMarkerSets") + .def(py::init(&LinkMarkerSets::create<>)); + + py::class_(m, "MarkerSet") + .def(py::init(&MarkerSet::create<>)); + + py::class_(m, "MarkerSets") + .def(py::init(&MarkerSets::create<>)); + // ==== ArticulatedObjectAttributes ==== py::class_( diff --git a/src/esp/metadata/CMakeLists.txt b/src/esp/metadata/CMakeLists.txt index b79813a6ef..37e09391ef 100644 --- a/src/esp/metadata/CMakeLists.txt +++ b/src/esp/metadata/CMakeLists.txt @@ -14,6 +14,7 @@ set( attributes/ArticulatedObjectAttributes.cpp attributes/LightLayoutAttributes.h attributes/LightLayoutAttributes.cpp + attributes/MarkerSets.h attributes/ObjectAttributes.h attributes/ObjectAttributes.cpp attributes/PhysicsManagerAttributes.h diff --git a/src/esp/metadata/attributes/AbstractObjectAttributes.h b/src/esp/metadata/attributes/AbstractObjectAttributes.h index 323855df28..e60083d2f2 100644 --- a/src/esp/metadata/attributes/AbstractObjectAttributes.h +++ b/src/esp/metadata/attributes/AbstractObjectAttributes.h @@ -6,6 +6,7 @@ #define ESP_METADATA_ATTRIBUTES_ABSTRACTOBJECTATTRIBUTES_H_ #include "AttributesBase.h" +#include "MarkerSets.h" namespace esp { namespace metadata { @@ -267,8 +268,8 @@ class AbstractObjectAttributes : public AbstractAttributes { * @brief Gets a smart pointer reference to a copy of the marker_sets * configuration data from config file. */ - std::shared_ptr getMarkerSetsConfiguration() const { - return getSubconfigCopy("marker_sets"); + std::shared_ptr getMarkerSetsConfiguration() const { + return getSubconfigCopy("marker_sets"); } /** @@ -276,8 +277,8 @@ class AbstractObjectAttributes : public AbstractAttributes { * configuration data from config file. This method is for editing the * configuration. */ - std::shared_ptr editMarkerSetsConfiguration() { - return editSubconfig("marker_sets"); + std::shared_ptr editMarkerSetsConfiguration() { + return editSubconfig("marker_sets"); } protected: diff --git a/src/esp/metadata/attributes/ArticulatedObjectAttributes.h b/src/esp/metadata/attributes/ArticulatedObjectAttributes.h index 5dfad75756..82c45e2157 100644 --- a/src/esp/metadata/attributes/ArticulatedObjectAttributes.h +++ b/src/esp/metadata/attributes/ArticulatedObjectAttributes.h @@ -6,6 +6,7 @@ #define ESP_METADATA_ATTRIBUTES_ARTICULATEDOBJECTATTRIBUTES_H_ #include "AttributesBase.h" +#include "MarkerSets.h" namespace esp { namespace metadata { @@ -254,8 +255,8 @@ class ArticulatedObjectAttributes : public AbstractAttributes { * @brief Gets a smart pointer reference to a copy of the marker_sets * configuration data from config file. */ - std::shared_ptr getMarkerSetsConfiguration() const { - return getSubconfigCopy("marker_sets"); + std::shared_ptr getMarkerSetsConfiguration() const { + return getSubconfigCopy("marker_sets"); } /** @@ -263,8 +264,8 @@ class ArticulatedObjectAttributes : public AbstractAttributes { * configuration data from config file. This method is for editing the * configuration. */ - std::shared_ptr editMarkerSetsConfiguration() { - return editSubconfig("marker_sets"); + std::shared_ptr editMarkerSetsConfiguration() { + return editSubconfig("marker_sets"); } protected: diff --git a/src/esp/metadata/attributes/MarkerSets.h b/src/esp/metadata/attributes/MarkerSets.h index 7d0f543acf..db680c4743 100644 --- a/src/esp/metadata/attributes/MarkerSets.h +++ b/src/esp/metadata/attributes/MarkerSets.h @@ -1,6 +1,7 @@ // Copyright (c) Meta Platforms, Inc. and its affiliates. // This source code is licensed under the MIT license found in the // LICENSE file in the root directory of this source tree. + #ifndef ESP_METADATA_ATTRIBUTES_MARKERSETS_H_ #define ESP_METADATA_ATTRIBUTES_MARKERSETS_H_ @@ -22,6 +23,71 @@ namespace attributes { class LinkMarkerSubset : public esp::core::config::Configuration { public: LinkMarkerSubset() : Configuration() {} + /** + * @brief Returns the number of existing markers in this LinkMarkerSubset. + */ + int getNumMarkers() const { + return getSubconfigView("markers")->getNumValues(); + } + + /** + * @brief whether the given @p markerName exists as a marker in + * this LinkMarkerSubset. + * + * @param markerName The desired marker set's name. + * @return whether the name is found as a marker value. + */ + bool hasNamedMarker(const std::string& markerName) const { + return getSubconfigView("markers")->hasValue(markerName); + } + + /** + * @brief Retrieve the marker point specified by the given @p markerName + */ + Mn::Vector3 getNamedMarker(const std::string& markerName) const { + return getSubconfigView("markers")->get(markerName); + } + + /** + * @brief Adds passed marker. Uses naming convention from load - key for this + * marker will be "markers_{numCurrentMarkers}" + */ + void addMarker(const Magnum::Vector3& marker) { + auto markersPtr = editSubconfig("markers"); + const std::string markerKey = Cr::Utility::formatString( + "markers_{:.02d}", markersPtr->getNumValues()); + markersPtr->set(markerKey, marker); + } + + /** + * @brief Retrieve a listing of all the marker handles in this + * LinkMarkerSubset. + */ + std::vector getAllMarkerNames() const { + return getSubconfigView("markers")->getKeys(); + } + + /** + * @brief Returns a list of all markers in this LinkMarkerSubset + */ + std::vector getAllMarkers() const { + const auto markersPtr = getSubconfigView("markers"); + std::vector markerTags = markersPtr->getKeys(); + std::vector res; + res.reserve(markerTags.size()); + for (const auto& tag : markerTags) { + res.emplace_back(std::move(markersPtr->get(tag))); + } + return res; + } + + /** + * @brief Remove a named marker. + */ + Mn::Vector3 removeMarker(const std::string& markerKey) { + return editSubconfig("markers")->remove( + markerKey); + } ESP_SMART_POINTERS(LinkMarkerSubset) }; // class LinkMarkerSubset @@ -81,12 +147,19 @@ class LinkMarkerSets : public esp::core::config::Configuration { return editSubconfig(linkSubsetName); } + /** + * @brief Removes named LinkMarkerSubset. Does nothing if DNE. + */ + void removeNamedMarkerSet(const std::string& linkSubsetName) { + removeSubconfig(linkSubsetName); + } + ESP_SMART_POINTERS(LinkMarkerSets) }; // class LinkMarkerSets /** * @brief This class provides an alias for the nested configuration tree used - * for a single markerset, covering 1 or more links + * for a single MarkerSet, covering 1 or more links */ class MarkerSet : public esp::core::config::Configuration { public: @@ -137,12 +210,19 @@ class MarkerSet : public esp::core::config::Configuration { return editSubconfig(linkSetName); } + /** + * @brief Removes named LinkMarkerSets. Does nothing if DNE. + */ + void removeNamedMarkerSet(const std::string& linkSetName) { + removeSubconfig(linkSetName); + } + ESP_SMART_POINTERS(MarkerSet) }; // class MarkerSet /** * @brief This class provides an alias for the nested configuration tree used - * for markersets. + * to hold multiple MarkerSets. */ class MarkerSets : public esp::core::config::Configuration { public: @@ -165,14 +245,14 @@ class MarkerSets : public esp::core::config::Configuration { } /** - * @brief Retrieve a listing of all the markerset handles in this collection. + * @brief Retrieve a listing of all the MarkerSet handles in this collection. */ std::vector getAllMarkerSetNames() const { return getSubconfigKeys(); } /** - * @brief Retrivess a copy of the named markerset, if it exists, and nullptr + * @brief Retrivess a copy of the named MarkerSet, if it exists, and nullptr * if it does not. */ MarkerSet::ptr getNamedMarkerSetCopy(const std::string& markerSetName) { @@ -191,6 +271,17 @@ class MarkerSets : public esp::core::config::Configuration { return editSubconfig(markerSetName); } + /** + * @brief Removes named MarkerSet. Does nothing if DNE. + */ + void removeNamedMarkerSet(const std::string& markerSetName) { + removeSubconfig(markerSetName); + } + + /** + * @brief Remove the specified MarkerSet + */ + ESP_SMART_POINTERS(MarkerSets) }; // class MarkerSets diff --git a/src/tests/AttributesConfigsTest.cpp b/src/tests/AttributesConfigsTest.cpp index 2e9b9f3961..1657fb7fb0 100644 --- a/src/tests/AttributesConfigsTest.cpp +++ b/src/tests/AttributesConfigsTest.cpp @@ -109,7 +109,7 @@ struct AttributesConfigsTest : Cr::TestSuite::Tester { * @param markerSetsHierarchy The hieraarchy the marker sets should follow. */ void testMarkerSetsConfigVals( - std::shared_ptr markerSetsConfig, + std::shared_ptr markerSetsConfig, const MarkerSetTestMap& // markers in link subset markerSetsHierarchy); @@ -307,7 +307,7 @@ void AttributesConfigsTest::testUserDefinedConfigVals( } // AttributesConfigsTest::testUserDefinedConfigVals void AttributesConfigsTest::testMarkerSetsConfigVals( - std::shared_ptr markerSetsConfig, + std::shared_ptr markerSetsConfig, const MarkerSetTestMap& // markers in link subset markerSetsHierarchy) { for (const auto& markerSetInfoEntry : markerSetsHierarchy) {