@@ -97,32 +97,48 @@ def custom_configuration_vector(
97
97
return q
98
98
99
99
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.
102
120
103
121
Args:
104
122
model: Mujoco model.
105
123
body_id: ID of body where subtree starts.
106
124
107
125
Returns:
108
- A list containing all subtree geom ids.
126
+ A list containing all subtree body ids.
109
127
"""
110
- geom_ids = []
128
+ body_ids : list [ int ] = []
111
129
stack = [body_id ]
112
130
while stack :
113
131
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
122
135
123
136
124
137
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.
126
142
127
143
Args:
128
144
model: Mujoco model.
@@ -136,25 +152,23 @@ def get_body_geom_ids(model: mujoco.MjModel, body_id: int) -> list[int]:
136
152
return list (range (geom_start , geom_end ))
137
153
138
154
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.
141
160
142
161
Args:
143
162
model: Mujoco model.
144
163
body_id: ID of body where subtree starts.
145
164
146
165
Returns:
147
- A list containing all subtree body ids.
166
+ A list containing all subtree geom ids.
148
167
"""
149
- body_ids = []
168
+ geom_ids : list [ int ] = []
150
169
stack = [body_id ]
151
170
while stack :
152
171
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