Skip to content

Commit caa10d7

Browse files
author
Usseglio-Viretta
committed
Updated Miscellaneous to v0.91
1 parent d56385f commit caa10d7

8 files changed

+1293
-6
lines changed

src/Miscellaneous/Function_Writetable.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
%% CREATE THE XLS FILE
3737
warning('off','MATLAB:xlswrite:AddSheet'); % Suppress warning when the requested worksheet does not exist and is created
38-
full_path_xls=[Current_folder filename '.xls']; % Path of the xls file
38+
full_path_xls=[Current_folder filename '.xls']; % Path of the xlsx file
3939
if exist(full_path_xls, 'file') % If the Excel file exits, it is deleted
4040
delete(full_path_xls);
4141
end

src/Miscellaneous/Function_probability_density.m

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,16 @@
9797
end
9898
if outcome_smoothing
9999
results.smoothed_cumulative_fct = [smoothed_x smoothed_y];
100-
results.smoothed_x50 = interp1(results.smoothed_cumulative_fct(:,2),results.smoothed_cumulative_fct(:,1),0.5);
100+
try
101+
results.smoothed_x50 = interp1(results.smoothed_cumulative_fct(:,2),results.smoothed_cumulative_fct(:,1),0.5);
102+
catch ME
103+
strcmp(ME.message,'Sample points must be unique and sorted in ascending order.')
104+
if strcmp(ME.message,'Sample points must be unique and sorted in ascending order.')
105+
idx = find( abs(results.smoothed_cumulative_fct(:,2)-0.5) == min(abs(results.smoothed_cumulative_fct(:,2)-0.5)) );
106+
results.smoothed_x50 = results.smoothed_cumulative_fct(idx(1),1);
107+
end
108+
end
109+
% results.smoothed_x50 = interp1(results.smoothed_cumulative_fct(:,2),results.smoothed_cumulative_fct(:,1),0.5);
101110
end
102111
end
103112

@@ -148,7 +157,17 @@
148157
cumulative_fct(current_value,2)=cumulative_fct(current_value+1,2)+pdi_(current_value,2);
149158
end
150159
% Find x50.
151-
x50 = interp1(cumulative_fct(:,2),cumulative_fct(:,1),0.5);
160+
try
161+
x50 = interp1(cumulative_fct(:,2),cumulative_fct(:,1),0.5);
162+
catch ME
163+
if strcmp(ME.message,'Sample points must be unique and sorted in ascending order.')
164+
idx = find( abs(cumulative_fct(:,2)-0.5) == min(abs(cumulative_fct(:,2)-0.5)) );
165+
x50 = cumulative_fct(idx(1),1);
166+
elseif strcmp(ME.message,'Interpolation requires at least two sample points for each grid dimension.')
167+
x50 = cumulative_fct(1,1);
168+
end
169+
end
170+
%x50 = interp1(cumulative_fct(:,2),cumulative_fct(:,1),0.5);
152171
end
153172

154173
function [probability_density_fct, integral_pdf] = function_calculate_probability_density_fct (x, cumulative_fct)
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
function [] = Microstructure_basic_visualization_interface(array, direction_name)
2+
3+
nargin; % Number of input variable when the function is call
4+
5+
if nargin == 1 % Set default name for the axis
6+
direction_name = {'Normal to axe 1','Normal to axe 2','Normal to axe 3'};
7+
end
8+
9+
10+
%% PARAMETERS
11+
font_name_GUI = 'Times new roman';
12+
font_size_GUI = 12;
13+
14+
% Default colormap
15+
color_phase_default = round(colororder*255);
16+
tmp=randi(255,10000,3);
17+
color_phase_default=[color_phase_default;tmp];
18+
color_phase_default=color_phase_default/255; % Normalized for Matlab
19+
choice_colormap = 'MATLAB default';
20+
21+
22+
%% PHASE INFORMATION
23+
Phase_code=unique(array); % Get phase code
24+
number_phase=length(Phase_code); % Get number of phase
25+
Domain_size = size(array);
26+
% Default Colors
27+
for current_phase=1:1:number_phase
28+
RGB_phase.index(current_phase).rgb = [color_phase_default(current_phase,1) color_phase_default(current_phase,2) color_phase_default(current_phase,3)];
29+
end
30+
31+
%% FIGURE
32+
Fig = figure; % Create figure
33+
Fig.Name= 'Visualize microstructure';
34+
Fig.Color='white'; % Background colour
35+
scrsz = get(0,'ScreenSize'); % Screen resolution
36+
set(Fig,'position',[scrsz(1) scrsz(2) scrsz(3)/2 scrsz(4)/2]); % Full screen figure
37+
% Figure for volume view
38+
axes_2dview = axes('Parent', Fig,'Visible','off','FontName',font_name_GUI,'Units','normalized','Position', [0 0.125 1 0.85]);
39+
% Remove tick and label
40+
set(axes_2dview,'xtick',[],'ytick',[]);
41+
set(axes_2dview,'xticklabel',[],'yticklabel',[]);
42+
% Box on
43+
box(axes_2dview,'on');
44+
% Fit the axes box
45+
axis(axes_2dview,'tight');
46+
% Aspect ratio is 1:1
47+
axis(axes_2dview,'equal');
48+
49+
% Slider
50+
Slider_axes_2dview = uicontrol('Parent', Fig,'Style', 'slider','Min',1,'Max',100,'Value',1,'Units','normalized','Position', [0.3 0.05 0.4 0.04],'Callback', @slider_axes2dview_Callback,...
51+
'Visible','on','enable','on');
52+
% Text (slider position)
53+
Text_slider = uicontrol('Parent', Fig,'Style', 'text','FontSize',font_size_GUI,'FontName',font_name_GUI,'String','Position: -/-','Visible','on','enable','on',...
54+
'BackgroundColor','w','HorizontalAlignment','left','Units','normalized','Position', [0.3 0.0 0.4 0.04]);
55+
% Popup menu (slider direction)
56+
Popup_slider = uicontrol('Parent', Fig,'Style', 'popup','FontSize',font_size_GUI,'FontName',font_name_GUI,...
57+
'String', direction_name,'Value',3,'Units','normalized','Position', [0.05 0.05 0.215 0.04],'enable','on','Visible','on','Callback', @popup_axes2dview_Callback);
58+
59+
direction = 3; pos_=1;
60+
set(Text_slider,'String',['Slice: ' num2str(pos_) '/' num2str(Domain_size(direction))]);
61+
minor_step = 1/(Domain_size(direction)-1);
62+
major_step = max([minor_step 0.1]);
63+
set(Slider_axes_2dview,'Min',1,'Max',Domain_size(direction),'SliderStep', [minor_step, major_step],'Value',1);
64+
65+
% Colormap
66+
Popup_colormap = uicontrol('Parent', Fig,'Style', 'popup','FontSize',font_size_GUI,'FontName',font_name_GUI,...
67+
'String', {'MATLAB default','gray','bone','copper','jet','parula','Random'},'Value',1,'Units','normalized','Position', [0.725 0.05 0.215 0.04],'enable','on','Visible','on','Callback', @popup_colormap_Callback);
68+
69+
% Slider
70+
function slider_axes2dview_Callback(source,~)
71+
% Get position value
72+
pos_=round(source.Value);
73+
direction = Popup_slider.Value;
74+
% Update text
75+
set(Text_slider,'String',['Slice: ' num2str(pos_) '/' num2str(Domain_size(direction))]);
76+
% Update position array
77+
% Position_slice(direction)=pos_;
78+
% Update figure
79+
update_figure
80+
end
81+
82+
% Select direction
83+
function popup_colormap_Callback(source,~)
84+
% Get colormap
85+
color_map = char(Popup_colormap.String(source.Value));
86+
if strcmp(color_map,'MATLAB default')
87+
for current_phase=1:1:number_phase
88+
RGB_phase.index(current_phase).rgb = [color_phase_default(current_phase,1) color_phase_default(current_phase,2) color_phase_default(current_phase,3)];
89+
end
90+
elseif strcmp(color_map,'Random')
91+
color_phase_random=randi(255,10000,3);
92+
color_phase_random=color_phase_random/255; % Normalized for Matlab
93+
for current_phase=1:1:number_phase
94+
RGB_phase.index(current_phase).rgb = [color_phase_random(current_phase,1) color_phase_random(current_phase,2) color_phase_random(current_phase,3)];
95+
end
96+
else
97+
custom_colormap = eval([color_map '(' num2str(number_phase) ')']);
98+
for current_phase=1:1:number_phase
99+
100+
RGB_phase.index(current_phase).rgb = [custom_colormap(current_phase,1) custom_colormap(current_phase,2) custom_colormap(current_phase,3)];
101+
end
102+
end
103+
% Update figure
104+
update_figure
105+
end
106+
107+
function popup_axes2dview_Callback(source,~)
108+
% Get direction
109+
direction=source.Value;
110+
% Set slider min, max
111+
minor_step = 1/(Domain_size(direction)-1);
112+
major_step = max([minor_step 0.1]);
113+
set(Slider_axes_2dview,'Min',1,'Max',Domain_size(direction),'SliderStep', [minor_step, major_step],'Value',1);
114+
% Update text
115+
set(Text_slider,'String',['Slice: ' num2str(1) '/' num2str(Domain_size(direction))]);
116+
% Update figure
117+
update_figure
118+
end
119+
120+
function update_figure
121+
direction = Popup_slider.Value;
122+
pos_ = round(Slider_axes_2dview.Value);
123+
Position_slice(direction)=pos_;
124+
if direction==1
125+
% Initializaion
126+
slice_color = zeros(Domain_size(2),Domain_size(3),3); % RGB color map
127+
slice_r = zeros(Domain_size(2),Domain_size(3)); % Red color map
128+
slice_g = zeros(Domain_size(2),Domain_size(3)); % Green color map
129+
slice_b = zeros(Domain_size(2),Domain_size(3)); % Blue color map
130+
% Attribute RGB colors for each voxel
131+
for current_phase=1:1:number_phase
132+
code_tmp =Phase_code(current_phase); % Current phase code
133+
slice_r(array(Position_slice(1),:,:)==code_tmp)= RGB_phase.index(current_phase).rgb(1); % Attribute red color
134+
slice_g(array(Position_slice(1),:,:)==code_tmp)= RGB_phase.index(current_phase).rgb(2); % Attribute green color
135+
slice_b(array(Position_slice(1),:,:)==code_tmp)= RGB_phase.index(current_phase).rgb(3); % Attribute blue color
136+
end
137+
elseif direction==2
138+
% Initializaion
139+
slice_color = zeros(Domain_size(1),Domain_size(3),3); % RGB color map
140+
slice_r = zeros(Domain_size(1),Domain_size(3)); % Red color map
141+
slice_g = zeros(Domain_size(1),Domain_size(3)); % Green color map
142+
slice_b = zeros(Domain_size(1),Domain_size(3)); % Blue color map
143+
% Attribute RGB colors for each voxel
144+
for current_phase=1:1:number_phase
145+
code_tmp =Phase_code(current_phase); % Current phase code
146+
slice_r(array(:,Position_slice(2),:)==code_tmp)= RGB_phase.index(current_phase).rgb(1); % Attribute red color
147+
slice_g(array(:,Position_slice(2),:)==code_tmp)= RGB_phase.index(current_phase).rgb(2); % Attribute green color
148+
slice_b(array(:,Position_slice(2),:)==code_tmp)= RGB_phase.index(current_phase).rgb(3); % Attribute blue color
149+
end
150+
elseif direction==3
151+
% Initializaion
152+
slice_color = zeros(Domain_size(1),Domain_size(2),3); % RGB color map
153+
slice_r = zeros(Domain_size(1),Domain_size(2)); % Red color map
154+
slice_g = zeros(Domain_size(1),Domain_size(2)); % Green color map
155+
slice_b = zeros(Domain_size(1),Domain_size(2)); % Blue color map
156+
% Attribute RGB colors for each voxel
157+
for current_phase=1:1:number_phase
158+
code_tmp =Phase_code(current_phase); % Current phase code
159+
slice_r(array(:,:,Position_slice(3))==code_tmp)= RGB_phase.index(current_phase).rgb(1); % Attribute red color
160+
slice_g(array(:,:,Position_slice(3))==code_tmp)= RGB_phase.index(current_phase).rgb(2); % Attribute green color
161+
slice_b(array(:,:,Position_slice(3))==code_tmp)= RGB_phase.index(current_phase).rgb(3); % Attribute blue color
162+
end
163+
end
164+
slice_color(:,:,1)=slice_r; % Attribute RGB color
165+
slice_color(:,:,2)=slice_g;
166+
slice_color(:,:,3)=slice_b;
167+
% Display the slice
168+
image(slice_color,'parent',axes_2dview);
169+
% Get axis position
170+
axe_position =axes_2dview.Position;
171+
set(axes_2dview ,'Position', axe_position);
172+
% Remove tick and label
173+
set(axes_2dview,'xtick',[],'ytick',[]);
174+
set(axes_2dview,'xticklabel',[],'yticklabel',[]);
175+
% Fit the axes box
176+
axis(axes_2dview,'tight');
177+
% Aspect ratio is 1:1
178+
axis(axes_2dview,'equal');
179+
end
180+
181+
% Initialize
182+
update_figure
183+
end
184+

0 commit comments

Comments
 (0)