From 59465fdd3fd46aaf75bb26d1b1e43bbf92db3e13 Mon Sep 17 00:00:00 2001 From: Shin Date: Thu, 5 Oct 2017 10:03:07 +0200 Subject: [PATCH 1/2] taking roi in cameraInfo in consideration when using camera_display plugin --- src/rviz/default_plugin/camera_display.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/rviz/default_plugin/camera_display.cpp b/src/rviz/default_plugin/camera_display.cpp index 1f08f097d2..5009e67e8c 100644 --- a/src/rviz/default_plugin/camera_display.cpp +++ b/src/rviz/default_plugin/camera_display.cpp @@ -490,8 +490,15 @@ bool CameraDisplay::updateCamera() #endif //adjust the image rectangles to fit the zoom & aspect ratio - bg_screen_rect_->setCorners( -1.0f*zoom_x, 1.0f*zoom_y, 1.0f*zoom_x, -1.0f*zoom_y ); - fg_screen_rect_->setCorners( -1.0f*zoom_x, 1.0f*zoom_y, 1.0f*zoom_x, -1.0f*zoom_y ); + //corners are computed according to roi + + double y_corner_start = (-2.0*info->roi.y_offset/info->height+1.0)*zoom_y; + double x_corner_start = (2.0*info->roi.x_offset/info->width-1.0)*zoom_x; + double y_corner_end = y_corner_start - (2.0*(info->roi.height == 0 ? info->height : info->roi.height)/info->height)*zoom_y; + double x_corner_end = x_corner_start + (2.0*(info->roi.width == 0 ? info->width : info->roi.width)/info->width)*zoom_x; + + bg_screen_rect_->setCorners( x_corner_start, y_corner_start, x_corner_end, y_corner_end); + fg_screen_rect_->setCorners( x_corner_start, y_corner_start, x_corner_end, y_corner_end); Ogre::AxisAlignedBox aabInf; aabInf.setInfinite(); From dd466dbd7b858ad4b40fad565b47e2d800de04f7 Mon Sep 17 00:00:00 2001 From: dhood Date: Mon, 18 Dec 2017 11:07:42 -0800 Subject: [PATCH 2/2] Keep simple logic for non-ROI case for readability --- src/rviz/default_plugin/camera_display.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/rviz/default_plugin/camera_display.cpp b/src/rviz/default_plugin/camera_display.cpp index 5009e67e8c..628d2c4853 100644 --- a/src/rviz/default_plugin/camera_display.cpp +++ b/src/rviz/default_plugin/camera_display.cpp @@ -490,12 +490,23 @@ bool CameraDisplay::updateCamera() #endif //adjust the image rectangles to fit the zoom & aspect ratio - //corners are computed according to roi + double x_corner_start, y_corner_start, x_corner_end, y_corner_end; - double y_corner_start = (-2.0*info->roi.y_offset/info->height+1.0)*zoom_y; - double x_corner_start = (2.0*info->roi.x_offset/info->width-1.0)*zoom_x; - double y_corner_end = y_corner_start - (2.0*(info->roi.height == 0 ? info->height : info->roi.height)/info->height)*zoom_y; - double x_corner_end = x_corner_start + (2.0*(info->roi.width == 0 ? info->width : info->roi.width)/info->width)*zoom_x; + if ( info->roi.height != 0 || info->roi.width != 0 ) + { + //corners are computed according to roi + x_corner_start = (2.0 * info->roi.x_offset / info->width - 1.0) * zoom_x; + y_corner_start = (-2.0 * info->roi.y_offset / info->height + 1.0) * zoom_y; + x_corner_end = x_corner_start + (2.0 * info->roi.width / info->width) * zoom_x; + y_corner_end = y_corner_start - (2.0 * info->roi.height / info->height) * zoom_y; + } + else + { + x_corner_start = -1.0f*zoom_x; + y_corner_start = 1.0f*zoom_y; + x_corner_end = 1.0f*zoom_x; + y_corner_end = -1.0f*zoom_y; + } bg_screen_rect_->setCorners( x_corner_start, y_corner_start, x_corner_end, y_corner_end); fg_screen_rect_->setCorners( x_corner_start, y_corner_start, x_corner_end, y_corner_end);