-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExportableDVHs.cs
551 lines (478 loc) · 27.9 KB
/
ExportableDVHs.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
// MIT License
//
// Copyright(c) 2022 Danish Centre for Particle Therapy
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
using System.IO;
using System.Linq;
using VMS.TPS.Common.Model.API;
using VMS.TPS.Common.Model.Types;
namespace Evaluering4D
{
/// <summary>
/// A class that creates the files for DVH export. The format is adjusted such that it is nice to import into matlab.
/// All structures for the main plan are exported in one file.
/// All structures for each of the phase-plans are exported in separate files.
/// If there are uncertainty scenarios on the main plan, these are exported in separate files as well.
/// </summary>
internal class ExportableDVHs
{
public PlanSetup[] AllPlans { get; }
public string[] AllPlanIds { get; }
public string Folder { get; }
public double DvhResolution { get; }
/// <summary>
/// The constructor for the class. All plans are needed, the folder to save in and the resolution of the DVHs in Gy selected by the user.
/// </summary>
/// <param name="allPlans">A vector with all plans to export</param>
/// <param name="folder">The folder to save the files</param>
/// <param name="dvhresolution">The resolution of the exported dvh</param>
public ExportableDVHs(PlanSetup[] allPlans, string folder, double dvhresolution)
{
AllPlans = allPlans;
Folder = folder;
DvhResolution = dvhresolution;
int numberPlans = allPlans.Length;
AllPlanIds = new string[numberPlans];
for (int i = 0; i < numberPlans; i++) AllPlanIds[i] = allPlans[i].Id;
}
/// <summary>
/// All DVHs are saved to files
/// </summary>
internal void SaveAll()
{
//Loopeing over all the plans
for (int i = 0; i < AllPlanIds.Count(); i++)
{
if (!AllPlans[i].IsDoseValid) continue; //If the plans for some reason are not calculated. This can happen if a materials tabel is missing.
string filename = AllPlanIds[i];
string firstLine = "Plan id: " + AllPlanIds[i] + " calculated on CT: " + AllPlans[i].StructureSet.Image.Id;
string modalityLine = "Modality: " + AllPlans[i].PlanType.ToString() + ", Dose grid size [cm]: [" + AllPlans[i].Dose.XRes.ToString("0.00") + ", " + AllPlans[i].Dose.YRes.ToString("0.00") + ", " + AllPlans[i].Dose.ZRes.ToString("0.00") + "], Number of fractions: " + AllPlans[i].NumberOfFractions.ToString() + ", Prescribed dose: " + AllPlans[0].TotalDose.Dose.ToString("0.00") + " Gy" + Environment.NewLine;
//Data is collected in a large matrix and we need to determine the size first, by finding the largest DVH for all structures and the number of structures..
int largestDVH = FindLargestDVH(AllPlans[i], DvhResolution);
int numbOfStructs = FindNumberOfStructs(AllPlans[i]);
double[,] dvhList = new double[largestDVH, numbOfStructs + 1];
FillValues(dvhList, AllPlans[i], largestDVH, DvhResolution);
string[] idList = new string[numbOfStructs + 1];
FillIDs(idList, AllPlans[i]);
double[] volList = new double[numbOfStructs];
FillIVols(volList, AllPlans[i]);
double[] minList = new double[numbOfStructs];
double[] maxList = new double[numbOfStructs];
double[] meanList = new double[numbOfStructs];
double[] D005List = new double[numbOfStructs];
double[] D050List = new double[numbOfStructs];
double[] D100List = new double[numbOfStructs];
double[] D500List = new double[numbOfStructs];
// The header consists of the volume of the structure, the min, max and mean dose and D0.05cc, D0.5cc and D1cc DVH'points as they need a high resolution of the extracted DVH which is not provided.
FillIminmaxmean(minList, maxList, meanList, D005List,D050List,D100List, D500List, AllPlans[i], DvhResolution);
WriteDVHfile(Folder, filename, dvhList, idList, numbOfStructs, largestDVH, firstLine, volList, minList, maxList, meanList,D005List, D050List, D100List, D500List, modalityLine); //MULTI
}
//We are checking if the nominal plan has uncertainty scenarios. If yes we need to export them as well.
if (AllPlans[0].PlanUncertainties.Count() != 0)
{
string modalityLine = "Modality: " + AllPlans[0].PlanType.ToString() + ", Dose grid size [cm]: [" + AllPlans[0].Dose.XRes.ToString("0.00") + ", " + AllPlans[0].Dose.YRes.ToString("0.00") + ", " + AllPlans[0].Dose.ZRes.ToString("0.00") + "], Number of fractions: " + AllPlans[0].NumberOfFractions.ToString() + ", Prescribed dose: " + AllPlans[0].TotalDose.Dose.ToString("0.00") + " Gy" + Environment.NewLine;
foreach (var uncert in AllPlans[0].PlanUncertainties)
{
if (uncert.Dose == null) continue;
string filename = AllPlans[0].Id.Substring(0, 2) + "_" + uncert.Id;
string firstLine = "Uncertainty scenario: " + uncert.DisplayName + " to nominal plan: " + AllPlans[0].Id + " calculated on CT: " + AllPlans[0].StructureSet.Image.Id;
//Data is collected in a large matrix and we need to determine the size first.
int largestDVH = FindLargestDVH(AllPlans[0], uncert, DvhResolution);
int numbOfStructs = FindNumberOfStructs(AllPlans[0]);
double[,] dvhList = new double[largestDVH, numbOfStructs + 1];
FillValues(dvhList, AllPlans[0], largestDVH, uncert, DvhResolution); // Values for the uncertainty scenario
string[] idList = new string[numbOfStructs + 1];
FillIDs(idList, AllPlans[0]); // Same value as for the nominal
double[] volList = new double[numbOfStructs];
FillIVols(volList, AllPlans[0]); // Same value as for the nominal
double[] minList = new double[numbOfStructs];
double[] maxList = new double[numbOfStructs];
double[] meanList = new double[numbOfStructs];
double[] D005List = new double[numbOfStructs];
double[] D050List = new double[numbOfStructs];
double[] D100List = new double[numbOfStructs];
double[] D500List = new double[numbOfStructs];
FillIminmaxmean(minList, maxList, meanList, D005List, D050List, D100List, D500List, AllPlans[0], uncert, DvhResolution); // Values for the uncertainty scenario
WriteDVHfile(Folder, filename, dvhList, idList, numbOfStructs, largestDVH, firstLine, volList, minList, maxList, meanList, D005List, D050List, D100List, D500List, modalityLine);
}
}
}
/// <summary>
/// Calculates the min, max and mean dose values for all structures in a plan and added to three lists with the correct format.
/// </summary>
/// <param name="minList">List of min dose for each structure</param>
/// <param name="maxList">List of max dose for each structure</param>
/// <param name="meanList">List of mean dose for each structure</param>
/// <param name="D005List"> List of D0.05cc values in Gy </param>
/// <param name="D050List">List of D0.5cc values in Gy</param>
/// <param name="D100List">List of D1.0cc values in Gy</param>
/// <param name="D500List">List of D5.0cc values in Gy</param>
/// <param name="planSetup">The single plan to extract from</param>
/// <param name="dvhresolution">The dvh resolution</param>
private void FillIminmaxmean(double[] minList, double[] maxList, double[] meanList, double[] D005List, double[] D050List, double[] D100List, double[] D500List, PlanSetup planSetup, double dvhresolution)
{
int countStruct = 0;
for (int j = 0; j < planSetup.StructureSet.Structures.Count(); j++)
{
if (planSetup.StructureSet.Structures.ElementAt(j) == null || planSetup.StructureSet.Structures.ElementAt(j).IsEmpty || planSetup.StructureSet.Structures.ElementAt(j).DicomType.ToLower() == "support")
{
continue;
}
DVHData dvhdata = planSetup.GetDVHCumulativeData(planSetup.StructureSet.Structures.ElementAt(j), DoseValuePresentation.Absolute, VolumePresentation.Relative, dvhresolution);
minList[countStruct] = dvhdata.MinDose.Dose;
maxList[countStruct] = dvhdata.MaxDose.Dose;
meanList[countStruct] = dvhdata.MeanDose.Dose;
//We need a high resolution for the volume datapoints
DVHData dvhdata2 = planSetup.GetDVHCumulativeData(planSetup.StructureSet.Structures.ElementAt(j), DoseValuePresentation.Absolute, VolumePresentation.AbsoluteCm3, 0.0001);
D005List[countStruct] = CalculateDXXcc(dvhdata2.CurveData, 0.05, planSetup.TotalDose.Dose);
D050List[countStruct] = CalculateDXXcc(dvhdata2.CurveData, 0.5, planSetup.TotalDose.Dose);
D100List[countStruct] = CalculateDXXcc(dvhdata2.CurveData, 1.0, planSetup.TotalDose.Dose);
D500List[countStruct] = CalculateDXXcc(dvhdata2.CurveData, 5.0, planSetup.TotalDose.Dose);
countStruct++;
}
}
/// <summary>
/// Calculates the min, max and mean dose values for all structures in a plan and added to three lists with the correct format.
/// </summary>
/// <param name="minList">List of min dose for each structure</param>
/// <param name="maxList">List of max dose for each structure</param>
/// <param name="meanList">List of mean dose for each structure</param>
/// <param name="D005List"> List of D0.05cc values in Gy </param>
/// <param name="D050List">List of D0.5cc values in Gy</param>
/// <param name="D100List">List of D1.0cc values in Gy</param>
/// <param name="D500List">List of D5.0cc values in Gy</param>
/// <param name="planSetup">The plan to extract from</param>
/// <param name="dvhresolution">The dvh resolution</param>
private void FillIminmaxmean(double[] minList, double[] maxList, double[] meanList, double[] D005List, double[] D050List, double[] D100List, double[] D500List, PlanSetup planSetup, PlanUncertainty uncert, double dvhresolution)
{
int countStruct = 0;
for (int j = 0; j < planSetup.StructureSet.Structures.Count(); j++)
{
if (planSetup.StructureSet.Structures.ElementAt(j) == null || planSetup.StructureSet.Structures.ElementAt(j).IsEmpty || planSetup.StructureSet.Structures.ElementAt(j).DicomType.ToLower() == "support")
{
continue;
}
DVHData dvhdata = uncert.GetDVHCumulativeData(planSetup.StructureSet.Structures.ElementAt(j), DoseValuePresentation.Absolute, VolumePresentation.Relative, dvhresolution);
minList[countStruct] = dvhdata.MinDose.Dose;
maxList[countStruct] = dvhdata.MaxDose.Dose;
meanList[countStruct] = dvhdata.MeanDose.Dose;
//We need a high resolution for the volume datapoints
DVHData dvhdata2 = uncert.GetDVHCumulativeData(planSetup.StructureSet.Structures.ElementAt(j), DoseValuePresentation.Absolute, VolumePresentation.AbsoluteCm3, 0.0001);
D005List[countStruct] = CalculateDXXcc(dvhdata2.CurveData,0.05,planSetup.TotalDose.Dose);
D050List[countStruct] = CalculateDXXcc(dvhdata2.CurveData, 0.5, planSetup.TotalDose.Dose);
D100List[countStruct] = CalculateDXXcc(dvhdata2.CurveData, 1.0, planSetup.TotalDose.Dose);
D500List[countStruct] = CalculateDXXcc(dvhdata2.CurveData, 5.0, planSetup.TotalDose.Dose);
countStruct++;
}
}
/// <summary>
/// Calculates the volume of all structures in a plan and add them to the volList with the correct format.
/// </summary>
/// <param name="volList">Volume of each structure</param>
/// <param name="planSetup">The plansetup to extract from</param>
private void FillIVols(double[] volList, PlanSetup planSetup)
{
int countStruct = 0;
for (int j = 0; j < planSetup.StructureSet.Structures.Count(); j++)
{
if (planSetup.StructureSet.Structures.ElementAt(j) == null || planSetup.StructureSet.Structures.ElementAt(j).IsEmpty || planSetup.StructureSet.Structures.ElementAt(j).DicomType.ToLower() == "support")
{
continue;
}
volList[countStruct] = planSetup.StructureSet.Structures.ElementAt(j).Volume;
countStruct++;
}
}
/// <summary>
/// The file is now written and saved for the given plan or uncertaintyscenario by collecting all the lists for the IDs, DVH values, mean, max, mean doses and volumes.
/// </summary>
/// <param name="v">The path to save to</param>
/// <param name="filename">The file name</param>
/// <param name="dvhList">DVH values</param>
/// <param name="idList">The structure ids</param>
/// <param name="numbOfStructs">Number of structures</param>
/// <param name="largestDVH">The larges DVH size</param>
/// <param name="firstLine">A string with the first line of the file</param>
/// <param name="volList">All volumes</param>
/// <param name="minList">All minimum doses</param>
/// <param name="maxList">All maximum doses</param>
/// <param name="meanList">All mean doses</param>
/// <param name="D005List"> All D0.05cc values in Gy </param>
/// <param name="D050List">All D0.5cc values in Gy</param>
/// <param name="D100List">All D1.0cc values in Gy</param>
///<param name="D500List">All D5.0cc values in Gy</param>
/// <param name="modalityLine">Line descriping modality, resolution of dose and fractionation</param>
private void WriteDVHfile(string v, string filename, double[,] dvhList, string[] idList, int numbOfStructs, int largestDVH, string firstLine, double[] volList, double[] minList, double[] maxList, double[] meanList, double[] D005List, double[] D050List, double[] D100List, double[] D500List, string modalityLine)
{
string lines = firstLine + Environment.NewLine;
lines += modalityLine;
//Structure IDs are added
string temp = "";
for (int p = 0; p < numbOfStructs + 1; p++)
{
temp += idList[p] + "\t";
}
lines += temp + Environment.NewLine;
temp = "Volume [cc] \t";
for (int p = 0; p < numbOfStructs; p++)
{
temp += Math.Round(volList[p],3, MidpointRounding.AwayFromZero).ToString("0.000") + "\t";
}
lines += temp + Environment.NewLine;
temp = "Min dose [Gy] \t";
for (int p = 0; p < numbOfStructs; p++)
{
temp += Math.Round(minList[p],3, MidpointRounding.AwayFromZero).ToString("0.000") + "\t";
}
lines += temp + Environment.NewLine;
temp = "Max dose [Gy] \t";
for (int p = 0; p < numbOfStructs; p++)
{
temp += Math.Round(maxList[p], 3, MidpointRounding.AwayFromZero).ToString("0.000") + "\t";
}
lines += temp + Environment.NewLine;
temp = "Mean dose [Gy] \t";
for (int p = 0; p < numbOfStructs; p++)
{
temp += Math.Round(meanList[p], 3, MidpointRounding.AwayFromZero).ToString("0.000") + "\t";
}
lines += temp + Environment.NewLine;
temp = "D0.05cc [Gy] \t";
for (int p = 0; p < numbOfStructs; p++)
{
temp += Math.Round(D005List[p], 3, MidpointRounding.AwayFromZero).ToString("0.000") + "\t";
}
lines += temp + Environment.NewLine;
temp = "D0.5cc [Gy] \t";
for (int p = 0; p < numbOfStructs; p++)
{
temp += Math.Round(D050List[p], 3, MidpointRounding.AwayFromZero).ToString("0.000") + "\t";
}
lines += temp + Environment.NewLine;
temp = "D1cc [Gy] \t";
for (int p = 0; p < numbOfStructs; p++)
{
temp += Math.Round(D100List[p], 3, MidpointRounding.AwayFromZero).ToString("0.000") + "\t";
}
lines += temp + Environment.NewLine;
temp = "D5cc [Gy] \t";
for (int p = 0; p < numbOfStructs; p++)
{
temp += Math.Round(D500List[p], 3, MidpointRounding.AwayFromZero).ToString("0.000") + "\t";
}
lines += temp + Environment.NewLine;
//Numbers are added
for (int h = 0; h < largestDVH; h++)
{
temp = "";
for (int p = 0; p < numbOfStructs + 1; p++)
{
temp += Math.Round(dvhList[h, p],3, MidpointRounding.AwayFromZero).ToString("0.000") + "\t";
}
lines += temp + Environment.NewLine;
}
File.WriteAllText(v + "\\" + filename + ".txt", lines);
}
/// <summary>
/// DVH values are filled into the correct format defined by the dvhList.
/// </summary>
/// <param name="dvhList">The list with DVH values for all structures</param>
/// <param name="planSetup">The plan setup</param>
/// <param name="largestDVH">Size of the largest DVH</param>
/// <param name="dvhresolution">DVH resolution</param>
private void FillValues(double[,] dvhList, PlanSetup planSetup, int largestDVH, double dvhresolution)
{
//First collumn is filled with dose values
dvhList[0, 0] = 0.0;
for (int j = 1; j < largestDVH; j++)
{
dvhList[j, 0] = dvhList[j - 1, 0] + dvhresolution;
}
//Here we start by 1 as the first column is the dose
//We will find all struyctures to fill in.
int countStruct = 1;
for (int j = 0; j < planSetup.StructureSet.Structures.Count(); j++)
{
if (planSetup.StructureSet.Structures.ElementAt(j) == null || planSetup.StructureSet.Structures.ElementAt(j).IsEmpty || planSetup.StructureSet.Structures.ElementAt(j).DicomType.ToLower() == "support")
{
continue;
}
DVHData dvhdata = planSetup.GetDVHCumulativeData(planSetup.StructureSet.Structures.ElementAt(j), DoseValuePresentation.Absolute, VolumePresentation.Relative, dvhresolution);
DVHPoint[] dvh = dvhdata.CurveData;
if (dvh.Count() == 0) continue;
for (int p = 0; p < dvh.Count(); p++)
{
dvhList[p, countStruct] = dvh[p].Volume;
}
countStruct++;
}
}
/// <summary>
/// DVH values are filled into the correct format defined by the dvhList.
/// </summary>
/// <param name="dvhList">The list with DVH values for all structures</param>
/// <param name="planSetup">The plan setup</param>
/// <param name="largestDVH">Size of the largest DVH</param>
/// <param name="uncert">Uncertainty scenario</param>
/// <param name="dvhresolution">DVH resolution</param>
private void FillValues(double[,] dvhList, PlanSetup planSetup, int largestDVH, PlanUncertainty uncert, double dvhresolution)
{
//First collumn is filled with dose values
dvhList[0, 0] = 0.0;
for (int j = 1; j < largestDVH; j++)
{
dvhList[j, 0] = dvhList[j - 1, 0] + dvhresolution;
}
//Here we start by 1 as the first column is the dose
//We will find all struyctures to fill in.
int countStruct = 1;
for (int j = 0; j < planSetup.StructureSet.Structures.Count(); j++)
{
if (planSetup.StructureSet.Structures.ElementAt(j) == null || planSetup.StructureSet.Structures.ElementAt(j).IsEmpty || planSetup.StructureSet.Structures.ElementAt(j).DicomType.ToLower() == "support")
{
continue;
}
DVHData dvhdata = uncert.GetDVHCumulativeData(planSetup.StructureSet.Structures.ElementAt(j), DoseValuePresentation.Absolute, VolumePresentation.Relative, dvhresolution);
DVHPoint[] dvh = dvhdata.CurveData;
if (dvh.Count() == 0) continue;
for (int p = 0; p < dvh.Count(); p++)
{
dvhList[p, countStruct] = dvh[p].Volume;
}
countStruct++;
}
}
/// <summary>
/// Structure ids are filled into the correct format defined by the idList.
/// </summary>
/// <param name="idList">A list of structure ids</param>
/// <param name="planSetup">The plansetup</param>
private void FillIDs(string[] idList, PlanSetup planSetup)
{
idList[0] = "Dose (Gy)";
int countStruct = 1;
for (int j = 0; j < planSetup.StructureSet.Structures.Count(); j++)
{
if (planSetup.StructureSet.Structures.ElementAt(j) == null || planSetup.StructureSet.Structures.ElementAt(j).IsEmpty || planSetup.StructureSet.Structures.ElementAt(j).DicomType.ToLower() == "support")
{
continue;
}
idList[countStruct] = planSetup.StructureSet.Structures.ElementAt(j).Id;
countStruct++;
}
}
/// <summary>
/// Determining the number of structures with a non zero contour.
/// </summary>
/// <param name="planSetup">The plansetup</param>
/// <returns></returns>
private int FindNumberOfStructs(PlanSetup planSetup)
{
//Looper over all structers as we have to count them.
int numb = 0;
for (int j = 0; j < planSetup.StructureSet.Structures.Count(); j++)
{
if (planSetup.StructureSet.Structures.ElementAt(j) == null || planSetup.StructureSet.Structures.ElementAt(j).IsEmpty || planSetup.StructureSet.Structures.ElementAt(j).DicomType.ToLower() == "support")
{
continue;
}
numb++;
}
return numb;
}
/// <summary>
/// Determining the largest DVH curve for all relevant structures of a plan.
/// </summary>
/// <param name="planSetup">Plansetup</param>
/// <param name="dvhresolution">DVH resolution</param>
/// <returns></returns>
private int FindLargestDVH(PlanSetup planSetup, double dvhresolution)
{
//Looper over all structers as we have to count them.
int dvhsize = 0;
for (int j = 0; j < planSetup.StructureSet.Structures.Count(); j++)
{
if (planSetup.StructureSet.Structures.ElementAt(j) == null || planSetup.StructureSet.Structures.ElementAt(j).IsEmpty || planSetup.StructureSet.Structures.ElementAt(j).DicomType.ToLower() == "support")
{
continue;
}
DVHData dvhdata = planSetup.GetDVHCumulativeData(planSetup.StructureSet.Structures.ElementAt(j), DoseValuePresentation.Absolute, VolumePresentation.Relative, dvhresolution);
DVHPoint[] dvh = dvhdata.CurveData;
if (dvh.Count() >= dvhsize)
dvhsize = dvh.Count();
}
return dvhsize;
}
/// <summary>
/// Determining the largest DVH curve for all relevant structures of a plan.
/// </summary>
/// <param name="planSetup">Plansetup</param>
/// <param name="uncert">Uncertainty scenario</param>
/// <param name="dvhresolution">DVH resolution</param>
/// <returns></returns>
private int FindLargestDVH(PlanSetup planSetup, PlanUncertainty uncert, double dvhresolution)
{
//Looper over all structers as we have to count them.
int dvhsize = 0;
for (int j = 0; j < planSetup.StructureSet.Structures.Count(); j++)
{
if (planSetup.StructureSet.Structures.ElementAt(j) == null || planSetup.StructureSet.Structures.ElementAt(j).IsEmpty || planSetup.StructureSet.Structures.ElementAt(j).DicomType.ToLower() == "support")
{
continue;
}
DVHData dvhdata = uncert.GetDVHCumulativeData(planSetup.StructureSet.Structures.ElementAt(j), DoseValuePresentation.Absolute, VolumePresentation.Relative, dvhresolution);
DVHPoint[] dvh = dvhdata.CurveData;
if (dvh.Count() >= dvhsize)
dvhsize = dvh.Count();
}
return dvhsize;
}
/// <summary>
/// Function for calculating the DVHpoints for the header
/// </summary>
/// <param name="DVH">The DVH data for a structure</param>
/// <param name="XXcc">The volume to read off the dose in</param>
/// <param name="prescribedDose">The prescribed dose for the plan</param>
/// <returns></returns>
private double CalculateDXXcc(DVHPoint[] DVH, double XXcc, double prescribedDose)
{
if (DVH == null || DVH.Count() == 0 || DVH.Max(d => d.Volume) < XXcc)
{
return -1000.0;
}
else
{
DVHPoint test = DVH.FirstOrDefault(d => d.Volume <= XXcc);
if (test.DoseValue == null)
{
return -1000.0;
}
if (test.DoseValue.IsAbsoluteDoseValue)
{
return test.DoseValue.Dose;
}
else
{
return test.DoseValue.Dose * prescribedDose;
}
}
}
}
}