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.
94 lines
3.1 KiB
94 lines
3.1 KiB
%--------------------------
|
|
% @Author: Jingqiao Hu
|
|
% @Date: 2021-10-13 20:30:29
|
|
% @LastEditTime: 2021-12-06 15:32:29
|
|
|
|
% paras:
|
|
% MMCs: [t1,t2,t3, x, y, len, sin(theta)], 7 paras
|
|
% NOTE: for the shared edge between neighbored voronoi cells, it have different phi for different cell
|
|
%--------------------------
|
|
function [MMCs, MMCs_max, MMCs_min, MMCs_num] = generate_MMC_fromCVT(cvt_num, t0, t_max, t_min)
|
|
|
|
% coor = [];
|
|
% phi_global = [];
|
|
% tri_faces_global = [];
|
|
% idx = 1;
|
|
|
|
MMCs = cell(cvt_num, 1);
|
|
MMCs_min = cell(cvt_num, 1);
|
|
MMCs_max = cell(cvt_num, 1);
|
|
|
|
center_pnts = zeros(cvt_num,2);
|
|
|
|
MMCs_num = 0;
|
|
|
|
for i = 0:cvt_num-1
|
|
[vor_edges_num, vor_center_pnt, vor_nodes, vor_edges] = read_voronoi(i);
|
|
center_pnts(i+1,:) = vor_center_pnt';
|
|
|
|
% [tri_pnts_num, tri_faces_num, tri_nodes, tri_faces] = read_cdt(i);
|
|
|
|
MMCi = zeros(7,vor_edges_num);
|
|
MMCi(1:3, :) = t0;
|
|
|
|
% each_phi = cell(vor_edges_num, 1);
|
|
% phi0 = 0;
|
|
|
|
for j = 1:vor_edges_num
|
|
n1 = vor_nodes(vor_edges(j,1)+1, :);
|
|
n2 = vor_nodes(vor_edges(j,2)+1, :);
|
|
% skip too short edge
|
|
if norm(n1 - n2) < 2e-1
|
|
continue;
|
|
end
|
|
cn = (n1 + n2) / 2;
|
|
|
|
MMCi(4:5, j) = cn; % [x,y]
|
|
MMCi(6, j) = norm(n2 - n1) / 2;
|
|
MMCi(7, j) = abs(n2(2) - cn(2)) / norm(n2 - cn);
|
|
if (n2(2) - cn(2))>0
|
|
MMCi(7, j) = -MMCi(7, j);
|
|
end
|
|
if (n2(1) - cn(1))>0
|
|
MMCi(7, j) = -MMCi(7, j);
|
|
end
|
|
|
|
% tmpPhi = tPhi(MMCi, tri_nodes(:,1), tri_nodes(:,2));
|
|
% each_phi{j} = tmpPhi;
|
|
% phi0 = phi0 + exp(p * tmpPhi);
|
|
end
|
|
% phi_max = log(phi0) / p;
|
|
% H = Heaviside_simply(phi_max, 0.07*4);
|
|
|
|
MMCs{i+1} = MMCi;
|
|
MMCi(1:3) = t_max;
|
|
MMCs_max{i+1} = MMCi;
|
|
MMCi(1:3) = t_min;
|
|
MMCs_min{i+1} = MMCi;
|
|
|
|
MMCs_num = MMCs_num + vor_edges_num;
|
|
|
|
% coor = [coor; tri_nodes]; % [n,2]
|
|
% phi_global = [phi_global; H(:)]; % [n,1]
|
|
% tri_faces_global = [tri_faces_global; tri_faces + idx];
|
|
% idx = idx + size(tri_nodes, 1);
|
|
|
|
% figure(1); clf; trimesh(tri_faces+1, tri_nodes(:,1), tri_nodes(:,2), phi_max); % axis equal; axis off;
|
|
end
|
|
|
|
% trimesh(tri_faces_global, coor(:,1), coor(:,2), phi_global);
|
|
% figure; trisurf(tri_faces_global, coor(:,1), coor(:,2), phi_global);
|
|
end
|
|
|
|
function [edges_num, center_pnt, nodes, edges] = read_voronoi(i)
|
|
datapath = ['data/cvt/vcell',num2str(i)];
|
|
fileID = fopen(datapath, 'r');
|
|
info = fscanf(fileID, '%f');
|
|
|
|
edges_num = info(1); % edges num of the v-cell
|
|
center_pnt = info(2:3); % the coordinate of the center point of the v-cell
|
|
nodes = reshape(info(4 : 4+edges_num*2-1), 2, [])'; % all nodes coodinates of the v-cell
|
|
edges = reshape(info(4+edges_num*2 : end), 2, [])'; % edges of the v-cell, formed of node-idx
|
|
|
|
fclose(fileID);
|
|
end
|
|
|