Beispiel #1
0
        public ConstraintResult Constrain(PlanningItem pi)
        {
            var c1passed = C1.Constrain(pi);
            var c2passed = C2.Constrain(pi);

            var passed = c1passed.IsSuccess && c1passed.IsSuccess ||
                         c2passed.IsSuccess && c2passed.IsSuccess;

            var msg =
                $"{(passed ? "One or both constraints passed" : "Neither constraint passed")} \n{c1passed.Message} \n{c2passed.Message}";

            return(new ConstraintResult(this, passed ? PASSED : GetFailedResultType(), msg,
                                        $"{c1passed.Value}/{c2passed.Value}"));
        }
Beispiel #2
0
 /// <summary>
 ///     Returns the structures from the planning item. Removes the need to cast to plan or plan sum.
 /// </summary>
 /// <param name="plan">the planning item</param>
 /// <returns>the referenced structure set</returns>
 public static IEnumerable <Structure> GetStructures(this PlanningItem plan)
 {
     if (plan is PlanSetup && plan != null)
     {
         var p = plan as PlanSetup;
         return(p.StructureSet?.Structures);
     }
     if (plan is PlanSum && plan != null)
     {
         var p = plan as PlanSum;
         return(p.StructureSet?.Structures);
     }
     return(null);
 }
        private PlanType GetPlanType(PlanningItem plan)
        {
            if (plan is PlanSetup)
            {
                return(PlanType.Plan);
            }

            if (plan is PlanSum)
            {
                return(PlanType.PlanSum);
            }

            throw new InvalidOperationException("Unknown plan type.");
        }
Beispiel #4
0
 /// <summary>
 ///     Returns the image from the planning item. Removes the need to cast to plan or plan sum.
 /// </summary>
 /// <param name="plan">the planning item</param>
 /// <returns>the referenced structure set</returns>
 public static Image GetImage(this PlanningItem plan)
 {
     if (plan is PlanSetup && plan != null)
     {
         var p = plan as PlanSetup;
         return(p.StructureSet?.Image);
     }
     if (plan is PlanSum && plan != null)
     {
         var p = plan as PlanSum;
         return(p.StructureSet?.Image);
     }
     return(null);
 }
Beispiel #5
0
        // Evaluate covered dose at Volume.
        private string EvaluateCoveredDoseAtVolume(Structure evalStructure, PlanningItem plan, ref List <string> warnings)
        {
            // Covered Dose at Volume DCxcc is equivalent to D(V_tot - x)cc
            double             Vtot       = evalStructure.Volume;
            double             doseEvalPt = (DVHUnit.CompareTo("cc") == 0) ? Vtot - double.Parse(DVHEvalPt) : 100 - double.Parse(DVHEvalPt);
            StructureObjective tmp        = new StructureObjective()
            {
                DVHUnit     = DVHUnit,
                DVHEvalPt   = string.Format("{0:0.00}", doseEvalPt),
                DVHEvalUnit = DVHEvalUnit
            };

            return(tmp.EvaluateDoseAtVolume(evalStructure, plan, ref warnings));
        }
Beispiel #6
0
 public override void Repaint()
 {
     if (!Globals.RationallyAddIn.Application.IsUndoingOrRedoing)
     {
         UpdateReorderFunctions(Globals.RationallyAddIn.Model.PlanningItems.Count - 1);
         if (Globals.RationallyAddIn.Model.PlanningItems.Count > Index)
         {
             PlanningItem item = Globals.RationallyAddIn.Model.PlanningItems[Index];
             Text          = item.ItemText;
             StrikeThrough = item.Finished;
         }
     }
     base.Repaint();
 }
Beispiel #7
0
 /// <summary>
 ///     Returns the structure set from the planning item. Removes the need to cast to plan or plan sum.
 /// </summary>
 /// <param name="plan">the planning item</param>
 /// <returns>the referenced structure set</returns>
 public static StructureSet GetStructureSet(this PlanningItem plan)
 {
     if (plan is PlanSetup && plan != null)
     {
         var p = plan as PlanSetup;
         return(p.StructureSet);
     }
     if (plan is PlanSum && plan != null)
     {
         var p = plan as PlanSum;
         return(p.StructureSet);
     }
     return(null);
 }
Beispiel #8
0
        // Evaulate the DVH with a given structure and plan and return a string indicating what value was achieved.
        public string EvaluateObjectiveAchieved(Structure evalStructure, PlanningItem plan, ref List <string> warnings)
        {
            string achieved = "";

            // Call separate functions depending on type. Return value and units.
            switch (DVHType)
            {
            case "Dose at Volume":
                achieved = EvaluateDoseAtVolume(evalStructure, plan, ref warnings);
                break;

            case "Volume at Dose":
                achieved = EvaluateVolumeAtDose(evalStructure, plan, ref warnings);
                break;

            case "Covered Dose at Volume":
                achieved = EvaluateCoveredDoseAtVolume(evalStructure, plan, ref warnings);
                break;

            case "Covered Volume at Dose":
                achieved = EvaluateCoveredVolumeAtDose(evalStructure, plan, ref warnings);
                break;

            case "Min":
                achieved = EvaluateMinMaxMean(evalStructure, plan, ref warnings, "Min");
                break;

            case "Mean":
                achieved = EvaluateMinMaxMean(evalStructure, plan, ref warnings, "Mean");
                break;

            case "Max":
                achieved = EvaluateMinMaxMean(evalStructure, plan, ref warnings, "Max");
                break;

            case "Volume":
                achieved = EvaluateVolume(evalStructure, plan, ref warnings);
                break;

            case "Conformality Index":
                achieved = EvaluateConformalityIndex(evalStructure, plan, ref warnings);
                break;

            default:
                warnings.Add(string.Format("DVHObjective not recognized.", DVHObjective));
                break;
            }
            return(achieved);
        }
 public void UpdateModel()
 {
     //if this row represents an existing PlanningItem in the model, update it.
     if (PlanningItem != null)
     {
         PlanningItem.ItemText = PlanningItemText.Text;
         PlanningItem.Finished = PlanningItemFinished.Checked;
     }
     else
     {
         PlanningItem newPlanningItem = new PlanningItem(PlanningItemText.Text, PlanningItemFinished.Checked);
         PlanningItemIndex = Math.Min(PlanningItemIndex, ProjectSetupWizard.Instance.ModelCopy.PlanningItems.Count);
         ProjectSetupWizard.Instance.ModelCopy.PlanningItems.Insert(PlanningItemIndex, newPlanningItem);
     }
 }
Beispiel #10
0
 /// <summary>
 /// Return the coldspot dose for a given volume. This is equivalent to taking the total volume of the object and subtracting the input volume
 /// </summary>
 /// <param name="i">the current planning item</param>
 /// <param name="s">the input structure</param>
 /// <param name="volume">the volume to query</param>
 /// <param name="vPres">the volume presentation of the input volume</param>
 /// <param name="dPres">the dose presentation to return</param>
 /// <returns>Return the coldspot dose for a given volume.</returns>
 public static DoseValue GetColdspotAtVolume(this PlanningItem i, Structure s, double volume, VolumePresentation vPres, DoseValuePresentation dPres)
 {
     if (i is PlanSetup)
     {
         var plan = i as PlanSetup;
         var dvh  = plan.GetDefaultDVHCumulativeData(s, dPres, vPres);
         return(dvh.CurveData.GetColdspot(volume));
     }
     else
     {
         var plan = i as PlanSum;
         var dvh  = plan.GetDefaultDVHCumulativeData(s, dPres, vPres);
         return(dvh.CurveData.GetColdspot(volume));
     }
 }
Beispiel #11
0
 private StructureSet GetStructureSet(PlanningItem planningItem)
 {
     if (planningItem is PlanSetup)
     {
         return(((PlanSetup)planningItem).StructureSet);
     }
     else if (planningItem is PlanSum)
     {
         return(((PlanSum)planningItem).StructureSet);
     }
     else
     {
         return(null);
     }
 }
        public override ConstraintResult Constrain(PlanningItem pi)
        {
            var msg    = string.Empty;
            var passed = GetFailedResultType();

            var volAtDose = GetVolumeAtDose(pi);

            passed = PassingFunc(volAtDose);

            var stringUnit = VolumeType == VolumePresentation.AbsoluteCm3 ? "CC" : "%";
            var val        = $"{volAtDose.ToString("F3")} {stringUnit}";

            msg = $"Volume of {StructureName} at {ConstraintDose.Dose} {ConstraintDose.UnitAsString} was {val}.";
            return(new ConstraintResult(this, passed, msg, val));
        }
 public double CalculateMean(PlanningItem planningItem, Structure structure)
 {
     try
     {
         var dvhResult = planningItem.GetDVHCumulativeData(
             structure, DoseValuePresentation.Absolute, VolumePresentation.AbsoluteCm3, 0.001);
         return(dvhResult.MeanDose.Dose);
     }
     catch (Exception e)
     {
         // There are many reasons the DVH calculation could fail,
         // so wrap any exception in a general exception
         throw new InvalidOperationException("Unable to calculate the mean dose.", e);
     }
 }
Beispiel #14
0
 public double ValorObtenido(PlanningItem planActual, Structure ptv = null)
 {
     if (tipo == Tipo.VolPTV)
     {
         return(ptv.Volume);
     }
     else if (tipo == Tipo.NumFx)
     {
         return(Convert.ToDouble(((PlanSetup)planActual).UniqueFractionation.NumberOfFractions));
     }
     else //dejo abierto para agregar otros tipos
     {
         return(Double.NaN);
     }
 }
        public ConstraintResult Constrain(PlanningItem pi)
        {
            var image    = pi.GetImage();
            var diffDays = (DateTime.Now - image.CreationDateTime).Value.TotalDays;
            var msg      = $"CT is {diffDays} days old";

            if (diffDays <= 60)
            {
                return(new ConstraintResult(this, ResultType.PASSED, msg));
            }
            else
            {
                return(new ConstraintResult(this, ResultType.ACTION_LEVEL_3, msg));
            }
        }
Beispiel #16
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));
                }
            }
        }
Beispiel #17
0
        public override ConstraintResult Constrain(PlanningItem pi)
        {
            var msg    = string.Empty;
            var passed = GetFailedResultType();

            var structures = StructureNames.Select(s => pi.GetStructure(s));
            var doseAtVol  = pi.GetDoseAtVolume(structures, Volume, VolumeType, ConstraintDose.GetPresentation());

            passed = PassingFunc(doseAtVol);

            var stringUnit = VolumeType == VolumePresentation.AbsoluteCm3 ? "CC" : "%";
            var value      = $"{doseAtVol.GetDose(ConstraintDose.Unit).ToString("F3")} {ConstraintDose.UnitAsString}";

            msg = $"Dose to {Volume} {stringUnit} of {StructureName} is {value}.";
            return(new ConstraintResult(this, passed, msg, value));
        }
 /// <summary>
 ///     Return the Complement dose (coldspot) for a given volume. This is equivalent to taking the total volume of the
 ///     object and subtracting the input volume
 /// </summary>
 /// <param name="i">the current planning item</param>
 /// <param name="ss">the input structures (will be merged into one dvh)</param>
 /// <param name="volume">the volume to query</param>
 /// <param name="vPres">the volume presentation of the input volume</param>
 /// <param name="dPres">the dose presentation to return</param>
 /// <returns>Return the coldspot dose for a given volume.</returns>
 public static DoseValue GetDoseComplementAtVolume(this PlanningItem i, IEnumerable <Structure> ss, double volume,
                                                   VolumePresentation vPres, DoseValuePresentation dPres)
 {
     if (i is PlanSetup)
     {
         var plan = i as PlanSetup;
         var dvh  = plan.GetComplexDVH(ss, vPres, dPres);
         return(dvh.GetDoseComplement(volume));
     }
     else
     {
         var plan = i as PlanSum;
         var dvh  = plan.GetComplexDVH(ss, vPres, dPres);
         return(dvh.GetDoseComplement(volume));
     }
 }
        /// <summary>
        /// Returns the course from a planning item
        /// </summary>
        /// <param name="pi">the planning item inside the course</param>
        /// <returns>the course for this planning item</returns>
        public static Course GetCourse(this PlanningItem pi)
        {
            if (pi is PlanSetup)
            {
                return((pi as PlanSetup).Course);
            }
            else if (pi is PlanSum)
            {
#if VMS110
                return((pi as PlanSum).Course());
#else
                return((pi as PlanSum).Course);
#endif
            }
            return(null);
        }
Beispiel #20
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));
     }
 }
        public void Execute(RationallyView view, Shape changedShape)
        {
            VisioShape planningItemTextComponent = new VisioShape(view.Page)
            {
                Shape = changedShape
            };

            if (Globals.RationallyAddIn.Model.PlanningItems.Count <= planningItemTextComponent.Index)
            {
                return;
            }

            PlanningItem toUpdate = Globals.RationallyAddIn.Model.PlanningItems[planningItemTextComponent.Index];

            toUpdate.ItemText = planningItemTextComponent.Text;
        }
Beispiel #22
0
        static string GetPlanSumCourse(Patient pat, PlanningItem item)
        {
            PlanSum sum = item as PlanSum;

            foreach (Course cour in pat.Courses)
            {
                foreach (PlanSum ps in cour.PlanSums)
                {
                    if (ps == sum)
                    {
                        return(cour.Id);
                    }
                }
            }
            return("");
        }
Beispiel #23
0
        public ConstraintResult Constrain(PlanningItem pi)
        {
            var ss      = pi.StructureSet;
            var hasBlue = ss.Structures.Any(s =>
            {
                return(s.Color == Colors.Blue);
            });

            if (hasBlue)
            {
                return(new ConstraintResult(this, ResultType.ACTION_LEVEL_3, "Has blue structure! Abort! Abort!!."));
            }
            else
            {
                return(new ConstraintResult(this, ResultType.PASSED, "Whew! No blue structures"));
            }
        }
        //D{Vol_Metric [%,cm3]}[Gy,%] <= Dose_Metric [Unit of dose defined in Dose_Metric]
        // Volume units defined by Vol_repr=0 => Relative [%] Vol_repr=1 => Absolute [cm3] using VolumePresentation Type.

        public static Tuple <DoseValue, Boolean> D_X_less_than(PlanningItem my_plan, Structure structure,
                                                               Double Vol_Metric, VolumePresentation Vol_repr, DoseValue Dose_Goal)
        {
            DoseValue             Dose_Metric  = new DoseValue(0.0, Dose_Goal.Unit);
            Boolean               test         = new Boolean();
            DoseValuePresentation Dose_present = DoseValuePresentation.Absolute;

            if (Dose_Goal.UnitAsString == "%")
            {
                Dose_present = DoseValuePresentation.Relative;
            }

            Dose_Metric = my_plan.GetDoseAtVolume(structure, Vol_Metric, Vol_repr, Dose_present);
            test        = (Dose_Metric.Dose <= Dose_Goal.Dose);

            return(Tuple.Create(Dose_Metric, test));
        }
Beispiel #25
0
 public static bool IsDoseValid(this PlanningItem pitem)
 {
     if (pitem is PlanSetup)
     {
         return(((PlanSetup)pitem).IsDoseValid);
     }
     else if (pitem is PlanSum)
     {   // scan for plans with invalid dose, if there are none then we can assume plansum dose is valid.
         PlanSum psum  = (PlanSum)pitem;
         var     plans = (from p in psum.PlanSetups where p.IsDoseValid == false select p);
         return(plans.Count() <= 0);
     }
     else
     {
         throw new ApplicationException("Unknown PlanningItem type " + pitem.ToString());
     }
 }
 // Determines if dose is valid in a plan.
 public static bool IsDoseValid(this PlanningItem pitem)
 {
     if (pitem is PlanSetup)
     {
         return(((PlanSetup)pitem).IsDoseValid);
     }
     else if (pitem is PlanSum)
     {
         PlanSum psum  = (PlanSum)pitem;
         var     plans = (from p in psum.PlanSetups where p.IsDoseValid == false select p);
         return(plans.Count() <= 0);
     }
     else
     {
         throw new ApplicationException("Unknown PlanningItem type " + pitem.ToString());
     }
 }
Beispiel #27
0
        public override ConstraintResult Constrain(PlanningItem pi)
        {
            var msg    = string.Empty;
            var passed = GetFailedResultType();

            var dvhs = GetStructures(pi)
                       .Select(s => pi.GetDVHCumulativeData(s, ConstraintDose.GetPresentation(),
                                                            VolumePresentation.AbsoluteCm3, 0.01));
            var min = dvhs.Min(d => d.MinDose);

            var value = $"{min.GetDose(ConstraintDose.Unit).ToString("F3")} {ConstraintDose.UnitAsString}";

            passed = min.GreaterThanOrEqualTo(ConstraintDose) ? ResultType.PASSED : GetFailedResultType();
            msg    = $"Minimum dose to {string.Join("/", StructureNames)} is {value}.";

            return(new ConstraintResult(this, passed, msg, value));
        }
Beispiel #28
0
    public static DateTime GetPlanImageCreation(this PlanningItem plan)
    {
        try
        {
            switch (plan)
            {
            case PlanSetup planSetup: return((DateTime)planSetup.StructureSet.Image.CreationDateTime);

            case PlanSum planSum: return((DateTime)planSum.StructureSet.Image.CreationDateTime);
            }

            throw new InvalidOperationException("Unknown PlanningItem type.");
        }
        catch
        {
            return(DateTime.Now);
        }
    }
Beispiel #29
0
    public static string GetPlanImageId(this PlanningItem plan)
    {
        try
        {
            switch (plan)
            {
            case PlanSetup planSetup: return(planSetup.StructureSet.Image.Id);

            case PlanSum planSum: return(planSum.StructureSet.Image.Id);
            }

            throw new InvalidOperationException("Unknown PlanningItem type.");
        }
        catch
        {
            return("");
        }
    }
        public void analizarPlanEstructura(PlanningItem plan, Structure estructura, double volumenDosisMaximaOVR) //Ver cuál sirve
        {
            DoseValuePresentation doseValuePresentation = DoseValuePresentation.Absolute;

            if (plan is PlanSetup)
            {
                valorMedido = Math.Round(((PlanSetup)plan).GetDoseAtVolume(estructura, volumenDosisMaximaOVR, VolumePresentation.AbsoluteCm3, doseValuePresentation).Dose / 100, 1);
            }
            else
            {
                DVHPoint[] curveData = ((PlanSum)plan).GetDVHCumulativeData(estructura, doseValuePresentation, VolumePresentation.AbsoluteCm3, 0.01).CurveData;
                valorMedido = Math.Round(DVHDataExtensions_ESAPIX.GetDoseAtVolume(curveData, volumenDosisMaximaOVR).Dose / 100, 1);
            }
            if (unidadValor == "%")
            {
                valorMedido = Math.Round(valorMedido / prescripcionEstructura * 100, 2); //extraigo en Gy y paso a porcentaje
            }
        }