Skip to content

Commit

Permalink
--Add MarkerSets.h; Specialize interaction to be MarkerSets class
Browse files Browse the repository at this point in the history
  • Loading branch information
jturner65 committed Apr 25, 2024
1 parent 7fcdbf9 commit 388d994
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 14 deletions.
19 changes: 19 additions & 0 deletions src/esp/bindings/AttributesBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand Down Expand Up @@ -229,6 +234,20 @@ void initAttributesBindings(py::module& m) {
.value("TREE_TRAVERSAL",
metadata::attributes::ArticulatedObjectLinkOrder::TreeTraversal);

// ==== Markersets and subordinate classes ===

py::class_<LinkMarkerSubset, LinkMarkerSubset::ptr>(m, "LinkMarkerSubset")
.def(py::init(&LinkMarkerSubset::create<>));

py::class_<LinkMarkerSets, LinkMarkerSets::ptr>(m, "LinkMarkerSets")
.def(py::init(&LinkMarkerSets::create<>));

py::class_<MarkerSet, MarkerSet::ptr>(m, "MarkerSet")
.def(py::init(&MarkerSet::create<>));

py::class_<MarkerSets, MarkerSets::ptr>(m, "MarkerSets")
.def(py::init(&MarkerSets::create<>));

// ==== ArticulatedObjectAttributes ====
py::class_<ArticulatedObjectAttributes, AbstractAttributes,
ArticulatedObjectAttributes::ptr>(
Expand Down
1 change: 1 addition & 0 deletions src/esp/metadata/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions src/esp/metadata/attributes/AbstractObjectAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define ESP_METADATA_ATTRIBUTES_ABSTRACTOBJECTATTRIBUTES_H_

#include "AttributesBase.h"
#include "MarkerSets.h"

namespace esp {
namespace metadata {
Expand Down Expand Up @@ -267,17 +268,17 @@ 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<Configuration> getMarkerSetsConfiguration() const {
return getSubconfigCopy<Configuration>("marker_sets");
std::shared_ptr<MarkerSets> getMarkerSetsConfiguration() const {
return getSubconfigCopy<MarkerSets>("marker_sets");
}

/**
* @brief Gets a smart pointer reference to the actual marker_sets
* configuration data from config file. This method is for editing the
* configuration.
*/
std::shared_ptr<Configuration> editMarkerSetsConfiguration() {
return editSubconfig<Configuration>("marker_sets");
std::shared_ptr<MarkerSets> editMarkerSetsConfiguration() {
return editSubconfig<MarkerSets>("marker_sets");
}

protected:
Expand Down
9 changes: 5 additions & 4 deletions src/esp/metadata/attributes/ArticulatedObjectAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define ESP_METADATA_ATTRIBUTES_ARTICULATEDOBJECTATTRIBUTES_H_

#include "AttributesBase.h"
#include "MarkerSets.h"

namespace esp {
namespace metadata {
Expand Down Expand Up @@ -254,17 +255,17 @@ 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<Configuration> getMarkerSetsConfiguration() const {
return getSubconfigCopy<Configuration>("marker_sets");
std::shared_ptr<MarkerSets> getMarkerSetsConfiguration() const {
return getSubconfigCopy<MarkerSets>("marker_sets");
}

/**
* @brief Gets a smart pointer reference to the actual marker_sets
* configuration data from config file. This method is for editing the
* configuration.
*/
std::shared_ptr<Configuration> editMarkerSetsConfiguration() {
return editSubconfig<Configuration>("marker_sets");
std::shared_ptr<MarkerSets> editMarkerSetsConfiguration() {
return editSubconfig<MarkerSets>("marker_sets");
}

protected:
Expand Down
99 changes: 95 additions & 4 deletions src/esp/metadata/attributes/MarkerSets.h
Original file line number Diff line number Diff line change
@@ -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_

Expand All @@ -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<Mn::Vector3>(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<Configuration>("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<std::string> getAllMarkerNames() const {
return getSubconfigView("markers")->getKeys();
}

/**
* @brief Returns a list of all markers in this LinkMarkerSubset
*/
std::vector<Mn::Vector3> getAllMarkers() const {
const auto markersPtr = getSubconfigView("markers");
std::vector<std::string> markerTags = markersPtr->getKeys();
std::vector<Mn::Vector3> res;
res.reserve(markerTags.size());
for (const auto& tag : markerTags) {
res.emplace_back(std::move(markersPtr->get<Mn::Vector3>(tag)));
}
return res;
}

/**
* @brief Remove a named marker.
*/
Mn::Vector3 removeMarker(const std::string& markerKey) {
return editSubconfig<Configuration>("markers")->remove<Mn::Vector3>(
markerKey);
}

ESP_SMART_POINTERS(LinkMarkerSubset)
}; // class LinkMarkerSubset
Expand Down Expand Up @@ -81,12 +147,19 @@ class LinkMarkerSets : public esp::core::config::Configuration {
return editSubconfig<LinkMarkerSubset>(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:
Expand Down Expand Up @@ -137,12 +210,19 @@ class MarkerSet : public esp::core::config::Configuration {
return editSubconfig<LinkMarkerSets>(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:
Expand All @@ -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<std::string> 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) {
Expand All @@ -191,6 +271,17 @@ class MarkerSets : public esp::core::config::Configuration {
return editSubconfig<MarkerSet>(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

Expand Down
4 changes: 2 additions & 2 deletions src/tests/AttributesConfigsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ struct AttributesConfigsTest : Cr::TestSuite::Tester {
* @param markerSetsHierarchy The hieraarchy the marker sets should follow.
*/
void testMarkerSetsConfigVals(
std::shared_ptr<esp::core::config::Configuration> markerSetsConfig,
std::shared_ptr<esp::metadata::attributes::MarkerSets> markerSetsConfig,
const MarkerSetTestMap& // markers in link subset
markerSetsHierarchy);

Expand Down Expand Up @@ -307,7 +307,7 @@ void AttributesConfigsTest::testUserDefinedConfigVals(
} // AttributesConfigsTest::testUserDefinedConfigVals

void AttributesConfigsTest::testMarkerSetsConfigVals(
std::shared_ptr<esp::core::config::Configuration> markerSetsConfig,
std::shared_ptr<esp::metadata::attributes::MarkerSets> markerSetsConfig,
const MarkerSetTestMap& // markers in link subset
markerSetsHierarchy) {
for (const auto& markerSetInfoEntry : markerSetsHierarchy) {
Expand Down

0 comments on commit 388d994

Please sign in to comment.