-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdicomMultiFilesEditor.m
459 lines (394 loc) · 17.3 KB
/
dicomMultiFilesEditor.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
function dicomMultiFilesEditor(varargin)
%function dicomMultiFilesEditor(varargin)
%DICOM Multi-Files Editor.
%See dicomMultiFilesEditor.doc (or pdf) for more information about options.
%
%Note: option settings must fit on one line and can contain one semicolon at most.
%Options can be strings, cell arrays of strings, or numerical arrays.
%
%Author: Daniel Lafontaine, [email protected]
%
%Last specifications modified:
%
% Copyright 2020, Daniel Lafontaine, on behalf of the dicomMultiFilesEditor development team.
%
% This file is part of The DICOM Multi-Files Editor (dicomMultiFilesEditor).
%
% dicomMultiFilesEditor development has been led by: Daniel Lafontaine
%
% dicomMultiFilesEditor is distributed under the terms of the Lesser GNU Public License.
%
% This version of dicomMultiFilesEditor is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% dicomMultiFilesEditor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
% without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
% See the GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with dicomMultiFilesEditor. If not, see <http://www.gnu.org/licenses/>.
initEditorGlobal();
editorLbBackgroundColor('set', [0.149 0.149 0.149]);
editorLbForegroundColor('set', [0.98 0.98 0.98]);
editorBackgroundColor('set', [0.16 0.18 0.20]);
editorForegroundColor('set', [0.94 0.94 0.94]);
editorHighlightColor ('set', [0.94 0.94 0.94]);
editorShadowColor ('set', [0.94 0.94 0.94]);
editorButtonBackgroundColor('set', [0.53 0.63 0.40]);
editorButtonForegroundColor('set', [0.10 0.10 0.10]);
editorWriteTagLineColor('set', [1 0 0]);
dIsCommandLine = false;
argMainDirOrFileName = '';
argMultiFiles = true;
argSeriesUID = false;
argTragetDir = '';
argDicomDict = '';
argHeaderNumber = '';
argSortFiles = '';
argInternal = false;
dOutputDirOffset = 0;
% varargin = replace(varargin, '"', '');
% varargin = replace(varargin, ']', '');
% varargin = replace(varargin, '[', '');
for k=1:length(varargin)
sSwitchAndArgument = char(varargin{k});
sSwitchAndArgument = replace(sSwitchAndArgument, '"', '');
sSwitchAndArgument = replace(sSwitchAndArgument, ']', '');
sSwitchAndArgument = replace(sSwitchAndArgument, '[', '');
cSwitch = sSwitchAndArgument(1:2);
sArgument = sSwitchAndArgument(3:end);
switch cSwitch
case '-m'
argMultiFiles = true;
case '-u'
argSeriesUID = true;
case '-r'
if k+1 <= length(varargin)
if dOutputDirOffset == 0
sOutputPath = strtrim(char(varargin{k+1}));
if sOutputPath(end) ~= '/'
argTragetDir = [sOutputPath '/'];
dOutputDirOffset = k+1;
end
end
end
case '-d'
argDicomDict = strtrim(sArgument);
case '-h'
argHeaderNumber = strtrim(sArgument);
case '-l'
argSortFiles = strtrim(sArgument);
case '-i'
argInternal = true;
otherwise
if k ~= dOutputDirOffset % The output dir is set before
if ~(sSwitchAndArgument(end) == '\') || ...
~(sSwitchAndArgument(end) == '/')
argMainDirOrFileName = [strtrim(sSwitchAndArgument) '/'];
else
argMainDirOrFileName = strtrim(sSwitchAndArgument);
end
dIsCommandLine = true;
end
end
end
initEditorDcm4che3();
editorTargetDir ('set', argTragetDir );
editorCustomDict ('set', argDicomDict );
editorMultiFiles ('set', argMultiFiles );
editorAutoSeriesUID('set', argSeriesUID );
editorIntegrateToBrowser('set', argInternal);
if numel(argHeaderNumber)
editorSaveHeaderNumber('set', argHeaderNumber);
else
editorSaveHeaderNumber('set', '1');
end
if editorMultiFiles('get') == false
editorDicomFileName('set', argMainDirOrFileName);
editorMainDir('set', '');
else
editorDicomFileName('set', '');
editorMainDir('set', argMainDirOrFileName);
end
if ~numel(argDicomDict)
editorDefaultDict('set', true);
else
editorDefaultDict('set', false);
end
if ~numel(argTragetDir)
editorDefaultPath('set', true);
else
editorDefaultPath('set', false);
end
if ~numel(argHeaderNumber)
editorSaveAllHeader('set', true);
else
editorSaveAllHeader('set', false);
end
if ~numel(argSortFiles)
editorSortFiles('set', false);
else
editorSortFiles('set', true);
end
initEditorRootPath()
dicomdict('factory');
dScreenSize = get(groot, 'Screensize');
dMainWindowSizeX = dScreenSize(3);
dMainWindowSizeY = dScreenSize(4);
dPositionX = (dScreenSize(3) /2) - (dMainWindowSizeX /2);
dPositionY = (dScreenSize(4) /2) - (dMainWindowSizeY /2);
dlgWindows = ...
figure('Position', [dPositionX ...
dPositionY ...
dMainWindowSizeX ...
dMainWindowSizeY ...
],...
'Name' , 'DICOM Multi-Files Editor',...
'NumberTitle', 'off',...
'units' , 'normalized',...
'resize' , 'on',...
'MenuBar' , 'none',...
'Toolbar' , 'none',...
'Color' , editorBackgroundColor('get'), ...
'SizeChangedFcn',@editorResizeDialog...
);
dlgEditorWindowsPtr('set', dlgWindows);
dDlgPosition = get(dlgWindows, 'position');
dDialogSize = dScreenSize(4) * dDlgPosition(4);
yPosition = dDialogSize - 30;
xSize = dScreenSize(3) * dDlgPosition(3);
ySize = dDialogSize - 30;
sRootPath = editorRootPath('get');
if ~isempty(sRootPath)
javaFrame = get(dlgEditorWindowsPtr('get'), 'JavaFrame');
if ~isempty(javaFrame)
javaFrame.setFigureIcon(javax.swing.ImageIcon(sprintf('%s/logo.png', sRootPath)));
end
end
uiMainWindow = ...
uipanel(dlgWindows,...
'Units' , 'pixels',...
'position', [0 ...
30 ...
xSize ...
ySize-30 ...
],...
'BackgroundColor', editorBackgroundColor('get'), ...
'ForegroundColor', editorForegroundColor('get'), ...
'ShadowColor' , editorShadowColor('get'), ...
'HighlightColor' , editorHighlightColor('get'), ...
'title' , 'DICOM Source'...
);
uiEditorMainWindowPtr('set', uiMainWindow);
uiProgressWindow = ...
uipanel(dlgWindows,...
'Units' , 'pixels',...
'position', [0 ...
0 ...
xSize ...
30 ...
],...
'BackgroundColor', editorBackgroundColor ('get'), ...
'ForegroundColor', editorForegroundColor('get'), ...
'ShadowColor' , editorShadowColor('get'), ...
'HighlightColor' , editorHighlightColor('get'), ...
'title' , 'Ready'...
);
uiEditorProgressWindowPtr('set', uiProgressWindow);
lbFilesWindow = ...
uicontrol(uiMainWindow,...
'style' , 'listbox',...
'position', [0 ...
20 ...
250 ...
uiMainWindow.Position(4)-30-20 ...
],...
'fontsize', 10,...
'Fontname', 'Monospaced',...
'Value' , 1 ,...
'Selected', 'on',...
'enable' , 'on',...
'string' , ' ',...
'Callback', @lbEditorFilesWindowCallback...
);
lbEditorFilesWindowPtr('set', lbFilesWindow);
btnSortFiles = ...
uicontrol(uiMainWindow,...
'Position', [0 ...
0 ...
250 ...
20 ...
],...
'enable' , 'off',...
'String' , 'Sort',...
'BackgroundColor', editorBackgroundColor('get'), ...
'ForegroundColor', editorForegroundColor('get'), ...
'Callback', @editorSortFilesCallback...
);
btnEditorSortFilesPtr('set', btnSortFiles);
lbMainWindow = ...
uicontrol(uiMainWindow,...
'style' , 'listbox',...
'position', [250 ...
0 ...
uiMainWindow.Position(3)-250 ...
uiMainWindow.Position(4)-30 ...
],...
'fontsize', 10,...
'Fontname', 'Monospaced',...
'Value' , 1 ,...
'Selected', 'on',...
'enable' , 'on',...
'string' , ' ',...
'Callback', @lbEditorMainWindowCallback...
);
lbEditorMainWindowPtr('set', lbMainWindow);
btnOpen = ...
uicontrol(dlgWindows,...
'Position', [5 ...
yPosition ...
100 ...
25 ...
],...
'String' , 'Open',...
'BackgroundColor', editorBackgroundColor('get'), ...
'ForegroundColor', editorForegroundColor('get'), ...
'Callback', @editorSetSourceCallback...
);
btnEditorOpenPtr('set', btnOpen);
btnWriteHeader = ...
uicontrol(dlgWindows,...
'Position', [327 ...
yPosition ...
100 ...
25 ...
],...
'enable' , 'off',...
'String' , 'Write Tag',...
'BackgroundColor', editorBackgroundColor('get'), ...
'ForegroundColor', editorForegroundColor('get'), ...
'Callback', @editorWriteHeaderCallback...
);
btnEditorWriteHeaderPtr('set', btnWriteHeader);
btnOptions = ...
uicontrol(dlgWindows,...
'Position', [116 ...
yPosition ...
100 ...
25 ...
],...
'String' , 'Options',...
'BackgroundColor', editorBackgroundColor('get'), ...
'ForegroundColor', editorForegroundColor('get'), ...
'Callback', @setEditorOptionsCallback...
);
btnEditorOptionsPtr('set', btnOptions);
btnGenUID = ...
uicontrol(dlgWindows,...
'Position', [217 ...
yPosition ...
100 ...
25 ...
],...
'String' , 'Generate UID',...
'BackgroundColor', editorBackgroundColor('get'), ...
'ForegroundColor', editorForegroundColor('get'), ...
'Callback', @editorGenerateUIDCallback...
);
btnEditorGenUIDPtr('set', btnGenUID);
btnSaveHeader = ...
uicontrol(dlgWindows,...
'Position', [529 ...
yPosition ...
100 ...
25 ...
],...
'enable' , 'off',...
'String' , 'Save Header',...
'BackgroundColor', editorBackgroundColor('get'), ...
'ForegroundColor', editorForegroundColor('get'), ...
'Callback', @editorSaveDicomHeaderCallback...
);
btnEditorSaveHeaderPtr('set', btnSaveHeader);
btnResetHeader = ...
uicontrol(dlgWindows,...
'Position', [428 ...
yPosition ...
100 ...
25 ...
],...
'enable' , 'off',...
'String' , 'Reset Header',...
'BackgroundColor', editorBackgroundColor('get'), ...
'ForegroundColor', editorForegroundColor('get'), ...
'Callback', @editorResetHeaderCallback...
);
btnEditorResetHeaderPtr('set', btnResetHeader);
btnExportDicom = ...
uicontrol(dlgWindows,...
'Position', [630 ...
yPosition ...
100 ...
25 ...
],...
'enable' , 'off',...
'String' , 'Export Dicom',...
'BackgroundColor', editorBackgroundColor('get'), ...
'ForegroundColor', editorForegroundColor('get'), ...
'Callback', @editorExportDicomCallback...
);
btnEditorExportDicomPtr('set', btnExportDicom);
edtFindValue = ...
uicontrol(dlgWindows,...
'enable' , 'on',...
'style' , 'edit',...
'Background', 'white',...
'string' , '',...
'position' , [xSize-256 ...
yPosition+1 ...
200 ...
23 ...
],...
'BackgroundColor', editorBackgroundColor('get'), ...
'ForegroundColor', editorForegroundColor('get'), ...
'Callback' , @editorSearchTagCallback...
);
edtEditorFindValuePtr('set', edtFindValue);
btnSearchTag = ...
uicontrol(dlgWindows,...
'Position', [xSize-55 ...
yPosition ...
50 ...
25 ...
],...
'enable' , 'on',...
'String' , 'Find',...
'BackgroundColor', editorButtonBackgroundColor('get'), ...
'ForegroundColor', editorButtonForegroundColor('get'), ...
'Callback', @editorSearchTagCallback...
);
btnEditorSearchTagPtr('set', btnSearchTag);
editorMainWindowMenu();
dlgWindows.Resize = 'on';
dlgWindows.WindowState = 'maximized';
waitfor(dlgWindows, 'WindowState', 'maximized');
% warning('off','MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame');
% if argInternal == true
% sLogoPath = './dicomMultiFilesEditor/logo.png';
% else
% sLogoPath = './logo.png';
% end
% javaFrame = get(dlgWindows,'JavaFrame');
% javaFrame.setFigureIcon(javax.swing.ImageIcon(sLogoPath));
uiBar = uipanel(uiEditorProgressWindowPtr('get'));
set(uiBar, 'BackgroundColor', editorBackgroundColor('get'));
set(uiBar, 'ForegroundColor', editorForegroundColor('get'));
set(uiBar, 'ShadowColor' , editorBackgroundColor('get'));
set(uiBar, 'HighlightColor' , editorBackgroundColor('get'));
uiEditorProgressBarPtr('set', uiBar);
if dIsCommandLine == true
editorSetSource(true);
end
end