extract .egsphant file form the GUI code which is given below MATLAB
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi all
i have a file with name "M_March_dimXYx3" (.egsphant) which contains (row X column)127X127 having 55 slices. when i go to properties file it appears that this file is in notepad form. i tried but unable to read and display this file in GUI MATLAB. i want to open the file using menu Editor which is in tools of GUI and want to display these images on axes and using slider show one by one all images in GUI. i can display just one slice.
i am also attaching code. this contains a lot of information but i need the above to do. so any body please help me to extraxt the exact part which i needed. which i told in the above paragraph. if you need any information i will help. any help is appreciated.hoping for early help. please help me. Muhammad isa
%*********************** Graphics Object Initiation ********************* % Executes just before DOSCTP is made visible % - Initiates the main GUI window function DOSCTP_OpeningFcn(hObject, eventdata, handles, varargin)
handles.GUIName = 'DOSCTP'; % Load user parameters user_parameters; set(handles.figMain,'Name',[handles.GUIName ' - Main Window']); % Check user parameters if (length(dMaterials)~=size(dRamp,1)) error('Number of materials and ramps must match.'); end if (length(dMaterials) > handles.s_DOSXYZ.MXMED) error('Number of materials is greater than MXMED.'); end % if (exist(handles.s_Path.EGSOutDir,'dir')~=7) % error('Invalid EGS user directory.'); % end % if (exist(handles.s_Path.PEGSFile,'file')~=2) % error('Invalid PEGS4 data file.'); % end % Store in variable name format required for GUI handles.s_DOSXYZ.Materials = dMaterials; % Materials name for ctcreate handles.s_DOSXYZ.Ramp = dRamp; % Ramp for conversion from CT to density % Enable or Disable Theta editing if (bEnableTheta) set(handles.editThetaMin,'Enable','on'); % set(handles.editThetaMax,'Enable','on'); end
% ~~~~ LIST OF SELECTED BEAMS ~~~~
% --- Parameters from BeamSelect ---
% -> handles.s_Beams(n).FileName Path of phase-space file
% -> handles.s_Beams(n).Linac Linear accelerator
% -> handles.s_Beams(n).Particle Incident particle
% -> handles.s_Beams(n).Energy Beam energy
% -> handles.s_Beams(n).Distance Beam length
% -> handles.s_Beams(n).FS Field shape/size
% -> handles.s_Beams(n).Applicator Applicator size
% -> handles.s_Beams(n).Name Name of beam given by user
% -> handles.s_Beams(n).ZLast Whether ZLast is stored or not
% -> handles.s_Beams(n).isource Which source type does this correspond to in DOSXYZnrc
% --- Parameters selected by user ---
% -> handles.s_Beams(n).Type 1 for single, 2 for arc
% -> handles.s_Beams(n).Angle Angle of the beam (degree) [theta(range) ; phi(range)]
% -> handles.s_Beams(b).ColAngle Collimator Angle
% -> handles.s_Beams(n).Weight Weight of particular beam
% -> handles.s_Beams(n).Divisions Divisions (for arc only)
% -> handles.s_Beams(n).SID Source to isocenter distance
% -> handles.s_Beams(b).ISMOOTH Redistribute phase space data or not
% -> handles.s_Beams(n).i_dbs 1 to use directional bremsstrahlung splitting, else 0
% -> handles.s_Beams(n).r_dbs DBS splitting radiusSSD at which r_dbs
% -> handles.s_Beams(n).ssd_dbs SSD at which r_dbs
% -> handles.s_Beams(n).z_dbs Z in the BEAMnrc run where the phase space source was scored (in cm)
% -> handles.s_Beams(n).hBeamLine Handle to the associated beamline
% -> handles.s_Beams(n).Color Color of the beamline
% ~~~~ LIST OF SELECTED CONTOURS ~~~~
% -> handles.s_Contours.Name Name of the contour
% -> handles.s_Contours.hLine Handle to associated contour line
% -> handles.s_Contours.Color Color of contour line
% -> handles.s_Contours.SliceNum The slice number it is on
% ~~~~ Contour Labelling Parameters ~~~~~
% -> handles.s_ConLabels.spacing Spacing between contour labels (pixels)
% -> handles.s_ConLabels.fontSize Font size of contour labels
% -> handles.s_ConLabels.fontColor Font color of contour labels
% -> handles.s_ConLabels.visible Show/hide contour labels (1 or 0)
% -> handles.s_ConLabels.lineWidth Width of the contour lines
% -> handles.s_ConLabels.showBar Show or hide the color bar on the image (1 or 0)
% -> handles.s_ConLabels.isoLvls Iso-levels of contours to display
% -------------------------------------------------------------------------
% Check if an image set has been loaded globally global s_Images; if isempty(s_Images) handles.imgLoaded = false; else handles.imgLoaded = true; end
% Set up keypress function set(hObject,'KeyPressFcn',@figMain_KeyPressFcn);
% Important this be stored first (matlab bug, slow computers?) guidata(hObject, handles); set(handles.figMain,'Pointer','watch');
% Initiate GUI parameters if an image set is present if (handles.imgLoaded) % Initiates GUI based on image set handles = beginGui(1,handles); else % Just initiate the mode selection setMode; end
% Default command line output for DOSCTP handles.output = hObject; % Update handles structure guidata(hObject, handles); % Reset pointer after everything has loaded set(handles.figMain,'Pointer','arrow');
% Executes when DOSCTP window is closed % - Outputs from this function are returned to the command line function varargout = DOSCTP_OutputFcn(hObject, eventdata, handles) % Return the handles of GUI varargout{1} = handles;
%************************************************************************** %**************************** Program Starts **************************** %**************************************************************************
% ------ FILE MENU ITEMS ------ %
% --------------------------------------------------------------------
% Opens dialogue for selecting a directory
function menuFileChgDir_Callback(hObject, eventdata, handles)
global s_Images;
if ~strcmp(get(handles.figMain,'Pointer'),'watch')
handles.s_Path.DcmFolder = uigetdir(handles.s_Path.DcmFolder,'Browse for Directory');
% Load the images
if (handles.s_Path.DcmFolder~=0)
[s_Images] = loadDICOM(handles.s_Path.DcmFolder);
% Allow the user to select a subset of the slices
try
handles.sliceRange = SliceSelect(s_Images);
s_Images = s_Images(handles.sliceRange(1):handles.sliceRange(2));
catch
disp('Slice range not selected.');
disp('-> Default to using all slices.');
end
if (~isempty(s_Images))
% Save the images into MAT file
[sFileName,sSaveDir] = uiputfile('*.mat','Save Data As...',handles.s_Path.DcmMatFile);
if (sFileName~=0)
% This is optional
handles.s_Path.DcmMatFile = [sFileName sSaveDir];
h = makeDialog('Saving images into MAT file...');
save([sSaveDir sFileName], 's_Images');
try
delete(h)
end
handles.s_Path.DcmMatFile = [sSaveDir sFileName];
end
handles.imgLoaded = true; % Now the program can begin
handles = beginGui(1,handles);
guidata(hObject, handles);
end
end
end
% Opens dialogue for selecting an egsphant file function menuFileLoadPhantom_Callback(hObject, eventdata, handles) global s_Images; if ~strcmp(get(handles.figMain,'Pointer'),'watch') [sFileName,sFolder] = uigetfile('*.egsphant','Browse for Phantom',handles.s_Path.EGSFile); handles.s_Path.EGSFile = [sFolder sFileName]; % Load the phantom file if (handles.s_Path.EGSFile~=0) s_Images = []; [s_Images] = loadPhantom(handles.s_Path.EGSFile,handles.s_DOSXYZ.Ramp,handles.s_DOSXYZ.Materials); if (~isempty(s_Images)) % --- Optional, Remove Start --- % Save the images into MAT file [sFileName,sSaveDir] = uiputfile('*.mat','Save Data As...',handles.s_Path.DcmMatFile); if (sFileName~=0) % This is optional handles.s_Path.DcmMatFile = [sFileName sSaveDir]; h = makeDialog('Saving phantom into MAT file...'); save([sSaveDir sFileName], 's_Images'); try delete(h); end end % --- Optional, Remove End --- handles.imgLoaded = true; % Now the program can begin handles = beginGui(1,handles); guidata(hObject, handles); else disp('No images loaded.'); end end end % Opens dialogue for selecting a .mat file function menuFileLoadMat_Callback(hObject, eventdata, handles) global s_Images; if ~strcmp(get(handles.figMain,'Pointer'),'watch') [sFileName,sFolder] = uigetfile('.mat','Browse for File',handles.s_Path.DcmMatFile); handles.s_Path.DcmMatFile = [sFolder sFileName]; % Initiate the variable (for error checking) if (handles.imgLoaded == false) s_Images = []; end % Load the data file if (sFileName~=0) h = makeDialog('Loading images...'); load(handles.s_Path.DcmMatFile,'s_Images'); if (isempty(s_Images)) msgbox('No DICOM image present.','Error!','warn','replace','WindowStyle','modal'); else handles.imgLoaded = true; % Now the program can begin handles = beginGui(1,handles); guidata(hObject, handles); end try delete(h); end end end
function menuFileExpVar_Callback(hObject, eventdata, handles) global s_Images; if (handles.imgLoaded) & ~strcmp(get(handles.figMain,'Pointer'),'watch') assignin('base','s_Beams',handles.s_Beams); assignin('base','s_Contours',handles.s_Contours); assignin('base','s_Ctc',handles.s_DOSXYZ); assignin('base','s_Images',s_Images); assignin('base','s_Simulation',handles.s_Simulation); assignin('base','handles',handles); % Some pre-defined information for users % - Dose currently being viewed if (~isempty(handles.Doses)) % Find normalization point in voxels (on transverse slice) curDose = handles.Doses(:,:,handles.tImg_Slice); [xNorm,yNorm,zNorm] = convertDim(handles.s_Simulation.NormPoint(1),handles.s_Simulation.NormPoint(2),handles.s_Simulation.NormPoint(3),'pixel'); maxDose = handles.Doses(yNorm,xNorm,zNorm); % try % if (maxDose~=0) % % Normalization % assignin('base','Doses3D',handles.Doses/maxDose.*100); % else % assignin('base','Doses3D',[]); % end % catch % disp('Insufficient memory to perform normalization on the doses.'); % disp('-> Exporting absolute dose.'); % disp('-> Dose at normalization point is exported as: normDose'); assignin('base','DosesAbs3D',handles.Doses); assignin('base','normDose',maxDose); % end else assignin('base','Doses3D',[]); end end
function menuFileExpRTOG_Callback(hObject, eventdata, handles) global s_Images; if (handles.imgLoaded) & ~strcmp(get(handles.figMain,'Pointer'),'watch') % Save the images into MAT file [sFileName,sSaveDir] = uiputfile('*.*','Save RTOG Set As...',[pwd '\rtog\']); if (sFileName~=0) % This is optional handles.s_Path.DcmMatFile = [sFileName sSaveDir]; h = makeDialog('Exporting RTOG...'); writeRTOG([sSaveDir sFileName],s_Images,handles); try delete(h) end end end
function menuFileExit_Callback(hObject, eventdata, handles) closereq;
% --------------------------------------------------------------------
function menuEditSimu_Callback(hObject, eventdata, handles) if (handles.imgLoaded) & ~strcmp(get(handles.figMain,'Pointer'),'watch') SimParaSelect(handles.s_Simulation); end
function menuEditConLabels_Callback(hObject, eventdata, handles) if (handles.imgLoaded) & ~strcmp(get(handles.figMain,'Pointer'),'watch') ConLabelSelect(handles.s_ConLabels,handles.allColors); end
% --------------------------------------------------------------------
function menuReportGenReport_Callback(hObject, eventdata, handles) global s_Images; % Now generate the report if (handles.imgLoaded) & ~strcmp(get(handles.figMain,'Pointer'),'watch') genReport(s_Images(1),handles.s_Beams,handles.s_DOSXYZ,handles.s_Simulation,handles.Doses,handles.s_Path.EGSFile); end
function menuReportImageTrans_Callback(hObject, eventdata, handles) if ~strcmp(get(handles.figMain,'Pointer'),'watch') saveImage(handles.axesMain); end
function menuReportImageSag_Callback(hObject, eventdata, handles) if ~strcmp(get(handles.figMain,'Pointer'),'watch') saveImage(handles.axesSView); end
function menuReportImageCoron_Callback(hObject, eventdata, handles) if ~strcmp(get(handles.figMain,'Pointer'),'watch') saveImage(handles.axesCView); end
function menuReportImageWindow_Callback(hObject, eventdata, handles) if ~strcmp(get(handles.figMain,'Pointer'),'watch') saveImage(handles.figMain); end
% --------------------------------------------------------------------
function menuToolsExpDCM_Callback(hObject, eventdata, handles) if ~strcmp(get(handles.figMain,'Pointer'),'watch') [sFileName,sFolder] = uigetfile('*.egsphant','Browse for Phantom',handles.s_Path.EGSFile); handles.s_Path.EGSFile = [sFolder sFileName]; if (handles.s_Path.EGSFile~=0) % Load the phantom file dirName = writeDICOM(handles);
if (~isempty(dirName))
msgbox('DICOM images written successfully.','Success!','warn','replace','WindowStyle','modal');
end
end
end
function menuTools3ddoseViewer_Callback(hObject, eventdata, handles) Dose3DViewer;
% --------------------------------------------------------------------
function menuAbout_Callback(hObject, eventdata, handles) AboutBox;
% ------ SLIDERS ITEMS ------ %
% --------------------------------------------------------------------
% Executes on slider movement
function sliderMain_Callback(hObject, eventdata, handles)
global s_Images;
if (handles.imgLoaded) & ~strcmp(get(handles.figMain,'Pointer'),'watch')
% Go back to display mode when viewing images
modeSelect = get(handles.panelMode,'SelectedObject');
if ~strcmp(get(modeSelect,'Tag'), 'toggleDisplay')
set(handles.panelMode,'SelectedObject',handles.toggleDisplay);
setMode;
end
% Return position of slider
iPosition = get(hObject,'Value') + 1; % +1 since min(sliderValue) is 0
handles.tImg_Slice = round(iPosition);
% Load the DICOM image on slider movement
handles = dispImg(s_Images,handles);
guidata(hObject, handles);
end
% ------ PUSHBUTTON ITEMS (Main) ------ %
% --------------------------------------------------------------------
% Executes on button press in push_ExportCtc
% - 1. Exports images to ctcreate
function push_ExportCtc_Callback(hObject, eventdata, handles)
global s_Images;
if (handles.imgLoaded) & ~strcmp(get(handles.figMain,'Pointer'),'watch')
% VoxelSelect will communicate through getappdata() - voxelNum, voxelCM
VoxelSelect(s_Images,handles.s_DOSXYZ,handles.s_Path.EGSFile);
end
% Executes on button press in push_EditPhantom % - 2. View/Edit the ctcreate phantom function push_EditPhantom_Callback(hObject, eventdata, handles) if (handles.imgLoaded) & ~strcmp(get(handles.figMain,'Pointer'),'watch') VoxEditor(handles.s_Path.EGSFile,handles.s_DOSXYZ.Ramp,handles.s_DOSXYZ.Materials); end
% Executes on button press in push_DOSXYZ % - 3. Set up input file for DOSXYZ function push_DOSXYZ_Callback(hObject, eventdata, handles) if (handles.imgLoaded) & ~strcmp(get(handles.figMain,'Pointer'),'watch') % Find selected beam indBeam = get(handles.listboxBeams,'Value'); % Check whether a beam is present and has a non-zero angle zeroAngle = false; for (i=1:length(handles.s_Beams)) if isempty(handles.s_Beams(i).Angle) zeroAngle = true; end end
if ( ~isempty(get(handles.listboxBeams,'String')) & ~zeroAngle )
createDXYZInp(handles);
else
msgbox('Beam is missing or angle not defined.','Error!','warn','replace','WindowStyle','modal');
end
end
% --- Executes on button press in push_ImportDose % - 4. Import .3ddose file(s) function push_ImportDose_Callback(hObject, eventdata, handles) global s_Images; if (handles.imgLoaded) & ~strcmp(get(handles.figMain,'Pointer'),'watch') origDose = []; % Ask user for type of dose button = questdlg('Where do you wish to load the doses from?','Select source...', ... '3ddose','RTOG','MAT','MAT'); switch button case {'3ddose','RTOG'} if strcmp(button,'3ddose') [filename,folder] = uigetfile('.3ddose','Browse for File',handles.s_Path.EGSOutDir); else [filename,folder] = uigetfile('*.*','Browse for the RTOG 0000 Header File',[pwd '\rtog\']); end doseFilePath = [folder filename]; if (filename~=0) % Open dialog box h = makeDialog('Loading doses...'); % Free memory for interpolation in resizeDose clear handles.Doses; guidata(hObject, handles); if strcmp(button,'3ddose') [expandDose,origDose] = resizeDose(s_Images,doseFilePath,'3ddose'); else [expandDose,origDose] = resizeDose(s_Images,doseFilePath,'RTOG'); end try delete(h) end end
if (isempty(origDose))
msgbox('Doses are not imported.','Error!','warn','replace','WindowStyle','modal');
else
% Save the images into MAT file
[sFileName,sSaveDir] = uiputfile('*.mat','Save Doses As...',handles.s_Path.DoseMatFile);
if (sFileName~=0)
% This is optional
handles.s_Path.DoseMatFile = [sSaveDir sFileName];
h = makeDialog('Saving doses into MAT file...');
save(handles.s_Path.DoseMatFile, 'origDose', 'expandDose');
try
delete(h)
end
end
% Store the read Doses
handles.Doses = expandDose;
% Clear the dose display
if (strcmp(get(handles.pushSeeDose,'String'),'Hide'))
set(handles.pushSeeDose,'String','Show');
handles = dispImg(s_Images,handles);
end
guidata(hObject, handles);
end
case 'MAT'
[sFileName,sFolder] = uigetfile('*.mat','Browse for Dose File',handles.s_Path.DoseMatFile);
handles.s_Path.DoseMatFile = [sFolder sFileName];
% Load the data file
if (sFileName~=0)
h = makeDialog('Loading doses...');
load(handles.s_Path.DoseMatFile, 'expandDose', 'origDose');
try
delete(h)
end
if (isempty(origDose))
msgbox('Invalid Dose File.','Error!','warn','replace','WindowStyle','modal');
else
% Used for checking the size of the doses
sizeX = double(s_Images(1).Columns);
sizeY = double(s_Images(1).Rows);
sizeZ = length(s_Images);
if ( (size(expandDose,2)~=sizeX) | (size(expandDose,1)~=sizeY) | (size(expandDose,3)~=sizeZ) )
msgbox('Dose File Does Not Match the Current DICOM Images.','Error!','warn','replace','WindowStyle','modal');
clear expandDose origDose;
else
handles.Doses = expandDose;
% Clear the dose display
if (strcmp(get(handles.pushSeeDose,'String'),'Hide'))
set(handles.pushSeeDose,'String','Show');
handles = dispImg(s_Images,handles);
end
guidata(hObject, handles);
end
end
end
end
end
% ------ PUSHBUTTON ITEMS (Secondary) ------ %
% --------------------------------------------------------------------
% Executes on button press in pushSeeDose.
% - Visualize doses at current slice
function pushSeeDose_Callback(hObject, eventdata, handles)
global s_Images;
if (handles.imgLoaded) & ~strcmp(get(handles.figMain,'Pointer'),'watch')
if (~isempty(handles.Doses))
% Doses are present
if strcmp(get(hObject,'String'),'Show')
set(hObject,'String','Hide');
handles = dispImg(s_Images,handles);
guidata(hObject, handles);
else
set(hObject,'String','Show');
handles = dispImg(s_Images,handles);
guidata(hObject, handles);
end
else
msgbox('No doses present.','Error!','warn','replace','WindowStyle','modal');
% A Precaution (for after doses are displayed, user loads new CT images)
set(hObject,'String','Show');
end
end
% Executes on button press in pushSetNorm. % - Sets the normalization point for doses function pushSetNorm_Callback(hObject, eventdata, handles) if (handles.imgLoaded) & ~strcmp(get(handles.figMain,'Pointer'),'watch') % Ask user for whether to enter by keyboard or use the mouse pointer button = questdlg('How do you wish to set the normalization point?','Select method...', ... 'Enter through Keyboard','Click with Mouse','Click with Mouse'); if (strcmp(button,'Click with Mouse')) % Set the mouse point set(handles.figMain,'Pointer','crosshair'); set(handles.panelMode,'SelectedObject',[]); setMode; elseif (strcmp(button,'Enter through Keyboard')) NormSelect(handles.s_Simulation.NormPoint); end end
% -----------------
% Executes on button press in pushDefineIso [ISOCENTER]
% - Changes mouse pointer and allows user to select a new isocenter
function pushDefineIso_Callback(hObject, eventdata, handles)
if (handles.imgLoaded) & ~strcmp(get(handles.figMain,'Pointer'),'watch')
IsoSelect(handles.s_Simulation.Isocenter);
end
% if (handles.imgLoaded) & ~strcmp(get(handles.figMain,'Pointer'),'watch')
% % Begin isocenter selection mode
% set(handles.panelMode,'SelectedObject',handles.togglePoint);
% setMode;
% end
% Executes on button press in pushDefaultIso [ISOCENTER] function pushDefaultIso_Callback(hObject, eventdata, handles) global s_Images; if (handles.imgLoaded) & ~strcmp(get(handles.figMain,'Pointer'),'watch') % Default z-slice to look at (z = 0 cm) for (i=1:length(s_Images)) if (s_Images(i).SliceLocation>0) zeroCoord = s_Images(i).SliceLocation; break; end end isoX = s_Images(i).PixelSpacing(1)*double(s_Images(i).Columns)/2 + s_Images(i).ImagePositionPatient(1); isoY = s_Images(i).PixelSpacing(2)*double(s_Images(i).Rows)/2 + s_Images(i).ImagePositionPatient(2); handles.s_Simulation.Isocenter = [isoX isoY s_Images(i).SliceLocation]; handles = dispImg(s_Images,handles); guidata(hObject, handles); end % ----------------- % Executes on button press in pushBeamAdd [BEAM] function pushBeamAdd_Callback(hObject, eventdata, handles) if (handles.imgLoaded) & ~strcmp(get(handles.figMain,'Pointer'),'watch') % Disable the beam list box set(handles.listboxBeams,'Enable','off'); % BeamSelect will communicate through getappdata() - beamPara BeamPSSelect; end
% --- Executes on button press in pushPRBeamAdd. function pushPRBeamAdd_Callback(hObject, eventdata, handles) if (handles.imgLoaded) & ~strcmp(get(handles.figMain,'Pointer'),'watch') % Disable the beam list box set(handles.listboxBeams,'Enable','off'); % BeamSelect will communicate through getappdata() - prBeamPara BeamPRSelect; end
% Executes on button press in pushBeamDel [BEAM] function pushBeamDel_Callback(hObject, eventdata, handles) if (handles.imgLoaded) & ~strcmp(get(handles.figMain,'Pointer'),'watch') % Disable the beam list box set(handles.listboxBeams,'Enable','off'); % Find selected beam indBeam = get(handles.listboxBeams,'Value'); % Check whether a beam is present if ( ~isempty(get(handles.listboxBeams,'String')) ) button = questdlg(['Are you sure you want to delete the beam ' handles.s_Beams(indBeam).Name '?'],'Delete Confirmation'); if (strcmp(button,'Yes')) % Remove item from listbox and handles listboxStr = get(handles.listboxBeams,'String'); tmpList = []; tmpBeams = []; j = 0; for (i=1:length(handles.s_Beams)) if ~(i==indBeam) j = j+1; if (j==1) tmpBeams = handles.s_Beams(i); else tmpBeams(j) = handles.s_Beams(i); end tmpList{j} = listboxStr{i}; end end % Delete the beam line for (j=1:length(handles.s_Beams(indBeam).hBeamLine)) delete(handles.s_Beams(indBeam).hBeamLine(j)); end % Store the truncated s_Beams handles.s_Beams = tmpBeams; % Remove item in listbox set(handles.listboxBeams,'Value',1); set(handles.listboxBeams,'String',tmpList); guidata(hObject, handles);
% Return to the default display mode
set(handles.panelMode,'SelectedObject',handles.toggleDisplay);
setMode;
% Update beam info panel
setBeamInfo(handles);
end
end
% Re-enable the beam list box
set(handles.listboxBeams,'Enable','on');
end
% Executes on button press in pushBeamEdit [BEAM] function pushBeamEdit_Callback(hObject, eventdata, handles) if (handles.imgLoaded) & ~strcmp(get(handles.figMain,'Pointer'),'watch') % Disable the beam list box set(handles.listboxBeams,'Enable','off'); % Find selected beam indBeam = get(handles.listboxBeams,'Value'); % Check whether a beam is present if ( ~isempty(get(handles.listboxBeams,'String')) ) answer = inputdlg('Enter new name for this beam:','Edit Beam',1,{handles.s_Beams(indBeam).Name}); try % answer is a string array, checking for emptiness if (~isempty(answer{1})) % Possibility here for nonempty matrix with a single cell array that is empty handles.s_Beams(indBeam).Name = answer{1}; listboxStr = get(handles.listboxBeams,'String'); listboxStr(indBeam) = answer; set(handles.listboxBeams,'String',listboxStr); guidata(hObject, handles); end catch if (~isempty(answer)) handles.s_Beams(indBeam).Name = answer{1}; listboxStr = get(handles.listboxBeams,'String'); listboxStr(indBeam) = answer; set(handles.listboxBeams,'String',listboxStr); guidata(hObject, handles); end end end % Re-enable the beam list box set(handles.listboxBeams,'Enable','on'); end
% Executes on button press in pushBeamAdv [BEAM] function pushBeamAdv_Callback(hObject, eventdata, handles) if (handles.imgLoaded) & ~strcmp(get(handles.figMain,'Pointer'),'watch') % Disable the beam list box set(handles.listboxBeams,'Enable','off'); % Find selected beam indBeam = get(handles.listboxBeams,'Value'); % Check whether a beam is present if ( ~isempty(get(handles.listboxBeams,'String')) ) % BeamAdvanced will communicate through getappdata() - beamAdPara BeamAdvanced(handles.s_Beams(indBeam)); end end % ----------------- % Executes on button press in pushContourAdd [CONTOUR] function pushContourAdd_Callback(hObject, eventdata, handles) if (handles.imgLoaded) & ~strcmp(get(handles.figMain,'Pointer'),'watch') listBoxStr = get(handles.listboxContours,'String'); if (isempty(listBoxStr)) indContour = 1; else indContour = length(listBoxStr)+1; end % Generate a default name for contour newContour.Name = ['Contour ' num2str(indContour)]; % Update list of contours in the list box contents = get(handles.listboxContours,'String'); contents{length(contents)+1} = newContour.Name; set(handles.listboxContours,'String',contents); % Move highlight to newly added contour set(handles.listboxContours,'Value',length(contents));
% Create a blank field for handles
newContour.hLine = [];
% Set up initial color
colorInd = indContour+2;
while (colorInd>length(handles.allColors))
colorInd = colorInd - length(handles.allColors);
end
newContour.Color = handles.allColors{colorInd};
set(handles.popupContourColor,'Value',colorInd);
% Create a blank field for slice location
newContour.SliceNum = [];
% Add contour to structure
if (length(handles.s_Contours)==0)
handles.s_Contours = newContour;
else
handles.s_Contours(length(handles.s_Contours)+1) = newContour;
end
guidata(hObject, handles);
% Begin continuous contour mode
set(handles.panelMode,'SelectedObject',handles.toggleContour);
setMode;
% Contour button re-enabled
set(handles.toggleContour,'Enable','on');
end
% Executes on button press in pushContourEdit [CONTOUR] function pushContourEdit_Callback(hObject, eventdata, handles) if (handles.imgLoaded) & ~strcmp(get(handles.figMain,'Pointer'),'watch') % Disable the contour list box set(handles.listboxContours,'Enable','off'); % Find selected contour indContour = get(handles.listboxContours,'Value'); % Check whether a contour is present if ( ~isempty(get(handles.listboxContours,'String')) ) answer = inputdlg('Enter new name for this contour:','Edit Contour',1,{handles.s_Contours(indContour).Name}); try % answer is a string array, checking for emptiness if (~isempty(answer{1})) % Possibility here for nonempty matrix with a single cell array that is empty handles.s_Contours(indContour).Name = answer{1}; listboxStr = get(handles.listboxContours,'String'); listboxStr(indContour) = answer; set(handles.listboxContours,'String',listboxStr); guidata(hObject, handles); end catch if (~isempty(answer)) handles.s_Contours(indContour).Name = answer{1}; listboxStr = get(handles.listboxContours,'String'); listboxStr(indContour) = answer; set(handles.listboxContours,'String',listboxStr); guidata(hObject, handles); end end end % Re-enable the contour list box set(handles.listboxContours,'Enable','on'); end
% Executes on button press in pushContourDel [CONTOUR] function pushContourDel_Callback(hObject, eventdata, handles) if (handles.imgLoaded) & ~strcmp(get(handles.figMain,'Pointer'),'watch') % Disable the contour list box set(handles.listboxContours,'Enable','off'); % Find selected contour indContour = get(handles.listboxContours,'Value'); % Check whether a contour is present if ( ~isempty(get(handles.listboxContours,'String')) ) button = questdlg(['Are you sure you want to delete the contour ' handles.s_Contours(indContour).Name '?'],'Delete Confirmation'); if (strcmp(button,'Yes')) % Remove item from listbox and handles listboxStr = get(handles.listboxContours,'String'); tmpList = []; tmpContours = []; j = 0; for (i=1:length(handles.s_Contours)) if ~(i==indContour) j = j+1; if (j==1) tmpContours = handles.s_Contours(i); else tmpContours(j) = handles.s_Contours(i); end tmpList{j} = listboxStr{i}; end end % Delete the contour delete(handles.s_Contours(indContour).hLine); % Store the truncated s_Contours handles.s_Contours = tmpContours; % Remove item in listbox set(handles.listboxContours,'Value',1) set(handles.listboxContours,'String',tmpList); guidata(hObject, handles);
% Return to the default display mode
set(handles.panelMode,'SelectedObject',handles.toggleDisplay);
setMode;
% Update the color info
if (~isempty(tmpList))
listboxContours_Callback(handles.listboxContours, [], handles);
end
end
end
% Re-enable the contour list box
set(handles.listboxContours,'Enable','on');
end
% ------ CHECKBOX ITEMS ------ %
% --------------------------------------------------------------------
% Executes on button press in checkBeam_Hide.
function checkBeam_Hide_Callback(hObject, eventdata, handles)
global s_Images;
if (handles.imgLoaded) & (~isempty(get(handles.listboxBeams,'String')))
if (get(hObject,'Value')) % Box checked
for (i=1:length(handles.s_Beams))
set(handles.s_Beams(i).hBeamLine,'Visible','off');
end
else
for (i=1:length(handles.s_Beams))
set(handles.s_Beams(i).hBeamLine,'Visible','on');
end
end
end
% ------ EDITBOX ITEMS ------ %
% --------------------------------------------------------------------
% Executes on change in editPhiMin [BEAM]
function editPhiMin_Callback(hObject, eventdata, handles)
global s_Images;
% Find selected beam
indBeam = get(handles.listboxBeams,'Value');
% Check whether a beam is present
if ( ~isempty(get(handles.listboxBeams,'String')) )
oldValue = handles.s_Beams(indBeam).Angle(2,1);
iInput = str2double(get(hObject,'String'));
if ( ~(isnan(iInput)) )
% Update edit field
handles.s_Beams(indBeam).Angle(2,1) = iInput;
handles = dispImg(s_Images,handles);
guidata(hObject, handles);
else
% Change back to original value
% - (bug: problem if user presses enter after invalid input)
% set(hObject,'String',num2str(oldValue,'%.2f'));
end
end
% Executes on change in editPhiMax [BEAM] function editPhiMax_Callback(hObject, eventdata, handles) global s_Images; % Find selected beam indBeam = get(handles.listboxBeams,'Value'); % Check whether a beam is present if ( ~isempty(get(handles.listboxBeams,'String')) ) oldValue = handles.s_Beams(indBeam).Angle(2,2); iInput = str2double(get(hObject,'String')); if ( ~(isnan(iInput)) ) % Update edit field handles.s_Beams(indBeam).Angle(2,2) = iInput; handles = dispImg(s_Images,handles); guidata(hObject, handles); else % Change back to original value % - (bug: problem if user presses enter after invalid input) % set(hObject,'String',num2str(oldValue,'%.2f')); end end
% Executes on change in editThetaMin [BEAM] function editThetaMin_Callback(hObject, eventdata, handles) global s_Images; % Find selected beam indBeam = get(handles.listboxBeams,'Value'); % Check whether a beam is present if ( ~isempty(get(handles.listboxBeams,'String')) ) oldValue = handles.s_Beams(indBeam).Angle(1,1); iInput = str2double(get(hObject,'String')); if ( ~(isnan(iInput)) ) % Update edit field (both min and max) handles.s_Beams(indBeam).Angle(1,1) = iInput; handles.s_Beams(indBeam).Angle(1,2) = iInput; % Update editThetaMax field in GUI set(handles.editThetaMax,'String',num2str(iInput,'%.2f')); % Not necessary to call dispImg guidata(hObject, handles); else % Change back to original value % - (bug: problem if user presses enter after invalid input) % set(hObject,'String',num2str(oldValue,'%.2f')); end end
% Executes on change in editWeightBeam [BEAM] function editWeightBeam_Callback(hObject, eventdata, handles) % Find selected beam indBeam = get(handles.listboxBeams,'Value'); % Check whether a beam is present if ( ~isempty(get(handles.listboxBeams,'String')) ) oldValue = handles.s_Beams(indBeam).Weight; iInput = str2double(get(hObject,'String')); if ( ~(isnan(iInput)) & iInput<=100 ) % The existing beams will be reduced by appropriate factor oldTotalRemainder = 100 - handles.s_Beams(indBeam).Weight; newTotalRemainder = 100 - iInput; for (i=1:length(handles.s_Beams)) if (i~=indBeam) handles.s_Beams(i).Weight = handles.s_Beams(i).Weight * newTotalRemainder / oldTotalRemainder; end end % Update new weight handles.s_Beams(indBeam).Weight = iInput; guidata(hObject, handles); else % Change back to original value set(hObject,'String',num2str(oldValue,'%.2f')); end end
% Executes on change in editBeamDivF [BEAM] function editBeamDivF_Callback(hObject, eventdata, handles) global s_Images; % Find selected beam indBeam = get(handles.listboxBeams,'Value'); % Check whether a beam is present if ( ~isempty(get(handles.listboxBeams,'String')) ) oldValue = handles.s_Beams(indBeam).Divisions; iInput = str2double(get(hObject,'String')); if ( ~(isnan(iInput)) & iInput>0 ) if (handles.s_Beams(indBeam).Type==2) & (iInput<2) iInput == 2; % Minimum of 2 end handles.s_Beams(indBeam).Divisions = iInput;
if (~isempty(handles.s_Beams(indBeam).Angle))
% Delete all beam line(s) so they can be re-drawn with new number of divisions
for (i=1:length(handles.s_Beams(indBeam).hBeamLine))
delete(handles.s_Beams(indBeam).hBeamLine(i));
end
handles.s_Beams(indBeam).hBeamLine = [];
% Redraw
handles = dispImg(s_Images,handles);
end
guidata(hObject, handles);
else
if (oldValue==0)
set(hObject,'String','2');
else
set(hObject,'String',num2str(oldValue,'%.0f'));
end
end
end
% Executes on change in editBeamColAngle [BEAM] function editBeamColAngle_Callback(hObject, eventdata, handles) % Find selected beam indBeam = get(handles.listboxBeams,'Value'); % Check whether a beam is present if ( ~isempty(get(handles.listboxBeams,'String')) ) oldValue = handles.s_Beams(indBeam).ColAngle; iInput = str2double(get(hObject,'String')); if ( ~(isnan(iInput)) & iInput>0 ) handles.s_Beams(indBeam).ColAngle = iInput; guidata(hObject, handles); else % Change back to original value set(hObject,'String',num2str(oldValue,'%.2f')); end end
% Executes on change in editBeamSID [BEAM] function editBeamSID_Callback(hObject, eventdata, handles) % Find selected beam indBeam = get(handles.listboxBeams,'Value'); % Check whether a beam is present if ( ~isempty(get(handles.listboxBeams,'String')) ) oldValue = handles.s_Beams(indBeam).SID; iInput = str2double(get(hObject,'String')); if ( ~(isnan(iInput)) & iInput>0 ) handles.s_Beams(indBeam).SID = iInput; guidata(hObject, handles); else % Change back to original value set(hObject,'String',num2str(oldValue,'%.2f')); end end
% Executes when the contrast window is changed [CONTRAST] function editWindow_Callback(hObject, eventdata, handles) global s_Images ; if (handles.imgLoaded) oldValue = handles.img_contWindow; iInput = str2double(get(hObject,'String')); if ( ~(isnan(iInput)) & iInput>0 ) % Update image window handles.img_contWindow = iInput; % Re-display the images handles = dispImg(s_Images,handles); guidata(hObject, handles); else % Change back to original value set(hObject,'String',num2str(oldValue)); end end
% Executes when the contrast level is changed [CONTRAST] function editLevel_Callback(hObject, eventdata, handles) global s_Images; if (handles.imgLoaded) oldValue = handles.img_contLevel; iInput = str2double(get(hObject,'String')); if ( ~(isnan(iInput)) & iInput>=0 ) % Update image level handles.img_contLevel = iInput; % Re-display the images handles = dispImg(s_Images,handles); guidata(hObject, handles); else % Change back to original value set(hObject,'String',num2str(oldValue)); end end
% Executes on change in plan name [MAIN] function editPlan_Callback(hObject, eventdata, handles) if (handles.imgLoaded) sPlan = get(hObject,'String'); % - check for spaces and replace with _ (underscore) indSpace = find(sPlan==' '); sPlan(indSpace) = '_'; handles.sPlanName = sPlan; % Rename the EGS phantom file k = max(findstr(handles.s_Path.EGSFile,'\')); handles.s_Path.EGSFile = handles.s_Path.EGSFile(1:k); handles.s_Path.EGSFile = [handles.s_Path.EGSFile handles.sPlanName '.egsphant']; guidata(hObject, handles); end
% Executes on change in patient name [MAIN] function editPatient_Callback(hObject, eventdata, handles) global s_Images; if (handles.imgLoaded) sPatient = get(hObject,'String'); for (i=1:length(s_Images)) s_Images(i).PatientName.FamilyName = sPatient; end end
% ------ POPUP MENU ITEMS ------ %
% --------------------------------------------------------------------
% Executes on selection change in popupIsoColor.
function popupIsoColor_Callback(hObject, eventdata, handles)
if findobj('Tag','isoPatch')
% returns popupIsoColor contents as cell array
contents = get(hObject,'String');
% returns selected item from popupIsoColor
selectedColor = contents{get(hObject,'Value')};
set(handles.isoPatch,'EdgeColor',selectedColor);
end
% Executes on selection change in popupBeamType. function popupBeamType_Callback(hObject, eventdata, handles) global s_Images; % Find selected beam indBeam = get(handles.listboxBeams,'Value'); % Check whether a beam is present if ( ~isempty(get(handles.listboxBeams,'String')) ) beamType = get(hObject,'Value'); handles.s_Beams(indBeam).Type = beamType; if (~isempty(handles.s_Beams(indBeam).Angle)) % Delete all beam line(s) for (i=1:length(handles.s_Beams(indBeam).hBeamLine)) delete(handles.s_Beams(indBeam).hBeamLine(i)); end handles.s_Beams(indBeam).hBeamLine = []; % Change the angle properly if (beamType==1) % Changing from arc to static handles.s_Beams(indBeam).Divisions = 0; % No divisions prevPhiRange = handles.s_Beams(indBeam).Angle(2,2) - handles.s_Beams(indBeam).Angle(2,1); handles.s_Beams(indBeam).Angle(2,1) = handles.s_Beams(indBeam).Angle(2,1) + prevPhiRange/2; elseif (beamType==2) % Changing from static to arc handles.s_Beams(indBeam).Divisions = 2; % Start with 2 divisions handles.s_Beams(indBeam).Angle(2,1) = handles.s_Beams(indBeam).Angle(2,1); handles.s_Beams(indBeam).Angle(2,2) = handles.s_Beams(indBeam).Angle(2,1); end end % Redraw handles = dispImg(s_Images,handles); guidata(hObject, handles); % Update beam info panel setBeamInfo(handles); end
% Executes on selection change in popupBeamColor. function popupBeamColor_Callback(hObject, eventdata, handles) % Find selected beam indBeam = get(handles.listboxBeams,'Value'); % Check whether a beam is present if ( ~isempty(get(handles.listboxBeams,'String')) ) % returns popupBeamColor contents as cell array contents = get(hObject,'String'); % returns selected item from popupBeamColor selectedColor = contents{get(hObject,'Value')}; % save the colour handles.s_Beams(indBeam).Color = selectedColor; set(handles.s_Beams(indBeam).hBeamLine,'Color',selectedColor); guidata(hObject, handles); end
% Executes on selection change in popupContourColor. function popupContourColor_Callback(hObject, eventdata, handles) % Find selected contour indContour = get(handles.listboxContours,'Value'); % Check whether a contour is present if ( ~isempty(get(handles.listboxContours,'String')) ) % returns popupContourColor contents as cell array contents = get(hObject,'String'); % returns selected item from popupBeamColor selectedColor = contents{get(hObject,'Value')}; % save the colour handles.s_Contours(indContour).Color = selectedColor; set(handles.s_Contours(indContour).hLine,'Color',selectedColor); guidata(hObject, handles); end
% ------ LISTBOX ITEMS ------ %
% --------------------------------------------------------------------
% Executes on selection change in listboxBeams.
% - Set up the text boxes based on the highlighted beam
function listboxBeams_Callback(hObject, eventdata, handles)
setBeamInfo(handles);
% Executes on selection change in listboxContours. % - Changes the display of the popupcolor menu function listboxContours_Callback(hObject, eventdata, handles) indContour = get(handles.listboxContours,'Value'); selectedColor = handles.s_Contours(indContour).Color; indColor = find(strcmp(handles.allColors,selectedColor)); set(handles.popupContourColor,'Value',indColor);
% ------ PANEL/TOGGLEBUTTON ITEMS ------ %
% --------------------------------------------------------------------
% Executes on selection change in panelMode
function panelMode_SelectionChangeFcn(hObject, eventdata, handles)
setMode;
% Executes on selection change in panelTools function panelTools_SelectionChangeFcn(hObject, eventdata, handles) global s_Images; % Perform action based on selected tool if (handles.imgLoaded) modeSelect = get(handles.panelMode,'SelectedObject'); if (~isempty(modeSelect)) % shouldn't be necessary, this is SelectionChange switch get(modeSelect,'Tag') % ~~~~~~~~~~~~~~~~~ case 'toggleDisplay' % Display mode selected toolSelect = get(handles.panelTools,'SelectedObject'); switch get(toolSelect,'String') case 'Navigate' setMode; case 'Zoom' % Set mouse pointer set(handles.figMain,'Pointer','crosshair'); % Display help message set(handles.textStatus,'String','Left-click and drag to form a zoom region, then release to zoom. Right-click to return to default view.'); end % ~~~~~~~~~~~~~~~~~ case 'togglePoint' % Isocenter mode selected toolSelect = get(handles.panelTools,'SelectedObject'); switch get(toolSelect,'String') case 'Define' setMode; case 'Intersect' crossPos = handles.tImg_MousePos; % Find out the current slice being viewed iCurImg = handles.tImg_Slice; % Find new isocenter (mm) [isoX,isoY,isoZ] = convertDim(crossPos(1),crossPos(2),handles.tImg_Slice,'mm'); handles.s_Simulation.Isocenter = [isoX isoY isoZ]; handles = dispImg(s_Images,handles); guidata(hObject, handles); % Return to the default display mode set(handles.panelMode,'SelectedObject',handles.toggleDisplay); setMode; end % ~~~~~~~~~~~~~~~~~ case 'toggleBeam' % Beam mode selected toolSelect = get(handles.panelTools,'SelectedObject'); switch get(toolSelect,'String') case 'Angle' setMode; end % ~~~~~~~~~~~~~~~~~ case 'toggleContour' % Contour mode selected toolSelect = get(handles.panelTools,'SelectedObject'); switch get(toolSelect,'String') case 'Draw' setMode; case 'Point' % Display help message set(handles.textStatus,'String','Left-click on the transverse image to place the contour points. Right-click to close the contour.'); end end end end
% -------------------------------------------------------------------- % ------ MOUSE ITEMS ------ % % -------------------------------------------------------------------- % Executes on mouse motion over figure - except title and menu. % - Updates the zoom box size (box is created by figMain_WindowButtonDownFcn) function figMain_WindowButtonMotionFcn(hObject, eventdata, handles) if (handles.imgLoaded) & ~strcmp(get(handles.figMain,'Pointer'),'watch') % Get mouse position curTPoint = get(handles.axesMain,'CurrentPoint'); modeSelect = get(handles.panelMode,'SelectedObject'); if (~isempty(modeSelect)) switch get(modeSelect,'Tag') % ~~~~~~~~~~~~~~~~~ case 'toggleDisplay' % Display mode selected toolSelect = get(handles.panelTools,'SelectedObject'); switch get(toolSelect,'String') case 'Zoom' if findobj('Tag','rectZoom') % UserData contains the initial mouse-click position mouseClickPos = get(handles.rectZoom,'UserData'); % Draw the square box if (curTPoint(1,1)-mouseClickPos(1)~=0) & (curTPoint(1,2)-mouseClickPos(2)~=0) if (curTPoint(1,1)-mouseClickPos(1)<0) & (curTPoint(1,2)-mouseClickPos(2)<0) set(handles.rectZoom,'Position',[curTPoint(1,1),curTPoint(1,2),mouseClickPos(1)-curTPoint(1,1),mouseClickPos(2)-curTPoint(1,2)]); elseif ( curTPoint(1,1)-mouseClickPos(1) < 0 ) set(handles.rectZoom,'Position',[curTPoint(1,1),mouseClickPos(2),mouseClickPos(1)-curTPoint(1,1),curTPoint(1,2)-mouseClickPos(2)]); elseif ( curTPoint(1,2)-mouseClickPos(2) < 0 ) set(handles.rectZoom,'Position',[mouseClickPos(1),curTPoint(1,2),curTPoint(1,1)-mouseClickPos(1),mouseClickPos(2)-curTPoint(1,2)]); else set(handles.rectZoom,'Position',[mouseClickPos(1),mouseClickPos(2),curTPoint(1,1)-mouseClickPos(1),curTPoint(1,2)-mouseClickPos(2)]); end end end end % ~~~~~~~~~~~~~~~~~ case 'toggleContour' toolSelect = get(handles.panelTools,'SelectedObject'); switch get(toolSelect,'String') case 'Draw' if ( ~isempty(get(handles.listboxContours,'String')) ) & ... strcmp(get(hObject,'SelectionType'),'normal') % mouse is left-clicked % Find selected contour indContour = get(handles.listboxContours,'Value'); % Check to see it is newly created try if (get(handles.s_Contours(indContour).hLine,'UserData')) % Extend contour xCoords = get(handles.s_Contours(indContour).hLine,'XData'); xCoords(length(xCoords)+1) = curTPoint(1,1); yCoords = get(handles.s_Contours(indContour).hLine,'YData'); yCoords(length(yCoords)+1) = curTPoint(1,2); set(handles.s_Contours(indContour).hLine,'XData',xCoords,'YData',yCoords); end catch keyboard end end end % ~~~~~~~~~~~~~~~~~ end end end
% -------------------------------------------------------------------- % Executes on mouse press over figure background, over a disabled or inactive control, or over an axes background. % - Zoom into selected region defined by the zoom box function figMain_WindowButtonUpFcn(hObject, eventdata, handles) if (handles.imgLoaded) & ~strcmp(get(handles.figMain,'Pointer'),'watch') modeSelect = get(handles.panelMode,'SelectedObject'); if (~isempty(modeSelect)) switch get(modeSelect,'Tag') % ~~~~~~~~~~~~~~~~~ case 'toggleDisplay' % Display mode selected toolSelect = get(handles.panelTools,'SelectedObject'); switch get(toolSelect,'String') case 'Zoom' if findobj('Tag','rectZoom') % Get the coordinates of the box bCoord = get(handles.rectZoom,'Position'); delete(handles.rectZoom); % Set a threshold for meaningful zooming thres = 5; % 5 pixels box if (bCoord(3)>thres & bCoord(3)>thres) set(handles.axesMain,'XLim',[bCoord(1) bCoord(1)+bCoord(3)] , ... 'YLim',[bCoord(2) bCoord(2)+bCoord(4)]); end end end % ~~~~~~~~~~~~~~~~~ case 'toggleContour' toolSelect = get(handles.panelTools,'SelectedObject'); switch get(toolSelect,'String') case 'Draw' if ( ~isempty(get(handles.listboxContours,'String')) ) % Find selected contour indContour = get(handles.listboxContours,'Value'); % Close the contour xCoords = get(handles.s_Contours(indContour).hLine,'XData'); xCoords(length(xCoords)+1) = xCoords(1); yCoords = get(handles.s_Contours(indContour).hLine,'YData'); yCoords(length(yCoords)+1) = yCoords(1); % UserData==false means the contour is old set(handles.s_Contours(indContour).hLine,'XData',xCoords,'YData',yCoords,'UserData',false); set(handles.panelMode,'SelectedObject',handles.toggleDisplay); setMode; end end end end end
% -------------------------------------------------------------------- % Executes on mouse press over figure background, over a disabled or inactive control, or over an axes background. % - Responsible for interaction with mouse clicks on images function figMain_WindowButtonDownFcn(hObject, eventdata, handles) global s_Images; % Action based on mode selected if (handles.imgLoaded) & ~strcmp(get(handles.figMain,'Pointer'),'watch') % Get the position of the mouse click curTPoint = get(handles.axesMain,'CurrentPoint'); curSPoint = get(handles.axesSView,'CurrentPoint'); curCPoint = get(handles.axesCView,'CurrentPoint'); % A fix for slow computers (everything drawn in this function is in axesMain) axes(handles.axesMain);
modeSelect = get(handles.panelMode,'SelectedObject');
if (~isempty(modeSelect))
switch get(modeSelect,'Tag')
% ~~~~~~~~~~~~~~~~~
case 'toggleDisplay' % Display mode selected
toolSelect = get(handles.panelTools,'SelectedObject');
switch get(toolSelect,'String')
case 'Navigate' % Navigate tool selected
% Check for out of bound
if (curTPoint(1,1)>0 & curTPoint(1,1)<=double(s_Images(handles.tImg_Slice).Columns) & ...
curTPoint(1,2)>0 & curTPoint(1,2)<=double(s_Images(handles.tImg_Slice).Rows))
% Mouse is clicked on transverse view window
handles.tImg_MousePos = [curTPoint(1,1) curTPoint(1,2)];
handles = dispImg(s_Images,handles);
guidata(hObject, handles);
elseif (curSPoint(1,1)>0 & curSPoint(1,1)<=double(s_Images(handles.tImg_Slice).Rows) & ...
curSPoint(1,2)>0 & curSPoint(1,2)<=length(s_Images))
% Mouse is clicked on saggital view window
handles.tImg_Slice = length(s_Images) - round(curSPoint(1,2)) +1;
% Move the slider accordingly
handles = dispImg(s_Images,handles);
guidata(hObject, handles);
set(handles.sliderMain,'Value',handles.tImg_Slice);
elseif (curCPoint(1,1)>0 & curCPoint(1,1)<=double(s_Images(handles.tImg_Slice).Columns) & ...
curCPoint(1,2)>0 & curCPoint(1,2)<=length(s_Images))
% Mouse is clicked on coronal view window
handles.tImg_Slice = length(s_Images) - round(curCPoint(1,2)) +1;
% Move the slider accordingly
set(handles.sliderMain,'Value',handles.tImg_Slice);
handles = dispImg(s_Images,handles);
guidata(hObject, handles);
end
case 'Zoom' % Zoom tool selected
% Check for out of bound
if (curTPoint(1,1)>0 & curTPoint(1,1)<=double(s_Images(handles.tImg_Slice).Columns) & ...
curTPoint(1,2)>0 & curTPoint(1,2)<=double(s_Images(handles.tImg_Slice).Rows))
% Mouse is clicked on transverse view window
if strcmp(get(hObject,'SelectionType'),'normal') % Left-Click
% Delete existing rectangles
if findobj('Tag','rectZoom')
delete(handles.rectZoom);
end
% Create the zoom rectangle
% Position: [x y width height]
% axes(handles.axesMain);
handles.rectZoom = rectangle('Position',[curTPoint(1,1),curTPoint(1,2),1,1],'Tag','rectZoom','EdgeColor','white', ...
'UserData',[curTPoint(1,1) curTPoint(1,2)]);
guidata(hObject, handles);
else % Right Click
% Reset axis
limits = get(handles.axesMain,'UserData');
set(handles.axesMain,'XLim',limits(1,:),'YLim',limits(2,:));
end
end
end
% ~~~~~~~~~~~~~~~~~
case 'togglePoint'
toolSelect = get(handles.panelTools,'SelectedObject');
switch get(toolSelect,'String')
case 'Define'
% Check for out of bound (transverse window)
if (curTPoint(1,1)>0 & curTPoint(1,1)<=double(s_Images(handles.tImg_Slice).Columns) & ...
curTPoint(1,2)>0 & curTPoint(1,2)<=double(s_Images(handles.tImg_Slice).Rows))
% Find out the current slice being viewed
iCurImg = handles.tImg_Slice;
% Find new isocenter (mm)
[isoX,isoY,isoZ] = convertDim(curTPoint(1,1),curTPoint(1,2),handles.tImg_Slice,'mm');
handles.s_Simulation.Isocenter = [isoX isoY isoZ];
handles = dispImg(s_Images,handles);
guidata(hObject, handles);
% Return to the default display mode
set(handles.panelMode,'SelectedObject',handles.toggleDisplay);
setMode;
end
end
% ~~~~~~~~~~~~~~~~~
case 'toggleBeam'
toolSelect = get(handles.panelTools,'SelectedObject');
switch get(toolSelect,'String')
case 'Angle'
% Check for out of bound (transverse window)
if (curTPoint(1,1)>0 & curTPoint(1,1)<=double(s_Images(handles.tImg_Slice).Columns) & ...
curTPoint(1,2)>0 & curTPoint(1,2)<=double(s_Images(handles.tImg_Slice).Rows))
% Find out the current slice being viewed
iCurImg = handles.tImg_Slice;
% Calculate beam angles
% - Get current mouse coordinates
[curX,curY,curZ] = convertDim(curTPoint(1,1),curTPoint(1,2),iCurImg,'mm');
% - Adjust by isocenter coordinates
X = curX - handles.s_Simulation.Isocenter(1);
Y = curY - handles.s_Simulation.Isocenter(2);
Z = curZ - handles.s_Simulation.Isocenter(3);
[theta,phi,r] = cart2sph(X,Y,Z);
% - Now adjust to DOSXYZnrc coordinate convention (degrees)
dosPhi = theta * 180 / pi;
dosTheta = (pi/2 - phi) * 180 / pi;
if (dosPhi<0)
dosPhi = 360 + dosPhi;
end
% Determine the currently selected beam
indBeam = get(handles.listboxBeams,'Value');
<pre> % --------- Careful ---------
% Overwrite dosTheta with original Theta, not necessarily 90
% ->
0 comentarios
Respuestas (0)
Ver también
Categorías
Más información sobre Basic Display en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!