Bladeren bron

Added Amira loading, implemented folder tracking in Geometry.

pferjancic 6 jaren geleden
bovenliggende
commit
abcfb5837e

+ 3 - 3
WiscPlanPhotonkV125/matlab_frontend/helicalDosecalcSetup7.m

@@ -20,10 +20,10 @@
 % Also edit: 
 % Kernel should always be named Kernels.mat 
 
-function helicalDosecalcSetup7(patient_dir)
+function num_batches = helicalDosecalcSetup7(patient_dir)
 % -- INPUT:
 % patient_dir: specify where kernel and [geometry] files are located
-num_batches = 2; % number of cores you want to run the beam calculation
+num_batches = 3; % number of cores you want to run the beam calculation
 
 iso = [0 0 0]; % Point about which gantry rotations begin
 SAD = 85;  % source-axis distance for the x-ray source ##
@@ -44,7 +44,7 @@ ypmax = 0.3125;
 % y-prime points in the z-direction in the CT coordinate system
 
 % Number of beamlets in the BEV for each direction
-Mxp = 64;  % Mxp = 64;  number of MLC leaves;
+Mxp = 32;  % Mxp = 64;  number of MLC leaves;
 Nyp = 1;  % always 1 for Tomo due to binary mlc
 
 

+ 12 - 10
WiscPlanPhotonkV125/matlab_frontend/lab/XTPS.m

@@ -52,8 +52,8 @@ classdef XTPS < handle
             obj.handles.hImportDicomRTMenu    = uimenu(obj.handles.hFileMenu, 'Label', '1. Import DicomRT Geometry');
 
             % ---- Grozomah: This part edited by Peter
-            obj.handles.hNRRD1                = uimenu(obj.handles.hFileMenu, 'Label', '1a. Import nrrd Geometry');
-            obj.handles.hNRRD2                = uimenu(obj.handles.hFileMenu, 'Label', '1b. Import nrrd Geometry 2');
+            obj.handles.hNRRD1                = uimenu(obj.handles.hFileMenu, 'Label', '1a. Geometry wizard (am/nrrd)');
+            obj.handles.hNRRD2                = uimenu(obj.handles.hFileMenu, 'Label', '1b. Add Geometry ROI');
             obj.handles.hImgPerturb           = uimenu(obj.handles.hFileMenu, 'Label', '1e. Implement image pertrubations');
             
             obj.handles.hDosecalcMenu         = uimenu(obj.handles.hFileMenu, 'Label', '2. Beamlet Dose Calculation');
@@ -420,19 +420,21 @@ classdef XTPS < handle
 %-------------------------------------------------------------------------------
 % Grozomah
         function NRRD1_Callback(obj, src, evt)
-            [obj.handles.hSVPS.Geometry obj.patient_dir] = nrrd2geometry();
+            [obj.handles.hSVPS.Geometry] = load2geometry();
             obj.load_geometry();
             
-            [obj.handles.hSVPS.Geometry] = nrrd2ROI(obj.handles.hSVPS.Geometry, obj.patient_dir);
+            [obj.handles.hSVPS.Geometry] = nrrd2ROI(obj.handles.hSVPS.Geometry);
             obj.load_geometry();
-            
-            
-            disp('NRRD geometry loaded!')
+
+            disp('New ROI loaded!')
         end
 %-------------------------------------------------------------------------------
 % Grozomah
         function NRRD2_Callback(obj, src, evt)
-            disp('NRRD2 called!')
+            [obj.handles.hSVPS.Geometry] = nrrd2ROI(obj.handles.hSVPS.Geometry);
+            obj.load_geometry();
+
+            disp('New ROI loaded!')
         end
         
 %-------------------------------------------------------------------------------
@@ -467,14 +469,14 @@ classdef XTPS < handle
 %             msgbox(sprintf('Start beamlet dose calculation.\nRun this if not started automatically:\n%s', cmdline));
 %             system(execline);
 
-            helicalDosecalcSetup7(obj.patient_dir)
+            obj.handles.hSVPS.Geometry.num_batches = helicalDosecalcSetup7(obj.handles.hSVPS.Geometry.patient_dir)
 
 
         end
         %-------------------------------------------------------------------------------
         % Grozomah
         function MergeBeamlets_Callback(obj, src, evt)
-            merge_beamlets(4, obj.patient_dir);
+            merge_beamlets(obj.handles.hSVPS.Geometry.num_batches, obj.handles.hSVPS.Geometry.patient_dir);
             disp('Beamlets merged!')
         end
         %-------------------------------------------------------------------------------

+ 37 - 35
WiscPlanPhotonkV125/matlab_frontend/nrrd2geometry.m → WiscPlanPhotonkV125/matlab_frontend/load2geometry.m

@@ -1,35 +1,37 @@
 
 
-function [Geometry patient_dir] = nrrd2geometry
+function [Geometry] = load2geometry
     
     %% -----===== Get CT files =====-----
-    [IMG_in, IMG_path, filterIdx] = uigetfile([{'*.nrrd'; '*.am'}], 'Select CT image', 'C:\Box Sync\Optimal Stopping\Data\CDP\CDP001\');
-    
-%     IMG_in = 'test_ct.nrrd';
-%     IMG_path = 'C:\010-work\003_localGit\WiscPlan_v2\PhantomData\';
+    Geometry.data_dir = uigetdir('C:\Box Sync\Optimal Stopping\Data\CDP', 'Select folder with patient data');
+    [IMG_in, IMG_path, filterIdx] = uigetfile([{'*.nrrd'; '*.am'}], 'Select CT image', Geometry.data_dir);
+%     'C:\Box Sync\Optimal Stopping\Data\CDP\CDP001\'
     
     total_num_steps = 4;
     hWaitbar = waitbar(0);
     
+    % --  geometry explained --
     % geometry_file important parts:
     % Geometry.ROIS - actually only to get the binary mask of the target
     % Geometry.data - CT image in HU
-    % Geometry.voxel_size - self explanatory
-    % Geometry.start - self explanatory
+    % Geometry.voxel_size - size of voxels in cm
+    % Geometry.start - image coordinate origin
     
     % these are derived from above:
     % +Geometry.rhomw - CT image with values in relative water density 
     % +Geometry.Smw - very similair to rhomw
     % +Geometry.Fmw2
-    % +Geometry.BTV
-    % +Geometry.ring
+    % +Geometry.BTV 
+    % +Geometry.ring - a ring around PTV used to pull down IMRT optimization
+    % --------------------------
     
     switch filterIdx
         case 0
-            warning('No file selected!')
+            warning('No file selected, aborting!')
+            return 
         case 1
             [Geometry.data, meta]=nrrdread([IMG_path, IMG_in]);
-%             warning('NRRD file loaded!')
+            disp('NRRD file loaded!')
             Geometry.rhomw = CT2dens(Geometry.data, 'pinn');
             Geometry.rhomw(Geometry.rhomw < 0.0012) = 0.0012;
             [Geometry.Smw Geometry.Fmw2] = dens2mstp(Geometry.rhomw);
@@ -38,7 +40,7 @@ function [Geometry patient_dir] = nrrd2geometry
         case 2
             imgIn=am2mat([IMG_path, IMG_in]);
             Geometry.data = permute(imgIn.data, [2,1,3]);
-%             warning('NRRD file loaded!')
+            disp('NRRD file loaded!')
             Geometry.rhomw = CT2dens(Geometry.data, 'pinn');
             Geometry.rhomw(Geometry.rhomw < 0.0012) = 0.0012;
             [Geometry.Smw Geometry.Fmw2] = dens2mstp(Geometry.rhomw);
@@ -47,6 +49,7 @@ function [Geometry patient_dir] = nrrd2geometry
             Geometry.start=imgIn.start;
         case 3
             % something selected
+            error('please do not select *all* in file selection')
         otherwise
 %             error('You should never see this.')
     end
@@ -55,23 +58,24 @@ function [Geometry patient_dir] = nrrd2geometry
     % Geometry.ROIS
     
     %% -----===== Get mask/contour files =====-----
-    [TRGT_in, TRGT_path, filterIdx2] = uigetfile([{'*.nrrd'; '*.am'}], 'Select file with Target', 'C:\Box Sync\Optimal Stopping\Data\CDP\CDP001\');
+    [TRGT_in, TRGT_path, filterIdx2] = uigetfile([{'*.nrrd'; '*.am'}], 'Select file with Target', Geometry.data_dir);
     
     switch filterIdx2
         case 0
             warning('No file selected!')
         case 1
             [TRGT_img, meta]=nrrdread([TRGT_path, TRGT_in]);
-            warning('NRRD file loaded!')
+            disp('NRRD file loaded!')
             Geometry.ROIS{1}.ind = find(TRGT_img>0);
             Geometry.ROIS{1}.name= 'Target';
         case 2
             TRGT_in=am2mat([TRGT_path, TRGT_in]);
-            warning('AM file loaded!')
+            disp('AM file loaded!')
             TRGT_img = permute(TRGT_in.data, [2,1,3]);
             Geometry.ROIS{1}.ind = find(TRGT_img>0);
             Geometry.ROIS{1}.name= 'Target';
         case 3
+            error('please do not select *all* in file selection')
             % something selected
         otherwise
 %             error('You should never see this.')
@@ -80,15 +84,17 @@ function [Geometry patient_dir] = nrrd2geometry
     
         %% -----===== Save geometry files =====-----
     patient_dir = uifile('getdir', 'Save the patient data to directory');
+    Geometry.patient_dir = patient_dir;
+    
 %     patient_dir = 'C:\010-work\003_localGit\WiscPlan_v2\data\PatientData\';
     
     % make directories
-    mkdir(patient_dir);
-    mkdir(fullfile(patient_dir, 'beamlet_batch_files'));
-    mkdir(fullfile(patient_dir, 'geometry_files'));
-    mkdir(fullfile(patient_dir, 'matlab_files'));
-    mkdir(fullfile(patient_dir, 'opt_input'));
-    mkdir(fullfile(patient_dir, 'opt_output'));
+    mkdir(Geometry.patient_dir);
+    mkdir(fullfile(Geometry.patient_dir, 'beamlet_batch_files'));
+    mkdir(fullfile(Geometry.patient_dir, 'geometry_files'));
+    mkdir(fullfile(Geometry.patient_dir, 'matlab_files'));
+    mkdir(fullfile(Geometry.patient_dir, 'opt_input'));
+    mkdir(fullfile(Geometry.patient_dir, 'opt_output'));
 
     %% -----===== BTV and Ring creation =====-----
 %     waitbar(1/total_num_steps, hWaitbar, 'Step 2: Assign target and BTV margin');
@@ -153,32 +159,28 @@ function [Geometry patient_dir] = nrrd2geometry
     %% -----===== Save the matlab files =====-----
     waitbar(2.33/total_num_steps, hWaitbar, 'Step 3: Save matlab geometry files');
     % Save matlab geometry file
-    save(fullfile(patient_dir, 'matlab_files', 'Geometry.mat'), 'Geometry');
+    save(fullfile(Geometry.patient_dir, 'matlab_files', 'Geometry.mat'), 'Geometry');
 
     waitbar(2.66/total_num_steps, hWaitbar, 'Step 3: Save raw geometry files');
     % Write binary geometry files
-    fid = fopen(fullfile(patient_dir, 'geometry_files', 'rhomw.bin'), 'w');
+    fid = fopen(fullfile(Geometry.patient_dir, 'geometry_files', 'rhomw.bin'), 'w');
     fwrite(fid, Geometry.rhomw, 'single');
     fclose(fid);
     
-    fid = fopen(fullfile(patient_dir, 'geometry_files', 'Smw.bin'), 'w');
+    fid = fopen(fullfile(Geometry.patient_dir, 'geometry_files', 'Smw.bin'), 'w');
     fwrite(fid, Geometry.Smw, 'single');
     fclose(fid);
 
-    fid = fopen(fullfile(patient_dir, 'geometry_files', 'Fmw2.bin'), 'w');
+    fid = fopen(fullfile(Geometry.patient_dir, 'geometry_files', 'Fmw2.bin'), 'w');
     fwrite(fid, Geometry.Fmw2, 'single');
     fclose(fid);
 
-%     fid = fopen(fullfile(patient_dir, 'geometry_files', 'target_mask.bin'), 'w');
-%     fwrite(fid, Geometry.BTV, 'single');
-%     fclose(fid);
-
-    % hWaitbar = waitbar(1/total_num_steps, 'Step 4, Create optimization geometry');
-
     delete(hWaitbar);
-    waitfor(msgbox(['Plan geometry created successfully in ' '"' patient_dir '"']));
-    
-    
+    waitfor(msgbox(['Plan geometry created successfully in ' '"' Geometry.patient_dir '"']));
     
 
-end
+end
+
+
+
+

+ 24 - 14
WiscPlanPhotonkV125/matlab_frontend/nrrd2ROI.m

@@ -2,23 +2,33 @@ function Geometry=nrrd2ROI(Geometry, patient_dir)
 
     %% -----===== Get ROI mask =====-----
     while true
-        newRoi = questdlg('Do you want to load another ROI?','New ROI','Yes','No','No')
+        newRoi = questdlg('Do you want to load another ROI?','New ROI','Yes','No','No');
         switch newRoi
             case 'Yes'
-                [TRGT_in, TRGT_path, ~] = uigetfile(['C:\010-work\003_localGit\WiscPlan_v2\data\','*.nrrd']);
-                if TRGT_in==0 % no file selected, no change to CT data
-                    warning('No file selected!')
-                else 
-                    [TRGT_img, meta]=nrrdread([TRGT_path, TRGT_in]);
+                
+                [ROI_in, ROI_path, filterIdx] = uigetfile([{'*.nrrd'; '*.am'}], 'Select ROI image', Geometry.data_dir);
+                switch filterIdx
+                    case 0
+                        warning('No file selected, aborting!')
+                        return 
+                    case 1
+                        [ROI_img, meta]=nrrdread([ROI_path, ROI_in]);
+                        disp('NRRD file loaded!')
+                    case 2
+                        ROI_img = am2mat([ROI_path, ROI_in]);
+                        ROI_img = permute(ROI_img.data, [2,1,3]);
+                        disp('AM file loaded!')
+                    case 3
+                        error('please do not select *all* in file selection')
+                    otherwise
+                        error('You should never see this.')
                 end
-            Geometry.ROIS{end+1}.ind = find(TRGT_img>0);
-            str = input('Enter ROI name: \n','s');
-            Geometry.ROIS{end}.name= str;
-            
-            
-            save(fullfile(patient_dir, 'matlab_files', 'Geometry.mat'), 'Geometry');
-            
-            
+                
+                Geometry.ROIS{end+1}.ind = find(ROI_img>0);
+                str = input('Enter ROI name: \n','s');
+                Geometry.ROIS{end}.name= str;
+                save(fullfile(Geometry.patient_dir, 'matlab_files', 'Geometry.mat'), 'Geometry');
+
             case 'No'
                 break
         end