7#include "solverutils.h"
9#include "fitsviewer/fitsdata.h"
11#include <QRegularExpression>
14SolverUtils::SolverUtils(
const SSolver::Parameters ¶meters,
double timeoutSeconds,
15 SSolver::ProcessType type) :
16 m_Parameters(parameters), m_TimeoutMilliseconds(timeoutSeconds * 1000.0), m_Type(
type)
21 m_StellarSolver.reset(
new StellarSolver());
25SolverUtils::~SolverUtils()
29 if (m_StellarSolver.get())
32 disconnect(m_StellarSolver.get(), &StellarSolver::finished,
this, &SolverUtils::solverDone);
36void SolverUtils::executeSolver()
38 runSolver(m_ImageData);
41void SolverUtils::runSolver(
const QString &filename)
48void SolverUtils::setHealpix(
int indexToUse,
int healpixToUse)
50 m_IndexToUse = indexToUse;
51 m_HealpixToUse = healpixToUse;
54void SolverUtils::abort()
56 if (m_StellarSolver.get()) m_StellarSolver->abort();
59bool SolverUtils::isRunning()
const
61 if (!m_StellarSolver.get())
return false;
62 return m_StellarSolver->isRunning();
65void SolverUtils::getSolutionHealpix(
int *indexUsed,
int *healpixUsed)
const
67 *indexUsed = m_StellarSolver->getSolutionIndexNumber();
68 *healpixUsed = m_StellarSolver->getSolutionHealpix();
72void SolverUtils::prepareSolver()
74 if (m_StellarSolver->isRunning())
75 m_StellarSolver->abort();
76 m_StellarSolver->setProperty(
"ProcessType", m_Type);
77 m_StellarSolver->loadNewImageBuffer(m_ImageData->getStatistics(), m_ImageData->getImageBuffer());
78 m_StellarSolver->setProperty(
"ExtractorType", Options::solveSextractorType());
79 m_StellarSolver->setProperty(
"SolverType", Options::solverType());
82 if (m_IndexToUse >= 0)
85 QStringList indexFiles = StellarSolver::getIndexFiles(
86 Options::astrometryIndexFolderList(), m_IndexToUse, m_HealpixToUse);
87 m_StellarSolver->setIndexFilePaths(indexFiles);
90 m_StellarSolver->setIndexFolderPaths(Options::astrometryIndexFolderList());
93 ExternalProgramPaths externalPaths;
94 externalPaths.sextractorBinaryPath = Options::sextractorBinary();
95 externalPaths.solverPath = Options::astrometrySolverBinary();
96 externalPaths.astapBinaryPath = Options::aSTAPExecutable();
97 externalPaths.watneyBinaryPath = Options::watneyBinary();
98 externalPaths.wcsPath = Options::astrometryWCSInfo();
99 m_StellarSolver->setExternalFilePaths(externalPaths);
102 m_StellarSolver->setProperty(
"AutoGenerateAstroConfig",
true);
104 auto params = m_Parameters;
105 params.partition = Options::stellarSolverPartition();
106 m_StellarSolver->setParameters(params);
108 m_TemporaryFilename.
clear();
110 const SSolver::SolverType
type =
static_cast<SSolver::SolverType
>(m_StellarSolver->property(
"SolverType").toInt());
111 if(type == SSolver::SOLVER_LOCALASTROMETRY || type == SSolver::SOLVER_ASTAP || type == SSolver::SOLVER_WATNEYASTROMETRY)
115 m_ImageData->saveImage(m_TemporaryFilename);
116 m_StellarSolver->setProperty(
"FileToProcess", m_TemporaryFilename);
118 else if (type == SSolver::SOLVER_ONLINEASTROMETRY )
122 m_ImageData->saveImage(m_TemporaryFilename);
123 m_StellarSolver->setProperty(
"FileToProcess", m_TemporaryFilename);
124 m_StellarSolver->setProperty(
"AstrometryAPIKey", Options::astrometryAPIKey());
125 m_StellarSolver->setProperty(
"AstrometryAPIURL", Options::astrometryAPIURL());
131 m_StellarSolver->setSearchScale(m_ScaleLowArcsecPerPixel * 0.8,
132 m_ScaleHighArcsecPerPixel * 1.2,
136 m_StellarSolver->setProperty(
"UseScale",
false);
139 m_StellarSolver->setSearchPositionInDegrees(m_raDegrees, m_decDegrees);
141 m_StellarSolver->setProperty(
"UsePosition",
false);
144 m_StellarSolver->setLogLevel(SSolver::LOG_NONE);
145 m_StellarSolver->setSSLogLevel(SSolver::LOG_OFF);
147 patchMultiAlgorithm(m_StellarSolver.get());
155 m_SolverTimer.
start();
162 m_StellarSolver->start();
165SolverUtils &SolverUtils::useScale(
bool useIt,
double scaleLowArcsecPerPixel,
double scaleHighArcsecPerPixel)
168 m_ScaleLowArcsecPerPixel = scaleLowArcsecPerPixel;
169 m_ScaleHighArcsecPerPixel = scaleHighArcsecPerPixel;
173SolverUtils &SolverUtils::usePosition(
bool useIt,
double raDegrees,
double decDegrees)
175 m_UsePosition = useIt;
176 m_raDegrees = raDegrees;
177 m_decDegrees = decDegrees;
181void SolverUtils::solverDone()
184 m_SolverTimer.
stop();
186 if (m_Type == SSolver::SOLVE)
188 FITSImage::Solution solution;
189 const bool success = m_StellarSolver->solvingDone() && !m_StellarSolver->failed();
191 solution = m_StellarSolver->getSolution();
192 emit done(
false, success, solution, elapsed);
196 const bool success = m_StellarSolver->extractionDone() && !m_StellarSolver->failed();
197 emit done(
false, success, FITSImage::Solution(), elapsed);
199 if (!m_TemporaryFilename.
isEmpty())
201 m_TemporaryFilename.
clear();
204void SolverUtils::solverTimeout()
206 m_SolverTimer.
stop();
208 disconnect(m_StellarSolver.get(), &StellarSolver::finished,
this, &SolverUtils::solverDone);
211 FITSImage::Solution empty;
212 emit done(
true,
false, empty, m_TimeoutMilliseconds / 1000.0);
213 if (!m_TemporaryFilename.
isEmpty())
215 m_TemporaryFilename.
clear();
220void SolverUtils::patchMultiAlgorithm(StellarSolver *solver)
222 if (solver && solver->property(
"UseScale").toBool() && !solver->property(
"UsePosition").toBool())
224 auto currentParameters = solver->getCurrentParameters();
225 currentParameters.multiAlgorithm = NOT_MULTI;
226 solver->setParameters(currentParameters);
Type type(const QSqlDatabase &db)
char * toString(const EngineQuery &query)
qint64 currentMSecsSinceEpoch()
void setFuture(const QFuture< T > &future)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool disconnect(const QMetaObject::Connection &connection)
QString arg(Args &&... args) const const
bool isEmpty() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void setInterval(int msec)
void setSingleShot(bool singleShot)