-
Notifications
You must be signed in to change notification settings - Fork 2
/
TriDFusion.m
420 lines (306 loc) · 14.8 KB
/
TriDFusion.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
function TriDFusion(varargin)
%function TriDFusion(varargin)
%Triple Dimention Fusion (3DF) Image Viewer main function.
%See TriDFuison.doc (or pdf) for more information about options.
%
% Note: Option settings must fit on one line and can contain at most one semicolon.
% -3d : Display 2D View using 3D engine.
% -b : Display 2D Border.
% -i : TriDFusion is integrated with DIDOM Database Browser.
% -fusion: Activate the fusion. *Requires 2 volumes.
% -mip : Activate the 3D MIP. *The order of activation of the MIP, vol, and iso dictates the emphasis of each feature of the 3D resulting image.
% -vol : Activate the 3D volume rendering. *The order of activation of the MIP, vol, and iso dictates the emphasis of each feature of the 3D resulting image.
% -iso : Activate the 3D iso surface. *The order of activation of the MIP, vol, and iso dictates the emphasis of each feature of the 3D resulting image.
% -w name: Execute a workflow.
% -r path: Set a destination path.
%
% Example:
% TriDFusion(); Open the graphical user interface.
% TriDFusion('path_to_dicom_series_folder'); Open the graphical user interface with a DICOM image.
% TriDFusion('path_to_dicom_series_folder_1', 'path_to_dicom_series_folder_2'); Open the graphical user interface with 2 DICOM images.
% TriDFusion('path_to_dicom_series_folder_1', 'path_to_dicom_series_folder_2', '-fusion'); Open the graphical user interface with 2 DICOM images and fuse them.
% TriDFusion('path_to_dicom_series_folder', '-mip'); Open the graphical user interface with a DICOM image and create a 3D MIP.
% TriDFusion('path_to_dicom_series_folder', '-iso'); Open the graphical user interface with a DICOM image and create a 3D iso surface model.
% TriDFusion('path_to_dicom_series_folder', '-vol'); Open the graphical user interface with a DICOM image and create a 3D volume rendering.
% TriDFusion('path_to_dicom_series_folder', '-mip', '-iso', '-vol'); Open the graphical user interface with a DICOM image and create a fusion of a 3D MIP, iso surface, and volume rendering. Any combination can be used.
% TriDFusion('path_to_dicom_series_folder', '-w', 'workflow_name'); Open the graphical user interface with a DICOM image and execute a workflow. Refer to processWorkflow.m for a list of available options. Refer to dicomViewer.m for workflows the default values.
%
%Author: Daniel Lafontaine, [email protected]
%
%Last specifications modified:
%
% Copyright 2020, Daniel Lafontaine, on behalf of the TriDFusion development team.
%
% This file is part of The Triple Dimention Fusion (TriDFusion).
%
% TriDFusion development has been led by: Daniel Lafontaine
%
% TriDFusion is distributed under the terms of the Lesser GNU Public License.
%
% This version of TriDFusion 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.
%
% TriDFusion 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 TriDFusion. If not, see <http://www.gnu.org/licenses/>.
viewerUIFigure('set', false); % Tested wih Matlab 2023b
viewerSUVtype('set', 'BW'); % Body Weight
initViewerGlobal();
% Set view defbault color
viewerAxesColor ('set', [0.149 0.149 0.149]);
viewerBackgroundColor('set', [0.16 0.18 0.20]);
viewerForegroundColor('set', [0.94 0.94 0.94]);
viewerHighlightColor ('set', [0.94 0.94 0.94]);
viewerShadowColor ('set', [0.94 0.94 0.94]);
viewerButtonPushedBackgroundColor('set', [0.53 0.63 0.40]);
viewerButtonPushedForegroundColor('set', [0.1 0.1 0.1]);
viewerColorbarIntensityMaxLineColor('set', [0.53 0.63 0.40]);
viewerColorbarIntensityMinLineColor('set', [0.53 0.63 0.40]);
viewerColorbarIntensityMaxTextColor('set', [0 0 0]);
viewerColorbarIntensityMinTextColor('set', [0 0 0]);
viewerFusionColorbarIntensityMaxLineColor('set', [0.53 0.63 0.40]);
viewerFusionColorbarIntensityMinLineColor('set', [0.53 0.63 0.40]);
viewerFusionColorbarIntensityMaxTextColor('set', [0 0 0]);
viewerFusionColorbarIntensityMinTextColor('set', [0 0 0]);
viewerCrossLinesColor('set', [0 1 1]);
viewerProgressBarLineColor('set', [0 1 1]);
arg3DEngine = false;
argBorder = false;
argInternal = false;
argFusion = false;
dOutputDirOffset = 0;
asRendererPriority = [];
sWorkflowName = [];
% varargin = replace(varargin, '"', '');
% varargin = replace(varargin, ']', '');
% varargin = replace(varargin, '[', '');
argLoop=1;
for k = 1 : length(varargin)
sSwitchAndArgument = char(varargin{k});
sSwitchAndArgument = replace(sSwitchAndArgument, '"', '');
sSwitchAndArgument = replace(sSwitchAndArgument, ']', '');
sSwitchAndArgument = replace(sSwitchAndArgument, '[', '');
switch lower(sSwitchAndArgument)
case '-r' % Output directory
if k+1 <= length(varargin)
if dOutputDirOffset == 0
sOutputPath = char(varargin{k+1});
sOutputPath = replace(sOutputPath, '"', '');
sOutputPath = replace(sOutputPath, ']', '');
sOutputPath = replace(sOutputPath, '[', '');
if sOutputPath(end) ~= '/' && ...
sOutputPath(end) ~= '\'
sOutputPath = [sOutputPath '/'];
end
dOutputDirOffset = k+1;
outputDir('set', sOutputPath);
end
end
case '-w' % Workflow name
if k+1 <= length(varargin)
sWorkflowName = char(varargin{k+1});
sWorkflowName = replace(sWorkflowName, '"', '');
sWorkflowName = replace(sWorkflowName, ']', '');
sWorkflowName = replace(sWorkflowName, '[', '');
end
case '-3d' % 2D display using 3D engine
arg3DEngine = true;
case '-b' % Show Border 2D
argBorder = true;
case '-i' % Viewer Integrate With DICOM DB Browser
argInternal = true;
case '-fusion' % Activate Fusion
argFusion = true;
case '-vol' % Activate 3D Volume Rendering
asRendererPriority{numel(asRendererPriority)+1} = 'vol';
case '-iso' % Activate 3D ISO Surface
asRendererPriority{numel(asRendererPriority)+1} = 'iso';
case '-mip' % Activate 3D MIP
asRendererPriority{numel(asRendererPriority)+1} = 'mip';
otherwise
if k ~= dOutputDirOffset % The output dir is set before
asMainDirArg{argLoop} = sSwitchAndArgument;
if asMainDirArg{argLoop}(end) ~= '/'
asMainDirArg{argLoop} = [asMainDirArg{argLoop} '/'];
end
argLoop = argLoop+1;
mainDir('set', asMainDirArg);
end
end
end
viewerTempDirectory('set', char([tempname '/']));
if exist(viewerTempDirectory('get'), 'dir')
rmdir(viewerTempDirectory('get'), 's');
end
mkdir(viewerTempDirectory('get'));
is3DEngine('set', arg3DEngine);
showBorder('set', argBorder );
seriesDescription ('set', ' ');
integrateToBrowser('set', argInternal);
cropValue('set', 0);
imageSegEditValue('set', 'lower', 0);
imageSegEditValue('set', 'upper', 0);
useCropEditValue('set', 'lower', false);
useCropEditValue('set', 'upper', false);
imageCropEditValue('set', 'lower', 0);
imageCropEditValue('set', 'upper', 1);
initViewerRootPath();
viewerSetFullScreenIcon();
aScreenSize = get(groot, 'Screensize');
xPosition = (aScreenSize(3) /2) - (620 /2);
yPosition = (aScreenSize(4) /2) - (330 /2);
if viewerUIFigure('get') == true
fiMainWindow = ...
uifigure('Name', 'TriDFusion (3DF) Image Viewer',...
'NumberTitle','off',...
'Position' ,[xPosition, ...
yPosition, ...
620, ...
330 ...
],...
'MenuBar' , 'none',...
'AutoResizeChildren', 'off', ...
'Toolbar' , 'none',...
'color' , 'black',...
'WindowStyle', 'normal',...
'SizeChangedFcn',@resizeFigureCallback...
);
else
fiMainWindow = ...
figure('Name', 'TriDFusion (3DF) Image Viewer',...
'NumberTitle','off',...
'Position' ,[xPosition, ...
yPosition, ...
620, ...
330 ...
],...
'MenuBar' , 'none',...
'AutoResizeChildren', 'off', ...
'Toolbar' , 'none',...
'color' , 'black',...
'SizeChangedFcn',@resizeFigureCallback...
);
end
if viewerUIFigure('get') == true
DnD_uifigure(fiMainWindow, @openDnDImagesCallback);
end
fiMainWindowPtr('set', fiMainWindow);
set(fiMainWindow, 'DefaultUipanelUnits', 'normalized');
%
% set(fiMainWindow, 'DefaultLineHitTest' , 'off');
% set(fiMainWindow, 'DefaultPatchHitTest', 'off');
% set(fiMainWindow, 'DefaultTextHitTest' , 'off');
% set(fiMainWindow, 'AutoResizeChildren', 'off');
% if viewerUIFigure('get') == true
% set(fiMainWindow, 'Renderer', 'opengl');
% set(fiMainWindow, 'GraphicsSmoothing', 'off');
% else
% set(fiMainWindow, 'Renderer', 'opengl');
% set(fiMainWindow, 'doublebuffer', 'on');
% end
setFigureDefaults(fiMainWindowPtr('get'));
iptPointerManager(fiMainWindowPtr('get'));
sRootPath = viewerRootPath('get');
if ~isempty(sRootPath)
javaFrame = get(fiMainWindowPtr('get'), 'JavaFrame');
if ~isempty(javaFrame)
javaFrame.setFigureIcon(javax.swing.ImageIcon(sprintf('%s/logo.png', sRootPath)));
end
end
%
%
% if argInternal == true
% sLogoPath = './TriDFusion/logo.png';
% else
% sLogoPath = './logo.png';
% end
%
% javaFrame = get(fiMainWindowPtr('get'), 'JavaFrame');
% javaFrame.setFigureIcon(javax.swing.ImageIcon(sLogoPath));
% movegui(fiMainWindowPtr('get'), 'center');
uiSplashWindow = ...
axes(fiMainWindowPtr('get'),...
'Units' , 'pixels',...
'HitTest' , 'off', ...
'position', [0 30 620 300]...
);
uiSplashWindow.Toolbar.Visible = 'off';
disableDefaultInteractivity(uiSplashWindow);
uiProgressWindow = ...
uipanel(fiMainWindowPtr('get'),...
'Units' , 'pixels',...
'position' , [0 0 620 30],...
'title' , 'Ready',...
'HitTest' , 'off', ...
'BackgroundColor', viewerBackgroundColor ('get'), ...
'ForegroundColor', viewerForegroundColor('get') ...
);
uiProgressWindowPtr('set', uiProgressWindow);
uiBar = uipanel(uiProgressWindow, 'Units', 'normalized');
set(uiBar, 'BackgroundColor', viewerBackgroundColor('get'));
set(uiBar, 'ForegroundColor', viewerForegroundColor('get'));
set(uiBar, 'Position', [0 0 1 1]);
uiBarPtr('set', uiBar);
% sRootPath = viewerRootPath('get');
if isempty(sRootPath)
imSplash = zeros([300 620 3]);
else
sSplashFile = sprintf('%sscreenDefault.png', sRootPath);
if exist(sSplashFile, 'file')
[imSplash, ~] = imread(sSplashFile);
else
imSplash = zeros([300 620 3]);
end
end
% imshow(imSplash, 'border', 'tight', 'Parent', uiSplashWindow);
% image(imSplash, 'Parent', uiSplashWindow);
imshow(imSplash,'border','tight','Parent', uiSplashWindow);
uiSplashWindow.Toolbar.Visible = 'off';
initTemplates();
delete(uiSplashWindow);
% aScreenSize = get(groot, 'Screensize');
% alPosition = get(fiMainWindowPtr('get'), 'Position');
% lMiddleX = alPosition(1) + (alPosition(3) /2);
% lMiddleY = alPosition(2) + (alPosition(4) /2);
set(fiMainWindowPtr('get'), 'Position', aScreenSize);
set(uiProgressWindowPtr('get'), 'Position', [0, 0, aScreenSize(3), 30]);
set(uiBarPtr('get'), 'Position', [0, 0, aScreenSize(3), 1]);
drawnow update;
% uiProgressWindow.Position = [0, 0, 1440, 30];
% movegui(fiMainWindowPtr('get'), 'center');
set(fiMainWindowPtr('get'), 'Resize' , 'on');
set(fiMainWindowPtr('get'), 'WindowState', 'maximized');
drawnow update;
% set(fiMainWindowPtr('get'), 'WindowState', 'maximized');
resizeViewer = dicomViewer();
setContours();
drawnow;
% refreshImages();
if argFusion == true % Init 2D Fusion
setFusionCallback();
end
for rr=1:numel(asRendererPriority)
if strcmpi(asRendererPriority{rr}, 'vol') % Init 3D Volume
set3DCallback();
end
if strcmpi(asRendererPriority{rr}, 'iso') % Init 3D ISO
setIsoSurfaceCallback();
end
if strcmpi(asRendererPriority{rr}, 'mip') % Init 3D MIP
setMIPCallback();
end
end
if ~isempty(sWorkflowName)
processWorkflow(sWorkflowName);
end
function resizeFigureCallback(~,~)
if exist('resizeViewer', 'var')
resizeViewer();
end
end
end