clear;
if ~exist('plt')
%     plt=Plotter('Piston_tmp','NNew_Data');
    plt=Plotter('Cube_tmp','NNew_Data');
end
if ~exist('S','var')
obj= readObj('./SHOW_DS/cube_t0__sf.obj');%%
S.Vertices=obj.v;%%
S.Faces=obj.f.v;%%
end

cla;clf;
plt.mp.viewxy=[90 70];
cur_c=plt.mp.recorder.intermediate_c{1};
% dis=cur_c.calSDF(S.Vertices);
Q_U_XV=compute_u(S.Vertices,plt.mp.recorder.U{1},plt.mp);%3x1xLen
Q_U_XV=reshape(Q_U_XV,3,[])';% lenx3
Q_S_XV=compute_stress(S.Vertices,plt.mp.recorder.U{1},plt.mp);
Q_S_XV=reshape(Q_S_XV(1:3,:,:),3,[])';% lenx3

%%%%%
figure
p=patch(S,...
         'EdgeColor',       'none',        ...
         'FaceLighting',    'gouraud',     ...
         'AmbientStrength',     0.5, ...
         'FaceVertexCData',   vecnorm(Q_U_XV,2,2), ...
         'FaceColor',       'interp' ...
         );


camlight('headlight');

axis('image');
axis off
view([90 70]);
colorbar 
annotation('textbox',[.3 .05 .4 .2], ...
    'String','deformation norm of XVoxel','EdgeColor','none')
% caxis([0 1.4e-5])
% caxis([0 2.7e-4]);
%%%%%
figure
Q4=(0.5*((Q_S_XV(:,1)-Q_S_XV(:,2)).^2+(Q_S_XV(:,1)-Q_S_XV(:,3)).^2+(Q_S_XV(:,3)-Q_S_XV(:,2)).^2)).^0.5;

p=patch(S,...
         'EdgeColor',       'none',        ...
         'FaceLighting',    'gouraud',     ...
         'AmbientStrength',     0.5, ...
         'FaceVertexCData',   Q4, ...
         'FaceColor',       'interp' ...
         );


camlight('headlight');

axis('image');
axis off
view([90 70]);
colorbar 
annotation('textbox',[.3 .05 .4 .2], ...
    'String','Von Mises stress of XVoxel','EdgeColor','none')
% caxis([0 7.5e-6])
% caxis([0 2.3e-5])