From 89fd01b5ff1bc474e1d56dfb0f55e5abaadb3d19 Mon Sep 17 00:00:00 2001 From: Bayram Yenikaya Date: Thu, 14 Mar 2024 08:32:40 -0700 Subject: [PATCH] fixed an issue with image display where image pixel size was not drawn correctly --- gui/polyView.cpp | 7 ++++--- gui/utils.cpp | 10 ++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/gui/polyView.cpp b/gui/polyView.cpp index eaafa0f..91e0201 100644 --- a/gui/polyView.cpp +++ b/gui/polyView.cpp @@ -444,10 +444,11 @@ void polyView::imageToScreenRect(// inputs utils::PositionedImage const& positioned_img, QRect & screenRect) { // output - std::vector x = {imageRect.left(), imageRect.right(), - imageRect.right(), imageRect.left()}; + // Increase the right and bottom by 1 seems to work properly for Qt image display + std::vector x = {imageRect.left(), imageRect.right()+1, + imageRect.right()+1, imageRect.left()}; std::vector y = {imageRect.top(), imageRect.top(), - imageRect.bottom(), imageRect.bottom()}; + imageRect.bottom()+1, imageRect.bottom()+1}; int big = std::numeric_limits::max(); int min_ix = big, min_iy = big, max_ix = -big, max_iy = -big; diff --git a/gui/utils.cpp b/gui/utils.cpp index 2839841..13d14cb 100644 --- a/gui/utils.cpp +++ b/gui/utils.cpp @@ -506,8 +506,9 @@ bool utils::readImagePosition(std::string const& filename, std::vector & // Convert from world coordinates to this image's pixel coordinates. void utils::worldToImage(double wx, double wy, utils::PositionedImage const& img, // inputs double & ix, double & iy) { // outputs - ix = (wx - img.pos[0]) / img.pos[2]; - iy = (wy - img.pos[1]) / img.pos[3]; + // half grid shift for pixel center + ix = (wx - img.pos[0] + img.pos[2]/2) / img.pos[2]; + iy = (wy - img.pos[1] + img.pos[3]/2) / img.pos[3]; // Flip in y iy = img.qimg.height() - 1 - iy; @@ -520,8 +521,9 @@ void utils::imageToWorld(double ix, double iy, utils::PositionedImage const& img // Flip in y iy = img.qimg.height() - 1 - iy; - wx = ix * img.pos[2] + img.pos[0]; - wy = iy * img.pos[3] + img.pos[1]; + // half grid shift for pixel center + wx = ix * img.pos[2] + img.pos[0] - img.pos[2]/2; + wy = iy * img.pos[3] + img.pos[1] - img.pos[3]/2; } // Find the box containing all polygons and images