File indexing completed on 2024-04-28 11:25:55

0001 /*  KStars tests
0002     SPDX-FileCopyrightText: 2020 Eric Dejouhanet <eric.dejouhanet@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef TESTFITSDATA_H
0008 #define TESTFITSDATA_H
0009 
0010 #include <QObject>
0011 #include "fitsviewer/fitsdata.h"
0012 #include "ekos/auxiliary/solverutils.h"
0013 #include <QElapsedTimer>
0014 #include <QFutureWatcher>
0015 #include <QRandomGenerator>
0016 #include <memory>
0017 
0018 class TestFitsData : public QObject
0019 {
0020         Q_OBJECT
0021     public:
0022         explicit TestFitsData(QObject *parent = nullptr);
0023 
0024     private:
0025         void initGenericDataFixture();
0026 
0027     private slots:
0028         void initTestCase();
0029         void cleanupTestCase();
0030 
0031         void init();
0032         void cleanup();
0033 
0034         void testLoadFits_data();
0035         void testLoadFits();
0036 
0037         void testCentroidAlgorithmBenchmark_data();
0038         void testCentroidAlgorithmBenchmark();
0039 
0040         void testGradientAlgorithmBenchmark_data();
0041         void testGradientAlgorithmBenchmark();
0042 
0043         void testThresholdAlgorithmBenchmark_data();
0044         void testThresholdAlgorithmBenchmark();
0045 
0046         void testSEPAlgorithmBenchmark_data();
0047         void testSEPAlgorithmBenchmark();
0048 
0049         void testComputeHFR_data();
0050         void testComputeHFR();
0051 
0052         void testBahtinovFocusHFR_data();
0053         void testBahtinovFocusHFR();
0054 
0055         void testParallelSolvers();
0056     private:
0057         void startGuideDetect(const QString &filename);
0058         void guideLoadFinished();
0059         void guideDetectFinished();
0060 
0061         std::unique_ptr<FITSData> guideFits;
0062         QFuture<bool> guideFuture;
0063         QFutureWatcher<bool> guideWatcher;
0064         int numGuideDetects { 0 };
0065 };
0066 
0067 class SolverLoop : public QObject
0068 {
0069         Q_OBJECT
0070     public:
0071         SolverLoop(const QVector<QString> &files, const QString &dir, bool isDetecting, int numReps);
0072         void start();
0073         bool done() const;
0074         int upto() const;
0075         QString status() const;
0076         void setRandomAbort(double secs)
0077         {
0078             randomAbortSecs = secs;
0079         };
0080 
0081     private:
0082         void detectFinished();
0083         void startDetect(int index);
0084         void solverDone(bool timedOut, bool success, const FITSImage::Solution &solution, double elapsedSeconds);
0085         void timeout();
0086         void randomTimeout();
0087 
0088         QVector<QString> filenames;
0089         QString directory;
0090         QFuture<bool> future;
0091         QFutureWatcher<bool> watcher;
0092         int numDetects { 0 };
0093         int repetitions { 0 };
0094         bool detecting { true };
0095         QSharedPointer<SolverUtils> solver;
0096 
0097         int currentIndex { 0 };
0098         QVector<QSharedPointer<FITSData>> images;
0099         QSharedPointer<FITSData>thisImage;
0100         // Timer to measure how long detections take.
0101         QElapsedTimer dTimer;
0102         // generate a random timeout between 0 and this many elapsed seconds.
0103         double randomAbortSecs { 0 };
0104         // Timer that can randomly interrupt detections.
0105         QTimer randomAbortTimer;
0106         QRandomGenerator rand;
0107         // the random timeout being used now.
0108         double thisRandomTimeout { 0 };
0109 
0110         QTimer timer;
0111         int timeoutSecs { 30 };
0112 };
0113 
0114 #endif // TESTFITSDATA_H