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

Plotting/figures: added extras

parent 284031a0
No related branches found
No related tags found
No related merge requests found
......@@ -15,7 +15,8 @@ function gt6DMakeClusterKAMFigureForPaper(cl, cl_rec, grs, varargin)
'rotation_angles', zeros(0, 1), ...
'use_slice_R_vector', false, ...
'borders', 'yes', ...
'colorbar', 'yes' );
'colorbar', 'yes', ...
'extras', [] );
conf = parse_pv_pairs(conf, varargin);
if (~exist('cl_rec', 'var') || isempty(cl_rec))
......@@ -29,14 +30,14 @@ function gt6DMakeClusterKAMFigureForPaper(cl, cl_rec, grs, varargin)
end
end
p = gtLoadParameters();
if (isempty(conf.rotation_angles))
internal_shift = cl_rec.SEG.segbb(1:3) - cl_rec.ODF6D.shift;
seg_vol_bb = [internal_shift, cl_rec.SEG.segbb(4:6)];
seg_vol = cl_rec.SEG.seg;
else
p = gtLoadParameters();
cl_rec.ODF6D = gtGrainRotateStructure(cl_rec.ODF6D, ...
cl.proj, 'ODF6D', p, conf.rotation_angles, conf.rotation_axes);
......@@ -124,6 +125,13 @@ function gt6DMakeClusterKAMFigureForPaper(cl, cl_rec, grs, varargin)
set_size(f, ax, [], conf, slice_kam);
end
if (~isempty(conf.extras))
im_props = struct( ...
'pixel_size', p.recgeo.voxsize * 1e3, ...
'size', [size(slice_kam, 1) size(slice_kam, 2)] );
gtFigureAddExtras(ax, im_props, conf.extras);
end
drawnow();
clims_igm = [conf.clims(1), max(slice_igm(:))];
......@@ -145,6 +153,13 @@ function gt6DMakeClusterKAMFigureForPaper(cl, cl_rec, grs, varargin)
set_size(f, ax, [], conf, slice_kam);
end
if (~isempty(conf.extras))
im_props = struct( ...
'pixel_size', p.recgeo.voxsize * 1e3, ...
'size', [size(slice_kam, 1) size(slice_kam, 2)] );
gtFigureAddExtras(ax, im_props, conf.extras);
end
drawnow();
%
......
......@@ -11,8 +11,9 @@ function gt6DMakePhaseFigureForPaper( phase_mat, phase_id, varargin )
% 'slice', 1, ...
% 'clims', [], ...
% 'pixel_to_cm', 0.05, ...
% 'borders', 'no', ...
% 'colorbar', 'no');
% 'borders', false, ...
% 'colorbar', false, ...
% 'extras', []);
%
conf = struct( ...
......@@ -30,7 +31,8 @@ function gt6DMakePhaseFigureForPaper( phase_mat, phase_id, varargin )
'clims', [], ...
'pixel_to_cm', 0.05, ...
'borders', false, ...
'colorbar', false );
'colorbar', false, ...
'extras', [] );
conf = parse_pv_pairs(conf, varargin);
slice_ids = get_slice(phase_mat.vol, conf.plane, conf.slice);
......@@ -123,6 +125,14 @@ function gt6DMakePhaseFigureForPaper( phase_mat, phase_id, varargin )
set(ax, 'CLim', conf.clims)
end
if (~isempty(conf.extras))
p = gtLoadParameters();
im_props = struct( ...
'pixel_size', p.recgeo.voxsize * 1e3, ...
'size', [size(final_slice_RGB, 2) size(final_slice_RGB, 1)] );
gtFigureAddExtras(ax, im_props, conf.extras);
end
set(f, 'Units', 'centimeters')
img_size = size(final_slice_RGB) * conf.pixel_to_cm;
img_size = img_size([2 1]);
......
......@@ -11,7 +11,8 @@ function gt6DRenderEBSDMapIPF(EBSD_struct, varargin)
'scale', [], ...
'pixel_to_cm', 0.05, ...
'borders', 'no', ...
'colorbar', 'no' );
'colorbar', 'no', ...
'extras', [] );
conf = parse_pv_pairs(conf, varargin);
EBSD_r_map = EBSD_struct.map_r;
......@@ -86,6 +87,13 @@ function gt6DRenderEBSDMapIPF(EBSD_struct, varargin)
ax = axes('Parent', f);
im = imagesc(cat(3, slice_R, slice_G, slice_B), 'Parent', ax);
if (~isempty(conf.extras))
im_props = struct( ...
'pixel_size', EBSD_struct.pixel_size, ...
'size', [size(slice_ids, 2) size(slice_ids, 1)] );
gtFigureAddExtras(ax, im_props, conf.extras);
end
set(f, 'Units', 'centimeters')
img_size = size(slice_ids) .* conf.pixel_to_cm;
img_size = img_size([2 1]);
......
function gtFigureAddExtras(ax, im_props, extras)
num_extras = numel(extras);
for ii_ex = 1:num_extras
switch (extras{ii_ex}.type)
case 'unit_bar'
add_unit_bar(ax, im_props, extras{ii_ex});
case {'line_vertical', 'line_horizontal'}
add_line(ax, im_props, extras{ii_ex})
case 'box'
add_box(ax, extras{ii_ex})
case 'text'
add_text(ax, extras{ii_ex})
end
end
end
function add_unit_bar(ax, im_props, ex_props)
bar_length = ex_props.line_length / im_props.pixel_size(2);
switch (ex_props.position)
case 'north_west'
xs_l = ex_props.margin([1 1]) + [0 bar_length];
ys_l = ex_props.margin([2 2]);
x_t = ex_props.margin(1);
y_t = ex_props.margin(2) + 1; % + ex_props.line_width
font_placing_vert = 'top';
font_placing_horz = 'left';
case 'south_west'
xs_l = ex_props.margin([1 1]) + [0 bar_length];
ys_l = im_props.size([2 2]) - ex_props.margin([2 2]);
x_t = ex_props.margin(1);
y_t = im_props.size(2) - ex_props.margin(2) - 1; % - ex_props.line_width
font_placing_vert = 'bottom';
font_placing_horz = 'left';
case 'north_est'
xs_l = im_props.size([1 1]) - ex_props.margin([1 1]) - [0 bar_length];
ys_l = ex_props.margin([2 2]);
x_t = im_props.size(1) - ex_props.margin(1); % - bar_length
y_t = ex_props.margin(2) + 1; % + ex_props.line_width
font_placing_vert = 'top';
font_placing_horz = 'right';
case 'south_est'
xs_l = im_props.size([1 1]) - ex_props.margin([1 1]) - [0 bar_length];
ys_l = im_props.size([2 2]) - ex_props.margin([2 2]);
x_t = im_props.size(1) - ex_props.margin(1); % - bar_length
y_t = im_props.size(2) - ex_props.margin(2) - 1; % - ex_props.line_width
font_placing_vert = 'bottom';
font_placing_horz = 'right';
end
line(xs_l, ys_l, 'parent', ax, 'Color', ex_props.color, 'LineWidth', ex_props.line_width)
text(x_t, y_t, sprintf('%g %s', ex_props.line_length, ex_props.base_unit), ...
'parent', ax, 'Color', ex_props.color, ...
'FontSize', ex_props.font_size, ...
'FontAngle', ex_props.font_angle, ...
'FontWeight', ex_props.font_weight, ...
'VerticalAlignment', font_placing_vert, ...
'HorizontalAlignment', font_placing_horz )
end
function add_line(ax, im_props, ex_props)
switch (ex_props.type)
case 'line_vertical'
xs_l = ex_props.position([1 1]);
ys_l = [1 im_props.size(2)];
case 'line_horizontal'
xs_l = [1 im_props.size(1)];
ys_l = ex_props.position([1 1]);
end
line(xs_l, ys_l, 'parent', ax, 'Color', ex_props.color, ...
'LineWidth', ex_props.line_width, 'LineStyle', ex_props.line_style)
end
function add_box(ax, ex_props)
x_nw = ex_props.position(1);
y_nw = ex_props.position(2);
x_sw = ex_props.position(1);
y_sw = ex_props.position(2) + ex_props.position(4) - 1;
x_ne = ex_props.position(1) + ex_props.position(3) - 1;
y_ne = ex_props.position(2);
x_se = ex_props.position(1) + ex_props.position(3) - 1;
y_se = ex_props.position(2) + ex_props.position(4) - 1;
line([x_nw x_sw], [y_nw y_sw], 'parent', ax, 'Color', ex_props.color, ...
'LineWidth', ex_props.line_width, 'LineStyle', ex_props.line_style)
line([x_ne x_se], [y_ne y_se], 'parent', ax, 'Color', ex_props.color, ...
'LineWidth', ex_props.line_width, 'LineStyle', ex_props.line_style)
line([x_nw x_ne], [y_nw y_ne], 'parent', ax, 'Color', ex_props.color, ...
'LineWidth', ex_props.line_width, 'LineStyle', ex_props.line_style)
line([x_sw x_se], [y_sw y_se], 'parent', ax, 'Color', ex_props.color, ...
'LineWidth', ex_props.line_width, 'LineStyle', ex_props.line_style)
end
function add_text(ax, ex_props)
text(ex_props.position(1), ex_props.position(2), ex_props.string, ...
'parent', ax, 'Color', ex_props.color, ...
'FontSize', ex_props.font_size, ...
'FontAngle', ex_props.font_angle, ...
'FontWeight', ex_props.font_weight, ...
'HorizontalAlignment', ex_props.alignment_horz, ...
'VerticalAlignment', ex_props.alignment_vert );
end
function extras = gtFigureCreateExtras(type, varargin)
switch (type)
case 'unit_bar'
extras = create_unit_bar(varargin{:});
case {'line_vertical', 'line_horizontal'}
extras = create_line(varargin{:});
case 'box'
extras = create_box(varargin{:});
case 'text'
extras = create_text(varargin{:});
end
extras.type = type;
end
function extras = create_unit_bar(varargin)
extras = struct( ...
'base_unit', 'um', ... % µm (\u00B5m), \mu m, mm
'line_length', 10, ...
'line_width', 2, ...
'position', 'south_west', ... {'north_west', 'south_west', 'north_est', 'south_est'}
'margin', [10 10], ...
'font_size', 10, ...
'font_weight', 'normal', ... {'normal', 'bold', 'light', 'demi'}
'font_angle', 'normal', ... {'normal', 'italic', 'oblique'}
'color', [1 1 1] );
extras = parse_pv_pairs(extras, varargin);
end
function extras = create_line(varargin)
extras = struct( ...
'line_width', 2, ...
'line_style', '-', ...
'position', 1, ...
'color', [1 1 1] );
extras = parse_pv_pairs(extras, varargin);
end
function extras = create_box(varargin)
extras = struct( ...
'line_width', 2, ...
'line_style', '-', ...
'position', [1 1 10 10], ...
'color', [1 1 1] );
extras = parse_pv_pairs(extras, varargin);
end
function extras = create_text(varargin)
extras = struct( ...
'string', '', ...
'position', [1 1], ...
'alignment_horz', 'center', ... {'left', 'center', 'right'}
'alignment_vert', 'middle', ... {'top', 'cap', 'middle', 'baseline', 'bottom'}
'font_size', 10, ...
'font_weight', 'normal', ... {'normal', 'bold', 'light', 'demi'}
'font_angle', 'normal', ... {'normal', 'italic', 'oblique'}
'color', [1 1 1] );
extras = parse_pv_pairs(extras, varargin);
end
......@@ -10,7 +10,9 @@ function gtMakeFigureFromPicture(img, mask, varargin)
'clims', [], ...
'pixel_to_cm', 0.05, ...
'borders', true, ...
'colorbar', true );
'colorbar', true, ...
'pixel_size', [], ...
'extras', [] );
conf = parse_pv_pairs(conf, varargin);
use_mask = ~isempty(mask);
......@@ -66,6 +68,17 @@ function gtMakeFigureFromPicture(img, mask, varargin)
end
colormap(ax, jet)
if (~isempty(conf.extras))
if (isempty(conf.pixel_size))
p = gtLoadParameters();
conf.pixel_size = p.recgeo.voxsize * 1e3;
end
im_props = struct( ...
'pixel_size', conf.pixel_size, ...
'size', [size(img, 1) size(img, 2)] );
gtFigureAddExtras(ax, im_props, conf.extras);
end
set_size(f, ax, conf, mask);
end
......
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