computes the isocenter [mm] as the joint center of gravity of all volumes of interest that are labeled as target within the cst struct call isoCenter = matRad_getIsoCenter(cst,ct,visBool) input cst: matRad cst struct ct: ct cube visBool: toggle on/off visualization (optional) output isoCenter: isocenter in [mm] References - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Copyright 2015 the matRad development team. This file is part of the matRad project. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution and at https://github.com/e0404/matRad/LICENSES.txt. No part of the matRad project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function isoCenter = matRad_getIsoCenter(cst,ct,visBool) 0002 % computes the isocenter [mm] as the joint center of gravity 0003 % of all volumes of interest that are labeled as target within the cst 0004 % struct 0005 % 0006 % call 0007 % isoCenter = matRad_getIsoCenter(cst,ct,visBool) 0008 % 0009 % input 0010 % cst: matRad cst struct 0011 % ct: ct cube 0012 % visBool: toggle on/off visualization (optional) 0013 % 0014 % output 0015 % isoCenter: isocenter in [mm] 0016 % 0017 % References 0018 % - 0019 % 0020 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0021 % 0022 % Copyright 2015 the matRad development team. 0023 % 0024 % This file is part of the matRad project. It is subject to the license 0025 % terms in the LICENSE file found in the top-level directory of this 0026 % distribution and at https://github.com/e0404/matRad/LICENSES.txt. No part 0027 % of the matRad project, including this file, may be copied, modified, 0028 % propagated, or distributed except according to the terms contained in the 0029 % LICENSE file. 0030 % 0031 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0032 0033 % if visBool not set toogle off visualization 0034 if nargin < 3 0035 visBool = 0; 0036 end 0037 0038 % Initializes V variable. 0039 V = []; 0040 0041 %Check if any constraints/Objectives have been defined yet 0042 noObjOrConst = all(cellfun(@isempty,cst(:,6))); 0043 0044 % Save target indices in V variable. 0045 for i = 1:size(cst,1) 0046 % We only let a target contribute if it has an objective/constraint or 0047 % if we do not have specified objectives/constraints at all so far 0048 if isequal(cst{i,3},'TARGET') && (~isempty(cst{i,6}) || noObjOrConst) 0049 V = [V; cst{i,4}{1}]; 0050 end 0051 end 0052 0053 % Delete repeated indices, one voxel can belong to two VOIs, because 0054 % VOIs can be overlapping. 0055 V = unique(V); 0056 0057 % throw error message if no target is found 0058 if isempty(V) 0059 error('Could not find target'); 0060 end 0061 0062 % Transform subcripts from linear indices 0063 [yCoordsV, xCoordsV, zCoordsV] = ind2sub(ct.cubeDim,V); 0064 0065 % Transform to [mm] 0066 xCoordsV = xCoordsV * ct.resolution.x; 0067 yCoordsV = yCoordsV * ct.resolution.y; 0068 zCoordsV = zCoordsV * ct.resolution.z; 0069 0070 % Calculated isocenter. 0071 isoCenter = mean([xCoordsV yCoordsV zCoordsV]); 0072 0073 % Visualization 0074 if visBool 0075 0076 clf 0077 hold on 0078 0079 % Plot target 0080 plot3(yCoordsV,xCoordsV,zCoordsV,'kx') 0081 0082 % Show isocenter: red point 0083 plot3(isoCenter(2),isoCenter(1),isoCenter(3),'r.','MarkerSize',30) 0084 0085 xlabel('y [mm]') 0086 ylabel('x [mm]') 0087 zlabel('z [mm]') 0088 0089 end