Load OSFLS states into RAM and keep track of trigger times

This commit is contained in:
Oskar Carlbaum
2017-09-20 18:02:01 +02:00
parent 94d0cc3ddd
commit 8ff9cb403e
2 changed files with 32 additions and 1 deletions

View File

@@ -67,11 +67,25 @@ void RenderableFieldlinesSequence::initialize() {
LERROR("JSON NOT YET IMPLEMENTED!");
break;
case OSFLS:
LERROR("OSFLS NOT YET IMPLEMENTED!");
if (_isLoadingStatesAtRuntime) {
LERROR("OSFLS LOAD AT RUNTIME NOT YET IMPLEMENTED!");
} else {
for (string filePath : _sourceFiles) {
FieldlinesState newState;
bool loadedSuccessfully = newState.loadStateFromOsfls(filePath);
if (loadedSuccessfully) {
_states.push_back(newState);
_startTimes.push_back(newState.triggerTime());
_nStates++;
}
}
}
break;
default:
break;
}
computeSequenceEndTime();
}
void RenderableFieldlinesSequence::deinitialize() {
@@ -171,4 +185,17 @@ bool RenderableFieldlinesSequence::extractInfoFromDictionary(
}
}
// Calculate expected end time.
void RenderableFieldlinesSequence::computeSequenceEndTime() {
if (_nStates > 1) {
const double LAST_TRIGGER_TIME = _startTimes[_nStates - 1];
const double SEQUENCE_DURATION = LAST_TRIGGER_TIME - _startTimes[0];
const double AVERAGE_STATE_DURATION = SEQUENCE_DURATION / (static_cast<double>(_nStates) - 1.0);
_sequenceEndTime = LAST_TRIGGER_TIME + AVERAGE_STATE_DURATION;
} else {
// If there's just one state it should never disappear!
_sequenceEndTime = DBL_MAX;
}
}
} // namespace openspace

View File

@@ -52,11 +52,15 @@ private:
};
bool _isLoadingStatesAtRuntime = false; // False => loading osfls at runtime
size_t _nStates = 0;
double _sequenceEndTime;
SourceFileType _sourceFileType;
std::vector<double> _startTimes;
std::vector<FieldlinesState> _states;
std::vector<std::string> _sourceFiles; // Stored in RAM if files are loaded at runtime, else emptied after initialization
void computeSequenceEndTime();
bool extractInfoFromDictionary(const ghoul::Dictionary& dictionary);
};