#include "imageinfo.h" #include #include #include #include #include static const QVector noEditableKey = {"SIMPLE", "BITPIX", "NAXIS", "NAXIS1", "NAXIS2", "NAXIS3", "EXTEND", "BZERO", "BSCALE"}; bool FITSRecord::editable() const { return noEditableKey.count(key); } ImageInfo::ImageInfo(QWidget *parent) : QTreeWidget(parent) { setColumnCount(3); setHeaderLabels({tr("Property"), tr("Value"), tr("Comment")}); setIndentation(5); QSettings settings; header()->restoreState(settings.value("imageinfo/headerstate").toByteArray()); } ImageInfo::~ImageInfo() { QSettings settings; settings.setValue("imageinfo/headerstate", header()->saveState()); } void ImageInfo::setInfo(const ImageInfoData &info) { clear(); if(info.fitsHeader.size()) { QTreeWidgetItem *fitsHeader = new QTreeWidgetItem({tr("FITS Header")}); for(const FITSRecord &record : info.fitsHeader) { new QTreeWidgetItem(fitsHeader, {record.key, record.value.toString(), record.comment}); } addTopLevelItem(fitsHeader); } if(info.info.size()) { QTreeWidgetItem *infoHeader = new QTreeWidgetItem({tr("Image info")}); for(auto &item : info.info) { new QTreeWidgetItem(infoHeader, {item.first, item.second}); } addTopLevelItem(infoHeader); } expandAll(); } void WCSData::freeWCS() { wcsvfree(&nwcs, &wcs); nwcs = 0; wcs = nullptr; } WCSData::WCSData(int width, int height, char *header, int nrec) : width(width), height(height) { int stat[NWCSFIX]; int nreject = 0; int status = wcspih(header, nrec, 1, 0, &nreject, &nwcs, &wcs); if(status != 0) { freeWCS(); return; } status = wcsfix(0, 0, wcs, stat); if(status != 0 || wcs->crpix[0] == 0) freeWCS(); } WCSData::~WCSData() { if(wcs) freeWCS(); } bool WCSData::pixelToWorld(const QPointF &pixel, SkyPoint &point) const { if(!valid())return false; double pixcrd[2] = {pixel.x(), pixel.y()}; double imgcrd[8] = {0}; double phi = 0; double theta = 0; double world[8] = {0}; int stat[NWCSFIX] = {0}; int status = wcsp2s(wcs, 1, 2, pixcrd, imgcrd, &phi, &theta, world, stat); if(status == 0) { point = SkyPoint(world[0], world[1]); return true; } return false; } bool WCSData::worldToPixel(const SkyPoint &point, QPointF &pixel) const { 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) const { 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; xra = ra; this->dec = dec; } QString SkyPoint::toString() const { if(std::isnan(ra) || std::isnan(dec)) return QString(); QTime t(0, 0); t = t.addSecs(ra * 240); double deg, min, sec; min = std::modf(dec, °) * 60; sec = std::modf(min, &min) * 60; return QString("RA: %1 DEC: %2° %3' %4\"").arg(t.toString("HH'h' mm'm' ss's'")).arg(deg, 2, 'f', 0, '0').arg(min, 2, 'f', 0, '0').arg(sec, 2, 'f', 0, '0'); }