本文整理汇总了C#中System.IO.BinaryReader.ReadDouble方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.BinaryReader.ReadDouble方法的具体用法?C# System.IO.BinaryReader.ReadDouble怎么用?C# System.IO.BinaryReader.ReadDouble使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.BinaryReader
的用法示例。
在下文中一共展示了System.IO.BinaryReader.ReadDouble方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadLogs
/// <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;
}
}
示例2: loadFromFileF64
/// <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++;
}
示例3: FromFile
/// <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;
}
示例4: Read_Pac1
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;
}
}
示例5: Read_pachm
/// <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.
//.........这里部分代码省略.........
示例6: Load
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;
}
示例7: ToArrays
/// <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
{
//.........这里部分代码省略.........
示例8: ReadObjectDataFromTable
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);
//.........这里部分代码省略.........
示例9: LoadData
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;
//.........这里部分代码省略.........
示例10: ScanNumber
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;
}
示例11: GetDataType
/// <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: Deserialize
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);
}
}
}