コード例 #1
0
ファイル: Sec.cs プロジェクト: IanusInferus/cmdt
        public Sec(string fn)
        {
            using (FileStream fs = new FileStream(fn, FileMode.Open, FileAccess.Read))
            {
                using (BinaryReader br = new BinaryReader(fs))
                {
                    int f1 = br.ReadInt32();
                    int f2 = br.ReadInt32();

                    if (f1 == 1 && f2 == 1)
                    {
                        version = 2;
                    }
                    else if (f1 == 2 && f2 == 1)
                    {
                        version = 3;
                    }
                    else
                    {
                        Debug.Assert(false);
                    }

                    while (br.ReadInt32() != 0x3150414d)
                    {
                        ;
                    }

                    /////////////////////////////////////////////////////////////////

                    br.BaseStream.Seek(7 * 4, SeekOrigin.Current);

                    /////////////////////////////////////////////////////////////////
                    num_points     = br.ReadInt32();
                    num_borders    = br.ReadInt32();
                    num_districts  = br.ReadInt32();
                    num_xdistricts = br.ReadInt32();

                    /////////////////////////////////////////////////////////////////

                    points = new FPoint[num_points];
                    for (int i = 0; i < num_points; i++)
                    {
                        FPoint fp = new FPoint();
                        fp.idx    = i;
                        fp.x      = br.ReadSingle();
                        fp.y      = br.ReadSingle();
                        points[i] = fp;
                    }

                    CalculateMinMax();                     //计算最大最小值

                    /////////////////////////////////////////////////////////////////

                    borders = new Border[num_borders];
                    for (int i = 0; i < num_borders; i++)
                    {
                        Border bb = new Border();

                        bb.idx = i;

                        int idx = br.ReadInt32();
                        bb.from = points[idx];

                        idx   = br.ReadInt32();
                        bb.to = points[idx];

                        bb.belong_district   = br.ReadInt32();
                        bb.neighbor_district = br.ReadInt32();

                        br.ReadInt32();                        //DO NOT KNOW ABOUT IT YET

                        borders[i] = bb;
                    }

                    /////////////////////////////////////////////////////////////////

                    districts = new District[num_districts];
                    for (int i = 0; i < num_districts; i++)
                    {
                        District dd = new District();

                        dd.num_borders = br.ReadInt32();
                        dd.attributes  = br.ReadBytes(8);
                        dd.tanX        = br.ReadSingle();
                        dd.tanY        = br.ReadSingle();
                        dd.M           = br.ReadSingle();

                        if (version == 2)
                        {
                            dd.not_sure = br.ReadBytes(24);
                        }
                        else if (version == 3)
                        {
                            dd.not_sure = br.ReadBytes(16);
                        }

                        dd.minx = br.ReadSingle();
                        dd.miny = br.ReadSingle();
                        dd.minz = br.ReadSingle();
                        dd.maxx = br.ReadSingle();
                        dd.maxy = br.ReadSingle();
                        dd.maxz = br.ReadSingle();

                        dd.borders = new Border[dd.num_borders];
                        for (int j = 0; j < dd.num_borders; j++)
                        {
                            int idx = br.ReadInt32();
                            dd.borders[j] = borders[idx];
                        }
                        districts[i] = dd;
                    }
                }
            }
            ValidateSecData();             //这个修正非常强!效果极好!
        }