Merge branch 'thesis/2018/dsn' of github.com:OpenSpace/OpenSpace into thesis/2018/dsn

This commit is contained in:
Lovisa Hassler
2018-12-17 17:41:00 -05:00
5 changed files with 86 additions and 45 deletions
+48 -37
View File
@@ -38,63 +38,75 @@ namespace openspace {
return dataFilesSuccess;
}
bool RadecManager::correctHour(double time) const{
const bool isTimeInFileInterval = (time >= _checkFileTime) &&
bool RadecManager::correctFileInterval(double time) const{
const bool isTimeInFileInterval = (time > _checkFileTime) &&
(time < _checkFileEndTime);
return isTimeInFileInterval;
}
bool RadecManager::correctMinute(double time) const {
const bool isTimeInActiveMinute = (time >= activeMinute && time < activeMinute + 60);
return isTimeInActiveMinute;
bool RadecManager::correctUpdateInterval(double time) const {
const bool isTimeInActiveMinute = (time > activeMinute - updateFrequency *60 && time < activeMinute + updateFrequency *60);
return isTimeInActiveMinute;
}
void RadecManager::setUpdateFrequency(double updatedFreq) {
//Determines how many minutes between updates
updateFrequency = updatedFreq;
}
glm::vec3 RadecManager::getPosForTime(double time) const {
if (!correctHour(time)) {
if (!correctFileInterval(time)) {
int idx = DataFileHelper::findFileIndexForCurrentTime(time, timeDoubles);
updateRadecData(idx);
int index = DataFileHelper::findFileIndexForCurrentTime(time, minuteTimes);
updateActiveMinute(index);
}
// positions have to be loaded before we try to update minute
if(positions.size() && !correctMinute(time)) {
if (positions.size() && !correctUpdateInterval(time)) {
//Compensate for light travel time to the spacecraft
int idx = DataFileHelper::findFileIndexForCurrentTime(time, minuteTimes);
updateActiveMinute(idx);
double lighttimeCompensation = positions[idx].lightTravelTime;
int compensatedIdx = DataFileHelper::findFileIndexForCurrentTime(time + lighttimeCompensation, minuteTimes);
getPositionInVector(compensatedIdx);
}
double lighttimeCompensation = positions[idx].lightTravelTime;
int compensatedIdx = DataFileHelper::findFileIndexForCurrentTime(time + lighttimeCompensation, minuteTimes);
getPositionInVector(compensatedIdx);
}
return glm::vec3(position.ra, position.dec, position.range);
}
bool RadecManager::radecParser(int index) const{
std::string filename;
filename = _dataFiles[index];
std::ifstream ifs(filename);
nlohmann::json j = nlohmann::json::parse(ifs);
if (index > -1 && index < _dataFiles.size()) {
filename = _dataFiles[index];
std::ifstream ifs(filename);
nlohmann::json j = nlohmann::json::parse(ifs);
int objectCounter = 0;
for (const auto& pos : j["Positions"]) {
objectCounter++;
try {
position.timeStamp = pos["TimeStamp"].get<std::string>();
position.ra = pos["RADn"].get<double>();
position.dec = pos["DecDn"].get<double>();
position.range = pos["GeoRngDn"].get<double>();
position.lightTravelTime = pos["DLT"].get<double>();
}
catch (const std::exception& e) {
LERROR(fmt::format("{}: Error in json object number {} while reading file '{}'", objectIdentifier, objectCounter, filename));
}
RadecManager::positions.push_back(position);
int objectCounter = 0;
for (const auto& pos : j["Positions"]) {
objectCounter++;
try {
position.timeStamp = pos["TimeStamp"].get<std::string>();
position.ra = pos["RADn"].get<double>();
position.dec = pos["DecDn"].get<double>();
position.range = pos["GeoRngDn"].get<double>();
position.lightTravelTime = pos["DLT"].get<double>();
}
catch (const std::exception& e) {
LERROR(fmt::format("{}: Error in json object number {} while reading file '{}'", objectIdentifier, objectCounter, filename));
}
RadecManager::positions.push_back(position);
}
return true;
}
return true;
else return false;
}
void RadecManager::updateActiveMinute(int idx) const{
minuteTimes.clear();
minuteTimes.reserve(0);
@@ -102,7 +114,6 @@ namespace openspace {
for (int i = 0; i < RadecManager::positions.size(); i++) {
minuteTimes.push_back(Time::convertTime(positions[i].timeStamp));
}
activeMinute = minuteTimes[idx];
}
@@ -145,7 +156,7 @@ namespace openspace {
if (lightTravelHours > 1)
index = index + lightTravelHours;
else if (index < 1) {
if (index < 1) {
radecParser(index);
radecParser(index + 1);
return;
@@ -159,8 +170,8 @@ namespace openspace {
radecParser(index - 1);
radecParser(index);
radecParser(index + 1);
}
}
}
}
+7 -4
View File
@@ -49,6 +49,7 @@ namespace openspace {
mutable std::vector<double> minuteTimes;
mutable Position position;
mutable double updateFrequency = 1;
mutable double activeMinute = -1;
/* Identifier for object using the translation, used for logging */
std::string objectIdentifier;
@@ -70,12 +71,14 @@ namespace openspace {
void updateActiveMinute(int idx) const;
/*Find the correct minute in the vector of loaded positions*/
RadecManager::Position getPositionInVector(int idx) const;
/*Check if current hour in open space is already loaded*/
bool correctHour(double time) const;
/*Check if current minute in open space is already loaded*/
bool correctMinute(double time) const;
/*Check if current file in open space is already loaded*/
bool correctFileInterval(double time) const;
/*Check if current time interval is still relevant*/
bool correctUpdateInterval(double time) const;
/*Update and reate buffer of data so that we can compensate for light travel time without getting out of bounce*/
void updateRadecData(int index) const;
/*Sets the update frequency from property*/
void setUpdateFrequency(double updateFrequency);
};
}
+29 -3
View File
@@ -32,6 +32,11 @@ namespace {
"Object Identifier",
"Identifier of the object that this translation is applied to."
};
constexpr openspace::properties::Property::PropertyInfo UpdateFrequencyInfo = {
"UpdateFrequency",
"Update Frequency",
"Determines how many minutes between positioning data reload. "
};
} // namespace
namespace openspace {
@@ -57,6 +62,12 @@ documentation::Documentation RadecTranslation::Documentation() {
Optional::No,
ObjectIdentifierInfo.description
},
{
UpdateFrequencyInfo.identifier,
new DoubleVerifier,
Optional::Yes,
UpdateFrequencyInfo.description
},
{
keyDataStart,
new StringVerifier,
@@ -75,10 +86,23 @@ documentation::Documentation RadecTranslation::Documentation() {
};
}
RadecTranslation::RadecTranslation() = default;
RadecTranslation::RadecTranslation()
: _updateFrequency(
UpdateFrequencyInfo, 1.f, 1.f, 100.f
)
{
addProperty(_updateFrequency);
_updateFrequency.onChange([this]() {
requireUpdate();
notifyObservers();
radecManager.setUpdateFrequency(_updateFrequency);
});
}
RadecTranslation::RadecTranslation(const ghoul::Dictionary& dictionary)
: RadecTranslation()
{
documentation::testSpecificationAndThrow(
Documentation(),
@@ -87,12 +111,14 @@ RadecTranslation::RadecTranslation(const ghoul::Dictionary& dictionary)
);
std::unique_ptr<ghoul::Dictionary> dictionaryPtr = std::make_unique<ghoul::Dictionary>(dictionary);
if (dictionary.hasKey(UpdateFrequencyInfo.identifier)) {
_updateFrequency = dictionary.value<float>(UpdateFrequencyInfo.identifier);
}
_dataStart = Time::convertTime(dictionaryPtr->value<std::string>(keyDataStart));
_dataEnd = Time::convertTime(dictionaryPtr->value<std::string>(keyDataEnd));
extractData(dictionaryPtr);
}
void RadecTranslation::extractData(std::unique_ptr<ghoul::Dictionary> &dictionary){
@@ -60,6 +60,8 @@ private:
mutable glm::vec3 _position;
///Determines between what dates there is data available. Set in the asset file.
double _dataStart, _dataEnd;
///Determines how many minutes between updates in positioning data
properties::FloatProperty _updateFrequency;
glm::dmat4 _rotEquatorialSphere = { -0.05487554, 0.4941095, -0.8676661, 0.0,
-0.8734371 , -0.4448296, -0.1980764, 0.0,