Newer
Older
Nicola Vigano
committed
function [cmap, Vsst, Vc_symm, vargs_out] = gtIPFCmap(phaseid, LD, varargin)
Laura Nervo
committed
% GTIPFCMAP Returns a colour map for the specified phase and lab/sample direction.
Yoann Guilhem
committed
%
% [cmap, Vsst, Vc_symm] = gtIPFCmap([phaseid], [LD], varargin)
% ------------------------------------------------------------
Laura Nervo
committed
% Makes an IPF colourmap of the lab_ direction (LD) in the crystal
% coordinates. This can be specified as a second argument, otherwise we
% assume the z-axis [0 0 1]
Yoann Guilhem
committed
%
Laura Nervo
committed
% INPUT:
% phaseid = <int> ID of the specific phase {1}
% LD = <double> Lab direction to study {[0 0 1]}
Yoann Guilhem
committed
%
% OPTIONAL INPUT (varargin as a list of pairs, see parse_pv_pairs.m)
% 'saturate' = <logical> Saturate colors in the SST {true}
% 'save' = <logical> Save color map to cmap_phase<phaseid>.mat
% 'crystal_system' = <string> Legacy to set (force) the crystal system
% for old datasets
Nicola Vigano
committed
% 'r_vectors' = <double> Rodrigues vectors as N x 3 array;
% if given, phaseid is ignored;
% 'background' = <logical> Add a background color in first row {true}
Yoann Guilhem
committed
%
% OUTPUT:
% cmap = <double> RGB color map, color code is the inverse
% pole figure in the SST
% Vsst = <double> Row vectors expressed in crystal frame
% moved to the SST triangle
% Vc_symm = <double> Row vectors expressed in crystal frame
% Version 002 08-02-2013 by YGuilhem
% Add r_vectors as optional input
Yoann Guilhem
committed
%
Laura Nervo
committed
% Version 003 08-01-2013 by LNervo
% Added second output argument: Vsst
%
% Version 002 03-01-2013 by YGuilhem
% Renamed gtIVPCmap to gtIPFCmap, changed colour saturation
Yoann Guilhem
committed
% Version 001 15-11-2012 by YGuilhem
% Built by gathering old gtIVPcubCmap and gtIVPhexCmap functions
% Default parameters
Nicola Vigano
committed
par.saturate = true;
par.save = false;
Yoann Guilhem
committed
par.crystal_system = '';
Nicola Vigano
committed
par.r_vectors = [];
par.background = true;
Nicola Vigano
committed
[par, rej_pars] = parse_pv_pairs(par, varargin);
Yoann Guilhem
committed
if ~exist('phaseid', 'var') || isempty(phaseid)
phaseid = 1;
end
if ~exist('LD', 'var') || isempty(LD)
LD = [0 0 1];
end
% Get the r-vectors
r_vectors = [];
phaseDir = fullfile('4_grains', sprintf('phase_%02d', phaseid));
if ~isempty(par.r_vectors)
r_vectors = par.r_vectors;
elseif exist(fullfile(phaseDir, 'r_vectors.mat'), 'file')
load(fullfile(phaseDir, 'r_vectors.mat'));
elseif exist(fullfile(phaseDir, 'index.mat'), 'file')
Yoann Guilhem
committed
grain = [];
load(fullfile(phaseDir, 'index.mat'), 'grain');
r_vectors = gtIndexAllGrainValues(grain, 'R_vector', [], 1, 1:3);
Yoann Guilhem
committed
else
Laura Nervo
committed
gtError('gtIPFCmap:missing_file', 'Could not find r_vectors.mat or index.mat file!');
Yoann Guilhem
committed
end
% Resize r_vectors if needed
if size(r_vectors, 2) == 4
r_vectors = r_vectors(:, 2:4);
end
if (isempty(par.crystal_system) || isempty(par.spacegroup))
parameters = gtLoadParameters();
par.crystal_system = parameters.cryst(phaseid).crystal_system;
par.spacegroup = parameters.cryst(phaseid).spacegroup;
end
if (isempty(par.symm))
par.symm = gtCrystGetSymmetryOperators(par.crystal_system, par.spacegroup);
Yoann Guilhem
committed
end
% Compute all orientation matrices g
Laura Nervo
committed
% Gcry = g Gsam
% g = U = gtMathsRod2OriMat(r_vectors.')
all_g = gtMathsRod2OriMat(r_vectors.');
Yoann Guilhem
committed
% Compute LDc = LD expressed in the crystal CS
LDc = gtVectorLab2Cryst(LD, all_g);
Yoann Guilhem
committed
Laura Nervo
committed
% Get the color and vector in the SST triangle
[cmap, Vsst, ~, Vc_symm] = gtCrystVector2SST(LDc, par.crystal_system, par.symm, par.saturate);
Yoann Guilhem
committed
Nicola Vigano
committed
if (par.background)
cmap = [ 0 0 0 ; cmap ];
end
Yoann Guilhem
committed
Nicola Vigano
committed
if (par.save)
LD_str = num2str(LD);
LD_str = strrep(LD_str,' ','');
Nicola Vigano
committed
fileName = fullfile('6_rendering', sprintf('cmap_phase%02d_%s.mat', phaseid, LD_str));
Yoann Guilhem
committed
save(fileName, 'cmap');
Nicola Vigano
committed
disp(['IPF cmap saved in ' fileName])
end
Nicola Vigano
committed
par.r_vectors = r_vectors;
par.phaseid = phaseid;
par.samDir = LD;
vargs_out = struct2pv(par);
Yoann Guilhem
committed
end
end % end of function