forked from andypotatohy/roast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
map2Points.m
59 lines (48 loc) · 2.09 KB
/
map2Points.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
function [dist,indexOnGoalPoints]= map2Points(inputPoints,goalPoints,criterion,numOfPts)
% [dist,indexOnGoalPoints]= map2Points(inputPoints,goalPoints,criterion,numOfPts)
%
% Map from one point cloud to another point cloud, based on the Euclidean
% distance.
%
% Note this function will give "out of memory" error if the input and goal
% point clouds are too big (>50K).
%
% (c) Yu (Andy) Huang, Parra Lab at CCNY
% April 2018
inputPoints = single(inputPoints);
goalPoints = single(goalPoints);
N_inputPoints = size(inputPoints,1);
N_goalPoints = size(goalPoints,1);
N_dim_input = size(inputPoints,2);
N_dim_goal = size(goalPoints,2);
% now supports any number of dimensions
if N_dim_input ~= N_dim_goal
error('You cannot map points that are in spaces of different dimensions!')
end
temp = reshape(inputPoints',1,N_dim_input,N_inputPoints);
temp1 = repmat(temp,[N_goalPoints 1 1]);
temp2 = repmat(goalPoints,[1 1 N_inputPoints]);
dist = sqrt(sum((temp1 - temp2).^2,2));
dist = squeeze(dist);
[dist_sorted,ind_sortedDist] = sort(dist);
switch criterion
case 'closest'
dist = dist_sorted(1,:);
indexOnGoalPoints = ind_sortedDist(1,:);
case 'farthest'
dist = dist_sorted(end,:);
indexOnGoalPoints = ind_sortedDist(end,:);
case 'closer'
if isempty(numOfPts), error('You want to map to the first XX closest points, please specify XX in the 4th argument.'); end
if numOfPts>N_goalPoints, error('Number of points exceed size of goal point cloud.'); end
dist = dist_sorted(1:numOfPts,:);
indexOnGoalPoints = ind_sortedDist(1:numOfPts,:);
case 'farther'
if isempty(numOfPts), error('You want to map to the first XX farthest points, please specify XX in the 4th argument.'); end
if numOfPts>N_goalPoints, error('Number of points exceed size of goal point cloud.'); end
dist = dist_sorted(end-numOfPts+1:end,:);
indexOnGoalPoints = ind_sortedDist(end-numOfPts+1:end,:);
otherwise
error('Please specify either closest, farthest, closer or farther as the mapping criterion.');
end