コード例 #1
0
        private bool RemoveOldTSStructures(List <Tuple <string, string> > structures)
        {
            //remove existing TS structures if they exist and re-add them to the structure list
            foreach (Tuple <string, string> itr in structures)
            {
                Structure tmp = selectedSS.Structures.FirstOrDefault(x => x.Id.ToLower() == itr.Item2.ToLower());

                //structure is present in selected structure set
                if (tmp != null)
                {
                    //check to see if the dicom type is "none"
                    if (!(tmp.DicomType == ""))
                    {
                        if (selectedSS.CanRemoveStructure(tmp))
                        {
                            selectedSS.RemoveStructure(tmp);
                        }
                        else
                        {
                            MessageBox.Show(String.Format("Error! \n{0} can't be removed from the structure set!", tmp.Id));
                            return(true);
                        }

                        if (!selectedSS.CanAddStructure(itr.Item1, itr.Item2))
                        {
                            MessageBox.Show(String.Format("Error! \n{0} can't be added to the structure set!", itr.Item2));
                            return(true);
                        }
                    }
                    else
                    {
                        MessageBox.Show(String.Format("Error! \n{0} is of DICOM type 'None'! \nESAPI can't operate on DICOM type 'None'", itr.Item2));
                        return(true);
                    }
                }

                //Need to add the Human body, PTV_BODY, and TS_PTV_VMAT contours manually
                //if these structures were present, they should have been romved (regardless if they were contoured or not).
                if (itr.Item2.ToLower().Contains("human") || itr.Item2.ToLower().Contains("ptv"))
                {
                    if (selectedSS.CanAddStructure(itr.Item1, itr.Item2))
                    {
                        selectedSS.AddStructure(itr.Item1, itr.Item2);
                        addedStructures.Add(itr.Item2);
                    }
                    else
                    {
                        MessageBox.Show(String.Format("Can't add {0} to the structure set!", itr.Item2));
                        return(true);
                    }
                }
            }
            return(false);
        }
コード例 #2
0
        //[MethodImpl(MethodImplOptions.NoInlining)]
        public void Execute(ScriptContext context /*, System.Windows.Window window, ScriptEnvironment environment*/)
        {
            // TODO : Add here the code that is called when the script is launched from Eclipse.
            if (context.Patient == null || context.StructureSet == null)
            {
                MessageBox.Show("Please load a patient, 3D image, and structure set before running this script.", SCRIPT_NAME, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }
            context.Patient.BeginModifications();   // enable writing with this script.

            StructureSet structureSet = context.StructureSet;

            string log = "";
            var    removedStructureIds = new List <string> {
            };
            var unremovedStructureIds  = new List <string> {
            };

            //search empty structure.
            foreach (var structure in structureSet.Structures)
            {
                if (structure.IsEmpty == true)
                {
                    if (structureSet.CanRemoveStructure(structure) == true)
                    {
                        removedStructureIds.Add(structure.Id);
                        log += structure.Id + " : removed" + "\n";
                    }
                    else
                    {
                        unremovedStructureIds.Add(structure.Id);
                        log += structure.Id + " : Not removed(change approval status!)" + "\n";
                    }
                }
            }

            //remove empty structure.
            foreach (var id in removedStructureIds)
            {
                if (structureSet.Structures.Any(st => st.Id == id))
                {
                    var removedStructure = structureSet.Structures.Single(st => st.Id == id);
                    structureSet.RemoveStructure(removedStructure);
                }
            }

            //show complete message.
            MessageBox.Show(log + "\nDone.", SCRIPT_NAME);
        }
コード例 #3
0
ファイル: planPrep.cs プロジェクト: esimiele/VMAT-TBI
        private bool removeFlashStr()
        {
            //remove the structures used to generate flash in the plan
            StructureSet ss = vmatPlan.StructureSet;
            //check to see if this structure set is used in any other calculated plans that are NOT the _VMAT TBI plan or any of the AP/PA legs plans
            string message = "";
            List <ExternalPlanSetup> otherPlans = new List <ExternalPlanSetup> {
            };

            foreach (Course c in vmatPlan.Course.Patient.Courses)
            {
                foreach (ExternalPlanSetup p in c.ExternalPlanSetups)
                {
                    if ((p != vmatPlan && !appaPlan.Where(x => x == p).Any()) && p.IsDoseValid && p.StructureSet == ss)
                    {
                        message += String.Format("Course: {0}, Plan: {1}", c.Id, p.Id) + System.Environment.NewLine;
                        otherPlans.Add(p);
                    }
                }
            }
            //photon dose calculation model type
            string calcModel = vmatPlan.GetCalculationModel(CalculationType.PhotonVolumeDose);

            if (otherPlans.Count > 0)
            {
                //if some plans were found that use this structure set and have dose calculated, inform the user and ask if they want to continue WITHOUT removing flash.
                message  = "The following plans have dose calculated and use the same structure set:" + System.Environment.NewLine + message + System.Environment.NewLine;
                message += "I need to remove the calculated dose from these plans before removing the flash structures." + System.Environment.NewLine;
                message += "Continue?";
                confirmUI CUI = new VMATTBIautoPlan.confirmUI();
                CUI.message.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                CUI.message.Text = message;
                CUI.ShowDialog();
                //need to return from this function regardless of what the user decides
                if (!CUI.confirm)
                {
                    return(true);
                }
                foreach (ExternalPlanSetup p in otherPlans)
                {
                    p.ClearCalculationModel(CalculationType.PhotonVolumeDose);
                    p.SetCalculationModel(CalculationType.PhotonVolumeDose, calcModel);
                }
            }
            //dumbass way around the issue of modifying structures in a plan that already has dose calculated... reset the calculation model, make the changes you need, then reset the calculation model
            vmatPlan.ClearCalculationModel(CalculationType.PhotonVolumeDose);
            vmatPlan.SetCalculationModel(CalculationType.PhotonVolumeDose, calcModel);
            foreach (ExternalPlanSetup p in appaPlan)
            {
                p.ClearCalculationModel(CalculationType.PhotonVolumeDose);
                p.SetCalculationModel(CalculationType.PhotonVolumeDose, calcModel);
            }
            IEnumerable <Structure> flashStr = ss.Structures.Where(x => x.Id.ToLower().Contains("flash"));
            List <Structure>        removeMe = new List <Structure> {
            };

            //can't remove directly from flashStr because the vector size would change on each loop iteration
            foreach (Structure s in flashStr)
            {
                if (!s.IsEmpty)
                {
                    if (ss.CanRemoveStructure(s))
                    {
                        removeMe.Add(s);
                    }
                }
            }
            foreach (Structure s in removeMe)
            {
                ss.RemoveStructure(s);
            }

            //from the generateTS class, the human_body structure was a copy of the body structure BEFORE flash was added. Therefore, if this structure still exists, we can just copy it back onto the body
            Structure bodyCopy = ss.Structures.FirstOrDefault(x => x.Id.ToLower() == "human_body");

            if (bodyCopy != null && !bodyCopy.IsEmpty)
            {
                Structure body = ss.Structures.First(x => x.Id.ToLower() == "body");
                body.SegmentVolume = bodyCopy.Margin(0.0);
                if (ss.CanRemoveStructure(bodyCopy))
                {
                    ss.RemoveStructure(bodyCopy);
                }
            }
            else
            {
                MessageBox.Show("WARNING 'HUMAN_BODY' STRUCTURE NOT FOUND! BE SURE TO RE-CONTOUR THE BODY STRUCTURE!");
            }
            flashRemoved = true;

            return(false);
        }