From 495215acf6f8a96d4c2031951e9e7293be992df8 Mon Sep 17 00:00:00 2001 From: Nicolas Pope <nwpope@utu.fi> Date: Wed, 8 Jul 2020 09:37:13 +0300 Subject: [PATCH] GUI to use actual available channels in frame --- applications/gui2/src/modules/camera.cpp | 3 ++- .../structures/include/ftl/data/new_frame.hpp | 2 +- components/structures/src/new_frame.cpp | 16 +++++++++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/applications/gui2/src/modules/camera.cpp b/applications/gui2/src/modules/camera.cpp index eb8d9ea31..5eb1a71e6 100644 --- a/applications/gui2/src/modules/camera.cpp +++ b/applications/gui2/src/modules/camera.cpp @@ -63,7 +63,7 @@ void Camera::_initiate(ftl::data::Frame &frame) { } }); - panel->setAvailableChannels({Channel::Colour, Channel::Right, Channel::Depth}); + panel->setAvailableChannels(frame.available()); setChannel(channel); screen->setView(view); @@ -101,6 +101,7 @@ void Camera::activate(ftl::data::FrameID id) { ); // For first data, extract useful things and create view + // Must be done in GUI thread, hence use of cv. std::unique_lock<std::mutex> lk(m); cv.wait_for(lk, 1s, [this](){ return has_seen_frame_; }); _initiate(std::atomic_load(¤t_fs_)->frames[frame_idx]); diff --git a/components/structures/include/ftl/data/new_frame.hpp b/components/structures/include/ftl/data/new_frame.hpp index 59f9b5781..71a21283c 100644 --- a/components/structures/include/ftl/data/new_frame.hpp +++ b/components/structures/include/ftl/data/new_frame.hpp @@ -164,7 +164,7 @@ class Frame { inline const std::unordered_map<ftl::codecs::Channel, ChangeType> &changed() const { return changed_; } - std::unordered_set<ftl::codecs::Channel> channels(); + std::unordered_set<ftl::codecs::Channel> channels() const; template <typename T> bool isType(ftl::codecs::Channel c) const; diff --git a/components/structures/src/new_frame.cpp b/components/structures/src/new_frame.cpp index 7872f2d82..b9ccbc6ce 100644 --- a/components/structures/src/new_frame.cpp +++ b/components/structures/src/new_frame.cpp @@ -7,6 +7,7 @@ using ftl::data::Session; using ftl::data::ChannelConfig; using ftl::data::StorageMode; using ftl::data::FrameStatus; +using ftl::codecs::Channel; #define LOGURU_REPLACE_GLOG 1 #include <loguru.hpp> @@ -97,6 +98,19 @@ bool ftl::data::Frame::availableAll(const std::unordered_set<ftl::codecs::Channe return result; } +std::unordered_set<ftl::codecs::Channel> ftl::data::Frame::available() const { + std::unordered_set<ftl::codecs::Channel> result = channels(); + + uint64_t m = 1; + // TODO: NAIVE, use ffs or ctz. + for (int i=0; i<32; ++i) { + if (m & available_) result.emplace(static_cast<Channel>(i)); + m <<= 1; + } + + return result; +} + void ftl::data::Frame::remove(ftl::codecs::Channel c) { const auto &i = data_.find(c); if (i != data_.end()) { @@ -377,7 +391,7 @@ Frame Frame::make_standalone() { return f; } -std::unordered_set<ftl::codecs::Channel> Frame::channels() { +std::unordered_set<ftl::codecs::Channel> Frame::channels() const { std::unordered_set<ftl::codecs::Channel> res{}; for (const auto& [k, v] : data_) { std::ignore = v; -- GitLab