public static MLCDefinitions GetInstance() { if (instance == null) { instance = new MLCDefinitions(); } return(instance); }
public static void GeneratePlan(VMS.TPS.Common.Model.API.Application app, MLCDefinitions mlcs, ExternalBeamMachineParameters beamPars, IMRTGenerator.JSON.Patient patient, IEnumerable <IMRTGenerator.JSON.Beam> beams ) { var pat = app.OpenPatientById(patient.PatientId); var sSet = pat.StructureSets.Single(ss => ss.Id == patient.StructureSet); pat.BeginModifications(); var cr = pat.Courses.SingleOrDefault(cr_ => cr_.Id == "DTPCOURSE"); if (null == cr) { cr = pat.AddCourse(); cr.Id = "DTPCOURSE"; } var plan = cr.AddExternalPlanSetup(sSet); // // Cannot use target structure // var targetStructure = sSet.Structures.Single(s => s.Id == plan.TargetVolumeID); var isoCenter = targetStructure.CenterPoint; foreach (var bm in beams) { var beam = plan.AddMLCBeam(beamPars, null, default(VRect <double>), 0.0, bm.GantryAngleInDeg, bm.PatientSupportAngleInDeg, isoCenter); beam.FitMLCToStructure(new FitToStructureMargins(bm.MlcMarginInmm), targetStructure, true, JawFitting.FitToRecommended, OpenLeavesMeetingPoint.OpenLeavesMeetingPoint_Middle, ClosedLeavesMeetingPoint.ClosedLeavesMeetingPoint_Center); adjustJaws(beam, bm.BeamletSizeXInmm, mlcs.MLCs[beam.MLC.Id].LeafWidths()); } if (null == calcModel) { calcModel = plan.GetModelsForCalculationType(CalculationType.PhotonInfluenceMatrix)?.OrderByDescending(cm => cm, new ModelNameComparer()).First(); calcModel = calcModel == null ? "" : calcModel; } plan.SetCalculationModel(CalculationType.PhotonInfluenceMatrix, calcModel); app.SaveModifications(); }
static void Main(string[] args) { var loc = System.Reflection.Assembly.GetExecutingAssembly().Location; var sname = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name; loc = loc.Substring(0, loc.Length - sname.Length - 4); var fileName = @"InputData.json"; var mlcs = MLCDefinitions.GetInstance(); using (var app = VMS.TPS.Common.Model.API.Application.CreateApplication()) { JSON.InputData inputData; using (var inputFile = new StreamReader(Path.Combine(loc, fileName))) { inputData = JSON.InputData.FromJson(inputFile.ReadToEnd()); } var beamPars = new ExternalBeamMachineParameters( inputData.Machine.MachineId, inputData.Machine.EnergyMode, (int)inputData.Machine.DoseRate, "STATIC", null ); foreach (var patInfo in inputData.Patients) { Generator.GeneratePlan(app, mlcs, beamPars, patInfo, inputData.Beams); } } }