private C3DFile(Stream stream) { C3DReader reader = null; try { reader = new C3DReader(stream); this._processorType = reader.CreateProcessorType; this._header = reader.ReadHeader(); this._parameterDictionary = reader.ReadParameters(); this._frameCollection = new C3DFrameCollection(); try { C3DParameterCache paramCache = C3DParameterCache.CreateCache(this); C3DFrame frame = null; while ((frame = reader.ReadNextFrame(paramCache)) != null) { this._frameCollection.Add(frame); } } catch { } } finally { if (reader != null) { reader.Close(); } } }
private void WriteIntFrame(C3DParameterCache cache, C3DFrame frame) { if (frame.Point3Ds != null) { for (Int32 i = 0; i < frame.Point3Ds.Length; i++) { this._writer.Write((Int16)Math.Round(frame.Point3Ds[i].X / cache.ScaleFactor, MidpointRounding.AwayFromZero)); this._writer.Write((Int16)Math.Round(frame.Point3Ds[i].Y / cache.ScaleFactor, MidpointRounding.AwayFromZero)); this._writer.Write((Int16)Math.Round(frame.Point3Ds[i].Z / cache.ScaleFactor, MidpointRounding.AwayFromZero)); this._writer.Write(frame.Point3Ds[i].GetIntLastPart(cache.ScaleFactor)); } } if (frame.AnalogSamples != null) { for (Int32 j = 0; j < cache.AnalogSamplesPerFrame; j++) { for (Int32 i = 0; i < cache.AnalogChannelCount; i++) { Single data = frame.AnalogSamples[i][j] / cache.AnalogGeneralScale / (cache.AnalogChannelScale != null && cache.AnalogChannelScale.Length > 0 ? cache.AnalogChannelScale[i] : 1.0F) + ((cache.AnalogZeroOffset != null && cache.AnalogZeroOffset.Length > 0) ? cache.AnalogZeroOffset[i] : (Int16)0); this._writer.Write((Int16)Math.Round(data, MidpointRounding.AwayFromZero)); } } } }
public C3DFrame ReadNextFrame(C3DParameterCache cache) { if (cache.FirstDataBlockPosition < 0) { return(null); } if (this._currentFrameIndex >= cache.FrameCount) { this._currentFrameIndex = -1; return(null); } if (this._currentFrameIndex < 0) { this._reader.BaseStream.Seek(cache.FirstDataBlockPosition, SeekOrigin.Begin); this._currentFrameIndex = 0; } if (this._reader.BaseStream.Position >= this._reader.BaseStream.Length) { this._currentFrameIndex = -1; return(null); } C3DFrame data = null; try { data = cache.ScaleFactor < 0 ? this.ReadNextFloatFrame(cache) : this.ReadNextIntFrame(cache); this._currentFrameIndex++; return(data); } catch (Exception ex) { throw new C3DException("The frame data has broken.", ex); } }