Skip to content

Fixed KinFu getCloud() at empty volume #2410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 34 additions & 30 deletions modules/rgbd/src/tsdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1393,7 +1393,7 @@ void TSDFVolumeGPU::fetchPointsNormals(OutputArray points, OutputArray normals)
(int)divUp(globalSize[2], (unsigned int)localSize[2]));

const size_t counterSize = sizeof(int);
size_t lsz = localSize[0]*localSize[1]*localSize[2]*counterSize;
size_t lszscan = localSize[0]*localSize[1]*localSize[2]*counterSize;

const int gsz[3] = {ngroups[2], ngroups[1], ngroups[0]};
UMat groupedSum(3, gsz, CV_32S, Scalar(0));
Expand All @@ -1409,7 +1409,7 @@ void TSDFVolumeGPU::fetchPointsNormals(OutputArray points, OutputArray normals)
ocl::KernelArg::PtrReadOnly(volPoseGpu),
voxelSize,
voxelSizeInv,
ocl::KernelArg::Local(lsz),
ocl::KernelArg::Local(lszscan),
ocl::KernelArg::WriteOnlyNoSize(groupedSum));

if(!kscan.run(3, globalSize, localSize, true))
Expand All @@ -1422,12 +1422,6 @@ void TSDFVolumeGPU::fetchPointsNormals(OutputArray points, OutputArray normals)

// 2. fill output arrays according to per-group points count

ocl::Kernel kfill;
kfill.create("fillPtsNrm", source, options, &errorStr);

if(kfill.empty())
throw std::runtime_error("Failed to create kernel: " + errorStr);

points.create(gpuSum, 1, POINT_TYPE);
UMat pts = points.getUMat();
UMat nrm;
Expand All @@ -1438,31 +1432,41 @@ void TSDFVolumeGPU::fetchPointsNormals(OutputArray points, OutputArray normals)
}
else
{
// it won't access but empty args are forbidden
// it won't be accessed but empty args are forbidden
nrm = UMat(1, 1, POINT_TYPE);
}
UMat atomicCtr(1, 1, CV_32S, Scalar(0));

// mem size to keep pts (and normals optionally) for all work-items in a group
lsz = localSize[0]*localSize[1]*localSize[2]*elemSize;

kfill.args(ocl::KernelArg::PtrReadOnly(volume),
volResGpu.val,
volDims.val,
neighbourCoords.val,
ocl::KernelArg::PtrReadOnly(volPoseGpu),
voxelSize,
voxelSizeInv,
((int)needNormals),
ocl::KernelArg::Local(lsz),
ocl::KernelArg::PtrReadWrite(atomicCtr),
ocl::KernelArg::ReadOnlyNoSize(groupedSum),
ocl::KernelArg::WriteOnlyNoSize(pts),
ocl::KernelArg::WriteOnlyNoSize(nrm)
);

if(!kfill.run(3, globalSize, localSize, true))
throw std::runtime_error("Failed to run kernel");
if (gpuSum)
{
ocl::Kernel kfill;
kfill.create("fillPtsNrm", source, options, &errorStr);

if(kfill.empty())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kfill.empty()

Put check right after .create()call.

UMat creation between them looks strange.

throw std::runtime_error("Failed to create kernel: " + errorStr);

UMat atomicCtr(1, 1, CV_32S, Scalar(0));

// mem size to keep pts (and normals optionally) for all work-items in a group
size_t lszfill = localSize[0]*localSize[1]*localSize[2]*elemSize;

kfill.args(ocl::KernelArg::PtrReadOnly(volume),
volResGpu.val,
volDims.val,
neighbourCoords.val,
ocl::KernelArg::PtrReadOnly(volPoseGpu),
voxelSize,
voxelSizeInv,
((int)needNormals),
ocl::KernelArg::Local(lszfill),
ocl::KernelArg::PtrReadWrite(atomicCtr),
ocl::KernelArg::ReadOnlyNoSize(groupedSum),
ocl::KernelArg::WriteOnlyNoSize(pts),
ocl::KernelArg::WriteOnlyNoSize(nrm)
);

if(!kfill.run(3, globalSize, localSize, true))
throw std::runtime_error("Failed to run kernel");
}
}
}

Expand Down