Beispiel #1
0
        public progressWindow(ESAPIworker e, optimizationLoop o)
        {
            InitializeComponent();

            //flags to let the code know if the user wants to stop the optimization loop, is the optimization loop finished, and can the progress window close
            abortOpt   = false;
            isFinished = false;
            canClose   = false;
            //copy the thread instance and optimizationLoop class instance
            slave = e;
            op    = o;
            //copy the patient MRN so the script will always write the output to my folder (so I don't have to worry about users forgetting to save the output)
            id = slave.data.id;

            //MLC model
            MLCmodel = slave.data.MLCmodel;

            //setup formating for progress window output text
            optObjHeader  = " Updated optimization constraints:" + System.Environment.NewLine;
            optObjHeader += " -------------------------------------------------------------------------" + System.Environment.NewLine;
            optObjHeader += String.Format(" {0, -15} | {1, -16} | {2, -10} | {3, -10} | {4, -8} |" + System.Environment.NewLine, "structure Id", "constraint type", "dose (cGy)", "volume (%)", "priority");
            optObjHeader += " -------------------------------------------------------------------------" + System.Environment.NewLine;

            optResHeader  = " Results of optimization:" + System.Environment.NewLine;
            optResHeader += " ---------------------------------------------------------------------------------------------------------" + System.Environment.NewLine;
            optResHeader += String.Format(" {0, -15} | {1, -16} | {2, -20} | {3, -16} | {4, -12} | {5, -9} |" + System.Environment.NewLine, "structure Id", "constraint type", "dose diff^2 (cGy^2)", "current priority", "cost", "cost (%)");
            optResHeader += " ---------------------------------------------------------------------------------------------------------" + System.Environment.NewLine;

            //set total number of milestones (used for calculation of percent progress completed)
            //7 milestones always have to be completed if coverage check is selected
            if (slave.data.oneMoreOpt)
            {
                calcItems = (10 + 7 * slave.data.numOptimizations);
            }
            else
            {
                calcItems = (7 + 7 * slave.data.numOptimizations);
            }
            //if coverage check is NOT selected, remove 4 of these milestones
            if (demo || !slave.data.runCoverageCheck)
            {
                calcItems -= 5;
            }
            if (slave.data.useFlash)
            {
                calcItems += 2;
            }

            //initialize and start the stopwatch
            runTime.Text = "00:00:00";
            dt.Tick     += new EventHandler(dt_tick);
            dt.Interval  = new TimeSpan(0, 0, 1);
            sw.Start();
            dt.Start();

            //start the optimization loop
            doStuff();
        }
Beispiel #2
0
        private void startOpt_Click(object sender, RoutedEventArgs e)
        {
            //start the optimization loop
            //checks
            if (opt_parameters.Children.Count == 0)
            {
                MessageBox.Show("No optimization parameters present to assign to the VMAT plan!");
                return;
            }
            if (!int.TryParse(numOptLoops.Text, out int numOptimizations))
            {
                MessageBox.Show("Error! Invalid input for number of optimization loops! \nFix and try again.");
                return;
            }
            //get an instnace of the VMAT TBI plan
            ExternalPlanSetup plan = getPlan();

            if (plan == null)
            {
                return;
            }

            if (!double.TryParse(targetNormTB.Text, out double planNorm))
            {
                MessageBox.Show("Error! Target normalization is NaN \nFix and try again.");
                return;
            }
            if (planNorm < 0.0 || planNorm > 100.0)
            {
                MessageBox.Show("Error! Target normalization is is either < 0% or > 100% \nExiting!");
                return;
            }

            //get constraints
            //same code as from the binary plug in
            List <Tuple <string, string, double, double, int> > optParametersList = new List <Tuple <string, string, double, double, int> > {
            };
            string structure      = "";
            string constraintType = "";
            double dose           = -1.0;
            double vol            = -1.0;
            int    priority       = -1;
            int    txtbxNum       = 1;
            bool   firstCombo     = true;
            bool   headerObj      = true;

            foreach (object obj in opt_parameters.Children)
            {
                if (!headerObj)
                {
                    foreach (object obj1 in ((StackPanel)obj).Children)
                    {
                        if (obj1.GetType() == typeof(ComboBox))
                        {
                            if (firstCombo)
                            {
                                structure  = (obj1 as ComboBox).SelectedItem.ToString();
                                firstCombo = false;
                            }
                            else
                            {
                                constraintType = (obj1 as ComboBox).SelectedItem.ToString();
                            }
                        }
                        else if (obj1.GetType() == typeof(TextBox))
                        {
                            if (!string.IsNullOrWhiteSpace((obj1 as TextBox).Text))
                            {
                                if (txtbxNum == 1)
                                {
                                    double.TryParse((obj1 as TextBox).Text, out vol);
                                }
                                else if (txtbxNum == 2)
                                {
                                    double.TryParse((obj1 as TextBox).Text, out dose);
                                }
                                else
                                {
                                    int.TryParse((obj1 as TextBox).Text, out priority);
                                }
                            }
                            txtbxNum++;
                        }
                    }
                    if (structure == "--select--" || constraintType == "--select--")
                    {
                        MessageBox.Show("Error! \nStructure or Sparing Type not selected! \nSelect an option and try again");
                        return;
                    }
                    else if (dose == -1.0 || vol == -1.0 || priority == -1.0)
                    {
                        MessageBox.Show("Error! \nDose, volume, or priority values are invalid! \nEnter new values and try again");
                        return;
                    }
                    else
                    {
                        optParametersList.Add(Tuple.Create(structure, constraintType, dose, vol, priority));
                    }
                    firstCombo = true;
                    txtbxNum   = 1;
                    dose       = -1.0;
                    vol        = -1.0;
                    priority   = -1;
                }
                else
                {
                    headerObj = false;
                }
            }

            if (optParametersList.Where(x => x.Item1.ToLower().Contains("flash")).Any())
            {
                useFlash = true;
            }

            //does the user want to run the initial dose coverage check?
            runCoverageCheck = runCoverageCk.IsChecked.Value;
            //does the user want to run one additional optimization to reduce hotspots?
            runOneMoreOpt = runAdditionalOpt.IsChecked.Value;
            //does the user want to copy and save each plan after it's optimized (so the user can choose between the various plans)?
            copyAndSavePlanItr = copyAndSave.IsChecked.Value;

            //start the optimization loop (all saving to the database is performed in the progressWindow class)
            pi.BeginModifications();
            optimizationLoop optLoop = new optimizationLoop(plan, optParametersList, planNorm, numOptimizations, scleroTrial, runCoverageCheck, runOneMoreOpt, copyAndSavePlanItr, useFlash, MLCmodel, app);
        }