Exemplo n.º 1
0
 public static double GetVolumeAtDose(this PlanningItem pitem, Structure structure, DoseValue dose, VolumePresentation requestedVolumePresentation)
 {
     if (pitem is PlanSetup)
     {
         return(((PlanSetup)pitem).GetVolumeAtDose(structure, dose, requestedVolumePresentation));
     }
     else
     {
         DVHData dvh = pitem.GetDVHCumulativeData(structure, DoseValuePresentation.Absolute, requestedVolumePresentation, 0.001);
         return(DvhExtensions.VolumeAtDose(dvh, dose.Dose));
     }
 }
Exemplo n.º 2
0
 public static double GetVolumeAtDose(this PlanningItem pitem, Structure structure, DoseValue dose, VolumePresentation requestedVolumePresentation)
 {
     if (pitem is PlanSetup)
     {
         //try catch statement to switch dose units to system presentation. Otherwise exception "Dose Units do not match to system settings
         try
         {
             return(((PlanSetup)pitem).GetVolumeAtDose(structure, dose, requestedVolumePresentation));
         }
         catch
         {
             if (dose.Unit.CompareTo(DoseValue.DoseUnit.cGy) == 0)
             {
                 return(((PlanSetup)pitem).GetVolumeAtDose(structure, new DoseValue(dose.Dose / 100, DoseValue.DoseUnit.Gy), requestedVolumePresentation));
             }
             else if (dose.Unit.CompareTo(DoseValue.DoseUnit.Gy) == 0)
             {
                 return(((PlanSetup)pitem).GetVolumeAtDose(structure, new DoseValue(dose.Dose * 100, DoseValue.DoseUnit.cGy), requestedVolumePresentation));
             }
             else
             {
                 return(((PlanSetup)pitem).GetVolumeAtDose(structure, dose, requestedVolumePresentation));
             }
         }
     }
     else
     {
         DVHData dvh = pitem.GetDVHCumulativeData(structure, DoseValuePresentation.Absolute, requestedVolumePresentation, 0.001);
         //convert dose unit to system unit: otherwise false output without warning
         try
         {
             ((PlanSum)pitem).PlanSetups.First().GetVolumeAtDose(structure, dose, requestedVolumePresentation);
             return(DvhExtensions.VolumeAtDose(dvh, dose.Dose));
         }
         catch
         {
             if (dose.Unit.CompareTo(DoseValue.DoseUnit.cGy) == 0)
             {
                 return(DvhExtensions.VolumeAtDose(dvh, dose.Dose / 100));
             }
             else if (dose.Unit.CompareTo(DoseValue.DoseUnit.Gy) == 0)
             {
                 return(DvhExtensions.VolumeAtDose(dvh, dose.Dose * 100));
             }
             else
             {
                 return(DvhExtensions.VolumeAtDose(dvh, dose.Dose));
             }
         }
     }
 }
Exemplo n.º 3
0
        public DVHViewModel(Patient pat, PlanningItem pItem, Course course, StructureSet ss, User user)
        {
            //patient information
            _contextInfo = new ContextInformation
            {
                SelectedPatient      = pat,
                SelectedPlanningItem = pItem,
                SelectedCourse       = course,
                SelectedStructureSet = pItem is PlanSetup ? ss : (pItem as PlanSum).StructureSet,
                CurrentUser          = user
            };

            _plans = new ObservableCollection <PlanInformation>();

            //add plans to be displayed
            if (pItem is PlanSetup)
            {
                PlanSumDoseVisibility = Visibility.Hidden;
                _plans.Add(new PlanInformation(pItem as PlanSetup));
            }
            else             //plan sum, so add all plans in it
            {
                PlanSumDoseVisibility = Visibility.Visible;
                DoseValue tempPlanSumTotalDose = new DoseValue(0, SelectedPlanningItem.Dose.DoseMax3D.Unit);

                foreach (PlanSetup plan in (pItem as PlanSum).PlanSetups)
                {
                    _plans.Add(new PlanInformation(plan));
                    tempPlanSumTotalDose = DvhExtensions.AddDoseValues(tempPlanSumTotalDose, plan.TotalDose);
                }

                _planSumTotalDose     = tempPlanSumTotalDose;
                _planSumTotalDoseText = tempPlanSumTotalDose.Dose.ToString();
            }

            //protocol selection dropdowns
            _categories       = ConstraintList.GetCategories();
            _protocols        = ConstraintList.GetProtocols();
            _selectedCategory = _categories.First();

            //DVH
            PlotModel     = CreatePlotModel();
            DVHStructures = GetContouredStructures();

            //constraints table
            DVHTable = new ObservableCollection <DVHTableRow>();

            //misc
            Username = _contextInfo.CurrentUser.Id;
        }
Exemplo n.º 4
0
        public static double GetVolumeAtDose(this PlanningItem pitem, Structure structure, DoseValue dose, VolumePresentation requestedVolumePresentation, DoseValue?planSumRx = null)
        {
            //Get units that the dose is represented in within Eclipse but can't call that function if it's requesting % for a plan sum, so if that's the case it must be set manually
            DoseValue.DoseUnit systemUnits = DoseValue.DoseUnit.Percent;
            if (dose.Unit != DoseValue.DoseUnit.Percent)
            {
                systemUnits = pitem.GetDVHCumulativeData(structure, dose.Unit == DoseValue.DoseUnit.Percent ? DoseValuePresentation.Relative : DoseValuePresentation.Absolute, VolumePresentation.Relative, 1).MeanDose.Unit;
            }

            //When calling GetVolumeAtDose, the dose must be in the same units as the system is set to

            //If "dose" is in %, they should be equal, but we will convert them if they are not equal to each other
            if (dose.Unit != systemUnits)
            {
                if (dose.Unit == DoseValue.DoseUnit.cGy && systemUnits == DoseValue.DoseUnit.Gy)
                {
                    dose = new DoseValue(dose.Dose / 100.0, DoseValue.DoseUnit.Gy);
                }
                else if (dose.Unit == DoseValue.DoseUnit.Gy && systemUnits == DoseValue.DoseUnit.cGy)
                {
                    dose = new DoseValue(dose.Dose * 100.0, DoseValue.DoseUnit.cGy);
                }
                else
                {
                    MessageBox.Show(String.Format("There was an error converting {0}, with units of {1} into the units used by Eclipse, {2}\n\nExpected values were cGy and Gy", dose.ToString(), dose.Unit.ToString(), systemUnits.ToString()), String.Format("Error during calculation of V{0}", dose.ToString()), MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }

            //Now functions can be called as normal
            if (pitem is PlanSetup)
            {
                return(((PlanSetup)pitem).GetVolumeAtDose(structure, dose, requestedVolumePresentation));
            }
            else
            {
                DVHData dvh = pitem.GetDVHCumulativeData(structure, DoseValuePresentation.Absolute, requestedVolumePresentation, 0.001);

                if (dose.Unit == DoseValue.DoseUnit.Percent)
                {
                    //MessageBox.Show(String.Format("Only absolute dose is supported for Plan Sums.  A prescription dose of {1} will be assumed to convert the V{0} for {2} into a percentage.", dosecGy.ToString(), planSumRx.ToString(), structure.Id), String.Format("Error during calculation of V{0}", dosecGy.ToString()), MessageBoxButton.OK, MessageBoxImage.Warning);
                    return(DvhExtensions.VolumeAtDose(dvh, dose.Dose, planSumRx));
                }
                else
                {
                    return(DvhExtensions.VolumeAtDose(dvh, dose.Dose));
                }
            }
        }
Exemplo n.º 5
0
 public static DoseValue GetDoseAtVolume(this PlanningItem pitem, Structure structure, double volume, VolumePresentation volumePresentation, DoseValuePresentation requestedDosePresentation)
 {
     if (pitem is PlanSetup)
     {
         return(((PlanSetup)pitem).GetDoseAtVolume(structure, volume, volumePresentation, requestedDosePresentation));
     }
     else
     {
         if (requestedDosePresentation != DoseValuePresentation.Absolute)
         {
             throw new ApplicationException("Only absolute dose supported for Plan Sums");
         }
         DVHData dvh = pitem.GetDVHCumulativeData(structure, DoseValuePresentation.Absolute, volumePresentation, 0.001);
         return(DvhExtensions.DoseAtVolume(dvh, volume));
     }
 }
Exemplo n.º 6
0
        public static DoseValue GetDoseAtVolume(this PlanningItem pitem, Structure structure, double volume, VolumePresentation volumePresentation, DoseValuePresentation requestedDosePresentation, DoseValue?planSumRx = null)
        {
            if (pitem is PlanSetup)
            {
                return(((PlanSetup)pitem).GetDoseAtVolume(structure, volume, volumePresentation, requestedDosePresentation));
            }
            else
            {
                DVHData dvh = pitem.GetDVHCumulativeData(structure, DoseValuePresentation.Absolute, volumePresentation, 0.001);

                if (requestedDosePresentation != DoseValuePresentation.Absolute)
                {
                    //MessageBox.Show(String.Format("Only absolute dose is supported for Plan Sums.  A prescription dose of {1} will be assumed to convert the D{0}% for {2} into a percentage.", volume, planSumRx.ToString(), structure.Id), String.Format("Error during calculation of D{0}%", volume), MessageBoxButton.OK, MessageBoxImage.Warning);
                    return(DvhExtensions.DoseAtVolume(dvh, volume, planSumRx));
                }
                else
                {
                    return(DvhExtensions.DoseAtVolume(dvh, volume));
                }
            }
        }
Exemplo n.º 7
0
        //---------------------------------------------------------------------------------------------
        void UpdateDvhLookup()
        {
            if (m_closing || SelectedStructure == null)
            {
                return;
            }

            bool doseAbsolute = m_absDoseCheckbox.IsChecked.Value;
            bool volAbsolute  = m_absVolCheckbox.IsChecked.Value;

            m_volumeAtDoseResultLabel.Content = "";
            m_doseAtVolumeResultLabel.Content = "";

            m_resultVolumeAtDose.Content = "";
            m_resultDoseAtVolume.Content = "";
            m_structureVolume.Text       = "";

            double inputVolume = Double.NaN;

            if (m_volumeTextBox.Text != null)
            {
                Double.TryParse(m_volumeTextBox.Text, out inputVolume);
            }

            double inputDose = Double.NaN;

            if (m_doseTextBox.Text != null)
            {
                Double.TryParse(m_doseTextBox.Text, out inputDose);
            }

            DoseValuePresentation dosePres = doseAbsolute ? DoseValuePresentation.Absolute : DoseValuePresentation.Relative;
            VolumePresentation    volPres  = volAbsolute ? VolumePresentation.AbsoluteCm3 : VolumePresentation.Relative;

            DVHData dvhData = SelectedPlanningItem.GetDVHCumulativeData(SelectedStructure, dosePres, volPres, s_binWidth);

            m_structureVolume.Text = dvhData.Volume.ToString("F5");

            if (SelectedPlanningItem != null && SelectedPlanningItem.Dose != null && SelectedStructure != null)
            {
                if (!Double.IsNaN(inputVolume))
                {
                    DoseValue val        = SelectedPlanningItem.GetDoseAtVolume(SelectedStructure, inputVolume, volPres, dosePres);
                    DoseValue controlVal = DvhExtensions.DoseAtVolume(dvhData, inputVolume);
                    double    err        = Math.Abs((val.Dose - controlVal.Dose) / val.Dose);
                    if (err > 0.001)
                    {
                        MessageBox.Show("Value : " + val.ToString() + " Control Val : " + controlVal.ToString());
                    }
                    m_resultDoseAtVolume.Content = val.ToString();

                    string doseAtVolumeResultType = volAbsolute ? "cm3 D(" : "% D(";
                    doseAtVolumeResultType           += inputVolume.ToString("F1") + (volAbsolute ? "cm3" : "%") + ") =";
                    m_doseAtVolumeResultLabel.Content = doseAtVolumeResultType;
                }
                if (!Double.IsNaN(inputDose))
                {
                    DoseValue.DoseUnit doseUnit = dvhData.MaxDose.Unit;
                    double             vol      = SelectedPlanningItem.GetVolumeAtDose(SelectedStructure, new DoseValue(inputDose, doseUnit), volPres);

                    double controlVal = DvhExtensions.VolumeAtDose(dvhData, inputDose);
                    double err        = Math.Abs((vol - controlVal) / vol);
                    if (err > 0.001)
                    {
                        MessageBox.Show("Value : " + vol.ToString("F3") + " Control Val : " + controlVal.ToString("F3"));
                    }

                    m_resultVolumeAtDose.Content = vol.ToString("F5") + (volAbsolute ? "cm3" : "%");

                    string volumeAtDoseResultType = doseUnit.ToString() + " V(";
                    volumeAtDoseResultType           += inputDose.ToString("F1") + doseUnit.ToString() + " ) =";
                    m_volumeAtDoseResultLabel.Content = volumeAtDoseResultType;
                }
            }
        }