RobotLocomotion / drake

Model-based design and verification for robotics.
https://drake.mit.edu
Other
3.27k stars 1.26k forks source link

scene_graph: Can haz way to get all geometries from a FrameId (or GeometrySet)? #13493

Closed EricCousineau-TRI closed 3 years ago

EricCousineau-TRI commented 4 years ago

Hoisting Anzu discussion to Drake issue; from subgraph PR in Anzu:

PR code is based on this bit: https://github.com/EricCousineau-TRI/repro/blob/54494a5c5154f19e693e4862fbaa79cddcd78d6f/drake_stuff/multibody_plant_prototypes/multibody_extras.py#L91-L100

def get_geometries(plant, scene_graph, bodies):
    """Returns all GeometryId's attached to bodies. Assumes corresponding
    FrameId's have been added."""
    geometry_ids = []
    inspector = scene_graph.model_inspector()
    for geometry_id in inspector.GetAllGeometryIds():
        body = plant.GetBodyFromFrameId(inspector.GetFrameId(geometry_id))
        if body in bodies:
            geometry_ids.append(geometry_id)
    return sorted(geometry_ids, key=lambda x: x.get_value())

@SeanCurtis-TRI's comment: BTW Blech! I'm sorry that missing API forces you to do this backwards! You should have:

for body in bodies:
    frame_id = plant.GetBodyFromFrameId(body.get_index())
    assert(frame_id is not None)
    geometry_ids += inspector.GetGeometries(frame_id):

EDIT: My follow-up in the Anzu PR: Aye, that would be awesome! Another option is, it possible to retrieve GeometryId's from GeometrySet [sic]? e.g. inspector.GetGeometries(geometry_set)?

SeanCurtis-TRI commented 4 years ago

The issue summary doesn't match the code snippets in the issue description. There is no mention of GeometrySet in the discussion. (And thanks for creating the issue. Feel free to assign it to me unless you really intend to do it any time soon.)

EricCousineau-TRI commented 4 years ago

Sounds good on all accounts! Updated title, added the mention of GeometrySet in discussion transcript, and reassigned!

SeanCurtis-TRI commented 4 years ago

@EricCousineau-TRI The main core of this PR has been resolved by #13999, I believe.

I vote we close this issue and split out the second part into its own issue. Thoughts?

SeanCurtis-TRI commented 4 years ago

Alternatively, the second part would be trivial to provide, so I might just knock it out to close this issue.

EricCousineau-TRI commented 4 years ago

I'm fine either way!

SeanCurtis-TRI commented 3 years ago

This issue is resolved in two parts: #13999 gave the ability to collect geometries on a per-frame basis and #14871 does the same thing on a per GeometrySet basis.