%**************************************************************************
%**************************************************************************

%                          _                               
%                         (_)                              
%          ____  ____ ____ _ ____                          
%         / _  |/ ___) _  | |  _ \                         
%        ( ( | | |  ( ( | | | | | |                        
%         \_|| |_|   \_||_|_|_| |_|                        
%        (_____|                                           
%    _                           _             _            
%   | |                         | |           (_)           
%   | | _   ___  _   _ ____   _ | | ____  ____ _  ____  ___ 
%   | || \ / _ \| | | |  _ \ / || |/ _  |/ ___) |/ _  )/___)
%   | |_) ) |_| | |_| | | | ( (_| ( ( | | |   | ( (/ /|___ |
%   |____/ \___/ \____|_| |_|\____|\_||_|_|   |_|\____|___/ 
%                                                         
%                                    _                        
%                                   (_)                       
%         ____ _   _ ____  ____ ____ _  ___  ____             
%       / _  | \ / ) _  )/ ___) ___) |/___)/ _  )            
%      ( (/ / ) X ( (/ /| |  ( (___| |___ ( (/ /             
%       \____|_/ \_)____)_|   \____)_(___/ \____)            
%                                                         
%           ______   ______ ______   __                      
%          (_____ \ / __   (_____ \ /  |                     
%            ____) ) | //| | ____) )_/ |                     
%           /_____/| |// | |/_____/  | |                     
%           _______|  /__| |_______  | |                     
%          (_______)\_____/(_______) |_|                     
%                                                         
%                                                         
%                                                                                                           
%**************************************************************************
%**************************************************************************
    

% Exercise 5: grain boundaries and misorientations
% we will load a crop from a larger map, previously saved in mtex
dpath = '/home/rk/mtex/workshop/workshop21/exercises/'
load([dpath 'exp_qtz_crop.mat'])
% let's set the symmetry to the Laue group
ebsd('q').CS =  ebsd('q').CS.Laue;

%% 1) Compute grains 
% and determine the total grain boundary length. How much does it change
% when smoothign grains?

%% 2) Make a nice plot of the grain boundary directions.
% What is the preferred direction?


%% 3) Determine low angle (LA) boundaries
% a) Determine the distribution of low angle boundaries (1-9 degree).

% b) Colorcode misorientation axes in crystal coordiantes and plot them in
%    a map.

% c) Colorcode misorientation axes in specimen coordiantes and plot them in
%    a map.

% d) Plot the misorientation axes in crystal coordiantes in a point plot
%    and colrocode them according to the corresponding direction in
%    specimen coordinates.
%    AND
%    plot the misorientation axes in specimen coordinates and color code
%    with respect to the misorientatin axis in crytsal coordinates.


%% 4) Select low angle (LA) boundaries
% a) Select LA boundaries with a misorientation angle of 3 - 5 degree.

% b) Select all LA boundaries with misorientation axes which are parallel 
%    to [1,0,-1,0] (within some threshold).


% c) Select all LA boundaries with misorientation axes which are parallel to 
%    the z direction. Display with a proper color coding.

% d) Plot all boundaries which have a c-axis misrotation angle > 3*degree and 
%    <9degree. Plot the corresponding rotation axes.


%% 5) Can we check if some of these LABs are tilt boundaries
%  A tilt boundary should have the rotation axis within the boundary plane.
%  What is possible with 2D EBSD?



%% Bonus exercise misorientation
%**************************************************************************
% Question (not really boundary related):
% Some people like to click somewhere in a grain and then get a
% map with the points color-coded according to the misorientation angle 
% with respect to this reference point.
%
% Write a little script which does exactly provide this functionality.
% Bonus: Do not only display a map with the misorientation angle but also
% with the misorientation axes for each point in the grain.
%**************************************************************************
