-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPDPlotViewModel.txt
99 lines (91 loc) · 3.4 KB
/
PDPlotViewModel.txt
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
private string _patientID;
public string PatientId
{
get { return _patientID; }
set { SetProperty(ref _patientID,value); }
}
private PDPlanSetup _selectedPlan;
public PDPlanSetup SelectedPlan
{
get { return _selectedPlan; }
set
{
SetProperty(ref _selectedPlan,value);
if (SelectedPlan != null)
{
Fields.Clear();
foreach(var beam in SelectedPlan.Beams)
{
Fields.Add(beam);
}
}
}
}
private PDBeam _selectedField;
public PDBeam SelectedField
{
get { return _selectedField; }
set
{
SetProperty(ref _selectedField,value);
if (SelectedField != null)
{
CalculateFieldSize();
}
}
}
private string _fieldSize;
private Application _app;
public string FieldSize
{
get { return _fieldSize; }
set {SetProperty(ref _fieldSize,value); }
}
public ObservableCollection<PDPlanSetup> Plans { get; private set; }
public ObservableCollection<PDBeam> Fields { get; private set; }
public PlotModel ProfilePlotModel { get; set; }
public DelegateCommand OpenPatientCommand { get; private set; }
public MainViewModel(Application app)
{
_app = app;
Plans = new ObservableCollection<PDPlanSetup>();
Fields = new ObservableCollection<PDBeam>();
OpenPatientCommand = new DelegateCommand(OnOpenPatient);
ProfilePlotModel = new PlotModel()
{
Title = "PD Profile"
};
}
private void OnOpenPatient()
{
Patient patient = _app.OpenPatientById(PatientId);
if (patient != null)
{
Plans.Clear();
foreach (var plan in patient.PDPlanSetups)
{
Plans.Add(plan);
}
}
}
private void CalculateFieldSize()
{
var image = SelectedField.PortalDoseImages.First();//get first portal image.
var frame = image.Image.FramesRT.First();//PD images only have one framme.
var profile = frame.GetImageProfile(
new VMS.CA.Scripting.VVector(0, frame.YSize / 2.0, 0),
new VMS.CA.Scripting.VVector(frame.XSize, frame.YSize / 2.0, 0),
new double[frame.XSize + 1]);
ProfilePlotModel.Series.Clear();
var series = new LineSeries();
foreach(var point in profile)
{
series.Points.Add(new DataPoint(point.Position.x, point.Value));
}
ProfilePlotModel.Series.Add(series);
ProfilePlotModel.InvalidatePlot(true);//notifypropertychanged of a series.
var center = profile.FirstOrDefault(p => p.Position.x >= frame.XSize / 2.0).Value;
var first50 = profile.FirstOrDefault(p => p.Value >= center*0.50).Position.x;
var last50 = profile.LastOrDefault(p => p.Value >= center*0.50).Position.x;
FieldSize = $"{(last50 - first50)*frame.XRes / 10.0:F3}";
}