Ejemplo n.º 1
0
        /// <summary>
        /// Run MCO
        /// </summary>
        /// <param name="app"></param>
        /// <param name="patient"></param>
        /// <param name="courseId"></param>
        /// <param name="planSetupId"></param>
        public static void RunMCO(Patient patient, string courseId, string planSetupId)
        {
            string message;
            string m_mcoImrtPlanSetupId = planSetupId;

            message = string.Format("Patient {0} opened for MCO", patient.Id);
            Trace.WriteLine(message);

            var planSetupOrig = Helpers.FindPlanSetup(patient, courseId, m_mcoImrtPlanSetupId);
            var planSetup     = planSetupOrig.Course.CopyPlanSetup(planSetupOrig) as ExternalPlanSetup;

            Helpers.RemoveOldPlan(planSetupOrig.Course, "MyMCOPlanV1");
            planSetup.Id = "MyMCOPlanV1";

            message = string.Format("planSetupOrig {0} found", planSetupOrig.Id);
            Trace.WriteLine(message);
            message = string.Format("Copy planSetupOrig {0} found", planSetup.Id);
            Trace.WriteLine(message);
            message = string.Format("Calculation model for Photons {0} found", planSetup.GetCalculationModel(CalculationType.PhotonIMRTOptimization));
            Trace.WriteLine(message);

            //Create Plan Collection
            message = string.Format("Is trade-off ready? {0}", planSetup.TradeoffExplorationContext.HasPlanCollection.ToString());
            Trace.WriteLine(message);
            message = string.Format("Has Tradeoff objectives set? {0}", planSetup.TradeoffExplorationContext.TradeoffObjectives.Any().ToString());
            Trace.WriteLine(message);
            var       tradeoffCandidates = planSetup.TradeoffExplorationContext.TradeoffStructureCandidates;
            Structure structure          = tradeoffCandidates.First();

            message = string.Format("Add one structure ({0}) as Tradeoff objectives set? {1}", structure.Id, planSetup.TradeoffExplorationContext.AddTradeoffObjective(structure));
            Trace.WriteLine(message);
            message = string.Format("Can a plan collection be created? {0}", planSetup.TradeoffExplorationContext.CanCreatePlanCollection);
            Trace.WriteLine(message);
            message = string.Format("Create the plan collection, result={0}", planSetup.TradeoffExplorationContext.CreatePlanCollection(false, TradeoffPlanGenerationIntermediateDoseMode.NotUsed));
            Trace.WriteLine(message);
            message = string.Format("Is trade-off exploration ready? {0}", planSetup.TradeoffExplorationContext.HasPlanCollection.ToString());
            Trace.WriteLine(message);
            foreach (var tradeoffObjective in planSetup.TradeoffExplorationContext.TradeoffObjectives)
            {
                message = string.Format("Objective cost ({0}) = {1}", tradeoffObjective.Structure, planSetup.TradeoffExplorationContext.GetObjectiveCost(tradeoffObjective));
                Trace.WriteLine(message);
            }
            message = string.Format("CurrentDose = {0}", planSetup.TradeoffExplorationContext.CurrentDose.DoseMax3D);
            Trace.WriteLine(message);
            foreach (var structureItem in planSetup.TradeoffExplorationContext.TargetStructures)
            {
                var structureDvh = planSetup.TradeoffExplorationContext.GetStructureDvh(structureItem);
                message = string.Format("GetStructureDvh({0}).MaxDose = {1}, MeanDose = {2}", structureItem.Id, structureDvh.MaxDose, structureDvh.MeanDose);
                Trace.WriteLine(message);
            }

            // Navigate with the trade-off objectives
            var    tradeoffObjectiveToNavigate        = planSetup.TradeoffExplorationContext.TradeoffObjectives.First();
            double costForTradeoffObjectiveToNavigate = 0.0;
            var    cost       = planSetup.TradeoffExplorationContext.GetObjectiveCost(tradeoffObjectiveToNavigate);
            var    lowerLimit = planSetup.TradeoffExplorationContext.GetObjectiveLowerLimit(tradeoffObjectiveToNavigate);
            var    upperLimit = planSetup.TradeoffExplorationContext.GetObjectiveUpperLimit(tradeoffObjectiveToNavigate);
            // move restrictor halfway between current cost and upper limit
            var newRestrictorPos = cost + (upperLimit - cost) * 0.5;

            message = string.Format("TradeoffObjective = {0}, Lower limit = {1}, upper limit = {2}, cost = {3}.", tradeoffObjectiveToNavigate.Structure, lowerLimit, upperLimit, cost);
            Trace.WriteLine(message);
            message = string.Format("Set upper restrictor of halfway between cost and upper limit {0} to {1}", tradeoffObjectiveToNavigate.Structure, newRestrictorPos);
            Trace.WriteLine(message);
            planSetup.TradeoffExplorationContext.SetObjectiveUpperRestrictor(tradeoffObjectiveToNavigate, newRestrictorPos);
            message = string.Format("Set tradeoffObjective {0} to {1}", tradeoffObjectiveToNavigate.Structure, costForTradeoffObjectiveToNavigate);
            Trace.WriteLine(message);
            planSetup.TradeoffExplorationContext.SetObjectiveCost(tradeoffObjectiveToNavigate, costForTradeoffObjectiveToNavigate);

            message = string.Format("--------View again the results---------");
            Trace.WriteLine(message);
            foreach (var tradeoffObjective in planSetup.TradeoffExplorationContext.TradeoffObjectives)
            {
                message = string.Format("Objective cost ({0}) = {1}", tradeoffObjective.Structure, planSetup.TradeoffExplorationContext.GetObjectiveCost(tradeoffObjective));
                Trace.WriteLine(message);
            }
            message = string.Format("CurrentDose = {0}", planSetup.TradeoffExplorationContext.CurrentDose.DoseMax3D);
            Trace.WriteLine(message);
            foreach (var structureItem in planSetup.TradeoffExplorationContext.TargetStructures)
            {
                var structureDvh = planSetup.TradeoffExplorationContext.GetStructureDvh(structureItem);
                message = string.Format("GetStructureDvh({0}).MaxDose = {1}, MeanDose = {2}", structureItem.Id, structureDvh.MaxDose, structureDvh.MeanDose);
                Trace.WriteLine(message);
            }
            cost       = planSetup.TradeoffExplorationContext.GetObjectiveCost(tradeoffObjectiveToNavigate);
            lowerLimit = planSetup.TradeoffExplorationContext.GetObjectiveLowerLimit(tradeoffObjectiveToNavigate);
            upperLimit = planSetup.TradeoffExplorationContext.GetObjectiveUpperLimit(tradeoffObjectiveToNavigate);
            message    = string.Format("TradeoffObjective = {0}, Lower limit = {1}, upper limit = {2}, cost = {3}.", tradeoffObjectiveToNavigate.Structure, lowerLimit, upperLimit, cost);
            Trace.WriteLine(message);

            //apply MCO
            message = string.Format("Saving plan collection and in case of IMRT applying to the plan setup.");
            Trace.WriteLine(message);
            planSetup.TradeoffExplorationContext.ApplyTradeoffExplorationResult();
            message = string.Format("Is Applying plan to plan setup in case IMRT successful? {0}", planSetup.TradeoffExplorationContext.CreateDeliverableVmatPlan(false));
            Trace.WriteLine(message);
        }