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

Merge branch 'bug/multiframesetdraw' into 'master'

Resolves a recent multi-frameset update bug

See merge request nicolas.pope/ftl!269
parents 0cbd95da 7b8d6566
No related branches found
No related tags found
1 merge request!269Resolves a recent multi-frameset update bug
Pipeline #22320 passed
...@@ -121,6 +121,13 @@ static Eigen::Vector3f cudaToEigen(const float3 &v) { ...@@ -121,6 +121,13 @@ static Eigen::Vector3f cudaToEigen(const float3 &v) {
return e; return e;
} }
void ftl::gui::Camera::drawUpdated(std::vector<ftl::rgbd::FrameSet*> &fss) {
// Only draw if frameset updated.
if (!stale_frame_.test_and_set()) {
draw(fss);
}
}
void ftl::gui::Camera::draw(std::vector<ftl::rgbd::FrameSet*> &fss) { void ftl::gui::Camera::draw(std::vector<ftl::rgbd::FrameSet*> &fss) {
if (fid_ != 255) return; if (fid_ != 255) return;
//if (fsid_ >= fss.size()) return; //if (fsid_ >= fss.size()) return;
...@@ -294,7 +301,9 @@ void ftl::gui::Camera::_draw(std::vector<ftl::rgbd::FrameSet*> &fss) { ...@@ -294,7 +301,9 @@ void ftl::gui::Camera::_draw(std::vector<ftl::rgbd::FrameSet*> &fss) {
} catch(std::exception &e) { } catch(std::exception &e) {
LOG(ERROR) << "Exception in render: " << e.what(); LOG(ERROR) << "Exception in render: " << e.what();
} }
for (auto *fs : fss) { for (auto *fs : fss) {
if (!usesFrameset(fs->id)) continue;
fs->mtx.unlock(); fs->mtx.unlock();
} }
} }
...@@ -366,8 +375,6 @@ void ftl::gui::Camera::_downloadFrames(ftl::cuda::TextureObject<uchar4> &a, ftl: ...@@ -366,8 +375,6 @@ void ftl::gui::Camera::_downloadFrames(ftl::cuda::TextureObject<uchar4> &a, ftl:
if (im2_.cols != im1_.cols || im2_.rows != im1_.rows) { if (im2_.cols != im1_.cols || im2_.rows != im1_.rows) {
throw FTL_Error("Left and right images are different sizes"); throw FTL_Error("Left and right images are different sizes");
} }
new_frame_.clear();
} }
void ftl::gui::Camera::_downloadFrame(ftl::cuda::TextureObject<uchar4> &a) { void ftl::gui::Camera::_downloadFrame(ftl::cuda::TextureObject<uchar4> &a) {
...@@ -381,8 +388,6 @@ void ftl::gui::Camera::_downloadFrame(ftl::cuda::TextureObject<uchar4> &a) { ...@@ -381,8 +388,6 @@ void ftl::gui::Camera::_downloadFrame(ftl::cuda::TextureObject<uchar4> &a) {
height_ = im1_.rows; height_ = im1_.rows;
im2_ = cv::Mat(); im2_ = cv::Mat();
new_frame_.clear();
} }
void ftl::gui::Camera::update(int fsid, const ftl::codecs::Channels<0> &c) { void ftl::gui::Camera::update(int fsid, const ftl::codecs::Channels<0> &c) {
...@@ -398,6 +403,7 @@ void ftl::gui::Camera::update(std::vector<ftl::rgbd::FrameSet*> &fss) { ...@@ -398,6 +403,7 @@ void ftl::gui::Camera::update(std::vector<ftl::rgbd::FrameSet*> &fss) {
UNIQUE_LOCK(mutex_, lk); UNIQUE_LOCK(mutex_, lk);
framesets_ = &fss; framesets_ = &fss;
stale_frame_.clear();
//if (fss.size() <= fsid_) return; //if (fss.size() <= fsid_) return;
if (fid_ == 255) { if (fid_ == 255) {
...@@ -405,7 +411,7 @@ void ftl::gui::Camera::update(std::vector<ftl::rgbd::FrameSet*> &fss) { ...@@ -405,7 +411,7 @@ void ftl::gui::Camera::update(std::vector<ftl::rgbd::FrameSet*> &fss) {
// Do a draw if not active. If active the draw function will be called // Do a draw if not active. If active the draw function will be called
// directly. // directly.
if (screen_->activeCamera() != this) { if (screen_->activeCamera() != this) {
_draw(fss); //_draw(fss);
} }
} else { } else {
for (auto *fs : fss) { for (auto *fs : fss) {
...@@ -707,7 +713,7 @@ const void ftl::gui::Camera::captureFrame() { ...@@ -707,7 +713,7 @@ const void ftl::gui::Camera::captureFrame() {
if (framesets_) draw(*framesets_); if (framesets_) draw(*framesets_);
{ {
//UNIQUE_LOCK(mutex_, lk); UNIQUE_LOCK(mutex_, lk);
if (im1_.rows != 0) { if (im1_.rows != 0) {
texture1_.update(im1_); texture1_.update(im1_);
} }
......
...@@ -67,6 +67,12 @@ class Camera { ...@@ -67,6 +67,12 @@ class Camera {
*/ */
void update(int fsid, const ftl::codecs::Channels<0> &c); void update(int fsid, const ftl::codecs::Channels<0> &c);
/**
* Draw virtual camera only if the frameset has been updated since last
* draw.
*/
void drawUpdated(std::vector<ftl::rgbd::FrameSet*> &fss);
void draw(std::vector<ftl::rgbd::FrameSet*> &fss); void draw(std::vector<ftl::rgbd::FrameSet*> &fss);
inline int64_t getFrameTimeMS() const { return int64_t(delta_ * 1000.0f); } inline int64_t getFrameTimeMS() const { return int64_t(delta_ * 1000.0f); }
...@@ -131,7 +137,7 @@ class Camera { ...@@ -131,7 +137,7 @@ class Camera {
cv::Mat im1_; // first channel (left) cv::Mat im1_; // first channel (left)
cv::Mat im2_; // second channel ("right") cv::Mat im2_; // second channel ("right")
bool stereo_; bool stereo_;
std::atomic_flag new_frame_; std::atomic_flag stale_frame_;
int rx_; int rx_;
int ry_; int ry_;
std::vector<ftl::rgbd::FrameSet*> *framesets_; std::vector<ftl::rgbd::FrameSet*> *framesets_;
......
...@@ -551,6 +551,12 @@ void ftl::gui::Screen::draw(NVGcontext *ctx) { ...@@ -551,6 +551,12 @@ void ftl::gui::Screen::draw(NVGcontext *ctx) {
mShader.drawIndexed(GL_TRIANGLES, 0, 2); mShader.drawIndexed(GL_TRIANGLES, 0, 2);
//glDisable(GL_SCISSOR_TEST); //glDisable(GL_SCISSOR_TEST);
} }
} else {
// Must periodically render the cameras here to update any thumbnails.
auto cams = swindow_->getCameras();
for (auto *c : cams) {
c->drawUpdated(swindow_->getFramesets());
}
} }
nvgTextAlign(ctx, NVG_ALIGN_RIGHT); nvgTextAlign(ctx, NVG_ALIGN_RIGHT);
......
...@@ -74,6 +74,12 @@ SourceWindow::SourceWindow(ftl::gui::Screen *screen) ...@@ -74,6 +74,12 @@ SourceWindow::SourceWindow(ftl::gui::Screen *screen)
new Label(this, "Select Camera","sans-bold",20); new Label(this, "Select Camera","sans-bold",20);
// FIXME: Reallocating the vector may currently causes thread issues since
// it might be in use elsewhere. A safer mechanism is needed for sharing
// framesets. Temporary solution: preallocate enough slots.
pre_pipelines_.reserve(5);
framesets_.reserve(5);
auto vscroll = new VScrollPanel(this); auto vscroll = new VScrollPanel(this);
ipanel_ = new Widget(vscroll); ipanel_ = new Widget(vscroll);
ipanel_->setLayout(new GridLayout(nanogui::Orientation::Horizontal, 2, ipanel_->setLayout(new GridLayout(nanogui::Orientation::Horizontal, 2,
...@@ -179,11 +185,6 @@ bool SourceWindow::_processFrameset(ftl::rgbd::FrameSet &fs, bool fromstream) { ...@@ -179,11 +185,6 @@ bool SourceWindow::_processFrameset(ftl::rgbd::FrameSet &fs, bool fromstream) {
interceptor_->select(fs.id, cs); interceptor_->select(fs.id, cs);
} }
/*if (fs.id > 0) {
LOG(INFO) << "Got frameset: " << fs.id;
return true;
}*/
// Make sure there are enough framesets allocated // Make sure there are enough framesets allocated
_checkFrameSets(fs.id); _checkFrameSets(fs.id);
...@@ -375,6 +376,7 @@ void SourceWindow::draw(NVGcontext *ctx) { ...@@ -375,6 +376,7 @@ void SourceWindow::draw(NVGcontext *ctx) {
cv::Mat t; cv::Mat t;
auto *cam = camera.second.camera; auto *cam = camera.second.camera;
if (cam) { if (cam) {
//cam->draw(framesets_);
if (cam->thumbnail(t)) { if (cam->thumbnail(t)) {
thumbs_[i].update(t); thumbs_[i].update(t);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment