Skip to content

Commit f3079fa

Browse files
committed
wip add python bindings
1 parent 1d52b88 commit f3079fa

File tree

4 files changed

+54
-28
lines changed

4 files changed

+54
-28
lines changed

bindings/pydrake/geometry/geometry_py_scene_graph.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ void DefineSceneGraphInspector(py::module m, T) {
184184
cls_doc.GetAllDeformableGeometryIds.doc)
185185
.def("GetConvexHull", &Class::GetConvexHull, py_rvp::reference_internal,
186186
py::arg("geometry_id"), cls_doc.GetConvexHull.doc)
187+
.def("GetObbInGeometryFrame", &Class::GetObbInGeometryFrame,
188+
py::arg("geometry_id"), cls_doc.GetObbInGeometryFrame.doc)
187189
.def("CollisionFiltered", &Class::CollisionFiltered,
188190
py::arg("geometry_id1"), py::arg("geometry_id2"),
189191
cls_doc.CollisionFiltered.doc)
@@ -566,16 +568,20 @@ void DefineQueryObject(py::module m, T) {
566568
&Class::GetPoseInWorld),
567569
py::arg("frame_id"), py_rvp::reference_internal,
568570
cls_doc.GetPoseInWorld.doc_1args_frame_id)
569-
.def("GetConfigurationsInWorld", &Class::GetConfigurationsInWorld,
570-
py::arg("deformable_geometry_id"), py_rvp::copy,
571-
cls_doc.GetConfigurationsInWorld.doc)
572571
.def("GetPoseInParent", &Class::GetPoseInParent, py::arg("frame_id"),
573572
py_rvp::reference_internal, cls_doc.GetPoseInParent.doc)
574573
.def("GetPoseInWorld",
575574
overload_cast_explicit<const math::RigidTransform<T>&, GeometryId>(
576575
&Class::GetPoseInWorld),
577576
py::arg("geometry_id"), py_rvp::reference_internal,
578577
cls_doc.GetPoseInWorld.doc_1args_geometry_id)
578+
.def("GetConfigurationsInWorld", &Class::GetConfigurationsInWorld,
579+
py::arg("deformable_geometry_id"), py_rvp::copy,
580+
cls_doc.GetConfigurationsInWorld.doc)
581+
.def("ComputeAabbInWorld", &Class::ComputeAabbInWorld,
582+
py::arg("geometry_id"), cls_doc.ComputeAabbInWorld.doc)
583+
.def("ComputeObbInWorld", &Class::ComputeObbInWorld,
584+
py::arg("geometry_id"), cls_doc.ComputeObbInWorld.doc)
579585
.def("ComputeSignedDistancePairwiseClosestPoints",
580586
&QueryObject<T>::ComputeSignedDistancePairwiseClosestPoints,
581587
py::arg("max_distance") = std::numeric_limits<double>::infinity(),

bindings/pydrake/geometry/test/scene_graph_test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,17 @@ def test_scene_graph_api(self, T):
279279
self.assertTrue(inspector.IsDeformableGeometry(geometry_id=sphere_4))
280280
self.assertEqual(inspector.GetAllDeformableGeometryIds(), [sphere_4])
281281
self.assertIsNone(inspector.GetConvexHull(geometry_id=sphere_3))
282+
# Test GetObbInGeometryFrame for a geometry that supports it.
283+
self.assertIsInstance(
284+
inspector.GetObbInGeometryFrame(geometry_id=sphere_3), mut.Obb)
285+
# Test GetObbInGeometryFrame for a geometry that does not support it.
286+
half_space = scene_graph.RegisterAnchoredGeometry(
287+
source_id=global_source,
288+
geometry=mut.GeometryInstance(X_PG=RigidTransform_[float](),
289+
shape=mut.HalfSpace(),
290+
name="half_space"))
291+
self.assertIsNone(
292+
inspector.GetObbInGeometryFrame(geometry_id=half_space))
282293
self.assertIsInstance(inspector.geometry_version(),
283294
mut.GeometryVersion)
284295

@@ -678,6 +689,13 @@ def test_query_object(self, T):
678689
self.assertIsInstance(
679690
query_object.GetPoseInWorld(geometry_id=geometry_id),
680691
RigidTransform_[T])
692+
self.assertIsInstance(
693+
query_object.ComputeAabbInWorld(
694+
geometry_id=deformable_geometry_id),
695+
mut.Aabb)
696+
self.assertIsInstance(
697+
query_object.ComputeObbInWorld(geometry_id=geometry_id),
698+
mut.Obb)
681699

682700
# Proximity queries -- all of these will produce empty results.
683701
results = query_object.ComputeSignedDistancePairwiseClosestPoints()

geometry/query_object.cc

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,40 +85,41 @@ const RigidTransform<T>& QueryObject<T>::GetPoseInWorld(
8585
}
8686

8787
template <typename T>
88-
Aabb QueryObject<T>::ComputeAabbInWorld(GeometryId geometry_id) const {
88+
const VectorX<T>& QueryObject<T>::GetConfigurationsInWorld(
89+
GeometryId geometry_id) const {
8990
ThrowIfNotCallable();
91+
9092
FullConfigurationUpdate();
9193
const GeometryState<T>& state = geometry_state();
92-
return state.ComputeAabbInWorld(geometry_id);
94+
return state.get_configurations_in_world(geometry_id);
9395
}
9496

9597
template <typename T>
96-
Obb QueryObject<T>::ComputeObbInWorld(GeometryId geometry_id) const {
98+
std::vector<VectorX<T>> QueryObject<T>::GetDrivenMeshConfigurationsInWorld(
99+
GeometryId geometry_id, Role role) const {
97100
ThrowIfNotCallable();
98-
FullPoseUpdate();
101+
FullConfigurationUpdate();
99102
const GeometryState<T>& state = geometry_state();
100-
return state.ComputeObbInWorld(geometry_id);
103+
return state.GetDrivenMeshConfigurationsInWorld(geometry_id, role);
101104
}
102105

103106
template <typename T>
104-
const VectorX<T>& QueryObject<T>::GetConfigurationsInWorld(
105-
GeometryId geometry_id) const {
107+
Aabb QueryObject<T>::ComputeAabbInWorld(GeometryId geometry_id) const {
106108
ThrowIfNotCallable();
107-
108109
FullConfigurationUpdate();
109110
const GeometryState<T>& state = geometry_state();
110-
return state.get_configurations_in_world(geometry_id);
111+
return state.ComputeAabbInWorld(geometry_id);
111112
}
112113

113114
template <typename T>
114-
std::vector<VectorX<T>> QueryObject<T>::GetDrivenMeshConfigurationsInWorld(
115-
GeometryId geometry_id, Role role) const {
115+
Obb QueryObject<T>::ComputeObbInWorld(GeometryId geometry_id) const {
116116
ThrowIfNotCallable();
117-
FullConfigurationUpdate();
117+
FullPoseUpdate();
118118
const GeometryState<T>& state = geometry_state();
119-
return state.GetDrivenMeshConfigurationsInWorld(geometry_id, role);
119+
return state.ComputeObbInWorld(geometry_id);
120120
}
121121

122+
122123
template <typename T>
123124
std::vector<PenetrationAsPointPair<T>>
124125
QueryObject<T>::ComputePointPairPenetration() const {

geometry/query_object.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -172,18 +172,6 @@ class QueryObject {
172172
is deformable. */
173173
const math::RigidTransform<T>& GetPoseInWorld(GeometryId geometry_id) const;
174174

175-
/** Reports the axis-aligned bounding box of the geometry indicated by
176-
`geometry_id` in the world frame.
177-
@throws std::exception if the geometry `geometry_id` is not valid.
178-
@throws std::exception if the geometry is not deformable. */
179-
Aabb ComputeAabbInWorld(GeometryId geometry_id) const;
180-
181-
/** Reports the oriented bounding box of the geometry indicated by
182-
`geometry_id` in the world frame.
183-
@throws std::exception if the geometry `geometry_id` is not valid.
184-
@throws std::exception if the geometry is deformable. */
185-
Obb ComputeObbInWorld(GeometryId geometry_id) const;
186-
187175
/** Reports the configuration of the deformable geometry indicated by
188176
`deformable_geometry_id` relative to the world frame.
189177
@sa GetPoseInWorld().
@@ -204,6 +192,19 @@ class QueryObject {
204192
@experimental */
205193
std::vector<VectorX<T>> GetDrivenMeshConfigurationsInWorld(
206194
GeometryId deformable_geometry_id, Role role) const;
195+
196+
/** Reports the axis-aligned bounding box of the geometry indicated by
197+
`geometry_id` in the world frame.
198+
@throws std::exception if the geometry `geometry_id` is not valid.
199+
@throws std::exception if the geometry is not deformable. */
200+
Aabb ComputeAabbInWorld(GeometryId geometry_id) const;
201+
202+
/** Reports the oriented bounding box of the geometry indicated by
203+
`geometry_id` in the world frame.
204+
@throws std::exception if the geometry `geometry_id` is not valid.
205+
@throws std::exception if the geometry is deformable. */
206+
Obb ComputeObbInWorld(GeometryId geometry_id) const;
207+
207208
//@}
208209

209210
/**

0 commit comments

Comments
 (0)