Skip to content
Snippets Groups Projects
Commit 7029fb63 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Display depth at cursor

parent 68d8259a
No related branches found
No related tags found
1 merge request!316Resolves #343 GUI and Frame Refactor
...@@ -235,6 +235,11 @@ void Camera::activate(ftl::data::FrameID id) { ...@@ -235,6 +235,11 @@ void Camera::activate(ftl::data::FrameID id) {
std::atomic_store(&current_fs_, fs); std::atomic_store(&current_fs_, fs);
std::atomic_store(&latest_, 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 // Need to notify GUI thread when first data comes
if (!has_seen_frame_) { if (!has_seen_frame_) {
//std::unique_lock<std::mutex> lk(m); //std::unique_lock<std::mutex> lk(m);
...@@ -270,10 +275,6 @@ void Camera::activate(ftl::data::FrameID id) { ...@@ -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(); screen->redraw();
nframes_++; nframes_++;
return true; return true;
...@@ -396,3 +397,19 @@ void Camera::touch(int id, ftl::codecs::TouchType t, int x, int y, float d, int ...@@ -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;
}
...@@ -52,6 +52,8 @@ public: ...@@ -52,6 +52,8 @@ public:
std::string getActiveSourceURI(); std::string getActiveSourceURI();
float depthAt(int x, int y);
bool isRecording(); bool isRecording();
void stopRecording(); void stopRecording();
void startRecording(const std::string &filename, const std::unordered_set<ftl::codecs::Channel> &channels); void startRecording(const std::string &filename, const std::unordered_set<ftl::codecs::Channel> &channels);
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <nanogui/layout.h> #include <nanogui/layout.h>
#include <nanogui/button.h> #include <nanogui/button.h>
#include <nanogui/vscrollpanel.h> #include <nanogui/vscrollpanel.h>
#include <ftl/utility/string.hpp>
#include <ftl/codecs/touch.hpp> #include <ftl/codecs/touch.hpp>
...@@ -394,6 +395,8 @@ bool CameraView::mouseMotionEvent(const Eigen::Vector2i &p, const Eigen::Vector2 ...@@ -394,6 +395,8 @@ bool CameraView::mouseMotionEvent(const Eigen::Vector2i &p, const Eigen::Vector2
auto pos = imview_->imageCoordinateAt((p - mPos + rel).cast<float>()); auto pos = imview_->imageCoordinateAt((p - mPos + rel).cast<float>());
if (pos.x() >= 0.0f && pos.y() >= 0.0f) { 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); 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; return true;
//} //}
...@@ -423,6 +426,14 @@ void CameraView::draw(NVGcontext*ctx) { ...@@ -423,6 +426,14 @@ void CameraView::draw(NVGcontext*ctx) {
} }
} }
View::draw(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) { void CameraView::performLayout(NVGcontext* ctx) {
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <ftl/streams/builder.hpp> #include <ftl/streams/builder.hpp>
#include <ftl/streams/netstream.hpp> #include <ftl/streams/netstream.hpp>
#include <ftl/render/colouriser.hpp> #include <ftl/render/colouriser.hpp>
#include <ftl/utility/string.hpp>
#include <nanogui/screen.h> #include <nanogui/screen.h>
#include <nanogui/opengl.h> #include <nanogui/opengl.h>
...@@ -13,14 +14,6 @@ ...@@ -13,14 +14,6 @@
using ftl::gui2::StatisticsWidget; using ftl::gui2::StatisticsWidget;
using std::string; 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) : StatisticsWidget::StatisticsWidget(nanogui::Widget* parent, ftl::gui2::Statistics* ctrl) :
nanogui::Widget(parent), ctrl_(ctrl), last_stats_count_(0) { nanogui::Widget(parent), ctrl_(ctrl), last_stats_count_(0) {
......
#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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment