📄 gui_setepsilon.m
字号:
function varargout = gui_SetEpsilon(varargin)
% GUI_SETEPSILON M-file for gui_SetEpsilon.fig
% GUI_SETEPSILON, by itself, creates a new GUI_SETEPSILON or raises the existing
% singleton*.
%
% H = GUI_SETEPSILON returns the handle to a new GUI_SETEPSILON or the handle to
% the existing singleton*.
%
% GUI_SETEPSILON('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI_SETEPSILON.M with the given input arguments.
%
% GUI_SETEPSILON('Property','Value',...) creates a new GUI_SETEPSILON or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before gui_SetEpsilon_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to gui_SetEpsilon_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Copyright 2002-2003 The MathWorks, Inc.
% Edit the above text to modify the response to help gui_SetEpsilon
% Last Modified by GUIDE v2.5 07-Jun-2006 11:48:42
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @gui_SetEpsilon_OpeningFcn, ...
'gui_OutputFcn', @gui_SetEpsilon_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before gui_SetEpsilon is made visible.
function gui_SetEpsilon_OpeningFcn(hObject, eventdata, handles, varargin)
global LineLen
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to gui_SetEpsilon (see VARARGIN)
% Update handles structure
handles.oGd = varargin{2};
axes(handles.axes1);
draw_geom(handles.oGd);
ax = axis;
nPointsX = 500;
nPointsY = nPointsX*(ax(4)-ax(3))/(ax(2)-ax(1));
x = linspace(ax(1), ax(2), nPointsX);
y = linspace(ax(3), ax(4), nPointsY);
handles.x = x;
handles.y = y;
[mX, mY] = meshgrid(x,y);
mB1 = logical(ones(size(mX)));
oGd = handles.oGd;
s = [];
LineLen = 55;
h = waitbar(0, 'Finding sub-domains in image...', 'name', 'SMTgui', ...
'windowstyle', 'modal');
for iSd = 1:oGd.nSd
waitbar(iSd/oGd.nSd, h);
if ~isfield(oGd.sdArray(iSd), 'Er')
oGd.sdArray(iSd).Er = 1;
end
epsilon = oGd.sdArray(iSd).Er;
if isempty(epsilon)
oGd.sdArray(iSd).Er = 1;
epsilon = 1;
end
if ~ischar(epsilon(1))
epsilon = num2str(epsilon);
end
s_line = [num2str(iSd) 32*ones(1,27-2*length(num2str(iSd))) epsilon];
s_line = [s_line 32*ones(1, LineLen-length(s_line))];
if length(s_line) > LineLen
s_line = s_line(1:LineLen);
end
s = strvcat(s, s_line);
if iSd == 1
continue;
end
sd = oGd.sdArray(iSd);
mB = in_subdomain(mX, mY, sd);
mB1 = mB1 & ~mB;
handles.mB(iSd,:,:) = mB;
end
delete(h)
handles.mB(1,:,:) = mB1;
set(handles.uiList, 'string', s);
handles.oGd = oGd;
handles.output = hObject;
guidata(hObject, handles);
uiList_Callback(handles.uiList, eventdata, handles)
%if handles.s == -1
% uiCanle
%end
% UIWAIT makes gui_SetEpsilon wait for user response (see UIRESUME)
uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = gui_SetEpsilon_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
delete(handles.figure1);
% --- Executes on selection change in uiList.
function uiList_Callback(hObject, eventdata, handles)
% hObject handle to uiList (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns uiList contents as cell array
% contents{get(hObject,'Value')} returns selected item from uiList
axes(handles.axes1)
map = [1 1 1; 0.75 0.75 0.75];
vSd = get(hObject,'Value');
bMixed = 0;
mB = zeros(size(shiftdim(handles.mB(1,:,:))));
prevEpsilon = num2str(handles.oGd.sdArray(vSd(1)).Er);
for ivSd = 1:length(vSd)
iSd = vSd(ivSd);
epsilon = handles.oGd.sdArray(iSd).Er;
if ~ischar(epsilon(1))
epsilon = num2str(epsilon);
end
bMixed = bMixed | ~strcmp(epsilon, prevEpsilon);
prevEpsilon = epsilon;
set(handles.uiEpsilon, 'string', epsilon);
mB = mB | shiftdim(handles.mB(iSd,:,:));
end
if bMixed
set(handles.uiEpsilon, 'string', 'Mixed');
end
image(handles.x, handles.y, mB)
colormap(map)
draw_geom(handles.oGd, 'noaxischange')
% --- Executes during object creation, after setting all properties.
function uiList_CreateFcn(hObject, eventdata, handles)
% hObject handle to uiList (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function uiEpsilon_Callback(hObject, eventdata, handles)
global LineLen
% hObject handle to uiEpsilon (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of uiEpsilon as text
% str2double(get(hObject,'String')) returns contents of uiEpsilon as a double
epsilon = get(hObject,'String');
if strcmp(epsilon, 'Mixed')
return
end
epsilon_num = str2double(epsilon);
vSd = get(handles.uiList, 'value');
s = get(handles.uiList, 'string');
for ivSd = 1:length(vSd)
iSd = vSd(ivSd);
s_line = [num2str(iSd) 32*ones(1,27-2*length(num2str(iSd))) epsilon];
s_line = [s_line 32*ones(1, LineLen-length(s_line))];
if length(s_line) > LineLen
s_line = s_line(1:LineLen);
end
s(iSd, :) = s_line;
if isnan(epsilon_num)
handles.oGd.sdArray(iSd).Er = epsilon;
else
handles.oGd.sdArray(iSd).Er = epsilon_num;
end
end
set(handles.uiList, 'string', s);
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function uiEpsilon_CreateFcn(hObject, eventdata, handles)
% hObject handle to uiEpsilon (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on mouse press over figure background, over a disabled or
% --- inactive control, or over an axes background.
function figure1_WindowButtonDownFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
cp = get(handles.figure1, 'currentpoint');
ax = get(handles.axes1, 'position');
if ~((cp(1) > ax(1)) & (cp(1) < ax(1) + ax(3)) &...
(cp(2) > ax(2)) & (cp(2) < ax(2) + ax(4)))
return
end
cp = get(handles.axes1, 'currentpoint');
x0 = cp(1,1);
y0 = cp(1,2);
iX = nearest_ind(handles.x, x0);
iY = nearest_ind(handles.y, y0);
mB = handles.mB(:, iY, iX);
iSd = find(mB);
set(handles.uiList, 'Value', iSd);
uiList_Callback(handles.uiList, eventdata, handles)
function uiCancel_Callback(hObject, eventdata, handles)
% hObject handle to cancel (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.status = -1;
guidata(hObject, handles);
handles.output = guidata(gcbo);
% Update handles structure
guidata(hObject, handles);
% Use UIRESUME instead of delete because the OutputFcn needs
% to get the updated handles structure.
uiresume(handles.figure1);
function uiOk_Callback(hObject, eventdata, handles)
% hObject handle to cancel (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.status = 0;
guidata(hObject, handles);
handles.output = guidata(gcbo);
% Update handles structure
guidata(hObject, handles);
% Use UIRESUME instead of delete because the OutputFcn needs
% to get the updated handles structure.
uiresume(handles.figure1);
% --- Executes when user attempts to close figure1.
function figure1_CloseRequestFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: delete(hObject) closes the figure
uiCancel_Callback(handles.uiCancel, eventdata, handles)
% --- Executes on key press over figure1 with no controls selected.
function figure1_KeyPressFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
key = double(get(hObject, 'CurrentCharacter'));
val = get(handles.uiList, 'value');
if key == 30
if val(1) > 1
val = val(1) - 1;
set(handles.uiList, 'value', val)
uiList_Callback(handles.uiList, eventdata, handles)
end
end
items = size(get(handles.uiList, 'string'), 1);
if key == 31
if val(1) < items
val = val(1) + 1;
set(handles.uiList, 'value', val)
uiList_Callback(handles.uiList, eventdata, handles)
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -