Commit f538bc0b authored by Jasem Mutlaq's avatar Jasem Mutlaq

WCS data is no longer loaded by default. It must be explicitly loaded either...

WCS data is no longer loaded by default. It must be explicitly loaded either via calling loadWCS() directly, or IF WCS header is valid, then toggling the EQ Grid and Object info
would also load the data. However, there is also now an option to load WCS automatically if so desired but this option is only recommended in fast machines as it can lead to unpredictable
behavior on slow machines.
parent 705ab3f9
......@@ -248,21 +248,21 @@ Align::Align()
connect(PAHFirstCaptureB, &QPushButton::clicked, this, [this]()
{
// Do not load WCS unless requested
alignView->setLoadWCSEnabled(false);
//alignView->setLoadWCSEnabled(false);
PAHFirstCaptureB->setEnabled(false);
captureAndSolve();
});
connect(PAHSecondCaptureB, &QPushButton::clicked, this, [this]()
{
// Do not load WCS unless requested
alignView->setLoadWCSEnabled(false);
//alignView->setLoadWCSEnabled(false);
PAHSecondCaptureB->setEnabled(false);
captureAndSolve();
});
connect(PAHThirdCaptureB, &QPushButton::clicked, this, [this]()
{
// Do not load WCS unless requested
alignView->setLoadWCSEnabled(false);
//alignView->setLoadWCSEnabled(false);
PAHThirdCaptureB->setEnabled(false);
captureAndSolve();
});
......@@ -4403,7 +4403,7 @@ void Align::processPAHStage(double orientation, double ra, double dec, double pi
QString newWCSFile = tmpFile.fileName();
tmpFile.close();
alignView->setLoadWCSEnabled(true);
//alignView->setLoadWCSEnabled(true);
if (pahStage == PAH_FIND_CP)
{
......
......@@ -278,6 +278,11 @@ bool FITSData::loadFITS (const QString &inFilename, bool silent)
debayer();
}
WCSLoaded = false;
if (mode == FITS_NORMAL || mode == FITS_ALIGN)
checkForWCS();
starsSearched = false;
return true;
......@@ -2079,11 +2084,71 @@ void FITSData::getCenterSelection(int * x, int * y)
delete (pEdge);
}
bool FITSData::checkForWCS()
{
#ifndef KSTARS_LITE
#ifdef HAVE_WCSLIB
int status=0;
char * header;
int nkeyrec, nreject, nwcs;
if (fits_hdr2str(fptr, 1, nullptr, 0, &header, &nkeyrec, &status))
{
char errmsg[512];
fits_get_errstatus(status, errmsg);
lastError = errmsg;
return false;
}
if ((status = wcspih(header, nkeyrec, WCSHDR_all, -3, &nreject, &nwcs, &wcs)))
{
free(header);
lastError = QString("wcspih ERROR %1: %2.").arg(status).arg(wcshdr_errmsg[status]);
return false;
}
free(header);
if (wcs == 0)
{
//fprintf(stderr, "No world coordinate systems found.\n");
lastError = i18n("No world coordinate systems found.");
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)
{
lastError = i18n("No world coordinate systems found.");
return false;
}
if ((status = wcsset(wcs)))
{
lastError = QString("wcsset error %1: %2.").arg(status).arg(wcs_errmsg[status]);
return false;
}
HasWCS = true;
return HasWCS;
#endif
#endif
return false;
}
bool FITSData::loadWCS()
{
#ifndef KSTARS_LITE
#ifdef HAVE_WCSLIB
if (WCSLoaded)
{
qWarning() << "WCS data already loaded";
return true;
}
int status=0;
char * header;
int nkeyrec, nreject, nwcs, stat[2];
......@@ -2163,8 +2228,9 @@ bool FITSData::loadWCS()
findObjectsInImage(&world[0], phi, theta, &imgcrd[0], &pixcrd[0], &stat[0]);
HasWCS = true;
return HasWCS;
WCSLoaded = true;
return true;
#endif
#endif
......@@ -3895,6 +3961,8 @@ bool FITSData::createWCSFile(const QString &newWCSFile, double orientation, doub
fits_flush_file(fptr, &status);
WCSLoaded = false;
return true;
}
......
......@@ -267,11 +267,21 @@ class FITSData
}
// WCS
bool loadWCS();
// Check if image has valid WCS header information and set HasWCS accordingly. Call in loadFITS()
bool checkForWCS();
// Does image have valid WCS?
bool hasWCS()
{
return HasWCS;
}
// Load WCS data
bool loadWCS();
// Is WCS Image loaded?
bool isWCSLoaded()
{
return WCSLoaded;
}
wcs_point * getWCSCoord()
{
return wcs_coord;
......@@ -418,7 +428,8 @@ class FITSData
bool tempFile; // Is this a tempoprary file or one loaded from disk?
bool starsSearched; // Did we search for stars yet?
bool HasWCS; // Do we have WCS keywords in this FITS data?
bool HasWCS=false; // Do we have WCS keywords in this FITS data?
bool WCSLoaded=false; // Is WCS data loaded?
bool markStars; // Do we need to mark stars for the user?
bool HasDebayer; // Is the image debayarable?
......
......@@ -90,7 +90,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()));
connect(&wcsWatcher, SIGNAL(finished()), this, SLOT(syncWCSState()));
image_frame->setMouseTracking(true);
setMouseMode(selectMouse);//This is the default mode because the Focus and Align FitsViews should not be in dragMouse mode
......@@ -176,10 +176,10 @@ void FITSView::resizeEvent(QResizeEvent * event)
}
void FITSView::setLoadWCSEnabled(bool value)
/*void FITSView::setLoadWCSEnabled(bool value)
{
loadWCSEnabled = value;
}
}*/
bool FITSView::loadFITS (const QString &inFilename , bool silent)
{
......@@ -246,7 +246,7 @@ bool FITSView::loadFITS (const QString &inFilename , bool silent)
maxPixel = imageData->getMax();
minPixel = imageData->getMin();
if (loadWCSEnabled && (mode == FITS_NORMAL || mode == FITS_ALIGN))
if (Options::autoWCS() && (mode == FITS_NORMAL || mode == FITS_ALIGN))
{
if (fitsProg.wasCanceled())
return false;
......@@ -293,6 +293,9 @@ bool FITSView::loadFITS (const QString &inFilename , bool silent)
setAlignment(Qt::AlignCenter);
if (Options::autoWCS() == false)
syncWCSState();
if (isVisible())
emit newStatus(QString("%1x%2").arg(image_width).arg(image_height), FITS_RESOLUTION);
......@@ -1147,6 +1150,14 @@ void FITSView::toggleCrosshair()
void FITSView::toggleEQGrid()
{
showEQGrid=!showEQGrid;
if (imageData->isWCSLoaded() == false)
{
QFuture<bool> future = QtConcurrent::run(imageData, &FITSData::loadWCS);
wcsWatcher.setFuture(future);
return;
}
if(image_frame)
updateFrame();
}
......@@ -1154,6 +1165,14 @@ void FITSView::toggleEQGrid()
void FITSView::toggleObjects()
{
showObjects=!showObjects;
if (imageData->isWCSLoaded() == false)
{
QFuture<bool> future = QtConcurrent::run(imageData, &FITSData::loadWCS);
wcsWatcher.setFuture(future);
return;
}
if(image_frame)
updateFrame();
......@@ -1397,12 +1416,30 @@ void FITSView::pinchTriggered(QPinchGesture * gesture)
}
void FITSView::handleWCSCompletion()
/*void FITSView::handleWCSCompletion()
{
//bool hasWCS = wcsWatcher.result();
if(imageData->hasWCS())
this->updateFrame();
emit wcsToggled(imageData->hasWCS());
}*/
void FITSView::syncWCSState()
{
bool hasWCS = imageData->hasWCS();
bool wcsLoaded= imageData->isWCSLoaded();
if (hasWCS && wcsLoaded)
this->updateFrame();
emit wcsToggled(hasWCS);
if (toggleEQGridAction)
toggleEQGridAction->setEnabled(hasWCS);
if (toggleObjectsAction)
toggleObjectsAction->setEnabled(hasWCS);
if (centerTelescopeAction)
centerTelescopeAction->setEnabled(hasWCS);
}
void FITSView::createFloatingToolBar()
......@@ -1443,22 +1480,24 @@ void FITSView::createFloatingToolBar()
action = floatingToolBar->addAction(QIcon::fromTheme("map-flat", QIcon(":/icons/breeze/default/map-flat.svg")), i18n("Show Pixel Gridlines"), this, SLOT(togglePixelGrid()));
action->setCheckable(true);
if (mode != FITS_GUIDE)
toggleStarsAction = floatingToolBar->addAction(QIcon::fromTheme("kstars_stars", QIcon(":/icons/breeze/default/kstars_stars.svg")), i18n("Detect Stars in Image"), this, SLOT(toggleStars()));
toggleStarsAction->setCheckable(true);
if (mode == FITS_NORMAL || mode == FITS_ALIGN)
{
floatingToolBar->addSeparator();
action = floatingToolBar->addAction(QIcon::fromTheme("kstars_grid", QIcon(":/icons/breeze/default/kstars_grid.svg")), i18n("Show Equatorial Gridlines"), this, SLOT(toggleEQGrid()));
action->setCheckable(true);
toggleEQGridAction = floatingToolBar->addAction(QIcon::fromTheme("kstars_grid", QIcon(":/icons/breeze/default/kstars_grid.svg")), i18n("Show Equatorial Gridlines"), this, SLOT(toggleEQGrid()));
toggleEQGridAction->setCheckable(true);
toggleEQGridAction->setEnabled(false);
action = floatingToolBar->addAction(QIcon::fromTheme("kstars_stars", QIcon(":/icons/breeze/default/kstars_stars.svg")), i18n("Detect Stars in Image"), this, SLOT(toggleStars()));
action->setCheckable(true);
action = floatingToolBar->addAction(QIcon::fromTheme("help-hint", QIcon(":/icons/breeze/default/help-hint.svg")), i18n("Show Objects in Image"), this, SLOT(toggleObjects()));
action->setCheckable(true);
toggleObjectsAction = floatingToolBar->addAction(QIcon::fromTheme("help-hint", QIcon(":/icons/breeze/default/help-hint.svg")), i18n("Show Objects in Image"), this, SLOT(toggleObjects()));
toggleObjectsAction->setCheckable(true);
toggleEQGridAction->setEnabled(false);
centerTelescopeAction = floatingToolBar->addAction(QIcon::fromTheme("center_telescope", QIcon(":/icons/center_telescope.svg")), i18n("Center Telescope"), this, SLOT(centerTelescope()));
centerTelescopeAction->setCheckable(true);
centerTelescopeAction->setEnabled(false);
}
}
......
......@@ -168,14 +168,13 @@ class FITSView : public QScrollArea
// Floating toolbar
void createFloatingToolBar();
void setLoadWCSEnabled(bool value);
//void setLoadWCSEnabled(bool value);
protected:
void wheelEvent(QWheelEvent * event);
void resizeEvent(QResizeEvent * event);
QFutureWatcher<bool> wcsWatcher; // WCS Future Watcher
bool loadWCSEnabled=true; // Load WCS data?
QPointF markerCrosshair; // Cross hair
FITSData * imageData; // Pointer to FITSData object
double currentZoom; // Current zoom level
......@@ -201,7 +200,11 @@ protected:
void processMarkerSelection(int x, int y);
protected slots:
void handleWCSCompletion();
/**
* @brief syncWCSState Update toolbar and actions depending on whether WCS is available or not
*/
void syncWCSState();
//void handleWCSCompletion();
private:
QLabel * noImageLabel=new QLabel();
......@@ -270,7 +273,7 @@ protected:
// Floating toolbar
QToolBar * floatingToolBar = nullptr;
QAction * centerTelescopeAction = nullptr;
QAction * centerTelescopeAction = nullptr, * toggleEQGridAction = nullptr, * toggleObjectsAction = nullptr, * toggleStarsAction = nullptr;
signals:
void newStatus(const QString &msg, FITSBar id);
......
......@@ -146,6 +146,16 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="kcfg_AutoWCS">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Automatically load World-Coordinate-System (WCS) data when opening a FITS file.&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Warning: Only enable this option on very fast machines as it can lead to unpredictable behavior resulting in crashes on slower machines.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Auto WCS</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="kcfg_Auto3DCube">
<property name="toolTip">
......
......@@ -1321,6 +1321,10 @@
<label>Process 3D FITS Cube (RGB). If false, only first channel is processed.</label>
<default>true</default>
</entry>
<entry name="AutoWCS" type="Bool">
<label>Automatically process World-Coordinate-System (WCS) data when loading a FITS file.</label>
<default>false</default>
</entry>
<entry name="LimitedResourcesMode" type="Bool">
<label>Conserve CPU and memory by disabling all resource-intensive features in FITS Viewer</label>
<default>false</default>
......
Markdown is supported
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