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
63using namespace QtDataVisualization;
64
65namespace Ekos
66{
67
68class SensorGraphic;
69class AberrationInspectorPlot;
70
71class AberrationInspector : public QDialog, public Ui::aberrationInspectorDialog
72{
74
75 public:
76
77 typedef enum { TILES_ALL, TILES_OUTER_CORNERS, TILES_INNER_DIAMOND } TileSelection;
78 typedef struct
79 {
80 int run;
81 CurveFitting::CurveFit curveFit;
82 bool useWeights;
83 CurveFitting::OptimisationDirection optDir;
84 int sensorWidth;
85 int sensorHeight;
86 double pixelSize;
87 int tileWidth;
88 double focuserStepMicrons;
89 QString yAxisLabel;
90 double starUnits;
91 double cfzSteps;
92 bool isPositionBased;
93 } abInsData;
94
95 /**
96 * @brief create an AberrationInspector with the associated data
97 * @param data is a structure describing the curve fitting methods
98 * @param positions datapoints
99 * @param measures datapoints for each tile
100 * @param weights datapoints for each tile
101 */
102 AberrationInspector(const abInsData &data, const QVector<int> &positions, const QVector<QVector<double>> &measures,
103 const QVector<QVector<double>> &weights, const QVector<QVector<int>> &numStars,
105 ~AberrationInspector();
106
107 private slots:
108 /**
109 * @brief mouse moved into table event. Used to show sensor graphic widget
110 * @param row
111 * @param column
112 */
113 void newMousePos(int row, int column);
114
115 /**
116 * @brief mouse left the table. Used to hide the sensor graphic widget
117 */
118 void leaveTableEvent();
119
120 /**
121 * @brief checkbox state changed event
122 * @param new state
123 */
124 void onStateChanged(int state);
125
126 /**
127 * @brief table cell changed
128 * @param new state
129 */
130 void onCellChanged(int row, int column);
131
132 private:
133 /**
134 * @brief setup elements of the GUI
135 */
136 void setupGUI();
137
138 /**
139 * @brief connect settings in order to persist changes
140 */
141 void connectSettings();
142
143 /**
144 * @brief load persisted settings
145 */
146 void loadSettings();
147
148 /**
149 * @brief persist settings
150 */
151 void syncSettings();
152
153 /**
154 * @brief initialise Aberration Inspector
155 */
156 void initAberrationInspector();
157
158 /**
159 * @brief fit v-curves for each tile and update other widgets with results
160 */
161 void fitCurves();
162
163 /**
164 * @brief initialise the 3D graphic
165 */
166 void initGraphic();
167
168 /**
169 * @brief setTileSelection combobox
170 * @param tileSelection
171 */
172 void setTileSelection(TileSelection tileSelection);
173
174 /**
175 * @brief setup an array of tiles to use / don't use
176 * @param tileSelection
177 */
178 void setupTiles(TileSelection tileSelection);
179
180 /**
181 * @brief update table widget as per user selection
182 */
183 void updateTable();
184
185 /**
186 * @brief analyse and display the results for backfocus and tilt
187 */
188 void analyseResults();
189
190 /**
191 * @brief 3D graphic sim mode toggled by user
192 * @param sim mode on / off
193 */
194 void simModeToggled(bool setting);
195
196 /**
197 * @brief update 3D graphic based on user selection
198 * @param tileSelection
199 */
200 void updateGraphic(TileSelection tileSelection);
201
202 /**
203 * @brief draw Sensor on 3D graphic
204 * @return success
205 */
206 bool processSensor();
207
208 /**
209 * @brief draw Sensor Labels on 3D graphic
210 */
211 void processSensorLabels();
212
213 /**
214 * @brief draw Petzval surface (light cone from flattener) on 3D graphic
215 * @param tileSelection
216 * @return success
217 */
218 bool processPetzval(TileSelection tileSelection);
219
220 /**
221 * @brief show / hide v-curve solution labels
222 * @param show / hide setting
223 */
224 void setShowLabels(bool setting);
225
226 /**
227 * @brief show / hide CFZ
228 * @param show / hide setting
229 */
230 void setShowCFZ(bool setting);
231
232 /**
233 * @brief Optimise tile centres based on weighted star position
234 * @param setting
235 */
236 void setOptCentres(bool setting);
237
238 /**
239 * @brief resize table based on contents
240 */
241 void tableResize();
242
243 /**
244 * @brief calculate backfocus based on user selection
245 * @param tileSelection
246 * @param calculated backfocusDelta
247 * @return success = true
248 */
249 bool calcBackfocusDelta(TileSelection tileSelection, double &backfocusDelta);
250
251 /**
252 * @brief calculate tilt based on user selection
253 * @return success = true
254 */
255 bool calcTilt();
256
257 /**
258 * @brief calculates average of 3 tile values
259 * @param tiles to average
260 * @param retured tile average
261 * @return success = true
262 */
263 bool avTiles(int tiles[3], double &average);
264
265 /**
266 * @brief set exclude tiles vector
267 * @param row
268 * @param checked
269 * @param tile selection
270 */
271 void setExcludeTile(int row, bool checked, TileSelection tileSelection);
272
273 /**
274 * @brief get tile from table row
275 * @param tileSelection
276 * @param row
277 * @return tile
278 */
279 int getTileFromRow(TileSelection tileSelection, int row);
280
281 /**
282 * @brief get the X,Y centre of the tile
283 * @param tile
284 * @return 2D vector of tile centre
285 */
286 QVector2D getXYTileCentre(tileID tile);
287
288 /**
289 * @brief get the label position for the passed in tile
290 * @param tile
291 * @return 3D vector of label position
292 */
293 QVector3D getLabelCentre(tileID tile);
294
295 /**
296 * @brief get the sensor vertex nearest the passed in tile
297 * @param tile
298 * @return 3D vector of sensor vertex
299 */
300 QVector3D getSensorVertex(tileID tile);
301
302 /**
303 * @brief get backspace adapted delta the passed in tile
304 * @param tile
305 * @return backspace adapted delta
306 */
307 double getBSDelta(tileID tile);
308 QVector3D rotatePoint(QVector3D point);
309
310 /**
311 * @brief simulation of backfocus changed
312 * @param value of slider
313 */
314 void simBackfocusChanged(int value);
315
316 /**
317 * @brief simulation of L-R tilt changed
318 * @param value of slider
319 */
320 void simLRTiltChanged(int value);
321
322 /**
323 * @brief simulation of T-B tilt changed
324 * @param value of slider
325 */
326 void simTBTiltChanged(int value);
327
328 abInsData m_data;
329 QVector<int> m_positions;
330 QVector<QVector<double>> m_measures;
331 QVector<QVector<double>> m_weights;
332 QVector<QVector<int>> m_numStars;
333 QVector<QPoint> m_tileOffsets;
334
335 // Which tiles to use
336 bool m_useTile[NUM_TILES] = { false, false, false, false, false, false, false, false, false };
337 bool m_excludeTile[NUM_TILES] = { false, false, false, false, false, false, false, false, false };
338
339 // Table
340 SensorGraphic *sensorGraphic { nullptr };
341 int m_HighlightedRow { -1 };
342
343 // Curve fitting
344 std::unique_ptr<CurveFitting> curveFitting;
345 QVector<int> m_minimum;
346 QVector<double> m_minMeasure;
347 QVector<bool> m_fit;
348 QVector<double> m_R2;
349
350 // Analysis - the folowing members are in microns
351 double m_backfocus = 0.0;
352 QVector<double> m_deltas;
353 double m_LRMicrons = 0.0;
354 double m_TBMicrons = 0.0;
355 double m_diagonalMicrons = 0.0;
356 // Tilts are in % slope
357 double m_LRTilt = 0.0;
358 double m_TBTilt = 0.0;
359 double m_diagonalTilt = 0.0;
360 bool m_resultsOK = false;
361
362 // Graphic simulation variables
363 bool m_simMode { false };
364 double m_simBackfocus { 0 };
365 double m_simLRTilt { 0 };
366 double m_simTBTilt { 0 };
367 float m_maxX { 0.0 };
368 float m_maxY { 0.0 };
369 float m_minZ { 0.0 };
370 float m_maxZ { 0.0 };
371
372 // Plot widget
373 AberrationInspectorPlot *m_plot;
374
375 // Graphic
376 Q3DSurface *m_graphic = nullptr;
377 QSurface3DSeries *m_sensor = nullptr;
378 QSurface3DSeries *m_petzval = nullptr;
379 QSurfaceDataProxy *m_sensorProxy = nullptr;
380 QSurfaceDataProxy *m_petzvalProxy = nullptr;
381 QCustom3DLabel *m_label[NUM_TILES] = { nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr };
382 bool m_graphicLabels { true };
383 bool m_graphicSensor { true };
384 bool m_graphicPetzvalWire { true };
385 bool m_graphicPetzvalSurface { false };
386};
387
388}
Ekos is an advanced Astrophotography tool for Linux.
Definition align.cpp:79
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 Fri May 17 2024 11:48:25 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.