-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileBrowser.xaml.cs
739 lines (637 loc) · 33.3 KB
/
FileBrowser.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
using VMS.TPS;
using VMS.TPS.Common.Model.API;
using VMS.TPS.Common.Model.Types;
namespace ProfileComparison
{
/// <summary>
/// The FileBrowser class contains the interaction methods for FileBrowser.xaml. It is called from ProfileComparison.cs
/// </summary>
/// <param name="context">ScriptContext that contains the API handle to the patient currently open in Eclipse</param>
public partial class FileBrowser : UserControl
{
public ScriptContext context;
// chartHeight and chartWidth are used when drawing profiles and must match the size of the uiChartArea canvas
// in FileBrowser.xaml. In the future I would like the code to determine these values automatically and support
// dynamic resizing. Alas, for another day.
readonly double chartHeight = 370;
readonly double chartWidth = 539;
// FileBrowser constructor
public FileBrowser()
{
InitializeComponent();
// Initialize chart area with sine and cosine waves. The variable res specifies the resolution of the lines
// that are used when drawing the waves (using a for loop from 1 to res).
double res = 700;
for (int i = 0; i < res; i++)
{
// Add a red line segment to the uiChartArea canvas representing the sine wave
uiChartArea.Children.Add(new Line()
{
X1 = i / res * chartWidth,
X2 = (i + 1) / res * chartWidth,
Y1 = (Math.Sin(i * 10 / res) + 1) * chartHeight / 2,
Y2 = (Math.Sin((i + 1) * 10 / res) + 1) * chartHeight / 2,
Stroke = Brushes.Red,
StrokeThickness = 1
});
// Add a blue line segment to the uiChartArea canvas representing the cosine wave
uiChartArea.Children.Add(new Line()
{
X1 = i * chartWidth / res,
X2 = (i + 1) / res * chartWidth,
Y1 = (Math.Cos(i * 10 / res) + 1) * chartHeight / 2,
Y2 = (Math.Cos((i + 1) * 10 / res) + 1) * chartHeight / 2,
Stroke = Brushes.Blue,
StrokeThickness = 1
});
}
}
/// <summary>
/// interp is a helper function called by CompareProfiles several times to perform linear interpolation
/// between two points: (x0,y0) and (x1,y1) at the point x.
/// </summary>
/// <param name="x">double</param>
/// <param name="x0">double</param>
/// <param name="x1">double</param>
/// <param name="y0">double</param>
/// <param name="y1">double</param>
/// <returns>the interpolated value of y as a double</returns>
public static double interp(double x, double x0, double x1, double y0, double y1)
{
// Special case if x1 == x0
if ((x1 - x0) == 0)
{
return (y0 + y1) / 2;
}
// Otherwise, return the standard equation for linear interpolation
return y0 + (x - x0) * (y1 - y0) / (x1 - x0);
}
// BrowseFile is called when the Browse button is clicked, opens the file browser dialog.
// The resulting file locating is sent back to the UI.
private void BrowseFile(object sender, RoutedEventArgs e)
{
// Clear all results fields and the chart canvas
ClearResults();
uiChartArea.Children.Clear();
// Open a new file selection dialog with the following parameters
OpenFileDialog fileDialog = new OpenFileDialog();
fileDialog.Filter = "SNCTXT Files (*.snctxt)|*.snctxt";
fileDialog.Title = "Select the water tank profile...";
fileDialog.Multiselect = false;
var success = fileDialog.ShowDialog();
// If the user selected a file, update the file name input box (if not, leave the existing value).
if ((bool)success)
{
uiFile.Text = fileDialog.FileName;
}
}
// ValidateSigma is called whenever the sigma input field is changed, to validate and reformat the input
private void ValidateSigma(object sender, KeyboardFocusChangedEventArgs e)
{
// First try to parse the input text as a number (the regex automatically removes the units)
Double.TryParse(Regex.Match(uiSigma.Text, @"\d+\.*\d*").Value, out double t);
if (t > 0)
{
// If successful, store the parsed number to three decimal precision with mm units
t = Math.Round(t * 1000) / 1000;
uiSigma.Text = t.ToString() + " mm";
}
else
// If not successful, revert the field to the default value
uiSigma.Text = "0.000 mm";
// Clear all results fields
ClearResults();
}
// ValidateTruncation is called whenever the threshold input field is changed, to validate and reformat the input
private void ValidateTruncation(object sender, KeyboardFocusChangedEventArgs e)
{
// First try to parse the input text as a number (the regex automatically removes the units)
Double.TryParse(Regex.Match(uiTruncation.Text, @"\d+\.*\d*").Value, out double t);
if (t > 0)
{
// If successful, store the parsed number to single decimal precision with the mm units
t = Math.Round(t * 1000) / 1000;
uiTruncation.Text = t.ToString() + " mm";
}
else
// If not successful, revert the field to the default value
uiTruncation.Text = "0.000 mm";
// Clear all results fields
ClearResults();
}
// ValidateTruncation is called whenever the threshold input field is changed, to validate and reformat the input
private void ValidateDTA(object sender, KeyboardFocusChangedEventArgs e)
{
// First try to parse the input text as a number (the regex automatically removes the units)
Double.TryParse(Regex.Match(uiDTA.Text, @"\d+\.*\d*").Value, out double t);
if (t > 0)
{
// If successful, store the parsed number to single decimal precision with the mm units
t = Math.Round(t * 10) / 10;
uiDTA.Text = t.ToString() + " mm";
}
else
// If not successful, revert the field to the default value
uiDTA.Text = "1.0 mm";
// Clear all results fields
ClearResults();
}
// ValidateThreshold is called whenever the threshold input field is changed, to validate and reformat the input
private void ValidateThreshold(object sender, KeyboardFocusChangedEventArgs e)
{
// First try to parse the input text as a number (the regex automatically removes the units)
Double.TryParse(Regex.Match(uiThreshold.Text, @"\d+\.*\d*").Value, out double t);
if (t >= 0)
{
// If successful, store the parsed number to single decimal precision with a percent symbol
t = Math.Round(t * 10) / 10;
uiThreshold.Text = t.ToString() + "%";
}
else
// If not successful, revert the field to the default value
uiThreshold.Text = "20.0%";
// Clear all results fields
ClearResults();
}
// ValidatePercent is called whenever the Gamma percent input field is changed, to validate and reformat the input
private void ValidatePercent(object sender, KeyboardFocusChangedEventArgs e)
{
// First try to parse the input text as a number (the regex automatically removes the % symbol)
Double.TryParse(Regex.Match(uiPercent.Text, @"\d+\.*\d*").Value, out double t);
if (t > 0)
{
// If successful, store the parsed number to single decimal precision with a percent symbol
t = Math.Round(t * 10) / 10;
uiPercent.Text = t.ToString() + "%";
}
else
// If not successful, revert the field to the default value
uiPercent.Text = "1.0%";
// Clear all results fields
ClearResults();
}
// ClearResults is called whenever an input variable is changed and clears the results text boxes
private void ClearResults()
{
uiDmeas.Text = "";
uiDcalc.Text = "";
uiDdiff.Text = "";
uiFmeas.Text = "";
uiFcalc.Text = "";
uiFdiff.Text = "";
uiLPass.Text = "";
uiLAvg.Text = "";
uiLMax.Text = "";
uiLC80.Text = "";
uiGPass.Text = "";
uiGAvg.Text = "";
uiGMax.Text = "";
uiGC80.Text = "";
}
// CompareProfiles is called when the form button is clicked and compares the dose volume of the current plan to
// the selected text file. The results are reported back to the UI and the profiles are plotted.
private void CompareProfiles(object sender, RoutedEventArgs e)
{
// If the user has not selected a text file yet, inform them that is a required step
if (uiFile.Text == "")
{
MessageBox.Show("You must select a SNC TXT file first");
return;
}
// Run ParseSNCTXT to extract the first profile from the selected file
List<Profile> txt = Script.ParseSNCTXT(uiFile.Text);
// Extract a line dose from the current planned dose using the coordinates from the SNC TXT profile, converting
// to DICOM coordinates using the UserToDicom ESAPI function
VVector start = context.Image.UserToDicom(txt.First().Position, context.PlanSetup);
VVector end = context.Image.UserToDicom(txt.Last().Position, context.PlanSetup);
// Set the TPS resolution equal to 10X the DTA (this is a reasonable balance between gamma calculation accuracy
// and computation speed; increasing this multiplier will increase gamma accuracy but with diminishing returns)
Double.TryParse(Regex.Match(uiDTA.Text, @"\d+\.*\d*").Value, out double dta);
DoseProfile tpsProfile = context.PlanSetup.Dose.GetDoseProfile(start, end,
new double[(int)Math.Ceiling((end - start).Length / dta * 10)]);
// Store the DoseProfile object as Profile list, converting the coordinates back from DICOM and normalizing
// to the maximum value along the profile
List<Profile> tps = new List<Profile>();
double maxval = 0;
foreach (ProfilePoint point in tpsProfile)
{
Profile nextRow = new Profile();
nextRow.Position = context.Image.DicomToUser(point.Position, context.PlanSetup);
nextRow.Value = point.Value;
tps.Add(nextRow);
if (point.Value > maxval)
{
maxval = point.Value;
}
}
// Initialize a new list to store the convolved TPS profile. Convolving the TPS makes the comparison to the
// measurement more accurate, as it can account for measurement parameters such as detector size or scan speed
List<Profile> convtps = new List<Profile>();
// Retrieve the convolution parameters from the UI
Double.TryParse(Regex.Match(uiSigma.Text, @"\d+\.*\d*").Value, out double sigma);
Double.TryParse(Regex.Match(uiTruncation.Text, @"\d+\.*\d*").Value, out double trunc);
// If the convolution filter parameter is zero, skip convolution
if (sigma == 0)
{
convtps = tps;
}
// Otherwise, apply a truncated Gaussian convolution to the TPS profile
else
{
// Precalculate the denominator of filter to increase computation speed
sigma = 2 * Math.Pow(sigma, 2);
// Initialize flags to keep track of edge conditions
bool firstEdge;
bool lastEdge;
// Loop through each point in the TPS profile
foreach (Profile point in tps)
{
// Initialize a new convoluted value at the same position with an initial value of zero
Profile nextRow = new Profile
{
Position = point.Position,
Value = 0
};
// If the point is too close to the start of the profile, set the startEdge flag
if ((point.Position - tps.First().Position).Length <= trunc / 2)
{
firstEdge = true;
}
else
{
firstEdge = false;
}
// If the point is too close to the end of the profile, set the lastEdge flag
if ((point.Position - tps.Last().Position).Length <= trunc / 2)
{
lastEdge = true;
}
else
{
lastEdge = false;
}
// Loop through the TPS profile again (yes, Fourier Transform would be faster, but this keeps it simple)
foreach (Profile filter in tps)
{
// If the distance between the filter position and the profile point exceeds the truncation distance,
// do not apply the filter
if ((point.Position - filter.Position).Length > trunc)
continue;
// Otherwise, apply the Gaussian convolution based on the distance along the filter and the sigma parameter
// provided by the user
else
{
// If the point and filter positions are the same, don't apply the filter (exp(0) = 1)
if (point.Position.Equals(filter.Position))
{
nextRow.Value += filter.Value;
}
// If the point's position is near the the starting edge of the profile such that the filter is cutoff, mirror
// it to prevent the edge effect (by mirror, double its value)
else if (firstEdge && (point.Position - filter.Position).Length > (point.Position - tps.First().Position).Length)
{
nextRow.Value += 2 * filter.Value * Math.Exp(-Math.Pow((point.Position - filter.Position).Length, 2) / sigma);
}
// If the point's position is near the the back edge of the profile such that the filter is cutoff
else if (lastEdge && (point.Position - filter.Position).Length > (point.Position - tps.Last().Position).Length)
{
nextRow.Value += 2 * filter.Value * Math.Exp(-Math.Pow((point.Position - filter.Position).Length, 2) / sigma);
}
// If neither condition, just apply the regular filter (with no edge conditions)
else
{
nextRow.Value += filter.Value * Math.Exp(-Math.Pow((point.Position - filter.Position).Length, 2) / sigma);
}
}
}
// Keep track of the convolved TPS profile max value so that it can be renormalized
if (nextRow.Value > maxval)
{
maxval = nextRow.Value;
}
// Add the convolved point to the Profile list
convtps.Add(nextRow);
}
}
// Normalize the convolved profile back to 100%
foreach (Profile point in convtps)
{
point.Value = point.Value / maxval * 100;
}
// Initialize temporary variable to store rounded statistics
double t;
// Initialize temporary variablse to store FWHM and center (used for central 80% determination) using the full profile. If a valid
// FWHM is found later, we will use that instead
double fwhm = (txt.Last().Position - txt.First().Position).Length;
VVector center = (txt.Last().Position + txt.First().Position) / 2;
// Initialize temporary variable to store max depth (used for depth profiles)
double maxdepth = 0;
// If the depth axis changes, assume this is a depth profile, so calculate PDD or R50 (based on if it is an photon or electron)
if (Math.Abs(txt.First().Position[1] - txt.Last().Position[1]) > 10)
{
// Initialize measured (SNC TXT) and calculated (TPS) depth metric variables
double dmeas = 0;
double dcalc = 0;
// Loop through the profile to find max depth (use the measured profile)
for (int i = 1; i < txt.Count(); i++)
{
if (txt[i].Value == 100)
{
maxdepth = txt[i].Position[1];
break;
}
}
// If the treatment beam energy contains an "E", it is an Electron beam, so calculate R50 (note, this assumes that the first
// beam is the one that was used to calculate dose; there may be a better way to determine this)
if (context.PlanSetup.Beams.First().EnergyModeDisplayName.Contains('E'))
{
// Loop through the SNC TXT profile using indices (necessary since [i] and [i-1] are looked at together)
for (int i = 1; i < txt.Count(); i++)
{
// If the values at [i] and [i-1] are above and below R50
if (Math.Sign(txt[i - 1].Value - 50) != Math.Sign(txt[i].Value - 50))
{
// Interpolate between the depths at [i] and [i-1] to determine R50
dmeas = interp(50, txt[i - 1].Value, txt[i].Value, txt[i - 1].Position[1], txt[i].Position[1]);
// Round and update the UI with the SNC TXT R50 value
t = Math.Round(dmeas * 10) / 100;
uiDmeas.Text = t.ToString() + " cm";
// End the for loop, as R50 was found
break;
}
}
// Loop through the convolved TPS profile using indices (necessary since [i] and [i-1] are looked at together)
for (int i = 1; i < convtps.Count(); i++)
{
// If the values at [i] and [i-1] are above and below R50
if (Math.Sign(convtps[i - 1].Value - 50) != Math.Sign(convtps[i].Value - 50))
{
// Interpolate between the depths at [i] and [i-1] to determine R50
dcalc = interp(50, convtps[i - 1].Value, convtps[i].Value, convtps[i - 1].Position[1], convtps[i].Position[1]);
// Round and update the UI with the convolved TPS R50 value
t = Math.Round(dcalc * 10) / 100;
uiDcalc.Text = t.ToString() + " cm";
// End the for loop, as R50 was found
break;
}
}
// If both the SNC TXT and TPS R50 values were found
if (dmeas != 0 && dcalc != 0)
{
// Calculate and round the difference between the two, then report to the UI
t = Math.Round((dcalc - dmeas) * 10) / 100;
uiDdiff.Text = t.ToString() + " cm";
}
}
// Otherwise, if "E" is not present in the beam energy, this is a photon energy, so calculate PDD(10)
else
{
// Loop through the SNC TXT profile using indices (necessary since [i] and [i-1] are looked at together)
for (int i = 1; i < txt.Count(); i++)
{
// If the depth at [i] and [i-1] are above and below 10 cm
if (Math.Sign(txt[i - 1].Position[1] - 100) != Math.Sign(txt[i].Position[1] - 100))
{
// Interpolate between [i] and [i-1] to PDD(10)
dmeas = interp(100, txt[i - 1].Position[1], txt[i].Position[1], txt[i - 1].Value, txt[i].Value);
// Round and update the UI with the SNC TXT PDD(10) value
t = Math.Round(dmeas * 100) / 100;
uiDmeas.Text = t.ToString() + "%";
// End the for loop, as PDD(10) was found
break;
}
}
// Loop through the convolved TPS profile using indices (necessary since [i] and [i-1] are looked at together)
for (int i = 1; i < convtps.Count(); i++)
{
// If the depth at [i] and [i-1] are above and below 10 cm
if (Math.Sign(convtps[i - 1].Position[1] - 100) != Math.Sign(convtps[i].Position[1] - 100))
{
// Interpolate between [i] and [i-1] to PDD(10)
dcalc = interp(100, convtps[i - 1].Position[1], convtps[i].Position[1],
convtps[i - 1].Value, convtps[i].Value);
// Round and update the UI with the convolved TPS PDD(10) value
t = Math.Round(dcalc * 100) / 100;
uiDcalc.Text = t.ToString() + "%";
// End the for loop, as PDD(10) was found
break;
}
}
// If both the SNC TXT and TPS PDD(10) values were found
if (dmeas != 0 && dcalc != 0)
{
// Calculate and round the difference between the two, then report to the UI
t = Math.Round((dcalc - dmeas) * 100) / 100;
uiDdiff.Text = t.ToString() + "%";
}
}
}
// Otherwise, if the depth does not change, calculate the FWHM of the profiles
else
{
// Run CalculateFWHM using the SNC TXT profile and store the resulting FWHM value
(double fmeas, VVector cmeas) = Script.CalculateFWHM(txt);
// If a valid FWHM was returned, round and report it to the UI
if (fmeas != 0)
{
fwhm = fmeas;
center = cmeas;
t = Math.Round(fmeas * 10) / 100;
uiFmeas.Text = t.ToString() + " cm";
}
// Run CalculateFWHM using the convolved TPS profile and store the resulting FWHM value
(double fcalc, VVector ccalc) = Script.CalculateFWHM(convtps);
// If a valid FWHM was returned, round and report it to the UI
if (fcalc != 0)
{
fwhm = fcalc;
center = ccalc;
t = Math.Round(fcalc * 10) / 100;
uiFcalc.Text = t.ToString() + " cm";
}
// If both a valid SNC TXT and convolved TPS FWHM were found, calculate and round the difference
if (fmeas != 0 && fcalc != 0)
{
t = Math.Round((fcalc - fmeas) * 10) / 100;
uiFdiff.Text = t.ToString() + " cm";
}
}
// Retrieve the other two gamma criteria from the UI (DTA was retrieved earlier when parsing the TPS profile)
Double.TryParse(Regex.Match(uiPercent.Text, @"\d+\.*\d*").Value, out double percent);
Double.TryParse(Regex.Match(uiThreshold.Text, @"\d+\.*\d*").Value, out double threshold);
// Execute CalculateGamma using the SNC TXT profile, convoluted TPS, and gamma criteria
List<Profile> gamma = Script.CalculateGamma(txt, convtps, percent, dta, threshold);
// Initialize the gamma statistics variables
double localPass = 0;
double globalPass = 0;
double localAverage = 0;
double globalAverage = 0;
double localMax = 0;
double globalMax = 0;
double localCentral = 0;
double globalCentral = 0;
double countCentral = 0;
// If a valid gamma Profile list was returned
if (gamma.Count > 0)
{
// Loop through the Profile list (remember, point.Value = local, point.Value2 = global)
foreach (Profile point in gamma)
{
// If the local gamma value passed, increment the local pass rate
if (point.Value <= 1)
{
localPass++;
}
// Update the local average statistic
localAverage += point.Value;
// Update the local maximum gamma statistic
if (localMax < point.Value)
{
localMax = point.Value;
}
// If the global gamma value passed, increment the global pass rate
if (point.Value2 <= 1)
{
globalPass++;
}
// Update the global average statistic
globalAverage += point.Value2;
// Update the local maximum gamma statistic
if (globalMax < point.Value2)
{
globalMax = point.Value2;
}
// If the profile point is within the central 80% of the FWHM or beyond the maximum depth
if (maxdepth > 0 && point.Position[1] > maxdepth)
{
// Count the total number of central 80% values
countCentral++;
// Count the number of central 80% local pass values
if (point.Value <= 1)
{
localCentral++;
}
// Count the number of central 80% global pass values
if (point.Value2 <= 1)
{
globalCentral++;
}
}
else if (fwhm > 0 && (point.Position - center).Length < fwhm * 0.4)
{
// Count the total number of central 80% values
countCentral++;
// Count the number of central 80% local pass values
if (point.Value <= 1)
{
localCentral++;
}
// Count the number of central 80% global pass values
if (point.Value2 <= 1)
{
globalCentral++;
}
}
}
// Finish the pass rate statistics (pass rate = sum passed / total number of points * 100)
localPass = localPass / gamma.Count * 100;
globalPass = globalPass / gamma.Count * 100;
// Finish the average statistics (average = sum / total number of points)
localAverage /= gamma.Count;
globalAverage /= gamma.Count;
// Round and update the UI for all gamma statistics
t = Math.Round((localPass) * 10) / 10;
uiLPass.Text = t.ToString() + "%";
t = Math.Round((localAverage) * 100) / 100;
uiLAvg.Text = t.ToString();
t = Math.Round((localMax) * 100) / 100;
uiLMax.Text = t.ToString();
t = Math.Round((globalPass) * 10) / 10;
uiGPass.Text = t.ToString() + "%";
t = Math.Round((globalAverage) * 100) / 100;
uiGAvg.Text = t.ToString();
t = Math.Round((globalMax) * 100) / 100;
uiGMax.Text = t.ToString();
// Round and update the UI for central 80% values, if FWHM was calculated
if (maxdepth > 0 || fwhm > 0)
{
localCentral = localCentral / countCentral * 100;
globalCentral = globalCentral / countCentral * 100;
t = Math.Round((localCentral) * 10) / 10;
uiLC80.Text = t.ToString() + "%";
t = Math.Round((globalCentral) * 10) / 10;
uiGC80.Text = t.ToString() + "%";
// Set label based on value
if (maxdepth > 0)
{
uiLabel.Content = "Below Dmax";
}
else
{
uiLabel.Content = "Central 80";
}
}
}
// Clear the Chart Area of all previous profiles
uiChartArea.Children.Clear();
// Draw the SNC TXT Profile using red lines
double xscale = chartWidth / (txt.Last().Position - txt.First().Position).Length;
for (int i = 1; i < txt.Count; i++)
{
uiChartArea.Children.Add(new Line()
{
X1 = (txt[i - 1].Position - txt.First().Position).Length * xscale,
X2 = (txt[i].Position - txt.First().Position).Length * xscale,
Y1 = (chartHeight - 20) * (100 - txt[i - 1].Value) / 100 + 20,
Y2 = (chartHeight - 20) * (100 - txt[i].Value) / 100 + 20,
Stroke = Brushes.Red,
StrokeThickness = 1
});
}
// Draw the convolved TPS Profile using blue lines (skip NaN values)
xscale = chartWidth / (convtps.Last().Position - convtps.First().Position).Length;
for (int i = 1; i < convtps.Count; i++)
{
if (Double.IsNaN(convtps[i - 1].Value) || Double.IsNaN(convtps[i].Value))
{
continue;
}
uiChartArea.Children.Add(new Line()
{
X1 = (convtps[i - 1].Position - convtps.First().Position).Length * xscale,
X2 = (convtps[i].Position - convtps.First().Position).Length * xscale,
Y1 = (chartHeight - 20) * (100 - convtps[i - 1].Value) / 100 + 20,
Y2 = (chartHeight - 20) * (100 - convtps[i].Value) / 100 + 20,
Stroke = Brushes.Blue,
StrokeThickness = 1
});
}
// Plot global gamma profile (note, the scale X axis is scaled based on the SNC TXT profile as the gamma
// profile may not contain the same dimensions as the other two profiles due to thresholding. Also, the
// Y axis scale is dynamically set to exither the maximum gamma value or a gamma value of 1)
xscale = chartWidth / (txt.Last().Position - txt.First().Position).Length;
for (int i = 1; i < gamma.Count; i++)
{
uiChartArea.Children.Add(new Line()
{
X1 = (gamma[i - 1].Position - txt.First().Position).Length * xscale,
X2 = (gamma[i].Position - txt.First().Position).Length * xscale,
Y1 = chartHeight * (Math.Max(1, globalMax) - gamma[i - 1].Value2) / Math.Max(1, globalMax),
Y2 = chartHeight * (Math.Max(1, globalMax) - gamma[i].Value2) / Math.Max(1, globalMax),
Stroke = Brushes.LightGray,
StrokeThickness = 1
});
}
}
}
}