From 00a66f780bca744da26437232e41f9f9ce0c4b96 Mon Sep 17 00:00:00 2001 From: Nicolas Pope <nwpope@utu.fi> Date: Tue, 29 Oct 2019 20:22:23 +0200 Subject: [PATCH] Code tidy again --- .../cpp/include/ftl/render/tri_render.hpp | 23 ++----------- components/renderers/cpp/src/tri_render.cpp | 32 ++++++------------- 2 files changed, 12 insertions(+), 43 deletions(-) diff --git a/components/renderers/cpp/include/ftl/render/tri_render.hpp b/components/renderers/cpp/include/ftl/render/tri_render.hpp index 6d03fd4a8..57dc68a7b 100644 --- a/components/renderers/cpp/include/ftl/render/tri_render.hpp +++ b/components/renderers/cpp/include/ftl/render/tri_render.hpp @@ -10,12 +10,8 @@ namespace ftl { namespace render { /** - * Render the voxel hash structure by generating image points for surface - * voxels and expanding those into interpolated splats. This is a two pass - * algorithm with the option of completing the second pass on a separate GPU. - * It also possible to only complete the first pass and perform the second step - * on a separate machine or at a later time, the advantage being to save local - * processing resources and that the first pass result may compress better. + * Generate triangles between connected points and render those. Colour is done + * by weighted reprojection to the original source images. */ class Triangular : public ftl::render::Renderer { public: @@ -30,15 +26,6 @@ class Triangular : public ftl::render::Renderer { private: int device_; - /*ftl::cuda::TextureObject<int> depth1_; - ftl::cuda::TextureObject<int> depth3_; - ftl::cuda::TextureObject<uchar4> colour1_; - ftl::cuda::TextureObject<float4> colour_tmp_; - ftl::cuda::TextureObject<float> depth2_; - ftl::cuda::TextureObject<uchar4> colour2_; - ftl::cuda::TextureObject<float4> normal1_;*/ - //SplatParams params_; - ftl::rgbd::Frame temp_; ftl::rgbd::Frame accum_; ftl::rgbd::FrameSet *scene_; @@ -47,7 +34,7 @@ class Triangular : public ftl::render::Renderer { float norm_filter_; bool backcull_; cv::Scalar background_; - bool splat_; + bool mesh_; float3 light_dir_; uchar4 light_diffuse_; uchar4 light_ambient_; @@ -55,10 +42,6 @@ class Triangular : public ftl::render::Renderer { cudaStream_t stream_; float3 light_pos_; - //template <typename T> - //void __blendChannel(ftl::rgbd::Frame &, ftl::codecs::Channel in, ftl::codecs::Channel out, cudaStream_t); - //void _blendChannel(ftl::rgbd::Frame &, ftl::codecs::Channel in, ftl::codecs::Channel out, cudaStream_t); - template <typename T> void __reprojectChannel(ftl::rgbd::Frame &, ftl::codecs::Channel in, ftl::codecs::Channel out, cudaStream_t); void _reprojectChannel(ftl::rgbd::Frame &, ftl::codecs::Channel in, ftl::codecs::Channel out, cudaStream_t); diff --git a/components/renderers/cpp/src/tri_render.cpp b/components/renderers/cpp/src/tri_render.cpp index 972e97fc9..4492716f9 100644 --- a/components/renderers/cpp/src/tri_render.cpp +++ b/components/renderers/cpp/src/tri_render.cpp @@ -103,9 +103,9 @@ Triangular::Triangular(nlohmann::json &config, ftl::rgbd::FrameSet *fs) : ftl::r backcull_ = value("back_cull", true); }); - splat_ = value("splatting", true); - on("splatting", [this](const ftl::config::Event &e) { - splat_ = value("splatting", true); + mesh_ = value("meshing", true); + on("meshing", [this](const ftl::config::Event &e) { + mesh_ = value("meshing", true); }); background_ = parseCVColour(value("background", std::string("#4c4c4c"))); @@ -212,7 +212,7 @@ void Triangular::__reprojectChannel(ftl::rgbd::Frame &output, ftl::codecs::Chann auto poseInv = MatrixConversion::toCUDA(s->getPose().cast<float>().inverse()); - if (splat_) { + if (mesh_) { ftl::cuda::reproject( f.createTexture<T>(in), f.createTexture<float>(Channel::Depth), // TODO: Use depth? @@ -472,43 +472,33 @@ bool Triangular::render(ftl::rgbd::VirtualSource *src, ftl::rgbd::Frame &out) { } // Create and render triangles for depth - if (splat_) { + if (mesh_) { _mesh(stream_); } else { _dibr(stream_); } - // Generate normals + // Generate normals for final virtual image ftl::cuda::normals(accum_.createTexture<float4>(Channel::Normals, Format<float4>(camera.width, camera.height)), temp_.createTexture<float4>(Channel::Normals), temp_.getTexture<int>(Channel::Depth2), 1, 0.02f, params_.camera, params_.m_viewMatrix.getFloat3x3(), params_.m_viewMatrixInverse.getFloat3x3(), stream_); + // Reprojection of colours onto surface _renderChannel(out, Channel::Colour, Channel::Colour, stream_); if (chan == Channel::Depth) { - //LOG(INFO) << "Copying depth"; + // Just convert int depth to float depth temp_.get<GpuMat>(Channel::Depth2).convertTo(out.get<GpuMat>(Channel::Depth), CV_32F, 1.0f / 1000.0f, cvstream); - //LOG(INFO) << "DEPTH COPIED"; } else if (chan == Channel::Normals) { - //out.create<GpuMat>(Channel::Normals, Format<uchar4>(camera.width, camera.height)); - - // Render normal attribute - //_renderChannel(out, Channel::Normals, Channel::Normals, stream_); - - // Convert normal to single float value - + // Visualise normals to RGBA out.create<GpuMat>(Channel::Normals, Format<uchar4>(camera.width, camera.height)).setTo(cv::Scalar(0,0,0,0), cvstream); ftl::cuda::normal_visualise(accum_.getTexture<float4>(Channel::Normals), out.createTexture<uchar4>(Channel::Normals), light_pos_, light_diffuse_, light_ambient_, stream_); - - // Put in output as single float - //cv::cuda::swap(temp_.get<GpuMat>(Channel::Colour), out.get<GpuMat>(Channel::Normals)); - //out.resetTexture(Channel::Normals); } //else if (chan == Channel::Contribution) //{ @@ -556,7 +546,3 @@ bool Triangular::render(ftl::rgbd::VirtualSource *src, ftl::rgbd::Frame &out) { cudaSafeCall(cudaStreamSynchronize(stream_)); return true; } - -//void Triangular::setOutputDevice(int device) { -// device_ = device; -//} -- GitLab