diff --git a/components/renderers/cpp/include/ftl/render/splat_render.hpp b/components/renderers/cpp/include/ftl/render/splat_render.hpp index 40bfa459b35e850d2147f74e33eabfaaddb3a261..93f31e16b200232235cba6893aeda1b8de578a93 100644 --- a/components/renderers/cpp/include/ftl/render/splat_render.hpp +++ b/components/renderers/cpp/include/ftl/render/splat_render.hpp @@ -45,6 +45,7 @@ class Splatter : public ftl::render::Renderer { bool clipping_; float norm_filter_; bool backcull_; + cv::Scalar background_; }; } diff --git a/components/renderers/cpp/src/splat_render.cpp b/components/renderers/cpp/src/splat_render.cpp index bfb627f6b2f0ca352d7635a9f418c3bec5af4166..94199d55c303f8ab471648e73b3830788efd34f4 100644 --- a/components/renderers/cpp/src/splat_render.cpp +++ b/components/renderers/cpp/src/splat_render.cpp @@ -6,11 +6,14 @@ #include <opencv2/core/cuda_stream_accessor.hpp> +#include <string> + using ftl::render::Splatter; using ftl::rgbd::Channel; using ftl::rgbd::Channels; using ftl::rgbd::Format; using cv::cuda::GpuMat; +using std::stoul; static Eigen::Affine3d create_rotation_matrix(float ax, float ay, float az) { Eigen::Affine3d rx = @@ -22,6 +25,22 @@ static Eigen::Affine3d create_rotation_matrix(float ax, float ay, float az) { return rz * rx * ry; } +static cv::Scalar parseColour(const std::string &colour) { + std::string c = colour; + if (c[0] == '#') { + c.erase(0, 1); + unsigned long value = stoul(c.c_str(), nullptr, 16); + return cv::Scalar( + (value >> 0) & 0xff, + (value >> 8) & 0xff, + (value >> 16) & 0xff, + (value >> 24) & 0xff + ); + } + + return cv::Scalar(0,0,0,0); +} + Splatter::Splatter(nlohmann::json &config, ftl::rgbd::FrameSet *fs) : ftl::render::Renderer(config), scene_(fs) { if (config["clipping"].is_object()) { auto &c = config["clipping"]; @@ -59,6 +78,11 @@ Splatter::Splatter(nlohmann::json &config, ftl::rgbd::FrameSet *fs) : ftl::rende on("back_cull", [this](const ftl::config::Event &e) { backcull_ = value("back_cull", true); }); + + background_ = parseColour(value("background", std::string("#e0e0e0"))); + on("background", [this](const ftl::config::Event &e) { + background_ = parseColour(value("background", std::string("#e0e0e0"))); + }); } Splatter::~Splatter() { @@ -236,7 +260,7 @@ bool Splatter::render(ftl::rgbd::VirtualSource *src, ftl::rgbd::Frame &out, cuda // Clear all channels to 0 or max depth out.get<GpuMat>(Channel::Depth).setTo(cv::Scalar(1000.0f), cvstream); - out.get<GpuMat>(Channel::Colour).setTo(cv::Scalar(76,76,76), cvstream); + out.get<GpuMat>(Channel::Colour).setTo(background_, cvstream); //LOG(INFO) << "Render ready: " << camera.width << "," << camera.height; @@ -310,7 +334,7 @@ bool Splatter::render(ftl::rgbd::VirtualSource *src, ftl::rgbd::Frame &out, cuda params.m_viewMatrixInverse = MatrixConversion::toCUDA(matrix); out.create<GpuMat>(Channel::Right, Format<uchar4>(camera.width, camera.height)); - out.get<GpuMat>(Channel::Right).setTo(cv::Scalar(76,76,76), cvstream); + out.get<GpuMat>(Channel::Right).setTo(background_, cvstream); renderChannel(params, out, Channel::Right, stream); } else if (chan != Channel::None) { if (ftl::rgbd::isFloatChannel(chan)) { @@ -318,7 +342,7 @@ bool Splatter::render(ftl::rgbd::VirtualSource *src, ftl::rgbd::Frame &out, cuda out.get<GpuMat>(chan).setTo(cv::Scalar(0.0f), cvstream); } else { out.create<GpuMat>(chan, Format<uchar4>(camera.width, camera.height)); - out.get<GpuMat>(chan).setTo(cv::Scalar(76,76,76,255), cvstream); + out.get<GpuMat>(chan).setTo(background_, cvstream); } renderChannel(params, out, chan, stream); }