Esempio n. 1
0
        public static TargetIndices CalculateIndices(StructureMeta gtv, DoseMatrix dd, double prescriptionDose)
        {
            var cropped = dd.Clone();

            cropped.CropMatrixToStructure(gtv, 20);

            var presVol = cropped.ConvertIsodoseLevelToMesh(prescriptionDose).CalculateVolumeCC();
            var halfVol = cropped.ConvertIsodoseLevelToMesh(prescriptionDose / 2).CalculateVolumeCC();

            var dvh        = cropped.CalcDVH();
            var points     = dvh.GetDVHData().Points;
            var test       = points.GetVolumeAtDose(prescriptionDose);
            var dosevol    = dvh.GetDVHData().Points.GetVolumeAtDose(prescriptionDose) / 100 * cropped.VolumeCC();
            var gradVol    = dvh.GetDVHData().Points.GetVolumeAtDose(prescriptionDose / 2) / 100 * cropped.VolumeCC();
            var isodoseDef = new IsodoseLevel()
            {
                Value = prescriptionDose, Color = new Scalar(0, 0, 255)
            };
            var isoStructure = cropped.Find2DIsodoseLines(isodoseDef).First();

            isoStructure.Look = StructureLooks.Purple;
            //var vol = isoStructure.CalculateVolumeCC();
            //var gtvVol = gtv.CalculateVolumeCC();
            var ci = presVol / 5;// gtvVol;
            //var ci2 = tvol / gtvVol;
            var gi = halfVol / dosevol;

            return(new TargetIndices()
            {
                Gradient = gi,
                RTOGCI = ci,
            });
        }
Esempio n. 2
0
        public static Point[][] Find2DIsodoseLine(this Mat mat, IsodoseLevel level)
        {
            Point[][]        ctrs;
            HierarchyIndex[] hi;
            var thresh = mat.Threshold(level.Value, 255, ThresholdTypes.Binary);

            thresh = thresh.WindowAndLevel(128, 256);
            thresh.FindContours(out ctrs, out hi, RetrievalModes.CComp, ContourApproximationModes.ApproxSimple);
            return(ctrs);
        }
Esempio n. 3
0
        public static SliceContourMeta FindZeroLevelContours(this Mat mat, Func <Vector3, Vector3> imageToPatientFunc, int z)
        {
            var zPos  = imageToPatientFunc(new Vector3(0, 0, z)).Z;
            var meta  = new SliceContourMeta();
            var child = new SliceContourMeta();
            var level = new IsodoseLevel()
            {
                Value = 0, Color = new Scalar(255)
            };

            Point[][]        ctrs;
            HierarchyIndex[] hi;
            var thresh = mat.Threshold(level.Value, 255, ThresholdTypes.Binary);

            thresh = thresh.WindowAndLevel(128, 256);
            thresh.FindContours(out ctrs, out hi, RetrievalModes.CComp, ContourApproximationModes.ApproxSimple);
            for (int i = 0; i < hi.Length; i++)
            {
                var contour = ctrs[i];
                if (hi[i].Parent == -1)
                {
                    contour.ToList().ForEach(c =>
                    {
                        var pos = imageToPatientFunc(new Vector3(c.X, c.Y, 1));
                        pos.Z   = zPos;
                        meta.AddPoint(new Point3f((float)pos.X, (float)pos.Y, (float)pos.Z));
                    });
                }
                if (hi[i].Parent != -1)
                {
                    contour.ToList().ForEach(c =>
                    {
                        var pos = imageToPatientFunc(new Vector3(c.X, c.Y, 1));
                        pos.Z   = zPos;
                        child.AddPoint(new Point3f((float)pos.X, (float)pos.Y, (float)pos.Z));
                    });
                }
            }
            if (child.ContourPoints.Any())
            {
                meta.Children.Add(child);
            }
            thresh.Dispose();
            return(meta);
        }