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.
 
 
 
 

59 lines
2.1 KiB

%--------------------------
% @Author: Jingqiao Hu
% @Date: 2022-05-11 11:01:29
% @LastEditTime: 2022-05-12 10:27:23
%--------------------------
function recover_def_mmc_surf(ref_nodes, def_nodes, MMCs, optDesign)
microx = 20;
for ele = 1 : size(ref_nodes, 1)
ref = ref_nodes{ele};
def = def_nodes{ele};
[regular_ref, regular_phi] = regular_ref_nodes(ref, MMCs, microx);
cx = reshape(regular_ref(:,1), microx, microx, microx);
cy = reshape(regular_ref(:,2), microx, microx, microx);
cz = reshape(regular_ref(:,3), microx, microx, microx);
regular_phi = reshape(regular_phi, microx, microx, microx);
[faces, verts] = isosurface(cx,cy,cz,regular_phi,0);
% interpolation for the deformed shape
Fx = scatteredInterpolant(ref(:,1),ref(:,2),ref(:,3),def(:,1),'natural');
Fy = scatteredInterpolant(ref(:,1),ref(:,2),ref(:,3),def(:,2),'natural');
Fz = scatteredInterpolant(ref(:,1),ref(:,2),ref(:,3),def(:,3),'natural');
vqx = Fx(verts);
vqy = Fy(verts);
vqz = Fz(verts);
stlwrite(['data/stl/',optDesign,'/output1-',num2str(ele),'.stl'], faces, [vqx,vqy,vqz]);
[faces, verts] = isocaps(cx,cy,cz,regular_phi,0);
vqx = Fx(verts);
vqy = Fy(verts);
vqz = Fz(verts);
stlwrite(['data/stl/',optDesign,'/output2-',num2str(ele),'.stl'], faces, [vqx,vqy,vqz]);
end
end
function [regular_ref, regular_phi] = regular_ref_nodes(ref, MMCs, microx)
minx = min(ref(:,1)); maxx = max(ref(:,1));
miny = min(ref(:,2)); maxy = max(ref(:,2));
minz = min(ref(:,3)); maxz = max(ref(:,3));
[gx,gy,gz] = meshgrid(linspace(minx, maxx, microx), linspace(miny, maxy, microx), linspace(minz, maxz, microx));
regular_ref = [gx(:), gy(:), gz(:)];
regular_phi = repmat(-1e5, size(regular_ref,1), 1);
for i = 1 : size(MMCs, 1)
t = MMCs(i, 1);
sp = MMCs(i, 2:4);
ep = MMCs(i, 5:7);
phi0 = signed_distance(regular_ref, sp, ep, t);
regular_phi = max(phi0, regular_phi);
end
end