Exemplo n.º 1
0
        /// <summary>
        /// Aligns beam isocenter to within the nearest mm.
        /// </summary>
        /// <param name="beam">beam in which isocenter will be set</param>
        /// <param name="str">the structure in which the center will be used</param>
        public static void AlignToStructureCenter(this IonBeam beam, Structure str)
        {
            var beamParams = beam.GetEditableParameters();
            var rounded    = new VVector(Math.Round(str.CenterPoint.x), Math.Round(str.CenterPoint.x), Math.Round(str.CenterPoint.x));

            beamParams.Isocenter = rounded;
            beam.ApplyParameters(beamParams);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Aligns beam isocenter to within the nearest mm to structure midpoint (not "weighted" center).
        /// </summary>
        /// <param name="beam">beam in which isocenter will be set</param>
        /// <param name="str">the structure in which the center will be used</param>
        public static void AlignToStructureMidpoint(this IonBeam beam, Structure str)
        {
            var beamParams = beam.GetEditableParameters();
            var midpoint   = str.GetMidpoint();
            var rounded    = new VVector(Math.Round(midpoint.x), Math.Round(midpoint.y), Math.Round(midpoint.z));

            beamParams.Isocenter = rounded;
            beam.ApplyParameters(beamParams);
        }
Exemplo n.º 3
0
        private void cbField_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            layerViews = new List <LayerView>();
            this.beam  = (IonBeam)cbField.SelectedItem;
            var starticp = beam.IonControlPoints.Where((p, i) => i % 2 == 0);

            // var endicp = beam.IonControlPoints.Where((p, i) => i % 2 == 1);
            //foreach (var icpPair in starticp.Zip(endicp, (st, en) => new { start = st, end = en }))
            foreach (var icp in starticp)
            {
                layerViews.Add(new LayerView(icp, beam.Meterset.Value, plan.PlannedDosePerFraction.Dose / 100));
            }
            beamXMax            = layerViews.Max(l => l.xmax);
            beamXMin            = layerViews.Min(l => l.xmin);
            beamYMax            = layerViews.Max(l => l.ymax);
            beamYMin            = layerViews.Min(l => l.ymin);
            lvLayer.ItemsSource = layerViews;
            pvEnergy.Model      = createEnergyPlotModel(layerViews);
        }
Exemplo n.º 4
0
        private string SetText()
        {
            // Retrieve the count of plans displayed in Scope Window
            int scopePlanCount = _plans.Count();

            if (scopePlanCount == 0)
            {
                MessageBox.Show("Scope Window does not contain any plans.");
                return("");
            }

            // Retrieve names for different types of plans
            List <string> externalPlanIds = new List <string>();
            List <string> brachyPlanIds   = new List <string>();
            List <string> protonPlanIds   = new List <string>();

            foreach (var ps in _plans)
            {
                if (ps is BrachyPlanSetup)
                {
                    brachyPlanIds.Add(ps.Id);
                }
                else if (ps is IonPlanSetup)
                {
                    protonPlanIds.Add(ps.Id);
                }
                else
                {
                    externalPlanIds.Add(ps.Id);
                }
            }

            // Construct output message
            string message = string.Format("Hello {0}, the number of plans in Scope Window is {1}.",
                                           _user.Name,
                                           scopePlanCount);

            if (externalPlanIds.Count > 0)
            {
                message += string.Format("\nPlan(s) {0} are external beam plans.", string.Join(", ", externalPlanIds));
            }
            if (brachyPlanIds.Count > 0)
            {
                message += string.Format("\nPlan(s) {0} are brachytherapy plans.", string.Join(", ", brachyPlanIds));
            }
            if (protonPlanIds.Count > 0)
            {
                message += string.Format("\nPlan(s) {0} are proton plans.", string.Join(", ", protonPlanIds));
            }

            // Display additional information. Use the active plan if available.
            PlanSetup plan = _plan != null ? _plan : _plans.ElementAt(0);

            message += string.Format("\n\nAdditional details for plan {0}:", plan.Id);

            // Access the structure set of the plan
            if (plan.StructureSet != null)
            {
                Image image      = plan.StructureSet.Image;
                var   structures = plan.StructureSet.Structures;
                message += string.Format("\n* Image ID: {0}", image.Id);
                message += string.Format("\n* Size of the Structure Set associated with the plan: {0}.", structures.Count());
                foreach (Structure s in structures)
                {
                    message += String.Format("\n\t-{0}: {1:F2}cc", s.Id, s.Volume);
                }
            }
            message += string.Format("\n* Number of Fractions: {0}.", plan.NumberOfFractions);
            message += String.Format("\n* Dose Per Fraction: {0}", plan.DosePerFraction);
            // Handle brachytherapy plans separately from external beam plans
            if (plan is BrachyPlanSetup)
            {
                BrachyPlanSetup brachyPlan      = (BrachyPlanSetup)plan;
                var             catheters       = brachyPlan.Catheters;
                var             seedCollections = brachyPlan.SeedCollections;
                message += string.Format("\n* Number of Catheters: {0}.", catheters.Count());
                message += string.Format("\n* Number of Seed Collections: {0}.", seedCollections.Count());
            }
            else
            {
                var beams = plan.Beams;
                message += string.Format("\n* Number of Beams: {0}.", beams.Count());
                foreach (Beam b in beams.OrderBy(x => x.BeamNumber))
                {
                    message += String.Format("\n\t-{0}: {1}MU", b.Id, b.Meterset.Value);
                }
            }
            if (plan is IonPlanSetup)
            {
                IonPlanSetup ionPlan = plan as IonPlanSetup;
                IonBeam      beam    = ionPlan.IonBeams.FirstOrDefault();
                if (beam != null)
                {
                    message += string.Format("\n* Number of Lateral Spreaders in first beam: {0}.", beam.LateralSpreadingDevices.Count());
                    message += string.Format("\n* Number of Range Modulators in first beam: {0}.", beam.RangeModulators.Count());
                    message += string.Format("\n* Number of Range Shifters in first beam: {0}.", beam.RangeShifters.Count());
                }
            }

            // MessageBox.Show(message);
            return(message);
        }
Exemplo n.º 5
0
        public void Execute(ScriptContext context, System.Windows.Window window, ScriptEnvironment environment)
        {
            // Retrieve the count of plans displayed in Scope Window
            int scopePlanCount = context.PlansInScope.Count();

            if (scopePlanCount == 0)
            {
                MessageBox.Show("Scope Window does not contain any plans.");
                return;
            }

            // Retrieve names for different types of plans
            List <string> externalPlanIds = new List <string>();
            List <string> brachyPlanIds   = new List <string>();
            List <string> protonPlanIds   = new List <string>();

            foreach (var ps in context.PlansInScope)
            {
                if (ps is BrachyPlanSetup)
                {
                    brachyPlanIds.Add(ps.Id);
                }
                else if (ps is IonPlanSetup)
                {
                    protonPlanIds.Add(ps.Id);
                }
                else
                {
                    externalPlanIds.Add(ps.Id);
                }
            }

            // Construct output message
            string message = string.Format("Hello {0}, the number of plans in Scope Window is {1}.",
                                           context.CurrentUser.Name,
                                           scopePlanCount);

            if (externalPlanIds.Count > 0)
            {
                message += string.Format("\nPlan(s) {0} are external beam plans.", string.Join(", ", externalPlanIds));
            }
            if (brachyPlanIds.Count > 0)
            {
                message += string.Format("\nPlan(s) {0} are brachytherapy plans.", string.Join(", ", brachyPlanIds));
            }
            if (protonPlanIds.Count > 0)
            {
                message += string.Format("\nPlan(s) {0} are proton plans.", string.Join(", ", protonPlanIds));
            }

            // Display additional information. Use the active plan if available.
            PlanSetup plan = context.PlanSetup != null ? context.PlanSetup : context.PlansInScope.ElementAt(0);

            message += string.Format("\n\nAdditional details for plan {0}:", plan.Id);
            // TODO Show fraction message
            message += string.Format("Number of fractions : {0}\n", plan.NumberOfFractions);
            message += string.Format("Dose per fraction : {0}\n", plan.PlannedDosePerFraction.ToString());

            // Access the structure set of the plan
            if (plan.StructureSet != null)
            {
                Image image      = plan.StructureSet.Image;
                var   structures = plan.StructureSet.Structures;
                message += string.Format("\n* Image ID: {0}", image.Id);
                message += string.Format("\n* Size of the Structure Set associated with the plan: {0}.\n", structures.Count());

                // TODO show structure info each
                foreach (var structureSingle in plan.StructureSet.Structures)
                {
                    // check validation
                    if (!structureSingle.IsEmpty)
                    {
                        message += string.Format("{0} in volume {1:F2} cc" + Environment.NewLine, structureSingle.Name, structureSingle.Volume);
                    }
                }
            }
            // message += string.Format("\n* Number of Fractions: {0}.", plan.NumberOfFractions);

            // Handle brachytherapy plans separately from external beam plans
            if (plan is BrachyPlanSetup)
            {
                BrachyPlanSetup brachyPlan      = (BrachyPlanSetup)plan;
                var             catheters       = brachyPlan.Catheters;
                var             seedCollections = brachyPlan.SeedCollections;
                message += string.Format("\n* Number of Catheters: {0}.", catheters.Count());
                message += string.Format("\n* Number of Seed Collections: {0}.", seedCollections.Count());
            }
            else
            {
                var beams = plan.Beams;
                message += string.Format("\n* Number of Beams: {0}." + Environment.NewLine, beams.Count());

                // TODO show info of beams
                foreach (Beam beamSingle in plan.Beams.OrderBy(x => x.BeamNumber))
                {
                    message += string.Format("Beam name equal to {0} , ", beamSingle.Id);
                    message += string.Format("and MeterSet = {0}" + Environment.NewLine, beamSingle.Meterset.Value.ToString() + " " + beamSingle.Meterset.Unit.ToString());
                }
            }
            if (plan is IonPlanSetup)
            {
                IonPlanSetup ionPlan = plan as IonPlanSetup;
                IonBeam      beam    = ionPlan.IonBeams.FirstOrDefault();
                if (beam != null)
                {
                    message += string.Format("\n* Number of Lateral Spreaders in first beam: {0}.", beam.LateralSpreadingDevices.Count());
                    message += string.Format("\n* Number of Range Modulators in first beam: {0}.", beam.RangeModulators.Count());
                    message += string.Format("\n* Number of Range Shifters in first beam: {0}.", beam.RangeShifters.Count());
                }
            }

            // MessageBox.Show(message);
            window.Content = message;
        }
Exemplo n.º 6
0
        public void Execute(ScriptContext context, System.Windows.Window window, ScriptEnvironment environment)
        {
            // Retrieve the count of plans displayed in Scope Window
            int scopePlanCount = context.PlansInScope.Count();

            if (scopePlanCount == 0)
            {
                MessageBox.Show("Scope Window does not contain any plans.");
                return;
            }

            // Retrieve names for different types of plans
            List <string> externalPlanIds = new List <string>();
            List <string> brachyPlanIds   = new List <string>();
            List <string> protonPlanIds   = new List <string>();

            foreach (var ps in context.PlansInScope)
            {
                // KK: "is" compares the type. Equiv to ps.GetType() == typeof(BrachyPlanSetup))
                if (ps is BrachyPlanSetup)
                {
                    brachyPlanIds.Add(ps.Id);
                }
                else if (ps is IonPlanSetup)
                {
                    protonPlanIds.Add(ps.Id);
                }
                else
                {
                    externalPlanIds.Add(ps.Id);
                }
            }

            // Construct output message
            string message = string.Format("Hello {0}, the number of plans in Scope Window is {1}.",
                                           context.CurrentUser.Name,
                                           scopePlanCount);

            if (externalPlanIds.Count > 0)
            {
                message += string.Format("\nPlan(s) {0} are external beam plans.", string.Join(", ", externalPlanIds));
            }
            if (brachyPlanIds.Count > 0)
            {
                message += string.Format("\nPlan(s) {0} are brachytherapy plans.", string.Join(", ", brachyPlanIds));
            }
            if (protonPlanIds.Count > 0)
            {
                message += string.Format("\nPlan(s) {0} are proton plans.", string.Join(", ", protonPlanIds));
            }

            // Display additional information. Use the active plan if available.
            PlanSetup plan = context.PlanSetup != null ? context.PlanSetup : context.PlansInScope.ElementAt(0);

            message += string.Format("\n\nAdditional details for plan {0}:", plan.Id);

            // Access the structure set of the plan
            if (plan.StructureSet != null)
            {
                Common.Model.API.Image image = plan.StructureSet.Image;
                var structures = plan.StructureSet.Structures;
                message += string.Format("\n* Image ID: {0}", image.Id);
                message += string.Format("\n* Size of the Structure Set associated with the plan: {0}.", structures.Count());

                string structureNames = "";
                foreach (var s in structures)
                {
                    structureNames += String.Format("\n\t{0}: volume is {1:F2} cc.", s.Id, s.Volume);
                }
                message += structureNames;
            }


            message += string.Format("\n* Number of Fractions: {0}.", plan.NumberOfFractions);

            message += string.Format("\n \t Dose per Fraction: {0}.", plan.DosePerFraction);

            // Handle brachytherapy plans separately from external beam plans
            if (plan is BrachyPlanSetup)
            {
                BrachyPlanSetup brachyPlan      = (BrachyPlanSetup)plan;
                var             catheters       = brachyPlan.Catheters;
                var             seedCollections = brachyPlan.SeedCollections;
                message += string.Format("\n* Number of Catheters: {0}.", catheters.Count());
                message += string.Format("\n* Number of Seed Collections: {0}.", seedCollections.Count());
            }
            else
            {
                var beams = plan.Beams;
                message += string.Format("\n* Number of Beams: {0}.", beams.Count());

                string beamNames = "";
                foreach (var b in beams.OrderBy(x => x.BeamNumber))
                {
                    beamNames += String.Format("\n\t{0} has {1} MU.", b.Id, b.Meterset.Value);
                }
                message += beamNames;
            }
            if (plan is IonPlanSetup)
            {
                IonPlanSetup ionPlan = plan as IonPlanSetup;
                IonBeam      beam    = ionPlan.IonBeams.FirstOrDefault();
                if (beam != null)
                {
                    message += string.Format("\n* Number of Lateral Spreaders in first beam: {0}.", beam.LateralSpreadingDevices.Count());
                    message += string.Format("\n* Number of Range Modulators in first beam: {0}.", beam.RangeModulators.Count());
                    message += string.Format("\n* Number of Range Shifters in first beam: {0}.", beam.RangeShifters.Count());
                }
            }

            //MessageBox.Show(message);
            window.Background = Brushes.Blue;
            window.Content    = new TextBlock
            {
                Foreground = Brushes.White,
                FontFamily = new FontFamily("Ariel"),
                FontSize   = 18,
                Text       = message
            };
            //window.Content = message;
        }