Skip to content

Commit 66825be

Browse files
committed
* added helper function to use temporary directory
* temorary directory used for dicom export and reimport * removed GUI elements from folder scanning
1 parent fe02bb8 commit 66825be

File tree

4 files changed

+64
-17
lines changed

4 files changed

+64
-17
lines changed

matRad/dicom/@matRad_DicomImporter/matRad_DicomImporter.m

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,10 @@
7070
matRad_cfg.dispError('The DICOM export requires the octave-forge package "dicom"!\n');
7171
end
7272
end
73-
disp(pathToFolder)
74-
if isempty(pathToFolder)
75-
obj.patDir = uigetdir(pwd);
76-
end
77-
78-
obj = matRad_scanDicomImportFolder(obj);
73+
74+
obj.patDir = pathToFolder;
75+
76+
obj.matRad_scanDicomImportFolder();
7977

8078
% matRad_DicomImporter imports only one structure, to select
8179
% patients and structures within a single patient the

matRad/dicom/@matRad_DicomImporter/matRad_scanDicomImportFolder.m

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@
211211
numOfFiles = numel(obj.allfiles(:,1));
212212

213213
if numel(Thickness) > 1
214-
msgbox('Slices are not equidistant! CT will be interpolate with the lowest value of resolution is given by CT slices.', 'Warning');
214+
matRad_cfg.dispWarning('Slices are not equidistant! CT will be interpolate with the lowest value of resolution is given by CT slices.');
215215
Thickness = Thickness(1); % min thickness
216216
ThBool = []; % in this case we will also create ct cube with the same resolution for all slices
217217
PriorThicknesses = flip(rmmissing(diff(FiltredLocArray))); % prior values of spacing, which are needed for interpolation
@@ -241,16 +241,15 @@
241241
obj.patient = unique(obj.allfiles(:,3));
242242

243243
if isempty(obj.patient)
244-
msgbox('No patient found with DICOM CT _and_ RT structure set in patient directory!', 'Error','error');
244+
matRad_cfg.dispError('No patient found with DICOM CT _and_ RT structure set in patient directory!');
245245
end
246246
else
247-
msgbox('No DICOM files found in patient directory!', 'Error','error');
247+
matRad_cfg.dispError('No DICOM files found in patient directory!');
248248
%h.WindowStyle = 'Modal';
249249
%error('No DICOM files found in patient directory');
250250
end
251251
else
252-
msgbox('Search folder empty!', 'Error','error');
253-
252+
matRad_cfg.dispError('Folder is empty!');
254253
end
255254

256255
clear warnDlgDICOMtagShown;

test/importTest/test_DicomImporter.m renamed to test/dicom/test_dicomIO.m

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function test_suite = test_DicomImporter
1+
function test_suite = test_dicomIO
22
%The output should always be test_suite, and the function name the same as
33
%your file name
44

@@ -26,14 +26,33 @@
2626
% assertExceptionThrown(f,id) - test if exception of id is thrown. Take care of Octave issues with exception id (or don't provide id)
2727
% Check MOxUnit for more information or look at other tests
2828

29-
function test_DicomImporter_classattachment
30-
path = 'C:\Users\r114m\Documents\GitHub\matRad\userdata\dicomExport\HEAD_AND_NECK';
31-
h = matRad_DicomImporter(path);
32-
assertTrue(isa(h,'matRad_DicomImporter'));
29+
function test_DicomImporter_emptyfolder
30+
path = helper_temporaryFolder('dicomIOtest');
31+
assertExceptionThrown(@() matRad_DicomImporter(path));
32+
33+
function test_DicomExporter
34+
testpatient = load('photons_testData.mat');
35+
path = helper_temporaryFolder('dicomIOtest');
36+
37+
dummyResultGUI = struct('physicalDose',rand(testpatient.ct.cubeDim),'w',ones(sum([testpatient.stf.totalNumOfBixels]),1));
38+
for i = 1:numel(testpatient.stf)
39+
dummyResultGUI.(['physicalDose_beam' num2str(i)]) = rand(testpatient.ct.cubeDim);
40+
end
41+
dummyResultGUI.wUnsequenced = dummyResultGUI.w;
42+
43+
h = matRad_DicomExporter(testpatient.ct,testpatient.cst,testpatient.pln,testpatient.stf,dummyResultGUI);
44+
assertTrue(isa(h,'matRad_DicomExporter'));
3345
assertTrue(isa(h,'handle'));
3446

47+
h.dicomDir = path;
48+
h.matRad_exportDicom();
49+
50+
dircontents = dir([path filesep '*.dcm']);
51+
assertTrue(numel(dircontents) > 0)
52+
53+
3554
function test_DicomImporter_loadFiles
36-
path = 'C:\Users\r114m\Documents\GitHub\matRad\userdata\dicomExport\HEAD_AND_NECK';
55+
path = helper_temporaryFolder('dicomIOtest',false);
3756
h = matRad_DicomImporter(path);
3857
assertTrue(isequal(h.patDir, path));
3958
assertTrue(~isempty(h.allfiles));

test/helper_temporaryFolder.m

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
function [tmpPath,status] = helper_temporaryFolder(folderName,clearIfExists)
2+
%helper_temporaryFolder Creates a temporary folder for test data in the
3+
% users temporary systemdirectory.
4+
5+
if nargin < 2
6+
clearIfExists = true;
7+
end
8+
9+
tmpPath = fullfile(tempdir(),folderName);
10+
11+
if isfolder(tmpPath) && clearIfExists
12+
status = rmdir(tmpPath,'s');
13+
if status
14+
status = mkdir(tmpPath);
15+
else
16+
status = double(isfolder(tmpPath));
17+
end
18+
elseif ~isfolder(tmpPath)
19+
status = mkdir(tmpPath);
20+
else
21+
status = 1;
22+
end
23+
24+
if ~status
25+
tmpPath = pwd();
26+
warning('temporary directory invalid - using wokring directory!');
27+
end
28+
29+
30+
end
31+

0 commit comments

Comments
 (0)