Esempio n. 1
0
        /// <summary>
        /// 使用线段绘图
        /// </summary>
        /// <param name="lines">线段集合</param>
        /// <param name="size">模型尺寸</param>
        /// <param name="imageWidth">图片宽度</param>
        /// <param name="imageHeight">图片高度</param>
        /// <param name="offsetX">x偏移量</param>
        /// <param name="offsetY">y偏移量</param>
        /// <returns></returns>
        public static Bitmap ToImage(List <Vector2[]> lines, ModelSize size, int imageWidth, int imageHeight, int offsetX = 0, int offsetY = 0)
        {
            //对角线不应超出宽度
            var fd = 1f;
            //var diagonal = (float)Math.Sqrt(size.Width * size.Width + size.Height * size.Height);
            //if (diagonal > imageWidth)
            //{
            //fd = imageWidth / diagonal;
            //}

            var fw = 1f;
            var fh = 1f;

            if (size.Length > imageWidth)
            {
                fw = imageWidth / (float)size.Length;
            }
            if (size.Height > imageHeight)
            {
                fh = imageHeight / (float)size.Height;
            }
            var f = Math.Min(fd, Math.Min(fw, fh));

            var ow = imageWidth / 2f + offsetX;
            var oh = imageHeight / 2f + offsetY;

            var bmp = new Bitmap(imageWidth, imageHeight);
            var g   = Graphics.FromImage(bmp);

            g.FillRectangle(new SolidBrush(Color.White), new Rectangle(0, 0, imageWidth, imageHeight));

            foreach (var line in lines)
            {
                int x1 = Convert.ToInt32((line[0].X * f) + ow);
                int y1 = Convert.ToInt32((line[0].Y * f) + oh);

                int x2 = Convert.ToInt32((line[1].X * f) + ow);
                int y2 = Convert.ToInt32((line[1].Y * f) + oh);

                Point p1 = new Point(x1, y1);
                Point p2 = new Point(x2, y2);

                g.DrawLine(new Pen(new SolidBrush(Color.Red)), p1, p2);
            }

            bmp.RotateFlip(RotateFlipType.Rotate180FlipX);
            return(bmp);
        }
Esempio n. 2
0
        /// <summary>
        /// 切片转图片
        /// </summary>
        /// <param name="slicedPlane">切片集合</param>
        /// <param name="size">模型尺寸</param>
        /// <param name="imageWidth">图片宽度</param>
        /// <param name="imageHeight">图片高度</param>
        /// <param name="offsetX">x偏移量</param>
        /// <param name="offsetY">y偏移量</param>
        /// <returns></returns>
        public static List <Bitmap> ToImage(List <SlicedPlane> slicedPlane, ModelSize size, int imageWidth, int imageHeight, int offsetX = 0, int offsetY = 0)
        {
            var firstNormal = (slicedPlane.First().SlicePlane as CircleSlicePlaneInfo).Plane.Normal;
            var images      = new List <Bitmap>();

            foreach (var sp in slicedPlane)
            {
                var lines = new List <Vector2[]>();
                var info  = sp.SlicePlane as CircleSlicePlaneInfo;

                var origin = new Vector3(0, 0, 0);
                if (info.Plane.D != 0)
                {
                    origin = firstNormal * info.Plane.D;
                }

                var a = -info.Angle;
                var q = Matrix4x4.CreateFromAxisAngle(info.Axis, a);
                q.Translation = -origin;

                foreach (var line in sp.Lines)
                {
                    var s = Vector3.Transform(line.Start, q);
                    var e = Vector3.Transform(line.End, q);

                    //var s = To2D(sp,line.Start);
                    //var e = To2D(sp,line.End);

                    lines.Add(new Vector2[] {
                        new Vector2(s.X, s.Y),
                        new Vector2(e.X, e.Y)
                    });
                }

                var img = ToImage(lines, size, imageWidth, imageHeight, offsetX, offsetY);
                images.Add(img);
            }

            return(images);
        }
Esempio n. 3
0
        public static List <Bitmap> ToImage(List <SlicedPlane> slicedPlane, ModelSize size, int imageWidth, int imageHeight, int offsetX = 0, int offsetY = 0)
        {
            var firstNormal = (slicedPlane.First().SlicePlane as LinearSlicePlaneInfo).Plane.Normal;
            var images      = new List <Bitmap>();

            foreach (var sp in slicedPlane)
            {
                var lines = new List <Vector2[]>();
                var info  = sp.SlicePlane as LinearSlicePlaneInfo;

                foreach (var line in sp.Lines)
                {
                    lines.Add(new Vector2[] {
                        new Vector2((float)line.Start.X, (float)line.Start.Z),
                        new Vector2((float)line.End.X, (float)line.End.Z)
                    });
                }

                var img = ToImage(lines, size, imageWidth, imageHeight, offsetX, offsetY);
                images.Add(img);
            }

            return(images);
        }