@@ -363,15 +363,53 @@ StaticLayer::updateBounds(
363
363
364
364
useExtraBounds (min_x, min_y, max_x, max_y);
365
365
366
- double wx, wy;
366
+ // Might even be in a different frame
367
+ if (map_frame_ == global_frame_) {
368
+ double wx, wy;
369
+
370
+ mapToWorld (x_, y_, wx, wy);
371
+ *min_x = std::min (wx, *min_x);
372
+ *min_y = std::min (wy, *min_y);
373
+
374
+ mapToWorld (x_ + width_, y_ + height_, wx, wy);
375
+ *max_x = std::max (wx, *max_x);
376
+ *max_y = std::max (wy, *max_y);
377
+ } else {
378
+ geometry_msgs::msg::TransformStamped transform;
379
+ try {
380
+ transform = tf_->lookupTransform (
381
+ global_frame_, map_frame_, tf2::TimePointZero,
382
+ transform_tolerance_);
383
+ } catch (tf2::TransformException & ex) {
384
+ RCLCPP_ERROR (logger_, " StaticLayer: %s" , ex.what ());
385
+ return ;
386
+ }
387
+ tf2::Transform tf2_transform;
388
+ tf2::fromMsg (transform.transform , tf2_transform);
389
+
390
+ double wx, wy;
391
+ mapToWorld (x_, y_, wx, wy);
392
+ tf2::Vector3 down_left (wx, wy, 0 );
393
+
394
+ mapToWorld (x_ + width_, y_, wx, wy);
395
+ tf2::Vector3 down_right (wx, wy, 0 );
396
+
397
+ mapToWorld (x_, y_ + height_, wx, wy);
398
+ tf2::Vector3 up_left (wx, wy, 0 );
367
399
368
- mapToWorld (x_, y_, wx, wy);
369
- *min_x = std::min (wx, *min_x);
370
- *min_y = std::min (wy, *min_y);
400
+ mapToWorld (x_ + width_, y_ + height_, wx, wy);
401
+ tf2::Vector3 up_right (wx, wy, 0 );
371
402
372
- mapToWorld (x_ + width_, y_ + height_, wx, wy);
373
- *max_x = std::max (wx, *max_x);
374
- *max_y = std::max (wy, *max_y);
403
+ down_left = tf2_transform * down_left;
404
+ down_right = tf2_transform * down_right;
405
+ up_left = tf2_transform * up_left;
406
+ up_right = tf2_transform * up_right;
407
+
408
+ *min_x = std::min ({*min_x, down_left.x (), down_right.x (), up_left.x (), up_right.x ()});
409
+ *min_y = std::min ({*min_y, down_left.y (), down_right.y (), up_left.y (), up_right.y ()});
410
+ *max_x = std::max ({*max_x, down_left.x (), down_right.x (), up_left.x (), up_right.x ()});
411
+ *max_y = std::max ({*max_y, down_left.y (), down_right.y (), up_left.y (), up_right.y ()});
412
+ }
375
413
376
414
has_updated_data_ = false ;
377
415
0 commit comments