Kaynağa Gözat

It now imports nrrd files and does displays where the edges are based on voxel map rather than geometry.

pferjancic 7 yıl önce
ebeveyn
işleme
02ff6bc459
25 değiştirilmiş dosya ile 171 ekleme ve 125 silme
  1. BIN
      WiscPlanPhotonkV125/PatientData/batch_dose0.bin
  2. BIN
      WiscPlanPhotonkV125/PatientData/batch_dose1.bin
  3. 1 1
      WiscPlanPhotonkV125/PatientData/beamlet_batch_files/beamlet_header.txt
  4. BIN
      WiscPlanPhotonkV125/PatientData/beamlet_batch_files/beamletbatch0.bin
  5. BIN
      WiscPlanPhotonkV125/PatientData/geometry_files/Fmw2.bin
  6. BIN
      WiscPlanPhotonkV125/PatientData/geometry_files/Smw.bin
  7. BIN
      WiscPlanPhotonkV125/PatientData/geometry_files/rhomw.bin
  8. BIN
      WiscPlanPhotonkV125/PatientData/geometry_files/target_mask.bin
  9. BIN
      WiscPlanPhotonkV125/PatientData/geometryfiles/density.bin
  10. 1 1
      WiscPlanPhotonkV125/PatientData/geometryfiles/geometryHeader.txt
  11. BIN
      WiscPlanPhotonkV125/PatientData/matlab_files/Geometry.mat
  12. BIN
      WiscPlanPhotonkV125/PatientData/matlab_files/optResults.mat
  13. BIN
      WiscPlanPhotonkV125/PatientData/opt_input/BTVDoseMinus.bin
  14. BIN
      WiscPlanPhotonkV125/PatientData/opt_input/BTVDosePlus.bin
  15. BIN
      WiscPlanPhotonkV125/PatientData/opt_input/RingDoseMinus.bin
  16. BIN
      WiscPlanPhotonkV125/PatientData/opt_input/RingDosePlus.bin
  17. BIN
      WiscPlanPhotonkV125/PatientData/opt_input/TargetDoseMinus.bin
  18. BIN
      WiscPlanPhotonkV125/PatientData/opt_input/TargetDosePlus.bin
  19. 13 67
      WiscPlanPhotonkV125/PatientData/opt_input/prescription.txt
  20. 3 1
      WiscPlanPhotonkV125/matlab_frontend/dicomrt/dicomrt2geometry.m
  21. 1 0
      WiscPlanPhotonkV125/matlab_frontend/get_full_dose.m
  22. 13 47
      WiscPlanPhotonkV125/matlab_frontend/helicalDosecalcSetup6.m
  23. 3 1
      WiscPlanPhotonkV125/matlab_frontend/lab/RDXTPS_geometry_setup_wizard_ASP.m
  24. 119 4
      WiscPlanPhotonkV125/matlab_frontend/lab/SliceViewerPanel.m
  25. 17 3
      WiscPlanPhotonkV125/matlab_frontend/lab/XTPS.m

BIN
WiscPlanPhotonkV125/PatientData/batch_dose0.bin


BIN
WiscPlanPhotonkV125/PatientData/batch_dose1.bin


+ 1 - 1
WiscPlanPhotonkV125/PatientData/beamlet_batch_files/beamlet_header.txt

@@ -1,5 +1,5 @@
 beamletDim
-32 32 40
+32 32 16
 Nbeamlets
 3832
 Nbeamletbatches

BIN
WiscPlanPhotonkV125/PatientData/beamlet_batch_files/beamletbatch0.bin


BIN
WiscPlanPhotonkV125/PatientData/geometry_files/Fmw2.bin


BIN
WiscPlanPhotonkV125/PatientData/geometry_files/Smw.bin


BIN
WiscPlanPhotonkV125/PatientData/geometry_files/rhomw.bin


BIN
WiscPlanPhotonkV125/PatientData/geometry_files/target_mask.bin


BIN
WiscPlanPhotonkV125/PatientData/geometryfiles/density.bin


+ 1 - 1
WiscPlanPhotonkV125/PatientData/geometryfiles/geometryHeader.txt

@@ -1,6 +1,6 @@
 Xcount Ycount Zcount
 32 32 16
 Xstart Ystart Zstart
--2.18752002716064453125E+00 -3.28751993179321289063E+00 -4.38751983642578125000E+00
+-2.18752002716064453125E+00 -2.18752002716064453125E+00 -3.29999995231628417969E+00
 dx dy dz
 1.36720001697540283203E-01 1.36720001697540283203E-01 3.26999992132186889648E-01

BIN
WiscPlanPhotonkV125/PatientData/matlab_files/Geometry.mat


BIN
WiscPlanPhotonkV125/PatientData/matlab_files/optResults.mat


BIN
WiscPlanPhotonkV125/PatientData/opt_input/BTVDoseMinus.bin


BIN
WiscPlanPhotonkV125/PatientData/opt_input/BTVDosePlus.bin


BIN
WiscPlanPhotonkV125/PatientData/opt_input/RingDoseMinus.bin


BIN
WiscPlanPhotonkV125/PatientData/opt_input/RingDosePlus.bin


BIN
WiscPlanPhotonkV125/PatientData/opt_input/TargetDoseMinus.bin


BIN
WiscPlanPhotonkV125/PatientData/opt_input/TargetDosePlus.bin


+ 13 - 67
WiscPlanPhotonkV125/PatientData/opt_input/prescription.txt

@@ -1,36 +1,9 @@
 Ntissue
-6
+4
 
 tissueNum
 0
 name
-couch
-alpha
-0
-betaVPlus
-0
-dVPlus
-0
-vPlus
-0
-betaVMinus
-0
-dVMinus
-0
-vMinus
-0
-betaPlus
-0
-dosePlusFilename
-C:\010-work\003_localGit\WiscPlan_v2\WiscPlanPhotonkV125\PatientData\opt_input\couchDosePlus.bin
-betaMinus
-0
-doseMinusFilename
-C:\010-work\003_localGit\WiscPlan_v2\WiscPlanPhotonkV125\PatientData\opt_input\couchDoseMinus.bin
-
-tissueNum
-1
-name
 Target
 alpha
 100
@@ -56,36 +29,9 @@ doseMinusFilename
 C:\010-work\003_localGit\WiscPlan_v2\WiscPlanPhotonkV125\PatientData\opt_input\TargetDoseMinus.bin
 
 tissueNum
-2
-name
-ROI_1
-alpha
-0
-betaVPlus
-0
-dVPlus
-0
-vPlus
-0
-betaVMinus
-0
-dVMinus
-0
-vMinus
-0
-betaPlus
-0
-dosePlusFilename
-C:\010-work\003_localGit\WiscPlan_v2\WiscPlanPhotonkV125\PatientData\opt_input\ROI_1DosePlus.bin
-betaMinus
-0
-doseMinusFilename
-C:\010-work\003_localGit\WiscPlan_v2\WiscPlanPhotonkV125\PatientData\opt_input\ROI_1DoseMinus.bin
-
-tissueNum
-3
+1
 name
-ROI_2
+BTV
 alpha
 0
 betaVPlus
@@ -103,16 +49,16 @@ vMinus
 betaPlus
 0
 dosePlusFilename
-C:\010-work\003_localGit\WiscPlan_v2\WiscPlanPhotonkV125\PatientData\opt_input\ROI_2DosePlus.bin
+C:\010-work\003_localGit\WiscPlan_v2\WiscPlanPhotonkV125\PatientData\opt_input\BTVDosePlus.bin
 betaMinus
 0
 doseMinusFilename
-C:\010-work\003_localGit\WiscPlan_v2\WiscPlanPhotonkV125\PatientData\opt_input\ROI_2DoseMinus.bin
+C:\010-work\003_localGit\WiscPlan_v2\WiscPlanPhotonkV125\PatientData\opt_input\BTVDoseMinus.bin
 
 tissueNum
-4
+2
 name
-BTV
+Ring
 alpha
 0
 betaVPlus
@@ -130,16 +76,16 @@ vMinus
 betaPlus
 0
 dosePlusFilename
-C:\010-work\003_localGit\WiscPlan_v2\WiscPlanPhotonkV125\PatientData\opt_input\BTVDosePlus.bin
+C:\010-work\003_localGit\WiscPlan_v2\WiscPlanPhotonkV125\PatientData\opt_input\RingDosePlus.bin
 betaMinus
 0
 doseMinusFilename
-C:\010-work\003_localGit\WiscPlan_v2\WiscPlanPhotonkV125\PatientData\opt_input\BTVDoseMinus.bin
+C:\010-work\003_localGit\WiscPlan_v2\WiscPlanPhotonkV125\PatientData\opt_input\RingDoseMinus.bin
 
 tissueNum
-5
+3
 name
-Ring
+ROI
 alpha
 0
 betaVPlus
@@ -157,9 +103,9 @@ vMinus
 betaPlus
 0
 dosePlusFilename
-C:\010-work\003_localGit\WiscPlan_v2\WiscPlanPhotonkV125\PatientData\opt_input\RingDosePlus.bin
+C:\010-work\003_localGit\WiscPlan_v2\WiscPlanPhotonkV125\PatientData\opt_input\ROIDosePlus.bin
 betaMinus
 0
 doseMinusFilename
-C:\010-work\003_localGit\WiscPlan_v2\WiscPlanPhotonkV125\PatientData\opt_input\RingDoseMinus.bin
+C:\010-work\003_localGit\WiscPlan_v2\WiscPlanPhotonkV125\PatientData\opt_input\ROIDoseMinus.bin
 

+ 3 - 1
WiscPlanPhotonkV125/matlab_frontend/dicomrt/dicomrt2geometry.m

@@ -20,7 +20,9 @@ function Geometry = dicomrt2geometry(dicomrt_dir)
 Geometry = [];
 
 if nargin < 1
-    dicomrt_dir = uifile('getdir', 'Select the directory contains the DICOM-RT images');
+%     dicomrt_dir = uifile('getdir', 'Select the directory contains the DICOM-RT images');
+% !!! Grozomah
+    dicomrt_dir = 'C:\010-work\003_localGit\WiscPlan_v2\WiscPlanPhotonkV125\CT with Contours\DICOM\TomoPhantPlan01';
 end
 
 if exist(dicomrt_dir, 'dir') ~= 7

+ 1 - 0
WiscPlanPhotonkV125/matlab_frontend/get_full_dose.m

@@ -9,3 +9,4 @@ optResults.batchNames{end+1} = optResults.batchNames{end};
 optResults.dose{end+1} = D;
 optResults.weights{end+1} = optResults.weights{end};
 save(optResultsFile, 'optResults', 'optSettings');
+

+ 13 - 47
WiscPlanPhotonkV125/matlab_frontend/helicalDosecalcSetup6.m

@@ -43,53 +43,19 @@ Nyp = 1;        % always 1 for Tomo due to binary mlc
 % ============================================= End of user-supplied inputs
 executable_path = 'C:\010-work\003_localGit\WiscPlan_v2\WiscPlanPhotonkV125\WiscPlanEXE\RyanCsphoton.x86.exe';
 kernel_file = 'Kernels.mat';
+geometry_file = fullfile(patient_dir, 'matlab_files\Geometry.mat');
+
+ROI_names = cellfun(@(c)c.name, Geometry.ROIS, 'UniformOutput', false);
+[target_idx okay] = listdlg('ListString', ROI_names, ...
+    'SelectionMode', 'single', 'Name', 'Target Selection', ...
+    'PromptString', 'Please select the target ROI. ');
+if okay ~= 1
+    msgbox('Plan creation aborted');
+    return;
+end
 
-
-% %%% geometry_file = fullfile(patient_dir, 'matlab_files\Geometry.mat');
-[a, ~]=nrrdread('C:\010-work\003_localGit\WiscPlan_v2\PhantomData\test_ct.nrrd');
-disp('loaded 1')
-[b, meta]=nrrdread('C:\010-work\003_localGit\WiscPlan_v2\PhantomData\test_seg.nrrd');
-disp('loaded 2')
-
-% geometry_file important parts:
-% Geometry.ROIS - actually only to get the binary mask of the target
-% Geometry.data - CT image in HU
-% Geometry.rhomw - CT image with values in relative water density 
-% Geometry.voxel_size - self explanatory
-% Geometry.start - self explanatory
-
-target_idx=1;
-Geometry.ROIS{target_idx}.ind = find(b>0);
-Geometry.data = a;
-Geometry.rhomw = a/1000;
-
-
-VoxSizeString = meta.spacedirections;
-C=textscan(VoxSizeString(2:end-1), '%f', 9,'Delimiter',{',',') ('})
-C=C{1};
-Geometry.voxel_size = [C(1), C(5), C(9)];
-
-
-StartString = meta.spaceorigin;
-C=textscan(StartString(2:end-1), '%f', 3,'Delimiter',',')
-Geometry.start=C{1};
-
-targetMask = b;
-
-% tumor bow and stern locations
-% load(geometry_file);
-% ROI_names = cellfun(@(c)c.name, Geometry.ROIS, 'UniformOutput', false);
-% [target_idx okay] = listdlg('ListString', ROI_names, ...
-%     'SelectionMode', 'single', 'Name', 'Target Selection', ...
-%     'PromptString', 'Please select the target ROI. ');
-% if okay ~= 1
-%     msgbox('Plan creation aborted');
-%     return;
-% end
-
-
-% targetMask = zeros(size(Geometry.data));
-% targetMask(Geometry.ROIS{target_idx}.ind) = 1;
+targetMask = zeros(size(Geometry.data));
+targetMask(Geometry.ROIS{target_idx}.ind) = 1;
 
 % Grozomah - targetMask needs to get a 'double' matrix with the location of
 % the target
@@ -186,7 +152,7 @@ yp = [ypmin:del_yp:ypmax-del_yp] + del_yp/2;
 
 [M,N,Q] = size(Geometry.rhomw);
 
-START = single(Geometry.start' - iso);
+START = single(Geometry.start - iso);
 INC = single(Geometry.voxel_size);
 
 % define the tumor mask

+ 3 - 1
WiscPlanPhotonkV125/matlab_frontend/lab/RDXTPS_geometry_setup_wizard_ASP.m

@@ -119,7 +119,9 @@ Geometry.ROIS{end}.visible = false;
 %% -----===== Save geometry files =====-----
 waitbar(2/total_num_steps, hWaitbar, 'Step 3: Save geometry files');
 
-patient_dir = uifile('getdir', 'Save the patient data to directory');
+% patient_dir = uifile('getdir', 'Save the patient data to directory');
+% !!! Grozomah
+patient_dir = 'C:\010-work\003_localGit\WiscPlan_v2\WiscPlanPhotonkV125\PatientData';
 
 % make directories
 mkdir(patient_dir);

+ 119 - 4
WiscPlanPhotonkV125/matlab_frontend/lab/SliceViewerPanel.m

@@ -91,12 +91,14 @@ classdef SliceViewerPanel < handle
                     % redraw only changed dimension
                     if obj.hSVPS.POI(obj.zOrien) ~= obj.hSVPS.prev_POI(obj.zOrien)
                         obj.redraw_image();
-                        obj.redraw_contour();
+%                         obj.redraw_contour();
+                        obj.redraw_overlay();
                     end
                 case {'Geometry' 'ctWindow' 'ROIdisp' 'dosedisp'}
                     % redraw all
                     obj.redraw_image();
-                    obj.redraw_contour();
+%                     obj.redraw_contour();
+                    obj.redraw_overlay();
                 case 'TCSVisible'
                     % redraw line
                     obj.redraw_lines();
@@ -336,8 +338,12 @@ classdef SliceViewerPanel < handle
         end
 %-------------------------------------------------------------------------------
         function redraw_contour(obj)
+            % This function is not called anymore. See redraw_overlay for
+            % the actual drawing of the contours
+            
             slice = obj.hSVPS.POI(obj.zOrien);
-
+    disp('Contour!!')
+    
             delete(obj.hROIs);
             obj.hROIs = [];
             hold(obj.hAxis,'on');
@@ -346,7 +352,8 @@ classdef SliceViewerPanel < handle
                 if obj.hSVPS.Geometry.ROIS{i}.visible == false
                     continue;
                 end
-
+                
+    
                 switch obj.zOrien
                     case 1
                         curve_indices = find(obj.hSVPS.Geometry.ROIS{i}.Xcurves_slices == slice);
@@ -385,6 +392,114 @@ classdef SliceViewerPanel < handle
             
             hold(obj.hAxis,'off');
         end
+%-------------------------------------------------------------------------------   
+        function redraw_overlay(obj)
+            slice = obj.hSVPS.POI(obj.zOrien);
+
+            delete(obj.hROIs);
+            obj.hROIs = [];
+            hold(obj.hAxis,'on');
+            
+            for i = 1:numel(obj.hSVPS.Geometry.ROIS)
+                % skip if display == OFF
+%                 fprintf('ROI #%.0f', i)
+                if obj.hSVPS.Geometry.ROIS{i}.visible == false
+%                     fprintf(' skipped!\n', i)
+                    continue;
+                end
+%                 fprintf(' analyzed!\n', i)
+                
+                testIdxList=obj.hSVPS.Geometry.ROIS{i}.ind;
+                matSize=size(obj.hSVPS.Geometry.data);
+                [x,y,z] = ind2sub(matSize, testIdxList);
+                
+%                 fprintf('ROI #%.0f \n', disp(obj.zOrien))
+                switch obj.zOrien
+                    case 1
+                        curve_indices = find(x == slice);
+                        if ~isempty(curve_indices)
+                            for curve_idx = curve_indices
+                                canvas=zeros(matSize(2),matSize(3));
+                                idx=sub2ind([matSize(2),matSize(3)], y(curve_indices), z(curve_indices));
+                                canvas(idx)=1;
+                                
+%                                 sum(canvas(:))
+                                B = bwboundaries(canvas);
+                                numContours=length(B);
+                                for contourI=1:numContours
+                                    B_I = B{contourI};
+                                    clear C
+                                    % up-down (+ high)
+                                    yshift= obj.hSVPS.Geometry.start(2) - 1.5*obj.hSVPS.Geometry.voxel_size(2);
+                                    zshift= obj.hSVPS.Geometry.start(3) - 1.0*obj.hSVPS.Geometry.voxel_size(3);
+
+                                    C(:,1)= yshift + (B_I(:,1))*obj.hSVPS.Geometry.voxel_size(2);
+                                    C(:,2)= zshift + (B_I(:,2))*obj.hSVPS.Geometry.voxel_size(3);
+                                    obj.hROIs(end+1) = plot(obj.hAxis, ...
+                                        C(:,2), C(:,1), ...
+                                        '--', 'LineWidth', 2, 'Color', obj.hSVPS.Geometry.ROIS{i}.color);
+                                end
+                            end
+                        end % end of IF
+
+                    case 2
+                        curve_indices = find(y == slice);
+                        if ~isempty(curve_indices)
+                            for curve_idx = curve_indices
+                                canvas=zeros(matSize(1),matSize(3));
+                                idx=sub2ind([matSize(1),matSize(3)], x(curve_indices), z(curve_indices));
+                                canvas(idx)=1;
+                                
+%                                 sum(canvas(:))
+                                B = bwboundaries(canvas);
+                                numContours=length(B);
+                                for contourI=1:numContours
+                                    B_I = B{contourI};
+                                    clear C
+                                    % up-down (+ high)
+                                    xshift= obj.hSVPS.Geometry.start(1) - 1.5*obj.hSVPS.Geometry.voxel_size(1);
+                                    zshift= obj.hSVPS.Geometry.start(3) - 1.0*obj.hSVPS.Geometry.voxel_size(3);
+
+                                    C(:,1)= xshift + (B_I(:,1))*obj.hSVPS.Geometry.voxel_size(1);
+                                    C(:,2)= zshift + (B_I(:,2))*obj.hSVPS.Geometry.voxel_size(3);
+                                    obj.hROIs(end+1) = plot(obj.hAxis, ...
+                                        C(:,2), C(:,1), ...
+                                        '--', 'LineWidth', 2, 'Color', obj.hSVPS.Geometry.ROIS{i}.color);
+                                end
+                            end
+                        end % end of IF
+                        
+                    case 3
+                        curve_indices = find(z == slice);
+                        if ~isempty(curve_indices)
+                            for curve_idx = curve_indices
+                                canvas=zeros(matSize(1),matSize(2));
+                                idx=sub2ind([matSize(1),matSize(2)], x(curve_indices), y(curve_indices));
+                                canvas(idx)=1;
+                                
+%                                 sum(canvas(:))
+                                B = bwboundaries(canvas);
+                                numContours=length(B);
+                                for contourI=1:numContours
+                                    B_I = B{contourI};
+                                    clear C
+                                    % up-down (+ high)
+                                    yshift= obj.hSVPS.Geometry.start(2) - 1.5*obj.hSVPS.Geometry.voxel_size(2);
+                                    xshift= obj.hSVPS.Geometry.start(1) - 1.5*obj.hSVPS.Geometry.voxel_size(1);
+
+                                    C(:,1)= yshift + (B_I(:,1))*obj.hSVPS.Geometry.voxel_size(1);
+                                    C(:,2)= xshift + (B_I(:,2))*obj.hSVPS.Geometry.voxel_size(2);
+                                    obj.hROIs(end+1) = plot(obj.hAxis, ...
+                                        C(:,2), C(:,1), ...
+                                        '--', 'LineWidth', 2, 'Color', obj.hSVPS.Geometry.ROIS{i}.color);
+                                end
+                            end
+                        end % end of IF
+                end
+            end
+            
+            hold(obj.hAxis,'off');
+        end
 %-------------------------------------------------------------------------------
     end % methods
 %===============================================================================

+ 17 - 3
WiscPlanPhotonkV125/matlab_frontend/lab/XTPS.m

@@ -226,9 +226,13 @@ classdef XTPS < handle
                     Geometry.ROIS{i}.Ycurves_slices = [];
                 end
                 
-                Zcurves_coordinate = cellfun(@(c)c(1,3), Geometry.ROIS{i}.curves);
-                Geometry.ROIS{i}.Zcurves_slices = ...
-                    round((Zcurves_coordinate - Geometry.start(3)) / Geometry.voxel_size(3)) + 1;
+                if isfield(Geometry.ROIS{i}, 'curves')
+                    Zcurves_coordinate = cellfun(@(c)c(1,3), Geometry.ROIS{i}.curves);
+                    Geometry.ROIS{i}.Zcurves_slices = ...
+                        round((Zcurves_coordinate - Geometry.start(3)) / Geometry.voxel_size(3)) + 1;
+                else
+                    Geometry.ROIS{i}.Zcurves_slices = [];
+                end
             end
             
             % Convert data into float
@@ -403,11 +407,21 @@ classdef XTPS < handle
         function ImportDicomRTMenu_Callback(obj, src, evt)
             [obj.handles.hSVPS.Geometry obj.patient_dir] = RDXTPS_geometry_setup_wizard_ASP();
             obj.load_geometry();
+            
+            a=obj.handles.hSVPS.Geometry;
+            disp(1)
         end
         
 %-------------------------------------------------------------------------------
 % Grozomah
         function NRRD1_Callback(obj, src, evt)
+            [obj.handles.hSVPS.Geometry obj.patient_dir] = nrrd2geometry;
+            obj.load_geometry();
+            
+            [obj.handles.hSVPS.Geometry] = nrrd2ROI(obj.handles.hSVPS.Geometry, obj.patient_dir);
+            obj.load_geometry();
+            
+            
             disp('NRRD1 called!')
         end
 %-------------------------------------------------------------------------------