1 /* MainWindow for StellarSolver Tester Application, developed by Robert Lancaster, 2020 2 3 This application is free software; you can redistribute it and/or 4 modify it under the terms of the GNU General Public 5 License as published by the Free Software Foundation; either 6 version 2 of the License, or (at your option) any later version. 7 */ 8 #ifndef MAINWINDOW_H 9 #define MAINWINDOW_H 10 11 //Includes for this project 12 #include "structuredefinitions.h" 13 #include "stellarsolver.h" 14 #include "externalsextractorsolver.h" 15 #include "onlinesolver.h" 16 17 //system includes 18 #include "math.h" 19 20 #ifndef _MSC_VER 21 #include <sys/mman.h> 22 #endif 23 24 //QT Includes 25 #include <QMainWindow> 26 #include <QObject> 27 #include <QWidget> 28 #include <QDir> 29 #include <QFileDialog> 30 #include <QMessageBox> 31 #include <QTextStream> 32 #include <QProcess> 33 #include <QPointer> 34 #include <QScrollBar> 35 #include <QThread> 36 #include <QLineEdit> 37 #include <QElapsedTimer> 38 #include <QTimer> 39 #include <QTableWidget> 40 41 //CFitsio Includes 42 #include "longnam.h" 43 #include "fitsio.h" 44 45 //KStars related includes 46 #include "stretch.h" 47 #include "math.h" 48 #include "dms.h" 49 #include "bayer.h" 50 51 //Astrometry.net includes 52 extern "C"{ 53 #include "tic.h" 54 #include "os-features.h" 55 #include "fileutils.h" 56 #include "ioutils.h" 57 #include "bl.h" 58 #include "an-bool.h" 59 #include "solver.h" 60 #include "fitsioutils.h" 61 #include "blindutils.h" 62 #include "astrometry/blind.h" 63 #include "log.h" 64 #include "engine.h" 65 #include "gslutils.h" 66 #include "augment-xylist.h" 67 #include "anqfits.h" 68 #include "ioutils.h" 69 #include "fitsioutils.h" 70 #include "permutedsort.h" 71 #include "fitstable.h" 72 #include "sip_qfits.h" 73 #include "sip-utils.h" 74 #include "tabsort.h" 75 } 76 77 namespace Ui { 78 79 class MainWindow; 80 } 81 82 class MainWindow : public QMainWindow 83 { 84 Q_OBJECT 85 public: 86 explicit MainWindow(); 87 ~MainWindow(); 88 setStarList(QList<FITSImage::Star> starList)89 void setStarList(QList<FITSImage::Star> starList){stars = starList;}; 90 91 private: 92 Ui::MainWindow *ui; 93 94 std::unique_ptr<StellarSolver> stellarSolver; 95 QString fileToProcess; 96 QList<FITSImage::Star> stars; 97 int selectedStar; 98 99 QList<SSolver::Parameters> optionsList; 100 bool optionsAreSaved = true; 101 102 //Options for StellarSolver Tester 103 QString dirPath = QDir::homePath(); 104 bool hasHFRData = false; 105 bool hasWCSData = false; 106 bool showFluxInfo = false; 107 bool showStarShapeInfo = false; 108 bool showSextractorParams = false; 109 bool showAstrometryParams = false; 110 bool showSolutionDetails = true; 111 bool settingSubframe = false; 112 113 bool useSubframe = false; 114 QRect subframe; 115 116 SSolver::ProcessType processType; 117 SSolver::ExtractorType m_ExtractorType; 118 SSolver::SolverType solverType; 119 int profileSelection; 120 121 //This allows for averaging over multiple trials 122 int currentTrial = 0; 123 int numberOfTrials = 0; 124 double totalTime = 0; 125 126 //Data about the image 127 bool imageLoaded = false; 128 FITSImage::Statistic stats; 129 fitsfile *fptr { nullptr }; 130 QImage rawImage; 131 QImage scaledImage; 132 int currentWidth; 133 int currentHeight; 134 double currentZoom; 135 int sampling = 2; 136 /// Generic data image buffer 137 uint8_t *m_ImageBuffer { nullptr }; 138 /// Above buffer size in bytes 139 uint32_t m_ImageBufferSize { 0 }; 140 StretchParams stretchParams; 141 BayerParams debayerParams; 142 bool checkDebayer(); 143 144 QElapsedTimer processTimer; 145 QTimer timerMonitor; 146 double elapsed; 147 148 void setupResultsTable(); 149 void clearAstrometrySettings(); 150 void addSextractionToTable(); 151 FITSImage::Solution lastSolution; 152 153 FITSImage::wcs_point *wcs_coord { nullptr }; 154 155 QDialog *convInspector = nullptr; 156 QTableWidget *convTable = nullptr; 157 158 public slots: 159 160 bool prepareForProcesses(); 161 void logOutput(QString text); 162 void toggleLogDisplay(); 163 void toggleFullScreen(); 164 void helpPopup(); 165 void startProcessMonitor(); 166 void stopProcessMonitor(); 167 void clearStars(); 168 void clearResults(); 169 void loadOptionsProfile(); 170 void settingJustChanged(); 171 172 void loadIndexFilesList(); 173 void setSubframe(); 174 175 //These are the functions that run when the bottom buttons are clicked 176 void sextractButtonClicked(); 177 void solveButtonClicked(); 178 void sextractImage(); 179 void solveImage(); 180 181 void resetStellarSolver(); 182 183 void abort(); 184 185 //These functions are for loading and displaying the image 186 bool imageLoad(); 187 bool loadFits(); 188 bool loadOtherFormat(); 189 bool debayer(); 190 bool debayer_8bit(); 191 bool debayer_16bit(); 192 void initDisplayImage(); 193 void doStretch(QImage *outputImage); 194 void clearImageBuffers(); 195 196 void zoomIn(); 197 void zoomOut(); 198 void panLeft(); 199 void panRight(); 200 void panUp(); 201 void panDown(); 202 void autoScale(); 203 void updateImage(); 204 205 //These functions handle the star table 206 void displayTable(); 207 void sortStars(); 208 void starClickedInTable(); 209 void updateStarTableFromList(); 210 void updateHiddenStarTableColumns(); 211 void saveStarTable(); 212 213 void mouseMovedOverImage(QPoint location); 214 QString getValue(int x, int y); 215 void mouseClickedInImage(QPoint location); 216 void mousePressedInImage(QPoint location); 217 QRect getStarSizeInImage(FITSImage::Star star, bool &accurate); 218 219 void reloadConvTable(); 220 //This function is for loading and parsing the options 221 bool getSolverOptionsFromFITS(); 222 223 //These functions handle the settings for the Sextractors and Solvers 224 SSolver::Parameters getSettingsFromUI(); 225 void sendSettingsToUI(SSolver::Parameters a); 226 void setupExternalSextractorSolverIfNeeded(); 227 void setupStellarSolverParameters(); 228 229 //These functions get called when the sextractor or solver finishes 230 bool sextractorComplete(); 231 bool solverComplete(); 232 bool loadWCSComplete(); 233 234 //These functions handle the solution table 235 void addSolutionToTable(FITSImage::Solution solution); 236 void updateHiddenResultsTableColumns(); 237 void saveResultsTable(); 238 239 //These functions save and load the settings of the program. 240 void saveOptionsProfiles(); 241 void loadOptionsProfiles(); 242 void closeEvent(QCloseEvent *event); 243 signals: 244 void readyForStarTable(); 245 246 }; 247 248 #endif // MAINWINDOW_H 249