Add WCSData::calculateBounds
This commit is contained in:
+66
-12
@@ -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; x<w; x++)
|
||||
{
|
||||
update(QPointF(x, 0));
|
||||
update(QPointF(x, h - 1));
|
||||
}
|
||||
|
||||
for(int y=0; y<h; y++)
|
||||
{
|
||||
update(QPointF(0, y));
|
||||
update(QPointF(w - 1, y));
|
||||
}
|
||||
|
||||
QPointF ncp;
|
||||
QPointF scp;
|
||||
QRectF s(0, 0, w - 1, h - 1);
|
||||
if(worldToPixel(SkyPoint(0, 90), ncp))
|
||||
{
|
||||
if(s.contains(ncp))
|
||||
maxDec = 90;
|
||||
}
|
||||
|
||||
if(worldToPixel(SkyPoint(0, -90), scp))
|
||||
{
|
||||
if(s.contains(scp))
|
||||
minDec = -90;
|
||||
}
|
||||
}
|
||||
|
||||
SkyPoint::SkyPoint() : ra(NAN), dec(NAN)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SkyPoint::SkyPoint(double ra, double dec) : ra(ra), dec(dec)
|
||||
|
||||
Reference in New Issue
Block a user