From 0e5c9d46005a77f7230289a345117563e42e22c2 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Thu, 3 Oct 2019 20:49:02 +0300
Subject: [PATCH] Allow splat enable disable

---
 .../cpp/include/ftl/render/splat_render.hpp   |  1 +
 components/renderers/cpp/src/splat_render.cpp | 67 ++++++++++---------
 2 files changed, 38 insertions(+), 30 deletions(-)

diff --git a/components/renderers/cpp/include/ftl/render/splat_render.hpp b/components/renderers/cpp/include/ftl/render/splat_render.hpp
index 93f31e16b..5f8a8ba49 100644
--- a/components/renderers/cpp/include/ftl/render/splat_render.hpp
+++ b/components/renderers/cpp/include/ftl/render/splat_render.hpp
@@ -46,6 +46,7 @@ class Splatter : public ftl::render::Renderer {
 	float norm_filter_;
 	bool backcull_;
 	cv::Scalar background_;
+	bool splat_;
 };
 
 }
diff --git a/components/renderers/cpp/src/splat_render.cpp b/components/renderers/cpp/src/splat_render.cpp
index 94199d55c..26f8e893e 100644
--- a/components/renderers/cpp/src/splat_render.cpp
+++ b/components/renderers/cpp/src/splat_render.cpp
@@ -79,6 +79,11 @@ Splatter::Splatter(nlohmann::json &config, ftl::rgbd::FrameSet *fs) : ftl::rende
 		backcull_ = value("back_cull", true);
 	});
 
+	splat_ = value("splatting", true);
+	on("splatting", [this](const ftl::config::Event &e) {
+		splat_ = value("splatting", true);
+	});
+
 	background_ = parseColour(value("background", std::string("#e0e0e0")));
 	on("background", [this](const ftl::config::Event &e) {
 		background_ = parseColour(value("background", std::string("#e0e0e0")));
@@ -170,7 +175,7 @@ void Splatter::renderChannel(
 				f.createTexture<float4>(channel),
 				f.createTexture<float4>(Channel::Points),
 				temp_.getTexture<int>(Channel::Depth2),
-				temp_.createTexture<float4>(Channel::Colour2),
+				(splat_) ? temp_.createTexture<float4>(Channel::Colour2) : out.createTexture<float4>(channel),
 				params, stream
 			);
 		} else if (is_float) {
@@ -178,7 +183,7 @@ void Splatter::renderChannel(
 				f.createTexture<float>(channel),
 				f.createTexture<float4>(Channel::Points),
 				temp_.getTexture<int>(Channel::Depth2),
-				temp_.createTexture<float>(Channel::Colour2),
+				(splat_) ? temp_.createTexture<float>(Channel::Colour2) : out.createTexture<float>(channel),
 				params, stream
 			);
 		} else {
@@ -186,7 +191,7 @@ void Splatter::renderChannel(
 				f.createTexture<uchar4>(channel),
 				f.createTexture<float4>(Channel::Points),
 				temp_.getTexture<int>(Channel::Depth2),
-				temp_.createTexture<uchar4>(Channel::Colour2),
+				(splat_) ? temp_.createTexture<uchar4>(Channel::Colour2) : out.createTexture<uchar4>(channel),
 				params, stream
 			);
 		}
@@ -195,33 +200,35 @@ void Splatter::renderChannel(
 	//out.get<GpuMat>(Channel::Left).setTo(cv::Scalar(0,0,0,0), cvstream);
 
 	// Now splat the points
-	if (is_4chan) {
-		ftl::cuda::splat(
-			out.getTexture<float4>(Channel::Normals),
-			temp_.getTexture<float4>(Channel::Colour2),
-			temp_.getTexture<int>(Channel::Depth2),
-			out.createTexture<float>(Channel::Depth),
-			out.createTexture<float4>(channel),
-			params, stream
-		);
-	} else if (is_float) {
-		ftl::cuda::splat(
-			out.getTexture<float4>(Channel::Normals),
-			temp_.getTexture<float>(Channel::Colour2),
-			temp_.getTexture<int>(Channel::Depth2),
-			out.createTexture<float>(Channel::Depth),
-			out.createTexture<float>(channel),
-			params, stream
-		);
-	} else {
-		ftl::cuda::splat(
-			out.getTexture<float4>(Channel::Normals),
-			temp_.getTexture<uchar4>(Channel::Colour2),
-			temp_.getTexture<int>(Channel::Depth2),
-			out.createTexture<float>(Channel::Depth),
-			out.createTexture<uchar4>(channel),
-			params, stream
-		);
+	if (splat_) {
+		if (is_4chan) {
+			ftl::cuda::splat(
+				out.getTexture<float4>(Channel::Normals),
+				temp_.getTexture<float4>(Channel::Colour2),
+				temp_.getTexture<int>(Channel::Depth2),
+				out.createTexture<float>(Channel::Depth),
+				out.createTexture<float4>(channel),
+				params, stream
+			);
+		} else if (is_float) {
+			ftl::cuda::splat(
+				out.getTexture<float4>(Channel::Normals),
+				temp_.getTexture<float>(Channel::Colour2),
+				temp_.getTexture<int>(Channel::Depth2),
+				out.createTexture<float>(Channel::Depth),
+				out.createTexture<float>(channel),
+				params, stream
+			);
+		} else {
+			ftl::cuda::splat(
+				out.getTexture<float4>(Channel::Normals),
+				temp_.getTexture<uchar4>(Channel::Colour2),
+				temp_.getTexture<int>(Channel::Depth2),
+				out.createTexture<float>(Channel::Depth),
+				out.createTexture<uchar4>(channel),
+				params, stream
+			);
+		}
 	}
 }
 
-- 
GitLab