From f79acf61490743fd6a35be6bbdbeb6e608ad8724 Mon Sep 17 00:00:00 2001 From: Nicolas Pope <nwpope@utu.fi> Date: Thu, 3 Oct 2019 21:56:49 +0300 Subject: [PATCH] Colours from config --- .../cpp/include/ftl/cuda/normals.hpp | 2 +- .../cpp/include/ftl/render/splat_render.hpp | 3 ++ components/renderers/cpp/src/normals.cu | 4 +- components/renderers/cpp/src/splat_render.cpp | 44 ++++++++++++++++--- 4 files changed, 44 insertions(+), 9 deletions(-) diff --git a/components/renderers/cpp/include/ftl/cuda/normals.hpp b/components/renderers/cpp/include/ftl/cuda/normals.hpp index 4cfaccc14..b4d2ced19 100644 --- a/components/renderers/cpp/include/ftl/cuda/normals.hpp +++ b/components/renderers/cpp/include/ftl/cuda/normals.hpp @@ -14,7 +14,7 @@ void normals(ftl::cuda::TextureObject<float4> &output, void normal_visualise(ftl::cuda::TextureObject<float4> &norm, ftl::cuda::TextureObject<uchar4> &output, - const float3 &light, const float3 &diffuse, const float3 &ambient, + const float3 &light, const uchar4 &diffuse, const uchar4 &ambient, cudaStream_t stream); void normal_filter(ftl::cuda::TextureObject<float4> &norm, diff --git a/components/renderers/cpp/include/ftl/render/splat_render.hpp b/components/renderers/cpp/include/ftl/render/splat_render.hpp index 5f8a8ba49..af6affb10 100644 --- a/components/renderers/cpp/include/ftl/render/splat_render.hpp +++ b/components/renderers/cpp/include/ftl/render/splat_render.hpp @@ -47,6 +47,9 @@ class Splatter : public ftl::render::Renderer { bool backcull_; cv::Scalar background_; bool splat_; + float3 light_dir_; + uchar4 light_diffuse_; + uchar4 light_ambient_; }; } diff --git a/components/renderers/cpp/src/normals.cu b/components/renderers/cpp/src/normals.cu index 08fd9794b..cbbd0e967 100644 --- a/components/renderers/cpp/src/normals.cu +++ b/components/renderers/cpp/src/normals.cu @@ -90,7 +90,7 @@ void ftl::cuda::normals(ftl::cuda::TextureObject<float4> &output, __global__ void vis_normals_kernel(ftl::cuda::TextureObject<float4> norm, ftl::cuda::TextureObject<uchar4> output, - float3 direction, float3 diffuse, float3 ambient) { + float3 direction, uchar4 diffuse, uchar4 ambient) { const unsigned int x = blockIdx.x*blockDim.x + threadIdx.x; const unsigned int y = blockIdx.y*blockDim.y + threadIdx.y; @@ -113,7 +113,7 @@ __global__ void vis_normals_kernel(ftl::cuda::TextureObject<float4> norm, void ftl::cuda::normal_visualise(ftl::cuda::TextureObject<float4> &norm, ftl::cuda::TextureObject<uchar4> &output, - const float3 &light, const float3 &diffuse, const float3 &ambient, + const float3 &light, const uchar4 &diffuse, const uchar4 &ambient, cudaStream_t stream) { const dim3 gridSize((norm.width() + T_PER_BLOCK - 1)/T_PER_BLOCK, (norm.height() + T_PER_BLOCK - 1)/T_PER_BLOCK); diff --git a/components/renderers/cpp/src/splat_render.cpp b/components/renderers/cpp/src/splat_render.cpp index 41d1a4217..d993e1458 100644 --- a/components/renderers/cpp/src/splat_render.cpp +++ b/components/renderers/cpp/src/splat_render.cpp @@ -25,7 +25,10 @@ static Eigen::Affine3d create_rotation_matrix(float ax, float ay, float az) { return rz * rx * ry; } -static cv::Scalar parseColour(const std::string &colour) { +/* + * Parse a CSS style colour string into a scalar. + */ +static cv::Scalar parseCVColour(const std::string &colour) { std::string c = colour; if (c[0] == '#') { c.erase(0, 1); @@ -41,6 +44,25 @@ static cv::Scalar parseColour(const std::string &colour) { return cv::Scalar(0,0,0,0); } +/* + * Parse a CSS style colour string into a scalar. + */ +static uchar4 parseCUDAColour(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 make_uchar4( + (value >> 0) & 0xff, + (value >> 8) & 0xff, + (value >> 16) & 0xff, + (value >> 24) & 0xff + ); + } + + return make_uchar4(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"]; @@ -84,9 +106,19 @@ Splatter::Splatter(nlohmann::json &config, ftl::rgbd::FrameSet *fs) : ftl::rende splat_ = value("splatting", true); }); - background_ = parseColour(value("background", std::string("#e0e0e0"))); + background_ = parseCVColour(value("background", std::string("#4c4c4c"))); on("background", [this](const ftl::config::Event &e) { - background_ = parseColour(value("background", std::string("#e0e0e0"))); + background_ = parseCVColour(value("background", std::string("#4c4c4c"))); + }); + + light_diffuse_ = parseCUDAColour(value("diffuse", std::string("#e0e0e0"))); + on("diffuse", [this](const ftl::config::Event &e) { + light_diffuse_ = parseCUDAColour(value("diffuse", std::string("#e0e0e0"))); + }); + + light_ambient_ = parseCUDAColour(value("ambient", std::string("#0e0e0e"))); + on("ambient", [this](const ftl::config::Event &e) { + light_ambient_ = parseCUDAColour(value("ambient", std::string("#0e0e0e"))); }); } @@ -324,9 +356,9 @@ bool Splatter::render(ftl::rgbd::VirtualSource *src, ftl::rgbd::Frame &out, cuda // Convert normal to single float value temp_.create<GpuMat>(Channel::Colour, Format<uchar4>(camera.width, camera.height)); ftl::cuda::normal_visualise(out.getTexture<float4>(Channel::Normals), temp_.createTexture<uchar4>(Channel::Colour), - make_float3(0.0f, 0.0f, 1.0f), - make_float3(220,220,220), - make_float3(30,30,30), stream); + make_float3(-0.3f, 0.2f, 1.0f), + light_diffuse_, + light_ambient_, stream); // Put in output as single float cv::cuda::swap(temp_.get<GpuMat>(Channel::Colour), out.create<GpuMat>(Channel::Normals)); -- GitLab