From 04e587b51cae6be6c903d09aae3d0e7c4435bbf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Poizl?= Date: Mon, 13 Jun 2022 23:28:39 +0200 Subject: [PATCH] Add WCSData::calculateBounds --- imageinfo.cpp | 78 ++++++++++++++++++++++++++++++++++++------- imageinfo.h | 7 ++-- imagescrollareagl.cpp | 6 ++-- loadrunable.cpp | 1 + 4 files changed, 74 insertions(+), 18 deletions(-) diff --git a/imageinfo.cpp b/imageinfo.cpp index 0ebacd5..5a3a159 100644 --- a/imageinfo.cpp +++ b/imageinfo.cpp @@ -79,9 +79,10 @@ WCSData::~WCSData() freeWCS(); } -SkyPoint WCSData::pixelToWorld(QPointF pixel) const +bool WCSData::pixelToWorld(const QPointF &pixel, SkyPoint &point) const { - if(wcs == nullptr)return SkyPoint(); + if(!valid())return false; + double pixcrd[2] = {pixel.x(), pixel.y()}; double imgcrd[8] = {0}; double phi = 0; @@ -91,27 +92,80 @@ SkyPoint WCSData::pixelToWorld(QPointF pixel) const int status = wcsp2s(wcs, 1, 2, pixcrd, imgcrd, &phi, &theta, world, stat); if(status == 0) { - return SkyPoint(world[0], world[1]); + point = SkyPoint(world[0], world[1]); + return true; } - return SkyPoint(); + return false; } -QPointF WCSData::worldToPixel(SkyPoint point) const +bool WCSData::worldToPixel(const SkyPoint &point, QPointF &pixel) const { - return QPointF(); + if(!valid())return false; + + double world[2] = {point.RA(), point.DEC()}; + double phi = 0; + double theta = 0; + double imgcrd[8] = {0}; + double pixcrd[8] = {0}; + int stat[NWCSFIX] = {0}; + int status = wcss2p(wcs, 1, 2, world, &phi, &theta, imgcrd, pixcrd, stat); + if(status == 0) + { + pixel = QPointF(pixcrd[0], pixcrd[1]); + return true; + } + return false; } -void WCSData::calculateBounds(double &minRa, double &maxRa, double &minDec, double &maxDec) +void WCSData::calculateBounds(int w, int h, double &minRa, double &maxRa, double &minDec, double &maxDec) { - minRa = -1000; - maxRa = 1000; - minDec = -1000; - maxDec = 1000; + if(wcs == nullptr)return; + + minRa = 1000; + maxRa = -1000; + minDec = 1000; + maxDec = -1000; + + auto update = [&](const QPointF &pixel) + { + SkyPoint point; + pixelToWorld(pixel, point); + minRa = std::min(minRa, point.RA()); + maxRa = std::max(maxRa, point.RA()); + minDec = std::min(minDec, point.DEC()); + maxDec = std::max(maxDec, point.DEC()); + }; + + for(int x=0; xbutton() == Qt::LeftButton && event->modifiers() & (Qt::ShiftModifier | Qt::ControlModifier)) + if(m_showThumbnails && event->button() == Qt::LeftButton && event->modifiers() & (Qt::ShiftModifier | Qt::ControlModifier)) m_selecting = true; if(m_selecting) @@ -448,7 +448,7 @@ void ImageWidget::mouseMoveEvent(QMouseEvent *event) else event->ignore(); - if(m_rawImage) + if(!m_showThumbnails && m_rawImage) { float dx = m_dx; float dy = m_dy; @@ -465,7 +465,7 @@ void ImageWidget::mouseMoveEvent(QMouseEvent *event) SkyPoint sky; if(m_wcs) { - sky = m_wcs->pixelToWorld(QPointF(pix.x(), pix.y())); + m_wcs->pixelToWorld(QPointF(pix.x(), pix.y()), sky); } if(m_rawImage->pixel(pix.x(), pix.y(), rgb)) diff --git a/loadrunable.cpp b/loadrunable.cpp index 5c2d415..c65a39d 100644 --- a/loadrunable.cpp +++ b/loadrunable.cpp @@ -174,6 +174,7 @@ int loadFITSHeader(fitsfile *file, ImageInfoData &info) if(status == 0) { info.wcs = std::make_shared(header, nrec); + if(!info.wcs->valid())info.wcs.reset(); } fits_free_memory(header, &status); return status;