From 25397b88342362902812bc2883aee78e17421bbf Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Sun, 23 Jun 2019 08:12:39 +0300
Subject: [PATCH] Alternative colour blend algorithms

---
 .../reconstruct/include/ftl/voxel_hash.hpp    | 23 +++++++++++++++----
 .../reconstruct/src/scene_rep_hash_sdf.cu     |  8 +++----
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/applications/reconstruct/include/ftl/voxel_hash.hpp b/applications/reconstruct/include/ftl/voxel_hash.hpp
index fe1201659..7cfa44126 100644
--- a/applications/reconstruct/include/ftl/voxel_hash.hpp
+++ b/applications/reconstruct/include/ftl/voxel_hash.hpp
@@ -232,10 +232,10 @@ struct HashData {
 		//out.color = 0.5f * (v0.color + v1.color);	//exponential running average 
 		
 
-		float3 c0 = make_float3(v0.color.x, v0.color.y, v0.color.z);
-		float3 c1 = make_float3(v1.color.x, v1.color.y, v1.color.z);
+		//float3 c0 = make_float3(v0.color.x, v0.color.y, v0.color.z);
+		//float3 c1 = make_float3(v1.color.x, v1.color.y, v1.color.z);
 
-		float3 res = (c0.x+c0.y+c0.z == 0) ? c1 : 0.5f*c0 + 0.5f*c1;
+		//float3 res = (c0.x+c0.y+c0.z == 0) ? c1 : 0.5f*c0 + 0.5f*c1;
 		//float3 res = (c0+c1)/2;
 		//float3 res = (c0 * (float)v0.weight + c1 * (float)v1.weight) / ((float)v0.weight + (float)v1.weight);
 		//float3 res = c1;
@@ -243,7 +243,22 @@ struct HashData {
 		//out.color.x = (uchar)(res.x+0.5f);	out.color.y = (uchar)(res.y+0.5f); out.color.z = (uchar)(res.z+0.5f);
 		
 		// Nick: reduces colour flicker but not ideal..
-		out.color = v1.color;
+		//out.color = v1.color;
+
+		// Option 3 (Nick): Use colour with minimum SDF since it should be closest to surface.
+		// Results in stable but pixelated output
+		//out.color = (v0.weight > 0 && (fabs(v0.sdf) < fabs(v1.sdf))) ? v0.color : v1.color;
+
+		// Option 4 (Nick): Merge colours based upon relative closeness
+		float3 c0 = make_float3(v0.color.x, v0.color.y, v0.color.z);
+		float3 c1 = make_float3(v1.color.x, v1.color.y, v1.color.z);
+		float factor = fabs(v0.sdf - v1.sdf) / 0.05f / 2.0f;
+		if (factor > 0.5f) factor = 0.5f;
+		float factor0 = (fabs(v0.sdf) < fabs(v1.sdf)) ? 1.0f - factor : factor;
+		float factor1 = 1.0f - factor0;
+		out.color.x = (v0.weight > 0) ? (uchar)(c0.x * factor0 + c1.x * factor1) : c1.x;
+		out.color.y = (v0.weight > 0) ? (uchar)(c0.y * factor0 + c1.y * factor1) : c1.y;
+		out.color.z = (v0.weight > 0) ? (uchar)(c0.z * factor0 + c1.z * factor1) : c1.z;
 
 		out.sdf = (v0.sdf * (float)v0.weight + v1.sdf * (float)v1.weight) / ((float)v0.weight + (float)v1.weight);
 		out.weight = min(c_hashParams.m_integrationWeightMax, (unsigned int)v0.weight + (unsigned int)v1.weight);
diff --git a/applications/reconstruct/src/scene_rep_hash_sdf.cu b/applications/reconstruct/src/scene_rep_hash_sdf.cu
index 6a3cd2bed..a4c87bcdd 100644
--- a/applications/reconstruct/src/scene_rep_hash_sdf.cu
+++ b/applications/reconstruct/src/scene_rep_hash_sdf.cu
@@ -565,10 +565,10 @@ __global__ void integrateDepthMapKernel(HashData hashData, DepthCameraData camer
 
 				uint idx = entry.ptr + i;
 
-				if (entry.flags != cameraParams.flags & 0xFF) {
-					entry.flags = cameraParams.flags & 0xFF;
-					hashData.d_SDFBlocks[idx].color = make_uchar3(0,0,0);
-				}
+				//if (entry.flags != cameraParams.flags & 0xFF) {
+				//	entry.flags = cameraParams.flags & 0xFF;
+					//hashData.d_SDFBlocks[idx].color = make_uchar3(0,0,0);
+				//}
 				
 				Voxel newVoxel;
 				//if (color.x == MINF) hashData.combineVoxelDepthOnly(hashData.d_SDFBlocks[idx], curr, newVoxel);
-- 
GitLab