Problem with uiwait; broken by impoly / imroi / roipoly
조회 수: 5 (최근 30일)
이전 댓글 표시
I need a GUI where the user can draw several polygons in an image, and when he is done, the polygon vertices are saved.
So I created a GUI with guide, with an axes with the image, and two pushbuttons. I used 'uiwait' as proposed in guide at the end of the Opening Function. One button 'New' let's the user draw a polyon using 'impoly'. The other button 'OK' calls 'uiresume', so that the code jumps to the Output Function.
The problem is:
Apparently the 'imroi' functions like 'impoly' break 'uiwait' early, and as soon as the first polygon is closed, the Output Function is called. I found two other posts indicating this. The only answer they found was to use 'roipolyold'. But since it is supposed to be removed in future releases, and I'm otherwise quite happy with 'imploly', I would really like to find another solution. I tried avoiding 'uiwait' und using 'waitfor' instead, but it always closed the figure right after opening and then got stuck on 'waitfor'.
I will be happy about any clues or ideas as to how I could get around this. Thanks!
댓글 수: 0
답변 (4개)
Image Analyst
2014년 8월 28일
Store the results of each polygon (the vertex coordinates) in a global variable cell array. Each time you click the button and draw a polygon, by whatever method, add it to the cell array variable as a new cell.
댓글 수: 8
Image Analyst
2014년 9월 5일
I suggest you put lines in like this to every function to see when they get run:
fprintf('Now entering blahblahblah()...\n')
% code for blahblahblah()
fprintf('Now leaving blahblahblah()...\n')
You'll see the OutputFcn() gets run both on startup and shutdown. I usually have a button called btnExit, but you can call it OK if that's what you want. When the user clicks it, this is the code that runs to shutdown the GUI:
%=====================================================
% --- Executes on button press in btnExit.
function btnExit_Callback(hObject, eventdata, handles)
% hObject handle to btnExit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
try
fprintf(1, 'Just entered btnExit_Callback...\n');
fprintf('Saving settings and parameters...');
SaveUserSettings(handles, 1);
% Get rid of variables from the global workspace so that they aren't
% hanging around the next time we try to run this m-file.
clear global;
% Cause it to shutdown.
delete(handles.figMainWindow);
fprintf(1, 'Leaving btnExit_Callback.\n');
catch ME
errorMessage = sprintf('Error in function btnExit_Callback.\nError Message:\n%s', ME.message);
WarnUser(errorMessage);
end
SaveUserSettings() is a custom written routine where I save the state of all controls on the GUI (checkbox states, scroll bar values, etc.). WarnUser is simply this:
%======================================================
% Warn user via the command window and a popup message.
function WarnUser(warningMessage)
fprintf(1, '%s\n', warningMessage);
uiwait(warndlg(warningMessage));
return; % from WarnUser()
Jan
2014년 10월 19일
I recently experienced a very similar problem: The callback function of a button drawed several ROIs from memory using imellipse . Thereafter, a uiwait(f) was called for the user to corrigate these ROIs. However, this uiwait(f) did not work.
Solution: call uiwait twice, like you did. Alternatively, You can call pause(0.001) before calling uiwait (once).
I did not got to the root of this problem, but this worked for me. Apperently there are indeed some problems when combining imroi functions and uiwait.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!