Example #1
0
        public static Point TransformPoint(PointD[] pos3, int idiolCenterX, int idiolCenterY, Point srcpos)
        {
            try
            {
                var srcPos  = new AffinePos(pos3[0], pos3[1], pos3[2], pos3[3]);
                var trsData = srcPos.ToTrnsData(1, 1);

                var xshift = (int)(trsData.XSrcCnter - idiolCenterX);
                var yshift = (int)(trsData.YSrcCnter - idiolCenterY);

                double radian = trsData.Angle;

                double cosRadian = Cos(radian);
                double sinRadian = Sin(radian);

                var x = srcpos.X - xshift;
                var y = srcpos.Y - yshift;

                var sourceX = (x - idiolCenterX) * cosRadian + (y - idiolCenterY) * (sinRadian);
                sourceX += (idiolCenterX);
                var sourceY = (x - idiolCenterX) * -sinRadian + (y - idiolCenterY) * cosRadian;
                sourceY += (idiolCenterY);

                var isourceX = (int)sourceX;
                var isourceY = (int)sourceY;

                return(new Point(isourceX, isourceY));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return(default(Point));
            }
        }
Example #2
0
        public static PointD GetCenter(this AffinePos pos)
        {
            var xCenter = Abs(pos.LT.X + pos.RB.X) / 2;
            var yCenter = Abs(pos.LB.Y + pos.RT.Y) / 2;


            return(new PointD(xCenter, yCenter));
        }
Example #3
0
        public static byte[][] Run(MemoryStream bytestream, int w, int h, PointD[] pos3, bool onlyxy = false)
        {
            try
            {
                var srcPos  = new AffinePos(pos3[0], pos3[1], pos3[2], pos3[3]);
                var trsData = srcPos.ToTrnsData(w, h);

                var xc = trsData.XSrcCnter;
                var yc = trsData.YSrcCnter;

                var xmax = Math.Max(w - xc, xc) * 2;
                var ymax = Math.Max(h - yc, yc) * 2;

                byte[][] R1 = CreateJagged(ymax, xmax);

                for (int i = 0; i < h; i++)
                {
                    var data = new byte[w];
                    bytestream.Seek(i * w, SeekOrigin.Begin);
                    bytestream.Read(data, 0, w);
                    var reshaped = data.Reshape(1, w).ToJagged();
                    xytransform(ref R1, trsData, reshaped, i, xmax, ymax);
                }

                if (onlyxy)
                {
                    return(R1);
                }

                var w1 = R1[0].Length;
                var h1 = R1.Length;



                var degree = trsData.Angle * 180 / Math.PI;

                double   radian    = trsData.Angle;
                double   cosRadian = Cos(radian);
                double   sinRadian = Sin(radian);
                int      newWidth  = (int)(w1 * Abs(cosRadian) + h1 * Abs(sinRadian));
                int      newHeight = (int)(h1 * Abs(cosRadian) + w1 * Abs(sinRadian));
                byte[][] R2        = CreateJagged(newWidth, newHeight);


                for (int i = 0; i < R1.Length; i++)
                {
                    var reshaped = R1[i].Reshape(1, w1).ToJagged();

                    rotateGeneral(ref R2, trsData, reshaped, i, w1, h1);
                }
                return(R2);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return(null);
            }
        }
Example #4
0
        public static TrnsData ToTrnsData
            (this AffinePos srcPos, int w, int h)
        {
            var innerh = PosL2(srcPos.LB, srcPos.LT);
            var innerw = PosL2(srcPos.RT, srcPos.LT);


            var trgPos = srcPos.MoveToCenter(new PointD(w / 2.0, h / 2.0)); // ok

            var fcenterX = srcPos.GetCenter().X;
            var fcenterY = srcPos.GetCenter().Y;
            var lcenterX = trgPos.GetCenter().X;
            var lcenterY = trgPos.GetCenter().Y;

            var xshift = lcenterX - fcenterX;
            var yshift = lcenterY - fcenterY;

            var    dx = srcPos.LT.X - srcPos.RT.X;
            var    dy = srcPos.LT.Y - srcPos.RT.Y;
            double radian;

            if (Abs(dx) < 0.0001)
            {
                radian = 1.5708;
            }
            else if (Abs(dy) < 0.0001)
            {
                radian = 3.14159;
            }
            else
            {
                radian = Math.Atan(dy / dx);
            }
            return(new TrnsData()
            {
                H = h,
                W = w,
                XShift = (int)xshift,
                YShift = (int)yshift,
                Innerw = innerw,
                Innterh = innerh,
                XSrcCnter = (int)fcenterX,
                YSrcCnter = (int)fcenterY,
                dX = (int)dx,
                dY = (int)dy,
                Angle = radian,
            });
        }
Example #5
0
        public static AffinePos MoveToCenter(this AffinePos pos, PointD center)
        {
            var wHalf = Math.Sqrt(Math.Pow((pos.LT.X - pos.RT.X), 2) + Math.Pow((pos.LT.Y - pos.RT.Y), 2));
            var hHalf = Math.Sqrt(Math.Pow((pos.LT.X - pos.LB.X), 2) + Math.Pow((pos.LT.Y - pos.LB.Y), 2));

            var x1 = center.X - wHalf;
            var x2 = center.X - wHalf;
            var x3 = center.X + wHalf;
            var x4 = center.X + wHalf;

            var y1 = center.Y - hHalf;
            var y3 = center.Y + hHalf;
            var y2 = center.Y + hHalf;
            var y4 = center.Y - hHalf;

            return(new AffinePos(x1, y1, x2, y2, x3, y3, x4, y4));
        }
Example #6
0
        public static AffinePos GetCentered(this AffinePos pos, PointD center)
        {
            var wHalf = Abs(pos.LT.X - pos.RT.X) / 2;
            var hHalf = Abs(pos.LT.Y - pos.RT.Y) / 2;


            var x1 = center.X - wHalf;
            var x2 = center.X - wHalf;
            var x3 = center.X + wHalf;
            var x4 = center.X + wHalf;

            var y1 = center.Y - hHalf;
            var y3 = center.Y + hHalf;
            var y2 = center.Y + hHalf;
            var y4 = center.Y - hHalf;

            return(new AffinePos(x1, y1, x2, y2, x3, y3, x4, y4));
        }