Kstars

aberrationinspector.h
1/*
2 SPDX-FileCopyrightText: 2023 John Evans <john.e.evans.email@googlemail.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#pragma once
8
9#include <Q3DSurface>
10#include <QCustom3DLabel>
11
12#include "curvefit.h"
13#include "ui_aberrationinspector.h"
14#include "aberrationinspectorutils.h"
15
16// The AberrationInspector class manages the Aberration Inspector dialog.
17// Settings are managed in a global way, rather than per Optical Train which would be overkill. The approach is the same as Focus
18// using loadSettings, connectSettings & syncSettings.
19//
20// Aberration Inspector uses focus position of different parts of the sensor to examine backfocus and tilt. A single Autofocus run can
21// be used as the basis for the analysis.
22//
23// Note, Aberration Inspector assumes all focus differences between different tiles on the sensor are due to Backfocus and sensor tilt.
24// In reality many other aberrations (e.g. collimation, coma, etc.) could contribute to focus differences but are assumed to be negligible.
25// If other aberrations are significant then the analysis output of Aberration Inspector is likely to be invalid.
26//
27// Aberration Inspector can have 2 use cases:
28// 1. Analysis mode. Run the inspector and look at the output.
29// 2. Use the tool to help with adjustment of Backfocus and / or tilt with a device such as a PhotonCage or Octopi. In this mode, use of the
30// tool will be iterative. Run the tool, look at the output, make an adjustment for Backfocus and / or tilt, rerun the tool and compare
31// the new output. Make a further adjustment and repeat until happy with the output. For this reason, each time Aberration Inspector is
32// run, a new Aberration Inspector Dialog (with incrementing Run number) is launched allowing comparision of results.
33//
34// To invoke Aberration Inspector:
35// 1. Setup focus to give the consistently good focus results. Point to a part of the sky with lots of stars.
36// 2. Set the Mosaic Mask on and set it up so that there are sufficient stars in each tile. This is important as each tile
37// will be focused solved individually so there needs to be enough stars in each tile. Increase the tile size to get each tile to cover
38// more of the sensor and therefore contain more stars; but don't overdo it as the bigger the tile the less accurate the results.
39// 3. Run Autofocus manually by pressing the Auto Focus button. Note, Aberration Inspector is not run when Focus is run in a sequence.
40// 4. Autofocus will run normally but will collect data for Aberration Inspector for each datapoint. If the Focus run isn't good then
41// discard and retry. If basic Autofocus isn't good then Aberration Inspector will not be good.
42// 5. When Autofocus completes, the Aberration Inspector dialog is launched.
43// 6. To run Aberration Inspector again, simply rerun Autofocus.
44//
45// The Aberration Inspector dialog has 4 components:
46// 1. The v-curves. A curve is drawn for each tile dependent on the user setting of TileSelection. So either 5 or 9 curves are drawn.
47// Like Focus, the v-curve shows measure (e.g. HFR) on the y-axis versus focuser position on the x-axis
48// 2. A table of results from the v-curves. A row is displayed per tile showing v-curve solution and delta from central tile
49// 3. Analysis of results table. Here the deltas between the solve position for the central tile is compared with other tiles and used
50// to produce numbers for:
51// Backfocus - The idea is that if backfocus is perfect then the average of tile deltas from the centre will be zero.
52// Tilt - Differences in tile deltas when backfocus is compensated for, are due to tilt. The analyse works on 2 axes of tilt,
53// Left-to-Right and Top-to-Bottom.
54// 4. 3D Graphic. This helps to orient the user and explain the results. 2 Surfaces can be displayed:
55// Sensor - The sensor is drawn as a 3D plane to scale, with the tilt shown on the z-axis. Top, bottom, left and right are labelled.
56// Petzval Surface - This is light surface that comes out of the telescope and hits the sensor. The surface is drawn as a simple,
57// circularly symmetrical paraboloid. In reality, the light surface coming out of the field flattener may be much more
58// complex.
59// With the 3D graphic, it is possible to enter simulation mode, and adjust the Backfocus and tilt and see the effect on the Sensor and
60// Petzval surface.
61//
62
63#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
64using namespace QtDataVisualization;
65#endif
66
67namespace Ekos
68{
69
70class SensorGraphic;
71class AberrationInspectorPlot;
72
73class AberrationInspector : public QDialog, public Ui::aberrationInspectorDialog
74{
76
77 public:
78
79 typedef enum { TILES_ALL, TILES_OUTER_CORNERS, TILES_INNER_DIAMOND } TileSelection;
80 typedef struct
81 {
82 int run;
83 CurveFitting::CurveFit curveFit;
84 bool useWeights;
85 CurveFitting::OptimisationDirection optDir;
86 int sensorWidth;
87 int sensorHeight;
88 double pixelSize;
89 int tileWidth;
90 double focuserStepMicrons;
91 QString yAxisLabel;
92 double starUnits;
93 double cfzSteps;
94 bool isPositionBased;
95 } abInsData;
96
97 /**
98 * @brief create an AberrationInspector with the associated data
99 * @param data is a structure describing the curve fitting methods
100 * @param positions datapoints
101 * @param measures datapoints for each tile
102 * @param weights datapoints for each tile
103 */
104 AberrationInspector(const abInsData &data, const QVector<int> &positions, const QVector<QVector<double>> &measures,
105 const QVector<QVector<double>> &weights, const QVector<QVector<int>> &numStars,
106 const QVector<QPoint> &tileCenterOffset);
107 ~AberrationInspector();
108
109 private slots:
110 /**
111 * @brief mouse moved into table event. Used to show sensor graphic widget
112 * @param row
113 * @param column
114 */
115 void newMousePos(int row, int column);
116
117 /**
118 * @brief mouse left the table. Used to hide the sensor graphic widget
119 */
120 void leaveTableEvent();
121
122 /**
123 * @brief checkbox state changed event
124 * @param new state
125 */
126 void onStateChanged(int state);
127
128 /**
129 * @brief table cell changed
130 * @param new state
131 */
132 void onCellChanged(int row, int column);
133
134 private:
135 /**
136 * @brief setup elements of the GUI
137 */
138 void setupGUI();
139
140 /**
141 * @brief connect settings in order to persist changes
142 */
143 void connectSettings();
144
145 /**
146 * @brief load persisted settings
147 */
148 void loadSettings();
149
150 /**
151 * @brief persist settings
152 */
153 void syncSettings();
154
155 /**
156 * @brief initialise Aberration Inspector
157 */
158 void initAberrationInspector();
159
160 /**
161 * @brief fit v-curves for each tile and update other widgets with results
162 */
163 void fitCurves();
164
165 /**
166 * @brief initialise the 3D graphic
167 */
168 void initGraphic();
169
170 /**
171 * @brief setTileSelection combobox
172 * @param tileSelection
173 */
174 void setTileSelection(TileSelection tileSelection);
175
176 /**
177 * @brief setup an array of tiles to use / don't use
178 * @param tileSelection
179 */
180 void setupTiles(TileSelection tileSelection);
181
182 /**
183 * @brief update table widget as per user selection
184 */
185 void updateTable();
186
187 /**
188 * @brief analyse and display the results for backfocus and tilt
189 */
190 void analyseResults();
191
192 /**
193 * @brief 3D graphic sim mode toggled by user
194 * @param sim mode on / off
195 */
196 void simModeToggled(bool setting);
197
198 /**
199 * @brief update 3D graphic based on user selection
200 * @param tileSelection
201 */
202 void updateGraphic(TileSelection tileSelection);
203
204 /**
205 * @brief draw Sensor on 3D graphic
206 * @return success
207 */
208 bool processSensor();
209
210 /**
211 * @brief draw Sensor Labels on 3D graphic
212 */
213 void processSensorLabels();
214
215 /**
216 * @brief draw Petzval surface (light cone from flattener) on 3D graphic
217 * @param tileSelection
218 * @return success
219 */
220 bool processPetzval(TileSelection tileSelection);
221
222 /**
223 * @brief show / hide v-curve solution labels
224 * @param show / hide setting
225 */
226 void setShowLabels(bool setting);
227
228 /**
229 * @brief show / hide CFZ
230 * @param show / hide setting
231 */
232 void setShowCFZ(bool setting);
233
234 /**
235 * @brief Optimise tile centres based on weighted star position
236 * @param setting
237 */
238 void setOptCentres(bool setting);
239
240 /**
241 * @brief resize table based on contents
242 */
243 void tableResize();
244
245 /**
246 * @brief calculate backfocus based on user selection
247 * @param tileSelection
248 * @param calculated backfocusDelta
249 * @return success = true
250 */
251 bool calcBackfocusDelta(TileSelection tileSelection, double &backfocusDelta);
252
253 /**
254 * @brief calculate tilt based on user selection
255 * @return success = true
256 */
257 bool calcTilt();
258
259 /**
260 * @brief calculates average of 3 tile values
261 * @param tiles to average
262 * @param retured tile average
263 * @return success = true
264 */
265 bool avTiles(int tiles[3], double &average);
266
267 /**
268 * @brief set exclude tiles vector
269 * @param row
270 * @param checked
271 * @param tile selection
272 */
273 void setExcludeTile(int row, bool checked, TileSelection tileSelection);
274
275 /**
276 * @brief get tile from table row
277 * @param tileSelection
278 * @param row
279 * @return tile
280 */
281 int getTileFromRow(TileSelection tileSelection, int row);
282
283 /**
284 * @brief get the X,Y centre of the tile
285 * @param tile
286 * @return 2D vector of tile centre
287 */
288 QVector2D getXYTileCentre(tileID tile);
289
290 /**
291 * @brief get the label position for the passed in tile
292 * @param tile
293 * @return 3D vector of label position
294 */
295 QVector3D getLabelCentre(tileID tile);
296
297 /**
298 * @brief get the sensor vertex nearest the passed in tile
299 * @param tile
300 * @return 3D vector of sensor vertex
301 */
302 QVector3D getSensorVertex(tileID tile);
303
304 /**
305 * @brief get backspace adapted delta the passed in tile
306 * @param tile
307 * @return backspace adapted delta
308 */
309 double getBSDelta(tileID tile);
310 QVector3D rotatePoint(QVector3D point);
311
312 /**
313 * @brief simulation of backfocus changed
314 * @param value of slider
315 */
316 void simBackfocusChanged(int value);
317
318 /**
319 * @brief simulation of L-R tilt changed
320 * @param value of slider
321 */
322 void simLRTiltChanged(int value);
323
324 /**
325 * @brief simulation of T-B tilt changed
326 * @param value of slider
327 */
328 void simTBTiltChanged(int value);
329
330 abInsData m_data;
331 QVector<int> m_positions;
332 QVector<QVector<double>> m_measures;
333 QVector<QVector<double>> m_weights;
334 QVector<QVector<int>> m_numStars;
335 QVector<QPoint> m_tileOffsets;
336
337 // Which tiles to use
338 bool m_useTile[NUM_TILES] = { false, false, false, false, false, false, false, false, false };
339 bool m_excludeTile[NUM_TILES] = { false, false, false, false, false, false, false, false, false };
340
341 // Table
342 SensorGraphic *sensorGraphic { nullptr };
343 int m_HighlightedRow { -1 };
344
345 // Curve fitting
346 std::unique_ptr<CurveFitting> curveFitting;
347 QVector<int> m_minimum;
348 QVector<double> m_minMeasure;
349 QVector<bool> m_fit;
350 QVector<double> m_R2;
351
352 // Analysis - the folowing members are in microns
353 double m_backfocus = 0.0;
354 QVector<double> m_deltas;
355 double m_LRMicrons = 0.0;
356 double m_TBMicrons = 0.0;
357 double m_diagonalMicrons = 0.0;
358 // Tilts are in % slope
359 double m_LRTilt = 0.0;
360 double m_TBTilt = 0.0;
361 double m_diagonalTilt = 0.0;
362 bool m_resultsOK = false;
363
364 // Graphic simulation variables
365 bool m_simMode { false };
366 double m_simBackfocus { 0 };
367 double m_simLRTilt { 0 };
368 double m_simTBTilt { 0 };
369 float m_maxX { 0.0 };
370 float m_maxY { 0.0 };
371 float m_minZ { 0.0 };
372 float m_maxZ { 0.0 };
373
374 // Plot widget
375 AberrationInspectorPlot *m_plot;
376
377 // Graphic
378 Q3DSurface *m_graphic = nullptr;
379 QSurface3DSeries *m_sensor = nullptr;
380 QSurface3DSeries *m_petzval = nullptr;
381 QSurfaceDataProxy *m_sensorProxy = nullptr;
382 QSurfaceDataProxy *m_petzvalProxy = nullptr;
383 QCustom3DLabel *m_label[NUM_TILES] = { nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr };
384 bool m_graphicLabels { true };
385 bool m_graphicSensor { true };
386 bool m_graphicPetzvalWire { true };
387 bool m_graphicPetzvalSurface { false };
388};
389
390}
Ekos is an advanced Astrophotography tool for Linux.
Definition align.cpp:83
Q_OBJECTQ_OBJECT
QFuture< T > run(Function function,...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:16:40 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.