% Mar/15/2014
% This script is used to plot the displacement and strain field results
% obtained using the Aramis 3D DIC software
% Displacement:  u_x, u_y, u_z
% Strain: epsilon_xx, epsilon_yy, epsilon_xy, epsilon_1, epsilon_2
% Lab3, AE3145, Spring 2014
 
 
close all;
%set(0,'DefaultFigureWindowStyle','docked')  
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PLOT DISPLACEMENT FIELDS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
%%% NOTE ARAMIS GENERATES .txt FILE WITH X,Y,Z DISPLACEMENT FIELDS EXPRESSED IN MILLIMETERS
 
%%% CONVERT DISPL. FROM mm TO microns using Xdis_mic = Xdis*1000 AND PLOT
%%% THIS QTY INSTEAD
 
Xdis_mic = Xdis*1000; 
figure                                          % open a new figure
pcolor(XcoordDef,YcoordDef,Xdis_mic)            % plot the DISPLACEMENT FIELD u_x at the deformed configuration
shading interp                                  % Interpolate the color shading
t = colorbar('peer',gca);                       % turn the colorbar on
title(t,'microns', 'fontsize', 20)              % color bar label and font size
set(t,'fontsize',18);                           % set font size of colorbar
set(gca, 'CLim', [-200, 100]);                  % set range of values in the color bar so as to accentuate displacement field gradients
title('X displacement Field', 'fontsize', 24)   % create the title of this figure
xlabel('X Coordinate (mm)','fontsize',18);      % set foint size of xlabel
ylabel('Y Coordinate (mm)','fontsize',18);      % set foint size of ylabel
 
Ydis_mic = Ydis*1000; 
figure                                          % open a new figure
pcolor(XcoordDef,YcoordDef,Ydis_mic)            % plot the DISPLACEMENT FIELD u_x at the deformed configuration
shading interp                                  % Interpolate the color shading
t = colorbar('peer',gca);                       % turn the colorbar on
title(t,'microns', 'fontsize', 20)              % color bar label and font size
set(t,'fontsize',18);                           % set font size of colorbar
% set(gca, 'CLim', [-8.71, 1.24]);              % set the range of values in the color bar so as to accentuate displacement field gradients
title('Y displacement Field', 'fontsize', 24)   % create the title of this figure
xlabel('X Coordinate (mm)','fontsize',18);      % set foint size of xlabel
ylabel('Y Coordinate (mm)','fontsize',18);      % set foint size of ylabel


% Zdis_mic = Zdis*1000; 
% figure                                          % open a new figure
% pcolor(XcoordDef,YcoordDef,Zdis_mic)            % plot the DISPLACEMENT FIELD u_x at the deformed configuration
% shading interp                                  % Interpolate the color shading
% t = colorbar('peer',gca);                       % turn the colorbar on
% title(t,'microns', 'fontsize', 20)              % color bar label and font size
% set(t,'fontsize',18);                           % set font size of colorbar
% set(gca, 'CLim', [-8.71, 1.24]);                % set the range of values in the color bar so as to accentuate displacement field gradients
% title('Z displacement Field', 'fontsize', 24)   % create the title of this figure
% xlabel('X Coordinate (mm)','fontsize',18);      % set foint size of xlabel
% ylabel('Y Coordinate (mm)','fontsize',18);      % set foint size of ylabel
% set(gca, 'CLim', [0, 40]);       % set the range of values in the color bar so as to accentuate displacement field gradients
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PLOT RECTANGULAR STRAIN FIELD COMPONENTS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
%%% NOTE ARAMIS GENERATES .txt FILE WITH Xstrain, Ystrain XYstrain FIELDS
%%% EXPRESSED IN %-STRAIN  
 
%%% CONVERT FROM %-STRAIN TO regular strain using Xstrain_reg = (Xstrain/100)
%%% THIS IS PARTICULARLY IMPORTANT IIN ANTICIPATION OF STRESS CALCULATIONS 
 
%%% ON THE OTHER HAND... YOU COULD PLOT IN microstrain (ue) BY CONVERTING %-STRAIN TO (microstrain
%%% using XStrain_ue = XStrain_reg*1e6
 
Xstrain_ue = (Xstrain/100)*1e6;
figure                                          % open a new figure
pcolor(XcoordDef,YcoordDef,Xstrain_ue)          % plot the STRAIN FIELD epsilon_xx field at the deformed configuration
shading interp                                  % Interpolate the color shading
t = colorbar('peer',gca);                       % turn the colorbar on
title(t,'microstrains', 'fontsize', 20)         % color bar label and font size
set(t,'fontsize',18);                           % set font size of colorbar
%  set(gca, 'CLim', [-2003.8, 2000]);            % set the range of values in the color bar so as to accentuate the dominant range of 
                                                % strain values
title('\epsilon_{xx}(x,y)', 'fontsize', 24)     % create the title of this figure
xlabel('X Coordinate (mm)','fontsize',18);      % set foint size of xlabel
ylabel('Y Coordinate (mm)','fontsize',18);      % set foint size of ylabel
                            
 
Ystrain_ue = (Ystrain/100)*1e6;
figure                                          % open a new figure
pcolor(XcoordDef,YcoordDef,Ystrain_ue)          % plot the STRAIN FIELD epsilon_yy field at the deformed configuration
shading interp                                  % Interpolate the color shading
t = colorbar('peer',gca);                       % turn the colorbar on
title(t,'microstrains', 'fontsize', 20)         % color bar label and font size
set(t,'fontsize',18);                           % set font size of colorbar
% set(gca, 'CLim', [-520.6, 500]);              % set the range of values in the color bar so as to accentuate the dominant range of 
                                                % strain values
title('\epsilon_{yy}(x,y)', 'fontsize', 24)     % create the title of this figure
xlabel('X Coordinate (mm)','fontsize',18);      % set foint size of xlabel
ylabel('Y Coordinate (mm)','fontsize',18);      % set foint size of ylabel

 
XYstrain_ue = (XYstrain/100)*1e6;
figure                                          % open a new figure
pcolor(XcoordDef,YcoordDef,XYstrain_ue)         % plot the STRAIN FIELD epsilon_yy field at the deformed configuration
shading interp                                  % Interpolate the color shading
t = colorbar('peer',gca);                       % turn the colorbar on
title(t,'microstrains', 'fontsize', 20)         % color bar label and font size
set(t,'fontsize',18);                           % set font size of colorbar
 set(gca, 'CLim', [-10, 10]);               % set the range of values in the color bar so as to accentuate the dominant range of 
                                                %strain valuestitle('\epsilon_{xy}(x,y)', 'fontsize', 24)     % create the title of this figure
title('\epsilon_{xy}(x,y)', 'fontsize', 24)     % create the title of this figure
xlabel('X Coordinate (mm)','fontsize',18);      % set foint size of xlabel
ylabel('Y Coordinate (mm)','fontsize',18);      % set foint size of ylabel


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PLOT PRINCIPAL STRAIN FIELD COMPONENTS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
MinorStrain_ue = (MinorStrain/100)*1e6;
figure                                          % open a new figure
pcolor(XcoordDef,YcoordDef,MinorStrain_ue)      % plot the PRINCIPAL STRAIN FIELD (MinorStrain) field at the deformed configuration
shading interp                                  % Interpolate the color shading
t = colorbar('peer',gca);                       % turn the colorbar on
title(t,'microstrains', 'fontsize', 20)         % color bar label and font size
set(t,'fontsize',18);                           % set font size of colorbar
% set(gca, 'CLim', [-1955.5, -998.8]);            % set the range of values in the color bar so as to accentuate the dominant range of 
                                                % strain values title 
title('Minor Strain', 'fontsize', 24)      % create the title of this figure
%title('\epsilon_{2}(x,y)', 'fontsize', 24)      % create the title of this figure
xlabel('X Coordinate (mm)','fontsize',18);      % set foint size of xlabel
ylabel('Y Coordinate (mm)','fontsize',18);      % set foint size of ylabel

 
MajorStrain_ue = (MajorStrain/100)*1e6;
figure                                          % open a new figure
pcolor(XcoordDef,YcoordDef,MajorStrain_ue)      % plot the PRINCIPAL STRAIN FIELD (MajorStrain) field at the deformed configuration
shading interp                                  % Interpolate the color shading
t = colorbar('peer',gca);                       % turn the colorbar on
title(t,'microstrains', 'fontsize', 20)         % color bar label and font size
set(t,'fontsize',18);                           % set font size of colorbar
% set(gca, 'CLim', [-596, 49.5]);                 % set the range of values in the color bar so as to accentuate the dominant range of 
                                                %strain values
title('Major Strain', 'fontsize', 24)     % create the title of this figure
%title('\epsilon_{1}(x,y)', 'fontsize', 24)      % create the title of this figure
xlabel('X Coordinate (mm)','fontsize',18);      % set foint size of xlabel
ylabel('Y Coordinate (mm)','fontsize',18);      % set foint size of ylabel

 
% %%%USEFUL TIPS: CALCULATE THE MEAN OF AN ARRAY USING A1 = nanmean(A). Note that the nanmean function avoids NaN entries in the 
% %calculation of the mean value of an array. If any NaN values are still left after the first mean operation is applied you may then 
% %repeat the process on A1 i.e. A_mean = nanmean(A1). You can consider applying to this to MajorStrain and MinorStrain arrays and in 
% %order to check the ratio of their means... This might even come in handy when checking the ratio of the hoop stress to the 
% %longitudinal stress, i.e., you could use it to compare the ratio of the mean values of the principal stress arrays.
