Changeset View
Changeset View
Standalone View
Standalone View
kstars/fitsviewer/fitsdata.h
Show All 17 Lines | |||||
18 | ***************************************************************************/ | 18 | ***************************************************************************/ | ||
19 | 19 | | |||
20 | #pragma once | 20 | #pragma once | ||
21 | 21 | | |||
22 | #include "config-kstars.h" | 22 | #include "config-kstars.h" | ||
23 | 23 | | |||
24 | #include "bayer.h" | 24 | #include "bayer.h" | ||
25 | #include "fitscommon.h" | 25 | #include "fitscommon.h" | ||
26 | #include "fitsstardetector.h" | ||||
26 | 27 | | |||
27 | #ifdef WIN32 | 28 | #ifdef WIN32 | ||
28 | // This header must be included before fitsio.h to avoid compiler errors with Visual Studio | 29 | // This header must be included before fitsio.h to avoid compiler errors with Visual Studio | ||
29 | #include <windows.h> | 30 | #include <windows.h> | ||
30 | #endif | 31 | #endif | ||
31 | 32 | | |||
32 | #include <fitsio.h> | 33 | #include <fitsio.h> | ||
33 | 34 | | |||
34 | #include <QFuture> | 35 | #include <QFuture> | ||
35 | #include <QObject> | 36 | #include <QObject> | ||
36 | #include <QRect> | 37 | #include <QRect> | ||
37 | #include <QVariant> | 38 | #include <QVariant> | ||
38 | 39 | | |||
39 | #ifndef KSTARS_LITE | 40 | #ifndef KSTARS_LITE | ||
40 | #include <kxmlguiwindow.h> | 41 | #include <kxmlguiwindow.h> | ||
41 | #ifdef HAVE_WCSLIB | 42 | #ifdef HAVE_WCSLIB | ||
42 | #include <wcs.h> | 43 | #include <wcs.h> | ||
43 | #endif | 44 | #endif | ||
44 | #endif | 45 | #endif | ||
45 | 46 | | |||
46 | #define MINIMUM_PIXEL_RANGE 5 | | |||
47 | #define MINIMUM_STDVAR 5 | | |||
48 | | ||||
49 | class QProgressDialog; | 47 | class QProgressDialog; | ||
50 | 48 | | |||
51 | class SkyObject; | 49 | class SkyObject; | ||
52 | class SkyPoint; | 50 | class SkyPoint; | ||
53 | class FITSHistogram; | 51 | class FITSHistogram; | ||
54 | 52 | | |||
55 | typedef struct | 53 | typedef struct | ||
56 | { | 54 | { | ||
57 | float ra; | 55 | float ra; | ||
58 | float dec; | 56 | float dec; | ||
59 | } wcs_point; | 57 | } wcs_point; | ||
60 | 58 | | |||
61 | class Edge | 59 | class Edge; | ||
62 | { | | |||
63 | public: | | |||
64 | float x; | | |||
65 | float y; | | |||
66 | int val; | | |||
67 | int scanned; | | |||
68 | float width; | | |||
69 | float HFR; | | |||
70 | float sum; | | |||
71 | }; | | |||
72 | 60 | | |||
73 | class FITSSkyObject : public QObject | 61 | class FITSSkyObject : public QObject | ||
74 | { | 62 | { | ||
75 | Q_OBJECT | 63 | Q_OBJECT | ||
76 | public: | 64 | public: | ||
77 | explicit FITSSkyObject(SkyObject *object, int xPos, int yPos); | 65 | explicit FITSSkyObject(SkyObject *object, int xPos, int yPos); | ||
78 | SkyObject *skyObject(); | 66 | SkyObject *skyObject(); | ||
79 | int x(); | 67 | int x(); | ||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Line(s) | 103 | public: | |||
167 | /* Calculate stats */ | 155 | /* Calculate stats */ | ||
168 | void calculateStats(bool refresh = false); | 156 | void calculateStats(bool refresh = false); | ||
169 | /* Check if a particular point exists within the image */ | 157 | /* Check if a particular point exists within the image */ | ||
170 | bool contains(const QPointF &point) const; | 158 | bool contains(const QPointF &point) const; | ||
171 | 159 | | |||
172 | // Access functions | 160 | // Access functions | ||
173 | void clearImageBuffers(); | 161 | void clearImageBuffers(); | ||
174 | void setImageBuffer(uint8_t *buffer); | 162 | void setImageBuffer(uint8_t *buffer); | ||
175 | uint8_t *getImageBuffer(); | 163 | uint8_t const *getImageBuffer() const; | ||
164 | uint8_t *getWritableImageBuffer(); | ||||
176 | 165 | | |||
177 | // Statistics | 166 | // Statistics | ||
178 | void saveStatistics(Statistic &other); | 167 | void saveStatistics(Statistic &other); | ||
179 | void restoreStatistics(Statistic &other); | 168 | void restoreStatistics(Statistic &other); | ||
169 | Statistic const &getStatistics() const { return stats; }; | ||||
180 | 170 | | |||
181 | uint16_t width() const | 171 | uint16_t width() const | ||
182 | { | 172 | { | ||
183 | return stats.width; | 173 | return stats.width; | ||
184 | } | 174 | } | ||
185 | uint16_t height() const | 175 | uint16_t height() const | ||
186 | { | 176 | { | ||
187 | return stats.height; | 177 | return stats.height; | ||
▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Line(s) | |||||
282 | QList<Edge *> getStarCenters() const | 272 | QList<Edge *> getStarCenters() const | ||
283 | { | 273 | { | ||
284 | return starCenters; | 274 | return starCenters; | ||
285 | } | 275 | } | ||
286 | QList<Edge *> getStarCentersInSubFrame(QRect subFrame) const; | 276 | QList<Edge *> getStarCentersInSubFrame(QRect subFrame) const; | ||
287 | 277 | | |||
288 | int findStars(StarAlgorithm algorithm = ALGORITHM_CENTROID, const QRect &trackingBox = QRect()); | 278 | int findStars(StarAlgorithm algorithm = ALGORITHM_CENTROID, const QRect &trackingBox = QRect()); | ||
289 | 279 | | |||
290 | void getCenterSelection(int *x, int *y); | | |||
291 | int findOneStar(const QRect &boundary); | | |||
292 | | ||||
293 | // Star Detection - Partially customized Canny edge detection algorithm | | |||
294 | static int findCannyStar(FITSData *data, const QRect &boundary = QRect()); | | |||
295 | template <typename T> | | |||
296 | static int findCannyStar(FITSData *data, const QRect &boundary); | | |||
297 | | ||||
298 | // Use SEP (Sextractor Library) to find stars | 280 | // Use SEP (Sextractor Library) to find stars | ||
299 | template <typename T> | 281 | template <typename T> | ||
300 | void getFloatBuffer(float *buffer, int x, int y, int w, int h); | 282 | void getFloatBuffer(float *buffer, int x, int y, int w, int h) const; | ||
301 | int findSEPStars(const QRect &boundary = QRect()); | 283 | int findSEPStars(QList<Edge*>&, const QRect &boundary = QRect()) const; | ||
302 | 284 | | |||
303 | // Apply ring filter to searched stars | 285 | // Apply ring filter to searched stars | ||
304 | int filterStars(const float innerRadius, const float outerRadius); | 286 | int filterStars(const float innerRadius, const float outerRadius); | ||
305 | 287 | | |||
306 | // Half Flux Radius | 288 | // Half Flux Radius | ||
307 | Edge *getMaxHFRStar() const | 289 | Edge *getMaxHFRStar() const | ||
308 | { | 290 | { | ||
309 | return maxHFRStar; | 291 | return maxHFRStar; | ||
▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Line(s) | 400 | #endif | |||
438 | 420 | | |||
439 | signals: | 421 | signals: | ||
440 | void converted(QImage); | 422 | void converted(QImage); | ||
441 | 423 | | |||
442 | private: | 424 | private: | ||
443 | void loadCommon(const QString &inFilename); | 425 | void loadCommon(const QString &inFilename); | ||
444 | bool privateLoad(void *fits_buffer, size_t fits_buffer_size, bool silent); | 426 | bool privateLoad(void *fits_buffer, size_t fits_buffer_size, bool silent); | ||
445 | void rotWCSFITS(int angle, int mirror); | 427 | void rotWCSFITS(int angle, int mirror); | ||
446 | bool checkCollision(Edge *s1, Edge *s2); | | |||
447 | int calculateMinMax(bool refresh = false); | 428 | int calculateMinMax(bool refresh = false); | ||
448 | bool checkDebayer(); | 429 | bool checkDebayer(); | ||
449 | void readWCSKeys(); | 430 | void readWCSKeys(); | ||
450 | 431 | | |||
451 | // FITS Record | 432 | // FITS Record | ||
452 | bool parseHeader(); | 433 | bool parseHeader(); | ||
453 | //int getFITSRecord(QString &recordList, int &nkeys); | 434 | //int getFITSRecord(QString &recordList, int &nkeys); | ||
454 | 435 | | |||
455 | // Templated functions | 436 | // Templated functions | ||
456 | template <typename T> | 437 | template <typename T> | ||
457 | bool debayer(); | 438 | bool debayer(); | ||
458 | 439 | | |||
459 | template <typename T> | 440 | template <typename T> | ||
460 | bool rotFITS(int rotate, int mirror); | 441 | bool rotFITS(int rotate, int mirror); | ||
461 | 442 | | |||
462 | // Apply Filter | 443 | // Apply Filter | ||
463 | template <typename T> | 444 | template <typename T> | ||
464 | void applyFilter(FITSScale type, uint8_t *targetImage, QVector<double> * min = nullptr, QVector<double> * max = nullptr); | 445 | void applyFilter(FITSScale type, uint8_t *targetImage, QVector<double> * min = nullptr, QVector<double> * max = nullptr); | ||
465 | // Star Detect - Centroid | | |||
466 | template <typename T> | | |||
467 | int findCentroid(const QRect &boundary, int initStdDev, int minEdgeWidth); | | |||
468 | int findCentroid(const QRect &boundary = QRect(), int initStdDev = MINIMUM_STDVAR, | | |||
469 | int minEdgeWidth = MINIMUM_PIXEL_RANGE); | | |||
470 | // Star Detect - Threshold | | |||
471 | template <typename T> | | |||
472 | int findOneStar(const QRect &boundary); | | |||
473 | 446 | | |||
474 | template <typename T> | 447 | template <typename T> | ||
475 | void calculateMinMax(); | 448 | void calculateMinMax(); | ||
476 | 449 | | |||
477 | template <typename T> | 450 | template <typename T> | ||
478 | QPair<T, T> getParitionMinMax(uint32_t start, uint32_t stride); | 451 | QPair<T, T> getParitionMinMax(uint32_t start, uint32_t stride); | ||
479 | 452 | | |||
480 | /* Calculate running average & standard deviation using Welford’s method for computing variance */ | 453 | /* Calculate running average & standard deviation using Welford’s method for computing variance */ | ||
481 | template <typename T> | 454 | template <typename T> | ||
482 | void runningAverageStdDev(); | 455 | void runningAverageStdDev(); | ||
483 | template <typename T> | 456 | template <typename T> | ||
484 | QPair<double, double> getSquaredSumAndMean(uint32_t start, uint32_t stride); | 457 | QPair<double, double> getSquaredSumAndMean(uint32_t start, uint32_t stride); | ||
485 | 458 | | |||
486 | // Sobel detector by Gonzalo Exequiel Pedone | | |||
487 | template <typename T> | | |||
488 | void sobel(QVector<float> &gradient, QVector<float> &direction); | | |||
489 | | ||||
490 | template <typename T> | 459 | template <typename T> | ||
491 | void convertToQImage(double dataMin, double dataMax, double scale, double zero, QImage &image); | 460 | void convertToQImage(double dataMin, double dataMax, double scale, double zero, QImage &image); | ||
492 | 461 | | |||
493 | // Give unique IDs to each contiguous region | | |||
494 | int partition(int width, int height, QVector<float> &gradient, QVector<int> &ids); | | |||
495 | void trace(int width, int height, int id, QVector<float> &image, QVector<int> &ids, int x, int y); | | |||
496 | | ||||
497 | #ifndef KSTARS_LITE | 462 | #ifndef KSTARS_LITE | ||
498 | FITSHistogram *histogram { nullptr }; // Pointer to the FITS data histogram | 463 | FITSHistogram *histogram { nullptr }; // Pointer to the FITS data histogram | ||
499 | #endif | 464 | #endif | ||
500 | /// Pointer to CFITSIO FITS file struct | 465 | /// Pointer to CFITSIO FITS file struct | ||
501 | fitsfile *fptr { nullptr }; | 466 | fitsfile *fptr { nullptr }; | ||
502 | 467 | | |||
503 | /// FITS image data type (TBYTE, TUSHORT, TINT, TFLOAT, TLONG, TDOUBLE) | 468 | /// FITS image data type (TBYTE, TUSHORT, TINT, TFLOAT, TLONG, TDOUBLE) | ||
504 | uint32_t m_DataType { 0 }; | 469 | uint32_t m_DataType { 0 }; | ||
▲ Show 20 Lines • Show All 65 Lines • Show Last 20 Lines |