clear;

%
% num

if ~exist('plt')
    plt=Plotter('Cube_tmp','NNew_Data');
end
figure
xticks=plt.xRange;
plt.plot_xyy(plt.xRange,plt.rec.num_recal_cells,plt.rec.num_recal_cells0,...
    'Step','The number of active voxels','1num',xticks,...
    'ax=gca;','ax.YAxis.Exponent=3;');

%
% time_ke

if ~exist('plt')
    plt=Plotter('Cube_tmp','NNew_Data');
end
figure
xticks=plt.xRange;
plt.plot_xyy(plt.xRange,plt.rec.time_Ke,plt.rec.time_Ke0,...
    'Step','Elapsed time\rm (s)','2time_ke',xticks,...
    'ax=gca;','ax.YAxis.Exponent=0;');

%
% stress norm

if ~exist('plt')
    plt=Plotter('Cube_tmp','NNew_Data');
end
% manual set
cla;clf;
% plt.mp.viewxy=[0 70];
stress_flg=0;
if stress_flg
    plt.cAxis=[0 8];
    figure
    plt.plot_stress(1)
    axis on
else
%     plt.cAxis=[0 2.7e-4];
    figure
    plt.plot_move(1)
    axis off
    colorbar
end

%




cla;clf;
idx_list=[1:2];%
base_pos = [0.05 0.7 0.3 0.3];%
base_annPos=[0.05+0.10 0.7 0.18 0.05];%
base_annText='Step. ';
cot=1;
for j=0
    for i=0:1
        if j==1 && i==2
            break;
        end
        dcoord=[i*0.3 j*-0.4 0 0];%
        if j==1
            dcoord=dcoord+[0.15 0 0 0];
        end
        pos=base_pos+dcoord;
        annPos=base_annPos+dcoord;
        subplot('Position',pos);
        annotation('textbox',annPos,'String',[base_annText,num2str(idx_list(cot))],...
            'EdgeColor','none','FontName',plt.font_name,'FontSize',plt.font_size);
        if stress_flg
            plt.plot_stress(idx_list(cot));
        else
            plt.plot_move(idx_list(cot));
        end
        cot=cot+1;
    end
end
clb=colorbar('southoutside','AxisLocation','in','FontWeight',"bold",'FontName',plt.font_name,'FontSize',plt.font_size,'FontWeight','bold','Position',[0.14 0.15 0.72 0.02]);

set(gcf, 'position', [0 0 700 700]);% set figure size
if stress_flg
    clb.Ruler.Exponent = 1;
    print(gcf,'-dpng','-r300',['NNew_Data/',plt.sample_name,'/3stress']);
else
    clb.Ruler.Exponent = 3;
    print(gcf,'-dpng','-r300',['NNew_Data/',plt.sample_name,'/4move']);
end

%
%
% Export data to excel

if ~exist('plt')
    plt=Plotter('Cube_tmp','NNew_Data');
end

plt.extract_excel();

%
% Extract txt

if ~exist('plt')
    plt=Plotter('Cube_tmp','NNew_Data');
end
plt.extract_stl_and_txt([2],4);

%
% Extract  video

clf;
if ~exist('plt')
    plt=Plotter('Cube_tmp','NNew_Data');
end

stress_flg=0;
if stress_flg
    writeobj=VideoWriter([plt.folder_name,'/',plt.sample_name,'/','stress_Video.avi']);
    cAxis=[0 2];
else
    writeobj=VideoWriter([plt.folder_name,'/',plt.sample_name,'/','movement_Video.avi']);
    cAxis=[0 250];
end
writeobj.FrameRate=6;
writeobj.open();

slowList=1:11;
slowList=kron(slowList,[1 1 1]);

for index=[slowList,12:51]
    figure
    cAxis=cAxis;
    data=mp.recorder.data{index};
    if stress_flg
        cdata=mp.recorder.sdata{index};
    else
        cdata=mp.recorder.udata{index};
    end
    cdata(cdata>cAxis(2))=cAxis(2);
    mp.display_u(data,cdata);
    colorbar('off')
    axis off
    caxis(cAxis);
    ax=gca;   
    ax.CameraPositionMode='manual';
    ax.CameraPosition = [50 50 100];

    ax.CameraTargetMode='manual';
    ax.CameraTarget=[0 0 50];
    ax.CameraViewAngleMode='manual';
    ax.CameraViewAngle = 80;

    
    frame=getframe(gcf);
    if index==1
        H=size(frame.cdata,1);
        W=size(frame.cdata,2);
    else
        disp(size(frame.cdata));
        frame.cdata=imresize(frame.cdata,[H W]);
    end

    writeobj.writeVideo(frame);
end