summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasem Mutlaq <mutlaqja@ikarustech.com>2016-10-22 09:44:04 (GMT)
committerJasem Mutlaq <mutlaqja@ikarustech.com>2016-10-22 09:44:04 (GMT)
commitb1404a252196a4459b59446a89f138a0d94f40b1 (patch)
tree6dec35093e93d87e05f3b2a27412df010932c895
parent099173ed040faea8568877bf93b6dda69d4f1bec (diff)
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
-rw-r--r--CMakeLists.txt2
-rw-r--r--kstars/CMakeLists.txt1
-rw-r--r--kstars/fitsviewer/fitsdata.cpp23
-rw-r--r--kstars/fitsviewer/fitsdata.h6
-rw-r--r--kstars/fitsviewer/fitsview.cpp11
-rw-r--r--kstars/fitsviewer/fitsview.h8
-rw-r--r--kstars/fitsviewer/fitsviewer.cpp1
7 files changed, 36 insertions, 16 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1229083..21aa0d7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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)
diff --git a/kstars/CMakeLists.txt b/kstars/CMakeLists.txt
index f9db3d2..d490b08 100644
--- a/kstars/CMakeLists.txt
+++ b/kstars/CMakeLists.txt
@@ -913,6 +913,7 @@ else(BUILD_KSTARS_LITE)
Qt5::Qml
Qt5::Quick
Qt5::Network
+ Qt5::Concurrent
${ZLIB_LIBRARIES}
)
endif(BUILD_KSTARS_LITE)
diff --git a/kstars/fitsviewer/fitsdata.cpp b/kstars/fitsviewer/fitsdata.cpp
index 368d0b2..5bbc2b0 100644
--- a/kstars/fitsviewer/fitsdata.cpp
+++ b/kstars/fitsviewer/fitsdata.cpp
@@ -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[]){
diff --git a/kstars/fitsviewer/fitsdata.h b/kstars/fitsviewer/fitsdata.h
index 750015e..91df5d1 100644
--- a/kstars/fitsviewer/fitsdata.h
+++ b/kstars/fitsviewer/fitsdata.h
@@ -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();
diff --git a/kstars/fitsviewer/fitsview.cpp b/kstars/fitsviewer/fitsview.cpp
index dbc95f9..f3fb5e4 100644
--- a/kstars/fitsviewer/fitsview.cpp
+++ b/kstars/fitsviewer/fitsview.cpp
@@ -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);
+}
diff --git a/kstars/fitsviewer/fitsview.h b/kstars/fitsviewer/fitsview.h
index 46c7e78..ff93b8d 100644
--- a/kstars/fitsviewer/fitsview.h
+++ b/kstars/fitsviewer/fitsview.h
@@ -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);
diff --git a/kstars/fitsviewer/fitsviewer.cpp b/kstars/fitsviewer/fitsviewer.cpp
index 15bf6e6..b90d860 100644
--- a/kstars/fitsviewer/fitsviewer.cpp
+++ b/kstars/fitsviewer/fitsviewer.cpp
@@ -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);