matRad_DoseOptimizationFunction

Purpose ^

Synopsis ^

This is a script file.

Description ^

Cross-reference information ^

This function calls: This function is called by:

Subfunctions ^

Source code ^

0001 classdef (Abstract) matRad_DoseOptimizationFunction
0002 % matRad_DoseOptimizationFunction. Superclass for objectives and constraints
0003 % This is the superclass for all objectives and constraints to enable easy
0004 % one-line identification.
0005 %
0006 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0007 %
0008 % Copyright 2019 the matRad development team.
0009 %
0010 % This file is part of the matRad project. It is subject to the license
0011 % terms in the LICENSE file found in the top-level directory of this
0012 % distribution and at https://github.com/e0404/matRad/LICENSES.txt. No part
0013 % of the matRad project, including this file, may be copied, modified,
0014 % propagated, or distributed except according to the terms contained in the
0015 % LICENSE file.
0016 %
0017 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0018     
0019     properties (Abstract, Constant)
0020         name                %Display name of the Objective. Needs to be implemented in sub-classes.
0021         parameterNames      %Cell array of Display names of the parameters. Needs to be implemented in sub-classes.
0022         parameterTypes      %Cell array of parameter types. Valid types are 'dose', 'numeric', or a cell list of string options. Needs to be implemented in sub-classes.
0023     end
0024     
0025     properties (Abstract, Access = public)
0026         parameters
0027     end
0028     
0029     methods
0030         function obj = matRad_DoseOptimizationFunction(dataStruct)
0031             if nargin > 0 && ~isempty(dataStruct) && isstruct(dataStruct)
0032                 obj = assignCommonPropertiesFromStruct(obj,dataStruct);
0033             end
0034         end
0035         
0036         % Overload the struct function to return a struct with general
0037         % the objective / constraint
0038         function s = struct(obj)
0039             s.className = class(obj);
0040             s.parameters = obj.parameters;
0041         end
0042     end
0043     
0044     % Helper methods
0045     methods (Access = public)
0046         function doseParams = getDoseParameters(obj)
0047             % get only the dose related parameters.
0048             ix = cellfun(@(c) isequal('dose',c),obj.parameterTypes);
0049             doseParams = [obj.parameters{ix}];
0050         end
0051         
0052         function obj = setDoseParameters(obj,doseParams)
0053             % set only the dose related parameters.
0054             ix = cellfun(@(c) isequal('dose',c),obj.parameterTypes);
0055             obj.parameters(ix) = num2cell(doseParams);
0056             
0057         end                
0058     end
0059     
0060     methods (Access = private)
0061         function obj = assignCommonPropertiesFromStruct(obj,s)
0062             for fn = fieldnames(s)'    %enumerat fields
0063                 try
0064                     obj.(fn{1}) = s.(fn{1});   %and copy
0065                 catch
0066                     continue;
0067                     %Do Nothing here
0068                     %warning('Could not copy field %s', fn{1});
0069                 end
0070             end
0071         end
0072     end
0073         
0074     
0075     methods (Static)
0076         % creates an optimization function from a struct
0077         function obj = createInstanceFromStruct(s)            
0078             try
0079                 %Check vor old version of cst objectives / cosntraints and
0080                 %convert if necessary
0081                 if isfield(s,'type')
0082                     s = matRad_DoseOptimizationFunction.convertOldOptimizationStruct(s);
0083                 end
0084                 
0085                 %Create objective / constraint from class name
0086                 obj = eval([s.className '(s)']);       
0087                 
0088                 env = matRad_getEnvironment();
0089                 
0090                 %Workaround for Octave which has a problem assigning
0091                 %properties in superclass
0092                 if strcmp(env,'OCTAVE')
0093                     obj = assignCommonPropertiesFromStruct(obj,s);
0094                 end
0095                 
0096             catch ME
0097                 error(['Could not instantiate Optimization Function: ' ME.message]);
0098             end
0099         end
0100                 
0101         function s = convertOldOptimizationStruct(old_s)
0102             %Converts old version obejctives to current format
0103             switch old_s.type
0104                 %Objectives
0105                 case 'square deviation'
0106                     s.className = 'DoseObjectives.matRad_SquaredDeviation';
0107                     s.penalty = old_s.penalty;
0108                     s.parameters{1} = old_s.dose;
0109                     
0110                 case 'square overdosing'
0111                     s.className = 'DoseObjectives.matRad_SquaredOverdosing';
0112                     s.penalty = old_s.penalty;
0113                     s.parameters{1} = old_s.dose;
0114                     
0115                 case 'square underdosing'
0116                     s.className = 'DoseObjectives.matRad_SquaredUnderdosing';
0117                     s.penalty = old_s.penalty;
0118                     s.parameters{1} = old_s.dose;
0119                     
0120                 case 'min DVH objective'
0121                     s.className = 'DoseObjectives.matRad_MinDVH';
0122                     s.parameters{1} = old_s.dose;
0123                     s.parameters{2} = old_s.volume;
0124                         
0125                 case 'max DVH objective'
0126                     s.className = 'DoseObjectives.matRad_MaxDVH';
0127                     s.parameters{1} = old_s.dose;
0128                     s.parameters{2} = old_s.volume;
0129                     
0130                 case 'mean'
0131                     s.className = 'DoseObjectives.matRad_MeanDose';
0132                     s.parameters{1} = old_s.dose;
0133                     
0134                 case 'EUD'
0135                     s.className = 'DoseObjectives.matRad_EUD';
0136                     s.parameters{1} = old_s.dose;
0137                     s.parameters{2} = old_s.EUD;
0138                     
0139                 %Constraints
0140                 case  'max dose constraint'
0141                     s.className = 'DoseConstraints.matRad_MinMaxDose';
0142                     s.parameters{1} = 0;
0143                     s.parameters{2} = old_s.dose;
0144                     
0145                 case  'min dose constraint'
0146                     s.className = 'DoseConstraints.matRad_MinMaxDose';
0147                     s.parameters{1} = old_s.dose;
0148                     s.parameters{2} = Inf;
0149                     
0150                 case  'min mean dose constraint'
0151                     s.className = 'DoseConstraints.matRad_MinMaxMeanDose';
0152                     s.parameters{1} = old_s.dose;
0153                     s.parameters{2} = Inf;
0154                     
0155                 case  'max mean dose constraint'
0156                     s.className = 'DoseConstraints.matRad_MinMaxMeanDose';
0157                     s.parameters{1} = 0;
0158                     s.parameters{2} = old_s.dose;
0159                     
0160                     
0161                 case  'min EUD constraint'
0162                     s.className = 'DoseConstraints.matRad_MinMaxEUD';
0163                     s.parameters{1} = old_s.EUD;
0164                     s.parameters{2} = old_s.dose;
0165                     s.parameters{3} = Inf;
0166                     
0167                 case  'max EUD constraint'
0168                     s.className = 'DoseConstraints.matRad_MinMaxEUD';
0169                     S.parameters{1} = old_s.EUD;
0170                     s.parameters{2} = 0;
0171                     s.parameters{3} = old_s.dose;
0172                     
0173                 case  'max DVH constraint'
0174                     s.className = 'DoseConstraints.matRad_MinMaxDVH';
0175                     s.parameters{1} = old_s.dose;
0176                     s.parameters{2} = 0;
0177                     s.parameters{3} = old_s.volume;
0178                     
0179                 case  'min DVH constraint'
0180                     s.className = 'DoseConstraints.matRad_MinMaxDVH';
0181                     s.parameters{1} = old_s.dose;
0182                     s.parameters{2} = old_s.volume;
0183                     s.parameters{3} = 100;
0184                 otherwise
0185                     ME = MException('optimization:ObjectCreationFailed','Old versioned input struct / parameter invalid for creation of optimization function!');
0186                     throw(ME);
0187             end
0188         end
0189     end
0190 end
0191

| Generated by m2html © 2005