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 C3DFrame ReadNextIntFrame(C3DParameterCache cache) { C3DPoint3DData[] pointDatas = new C3DPoint3DData[cache.PointCount]; C3DAnalogSamples[] analogSamples = new C3DAnalogSamples[cache.AnalogChannelCount]; for (Int32 i = 0; i < pointDatas.Length; i++) { pointDatas[i] = new C3DPoint3DData(this._reader.ReadInt16(), this._reader.ReadInt16(), this._reader.ReadInt16(), this._reader.ReadInt16(), cache.ScaleFactor); } for (Int32 i = 0; i < analogSamples.Length; i++) { analogSamples[i] = new C3DAnalogSamples(cache.AnalogSamplesPerFrame); } for (Int32 j = 0; j < cache.AnalogSamplesPerFrame; j++) { for (Int32 i = 0; i < cache.AnalogChannelCount; i++) { Int16 data = this._reader.ReadInt16(); analogSamples[i][j] = (data - ((cache.AnalogZeroOffset != null && cache.AnalogZeroOffset.Length > i) ? cache.AnalogZeroOffset[i] : (Int16)0)) * cache.AnalogGeneralScale * (cache.AnalogChannelScale != null && cache.AnalogChannelScale.Length > i ? cache.AnalogChannelScale[i] : 1.0F); } } return(new C3DFrame(pointDatas, analogSamples)); }
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 void WriteC3DFile(C3DFile file) { this._dataStartOffset = 0; this._newDataStartBlockIndex = 0; this._writer.Write(new Byte[C3DConstants.FILE_SECTION_SIZE]); this.WriteParameters(file.Header.FirstParameterSectionID, file.Parameters); C3DParameterCache paramCache = C3DParameterCache.CreateCache(file); this.WriteFrameCollection(paramCache, file.AllFrames); this.UpdateHeaderAndParameters(file); this.WriteHeader(file.Header); }
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); } }
private void WriteFrameCollection(C3DParameterCache cache, C3DFrameCollection frameCollection) { Int32 startPosition = (this._newDataStartBlockIndex - 1) * C3DConstants.FILE_SECTION_SIZE; this._writer.Seek(startPosition, SeekOrigin.Begin); for (Int32 i = 0; i < frameCollection.Count; i++) { if (cache.ScaleFactor < 0) { this.WriteFloatFrame(cache, frameCollection[i]); } else { this.WriteIntFrame(cache, frameCollection[i]); } } Int16 finalIndex = (Int16)((this._writer.BaseStream.Position + C3DConstants.FILE_SECTION_SIZE) / C3DConstants.FILE_SECTION_SIZE + 1); this._writer.Write(new Byte[(finalIndex - 1) * C3DConstants.FILE_SECTION_SIZE - this._writer.BaseStream.Position]); }
public C3DFrame ReadNextFrame(C3DParameterDictionary dictionary) { return(this.ReadNextFrame(C3DParameterCache.CreateCache(dictionary))); }