From dae8c3d08619e90d964358479d11c3110c68c2ac Mon Sep 17 00:00:00 2001 From: Lisa Seckler Date: Fri, 28 Nov 2025 10:29:47 +0100 Subject: [PATCH 1/4] Warning gantry and couch angles + correct displayed progress Warning for different numbers of gantry and couch angles + correct progress displaying of the stf calculation --- ...Rad_StfGeneratorExternalRayBixelAbstract.m | 8 ++-- matRad/util/matRad_progress.m | 41 +++++++++++-------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/matRad/steering/matRad_StfGeneratorExternalRayBixelAbstract.m b/matRad/steering/matRad_StfGeneratorExternalRayBixelAbstract.m index 524cf6490..aecd9d67d 100644 --- a/matRad/steering/matRad_StfGeneratorExternalRayBixelAbstract.m +++ b/matRad/steering/matRad_StfGeneratorExternalRayBixelAbstract.m @@ -54,7 +54,7 @@ function setDefaults(this) nBeams = numel(this.gantryAngles); if nBeams ~= numel(this.couchAngles) matRad_cfg = MatRad_Config.instance(); - matRad_cfg.dispWarning('For some reason, we have a different number of beam and couch angles!'); + matRad_cfg.dispError('There are more gantry angles than couch angles. They have to have the same size.') end end @@ -67,9 +67,11 @@ function setDefaults(this) if ~this.lockAngleUpdate this.lockAngleUpdate = true; if numel(this.gantryAngles) > numel(this.couchAngles) + matRad_cfg.dispError('There are more gantry angles than couch angles. They have to have the same size.') %Append Couch angles with zeros this.couchAngles = [this.couchAngles zeros(1,numel(this.gantryAngles)-numel(this.couchAngles))]; elseif numel(this.couchAngles) > numel(this.gantryAngles) + matRad_cfg.dispError('There are more couch angles than gantry angles. They have to have the same size.') %Try to identify the removed beam angles [removedAngles,ix] = setdiff(oldAngles,this.gantryAngles); @@ -239,7 +241,7 @@ function initialize(this) % Show progress if matRad_cfg.logLevel > 2 - matRad_progress(i,length(this.gantryAngles)); + matRad_progress(i,length(this.gantryAngles),1); end %% visualization @@ -384,7 +386,7 @@ function initialize(this) % Show progress if matRad_cfg.logLevel > 2 - matRad_progress(i,length(this.gantryAngles)); + matRad_progress(i,length(this.gantryAngles),2); end end end diff --git a/matRad/util/matRad_progress.m b/matRad/util/matRad_progress.m index 9cc357a3b..7037751ce 100644 --- a/matRad/util/matRad_progress.m +++ b/matRad/util/matRad_progress.m @@ -1,4 +1,4 @@ -function matRad_progress(currentIndex, totalNumberOfEvaluations) +function matRad_progress(currentIndex, totalNumberOfEvaluations,scen) % matRad progress bar % % call @@ -27,23 +27,30 @@ function matRad_progress(currentIndex, totalNumberOfEvaluations) % LICENSE file. % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -% If it's not the first step, erase the stuff printed before -if (currentIndex == 1) - fprintf('Progress: '); + +persistent isInitialized + +if isempty(isInitialized) + isInitialized = true; end - -if (currentIndex > 1) - Length = numel(sprintf('%3.2f %%',(currentIndex-1)/totalNumberOfEvaluations*100)); - fprintf(repmat('\b',1,Length)); + +percent = (currentIndex / totalNumberOfEvaluations) * 100; + +% --- first part of the progress --- +if scen == 1 + % new line + fprintf('\rProgress: %6.2f %%', percent); end - -% Print the progress tool -fprintf('%3.2f %%',currentIndex/totalNumberOfEvaluations*100); - -% After the last iteration print a newline command -if (currentIndex == totalNumberOfEvaluations) - fprintf('\n'); + +% --- for scenario 2, same line --- +if scen == 2 + fprintf(' Progress: %6.2f %%', percent); end - + +% --- finish line after the last angle --- +if currentIndex == totalNumberOfEvaluations && scen == 2 + fprintf('\n'); + clear isInitialized end + + From 7523a8f0ab5f8835ff9d91c94adcfc2b63389b6c Mon Sep 17 00:00:00 2001 From: lisaseckler Date: Fri, 27 Mar 2026 11:41:26 +0100 Subject: [PATCH 2/4] Updating commit: Error for different number of angles & progress bar The error that is thrown for different numbers of gantry angles and couch angles is now directly in the matRad_StfGeneratorBase.m. The matRad_progress.m is updated. --- matRad/steering/matRad_StfGeneratorBase.m | 3 ++ ...Rad_StfGeneratorExternalRayBixelAbstract.m | 15 ++++----- matRad/util/matRad_progress.m | 31 +++++-------------- 3 files changed, 16 insertions(+), 33 deletions(-) diff --git a/matRad/steering/matRad_StfGeneratorBase.m b/matRad/steering/matRad_StfGeneratorBase.m index 31c5a11ee..b36124399 100644 --- a/matRad/steering/matRad_StfGeneratorBase.m +++ b/matRad/steering/matRad_StfGeneratorBase.m @@ -145,6 +145,9 @@ function assignPropertiesFromPln(this,pln,warnWhenPropertyChanged) %ones given in the propStf struct if isfield(pln,'propStf') && isstruct(pln.propStf) plnStruct = pln.propStf; %get remaining fields + if numel(plnStruct.gantryAngles) ~= numel(plnStruct.couchAngles) + matRad_cfg.dispError('Inconsistent number of couch and gantry angles. Select the same number!'); + end if isfield(plnStruct,'generator') && ~isempty(plnStruct.generator) && ~any(strcmp(plnStruct.generator,this.shortName)) matRad_cfg.dispWarning('Inconsistent stf generators given! pln asks for ''%s'', but you are using ''%s''!',plnStruct.generator,this.shortName); end diff --git a/matRad/steering/matRad_StfGeneratorExternalRayBixelAbstract.m b/matRad/steering/matRad_StfGeneratorExternalRayBixelAbstract.m index aecd9d67d..707bf30e0 100644 --- a/matRad/steering/matRad_StfGeneratorExternalRayBixelAbstract.m +++ b/matRad/steering/matRad_StfGeneratorExternalRayBixelAbstract.m @@ -54,7 +54,7 @@ function setDefaults(this) nBeams = numel(this.gantryAngles); if nBeams ~= numel(this.couchAngles) matRad_cfg = MatRad_Config.instance(); - matRad_cfg.dispError('There are more gantry angles than couch angles. They have to have the same size.') + matRad_cfg.dispError('The number of gantry angles and couch angles must be equal.'); end end @@ -67,11 +67,13 @@ function setDefaults(this) if ~this.lockAngleUpdate this.lockAngleUpdate = true; if numel(this.gantryAngles) > numel(this.couchAngles) - matRad_cfg.dispError('There are more gantry angles than couch angles. They have to have the same size.') + matRad_cfg = MatRad_Config.instance(); + matRad_cfg.dispError('There are more gantry angles than couch angles. They have to have the same size.'); %Append Couch angles with zeros this.couchAngles = [this.couchAngles zeros(1,numel(this.gantryAngles)-numel(this.couchAngles))]; elseif numel(this.couchAngles) > numel(this.gantryAngles) - matRad_cfg.dispError('There are more couch angles than gantry angles. They have to have the same size.') + matRad_cfg = MatRad_Config.instance(); + matRad_cfg.dispError('There are more couch angles than gantry angles. They have to have the same size.'); %Try to identify the removed beam angles [removedAngles,ix] = setdiff(oldAngles,this.gantryAngles); @@ -241,7 +243,7 @@ function initialize(this) % Show progress if matRad_cfg.logLevel > 2 - matRad_progress(i,length(this.gantryAngles),1); + matRad_progress(i,length(this.gantryAngles)); end %% visualization @@ -383,11 +385,6 @@ function initialize(this) pause(1); end - - % Show progress - if matRad_cfg.logLevel > 2 - matRad_progress(i,length(this.gantryAngles),2); - end end end diff --git a/matRad/util/matRad_progress.m b/matRad/util/matRad_progress.m index 7037751ce..d14e56f88 100644 --- a/matRad/util/matRad_progress.m +++ b/matRad/util/matRad_progress.m @@ -1,5 +1,4 @@ -function matRad_progress(currentIndex, totalNumberOfEvaluations,scen) -% matRad progress bar +function matRad_progress(currentIndex, totalNumberOfEvaluations) % % call % matRad_progress(currentIndex, totalNumberOfEvaluations) @@ -28,29 +27,13 @@ function matRad_progress(currentIndex, totalNumberOfEvaluations,scen) % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -persistent isInitialized - -if isempty(isInitialized) - isInitialized = true; -end - -percent = (currentIndex / totalNumberOfEvaluations) * 100; - -% --- first part of the progress --- -if scen == 1 - % new line + percent = (currentIndex / totalNumberOfEvaluations) * 100; + fprintf('\rProgress: %6.2f %%', percent); -end - -% --- for scenario 2, same line --- -if scen == 2 - fprintf(' Progress: %6.2f %%', percent); -end - -% --- finish line after the last angle --- -if currentIndex == totalNumberOfEvaluations && scen == 2 - fprintf('\n'); - clear isInitialized + + if currentIndex == totalNumberOfEvaluations + fprintf('\n'); + end end From b180fa007492d2bf21309407c4ebdffcdfeacb57 Mon Sep 17 00:00:00 2001 From: Niklas Wahl Date: Mon, 30 Mar 2026 13:35:11 +0200 Subject: [PATCH 3/4] Updates the progress function to accept an optional "linereset" parameter that tells the progress update that it needs to reset itself to a new line --- .../matRad_DoseEngineBase.m | 9 ++++-- .../matRad_PencilBeamEngineAbstract.m | 4 ++- matRad/util/matRad_progress.m | 30 ++++++++++++++----- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/matRad/doseCalc/+DoseEngines/@matRad_DoseEngineBase/matRad_DoseEngineBase.m b/matRad/doseCalc/+DoseEngines/@matRad_DoseEngineBase/matRad_DoseEngineBase.m index 1fcd1da6c..4595c2730 100644 --- a/matRad/doseCalc/+DoseEngines/@matRad_DoseEngineBase/matRad_DoseEngineBase.m +++ b/matRad/doseCalc/+DoseEngines/@matRad_DoseEngineBase/matRad_DoseEngineBase.m @@ -377,13 +377,16 @@ function setDefaults(this) end - function progressUpdate(this,pos,total) + function progressUpdate(this,pos,total,linereset) % This function updates the progress of the dose calculation process. % It can handle both absolute and relative progress updates. % If only one argument is provided, it assumes a relative progress % update from 0 to 1000. If two arguments are provided, it uses the % actual values to calculate the progress percentage. - + if nargin < 4 + linereset = false; + end + % Default total value handling if nargin < 3 pos = pos*1000; % Assume pos is a relative progress if total is not provided @@ -403,7 +406,7 @@ function progressUpdate(this,pos,total) % Log progress if the log level is high enough % This allows for detailed tracking of the calculation progress in logs if matRad_cfg.logLevel > 2 - matRad_progress(pos,total); % Log the progress + matRad_progress(pos,total,linereset); % Log the progress end % Update the waitbar with the current progress if it exists diff --git a/matRad/doseCalc/+DoseEngines/matRad_PencilBeamEngineAbstract.m b/matRad/doseCalc/+DoseEngines/matRad_PencilBeamEngineAbstract.m index 6d647af0e..583729fce 100644 --- a/matRad/doseCalc/+DoseEngines/matRad_PencilBeamEngineAbstract.m +++ b/matRad/doseCalc/+DoseEngines/matRad_PencilBeamEngineAbstract.m @@ -111,6 +111,7 @@ function setDefaults(this) %Initialize Beam Geometry currBeam = this.initBeam(dij,ct,cst,scenStf,i); + progressLineReset = true; %Keep tabs on bixels computed in this beam bixelBeamCounter = 0; @@ -148,7 +149,8 @@ function setDefaults(this) % Progress Update & Bookkeeping bixelCounter = bixelCounter + currRay.numOfBixels; bixelBeamCounter = bixelBeamCounter + currRay.numOfBixels; - this.progressUpdate(bixelCounter,dij.totalNumOfBixels); + this.progressUpdate(bixelCounter,dij.totalNumOfBixels,progressLineReset); + progressLineReset = false; end end end diff --git a/matRad/util/matRad_progress.m b/matRad/util/matRad_progress.m index d14e56f88..d4bcbf8df 100644 --- a/matRad/util/matRad_progress.m +++ b/matRad/util/matRad_progress.m @@ -1,4 +1,4 @@ -function matRad_progress(currentIndex, totalNumberOfEvaluations) +function matRad_progress(currentIndex, totalNumberOfEvaluations, linereset) % % call % matRad_progress(currentIndex, totalNumberOfEvaluations) @@ -6,6 +6,7 @@ function matRad_progress(currentIndex, totalNumberOfEvaluations) % input % currentIndex: current iteration index % totalNumberOfEvaluations: maximum iteration index +% linereset: (optional) reset output to new line % % output % graphical display of progess. make sure there is no other output @@ -27,13 +28,26 @@ function matRad_progress(currentIndex, totalNumberOfEvaluations) % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - percent = (currentIndex / totalNumberOfEvaluations) * 100; - - fprintf('\rProgress: %6.2f %%', percent); - - if currentIndex == totalNumberOfEvaluations - fprintf('\n'); - end +if nargin < 3 + linereset = false; +end + +% If it's not the first step, erase the stuff printed before +if (currentIndex == 1 || linereset) + fprintf('Progress: '); +else + length = numel(sprintf('%3.2f %%',(currentIndex-1)/totalNumberOfEvaluations*100)); + fprintf(repmat('\b',1,length)); +end + +% Print the progress tool +fprintf('%3.2f %%',currentIndex/totalNumberOfEvaluations*100); + +% After the last iteration print a newline command +if (currentIndex == totalNumberOfEvaluations) + fprintf('\n'); +end + end From b4e5dceddbae35b9ac1f52cb8507aab57c1453c6 Mon Sep 17 00:00:00 2001 From: lisaseckler Date: Thu, 2 Apr 2026 11:11:01 +0200 Subject: [PATCH 4/4] Updated stf generator base file Error is now only coming from StfGeneratorExternalRayBixelAbstract --- matRad/steering/matRad_StfGeneratorBase.m | 3 --- 1 file changed, 3 deletions(-) diff --git a/matRad/steering/matRad_StfGeneratorBase.m b/matRad/steering/matRad_StfGeneratorBase.m index ce0792aea..e269d7671 100644 --- a/matRad/steering/matRad_StfGeneratorBase.m +++ b/matRad/steering/matRad_StfGeneratorBase.m @@ -146,9 +146,6 @@ function assignPropertiesFromPln(this,pln,warnWhenPropertyChanged) %ones given in the propStf struct if isfield(pln,'propStf') && isstruct(pln.propStf) plnStruct = pln.propStf; %get remaining fields - if numel(plnStruct.gantryAngles) ~= numel(plnStruct.couchAngles) - matRad_cfg.dispError('Inconsistent number of couch and gantry angles. Select the same number!'); - end if isfield(plnStruct,'generator') && ~isempty(plnStruct.generator) && ~any(strcmp(plnStruct.generator,this.shortName)) matRad_cfg.dispWarning('Inconsistent stf generators given! pln asks for ''%s'', but you are using ''%s''!',plnStruct.generator,this.shortName); end