Skip to content

Commit

Permalink
--MarkerSets assignment to objects, 'interface' class and bindings (#…
Browse files Browse the repository at this point in the history
…2371)

* --add markersets alias class
Intended to provide convenience access to markersets hierarchy
* --Add MarkerSets.h; Specialize interaction to be MarkerSets class
* --modify wrapper access to be just through sorted list of marker points
* --add function to rekey Configuration values.
This function will replace the original keys for all the values in a configuration (regardless of type) with sequential numeric strings preserving the natural ordering of the original set of keys
* --increase array key limit to 1000 elements from 100
The constructed key for array values is formatted  with a fixed-width leading-zero numeric string so that it will always sort properly.
* --add rekeying to markersets after they are loaded.
* --add MarkerSets accessors for all possible permutations
* --make sure we clear out existing markers before we write new ones.
* --bindings for subsets, link sets
* --Finish bindings, cleanup LinkMarkerSet
* --rename hierarchy components for clarity and brevity
* --transform points between object local and world points
* --add ability to map back to id from link name
* --enable casting/templated subconfig create
* --create subconfigs with appropriate type; init attrs  w.empty markerset
* --address occasional bugs with empty strings written to paths for saved jsons
* --explicitly state limitations of using object initialization attributes
  • Loading branch information
jturner65 committed May 1, 2024
1 parent 3bc4e65 commit 2ac5b9f
Show file tree
Hide file tree
Showing 32 changed files with 1,850 additions and 463 deletions.
220 changes: 210 additions & 10 deletions src/esp/bindings/AttributesBindings.cpp

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions src/esp/bindings/ConfigBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ void initConfigBindings(py::module& m) {
R"(Retrieves a string representation of the value referred to by the passed key.)")

.def(
"get_keys_by_type", &Configuration::getStoredKeys,
"get_keys_by_type", &Configuration::getKeysByType,
R"(Retrieves a list of all the keys of values of the specified types. Takes ConfigValType
enum value as argument.)",
"value_type"_a)
enum value as argument, and whether the keys should be sorted or not.)",
"value_type"_a, "sorted"_a = false)

.def("get_keys_and_types", &Configuration::getValueTypes,
R"(Returns a dictionary where the keys are the names of the values
Expand Down Expand Up @@ -202,7 +202,9 @@ void initConfigBindings(py::module& m) {
// subconfigs
.def(
"get_subconfig_keys", &Configuration::getSubconfigKeys,
R"(Retrieves a list of the keys of this configuration's subconfigurations)")
R"(Retrieves a list of the keys of this configuration's subconfigurations,
specifying whether the keys should be sorted or not)",
"sorted"_a = false)

.def("get_subconfig", &Configuration::editSubconfig<Configuration>,
py::return_value_policy::reference_internal,
Expand All @@ -220,7 +222,8 @@ void initConfigBindings(py::module& m) {
R"(Returns true if specified key references an existing subconfiguration within this configuration.)")
.def(
"remove_subconfig", &Configuration::removeSubconfig,
R"(Removes and returns subconfiguration corresponding to passed key, if found. Gives warning otherwise.)");
R"(Removes and returns subconfiguration corresponding to passed key, if found. Gives warning otherwise.)")
.def("__repr__", &Configuration::getAllValsAsString, "new_line"_a = "\n");

} // initConfigBindings

Expand Down
60 changes: 56 additions & 4 deletions src/esp/bindings/PhysicsObjectBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ void declareBasePhysicsObjectWrapper(py::module& m,
("Get or set the translation vector of this " + objType +
"'s root SceneNode. If modified, sim state will be updated.")
.c_str())
.def(
"transform_world_pts_to_local",
&PhysObjWrapper::transformWorldPointsToLocal,
R"(Given the list of passed points in world space, return those points
transformed to this object's local space. The link_id is for articulated
objects and is ignored for rigid objects and stages )",
"ws_points"_a, "link_id"_a)
.def(
"transform_local_pts_to_world",
&PhysObjWrapper::transformLocalPointsToWorld,
R"(Given the list of passed points in this object's local space, return
those points transformed to world space. The link_id is for articulated
objects and is ignored for rigid objects and stages )",
"ls_points"_a, "link_id"_a)
.def_property(
"rotation", &PhysObjWrapper::getRotation,
&PhysObjWrapper::setRotation,
Expand Down Expand Up @@ -187,9 +201,14 @@ void declareBasePhysicsObjectWrapper(py::module& m,
.def_property_readonly(
"user_attributes", &PhysObjWrapper::getUserAttributes,
("User-defined " + objType +
" attributes. These are not used internally by Habitat in any "
" attributes. These are not used internally by Habitat in any "
"capacity, but are available for a user to consume how they wish.")
.c_str())
.def_property_readonly(
"marker_sets", &PhysObjWrapper::getMarkerSets,
py::return_value_policy::reference_internal,
("The MarkerSets defined for " + objType + " this object.").c_str())

.def_property_readonly(
"csv_info", &PhysObjWrapper::getObjectInfo,
("Comma-separated informational string describing this " + objType +
Expand Down Expand Up @@ -345,7 +364,20 @@ void declareRigidObjectWrapper(py::module& m,
.def_property_readonly(
"creation_attributes",
&ManagedRigidObject::getInitializationAttributes,
("Get a copy of the attributes used to create this " + objType + ".")
("Get a copy of the template attributes describing the initial state "
"of this " +
objType +
". These attributes have the combination of data from the "
"original " +
objType +
" attributes and specific instance attributes "
"used to create this " +
objType +
". Note : values will reflect "
"both sources, and should not be saved to disk as " +
objType +
" attributes, since instance attribute modifications will "
"still occur on subsequent loads.")
.c_str())
.def_property_readonly(
"velocity_control", &ManagedRigidObject::getVelocityControl,
Expand All @@ -366,7 +398,20 @@ void declareArticulatedObjectWrapper(py::module& m,
.def_property_readonly(
"creation_attributes",
&ManagedArticulatedObject::getInitializationAttributes,
("Get a copy of the attributes used to create this " + objType + ".")
("Get a copy of the template attributes describing the initial state "
"of this " +
objType +
". These attributes have the combination of data from the "
"original " +
objType +
" attributes and specific instance attributes "
"used to create this " +
objType +
". Note : values will reflect "
"both sources, and should not be saved to disk as " +
objType +
" attributes, since instance attribute modifications will "
"still occur on subsequent loads.")
.c_str())
.def_property_readonly(
"global_scale", &ManagedArticulatedObject::getGlobalScale,
Expand Down Expand Up @@ -398,6 +443,13 @@ void declareArticulatedObjectWrapper(py::module& m,
("Get a dict mapping Habitat object ids to this " +
objType + "'s link ids.")
.c_str())
.def("get_link_id_from_name",
&ManagedArticulatedObject::getLinkIdFromName,
("Get this " + objType +
"'s articulated link id specified by the passed "
"link_name.")
.c_str(),
"link_name"_a)
.def_property_readonly(
"num_links", &ManagedArticulatedObject::getNumLinks,
("Get the number of links this " + objType + " holds.").c_str())
Expand Down Expand Up @@ -484,7 +536,7 @@ void declareArticulatedObjectWrapper(py::module& m,
.c_str(),
"link_id"_a)
.def("get_link_name", &ManagedArticulatedObject::getLinkName,
("Get the name of the this " + objType +
("Get the name of this " + objType +
"'s link specified by the given link_id.")
.c_str(),
"link_id"_a)
Expand Down
63 changes: 53 additions & 10 deletions src/esp/core/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,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 @@ -511,7 +511,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 Expand Up @@ -576,10 +576,10 @@ void Configuration::writeValuesToJson(io::JsonGenericValue& jsonObj,
auto jsonVal = valIter->second.writeToJsonObject(allocator);
jsonObj.AddMember(name, jsonVal, allocator);
} else {
ESP_VERY_VERBOSE()
<< "Unitialized ConfigValue in Configuration @ key ["
ESP_VERY_VERBOSE(Mn::Debug::Flag::NoSpace)
<< "Unitialized ConfigValue in Configuration @ key `"
<< valIter->first
<< "], so nothing will be written to JSON for this key.";
<< "`, so nothing will be written to JSON for this key.";
}
} // iterate through all values
} // Configuration::writeValuesToJson
Expand All @@ -600,10 +600,10 @@ void Configuration::writeSubconfigsToJson(io::JsonGenericValue& jsonObj,
cfgIter->second->writeToJsonObject(allocator);
jsonObj.AddMember(name, subObj, allocator);
} else {
ESP_VERY_VERBOSE()
<< "Unitialized/empty Subconfig in Configuration @ key ["
ESP_VERY_VERBOSE(Mn::Debug::Flag::NoSpace)
<< "Unitialized/empty Subconfig in Configuration @ key `"
<< cfgIter->first
<< "], so nothing will be written to JSON for this key.";
<< "`, so nothing will be written to JSON for this key.";
}
} // iterate through all configurations

Expand Down Expand Up @@ -648,15 +648,58 @@ template <>
std::shared_ptr<Configuration> Configuration::editSubconfig<Configuration>(
const std::string& name) {
// retrieve existing (or create new) subgroup, with passed name
return addSubgroup(name);
return addOrEditSubgroup<Configuration>(name).first->second;
}

template <>
void Configuration::setSubconfigPtr<Configuration>(
const std::string& name,
std::shared_ptr<Configuration>& configPtr) {
configMap_[name] = std::move(configPtr);
} // setSubconfigPtr
}

int Configuration::rekeyAllValues() {
// Get all sorted key-value pairs of values
std::map<std::string, ConfigValue> sortedValMap(valueMap_.begin(),
valueMap_.end());
// clear out existing value map - subconfigs are not touched.
valueMap_.clear();
// place sorted values with newly constructed keys
int keyIter = 0;
for (auto it = sortedValMap.cbegin(); it != sortedValMap.cend(); ++it) {
std::string newKey = Cr::Utility::formatString("{:.03d}", keyIter++);
valueMap_[newKey] = it->second;
}
return keyIter;
} // Configuration::rekeyAllValues()

int Configuration::rekeySubconfigValues(const std::string& subconfigKey) {
std::pair<ConfigMapType::iterator, bool> rekeySubconfigEntry =
addOrEditSubgroup<Configuration>(subconfigKey);
// check if subconfig existed already - result from addOrEditSubgroup would
// be false if add failed.
if (rekeySubconfigEntry.second) {
// Subconfig did not exist, was created by addOrEdit, so delete and return
// 0.
ESP_DEBUG(Mn::Debug::Flag::NoSpace)
<< "No subconfig found with key `" << subconfigKey
<< "` so rekeying aborted.";
configMap_.erase(rekeySubconfigEntry.first);
return 0;
}
// retrieve subconfig
auto rekeySubconfig = rekeySubconfigEntry.first->second;
if (rekeySubconfig->getNumValues() == 0) {
// Subconfig exists but has no values defined, so no rekeying possible
ESP_DEBUG(Mn::Debug::Flag::NoSpace)
<< "Subconfig with key `" << subconfigKey
<< "` has no values, so no rekeying accomplished.";
return 0;
}
// rekey subconfig and return the number of values affected
return rekeySubconfig->rekeyAllValues();

} // Configuration::rekeySubconfig

int Configuration::findValueInternal(const Configuration& config,
const std::string& key,
Expand Down
Loading

0 comments on commit 2ac5b9f

Please sign in to comment.