Пример #1
0
        public int xDim, yDim;        // pixel dimensions of the fluence map
        public CreateMLCFields(ExternalPlanSetup pln, ExternalBeamMachineParameters machParam, VVector isoCtr, ImageFactory img, double picWidth, double picLength)
        {
            currPln       = pln;
            currMachParam = machParam;
            currIsoCtr    = isoCtr;
            imgFcty       = img;
            // Resize image based on input pic length and width //
            double nPxWidth  = Math.Floor(picWidth / flncRes);  // number of 2.5mm pixels in planned picture width
            double nPxLength = Math.Floor(picLength / flncRes); // number of 2.5mm pixels in planned picture length
            double mag       = Math.Min(nPxWidth / imgFcty.Image.Width, nPxLength / imgFcty.Image.Height);

            xDim = (int)Math.Floor(mag * imgFcty.Image.Width);
            yDim = (int)Math.Floor(mag * imgFcty.Image.Height);
            // Remove all existing beams //
            int nBeams = currPln.Beams.Count();

            for (int i = 0; i < nBeams; i++)
            {
                Beam currBm = currPln.Beams.First();
                currPln.RemoveBeam(currBm);
            }
        }
Пример #2
0
        public bool separate()
        {
            //check for setup fields in the vmat and AP/PA plans
            if (!vmatPlan.Beams.Where(x => x.IsSetupField).Any() || (appaPlan.Count() > 0 && !legsSeparated && !appaPlan.First().Beams.Where(x => x.IsSetupField).Any()))
            {
                string problemPlan = "";
                if (!vmatPlan.Beams.Where(x => x.IsSetupField).Any())
                {
                    problemPlan = "VMAT plan";
                }
                else
                {
                    problemPlan = "AP/PA plan(s)";
                }
                confirmUI CUI = new VMATTBIautoPlan.confirmUI();
                CUI.message.Text = String.Format("I didn't find any setup fields in the {0}.", problemPlan) + Environment.NewLine + Environment.NewLine + "Are you sure you want to continue?!";
                CUI.ShowDialog();
                if (!CUI.confirm)
                {
                    return(true);
                }
            }

            //check if flash was used in the plan. If so, ask the user if they want to remove these structures as part of cleanup
            if (checkForFlash())
            {
                confirmUI CUI = new VMATTBIautoPlan.confirmUI();
                CUI.message.Text = "I found some structures in the structure set for generating flash." + Environment.NewLine + Environment.NewLine + "Do you want me to remove them?!";
                CUI.button1.Text = "No";
                CUI.ShowDialog();
                if (CUI.confirm)
                {
                    if (removeFlashStr())
                    {
                        return(true);
                    }
                }
            }
            //counter for indexing names
            int count = 0;

            //loop through the list of beams in each isocenter
            foreach (List <Beam> beams in vmatBeamsPerIso)
            {
                //string message = "";
                //foreach (Beam b in beams) message += b.Id + "\n";
                //MessageBox.Show(message);

                //copy the plan, set the plan id based on the counter, and make a empty list to hold the beams that need to be removed
                ExternalPlanSetup newplan = (ExternalPlanSetup)vmatPlan.Course.CopyPlanSetup(vmatPlan);
                newplan.Id = String.Format("{0} {1}", count + 1, names.ElementAt(count));
                List <Beam> removeMe = new List <Beam> {
                };
                //can't add reference point to plan because it must be open in Eclipse for ESAPI to perform this function. Need to fix in v16
                //newplan.AddReferencePoint(newplan.StructureSet.Structures.First(x => x.Id.ToLower() == "ptv_body"), null, newplan.Id, newplan.Id);
                //add the current plan copy to the separatedPlans list
                separatedPlans.Add(newplan);
                //loop through each beam in the plan copy and compare it to the list of beams in the current isocenter
                foreach (Beam b in newplan.Beams)
                {
                    //if the current beam in newPlan is NOT found in the beams list, add it to the removeMe list. This logic has to be applied. You can't directly remove the beams in this loop as ESAPI will
                    //complain that the enumerable that it is using to index the loop changes on each iteration (i.e., newplan.Beams changes with each iteration). Do NOT add setup beams to the removeMe list. The
                    //idea is to have dosi add one set of setup fields to the original plan and then not remove those for each created plan. Unfortunately, dosi will have to manually adjust the iso position for
                    //the setup fields in each new plan (no way to adjust the existing isocenter of an existing beam, it has to be re-added)
                    if (!beams.Where(x => x.Id == b.Id).Any() && !b.IsSetupField)
                    {
                        removeMe.Add(b);
                    }
                }
                //now remove the beams for the current plan copy
                foreach (Beam b in removeMe)
                {
                    newplan.RemoveBeam(b);
                }
                count++;
            }

            //do the same as above, but for the AP/PA legs plan
            if (!legsSeparated)
            {
                foreach (List <Beam> beams in appaBeamsPerIso)
                {
                    //string message = "";
                    //foreach (Beam b in beams) message += b.Id + "\n";
                    //MessageBox.Show(message);
                    ExternalPlanSetup newplan  = (ExternalPlanSetup)appaPlan.First().Course.CopyPlanSetup(appaPlan.First());
                    List <Beam>       removeMe = new List <Beam> {
                    };
                    newplan.Id = String.Format("{0} {1}", count + 1, (names.ElementAt(count).Contains("upper") ? "Upper Legs" : "Lower Legs"));
                    //newplan.AddReferencePoint(newplan.StructureSet.Structures.First(x => x.Id.ToLower() == "ptv_body"), null, newplan.Id, newplan.Id);
                    separatedPlans.Add(newplan);
                    foreach (Beam b in newplan.Beams)
                    {
                        //if the current beam in newPlan is NOT found in the beams list, then remove it from the current new plan
                        if (!beams.Where(x => x.Id == b.Id).Any() && !b.IsSetupField)
                        {
                            removeMe.Add(b);
                        }
                    }
                    foreach (Beam b in removeMe)
                    {
                        newplan.RemoveBeam(b);
                    }
                    count++;
                }
            }
            //inform the user it's done
            string message = "Original plan(s) have been separated! \r\nBe sure to set the target volume and primary reference point!\r\n";

            if (vmatPlan.Beams.Where(x => x.IsSetupField).Any() || (appaPlan.Count() > 0 && !legsSeparated && appaPlan.First().Beams.Where(x => x.IsSetupField).Any()))
            {
                message += "Also reset the isocenter position of the setup fields!";
            }
            MessageBox.Show(message);
            return(false);
        }
Пример #3
0
        public static void BeamMaker(ref ExternalPlanSetup plan, StructureSet ss, double prescriptionDose, Tuple <string, string, bool> beamParams)
        {
            //First check if beams already exist
            foreach (Beam beam in plan.Beams.ToList())
            {
                plan.RemoveBeam(beam);
            }
            string treatmentCenter = beamParams.Item1;
            string treatmentArea   = beamParams.Item2;
            string beamName        = "";
            int    doseRate        = 600;

            //Get the right beam name
            if (treatmentCenter == "BC Cancer - Surrey")
            {
                beamName = "fv" + treatmentArea.Replace(" ", "") + "TB";
                beamName = beamName.ToUpper();
                doseRate = 400;
            }
            else if (treatmentCenter == "BC Cancer - Vancouver")
            {
                beamName = "Va" + treatmentArea.Replace(" ", "");
            }



            //need to create two arc beams, and make sure they fit to PTVs.
            ExternalBeamMachineParameters ebmp = new ExternalBeamMachineParameters(beamName, "6X", doseRate, "ARC", null);
            //First need to find the isocentre, which will be in the main PTV

            //find all the ptvs
            List <Structure> ptvs     = new List <Structure>();
            List <Structure> mainPTVs = new List <Structure>();

            foreach (Structure structure in ss.Structures)
            {
                if (structure.Name.ToLower().Contains("ptv"))
                {
                    ptvs.Add(structure);
                    if (StringOperations.FindPTVNumber(structure.Name) == prescriptionDose / 100)
                    //Check if receiving prescription dose
                    {
                        mainPTVs.Add(structure);
                    }
                }
            }
            //Check if it's receiving the prescription dose. If so, set isocentre here. If there is more than
            //One receiving the prescription dose, set at the average between the two.
            VVector isocentre;

            if (mainPTVs.Count > 0)
            {
                double x = 0;
                double y = 0;
                double z = 0;
                //Find average x,y,z
                for (int i = 0; i < mainPTVs.Count; i++)
                {
                    x += Math.Round(mainPTVs[i].CenterPoint.x / 10.0f) * 10.0f / mainPTVs.Count;
                    y += Math.Round(mainPTVs[i].CenterPoint.y / 10.0f) * 10.0f / mainPTVs.Count;
                    z += Math.Round(mainPTVs[i].CenterPoint.z / 10.0f) * 10.0f / mainPTVs.Count;
                }
                isocentre = new VVector(x, y, z);
            }
            else
            {
                isocentre = new VVector(0, 0, 0);
            }
            //Create two VMAT beams

            //First get the right jaw dimensions:
            VRect <double> jaws1 = FitJawsToTarget(isocentre, plan, ptvs, 30, 0);
            VRect <double> jaws2 = FitJawsToTarget(isocentre, plan, ptvs, 330, 0);
            Beam           vmat1 = plan.AddArcBeam(ebmp, jaws1, 30, 180.1, 179.9, GantryDirection.Clockwise, 0, isocentre);
            Beam           vmat2 = plan.AddArcBeam(ebmp, jaws2, 330, 179.9, 180.1, GantryDirection.CounterClockwise, 0, isocentre);

            vmat1.Id = "PC_vmat1";
            vmat2.Id = "PC_vmat2";
        }