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

Render overlay text labels

parent cabc2aed
No related branches found
No related tags found
1 merge request!316Resolves #343 GUI and Frame Refactor
Pipeline #28492 passed
......@@ -366,10 +366,10 @@ bool Camera::hasFrame() {
return false;
}
void Camera::drawOverlay() {
void Camera::drawOverlay(NVGcontext *ctx) {
auto ptr = std::atomic_load(&latest_);
// TODO: Need all the source framesets here or all data dumped in by renderer
overlay_->draw(*ptr, ptr->frames[frame_idx].cast<ftl::rgbd::Frame>(), view->size().cast<float>());
overlay_->draw(ctx, *ptr, ptr->frames[frame_idx].cast<ftl::rgbd::Frame>(), view->size().cast<float>());
}
void Camera::sendPose(const Eigen::Matrix4d &pose) {
......
......@@ -50,7 +50,7 @@ public:
ftl::render::Colouriser* colouriser() { return colouriser_.get(); };
ftl::overlay::Overlay* overlay() { return overlay_.get(); }
void drawOverlay();
void drawOverlay(NVGcontext *ctx);
std::string getActiveSourceURI();
......
......@@ -447,7 +447,7 @@ void CameraView::draw(NVGcontext*ctx) {
}
View::draw(ctx);
ctrl_->drawOverlay();
ctrl_->drawOverlay(ctx);
auto mouse = screen()->mousePos();
auto pos = imview_->imageCoordinateAt((mouse - mPos).cast<float>());
......
......@@ -6,6 +6,8 @@
#include <ftl/rgbd/frameset.hpp>
#include <nanogui/glutil.h>
struct NVGcontext;
namespace ftl {
namespace overlay {
......@@ -24,7 +26,7 @@ class Overlay : public ftl::Configurable {
//void apply(ftl::rgbd::FrameSet &fs, cv::Mat &out, ftl::rgbd::FrameState &state);
void draw(ftl::data::FrameSet &fs, ftl::rgbd::Frame &frame, const Eigen::Vector2f &);
void draw(NVGcontext *, ftl::data::FrameSet &fs, ftl::rgbd::Frame &frame, const Eigen::Vector2f &);
private:
nanogui::GLShader oShader;
......
#include <ftl/render/overlay.hpp>
#include <ftl/utility/matrix_conversion.hpp>
#include <ftl/cuda_common.hpp>
#include <opencv2/imgproc.hpp>
......@@ -241,7 +242,7 @@ void Overlay::_drawAxis(const Eigen::Matrix4d &pose, const Eigen::Vector3f &scal
(const void *)(loffset * sizeof(uint32_t)));
}
void Overlay::draw(ftl::data::FrameSet &fs, ftl::rgbd::Frame &frame, const Eigen::Vector2f &screenSize) {
void Overlay::draw(NVGcontext *ctx, ftl::data::FrameSet &fs, ftl::rgbd::Frame &frame, const Eigen::Vector2f &screenSize) {
if (!value("enabled", false)) return;
double zfar = 8.0f;
......@@ -296,6 +297,7 @@ void Overlay::draw(ftl::data::FrameSet &fs, ftl::rgbd::Frame &frame, const Eigen
if (value("show_poses", true)) {
for (size_t i=0; i<fs.frames.size(); ++i) {
auto &f = fs.frames[i].cast<ftl::rgbd::Frame>();
if (f.id().id == frame.id().id) continue;
auto pose = f.getPose(); //.inverse() * state.getPose();
......@@ -304,8 +306,18 @@ void Overlay::draw(ftl::data::FrameSet &fs, ftl::rgbd::Frame &frame, const Eigen
const auto &meta = fs.frames[i].get<std::map<std::string,std::string>>(Channel::MetaData);
name = (meta.count("name")) ? meta.find("name")->second : "NoName";
}
_drawOutlinedShape(Shape::CAMERA, frame.getPose().inverse() * pose, Eigen::Vector3f(0.2f,0.2f,0.2f), make_uchar4(255,0,0,80), make_uchar4(255,0,0,255));
_drawAxis(frame.getPose().inverse() * pose, Eigen::Vector3f(0.2f, 0.2f, 0.2f));
auto tpose = frame.getPose().inverse() * pose;
_drawOutlinedShape(Shape::CAMERA, tpose, Eigen::Vector3f(0.2f,0.2f,0.2f), make_uchar4(255,0,0,80), make_uchar4(255,0,0,255));
_drawAxis(tpose, Eigen::Vector3f(0.2f, 0.2f, 0.2f));
float3 textpos;
textpos.x = tpose(0,3);
textpos.y = tpose(1,3);
textpos.z = tpose(2,3);
float2 textscreen = f.getLeft().camToScreen<float2>(textpos);
nvgText(ctx, textscreen.x, textscreen.y, name.c_str(), nullptr);
//ftl::overlay::drawCamera(state.getLeft(), out, over_depth_, fs.frames[i].getLeftCamera(), pose, cv::Scalar(0,0,255,255), 0.2,value("show_frustrum", false));
//if (name) ftl::overlay::drawText(state.getLeft(), out, over_depth_, *name, pos, 0.5, cv::Scalar(0,0,255,255));
......@@ -359,13 +371,25 @@ void Overlay::draw(ftl::data::FrameSet &fs, ftl::rgbd::Frame &frame, const Eigen
Eigen::Vector3f scale(s.size[0]/2.0f, s.size[1]/2.0f, s.size[2]/2.0f);
auto tpose = frame.getPose().inverse() * pose;
switch (s.type) {
case ftl::codecs::Shape3DType::CAMERA: _drawOutlinedShape(Shape::CAMERA, frame.getPose().inverse() * pose, scale, make_uchar4(255,0,0,80), make_uchar4(255,0,0,255)); break;
case ftl::codecs::Shape3DType::CLIPPING: _drawOutlinedShape(Shape::BOX, frame.getPose().inverse() * pose, scale, make_uchar4(255,0,255,80), make_uchar4(255,0,255,255)); break;
case ftl::codecs::Shape3DType::ARUCO: _drawAxis(frame.getPose().inverse() * pose, Eigen::Vector3f(0.2f, 0.2f, 0.2f)); break;
case ftl::codecs::Shape3DType::CAMERA: _drawOutlinedShape(Shape::CAMERA, tpose, scale, make_uchar4(255,0,0,80), make_uchar4(255,0,0,255)); break;
case ftl::codecs::Shape3DType::CLIPPING: _drawOutlinedShape(Shape::BOX, tpose, scale, make_uchar4(255,0,255,80), make_uchar4(255,0,255,255)); break;
case ftl::codecs::Shape3DType::ARUCO: _drawAxis(tpose, Eigen::Vector3f(0.2f, 0.2f, 0.2f)); break;
default: break;
}
if (s.label.size() > 0) {
float3 textpos;
textpos.x = tpose(0,3);
textpos.y = tpose(1,3);
textpos.z = tpose(2,3);
float2 textscreen = frame.getLeft().camToScreen<float2>(textpos);
nvgText(ctx, textscreen.x, textscreen.y, s.label.c_str(), nullptr);
}
//ftl::overlay::drawBox(state.getLeft(), out, over_depth_, pose, cv::Scalar(0,0,255,100), s.size.cast<double>());
//ftl::overlay::drawText(state.getLeft(), out, over_depth_, s.label, pos, 0.5, cv::Scalar(0,0,255,100));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment