From aadee2a40e95d181ebfdfe629c157e907fe6a852 Mon Sep 17 00:00:00 2001 From: Nicolas Pope <nwpope@utu.fi> Date: Thu, 20 Aug 2020 17:30:28 +0300 Subject: [PATCH] Don't render plane when missing depth --- components/renderers/cpp/src/CUDARender.cpp | 38 ++++++++++++------- .../include/ftl/data/new_frameset.hpp | 2 + components/structures/src/frameset.cpp | 7 ++++ 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/components/renderers/cpp/src/CUDARender.cpp b/components/renderers/cpp/src/CUDARender.cpp index 3b5a6adc4..dab897d56 100644 --- a/components/renderers/cpp/src/CUDARender.cpp +++ b/components/renderers/cpp/src/CUDARender.cpp @@ -250,6 +250,9 @@ void CUDARender::_mesh(ftl::rgbd::Frame &out, const Eigen::Matrix4d &t, cudaStre int valid_count = 0; + // FIXME: Is it possible to remember previously if there should be depth? + bool use_depth = scene_->anyHasChannel(Channel::Depth) || scene_->anyHasChannel(Channel::GroundTruth); + // For each source depth map for (size_t i=0; i < scene_->frames.size(); ++i) { //if (!scene_->hasFrame(i)) continue; @@ -261,6 +264,11 @@ void CUDARender::_mesh(ftl::rgbd::Frame &out, const Eigen::Matrix4d &t, cudaStre continue; } + // We have the needed depth data? + if (use_depth && !f.hasOwn(Channel::Depth) && !f.hasOwn(Channel::GroundTruth)) { + continue; + } + ++valid_count; //auto pose = MatrixConversion::toCUDA(t.cast<float>() * f.getPose().cast<float>()); @@ -273,20 +281,22 @@ void CUDARender::_mesh(ftl::rgbd::Frame &out, const Eigen::Matrix4d &t, cudaStre auto &screenbuffer = _getScreenBuffer(bufsize); // Calculate and save virtual view screen position of each source pixel - if (f.hasChannel(Channel::Depth)) { - ftl::cuda::screen_coord( - f.createTexture<float>(Channel::Depth), - depthbuffer, - screenbuffer, - params_, transform, f.getLeftCamera(), stream - ); - } else if (f.hasChannel(Channel::GroundTruth)) { - ftl::cuda::screen_coord( - f.createTexture<float>(Channel::GroundTruth), - depthbuffer, - screenbuffer, - params_, transform, f.getLeftCamera(), stream - ); + if (use_depth) { + if (f.hasChannel(Channel::Depth)) { + ftl::cuda::screen_coord( + f.createTexture<float>(Channel::Depth), + depthbuffer, + screenbuffer, + params_, transform, f.getLeftCamera(), stream + ); + } else if (f.hasChannel(Channel::GroundTruth)) { + ftl::cuda::screen_coord( + f.createTexture<float>(Channel::GroundTruth), + depthbuffer, + screenbuffer, + params_, transform, f.getLeftCamera(), stream + ); + } } else { // Constant depth version ftl::cuda::screen_coord( diff --git a/components/structures/include/ftl/data/new_frameset.hpp b/components/structures/include/ftl/data/new_frameset.hpp index 8dcc4b3b2..6eafe9cb5 100644 --- a/components/structures/include/ftl/data/new_frameset.hpp +++ b/components/structures/include/ftl/data/new_frameset.hpp @@ -134,6 +134,8 @@ class FrameSet : public ftl::data::Frame { */ bool hasAnyChanged(ftl::codecs::Channel) const; + bool anyHasChannel(ftl::codecs::Channel) const; + private: std::atomic<int> flags_; }; diff --git a/components/structures/src/frameset.cpp b/components/structures/src/frameset.cpp index cba77a213..e8cfd9404 100644 --- a/components/structures/src/frameset.cpp +++ b/components/structures/src/frameset.cpp @@ -78,6 +78,13 @@ bool ftl::data::FrameSet::hasAnyChanged(ftl::codecs::Channel c) const { return false; } +bool ftl::data::FrameSet::anyHasChannel(ftl::codecs::Channel c) const { + for (size_t i=0; i<frames.size(); ++i) { + if (frames[i].hasOwn(c)) return true; + } + return false; +} + void FrameSet::store() { if (status() != ftl::data::FrameStatus::CREATED) throw FTL_Error("Cannot store frameset multiple times"); -- GitLab