diff --git a/applications/reconstruct/src/dibr.cu b/applications/reconstruct/src/dibr.cu index 88d480872a551845ba298809f5750341fd29923c..8c2f20c6ae77f24925555d5f89e6435794d158b9 100644 --- a/applications/reconstruct/src/dibr.cu +++ b/applications/reconstruct/src/dibr.cu @@ -345,7 +345,7 @@ __global__ void OLD_dibr_visibility_kernel(TextureObject<int> depth, int cam, Sp } } -#define NEIGHBOR_RADIUS_2 5 +#define NEIGHBOR_RADIUS_2 10 #define NEIGHBOR_WINDOW ((NEIGHBOR_RADIUS_2*2+1)*(NEIGHBOR_RADIUS_2*2+1)) #define MAX_NEIGHBORS_2 20 @@ -361,7 +361,7 @@ __global__ void OLD_dibr_visibility_kernel(TextureObject<int> depth, int cam, Sp __shared__ float3 neighborhood_cache[2*T_PER_BLOCK][MAX_NEIGHBORS_2]; __shared__ int minimum[2*T_PER_BLOCK]; __shared__ int maximum[2*T_PER_BLOCK]; - __shared__ int nidx[2*T_PER_BLOCK]; + __shared__ unsigned int nidx[2*T_PER_BLOCK]; const int warp = threadIdx.x / WARP_SIZE + threadIdx.y*2; const int x = (blockIdx.x*blockDim.x + threadIdx.x) / WARP_SIZE; @@ -405,8 +405,8 @@ __global__ void OLD_dibr_visibility_kernel(TextureObject<int> depth, int cam, Sp const int v = (i / (2*NEIGHBOR_RADIUS_2+1)) - NEIGHBOR_RADIUS_2; const float3 point = params.camera.kinectDepthToSkeleton(x+u, y+v, float(point_in.tex2D(x+u, y+v)) / 1000.0f); - if (length(point - camPos) <= 0.04f) { - int idx = atomicInc(&nidx[warp], MAX_NEIGHBORS_2-1); + if (length(point - camPos) <= SPATIAL_SMOOTHING) { + unsigned int idx = atomicInc(&nidx[warp], MAX_NEIGHBORS_2-1); neighborhood_cache[warp][idx] = point; atomicMin(&minimum[warp], point.z*1000.0f); atomicMax(&maximum[warp], point.z*1000.0f); @@ -451,7 +451,7 @@ __global__ void OLD_dibr_visibility_kernel(TextureObject<int> depth, int cam, Sp // TODO:(Nick) Should perhaps use points from all cameras? // Instead of doing each camera separately... // If the depth already is close then it has already been done and can skip this point - const float energy = ftl::cuda::mls_point_energy<MAX_NEIGHBORS_2>(neighborhood_cache[warp], nearest, SPATIAL_SMOOTHING); + const float energy = ftl::cuda::mls_point_energy<MAX_NEIGHBORS_2>(neighborhood_cache[warp], nearest, nidx[warp], SPATIAL_SMOOTHING); if (energy <= 0.0f) break; diff --git a/applications/reconstruct/src/mls_cuda.hpp b/applications/reconstruct/src/mls_cuda.hpp index 420b3beb0a5603abbc1a34e5cfeba5b99912408d..7f2cf1d88d92e319ceef96274626477d6e2b839c 100644 --- a/applications/reconstruct/src/mls_cuda.hpp +++ b/applications/reconstruct/src/mls_cuda.hpp @@ -275,6 +275,28 @@ __device__ float mls_point_energy( return weights; } +/** + * Calculate the point sample energy. + */ +template <int M> +__device__ float mls_point_energy( + const float3 (&pointset)[M], + const float3 &nearPoint, + unsigned int N, + float smoothing) { + + float weights = 0.0f; + + //#pragma unroll + for (int i=0; i<N; ++i) { + const float3 samplePoint = pointset[i]; + const float weight = ftl::cuda::spatialWeighting(length(nearPoint - samplePoint), smoothing); + weights += weight; + } + + return weights; +} + /** * Estimate a point set surface location near an existing and return also * an estimate of the normal and colour of that point.