Skip to content

Commit

Permalink
--modify wrapper access to be just through sorted list of marker points.
Browse files Browse the repository at this point in the history
  • Loading branch information
jturner65 committed Apr 25, 2024
1 parent 388d994 commit 582c403
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 97 deletions.
4 changes: 3 additions & 1 deletion src/esp/bindings/AttributesBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ void initAttributesBindings(py::module& m) {
.def(py::init(&MarkerSet::create<>));

py::class_<MarkerSets, MarkerSets::ptr>(m, "MarkerSets")
.def(py::init(&MarkerSets::create<>));
.def(py::init(&MarkerSets::create<>))
.def_property_readonly("num_marker_sets", &MarkerSets::getNumMarkerSets,
R"(The current number of Markersets present.)");

// ==== ArticulatedObjectAttributes ====
py::class_<ArticulatedObjectAttributes, AbstractAttributes,
Expand Down
4 changes: 2 additions & 2 deletions src/esp/core/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ int Configuration::loadOneConfigFromJson(int numConfigSettings,

for (size_t i = 0; i < jsonObj.Size(); ++i) {
const std::string subKey =
Cr::Utility::formatString("{}_{:.02d}", key, i);
Cr::Utility::formatString("{}_{:.03d}", key, i);
numConfigSettings += subGroupPtr->loadOneConfigFromJson(
numConfigSettings, subKey, jsonObj[i]);
}
Expand All @@ -453,7 +453,7 @@ int Configuration::loadOneConfigFromJson(int numConfigSettings,

for (size_t i = 0; i < jsonObj.Size(); ++i) {
const std::string subKey =
Cr::Utility::formatString("{}_{:.02d}", key, i);
Cr::Utility::formatString("{}_{:.03d}", key, i);
numConfigSettings += subGroupPtr->loadOneConfigFromJson(
numConfigSettings, subKey, jsonObj[i]);
}
Expand Down
52 changes: 10 additions & 42 deletions src/esp/metadata/attributes/MarkerSets.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,49 +30,14 @@ class LinkMarkerSubset : public esp::core::config::Configuration {
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 {
std::vector<Mn::Vector3> getMarkers() const {
const auto markersPtr = getSubconfigView("markers");
std::vector<std::string> markerTags = markersPtr->getKeys();
// Sort the keys
std::sort(markerTags.begin(), markerTags.end());
std::vector<Mn::Vector3> res;
res.reserve(markerTags.size());
for (const auto& tag : markerTags) {
Expand All @@ -82,11 +47,14 @@ class LinkMarkerSubset : public esp::core::config::Configuration {
}

/**
* @brief Remove a named marker.
* @brief Set the list of marker points
*/
Mn::Vector3 removeMarker(const std::string& markerKey) {
return editSubconfig<Configuration>("markers")->remove<Mn::Vector3>(
markerKey);
void setMarkers(const std::vector<Mn::Vector3>& markers) {
auto markersPtr = editSubconfig<Configuration>("markers");
for (std::size_t i = 0; i < markers.size(); ++i) {
const std::string key = Cr::Utility::formatString("{:.03d}", i);
markersPtr->set(key, markers[i]);
}
}

ESP_SMART_POINTERS(LinkMarkerSubset)
Expand Down
104 changes: 52 additions & 52 deletions src/tests/AttributesConfigsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1350,10 +1350,10 @@ void AttributesConfigsTest::testStageAttrVals(
// Test marker sets

MarkersTestMap subset_id_000_stage_name(
{{"markers_03", Mn::Vector3{4.1, 5.2, 6.3}},
{"markers_02", Mn::Vector3{3.1, 4.2, 5.3}},
{"markers_01", Mn::Vector3{2.1, 3.2, 4.3}},
{"markers_00", Mn::Vector3{1.1, 2.2, 3.3}}});
{{"markers_003", Mn::Vector3{4.1, 5.2, 6.3}},
{"markers_002", Mn::Vector3{3.1, 4.2, 5.3}},
{"markers_001", Mn::Vector3{2.1, 3.2, 4.3}},
{"markers_000", Mn::Vector3{1.1, 2.2, 3.3}}});

MarkersTestMap subset_id_001_stage_name(
{{"3", Mn::Vector3{4.2, 5.3, 6.4}},
Expand All @@ -1369,10 +1369,10 @@ void AttributesConfigsTest::testStageAttrVals(
{{"link_id_00_stage_name", link_id_00_stage_name}}};

MarkersTestMap subset_id_100_stage_name(
{{"markers_03", Mn::Vector3{14.1, 15.2, 16.3}},
{"markers_02", Mn::Vector3{13.1, 14.2, 15.3}},
{"markers_01", Mn::Vector3{12.1, 13.2, 14.3}},
{"markers_00", Mn::Vector3{11.1, 12.2, 13.3}}});
{{"markers_003", Mn::Vector3{14.1, 15.2, 16.3}},
{"markers_002", Mn::Vector3{13.1, 14.2, 15.3}},
{"markers_001", Mn::Vector3{12.1, 13.2, 14.3}},
{"markers_000", Mn::Vector3{11.1, 12.2, 13.3}}});

MarkersTestMap subset_id_101_stage_name(
{{"3", Mn::Vector3{14.2, 15.3, 16.4}},
Expand All @@ -1398,10 +1398,10 @@ void AttributesConfigsTest::testStageAttrVals(
{"0", Mn::Vector3{11.3, 12.4, 13.5}}});

MarkersTestMap subset_id_111_stage_name(
{{"markers_03", Mn::Vector3{14.4, 15.5, 16.6}},
{"markers_02", Mn::Vector3{13.4, 14.5, 15.6}},
{"markers_01", Mn::Vector3{12.4, 13.5, 14.6}},
{"markers_00", Mn::Vector3{11.4, 12.5, 13.6}}});
{{"markers_003", Mn::Vector3{14.4, 15.5, 16.6}},
{"markers_002", Mn::Vector3{13.4, 14.5, 15.6}},
{"markers_001", Mn::Vector3{12.4, 13.5, 14.6}},
{"markers_000", Mn::Vector3{11.4, 12.5, 13.6}}});

SubsetTestMap link_id_11_stage_name(
{{"subset_id_110_stage_name", subset_id_110_stage_name},
Expand Down Expand Up @@ -1620,10 +1620,10 @@ void AttributesConfigsTest::testObjectAttrVals(
// Test marker sets

MarkersTestMap subset_id_000_obj_name(
{{"markers_03", Mn::Vector3{4.1, 5.2, 6.3}},
{"markers_02", Mn::Vector3{3.1, 4.2, 5.3}},
{"markers_01", Mn::Vector3{2.1, 3.2, 4.3}},
{"markers_00", Mn::Vector3{1.1, 2.2, 3.3}}});
{{"markers_003", Mn::Vector3{4.1, 5.2, 6.3}},
{"markers_002", Mn::Vector3{3.1, 4.2, 5.3}},
{"markers_001", Mn::Vector3{2.1, 3.2, 4.3}},
{"markers_000", Mn::Vector3{1.1, 2.2, 3.3}}});

MarkersTestMap subset_id_001_obj_name({{"3", Mn::Vector3{4.2, 5.3, 6.4}},
{"2", Mn::Vector3{3.2, 4.3, 5.4}},
Expand All @@ -1640,10 +1640,10 @@ void AttributesConfigsTest::testObjectAttrVals(
{"0", Mn::Vector3{1.3, 2.4, 3.5}}});

MarkersTestMap subset_id_011_obj_name(
{{"markers_03", Mn::Vector3{4.4, 5.5, 6.6}},
{"markers_02", Mn::Vector3{3.4, 4.5, 5.6}},
{"markers_01", Mn::Vector3{2.4, 3.5, 4.6}},
{"markers_00", Mn::Vector3{1.4, 2.5, 3.6}}});
{{"markers_003", Mn::Vector3{4.4, 5.5, 6.6}},
{"markers_002", Mn::Vector3{3.4, 4.5, 5.6}},
{"markers_001", Mn::Vector3{2.4, 3.5, 4.6}},
{"markers_000", Mn::Vector3{1.4, 2.5, 3.6}}});

SubsetTestMap link_id_01_obj_name(
{{"subset_id_010_obj_name", subset_id_010_obj_name},
Expand All @@ -1654,10 +1654,10 @@ void AttributesConfigsTest::testObjectAttrVals(
{"link_id_01_obj_name", link_id_01_obj_name}}};

MarkersTestMap subset_id_100_obj_name(
{{"markers_03", Mn::Vector3{14.1, 15.2, 16.3}},
{"markers_02", Mn::Vector3{13.1, 14.2, 15.3}},
{"markers_01", Mn::Vector3{12.1, 13.2, 14.3}},
{"markers_00", Mn::Vector3{11.1, 12.2, 13.3}}});
{{"markers_003", Mn::Vector3{14.1, 15.2, 16.3}},
{"markers_002", Mn::Vector3{13.1, 14.2, 15.3}},
{"markers_001", Mn::Vector3{12.1, 13.2, 14.3}},
{"markers_000", Mn::Vector3{11.1, 12.2, 13.3}}});

MarkersTestMap subset_id_101_obj_name(
{{"3", Mn::Vector3{14.2, 15.3, 16.4}},
Expand All @@ -1676,10 +1676,10 @@ void AttributesConfigsTest::testObjectAttrVals(
{"0", Mn::Vector3{11.3, 12.4, 13.5}}});

MarkersTestMap subset_id_111_obj_name(
{{"markers_03", Mn::Vector3{14.4, 15.5, 16.6}},
{"markers_02", Mn::Vector3{13.4, 14.5, 15.6}},
{"markers_01", Mn::Vector3{12.4, 13.5, 14.6}},
{"markers_00", Mn::Vector3{11.4, 12.5, 13.6}}});
{{"markers_003", Mn::Vector3{14.4, 15.5, 16.6}},
{"markers_002", Mn::Vector3{13.4, 14.5, 15.6}},
{"markers_001", Mn::Vector3{12.4, 13.5, 14.6}},
{"markers_000", Mn::Vector3{11.4, 12.5, 13.6}}});

SubsetTestMap link_id_11_obj_name(
{{"subset_id_110_obj_name", subset_id_110_obj_name},
Expand Down Expand Up @@ -1906,10 +1906,10 @@ void AttributesConfigsTest::testArticulatedObjectAttrVals(
// Test marker sets

MarkersTestMap subset_id_000_ao_name(
{{"markers_03", Mn::Vector3{14.1, 5.2, 6.3}},
{"markers_02", Mn::Vector3{13.1, 4.2, 5.3}},
{"markers_01", Mn::Vector3{12.1, 3.2, 4.3}},
{"markers_00", Mn::Vector3{11.1, 2.2, 3.3}}});
{{"markers_003", Mn::Vector3{14.1, 5.2, 6.3}},
{"markers_002", Mn::Vector3{13.1, 4.2, 5.3}},
{"markers_001", Mn::Vector3{12.1, 3.2, 4.3}},
{"markers_000", Mn::Vector3{11.1, 2.2, 3.3}}});

MarkersTestMap subset_id_001_ao_name({{"3", Mn::Vector3{14.2, 5.3, 6.4}},
{"2", Mn::Vector3{13.2, 4.3, 5.4}},
Expand All @@ -1926,10 +1926,10 @@ void AttributesConfigsTest::testArticulatedObjectAttrVals(
{"0", Mn::Vector3{11.3, 2.4, 3.5}}});

MarkersTestMap subset_id_011_ao_name(
{{"markers_03", Mn::Vector3{14.4, 5.5, 6.6}},
{"markers_02", Mn::Vector3{13.4, 4.5, 5.6}},
{"markers_01", Mn::Vector3{12.4, 3.5, 4.6}},
{"markers_00", Mn::Vector3{11.4, 2.5, 3.6}}});
{{"markers_003", Mn::Vector3{14.4, 5.5, 6.6}},
{"markers_002", Mn::Vector3{13.4, 4.5, 5.6}},
{"markers_001", Mn::Vector3{12.4, 3.5, 4.6}},
{"markers_000", Mn::Vector3{11.4, 2.5, 3.6}}});

SubsetTestMap link_id_01_ao_name(
{{"subset_id_010_ao_name", subset_id_010_ao_name},
Expand All @@ -1941,16 +1941,16 @@ void AttributesConfigsTest::testArticulatedObjectAttrVals(
{"0", Mn::Vector3{21.3, 2.4, 3.5}}});

MarkersTestMap subset_id_021_ao_name(
{{"markers_03", Mn::Vector3{24.4, 5.5, 6.6}},
{"markers_02", Mn::Vector3{23.4, 4.5, 5.6}},
{"markers_01", Mn::Vector3{22.4, 3.5, 4.6}},
{"markers_00", Mn::Vector3{21.4, 2.5, 3.6}}});
{{"markers_003", Mn::Vector3{24.4, 5.5, 6.6}},
{"markers_002", Mn::Vector3{23.4, 4.5, 5.6}},
{"markers_001", Mn::Vector3{22.4, 3.5, 4.6}},
{"markers_000", Mn::Vector3{21.4, 2.5, 3.6}}});

MarkersTestMap subset_id_022_ao_name(
{{"markers_03", Mn::Vector3{224.4, 5.5, 6.6}},
{"markers_02", Mn::Vector3{223.4, 4.5, 5.6}},
{"markers_01", Mn::Vector3{222.4, 3.5, 4.6}},
{"markers_00", Mn::Vector3{221.4, 2.5, 3.6}}});
{{"markers_003", Mn::Vector3{224.4, 5.5, 6.6}},
{"markers_002", Mn::Vector3{223.4, 4.5, 5.6}},
{"markers_001", Mn::Vector3{222.4, 3.5, 4.6}},
{"markers_000", Mn::Vector3{221.4, 2.5, 3.6}}});

SubsetTestMap link_id_02_ao_name(
{{"subset_id_020_ao_name", subset_id_020_ao_name},
Expand All @@ -1963,10 +1963,10 @@ void AttributesConfigsTest::testArticulatedObjectAttrVals(
{"link_id_02_ao_name", link_id_02_ao_name}}};

MarkersTestMap subset_id_100_ao_name(
{{"markers_03", Mn::Vector3{114.1, 15.2, 16.3}},
{"markers_02", Mn::Vector3{113.1, 14.2, 15.3}},
{"markers_01", Mn::Vector3{112.1, 13.2, 14.3}},
{"markers_00", Mn::Vector3{111.1, 12.2, 13.3}}});
{{"markers_003", Mn::Vector3{114.1, 15.2, 16.3}},
{"markers_002", Mn::Vector3{113.1, 14.2, 15.3}},
{"markers_001", Mn::Vector3{112.1, 13.2, 14.3}},
{"markers_000", Mn::Vector3{111.1, 12.2, 13.3}}});

MarkersTestMap subset_id_101_ao_name(
{{"3", Mn::Vector3{114.2, 15.3, 16.4}},
Expand All @@ -1985,10 +1985,10 @@ void AttributesConfigsTest::testArticulatedObjectAttrVals(
{"0", Mn::Vector3{111.3, 12.4, 13.5}}});

MarkersTestMap subset_id_111_ao_name(
{{"markers_03", Mn::Vector3{114.4, 15.5, 16.6}},
{"markers_02", Mn::Vector3{113.4, 14.5, 15.6}},
{"markers_01", Mn::Vector3{112.4, 13.5, 14.6}},
{"markers_00", Mn::Vector3{111.4, 12.5, 13.6}}});
{{"markers_003", Mn::Vector3{114.4, 15.5, 16.6}},
{"markers_002", Mn::Vector3{113.4, 14.5, 15.6}},
{"markers_001", Mn::Vector3{112.4, 13.5, 14.6}},
{"markers_000", Mn::Vector3{111.4, 12.5, 13.6}}});

SubsetTestMap link_id_11_ao_name(
{{"subset_id_110_ao_name", subset_id_110_ao_name},
Expand Down

0 comments on commit 582c403

Please sign in to comment.