Skip to content

Commit

Permalink
Merge pull request #161 from ralfHielscher/master
Browse files Browse the repository at this point in the history
mtex 4.3.0
  • Loading branch information
ralfHielscher committed Mar 8, 2016
2 parents 67659bc + 4b0d753 commit 5f22c89
Show file tree
Hide file tree
Showing 139 changed files with 2,912 additions and 871 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ c/mex/win64/*
c/mex/maci64/*
c/mex/maci/*
data/cif/*
examples/html
doc/html
*.mat
*~
*swp
*swo
*.directory
*.orig
help/mtex/*
Expand Down
49 changes: 46 additions & 3 deletions EBSDAnalysis/@EBSD/EBSD.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
orientations % rotation including symmetry
weights %
grainId % id of the grain to which the EBSD measurement belongs to
mis2mean % misorientation to the mean orientation of the corresponding grain
mis2mean % misorientation to the mean orientation of the corresponding grain
% dx % step size in x
% dy % step size in y
end

methods
Expand All @@ -51,6 +53,21 @@

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;
ebsd.prop = rot.prop;
return
end


ebsd.rotations = rotation(rot);
ebsd = ebsd.init(phases,CSList);
ebsd.id = (1:numel(phases)).';
Expand All @@ -59,7 +76,11 @@
ebsd.prop = get_option(varargin,'options',struct);

% get unit cell
ebsd.unitCell = get_option(varargin,'unitCell',[]);
if check_option(varargin,'uniCell')
ebsd.unitCell = get_option(varargin,'unitCell',[]);
else
ebsd.unitCell = calcUnitCell([ebsd.prop.x(:),ebsd.prop.y(:)]);
end

% remove ignore phases
if check_option(varargin,'ignorePhase')
Expand Down Expand Up @@ -108,7 +129,7 @@

function ebsd = set.grainId(ebsd,grainId)
if numel(grainId) == length(ebsd)
ebsd.prop.grainId = grainId(:);
ebsd.prop.grainId = reshape(grainId,size(ebsd.id));
elseif numel(grainId) == nnz(ebsd.isIndexed)
ebsd.prop.grainId = zeros(length(ebsd),1);
ebsd.prop.grainId(ebsd.isIndexed) = grainId;
Expand Down Expand Up @@ -142,6 +163,28 @@
ebsd.prop.weights = weights;
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

end
2 changes: 1 addition & 1 deletion EBSDAnalysis/@EBSD/KAM.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@
% compute kernel average misorientation
kam = sparse(Dl(ind),Dr(ind),omega(ind)+0.00001,length(ebsd),length(ebsd));
kam = kam+kam';
kam = full(sum(kam,2)./sum(kam>0,2));
kam = reshape(full(sum(kam,2)./sum(kam>0,2)),size(ebsd));
4 changes: 2 additions & 2 deletions EBSDAnalysis/@EBSD/calcGrains.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@

% save
grains.prop.GOS = GOS;
grains.prop.meanRotation = meanRotation;
mis2mean = inv(rotation(q(:))) .* meanRotation(grainId(:));
grains.prop.meanRotation = reshape(meanRotation,[],1);
mis2mean = inv(rotation(q(:))) .* grains.prop.meanRotation(grainId(:));

end

Expand Down
23 changes: 16 additions & 7 deletions EBSDAnalysis/@EBSD/calcMisorientation.m
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
function [mori,ori2] = calcMisorientation(ebsd1,varargin)
% calculate uncorelated misorientations between two ebsd phases
% calculate uncorrelated misorientations between two ebsd phases
%
% Syntax
% mori = calcMisorientation(ebsd,'sampleSize',1000)
% mori = calcMisorientation(ebsd,'minDistance',100)
% mori = calcMisorientation(ebsd1,ebsd2)
% [ori1,ori2] = calcMisorientation(ebsd1)
% plot(axis(ori1,ori2))
%
% % 1000 uncorrelated misorientations of phase1
% mori = calcMisorientation(ebsd('phase1'),'sampleSize',1000)
%
% % uncorrelated misorientations with minimum distance 100
% mori = calcMisorientation(ebsd('phase1'),'minDistance',100)
%
% % uncorrelated misorientations between phase1 and phase2
% mori = calcMisorientation(ebsd('phase1'),ebsd('phase2'))
%
% % compute pairs of orientations to be used to compute axis
% % distributions in specimen coordinates
% [ori1,ori2] = calcMisorientation(ebsd('phase1'))
% plot(axis(ori1,ori2),'contourf')
%
% Input
% ebsd, ebsd1, ebsd2 - @EBSD
% ebsd - @EBSD
%
% Output
% m - @orientation, such that
Expand Down
2 changes: 1 addition & 1 deletion EBSDAnalysis/@EBSD/calcTensor.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

% initialize avarage tensors
TVoigt = T{1};
TVoigt.M = zeros(size(T{1}));
TVoigt.M = zeros(repmat(3,1,TVoigt.rank));
TVoigt.CS = specimenSymmetry;
TReuss = TVoigt;

Expand Down
5 changes: 5 additions & 0 deletions EBSDAnalysis/@EBSD/display.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,9 @@ function display(ebsd,varargin)
disp(char(dynProp(ebsd.prop),'Id',ebsd.id,'Phase',ebsd.phase,...
'orientation',ebsd.rotations));
disp([' Scan unit : ',ebsd.scanUnit]);

if min(ebsd.size) > 1
disp([' Grid size : ',size2str(ebsd)]);
end

disp(' ');
51 changes: 51 additions & 0 deletions EBSDAnalysis/@EBSD/gridify.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
function [ebsdGrid,newId] = gridify(ebsd,varargin)
% extend EBSD data to an grid
%
% Syntax
% [ebsdGrid,newId] = gridify(ebsd)
%
% Input
%
% Output
% ebsdGrid -
% newId -

% generate regular grid
prop = ebsd.prop;
ext = ebsd.extend;
dx = max(ebsd.unitCell(:,1))-min(ebsd.unitCell(:,1));
dy = max(ebsd.unitCell(:,2))-min(ebsd.unitCell(:,2));
[prop.x,prop.y] = meshgrid(linspace(ext(1),ext(2),1+round((ext(2)-ext(1))/dx)),...
linspace(ext(3),ext(4),1+round((ext(4)-ext(3))/dy))); % ygrid runs first
sGrid = size(prop.x);

% detect position within grid
newId = sub2ind(sGrid, 1 + round((ebsd.prop.y - ext(3))/dy), ...
1 + round((ebsd.prop.x - ext(1))/dx));

% set phaseId to notIndexed at all empty grid points
phaseId = nan(sGrid);
phaseId(newId) = ebsd.phaseId;

% update rotations
a = nan(sGrid); b = a; c = a; d = a;
a(newId) = ebsd.rotations.a;
b(newId) = ebsd.rotations.b;
c(newId) = ebsd.rotations.c;
d(newId) = ebsd.rotations.d;

% update all other properties
for fn = fieldnames(ebsd.prop).'
if any(strcmp(char(fn),{'x','y','z'})), continue;end
if isnumeric(prop.(char(fn)))
prop.(char(fn)) = nan(sGrid);
else
prop.(char(fn)) = prop.(char(fn)).nan(sGrid);
end
prop.(char(fn))(newId) = ebsd.prop.(char(fn));
end

ebsdGrid = EBSDsquare(rotation(quaternion(a,b,c,d)),phaseId(:),...
ebsd.phaseMap,ebsd.CSList,[dx,dy],'options',prop);

end
8 changes: 5 additions & 3 deletions EBSDAnalysis/@EBSD/plot.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@
if nargin>1 && isnumeric(varargin{1})

property = varargin{1};

assert(any(numel(property) == length(ebsd) * [1,3]),...
'The number of values should match the number of ebsd data!')

h = plotUnitCells([ebsd.prop.x, ebsd.prop.y],...
h = plotUnitCells([ebsd.prop.x(:), ebsd.prop.y(:)],...
property, ebsd.unitCell, 'parent', mP.ax, varargin{:});

else % phase plot
Expand Down Expand Up @@ -81,7 +81,7 @@
% this is needed for the zoom: TODO maybe this can be done better
%if isNew, ; end % TODO set axis tight removes all the plot
try axis(mP.ax,'tight'); end
set(mP.ax,'zlim',[0,1]);
%set(mP.ax,'zlim',[0,1.1]);
mP.extend(1) = min(mP.extend(1),min(ebsd.prop.x(:)));
mP.extend(2) = max(mP.extend(2),max(ebsd.prop.x(:)));
mP.extend(3) = min(mP.extend(3),min(ebsd.prop.y(:)));
Expand All @@ -91,6 +91,8 @@

if isNew
mtexFig.drawNow('figSize',getMTEXpref('figSize'),varargin{:});
else
mP.micronBar.setOnTop
end

mtexFig.keepAspectRatio = false;
Expand Down
4 changes: 1 addition & 3 deletions EBSDAnalysis/@EBSD/private/plotUnitCells.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

end

if length(d) == size(xy,1)
if numel(d) == size(xy,1) || numel(d) == 3*size(xy,1)

obj.FaceVertexCData = reshape(d,size(xy,1),[]);
%if size(d,2) == 3, set(get(ax,'parent'),'renderer','opengl');end
Expand Down Expand Up @@ -54,8 +54,6 @@

end



h = optiondraw(patch(obj,'parent',ax),varargin{:});

if ~check_option(varargin,'DisplayName')
Expand Down
37 changes: 37 additions & 0 deletions EBSDAnalysis/@EBSD/quiver.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
function h = quiver(ebsd,dir,varargin)
% plot directions at ebsd centers
%
% Syntax
% quiver(ebsd,dir,'linecolor','r')
%
% mtexdata small
% quiver(ebsd,ebsd.rotations.axis)
%
% Input
% ebsd - @grain2d
% dir - @vector3d
%
% Options
% antipodal -
% maxHeadSize
%

xy = [ebsd.prop.x(:),ebsd.prop.y(:)];

if check_option(varargin,'antipodal') || dir.antipodal

varargin = [{'MaxHeadSize',0,'linewidth',2,'autoScaleFactor',0.5},varargin];
xy = [xy;xy];
dir = [dir(:);-dir(:)];

else

varargin = [{'MaxHeadSize',5,'linewidth',2,'autoScaleFactor',0.5},varargin];

end

h = optiondraw(quiver(xy(:,1),xy(:,2),dir.x,dir.y),varargin{:});

if nargout == 0, clear h; end

end
43 changes: 32 additions & 11 deletions EBSDAnalysis/@EBSD/reduce.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
function ebsd = reduce(ebsd,fak)
% reduce ebsd data by a factor
%
%
% Syntax
% ebsd = reduce(ebsd,2) % take every second pixel horiz. and vert.
% ebsd = reduce(ebsd) % take every second pixel horiz. and vert.
% ebsd = reduce(ebsd,3) % take every third pixel horiz. and vert.
%
% Input
Expand All @@ -13,16 +12,38 @@
% ebsd - @EBSD
%

% generate regular grid
ext = ebsd.extend;
dx = max(ebsd.unitCell(:,1))-min(ebsd.unitCell(:,1));
dy = max(ebsd.unitCell(:,2))-min(ebsd.unitCell(:,2));
if nargin == 1, fak = 2; end

if length(ebsd.unitCell) == 4

% generate regular grid
ext = ebsd.extend;
dx = max(ebsd.unitCell(:,1))-min(ebsd.unitCell(:,1));
dy = max(ebsd.unitCell(:,2))-min(ebsd.unitCell(:,2));

% detect position within grid
iy = round((ebsd.prop.y - ext(3))/dy);
ix = round((ebsd.prop.x - ext(1))/dx);

% detect position within grid
iy = round((ebsd.prop.y - ext(3))/dy);
ix = round((ebsd.prop.x - ext(1))/dx);
ebsd = ebsd.subSet(~mod(ix,fak) & ~mod(iy,fak));
ebsd.unitCell = fak*ebsd.unitCell;

elseif length(ebsd.unitCell) == 6 % hexgrid


% generate regular grid
ext = ebsd.extend;
dx = max(ebsd.unitCell(:,1))-min(ebsd.unitCell(:,1));
dy = max(ebsd.unitCell(:,2))-min(ebsd.unitCell(:,2));

% detect position within grid
iy = round((ebsd.prop.y - ext(3))/dy*4/3);
ix = round((ebsd.prop.x - ext(1))/dx*2);

ebsd = ebsd.subSet(~mod(ix,fak) & ~mod(iy,fak));
ebsd.unitCell = fak*ebsd.unitCell;
ebsd = ebsd.subSet(~mod(iy,fak) & ~mod(ix+iy,2*fak));

ebsd.unitCell = fak*ebsd.unitCell;

end

end
Loading

0 comments on commit 5f22c89

Please sign in to comment.