diff --git a/applications/gui2/src/modules/camera.cpp b/applications/gui2/src/modules/camera.cpp index 1bf50c6a93b6388cb983a282f51f75056ad1ae43..1103dd0dfcdb5833d092665485606237272d0689 100644 --- a/applications/gui2/src/modules/camera.cpp +++ b/applications/gui2/src/modules/camera.cpp @@ -235,6 +235,11 @@ void Camera::activate(ftl::data::FrameID id) { std::atomic_store(¤t_fs_, fs); std::atomic_store(&latest_, fs); + // Deal with audio + if (fs->frames[frame_idx].hasOwn(Channel::AudioStereo)) { + speaker->queue(fs->timestamp(), fs->frames[frame_idx]); + } + // Need to notify GUI thread when first data comes if (!has_seen_frame_) { //std::unique_lock<std::mutex> lk(m); @@ -270,10 +275,6 @@ void Camera::activate(ftl::data::FrameID id) { } } - // Deal with audio - if (fs->frames[frame_idx].hasOwn(Channel::AudioStereo)) { - speaker->queue(fs->timestamp(), fs->frames[frame_idx]); - } screen->redraw(); nframes_++; return true; @@ -396,3 +397,19 @@ void Camera::touch(int id, ftl::codecs::TouchType t, int x, int y, float d, int }*/ } + +float Camera::depthAt(int x, int y) { + auto ptr = std::atomic_load(&latest_); + + if (ptr) { + const auto &frame = ptr->frames[frame_idx].cast<ftl::rgbd::Frame>(); + + if (frame.hasChannel(Channel::Depth)) { + const auto &depth = frame.get<cv::Mat>(Channel::Depth); + if (x >= 0 && y >= 0 && x < depth.cols && y < depth.rows) { + return depth.at<float>(y, x); + } + } + } + return 0.0f; +} diff --git a/applications/gui2/src/modules/camera.hpp b/applications/gui2/src/modules/camera.hpp index a33a1950c3ca762874cdb6fb2a1002902d5bbdff..2f2857b3a389219057aaee4a8c1b7114f385874b 100644 --- a/applications/gui2/src/modules/camera.hpp +++ b/applications/gui2/src/modules/camera.hpp @@ -52,6 +52,8 @@ public: std::string getActiveSourceURI(); + float depthAt(int x, int y); + bool isRecording(); void stopRecording(); void startRecording(const std::string &filename, const std::unordered_set<ftl::codecs::Channel> &channels); diff --git a/applications/gui2/src/views/camera.cpp b/applications/gui2/src/views/camera.cpp index 4b4dd782fcf83b6dcc10673f5968b057739069b0..87469f85107b37c86c021093aa9e0d3338aacd26 100644 --- a/applications/gui2/src/views/camera.cpp +++ b/applications/gui2/src/views/camera.cpp @@ -2,6 +2,7 @@ #include <nanogui/layout.h> #include <nanogui/button.h> #include <nanogui/vscrollpanel.h> +#include <ftl/utility/string.hpp> #include <ftl/codecs/touch.hpp> @@ -394,6 +395,8 @@ bool CameraView::mouseMotionEvent(const Eigen::Vector2i &p, const Eigen::Vector2 auto pos = imview_->imageCoordinateAt((p - mPos + rel).cast<float>()); if (pos.x() >= 0.0f && pos.y() >= 0.0f) { ctrl_->touch(0, ftl::codecs::TouchType::MOUSE_LEFT, pos.x(), pos.y(), 0.0f, (button > 0) ? 255 : 0); + + //LOG(INFO) << "Depth at " << pos.x() << "," << pos.y() << " = " << ctrl_->depthAt(pos.x(), pos.y()); } return true; //} @@ -423,6 +426,14 @@ void CameraView::draw(NVGcontext*ctx) { } } View::draw(ctx); + + auto mouse = screen()->mousePos(); + auto pos = imview_->imageCoordinateAt((mouse - mPos).cast<float>()); + float d = ctrl_->depthAt(pos.x(), pos.y()); + + if (d > 0.0f) { + nvgText(ctx, mouse.x()+25.0f, mouse.y()+20.0f, (to_string_with_precision(d,2) + std::string("m")).c_str(), nullptr); + } } void CameraView::performLayout(NVGcontext* ctx) { diff --git a/applications/gui2/src/views/statistics.cpp b/applications/gui2/src/views/statistics.cpp index 7a512c096ad2c7fe31b8656adfb6ad2b42645c90..a593ac942c9506ebba0b6b020ed54d2d36cbed34 100644 --- a/applications/gui2/src/views/statistics.cpp +++ b/applications/gui2/src/views/statistics.cpp @@ -4,6 +4,7 @@ #include <ftl/streams/builder.hpp> #include <ftl/streams/netstream.hpp> #include <ftl/render/colouriser.hpp> +#include <ftl/utility/string.hpp> #include <nanogui/screen.h> #include <nanogui/opengl.h> @@ -13,14 +14,6 @@ using ftl::gui2::StatisticsWidget; using std::string; -template <typename T> -std::string to_string_with_precision(const T a_value, const int n = 6) { - std::ostringstream out; - out.precision(n); - out << std::fixed << a_value; - return out.str(); -} - StatisticsWidget::StatisticsWidget(nanogui::Widget* parent, ftl::gui2::Statistics* ctrl) : nanogui::Widget(parent), ctrl_(ctrl), last_stats_count_(0) { diff --git a/components/common/cpp/include/ftl/utility/string.hpp b/components/common/cpp/include/ftl/utility/string.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d88aa11532a649702fa4325970e60c2fac16ca7c --- /dev/null +++ b/components/common/cpp/include/ftl/utility/string.hpp @@ -0,0 +1,12 @@ +#ifndef _FTL_UTILITY_STRING_HPP_ +#define _FTL_UTILITY_STRING_HPP_ + +template <typename T> +std::string to_string_with_precision(const T a_value, const int n = 6) { + std::ostringstream out; + out.precision(n); + out << std::fixed << a_value; + return out.str(); +} + +#endif \ No newline at end of file