Beispiel #1
0
 private void field_ddl_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     //enable the field lists
     //comp_ddl.IsEnabled = true;
     if (field_ddl.SelectedIndex == -1)
     {
         MessageBox.Show("Select a field to analyze");
     }
     else
     {
         field = plan.Beams.Where(i => i.Id == field_ddl.SelectedItem.ToString()).First();
         meas_ddl.IsEnabled = true;
         comp_ddl.Items.Clear();
         meas_ddl.Items.Clear();
         //comp_ddl.Items.Add("");
         //first the portal dose images
         foreach (PortalDoseImage pdi in field.PortalDoseImages)
         {
             meas_ddl.Items.Add(pdi.Id);
         }
         //each field only has one predicted dose image so force the predicted dose image when the portal dose image is selected.
         if (field.PredictedDoseImage != null)
         {
             comp_ddl.Items.Add(field.PredictedDoseImage.Id);
             comp_ddl.SelectedValue = field.PredictedDoseImage.Id;
         }
         else
         {
             //there is no predicted image.
             comp_ddl.Items.Add("No Predicted Image");
             comp_ddl.SelectedIndex = 0;
             //this exact string will be handled in GammaPassMatrix.xaml.cs file.
         }
     }
 }
Beispiel #2
0
 public ShowImageModel(PDBeam pDBeam)
 {
     MVs = pDBeam.PortalDoseImages.SelectMany(e => e.Image.Frames).Select(x => new MVImage(x, pDBeam.PDPlanSetup.PlanSetup.Course.Id,
                                                                                           pDBeam.PDPlanSetup.PlanSetup.Id + pDBeam.Id));
 }
        private void calc_btn_Click(object sender, RoutedEventArgs e)
        {
            //pulling initial values from the MainWindow class.
            newcontext = PD_AdvAnalysis.MainWindow.newcontext;
            field      = PD_AdvAnalysis.MainWindow.field;
            if (newcontext == null)
            {
                MessageBox.Show("No Patient Selected.");
                return;
            }
            gamma_grd.Children.Clear();
            //here's where all the magic happens!!
            //check the fields are selected
            if (meas_ddl.SelectedIndex == -1)
            {
                MessageBox.Show("Please select a field");
            }
            else if (String.IsNullOrEmpty(startdd_txt.Text) || string.IsNullOrEmpty(startdta_txt.Text) || string.IsNullOrEmpty(enddd_txt.Text) || string.IsNullOrEmpty(enddta_txt.Text) || string.IsNullOrEmpty(deldd_txt.Text) || string.IsNullOrEmpty(deldta_txt.Text) || string.IsNullOrEmpty(tol_txt.Text))
            {
                MessageBox.Show("Please input all numeric parameters in the appropriate box");
            }
            else if (comp_ddl.SelectedItem.ToString() == "No Predicted Image")
            {
                MessageBox.Show("This field contains no predicted image.");
            }
            else
            {
                //check for any empty mandatory boxes with this bool.
                bool any_empty = false;
                //This portion of the code makes the textboxes red if they are empty
                List <Control> mandatory_boxes = new List <Control>()
                {
                    startdd_txt, enddd_txt, deldd_txt, startdta_txt, enddta_txt, deldta_txt, tol_txt
                };
                foreach (Control c in mandatory_boxes)
                {
                    double test_double;
                    if (!Double.TryParse((c as TextBox).Text, out test_double))
                    {
                        (c as TextBox).Focus();
                        (c as TextBox).BorderBrush     = Brushes.Red;
                        (c as TextBox).BorderThickness = new Thickness(2);
                        any_empty = true;
                    }
                    else
                    {
                        (c as TextBox).BorderBrush = Brushes.Transparent;
                    }
                }
                //this is testing to see if the the threshold percentage is added.
                if ((bool)threshold_chk.IsChecked)
                {
                    double test_double2;
                    if (!Double.TryParse((threshold_txt).Text, out test_double2))
                    {
                        (threshold_txt).Focus();
                        (threshold_txt).BorderBrush     = Brushes.Red;
                        (threshold_txt).BorderThickness = new Thickness(2);
                        any_empty = true;
                    }
                    else
                    {
                        (threshold_txt).BorderBrush = Brushes.Transparent;
                    }
                }
                //if the test contains a necessary test parameter, then make sure the test parameter is selected.
                //for instance, the test gamma area < _____ must be > ______ needs to have the parameters defined.
                int[] threshold_parm = new int[] { 4, 5, 8, 9, 12, 13 };

                if (threshold_parm.Contains(EvalTestKind_cmb.SelectedIndex))
                {
                    double test_double3;
                    if (!Double.TryParse((testparam_txt).Text, out test_double3))
                    {
                        (testparam_txt).Focus();
                        (testparam_txt).BorderBrush     = Brushes.Red;
                        (testparam_txt).BorderThickness = new Thickness(2);
                        any_empty = true;
                    }
                    else
                    {
                        (testparam_txt).BorderBrush = Brushes.Transparent;
                    }
                }
                //final catch in case any necessary inputs are missed.
                if (any_empty)
                {
                    return;
                }
                //get beams
                fieldm = field.PortalDoseImages.First(i => i.Id == meas_ddl.SelectedItem.ToString());
                //don't need to do the where clause for the predicted.
                double startdd = Convert.ToDouble(startdd_txt.Text); double endd = Convert.ToDouble(enddd_txt.Text); double deldd = Convert.ToDouble(deldd_txt.Text);
                double startdta = Convert.ToDouble(startdta_txt.Text); double enddta = Convert.ToDouble(enddta_txt.Text); double deldta = Convert.ToDouble(deldta_txt.Text);
                double tol = Convert.ToDouble(tol_txt.Text) / 100;
                double parm;
                Double.TryParse(testparam_txt.Text, out parm);

                //setup portal dosimetry analysis template.
                IEnumerable <EvaluationTestDesc> tested = new List <EvaluationTestDesc> {
                    new EvaluationTestDesc((EvaluationTestKind)EvalTestKind_cmb.SelectedIndex, parm, tol, false)
                };


                //new EvaluationTestDesc()
                //loop through all testable queries
                //columns go here.;
                //lay down the dta and dd labels.
                int bw = 50; int bh = 25;
                int marginx = bw; int marginy = bh;
                for (double i = startdd; i <= endd; i += deldd)
                {
                    TextBox dbox = new TextBox(); dbox.IsReadOnly = true; dbox.Text = String.Format("{0}%", i);
                    dbox.Width = bw; dbox.Background = Brushes.White; dbox.BorderBrush = Brushes.Black;
                    dbox.HorizontalAlignment = HorizontalAlignment.Left; dbox.VerticalAlignment = VerticalAlignment.Top;
                    dbox.Height = bh;
                    dbox.Margin = new Thickness(marginx, 0, 0, 0);
                    gamma_grd.Children.Add(dbox);
                    marginx += bw;
                }
                for (double j = startdta; j <= enddta; j += deldta)
                {
                    TextBox dbox = new TextBox(); dbox.IsReadOnly = true; dbox.Text = String.Format("{0}mm", j);
                    dbox.Width = bw; dbox.Background = Brushes.White; dbox.BorderBrush = Brushes.Black;
                    dbox.HorizontalAlignment = HorizontalAlignment.Left; dbox.VerticalAlignment = VerticalAlignment.Top;
                    dbox.Height = bh;
                    dbox.Margin = new Thickness(0, marginy, 0, 0);
                    marginy    += bh;
                    gamma_grd.Children.Add(dbox);
                }
                marginx = bw; marginy = 0;

                //now calculate all the boxes for the matrix.
                for (double i = startdta; i <= enddta; i += deldta)
                {
                    //lay down a new header for the column.
                    marginy += bh;
                    marginx  = 0;
                    //rows go here
                    double margins_txt;
                    Double.TryParse(marg_txt.Text, out margins_txt);
                    double th_txt;
                    double.TryParse(threshold_txt.Text, out th_txt);
                    int analysisMode = (bool)abs_rdb.IsChecked ? 0 : 2;
                    for (double j = startdd; j <= endd; j += deldd)
                    {
                        marginx += bw;
                        //lay down an initial grid for the dta and dd
                        TextBox header_box = new TextBox();
                        //modify the template
                        PDTemplate template1 = new PDTemplate(false, false, false, (AnalysisMode)analysisMode, (NormalizationMethod)Normalizaton_cmb.SelectedIndex, (bool)threshold_chk.IsChecked, th_txt, (ROIType)ROITypes_cmb.SelectedIndex, margins_txt, j / 100, i, false, tested);
                        //apply the template to the analysis.
                        PDAnalysis analysis = fieldm.CreateTransientAnalysis(template1, field.PredictedDoseImage);
                        //This code determines if the Gamma Test Parameters are in absolute or relative value
                        int[]  selec_in = new int[] { 0, 1, 4, 5, 8, 9, 12, 13 };
                        double gamma_pass;

                        if (selec_in.Contains(EvalTestKind_cmb.SelectedIndex))
                        {
                            gamma_pass = analysis.EvaluationTests.First().TestValue * 100;
                        }
                        else
                        {
                            gamma_pass = analysis.EvaluationTests.First().TestValue;
                        }
                        //The Code below shows the results from the gamma test. It is color coded to show where the gamma passes or failes.
                        TextBox gamma_box = new TextBox(); gamma_box.IsReadOnly = true; gamma_box.Text = gamma_pass.ToString("F3");
                        gamma_box.Width = bw; gamma_box.Height = bh; gamma_box.Background = gamma_pass < tol * 100 ? Brushes.Pink : Brushes.LightGreen; gamma_box.BorderBrush = Brushes.Black;
                        gamma_box.HorizontalAlignment = HorizontalAlignment.Left; gamma_box.VerticalAlignment = VerticalAlignment.Top;
                        gamma_box.Margin = new Thickness(marginx, marginy, 0, 0);
                        gamma_grd.Children.Add(gamma_box);
                    }
                }
            }
        }