-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_ConnectedGrains.m
More file actions
104 lines (94 loc) · 3.92 KB
/
Copy pathplot_ConnectedGrains.m
File metadata and controls
104 lines (94 loc) · 3.92 KB
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
function plot_ConnectedGrains(grainsVar, mergedGrains, connectedGrains, allNeighTwins, connComponents, varargin)
% Plotting ConnectedGrains and More
if ~isempty(varargin{1})
allTwinBoundaries = varargin{1};
end
imgSampPath = evalin('base', 'imgSampPath');
samp_name = evalin('base', 'samp_name');
methodName = evalin('base', 'methodName');
phaseName = evalin('base', 'phaseName');
if length(grainsVar.mineralList) > 1
grainsVar = grainsVar(phaseName);
end
figure;
plot(grainsVar, grainsVar.meanOrientation)
hold on
plot(grainsVar.boundary, 'linecolor', 'k', 'linewidth', 1)
plot(mergedGrains.boundary, 'linecolor', 'r', 'linewidth', 1.5, 'linestyle', '-', ...
'displayName', 'merged grains')
plot(connectedGrains.boundary, 'linecolor', 'k', 'linewidth', 2, 'linestyle', '-', ...
'displayName', 'connected grains')
hold off
export_fig(char(fullfile(imgSampPath, sprintf('%s_connCompGBs_%s.png', samp_name, methodName))), '-m2');
close
if ~isempty(allTwinBoundaries)
figure;
plot(grainsVar, grainsVar.meanOrientation)
hold on
plot(grainsVar.boundary, 'linecolor', 'k', 'linewidth', 1)
plot(allTwinBoundaries, allTwinBoundaries.prop.twinOrder, 'linewidth', 1.5)
hold on
plot(connectedGrains.boundary, 'linecolor', 'k', 'linewidth', 2, 'linestyle', '-') % ,'displayName', 'connected grains')
hold off
colormap(jet(6));
setColorRange([0.5 6.5])
mtexColorbar('title', 'twin order of twin boundaries');
export_fig(char(fullfile(imgSampPath, sprintf('%s_connCompGBs_wTBs_%s.png', samp_name, methodName))), '-m2');
close
end
numComponents = max(connComponents);
cmap = lines(numComponents);
componentColors = cmap(connComponents, :);
figure;
plot(grainsVar, componentColors)
hold on
plot(grainsVar.boundary, 'linecolor', 'k', 'linewidth', 1)
plot(connectedGrains.boundary, 'linecolor', 'w', 'linewidth', 2, 'linestyle', '-') %,'displayName', 'connected grains')
% title(sprintf('Connected Components (%d clusters)', numComponents))
hold off
export_fig(char(fullfile(imgSampPath, sprintf('%s_connComps_IDcolored_%s.png', samp_name, methodName))), '-m2');
close
% Plot connections within each component, colored by twin order
figure;
plot(grainsVar, grainsVar.meanOrientation)
hold on
plot(grainsVar.boundary, 'linewidth', 1)
hold on
plot(connectedGrains.boundary, 'linecolor', 'w', 'linewidth', 2, 'linestyle', '-')
for i = 1:length(allNeighTwins)
matrix = allNeighTwins{i};
if isempty(matrix) || size(matrix, 2) < 2
continue;
end
twinMask = matrix(:,2) ~= 0;
if ~any(twinMask)
continue;
end
neighbors = matrix(twinMask, 1);
orders = matrix(twinMask, 2);
centroid1 = grainsVar(i).centroid;
for j = 1:length(neighbors)
neighborId = neighbors(j);
twinOrder = orders(j);
if connComponents(i) == connComponents(neighborId)
centroid2 = grainsVar(neighborId).centroid;
cmap = jet(6);
if twinOrder >= 1 && twinOrder <= 6
edgeColor = cmap(twinOrder, :);
else
edgeColor = [0.5 0.5 0.5];
end
h = plot([centroid1(1), centroid2(1)], [centroid1(2), centroid2(2)], ...
'Color', edgeColor, 'LineWidth', 1.75);
h.Color(4) = 0.45; % Set alpha to 0.5 (50% opacity), adjust between 0-1
end
end
end
title('Twin Connections within Connected Components');
colormap(jet(6));
setColorRange([0.5 6.5])
mtexColorbar('title', 'twin order')
hold off
export_fig(char(fullfile(imgSampPath, sprintf('%s_connCompGBs_twinNetwork_%s.png', samp_name, methodName))), '-m2');
close
end