Skip to content

Commit

Permalink
--ao binding expansion; tighter restrictions on enum setting.
Browse files Browse the repository at this point in the history
  • Loading branch information
jturner65 committed Aug 16, 2023
1 parent 81cc117 commit c4609d0
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 24 deletions.
55 changes: 52 additions & 3 deletions src/esp/bindings/AttributesBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 186,43 @@ void initAttributesBindings(py::module& m) {
R"(This method is inherited from Configuration, but should not be used with Attributes due
to the possibility of changing the type of a required variable. Use the provided Attributes
instead, to change values for this object.)",
"key"_a, "value"_a)
"key"_a, "value"_a);
// ======== Enums ================

// ==== ArticulatedObjectBaseType enum ====
// Describes the type of base joint used to connect the Articulated Object to
// the world
py::enum_<metadata::attributes::ArticulatedObjectBaseType>(
m, "ArticulatedObjectBaseType")
.value("UNSPECIFIED",
metadata::attributes::ArticulatedObjectBaseType::Unspecified)
.value("FREE", metadata::attributes::ArticulatedObjectBaseType::Free)
.value("FIXED", metadata::attributes::ArticulatedObjectBaseType::Fixed);

// ==== ArticulatedObjectInertiaSource enum ====
// Describes the source of the interia values to use for the Articulated
// Object.
py::enum_<metadata::attributes::ArticulatedObjectInertiaSource>(
m, "ArticulatedObjectInertiaSource")
.value("UNSPECIFIED",
metadata::attributes::ArticulatedObjectInertiaSource::Unspecified)
.value("COMPUTED",
metadata::attributes::ArticulatedObjectInertiaSource::Computed)
.value("URDF",
metadata::attributes::ArticulatedObjectInertiaSource::URDF);

//
// ==== ArticulatedObjectLinkOrder enum ====
// Describes how the links in the Articulated Object should be ordered.
py::enum_<metadata::attributes::ArticulatedObjectLinkOrder>(
m, "ArticulatedObjectLinkOrder")
.value("UNSPECIFIED",
metadata::attributes::ArticulatedObjectLinkOrder::Unspecified)
.value("URDF_ORDER",
metadata::attributes::ArticulatedObjectLinkOrder::URDFOrder)
.value("TREE_TRAVERSAL",
metadata::attributes::ArticulatedObjectLinkOrder::TreeTraversal);

;
// ==== ArticulatedObjectAttributes ====
py::class_<ArticulatedObjectAttributes, AbstractAttributes,
ArticulatedObjectAttributes::ptr>(
Expand Down Expand Up @@ -221,7 255,22 @@ void initAttributesBindings(py::module& m) {
"render_mode", &ArticulatedObjectAttributes::getRenderMode,
&ArticulatedObjectAttributes::setRenderMode,
R"(Whether we should render using the articulated object, its skin,
primitives representing each link, both or none.)");
primitives representing each link, both or none.)")
.def_property(
"base_type", &ArticulatedObjectAttributes::getBaseType,
&ArticulatedObjectAttributes::setBaseType,
R"(The type of base/root joint to use to add this Articulated Object to the world.
Possible values are "FREE" and "FIXED".)")
.def_property(
"inertia_source", &ArticulatedObjectAttributes::getInertiaSource,
&ArticulatedObjectAttributes::setInertiaSource,
R"(Tthe source of the inertia tensors to use for this Articulated Object.
Possible values are "COMPUTED" and "URDF".)")
.def_property(
"link_order", &ArticulatedObjectAttributes::getLinkOrder,
&ArticulatedObjectAttributes::setLinkOrder,
R"(The link order to use for the linkages of this Articulated Object.
Possible values are "URDF_ORDER" and "TREE_TRAVERSAL".)");

// ==== AbstractObjectAttributes ====
py::class_<AbstractObjectAttributes, AbstractAttributes,
Expand Down
54 changes: 33 additions & 21 deletions src/esp/metadata/attributes/ArticulatedObjectAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 63,21 @@ class ArticulatedObjectAttributes : public AbstractAttributes {

/**
* @brief Set the type of base/root joint to use to add this Articulated
* Object to the world.
* Object to the world. Cannot be "UNSPECIFIED"
*/
void setBaseType(const std::string& baseType) {
// force to lowercase before setting
// force to lowercase to check if present
const std::string baseTypeLC = Cr::Utility::String::lowercase(baseType);
auto mapIter = AOBaseTypeMap.find(baseTypeLC);
ESP_CHECK(mapIter != AOBaseTypeMap.end(),
"Illegal base type value"
<< baseType
<< "attempted to be set in ArticulatedObjectAttributes:"
<< getHandle() << ". Aborting.");
if ((mapIter == AOBaseTypeMap.end()) ||
(mapIter->second == ArticulatedObjectBaseType::Unspecified)) {
ESP_ERROR(Mn::Debug::Flag::NoSpace)
<< "'" << baseType
<< "' is an illegal value for "
"ArticulatedObjectAttributes::setBaseType, so default value "
<< get<std::string>("base_type") << " not changed.";
return;
}
set("base_type", baseType);
}

Expand All @@ -99,13 103,17 @@ class ArticulatedObjectAttributes : public AbstractAttributes {
*/
void setInertiaSource(const std::string& inertiaSrc) {
// force to lowercase before setting
const std::string renderModeLC = Cr::Utility::String::lowercase(inertiaSrc);
auto mapIter = AOInertiaSourceMap.find(renderModeLC);
ESP_CHECK(mapIter != AOInertiaSourceMap.end(),
"Illegal inertia source value"
<< inertiaSrc
<< "attempted to be set in ArticulatedObjectAttributes:"
<< getHandle() << ". Aborting.");
const std::string inertiaSrcLC = Cr::Utility::String::lowercase(inertiaSrc);
auto mapIter = AOInertiaSourceMap.find(inertiaSrcLC);
if ((mapIter == AOInertiaSourceMap.end()) ||
(mapIter->second == ArticulatedObjectInertiaSource::Unspecified)) {
ESP_ERROR(Mn::Debug::Flag::NoSpace)
<< "'" << inertiaSrc
<< "' is an illegal value for "
"ArticulatedObjectAttributes::setInertiaSource, so default value '"
<< get<std::string>("inertia_source") << "' not changed.";
return;
}
set("inertia_source", inertiaSrc);
}

Expand All @@ -131,13 139,17 @@ class ArticulatedObjectAttributes : public AbstractAttributes {
*/
void setLinkOrder(const std::string& linkOrder) {
// force to lowercase before setting
const std::string renderModeLC = Cr::Utility::String::lowercase(linkOrder);
auto mapIter = AOLinkOrderMap.find(renderModeLC);
ESP_CHECK(mapIter != AOLinkOrderMap.end(),
"Illegal link order value"
<< linkOrder
<< "attempted to be set in ArticulatedObjectAttributes:"
<< getHandle() << ". Aborting.");
const std::string linkOrderLC = Cr::Utility::String::lowercase(linkOrder);
auto mapIter = AOLinkOrderMap.find(linkOrderLC);
if ((mapIter == AOLinkOrderMap.end()) ||
(mapIter->second == ArticulatedObjectLinkOrder::Unspecified)) {
ESP_ERROR(Mn::Debug::Flag::NoSpace)
<< "'" << linkOrder
<< "' is an illegal value for "
"ArticulatedObjectAttributes::setLinkOrder, so default value '"
<< get<std::string>("link_order") << "' not changed.";
return;
}
set("link_order", linkOrder);
}

Expand Down

0 comments on commit c4609d0

Please sign in to comment.