Files
OpenSpace/modules/space/translation/gptranslation.cpp
Alexander Bock 7bc9e99b87 Feature/satellites (#2185)
* Remove planet geometry and simplespheregeometry
* Only use a single TLE loading implementation
* Add caching to the satellite loader;  Add Lua function to load kepler file
* Fix RenderablePlanetProjection specification
* Add OMM loading funtion;  Remove mean motion from Kepler parameters
* Replace TLETranslation class with GPTranslation and support OMM files
* Support loading SMDB files in kepler functions
* Merge RenderableSatellites and RenderableSmallBody with RenderableOrbitalKepler
* Update submodules
* Adapt existing satellites to new OMM file type
* Remove TLE helper
* Remove SSSB shared file and adapt sssb assets
2022-08-02 13:11:50 +02:00

93 lines
4.1 KiB
C++

/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2022 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <modules/space/translation/gptranslation.h>
#include <modules/space/kepler.h>
#include <openspace/documentation/verifier.h>
#include <filesystem>
#include <optional>
namespace {
struct [[codegen::Dictionary(GPTranslation)]] Parameters {
// Specifies the filename of the general pertubation file
std::filesystem::path file;
enum class [[codegen::map(openspace::kepler::Format)]] Format {
// A NORAD-style Two-Line element
TLE,
// Orbit Mean-Elements Message in the KVN notation
OMM,
// JPL's Small Bodies Database
SBDB
};
// The file format that is contained in the file
Format format;
// Specifies the element within the file that should be used in case the file
// provides multiple general pertubation elements. Defaults to 1.
std::optional<int> element [[codegen::greater(0)]];
};
#include "gptranslation_codegen.cpp"
} // namespace
namespace openspace {
documentation::Documentation GPTranslation::Documentation() {
return codegen::doc<Parameters>("space_transform_gp");
}
GPTranslation::GPTranslation(const ghoul::Dictionary& dictionary) {
const Parameters p = codegen::bake<Parameters>(dictionary);
if (!std::filesystem::is_regular_file(p.file)) {
throw ghoul::RuntimeError("The provided TLE file must exist");
}
int element = p.element.value_or(1);
std::vector<kepler::Parameters> parameters = kepler::readFile(
p.file,
codegen::map<kepler::Format>(p.format)
);
if (parameters.size() < element) {
throw ghoul::RuntimeError(fmt::format(
"Requested element {} but only {} are available", element, parameters.size()
));
}
kepler::Parameters param = parameters[element - 1];
setKeplerElements(
param.eccentricity,
param.semiMajorAxis,
param.inclination,
param.ascendingNode,
param.argumentOfPeriapsis,
param.meanAnomaly,
param.period,
param.epoch
);
}
} // namespace openspace