public void Execute(ScriptContext context /*, System.Windows.Window window, ScriptEnvironment environment*/) { if (context.Patient != null) { MessageBox.Show("Patient id is " + context.Patient.Id); Patient patient = context.Patient; foreach (IonBeam ionBeam in context.IonPlanSetup.IonBeams) { IonBeamParameters beamParameters = ionBeam.GetEditableParameters(); IonControlPointPairCollection layers = beamParameters.IonControlPointPairs; List <List <double> > allLayersParams = new List <List <double> >(); foreach (IonControlPointPair layer in layers) { List <double> thisLayerParams = new List <double>(); double energyForThisLayer = layer.NominalBeamEnergy; double minSpotWeightFromOptimization = 1000; double maxSpotWeightFromOptimization = 0; foreach (IonSpotParameters spot in layer.RawSpotList) { if (spot.Weight < minSpotWeightFromOptimization) { minSpotWeightFromOptimization = spot.Weight; } if (spot.Weight > maxSpotWeightFromOptimization) { maxSpotWeightFromOptimization = spot.Weight; } } thisLayerParams.Add(energyForThisLayer); thisLayerParams.Add(minSpotWeightFromOptimization); thisLayerParams.Add(maxSpotWeightFromOptimization); allLayersParams.Add(thisLayerParams); } string report = ""; report += "Energy Raw min Raw max\n"; foreach (List <double> line in allLayersParams) { report += String.Format("{0,8:F1} {1,12:f2} {2,13:f2}\n", line[0], line[1], line[2]); } MessageBox.Show(report); } } }
public void Execute(ScriptContext context /*, System.Windows.Window window, ScriptEnvironment environment*/) { if (context.Patient != null) { MessageBox.Show("Patient id is " + context.Patient.Id); Patient patient = context.Patient; patient.BeginModifications(); foreach (IonBeam ionBeam in context.IonPlanSetup.IonBeams) { IonBeamParameters beamParameters = ionBeam.GetEditableParameters(); IonControlPointPairCollection layers = beamParameters.IonControlPointPairs; List <List <double> > allLayersParams = new List <List <double> >(); double minEnergy = 70; double maxEnergy = 250; double spotWeightLowerLimitAtMinEnergy = 0.1; double spotWeightLowerLimitAtMaxEnergy = 2; double spotWeightUpperLimitAtMinEnergy = 15; double spotWeightUpperLimitAtMaxEnergy = 30; foreach (IonControlPointPair layer in layers) { List <double> thisLayerParams = new List <double>(); double energyForThisLayer = layer.NominalBeamEnergy; double minSpotWeightFromOptimization = 1000; double maxSpotWeightFromOptimization = 0; double minSpotWeightAfterProcessing = 1000; double maxSpotWeightAfterProcessing = 0; double spotWeightLowerLimitForThisLayer = spotWeightLowerLimitAtMinEnergy + (spotWeightLowerLimitAtMaxEnergy - spotWeightLowerLimitAtMinEnergy) * (energyForThisLayer - minEnergy) / (maxEnergy - minEnergy); double spotWeightUpperLimitForThisLayer = spotWeightUpperLimitAtMinEnergy + (spotWeightUpperLimitAtMaxEnergy - spotWeightUpperLimitAtMinEnergy) * (energyForThisLayer - minEnergy) / (maxEnergy - minEnergy); foreach (IonSpotParameters spot in layer.RawSpotList) { if (spot.Weight < minSpotWeightFromOptimization) { minSpotWeightFromOptimization = spot.Weight; } if (spot.Weight > maxSpotWeightFromOptimization) { maxSpotWeightFromOptimization = spot.Weight; } if (spot.Weight < spotWeightLowerLimitForThisLayer) { if (spot.Weight < 0.5 * spotWeightLowerLimitForThisLayer) { spot.Weight = 0; } else { spot.Weight = (float)spotWeightLowerLimitForThisLayer; } } if (spot.Weight > spotWeightUpperLimitForThisLayer) { spot.Weight = (float)spotWeightUpperLimitForThisLayer; } if (spot.Weight < minSpotWeightAfterProcessing) { minSpotWeightAfterProcessing = spot.Weight; } if (spot.Weight > maxSpotWeightAfterProcessing) { maxSpotWeightAfterProcessing = spot.Weight; } } thisLayerParams.Add(energyForThisLayer); thisLayerParams.Add(minSpotWeightFromOptimization); thisLayerParams.Add(maxSpotWeightFromOptimization); thisLayerParams.Add(minSpotWeightAfterProcessing); thisLayerParams.Add(maxSpotWeightAfterProcessing); allLayersParams.Add(thisLayerParams); } ionBeam.ApplyParameters(beamParameters); string report = ""; report += "Energy Raw min Raw max PP min PP max\n"; foreach (List <double> line in allLayersParams) { report += String.Format("{0,8:F1} {1,12:f2} {2,13:f2} {3,10:f2} {4,10:f2} \n", line[0], line[1], line[2], line[3], line[4]); } MessageBox.Show(report); } } }