/
EBSD.m
223 lines (190 loc) · 6.6 KB
/
EBSD.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
classdef EBSD < phaseList & dynProp & dynOption
% class representing EBSD measurements
%
% In MTEX a variable of type <EBSD.EBSD.html |EBSD|> is used to store
% EBSD measurements as a table with rows containing the orientation, the
% spatial coordinates and the phase of each individual measurement.
%
% Syntax
%
% prop.xy = xy;
% prop.mad = mad;
% CSList = {'notIndexed',CS1,CS2,CS3};
% rot = rotation.byEuler(phi1,Phi,phi2);
%
% ebsd = EBSD(rot,phaseId,CSList,prop)
% ebsd = EBSD(rot,phaseId,CSList,prop,'unitCell',unitCell)
%
% Input
% rot - @rotation
% phaseId - phase as index to CSList
% CS1,CS2,CS3 - @crystalSymmetry
% prop - struct with properties, xy is mandatory
% unitCell - vertices a single pixel
%
% Options
% phase - specifying the phase of the EBSD object
% options - struct with fields holding properties for each orientation
% xy - spatial coordinates n x 2, where n is the number of input orientations
% unitCell - for internal use
%
% Class Properties
% id - unique id of each pixel
% CSList - cell list of @crystalSymmetry
% phaseId - phase of each pixel as entry of CSList
% phase - phase of each pixel as imported
% phaseMap - convert between phase = phaseMap(phaseId)
% rotations - @rotation of each pixel
% x, y - coordinates of the center of each pixel
% scanUnit - unit of the x,y coordinates (um is default)
% prop - auxiliary properties, e.g., MAD, BC, mis2mean
% isIndexed - is pixel indexed or not
% indexedPhaseId - phaseIds of all indexed phases
%
% Derived Classes
% @EBSDsquare - EBSD data measured on a square grid
% @EBSDhex - EBSD data measured on a hex grid
%
% See also
% EBSDImport EBSDSelect EBSDPlotting GrainReconstruction
% properties with as many rows as data
properties
id = [] % unique id's starting with 1
rotations = rotation % rotations without crystal symmetry
end
% general properties
properties
scanUnit = 'um' % unit of the x,y coordinates
unitCell = [] % cell associated to a measurement
end
properties (Dependent = true)
orientations % rotation including symmetry
grainId % id of the grain to which the EBSD measurement belongs to
mis2mean % misorientation to the mean orientation of the corresponding grain
end
properties (Access = protected)
A_D = [] % adjacency matrix of the measurement points
end
methods
function ebsd = EBSD(rot,phases,CSList,prop,varargin)
if nargin == 0, return; end
% copy constructor
if isa(rot,'EBSD')
ebsd.id = rot.id(:);
ebsd.rotations = rot.rotations(:);
ebsd.phaseId = rot.phaseId(:);
ebsd.phaseMap = rot.phaseMap;
ebsd.CSList = rot.CSList;
ebsd.unitCell = rot.unitCell;
ebsd.scanUnit = rot.scanUnit;
ebsd.A_D = rot.A_D;
for fn = fieldnames(rot.prop)'
ebsd.prop.(char(fn))= rot.prop.(char(fn))(:);
end
ebsd.opt = rot.opt;
ebsd = ebsd.subSet(~isnan(ebsd.phaseId));
return
end
ebsd.rotations = rotation(rot);
ebsd = ebsd.init(phases,CSList);
ebsd.id = (1:numel(phases)).';
% extract additional properties
ebsd.prop = prop;
% get unit cell
if check_option(varargin,'unitCell')
ebsd.unitCell = get_option(varargin,'unitCell',[]);
else
ebsd = ebsd.updateUnitCell;
end
end
% --------------------------------------------------------------
function varargout = size(ebsd,varargin)
[varargout{1:nargout}] = size(ebsd.id,varargin{:});
end
function ori = get.mis2mean(ebsd)
ori = ebsd.prop.mis2mean;
try
ori = orientation(ori,ebsd.CS,ebsd.CS);
catch
end
end
function ebsd = set.mis2mean(ebsd,ori)
if length(ori) == length(ebsd)
ebsd.prop.mis2mean = rotation(ori(:));
elseif length(ori) == nnz(ebsd.isIndexed)
ebsd.prop.mis2mean = rotation.id(length(ebsd),1);
ebsd.prop.mis2mean(ebsd.isIndexed) = rotation(ori);
elseif isscalar(ori)
ebsd.prop.mis2mean = rotation(ori) .* rotation.id(length(ebsd),1);
else
error('The list of mis2mean has to have the same size as the list of ebsd data.')
end
end
function grainId = get.grainId(ebsd)
try
grainId = ebsd.prop.grainId;
catch
error('No grainId stored in the EBSD variable. \n%s\n\n%s\n',...
'Use the following command to store the grainId within the EBSD data',...
'[grains,ebsd.grainId] = calcGrains(ebsd)')
end
end
function ebsd = set.grainId(ebsd,grainId)
if numel(grainId) == length(ebsd)
ebsd.prop.grainId = reshape(grainId,size(ebsd.id));
elseif numel(grainId) == nnz(ebsd.isIndexed)
ebsd.prop.grainId = zeros(size(ebsd));
ebsd.prop.grainId(ebsd.isIndexed) = grainId;
elseif isscalar(grainId)
ebsd.prop.grainId = grainId * ones(size(ebsd));
else
error('The list of grainId has to have the same size as the list of ebsd data.')
end
end
function ori = get.orientations(ebsd)
if isempty(ebsd)
ori = orientation;
else
ori = orientation(ebsd.rotations,ebsd.CS);
% set not indexed orientations to nan
if ~all(ebsd.isIndexed), ori(~ebsd.isIndexed) = NaN; end
end
end
function ebsd = set.orientations(ebsd,ori)
if ~isempty(ebsd)
if isa(ori,'quaternion')
ebsd.rotations = rotation(ori);
ebsd.CS = ori.CS;
elseif isnan(ori) && isscalar(ori)
ebsd.rotations = rotation.nan(size(ebsd));
else
error('type mismatch');
end
end
end
% function dx = get.dx(ebsd)
% uc = ebsd.unitCell;
% if size(uc,1) == 4
% dx = max(uc(:,1)) - min(uc(:,1));
% elseif size(uc,1) == 6
% dx = max(uc(:,1)) - min(uc(:,1));
% else
% dx = inf;
% end
% end
%
% function dy = get.dy(ebsd)
% uc = ebsd.unitCell;
% if size(uc,1) == 4
% dy = max(uc(:,2)) - min(uc(:,2));
% elseif size(uc,1) == 6
% dy = max(uc(:,2)) - min(uc(:,2));
% else
% dy = inf;
% end
% end
end
methods (Static = true)
[ebsd,interface,options] = load(fname,varargin)
end
end