Skip to content

Commit

Permalink
Merge pull request #285 from ralfHielscher/develop
Browse files Browse the repository at this point in the history
merge MTEX 4.5.2 from develop
  • Loading branch information
ralfHielscher authored Nov 19, 2017
2 parents ed9abd9 + 8e0f190 commit b20516b
Show file tree
Hide file tree
Showing 102 changed files with 3,379 additions and 1,769 deletions.
10 changes: 8 additions & 2 deletions EBSDAnalysis/@EBSD/KAM.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
% Options
% threshold - ignore misorientation angles larger then threshold
% order - consider neighbors of order n
% max - take not the mean but the maximum misorientation angle
%
% See alo
% See also
% grain2d.GOS

% compute adjacent measurements
Expand Down Expand Up @@ -76,4 +77,9 @@
% compute kernel average misorientation
kam = sparse(Dl(ind),Dr(ind),omega(ind)+0.00001,length(ebsd),length(ebsd));
kam = kam+kam';
kam = reshape(full(sum(kam,2)./sum(kam>0,2)),size(ebsd));

if check_option(varargin,'max')
kam = reshape(full(max(kam,2)),size(ebsd));
else
kam = reshape(full(sum(kam,2)./sum(kam>0,2)),size(ebsd));
end
8 changes: 4 additions & 4 deletions EBSDAnalysis/@EBSD/calcGrains.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function [grains,grainId,mis2mean] = calcGrains(ebsd,varargin)
% 2d and 3d construction of GrainSets from spatially indexed EBSD data
% grains reconstruction from 2d EBSD data
%
% Syntax
% grains = calcGrains(ebsd,'angle',10*degree)
Expand All @@ -9,7 +9,7 @@
% ebsd - @EBSD
%
% Output
% grains - @Grain2d | @Grain3d
% grains - @grain2d
%
% Options
% threshold|angle - array of threshold angles per phase of mis/disorientation in radians
Expand All @@ -19,7 +19,7 @@
% unitcell - omit voronoi decomposition and treat a unitcell lattice
%
% See also
% GrainSet/GrainSet
%

% subdivide the domain into cells according to the measurement locations,
% i.e. by Voronoi teselation or unit cell
Expand Down Expand Up @@ -68,7 +68,7 @@
for k = 1:numel(doMeanCalc)

qind = subSet(q,d(grainRange(doMeanCalc(k))+1:grainRange(doMeanCalc(k)+1)));
mq = mean(qind);
mq = mean(qind,'robust');
meanRotation = setSubSet(meanRotation,doMeanCalc(k),mq);
GOS(doMeanCalc(k)) = mean(angle(mq,qind));

Expand Down
2 changes: 1 addition & 1 deletion EBSDAnalysis/@EBSD/findByLocation.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
% g = findByLocation(ebsd,p)
%
% See also
% EBSD/findByLocation GrainSet/findByOrientation
% EBSD/findByLocation grain2d/findByOrientation

if all(isfield(ebsd.prop,{'x','y','z'}))
x_D = [ebsd.prop.x,ebsd.prop.y,ebsd.prop.z];
Expand Down
4 changes: 2 additions & 2 deletions EBSDAnalysis/@EBSD/findByOrientation.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function ebsd = findByOrientation(ebsd,q0,epsilon)
% select grains by orientation
% select ebsd data by orientation
%
% Input
% ebsd - @EBSD
Expand All @@ -10,7 +10,7 @@
% ebsd - @EBSD
%
% See also
% EBSD/findByLocation GrainSet/findByOrientation
% EBSD/findByLocation grain2d/findByOrientation

ind = find(ebsd.orientations,q0,epsilon);

Expand Down
7 changes: 7 additions & 0 deletions EBSDAnalysis/@EBSD/private/gbc_custom.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function criterion = gbc_custom(ori,CS,Dl,Dr,varargin)
% blue print for a self defined grain boundary criterion

% check whether the two ebsd measurements are seperated by a grain boundary
custom = get_option(varargin,'custom');
delta = get_option(varargin,'delta');
criterion = abs(custom(Dl)-custom(Dr)) < delta;
4 changes: 2 additions & 2 deletions EBSDAnalysis/@EBSD/private/plotUnitCells.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
obj.FaceVertexCData = reshape(d,size(xy,1),[]);
%if size(d,2) == 3, set(get(ax,'parent'),'renderer','opengl');end

if check_option(varargin,{'transparent','translucent'})
if check_option(varargin,{'transparent','translucent','faceAlpha'})

s = get_option(varargin,{'transparent','translucent'},1,'double');
s = get_option(varargin,{'transparent','translucent','faceAlpha'},1,'double');

if size(d,2) == 3 % rgb
obj.FaceVertexAlphaData = s.*(1-min(d,[],2));
Expand Down
2 changes: 2 additions & 0 deletions EBSDAnalysis/@EBSD/subsasgn.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
ebsd.id = subsasgn(ebsd.id,s(1),[]);
ebsd.phaseId = subsasgn(ebsd.phaseId,s(1),[]);

ebsd = EBSD(ebsd)

elseif ischar(b)

phId = find(strcmpi(b,ebsd.mineralList),1);
Expand Down
2 changes: 1 addition & 1 deletion EBSDAnalysis/@EBSDsquare/calcGND.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function gnd = calcGND(ebsd,varargin)
function [gnd,rho] = calcGND(ebsd,varargin)
% compute the geometrically necessary dislocation
%
% Formulae are taken from the paper:
Expand Down
4 changes: 2 additions & 2 deletions EBSDAnalysis/@grain2d/cat.m
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
function grains = cat(dim,varargin)
% concatenation of grains from the same GrainSet
% implements [grain1, grain2]
%
% Syntax
% g = [grains_1, grains_2, grains_n]
% g = [grains('fe') grains('mg')]
% g = [grains(1:100) grains(500:end)]
%
% See also
% GrainSet/vertcat
% grain2d/vertcat

grains = cat@dynProp(1,varargin{:});

Expand Down
2 changes: 1 addition & 1 deletion EBSDAnalysis/@grain2d/findByLocation.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
% hold on, plot(grains(id).boundary,'linecolor','r','lineWidth',2), hold off
%
% See also
% EBSD/findByLocation GrainSet/findByOrientation
% EBSD/findByLocation grain2d/findByOrientation

poly = grains.poly;

Expand Down
6 changes: 3 additions & 3 deletions EBSDAnalysis/@grain2d/findByOrientation.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
% g = findByOrientation(grains,ori,epsilon);
%
% Input
% grains - @GrainSet
% grains - @grain2d
% q0 - @quaternion | @rotation | @orientation
% epsilon - searching radius
%
% Output
% grains - @GrainSet
% grains - @grain2d
%
% See also
% EBSD/findByLocation GrainSet/findByOrientation
% EBSD/findByLocation grain2d/findByOrientation

ind = find(grains.meanOrientation,q0,epsilon);

Expand Down
2 changes: 1 addition & 1 deletion EBSDAnalysis/@grain2d/neighbors.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
% returns the number of neighboring grains
%
% Input
% grains - @GrainSet
% grains - @grain2d
%
% Output
% counts - number of neighbors per grain
Expand Down
4 changes: 2 additions & 2 deletions EBSDAnalysis/@grain2d/plot.m
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@
obj.Faces(k,1:s(k)) = Faces( cs(k)+1:cs(k+1) );
end

if check_option(varargin,{'transparent','translucent'})
s = get_option(varargin,{'transparent','translucent'},1,'double');
if check_option(varargin,{'transparent','translucent','FaceAlpha'})
s = get_option(varargin,{'transparent','translucent','FaceAlpha'},1,'double');
dg = obj.FaceVertexCData;
if size(d,2) == 3 % rgb
obj.FaceVertexAlphaData = s.*(1-min(dg,[],2));
Expand Down
4 changes: 2 additions & 2 deletions EBSDAnalysis/@grain2d/subSet.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
%
%
% Input
% grains - @grainSet
% grains - @grain2d
% ind -
%
% Ouput
% grains - @grainSet
% grains - @grain2d
%

% restrict boundary
Expand Down
14 changes: 9 additions & 5 deletions EBSDAnalysis/@grain2d/subsref.m
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
function varargout = subsref(grains,s)
% access subsets of a GrainSet
% implements grains(1:3)
%
% Syntax
% grains(1:10) % the 10 first grains of a GrainSet
% grains('Fe') % only Fe grains
% grains(1:10) % the 10 first grains
% grains('Fe') % only Fe grains
% grains( ~grains('fe') ) % all grains but Fe
% logical array with size of the complete
% GrainSet
% grains(cond)
%
% Input
% grains - @grain2d
% cond - logical array with same size as grains
%

if strcmp(s(1).type,'()')

Expand Down
3 changes: 2 additions & 1 deletion EBSDAnalysis/@grain2d/text.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

xy = grains.centroid;

h = optiondraw(text(xy(:,1),xy(:,2),txt),varargin{:});
h = optiondraw(text(xy(:,1),xy(:,2),txt,...
'HorizontalAlignment','center','VerticalAlignment','middle'),varargin{:});

if nargout == 0, clear h; end

Expand Down
4 changes: 2 additions & 2 deletions EBSDAnalysis/@grainBoundary/grainBoundary.m
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@
gB.misrotation(isNotBoundary) = ...
inv(ebsd.rotations(gB.ebsdId(isNotBoundary,2))) ...
.* ebsd.rotations(gB.ebsdId(isNotBoundary,1));

% compute triple points
gB.triplePoints = gB.calcTriplePoints(grainsPhaseId);
gB.triplePoints = gB.calcTriplePoints(grainsPhaseId);

end

Expand Down
122 changes: 109 additions & 13 deletions EBSDAnalysis/@grainBoundary/plot.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,118 @@
% linecolor
%


% create a new plot
[mtexFig,isNew] = newMtexFigure(varargin{:});
mP = newMapPlot('scanUnit',gB.scanUnit,'parent',mtexFig.gca,varargin{:});

if get_option(varargin,'linewidth',0) > 3 || check_option(varargin,'smooth')
plotOrdered(gB,varargin{:});
else
plotSimple(gB,varargin{:});
end

% if no DisplayName is set remove patch from legend
if ~check_option(varargin,'DisplayName')
set(get(get(h,'Annotation'),'LegendInformation'),'IconDisplayStyle','off');
else
legend('-DynamicLegend','location','NorthEast');
end

try axis(mP.ax,'tight'); end
mP.micronBar.setOnTop

if nargout == 0, clear h; end
if isNew, mtexFig.drawNow('figSize',getMTEXpref('figSize'),varargin{:}); end
mtexFig.keepAspectRatio = false;

function plotOrdered(gB,varargin)

% add a nan vertex at the end - patch should not close the faces
V = [gB.V;nan(1,2)];

% extract the edges
F = gB.F;

% detect where the edges are not consistent
breaks = F(2:end,1) ~= F(1:end-1,2);

% generate a new list of edges
% which has a nan pointer at every point of inconsistency
% first a full list of nan pointers
FF = size(V,1) * ones(size(F,1) + sum(breaks),2);

% insert the edges at the right positions
newpos = (1:length(breaks)+1).' + cumsum([0;breaks]);
FF(newpos,:) = F;

% remove duplicated
F = reshape(FF.',[],1);
dF = [true;diff(F)~=0];
F = F(dF);

% extract x and y values
x = V(F,1).';
y = V(F,2).';

% color given by second argument
if nargin > 1 && isnumeric(varargin{1}) && ...
(size(varargin{1},1) == length(gB) || size(varargin{1},2) == length(gB))

if size(varargin{1},1) ~= length(gB), varargin{1} = varargin{1}.'; end
data = reshape(varargin{1},length(gB),[]);

alpha = 0.01;

% for colorizing the segments with different colors we have to make a lot
% of efford
% 1. colors are asigned to vertices in Matlab not to edges
% 2. therefore we replace every vertex by two vertices
x = repelem(x,1,2);
x(1) = []; x(end)=[];
xx = x;
x(2:2:end-1) = (1-alpha)*xx(2:2:end-1) + alpha*xx(1:2:end-2);
x(3:2:end-1) = (1-alpha)*xx(3:2:end-1) + alpha*xx(4:2:end);
x(end+1) = NaN;

y = repelem(y,1,2);
y(1) = []; y(end)=[];
yy = y;
y(2:2:end-1) = (1-alpha)*yy(2:2:end-1) + alpha*yy(1:2:end-2);
y(3:2:end-1) = (1-alpha)*yy(3:2:end-1) + alpha*yy(4:2:end);
y(end+1) = NaN;

% align the data
data = repelem(data,2,1);
color = nan(length(y),size(data,2));
color(~isnan(y),:) = data;

% plot the line
p = patch('XData',x(:),'YData',y(:),'FaceVertexCData',color,...
'faceColor','none','hitTest','off','parent',...
mP.ax,'EdgeColor','interp');

% this makes the line connectors more nice
try
pause(0.01)
e = p.Edge;
e.LineJoin = 'round';
end

else % color given directly

color = get_option(varargin,{'linecolor','edgecolor','facecolor'},'k');

%p = patch(x,y,'r','faceColor','none','hitTest','off','parent',mP.ax,'EdgeColor',color);
p = line(x,y,'hitTest','off','parent',mP.ax,'color',color,'lineJoin','round');

end

h = optiondraw(p,varargin{:});

end


function plotSimple(gB,varargin)
obj.Faces = gB.F;
obj.Vertices = gB.V;
obj.parent = mP.ax;
Expand Down Expand Up @@ -52,17 +159,6 @@

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

% if no DisplayName is set remove patch from legend
if ~check_option(varargin,'DisplayName')
set(get(get(h,'Annotation'),'LegendInformation'),'IconDisplayStyle','off');
else
legend('-DynamicLegend','location','NorthEast');
end


try axis(mP.ax,'tight'); end
mP.micronBar.setOnTop

if nargout == 0, clear h; end
if isNew, mtexFig.drawNow('figSize',getMTEXpref('figSize'),varargin{:}); end
mtexFig.keepAspectRatio = false;
end
Loading

0 comments on commit b20516b

Please sign in to comment.