Commit b1404a25 authored by Jasem Mutlaq's avatar Jasem Mutlaq
Browse files

Using QtConcurrent to parallelize some aspects of KStars. Now WCS is running...

Using QtConcurrent to parallelize some aspects of KStars. Now WCS is running in a seprate thread and this brought opening time from 5 seconds to less than 1 second in WCS-enabled frames
parent 099173ed
......@@ -34,7 +34,7 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" ${CMAKE_MODULE
if(BUILD_KSTARS_LITE)
find_package(Qt5 5.7 REQUIRED COMPONENTS Gui Qml Quick QuickControls2 Xml Svg Sql Network Sensors Positioning)
else()
find_package(Qt5 5.4 REQUIRED COMPONENTS Gui Qml Quick Xml Sql Svg Network PrintSupport)
find_package(Qt5 5.4 REQUIRED COMPONENTS Gui Qml Quick Xml Sql Svg Network PrintSupport Concurrent)
endif()
include(ECMInstallIcons)
include(ECMAddAppIcon)
......
......@@ -913,6 +913,7 @@ else(BUILD_KSTARS_LITE)
Qt5::Qml
Qt5::Quick
Qt5::Network
Qt5::Concurrent
${ZLIB_LIBRARIES}
)
endif(BUILD_KSTARS_LITE)
......
......@@ -254,8 +254,8 @@ bool FITSData::loadFITS (const QString &inFilename, bool silent)
calculateStats();
if (mode == FITS_NORMAL)
checkWCS();
//if (mode == FITS_NORMAL)
//checkWCS();
if (checkDebayer())
debayer();
......@@ -1702,7 +1702,7 @@ void FITSData::getCenterSelection(int *x, int *y)
delete (pEdge);
}
void FITSData::checkWCS()
bool FITSData::checkWCS()
{
#ifdef HAVE_WCSLIB
......@@ -1717,13 +1717,13 @@ void FITSData::checkWCS()
if (fits_hdr2str(fptr, 1, NULL, 0, &header, &nkeyrec, &status))
{
fits_report_error(stderr, status);
return;
return false;
}
if ((status = wcspih(header, nkeyrec, WCSHDR_all, -3, &nreject, &nwcs, &wcs)))
{
fprintf(stderr, "wcspih ERROR %d: %s.\n", status, wcshdr_errmsg[status]);
return;
return false;
}
free(header);
......@@ -1731,19 +1731,17 @@ void FITSData::checkWCS()
if (wcs == 0)
{
//fprintf(stderr, "No world coordinate systems found.\n");
return;
return false;
}
// FIXME: Call above goes through EVEN if no WCS is present, so we're adding this to return for now.
if (wcs->crpix[0] == 0)
return;
HasWCS = true;
return false;
if ((status = wcsset(wcs)))
{
fprintf(stderr, "wcsset ERROR %d: %s.\n", status, wcs_errmsg[status]);
return;
return false;
}
delete[] wcs_coord;
......@@ -1772,9 +1770,12 @@ void FITSData::checkWCS()
}
}
}
findObjectsInImage(wcs, &world[0], phi, theta, &imgcrd[0], &pixcrd[0], &stat[0]);
#endif
HasWCS = true;
return HasWCS;
#endif
}
void FITSData::findObjectsInImage(struct wcsprm *wcs, double world[], double phi, double theta, double imgcrd[], double pixcrd[], int stat[]){
......
......@@ -168,6 +168,7 @@ public:
FITSMode getMode() { return mode;}
// WCS
bool checkWCS();
bool hasWCS() { return HasWCS; }
wcs_point *getWCSCoord() { return wcs_coord; }
......@@ -201,7 +202,7 @@ public:
// Horizontal flip counter. We keep count to rotate WCS keywords on save
int getFlipVCounter() const;
void setFlipVCounter(int value);
void setFlipVCounter(int value);
void findObjectsInImage(struct wcsprm *wcs, double world[], double phi, double theta, double imgcrd[], double pixcrd[], int stat[]);
QList<FITSSkyObject *> getSkyObjects();
......@@ -212,8 +213,7 @@ private:
bool rotFITS (int rotate, int mirror);
void rotWCSFITS (int angle, int mirror);
bool checkCollision(Edge* s1, Edge*s2);
int calculateMinMax(bool refresh=false);
void checkWCS();
int calculateMinMax(bool refresh=false);
bool checkDebayer();
void readWCSKeys();
......
......@@ -28,6 +28,7 @@
#include <QApplication>
#include <QPaintEvent>
#include <QtConcurrent>
#include <QScrollArea>
#include <QFile>
#include <QCursor>
......@@ -427,6 +428,7 @@ FITSView::FITSView(QWidget * parent, FITSMode fitsMode, FITSScale filterType) :
connect(image_frame, SIGNAL(newStatus(QString,FITSBar)), this, SIGNAL(newStatus(QString,FITSBar)));
connect(image_frame, SIGNAL(pointSelected(int,int)), this, SLOT(processPointSelection(int,int)));
connect(image_frame, SIGNAL(markerSelected(int,int)), this, SLOT(processMarkerSelection(int,int)));
connect(&wcsWatcher, SIGNAL(finished()), this, SLOT(handleWCSCompletion()));
image_frame->setMouseTracking(true);
setMouseMode(selectMouse);//This is the default mode because the Focus and Align FitsViews should not be in dragMouse mode
......@@ -499,7 +501,7 @@ bool FITSView::loadFITS (const QString &inFilename , bool silent)
image_frame->setSize(image_width, image_height);
hasWCS = image_data->hasWCS();
//hasWCS = image_data->hasWCS();
maxPixel = image_data->getMax();
minPixel = image_data->getMin();
......@@ -510,6 +512,8 @@ bool FITSView::loadFITS (const QString &inFilename , bool silent)
return false;
else
{
QFuture<bool> future = QtConcurrent::run(image_data, &FITSData::checkWCS);
wcsWatcher.setFuture(future);
fitsProg.setValue(75);
qApp->processEvents();
}
......@@ -1447,3 +1451,8 @@ void FITSView::pinchTriggered(QPinchGesture *gesture)
}
void FITSView::handleWCSCompletion()
{
hasWCS = wcsWatcher.result();
emit wcsToggled(hasWCS);
}
......@@ -27,6 +27,7 @@
#include <QResizeEvent>
#include <QPaintEvent>
#include <QFutureWatcher>
#include <QEvent>
#include <QGestureEvent>
#include <QGestureEvent>
......@@ -179,6 +180,9 @@ public slots:
void processPointSelection(int x, int y);
void processMarkerSelection(int x, int y);
protected slots:
void handleWCSCompletion();
private:
bool event(QEvent *event);
bool gestureEvent(QGestureEvent *event);
......@@ -236,9 +240,13 @@ private:
QRect trackingBox;
QPixmap trackingBoxPixmap;
// WCS Future Watch
QFutureWatcher<bool> wcsWatcher;
signals:
void newStatus(const QString &msg, FITSBar id);
void debayerToggled(bool);
void wcsToggled(bool);
void actionUpdated(const QString &name, bool enable);
void trackingStarSelected(int x, int y);
......
......@@ -369,6 +369,7 @@ int FITSViewer::addFITS(const QUrl *imageName, FITSMode mode, FITSScale filter,
connect(tab->getView(), SIGNAL(actionUpdated(QString,bool)), this, SLOT(updateAction(QString,bool)));
connect(tab, SIGNAL(changeStatus(bool)), this, SLOT(updateTabStatus(bool)));
connect(tab, SIGNAL(debayerToggled(bool)), this, SLOT(setDebayerAction(bool)));
connect(tab->getView(), SIGNAL(wcsToggled(bool)), this, SLOT(updateWCSFunctions()));
saveFileAction->setEnabled(true);
saveFileAsAction->setEnabled(true);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment