Refractor drawing grid
This commit is contained in:
+10
-113
@@ -26,8 +26,6 @@ struct RawImageType
|
||||
QOpenGLTexture::PixelType dataType;
|
||||
};
|
||||
|
||||
void prepareGrid(WCSDataT *wcs, uint32_t w, uint32_t h, QPainterPath &grid, QPainterPath &text);
|
||||
|
||||
RawImageType getRawImageType(const RawImage *img)
|
||||
{
|
||||
RawImageType type;
|
||||
@@ -183,9 +181,9 @@ void ImageWidgetGL::setWCS(std::shared_ptr<WCSDataT> wcs)
|
||||
{
|
||||
m_wcs = wcs;
|
||||
m_grid.clear();
|
||||
m_text.clear();
|
||||
|
||||
if(m_drawGrid)
|
||||
prepareGrid(m_wcs.get(), m_imgWidth, m_imgHeight, m_grid, m_text);
|
||||
m_grid = m_wcs->prepareGrid(m_imgWidth, m_imgHeight);
|
||||
}
|
||||
|
||||
void ImageWidgetGL::zoom(int zoom, const QPointF &mousePos)
|
||||
@@ -502,111 +500,10 @@ void swPaint(std::shared_ptr<RawImage> &rawImage, float dx, float dy, float scal
|
||||
painter.drawImage(0, 0, img);
|
||||
}
|
||||
|
||||
void prepareGrid(WCSDataT *wcs, uint32_t w, uint32_t h, QPainterPath &grid, QPainterPath &text)
|
||||
{
|
||||
if(!wcs)return;
|
||||
|
||||
double minRa, maxRa, minDec, maxDec, crVal1, crVal2;
|
||||
wcs->calculateBounds(minRa, maxRa, minDec, maxDec, crVal1, crVal2);
|
||||
|
||||
double raStep = 15;
|
||||
double decStep = 15;
|
||||
double raRange = maxRa - minRa;
|
||||
double decRange = maxDec - minDec;
|
||||
const QVector<double> raSteps = {15, 5, 2.5, 1.25, 0.25, 20/240.0, 10/240.0, 5/240.0, 1/240.0};
|
||||
const QVector<double> decSteps = {20, 10, 5, 2, 1, 20/60.0, 10/60.0, 5/60.0, 2/60.0, 1/60.0, 20/3600.0, 10/3600.0, 5/3600.0, 2/3600.0, 1/3600.0};
|
||||
|
||||
for(double ra : raSteps)
|
||||
{
|
||||
if(ra * 5 <= raRange)
|
||||
{
|
||||
raStep = ra;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for(double dec : decSteps)
|
||||
{
|
||||
if(dec * 5 <= decRange)
|
||||
{
|
||||
decStep = dec;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
minRa -= std::fmod(minRa, raStep);
|
||||
minDec -= std::fmod(minDec, decStep);
|
||||
if(minRa < 0)minRa -= raStep;
|
||||
if(minDec < 0)minDec -= decStep;
|
||||
|
||||
QRectF clip(0, 0, w, h);
|
||||
|
||||
maxRa += raStep;
|
||||
maxDec += decStep;
|
||||
for(double ra = minRa; ra <= maxRa; ra += raStep)
|
||||
{
|
||||
QPointF p;
|
||||
wcs->worldToPixel(SkyPoint(ra, minDec), p);
|
||||
grid.moveTo(p);
|
||||
for(double dec = minDec + decStep * 0.02; dec <= maxDec; dec += decStep * 0.02)
|
||||
{
|
||||
wcs->worldToPixel(SkyPoint(ra, dec), p);
|
||||
grid.lineTo(p);
|
||||
}
|
||||
}
|
||||
|
||||
for(double dec = minDec; dec <= maxDec; dec += decStep)
|
||||
{
|
||||
QPointF p;
|
||||
wcs->worldToPixel(SkyPoint(minRa, dec), p);
|
||||
grid.moveTo(p);
|
||||
for(double ra = minRa + raStep * 0.02; ra <= maxRa; ra += raStep * 0.02)
|
||||
{
|
||||
wcs->worldToPixel(SkyPoint(ra, dec), p);
|
||||
grid.lineTo(p);
|
||||
}
|
||||
}
|
||||
|
||||
SkyPoint sp1, sp2,orig;
|
||||
wcs->pixelToWorld(QPointF(-1, -1), orig);
|
||||
sp1 = orig;
|
||||
QFont font("Sans", 12);
|
||||
for(uint32_t x = 0; x < w; x++)
|
||||
{
|
||||
QPointF p(x, 0);
|
||||
if(!wcs->pixelToWorld(p, sp2))
|
||||
break;
|
||||
|
||||
if(static_cast<int>(sp1.RA() / raStep) != static_cast<int>(sp2.RA() / raStep))
|
||||
text.addText(p + QPointF(0, 14), font, std::abs(sp1.RA()) > std::abs(sp2.RA()) ? sp1.RAString() : sp2.RAString());
|
||||
|
||||
if(static_cast<int>(sp1.DEC() / decStep) != static_cast<int>(sp2.DEC() / decStep))
|
||||
text.addText(p + QPointF(0, 14), font, std::abs(sp1.DEC()) > std::abs(sp2.DEC()) ? sp1.DECString() : sp2.DECString());
|
||||
|
||||
sp1 = sp2;
|
||||
}
|
||||
|
||||
sp1 = orig;
|
||||
for(uint32_t y = 0; y < h; y++)
|
||||
{
|
||||
QPointF p(0, y);
|
||||
if(!wcs->pixelToWorld(p, sp2))
|
||||
break;
|
||||
|
||||
if(static_cast<int>(sp1.RA() / raStep) != static_cast<int>(sp2.RA() / raStep))
|
||||
text.addText(p + QPointF(2, 0), font, std::abs(sp1.RA()) > std::abs(sp2.RA()) ? sp1.RAString() : sp2.RAString());
|
||||
|
||||
if(static_cast<int>(sp1.DEC() / decStep) != static_cast<int>(sp2.DEC() / decStep))
|
||||
text.addText(p + QPointF(2, 0), font, std::abs(sp1.DEC()) > std::abs(sp2.DEC()) ? sp1.DECString() : sp2.DECString());
|
||||
|
||||
sp1 = sp2;
|
||||
}
|
||||
}
|
||||
|
||||
void ImageWidgetGL::drawGrid(bool enable)
|
||||
{
|
||||
if(m_grid.elementCount() == 0)
|
||||
prepareGrid(m_wcs.get(), m_imgWidth, m_imgHeight, m_grid, m_text);
|
||||
if(m_grid.empty)
|
||||
m_grid = m_wcs->prepareGrid(m_imgWidth, m_imgHeight);
|
||||
|
||||
if(enable != m_drawGrid)
|
||||
{
|
||||
@@ -733,7 +630,7 @@ void ImageWidgetGL::paintGL()
|
||||
f->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
m_vao->release();
|
||||
|
||||
if(m_drawGrid)
|
||||
if(m_drawGrid && !m_grid.empty)
|
||||
{
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
@@ -745,12 +642,12 @@ void ImageWidgetGL::paintGL()
|
||||
tran.scale(m_scale, m_scale);
|
||||
painter.setTransform(tran);
|
||||
painter.setClipRect(0, 0, m_imgWidth, m_imgHeight);
|
||||
painter.drawPath(m_grid);
|
||||
painter.setPen(Qt::NoPen);
|
||||
painter.setBrush(Qt::yellow);
|
||||
painter.drawPath(m_text);
|
||||
painter.drawPath(m_grid.grid);
|
||||
painter.setPen(Qt::yellow);
|
||||
painter.setFont(QFont({"Arial", "Sans"}, 12 / m_scale));
|
||||
for(auto &text : m_grid.text)
|
||||
painter.drawText(QRectF(text.first, QSizeF(4000, 4000)), text.second);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user