Kstars

solverutils.h
1 /*
2  SPDX-FileCopyrightText: 2022 Hy Murveit <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include <stellarsolver.h>
10 
11 #include <QObject>
12 #include <QString>
13 #include <QTimer>
14 #include <QFutureWatcher>
15 #include <mutex>
16 #include <memory>
17 
18 #ifdef _WIN32
19 #undef Unused
20 #endif
21 
22 class FITSData;
23 
24 // This is a wrapper to make calling the StellarSolver solver a bit simpler.
25 // Must supply the imagedata and stellar solver parameters
26 // and connect to the signals. Remote solving not supported.
27 class SolverUtils : public QObject
28 {
29  Q_OBJECT
30 
31  public:
32  SolverUtils(const SSolver::Parameters &parameters, double timeoutSeconds = 15);
33  ~SolverUtils();
34 
35  void runSolver(const QSharedPointer<FITSData> &data);
36  void runSolver(const QString &filename);
37  SolverUtils &useScale(bool useIt, double scaleLowArcsecPerPixel, double scaleHighArcsecPerPixel);
38  SolverUtils &usePosition(bool useIt, double raDegrees, double decDegrees);
39  bool isRunning() const;
40  void abort();
41 
42  void setHealpix(int indexToUse = -1, int healpixToUse = -1);
43  void getSolutionHealpix(int *indexUsed, int *healpixUsed) const;
44 
45  /**
46  * @brief rotationToPositionAngle Convert from astrometry.net rotation to PA
47  * @param value rotation in degrees (-180 to +180)
48  * @return Position angle in degrees (-180 to +180)
49  */
50  static double rotationToPositionAngle(double value);
51 
52  /** @brief rotationToPositionAngle Convert from position angle to astrometry.net rotation
53  * @param value Position angle in degrees (-180 to +180)
54  * @return rotation in degrees (-180 to +180)
55  */
56  static double positionAngleToRotation(double value);
57 
58  /**
59  * @brief rangePA Limit any angle to fall between -180 to +180 degrees for position angle
60  * @param value angle
61  * @return angle limited to -180 to +180
62  */
63  static double rangePA(double value);
64 
65  signals:
66  void done(bool timedOut, bool success, const FITSImage::Solution &solution, double elapsedSeconds);
67  void newLog(const QString &logText);
68 
69  private:
70  void solverDone();
71  void solverTimeout();
72  void executeSolver();
73  void prepareSolver();
74 
75  std::unique_ptr<StellarSolver> m_StellarSolver;
76 
77  qint64 m_StartTime;
78  QTimer m_SolverTimer;
79  // Copy of parameters
80  SSolver::Parameters m_Parameters;
81  // Solver timeout in milliseconds.
82  const uint32_t m_TimeoutMilliseconds {0};
83  // Temporary file name in case of external solver.
84  QString m_TemporaryFilename;
85  QFutureWatcher<bool> m_Watcher;
86  double m_ScaleLowArcsecPerPixel {0}, m_ScaleHighArcsecPerPixel {0};
87 
88  QSharedPointer<FITSData> m_ImageData;
89 
90  int m_IndexToUse { -1 };
91  int m_HealpixToUse { -1 };
92 
93  bool m_UseScale { false };
94  bool m_UsePosition { false };
95  double m_raDegrees { 0.0 };
96  double m_decDegrees { 0.0 };
97 
98  std::mutex deleteSolverMutex;
99 };
100 
Q_OBJECTQ_OBJECT
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 12 2022 04:00:58 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.