Skip to content
Snippets Groups Projects
Commit 6b97a40d authored by Sebastian Hahta's avatar Sebastian Hahta
Browse files

Merge branch 'feature/gui2' of gitlab.utu.fi:nicolas.pope/ftl into feature/gui2

parents bdd8f80c 087ed62a
No related branches found
No related tags found
1 merge request!316Resolves #343 GUI and Frame Refactor
Pipeline #28522 failed
......@@ -5,6 +5,10 @@
#include <ftl/rgbd/capabilities.hpp>
#include <chrono>
#include <opencv2/imgproc.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/cudaarithm.hpp>
#include <loguru.hpp>
using ftl::gui2::Camera;
......@@ -341,6 +345,19 @@ void Camera::startStreaming(const std::unordered_set<ftl::codecs::Channel> &chan
io->feed()->startStreaming(filter);
}
void Camera::snapshot(const std::string &filename) {
auto ptr = std::atomic_load(&latest_);
if (ptr) {
auto &frame = ptr->frames[frame_idx];
if (frame.hasChannel(channel)) {
const auto &snap = frame.get<cv::Mat>(channel);
cv::Mat output;
cv::cvtColor(snap, output, cv::COLOR_BGRA2BGR);
cv::imwrite(filename, output);
}
}
}
ftl::cuda::TextureObject<uchar4>& Camera::getFrame() {
if (std::atomic_load(&current_fs_)) {
auto& frame = current_fs_->frames[frame_idx].cast<ftl::rgbd::Frame>();
......
......@@ -61,6 +61,8 @@ public:
void startRecording(const std::string &filename, const std::unordered_set<ftl::codecs::Channel> &channels);
void startStreaming(const std::unordered_set<ftl::codecs::Channel> &channels);
void snapshot(const std::string &filename);
private:
int frame_idx = -1;
ftl::data::FrameID frame_id_;
......
......@@ -377,6 +377,29 @@ CameraView::CameraView(ftl::gui2::Screen* parent, ftl::gui2::Camera* ctrl) :
imview_->setCursor(nanogui::Cursor::Crosshair);
mod->setCursor(nanogui::Cursor::Crosshair);
}
auto theme = dynamic_cast<ftl::gui2::Screen*>(screen())->getTheme("toolbutton");
//this->setTheme(theme);
context_menu_ = new nanogui::Window(parent, "");
context_menu_->setVisible(false);
context_menu_->setLayout(new nanogui::BoxLayout(nanogui::Orientation::Vertical));
context_menu_->setTheme(theme);
auto *button = new nanogui::Button(context_menu_, "Capture Image");
button->setCallback([this]() {
char timestamp[18];
std::time_t t=std::time(NULL);
std::strftime(timestamp, sizeof(timestamp), "%F-%H%M%S", std::localtime(&t));
context_menu_->setVisible(false);
ctrl_->snapshot(std::string(timestamp)+std::string(".png"));
});
button = new nanogui::Button(context_menu_, "Settings");
button->setCallback([this, button]() {
context_menu_->setVisible(false);
ctrl_->screen->getModule<ftl::gui2::ConfigCtrl>()->show(ctrl_->getID());
});
}
CameraView::~CameraView() {
......@@ -385,6 +408,11 @@ CameraView::~CameraView() {
// should be fixed in nanogui
panel_->dispose();
}
if (context_menu_->parent()->getRefCount() > 0) {
context_menu_->setVisible(false);
context_menu_->dispose();
}
}
void CameraView::refresh() {
......@@ -434,8 +462,17 @@ bool CameraView::mouseButtonEvent(const Eigen::Vector2i &p, int button, bool dow
if (pos.x() >= 0.0f && pos.y() >= 0.0f) {
ctrl_->touch(0, ftl::codecs::TouchType::MOUSE_LEFT, pos.x(), pos.y(), 0.0f, (down) ? 255 : 0);
}
context_menu_->setVisible(false);
return true;
} else if (button == 1) {
if (!down) {
context_menu_->setPosition(p - mPos);
context_menu_->setVisible(true);
return true;
}
} else {
context_menu_->setVisible(false);
}
return false;
}
......
......@@ -34,6 +34,7 @@ protected:
Camera* ctrl_;
MediaPanel* panel_;
FTLImageView* imview_;
nanogui::Window *context_menu_;
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
......
......@@ -65,8 +65,7 @@ bool CameraView3D::keyboardEvent(int key, int scancode, int action, int modifier
}
bool CameraView3D::mouseButtonEvent(const Eigen::Vector2i &p, int button, bool down, int modifiers) {
LOG(INFO) << "mouseButtonEvent: " << p;
return true;
return CameraView::mouseButtonEvent(p, button, down, modifiers);
}
bool CameraView3D::mouseMotionEvent(const Eigen::Vector2i &p, const Eigen::Vector2i &rel, int button, int modifiers) {
......
......@@ -65,13 +65,13 @@ std::list<ftl::data::FrameSetPtr> Feed::Filter::getLatestFrameSets() {
SHARED_LOCK(feed_->mtx_, lk);
if (sources_.empty()) {
for (auto &i : feed_->latest_) {
results.emplace_back(std::atomic_load(&(i.second)));
if (i.second) results.emplace_back(std::atomic_load(&(i.second)));
}
} else {
for (auto &s : sources_) {
auto i = feed_->latest_.find(s);
if (i != feed_->latest_.end()) {
results.emplace_back(std::atomic_load(&(i->second)));
if (i->second) results.emplace_back(std::atomic_load(&(i->second)));
}
}
}
......@@ -181,10 +181,10 @@ Feed::Feed(nlohmann::json &config, ftl::net::Universe*net) :
pre_pipelines_[fs->frameset()]->apply(*fs, *fs, 0);
}
// FIXME: Adding new to latest_ will modify data structure in non-threadsafe way!
std::atomic_store(&latest_[fs->frameset()], fs);
SHARED_LOCK(mtx_, lk);
std::atomic_store(&latest_.at(fs->frameset()), fs);
for (auto* filter : filters_) {
// TODO: smarter update (update only when changed) instead of
// filter->channels_available_ = fs->channels();
......@@ -603,6 +603,7 @@ std::string Feed::getName(const std::string &puri) {
void Feed::add(uint32_t fsid, const std::string &uri, ftl::stream::Stream* stream) {
fsid_lookup_[uri] = fsid;
latest_[fsid] = nullptr;
streams_[fsid].push_back(stream);
_createPipeline(fsid);
......@@ -677,6 +678,7 @@ uint32_t Feed::add(const std::string &path) {
// Make the source object
ftl::data::DiscreteSource *source;
latest_[fsid] = nullptr;
lk.unlock();
if (uri.getBaseURI() == "device:render" || uri.getBaseURI() == "device:openvr") {
......@@ -768,7 +770,8 @@ uint32_t Feed::getID(const std::string &source) {
const std::unordered_set<Channel> Feed::availableChannels(ftl::data::FrameID id) {
ftl::data::FrameSetPtr fs;
std::atomic_store(&fs, latest_[id.frameset()]);
// FIXME: Should this be locked?
std::atomic_store(&fs, latest_.at(id.frameset()));
if (fs && fs->hasFrame(id.source())) {
return (*fs.get())[id.source()].allChannels();
}
......@@ -780,10 +783,12 @@ std::vector<ftl::data::FrameID> Feed::listFrames() {
SHARED_LOCK(mtx_, lk);
result.reserve(fsid_lookup_.size());
for (const auto [k, fs] : latest_) {
if (fs) {
for (unsigned i = 0; i < fs->frames.size(); i++) {
result.push_back(ftl::data::FrameID(k, i));
}
}
}
return result;
}
......@@ -817,9 +822,10 @@ std::vector<unsigned int> Feed::listFrameSets() {
std::vector<unsigned int> result;
result.reserve(fsid_lookup_.size());
for (const auto [k, fs] : latest_) {
std::ignore = fs;
if (fs) {
result.push_back(k);
}
}
return result;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment