-
Notifications
You must be signed in to change notification settings - Fork 188
/
Copy pathpointCloud2TDF.m
executable file
·30 lines (24 loc) · 1.23 KB
/
pointCloud2TDF.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function voxelGridTDF = pointCloud2TDF(points,xRange,yRange,zRange,voxelSize,voxelMargin)
% Given a point cloud, compute a voxel grid of TDF values (warning: slow!)
% Works fine for small point clouds - uses in-house Matlab functions
%
% ---------------------------------------------------------
% Copyright (c) 2016, Andy Zeng
%
% This file is part of the 3DMatch Toolbox and is available
% under the terms of the Simplified BSD License provided in
% LICENSE. Please retain this notice and LICENSE if you use
% this file (or any portion of it) in your project.
% ---------------------------------------------------------
% Compute voxel grid
[gridX,gridY,gridZ] = ndgrid((xRange(1)+voxelSize/2):voxelSize:(xRange(2)-voxelSize/2), ...
(yRange(1)+voxelSize/2):voxelSize:(yRange(2)-voxelSize/2), ...
(zRange(1)+voxelSize/2):voxelSize:(zRange(2)-voxelSize/2));
% Build KD-tree and do 1-NN search
modelKDT = KDTreeSearcher(points');
[nnIdx,nnDist] = knnsearch(modelKDT,[gridX(:),gridY(:),gridZ(:)]);
% Reshape values into voxel grid
voxelGridTDF = reshape(nnDist,size(gridX));
% Apply truncation
voxelGridTDF = 1.0 - min(voxelGridTDF./(voxelSize*voxelMargin),1.0);
end