Kstars

solverutils.h
1/*
2 SPDX-FileCopyrightText: 2022 Hy Murveit <hy@murveit.com>
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#include <QSharedPointer>
18
19#ifdef _WIN32
20#undef Unused
21#endif
22
23class FITSData;
24
25// This is a wrapper to make calling the StellarSolver solver a bit simpler.
26// Must supply the imagedata and stellar solver parameters
27// and connect to the signals. Remote solving not supported.
28class SolverUtils : public QObject
29{
31
32 public:
33 SolverUtils(const SSolver::Parameters &parameters, double timeoutSeconds = 15,
34 SSolver::ProcessType type = SSolver::SOLVE);
35 ~SolverUtils();
36
37 void runSolver(const QSharedPointer<FITSData> &data);
38 void runSolver(const QString &filename);
39 SolverUtils &useScale(bool useIt, double scaleLowArcsecPerPixel, double scaleHighArcsecPerPixel);
40 SolverUtils &usePosition(bool useIt, double raDegrees, double decDegrees);
41 bool isRunning() const;
42 void abort();
43
44 void setHealpix(int indexToUse = -1, int healpixToUse = -1);
45 void getSolutionHealpix(int *indexUsed, int *healpixUsed) const;
46
47 const FITSImage::Background &getBackground() const
48 {
49 // Better leak than crash. Warn?
50 if (!m_StellarSolver) return *new FITSImage::Background();
51 return m_StellarSolver->getBackground();
52 }
53 const QList<FITSImage::Star> &getStarList() const
54 {
55 // Better leak than crash. Warn?
56 if (!m_StellarSolver) return *new QList<FITSImage::Star>();
57 return m_StellarSolver->getStarList();
58 }
59 int getNumStarsFound() const
60 {
61 if (!m_StellarSolver) return 0;
62 return m_StellarSolver->getNumStarsFound();
63 };
64
65 // We don't trust StellarSolver's mutli-processing algorithm MULTI_DEPTHS which is used
66 // with multiAlgorithm==MULTI_AUTO && use_scale && !use_position. This disables that.
67 static void patchMultiAlgorithm(StellarSolver *solver);
68
69 signals:
70 void done(bool timedOut, bool success, const FITSImage::Solution &solution, double elapsedSeconds);
71 void newLog(const QString &logText);
72
73 private:
74 void solverDone();
75 void solverTimeout();
76 void executeSolver();
77 void prepareSolver();
78
79 std::unique_ptr<StellarSolver> m_StellarSolver;
80
81 qint64 m_StartTime;
82 QTimer m_SolverTimer;
83 // Copy of parameters
84 SSolver::Parameters m_Parameters;
85 // Solver timeout in milliseconds.
86 const uint32_t m_TimeoutMilliseconds {0};
87 // Temporary file name in case of external solver.
88 QString m_TemporaryFilename;
89 QFutureWatcher<bool> m_Watcher;
90 double m_ScaleLowArcsecPerPixel {0}, m_ScaleHighArcsecPerPixel {0};
91
92 QSharedPointer<FITSData> m_ImageData;
93
94 int m_IndexToUse { -1 };
95 int m_HealpixToUse { -1 };
96
97 bool m_UseScale { false };
98 bool m_UsePosition { false };
99 double m_raDegrees { 0.0 };
100 double m_decDegrees { 0.0 };
101
102 SSolver::ProcessType m_Type = SSolver::SOLVE;
103 std::mutex deleteSolverMutex;
104};
105
Q_OBJECTQ_OBJECT
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:38:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.