public static double GetVolumeAtDose(this PlanningItem pitem, Structure structure, DoseValue dose, VolumePresentation requestedVolumePresentation) { if (pitem is PlanSetup) { return(((PlanSetup)pitem).GetVolumeAtDose(structure, dose, requestedVolumePresentation)); } else { DVHData dvh = pitem.GetDVHCumulativeData(structure, DoseValuePresentation.Absolute, requestedVolumePresentation, 0.001); return(DVHExtensions.VolumeAtDose(dvh, dose.Dose)); } }
public static DoseValue GetDoseAtVolume(this PlanningItem pitem, Structure structure, double volume, VolumePresentation volumePresentation, DoseValuePresentation requestedDosePresentation) { if (pitem is PlanSetup) { return(((PlanSetup)pitem).GetDoseAtVolume(structure, volume, volumePresentation, requestedDosePresentation)); } else { if (requestedDosePresentation != DoseValuePresentation.Absolute) { throw new ApplicationException("Only absolute dose supported for Plan Sums"); } DVHData dvh = pitem.GetDVHCumulativeData(structure, DoseValuePresentation.Absolute, volumePresentation, 0.001); return(DVHExtensions.DoseAtVolume(dvh, volume)); } }
private void ParsingMetric() { // parsing and calculating metric. All results are in absolute metricValues = new dynamic[numItems]; VolumePresentation volpres = new VolumePresentation(); DoseValue dosevalue = new DoseValue(-1, DoseValue.DoseUnit.cGy); double value = -1; int length; for (int i = 0; i < numItems; i++) { length = metricList[i].Length; //MessageBox.Show(metricList[i]); if (metricList[i].ToLower() == "dmax" || metricList[i].ToLower() == "p_dmax") { // exclude non-existing structures if (rtStructureDic[structureList[i]] is null) { continue; } //// for 15.6 //if (rtStructureDic[structureList[i]].IsEmpty) //{ // metricValues[i] = new DoseValue(-1, DoseValue.DoseUnit.cGy); //} //else //{ // var dvh = plan.GetDVHCumulativeData(rtStructureDic[structureList[i]], // DoseValuePresentation.Absolute, VolumePresentation.AbsoluteCm3, 0.01); // metricValues[i] = dvh.MaxDose; //} // for 13.6 try { double structVolume = rtStructureDic[structureList[i]].Volume; // to verify struct exists. var dvh = plan.GetDVHCumulativeData(rtStructureDic[structureList[i]], DoseValuePresentation.Absolute, VolumePresentation.AbsoluteCm3, 0.01); metricValues[i] = dvh.MaxDose; //metricValues[i] = plan.GetDoseAtVolume(rtStructureDic[structureList[i]], 0, // VolumePresentation.Relative, DoseValuePresentation.Absolute); } catch { // in case structure not exist. metricValues[i] = new DoseValue(-1, DoseValue.DoseUnit.cGy); // make it float. } if (metricList[i].ToLower() == "p_dmax") // % of struct max to presc { metricValues[i] = 100.0 * metricValues[i] / plan.TotalDose; } } else if (metricList[i].ToUpper().StartsWith("V_") || // V_##% returns % relative metricList[i].ToUpper().StartsWith("R_")) // R_##% returns ratio to VPTV { if (metricList[i].EndsWith("%")) { // convert percentage to absolute in cGy value = Convert.ToDouble(metricList[i].Substring(2, length - 3)) * plan.TotalDose.Dose / 100.0; dosevalue = new DoseValue(value, DoseValue.DoseUnit.cGy); } else if (metricList[i].ToLower().EndsWith("cgy")) { value = Convert.ToDouble(metricList[i].Substring(2, length - 5)); dosevalue = new DoseValue(value, DoseValue.DoseUnit.cGy); } if (dosevalue.Dose > globalDmax.Dose) { metricValues[i] = 0; } else { DVHData dvh = plan.GetDVHCumulativeData(rtStructureDic[structureList[i]], DoseValuePresentation.Absolute, VolumePresentation.AbsoluteCm3, 0.01); double ddose = (dosevalue.Unit == DoseValue.DoseUnit.cGy) ? dosevalue.Dose : dosevalue.Dose * 100.0; metricValues[i] = 100 * DVHExtensions.VolumeAtDose(dvh, ddose) / DVHExtensions.VolumeAtDose(dvh, 0.0); // to % //metricValues[i] = plan.GetVolumeAtDose(rtStructureDic[structureList[i]], // dosevalue, VolumePresentation.Relative); } if (metricList[i].ToUpper().StartsWith("R_")) // ratio of Abs to VPTV { double structVolume; // if structure not exist, set volume to 0. try { structVolume = rtStructureDic[structureList[i]].Volume; } catch { structVolume = -1.0; } metricValues[i] = (metricValues[i] * structVolume / (100 * ptvVolume)); //metricValues[i] = (metricValues[i] / ptvVolume) * 100.0; // to % //* rtStructureDic[structureList[i]].Volume / (100 * ptvVolume); } } else if (metricList[i].ToUpper().StartsWith("D_")) // D_##% or D_##cc { if (metricList[i].ToLower().EndsWith("cc")) { volpres = VolumePresentation.AbsoluteCm3; value = Convert.ToDouble(metricList[i].Substring(2, length - 4)); } else if (metricList[i].EndsWith("%")) { volpres = VolumePresentation.Relative; value = Convert.ToDouble(metricList[i].Substring(2, length - 3)); } try { DVHData dvh = plan.GetDVHCumulativeData(rtStructureDic[structureList[i]], DoseValuePresentation.Absolute, volpres, 0.01); metricValues[i] = DVHExtensions.DoseAtVolume(dvh, value); //metricValues[i] = plan.GetDoseAtVolume(rtStructureDic[structureList[i]], // value, volpres, DoseValuePresentation.Absolute); } catch { metricValues[i] = new DoseValue(-1, DoseValue.DoseUnit.cGy); } } else { metricValues[i] = "Unknown Metric: " + metricList[i]; } } // System.Windows.MessageBox.Show("Parsing metric done"); return; }