Skip to content

Commit fb026c5

Browse files
committed
Nits.
1 parent 7bf62a2 commit fb026c5

File tree

1 file changed

+39
-25
lines changed

1 file changed

+39
-25
lines changed

mink/utils.py

+39-25
Original file line numberDiff line numberDiff line change
@@ -97,32 +97,48 @@ def custom_configuration_vector(
9797
return q
9898

9999

100-
def get_subtree_geom_ids(model: mujoco.MjModel, body_id: int) -> list[int]:
101-
"""Get all geoms belonging to subtree starting at a given body.
100+
def get_body_body_ids(model: mujoco.MjModel, body_id: int) -> list[int]:
101+
"""Get immediate children bodies belonging to a given body.
102+
103+
Args:
104+
model: Mujoco model.
105+
body_id: ID of body.
106+
107+
Returns:
108+
A list containing all child body ids.
109+
"""
110+
return [
111+
i
112+
for i in range(model.nbody)
113+
if model.body_parentid[i] == body_id
114+
and body_id != i # Exclude the body itself.
115+
]
116+
117+
118+
def get_subtree_body_ids(model: mujoco.MjModel, body_id: int) -> list[int]:
119+
"""Get all bodies belonging to subtree starting at a given body.
102120
103121
Args:
104122
model: Mujoco model.
105123
body_id: ID of body where subtree starts.
106124
107125
Returns:
108-
A list containing all subtree geom ids.
126+
A list containing all subtree body ids.
109127
"""
110-
geom_ids = []
128+
body_ids: list[int] = []
111129
stack = [body_id]
112130
while stack:
113131
body_id = stack.pop()
114-
geom_ids.extend(get_body_geom_ids(model, body_id))
115-
children = [
116-
i
117-
for i in range(model.nbody)
118-
if model.body_parentid[i] == body_id and body_id != i
119-
]
120-
stack.extend(children)
121-
return geom_ids
132+
body_ids.append(body_id)
133+
stack += get_body_body_ids(model, body_id)
134+
return body_ids
122135

123136

124137
def get_body_geom_ids(model: mujoco.MjModel, body_id: int) -> list[int]:
125-
"""Get all geoms belonging to a given body.
138+
"""Get immediate geoms belonging to a given body.
139+
140+
Here, immediate geoms are those directly attached to the body and not its
141+
descendants.
126142
127143
Args:
128144
model: Mujoco model.
@@ -136,25 +152,23 @@ def get_body_geom_ids(model: mujoco.MjModel, body_id: int) -> list[int]:
136152
return list(range(geom_start, geom_end))
137153

138154

139-
def get_subtree_body_ids(model: mujoco.MjModel, body_id: int) -> list[int]:
140-
"""Get all bodies belonging to subtree starting at a given body.
155+
def get_subtree_geom_ids(model: mujoco.MjModel, body_id: int) -> list[int]:
156+
"""Get all geoms belonging to subtree starting at a given body.
157+
158+
Here, a subtree is defined as the kinematic tree starting at the body and including
159+
all its descendants.
141160
142161
Args:
143162
model: Mujoco model.
144163
body_id: ID of body where subtree starts.
145164
146165
Returns:
147-
A list containing all subtree body ids.
166+
A list containing all subtree geom ids.
148167
"""
149-
body_ids = []
168+
geom_ids: list[int] = []
150169
stack = [body_id]
151170
while stack:
152171
body_id = stack.pop()
153-
body_ids.append(body_id)
154-
children = [
155-
i
156-
for i in range(model.nbody)
157-
if model.body_parentid[i] == body_id and body_id != i
158-
]
159-
stack.extend(children)
160-
return body_ids
172+
geom_ids.extend(get_body_geom_ids(model, body_id))
173+
stack += get_body_body_ids(model, body_id)
174+
return geom_ids

0 commit comments

Comments
 (0)