/// <summary>
 /// Reads an eight byte (double precision) floating point value from the binary stream.
 /// </summary>
 /// <returns></returns>
 public double ReadDouble()
 {
     return(_binaryReader.ReadDouble());
 }
示例#2
0
            public static bool Read_Pac1(string filename, ref Direct_Sound[] Direct_Data, ref ImageSourceData[] IS_Data, ref Environment.Receiver_Bank[] Receiver)
            {
                System.IO.BinaryReader sr = new System.IO.BinaryReader(System.IO.File.Open(filename, System.IO.FileMode.Open));
                try
                {
                    //1. Date & Time
                    string Savedate = sr.ReadString();
                    //2. Plugin Version
                    string Pach_version = sr.ReadString();
                    //3. Cut off Time and SampleRate
                    double CO_TIME    = sr.ReadDouble();
                    int    SampleRate = sr.ReadInt32();
                    //4. Source Count
                    int SrcCt = 1;
                    if (double.Parse(Pach_version.Substring(0, 3)) >= 1.1)
                    {
                        SrcCt = sr.ReadInt32();
                    }
                    //4.1 Source Location x
                    //4.2 Source Location y
                    //4.3 Source Location z
                    Hare.Geometry.Point[] SrcPt = new Hare.Geometry.Point[SrcCt];
                    for (int s = 0; s < SrcCt; s++)
                    {
                        SrcPt[s] = new Hare.Geometry.Point(sr.ReadDouble(), sr.ReadDouble(), sr.ReadDouble());
                    }
                    //5. No of Receivers
                    int Rec_Ct = sr.ReadInt32();
                    //6. Write the coordinates of each receiver point
                    //6b. Write the environmental characteristics at each receiver point (Rho * C); V2.0 only...
                    Hare.Geometry.Point[] Recs = new Hare.Geometry.Point[Rec_Ct];
                    double[] Rho_C             = new double[Rec_Ct];
                    for (int q = 0; q < Rec_Ct; q++)
                    {
                        Recs[q] = new Hare.Geometry.Point(sr.ReadDouble(), sr.ReadDouble(), sr.ReadDouble());
                        if (double.Parse(Pach_version.Substring(0, 3)) >= 2.0)
                        {
                            Rho_C[q] = sr.ReadDouble();
                        }
                        else
                        {
                            Rho_C[q] = 400;
                        }
                    }

                    Direct_Data = new Direct_Sound[SrcCt];
                    IS_Data     = new ImageSourceData[SrcCt];
                    Receiver    = new Environment.Receiver_Bank[SrcCt];

                    int DDCT = 0;
                    int ISCT = 0;
                    int RTCT = 0;
                    do
                    {
                        string readin = sr.ReadString();
                        switch (readin)
                        {
                        case "Direct_Sound":
                        case "Direct_Sound w sourcedata":
                            //9. Read Direct Sound Data
                            Direct_Data[DDCT]            = Direct_Sound.Read_Data(ref sr, Recs, SrcPt[DDCT], Rho_C, Pach_version);
                            Direct_Data[DDCT].CO_Time    = CO_TIME;
                            Direct_Data[DDCT].SampleFreq = (int)SampleRate;
                            DDCT++;
                            break;

                        case "Image-Source_Data":
                            //10. Read Image Source Sound Data
                            IS_Data[ISCT] = ImageSourceData.Read_Data(ref sr, Recs.Length, Direct_Data[DDCT - 1], false, ISCT, Pach_version);
                            ISCT++;
                            break;

                        case "Ray-Traced_Data":
                            //11. Read Ray Traced Sound Data
                            Receiver[RTCT] = Environment.Receiver_Bank.Read_Data(ref sr, Rec_Ct, Recs, Rho_C, Direct_Data[RTCT].Delay_ms, ref SampleRate, Pach_version);
                            RTCT++;
                            break;

                        case "End":
                            sr.Close();
                            return(true);
                        }
                    } while (true);
                }
                catch (System.Exception X)
                {
                    sr.Close();
                    System.Windows.Forms.MessageBox.Show("File Read Failed...", String.Format("Results file was corrupt or incomplete. We apologize for this inconvenience. Please report this to the software author. It will be much appreciated. \r\n Exception Message: {0}. \r\n Method: {1}", X.Message, X.TargetSite));
                    return(false);
                }
            }
示例#3
0
 public bool Read(ref double val, string name = null)
 {
     val = _reader.ReadDouble();
     return(true);
 }
 public static System.Windows.Point ReadPoint(this System.IO.BinaryReader reader)
 {
     return(new System.Windows.Point(reader.ReadDouble(), reader.ReadDouble()));
 }
示例#5
0
        public void Load(AsyncCallback callback)
        {
            Func <bool> ac = () =>
            {
                string path;
#if DEBUG
                path = "settings.dat";
#else
                path = System.IO.Path.Combine(
                    Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                    "Clocks");

                path = System.IO.Path.Combine(path, "settings.dat");
#endif
                if (System.IO.File.Exists(path))
                {
                    System.IO.BinaryReader br = null;
                    System.IO.FileStream   fs = null;
                    bool needDispose          = true;

                    try
                    {
                        fs = new System.IO.FileStream(
                            path, System.IO.FileMode.Open,
                            System.IO.FileAccess.Read, System.IO.FileShare.Read);

                        br = new System.IO.BinaryReader(fs);

                        cfA = br.ReadByte();
                        cfR = br.ReadByte();
                        cfG = br.ReadByte();
                        cfB = br.ReadByte();

                        fgA = br.ReadByte();
                        fgR = br.ReadByte();
                        fgG = br.ReadByte();
                        fgB = br.ReadByte();

                        autoload    = br.ReadBoolean();
                        showSeconds = br.ReadBoolean();

                        x       = br.ReadDouble();
                        y       = br.ReadDouble();
                        topMost = br.ReadBoolean();
                    }
                    catch (System.IO.EndOfStreamException ex)
                    {
#if DEBUG
                        //        System.Windows.MessageBox.Show("1 path " + path + "\n" + ex.Message);
#endif
                        //освобождаем поток, чтоб удалить файл
                        if (br != null)
                        {
                            br.Dispose();
                        }

                        needDispose = false;

                        try
                        {
                            System.IO.File.Delete(path);
                        }
                        catch (UnauthorizedAccessException) { }

                        return(false);
                    }
                    catch (Exception ex)
                    {
#if DEBUG
                        //   System.Windows.MessageBox.Show("2 path " + path + "\n" +ex.Message);
#endif
                        return(false);
                    }
                    finally
                    {
                        if (needDispose)
                        {
                            if (br != null)
                            {
                                br.Dispose();
                            }
                        }
                    }
                }
                else
                {
                    fgA = 255; fgR = 95; fgG = 158; fgB = 160;
                    cfA = 255; cfR = 173; cfG = 216; cfB = 230;
                }

                return(true);
            };

            ac.BeginInvoke(callback, null);
        }
示例#6
0
        public override object Deserialize(System.IO.BinaryReader binaryReader)
        {
            bool hasValue = binaryReader.ReadBoolean();

            if (!hasValue)
            {
                return(null);
            }
            int typeID = binaryReader.ReadByte();

            switch (typeID)
            {
            case 1:
                return(binaryReader.ReadBoolean());

            case 2:
                return(binaryReader.ReadByte());

            case 128:
                return(binaryReader.ReadSByte());

            case 3:
                return(binaryReader.ReadInt16());

            case 129:
                return(binaryReader.ReadUInt16());

            case 4:
                return(binaryReader.ReadInt32());

            case 130:
                return(binaryReader.ReadUInt32());

            case 5:
                return(binaryReader.ReadInt64());

            case 131:
                return(binaryReader.ReadUInt64());

            case 9:
                return(binaryReader.ReadDouble());

            case 16:
                return(binaryReader.ReadString());

            case 144:
                return(binaryReader.ReadChar());

            case 24:
                return(new DateTime(binaryReader.ReadInt64()));

            case 32:
                return(new Guid(binaryReader.ReadBytes(16)));

            case 36:
                return(binaryReader.ReadBytes(binaryReader.ReadInt32()));

            default:
                throw new Exception(string.Format("Serialization for type <{0}> is not supported", typeID));
            }
        }
示例#7
0
 public override void Read(System.IO.BinaryReader reader)
 {
     _key = reader.ReadDouble();
 }
            /// <summary>
            /// reads a file and populates the map receiver instance.
            /// </summary>
            /// <returns></returns>
            public static bool Read_pachm(out Mapping.PachMapReceiver[] Map)
            {
                System.Windows.Forms.OpenFileDialog of = new System.Windows.Forms.OpenFileDialog();
                of.DefaultExt = ".pachm";
                of.AddExtension = true;
                of.Filter = "Pachyderm Mapping Data File (*.pachm)|*.pachm|" + "All Files|";
                if (of.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    Map = null;
                    return false;
                }
                System.IO.BinaryReader sr = new System.IO.BinaryReader(System.IO.File.Open(of.FileName, System.IO.FileMode.Open));
                //1. Write calculation type. (string)
                string CalcType = sr.ReadString();
                if (CalcType != "Type;Map_Data" && CalcType != "Type;Map_Data_NoDir") throw new Exception("Map Data File Expected");
                bool Directional = (CalcType == "Type;Map_Data");

                //2. Write the number of samples in each histogram. (int)
                int SampleCT = (int)sr.ReadUInt32();
                //3. Write the sample rate. (int)
                int SampleRate = (int)sr.ReadUInt32();
                //4. Write the number of Receivers (int)
                int Rec_CT = (int)sr.ReadUInt32();
                //4.5 Write the version number
                double version = 1.1;
                double rev = 0;
                //5. Announce that the following data pertains to the form of the analysis mesh. (string)
                int s_ct=1;
                Rhino.Geometry.Mesh Map_Mesh = new Rhino.Geometry.Mesh();
                Map = new Mapping.PachMapReceiver[1];
                //Map[0] = new Pach_Map_Receiver();
                //double[] Rho_C = null;
                double[] delay;

                do
                {
                    switch (sr.ReadString())
                    {
                        case "Version":
                            //Pach1.7 = Versioning functionality added.
                            string v = sr.ReadString();
                            version = double.Parse(v.Substring(0, 3));
                            rev = int.Parse(v.Split(new char[1] { '.' })[3]);
                            break;
                        case "Mesh Information":
                            //6. Announce Mesh Vertices (string)
                            //Write the number of vertices & faces (int) (int)
                            if (sr.ReadString() != "Mesh Vertices") throw new Exception("Mesh Vertices Expected");

                            int VC = (int)sr.ReadUInt32();
                            int FC = (int)sr.ReadUInt32();
                            for (int i = 0; i < VC; i++)
                            {
                                //Write Vertex: (double) (double) (double)
                                Map_Mesh.Vertices.Add(new Rhino.Geometry.Point3d(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()));
                            }

                            //7. Announce Mesh Faces (string)
                            if (sr.ReadString() != "Mesh Faces") throw new Exception("Mesh Faces Expected");

                            for (int i = 0; i < FC; i++)
                            {
                                // Write mesh vertex indices: (int) (int) (int) (int)
                                Map_Mesh.Faces.AddFace((int)sr.ReadUInt32(), (int)sr.ReadUInt32(), (int)sr.ReadUInt32(), (int)sr.ReadUInt32());
                            }
                            break;
                        case "Sources":
                            //7.5: Announce the number of sources.
                            s_ct = sr.ReadInt32();
                            delay = new double[s_ct];
                            Map = new Mapping.PachMapReceiver[s_ct];
                            //7.5a Announce the type of source.

                            for (int s = 0; s < s_ct; s++)
                            {
                                Map[s] = new Mapping.PachMapReceiver();
                                Map[s].CutOffTime = (double)SampleCT / (double)SampleRate;
                                Map[s].SampleCT = SampleCT;
                                Map[s].SampleRate = SampleRate;
                                Map[s].Map_Mesh = Map_Mesh;
                                Map[s].Rec_List = new Mapping.PachMapReceiver.Map_Receiver[Rec_CT];
                                Map[s].SrcType = sr.ReadString();
                                //4.4 Source delay (ms)
                                if (version > 2.0 || (version == 2.0 && rev >= 1))
                                {
                                    delay[s] = sr.ReadDouble();
                                }
                            }
                            break;
                        case "SourceswLoc":
                            //7.5: Announce the number of sources.
                            s_ct = sr.ReadInt32();
                            delay = new double[s_ct];
                            Map = new Mapping.PachMapReceiver[s_ct];
                            //7.5a Announce the type of source.

                            for (int s = 0; s < s_ct; s++)
                            {
                                Map[s] = new Mapping.PachMapReceiver();
                                Map[s].CutOffTime = (double)SampleCT / (double)SampleRate * 1000;
                                Map[s].SampleCT = SampleCT;
                                Map[s].SampleRate = SampleRate;
                                Map[s].Map_Mesh = Map_Mesh;
                                Map[s].Rec_List = new Mapping.PachMapReceiver.Map_Receiver[Rec_CT];
                                Map[s].Src = new Rhino.Geometry.Point3d(sr.ReadDouble(), sr.ReadDouble(), sr.ReadDouble());
                                Map[s].SrcType = sr.ReadString();
                                //4.4 Source delay (ms)
                                if (version > 2.0 || (version == 2.0 && rev >= 1))
                                {
                                    delay[s] = sr.ReadDouble();
                                }
                            }
                            break;
                        case "Receiver Hit Data":
                            if (Map[0] == null)
                            {
                                Map = new Mapping.PachMapReceiver[1];
                                Map[0] = new Mapping.PachMapReceiver();
                                Map[0].CutOffTime = (double)SampleCT / (double)SampleRate;
                                Map[0].SampleRate = SampleRate;
                                Map[0].SampleCT = SampleCT;
                                Map[0].Map_Mesh = Map_Mesh;
                                Map[0].Rec_List = new Mapping.PachMapReceiver.Map_Receiver[Rec_CT];
                                Map[0].SrcType = "Geodesic";
                            }

                            //8. Announce that the following data pertains to the receiver histograms (string)
                            //8a. Announce whether or not data is linked to vertices rather than faces (bool)
                            bool vert_Receiver = sr.ReadBoolean();
                            for (int s = 0; s < s_ct; s++)
                            {
                                Map[s].Rec_Vertex = vert_Receiver;
                                for (int i = 0; i < Map[s].Rec_List.Length; i++)
                                {
                                    //for version 1.7 and up, write direct sound arrival time.
                                    //Write Receiver Index (int)
                                    int j = (int)sr.ReadUInt32();
                                    //Write Direct Sound Arrival Time.
                                    double Direct_Time;
                                    if (version >= 1.7) Direct_Time = sr.ReadDouble(); else Direct_Time = (Utilities.PachTools.RPttoHPt(Map[s].Src) - Map[s].Rec_List[i].H_Origin).Length() / 343f;
                                    //Write Impedance of Air
                                    double Rho_C = version >= 2.0 ? sr.ReadDouble() : 400;

                                    if (vert_Receiver)
                                    {
                                        Map[s].Rec_List[i] = new Mapping.PachMapReceiver.Map_Receiver(Map_Mesh.Vertices[i], new Rhino.Geometry.Point3f((float)Map[s].Src.X, (float)Map[s].Src.Y, (float)Map[s].Src.Z), Direct_Time, Rho_C, i, SampleRate, SampleCT, Directional);
                                    }
                                    else
                                    {
                                        Rhino.Geometry.Point3d RecLoc = Map_Mesh.Faces.GetFaceCenter(i);
                                        Map[s].Rec_List[i] = new Mapping.PachMapReceiver.Map_Receiver(new Rhino.Geometry.Point3f((float)RecLoc.X, (float)RecLoc.Y, (float)RecLoc.Z), new Rhino.Geometry.Point3f((float)Map[s].Src.X, (float)Map[s].Src.Y, (float)Map[s].Src.Z), Direct_Time, Rho_C, i, SampleRate, SampleCT, Directional);
                                    }

                                    for (int Octave = 0; Octave < 8; Octave++)
                                    {
                                        //Write Octave (int)
                                        int Oct_out = (int)sr.ReadUInt32();
                                        if (Oct_out != Octave) throw new Exception(string.Format("Octave {0} Expected", Octave));
                                        double[] Hist = Map[s].Rec_List[i].GetEnergyHistogram(Octave);
                                        if (Directional)
                                        {
                                            if (version < 1.7)
                                            {
                                                for (int e = 0; e < SampleCT; e++)
                                                    Map[s].Rec_List[i].Combine_Sample(e, sr.ReadDouble(), new Hare.Geometry.Vector(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()), new Hare.Geometry.Vector(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()), Octave);
                                            }
                                            else
                                            {
                                                for (int e = 0; e < SampleCT; e++)
                                                    Map[s].Rec_List[i].Combine_Sample(e, sr.ReadDouble(), new Hare.Geometry.Vector(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()), new Hare.Geometry.Vector(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()), Octave);
                                            }
                                        }
                                        else
                                        {
                                            if (version < 1.7)
                                            {
                                                for (int e = 0; e < SampleCT; e++)
                                                    Map[s].Rec_List[i].Combine_Sample(e, sr.ReadDouble(), new Hare.Geometry.Vector(0, 0, 0), new Hare.Geometry.Vector(0, 0, 0), Octave);
                                            }
                                            else
                                            {
                                                for (int e = 0; e < SampleCT; e++)
                                                    Map[s].Rec_List[i].Combine_Sample(e, sr.ReadDouble(), new Hare.Geometry.Vector(0, 0, 0), new Hare.Geometry.Vector(0,0,0), Octave);
                                            }
                                        }
                                    }
                                    if (sr.ReadString() != "End_Receiver_Hits") throw new Exception("End of Receiver Hits Expected");
                                }
                            }
                            break;
                        case "End_of_File":
                            sr.Close();
                            return true;
                    }
                } while (true);
                throw new Exception("Unsuccessful Read");
            }
示例#9
0
    private static TclObject ScanNumber( byte[] src, int pos, int type )
    // Format character from "binary scan"
    {
      switch ( type )
      {

        case 'c':
          {
            return TclInteger.newInstance( (sbyte)src[pos] );
          }

        case 's':
          {
            short value = (short)( ( src[pos] & 0xff ) + ( ( src[pos + 1] & 0xff ) << 8 ) );
            return TclInteger.newInstance( (int)value );
          }

        case 'S':
          {
            short value = (short)( ( src[pos + 1] & 0xff ) + ( ( src[pos] & 0xff ) << 8 ) );
            return TclInteger.newInstance( (int)value );
          }

        case 'i':
          {
            int value = ( src[pos] & 0xff ) + ( ( src[pos + 1] & 0xff ) << 8 ) + ( ( src[pos + 2] & 0xff ) << 16 ) + ( ( src[pos + 3] & 0xff ) << 24 );
            return TclInteger.newInstance( value );
          }
        case 'I':
          {
            int value = ( src[pos + 3] & 0xff ) + ( ( src[pos + 2] & 0xff ) << 8 ) + ( ( src[pos + 1] & 0xff ) << 16 ) + ( ( src[pos] & 0xff ) << 24 );
            return TclInteger.newInstance( value );
          }
        case 'f':
          {
            System.IO.MemoryStream ms = new System.IO.MemoryStream( src, pos, 4, false );
            System.IO.BinaryReader reader = new System.IO.BinaryReader( ms );
            double fvalue = reader.ReadSingle();
            reader.Close();
            ms.Close();
            return TclDouble.newInstance( fvalue );
          }
        case 'd':
          {
            System.IO.MemoryStream ms = new System.IO.MemoryStream( src, pos, 8, false );
            System.IO.BinaryReader reader = new System.IO.BinaryReader( ms );
            double dvalue = reader.ReadDouble();
            reader.Close();
            ms.Close();
            return TclDouble.newInstance( dvalue );
          }
      }
      return null;
    }
示例#10
0
        public long SeekBlock(string id, long blockEnd = -1)
        {
            if (blockEnd == -1)
            {
                blockEnd = r.BaseStream.Length;
            }

            while (r.BaseStream.Position < blockEnd)
            {
                var rId   = r.ReadString();
                var rType = r.ReadInt32();

                switch (rType)
                {
                case FORMAT_TYPE_INT:
                    r.ReadInt32();
                    break;

                case FORMAT_TYPE_LONG:
                    r.ReadInt64();
                    break;

                case FORMAT_TYPE_DOUBLE:
                    r.ReadDouble();
                    break;

                case FORMAT_TYPE_FLOAT:
                    r.ReadSingle();
                    break;

                case FORMAT_TYPE_STRING:
                    r.ReadString();
                    break;

                case FORMAT_TYPE_BYTES:
                    r.BaseStream.Position += r.ReadInt64();
                    break;

                case FORMAT_TYPE_BLOCK:

                    if (rId == id)
                    {
                        return(r.BaseStream.Position + r.ReadInt64());
                    }

                    // Skip block.
                    r.BaseStream.Position = r.BaseStream.Position + r.ReadInt64();

                    // If it does not exists, continue searching within this block.
                    continue;

                default:
                    // Unknown type.
                    // Jump to end of block.
                    m_errors.Add(id, "Unknown type: " + rType);
                    r.BaseStream.Position = blockEnd;
                    break;
                }
            }

            return(-1);
        }
 /// <summary>
 /// Reads a binary header to determine the appropriate data type
 /// </summary>
 public static RasterDataTypes GetDataType(string filename)
 {
     System.IO.BinaryReader br = new System.IO.BinaryReader(new System.IO.FileStream(filename, System.IO.FileMode.Open));
     br.ReadInt32(); // NumColumns
     br.ReadInt32(); // NumRows
     br.ReadDouble(); // CellWidth
     br.ReadDouble(); // CellHeight
     br.ReadDouble(); // xllcenter
     br.ReadDouble(); // yllcenter
     RasterDataTypes result = (RasterDataTypes)br.ReadInt32();
     br.Close();
     return result;
 }
示例#12
0
        public static Row Deserialize(byte[] bytes)
        {
            using (System.IO.MemoryStream MS = new System.IO.MemoryStream(bytes, false)) {
                using (System.IO.BinaryReader BR = new System.IO.BinaryReader(MS)) {
                    byte[]    columnSet  = BR.ReadBytes(32);
                    int       FieldCount = BR.ReadInt32();
                    object[]  fields     = new object[FieldCount];
                    ColumnSet cs         = css [columnSet];
                    if (cs.Columns.Length != fields.Length)
                    {
                        throw new Exception();
                    }
                    for (int n = 0; n != fields.Length; n++)
                    {
                        bool Null = BR.ReadBoolean();
                        if (Null)
                        {
                            fields [n] = null;
                            continue;
                        }
                        switch (cs.Columns [n].TFQN)
                        {
                        case "System.Byte[]":
                            fields [n] = BR.ReadBytes(BR.ReadInt32());
                            break;

                        case "System.Byte":
                            fields [n] = BR.ReadByte();
                            break;

                        case "System.SByte":
                            fields [n] = BR.ReadSByte();
                            break;

                        case "System.Int16":
                            fields [n] = BR.ReadInt16();
                            break;

                        case "System.UInt16":
                            fields [n] = BR.ReadUInt16();
                            break;

                        case "System.Int32":
                            fields [n] = BR.ReadInt32();
                            break;

                        case "System.UInt32":
                            fields [n] = BR.ReadUInt32();
                            break;

                        case "System.Int64":
                            fields [n] = BR.ReadInt64();
                            break;

                        case "System.UInt64":
                            fields [n] = BR.ReadUInt64();
                            break;

                        case "System.Single":
                            fields [n] = BR.ReadSingle();
                            break;

                        case "System.Double":
                            fields [n] = BR.ReadDouble();
                            break;

                        case "System.String":
                            fields [n] = BR.ReadString();
                            break;

                        case "System.Char":
                            fields [n] = BR.ReadChar();
                            break;

                        case "System.Boolean":
                            fields [n] = BR.ReadBoolean();
                            break;

                        case "System.DateTime":
                            fields [n] = new DateTime(BR.ReadInt64());
                            break;

                        case "System.Guid":
                            fields [n] = new Guid(BR.ReadBytes(16));
                            break;
                        }
                    }
                    return(new Row(cs, fields));
                }
            }
        }
示例#13
0
文件: Row.cs 项目: vebin/BD2
 public static Row Deserialize(byte[] bytes)
 {
     using (System.IO.MemoryStream MS = new System.IO.MemoryStream (bytes, false)) {
         using (System.IO.BinaryReader BR = new System.IO.BinaryReader (MS)) {
             byte[] columnSet = BR.ReadBytes (32);
             int FieldCount = BR.ReadInt32 ();
             object[] fields = new object[FieldCount];
             ColumnSet cs = css [columnSet];
             if (cs.Columns.Length != fields.Length)
                 throw new Exception ();
             for (int n = 0; n != fields.Length; n++) {
                 bool Null = BR.ReadBoolean ();
                 if (Null) {
                     fields [n] = null;
                     continue;
                 }
                 switch (cs.Columns [n].TFQN) {
                 case "System.Byte[]":
                     fields [n] = BR.ReadBytes (BR.ReadInt32 ());
                     break;
                 case "System.Byte":
                     fields [n] = BR.ReadByte ();
                     break;
                 case "System.SByte":
                     fields [n] = BR.ReadSByte ();
                     break;
                 case "System.Int16":
                     fields [n] = BR.ReadInt16 ();
                     break;
                 case "System.UInt16":
                     fields [n] = BR.ReadUInt16 ();
                     break;
                 case "System.Int32":
                     fields [n] = BR.ReadInt32 ();
                     break;
                 case "System.UInt32":
                     fields [n] = BR.ReadUInt32 ();
                     break;
                 case "System.Int64":
                     fields [n] = BR.ReadInt64 ();
                     break;
                 case "System.UInt64":
                     fields [n] = BR.ReadUInt64 ();
                     break;
                 case "System.Single":
                     fields [n] = BR.ReadSingle ();
                     break;
                 case "System.Double":
                     fields [n] = BR.ReadDouble ();
                     break;
                 case "System.String":
                     fields [n] = BR.ReadString ();
                     break;
                 case "System.Char":
                     fields [n] = BR.ReadChar ();
                     break;
                 case "System.Boolean":
                     fields [n] = BR.ReadBoolean ();
                     break;
                 case "System.DateTime":
                     fields [n] = new DateTime (BR.ReadInt64 ());
                     break;
                 case "System.Guid":
                     fields [n] = new Guid (BR.ReadBytes (16));
                     break;
                 }
             }
             return new Row (cs, fields);
         }
     }
 }
    /// <summary>
    /// Imports a Galactic SPC file into a x and an y array. The file must not be a multi spectrum file (an exception is thrown in this case).
    /// </summary>
    /// <param name="xvalues">The x values of the spectrum.</param>
    /// <param name="yvalues">The y values of the spectrum.</param>
    /// <param name="filename">The filename where to import from.</param>
    /// <returns>Null if successful, otherwise an error description.</returns>
    public static string ToArrays(string filename, out double [] xvalues, out double [] yvalues)
    {
      System.IO.Stream stream=null;

      SPCHDR hdr = new SPCHDR();
      SUBHDR subhdr = new SUBHDR();

      try
      {
        stream = new System.IO.FileStream(filename,System.IO.FileMode.Open,System.IO.FileAccess.Read,System.IO.FileShare.Read);
        System.IO.BinaryReader binreader = new System.IO.BinaryReader(stream);


        hdr.ftflgs = binreader.ReadByte(); // ftflgs : not-evenly spaced data
        hdr.fversn = binreader.ReadByte(); // fversn : new version
        hdr.fexper = binreader.ReadByte(); // fexper : general experimental technique
        hdr.fexp   = binreader.ReadByte(); // fexp   : fractional scaling exponent (0x80 for floating point)

        hdr.fnpts  = binreader.ReadInt32(); // fnpts  : number of points

        hdr.ffirst = binreader.ReadDouble(); // ffirst : first x-value
        hdr.flast  = binreader.ReadDouble(); // flast : last x-value
        hdr.fnsub  = binreader.ReadInt32(); // fnsub : 1 (one) subfile only
      
        binreader.ReadByte(); //  Type of X axis units (see definitions below) 
        binreader.ReadByte(); //  Type of Y axis units (see definitions below) 
        binreader.ReadByte(); // Type of Z axis units (see definitions below)
        binreader.ReadByte(); // Posting disposition (see GRAMSDDE.H)

        binreader.Read(new byte[0x1E0],0,0x1E0); // rest of SPC header


        // ---------------------------------------------------------------------
        //   following the x-values array
        // ---------------------------------------------------------------------

        if(hdr.fversn!=0x4B)
        {
          if(hdr.fversn==0x4D)
            throw new System.FormatException(string.Format("This SPC file has the old format version of {0}, the only version supported here is the new version {1}",hdr.fversn,0x4B));
          else
            throw new System.FormatException(string.Format("This SPC file has a version of {0}, the only version recognized here is {1}",hdr.fversn,0x4B));
        }

        if(0!=(hdr.ftflgs & 0x80))
        {
          xvalues = new double[hdr.fnpts];
          for(int i=0;i<hdr.fnpts;i++)
            xvalues[i] = binreader.ReadSingle();
        }
        else if(0==hdr.ftflgs) // evenly spaced data
        {
          xvalues = new double[hdr.fnpts];
          for(int i=0;i<hdr.fnpts;i++)
            xvalues[i] = hdr.ffirst + i*(hdr.flast-hdr.ffirst)/(hdr.fnpts-1);
        }
        else
        {
          throw new System.FormatException("The SPC file must not be a multifile; only single file format is accepted!");
        }



        // ---------------------------------------------------------------------
        //   following the y SUBHEADER
        // ---------------------------------------------------------------------

        subhdr.subflgs = binreader.ReadByte(); // subflgs : always 0
        subhdr.subexp  = binreader.ReadByte(); // subexp : y-values scaling exponent (set to 0x80 means floating point representation)
        subhdr.subindx = binreader.ReadInt16(); // subindx :  Integer index number of trace subfile (0=first)

        subhdr.subtime = binreader.ReadSingle(); // subtime;   Floating time for trace (Z axis corrdinate) 
        subhdr.subnext = binreader.ReadSingle(); // subnext;   Floating time for next trace (May be same as beg) 
        subhdr.subnois = binreader.ReadSingle(); // subnois;   Floating peak pick noise level if high byte nonzero 

        subhdr.subnpts = binreader.ReadInt32(); // subnpts;  Integer number of subfile points for TXYXYS type 
        subhdr.subscan = binreader.ReadInt32(); // subscan; Integer number of co-added scans or 0 (for collect) 
        subhdr.subwlevel = binreader.ReadSingle();        // subwlevel;  Floating W axis value (if fwplanes non-zero) 
        subhdr.subresv   = binreader.ReadInt32(); // subresv[4];   Reserved area (must be set to zero) 


        // ---------------------------------------------------------------------
        //   following the y-values array
        // ---------------------------------------------------------------------
        yvalues = new double[hdr.fnpts];
        
        if(hdr.fexp==0x80) //floating point format
        {
          for(int i=0;i<hdr.fnpts;i++)
            yvalues[i] = binreader.ReadSingle();
        }
        else // fixed exponent format
        {
          for(int i=0;i<hdr.fnpts;i++)
            yvalues[i] = binreader.ReadInt32()*Math.Pow(2,hdr.fexp-32);
        }
      }
      catch(Exception e)
      {
        xvalues = null;
        yvalues = null;
        return e.ToString();
      }
      finally
      {
        if(null!=stream)
          stream.Close();
      }
      
      return null;
    }
示例#15
0
        /// <summary>
        /// Imports a Galactic SPC file into a x and an y array. The file must not be a multi spectrum file (an exception is thrown in this case).
        /// </summary>
        /// <param name="xvalues">The x values of the spectrum.</param>
        /// <param name="yvalues">The y values of the spectrum.</param>
        /// <param name="filename">The filename where to import from.</param>
        /// <returns>Null if successful, otherwise an error description.</returns>
        public static string ToArrays(string filename, out double [] xvalues, out double [] yvalues)
        {
            System.IO.Stream stream = null;

            SPCHDR hdr    = new SPCHDR();
            SUBHDR subhdr = new SUBHDR();

            try
            {
                stream = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);
                System.IO.BinaryReader binreader = new System.IO.BinaryReader(stream);


                hdr.ftflgs = binreader.ReadByte();         // ftflgs : not-evenly spaced data
                hdr.fversn = binreader.ReadByte();         // fversn : new version
                hdr.fexper = binreader.ReadByte();         // fexper : general experimental technique
                hdr.fexp   = binreader.ReadByte();         // fexp   : fractional scaling exponent (0x80 for floating point)

                hdr.fnpts = binreader.ReadInt32();         // fnpts  : number of points

                hdr.ffirst = binreader.ReadDouble();       // ffirst : first x-value
                hdr.flast  = binreader.ReadDouble();       // flast : last x-value
                hdr.fnsub  = binreader.ReadInt32();        // fnsub : 1 (one) subfile only

                binreader.ReadByte();                      //  Type of X axis units (see definitions below)
                binreader.ReadByte();                      //  Type of Y axis units (see definitions below)
                binreader.ReadByte();                      // Type of Z axis units (see definitions below)
                binreader.ReadByte();                      // Posting disposition (see GRAMSDDE.H)

                binreader.Read(new byte[0x1E0], 0, 0x1E0); // rest of SPC header


                // ---------------------------------------------------------------------
                //   following the x-values array
                // ---------------------------------------------------------------------

                if (hdr.fversn != 0x4B)
                {
                    if (hdr.fversn == 0x4D)
                    {
                        throw new System.FormatException(string.Format("This SPC file has the old format version of {0}, the only version supported here is the new version {1}", hdr.fversn, 0x4B));
                    }
                    else
                    {
                        throw new System.FormatException(string.Format("This SPC file has a version of {0}, the only version recognized here is {1}", hdr.fversn, 0x4B));
                    }
                }

                if (0 != (hdr.ftflgs & 0x80))
                {
                    xvalues = new double[hdr.fnpts];
                    for (int i = 0; i < hdr.fnpts; i++)
                    {
                        xvalues[i] = binreader.ReadSingle();
                    }
                }
                else if (0 == hdr.ftflgs) // evenly spaced data
                {
                    xvalues = new double[hdr.fnpts];
                    for (int i = 0; i < hdr.fnpts; i++)
                    {
                        xvalues[i] = hdr.ffirst + i * (hdr.flast - hdr.ffirst) / (hdr.fnpts - 1);
                    }
                }
                else
                {
                    throw new System.FormatException("The SPC file must not be a multifile; only single file format is accepted!");
                }



                // ---------------------------------------------------------------------
                //   following the y SUBHEADER
                // ---------------------------------------------------------------------

                subhdr.subflgs = binreader.ReadByte();     // subflgs : always 0
                subhdr.subexp  = binreader.ReadByte();     // subexp : y-values scaling exponent (set to 0x80 means floating point representation)
                subhdr.subindx = binreader.ReadInt16();    // subindx :  Integer index number of trace subfile (0=first)

                subhdr.subtime = binreader.ReadSingle();   // subtime;   Floating time for trace (Z axis corrdinate)
                subhdr.subnext = binreader.ReadSingle();   // subnext;   Floating time for next trace (May be same as beg)
                subhdr.subnois = binreader.ReadSingle();   // subnois;   Floating peak pick noise level if high byte nonzero

                subhdr.subnpts   = binreader.ReadInt32();  // subnpts;  Integer number of subfile points for TXYXYS type
                subhdr.subscan   = binreader.ReadInt32();  // subscan; Integer number of co-added scans or 0 (for collect)
                subhdr.subwlevel = binreader.ReadSingle(); // subwlevel;  Floating W axis value (if fwplanes non-zero)
                subhdr.subresv   = binreader.ReadInt32();  // subresv[4];   Reserved area (must be set to zero)


                // ---------------------------------------------------------------------
                //   following the y-values array
                // ---------------------------------------------------------------------
                yvalues = new double[hdr.fnpts];

                if (hdr.fexp == 0x80) //floating point format
                {
                    for (int i = 0; i < hdr.fnpts; i++)
                    {
                        yvalues[i] = binreader.ReadSingle();
                    }
                }
                else // fixed exponent format
                {
                    for (int i = 0; i < hdr.fnpts; i++)
                    {
                        yvalues[i] = binreader.ReadInt32() * Math.Pow(2, hdr.fexp - 32);
                    }
                }
            }
            catch (Exception e)
            {
                xvalues = null;
                yvalues = null;
                return(e.ToString());
            }
            finally
            {
                if (null != stream)
                {
                    stream.Close();
                }
            }

            return(null);
        }
示例#16
0
        public static JSONNode Deserialize(System.IO.BinaryReader aReader)
        {
            JSONBinaryTag type = (JSONBinaryTag)aReader.ReadByte();

            switch (type)
            {
            case JSONBinaryTag.Array:
            {
                int       count = aReader.ReadInt32();
                JSONArray tmp   = new JSONArray();
                for (int i = 0; i < count; i++)
                {
                    tmp.Add(Deserialize(aReader));
                }
                return(tmp);
            }

            case JSONBinaryTag.Class:
            {
                int       count = aReader.ReadInt32();
                JSONClass tmp   = new JSONClass();
                for (int i = 0; i < count; i++)
                {
                    string key = aReader.ReadString();
                    var    val = Deserialize(aReader);
                    tmp.Add(key, val);
                }
                return(tmp);
            }

            case JSONBinaryTag.Value:
            {
                return(new JSONData(aReader.ReadString()));
            }

            case JSONBinaryTag.IntValue:
            {
                return(new JSONData(aReader.ReadInt32()));
            }

            case JSONBinaryTag.DoubleValue:
            {
                return(new JSONData(aReader.ReadDouble()));
            }

            case JSONBinaryTag.BoolValue:
            {
                return(new JSONData(aReader.ReadBoolean()));
            }

            case JSONBinaryTag.FloatValue:
            {
                return(new JSONData(aReader.ReadSingle()));
            }

            default:
            {
                throw new Exception("Error deserializing JSON. Unknown tag: " + type);
            }
            }
        }
示例#17
0
        /// <summary>
        /// Читает P-объект из бинарного ридера, начиная с текущего места
        /// </summary>
        /// <param name="typ"></param>
        /// <param name="br"></param>
        /// <returns></returns>
        public static object GetPO(PType typ, System.IO.BinaryReader br)
        {
            switch (typ.Vid)
            {
            case PTypeEnumeration.none: return(null);

            case PTypeEnumeration.boolean: return(br.ReadBoolean());

            case PTypeEnumeration.integer: return(br.ReadInt32());

            case PTypeEnumeration.longinteger: return(br.ReadInt64());

            case PTypeEnumeration.real: return(br.ReadDouble());

            case PTypeEnumeration.@byte: return(br.ReadByte());

            case PTypeEnumeration.fstring:
            {
                //int len = ((PTypeFString)typ).Length;
                int    size = ((PTypeFString)typ).Size;
                byte[] arr  = new byte[size];
                arr = br.ReadBytes(size);
                string s = System.Text.Encoding.Unicode.GetString(arr);
                return(s);
            }

            case PTypeEnumeration.sstring:
            {
                //int len = br.ReadInt32();
                //char[] chrs = br.ReadChars(len);
                //return new string(chrs);
                return(br.ReadString());
            }

            case PTypeEnumeration.record:
            {
                PTypeRecord r_tp   = (PTypeRecord)typ;
                object[]    fields = new object[r_tp.Fields.Length];
                for (int i = 0; i < r_tp.Fields.Length; i++)
                {
                    fields[i] = GetPO(r_tp.Fields[i].Type, br);
                }
                return(fields);
            }

            case PTypeEnumeration.sequence:
            {
                PTypeSequence mts  = (PTypeSequence)typ;
                PType         tel  = mts.ElementType;
                long          llen = br.ReadInt64();
                object[]      els  = new object[llen];
                for (long ii = 0; ii < llen; ii++)
                {
                    els[ii] = GetPO(tel, br);
                }
                return(els);
            }

            case PTypeEnumeration.union:
            {
                PTypeUnion mtu = (PTypeUnion)typ;
                int        v   = br.ReadByte();
                PType      mt  = mtu.Variants[v].Type;
                return(new object[] { v, GetPO(mt, br) });
            }

            default: throw new Exception("Err in TPath Get(): type is not implemented " + typ.Vid);
            }
        }
示例#18
0
 /// <summary>
 /// Loads a quadtree from a file
 /// </summary>
 /// <param name="filename"></param>
 /// <returns></returns>
 public static QuadTree FromFile(string filename)
 {
     System.IO.FileStream fs = new System.IO.FileStream(filename, System.IO.FileMode.Open,System.IO.FileAccess.Read);
     System.IO.BinaryReader br = new System.IO.BinaryReader(fs);
     if (br.ReadDouble() != INDEXFILEVERSION) //Check fileindex version
     {
         fs.Close();
         fs.Dispose();
         throw new ObsoleteFileFormatException("Invalid index file version. Please rebuild the spatial index by either deleting the index");
     }
     QuadTree node = ReadNode(0, ref br);
     br.Close();
     fs.Close();
     return node;
 }
 /// <summary>
 ///Deserializes DiagramState
 ///</summary>
 ///<param name="reader">the reader from which to deserialize</param>
 ///<returns>deserialized DiagramState</returns>
 public virtual object Deserialize(System.IO.BinaryReader reader)
 {
     this._Z = reader.ReadDouble();
     return(this);
 }
示例#20
0
 /// <summary>
 /// Loads an xyz point from a reader
 /// </summary>
 /// <param name="S">binary reader</param>
 /// <returns></returns>
 public static xyz Load(System.IO.BinaryReader S)
 {
     return(new xyz(S.ReadDouble(), S.ReadDouble(), S.ReadDouble()));
 }
示例#21
0
        public static Properties ReadFrom(System.IO.BinaryReader reader)
        {
            if (reader == null)
            {
                throw new System.ArgumentNullException(nameof(reader));
            }

            var maxTickCount           = reader.ReadInt32();
            var teamSize               = reader.ReadInt32();
            var ticksPerSecond         = reader.ReadDouble();
            var updatesPerTick         = reader.ReadInt32();
            var lootBoxSize            = Vec2Double.ReadFrom(reader);
            var unitSize               = Vec2Double.ReadFrom(reader);
            var unitMaxHorizontalSpeed = reader.ReadDouble();
            var unitFallSpeed          = reader.ReadDouble();
            var unitJumpTime           = reader.ReadDouble();
            var unitJumpSpeed          = reader.ReadDouble();
            var jumpPadJumpTime        = reader.ReadDouble();
            var jumpPadJumpSpeed       = reader.ReadDouble();
            var unitMaxHealth          = reader.ReadInt32();
            var healthPackHealth       = reader.ReadInt32();
            var weaponParametersSize   = reader.ReadInt32();
            var weaponParameters       = new System.Collections.Generic.Dictionary <WeaponType, WeaponParameters>(weaponParametersSize);

            for (var i = 0; i < weaponParametersSize; i++)
            {
                WeaponType weaponParametersKey;
                switch (reader.ReadInt32())
                {
                case 0:
                    weaponParametersKey = WeaponType.Pistol;
                    break;

                case 1:
                    weaponParametersKey = WeaponType.AssaultRifle;
                    break;

                case 2:
                    weaponParametersKey = WeaponType.RocketLauncher;
                    break;

                default:
                    throw new System.Exception("Unexpected discriminant value");
                }

                WeaponParameters weaponParametersValue;
                weaponParametersValue = Model.WeaponParameters.ReadFrom(reader);
                weaponParameters.Add(weaponParametersKey, weaponParametersValue);
            }

            var mineSize = Vec2Double.ReadFrom(reader);
            var mineExplosionParameters = ExplosionParameters.ReadFrom(reader);
            var minePrepareTime         = reader.ReadDouble();
            var mineTriggerTime         = reader.ReadDouble();
            var mineTriggerRadius       = reader.ReadDouble();
            var killScore = reader.ReadInt32();

            return(new Properties(
                       maxTickCount,
                       teamSize,
                       ticksPerSecond,
                       updatesPerTick,
                       lootBoxSize,
                       unitSize,
                       unitMaxHorizontalSpeed,
                       unitFallSpeed,
                       unitJumpTime,
                       unitJumpSpeed,
                       jumpPadJumpTime,
                       jumpPadJumpSpeed,
                       unitMaxHealth,
                       healthPackHealth,
                       weaponParameters,
                       mineSize,
                       mineExplosionParameters,
                       minePrepareTime,
                       mineTriggerTime,
                       mineTriggerRadius,
                       killScore));
        }
示例#22
0
文件: Point.cs 项目: thbin/TraceLab
 /// <summary>
 /// Reads the data. (allows faster custom serialization for better performance in TraceLab)
 /// </summary>
 /// <param name="reader">The reader.</param>
 public void ReadData(System.IO.BinaryReader reader)
 {
     this.m_x = reader.ReadDouble();
     this.m_y = reader.ReadDouble();
 }
示例#23
0
        public static void Read(this IPathCommand command, System.IO.BinaryReader reader)
        {
            switch (command.Type)
            {
            case CommandType.MoveTo:
            {
                MoveTo pCommand = command as MoveTo;
                pCommand.X = reader.ReadDouble();
                pCommand.Y = reader.ReadDouble();
            }
            break;

            case CommandType.LineTo:
            {
                LineTo pCommand = command as LineTo;
                pCommand.X = reader.ReadDouble();
                pCommand.Y = reader.ReadDouble();
            }
            break;

            case CommandType.CurveTo:
            {
                CurveTo pCommand = command as CurveTo;
                pCommand.ControlStart = reader.ReadPoint();
                pCommand.ControlEnd   = reader.ReadPoint();
                pCommand.End          = reader.ReadPoint();
            }
            break;

            case CommandType.SmoothCurveTo:
            {
                SmoothCurveTo pCommand = command as SmoothCurveTo;
                pCommand.ControlEnd = reader.ReadPoint();
                pCommand.End        = reader.ReadPoint();
            }
            break;

            case CommandType.EllipticalArcTo:
            {
                EllipticalArcTo pCommand = command as EllipticalArcTo;
                pCommand.Size           = new Size(reader.ReadDouble(), reader.ReadDouble());
                pCommand.End            = reader.ReadPoint();
                pCommand.RotationAngle  = reader.ReadDouble();
                pCommand.IsLargeArc     = reader.ReadBoolean();
                pCommand.SweepDirection = (reader.ReadBoolean() == false ? SweepDirection.Counterclockwise : SweepDirection.Clockwise);
            }
            break;

            case CommandType.QuadraticBeizerCurveTo:
            {
                QuadraticBeizerCurveTo pCommand = command as QuadraticBeizerCurveTo;
                pCommand.Control = reader.ReadPoint();
                pCommand.End     = reader.ReadPoint();
            }
            break;

            case CommandType.SmoothQuadraticBeizerCurveTo:
            {
                SmoothQuadraticBeizerCurveTo pCommand = command as SmoothQuadraticBeizerCurveTo;
                pCommand.End = reader.ReadPoint();
            }
            break;

            case CommandType.ClosePath:
            {
                // Do nothing
            }
            break;
            }
        }
示例#24
0
 public Light(System.IO.BinaryReader reader, bool sentFromServer)
     : base(reader, sentFromServer)
 {
     LightColour = new LightColour(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
     myRange     = reader.ReadDouble();
 }
示例#25
0
 public override void ReceiveExtraAI(System.IO.BinaryReader reader)
 {
     projectile.localAI[0] = (float)reader.ReadDouble();
 }
示例#26
0
        /// <summary>Loads the black-box logs from the previous simulation run</summary>
        internal static void LoadLogs()
        {
            string BlackBoxFile = OpenBveApi.Path.CombineFile(Program.FileSystem.SettingsFolder, "logs.bin");

            try
            {
                using (System.IO.FileStream Stream = new System.IO.FileStream(BlackBoxFile, System.IO.FileMode.Open, System.IO.FileAccess.Read))
                {
                    using (System.IO.BinaryReader Reader = new System.IO.BinaryReader(Stream, System.Text.Encoding.UTF8))
                    {
                        byte[]      Identifier = new byte[] { 111, 112, 101, 110, 66, 86, 69, 95, 76, 79, 71, 83 };
                        const short Version    = 1;
                        byte[]      Data       = Reader.ReadBytes(Identifier.Length);
                        for (int i = 0; i < Identifier.Length; i++)
                        {
                            if (Identifier[i] != Data[i])
                            {
                                throw new System.IO.InvalidDataException();
                            }
                        }
                        short Number = Reader.ReadInt16();
                        if (Version != Number)
                        {
                            throw new System.IO.InvalidDataException();
                        }
                        Game.LogRouteName = Reader.ReadString();
                        Game.LogTrainName = Reader.ReadString();
                        Game.LogDateTime  = DateTime.FromBinary(Reader.ReadInt64());
                        Interface.CurrentOptions.GameMode = (Interface.GameMode)Reader.ReadInt16();
                        Game.BlackBoxEntryCount           = Reader.ReadInt32();
                        Game.BlackBoxEntries = new Game.BlackBoxEntry[Game.BlackBoxEntryCount];
                        for (int i = 0; i < Game.BlackBoxEntryCount; i++)
                        {
                            Game.BlackBoxEntries[i].Time           = Reader.ReadDouble();
                            Game.BlackBoxEntries[i].Position       = Reader.ReadDouble();
                            Game.BlackBoxEntries[i].Speed          = Reader.ReadSingle();
                            Game.BlackBoxEntries[i].Acceleration   = Reader.ReadSingle();
                            Game.BlackBoxEntries[i].ReverserDriver = Reader.ReadInt16();
                            Game.BlackBoxEntries[i].ReverserSafety = Reader.ReadInt16();
                            Game.BlackBoxEntries[i].PowerDriver    = (Game.BlackBoxPower)Reader.ReadInt16();
                            Game.BlackBoxEntries[i].PowerSafety    = (Game.BlackBoxPower)Reader.ReadInt16();
                            Game.BlackBoxEntries[i].BrakeDriver    = (Game.BlackBoxBrake)Reader.ReadInt16();
                            Game.BlackBoxEntries[i].BrakeSafety    = (Game.BlackBoxBrake)Reader.ReadInt16();
                            Game.BlackBoxEntries[i].EventToken     = (Game.BlackBoxEventToken)Reader.ReadInt16();
                        }
                        Game.ScoreLogCount      = Reader.ReadInt32();
                        Game.ScoreLogs          = new Game.ScoreLog[Game.ScoreLogCount];
                        Game.CurrentScore.Value = 0;
                        for (int i = 0; i < Game.ScoreLogCount; i++)
                        {
                            Game.ScoreLogs[i].Time      = Reader.ReadDouble();
                            Game.ScoreLogs[i].Position  = Reader.ReadDouble();
                            Game.ScoreLogs[i].Value     = Reader.ReadInt32();
                            Game.ScoreLogs[i].TextToken = (Game.ScoreTextToken)Reader.ReadInt16();
                            Game.CurrentScore.Value    += Game.ScoreLogs[i].Value;
                        }
                        Game.CurrentScore.Maximum = Reader.ReadInt32();
                        Identifier = new byte[] { 95, 102, 105, 108, 101, 69, 78, 68 };
                        Data       = Reader.ReadBytes(Identifier.Length);
                        for (int i = 0; i < Identifier.Length; i++)
                        {
                            if (Identifier[i] != Data[i])
                            {
                                throw new System.IO.InvalidDataException();
                            }
                        }
                        Reader.Close();
                    } Stream.Close();
                }
            }
            catch
            {
                Game.LogRouteName       = "";
                Game.LogTrainName       = "";
                Game.LogDateTime        = DateTime.Now;
                Game.BlackBoxEntries    = new Game.BlackBoxEntry[256];
                Game.BlackBoxEntryCount = 0;
                Game.ScoreLogs          = new Game.ScoreLog[64];
                Game.ScoreLogCount      = 0;
            }
        }
示例#27
0
        /// <summary>
        /// Reads summary information from a stream, preparing the LinkedZone and its Sides for coming access requests.
        /// </summary>
        /// <param name="str">the stream from which data have to be retrieved.</param>
        protected void Read(System.IO.Stream str)
        {
            r = new System.IO.BinaryReader(m_Stream = str);
            byte   infotype     = r.ReadByte();
            ushort headerformat = r.ReadUInt16();

            if (infotype == ((byte)0x41))
            {
                switch (headerformat)
                {
                case (ushort)0x07: break;

                default: throw new SystemException("Unsupported format");
                }
            }
            ;

            if (r.ReadByte() != SectionTag)
            {
                throw new Exception("The first section in a TLG file must contain tracks!");
            }
            r.ReadInt64();

            m_Transform.MXX = m_Transform.MYY = 1.0;
            m_Transform.MXY = m_Transform.MYX = 0.0;
            m_Transform.TX  = m_Transform.TY = 0.0;
            m_Transform.RX  = m_Transform.RY = 0.0;

            m_Id.Part0 = r.ReadInt32();
            m_Id.Part1 = r.ReadInt32();
            m_Id.Part2 = r.ReadInt32();
            m_Id.Part3 = r.ReadInt32();

            m_Center.X      = r.ReadDouble();
            m_Center.Y      = r.ReadDouble();
            m_Extents.MinX  = r.ReadDouble();
            m_Extents.MaxX  = r.ReadDouble();
            m_Extents.MinY  = r.ReadDouble();
            m_Extents.MaxY  = r.ReadDouble();
            m_Transform.MXX = r.ReadDouble();
            m_Transform.MXY = r.ReadDouble();
            m_Transform.MYX = r.ReadDouble();
            m_Transform.MYY = r.ReadDouble();
            m_Transform.TX  = r.ReadDouble();
            m_Transform.TY  = r.ReadDouble();
            m_Transform.RX  = r.ReadDouble();
            m_Transform.RY  = r.ReadDouble();

            int    ntopviews    = r.ReadInt32();
            int    nbottomviews = r.ReadInt32();
            double toptz        = r.ReadDouble();
            double topbz        = r.ReadDouble();
            double bottomtz     = r.ReadDouble();
            double bottombz     = r.ReadDouble();
            long   topviews_sp  = str.Position;

            str.Seek(ntopviews * View.Size, System.IO.SeekOrigin.Current);
            long bottomviews_sp = str.Position;

            str.Seek(nbottomviews * View.Size, System.IO.SeekOrigin.Current);
            uint ntoptracks    = r.ReadUInt32();
            uint nbottomtracks = r.ReadUInt32();

            N_Tracks = r.ReadUInt32();
            long toptracks_sp    = str.Position;
            long bottomtracks_sp = toptracks_sp + MIPIndexedEmulsionTrack.Size * ntoptracks;

            Tracks_SP = bottomtracks_sp + MIPIndexedEmulsionTrack.Size * nbottomtracks;
            long toptrackindices_sp    = Tracks_SP + MIPBaseTrack.Size * N_Tracks;
            long bottomtrackindices_sp = toptrackindices_sp + MIPIndexedEmulsionTrack.IndexSize * ntoptracks;

            m_Top    = new Side(toptz, topbz, (int)ntopviews, topviews_sp, (int)ntoptracks, toptracks_sp, toptrackindices_sp, str);
            m_Bottom = new Side(bottomtz, bottombz, (int)nbottomviews, bottomviews_sp, (int)nbottomtracks, bottomtracks_sp, bottomtrackindices_sp, str);
        }
示例#28
0
 public void Read(System.IO.BinaryReader reader)
 {
     X = reader.ReadDouble();
     Y = reader.ReadDouble();
 }
示例#29
0
        public override void LoadData(System.IO.FileStream __fsFileStream)
        {
            System.IO.BinaryReader _brdrReader = new System.IO.BinaryReader(__fsFileStream);

            // only read necessary params from file header
            __fsFileStream.Seek(42, System.IO.SeekOrigin.Begin);
            int _iXDimension = (int)_brdrReader.ReadInt16();
            __fsFileStream.Seek(108, System.IO.SeekOrigin.Begin);
            DataType _dtDataType = (DataType)_brdrReader.ReadInt16();
            __fsFileStream.Seek(656, System.IO.SeekOrigin.Begin);
            int _iYDimension = (int)_brdrReader.ReadInt16();
            __fsFileStream.Seek(1446, System.IO.SeekOrigin.Begin);
            UInt32 numframes = (UInt32)_brdrReader.ReadInt32();

            // Start reading the XCalibStruct.
            SpeCalib XCalib = new SpeCalib(0, 0);
            __fsFileStream.Seek(3000, System.IO.SeekOrigin.Begin);
            XCalib.Offset = (double)_brdrReader.ReadDouble();
            __fsFileStream.Seek(3008, System.IO.SeekOrigin.Begin);
            XCalib.Factor = (double)_brdrReader.ReadDouble();
            __fsFileStream.Seek(3016, System.IO.SeekOrigin.Begin);
            XCalib.current_unit = (char)_brdrReader.ReadChar();
            __fsFileStream.Seek(3098, System.IO.SeekOrigin.Begin);
            XCalib.CalibValid = (char)_brdrReader.ReadChar();
            __fsFileStream.Seek(3101, System.IO.SeekOrigin.Begin);
            XCalib.PolynomOrder = (char)_brdrReader.ReadChar();
            __fsFileStream.Seek(3263, System.IO.SeekOrigin.Begin);

            XCalib.PolynomCoeff[0] = _brdrReader.ReadDouble();
            XCalib.PolynomCoeff[1] = _brdrReader.ReadDouble();
            XCalib.PolynomCoeff[2] = _brdrReader.ReadDouble();
            XCalib.PolynomCoeff[3] = _brdrReader.ReadDouble();
            XCalib.PolynomCoeff[4] = _brdrReader.ReadDouble();
            XCalib.PolynomCoeff[5] = _brdrReader.ReadDouble();

            __fsFileStream.Seek(3311, System.IO.SeekOrigin.Begin);
            XCalib.LaserPosition = (double)_brdrReader.ReadDouble();

            // Start reading the YCalibStruct.
            SpeCalib YCalib = new SpeCalib(0, 0);
            __fsFileStream.Seek(3489, System.IO.SeekOrigin.Begin);   // move ptr to x_calib start
            YCalib.Offset = (double)_brdrReader.ReadDouble();
            __fsFileStream.Seek(3497, System.IO.SeekOrigin.Begin);
            YCalib.Factor = (double)_brdrReader.ReadDouble();
            __fsFileStream.Seek(3505, System.IO.SeekOrigin.Begin);
            YCalib.current_unit = (char)_brdrReader.ReadChar();
            __fsFileStream.Seek(3587, System.IO.SeekOrigin.Begin);
            YCalib.CalibValid = (char)_brdrReader.ReadChar();
            __fsFileStream.Seek(3590, System.IO.SeekOrigin.Begin);
            YCalib.PolynomOrder = (char)_brdrReader.ReadChar();
            __fsFileStream.Seek(3752, System.IO.SeekOrigin.Begin);

            YCalib.PolynomCoeff[0] = _brdrReader.ReadDouble();
            YCalib.PolynomCoeff[1] = _brdrReader.ReadDouble();
            YCalib.PolynomCoeff[2] = _brdrReader.ReadDouble();
            YCalib.PolynomCoeff[3] = _brdrReader.ReadDouble();
            YCalib.PolynomCoeff[4] = _brdrReader.ReadDouble();
            YCalib.PolynomCoeff[5] = _brdrReader.ReadDouble();

            __fsFileStream.Seek(3800, System.IO.SeekOrigin.Begin);
            YCalib.LaserPosition = (double)_brdrReader.ReadDouble();

            int _iDimension;
            SpeCalib _calCurrCalib;
            if (_iYDimension == 1)
            {
                _iDimension = _iXDimension;
                _calCurrCalib = XCalib;
            }
            else if (_iXDimension == 1)
            {
                _iDimension = _iYDimension;
                _calCurrCalib = YCalib;
            }
            else
            {
                throw new UnexpectedFormatException("xylib does not support 2-D images");
            }

            __fsFileStream.Seek(4100, System.IO.SeekOrigin.Begin);      // move ptr to frames-start
            for (int frm = 0; frm < (int)numframes; frm++)
            {
                Block _blkBlock = new Block();

                Column _colXCol = this.GetCalibColumn(_calCurrCalib, _iDimension);
                _blkBlock.AddColumn(_colXCol, "", true);

                ListColumn _colYCol = new ListColumn();

                for (int i = 0; i < _iDimension; ++i)
                {
                    double _dYVal = 0;
                    switch (_dtDataType)
                    {
                        case DataType.SPE_DATA_FLOAT:
                            _dYVal = (double)_brdrReader.ReadSingle();
                            break;
                        case DataType.SPE_DATA_LONG:
                            _dYVal = (double)_brdrReader.ReadInt32();
                            break;
                        case DataType.SPE_DATA_INT:
                            _dYVal = (double)_brdrReader.ReadInt16();
                            break;
                        case DataType.SPE_DATA_UINT:
                            _dYVal = (double)_brdrReader.ReadUInt16();
                            break;
                        default:
                            break;
                    }
                    _colYCol.AddValue(_dYVal);
                }
                _blkBlock.AddColumn(_colYCol, "", true);
                this.m_blcklstBlocks.Add(_blkBlock);
            }
        }
示例#30
0
            /// <summary>
            /// reads a file and populates the map receiver instance.
            /// </summary>
            /// <returns></returns>
            public static bool Read_pachm(string path, ref Mapping.PachMapReceiver[] Map)
            {
                System.IO.BinaryReader sr = new System.IO.BinaryReader(System.IO.File.Open(path, System.IO.FileMode.Open));
                //1. Write calculation type. (string)
                string CalcType = sr.ReadString();

                if (CalcType != "Type;Map_Data" && CalcType != "Type;Map_Data_NoDir")
                {
                    throw new Exception("Map Data File Expected");
                }
                bool Directional = (CalcType == "Type;Map_Data");

                //2. Write the number of samples in each histogram. (int)
                int SampleCT = (int)sr.ReadUInt32();
                //3. Write the sample rate. (int)
                int SampleRate = (int)sr.ReadUInt32();
                //4. Write the number of Receivers (int)
                int Rec_CT = (int)sr.ReadUInt32();
                //4.5 Write the version number
                double version = 1.1;
                double rev     = 0;
                //5. Announce that the following data pertains to the form of the analysis mesh. (string)
                int s_ct = 1;

                Rhino.Geometry.Mesh Map_Mesh = new Rhino.Geometry.Mesh();
                Map = new Mapping.PachMapReceiver[1];
                //Map[0] = new Pach_Map_Receiver();
                //double[] Rho_C = null;
                double[] delay;

                do
                {
                    switch (sr.ReadString())
                    {
                    case "Version":
                        //Pach1.7 = Versioning functionality added.
                        string v = sr.ReadString();
                        version = double.Parse(v.Substring(0, 3));
                        rev     = int.Parse(v.Split(new char[1] {
                            '.'
                        })[3]);
                        break;

                    case "Mesh Information":
                        //6. Announce Mesh Vertices (string)
                        //Write the number of vertices & faces (int) (int)
                        if (sr.ReadString() != "Mesh Vertices")
                        {
                            throw new Exception("Mesh Vertices Expected");
                        }

                        int VC = (int)sr.ReadUInt32();
                        int FC = (int)sr.ReadUInt32();
                        for (int i = 0; i < VC; i++)
                        {
                            //Write Vertex: (double) (double) (double)
                            Map_Mesh.Vertices.Add(new Rhino.Geometry.Point3d(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()));
                        }

                        //7. Announce Mesh Faces (string)
                        if (sr.ReadString() != "Mesh Faces")
                        {
                            throw new Exception("Mesh Faces Expected");
                        }

                        for (int i = 0; i < FC; i++)
                        {
                            // Write mesh vertex indices: (int) (int) (int) (int)
                            Map_Mesh.Faces.AddFace((int)sr.ReadUInt32(), (int)sr.ReadUInt32(), (int)sr.ReadUInt32(), (int)sr.ReadUInt32());
                        }
                        break;

                    case "Sources":
                        //7.5: Announce the number of sources.
                        s_ct  = sr.ReadInt32();
                        delay = new double[s_ct];
                        Map   = new Mapping.PachMapReceiver[s_ct];
                        //7.5a Announce the type of source.

                        for (int s = 0; s < s_ct; s++)
                        {
                            Map[s]            = new Mapping.PachMapReceiver();
                            Map[s].CutOffTime = (double)SampleCT / (double)SampleRate;
                            Map[s].SampleCT   = SampleCT;
                            Map[s].SampleRate = SampleRate;
                            Map[s].Map_Mesh   = Map_Mesh;
                            Map[s].Rec_List   = new Mapping.PachMapReceiver.Map_Receiver[Rec_CT];
                            Map[s].SrcType    = sr.ReadString();
                            //4.4 Source delay (ms)
                            if (version > 2.0 || (version == 2.0 && rev >= 1))
                            {
                                delay[s] = sr.ReadDouble();
                            }
                            Map[s].SWL = new double[8];
                            if (version > 2.0 || (version == 2.0 && rev >= 2))
                            {
                                for (int j = 0; j < 8; j++)
                                {
                                    Map[s].SWL[j] = sr.ReadDouble();                            //v.2.0.0.2
                                }
                            }
                            else
                            {
                                Map[s].SWL = new double[8] {
                                    120, 120, 120, 120, 120, 120, 120, 120
                                }
                            };
                        }
                        break;

                    case "SourceswLoc":
                        //7.5: Announce the number of sources.
                        s_ct  = sr.ReadInt32();
                        delay = new double[s_ct];
                        Map   = new Mapping.PachMapReceiver[s_ct];
                        //7.5a Announce the type of source.

                        for (int s = 0; s < s_ct; s++)
                        {
                            Map[s]            = new Mapping.PachMapReceiver();
                            Map[s].CutOffTime = (double)SampleCT / (double)SampleRate * 1000;
                            Map[s].SampleCT   = SampleCT;
                            Map[s].SampleRate = SampleRate;
                            Map[s].Map_Mesh   = Map_Mesh;
                            Map[s].Rec_List   = new Mapping.PachMapReceiver.Map_Receiver[Rec_CT];
                            Map[s].Src        = new Rhino.Geometry.Point3d(sr.ReadDouble(), sr.ReadDouble(), sr.ReadDouble());
                            Map[s].SrcType    = sr.ReadString();
                            //4.4 Source delay (ms)
                            if (version > 2.0 || (version == 2.0 && rev >= 1))
                            {
                                delay[s] = sr.ReadDouble();
                            }
                            Map[s].SWL = new double[8];
                            if (version > 2.0 || (version == 2.0 && rev >= 2))
                            {
                                for (int j = 0; j < 8; j++)
                                {
                                    Map[s].SWL[j] = sr.ReadDouble();                            //v.2.0.0.2
                                }
                            }
                            else
                            {
                                Map[s].SWL = new double[8] {
                                    120, 120, 120, 120, 120, 120, 120, 120
                                }
                            };
                        }
                        break;

                    case "Receiver Hit Data":
                        if (Map[0] == null)
                        {
                            Map               = new Mapping.PachMapReceiver[1];
                            Map[0]            = new Mapping.PachMapReceiver();
                            Map[0].CutOffTime = (double)SampleCT / (double)SampleRate;
                            Map[0].SampleRate = SampleRate;
                            Map[0].SampleCT   = SampleCT;
                            Map[0].Map_Mesh   = Map_Mesh;
                            Map[0].Rec_List   = new Mapping.PachMapReceiver.Map_Receiver[Rec_CT];
                            Map[0].SrcType    = "Geodesic";
                        }

                        //8. Announce that the following data pertains to the receiver histograms (string)
                        //8a. Announce whether or not data is linked to vertices rather than faces (bool)
                        bool vert_Receiver = sr.ReadBoolean();
                        for (int s = 0; s < s_ct; s++)
                        {
                            Map[s].Rec_Vertex = vert_Receiver;
                            for (int i = 0; i < Map[s].Rec_List.Length; i++)
                            {
                                //for version 1.7 and up, write direct sound arrival time.
                                //Write Receiver Index (int)
                                int j = (int)sr.ReadUInt32();
                                //Write Direct Sound Arrival Time.
                                double Direct_Time;
                                if (version >= 1.7)
                                {
                                    Direct_Time = sr.ReadDouble();
                                }
                                else
                                {
                                    Direct_Time = (Utilities.PachTools.RPttoHPt(Map[s].Src) - Map[s].Rec_List[i].H_Origin).Length() / 343f;
                                }
                                //Write Impedance of Air
                                double Rho_C = version >= 2.0 ? sr.ReadDouble() : 400;

                                if (vert_Receiver)
                                {
                                    Map[s].Rec_List[i] = new Mapping.PachMapReceiver.Map_Receiver(Map_Mesh.Vertices[i], new Rhino.Geometry.Point3f((float)Map[s].Src.X, (float)Map[s].Src.Y, (float)Map[s].Src.Z), Direct_Time, Rho_C, i, SampleRate, SampleCT, Directional);
                                }
                                else
                                {
                                    Rhino.Geometry.Point3d RecLoc = Map_Mesh.Faces.GetFaceCenter(i);
                                    Map[s].Rec_List[i] = new Mapping.PachMapReceiver.Map_Receiver(new Rhino.Geometry.Point3f((float)RecLoc.X, (float)RecLoc.Y, (float)RecLoc.Z), new Rhino.Geometry.Point3f((float)Map[s].Src.X, (float)Map[s].Src.Y, (float)Map[s].Src.Z), Direct_Time, Rho_C, i, SampleRate, SampleCT, Directional);
                                }

                                for (int Octave = 0; Octave < 8; Octave++)
                                {
                                    //Write Octave (int)
                                    int Oct_out = (int)sr.ReadUInt32();
                                    if (Oct_out != Octave)
                                    {
                                        throw new Exception(string.Format("Octave {0} Expected", Octave));
                                    }
                                    double[] Hist = Map[s].Rec_List[i].GetEnergyHistogram(Octave);
                                    if (Directional)
                                    {
                                        if (version < 1.7)
                                        {
                                            for (int e = 0; e < SampleCT; e++)
                                            {
                                                Map[s].Rec_List[i].Combine_Sample(e, sr.ReadDouble(), new Hare.Geometry.Vector(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()), new Hare.Geometry.Vector(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()), Octave);
                                            }
                                        }
                                        else
                                        {
                                            for (int e = 0; e < SampleCT; e++)
                                            {
                                                Map[s].Rec_List[i].Combine_Sample(e, sr.ReadDouble(), new Hare.Geometry.Vector(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()), new Hare.Geometry.Vector(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()), Octave);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (version < 1.7)
                                        {
                                            for (int e = 0; e < SampleCT; e++)
                                            {
                                                Map[s].Rec_List[i].Combine_Sample(e, sr.ReadDouble(), new Hare.Geometry.Vector(0, 0, 0), new Hare.Geometry.Vector(0, 0, 0), Octave);
                                            }
                                        }
                                        else
                                        {
                                            for (int e = 0; e < SampleCT; e++)
                                            {
                                                Map[s].Rec_List[i].Combine_Sample(e, sr.ReadDouble(), new Hare.Geometry.Vector(0, 0, 0), new Hare.Geometry.Vector(0, 0, 0), Octave);
                                            }
                                        }
                                    }
                                }
                                if (sr.ReadString() != "End_Receiver_Hits")
                                {
                                    throw new Exception("End of Receiver Hits Expected");
                                }
                            }
                        }
                        break;

                    case "End_of_File":
                        sr.Close();
                        return(true);
                    }
                } while (true);
                throw new Exception("Unsuccessful Read");
            }
示例#31
0
文件: GameMap.cs 项目: kamilion/WISP
        protected void ReadObjectDataFromTable(Dictionary<string, byte[]> data)
        {
            if (data.ContainsKey("dimX"))
            {
                m_DimensionX = BitConverter.ToDouble((byte[])data["dimX"], 0);
            }

            if (data.ContainsKey("dimY"))
            {
                m_DimensionY = BitConverter.ToDouble((byte[])data["dimY"], 0);
            }

            if (data.ContainsKey("dimZ"))
            {
                m_DimensionZ = BitConverter.ToDouble((byte[])data["dimZ"], 0);
            }

            if (data.ContainsKey("chSizeX"))
            {
                m_ChunkSizeX = BitConverter.ToDouble((byte[])data["chSizeX"], 0);
            }

            if (data.ContainsKey("chSizeY"))
            {
                m_ChunkSizeY = BitConverter.ToDouble((byte[])data["chSizeY"], 0);
            }

            if (data.ContainsKey("chSizeZ"))
            {
                m_ChunkSizeZ = BitConverter.ToDouble((byte[])data["chSizeZ"], 0);
            }

            if (data.ContainsKey("scale"))
            {
                m_Scale = BitConverter.ToDouble((byte[])data["scale"], 0);
            }

            if (data.ContainsKey("mapName"))
            {
                byte[] dat = (byte[])data["mapName"];
                m_Name = Encoding.UTF8.GetString(dat, 0, dat.Length);
            }

            if (data.ContainsKey("bg"))
            {

                byte[] dat = (byte[])data["bg"];
                m_MapBackground = Encoding.UTF8.GetString(dat, 0, dat.Length);
            }

            // load region data
            if (data.ContainsKey("regions"))
            {
                System.IO.MemoryStream memStream = new System.IO.MemoryStream((byte[])data["regions"]);
                System.IO.BinaryReader read = new System.IO.BinaryReader(memStream);
                int numRegions = read.ReadInt32(); // number of regions
                for (int i = 0; i < numRegions; i++)
                {
                    Region r = new Region();

                    // read region name
                    int nameLen = read.ReadInt32(); // read name length
                    byte[] datName = read.ReadBytes(nameLen);
                    r.ObjectName = Encoding.UTF8.GetString(datName, 0, datName.Length);

                    // read region internal name
                    int iNameLen = read.ReadInt32();
                    byte[] datIName = read.ReadBytes(iNameLen);
                    r.InternalName = Encoding.UTF8.GetString(datIName, 0, datIName.Length);

                    // read location
                    r.WorldLocation = new SVector3(read.ReadDouble(), read.ReadDouble(), read.ReadDouble());

                    // Read path geo
                    int numPoints = read.ReadInt32();
                    List<SVector3> pGeo = new List<SVector3>();
                    for (int v = 0; v < numPoints; v++)
                    {
                        SVector3 vPoint = new SVector3(read.ReadDouble(), read.ReadDouble(), read.ReadDouble());
                        pGeo.Add(vPoint);
                    }

                    r.Geo = pGeo;

                    // region ID
                    int UIDLen = read.ReadInt32(); // read title length
                    byte[] datUid = read.ReadBytes(UIDLen);
                    string uid = Encoding.UTF8.GetString(datUid, 0, datUid.Length);

                    r.UID = new Guid(uid);

                    // title
                    int titleLen = read.ReadInt32(); // read title length
                    byte[] datTitle = read.ReadBytes(titleLen);
                    r.ObjectName = Encoding.UTF8.GetString(datTitle, 0, datTitle.Length);

                    // description
                    int descLen = read.ReadInt32(); // read desc length
                    byte[] datDesc = read.ReadBytes(descLen);
                    r.Description = Encoding.UTF8.GetString(datDesc, 0, datDesc.Length);

                    // content id
                    int cIDLen = read.ReadInt32(); // content id length
                    byte[] datCont = read.ReadBytes(cIDLen);
                    r.ContentTag = Encoding.UTF8.GetString(datCont, 0, datCont.Length);

                    m_Regions.AddObject(r);
                }
            }
        }
示例#32
0
 public double getDouble()
 {
     return(reader.ReadDouble());
 }
示例#33
0
        protected void ReadObjectDataFromTable(Dictionary <string, byte[]> data)
        {
            if (data.ContainsKey("dimX"))
            {
                m_DimensionX = BitConverter.ToDouble((byte[])data["dimX"], 0);
            }

            if (data.ContainsKey("dimY"))
            {
                m_DimensionY = BitConverter.ToDouble((byte[])data["dimY"], 0);
            }

            if (data.ContainsKey("dimZ"))
            {
                m_DimensionZ = BitConverter.ToDouble((byte[])data["dimZ"], 0);
            }

            if (data.ContainsKey("chSizeX"))
            {
                m_ChunkSizeX = BitConverter.ToDouble((byte[])data["chSizeX"], 0);
            }

            if (data.ContainsKey("chSizeY"))
            {
                m_ChunkSizeY = BitConverter.ToDouble((byte[])data["chSizeY"], 0);
            }

            if (data.ContainsKey("chSizeZ"))
            {
                m_ChunkSizeZ = BitConverter.ToDouble((byte[])data["chSizeZ"], 0);
            }

            if (data.ContainsKey("scale"))
            {
                m_Scale = BitConverter.ToDouble((byte[])data["scale"], 0);
            }

            if (data.ContainsKey("mapName"))
            {
                byte[] dat = (byte[])data["mapName"];
                m_Name = Encoding.UTF8.GetString(dat, 0, dat.Length);
            }

            if (data.ContainsKey("bg"))
            {
                byte[] dat = (byte[])data["bg"];
                m_MapBackground = Encoding.UTF8.GetString(dat, 0, dat.Length);
            }


            // load region data
            if (data.ContainsKey("regions"))
            {
                System.IO.MemoryStream memStream = new System.IO.MemoryStream((byte[])data["regions"]);
                System.IO.BinaryReader read      = new System.IO.BinaryReader(memStream);
                int numRegions = read.ReadInt32(); // number of regions
                for (int i = 0; i < numRegions; i++)
                {
                    Region r = new Region();

                    // read region name
                    int    nameLen = read.ReadInt32(); // read name length
                    byte[] datName = read.ReadBytes(nameLen);
                    r.ObjectName = Encoding.UTF8.GetString(datName, 0, datName.Length);

                    // read region internal name
                    int    iNameLen = read.ReadInt32();
                    byte[] datIName = read.ReadBytes(iNameLen);
                    r.InternalName = Encoding.UTF8.GetString(datIName, 0, datIName.Length);

                    // read location
                    r.WorldLocation = new SVector3(read.ReadDouble(), read.ReadDouble(), read.ReadDouble());

                    // Read path geo
                    int             numPoints = read.ReadInt32();
                    List <SVector3> pGeo      = new List <SVector3>();
                    for (int v = 0; v < numPoints; v++)
                    {
                        SVector3 vPoint = new SVector3(read.ReadDouble(), read.ReadDouble(), read.ReadDouble());
                        pGeo.Add(vPoint);
                    }

                    r.Geo = pGeo;

                    // region ID
                    int    UIDLen = read.ReadInt32(); // read title length
                    byte[] datUid = read.ReadBytes(UIDLen);
                    string uid    = Encoding.UTF8.GetString(datUid, 0, datUid.Length);

                    r.UID = new Guid(uid);

                    // title
                    int    titleLen = read.ReadInt32(); // read title length
                    byte[] datTitle = read.ReadBytes(titleLen);
                    r.ObjectName = Encoding.UTF8.GetString(datTitle, 0, datTitle.Length);

                    // description
                    int    descLen = read.ReadInt32(); // read desc length
                    byte[] datDesc = read.ReadBytes(descLen);
                    r.Description = Encoding.UTF8.GetString(datDesc, 0, datDesc.Length);

                    // content id
                    int    cIDLen  = read.ReadInt32(); // content id length
                    byte[] datCont = read.ReadBytes(cIDLen);
                    r.ContentTag = Encoding.UTF8.GetString(datCont, 0, datCont.Length);

                    m_Regions.AddObject(r);
                }
            }
        }
            public static bool Read_Pac1(string filename, ref Direct_Sound[] Direct_Data, ref ImageSourceData[] IS_Data, ref Environment.Receiver_Bank[] Receiver)
            {
                System.IO.BinaryReader sr = new System.IO.BinaryReader(System.IO.File.Open(filename, System.IO.FileMode.Open));
                try
                {
                    //1. Date & Time
                    string Savedate = sr.ReadString();
                    //2. Plugin Version
                    string Pach_version = sr.ReadString();
                    //3. Cut off Time and SampleRate
                    double CO_TIME = sr.ReadDouble();
                    int SampleRate = sr.ReadInt32();
                    //4. Source Count
                    int SrcCt = 1;
                    if (double.Parse(Pach_version.Substring(0, 3)) >= 1.1) SrcCt = sr.ReadInt32();
                    //4.1 Source Location x
                    //4.2 Source Location y
                    //4.3 Source Location z
                    Hare.Geometry.Point[] SrcPt = new Hare.Geometry.Point[SrcCt];
                    for (int s = 0; s < SrcCt; s++) SrcPt[s] = new Hare.Geometry.Point(sr.ReadDouble(), sr.ReadDouble(), sr.ReadDouble());
                    //5. No of Receivers
                    int Rec_Ct = sr.ReadInt32();
                    //6. Write the coordinates of each receiver point
                    //6b. Write the environmental characteristics at each receiver point (Rho * C); V2.0 only...
                    Hare.Geometry.Point[] Recs = new Hare.Geometry.Point[Rec_Ct];
                    double[] Rho_C = new double[Rec_Ct];
                    for (int q = 0; q < Rec_Ct; q++)
                    {
                        Recs[q] = new Hare.Geometry.Point(sr.ReadDouble(), sr.ReadDouble(), sr.ReadDouble());
                        if (double.Parse(Pach_version.Substring(0, 3)) >= 2.0) Rho_C[q] = sr.ReadDouble();
                        else Rho_C[q] = 400;
                    }

                    Direct_Data = new Direct_Sound[SrcCt];
                    IS_Data = new ImageSourceData[SrcCt];
                    Receiver = new Environment.Receiver_Bank[SrcCt];

                    int DDCT = 0;
                    int ISCT = 0;
                    int RTCT = 0;
                    do
                    {
                        string readin = sr.ReadString();
                        switch (readin)
                        {
                            case "Direct_Sound":
                            case "Direct_Sound w sourcedata":
                                //9. Read Direct Sound Data
                                Direct_Data[DDCT] = Direct_Sound.Read_Data(ref sr, Recs, SrcPt[DDCT], Rho_C, Pach_version);
                                Direct_Data[DDCT].CO_Time = CO_TIME;
                                Direct_Data[DDCT].SampleFreq = (int)SampleRate;
                                DDCT++;
                                break;
                            case "Image-Source_Data":
                                //10. Read Image Source Sound Data
                                IS_Data[ISCT] = ImageSourceData.Read_Data(ref sr, Recs.Length, Direct_Data[DDCT - 1], false, ISCT, Pach_version);
                                ISCT++;
                                break;
                            case "Ray-Traced_Data":
                                //11. Read Ray Traced Sound Data
                                Receiver[RTCT] = Environment.Receiver_Bank.Read_Data(ref sr, Rec_Ct, Recs, Rho_C, Direct_Data[RTCT].Delay_ms, ref SampleRate, Pach_version);
                                RTCT++;
                                break;
                            case "End":
                                sr.Close();
                                return true;
                        }
                    } while (true);
                }
                catch (System.Exception X)
                {
                    sr.Close();
                    System.Windows.Forms.MessageBox.Show("File Read Failed...", String.Format("Results file was corrupt or incomplete. We apologize for this inconvenience. Please report this to the software author. It will be much appreciated. \r\n Exception Message: {0}. \r\n Method: {1}" , X.Message, X.TargetSite));
                    return false;
                }
            }
 public static ActionLibrary Load(System.IO.Stream s)
 {
     ActionLibrary lib = new ActionLibrary();
     System.IO.BinaryReader br = new System.IO.BinaryReader(s, Encoding.ASCII);
     lib.GameMakerVersion = br.ReadInt32();
     bool gm5 = lib.GameMakerVersion == 500;
     lib.TabCaption = new string(br.ReadChars(br.ReadInt32()));
     lib.LibraryID = br.ReadInt32();
     lib.Author = new string(br.ReadChars(br.ReadInt32()));
     lib.Version = br.ReadInt32();
     lib.LastChanged = new DateTime(1899, 12, 30).AddDays(br.ReadDouble());
     lib.Info = new string(br.ReadChars(br.ReadInt32()));
     lib.InitializationCode = new string(br.ReadChars(br.ReadInt32()));
     lib.AdvancedModeOnly = br.ReadInt32() == 0 ? false : true;
     lib.ActionNumberIncremental = br.ReadInt32();
     for (int i = br.ReadInt32(); i > 0; i--)
     {
         int ver = br.ReadInt32();
         ActionDefinition a = new ActionDefinition(lib, new string(br.ReadChars(br.ReadInt32())), br.ReadInt32());
         a.GameMakerVersion = ver;
         int size = br.ReadInt32();
         a.OriginalImage = new byte[size];
         br.Read(a.OriginalImage, 0, size);
         System.IO.MemoryStream ms = new System.IO.MemoryStream(a.OriginalImage);
         System.Drawing.Bitmap b = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromStream(ms);
         a.Image = new System.Drawing.Bitmap(24, 24, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
         using (var g = System.Drawing.Graphics.FromImage(a.Image))
         {
             g.DrawImage(b, new System.Drawing.Rectangle(0, 0, b.Width, b.Height));
         }
         if (b.PixelFormat != System.Drawing.Imaging.PixelFormat.Format32bppArgb)
             ((System.Drawing.Bitmap)a.Image).MakeTransparent(b.GetPixel(0, b.Height - 1));
         ms.Close();
         b.Dispose();
         a.Hidden = br.ReadInt32() == 0 ? false : true;
         a.Advanced = br.ReadInt32() == 0 ? false : true;
         a.RegisteredOnly = ver == 500 || (br.ReadInt32() == 0) ? false : true;
         a.Description = new string(br.ReadChars(br.ReadInt32()));
         a.ListText = new string(br.ReadChars(br.ReadInt32()));
         a.HintText = new string(br.ReadChars(br.ReadInt32()));
         a.Kind = (ActionKind)br.ReadInt32();
         a.InterfaceKind = (ActionInferfaceKind)br.ReadInt32();
         a.IsQuestion = br.ReadInt32() == 0 ? false : true;
         a.ShowApplyTo = br.ReadInt32() == 0 ? false : true;
         a.ShowRelative = br.ReadInt32() == 0 ? false : true;
         a.ArgumentCount = br.ReadInt32();
         int count = br.ReadInt32();
         if (a.Arguments.Length != count)
             a.Arguments = new ActionArgument[count];
         for (int j = 0; j < count; j++)
         {
             a.Arguments[j] = new ActionArgument();
             a.Arguments[j].Caption = new string(br.ReadChars(br.ReadInt32()));
             a.Arguments[j].Type = (ActionArgumentType)br.ReadInt32();
             a.Arguments[j].DefaultValue = new string(br.ReadChars(br.ReadInt32()));
             a.Arguments[j].Menu = new string(br.ReadChars(br.ReadInt32()));
         }
         a.ExecutionType = (ActionExecutionType)br.ReadInt32();
         a.FunctionName = new string(br.ReadChars(br.ReadInt32()));
         a.Code = new string(br.ReadChars(br.ReadInt32()));
         lib.Actions.Add(a);
     }
     //Hmm...
     //ActionDefinition d = new ActionDefinition(lib);
     //d.Description = "Font...";
     //d.ArgumentCount = 1;
     //d.Arguments[0] = new ActionArgument();
     //d.Arguments[0].Type = ActionArgumentType.FontString;
     //d.ListText = "@0";
     //lib.Actions.Add(d);
     //d.Arguments[0].DefaultValue = "\"Times New Roman\",10,0,0,0,0,0";
     return lib;
 }
示例#36
0
        /// <summary>
        /// Loads a file consisting of 256x256 doubles and imports it as an array into the map.
        /// </summary>
        /// <remarks>TODO: Move this to libTerrain itself</remarks>
        /// <param name="filename">The filename of the double array to import</param>
        public void loadFromFileF64(string filename)
        {
            System.IO.FileInfo file = new System.IO.FileInfo(filename);
            System.IO.FileStream s = file.Open(System.IO.FileMode.Open, System.IO.FileAccess.Read);
            System.IO.BinaryReader bs = new System.IO.BinaryReader(s);
            int x, y;
            for (x = 0; x < w; x++)
            {
                for (y = 0; y < h; y++)
                {
                    heightmap.map[x, y] = bs.ReadDouble();
                }
            }

            bs.Close();
            s.Close();

            tainted++;
        }
示例#37
0
        /// <summary>
        /// read back, read  coord-transform-chain  back from specific stream
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public static ICoordTransformer Read(System.IO.BinaryReader reader)
        {
            CoordTransformerKind txKind = (CoordTransformerKind)reader.ReadUInt16();

            switch (txKind)
            {
            default:
                throw new System.NotSupportedException();

            case CoordTransformerKind.Affine3x2:
            {
                double sx = reader.ReadDouble(); double shy = reader.ReadDouble();
                double shx = reader.ReadDouble(); double sy = reader.ReadDouble();
                double tx = reader.ReadDouble(); double ty = reader.ReadDouble();
                return(new Affine(sx, shy, shx, sy, tx, ty));
            }

            case CoordTransformerKind.Bilinear:
            {
                return(new Bilinear(
                           reader.ReadDouble(), reader.ReadDouble(),
                           reader.ReadDouble(), reader.ReadDouble(),
                           reader.ReadDouble(), reader.ReadDouble(),
                           reader.ReadDouble(), reader.ReadDouble()
                           ));
            }

            case CoordTransformerKind.Perspective:
            {
                return(new Perspective(
                           reader.ReadDouble(), reader.ReadDouble(), reader.ReadDouble(),
                           reader.ReadDouble(), reader.ReadDouble(), reader.ReadDouble(),
                           reader.ReadDouble(), reader.ReadDouble(), reader.ReadDouble()
                           ));
            }

            case CoordTransformerKind.TransformChain:
            {
                return(new CoordTransformationChain(
                           Read(reader), //left
                           Read(reader)  // right
                           ));
            }
            }
        }
示例#38
0
		/// <summary>Loads the black-box logs from the previous simulation run</summary>
		internal static void LoadLogs()
		{
			string BlackBoxFile = OpenBveApi.Path.CombineFile(Program.FileSystem.SettingsFolder, "logs.bin");
			try
			{
				using (System.IO.FileStream Stream = new System.IO.FileStream(BlackBoxFile, System.IO.FileMode.Open, System.IO.FileAccess.Read))
				{
					using (System.IO.BinaryReader Reader = new System.IO.BinaryReader(Stream, System.Text.Encoding.UTF8))
					{
						byte[] Identifier = new byte[] { 111, 112, 101, 110, 66, 86, 69, 95, 76, 79, 71, 83 };
						const short Version = 1;
						byte[] Data = Reader.ReadBytes(Identifier.Length);
						for (int i = 0; i < Identifier.Length; i++)
						{
							if (Identifier[i] != Data[i]) throw new System.IO.InvalidDataException();
						}
						short Number = Reader.ReadInt16();
						if (Version != Number) throw new System.IO.InvalidDataException();
						Game.LogRouteName = Reader.ReadString();
						Game.LogTrainName = Reader.ReadString();
						Game.LogDateTime = DateTime.FromBinary(Reader.ReadInt64());
						Interface.CurrentOptions.GameMode = (Interface.GameMode)Reader.ReadInt16();
						Game.BlackBoxEntryCount = Reader.ReadInt32();
						Game.BlackBoxEntries = new Game.BlackBoxEntry[Game.BlackBoxEntryCount];
						for (int i = 0; i < Game.BlackBoxEntryCount; i++)
						{
							Game.BlackBoxEntries[i].Time = Reader.ReadDouble();
							Game.BlackBoxEntries[i].Position = Reader.ReadDouble();
							Game.BlackBoxEntries[i].Speed = Reader.ReadSingle();
							Game.BlackBoxEntries[i].Acceleration = Reader.ReadSingle();
							Game.BlackBoxEntries[i].ReverserDriver = Reader.ReadInt16();
							Game.BlackBoxEntries[i].ReverserSafety = Reader.ReadInt16();
							Game.BlackBoxEntries[i].PowerDriver = (Game.BlackBoxPower)Reader.ReadInt16();
							Game.BlackBoxEntries[i].PowerSafety = (Game.BlackBoxPower)Reader.ReadInt16();
							Game.BlackBoxEntries[i].BrakeDriver = (Game.BlackBoxBrake)Reader.ReadInt16();
							Game.BlackBoxEntries[i].BrakeSafety = (Game.BlackBoxBrake)Reader.ReadInt16();
							Game.BlackBoxEntries[i].EventToken = (Game.BlackBoxEventToken)Reader.ReadInt16();
						}
						Game.ScoreLogCount = Reader.ReadInt32();
						Game.ScoreLogs = new Game.ScoreLog[Game.ScoreLogCount];
						Game.CurrentScore.Value = 0;
						for (int i = 0; i < Game.ScoreLogCount; i++)
						{
							Game.ScoreLogs[i].Time = Reader.ReadDouble();
							Game.ScoreLogs[i].Position = Reader.ReadDouble();
							Game.ScoreLogs[i].Value = Reader.ReadInt32();
							Game.ScoreLogs[i].TextToken = (Game.ScoreTextToken)Reader.ReadInt16();
							Game.CurrentScore.Value += Game.ScoreLogs[i].Value;
						}
						Game.CurrentScore.Maximum = Reader.ReadInt32();
						Identifier = new byte[] { 95, 102, 105, 108, 101, 69, 78, 68 };
						Data = Reader.ReadBytes(Identifier.Length);
						for (int i = 0; i < Identifier.Length; i++)
						{
							if (Identifier[i] != Data[i]) throw new System.IO.InvalidDataException();
						}
						Reader.Close();
					} Stream.Close();
				}
			}
			catch
			{
				Game.LogRouteName = "";
				Game.LogTrainName = "";
				Game.LogDateTime = DateTime.Now;
				Game.BlackBoxEntries = new Game.BlackBoxEntry[256];
				Game.BlackBoxEntryCount = 0;
				Game.ScoreLogs = new Game.ScoreLog[64];
				Game.ScoreLogCount = 0;
			}
		}
示例#39
0
 private void btnLoadOverlay_Click(object sender, EventArgs e)
 {
     dlgLoadOverlay.InitialDirectory = m_DefaultDirectory;
     if (dlgLoadOverlay.ShowDialog() == DialogResult.OK)
     {
         System.IO.BinaryReader r  = null;
         System.IO.FileStream   fr = null;
         try
         {
             if (dlgLoadOverlay.FileName.ToLower().EndsWith(".x3l"))
             {
                 m_OverlayScene = (GDI3D.Scene)xmlscene.Deserialize(new System.IO.StringReader(System.IO.File.ReadAllText(dlgLoadOverlay.FileName)));
             }
             else if (dlgLoadOverlay.FileName.ToLower().EndsWith(".rwd") || rx_RWD.Match(dlgLoadOverlay.FileName.ToLower()).Success)
             {
                 fr = new System.IO.FileStream(dlgLoadOverlay.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);
                 SySal.Scanning.Plate.IO.OPERA.RawData.Fragment frag = new Scanning.Plate.IO.OPERA.RawData.Fragment(fr);
                 fr.Close();
                 fr = null;
                 GDI3D.Scene scene = new GDI3D.Scene();
                 int         total = 0;
                 int         v;
                 for (v = 0; v < frag.Length; v++)
                 {
                     total += frag[v].Top.Length + frag[v].Bottom.Length;
                 }
                 scene.Lines           = new GDI3D.Line[2 * total];
                 scene.Points          = new GDI3D.Point[0];
                 scene.OwnerSignatures = new string[total];
                 total = 0;
                 for (v = 0; v < frag.Length; v++)
                 {
                     int i;
                     for (i = 0; i < frag[v].Top.Length; i++)
                     {
                         SySal.Tracking.MIPEmulsionTrackInfo info = frag[v].Top[i].Info;
                         info.Intercept = frag[v].Top.MapPoint(info.Intercept);
                         info.Slope     = frag[v].Top.MapVector(info.Slope);
                         scene.OwnerSignatures[total / 2] = v + "T" + i + ": " + info.Count + " " + info.AreaSum + " " + info.Intercept.X.ToString("F1") + " " + info.Intercept.Y.ToString("F1") + " " + info.Slope.X.ToString("F4") + " " + info.Slope.Y.ToString("F4") + " " + info.Sigma.ToString("F3");
                         scene.Lines[total++]             = new GDI3D.Line(info.Intercept.X, info.Intercept.Y, 0, info.Intercept.X + EmulThickness * info.Slope.X, info.Intercept.Y + EmulThickness * info.Slope.Y, EmulThickness, i, 224, 0, 0);
                         scene.Lines[total++]             = new GDI3D.Line(info.Intercept.X, info.Intercept.Y, 0, info.Intercept.X - BaseThickness * info.Slope.X, info.Intercept.Y - BaseThickness * info.Slope.Y, -BaseThickness, i, 0, 224, 0);
                     }
                     for (i = 0; i < frag[v].Bottom.Length; i++)
                     {
                         SySal.Tracking.MIPEmulsionTrackInfo info = frag[v].Bottom[i].Info;
                         info.Intercept = frag[v].Bottom.MapPoint(info.Intercept);
                         info.Slope     = frag[v].Bottom.MapVector(info.Slope);
                         scene.OwnerSignatures[total / 2] = v + "B" + i + ": " + info.Count + " " + info.AreaSum + " " + info.Intercept.X.ToString("F1") + " " + info.Intercept.Y.ToString("F1") + " " + info.Slope.X.ToString("F4") + " " + info.Slope.Y.ToString("F4") + " " + info.Sigma.ToString("F3");
                         scene.Lines[total++]             = new GDI3D.Line(info.Intercept.X, info.Intercept.Y, -BaseThickness, info.Intercept.X - EmulThickness * info.Slope.X, info.Intercept.Y - EmulThickness * info.Slope.Y, -BaseThickness - EmulThickness, i, 0, 0, 224);
                         scene.Lines[total++]             = new GDI3D.Line(info.Intercept.X, info.Intercept.Y, -BaseThickness, info.Intercept.X + BaseThickness * info.Slope.X, info.Intercept.Y + BaseThickness * info.Slope.Y, 0, i, 0, 224, 0);
                     }
                 }
                 m_OverlayScene = scene;
             }
             else if (dlgLoadOverlay.FileName.ToLower().EndsWith(".reader"))
             {
                 r = new System.IO.BinaryReader(new System.IO.FileStream(dlgLoadOverlay.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read));
                 int         total = r.ReadInt32();
                 GDI3D.Scene scene = new GDI3D.Scene();
                 scene.Lines           = new GDI3D.Line[2 * total];
                 scene.Points          = new GDI3D.Point[0];
                 scene.OwnerSignatures = new string[total];
                 r.ReadDouble(); r.ReadDouble(); r.ReadDouble(); r.ReadDouble();
                 int i;
                 for (i = 0; i < total; i++)
                 {
                     Int64  zone    = r.ReadInt64();
                     short  side    = r.ReadInt16();
                     int    id      = r.ReadInt32();
                     short  count   = r.ReadInt16();
                     int    areasum = r.ReadInt32();
                     double x       = r.ReadDouble();
                     double y       = r.ReadDouble();
                     double z       = (side == 1) ? 0 : -BaseThickness;
                     double sx      = r.ReadDouble();
                     double sy      = r.ReadDouble();
                     double sigma   = r.ReadDouble();
                     int    view    = r.ReadInt32();
                     double vx      = r.ReadDouble();
                     double vy      = r.ReadDouble();
                     scene.OwnerSignatures[i] = zone + " " + side + " " + id + ": " + count + " " + areasum + " " + x.ToString("F1") + " " + y.ToString("F1") + " " + sx.ToString("F4") + " " + sy.ToString("F4") + " " + sigma.ToString("F3") + " in " + view + ": " + vx.ToString("F1") + " " + vy.ToString("F1");
                     double dz     = ((side == 1) ? EmulThickness : -EmulThickness);
                     double dzbase = ((side == 1) ? -BaseThickness : BaseThickness);
                     scene.Lines[2 * i]     = new GDI3D.Line(x, y, z, x + dz * sx, y + dz * sy, z + dz, i, (side == 1) ? 255 : 0, 0, (side == 2) ? 255 : 0);
                     scene.Lines[2 * i + 1] = new GDI3D.Line(x, y, z, x + dzbase * sx, y + dzbase * sy, z + dzbase, i, (side == 1) ? 255 : 0, 192, (side == 2) ? 255 : 0);
                 }
                 r.Close();
                 r = null;
                 m_OverlayScene = scene;
             }
             else if (dlgLoadOverlay.FileName.ToLower().EndsWith(".tlg"))
             {
                 SySal.DataStreams.OPERALinkedZone lzd = new DataStreams.OPERALinkedZone(dlgLoadOverlay.FileName);
                 int         total = lzd.Length;
                 GDI3D.Scene scene = new GDI3D.Scene();
                 scene.Lines           = new GDI3D.Line[3 * total];
                 scene.Points          = new GDI3D.Point[0];
                 scene.OwnerSignatures = new string[total];
                 int i;
                 for (i = 0; i < total; i++)
                 {
                     SySal.Tracking.MIPEmulsionTrackInfo info = lzd[i].Info;
                     scene.OwnerSignatures[i] = i + ": " + info.Count + " " + info.AreaSum + " " + info.Intercept.X.ToString("F1") + " " + info.Intercept.Y.ToString("F1") + " " + info.Slope.X.ToString("F4") + " " + info.Slope.Y.ToString("F4") + " " + info.Sigma.ToString("F3");
                     scene.Lines[3 * i]       = new GDI3D.Line(info.Intercept.X, info.Intercept.Y, 0, info.Intercept.X + EmulThickness * info.Slope.X, info.Intercept.Y + EmulThickness * info.Slope.Y, EmulThickness, i, 224, 0, 0);
                     scene.Lines[3 * i + 1]   = new GDI3D.Line(info.Intercept.X, info.Intercept.Y, 0, info.Intercept.X - BaseThickness * info.Slope.X, info.Intercept.Y - BaseThickness * info.Slope.Y, -BaseThickness, i, 0, 224, 0);
                     scene.Lines[3 * i + 2]   = new GDI3D.Line(info.Intercept.X - BaseThickness * info.Slope.X, info.Intercept.Y - BaseThickness * info.Slope.Y, -BaseThickness, info.Intercept.X - (BaseThickness + EmulThickness) * info.Slope.X, info.Intercept.Y - (BaseThickness + EmulThickness) * info.Slope.Y, -BaseThickness - EmulThickness, i, 0, 0, 224);
                 }
                 lzd.Dispose();
                 m_OverlayScene = scene;
             }
             else
             {
                 MessageBox.Show("Unsupported format", "File error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             }
         }
         catch (Exception x)
         {
             MessageBox.Show(x.ToString(), "File error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         finally
         {
             if (r != null)
             {
                 r.Close();
                 r = null;
             }
             if (fr != null)
             {
                 fr.Close();
                 fr = null;
             }
             m_OverlayBmp = null;
         }
     }
 }