function output = measureScase(varargin) measureSCaseStart = tic; Logger.start("measureSCase"); config = getConfig(); % Initialise cases if nargin > 0 casesToMeasure = [string(varargin)]; else casesToMeasure = config.casesToMeasure; end if config.overwriteMeasurements SCases = createEmptySCase(casesToMeasure); else SCases = loadSCase(casesToMeasure); end % Run measurements for i = 1:length(SCases) SCaseStart = tic; Logger.newDelimitedSection(SCases(i).id); if config.runMeasurements.loadData Logger.logn(""); SCases(i).patient.loadData(); end if config.shouldersToMeasure.rightAuto Logger.newDelimitedSection("Shoulder Right Auto"); runShoulderMeasurements(SCases(i).shoulders.right.auto); Logger.closeSection(); end if config.shouldersToMeasure.rightManual Logger.newDelimitedSection("Shoulder Right Manual"); runShoulderMeasurements(SCases(i).shoulders.right.manual); Logger.closeSection(); end if config.shouldersToMeasure.leftAuto Logger.newDelimitedSection("Shoulder Left Auto"); runShoulderMeasurements(SCases(i).shoulders.left.auto); Logger.closeSection(); end if config.shouldersToMeasure.leftManual Logger.newDelimitedSection("Shoulder Left Manual"); runShoulderMeasurements(SCases(i).shoulders.left.manual); Logger.closeSection(); end Logger.newDelimitedSection(... sprintf("SCase measured in %.2fs", toc(SCaseStart))); Logger.closeBlock(); end % Save results if config.saveMeasurements saveMeasurements(SCases); end if config.saveAllMeasurementsInOneFile saveAllMeasurementsInOneFile(SCases, casesToMeasure); end Logger.newDelimitedSection(... sprintf("Whole measureSCase() ran in %.2fs", toc(measureSCaseStart))); Logger.stop(); output = SCases; end function runShoulderMeasurements(shoulder) shoulderStart = tic; config = getConfig(); % Measurements if config.runMeasurements.loadData shoulder.loadData(); end if shoulder.isempty() Logger.logn("Not enough data loaded to perform further measurements.") return end if config.runMeasurements.sliceAndSegmentRotatorCuffMuscles Logger.newDelimitedSection("Segment"); Logger.logn(""); Logger.timeLogExecution("Slice and segment rotator cuff muscles: ",... @(shoulder) shoulder.rotatorCuff.sliceAndSegment(), shoulder); Logger.closeSection(); end if config.runMeasurements.morphology shoulder.morphology(); end if config.runMeasurements.measureFirst shoulder.measureFirst(); end if config.runMeasurements.measureSecond shoulder.measureSecond(); end if config.runMeasurements.measureGlenoidDensity Logger.newDelimitedSection("Glenoid density"); Logger.logn(""); Logger.timeLogExecution("Glenoid density: ",... @(shoulder) shoulder.scapula.glenoid.measureDensity(), shoulder); Logger.closeSection(); end Logger.newDelimitedSection(... sprintf("Shoulder measured in %.2fs", toc(shoulderStart))); Logger.closeSection(); end function saveMeasurements(SCases) savingStart = tic; Logger.log("Saving new measurements: ") try arrayfun(@(SCase) SCase.saveMatlab, SCases); Logger.logn("Done in %.2fs", toc(savingStart)); catch ME Logger.logn(ME.message); end end function saveAllMeasurementsInOneFile(SCases, casesToMeasure) savingStart = tic; Logger.log("Saving whole database in one file: ") try if not(isequal(casesToMeasure, "*")) SCaseDB = loadSCase("*"); else SCaseDB = SCases; end save(fullfile(getConfig().dataDir, "matlab", "SCaseDB.mat"), "SCaseDB"); Logger.logn("Done in %.2fs", toc(savingStart)); catch ME Logger.logn(ME.message); end end