Skip to content

Commit

Permalink
py geometry: Bind property retrieval
Browse files Browse the repository at this point in the history
Clean up binding order and use of `Class` / `cls_doc` aliases
  • Loading branch information
EricCousineau-TRI committed Nov 25, 2019
1 parent a822330 commit d589124
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 23 deletions.
51 changes: 28 additions & 23 deletions bindings/pydrake/geometry_py.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,39 +148,44 @@ void DoScalarDependentDefinitions(py::module m, T) {
// SceneGraphInspector
{
using Class = SceneGraphInspector<T>;
constexpr auto& cls_doc = doc.SceneGraphInspector;
auto cls = DefineTemplateClassWithDefault<Class>(
m, "SceneGraphInspector", param, doc.SceneGraphInspector.doc);
m, "SceneGraphInspector", param, cls_doc.doc);
cls // BR
.def("num_sources", &SceneGraphInspector<T>::num_sources,
doc.SceneGraphInspector.num_sources.doc)
.def("num_frames", &SceneGraphInspector<T>::num_frames,
doc.SceneGraphInspector.num_frames.doc)
.def("num_geometries", &SceneGraphInspector<T>::num_geometries,
doc.SceneGraphInspector.num_geometries.doc)
.def("GetAllGeometryIds", &SceneGraphInspector<T>::GetAllGeometryIds,
doc.SceneGraphInspector.GetAllGeometryIds.doc)
.def("GetFrameId", &SceneGraphInspector<T>::GetFrameId,
py::arg("geometry_id"), doc.SceneGraphInspector.GetFrameId.doc)
.def("GetGeometryIdByName",
&SceneGraphInspector<T>::GetGeometryIdByName, py::arg("frame_id"),
py::arg("role"), py::arg("name"),
doc.SceneGraphInspector.GetGeometryIdByName.doc)
.def("num_sources", &Class::num_sources, cls_doc.num_sources.doc)
.def("num_frames", &Class::num_frames, cls_doc.num_frames.doc)
.def("num_geometries", &Class::num_geometries,
cls_doc.num_geometries.doc)
.def("GetAllGeometryIds", &Class::GetAllGeometryIds,
cls_doc.GetAllGeometryIds.doc)
.def("GetFrameId", &Class::GetFrameId, py::arg("geometry_id"),
cls_doc.GetFrameId.doc)
.def("GetGeometryIdByName", &Class::GetGeometryIdByName,
py::arg("frame_id"), py::arg("role"), py::arg("name"),
cls_doc.GetGeometryIdByName.doc)
.def("GetNameByFrameId",
overload_cast_explicit<const std::string&, FrameId>(
&SceneGraphInspector<T>::GetName),
&Class::GetName),
py_reference_internal, py::arg("frame_id"),
doc.SceneGraphInspector.GetName.doc_1args_frame_id)
cls_doc.GetName.doc_1args_frame_id)
.def("GetNameByGeometryId",
overload_cast_explicit<const std::string&, GeometryId>(
&SceneGraphInspector<T>::GetName),
&Class::GetName),
py_reference_internal, py::arg("geometry_id"),
doc.SceneGraphInspector.GetName.doc_1args_geometry_id)
.def("GetPoseInFrame", &SceneGraphInspector<T>::GetPoseInFrame,
cls_doc.GetName.doc_1args_geometry_id)
.def("GetShape", &Class::GetShape, py_reference_internal,
py::arg("geometry_id"), cls_doc.GetShape.doc)
.def("GetPoseInFrame", &Class::GetPoseInFrame, py_reference_internal,
py::arg("geometry_id"), cls_doc.GetPoseInFrame.doc)
.def("GetProximityProperties", &Class::GetProximityProperties,
py_reference_internal, py::arg("geometry_id"),
doc.SceneGraphInspector.GetPoseInFrame.doc)
.def("GetShape", &SceneGraphInspector<T>::GetShape,
cls_doc.GetProximityProperties.doc)
.def("GetIllustrationProperties", &Class::GetIllustrationProperties,
py_reference_internal, py::arg("geometry_id"),
doc.SceneGraphInspector.GetShape.doc);
cls_doc.GetIllustrationProperties.doc)
.def("GetPerceptionProperties", &Class::GetPerceptionProperties,
py_reference_internal, py::arg("geometry_id"),
cls_doc.GetPerceptionProperties.doc);
}

// SceneGraph
Expand Down
11 changes: 11 additions & 0 deletions bindings/pydrake/test/geometry_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ def test_scene_graph_api(self, T):
geometry_id=global_geometry, properties=prop,
assign=mut.RoleAssign.kNew)

# Check property accessors.
self.assertIsInstance(
inspector.GetProximityProperties(geometry_id=global_geometry),
mut.ProximityProperties)
self.assertIsInstance(
inspector.GetIllustrationProperties(geometry_id=global_geometry),
mut.IllustrationProperties)
self.assertIsInstance(
inspector.GetPerceptionProperties(geometry_id=global_geometry),
mut.PerceptionProperties)

def test_connect_drake_visualizer(self):
# Test visualization API.
# Use a mockable so that we can make a smoke test without side
Expand Down

0 comments on commit d589124

Please sign in to comment.