-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSBXGui_osx.m
184 lines (165 loc) · 5.98 KB
/
SBXGui_osx.m
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
function varargout = SBXGui_osx(varargin)
% SBXGUI_OSX Provides a simple gui to select and download dicom images from a
% slicebox server. Works best using OSX.
% [I, dcminfo] = SBXGUI_OSX(username, password) Launches the gui, which
% provides a simple way to select and download dicom files from a
% slicebox server. If no sbxsettings.conf exists, the options'url', and
% 'cachepath' must also be specified.
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @SBXGui_osx_OpeningFcn, ...
'gui_OutputFcn', @SBXGui_osx_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 SBXGui_osx is made visible.
function SBXGui_osx_OpeningFcn(hObject, eventdata, handles, varargin)
% Create the sbxdata object and fetch the flattened database image.
sbxdata = makesbxdata(varargin{:});
flatseries = sbxgetflatseries(sbxdata);
patients = [];
idlist = [];
for i = 2:length(flatseries)
if ~any(idlist==flatseries(i).patient.id)
patient = flatseries(i).patient;
patient.numberOfSeries = 1;
patients = [patients, patient];
idlist = [idlist, flatseries(i).patient.id];
else
j = find(idlist == flatseries(i).patient.id);
patients(j).numberOfSeries = patients(j).numberOfSeries + 1;
end
end
handles.sbxdata = sbxdata;
handles.patients = patients;
handles.flatseries = flatseries;
handles.isBusy = false;
handles.closeReason = 1;
patientTable = handles.patientTable;
data = cell(length(patients), 4);
for i = 1:length(patients);
data(i,:) = {patients(i).id, patients(i).patientName.value,...
patients(i).patientID.value, patients(i).numberOfSeries};
end
set(patientTable, 'Data', data);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes SBXGui_osx wait for user response (see UIRESUME)
uiwait(handles.sbxgui);
% If a series has been selected, return the image and dicom info.
% Otherwise, return empty cells.
function varargout = SBXGui_osx_OutputFcn(hObject, eventdata, handles)
if(handles.closeReason == 0)
varargout{1} = handles.image;
varargout{2} = handles.dcminfo;
else
varargout{1} = {};
varargout{2} = {};
end
% The figure can be deleted now
delete(handles.sbxgui);
function patientTable_CellSelectionCallback(hObject, eventdata, handles)
% When a row in the patientTable is selected, populate the seriesTable with
% all the series which belong to that particular patient.
if handles.isBusy
return;
end
row = eventdata.Indices(1);
patientData = get(hObject, 'Data');
id = patientData{row,1};
seriesTable = handles.seriesTable;
series = [];
for i = 1:length(handles.flatseries)
if handles.flatseries(i).patient.id == id
series = [series handles.flatseries(i).series];
end
end
data = cell(length(series),5);
for i = 1:length(series)
data(i,:) = {series(i).id, series(i).studyId, series(i).seriesDate.value,...
series(i).seriesDescription.value, series(i).modality.value};
end
set(seriesTable, 'Data', data);
guidata(hObject,handles);
% --- Executes when selected cell(s) is changed in seriesTable.
function seriesTable_CellSelectionCallback(hObject, eventdata, handles)
% When clicking a cell (well, row really) in seriesTable, pull the
% imageinfo from slicebox. Also update the infobox. While working, disable
% all the buttons.
if(~isempty(eventdata.Indices))
row = eventdata.Indices(1);
seriesData = get(hObject,'Data');
seriesId = seriesData{row,1};
setBusy(true, handles);
seriesinfo = sbxgetimageinfo(seriesId, handles.sbxdata);
setBusy(false, handles);
handles.seriesinfo = seriesinfo;
infotext = handles.infotext;
textdata = sprintf('Number of Slices: %d\nType: %s',numel(seriesinfo),...
seriesinfo{1}.imageType.value);
set(infotext, 'String', textdata);
else
infotext = handles.infotext;
textdata = [];
set(infotext, 'String', textdata);
end
guidata(hObject,handles);
% --- Executes on button press in loadButton.
function loadButton_Callback(hObject, eventdata, handles)
% load the images in the series seleected in the seriesTable. Disable all
% buttons while files are being downloaded.
if(isfield(handles, 'seriesinfo'))
% add stuff from
% http://undocumentedmatlab.com/blog/animated-busy-spinning-icon here
setBusy(true, handles);
pause(.1);
[image, dcminfo] = sbxreadimages(handles.seriesinfo, handles.sbxdata);
setBusy(false, handles);
handles.image = image;
handles.dcminfo = dcminfo;
handles.closeReason = 0;
guidata(handles.sbxgui, handles);
close(handles.sbxgui);
else
error('You must select a series to load!');
end
function cancelButton_Callback(hObject, eventdata, handles)
handles.closeReason = 1;
guidata(handles.sbxgui, handles);
close(handles.sbxgui);
function sbxgui_CloseRequestFcn(hObject, eventdata, handles)
if isequal(get(hObject, 'waitstatus'), 'waiting')
% The GUI is still in UIWAIT, us UIRESUME
uiresume(hObject);
else
% The GUI is no longer waiting, just close it
delete(hObject);
% if(handles.closeReason == 1)
% ME = MException('SBX:gui:GuiCancelled', 'Selection of images aborted');
% throw(ME);
% end
end
function setBusy(busy, handles)
if busy
handles.isBusy = true;
set(handles.sbxgui, 'pointer', 'watch');
set(handles.loadButton, 'Enable', 'off');
set(handles.cancelButton, 'Enable', 'off');
guidata(handles.sbxgui, handles);
else
handles.isBusy = false;
set(handles.sbxgui, 'pointer', 'arrow');
set(handles.loadButton, 'Enable', 'on');
set(handles.cancelButton, 'Enable', 'on');
guidata(handles.sbxgui, handles);
end