Skip to content
Snippets Groups Projects
Commit 34436242 authored by Laura Nervo's avatar Laura Nervo Committed by Nicola Vigano
Browse files

gtDrawGrainUnitCell : added varargin options 'strain' and 'grainids'; changed...

gtDrawGrainUnitCell : added varargin options 'strain' and 'grainids'; changed used of input cmap (now can be the full cmap)

Signed-off-by: default avatarLaura Nervo <laura.nervo@esrf.fr>

git-svn-id: https://svn.code.sf.net/p/dct/code/trunk@1008 4c865b51-4357-4376-afb4-474e03ccb993
parent aaab3454
No related branches found
No related tags found
No related merge requests found
...@@ -9,21 +9,28 @@ function [f_handle, cb_handle] = gtDrawGrainUnitCells(grains, varargin) ...@@ -9,21 +9,28 @@ function [f_handle, cb_handle] = gtDrawGrainUnitCells(grains, varargin)
% grains = grain structure from indexing <cell> % grains = grain structure from indexing <cell>
% %
% OPTIONAL INPUT (varargin): % OPTIONAL INPUT (varargin):
% hf = figure handle {[]} % grainids = <double> list of grain IDs of interest
% cmap = can be a component of the strain tensor <double> % hf = figure handle {}
% {grain.strain.strainT(3,3)} or a colour map (length must be as grains) % cmap = <double> can be a component of the strain tensor
% latticepar = lattice parameters <double 1x6> % {grain.strain.strainT(3,3)} or a colour map
% labgeo = laboratory geometry as in parameters <struct> % latticepar = <double 1x6> lattice parameters
% phaseid = phase number <int> {1} % labgeo = <struct> laboratory geometry as in parameters
% type = cell type <string> {'cubic'} / 'hexagonal' % phaseid = <int> phase number {1}
% hlight = grain id-s to be highlighted {[]} % type = <string> unit cell type {'cubic'}/'hexagonal'
% scale = number to scale grain size; empty to use bbox info in grain <double> {[]} % hlight = <double> grain id-s to be highlighted {}
% view = 3D angular view <double 1x2> {[-37.5 30]} % scale = <double> number to scale grain size; empty to use bbox info in grain {}
% showbar = flag to show the colourbar <logical> {false} % view = <double 1x2> 3D angular view {[0 90]}
% showbar = <logical> flag to show the colourbar {false}
% colormap = <string> type of the colormap 'jet',{'cool'},'gray','autumn','hsv',...
% only if it is not with true colours (RGB)
% If needed, one can set the number of
% levels: i.e. 'colormap','jet(10)'
% strain = <double> scale factor for the strain values, if wanted {0}
% zero to use the unstrained unit cell
% %
% OUTPUT: % OUTPUT:
% f_handle = handle to the figure % f_handle = handle of the figure
% cb_handle = handle to the colorbar % cb_handle = handle of the colorbar
% %
% %
% Version 004 15-11-2012 by LNervo % Version 004 15-11-2012 by LNervo
...@@ -35,6 +42,7 @@ function [f_handle, cb_handle] = gtDrawGrainUnitCells(grains, varargin) ...@@ -35,6 +42,7 @@ function [f_handle, cb_handle] = gtDrawGrainUnitCells(grains, varargin)
% modify parameters/global settings % modify parameters/global settings
app.grainids = [];
app.hf = []; app.hf = [];
app.cmap = []; app.cmap = [];
app.latticepar = []; app.latticepar = [];
...@@ -46,7 +54,7 @@ app.scale = []; ...@@ -46,7 +54,7 @@ app.scale = [];
app.view = [0 90]; app.view = [0 90];
app.showbar = false; app.showbar = false;
app.colormap = 'cool'; app.colormap = 'cool';
app.strainscale = 0; app.strain = 0;
app = parse_pv_pairs(app, varargin); app = parse_pv_pairs(app, varargin);
...@@ -56,12 +64,12 @@ if ~exist('grains','var') || isempty(grains) ...@@ -56,12 +64,12 @@ if ~exist('grains','var') || isempty(grains)
tmp = load(fullfile('4_grains',sprintf('phase_%02d',app.phaseid),'index.mat'),'grain'); tmp = load(fullfile('4_grains',sprintf('phase_%02d',app.phaseid),'index.mat'),'grain');
grains = tmp.grain; grains = tmp.grain;
end end
if isempty(app.grainids)
app.grainids = 1:length(grains);
end
if isempty(app.cmap) if isempty(app.cmap)
if isfield(grains{1},'strain') if isfield(grains{1},'strain')
app.cmap = gtIndexAllGrainValues(grains,'strain','strainT',3,3); app.cmap = gtIndexAllGrainValues(grains,'strain','strainT',3,3);
if app.strainscale~=0
app.cmap = app.cmap*app.strainscale;
end
disp('Using strainT(3,3) as colorscale') disp('Using strainT(3,3) as colorscale')
app.showbar = true; app.showbar = true;
else else
...@@ -73,7 +81,15 @@ else ...@@ -73,7 +81,15 @@ else
if size(app.cmap,1)==1 if size(app.cmap,1)==1
app.cmap = repmat(app.cmap,length(grains),1); app.cmap = repmat(app.cmap,length(grains),1);
end end
% remove bkg color
if all(app.cmap(1,:) == 0)
app.cmap(1,:) = [];
end
end end
grains = grains(app.grainids);
app.cmap = app.cmap(app.grainids,:);
if isempty(app.latticepar) if isempty(app.latticepar)
load('parameters.mat'); load('parameters.mat');
app.latticepar = parameters.cryst(app.phaseid).latticepar; app.latticepar = parameters.cryst(app.phaseid).latticepar;
...@@ -115,24 +131,18 @@ if app.showbar ...@@ -115,24 +131,18 @@ if app.showbar
end end
% vertices and faces calculation % vertices and faces calculation
vertices = [];
faces_sides = [];
faces_end = [];
hkl = [];
if strcmpi(app.type, 'cubic') if strcmpi(app.type, 'cubic')
data = gtCubicUnitCell('ratio',1,'draw',false); data = gtCubicUnitCell('ratio',app.latticepar(3)/app.latticepar(1),'draw',false);
vertices = data.vertices(1:8,:); vertices = data.vertices(1:8,:);
faces_sides = data.faces_sides; faces_sides = data.faces_sides;
faces_end = data.faces_end; faces_end = data.faces_end;
hkl = data.hkl; hkl = data.hkl;
elseif strcmpi(app.type, 'hexagonal') elseif strcmpi(app.type, 'hexagonal')
a = app.latticepar(1); data = gtHexagonalUnitCell('ratio',app.latticepar(3)/app.latticepar(1),'draw',false);
c = app.latticepar(3); vertices = data.vertices(1:12,:);
data = gtHexagonalUnitCell('ratio',c/a,'draw',false);
vertices = data.vertices(1:12,:);
faces_sides = data.faces_sides; faces_sides = data.faces_sides;
faces_end = data.faces_end; faces_end = data.faces_end;
hkl = data.hkil; hkl = data.hkil;
end end
[Bmat, Amat] = gtCrystHKL2CartesianMatrix(app.latticepar); [Bmat, Amat] = gtCrystHKL2CartesianMatrix(app.latticepar);
...@@ -141,19 +151,18 @@ pl_cryst = gtCrystHKL2Cartesian(hkl, Bmat); % hkl plane normals in cryst referen ...@@ -141,19 +151,18 @@ pl_cryst = gtCrystHKL2Cartesian(hkl, Bmat); % hkl plane normals in cryst referen
% draw unit cells % draw unit cells
for ii = 1:nof_grains for ii = 1:nof_grains
if ismember(ii, app.hlight) if ismember(ii, app.hlight)
hl = true; hl = true;
else else
hl = false; hl = false;
end end
sfPlotGrainCell(grains{ii}, vertices, faces_sides, hl, pixelsize, app.cmap(ii,:), app.scale, app.strain);
sfPlotGrainCell(grains{ii}, vertices, faces_sides, hl, pixelsize, app.cmap(ii,:), app.scale); sfPlotGrainCell(grains{ii}, vertices, faces_end, hl, pixelsize, app.cmap(ii,:), app.scale, app.strain);
sfPlotGrainCell(grains{ii}, vertices, faces_end, hl, pixelsize, app.cmap(ii,:), app.scale);
end end
f_handle = hf; axis equal;
f_handle = gcf;
if nargout == 2 if nargout == 2
cb_handle = cb; cb_handle = cb;
...@@ -163,11 +172,11 @@ end % of main function ...@@ -163,11 +172,11 @@ end % of main function
%% %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SUB-FUNCTIONS % SUB-FUNCTIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function sfPlotGrainCell(grain, vertices, faces, hl, pixelsize, cmap, scale) function sfPlotGrainCell(grain, vertices, faces, hl, pixelsize, cmap, scale, strainscale)
if isempty(scale) if isempty(scale)
ga = 0.5*pixelsize*(grain.stat.bbxsmean + grain.stat.bbysmean)/2; ga = 0.5*pixelsize*(grain.stat.bbxsmean + grain.stat.bbysmean)/2;
...@@ -189,8 +198,8 @@ end ...@@ -189,8 +198,8 @@ end
grain_vertices = ga*vertices*g_grain'; grain_vertices = ga*vertices*g_grain';
grain_vertices_st = repmat(gc,size(vertices,1),1) + (eye(3)*grain_vertices')'; grain_vertices_st = repmat(gc,size(vertices,1),1) + (eye(3)*grain_vertices')';
if isfield(grain,'strain') && ~any(isnan(grain.strain.strainT(:))) if isfield(grain,'strain') && ~any(isnan(grain.strain.strainT(:))) && strainscale ~= 0
grain_vertices_st = grain_vertices_st + (grain.strain.strainT*50*grain_vertices')'; grain_vertices_st = grain_vertices_st + (grain.strain.strainT*strainscale*grain_vertices')';
end end
facecolor = repmat(cmap,size(faces,1),1); facecolor = repmat(cmap,size(faces,1),1);
......
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