You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.0 KiB
75 lines
2.0 KiB
3 years ago
|
%--------------------------
|
||
|
% @Author: Jingqiao Hu
|
||
|
% @Date: 2021-12-29 20:23:06
|
||
|
% @LastEditTime: 2022-01-11 12:42:34
|
||
|
|
||
|
% for each voronoi edge
|
||
|
% update the MMC variables based on voronoi-edges
|
||
|
%--------------------------
|
||
|
function [MMC, MMCpoly] = update_MMCs(vor_edges, T, nnbSeedIDX, seed)
|
||
|
|
||
|
%% MMC properties
|
||
|
nodes1 = vor_edges(:,[1,2]);
|
||
|
nodes2 = vor_edges(:,[3,4]);
|
||
|
|
||
|
nodes3 = (nodes1 + nodes2) / 2;
|
||
|
x = nodes3(:,1);
|
||
|
y = nodes3(:,2);
|
||
|
|
||
|
len = vecnorm(nodes2 - nodes1, 2, 2);
|
||
|
|
||
|
sina = abs(nodes2(:,2) - nodes1(:,2)) ./ len;
|
||
|
dir = (nodes2(:,2) < nodes1(:,2)) .* (nodes2(:,1) < nodes1(:,1)) + ...
|
||
|
(nodes2(:,2) > nodes1(:,2)) .* (nodes2(:,1) > nodes1(:,1));
|
||
|
sina(dir < 1) = -sina(dir < 1);
|
||
|
|
||
|
MMC0 = [x, y, len/2, sina]; % [n,7]
|
||
|
|
||
|
Tedge = T_edge2seed(T, nnbSeedIDX, seed, MMC0);
|
||
|
MMC = [repmat(Tedge, 1, 3), MMC0];
|
||
|
|
||
|
%% the polygon of each MMC
|
||
|
cosa = sqrt(1 - sina.^2);
|
||
|
stepx = Tedge/2 .* abs(sina);
|
||
|
stepy = Tedge/2 .* cosa;
|
||
|
stepy(dir>0) = -stepy(dir>0);
|
||
|
n0 = [nodes1(:,1) - stepx, nodes1(:,2) - stepy]; % [n,2]
|
||
|
n1 = [nodes1(:,1) + stepx, nodes1(:,2) + stepy];
|
||
|
n2 = [nodes2(:,1) + stepx, nodes2(:,2) + stepy];
|
||
|
n3 = [nodes2(:,1) - stepx, nodes2(:,2) - stepy];
|
||
|
|
||
|
MMCpoly = [n0, n1, n2, n3];
|
||
|
|
||
|
% % test polyshape
|
||
|
% figure(1); clf
|
||
|
% parfor i = 1:size(n0,1)
|
||
|
% n = [n0(i,:); n1(i,:); n2(i,:); n3(i,:)];
|
||
|
% p = polyshape(n);
|
||
|
% plot(p); hold on;
|
||
|
% end
|
||
|
% axis equal;
|
||
|
end
|
||
|
|
||
|
% projection to width for each edge based on the distance to two neighbor seed
|
||
|
function Tedge = T_edge2seed(Tseed, nnbSeedIDX, seed, MMC)
|
||
|
|
||
|
nedge = size(MMC, 1);
|
||
|
Tedge = zeros(nedge, 1);
|
||
|
|
||
|
% FIXME:
|
||
|
parfor i = 1 : nedge
|
||
|
mmc = MMC(i, 1:2); % [x,y]
|
||
|
|
||
|
sid = nnbSeedIDX(i,:);
|
||
|
s = seed(sid, :); % 2*[x,y]
|
||
|
|
||
|
t = Tseed(sid); % 2*1
|
||
|
|
||
|
% compute the distance from seed to mmc
|
||
|
% dist0 = s - repmat(mmc, 2, 1);
|
||
|
% dist1 = vecnorm(dist0, 2, 2);
|
||
|
% Tedge(i) = mean(t ./ dist1);
|
||
|
|
||
|
Tedge(i) = mean(t);
|
||
|
end
|
||
|
end
|