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); } }