From e3afd82c4700536a2221fc76f64fdc873c93e964 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Sat, 28 Dec 2019 00:25:17 +0100 Subject: [PATCH] Move the mapping target->frame from SpiceManager to SpacecraftInstrumentModule (#closes 21) --- include/openspace/util/spicemanager.h | 52 ------------------- .../rendering/renderablefov.cpp | 15 ++++-- .../rendering/renderableplaneprojection.cpp | 5 +- .../spacecraftinstrumentsmodule.cpp | 27 ++++++++++ .../spacecraftinstrumentsmodule.h | 6 +++ src/util/spicemanager.cpp | 45 ---------------- 6 files changed, 49 insertions(+), 101 deletions(-) diff --git a/include/openspace/util/spicemanager.h b/include/openspace/util/spicemanager.h index 8aab7b6094..634a836571 100644 --- a/include/openspace/util/spicemanager.h +++ b/include/openspace/util/spicemanager.h @@ -652,36 +652,6 @@ public: FieldOfViewMethod method, AberrationCorrection aberrationCorrection, double& ephemerisTime) const; - /** - * Determine whether a specific \p target is in the field-of-view of a specified - * \p instrument or an \p observer at a given time. The reference frame used is - * derived from the \p target by converting it into an \c IAU inertial reference - * frame. - * - * \param target The name or NAIF ID code string of the target - * \param observer The name or NAIF ID code string of the observer - * \param instrument The name or NAIF ID code string of the instrument - * \param method The type of shape model used for the target - * \param aberrationCorrection The aberration correction method - * \param ephemerisTime Time of the observation (seconds past J2000) - * \return \c true if the target is visible, \c false otherwise - * - * \throw SpiceException If the \p target or \p observer do not name valid - * NAIF objects, the \p target or \p observer name the same NAIF object, the - * \p instrument does not name a valid NAIF object, or insufficient kernel - * information has been loaded. - * \pre \p target must not be empty. - * \pre \p observer must not be empty. - * \pre \p target and \p observer must not be different strings - * \pre \p referenceFrame must not be empty. - * \pre \p instrument must not be empty. - * - * \sa http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/fovtrg_c.html - */ - bool isTargetInFieldOfView(const std::string& target, const std::string& observer, - const std::string& instrument, FieldOfViewMethod method, - AberrationCorrection aberrationCorrection, double& ephemerisTime) const; - /// Struct that is used as the return value from the #targetState method struct TargetStateResult { /// The target position @@ -902,26 +872,6 @@ public: AberrationCorrection aberrationCorrection, double ephemerisTime, int numberOfTerminatorPoints); - /** - * This function adds a frame to a body. - * - * \param body - the name of the body - * \param frame - the name of the frame - * \return false if the arguments are empty - * - * \todo I think this function should die ---abock - */ - bool addFrame(std::string body, std::string frame); - - /** - * This function returns the frame of a body if defined, otherwise it returns - * IAU_ + body (most frames are known by the International Astronomical Union) - * \param body - the name of the body - * \return the frame of the body - * \todo I think this function should die ---abock - */ - std::string frameFromBody(const std::string& body) const; - /** * Sets the SpiceManager's exception handling. If UseException::No is passed to this * function, all subsequent calls will not throw an error, but fail silently instead. @@ -1048,8 +998,6 @@ private: std::map>> _spkIntervals; std::map> _ckCoverageTimes; std::map> _spkCoverageTimes; - // Vector of pairs: Body, Frame - std::vector> _frameByBody; /// Stores whether the SpiceManager throws exceptions (Yes) or fails silently (No) UseException _useExceptions = UseException::Yes; diff --git a/modules/spacecraftinstruments/rendering/renderablefov.cpp b/modules/spacecraftinstruments/rendering/renderablefov.cpp index ab4e0696e9..d4396b270e 100644 --- a/modules/spacecraftinstruments/rendering/renderablefov.cpp +++ b/modules/spacecraftinstruments/rendering/renderablefov.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -151,7 +152,6 @@ namespace { return 0.5 * bisect(p1, half, testFunction, half); } } - } // namespace namespace openspace { @@ -294,7 +294,10 @@ RenderableFov::RenderableFov(const ghoul::Dictionary& dictionary) if (dictionary.hasKey(KeyFrameConversions)) { ghoul::Dictionary fc = dictionary.value(KeyFrameConversions); for (const std::string& key : fc.keys()) { - openspace::SpiceManager::ref().addFrame(key, fc.value(key)); + global::moduleEngine.module()->addFrame( + key, + fc.value(key) + ); } } @@ -524,7 +527,12 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string& { const bool convert = (ref.find("IAU_") == std::string::npos); if (convert) { - return { SpiceManager::ref().frameFromBody(target), true }; + return { + global::moduleEngine.module()->frameFromBody( + target + ), + true + }; } else { return { ref, false }; @@ -917,6 +925,7 @@ std::pair RenderableFov::determineTarget(double time) { bool inFOV = SpiceManager::ref().isTargetInFieldOfView( pt, _instrument.spacecraft, + global::moduleEngine.module()->frameFromBody(pt), _instrument.name, SpiceManager::FieldOfViewMethod::Ellipsoid, _instrument.aberrationCorrection, diff --git a/modules/spacecraftinstruments/rendering/renderableplaneprojection.cpp b/modules/spacecraftinstruments/rendering/renderableplaneprojection.cpp index 85eed498c2..64b7864e70 100644 --- a/modules/spacecraftinstruments/rendering/renderableplaneprojection.cpp +++ b/modules/spacecraftinstruments/rendering/renderableplaneprojection.cpp @@ -24,8 +24,10 @@ #include +#include #include #include +#include #include #include #include @@ -309,7 +311,8 @@ void RenderablePlaneProjection::setTarget(std::string body) { return; } - _target.frame = SpiceManager::ref().frameFromBody(body); + _target.frame = + global::moduleEngine.module()->frameFromBody(body); _target.body = std::move(body); } diff --git a/modules/spacecraftinstruments/spacecraftinstrumentsmodule.cpp b/modules/spacecraftinstruments/spacecraftinstrumentsmodule.cpp index 3e2bf6847a..460418b055 100644 --- a/modules/spacecraftinstruments/spacecraftinstrumentsmodule.cpp +++ b/modules/spacecraftinstruments/spacecraftinstrumentsmodule.cpp @@ -94,4 +94,31 @@ SpacecraftInstrumentsModule::documentations() const }; } +bool SpacecraftInstrumentsModule::addFrame(std::string body, std::string frame) { + if (body.empty() || frame.empty()) { + return false; + } + else { + _frameByBody.emplace_back(body, frame); + return true; + } +} + +std::string SpacecraftInstrumentsModule::frameFromBody(const std::string& body) { + for (const std::pair& pair : _frameByBody) { + if (pair.first == body) { + return pair.second; + } + } + + constexpr const char* unionPrefix = "IAU_"; + + if (body.find(unionPrefix) == std::string::npos) { + return unionPrefix + body; + } + else { + return body; + } +} + } // namespace openspace diff --git a/modules/spacecraftinstruments/spacecraftinstrumentsmodule.h b/modules/spacecraftinstruments/spacecraftinstrumentsmodule.h index d05fefe8c5..fc37bd53bb 100644 --- a/modules/spacecraftinstruments/spacecraftinstrumentsmodule.h +++ b/modules/spacecraftinstruments/spacecraftinstrumentsmodule.h @@ -41,10 +41,16 @@ public: static ghoul::opengl::ProgramObjectManager ProgramObjectManager; + bool addFrame(std::string body, std::string frame); + std::string frameFromBody(const std::string& body); + protected: void internalInitialize(const ghoul::Dictionary&) override; void internalDeinitialize() override; void internalDeinitializeGL() override; + +private: + std::vector> _frameByBody; }; } // namespace openspace diff --git a/src/util/spicemanager.cpp b/src/util/spicemanager.cpp index 9aa2e51803..bd65b59db5 100644 --- a/src/util/spicemanager.cpp +++ b/src/util/spicemanager.cpp @@ -687,24 +687,6 @@ bool SpiceManager::isTargetInFieldOfView(const std::string& target, return visible == SPICETRUE; } -bool SpiceManager::isTargetInFieldOfView(const std::string& target, - const std::string& observer, - const std::string& instrument, - FieldOfViewMethod method, - AberrationCorrection aberrationCorrection, - double& ephemerisTime) const -{ - return isTargetInFieldOfView( - target, - observer, - frameFromBody(target), - instrument, - method, - aberrationCorrection, - ephemerisTime - ); -} - SpiceManager::TargetStateResult SpiceManager::targetState(const std::string& target, const std::string& observer, const std::string& referenceFrame, @@ -913,33 +895,6 @@ SpiceManager::TerminatorEllipseResult SpiceManager::terminatorEllipse( return res; } -bool SpiceManager::addFrame(std::string body, std::string frame) { - if (body.empty() || frame.empty()) { - return false; - } - else { - _frameByBody.emplace_back(body, frame); - return true; - } -} - -std::string SpiceManager::frameFromBody(const std::string& body) const { - for (const std::pair& pair : _frameByBody) { - if (pair.first == body) { - return pair.second; - } - } - - constexpr const char* unionPrefix = "IAU_"; - - if (body.find(unionPrefix) == std::string::npos) { - return unionPrefix + body; - } - else { - return body; - } -} - void SpiceManager::findCkCoverage(const std::string& path) { ghoul_assert(!path.empty(), "Empty file path"); ghoul_assert(FileSys.fileExists(path), fmt::format("File '{}' does not exist", path));