Example #1
0
        public static DVHPoint[] CalculateMarchingDVH(StructureMeta sm, DoseMatrix dm)
        {
            var maxDose = dm.MaxDose;

            var resample      = dm.ResampleMatrixToStructure(sm);
            var onlyStructure = resample.ExcludeOutsideStructure(sm);

            onlyStructure.CropMatrixToStructure(sm, 10);

            //for (int z = 0; z < onlyStructure.DimensionZ; z++)
            //{

            //    var slice = onlyStructure.GetZPlaneBySlice(z);
            //    FloatMat.Show(slice);

            //}
            var points = new List <DVHPoint>();

            for (double i = 0; i < maxDose; i += 0.5)
            {
                var mesh = MachingCubes.Calculate(onlyStructure, i);
                if (i == 3)
                {
                    mesh.Export(@"F:\OneDrive\__RED_ION\Git\EvilDICOM.CV\DICOMCV.Tests\gtv3dd.obj");
                }
                points.Add(new DVHPoint(new Dose(i, "Gy"), new Volume(mesh.CalculateVolumeCC(), "cc")));
            }

            return(points.ToArray());
        }
Example #2
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);
        }
Example #3
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);
        }
Example #4
0
        public DoseMatrix Clone()
        {
            var dm = new DoseMatrix();

            dm._mat               = _mat.Clone();
            dm.XRes               = XRes;
            dm.YRes               = YRes;
            dm.ZRes               = ZRes;
            dm.MaxDose            = MaxDose;
            dm.MaxDoseSlice       = MaxDoseSlice;
            dm.ImageOrientation   = ImageOrientation;
            dm.BytesAllocated     = BytesAllocated;
            dm.DimensionX         = DimensionX;
            dm.DimensionY         = DimensionY;
            dm.DimensionZ         = DimensionZ;
            dm.DoseUnit           = DoseUnit;
            dm.Origin             = Origin;
            dm.PlanUID            = PlanUID;
            dm.PrescriptionDoseGy = PrescriptionDoseGy;
            dm.SumType            = SumType;
            dm.CalculatePatientTransformMatrix();
            dm.CalculateBounds();
            return(dm);
        }
Example #5
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);
                    }
                }
            }
        }