public BufferInstances GetInstances() { BufferInstances instances = new BufferInstances(); foreach (string fileName in base.m_PluginAssemblies) { Assembly filterAssembly = Assembly.LoadFrom(fileName); foreach (Type assemblyType in filterAssembly.GetTypes()) { Type typeInterface = assemblyType.GetInterface("IBuffer", true); if (assemblyType.IsPublic && !assemblyType.IsAbstract && typeInterface != null) { BufferInstance newBuffer = new BufferInstance(); newBuffer.Instance = Activator.CreateInstance(assemblyType) as IBuffer; if (newBuffer.Instance != null) { instances.Add(newBuffer); } newBuffer = null; } typeInterface = null; } filterAssembly = null; } return(instances); }
/// <summary> /// Initializes a new instance of the <see cref="PointCloudBinarySourceCompositeEnumerator"/> class. /// This version does not use a process, so that it can be managed by a composite. /// </summary> /// <param name="sources">The sources.</param> /// <param name="buffer">The buffer.</param> public PointCloudBinarySourceCompositeEnumerator(IEnumerable <IPointCloudBinarySourceEnumerable> sources, BufferInstance buffer) { m_sources = sources.ToArray(); m_process = null; m_buffer = buffer; m_points = m_sources.Sum(s => s.Count); Reset(); }
public PointCloudBinarySourceCompositeEnumerator(IEnumerable <IPointCloudBinarySourceEnumerable> sources, ProgressManagerProcess process) { m_sources = sources.ToArray(); m_process = process; m_buffer = m_process.AcquireBuffer(true); m_points = m_sources.Sum(s => s.Count); Reset(); }
public PointCloudTileSourceEnumeratorChunk(PointCloudTile tile, BufferInstance buffer) { m_tile = tile; m_buffer = buffer; m_pointSizeBytes = m_tile.TileSet.TileSource.PointSizeBytes; m_dataPtr = buffer.DataPtr; m_dataEndPtr = m_dataPtr + m_tile.StorageSize; }
public PointCloudTileSourceEnumerator(PointCloudTileSource source, ProgressManagerProcess process) { m_source = source; m_buffer = process.AcquireBuffer(source.MaxTileBufferSize, true); m_process = process; m_stream = StreamManager.OpenReadStream(source.FilePath, source.PointDataOffset); Reset(); }
public PointBufferWrapperChunk(int index, BufferInstance buffer, int byteIndex, int byteLength, short pointSizeBytes, float progress) { m_buffer = buffer; m_index = index; m_pointSizeBytes = pointSizeBytes; m_bytesRead = byteLength; m_pointsRead = m_bytesRead / m_pointSizeBytes; m_dataPtr = buffer.DataPtr + byteIndex; m_dataEndPtr = m_dataPtr + m_bytesRead; m_progress = progress; }
public PointBufferWrapperChunk(PointBufferWrapperChunk chunk, int pointCount) { m_buffer = chunk.m_buffer; m_index = chunk.m_index; m_pointSizeBytes = chunk.m_pointSizeBytes; m_pointsRead = pointCount; m_bytesRead = m_pointsRead * m_pointSizeBytes; m_dataPtr = chunk.m_dataPtr; m_dataEndPtr = m_dataPtr + m_bytesRead; m_progress = chunk.m_progress; }
public PointBufferWrapper(BufferInstance buffer, short pointSizeBytes, int pointCount) { m_buffer = buffer; m_pointCount = pointCount; m_pointSizeBytes = pointSizeBytes; m_length = m_pointCount * m_pointSizeBytes; m_pointDataPtr = m_buffer.DataPtr; m_pointDataEndPtr = m_pointDataPtr + m_length; m_bufferIndex = 0; }
/// <summary> /// Initializes a new instance of the <see cref="PointBufferWrapper"/> class, /// for wrapping a binary source segment buffer. /// </summary> /// <param name="buffer">The buffer.</param> /// <param name="source">The source.</param> /// <param name="pointCount">The point count.</param> public PointBufferWrapper(BufferInstance buffer, IPointCloudBinarySource source, int pointCount) { m_buffer = buffer; m_pointCount = pointCount; m_pointSizeBytes = source.PointSizeBytes; m_length = m_pointCount * m_pointSizeBytes; m_pointDataPtr = m_buffer.DataPtr; m_pointDataEndPtr = m_pointDataPtr + m_length; m_bufferIndex = 0; }
public PointCloudBinarySourceEnumeratorChunk(int index, BufferInstance buffer, int bytesRead, short pointSizeBytes, float progress) { m_buffer = buffer; m_index = index; m_pointSizeBytes = pointSizeBytes; m_bytesRead = bytesRead; m_pointsRead = m_bytesRead / m_pointSizeBytes; m_dataPtr = buffer.DataPtr; m_dataEndPtr = m_dataPtr + m_bytesRead; m_progress = progress; }
public void Clear() { this._startIndex = 0; this._index = 0; this._length = 0U; if (null == this._bufferEntry) { return; } this._bufferPool.Free(this._bufferEntry); this._bufferEntry = (BufferInstance)null; }
public void Add(TsPacket packet) { if (null == this._handler) { return; } if (null != packet) { if (packet.IsStart) { if ((int)this._length == 0 && this._index > this._startIndex) { this.Flush(); } this._index = this._startIndex; this.ParseHeader(packet); } if (null != this._bufferEntry) { if (this._index + packet.BufferLength > this._bufferEntry.Buffer.Length) { int minSize = Math.Max(this._index - this._startIndex + packet.BufferLength, 512); if (this._index < this._bufferEntry.Buffer.Length / 2) { minSize *= 2; } BufferInstance bufferInstance = this._bufferPool.Allocate(minSize); Array.Copy((Array)this._bufferEntry.Buffer, this._startIndex, (Array)bufferInstance.Buffer, 0, this._index - this._startIndex); this._bufferPool.Free(this._bufferEntry); this._bufferEntry = bufferInstance; this._index -= this._startIndex; this._startIndex = 0; } packet.CopyTo(this._bufferEntry.Buffer, this._index); this._index += packet.BufferLength; } } if (packet == null || this._length > 0U && (long)(this._index - this._startIndex) == (long)this._length) { this.Flush(); } if (packet == null && null != this._bufferEntry) { this._bufferPool.Free(this._bufferEntry); this._bufferEntry = (BufferInstance)null; } if (packet != null || null == this._handler) { return; } this._handler((TsPesPacket)null); }
public PointCloudBinarySourceEnumerator(IPointCloudBinarySourceSequentialEnumerable source, ProgressManagerProcess process) { m_source = source; m_stream = m_source.GetStreamReader(); m_buffer = process.AcquireBuffer(true); m_process = process; m_endPosition = m_source.PointDataOffset + m_source.Count * m_source.PointSizeBytes; m_usableBytesPerBuffer = (m_buffer.Length / m_source.PointSizeBytes) * m_source.PointSizeBytes; Reset(); }
/// <summary> /// Initializes a new instance of the <see cref="PointCloudBinarySourceEnumerator"/> class. /// This version does not use a process, so that it can be managed by a composite. /// </summary> /// <param name="source">The source.</param> /// <param name="buffer">The buffer.</param> public PointCloudBinarySourceEnumerator(IPointCloudBinarySourceSequentialEnumerable source, BufferInstance buffer) { m_source = source; m_stream = m_source.GetStreamReader(); m_buffer = buffer; m_process = null; m_endPosition = m_source.PointDataOffset + m_source.Count * m_source.PointSizeBytes; m_usableBytesPerBuffer = (m_buffer.Length / m_source.PointSizeBytes) * m_source.PointSizeBytes; Reset(); }
private void ParseHeader(TsPacket packet) { if (packet.BufferLength < 6) { return; } int bufferOffset = packet.BufferOffset; int index1 = bufferOffset; byte[] buffer = packet.Buffer; uint num1 = (uint)((int)buffer[index1] << 16 | (int)buffer[index1 + 1] << 8) | (uint)buffer[index1 + 2]; int num2 = index1 + 3; if (1 != (int)num1) { return; } byte[] numArray = buffer; int index2 = num2; int num3 = 1; int index3 = index2 + num3; this._streamId = numArray[index2]; uint num4 = (uint)buffer[index3] << 8 | (uint)buffer[index3 + 1]; int num5 = index3 + 2; int minSize = 4096; if (num4 > 0U) { this._length = num4 + (uint)(num5 - bufferOffset); minSize = (int)this._length; } else { this._length = 0U; } if (this._bufferEntry != null && this._bufferEntry.Buffer.Length - this._startIndex < minSize) { this._bufferPool.Free(this._bufferEntry); this._bufferEntry = (BufferInstance)null; } if (null == this._bufferEntry) { this._bufferEntry = this._bufferPool.Allocate(minSize); this._startIndex = 0; } this._index = this._startIndex; }
public PointCloudTileSource(LASFile file, PointCloudTileSet tileSet, Statistics zStats) : base(file, tileSet.PointCount, tileSet.Extent, file.Header.Quantization, file.Header.OffsetToPointData, (short)file.Header.PointDataRecordLength) { m_file = file; m_id = IdentityManager.AcquireIdentity(GetType().Name); m_tileSet = tileSet; m_tileSet.TileSource = this; m_statisticsZ = zStats; m_statisticsQuantizedZ = zStats.ConvertToQuantized(Quantization); m_lowResBuffer = BufferManager.AcquireBuffer(m_id, tileSet.LowResCount * PointSizeBytes); m_file.UpdateEVLR(new LASRecordIdentifier("Jacere", 0), TileSet); m_file.UpdateEVLR(new LASRecordIdentifier("Jacere", 1), StatisticsZ); }
public unsafe void LoadTileGrid(PointCloudTile tile, BufferInstance inputBuffer, Grid <float> grid, Grid <int> quantizedGrid) { Open(); var quantizedExtent = tile.QuantizedExtent; double cellSizeX = (double)quantizedExtent.RangeX / grid.SizeX; double cellSizeY = (double)quantizedExtent.RangeY / grid.SizeY; #warning Why did I do FillVal it this way? //grid.FillVal = -1.0f; grid.Reset(); quantizedGrid.Reset(); byte *inputBufferPtr = inputBuffer.DataPtr; int bytesRead = tile.ReadTile(m_inputStream, inputBuffer.Data); byte *pb = inputBufferPtr; byte *pbEnd = inputBufferPtr + tile.StorageSize; while (pb < pbEnd) { var p = (SQuantizedPoint3D *)pb; pb += PointSizeBytes; var pixelX = (int)(((*p).X - quantizedExtent.MinX) / cellSizeX); var pixelY = (int)(((*p).Y - quantizedExtent.MinY) / cellSizeY); // max val for now, apparently if ((*p).Z > quantizedGrid.Data[pixelY, pixelX]) { quantizedGrid.Data[pixelY, pixelX] = (*p).Z; } } quantizedGrid.CorrectMaxOverflow(); quantizedGrid.CopyToUnquantized(grid, Quantization, Extent); }
public void Free(BufferInstance bufferInstance) { if (!bufferInstance.Dereference()) { return; } for (int index = 0; index < bufferInstance.Buffer.Length; ++index) { bufferInstance.Buffer[index] = byte.MaxValue; } Interlocked.Increment(ref this._freeCount); Interlocked.Add(ref this._actualFreeBytes, bufferInstance.Buffer.Length); BufferPool.BufferSubPool pool = this.FindPool(bufferInstance.Buffer.Length); if (null == pool) { return; } if (pool.Size != bufferInstance.Buffer.Length) { throw new ArgumentException("Invalid buffer size", "bufferInstance"); } pool.Free((PoolBufferInstance)bufferInstance); }
public PointCloudTileSource TilePointFileIndex(LASFile tiledFile, BufferInstance segmentBuffer, ProgressManager progressManager) { var stopwatch = new Stopwatch(); stopwatch.Start(); var analysis = AnalyzePointFile(segmentBuffer.Length, progressManager); var quantizedExtent = m_source.QuantizedExtent; var tileCounts = analysis.Density.GetTileCountsForInitialization(); var fileSize = tiledFile.PointDataOffset + (m_source.PointSizeBytes * m_source.Count); AttemptFastAllocate(tiledFile.FilePath, fileSize); var lowResPointCountMax = PROPERTY_MAX_LOWRES_POINTS.Value; var lowResBuffer = BufferManager.AcquireBuffer(m_id, lowResPointCountMax * m_source.PointSizeBytes); var lowResWrapper = new PointBufferWrapper(lowResBuffer, m_source.PointSizeBytes, lowResPointCountMax); var validTiles = analysis.GridIndex.Sum(r => r.GridRange.ValidCells); var lowResPointsPerTile = lowResPointCountMax / validTiles; var lowResTileSize = (ushort)Math.Sqrt(lowResPointsPerTile); var lowResGrid = Grid <int> .Create(lowResTileSize, lowResTileSize, true, -1); var lowResCounts = tileCounts.Copy <int>(); using (var outputStream = StreamManager.OpenWriteStream(tiledFile.FilePath, fileSize, tiledFile.PointDataOffset)) { var i = 0; foreach (var segment in analysis.GridIndex) { progressManager.Log("~ Processing Index Segment {0}/{1}", ++i, analysis.GridIndex.Count); var sparseSegment = m_source.CreateSparseSegment(segment); var sparseSegmentWrapper = new PointBufferWrapper(segmentBuffer, sparseSegment); var tileRegionFilter = new TileRegionFilter(tileCounts, quantizedExtent, segment.GridRange); // this call will fill the buffer with points, add the counts, and sort QuantTilePointsIndexed(sparseSegment, sparseSegmentWrapper, tileRegionFilter, tileCounts, lowResWrapper, lowResGrid, lowResCounts, progressManager); var segmentFilteredPointCount = tileRegionFilter.GetCellOrdering().Sum(t => tileCounts.Data[t.Row, t.Col]); var segmentFilteredBytes = segmentFilteredPointCount * sparseSegmentWrapper.PointSizeBytes; // write out the buffer using (var process = progressManager.StartProcess("WriteIndexSegment")) { var segmentBufferIndex = 0; foreach (var tile in segment.GridRange.GetCellOrdering()) { var tileCount = tileCounts.Data[tile.Row, tile.Col]; if (tileCount > 0) { var tileSize = (tileCount - lowResCounts.Data[tile.Row, tile.Col]) * sparseSegmentWrapper.PointSizeBytes; outputStream.Write(sparseSegmentWrapper.Data, segmentBufferIndex, tileSize); segmentBufferIndex += tileSize; if (!process.Update((float)segmentBufferIndex / segmentFilteredBytes)) { break; } } } } if (progressManager.IsCanceled()) { break; } } // write low-res var lowResActualPointCount = lowResCounts.Data.Cast <int>().Sum(); outputStream.Write(lowResWrapper.Data, 0, lowResActualPointCount * lowResWrapper.PointSizeBytes); } var actualDensity = new PointCloudTileDensity(tileCounts, m_source.Quantization); var tileSet = new PointCloudTileSet(m_source, actualDensity, tileCounts, lowResCounts); var tileSource = new PointCloudTileSource(tiledFile, tileSet, analysis.Statistics); if (!progressManager.IsCanceled()) { tileSource.IsDirty = false; } tileSource.WriteHeader(); return(tileSource); }
public unsafe PointCloudBinarySource ConvertTextToBinary(string binaryPath, ProgressManager progressManager) { short pointSizeBytes = 3 * sizeof(double); double minX = 0, minY = 0, minZ = 0; double maxX = 0, maxY = 0, maxZ = 0; int pointCount = 0; using (var process = progressManager.StartProcess("ConvertTextToBinary")) { BufferInstance inputBuffer = process.AcquireBuffer(true); BufferInstance outputBuffer = process.AcquireBuffer(true); int pointsPerBuffer = outputBuffer.Length / pointSizeBytes; int usableBytesPerBuffer = pointsPerBuffer * pointSizeBytes; byte *inputBufferPtr = inputBuffer.DataPtr; byte *outputBufferPtr = outputBuffer.DataPtr; int bufferIndex = 0; int skipped = 0; using (var inputStream = StreamManager.OpenReadStream(FilePath)) { long inputLength = inputStream.Length; long estimatedOutputLength = inputLength; using (var outputStream = StreamManager.OpenWriteStream(binaryPath, estimatedOutputLength, 0, true)) { int bytesRead; int readStart = 0; while ((bytesRead = inputStream.Read(inputBuffer.Data, readStart, inputBuffer.Length - readStart)) > 0) { bytesRead += readStart; readStart = 0; int i = 0; while (i < bytesRead) { // identify line start while (i < bytesRead && (inputBufferPtr[i] == '\r' || inputBufferPtr[i] == '\n')) { ++i; } int lineStart = i; // identify line end while (i < bytesRead && inputBufferPtr[i] != '\r' && inputBufferPtr[i] != '\n') { ++i; } // handle buffer overlap if (i == bytesRead) { Array.Copy(inputBuffer.Data, lineStart, inputBuffer.Data, 0, i - lineStart); readStart = i - lineStart; break; } // this may get overwritten if this is not a valid parse double *p = (double *)(outputBufferPtr + bufferIndex); if (!ParseXYZFromLine(inputBufferPtr, lineStart, i, p)) { ++skipped; continue; } if (pointCount == 0) { minX = maxX = p[0]; minY = maxY = p[1]; minZ = maxZ = p[2]; } else { if (p[0] < minX) { minX = p[0]; } else if (p[0] > maxX) { maxX = p[0]; } if (p[1] < minY) { minY = p[1]; } else if (p[1] > maxY) { maxY = p[1]; } if (p[2] < minZ) { minZ = p[2]; } else if (p[2] > maxZ) { maxZ = p[2]; } } bufferIndex += pointSizeBytes; ++pointCount; // write usable buffer chunk if (usableBytesPerBuffer == bufferIndex) { outputStream.Write(outputBuffer.Data, 0, bufferIndex); bufferIndex = 0; } } if (!process.Update((float)inputStream.Position / inputLength)) { break; } } // write remaining buffer if (bufferIndex > 0) { outputStream.Write(outputBuffer.Data, 0, bufferIndex); } } } process.Log("Skipped {0} lines", skipped); process.LogTime("Copied {0:0,0} points", pointCount); } var extent = new Extent3D(minX, minY, minZ, maxX, maxY, maxZ); var source = new PointCloudBinarySource(this, pointCount, extent, null, 0, pointSizeBytes); return(source); }
public IPointCloudBinarySourceEnumerator GetBlockEnumerator(BufferInstance buffer) { return(new PointCloudBinarySourceEnumerator(this, buffer)); }
public IPointCloudBinarySourceEnumerator GetBlockEnumerator(BufferInstance buffer) { return(new PointCloudBinarySourceCompositeEnumerator(m_sources, buffer)); }
public IPointCloudBinarySourceEnumerator GetBlockEnumerator(BufferInstance buffer) { throw new NotImplementedException(); }
public PointBufferWrapper(BufferInstance buffer, IPointCloudBinarySource source) : this(buffer, source, (int)source.Count) { }