From 6c5ea3a2abb17a1ac50542820bed9056ae520331 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Sun, 6 Oct 2019 12:48:45 +0300
Subject: [PATCH] Mess with confidence channel

---
 applications/reconstruct/src/ilw/ilw.cpp             |  2 +-
 applications/reconstruct/src/ilw/ilw.cu              | 12 ++++++------
 components/renderers/cpp/src/splat_render.cpp        |  8 ++++----
 .../rgbd-sources/include/ftl/rgbd/channels.hpp       |  1 +
 4 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/applications/reconstruct/src/ilw/ilw.cpp b/applications/reconstruct/src/ilw/ilw.cpp
index 741e457aa..5aa62b530 100644
--- a/applications/reconstruct/src/ilw/ilw.cpp
+++ b/applications/reconstruct/src/ilw/ilw.cpp
@@ -23,7 +23,7 @@ ILW::ILW(nlohmann::json &config) : ftl::Configurable(config) {
     params_.spatial_smooth = value("spatial_smooth", 0.04f);
     params_.cost_ratio = value("cost_ratio", 0.2f);
 	discon_mask_ = value("discontinuity_mask",2);
-	fill_depth_ = value("fill_depth", true);
+	fill_depth_ = value("fill_depth", false);
 
     on("fill_depth", [this](const ftl::config::Event &e) {
         fill_depth_ = value("fill_depth", true);
diff --git a/applications/reconstruct/src/ilw/ilw.cu b/applications/reconstruct/src/ilw/ilw.cu
index d36d609a1..af5916cf0 100644
--- a/applications/reconstruct/src/ilw/ilw.cu
+++ b/applications/reconstruct/src/ilw/ilw.cu
@@ -160,21 +160,21 @@ __global__ void correspondence_energy_vector_kernel(
 			const float depth2 = d2.tex2D((int)screen.x, (int)screen.y);
 
             // Determine degree of correspondence
-            float cost = 1.0f - ftl::cuda::weighting(fabs(depth2 - camPos.z), params.spatial_smooth);
+            float cost = ftl::cuda::weighting(fabs(depth2 - camPos.z), params.spatial_smooth);
             // Point is too far away to even count
-			if (cost == 1.0f) continue;
+			//if (cost == 1.0f) continue;
 			
 			const uchar4 colour2 = c2.tex2D((int)screen.x, (int)screen.y);
 
             // Mix ratio of colour and distance costs
-            const float ccost = 1.0f - ftl::cuda::colourWeighting(colour1, colour2, params.colour_smooth);
-			if ((params.flags & ftl::cuda::kILWFlag_SkipBadColour) && ccost == 1.0f) continue;
+            const float ccost = ftl::cuda::colourWeighting(colour1, colour2, params.colour_smooth);
+			//if ((params.flags & ftl::cuda::kILWFlag_SkipBadColour) && ccost == 1.0f) continue;
 			
 			// Cost eq 1: summed contributions
-			cost = params.cost_ratio * (ccost) + (1.0f - params.cost_ratio) * cost;
+			cost = 1.0f - (params.cost_ratio * (ccost) + (1.0f - params.cost_ratio) * cost);
 			
 			// Cost eq 2: Multiplied
-			//cost = ccost * cost * cost * cost;
+			//cost = 1.0f - (ccost * ccost * cost);
 
             ++count;
             avgcost += (params.flags & ftl::cuda::kILWFlag_ColourConfidenceOnly) ? ccost : cost;
diff --git a/components/renderers/cpp/src/splat_render.cpp b/components/renderers/cpp/src/splat_render.cpp
index b22b377e1..1ccaf156c 100644
--- a/components/renderers/cpp/src/splat_render.cpp
+++ b/components/renderers/cpp/src/splat_render.cpp
@@ -363,10 +363,10 @@ bool Splatter::render(ftl::rgbd::VirtualSource *src, ftl::rgbd::Frame &out, cuda
 		cv::cuda::swap(temp_.get<GpuMat>(Channel::Colour), out.create<GpuMat>(Channel::Normals));
 		out.resetTexture(Channel::Normals);
 	}
-	else if (chan == Channel::Contribution)
-	{
-		cv::cuda::swap(temp_.get<GpuMat>(Channel::Contribution), out.create<GpuMat>(Channel::Contribution));
-	}
+	//else if (chan == Channel::Contribution)
+	//{
+	//	cv::cuda::swap(temp_.get<GpuMat>(Channel::Contribution), out.create<GpuMat>(Channel::Contribution));
+	//}
 	else if (chan == Channel::Right)
 	{
 		Eigen::Affine3f transform(Eigen::Translation3f(camera.baseline,0.0f,0.0f));
diff --git a/components/rgbd-sources/include/ftl/rgbd/channels.hpp b/components/rgbd-sources/include/ftl/rgbd/channels.hpp
index 551507730..467df0b1e 100644
--- a/components/rgbd-sources/include/ftl/rgbd/channels.hpp
+++ b/components/rgbd-sources/include/ftl/rgbd/channels.hpp
@@ -105,6 +105,7 @@ inline bool isFloatChannel(ftl::rgbd::Channel chan) {
 	switch (chan) {
 	case Channel::Depth		:
     //case Channel::Normals   :
+	case Channel::Confidence:
 	case Channel::Energy	: return true;
 	default					: return false;
 	}
-- 
GitLab