mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-30 07:49:31 -05:00
Feature/cleanup (#1608)
* Revert screenlog back to showing Info and above messages * Various code cleanup
This commit is contained in:
@@ -41,6 +41,7 @@ ImageSequencer& ImageSequencer::ref() {
|
||||
ghoul_assert(_instance != nullptr, "Instance has not been initialized");
|
||||
return *_instance;
|
||||
}
|
||||
|
||||
void ImageSequencer::initialize() {
|
||||
ghoul_assert(_instance == nullptr, "Instance already has been initialized");
|
||||
_instance = new ImageSequencer;
|
||||
@@ -52,11 +53,11 @@ void ImageSequencer::deinitialize() {
|
||||
_instance = nullptr;
|
||||
}
|
||||
|
||||
bool ImageSequencer::isReady() {
|
||||
bool ImageSequencer::isReady() const {
|
||||
return _hasData;
|
||||
}
|
||||
|
||||
std::pair<double, std::string> ImageSequencer::nextTarget(double time) {
|
||||
std::pair<double, std::string> ImageSequencer::nextTarget(double time) const {
|
||||
const auto it = std::lower_bound(
|
||||
_targetTimes.begin(),
|
||||
_targetTimes.end(),
|
||||
@@ -72,7 +73,7 @@ std::pair<double, std::string> ImageSequencer::nextTarget(double time) {
|
||||
}
|
||||
}
|
||||
|
||||
std::pair<double, std::string> ImageSequencer::currentTarget(double time) {
|
||||
std::pair<double, std::string> ImageSequencer::currentTarget(double time) const {
|
||||
const auto it = std::lower_bound(
|
||||
_targetTimes.begin(),
|
||||
_targetTimes.end(),
|
||||
@@ -80,7 +81,7 @@ std::pair<double, std::string> ImageSequencer::currentTarget(double time) {
|
||||
[](const std::pair<double, std::string>& a, double b) { return a.first < b; }
|
||||
);
|
||||
|
||||
if (it != _targetTimes.end() && it != _targetTimes.begin()){
|
||||
if (it != _targetTimes.end() && it != _targetTimes.begin()) {
|
||||
return *std::prev(it);
|
||||
}
|
||||
else {
|
||||
@@ -88,51 +89,25 @@ std::pair<double, std::string> ImageSequencer::currentTarget(double time) {
|
||||
}
|
||||
}
|
||||
|
||||
std::pair<double, std::vector<std::string>> ImageSequencer::incidentTargetList(
|
||||
double time,
|
||||
int range)
|
||||
{
|
||||
std::pair<double, std::vector<std::string>> incidentTargets;
|
||||
|
||||
auto it = std::lower_bound(
|
||||
_targetTimes.begin(),
|
||||
_targetTimes.end(),
|
||||
time,
|
||||
[](const std::pair<double, std::string>& a, double b) { return a.first < b; }
|
||||
);
|
||||
|
||||
if (it != _targetTimes.end() && it != _targetTimes.begin()){
|
||||
// move the iterator to the first element of the range
|
||||
std::advance(it, -(range + 1));
|
||||
|
||||
// now extract incident range
|
||||
for (int i = 0; i < 2 * range + 1; i++){
|
||||
incidentTargets.first = it->first;
|
||||
incidentTargets.second.push_back(it->second);
|
||||
it++;
|
||||
if (it == _targetTimes.end()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return incidentTargets;
|
||||
}
|
||||
|
||||
double ImageSequencer::intervalLength(double time) {
|
||||
const double upcoming = nextCaptureTime(time);
|
||||
if (_nextCapture != upcoming) {
|
||||
_nextCapture = upcoming;
|
||||
_intervalLength = upcoming - time;
|
||||
}
|
||||
return _intervalLength;
|
||||
}
|
||||
|
||||
double ImageSequencer::nextCaptureTime(double currentTime) {
|
||||
double ImageSequencer::prevCaptureTime(double time) const {
|
||||
const auto it = std::lower_bound(
|
||||
_captureProgression.begin(),
|
||||
_captureProgression.end(),
|
||||
currentTime
|
||||
time
|
||||
);
|
||||
if (it != _captureProgression.end() && it != _captureProgression.begin()) {
|
||||
return *std::prev(it);
|
||||
}
|
||||
else {
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
double ImageSequencer::nextCaptureTime(double time) const {
|
||||
const auto it = std::lower_bound(
|
||||
_captureProgression.begin(),
|
||||
_captureProgression.end(),
|
||||
time
|
||||
);
|
||||
if (it != _captureProgression.end()) {
|
||||
return *it;
|
||||
@@ -142,10 +117,10 @@ double ImageSequencer::nextCaptureTime(double currentTime) {
|
||||
}
|
||||
}
|
||||
|
||||
Image ImageSequencer::latestImageForInstrument(const std::string& instrumentID) {
|
||||
Image ImageSequencer::latestImageForInstrument(const std::string& instrumentID) const {
|
||||
const auto it = _latestImages.find(instrumentID);
|
||||
if (it != _latestImages.end()) {
|
||||
return _latestImages[instrumentID];
|
||||
return _latestImages.at(instrumentID);
|
||||
}
|
||||
else {
|
||||
return Image();
|
||||
@@ -177,23 +152,24 @@ std::vector<std::pair<std::string, bool>> ImageSequencer::activeInstruments(doub
|
||||
}
|
||||
}
|
||||
}
|
||||
// return entire map, seen in GUI.
|
||||
// return entire map, seen in GUI
|
||||
return _switchingMap;
|
||||
}
|
||||
|
||||
bool ImageSequencer::isInstrumentActive(double time, const std::string& instrumentID) {
|
||||
bool ImageSequencer::isInstrumentActive(double time, const std::string& instrument) const
|
||||
{
|
||||
for (const std::pair<std::string, TimeRange>& i : _instrumentTimes) {
|
||||
//check if this instrument is in range
|
||||
if (i.second.includes(time)) {
|
||||
//if so, then get the corresponding spiceID
|
||||
const std::vector<std::string>& ids =
|
||||
_fileTranslation[i.first]->translations();
|
||||
//check which specific subinstrument is firing
|
||||
for (const std::string& s : ids) {
|
||||
if (s == instrumentID) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// check if this instrument is in range
|
||||
if (!i.second.includes(time)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// if so, then get the corresponding spiceID
|
||||
const std::vector<std::string>& is = _fileTranslation.at(i.first)->translations();
|
||||
// check which specific subinstrument is firing
|
||||
const auto it = std::find(is.begin(), is.end(), instrument);
|
||||
if (it != is.end()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -203,50 +179,47 @@ float ImageSequencer::instrumentActiveTime(double time,
|
||||
const std::string& instrumentID) const
|
||||
{
|
||||
for (const std::pair<std::string, TimeRange>& i : _instrumentTimes) {
|
||||
//check if this instrument is in range
|
||||
if (i.second.includes(time)){
|
||||
//if so, then get the corresponding spiceID
|
||||
const std::vector<std::string>& ids =
|
||||
_fileTranslation.at(i.first)->translations();
|
||||
// check if this instrument is in range
|
||||
if (!i.second.includes(time)) {
|
||||
continue;
|
||||
}
|
||||
// if so, then get the corresponding spiceID
|
||||
const std::vector<std::string>& is = _fileTranslation.at(i.first)->translations();
|
||||
|
||||
// check which specific subinstrument is firing
|
||||
for (const std::string& s : ids) {
|
||||
if (s == instrumentID) {
|
||||
return static_cast<float>(
|
||||
(time - i.second.start) / (i.second.end - i.second.start)
|
||||
);
|
||||
}
|
||||
}
|
||||
// check which specific subinstrument is firing
|
||||
const auto it = std::find(is.begin(), is.end(), instrumentID);
|
||||
if (it != is.end()) {
|
||||
return static_cast<float>(
|
||||
(time - i.second.start) / (i.second.end - i.second.start)
|
||||
);
|
||||
}
|
||||
}
|
||||
return -1.f;
|
||||
}
|
||||
|
||||
bool ImageSequencer::imagePaths(std::vector<Image>& captures,
|
||||
const std::string& projectee,
|
||||
const std::string& instrumentRequest,
|
||||
double time, double sinceTime)
|
||||
std::vector<Image> ImageSequencer::imagePaths(const std::string& projectee,
|
||||
const std::string& instrument, double time,
|
||||
double sinceTime)
|
||||
{
|
||||
// TODO: Check how this works with time jumps
|
||||
|
||||
// check if this instance is either in range or
|
||||
// a valid candidate to recieve data
|
||||
|
||||
const bool instrumentActive = isInstrumentActive(time, instrumentRequest);
|
||||
const bool instrumentActive = isInstrumentActive(time, instrument);
|
||||
const bool hasCurrentTime = _subsetMap[projectee]._range.includes(time);
|
||||
const bool hasSinceTime = _subsetMap[projectee]._range.includes(sinceTime);
|
||||
|
||||
if (!instrumentActive || (!hasCurrentTime && !hasSinceTime)) {
|
||||
return false;
|
||||
return std::vector<Image>();
|
||||
}
|
||||
|
||||
|
||||
// for readability we store the iterators
|
||||
auto begin = _subsetMap[projectee]._subset.begin();
|
||||
auto end = _subsetMap[projectee]._subset.end();
|
||||
auto end = _subsetMap[projectee]._subset.end();
|
||||
|
||||
// create temporary storage
|
||||
std::vector<Image> captureTimes;
|
||||
std::vector<Image> captures;
|
||||
// what to look for
|
||||
Image findPrevious, findCurrent;
|
||||
findPrevious.timeRange.start = sinceTime;
|
||||
@@ -259,59 +232,52 @@ bool ImageSequencer::imagePaths(std::vector<Image>& captures,
|
||||
auto curr = std::lower_bound(begin, end, findCurrent , compareTime);
|
||||
auto prev = std::lower_bound(begin, end, findPrevious, compareTime);
|
||||
|
||||
if (curr == begin || curr == end || prev == begin || prev == end || prev >= curr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (curr->timeRange.start < prev->timeRange.start) {
|
||||
return false;
|
||||
if (curr == begin || curr == end || prev == begin || prev == end || prev >= curr ||
|
||||
curr->timeRange.start < prev->timeRange.start)
|
||||
{
|
||||
return std::vector<Image>();
|
||||
}
|
||||
|
||||
std::copy_if(
|
||||
prev,
|
||||
curr,
|
||||
back_inserter(captureTimes),
|
||||
[instrumentRequest](const Image& i) {
|
||||
return i.activeInstruments[0] == instrumentRequest;
|
||||
}
|
||||
back_inserter(captures),
|
||||
[instrument](const Image& i) { return i.activeInstruments[0] == instrument; }
|
||||
);
|
||||
|
||||
captures = captureTimes;
|
||||
if (!captures.empty()) {
|
||||
_latestImages[captures.back().activeInstruments.front()] = captures.back();
|
||||
}
|
||||
|
||||
std::vector<int> toDelete;
|
||||
for (auto it = captures.begin(); it != captures.end(); ++it) {
|
||||
if (it->isPlaceholder) {
|
||||
double beforeDist = std::numeric_limits<double>::max();
|
||||
if (it != captures.begin()) {
|
||||
beforeDist = std::abs(
|
||||
std::prev(it)->timeRange.start - it->timeRange.start
|
||||
);
|
||||
}
|
||||
for (std::vector<Image>::iterator it = captures.begin(); it != captures.end(); ++it) {
|
||||
if (!it->isPlaceholder) {
|
||||
continue;
|
||||
}
|
||||
|
||||
double nextDist = std::numeric_limits<double>::max();
|
||||
if (it != captures.end() - 1) {
|
||||
nextDist = std::abs(
|
||||
std::next(it)->timeRange.start - it->timeRange.start
|
||||
);
|
||||
}
|
||||
double beforeDist = std::numeric_limits<double>::max();
|
||||
if (it != captures.begin()) {
|
||||
beforeDist = std::abs(std::prev(it)->timeRange.start - it->timeRange.start);
|
||||
}
|
||||
|
||||
if (beforeDist < 1.0 || nextDist < 1.0) {
|
||||
toDelete.push_back(static_cast<int>(std::distance(captures.begin(), it)));
|
||||
}
|
||||
double nextDist = std::numeric_limits<double>::max();
|
||||
if (it != captures.end() - 1) {
|
||||
nextDist = std::abs(std::next(it)->timeRange.start - it->timeRange.start);
|
||||
}
|
||||
|
||||
if (beforeDist < 1.0 || nextDist < 1.0) {
|
||||
toDelete.push_back(static_cast<int>(std::distance(captures.begin(), it)));
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < toDelete.size(); ++i) {
|
||||
// We have to subtract i here as we already have deleted i value
|
||||
// before this and we need to adjust the location
|
||||
// We have to subtract i here as we already have deleted i value before this and
|
||||
// we need to adjust the location
|
||||
int v = toDelete[i] - static_cast<int>(i);
|
||||
captures.erase(captures.begin() + v);
|
||||
}
|
||||
|
||||
return true;
|
||||
return captures;
|
||||
}
|
||||
|
||||
void ImageSequencer::sortData() {
|
||||
@@ -348,15 +314,12 @@ void ImageSequencer::sortData() {
|
||||
}
|
||||
|
||||
void ImageSequencer::runSequenceParser(SequenceParser& parser) {
|
||||
// get new data
|
||||
std::map<std::string, std::unique_ptr<Decoder>>& translations =
|
||||
parser.translations();
|
||||
std::map<std::string, ImageSubset>& imageData = parser.getSubsetMap();
|
||||
std::map<std::string, std::unique_ptr<Decoder>>& translations = parser.translations();
|
||||
std::map<std::string, ImageSubset>& imageData = parser.subsetMap();
|
||||
const std::vector<std::pair<std::string, TimeRange>>& instrumentTimes =
|
||||
parser.getInstrumentTimes();
|
||||
const std::vector<std::pair<double, std::string>>& targetTimes =
|
||||
parser.getTargetTimes();
|
||||
const std::vector<double>& captureProgression = parser.getCaptureProgression();
|
||||
parser.instrumentTimes();
|
||||
const std::vector<std::pair<double, std::string>>& targetTimes = parser.targetTimes();
|
||||
const std::vector<double>& captureProgression = parser.captureProgression();
|
||||
|
||||
// check for sanity
|
||||
if (imageData.empty() || instrumentTimes.empty() || captureProgression.empty()) {
|
||||
@@ -382,11 +345,9 @@ void ImageSequencer::runSequenceParser(SequenceParser& parser) {
|
||||
|
||||
// simple search function
|
||||
double min = 10;
|
||||
auto findMin = [&](const std::vector<Image>& vector) -> double {
|
||||
for (size_t i = 1; i < vector.size(); ++i) {
|
||||
double e = std::abs(
|
||||
vector[i].timeRange.start - vector[i - 1].timeRange.start
|
||||
);
|
||||
auto findMin = [&](const std::vector<Image>& vec) -> double {
|
||||
for (size_t i = 1; i < vec.size(); ++i) {
|
||||
double e = std::abs(vec[i].timeRange.start - vec[i - 1].timeRange.start);
|
||||
min = std::min(e, min);
|
||||
}
|
||||
return min;
|
||||
@@ -394,7 +355,6 @@ void ImageSequencer::runSequenceParser(SequenceParser& parser) {
|
||||
|
||||
// find the smallest separation of images in time
|
||||
double epsilon;
|
||||
//epsilon = findMin(source);
|
||||
epsilon = findMin(destination);
|
||||
// set epsilon as 1% smaller than min
|
||||
epsilon -= min * 0.01;
|
||||
@@ -409,8 +369,7 @@ void ImageSequencer::runSequenceParser(SequenceParser& parser) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// pad image data with predictions (ie - where no actual images,
|
||||
// add placeholder)
|
||||
// pad image data with predictions (ie - where no actual images, add placeholder)
|
||||
_subsetMap[key]._subset.insert(
|
||||
_subsetMap[key]._subset.end(),
|
||||
source.begin(),
|
||||
@@ -425,11 +384,7 @@ void ImageSequencer::runSequenceParser(SequenceParser& parser) {
|
||||
instrumentTimes.begin(),
|
||||
instrumentTimes.end()
|
||||
);
|
||||
_targetTimes.insert(
|
||||
_targetTimes.end(),
|
||||
targetTimes.begin(),
|
||||
targetTimes.end()
|
||||
);
|
||||
_targetTimes.insert(_targetTimes.end(), targetTimes.begin(), targetTimes.end());
|
||||
_captureProgression.insert(
|
||||
_captureProgression.end(),
|
||||
captureProgression.begin(),
|
||||
|
||||
Reference in New Issue
Block a user