diff --git a/include/openspace/util/spicemanager.h b/include/openspace/util/spicemanager.h index 852e4cf386..f05f6cb329 100644 --- a/include/openspace/util/spicemanager.h +++ b/include/openspace/util/spicemanager.h @@ -630,6 +630,22 @@ public: */ bool getFieldOfView(int instrument, std::string& fovShape, std::string& frameName, glm::dvec3& boresightVector, std::vector& bounds) const; + + /** + * 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 + */ + bool addFrame(const std::string body, const 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 + */ + std::string frameFromBody(const std::string body) const; /** * This method checks if one of the previous SPICE methods has failed. If it has, the @@ -673,6 +689,8 @@ private: std::map > > _spkIntervals; std::map > _ckCoverageTimes; std::map > _spkCoverageTimes; + // Vector of pairs: Body, Frame + std::vector< std::pair > _frameByBody; const static bool _showErrors = false; diff --git a/src/rendering/model/renderablemodel.cpp b/src/rendering/model/renderablemodel.cpp index 79dbc20762..76838fd328 100644 --- a/src/rendering/model/renderablemodel.cpp +++ b/src/rendering/model/renderablemodel.cpp @@ -96,6 +96,8 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary) dictionary.getValue(keyDestination, _destination); dictionary.getValue(keyBody, _target); + openspace::SpiceManager::ref().addFrame(_target, _source); + setBoundingSphere(pss(1.f, 9.f)); addProperty(_performShading); diff --git a/src/rendering/renderableplaneprojection.cpp b/src/rendering/renderableplaneprojection.cpp index 206a37fe8f..67885de7a5 100644 --- a/src/rendering/renderableplaneprojection.cpp +++ b/src/rendering/renderableplaneprojection.cpp @@ -281,7 +281,7 @@ void RenderablePlaneProjection::setTarget(std::string body) { } if (found) { _target.body = body; - _target.frame = "IAU_" + body; + _target.frame = openspace::SpiceManager::ref().frameFromBody(body); } } diff --git a/src/util/spicemanager.cpp b/src/util/spicemanager.cpp index 2c1289e659..3f9b24d5d5 100644 --- a/src/util/spicemanager.cpp +++ b/src/util/spicemanager.cpp @@ -641,13 +641,12 @@ bool SpiceManager::targetWithinFieldOfView(const std::string& instrument, int visible; - std::string bodyfixed = "IAU_"; - bodyfixed += target; + std::string frame = frameFromBody(target); fovtrg_c(instrument.c_str(), target.c_str(), method.c_str(), - bodyfixed.c_str(), + frame.c_str(), aberrationCorrection.c_str(), observer.c_str(), &targetEpoch, @@ -688,9 +687,9 @@ bool SpiceManager::getSurfaceIntercept(const std::string& target, // allow client specify non-inertial frame. std::string bodyfixed = "IAU_"; convert = (referenceFrame.find(bodyfixed) == std::string::npos); - if (convert){ - bodyfixed += target; - }else{ + if (convert) { + bodyfixed = frameFromBody(target); + } else { bodyfixed = referenceFrame; } @@ -813,11 +812,11 @@ bool SpiceManager::getPositionTransformMatrix(const std::string& fromFrame, ephemerisTime, (double(*)[3])glm::value_ptr(positionMatrix)); success = !(failed_c()); - if (!success && !_showErrors) { + if (!success) { reset_c(); estimated = getEstimatedTransformMatrix(ephemerisTime, fromFrame, toFrame, positionMatrix); } - else { + if (_showErrors) { bool hasError = checkForError("Error retrieving position transform matrix from " "frame '" + fromFrame + "' to frame '" + toFrame + "' at time '" + std::to_string(ephemerisTime)); @@ -958,6 +957,34 @@ bool SpiceManager::getFieldOfView(int instrument, return true; } +std::string SpiceManager::frameFromBody(const std::string body) const { + + for (auto pair : _frameByBody) { + if (pair.first == body) { + return pair.second; + } + } + + std::string unionPrefix = "IAU_"; + std::string frame = ""; + + if (body.find(unionPrefix) == std::string::npos) + frame = unionPrefix + body; + else + frame = body; + + return frame; +} + +bool SpiceManager::addFrame(const std::string body, const std::string frame) { + if (body == "" || frame == "") + return false; + else { + _frameByBody.push_back(std::make_pair(body, frame)); + return true; + } +} + bool SpiceManager::checkForError(std::string errorMessage) { int failed = failed_c();