12#include "config-kstars.h"
15#ifdef HAVE_STELLARSOLVER
16#include <structuredefinitions.h>
18#include "structuredefinitions.h"
21#include "kstarsdatetime.h"
23#include "skybackground.h"
24#include "fitscommon.h"
25#include "fitsstardetector.h"
26#include "auxiliary/imagemask.h"
39#include <QTemporaryFile>
40#include <QNetworkReply>
44#include <kxmlguiwindow.h>
50#include "fitsskyobject.h"
55class FITSHistogramData;
84 explicit FITSData(FITSMode fitsMode = FITS_NORMAL);
123 bool loadFromBuffer(
const QByteArray &buffer);
130 bool parseSolution(FITSImage::Solution &solution)
const;
133 bool saveImage(
const QString &newFilename);
136 void clearImageBuffers();
137 void setImageBuffer(uint8_t *buffer);
138 uint8_t
const *getImageBuffer()
const;
139 uint8_t *getWritableImageBuffer();
147 void calculateStats(
bool refresh =
false,
bool roi =
false);
148 void saveStatistics(FITSImage::Statistic &other);
149 void restoreStatistics(FITSImage::Statistic &other);
150 FITSImage::Statistic
const &getStatistics()
const
155 uint16_t width(
bool roi =
false)
const
157 return roi ? m_ROIStatistics.width : m_Statistics.width;
159 uint16_t height(
bool roi =
false)
const
161 return roi ? m_ROIStatistics.height : m_Statistics.height;
163 int64_t size(
bool roi =
false)
const
165 return roi ? m_ROIStatistics.size : m_Statistics.size;
169 return m_Statistics.channels;
171 uint32_t samplesPerChannel(
bool roi =
false)
const
173 return roi ? m_ROIStatistics.samples_per_channel : m_Statistics.samples_per_channel;
175 uint32_t dataType()
const
177 return m_Statistics.dataType;
179 double getMin(uint8_t channel = 0,
bool roi =
false)
const
181 return roi ? m_ROIStatistics.min[channel] : m_Statistics.min[channel];
183 double getMax(uint8_t channel = 0,
bool roi =
false)
const
185 return roi ? m_ROIStatistics.max[channel] : m_Statistics.max[channel];
188 void setMinMax(
double newMin,
double newMax, uint8_t channel = 0);
189 void getMinMax(
double *min,
double *max, uint8_t channel = 0)
const
191 *min = m_Statistics.min[channel];
192 *max = m_Statistics.max[channel];
194 void setStdDev(
double value, uint8_t channel = 0)
196 m_Statistics.stddev[channel] = value;
198 double getStdDev(uint8_t channel = 0,
bool roi =
false )
const
200 return roi ? m_ROIStatistics.stddev[channel] : m_Statistics.stddev[channel];
202 double getAverageStdDev(
bool roi =
false)
const;
203 void setMean(
double value, uint8_t channel = 0)
205 m_Statistics.mean[channel] = value;
207 double getMean(uint8_t channel = 0,
bool roi =
false)
const
209 return roi ? m_ROIStatistics.mean[channel] : m_Statistics.mean[channel];
213 double getAverageMean(
bool roi =
false)
const;
214 void setMedian(
double val, uint8_t channel = 0)
216 m_Statistics.median[channel] = val;
220 double getAverageMedian(
bool roi =
false)
const;
221 double getMedian(uint8_t channel = 0,
bool roi =
false)
const
223 return roi ? m_ROIStatistics.median[channel] : m_Statistics.median[channel];
226 int getBytesPerPixel()
const
228 return m_Statistics.bytesPerPixel;
230 void setSNR(
double val)
232 m_Statistics.SNR = val;
234 double getSNR()
const
236 return m_Statistics.SNR;
240 switch(m_Statistics.dataType)
258 double getADU()
const;
270 return m_HeaderRecords;
279 void setStarAlgorithm(StarAlgorithm algorithm)
281 starAlgorithm = algorithm;
283 int getDetectedStars()
const
285 return starCenters.
count();
287 bool areStarsSearched()
const
289 return starsSearched;
291 void appendStar(Edge *newCenter)
293 starCenters.
append(newCenter);
303 qDeleteAll(starCenters);
304 starCenters = centers;
308 void setSkyBackground(
const SkyBackground &bg)
310 m_SkyBackground = bg;
312 const SkyBackground &getSkyBackground()
const
314 return m_SkyBackground;
316 const QVariantMap &getSourceExtractorSettings()
const
318 return m_SourceExtractorSettings;
320 void setSourceExtractorSettings(
const QVariantMap &settings)
322 m_SourceExtractorSettings = settings;
325 template <
typename T>
326 void getFloatBuffer(
float *buffer,
int x,
int y,
int w,
int h)
const;
333 const Edge &getSelectedHFRStar()
const
335 return m_SelectedHFRStar;
339 double getEccentricity();
341 double getHFR(HFRType type = HFR_AVERAGE);
342 double getHFR(
int x,
int y,
double scale = 1.0);
361 const QPoint getRoiCenter()
const
366 void setRoiCenter(
QPoint c)
377 bool contains(
const QPointF &point)
const;
386 WCSState getWCSState()
const
416 void injectWCS(
double orientation,
double ra,
double dec,
double pixscale,
bool eastToTheRight);
435 bool debayer(
bool reload =
false);
437 bool debayer_16bit();
438 void getBayerParams(BayerParams *param);
439 void setBayerParams(BayerParams *param);
447 void resetHistogram()
449 m_HistogramConstructed =
false;
451 double getHistogramBinWidth(
int channel = 0)
453 return m_HistogramBinWidth[channel];
459 return m_CumulativeFrequency[channel];
464 const QVector<double> &getHistogramIntensity(uint8_t channel = 0)
const
466 return m_HistogramIntensity[channel];
468 const QVector<double> &getHistogramFrequency(uint8_t channel = 0)
const
470 return m_HistogramFrequency[channel];
472 int getHistogramBinCount()
const
474 return m_HistogramBinCount;
478 int32_t histogramBin(
int x,
int y,
int channel)
const;
484 double getJMIndex()
const
489 bool isHistogramConstructed()
const
491 return m_HistogramConstructed;
493 void constructHistogram();
501 void applyFilter(FITSScale type, uint8_t *image =
nullptr,
QVector<double> *targetMin =
nullptr,
505 int getRotCounter()
const;
506 void setRotCounter(
int value);
509 const QString &filename()
const
513 void setFilename(
QString &filename)
515 m_Filename = filename;
517 const QString &compressedFilename()
const
519 return m_compressedFilename;
521 bool isCompressed()
const
523 return m_isCompressed;
526 const QString &extension()
const
530 void setExtension(
const QString &extension)
532 m_Extension = extension;
536 int getFlipHCounter()
const;
537 void setFlipHCounter(
int value);
540 int getFlipVCounter()
const;
541 void setFlipVCounter(
int value);
553 bool searchObjects();
557 bool searchCatObjects();
570 int catROIRadius()
const
572 return m_CatROIRadius;
575 bool findWCSBounds(
double &minRA,
double &maxRA,
double &minDec,
double &maxDec);
583 void setCatSearchROI(
const QPoint searchCenter,
const int radius);
606 return m_CatObjectsFilters;
612 void setCatObjectsFilters(
const QStringList filters);
617 const bool &getCatQueryInProgress()
const
619 return m_CatQueryInProgress;
626 bool highlightCatObject(
const int hilite,
const int lolite);
630 void filterCatObjects();
657 static bool readableFilename(
const QString &filename);
665 void histogramReady();
675 void headerChanged();
680 void loadingCatalogData();
684 void loadedCatalogData();
689 void catalogQueryFailed(
const QString text);
692 void makeRoiBuffer(
QRect roi);
695 void loadCommon(
const QString &inFilename);
704 bool loadCanonicalImage(
const QByteArray &buffer);
706 bool loadFITSImage(
const QByteArray &buffer,
const bool isCompressed =
false);
710 bool saveXISFImage(
const QString &newFilename);
714 void rotWCSFITS(
int angle,
int mirror);
715 void calculateMinMax(
bool refresh =
false,
bool roi =
false);
716 void calculateMedian(
bool refresh =
false,
bool roi =
false);
728 void updateWCSHeaderData(
const double orientation,
const double ra,
const double dec,
const double pixscale,
729 const bool eastToTheRight);
734 void setupWCSParams();
737 void recordLastError(
int errorCode);
738 void logOOMError(uint32_t requiredMemory = 0);
745 template <
typename T>
748 template <
typename T>
749 bool rotFITS(
int rotate,
int mirror);
752 template <
typename T>
755 template <
typename T>
756 void calculateMinMax(
bool roi =
false);
757 template <
typename T>
758 void calculateMedian(
bool roi =
false);
760 template <
typename T>
761 QPair<T, T> getParitionMinMax(uint32_t start, uint32_t stride,
bool roi);
765 template <
typename T>
767 template <
typename T>
768 void gaussianBlur(
int kernelSize,
double sigma);
771 template <
typename T>
772 void calculateStdDev(
bool roi =
false );
774 template <
typename T>
775 void convertToQImage(
double dataMin,
double dataMax,
double scale,
double zero,
QImage &image);
782 template <
typename T>
void constructHistogramInternal();
783 template <
typename T> int32_t histogramBinInternal(T value,
int channel)
const;
784 template <
typename T> int32_t histogramBinInternal(
int x,
int y,
int channel)
const;
794 bool searchSkyMapObjects();
806 bool findSimbadObjectsInImage(
SkyPoint searchCenter,
double radius);
812 bool getCatObjectFilter(
const QString type)
const;
832 bool addCatObject(
const int num,
const QString name,
const QString type,
const QString coord,
const double dist,
833 const double magnitude,
const QString sizeStr);
836 fitsfile *fptr {
nullptr };
838 uint8_t *m_ImageBuffer {
nullptr };
840 uint32_t m_ImageBufferSize { 0 };
842 uint8_t *m_ImageRoiBuffer {
nullptr };
844 uint32_t m_ImageRoiBufferSize { 0 };
846 bool m_isTemporary {
false };
848 bool m_isCompressed {
false };
850 bool starsSearched {
false };
852 StarAlgorithm starAlgorithm { ALGORITHM_GRADIENT };
854 bool HasWCS {
false };
856 bool HasDebayer {
false };
858 uint8_t *m_PackBuffer {
nullptr};
861 QString m_Filename, m_compressedFilename, m_Extension;
868 int rotCounter { 0 };
870 int flipHCounter { 0 };
872 int flipVCounter { 0 };
875 struct wcsprm *m_WCSHandle
881 WCSState m_WCSState { Idle };
886 Edge m_SelectedHFRStar;
889 BayerParams debayerParams;
895 int m_FITSBITPIX {USHORT_IMG};
896 FITSImage::Statistic m_Statistics;
897 FITSImage::Statistic m_ROIStatistics;
906 bool m_ObjectsSearched {
false};
907 bool m_CatObjectsSearched {
false};
908 void resetCatObjectsSearched()
910 m_CatObjectsSearched =
false;
913 FITSImage::Solution m_PlateSolveSolution { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, FITSImage::POSITIVE, 0.0, 0.0 };
926 uint16_t m_HistogramBinCount { 0 };
927 double m_JMIndex { 1 };
928 bool m_HistogramConstructed {
false };
936 SkyBackground m_SkyBackground;
938 QVariantMap m_SourceExtractorSettings;
943 double cacheHFR { -1 };
944 HFRType cacheHFRType { HFR_AVERAGE };
945 double cacheEccentricity { -1 };
951 bool m_CatQueryInProgress {
false };
952 bool m_CatUpdateTable {
false };
953 QPoint m_CatROIPt { -1, -1 };
954 int m_CatROIRadius { -1 };
Extension of QDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day,...
The sky coordinates of a point in the sky.
void append(QList< T > &&value)
qsizetype count() const const
Object to hold FITS Header records.
QString comment
FITS Header Value.
QVariant value
FITS Header Key.