Skip to content
Snippets Groups Projects
Commit 5f19e50c authored by Laura Nervo's avatar Laura Nervo
Browse files

gtDrawGrainUnitCell : added option to draw the c-axis, saved grain info into...

gtDrawGrainUnitCell : added option to draw the c-axis, saved grain info into 'UserData' figure property.

Signed-off-by: default avatarLaura Nervo <laura.nervo@esrf.fr>
parent 497d9d66
No related branches found
No related tags found
No related merge requests found
......@@ -31,12 +31,13 @@ function [f_handle, p_handle] = gtDrawGrainUnitCells(grains, varargin)
% hf = figure handle if already existing {[]}
% zoom = <double> zoom in of this quantity {1.2}
% view = <double> 3D angular view {[0 90]} (1x2)
% caxis = <logical> flag to draw the c-axis {false}
% legend = <logical> display or not the legend {false}
% legendpos = <double> location of the legend box {'NorthEast'}
%
% OUTPUT:
% f_handle = handle of the figure
% p_handle = handle of the patches
% f_handle = figure handle
% p_handle = patches handle
%
%
% Usage:
......@@ -61,7 +62,7 @@ function [f_handle, p_handle] = gtDrawGrainUnitCells(grains, varargin)
app.ids = arrayfun(@(num) 1:numel(grains{num}), 1:numel(grains), 'UniformOutput', false);
app.cmap{1} = [];
app.hlight{1} = [];
app.linecolor = {'k','r','y','g','b'};
app.linecolor = {[0 0 0],[1 0 0],[0 1 0],[0 0 1],[1 1 0],[1 0 1],[0 1 1],[1 1 1]};
app.strain = cellfun(@(num) 0, grains, 'UniformOutput', false);
app.alpha = cellfun(@(num) 1, grains, 'UniformOutput', false);
app.pxsize{1} = [];
......@@ -73,6 +74,7 @@ app.label{1} = [];
app.hf = [];
app.zoom = 1.2;
app.view = [0 90];
app.caxis = false;
app.legend = false;
app.legendpos = 'NorthEast';
......@@ -93,7 +95,7 @@ else
hf = app.hf;
end
set(gcf, 'Visible', 'off');
set(hf, 'Visible', 'off');
hp = [];
......@@ -113,7 +115,7 @@ for ii=1:numel(grains)
if isempty(app.type{ii}), app.type{ii} = cryst.crystal_system; end
if isempty(app.ratio{ii}), app.ratio{ii} = cryst.latticepar(3)/cryst.latticepar(1); end
if isempty(app.ids{ii}), app.ids{ii} = 1:length(grains{ii}); end
if isempty(app.cmap{ii}), app.cmap{ii} = zeros(length(grains{ii}),1); end
if isempty(app.cmap{ii}), app.cmap{ii} = repmat([1 0 0],length(grains{ii}),3); end %red color
ids = app.ids{ii};
grain = grains{ii};
......@@ -134,9 +136,9 @@ for ii=1:numel(grains)
% vertices and faces calculation : TO DO LIST : unify in one function
if strcmpi(app.type{ii}, 'cubic')
data{ii} = gtCubicUnitCell('ratio',app.ratio{ii},'draw',false);
data{ii} = gtCubicUnitCell('ratio',app.ratio{ii},'draw',false,'centered',true);
elseif strcmpi(app.type{ii}, 'hexagonal')
data{ii} = gtHexagonalUnitCell('ratio',app.ratio{ii},'draw',false);
data{ii} = gtHexagonalUnitCell('ratio',app.ratio{ii},'draw',false,'centered',true);
end
% draw unit cells
......@@ -148,18 +150,16 @@ for ii=1:numel(grains)
% grain size
if isfield(grain{jj}, 'stat')
if isfield(grain{jj}.stat, 'size_int')
grainsize = 0.5*app.pxsize{ii}*grain{jj}.stat.size_int;
grain{jj}.radius = 0.5*app.pxsize{ii}*grain{jj}.stat.size_int; % mm
elseif isfield(grain{jj}.stat, 'bbxsmean') && isfield(grain{jj}.stat, 'bbysmean')
grainsize = 0.5*app.pxsize{ii}*(grain{jj}.stat.bbxsmean + grain{jj}.stat.bbysmean)/2;
grain{jj}.radius = 0.5*app.pxsize{ii}*(grain{jj}.stat.bbxsmean + grain{jj}.stat.bbysmean)/2; % mm
end
else
grainsize = 10;
grain{jj}.radius = 10;
end
% grain strain
if ~isfield(grain{jj}, 'strain')
strainT = NaN(3);
else
strainT = grain{jj}.strain.strainT;
grain{jj}.strain.strainT = NaN(3);
end
% highlight grain?
......@@ -167,27 +167,30 @@ for ii=1:numel(grains)
% computes vertices and caxis coordinates
vertices{jj} = gtComputeGrainUnitCell(grain{jj}.R_vector, data{ii}.vertices, ...
grainsize, grain{jj}.center, strainT, app.strain{ii});
caxis{jj} = gtComputeGrainUnitCell(grain{jj}.R_vector, data{ii}.caxis, ...
grainsize, grain{jj}.center, strainT, app.strain{ii});
grain{jj}.radius, grain{jj}.center, grain{jj}.strain.strainT, app.strain{ii});
if app.caxis
caxis{jj} = gtComputeGrainUnitCell(grain{jj}.R_vector, data{ii}.caxis, ...
grain{jj}.radius, grain{jj}.center, grain{jj}.strain.strainT, app.strain{ii});
else
caxis{jj} = [];
end
% draws patches for prismatic planes
p{end+1} = gtPlotGrainUnitCell(...
vertices{jj}, caxis{jj}, data{ii}.faces_sides, ...
p{end+1} = gtPlotGrainUnitCell(vertices{jj}, caxis{jj}, data{ii}.faces, ...
cmap(jj,:), hl, app.linecolor{ii}, app.alpha{ii});
set(p{end}, 'UserData', [ii ids(jj)]);
set(p{end}, 'Tag', sprintf('data_%02d_grain_%04d',ii,grain{jj}.id));
% draws patches for basal planes
p{end+1} = gtPlotGrainUnitCell(...
vertices{jj}, caxis{jj}, data{ii}.faces_end, ...
cmap(jj,:), hl, app.linecolor{ii}, app.alpha{ii});
set(p{end}, 'UserData', [ii ids(jj)]);
set(p{end}, 'Tag', sprintf('data_%02d_grain_%04d',ii,grain{jj}.id));
userdata(jj).grain = struct('id', grain{jj}.id, 'center', grain{jj}.center, 'R_vector', grain{jj}.R_vector, ...
'strainT', grain{jj}.strain.strainT, 'strain', app.strain{ii}, ...
'radius', grain{jj}.radius, 'cmap', cmap(jj,:), ...
'caxis', caxis{jj}, 'vertices', vertices{jj}, 'dataset', ii);
end % end for jj % loop over grains
app.cmap{ii} = cmap;
plotdata{ii} = userdata;
hp{ii} = p;
end % end for ii % loop over datasets
......@@ -201,11 +204,12 @@ zoom('off')
view(app.view);
if app.legend
leg = legend('Parent',gcf,'String',app.label,'Location',app.legendpos);
leg = legend('Parent',hf,'String',app.label,'Location',app.legendpos);
end
set(gcf, 'Visible', 'on');
f_handle = gcf;
set(hf, 'UserData', plotdata);
set(hf, 'Visible', 'on');
f_handle = hf;
app.hf = f_handle;
if nargout == 2
......
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