@@ -67,9 +67,9 @@ def _transform_to_own_frame(self, shape: Shape):
6767 # If we don’t have a world, fall back to the owning body/frame
6868 shape .origin .reference_frame = self .reference_frame
6969 elif (
70- self .reference_frame is not None
71- and shape .origin .reference_frame != self .reference_frame
72- and self .reference_frame ._world is not None
70+ self .reference_frame is not None
71+ and shape .origin .reference_frame != self .reference_frame
72+ and self .reference_frame ._world is not None
7373 ):
7474 logger .warning (
7575 f"Transformed shape { shape } to { self .reference_frame } since it was in a different "
@@ -114,7 +114,7 @@ def combined_mesh(self) -> Trimesh:
114114 return concatenate (transformed_meshes )
115115
116116 def as_bounding_box_collection_at_origin (
117- self , origin : TransformationMatrix
117+ self , origin : TransformationMatrix
118118 ) -> BoundingBoxCollection :
119119 """
120120 Provides the bounding box collection for this entity given a transformation matrix as origin.
@@ -136,7 +136,7 @@ def as_bounding_box_collection_at_origin(
136136 )
137137
138138 def as_bounding_box_collection_in_frame (
139- self , reference_frame : KinematicStructureEntity
139+ self , reference_frame : KinematicStructureEntity
140140 ) -> BoundingBoxCollection :
141141 """
142142 Provides the bounding box collection for this entity in the given reference frame.
@@ -182,9 +182,11 @@ class BoundingBoxCollection(ShapeCollection):
182182 shapes : List [BoundingBox ]
183183
184184 def __post_init__ (self ):
185+ if not self .reference_frame :
186+ raise ValueError ("BoundingBoxCollection must have a reference frame." )
185187 for box in self .bounding_boxes :
186188 assert (
187- box .origin .reference_frame == self .reference_frame
189+ box .origin .reference_frame == self .reference_frame
188190 ), "All bounding boxes must have the same reference frame."
189191
190192 def __iter__ (self ) -> Iterator [BoundingBox ]:
@@ -209,15 +211,15 @@ def merge(self, other: BoundingBoxCollection) -> BoundingBoxCollection:
209211 :return: The merged bounding box collection.
210212 """
211213 assert (
212- self .reference_frame == other .reference_frame
214+ self .reference_frame == other .reference_frame
213215 ), "The reference frames of the bounding box collections must be the same."
214216 return BoundingBoxCollection (
215217 reference_frame = self .reference_frame ,
216218 shapes = self .bounding_boxes + other .bounding_boxes ,
217219 )
218220
219221 def bloat (
220- self , x_amount : float = 0.0 , y_amount : float = 0 , z_amount : float = 0
222+ self , x_amount : float = 0.0 , y_amount : float = 0 , z_amount : float = 0
221223 ) -> BoundingBoxCollection :
222224 """
223225 Enlarges all bounding boxes in the collection by a given amount in all dimensions.
@@ -235,10 +237,10 @@ def bloat(
235237
236238 @classmethod
237239 def from_simple_event (
238- cls ,
239- reference_frame : KinematicStructureEntity ,
240- simple_event : SimpleEvent ,
241- keep_surface : bool = False ,
240+ cls ,
241+ reference_frame : KinematicStructureEntity ,
242+ simple_event : SimpleEvent ,
243+ keep_surface : bool = False ,
242244 ) -> BoundingBoxCollection :
243245 """
244246 Create a list of bounding boxes from a simple random event.
@@ -250,9 +252,9 @@ def from_simple_event(
250252 """
251253 result = []
252254 for x , y , z in itertools .product (
253- simple_event [SpatialVariables .x .value ].simple_sets ,
254- simple_event [SpatialVariables .y .value ].simple_sets ,
255- simple_event [SpatialVariables .z .value ].simple_sets ,
255+ simple_event [SpatialVariables .x .value ].simple_sets ,
256+ simple_event [SpatialVariables .y .value ].simple_sets ,
257+ simple_event [SpatialVariables .z .value ].simple_sets ,
256258 ):
257259
258260 bb = BoundingBox (
@@ -262,7 +264,9 @@ def from_simple_event(
262264 x .upper ,
263265 y .upper ,
264266 z .upper ,
265- TransformationMatrix (reference_frame = reference_frame ),
267+ TransformationMatrix .from_xyz_quaternion (x .upper - (x .upper - x .lower ) / 2 , y .upper - (y .upper - y .lower ) / 2 ,
268+ z .upper - (z .upper - z .lower ) / 2 , 0 , 0 , 0 , 1 ,
269+ reference_frame = reference_frame )
266270 )
267271 if not keep_surface and (bb .depth == 0 or bb .height == 0 or bb .width == 0 ):
268272 continue
@@ -271,7 +275,7 @@ def from_simple_event(
271275
272276 @classmethod
273277 def from_event (
274- cls , reference_frame : KinematicStructureEntity , event : Event
278+ cls , reference_frame : KinematicStructureEntity , event : Event
275279 ) -> Self :
276280 """
277281 Create a list of bounding boxes from a random event.
@@ -301,7 +305,7 @@ def from_shapes(cls, shapes: ShapeCollection) -> Self:
301305 return cls (shapes = [])
302306 for shape in shapes :
303307 assert (
304- shape .origin .reference_frame == shapes [0 ].origin .reference_frame
308+ shape .origin .reference_frame == shapes [0 ].origin .reference_frame
305309 ), "All shapes must have the same reference frame."
306310
307311 local_bbs = [shape .local_frame_bounding_box for shape in shapes ]
@@ -339,5 +343,5 @@ def bounding_box(self) -> BoundingBox:
339343 max (all_x ),
340344 max (all_y ),
341345 max (all_z ),
342- self . reference_frame . global_pose ,
346+ TransformationMatrix . from_xyz_quaternion ( reference_frame = self . reference_frame ) ,
343347 )
0 commit comments