示例#1
0
        public static GrdFile Read(FileInfo fileInfo)
        {
            var grd = new GrdFile(fileInfo);

            using (var reader = new BinaryReader(fileInfo.OpenRead()))
            {
                grd.Info = new string(reader.ReadChars(4));

                grd.Row    = reader.ReadInt16();
                grd.Column = reader.ReadInt16();

                grd.MinX = reader.ReadDouble();
                grd.MaxX = reader.ReadDouble();
                grd.MinY = reader.ReadDouble();
                grd.MaxY = reader.ReadDouble();
                grd.MinZ = reader.ReadDouble();
                grd.MaxZ = reader.ReadDouble();

                grd.Data = new float[grd.Row, grd.Column];
                for (int i = grd.Row - 1; i >= 0; i--)
                {
                    for (int j = 0; j < grd.Column; j++)
                    {
                        grd.Data[j, i] = reader.ReadSingle();
                    }
                }
            }

            return(grd);
        }
示例#2
0
        public static void DrawLine(GrdFile grd, int x1, int y1, int x2, int y2)
        {
            Preconditions.CheckOutOfRange(x1, 0, 944, "x1");
            Preconditions.CheckOutOfRange(y1, 0, 944, "y1");
            Preconditions.CheckOutOfRange(x2, 0, 944, "x2");
            Preconditions.CheckOutOfRange(y2, 0, 944, "y2");

            int dx = Math.Abs(x2 - x1), sx = x1 < x2 ? 1 : -1;
            int dy = Math.Abs(y2 - y1), sy = y1 < y2 ? 1 : -1;
            var err = (dx > dy ? dx : -dy) / 2;

            while (true)
            {
                grd.Data[x1, y1] = -1;
                if (x1 == x2 && y1 == y2)
                {
                    break;
                }

                var e2 = err;
                if (e2 > -dx)
                {
                    err -= dy; x1 += sx;
                }
                if (e2 < dy)
                {
                    err += dx; y1 += sy;
                }
            }
        }
示例#3
0
        public static GrdFile NewInstance()
        {
            GrdFile grd = new GrdFile();

            return(grd);
        }