mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-22 02:48:25 -05:00
Use proper default values- and clearify interface of TimeRange
This commit is contained in:
@@ -197,7 +197,7 @@ bool HongKangParser::create() {
|
||||
//store actual image in map. All targets get _only_ their corresp. subset.
|
||||
_subsetMap[image.target]._subset.push_back(image);
|
||||
//compute and store the range for each subset
|
||||
_subsetMap[image.target]._range.setRange(time);
|
||||
_subsetMap[image.target]._range.include(time);
|
||||
}
|
||||
if (it->second->getDecoderType() == "SCANNER"){ // SCANNER START
|
||||
scan_start = time;
|
||||
@@ -220,8 +220,8 @@ bool HongKangParser::create() {
|
||||
findPlaybookSpecifiedTarget(line, scannerTarget);
|
||||
scannerSpiceID = it->second->getTranslation();
|
||||
|
||||
scanRange._min = scan_start;
|
||||
scanRange._max = scan_stop;
|
||||
scanRange.start = scan_start;
|
||||
scanRange.end = scan_stop;
|
||||
_instrumentTimes.push_back(std::make_pair(it->first, scanRange));
|
||||
|
||||
//store individual image
|
||||
@@ -235,7 +235,7 @@ bool HongKangParser::create() {
|
||||
image.projected = false;
|
||||
|
||||
_subsetMap[scannerTarget]._subset.push_back(image);
|
||||
_subsetMap[scannerTarget]._range.setRange(scan_start);
|
||||
_subsetMap[scannerTarget]._range.include(scan_start);
|
||||
}
|
||||
}
|
||||
//go back to stored position in file
|
||||
@@ -246,8 +246,8 @@ bool HongKangParser::create() {
|
||||
if (capture_start != -1){
|
||||
//end of capture sequence for camera, store end time of this sequence
|
||||
capture_stop = time;
|
||||
cameraRange._min = capture_start;
|
||||
cameraRange._max = capture_stop;
|
||||
cameraRange.start = capture_start;
|
||||
cameraRange.end = capture_stop;
|
||||
_instrumentTimes.push_back(std::make_pair(previousCamera, cameraRange));
|
||||
|
||||
capture_start = -1;
|
||||
|
||||
@@ -199,7 +199,7 @@ std::map<std::string, bool> ImageSequencer::getActiveInstruments(){
|
||||
bool ImageSequencer::instrumentActive(std::string instrumentID) {
|
||||
for (const auto& i : _instrumentTimes) {
|
||||
//check if this instrument is in range
|
||||
if (i.second.inRange(_currentTime)) {
|
||||
if (i.second.includes(_currentTime)) {
|
||||
//if so, then get the corresponding spiceID
|
||||
std::vector<std::string> spiceIDs = _fileTranslation[i.first]->getTranslation();
|
||||
//check which specific subinstrument is firing
|
||||
@@ -216,13 +216,13 @@ bool ImageSequencer::instrumentActive(std::string instrumentID) {
|
||||
float ImageSequencer::instrumentActiveTime(const std::string& instrumentID) const {
|
||||
for (const auto& i : _instrumentTimes){
|
||||
//check if this instrument is in range
|
||||
if (i.second.inRange(_currentTime)){
|
||||
if (i.second.includes(_currentTime)){
|
||||
//if so, then get the corresponding spiceID
|
||||
std::vector<std::string> spiceIDs = _fileTranslation.at(i.first)->getTranslation();
|
||||
//check which specific subinstrument is firing
|
||||
for (auto s : spiceIDs){
|
||||
if (s == instrumentID) {
|
||||
return static_cast<float>((_currentTime - i.second._min) / (i.second._max - i.second._min));
|
||||
return static_cast<float>((_currentTime - i.second.start) / (i.second.end - i.second.start));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -240,8 +240,8 @@ bool ImageSequencer::getImagePaths(std::vector<Image>& captures,
|
||||
|
||||
|
||||
//if (!Time::ref().timeJumped() && projectee == getCurrentTarget().second)
|
||||
if (_subsetMap[projectee]._range.inRange(_currentTime) ||
|
||||
_subsetMap[projectee]._range.inRange(_previousTime)){
|
||||
if (_subsetMap[projectee]._range.includes(_currentTime) ||
|
||||
_subsetMap[projectee]._range.includes(_previousTime)){
|
||||
auto compareTime = [](const Image &a,
|
||||
const Image &b)->bool{
|
||||
return a.startTime < b.startTime;
|
||||
@@ -329,7 +329,7 @@ void ImageSequencer::sortData() {
|
||||
_instrumentTimes.begin(),
|
||||
_instrumentTimes.end(),
|
||||
[](const std::pair<std::string, TimeRange>& a, const std::pair<std::string, TimeRange>& b) {
|
||||
return a.second._min < b.second._min;
|
||||
return a.second.start < b.second.start;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -83,6 +83,7 @@ bool InstrumentTimesParser::create() {
|
||||
const std::pair<double, std::string> &b)->bool{
|
||||
return a.first < b.first;
|
||||
};
|
||||
|
||||
|
||||
using RawPath = ghoul::filesystem::Directory::RawPath;
|
||||
ghoul::filesystem::Directory sequenceDir(_fileName, RawPath::Yes);
|
||||
@@ -100,23 +101,28 @@ bool InstrumentTimesParser::create() {
|
||||
std::ifstream in(filepath);
|
||||
std::string line;
|
||||
std::smatch matches;
|
||||
|
||||
TimeRange instrumentActiveTimeRange;
|
||||
|
||||
while (std::getline(in, line)) {
|
||||
if (std::regex_match(line, matches, _pattern)) {
|
||||
ghoul_assert(matches.size() == 3, "Bad event data formatting. Must have regex 3 matches (source string, start time, stop time).");
|
||||
std::string start = matches[1].str();
|
||||
std::string stop = matches[2].str();
|
||||
|
||||
TimeRange timeRange;
|
||||
timeRange._min = SpiceManager::ref().ephemerisTimeFromDate(start);
|
||||
timeRange._max = SpiceManager::ref().ephemerisTimeFromDate(stop);
|
||||
TimeRange captureTimeRange;
|
||||
captureTimeRange.start = SpiceManager::ref().ephemerisTimeFromDate(start);
|
||||
captureTimeRange.end = SpiceManager::ref().ephemerisTimeFromDate(stop);
|
||||
|
||||
_instrumentTimes.push_back({ instrumentID, timeRange });
|
||||
_targetTimes.push_back({ timeRange._min, _target });
|
||||
_captureProgression.push_back(timeRange._min);
|
||||
instrumentActiveTimeRange.include(captureTimeRange);
|
||||
|
||||
//_instrumentTimes.push_back({ instrumentID, timeRange });
|
||||
_targetTimes.push_back({ captureTimeRange.start, _target });
|
||||
_captureProgression.push_back(captureTimeRange.start);
|
||||
|
||||
Image image;
|
||||
image.startTime = timeRange._min;
|
||||
image.stopTime = timeRange._max;
|
||||
image.startTime = captureTimeRange.start;
|
||||
image.stopTime = captureTimeRange.end;
|
||||
image.path = "";
|
||||
image.isPlaceholder = true;
|
||||
image.activeInstruments.push_back(instrumentID);
|
||||
@@ -124,9 +130,10 @@ bool InstrumentTimesParser::create() {
|
||||
image.projected = false;
|
||||
|
||||
_subsetMap[_target]._subset.push_back(image);
|
||||
_subsetMap[_target]._range.setRange(image.startTime);
|
||||
}
|
||||
}
|
||||
_subsetMap[_target]._range = instrumentActiveTimeRange;
|
||||
_instrumentTimes.push_back({ instrumentID, instrumentActiveTimeRange });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -249,7 +249,7 @@ bool LabelParser::create() {
|
||||
createImage(image, startTime, stopTime, spiceInstrument, _target, path);
|
||||
|
||||
_subsetMap[image.target]._subset.push_back(image);
|
||||
_subsetMap[image.target]._range.setRange(startTime);
|
||||
_subsetMap[image.target]._range.include(startTime);
|
||||
|
||||
_captureProgression.push_back(startTime);
|
||||
std::stable_sort(_captureProgression.begin(), _captureProgression.end());
|
||||
|
||||
@@ -46,19 +46,30 @@ struct Image {
|
||||
};
|
||||
|
||||
struct TimeRange {
|
||||
TimeRange() : _min(-1), _max(-1){};
|
||||
void setRange(double val){
|
||||
if (_min > val) _min = val;
|
||||
if (_max < val) _max = val;
|
||||
|
||||
TimeRange() : start(DBL_MAX), end(-DBL_MAX) { };
|
||||
TimeRange(double startTime, double endTime) : start(startTime) , end(endTime) { };
|
||||
|
||||
void include(double val){
|
||||
if (start > val) start = val;
|
||||
if (end < val) end = val;
|
||||
};
|
||||
|
||||
void include(const TimeRange& other) {
|
||||
if (other.start < start) start = other.start;
|
||||
if (other.end > end) end = other.end;
|
||||
}
|
||||
|
||||
bool inRange(double min, double max){
|
||||
return (min >= _min && max <= _max);
|
||||
return (min >= start && max <= end);
|
||||
}
|
||||
bool inRange(double val) const {
|
||||
return (val >= _min && val <= _max);
|
||||
|
||||
bool includes(double val) const {
|
||||
return (start <= val && val <= end);
|
||||
}
|
||||
double _min;
|
||||
double _max;
|
||||
|
||||
double start;
|
||||
double end;
|
||||
};
|
||||
|
||||
struct ImageSubset {
|
||||
|
||||
Reference in New Issue
Block a user