Beispiel #1
0
        public static DoseValue CalculateMeanDose(PlanSetup plan, Structure structure)
        {
            Dose dose = plan.Dose;

            if (dose == null)
            {
                return(new DoseValue(Double.NaN, DoseValue.DoseUnit.Unknown));
            }

            plan.DoseValuePresentation = DoseValuePresentation.Absolute;

            double sum   = 0.0;
            int    count = 0;

            double xres = 2.5;
            double yres = 2.5;
            double zres = 2.5;

            int xcount = (int)((dose.XRes * dose.XSize) / xres);

            System.Collections.BitArray segmentStride = new System.Collections.BitArray(xcount);
            double[]           doseArray = new double[xcount];
            DoseValue.DoseUnit doseUnit  = dose.DoseMax3D.Unit;

            for (double z = 0; z < dose.ZSize * dose.ZRes; z += zres)
            {
                for (double y = 0; y < dose.YSize * dose.YRes; y += yres)
                {
                    VVector start = dose.Origin +
                                    dose.YDirection * y +
                                    dose.ZDirection * z;
                    VVector end = start + dose.XDirection * dose.XRes * dose.XSize;

                    SegmentProfile segmentProfile = structure.GetSegmentProfile(start, end, segmentStride);
                    DoseProfile    doseProfile    = null;

                    for (int i = 0; i < segmentProfile.Count; i++)
                    {
                        if (segmentStride[i])
                        {
                            if (doseProfile == null)
                            {
                                doseProfile = dose.GetDoseProfile(start, end, doseArray);
                            }

                            double doseValue = doseProfile[i].Value;
                            if (!Double.IsNaN(doseValue))
                            {
                                sum += doseProfile[i].Value;
                                count++;
                            }
                        }
                    }
                    doseProfile = null;
                }
            }
            double mean = sum / ((double)count);

            return(new DoseValue(mean, doseUnit));
        }
Beispiel #2
0
        public double[] GetDoseForStructure(Structure structure)
        {
            var doseList = new List <double>();

            for (double z = _zStart; z < _zEnd; z += DoseSamplingDistanceInMm)
            {
                for (double y = _yStart; y < _yEnd; y += DoseSamplingDistanceInMm)
                {
                    VVector start = new VVector(_xStart, y, z);
                    VVector stop  = new VVector(_xEnd, y, z);

                    BitArray bitArray       = new BitArray(_dose.XSize);
                    var      segmentProfile = structure.GetSegmentProfile(start, stop, bitArray);

                    double[] doseArray   = new double[_dose.XSize];
                    var      doseProfile = _dose.GetDoseProfile(start, stop, doseArray);

                    for (int i = 0; i < segmentProfile.Count; i++)
                    {
                        if (segmentProfile[i].Value)
                        {
                            doseList.Add(doseProfile[i].Value);
                        }
                    }
                }
            }

            return(doseList.ToArray());
        }
Beispiel #3
0
        private DoseProfile CalculateProfile(
            Double x_start, Double y_start, Double z_start, Double x_stop, Double y_stop, Double z_stop, Double step, Dose dose
            )
        {
            // 始点と終点を定義
            var start = new VVector(x_start, y_start, z_start);
            var stop  = new VVector(x_stop, y_stop, z_stop);

            // 始点・終点間距離を定義
            var distance = VVector.Distance(start, stop);

            if (distance == 0)
            {
                throw new ApplicationException("Distance between two points is 0.");
            }

            // 距離をステップサイズで割ってサンプリング点数を決定(切り捨て)
            Double point = Math.Floor(distance / step);

            if (point < 1.0)
            {
                throw new ApplicationException("Step size is largar than distance between two points.");
            }

            // 始点から終点へ向かう長さ1のベクトルを得る
            var dir = stop - start;

            dir.ScaleToUnitLength();

            // stepサイズに合うように終点位置を調整
            var stop_new = start + dir * point * step;

            // DoseProfile用の配列を準備
            double[] profile = new double[(int)(point + 1)];
            // DoseProfileを取得
            var doseProfile = dose.GetDoseProfile(start, stop_new, profile);

            return(doseProfile);
        }
Beispiel #4
0
        public void Execute(ScriptContext context /*, System.Windows.Window window, ScriptEnvironment environment*/)
        {
            // TODO : Add here the code that is called when the script is launched from Eclipse.
            //get access to the plan.
            PlanSetup ps = context.PlanSetup;
            Dose      d  = ps.Dose;
            //create a vector where the dose profile will start.
            VVector start = new VVector();

            start.x = -100; //mm
            start.y = -100; //location from the dicom origin.
            start.z = 0;
            VVector end = new VVector();

            end.x = 100;
            end.y = start.y;
            end.z = start.z;
            //size of the doseprofile.
            double[]    size = new double[201];
            DoseProfile dp   = d.GetDoseProfile(start,
                                                end,
                                                size);

            //write this doseprofile to a csv file.
            string filename = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) +
                              "\\profile.csv";

            using (StreamWriter sw = new StreamWriter(filename))
            {
                sw.WriteLine("Position,Dose");
                foreach (ProfilePoint pp in dp)
                {
                    sw.WriteLine(String.Format("{0},{1}", pp.Position.x, pp.Value));
                }
            }
        }