コード例 #1
0
 public override int GetHashCode()
 {
     unchecked
     {
         return(ContourPoints.Aggregate(19, (current, foo) => current * 31 + foo.GetHashCode()));
     }
 }
コード例 #2
0
        /// <summary>
        /// Masks an image of the same voxel count as the input doseGrid. Voxels inside the
        /// contour are filled with the specified color. Intent is white (0x255) on inside and outside
        /// areas/holes are left black (0x00)
        /// </summary>
        /// <param name="mask">the mask to fill or modify (recursively)</param>
        /// <param name="txMatrix">the patient transform matrix from the imagematrix/dosematrix</param>
        /// <param name="color">the color to fill the contour</param>
        /// <param name="scale">the scale of the image (in case the image has been resampled)</param>
        public void MaskImageFast(Mat mask, Mat txMatrix, byte color = 255, double scale = 1)
        {
            if (ContourPoints.Count == 0)
            {
                mask.SetArray(new byte[mask.Cols * mask.Rows]); return;
            }


            var allPoints = new Vec4f[ContourPoints.Count];
            var points    = ContourPoints.Select(c => new Vec4f(c.X, c.Y, Z, 1));

            using (var pointMat = new Mat <float>(new[] { ContourPoints.Count }, points.ToArray()))
            {
                var txPointMat = pointMat.Transform(txMatrix.Inv());
                txPointMat.GetArray(out allPoints);
            }
            var points2D = allPoints.Select(a => new Point(a.Item0 * scale, a.Item1 * scale)).ToList();

            Cv2.FillPoly(mask, new[] { points2D }, new Scalar(color), LineTypes.Link8);

            var grandchildren     = Children.SelectMany(c => c.Children);
            var outermostChildren = Children.Where(c => !grandchildren.Any(gc => gc == c));

            foreach (var child in outermostChildren)
            {
                //Recursively alternates black white to account for holes and fills of children contours
                child.MaskImageFast(mask, txMatrix, color == 255 ? (byte)0 : (byte)255);
            }
        }
コード例 #3
0
        public bool Equals(ContourPolygon other)
        {
            if (other == null)
            {
                return(false);
            }

            if (Length != other.Length)
            {
                return(false);
            }

            return(!ContourPoints.Where((t, i) => t != other.ContourPoints[i]).Any());
        }
コード例 #4
0
        public void AddPoint(OpenCvSharp.Point3f pt)
        {
            var z = pt.Z;

            if (float.IsNaN(Z))
            {
                Z = z;
            }

            if (z != Z)
            {
                throw new ArgumentException("Point not in same plane as other points in contour!");
            }
            ContourPoints.Add(new Point2f(pt.X, pt.Y));
        }
コード例 #5
0
        public Mat DrawOnSlice(Mat txMatrix, Mat slice, double scale = 1)
        {
            var allPoints = new Vec4f[ContourPoints.Count];
            var points    = ContourPoints.Select(c => new Vec4f(c.X, c.Y, Z, 1));

            using (var pointMat = new Mat <float>(new[] { ContourPoints.Count }, points.ToArray()))
            {
                var txPointMat = pointMat.Transform(txMatrix.Inv());
                txPointMat.GetArray(out allPoints);
            }
            var    points2D = allPoints.Select(a => new Point(a.Item0 * scale, a.Item1 * scale)).ToList();
            double min, max;

            slice.MinMaxIdx(out min, out max);
            var color = slice.Type() == MatType.CV_8UC3? slice: slice.WindowAndLevel((max - min) / 2, max - min);

            Cv2.DrawContours(color, new[] { points2D }, 0, new Scalar(255, 255, 0));

            var grandchildren     = Children.SelectMany(c => c.Children);
            var outermostChildren = Children.Where(c => !grandchildren.Any(gc => gc == c));

            return(color);
        }