Skip to content
Snippets Groups Projects
Commit fa752294 authored by Nicola Vigano's avatar Nicola Vigano
Browse files

Improved IPF key generation function

parent db40e542
No related branches found
No related tags found
No related merge requests found
function h = gtIPFCmapKey(varargin)
function [h, ax] = gtIPFCmapKey(varargin)
% GTIPFCMAPKEY Show inverse pole figure color space in the hexagonal SST
%
% h = gtIPFCmapKey(varargin)
......@@ -23,22 +23,24 @@ function h = gtIPFCmapKey(varargin)
app = struct( ...
'crystal_system', '', ...
'N', 30, ...
'N', 45, ...
'poles_label', true, ...
'ipf_label', true, ...
'font_size', 12, ...
'font_size', 20, ...
'font_color', [0 0 0], ...
'drawing', true, ...
'hf', [], ...
'ha', [], ...
'fig_color', [1 1 1], ...
'sample_dir', '' );
'sample_dir', '', ...
'phase_id', 1, ...
'saturate', true );
[app, rej_pars] = parse_pv_pairs(app, varargin);
if (isempty(app.crystal_system))
parameters = gtLoadParameters();
app.crystal_system = parameters.cryst(1).crystal_system;
app.crystal_system = parameters.cryst(app.phase_id).crystal_system;
end
if (isempty(app.hf))
......@@ -53,69 +55,70 @@ else
end
hold(ha, 'on');
if (ismember(app.crystal_system, {'hexagonal', 'hex', 'hcp', 'h'}))
% For hexagonal colour map, we need two angles:
% - phi (around z-axis)
% - psi (from z-axis to vector)
% Work in radians
phimin = 0;
phimax = pi/6;
inc = phimax/app.N;
psimin = 0;
psimax = pi/2;
elseif (ismember(app.crystal_system, {'cubic', 'cube', 'c'}))
% For cubic colour map, we need two angles:
% - phi (around z-axis)
% - chi (around y-axis)
% Work in radians
phimin = 0;
phimax = pi/4;
inc = phimax/app.N;
psimin = 0;
psimax = atan(sqrt(2))+inc;
chimax = pi/4;
switch (lower(app.crystal_system))
case {'hexagonal', 'hex', 'hcp', 'h'}
% For hexagonal colour map, we need two angles:
% - phi (around z-axis)
% - psi (from z-axis to vector)
% Work in radians
phimin = 0;
phimax = pi/6;
inc = phimax/app.N;
psimin = 0;
psimax = pi/2;
case {'cubic', 'cube', 'c'}
% For cubic colour map, we need two angles:
% - phi (around z-axis)
% - chi (around y-axis)
% Work in radians
phimin = 0;
phimax = pi/4;
inc = phimax/app.N;
psimin = 0;
psimax = atan(sqrt(2))+inc;
chimax = pi/4;
end
h_p = [];
for phi = phimin:inc:(phimax-inc) % Rotation around z-axis
for psi = psimin:inc:(psimax-inc) % Out from z-axis to vector
if (ismember(app.crystal_system, {'hexagonal', 'hex', 'hcp', 'h'}))
ratioR = 1 - psi/psimax;
elseif (ismember(app.crystal_system, {'cubic', 'cube', 'c'}))
z = cos(psi);
x = sin(psi)*cos(phi);
chi = atan2(x, z);
if chi > chimax + inc/2
continue;
end
ratioR = 1 - chi/chimax;
end
ratioB = phi/phimax;
for phi = phimin:inc:(phimax-inc) % Rotation around z-axis
psis = (psimin:inc:(psimax-inc))';
if (ismember(app.crystal_system, {'hexagonal', 'hex', 'hcp', 'h'}))
ratios_R = 1 - psis ./ psimax;
elseif (ismember(app.crystal_system, {'cubic', 'cube', 'c'}))
zs = cos(psis);
xs = sin(psis) * cos(phi);
chis = atan2(xs, zs);
valid_chis = chis <= (chimax + inc / 2);
ratios_R = 1 - chis(valid_chis) / chimax;
psis = psis(valid_chis);
end
ratioB = phi / phimax;
red = ratioR;
green = (1 - ratioR) * (1 - ratioB);
blue = (1 - ratioR) * ratioB;
rgb = [red green blue];
red = ratios_R;
green = (1 - ratios_R) .* (1 - ratioB);
blue = (1 - ratios_R) .* ratioB;
rgb = [red, green, blue];
% Ensure that we stay in [0 1]
rgb(rgb < 0) = 0;
rgb(rgb > 1) = 1;
% Ensure that we stay in [0 1]
rgb = max(rgb, 0);
rgb = min(rgb, 1);
if (app.saturate)
rgb = gtCrystSaturateSSTColor(rgb);
end
if (app.saturate)
rgb = gtCrystSaturateSSTColor(rgb);
end
% Radius distorted for stereographic proj
r_patch = tan([psi/2 (psi+inc)/2]);
[phi_patch, r_patch] = meshgrid([phi phi+inc]', r_patch);
[x_patch, y_patch] = pol2cart(phi_patch, r_patch);
if (app.drawing)
for ii = 1:numel(psis)
% Radius distorted for stereographic proj
r_patch = tan([psis(ii)/2 (psis(ii)+inc)/2]);
[phi_patch, r_patch] = meshgrid([phi phi+inc]', r_patch);
[x_patch, y_patch] = pol2cart(phi_patch, r_patch);
if (app.drawing)
h_p(end+1) = patch(x_patch, y_patch, rgb, 'EdgeColor', 'none', 'Faces', [1 2 4 3], 'Parent', ha);
h_p(end+1) = patch(x_patch, y_patch, rgb(ii, :), 'EdgeColor', 'none', 'Faces', [1 2 4 3], 'Parent', ha);
end
end
end
......@@ -192,7 +195,7 @@ if (ismember(app.crystal_system, {'hexagonal', 'hex', 'hcp', 'h'}))
elseif (ismember(app.crystal_system, {'cubic', 'cube', 'c'}))
uvw_poles_x = [0 0.366 0.4142 0.236 0.2247 0.3 0.4];
uvw_poles_y = [0 0.366 0 0 0.2247 0.153 0.2];
uvw_poles_l = {'[0 0 1]', '[1 1 1]', '[1 0 1]', '[1 0 2]', '[1 1 2]', '[2 1 3]', '[2 1 2]'};
uvw_poles_l = {'[0 0 1]', '[1 1 1]', ' [1 0 1]', '[1 0 2] ', '[1 1 2] ', '[2 1 3]', '[2 1 2]'};
%uvw_poles_l(end+1) = {'[159]'};
%uvw_poles_x(end+1) = 0.2584;
%uvw_poles_y(end+1) = 0.0516; % 159
......@@ -201,7 +204,7 @@ end
h_t = [];
if (app.poles_label)
for ii = 1:length(uvw_poles_x)
plot(uvw_poles_x(ii), uvw_poles_y(ii), '*', ...
plot(uvw_poles_x(ii), uvw_poles_y(ii), 'o', 'LineWidth', 5, ...
'Tag', 'h_points_plot', 'Color', app.font_color, 'Parent', ha);
h_t{ii} = text(uvw_poles_x(ii), uvw_poles_y(ii), uvw_poles_l{ii}, ...
......@@ -212,6 +215,12 @@ if (app.poles_label)
if (ii == 2)
set(h_t{ii}, 'VerticalAlignment', 'bottom')
end
if (ii == 7)
set(h_t{ii}, 'VerticalAlignment', 'bottom')
end
if (ii == 5)
set(h_t{ii}, 'VerticalAlignment', 'middle', 'HorizontalAlignment', 'right')
end
end
end
......@@ -222,7 +231,7 @@ set(hf, 'Color', app.fig_color)
set(ha, 'Visible', 'off');
if (app.ipf_label)
label and sample direction to plot
% label and sample direction to plot
h_ipf = text(0, 0.6, 0, 'IPF', ...
'FontSize', app.font_size, 'Color', app.font_color, ...
'VerticalAlignment', 'top', 'HorizontalAlignment', 'left', ...
......@@ -236,13 +245,14 @@ h_ipf_dir = text(0, 0.52, 0, app.sample_dir, ...
if (ismember(app.crystal_system, {'cubic', 'cube', 'c'}))
if (app.ipf_label)
set(h_ipf, 'Position', [0, 0.35, 0])
set(h_ipf, 'Position', [-0.1, 0.40, 0])
end
set(h_ipf_dir, 'Position', [0, 0.32, 0])
set(h_ipf_dir, 'Position', [-0.1, 0.35, 0])
end
if (nargout > 0)
h = guihandles(hf);
ax = ha;
end
end % end of function
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment