private long QueryRec(int i, VInt2 p, long radius, Agent agent, VRect r) { if (this.nodes[i].child00 == i) { for (Agent agent2 = this.nodes[i].linkedList; agent2 != null; agent2 = agent2.next) { long num = agent.InsertAgentNeighbour(agent2, radius * radius); if (num < radius * radius) { radius = (long)IntMath.Sqrt(num); } } } else { VInt2 center = r.center; if ((long)p.x - radius < (long)center.x) { if ((long)p.y - radius < (long)center.y) { radius = this.QueryRec(this.nodes[i].child00, p, radius, agent, VRect.MinMaxRect(r.xMin, r.yMin, center.x, center.y)); } if ((long)p.y + radius > (long)center.y) { radius = this.QueryRec(this.nodes[i].child01, p, radius, agent, VRect.MinMaxRect(r.xMin, center.y, center.x, r.yMax)); } } if ((long)p.x + radius > (long)center.x) { if ((long)p.y - radius < (long)center.y) { radius = this.QueryRec(this.nodes[i].child10, p, radius, agent, VRect.MinMaxRect(center.x, r.yMin, r.xMax, center.y)); } if ((long)p.y + radius > (long)center.y) { radius = this.QueryRec(this.nodes[i].child11, p, radius, agent, VRect.MinMaxRect(center.x, center.y, r.xMax, r.yMax)); } } } return(radius); }
private void BuildQuadtree() { this.quadtree.Clear(); if (this.agents.Count > 0) { VRect r = VRect.MinMaxRect(this.agents[0].position.x, this.agents[0].position.y, this.agents[0].position.x, this.agents[0].position.y); for (int i = 1; i < this.agents.Count; i++) { VInt3 position = this.agents[i].position; int left = Mathf.Min(r.xMin, position.x); int top = Mathf.Min(r.yMin, position.z); int right = Mathf.Max(r.xMax, position.x); r = VRect.MinMaxRect(left, top, right, Mathf.Max(r.yMax, position.z)); } this.quadtree.SetBounds(r); for (int j = 0; j < this.agents.Count; j++) { this.quadtree.Insert(this.agents[j]); } } }
private long QueryRec(int i, Int2 p, long radius, Agent agent, VRect r) { if (this.nodes[i].child00 == i) { for (Agent agent2 = this.nodes[i].linkedList; agent2 != null; agent2 = agent2.next) { long a = agent.InsertAgentNeighbour(agent2, radius * radius); if (a < (radius * radius)) { radius = IntMath.Sqrt(a); } } return(radius); } Int2 center = r.center; if ((p.x - radius) < center.x) { if ((p.y - radius) < center.y) { radius = this.QueryRec(this.nodes[i].child00, p, radius, agent, VRect.MinMaxRect(r.xMin, r.yMin, center.x, center.y)); } if ((p.y + radius) > center.y) { radius = this.QueryRec(this.nodes[i].child01, p, radius, agent, VRect.MinMaxRect(r.xMin, center.y, center.x, r.yMax)); } } if ((p.x + radius) > center.x) { if ((p.y - radius) < center.y) { radius = this.QueryRec(this.nodes[i].child10, p, radius, agent, VRect.MinMaxRect(center.x, r.yMin, r.xMax, center.y)); } if ((p.y + radius) > center.y) { radius = this.QueryRec(this.nodes[i].child11, p, radius, agent, VRect.MinMaxRect(center.x, center.y, r.xMax, r.yMax)); } } return(radius); }
// Token: 0x06001102 RID: 4354 RVA: 0x0005A498 File Offset: 0x00058698 public bool Overlaps(VRect other) { return(other.xMax > this.xMin && other.xMin < this.xMax && other.yMax > this.yMin && other.yMin < this.yMax); }
public bool Overlaps(VRect other) { return((((other.xMax > this.xMin) && (other.xMin < this.xMax)) && (other.yMax > this.yMin)) && (other.yMin < this.yMax)); }
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); }
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); }
public void SetBounds(VRect r) { this.bounds = r; }
// SCR_CalcRefdef // // Must be called whenever vid changes // Internal use only private void CalcRefdef( ) { Host.Screen.FullUpdate = 0; // force a background redraw _VidDef.recalc_refdef = false; // force the status bar to redraw Host.Hud.Changed( ); // bound viewsize if (Host.Cvars.ViewSize.Get <Single>( ) < 30) { Host.CVars.Set("viewsize", 30f); } if (Host.Cvars.ViewSize.Get <Single>( ) > 120) { Host.CVars.Set("viewsize", 120f); } // bound field of view if (Host.Cvars.Fov.Get <Single>( ) < 10) { Host.CVars.Set("fov", 10f); } if (Host.Cvars.Fov.Get <Single>( ) > 170) { Host.CVars.Set("fov", 170f); } // intermission is always full screen Single size; if (Host.Client.cl.intermission > 0) { size = 120; } else { size = Host.Cvars.ViewSize.Get <Single>( ); } if (size >= 120) { Host.Hud.Lines = 0; // no status bar at all } else if (size >= 110) { Host.Hud.Lines = 24; // no inventory } else { Host.Hud.Lines = 24 + 16 + 8; } var full = false; if (Host.Cvars.ViewSize.Get <Single>( ) >= 100.0) { full = true; size = 100.0f; } else { size = Host.Cvars.ViewSize.Get <Single>( ); } if (Host.Client.cl.intermission > 0) { full = true; size = 100; Host.Hud.Lines = 0; } size /= 100.0f; var h = _VidDef.height - Host.Hud.Lines; var rdef = Host.RenderContext.RefDef; rdef.vrect.width = ( Int32 )(_VidDef.width * size); if (rdef.vrect.width < 96) { size = 96.0f / rdef.vrect.width; rdef.vrect.width = 96; // min for icons } rdef.vrect.height = ( Int32 )(_VidDef.height * size); if (rdef.vrect.height > _VidDef.height - Host.Hud.Lines) { rdef.vrect.height = _VidDef.height - Host.Hud.Lines; } if (rdef.vrect.height > _VidDef.height) { rdef.vrect.height = _VidDef.height; } rdef.vrect.x = (_VidDef.width - rdef.vrect.width) / 2; if (full) { rdef.vrect.y = 0; } else { rdef.vrect.y = (h - rdef.vrect.height) / 2; } rdef.fov_x = Host.Cvars.Fov.Get <Single>( ); rdef.fov_y = CalcFov(rdef.fov_x, rdef.vrect.width, rdef.vrect.height); _VRect = rdef.vrect; }
public void Insert(Agent agent) { int num = 0; VRect r = this.bounds; VInt2 xz = agent.position.xz; agent.next = null; this.maxRadius = IntMath.Max((long)agent.radius.i, this.maxRadius); int num2 = 0; while (true) { num2++; if (this.nodes[num].child00 == num) { if (this.nodes[num].count < 15 || num2 > 10) { break; } RVOQuadtree.Node node = this.nodes[num]; node.child00 = this.GetNodeIndex(); node.child01 = this.GetNodeIndex(); node.child10 = this.GetNodeIndex(); node.child11 = this.GetNodeIndex(); this.nodes[num] = node; this.nodes[num].Distribute(this.nodes, r); } if (this.nodes[num].child00 != num) { VInt2 center = r.center; if (xz.x > center.x) { if (xz.y > center.y) { num = this.nodes[num].child11; r = VRect.MinMaxRect(center.x, center.y, r.xMax, r.yMax); } else { num = this.nodes[num].child10; r = VRect.MinMaxRect(center.x, r.yMin, r.xMax, center.y); } } else if (xz.y > center.y) { num = this.nodes[num].child01; r = VRect.MinMaxRect(r.xMin, center.y, center.x, r.yMax); } else { num = this.nodes[num].child00; r = VRect.MinMaxRect(r.xMin, r.yMin, center.x, center.y); } } } this.nodes[num].Add(agent); RVOQuadtree.Node[] array = this.nodes; int num3 = num; array[num3].count = array[num3].count + 1; }
public void SetJawPositions(VRect <double> positions) { var local = this; X.Instance.CurrentContext.Thread.Invoke(() => { local._client.SetJawPositions(positions); }); }
public void SetupFieldsPerformUpdates() { Log.Initialize(_context); _context.Patient.BeginModifications(); ExternalPlanSetup plan = _context.PlanSetup as ExternalPlanSetup; Beam beam = plan.Beams.FirstOrDefault(); VRect <double> jaws = new VRect <double>(-50, -50, 50, 50); ExternalBeamMachineParameters machineParams = new ExternalBeamMachineParameters(beam.TreatmentUnit.Id, beam.EnergyModeDisplayName, beam.DoseRate, "STATIC", ""); int ap, pa, rtLat, ltLat; switch (PatientOrientation) { case "HeadFirstSupine": ap = 0; pa = 180; rtLat = 270; ltLat = 90; break; case "FeetFirstSupine": ap = 0; pa = 180; rtLat = 90; ltLat = 270; break; case "HeadFirstProne": ap = 180; pa = 0; rtLat = 90; ltLat = 270; break; case "FeetFirstProne": ap = 180; pa = 0; rtLat = 270; ltLat = 90; break; default: ap = 0; pa = 180; rtLat = 270; ltLat = 90; break; } if (!MvKvPairFlag) { if (CbctFlag) { plan.AddSetupBeam(machineParams, jaws, 0, 0, 0, beam.IsocenterPosition).Id = _cbctName; } if (ApFlag) { plan.AddSetupBeam(machineParams, jaws, 0, ap, 0, beam.IsocenterPosition).Id = _apName; } if (PaFlag) { plan.AddSetupBeam(machineParams, jaws, 0, pa, 0, beam.IsocenterPosition).Id = _paName; } if (RtLatFlag) { plan.AddSetupBeam(machineParams, jaws, 0, rtLat, 0, beam.IsocenterPosition).Id = _rtLatName; } if (LtLatFlag) { plan.AddSetupBeam(machineParams, jaws, 0, ltLat, 0, beam.IsocenterPosition).Id = _ltLatName; } } else { if (CbctFlag) { plan.AddSetupBeam(machineParams, jaws, 0, 0, 0, beam.IsocenterPosition).Id = _cbctName; } if (ApFlag) { plan.AddSetupBeam(machineParams, jaws, 0, ap, 0, beam.IsocenterPosition).Id = $"{_apName} {Suffix1}"; plan.AddSetupBeam(machineParams, jaws, 0, ap, 0, beam.IsocenterPosition).Id = $"{_apName} {Suffix2}"; } if (PaFlag) { plan.AddSetupBeam(machineParams, jaws, 0, pa, 0, beam.IsocenterPosition).Id = $"{_paName} {Suffix1}"; plan.AddSetupBeam(machineParams, jaws, 0, pa, 0, beam.IsocenterPosition).Id = $"{_paName} {Suffix2}"; } if (RtLatFlag) { plan.AddSetupBeam(machineParams, jaws, 0, rtLat, 0, beam.IsocenterPosition).Id = $"{_rtLatName} {Suffix1}"; plan.AddSetupBeam(machineParams, jaws, 0, rtLat, 0, beam.IsocenterPosition).Id = $"{_rtLatName} {Suffix2}"; } if (LtLatFlag) { plan.AddSetupBeam(machineParams, jaws, 0, ltLat, 0, beam.IsocenterPosition).Id = $"{_ltLatName} {Suffix1}"; plan.AddSetupBeam(machineParams, jaws, 0, ltLat, 0, beam.IsocenterPosition).Id = $"{_ltLatName} {Suffix2}"; } } log.Info("Setup Fields"); LogManager.Shutdown(); }
//GG //public void QueryRec(int i, Rect r) public void QueryRec(int i, VRect r) { // Determine the radius that we need to search to take all agents into account // Note: the second agentRadius usage should actually be the radius of the other agents, not this agent // but for performance reasons and for simplicity we assume that agents have approximately the same radius. // Thus an agent with a very small radius may in some cases detect an agent with a very large radius too late // however this effect should be minor. var radius = System.Math.Min(System.Math.Max((nodes[i].maxSpeed + speed) * timeHorizon, agentRadius) + agentRadius, maxRadius); if (nodes[i].child00 == i) { // Leaf node for (Agent a = nodes[i].linkedList; a != null; a = a.next) { //GG //float v = agent.InsertAgentNeighbour(a, radius * radius); long v = agent.InsertAgentNeighbour(a, (int)(radius * radius)); // Limit the search if the agent has hit the max number of nearby agents threshold if (v < maxRadius * maxRadius) { //GG //maxRadius = Mathf.Sqrt(v); maxRadius = IntMath.Sqrt(v); } } } else { // Not a leaf node //GG //Vector2 c = r.center; VInt2 c = r.center; if (p.x - radius < c.x) { if (p.y - radius < c.y) { //GG //QueryRec(nodes[i].child00, Rect.MinMaxRect(r.xMin, r.yMin, c.x, c.y)); QueryRec(nodes[i].child00, VRect.MinMaxRect(r.xMin, r.yMin, c.x, c.y)); radius = System.Math.Min(radius, maxRadius); } if (p.y + radius > c.y) { //GG //QueryRec(nodes[i].child01, Rect.MinMaxRect(r.xMin, c.y, c.x, r.yMax)); QueryRec(nodes[i].child01, VRect.MinMaxRect(r.xMin, c.y, c.x, r.yMax)); radius = System.Math.Min(radius, maxRadius); } } if (p.x + radius > c.x) { if (p.y - radius < c.y) { //GG //QueryRec(nodes[i].child10, Rect.MinMaxRect(c.x, r.yMin, r.xMax, c.y)); QueryRec(nodes[i].child10, VRect.MinMaxRect(c.x, r.yMin, r.xMax, c.y)); radius = System.Math.Min(radius, maxRadius); } if (p.y + radius > c.y) { //GG //QueryRec(nodes[i].child11, Rect.MinMaxRect(c.x, c.y, r.xMax, r.yMax)); QueryRec(nodes[i].child11, VRect.MinMaxRect(c.x, c.y, r.xMax, r.yMax)); } } } }
/** Add a new agent to the tree. * \warning Agents must not be added multiple times to the same tree */ public void Insert(Agent agent) { int i = 0; //GG /*Rect r = bounds; * Vector2 p = new Vector2(agent.position.x, agent.position.y);*/ VRect r = bounds; VInt2 p = new VInt2(agent.position.x, agent.position.y); agent.next = null; //GG //maxRadius = System.Math.Max(agent.radius, maxRadius); maxRadius = System.Math.Max((int)agent.radius, maxRadius); int depth = 0; while (true) { depth++; if (nodes[i].child00 == i) { // Leaf node. Break at depth 10 in case lots of agents ( > LeafSize ) are in the same spot if (nodes[i].count < LeafSize || depth > 10) { nodes[i].Add(agent); nodes[i].count++; break; } else { // Split Node node = nodes[i]; node.child00 = GetNodeIndex(); node.child01 = GetNodeIndex(); node.child10 = GetNodeIndex(); node.child11 = GetNodeIndex(); nodes[i] = node; nodes[i].Distribute(nodes, r); } } // Note, no else if (nodes[i].child00 != i) { // Not a leaf node //GG //Vector2 c = r.center; VInt2 c = r.center; if (p.x > c.x) { if (p.y > c.y) { i = nodes[i].child11; //GG //r = Rect.MinMaxRect(c.x, c.y, r.xMax, r.yMax); r = VRect.MinMaxRect(c.x, c.y, r.xMax, r.yMax); } else { i = nodes[i].child10; //GG //r = Rect.MinMaxRect(c.x, r.yMin, r.xMax, c.y); r = VRect.MinMaxRect(c.x, r.yMin, r.xMax, c.y); } } else { if (p.y > c.y) { i = nodes[i].child01; //GG //r = Rect.MinMaxRect(r.xMin, c.y, c.x, r.yMax); r = VRect.MinMaxRect(r.xMin, c.y, c.x, r.yMax); } else { i = nodes[i].child00; //GG //r = Rect.MinMaxRect(r.xMin, r.yMin, c.x, c.y); r = VRect.MinMaxRect(r.xMin, r.yMin, c.x, c.y); } } } } }
//GG //public void SetBounds(Rect r) public void SetBounds(VRect r) { bounds = r; }
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"; }