Пример #1
0
        public static DVH CalculateSDF_DVH(StructureMeta sm, DoseMatrix dm)
        {
            var cropDM = dm.Clone();

            cropDM.CropMatrixToStructure(sm, 2);
            // cropDM.ShowAllSlices();
            var sdf = sm.CalculateSDFMatrix(cropDM);

            cropDM.Resample(cropDM.XRes / 3, cropDM.YRes / 3, cropDM.ZRes / 3);
            sdf.Resample(sdf.XRes / 3, sdf.YRes / 3, sdf.ZRes / 3);

            var maxDose  = cropDM.MaxDose;
            var voxelCC  = cropDM.XRes / 10 * cropDM.YRes / 10 * cropDM.ZRes / 10;
            var doseUnit = dm.DoseUnit == DoseUnit.ABSOLUTE ? "Gy" : "%";
            var dvh      = new DVH(maxDose, voxelCC, doseUnit);

            var vol = 0.0;

            for (int z = 0; z < cropDM.DimensionZ; z++)
            {
                var zPos     = cropDM.ImageToPatientTx(new Core.Helpers.Vector3(0, 0, z)).Z;
                var contours = new SliceContourMeta[] { sdf.FindStructureContour(zPos) };
                vol += contours.Sum(c => c.CalculateArea()) * cropDM.ZRes;
                CalculateContoursDVH(contours, cropDM, dvh);
            }
            dvh.Volume = vol;

            return(dvh);
        }
Пример #2
0
        public static DVH CalculateDVH(StructureMeta sm, DoseMatrix dm)
        {
            var maxDose  = dm.MaxDose;
            var voxelCC  = dm.XRes / 10 * dm.YRes / 10 * dm.ZRes / 10;
            var doseUnit = dm.DoseUnit == DoseUnit.ABSOLUTE ? "Gy" : "%";
            var dvh      = new DVH(maxDose, voxelCC, doseUnit);

            var zSlices = sm.SliceContours.GroupBy(sc => sc.Z).OrderBy(grp => grp.Key);

            foreach (var slice in zSlices)
            {
                var z = slice.Key;
                CalculateContoursDVH(slice, dm, dvh);
            }
            return(dvh);
        }
Пример #3
0
        /// <summary>
        /// Zeros all voxels outside of structure contours
        /// </summary>
        /// <param name="sm"></param>
        //public DoseMatrix MaskMatrixToStructure(StructureMeta sm)
        //{
        //    var minZSlice = sm.SliceContours.Select(s => s.Z).Min();
        //    var maxZSlice = sm.SliceContours.Select(s => s.Z).Max();
        //    var sliceThickness = sm.GetSliceThickness();
        //    for (int z = 0; z < DimensionZ; z++)
        //    {
        //        var slice = GetZPlaneBySlice(z);
        //        using (var mask = new Mat(slice.Rows, slice.Cols, MatType.CV_8UC1, new Scalar(0)))
        //        {
        //            if(sm.SliceContours.Any(s=>s.Z==z))
        //            //This method will mask and exclude holes and include fills
        //            contour.MaskImageFast(mask, dm.PatientTransformMatrix, 255, scale);
        //            dvh.AddSliceToDVH(zDose, mask);
        //        }
        //        SetZPlaneBySlice(slice, z);
        //    }
        //}

        public DVH CalcDVH()
        {
            double min, max;

            _mat.MinMaxIdx(out min, out max);
            var voxelCC  = XRes / 10 * YRes / 10 * ZRes / 10;
            var doseUnit = DoseUnit == DoseUnit.ABSOLUTE ? "Gy" : "%";
            var dvh      = new DVH(max, voxelCC, doseUnit);

            for (int z = 0; z < DimensionZ; z++)
            {
                var slice = GetZPlaneBySlice(z);
                dvh.AddSliceToDVH(slice, null);
            }

            return(dvh);
        }
Пример #4
0
        private static void CalculateContoursDVH(IEnumerable <SliceContourMeta> contours, DoseMatrix dm, DVH dvh)
        {
            var z = contours.FirstOrDefault().Z;

            using (var zDose = dm.GetZPlane(z))
            {
                //Mask contours as white/holes as black/and fills as white

                foreach (var contour in contours)
                {
                    using (var mask = new Mat(zDose.Rows, zDose.Cols, MatType.CV_8UC1, new Scalar(0)))
                    {
                        //This method will mask and exclude holes and include fills
                        contour.MaskImageFast(mask, dm.PatientTransformMatrix, 255);
                        dvh.AddSliceToDVH(zDose, mask);
                    }
                }
            }
        }