Kstars

guideview.cpp
1/* Ekos GuideView
2 Child of FITSView with few additions necessary for Internal Guider
3
4 SPDX-FileCopyrightText: 2020 Hy Murveit <hy@murveit.com>
5
6 SPDX-License-Identifier: GPL-2.0-or-later
7*/
8
9#include "guideview.h"
10#include "fitsviewer/fitsdata.h"
11
12#include <QPainter>
13#include <math.h>
14
15GuideView::GuideView(QWidget *parent, FITSMode mode, FITSScale filter) : FITSView(parent, mode, filter)
16{
17}
18
19void GuideView::updateNeighbors()
20{
21 if (newNeighbors)
22 updateFrame(true);
23}
24
25void GuideView::drawOverlay(QPainter *painter, double scale)
26{
27 Q_UNUSED(scale);
28
29 FITSView::drawOverlay(painter, getScale());
30
31 for (const auto &neighbor : neighbors)
32 drawNeighbor(painter, neighbor);
33 newNeighbors = false;
34
35}
36
37void GuideView::addGuideStarNeighbor(double targetX, double targetY, bool found,
38 double detectedX, double detectedY, bool isGuideStar)
39{
40 Neighbor n;
41 n.targetX = targetX;
42 n.targetY = targetY;
43 n.found = found;
44 n.detectedX = detectedX;
45 n.detectedY = detectedY;
46 n.isGuideStar = isGuideStar;
47 neighbors.append(n);
48 newNeighbors = true;
49}
50
51void GuideView::clearNeighbors()
52{
53 neighbors.clear();
54}
55
56// We draw a circle around each "neighbor" star and draw a line from the guide star to the neighbor
57// Which starts at the reticle around the guide star and ends at the circle around the neighbor.
58void GuideView::drawNeighbor(QPainter *painter, const Neighbor &neighbor)
59{
60 double origOpacity = painter->opacity();
61 QPen pen(neighbor.found ? Qt::green : Qt::red);
62 pen.setWidth(2);
63 pen.setStyle(Qt::SolidLine);
64 painter->setPen(pen);
65 painter->setBrush(Qt::NoBrush);
66 const double scale = getScale();
67
68 if (!neighbor.isGuideStar)
69 {
70 const QPointF center(neighbor.targetX * scale, neighbor.targetY * scale);
71
72 double rawRadius = 10;
73 if (imageData() != nullptr)
74 rawRadius = std::min(20.0, std::max(3.0, imageData()->width() / 150.0));
75
76 const double r = rawRadius * scale;
77 painter->drawEllipse(center, r, r);
78
79 const QRect &box = getTrackingBox();
80 const int x1 = (box.x() + box.width() / 2.0) * scale;
81 const int y1 = (box.y() + box.height() / 2.0) * scale;
82 painter->setOpacity(0.25);
83 const double dx = neighbor.targetX * scale - x1;
84 const double dy = neighbor.targetY * scale - y1;
85
86 const double lineLength = std::hypotf(fabs(dx), fabs(dy));
87
88 // f1 indicates the place along line between the guide star and the neighbor star
89 // where the line should start because it intersects the reticle box around the guide star.
90 double f1;
91 if (std::fabs(dx) > std::fabs(dy))
92 {
93 const double rBox = scale * box.width() / 2.0;
94 f1 = std::hypot(rBox, std::fabs(dy) * rBox / std::fabs(dx)) / lineLength;
95 }
96 else
97 {
98 const double rBox = scale * box.height() / 2.0;
99 f1 = std::hypotf(rBox, std::fabs(dx) * rBox / std::fabs(dy)) / lineLength;
100 }
101 // f2 indicates the place along line between the guide star and the neighbor star
102 // where the line should stop because it intersects the circle around the neighbor.
103 const double f2 = 1.0 - (r / lineLength);
104
106 painter->drawLine(x1 + dx * f1, y1 + dy * f1, x1 + dx * f2, y1 + dy * f2);
107 }
108 painter->setOpacity(origOpacity);
109}
void append(QList< T > &&value)
void clear()
void drawEllipse(const QPoint &center, int rx, int ry)
void drawLine(const QLine &line)
qreal opacity() const const
void setBrush(Qt::BrushStyle style)
void setOpacity(qreal opacity)
void setPen(Qt::PenStyle style)
void setWidth(int width)
SolidLine
QTextStream & center(QTextStream &stream)
QFuture< void > filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&filterFunction)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:19:02 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.