Ejemplo n.º 1
0
        //private void TextBox_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
        //{
        //    VMMetric metric = ((FrameworkElement)sender).DataContext as VMMetric;
        //    TextBox txtBox = sender as TextBox;
        //    string paramName = txtBox.Name;

        //    DataGridRow row = dtaMetrics.ContainerFromElement(txtBox) as DataGridRow;
        //    if (row == null)
        //        return;

        //    int rowIndex = row.GetIndex();
        //    VMStructure struc = dtaMetrics.Items[rowIndex] as VMStructure;
        //}

        //private void TextBox_KeyDown(object sender, KeyEventArgs e)
        //{
        //    TextBox txtBox = sender as TextBox;
        //    if (e.Key == Key.Enter)
        //        Keyboard.ClearFocus();
        //}

        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            //Clear metric results to force recalc
            VMMetric metric = ((FrameworkElement)sender).DataContext as VMMetric;

            metric.ClearMetrics();
        }
Ejemplo n.º 2
0
        //private void btnDVH_Click(object sender, RoutedEventArgs e)
        //{
        //    UMRO.Utils.DVHViewer.DVHViewer viewer = new UMRO.Utils.DVHViewer.DVHViewer();
        //    viewer.PrescribedDose = (pItemOpen as PlanSetup).TotalPrescribedDose.Dose;

        //    foreach (var structure in _viewModel.Structures.Where(s => s.IsSelected))
        //    {
        //        foreach (var plan in PItemsInScope)
        //        {
        //            MyDVHData dvh = DVHDataModel.Instance.GetStdDVH(structure.Id, plan.Id, VMS.TPS.Common.Model.Types.DoseValuePresentation.Absolute, VMS.TPS.Common.Model.Types.VolumePresentation.AbsoluteCm3);
        //            if (dvh != null)
        //            {
        //                Point[] dvhPoints = new Point[dvh.CurveData.Count()];
        //                for (int i = 0; i < dvh.CurveData.Count(); i++)
        //                {
        //                    dvhPoints[i].X = dvh.CurveData[i].Dose;
        //                    dvhPoints[i].Y = dvh.CurveData[i].Volume;
        //                }

        //                viewer.AddCumulativeDVH(structure.Id + "-" + plan.Id, structure.Color, dvhPoints, "Gy");
        //            }
        //            //check if a biological corrected DVH has beem calculated
        //            VMMetric metric = structure.DoseMetrics.FirstOrDefault(s => s.UseBioDose);
        //            if (metric != null)
        //            {
        //                MyDVHData bioDvh = DVHDataModel.Instance.GetBioDVH(structure.Id, plan.Id, VMS.TPS.Common.Model.Types.VolumePresentation.AbsoluteCm3, metric);
        //                if (bioDvh != null)
        //                {
        //                    Point[] dvhPoints = new Point[bioDvh.CurveData.Count()];
        //                    for (int i = 0; i < bioDvh.CurveData.Count(); i++)
        //                    {
        //                        dvhPoints[i].X = bioDvh.CurveData[i].Dose;
        //                        dvhPoints[i].Y = bioDvh.CurveData[i].Volume;
        //                    }

        //                    viewer.AddCumulativeDVH(structure.Id + "-" + plan.Id + "(EQD2)", structure.Color, dvhPoints, "Gy");
        //                }

        //            }
        //        }
        //    }

        //    Window window = new Window();
        //    window.Content = viewer;
        //    window.ShowDialog();
        //}


        private void imgAddMetric_MouseDown(object sender, MouseButtonEventArgs e)
        {
            VMStructure stru   = ((FrameworkElement)sender).DataContext as VMStructure;
            VMMetric    metric = new VMMetric();

            stru.DoseMetrics.Add(metric);
        }
Ejemplo n.º 3
0
        private void chkBioDose_Checked(object sender, RoutedEventArgs e)
        {
            VMMetric    metric = ((FrameworkElement)sender).DataContext as VMMetric;
            CheckBox    chkbox = sender as CheckBox;
            DataGridRow row    = dtaMetrics.ContainerFromElement(chkbox) as DataGridRow;

            if (row == null)
            {
                return;
            }

            int         rowIndex = row.GetIndex();
            VMStructure struc    = dtaMetrics.Items[rowIndex] as VMStructure;

            //Get NTCP Parameters
            if (metric.NTCPParameters.AlphaBeta == 0)
            {
                BioDoseConfiguration bioConfig = Myconfig.GetBioDoseConfiguration();
                if (struc.IsTarget)
                {
                    metric.NTCPParameters.AlphaBeta = bioConfig.TargetAlphaBeta;
                }
                else
                {
                    metric.NTCPParameters.AlphaBeta = bioConfig.OrganAlphaBeta;
                }
            }

            UpdateDoseMetrics(struc, metric);
        }
Ejemplo n.º 4
0
        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                Cursor = Cursors.Wait;

                VMMetric    selMetric = ((FrameworkElement)sender).DataContext as VMMetric;
                ComboBox    cmb       = sender as ComboBox;
                DataGridRow row       = dtaMetrics.ContainerFromElement(cmb) as DataGridRow;
                if (row == null)
                {
                    return;
                }

                int         rowIndex = row.GetIndex();
                VMStructure struc    = dtaMetrics.Items[rowIndex] as VMStructure;
                if (cmb.SelectedValue != null)
                {
                    selMetric.Name = cmb.SelectedValue.ToString();

                    if (selMetric.Name == "NTCP")
                    {
                        if (selMetric.NTCPParameters.LKBn == 0)
                        {
                            SiteChooser siteChoose = new SiteChooser();
                            siteChoose.ShowDialog();
                            selMetric.NTCPParameters.AlphaBeta = siteChoose.AlphaBeta;
                            selMetric.NTCPParameters.LKBn      = siteChoose.LKBn;
                            selMetric.NTCPParameters.LKBm      = siteChoose.LKBm;
                            selMetric.NTCPParameters.LKBD50    = siteChoose.LKBD50;
                        }
                    }

                    UpdateDoseMetrics(struc, selMetric);

                    selMetric.UseBioDose = false;
                    if (MetricUsesGy(selMetric.Name))
                    {
                        selMetric.CanUseBiodose = true;
                    }
                    else if (selMetric.Name == "NTCP")
                    {
                        selMetric.UseBioDose = true;
                    }
                    else
                    {
                        selMetric.CanUseBiodose = false;
                    }
                }

                Cursor = Cursors.Arrow;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 5
0
        public static double NTCP(Structure structure, PlanSetup plan, VMMetric metric, bool useRapPlanEstimate)
        {
            MyDVHData StdDVH = new MyDVHData();

            StdDVH.LoadDVH(structure, plan, DoseValuePresentation.Absolute, VolumePresentation.AbsoluteCm3, useRapPlanEstimate);

            if (StdDVH.CurveData == null)
            {
                //missing upper or lower dvh estimate
                return(0);
            }
            //Convert DHV to direct
            MyDVHData.DVHPoint[] dirDVH = new MyDVHData.DVHPoint[StdDVH.CurveData.Count()];
            dirDVH[dirDVH.Count() - 1] = new MyDVHData.DVHPoint
            {
                Dose   = StdDVH.CurveData[StdDVH.CurveData.Count() - 1].Dose,
                Volume = StdDVH.CurveData[StdDVH.CurveData.Count() - 1].Volume
            };

            for (int i = 0; i < StdDVH.CurveData.Count() - 1; i++)
            {
                dirDVH[i] = new MyDVHData.DVHPoint
                {
                    Dose   = StdDVH.CurveData[i].Dose,
                    Volume = StdDVH.CurveData[i].Volume - StdDVH.CurveData[i + 1].Volume
                };
            }

            //Biocorrect DVH
            foreach (var point in dirDVH)
            {
                point.Dose = BioDose.bioCorrectEQD2(point.Dose, plan, structure, metric.NTCPParameters.AlphaBeta);
            }

            double EUD_a = 1.0 / metric.NTCPParameters.LKBn;

            double sum_bEUD = 0;

            for (int i = 0; i < dirDVH.Count(); i++)
            {
                double tEUD = (dirDVH[i].Volume / (structure.Volume)) * Math.Pow(dirDVH[i].Dose, EUD_a);
                sum_bEUD = sum_bEUD + tEUD;
            }

            double gEUD = Math.Pow(sum_bEUD, metric.NTCPParameters.LKBn);
            //NORMSDIST((gEUD-lkb_d50)/(lkb_m*lkb_d50))
            double NTCPOPER = (gEUD - metric.NTCPParameters.LKBD50) / (metric.NTCPParameters.LKBm * metric.NTCPParameters.LKBD50);

            if (NTCPOPER > 4.89)//ANYTHING OVER THIS RESULTS IN AN NTCP OF 100%, BUT CAN GIVE THE STATS PACKAGE AN ERROR
            {
                NTCPOPER = 4.89;
            }
            return(100 * Statistics.NormSDist(NTCPOPER));
        }
Ejemplo n.º 6
0
        private double CalculateDoseMetric(PlanSetup plan, VMMetric metric, Structure structure, bool UseRapPlanEstimate = false)
        {
            double metricValue = -1;

            try
            {
                if (metric.Name == EnumUtils.stringValueOf(DoseMetrics.DMean))
                {
                    metricValue = Calc.DMean(structure, plan, metric, UseRapPlanEstimate);
                }
                else if (metric.Name == EnumUtils.stringValueOf(DoseMetrics.DMax))
                {
                    metricValue = Calc.DMax(structure, plan, metric, UseRapPlanEstimate);
                }
                else if (metric.Name == EnumUtils.stringValueOf(DoseMetrics.D0_1cc))
                {
                    metricValue = Calc.D0_1cc(structure, plan, metric, UseRapPlanEstimate);
                }
                else if (metric.Name == EnumUtils.stringValueOf(DoseMetrics.D95p))
                {
                    metricValue = Calc.D95p(structure, plan, metric, UseRapPlanEstimate);
                }
                else if (metric.Name == EnumUtils.stringValueOf(DoseMetrics.D5p))
                {
                    metricValue = Calc.D5p(structure, plan, metric, UseRapPlanEstimate);
                }
                else if (metric.Name == EnumUtils.stringValueOf(DoseMetrics.V33p))
                {
                    metricValue = Calc.V33p(structure, plan, metric, UseRapPlanEstimate);
                }
                else if (metric.Name == EnumUtils.stringValueOf(DoseMetrics.NTCP))
                {
                    metricValue = Calc.NTCP(structure, plan, metric, UseRapPlanEstimate);
                }
                else
                {
                    //check if custom metric
                    metricValue = Calc.CustomMetric(structure, metric, plan, UseRapPlanEstimate);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            if (metricValue == -1)
            {
                throw new ApplicationException("The Dose Metric " + metric.Name + " is not implemented");
            }

            return(metricValue);
        }
Ejemplo n.º 7
0
        public static double DMax(Structure structure, PlanSetup plan, VMMetric metric, bool useRapPlanEstimate)
        {
            MyDVHData cumDVH = new MyDVHData();

            cumDVH.LoadDVH(structure, plan, DoseValuePresentation.Absolute, VolumePresentation.AbsoluteCm3, useRapPlanEstimate);
            if (cumDVH != null)
            {
                return(cumDVH.MaxDose);
            }
            else
            {
                return(0);
            }
        }
Ejemplo n.º 8
0
        private void UpdateDoseMetrics(VMStructure struc, VMMetric selMetric)
        {
            Cursor = Cursors.Wait;
            Structure structure = StructureSet.Structures.FirstOrDefault(s => s.Id == struc.Id);

            if (structure == null)
            {
                throw new ApplicationException("Could not find Structure");
            }
            int i = 0;

            selMetric.StdPlanMetric           = CalculateDoseMetric(StdPlan, selMetric, structure);
            selMetric.RapidPlanMetric         = CalculateDoseMetric(RapidPlan, selMetric, structure);
            selMetric.RapidPlanEstimateMetric = CalculateDoseMetric(RapidPlan, selMetric, structure, true);

            Cursor = Cursors.Arrow;
        }
Ejemplo n.º 9
0
        public static double CustomMetric(Structure structure, VMMetric metric, PlanSetup plan, bool useRapPlanEstimate)
        {
            CustomMetricsConfiguration config = Myconfig.GetCustomMetricsSection();

            foreach (CustomMetricElement custMetric in config.Metrics)
            {
                if (metric.Name == custMetric.Name)
                {
                    if (custMetric.Base == "D#%(Gy)")
                    {
                        return(GetDoseToVolume(structure, plan, custMetric.Parameter, DoseValuePresentation.Absolute, VolumePresentation.Relative, metric, useRapPlanEstimate));
                    }
                    else if (custMetric.Base == "D#%(%)")
                    {
                        return(GetDoseToVolume(structure, plan, custMetric.Parameter, DoseValuePresentation.Relative, VolumePresentation.Relative, metric, useRapPlanEstimate));
                    }
                    else if (custMetric.Base == "D#cc(Gy)")
                    {
                        return(GetDoseToVolume(structure, plan, custMetric.Parameter, DoseValuePresentation.Absolute, VolumePresentation.AbsoluteCm3, metric, useRapPlanEstimate));
                    }
                    else if (custMetric.Base == "D#cc(%)")
                    {
                        return(GetDoseToVolume(structure, plan, custMetric.Parameter, DoseValuePresentation.Relative, VolumePresentation.AbsoluteCm3, metric, useRapPlanEstimate));
                    }
                    else if (custMetric.Base == "V#%(cc)")
                    {
                        return(GetVolumeWithDose(structure, plan, custMetric.Parameter, DoseValuePresentation.Relative, VolumePresentation.AbsoluteCm3, metric, useRapPlanEstimate));
                    }
                    else if (custMetric.Base == "V#%(%)")
                    {
                        return(GetVolumeWithDose(structure, plan, custMetric.Parameter, DoseValuePresentation.Relative, VolumePresentation.Relative, metric, useRapPlanEstimate));
                    }
                    else if (custMetric.Base == "V#Gy(cc)")
                    {
                        return(GetVolumeWithDose(structure, plan, custMetric.Parameter, DoseValuePresentation.Absolute, VolumePresentation.AbsoluteCm3, metric, useRapPlanEstimate));
                    }
                    else if (custMetric.Base == "V#Gy(%)")
                    {
                        return(GetVolumeWithDose(structure, plan, custMetric.Parameter, DoseValuePresentation.Absolute, VolumePresentation.Relative, metric, useRapPlanEstimate));
                    }
                }
            }

            //not one of the defined custom metric bases
            return(-1);
        }
Ejemplo n.º 10
0
        private void btnRecalc_Click(object sender, RoutedEventArgs e)
        {
            VMMetric    metric = ((FrameworkElement)sender).DataContext as VMMetric;
            Button      button = sender as Button;
            DataGridRow row    = dtaMetrics.ContainerFromElement(button) as DataGridRow;

            if (row == null)
            {
                return;
            }

            int         rowIndex = row.GetIndex();
            VMStructure struc    = dtaMetrics.Items[rowIndex] as VMStructure;

            UpdateDoseMetrics(struc, metric);

            metric.ShowNTCPParams = false;
        }
Ejemplo n.º 11
0
        private void chkBioDose_Unchecked(object sender, RoutedEventArgs e)
        {
            VMMetric metric = ((FrameworkElement)sender).DataContext as VMMetric;

            CheckBox    chkbox = sender as CheckBox;
            DataGridRow row    = dtaMetrics.ContainerFromElement(chkbox) as DataGridRow;

            if (row == null)
            {
                return;
            }

            int         rowIndex = row.GetIndex();
            VMStructure struc    = dtaMetrics.Items[rowIndex] as VMStructure;

            UpdateDoseMetrics(struc, metric);

            metric.ShowNTCPParams = false;
        }
Ejemplo n.º 12
0
        private void imgBioParams_MouseDown(object sender, MouseButtonEventArgs e)
        {
            VMMetric metric = ((FrameworkElement)sender).DataContext as VMMetric;

            metric.ShowNTCPParams = !metric.ShowNTCPParams;
        }
Ejemplo n.º 13
0
 public static double V33p(Structure structure, PlanSetup plan, VMMetric metric, bool useRapPlanEstimate)
 {
     return(GetVolumeWithDose(structure, plan, 33, DoseValuePresentation.Relative, VolumePresentation.AbsoluteCm3, metric, useRapPlanEstimate));
 }
Ejemplo n.º 14
0
 public static double D5p(Structure structure, PlanSetup plan, VMMetric metric, bool useRapPlanEstimate)
 {
     return(GetDoseToVolume(structure, plan, 5, DoseValuePresentation.Absolute, VolumePresentation.Relative, metric, useRapPlanEstimate));
 }
Ejemplo n.º 15
0
        private static double GetVolumeWithDose(Structure structure, PlanSetup plan, double dose, DoseValuePresentation dosePresentation, VolumePresentation volPresentation, VMMetric metric, bool useRapPlanEstimate)
        {
            double volume = 0;

            MyDVHData dvh = new MyDVHData();

            dvh.LoadDVH(structure, plan, dosePresentation, volPresentation, useRapPlanEstimate);

            if (dvh != null)
            {
                if (dvh.CurveData == null)
                {
                    //missing upper or lower dvh estimate
                    return(0);
                }
                MyDVHData.DVHPoint[] points = dvh.CurveData;
                for (int i = 0; i < points.Count(); i++)
                {
                    if (points[i].Dose > dose)
                    {
                        if (i == 0)
                        {
                            volume = points[0].Volume;
                            break;
                        }

                        //interpolate volume
                        volume = points[i - 1].Volume + (points[i].Volume - points[i - 1].Volume) *
                                 (dose - points[i - 1].Dose) / (points[i].Dose - points[i - 1].Dose);
                        break;
                    }
                }

                return(volume);
            }
            else
            {
                return(0);
            }
        }