Пример #1
0
        private static ControlPointCollection DrawPoints(IGlyphRenderer surface, ControlPointCollection points, Vector2 point)
        {
            switch (points.Count)
            {
            case 0: break;

            case 1:
                surface.QuadraticBezierTo(
                    points.SecondControlPoint,
                    point);
                break;

            case 2:
                surface.CubicBezierTo(
                    points.SecondControlPoint,
                    points.ThirdControlPoint,
                    point);
                break;

            default:
                throw new NotSupportedException("Too many control points");
            }

            points.Clear();
            return(points);
        }
Пример #2
0
        private void RecreateControlPoints()
        {
            System.ICloneable prototype = (System.ICloneable)_controlPointPrototype;

            ControlPoint[] controlPoints = new ControlPoint[_obj.Points.Length];
            for (int i = 0; i < controlPoints.Length; i++)
            {
                controlPoints[i] = (ControlPoint)prototype.Clone();
            }

            _transformedPoints = new ControlPointCollection(controlPoints);
            _updateProvider    = true;

            UpdateControlPointsState();
        }
Пример #3
0
 private static double[] GetMetersetWeights(ControlPointCollection controlPoints)
 {
     return(controlPoints.Select(x => x.MetersetWeight).ToArray());
 }
Пример #4
0
        public PlanData ExtractPlanData(PlanSetup pln)
        {
            ///////////////// Not original code by Amir, implemented from ExportPlanData (Yildirim Mutaf). Although, slight adjustments have been made.
            p1.ImageDate      = pln.StructureSet.Image.CreationDateTime.Value.ToString("g");
            p1.ImageId        = pln.StructureSet.Image.Id;
            p1.NumberOfImages = pln.StructureSet.Image.ZSize;
            p1.ImageResX      = pln.StructureSet.Image.XRes;
            p1.ImageResY      = pln.StructureSet.Image.YRes;
            p1.ImageResZ      = pln.StructureSet.Image.ZRes;
            p1.ContourId      = pln.StructureSet.Id;

            // RX INFORMATION
            RTPrescription rx = pln.RTPrescription;

            p1.PhysicianFullName = "NA";
            p1.RxSite            = "NA";
            p1.RxTechnique       = "NA";
            p1.RxSequence        = "NA";
            p1.RxNotes           = "";
            p1.RxTargets         = "";

            p1.Energy = "";

            if (rx != null)
            {
                p1.PhysicianFullName = rx.HistoryUserDisplayName;
                p1.RxSite            = rx.Site;
                p1.RxTechnique       = rx.Technique;
                p1.RxSequence        = rx.PhaseType;
                p1.RxNotes           = rx.Notes;
                p1.RxGating          = rx.Gating;

                IEnumerable <RTPrescriptionTarget> targets = rx.Targets;
                foreach (RTPrescriptionTarget trgt in targets)
                {
                    p1.RxTargets += trgt.TargetId + "; ";
                }


                //IEnumerable<string> ens = rx.Energies;
                //foreach (string en in ens)
                //    DATA.Energy += en + "; ";
            }
            else
            {
                // rx is null. set a flag to capture this.
            }
            p1.PlanOrientation = Enum.GetName(typeof(PatientOrientation), pln.TreatmentOrientation);
            p1.UseGating       = pln.UseGating;


            // FIELD INFORMATION
            IEnumerable <Beam> bms = pln.Beams;
            int    nbms            = 0;
            double Total_MU        = 0.0;
            //string enEnergyMode = "";
            double iso_X = 0.0, iso_Y = 0.0, iso_Z = 0.0;

            p1.MLCType        = "";
            p1.ToleranceTable = "";
            p1.BolusId        = "";
            p1.MachineId      = "";

            // bool SRS = false;
            p1.UseCouchKick   = false;
            p1.UseJawTracking = false;
            List <string> energies = new List <string>();

            foreach (Beam b in bms)
            {
                if (!b.IsSetupField)
                {
                    nbms++;
                    energies.Add(b.EnergyModeDisplayName);

                    Total_MU += b.Meterset.Value;

                    p1.MLCType        = Enum.GetName(typeof(MLCPlanType), b.MLCPlanType);
                    p1.MachineId      = b.TreatmentUnit.Id;
                    p1.ToleranceTable = b.ToleranceTableLabel;


                    List <double> x1jaws = new List <double>();
                    List <double> x2jaws = new List <double>();
                    List <double> y1jaws = new List <double>();
                    List <double> y2jaws = new List <double>();
                    // this is field specific

                    ControlPointCollection ctrl_colls = b.ControlPoints;
                    foreach (ControlPoint ctrl in ctrl_colls)
                    {
                        VRect <double> jaws = ctrl.JawPositions;
                        x1jaws.Add(jaws.X1);
                        x2jaws.Add(jaws.X2);
                        y1jaws.Add(jaws.Y1);
                        y2jaws.Add(jaws.Y2);
                    }
                    // this is field specific
                    double meanX1 = x1jaws.Average();
                    double meanX2 = x2jaws.Average();
                    double meanY1 = y1jaws.Average();
                    double meanY2 = y2jaws.Average();

                    double minX1 = x1jaws.Min();
                    double minX2 = x2jaws.Min();
                    double minY1 = y1jaws.Min();
                    double minY2 = y2jaws.Min();

                    double maxX1 = x1jaws.Max();
                    double maxX2 = x2jaws.Max();
                    double maxY1 = y1jaws.Max();
                    double maxY2 = y2jaws.Max();

                    if (Math.Abs(maxX1 - minX1) > 0.01 || Math.Abs(maxX2 - minX2) > 0.01 || Math.Abs(maxY1 - minY1) > 0.01 || Math.Abs(maxY2 - minY2) > 0.01)
                    {
                        p1.UseJawTracking = true;
                    }

                    if (!p1.UseCouchKick && b.ControlPoints.First().PatientSupportAngle != 0.0)
                    {
                        p1.UseCouchKick = true;
                    }

                    // this is field specific
                    double delta_X = (b.IsocenterPosition.x - pln.StructureSet.Image.UserOrigin.x) / 10.0;
                    double delta_Y = (b.IsocenterPosition.y - pln.StructureSet.Image.UserOrigin.y) / 10.0;
                    double delta_Z = (b.IsocenterPosition.z - pln.StructureSet.Image.UserOrigin.z) / 10.0;
                    iso_X = delta_X;
                    iso_Y = delta_Y;
                    iso_Z = delta_Z;

                    if (b.Boluses.Any()) // this is field specific
                    {
                        p1.BolusId = b.Boluses.First().Id;
                    }
                }
            }

            foreach (var en in energies.Distinct())
            {
                p1.Energy += en + "; ";
            }

            if (p1.Energy.IndexOf('E') >= 0)
            {
                p1.EnergyMode = "Electron";
            }
            else if (p1.Energy.IndexOf('X') >= 0)
            {
                p1.EnergyMode = "Photon";
            }
            else
            {
                p1.EnergyMode = "Unknown";
            }

            p1.NumberOfFields = nbms;

            p1.TotalMu = Total_MU;
            p1.IsoX    = iso_X;
            p1.IsoY    = iso_Y;
            p1.IsoZ    = iso_Z;

            p1.IsoXstr = Math.Round(iso_X, 2).ToString();
            p1.IsoYstr = Math.Round(iso_Y, 2).ToString();
            p1.IsoZstr = Math.Round(iso_Z, 2).ToString();

            p1.UseShifts = false;
            if (Math.Abs(iso_X) > 0.009 || Math.Abs(iso_Y) > 0.009 || Math.Abs(iso_Z) > 0.009)
            {
                p1.UseShifts = true;
            }

            p1.DoseAlgorithm  = "";
            p1.DoseGridSizeCM = "";
            p1.DoseMax3D      = 0.0;
            p1.DoseResX       = 0.0;
            p1.DoseResY       = 0.0;
            p1.DoseResZ       = 0.0;

            p1.TargetVolume      = pln.TargetVolumeID;
            p1.NumberOfFractions = pln.NumberOfFractions.Value;
            p1.FractionDose      = pln.PlannedDosePerFraction.Dose;
            p1.TotalDose         = pln.TotalDose.Dose;
            p1.PlanNormalization = pln.PlanNormalizationValue;
            p1.PrimaryRefPoint   = pln.PrimaryReferencePoint.Id;

            Dose dose = pln.Dose;

            if (dose != null)
            {
                p1.DoseMax3D = dose.DoseMax3D.Dose;
                p1.DoseResX  = dose.XRes;
                p1.DoseResY  = dose.YRes;
                p1.DoseResZ  = dose.ZRes;

                switch (p1.EnergyMode)
                {
                case "Photon":
                    p1.DoseAlgorithm = pln.PhotonCalculationModel;
                    break;

                case "Electron":
                    p1.DoseAlgorithm = pln.ElectronCalculationModel;
                    break;

                default:
                    break;
                }
            }
            else
            {
                p1.DoseIsNull = true;
            }


            return(p1);
        }
Пример #5
0
        public String CompareControlPoints(Beam b1, Beam b2, string DELIM)
        {// only do this if the number of control points are the same.
            String r       = "";
            float  epsilon = (float)0.001;
            //List<double> x1jaws = new List<double>();
            //List<double> x2jaws = new List<double>();
            //List<double> y1jaws = new List<double>();
            //List<double> y2jaws = new List<double>();

            List <double> CollAngle1 = new List <double>();
            List <double> CollAngle2 = new List <double>();


            ControlPointCollection ctrl_colls1 = b1.ControlPoints;
            ControlPointCollection ctrl_colls2 = b2.ControlPoints;
            double MU1 = b1.Meterset.Value;
            double MU2 = b2.Meterset.Value;

            int           nctrls          = ctrl_colls1.Count();
            int           MLCDiffTally    = 0;
            List <double> DeltaMU         = new List <double>(nctrls);
            List <double> DeltaCol        = new List <double>(nctrls);
            List <double> CouchAngle1     = new List <double>(nctrls);
            List <double> CouchAngle2     = new List <double>(nctrls);
            List <double> DeltaCouchAngle = new List <double>(nctrls);


            List <double> DeltaJawsX1 = new List <double>(nctrls);
            List <double> DeltaJawsX2 = new List <double>(nctrls);
            List <double> DeltaJawsY1 = new List <double>(nctrls);
            List <double> DeltaJawsY2 = new List <double>(nctrls);

            List <double> DeltaMUs = new List <double>(nctrls);

            List <double> CouchVrt1     = new List <double>(nctrls);
            List <double> CouchVrt2     = new List <double>(nctrls);
            List <double> DeltaCouchVrt = new List <double>(nctrls);

            List <double> CouchLng1     = new List <double>(nctrls);
            List <double> CouchLng2     = new List <double>(nctrls);
            List <double> DeltaCouchLng = new List <double>(nctrls);

            List <double> CouchLat1     = new List <double>(nctrls);
            List <double> CouchLat2     = new List <double>(nctrls);
            List <double> DeltaCouchLat = new List <double>(nctrls);

            for (int i = 1; i <= nctrls - 1; i++)
            {
                ControlPoint ctrl1  = ctrl_colls1[i];
                ControlPoint ctrl2  = ctrl_colls2[i];
                double       segMU1 = MU1 * (ctrl1.MetersetWeight - ctrl_colls1[i - 1].MetersetWeight);
                double       segMU2 = MU2 * (ctrl2.MetersetWeight - ctrl_colls2[i - 1].MetersetWeight);

                DeltaMU.Add(segMU1 - segMU2);

                CollAngle1.Add(ctrl1.CollimatorAngle);
                CollAngle2.Add(ctrl2.CollimatorAngle);
                DeltaCol.Add(ctrl1.CollimatorAngle - ctrl2.CollimatorAngle);

                CouchAngle1.Add(ctrl1.PatientSupportAngle);
                CouchAngle2.Add(ctrl2.PatientSupportAngle);
                DeltaCouchAngle.Add(ctrl1.PatientSupportAngle - ctrl2.PatientSupportAngle);

                CouchVrt1.Add(ctrl1.TableTopVerticalPosition);
                CouchVrt2.Add(ctrl2.TableTopVerticalPosition);
                DeltaCouchVrt.Add(ctrl1.TableTopVerticalPosition - ctrl2.TableTopVerticalPosition);

                CouchLng1.Add(ctrl1.TableTopLongitudinalPosition);
                CouchLng2.Add(ctrl2.TableTopLongitudinalPosition);
                DeltaCouchLng.Add(ctrl1.TableTopLongitudinalPosition - ctrl2.TableTopLongitudinalPosition);

                CouchLat1.Add(ctrl1.TableTopLateralPosition);
                CouchLat2.Add(ctrl2.TableTopLateralPosition);
                DeltaCouchLat.Add(ctrl1.TableTopLateralPosition - ctrl2.TableTopLateralPosition);

                MLCDiffTally += CompareMLCSequences(ctrl1, ctrl2);

                //DeltaLeafs.Add(ctrl1.LeafPositions[0,0] - ctrl2.LeafPositions[0,0]);

                VRect <double> jaws1 = ctrl1.JawPositions;
                VRect <double> jaws2 = ctrl2.JawPositions;

                DeltaJawsX1.Add((jaws1.X1 - jaws2.X1) / 10);
                DeltaJawsX2.Add((jaws1.X2 - jaws2.X2) / 10);
                DeltaJawsY1.Add((jaws1.Y1 - jaws2.Y1) / 10);
                DeltaJawsY2.Add((jaws1.Y2 - jaws2.Y2) / 10);
            }
            r += ShowCPDifference(DeltaMU, "MU", epsilon, DELIM);

            r += ReturnCPParameterComparison(CollAngle1, CollAngle2, DeltaCol, "Collimator angle", DELIM);
            r += ReturnCPParameterComparison(CouchAngle1, CouchAngle2, DeltaCouchAngle, "Couch angle", DELIM);
            r += ReturnCPParameterComparison(CouchVrt1, CouchVrt2, DeltaCouchVrt, "Couch Vrt", DELIM);
            r += ReturnCPParameterComparison(CouchLng1, CouchLng2, DeltaCouchLng, "Couch Lng", DELIM);
            r += ReturnCPParameterComparison(CouchLat1, CouchLat2, DeltaCouchLat, "Couch Lat", DELIM);



            if (MLCDiffTally > 0)
            {
                r += "Check - Differences found among leaf positions: " + MLCDiffTally + " different leaf pairs found. " + DELIM;
            }
            else
            {
                r += "OK - All control points show the same leaf positions" + DELIM;
            }

            r += ShowCPDifference(DeltaJawsX1, "X1 jaw", epsilon, DELIM);
            r += ShowCPDifference(DeltaJawsX2, "X2 jaw", epsilon, DELIM);
            r += ShowCPDifference(DeltaJawsY1, "Y1 jaw", epsilon, DELIM);

            DELIM = (Environment.NewLine).PadRight(10);
            r    += ShowCPDifference(DeltaJawsY2, "Y2 jaw", epsilon, DELIM);

            return(r);
        }
 private void getCP_btn_Click(object sender, RoutedEventArgs e)
 {
     //loop through the ffields
     foreach (Beam b in ps.Beams)
     //for (int ll = 0; ll < ps.Beams.Count(); ll++)
     {
         //Beam b = ps.Beams[ll];
         //List<cpInfo> cps = new List<cpInfo>();
         fields.Add(new FieldInfo
         {
             FieldId = b.Id,
             cpInfos = new List <cpInfo>(),
             Ebmp    = new ExternalBeamMachineParameters(b.TreatmentUnit.Id, b.EnergyModeDisplayName,
                                                         b.DoseRate, b.Technique.Id, null),
             collAngle        = b.ControlPoints.First().CollimatorAngle,
             gantry           = b.ControlPoints.First().GantryAngle,
             couch            = b.ControlPoints.First().PatientSupportAngle,
             isocenter        = b.IsocenterPosition,
             bp               = b.GetEditableParameters(),
             MU               = b.Meterset,
             gantry_direction = b.GantryDirection,
             gantry_stop      = b.GantryDirection == 0 ? b.ControlPoints.First().GantryAngle :
                                b.ControlPoints.Last().GantryAngle,
         });
         if (b.Applicator != null)
         {
             fields.Last().applicator = b.Applicator;
         }
         ControlPointCollection cpc = b.ControlPoints;
         //loop through control pointss and add to cps
         for (int cp = 0; cp < cpc.Count(); cp++)
         {
             //create a new instance of cpc
             fields.Last().cpInfos.Add(new cpInfo
             {
                 cpId      = cp,
                 cpDetails = new List <cpDetail>(),
                 meterSet  = cpc[cp].MetersetWeight,
             });
             float[,] leaf_positions = cpc[cp].LeafPositions;
             for (int i = 0; i < leaf_positions.GetLength(1); i++)
             {
                 fields.Last().cpInfos.Last().cpDetails.Add(new cpDetail
                 {
                     leaffNum = i,
                     //1 is a and 0 is b.
                     leafA = leaf_positions[1, i], //+10, //replace 10mm with leaf shifts
                     leafB = leaf_positions[0, i]  // +10 //replace 10mm with leaf shifts.
                 });
             }
         }
     }
     //make sure you got sosme controlpoints.
     if (fields.Count() != 0)
     {
         fieldnum = 0; cp_num = 0;
         //cp_dg.Items.Clear();
         cp_dg.ItemsSource = fields.First().cpInfos.First().cpDetails;
         cp_dg.Items.Refresh();
         fieldId.Content = fields.First().FieldId;
         cpId.Content    = String.Format("CP: {0}; MeterSet:{1}",
                                         fields.First().cpInfos.First().cpId, fields.First().cpInfos.First().meterSet);
     }
 }
Пример #7
0
        public void getDeliveryTimes(PlanSetup tempplan) // This method computes the beam on and MLC travel timesfor merged fields
        {
            float[,] tempMLC1, tempMLC0;                 // used to hold MLC positions for sequental segments
            float  maxmlc;
            double timebeamon = 0, timetravel = 0, segweight = 0, museg = 0, MLCspeed = 25.0;
            int    doserate, beamcount = 0;

            double[] totaltimebeam = new double[tempplan.Beams.Count()];
            foreach (Beam tempbeam in tempplan.Beams)
            {
                doserate = tempbeam.DoseRate;
                ControlPointCollection tempcollection = tempbeam.ControlPoints;
                if (!tempbeam.IsSetupField && !tempbeam.Technique.Id.Equals("ARC"))  // MLC travel between segments, don't calculate ARC treatments
                {
                    for (int i = 2; i < tempcollection.Count; i = i + 2)
                    {
                        tempMLC1         = tempcollection[i].LeafPositions; // (bank 0=B 1=A, MLC num)
                        tempMLC0         = tempcollection[i - 1].LeafPositions;
                        float[,] diffmlc = new float[tempMLC1.GetLength(0), tempMLC1.GetLength(1)];
                        for (int k = 0; k < tempMLC1.GetLength(0); k++)
                        {
                            for (int j = 0; j < tempMLC1.GetLength(1); j++)
                            {
                                diffmlc[k, j] = Math.Abs(tempMLC1[k, j] - tempMLC0[k, j]);
                            }
                        }
                        maxmlc      = diffmlc.Cast <float>().Max();
                        timetravel += maxmlc / MLCspeed;  // the total time (in sec) for the mlc to move between control points (no beam on), mlc travels at 25mm/sec
                        for (int n = 0; n < tempMLC1.GetLength(0); n++)
                        {
                            for (int s = 0; s < tempMLC1.GetLength(1); s++)
                            {
                                if (maxmlc == diffmlc[n, s])
                                {
                                    // MessageBox.Show("The index values are: " + n + " and " + s); //was used for testing
                                }
                            }
                        }
                    }
                }
                if (!tempbeam.IsSetupField && !tempbeam.Technique.Id.Equals("ARC")) // beam on time to deliver MUs
                {
                    for (int m = 1; m < tempcollection.Count; m = m + 2)
                    {
                        segweight   = tempcollection[m].MetersetWeight - tempcollection[m - 1].MetersetWeight;
                        museg       = segweight * tempbeam.Meterset.Value;
                        timebeamon += 60.0 * museg / doserate;  // the time with beam on (in sec)
                    }
                }
                totaltimebeam[beamcount] = Math.Round(timebeamon + timetravel, 1);
                if (!tempbeam.IsSetupField && !tempbeam.Technique.Id.Equals("ARC")) // add the beam to the list
                {
                    var ctlpt = tempbeam.ControlPoints.First();
                    beamtimes.Add(new BeamTimes {
                        BeamName = tempbeam.Id, BeamOnTime = timebeamon, MLCTravelTime = timetravel, gantryangle = ctlpt.GantryAngle, energy = tempbeam.EnergyModeDisplayName
                    });
                }

                timebeamon = 0;
                timetravel = 0;
                beamcount++;
            }

            //String message = null;
            //foreach(var listitem in beamtimes)
            //{
            //    message = message + listitem.BeamName + " Beam time (s): " + Math.Round(listitem.BeamOnTime + listitem.MLCTravelTime, 1).ToString("0.0") + "\n";
            //}

            //MessageBox.Show(message);
        }
Пример #8
0
        /// <summary>
        /// Renders the glyph to the render surface in font units relative to a bottom left origin at (0,0)
        /// </summary>
        /// <param name="surface">The surface.</param>
        /// <param name="pointSize">Size of the point.</param>
        /// <param name="location">The location.</param>
        /// <param name="dpi">The dpi.</param>
        /// <exception cref="System.NotSupportedException">Too many control points</exception>
        public void RenderTo(IGlyphRenderer surface, float pointSize, Vector2 location, Vector2 dpi)
        {
            location = location * dpi;

            int pointIndex  = 0;
            var scaleFactor = (float)(this.sizeOfEm * 72f);

            surface.BeginGlyph();

            Vector2 firstPoint = Vector2.Zero;
            Vector2 scale      = new Vector2(1, -1);

            for (int i = 0; i < this.endPoints.Length; i++)
            {
                int  nextContour              = this.endPoints[i] + 1;
                bool isFirstPoint             = true;
                ControlPointCollection points = new ControlPointCollection();
                bool justFromCurveMode        = false;

                for (; pointIndex < nextContour; ++pointIndex)
                {
                    var point = location + (scale * ((this.controlPoints[pointIndex] * pointSize * dpi) / scaleFactor)); // scale each point as we go, w will now have the correct relative point size

                    if (this.onCurves[pointIndex])
                    {
                        // on curve
                        if (justFromCurveMode)
                        {
                            points = DrawPoints(surface, points, point);
                        }
                        else
                        {
                            if (isFirstPoint)
                            {
                                isFirstPoint = false;
                                firstPoint   = point;
                                surface.MoveTo(firstPoint);
                            }
                            else
                            {
                                surface.LineTo(point);
                            }
                        }
                    }
                    else
                    {
                        switch (points.Count)
                        {
                        case 0:
                            points.Add(point);
                            break;

                        case 1:
                            // we already have prev second control point
                            // so auto calculate line to
                            // between 2 point
                            Vector2 mid = (points.SecondControlPoint + point) / 2;
                            surface.QuadraticBezierTo(
                                points.SecondControlPoint,
                                mid);
                            points.SecondControlPoint = point;     //replace 2nd
                            break;

                        default:
                            throw new NotSupportedException("Too many control points");
                        }
                    }
                    justFromCurveMode = !this.onCurves[pointIndex];
                }

                // close figure
                // if in curve mode
                if (justFromCurveMode)
                {
                    DrawPoints(surface, points, firstPoint);
                }

                surface.EndFigure();
            }

            surface.EndGlyph();
        }