/// <summary> /// Performs the actual work not the most efficient way but I'll work it out /// </summary> public void Evaluate(IMathematics mathematics, bool fuzzy) { Model.DoseMatrixOptimal sourceDose = new Model.DoseMatrixOptimal(_source.DoseMatrix()); Model.DoseMatrixOptimal targetDose = new Model.DoseMatrixOptimal(_target.DoseMatrix()); TotalCount = targetDose.Length; Debug.WriteLine("\n\n\nEvaluating " + _source.FileName + " and " + _target.FileName + " Dimensions disagree"); Debug.WriteLine("Max dose: Source - " + sourceDose.MaxPointDose.Dose + " Target - " + targetDose.MaxPointDose.Dose); Tuple <int, int> ret; for (int i = 0; i < _dtas.Length; i++) { if (_dtas[i].Relative) { ret = mathematics.CompareRelative(sourceDose, targetDose, _dtas[i].Tolerance, _dtas[i].Threshhold, fuzzy); } else { ret = mathematics.CompareAbsolute(sourceDose, targetDose, _dtas[i].Tolerance, _dtas[i].Threshhold, fuzzy); } _comparisons[i] = new Controller.SingleComparison(); _comparisons[i].TotalCompared = ret.Item2; _comparisons[i].TotalFailed = ret.Item1; _comparisons[i]._dta = _dtas[0]; } IsEvaluated = true; }
/// <summary> /// Performs the actual work not the most efficient way but I'll work it out /// </summary> public void Evaluate(IMathematics mathematics) { Model.DoseMatrixOptimal sourceDose = new Model.DoseMatrixOptimal(_source.DoseMatrix()); Model.DoseMatrixOptimal targetDose = new Model.DoseMatrixOptimal(_target.DoseMatrix()); TotalCount = targetDose.Length; Debug.WriteLine("\n\n\nEvaluating " + _source.FileName + " and " + _target.FileName + " Dimensions disagree"); Debug.WriteLine("Max dose: Source - " + sourceDose.MaxPointDose.Dose + " Target - " + targetDose.MaxPointDose.Dose); Model.SingleComparison ret; for (int i = 0; i < _dtas.Length; i++) { if (_dtas[i].Relative) { ret = mathematics.CompareRelative(sourceDose, targetDose, _dtas[i]); } else { ret = mathematics.CompareAbsolute(sourceDose, targetDose, _dtas[i]); } _comparisons[i] = ret; } IsEvaluated = true; }
/// <summary> /// Performs the actual work not the most efficient way but I'll work it out /// </summary> public void Evaluate(IMathematics mathematics, bool fuzzy) { Model.DoseMatrixOptimal sourceDose = new Model.DoseMatrixOptimal(_source.DoseMatrix()); Model.DoseMatrixOptimal targetDose = new Model.DoseMatrixOptimal(_target.DoseMatrix()); TotalCount = targetDose.Length; if (sourceDose.CompareDimensions(targetDose)) //if (false) { Debug.WriteLine("\n\n\nEvaluating " + _source.FileName + " and " + _target.FileName); Tuple <int, int> ret; ret = mathematics.CompareAbsolute(sourceDose, targetDose, TightTol, ThreshholdTol, fuzzy); TotalFailedTightTolAbs = ret.Item1; TotalComparedTightTolAbs = ret.Item2; if (ret.Item1 == 0) // if failed tightest evaluation skip further evaluation Requires tight < main to work. { TotalFailedMainTolAbs = ret.Item1; TotalComparedMainTolAbs = ret.Item2; TotalFailedTightTolRel = ret.Item1; TotalComparedTightTolRel = ret.Item2; TotalFailedMainTolRel = ret.Item1; TotalComparedMainTolRel = ret.Item2; } else { ret = mathematics.CompareAbsolute(sourceDose, targetDose, MainTol, ThreshholdTol, fuzzy); TotalFailedMainTolAbs = ret.Item1; TotalComparedMainTolAbs = ret.Item2; ret = mathematics.CompareRelative(sourceDose, targetDose, TightTol, ThreshholdTol, fuzzy); TotalFailedTightTolRel = ret.Item1; TotalComparedTightTolRel = ret.Item2; ret = mathematics.CompareRelative(sourceDose, targetDose, MainTol, ThreshholdTol, fuzzy); TotalFailedMainTolRel = ret.Item1; TotalComparedMainTolRel = ret.Item2; } IsEvaluated = true; } else { Debug.WriteLine("\n\n\nEvaluating " + _source.FileName + " and " + _target.FileName + " Dimensions disagree"); Debug.WriteLine("Max dose: Source - " + sourceDose.MaxPointDose.Dose + " Target - " + targetDose.MaxPointDose.Dose); Tuple <int, int> ret; ret = mathematics.CompareAbsolute(sourceDose, targetDose, TightTol, ThreshholdTol, fuzzy); TotalFailedTightTolAbs = ret.Item1; TotalComparedTightTolAbs = ret.Item2; if (ret.Item1 == 0) { TotalFailedMainTolAbs = ret.Item1; TotalComparedMainTolAbs = ret.Item2; TotalFailedTightTolRel = ret.Item1; TotalComparedTightTolRel = ret.Item2; TotalFailedMainTolRel = ret.Item1; TotalComparedMainTolRel = ret.Item2; } else { ret = mathematics.CompareAbsolute(sourceDose, targetDose, MainTol, ThreshholdTol, fuzzy); TotalFailedMainTolAbs = ret.Item1; TotalComparedMainTolAbs = ret.Item2; ret = mathematics.CompareRelative(sourceDose, targetDose, TightTol, ThreshholdTol, fuzzy); TotalFailedTightTolRel = ret.Item1; TotalComparedTightTolRel = ret.Item2; ret = mathematics.CompareRelative(sourceDose, targetDose, MainTol, ThreshholdTol, fuzzy); TotalFailedMainTolRel = ret.Item1; TotalComparedMainTolRel = ret.Item2; } IsEvaluated = true; } }
public DscDataHandler(DicomStrictCompare.Controller.Settings settings) { this.Settings = settings; DosePairsList = new ConcurrentBag <MatchedDosePair>(); mathematics = new X86Mathematics(); }
public DscDataHandler() { DosePairsList = new ConcurrentBag <MatchedDosePair>(); mathematics = new X86Mathematics(); }
public void Run(bool runDoseComparisons, bool runPDDComparisons, string SaveDirectory, object sender) { // Maximum number of CPU threads ParallelOptions cpuParallel = new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount }; //ParallelOptions cpuParallel = new ParallelOptions { MaxDegreeOfParallelism = 1 }; ParallelOptions parallel = cpuParallel; // Sets the system to use the correct resources without doubling down on GPU mathematics = new X86Mathematics(); parallel = cpuParallel; double progress = 0; #region safetyChecks try { _ = SourceDirectory.IsNormalized(); } catch (NullReferenceException) { throw new NullReferenceException("Source directory cannot be null"); } try { _ = TargetDirectory.IsNormalized(); } catch (NullReferenceException) { throw new NullReferenceException("Target directory cannot be null");; } if (SourceListStrings.Length <= 0) { throw new InvalidOperationException("There are no Dose files in the source directory Tree"); } if (TargetListStrings.Length <= 0) { throw new InvalidOperationException("There are no Dose files in the Target directory Tree"); } #endregion #region setup (sender as BackgroundWorker).ReportProgress((int)progress, "Setup: Scanning Source Doses "); SourceDosesList = FileHandler.DoseFiles(SourceListStrings); (sender as BackgroundWorker).ReportProgress((int)progress, "Setup: Scanning Source Plans "); SourcePlanList = FileHandler.PlanFiles(SourceListStrings); (sender as BackgroundWorker).ReportProgress((int)progress, "Setup: Scanning Target Doses "); TargetDosesList = FileHandler.DoseFiles(TargetListStrings); (sender as BackgroundWorker).ReportProgress((int)progress, "Setup: Scanning Target Plans "); TargetPlanList = FileHandler.PlanFiles(TargetListStrings); #endregion DosePairsList = new ConcurrentBag <MatchedDosePair>(); progress += 5; (sender as BackgroundWorker).ReportProgress((int)progress, "Scanning Source Folder"); _ = Parallel.ForEach(SourceDosesList, new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount }, doseFile => { doseFile.SetFieldName(SourcePlanList); }); progress += 5; (sender as BackgroundWorker).ReportProgress((int)progress, "Scanning Target Folder"); _ = Parallel.ForEach(TargetDosesList, new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount }, doseFile => { doseFile.SetFieldName(TargetPlanList); }); double ProgressIncrimentor = 10.0 / TargetDosesList.Count; (sender as BackgroundWorker).ReportProgress((int)progress, "Matching"); // match each pair for analysis _ = Parallel.ForEach(TargetDosesList, cpuParallel, (dose) => { progress += ProgressIncrimentor; progress %= 100; (sender as BackgroundWorker).ReportProgress((int)progress, "Matching"); var sourceDose = SourceDosesList.Find(x => x.MatchIdentifier == dose.MatchIdentifier); if (sourceDose != null) { Debug.WriteLine("matched " + dose.FileName + " and " + sourceDose.FileName); DosePairsList.Add(new MatchedDosePair(sourceDose, dose, Settings)); } }); if (DosePairsList.Count <= 0) { return; } progress = 39; ProgressIncrimentor = 30.0 / DosePairsList.Count; progress %= 100; (sender as BackgroundWorker).ReportProgress((int)progress, "PDD Production"); if (runPDDComparisons) { _ = Parallel.ForEach(DosePairsList, cpuParallel, pair => { progress += ProgressIncrimentor; progress %= 100; (sender as BackgroundWorker).ReportProgress((int)progress, "PDD Production"); pair.GeneratePDD(); Debug.WriteLine("Saving " + pair.ChartTitle + " to " + SaveDirectory); try { SaveFile saveFile = new SaveFile(pair.ChartTitle, SaveDirectory); pair.PDDoutString = saveFile.Save(pair.SourcePDD, pair.TargetPDD, pair.ChartFileName, SaveDirectory, pair.ChartTitle, SourceAliasName, TargetAliasName); } catch (Exception) { Debug.WriteLine("Failed to save " + pair.ChartTitle); } }); progress = 69; //fix for memory abuse is to limit the number of cores, Arbitrarily I have hard coded it to half the logical cores of the system. if (runDoseComparisons) { ProgressIncrimentor = 30.0 / DosePairsList.Count; ResultMessage += MatchedDosePair.StaticResultHeader(Settings.Dtas); _ = Parallel.ForEach(DosePairsList, parallel, pair => { progress += ProgressIncrimentor; progress %= 100; (sender as BackgroundWorker).ReportProgress((int)progress, "Comparing " + progress); try { pair.Evaluate(mathematics, Settings.Fuzzy); ResultMessage += pair.ResultString + '\n'; } // Will catch array misalignment problems catch (Exception e) { string temp = pair.Name + ",Was not Evaluated ,\n"; ResultMessage += temp; Debug.WriteLine(temp); Debug.WriteLine(e.Message.ToString()); Debug.Write(e.StackTrace.ToString()); } }); } } }