Add parsing WCS info from XISF
This commit is contained in:
+43
-3
@@ -62,7 +62,6 @@ 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)
|
||||
@@ -70,8 +69,49 @@ WCSData::WCSData(int width, int height, char *header, int nrec) :
|
||||
freeWCS();
|
||||
return;
|
||||
}
|
||||
status = wcsfix(0, 0, wcs, stat);
|
||||
if(status != 0 || wcs->crpix[0] == 0)
|
||||
status = cdfix(wcs);
|
||||
if(status > 0 || wcs->crpix[0] == 0)
|
||||
freeWCS();
|
||||
}
|
||||
|
||||
WCSData::WCSData(int width, int height, const QVector<FITSRecord> &header) :
|
||||
width(width),
|
||||
height(height)
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
QByteArray str;
|
||||
int nrec = 1;
|
||||
for(const FITSRecord &record : header)
|
||||
{
|
||||
if(record.key.startsWith("PV"))continue;
|
||||
|
||||
QByteArray value = record.value.toString().toLatin1();
|
||||
if(value.startsWith('\'') && value.endsWith('\''))
|
||||
{
|
||||
value.chop(1);
|
||||
value = value.remove(0, 1);
|
||||
}
|
||||
QByteArray rec;
|
||||
rec.append(record.key.leftJustified(8, ' '));
|
||||
rec.append("= ");
|
||||
rec.append(value);
|
||||
rec.append(" / ");
|
||||
rec.append(record.comment);
|
||||
str.append(rec.leftJustified(80, ' ', true));
|
||||
nrec++;
|
||||
}
|
||||
str.append(QByteArray("END").leftJustified(80));
|
||||
|
||||
int nreject = 0;
|
||||
status = wcspih(str.data(), nrec, 1, 0, &nreject, &nwcs, &wcs);
|
||||
if(status != 0)
|
||||
{
|
||||
freeWCS();
|
||||
return;
|
||||
}
|
||||
status = cdfix(wcs);
|
||||
if(status > 0 || wcs->crpix[0] == 0)
|
||||
freeWCS();
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ class WCSData
|
||||
void freeWCS();
|
||||
public:
|
||||
WCSData(int width, int height, char *header, int nrec);
|
||||
WCSData(int width, int height, const QVector<FITSRecord> &header);
|
||||
WCSData(const WCSData &) = delete;
|
||||
~WCSData();
|
||||
bool pixelToWorld(const QPointF &pixel, SkyPoint &point) const;
|
||||
|
||||
+4
-1
@@ -325,6 +325,8 @@ bool loadXISF(const QString &path, ImageInfoData &info, RawImage **image)
|
||||
{
|
||||
info.fitsHeader.append({fits.name.c_str(), fits.value.IsNumeral() ? QVariant(fits.value.ToDouble()) : QVariant(fits.value.c_str()), fits.comment.c_str()});
|
||||
}
|
||||
info.wcs = std::make_shared<WCSData>(xisf.ImageInfo().width, xisf.ImageInfo().height, info.fitsHeader);
|
||||
if(!info.wcs->valid())info.wcs.reset();
|
||||
|
||||
if(floatType && bps == 32)
|
||||
return loadPCLImage<float, pcl::FImage, CV_32F>(xisf, image);
|
||||
@@ -337,7 +339,6 @@ bool loadXISF(const QString &path, ImageInfoData &info, RawImage **image)
|
||||
case 16:
|
||||
return loadPCLImage<uint16_t, pcl::UInt16Image, CV_16U>(xisf, image);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
catch (pcl::Error err)
|
||||
@@ -500,6 +501,8 @@ bool readXISFHeader(const QString &path, ImageInfoData &info)
|
||||
{
|
||||
info.fitsHeader.append({fits.name.c_str(), fits.value.IsNumeral() ? QVariant(fits.value.ToDouble()) : QVariant(fits.value.c_str()), fits.comment.c_str()});
|
||||
}
|
||||
info.wcs = std::make_shared<WCSData>(xisf.ImageInfo().width, xisf.ImageInfo().height, info.fitsHeader);
|
||||
if(!info.wcs->valid())info.wcs.reset();
|
||||
}
|
||||
catch (pcl::Error err)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user