public PointCloudTileDensity(SQuantizedExtentGrid<int> tileCounts, SQuantization3D quantization) { var counts = tileCounts.Data.Cast<int>(); TileCount = tileCounts.CellCount; var nonZeroCounts = counts.Where(c => c > 0).ToArray(); Array.Sort(nonZeroCounts); PointCount = nonZeroCounts.SumLong(); //var tileArea = tileCounts.CellSize * tileCounts.CellSize; //var tileArea = extent.Area / TileCount; var tileArea = (tileCounts.CellSizeX * quantization.ScaleFactorX) * (tileCounts.CellSizeY * quantization.ScaleFactorY); ValidTileCount = nonZeroCounts.Length; MinTileCount = nonZeroCounts[0]; MaxTileCount = nonZeroCounts[ValidTileCount - 1]; MedianTileCount = nonZeroCounts[ValidTileCount / 2]; MeanTileCount = (int)(PointCount / ValidTileCount); MinTileDensity = MinTileCount / tileArea; MaxTileDensity = MaxTileCount / tileArea; MedianTileDensity = MedianTileCount / tileArea; MeanTileDensity = MeanTileCount / tileArea; }
public PointCloudBinarySource(FileHandlerBase file, long count, Extent3D extent, SQuantization3D quantization, long dataOffset, short pointSizeBytes) : base(file) { m_count = count; m_extent = extent; m_quantization = quantization; m_pointDataOffset = dataOffset; m_pointSizeBytes = pointSizeBytes; m_quantizedExtent = quantization.Convert(m_extent); }
public SQuantizedExtentGrid <T> CreateGridFromCellSize <T>(double cellSize, SQuantization3D quantization, bool buffered = false, T fillVal = default(T)) { var cellSizeX = (int)(cellSize / quantization.ScaleFactorX); var cellSizeY = (int)(cellSize / quantization.ScaleFactorY); var sizeX = (ushort)Math.Ceiling((double)RangeX / cellSizeX); var sizeY = (ushort)Math.Ceiling((double)RangeY / cellSizeY); var def = new GridDefinition(sizeX, sizeY, buffered); return(new SQuantizedExtentGrid <T>(def, cellSizeX, cellSizeY, fillVal)); }
public PointCloudBinarySourceComposite(FileHandlerBase file, Extent3D extent, IPointCloudBinarySource[] sources) : base(file) { m_sources = sources; // verify that they are compatible m_count = m_sources.Sum(s => s.Count); m_extent = extent; m_quantization = m_sources[0].Quantization; m_pointSizeBytes = m_sources[0].PointSizeBytes; m_quantizedExtent = m_quantization.Convert(m_extent); }
public LASHeader(BinaryReader reader) { long length = reader.BaseStream.Length; if (length < c_minHeaderSize[LASVersion.LAS_1_0]) throw new OpenFailedException("Invalid format: header too short"); if (Encoding.ASCII.GetString(reader.ReadBytes(FILE_SIGNATURE.Length)) != FILE_SIGNATURE) throw new OpenFailedException("Invalid format: signature does not match"); m_fileSourceID = reader.ReadUInt16(); m_globalEncoding = reader.ReadLASGlobalEncoding(); m_projectID = reader.ReadLASProjectID(); m_version = reader.ReadLASVersionInfo(); m_systemIdentifier = reader.ReadBytes(32).ToAsciiString(); m_generatingSoftware = reader.ReadBytes(32).ToAsciiString(); m_fileCreationDayOfYear = reader.ReadUInt16(); m_fileCreationYear = reader.ReadUInt16(); m_headerSize = reader.ReadUInt16(); m_offsetToPointData = reader.ReadUInt32(); ushort minHeaderSize = c_minHeaderSize[m_version.Version]; if (length < minHeaderSize) throw new OpenFailedException("Invalid format: header too short for version"); if(minHeaderSize > m_headerSize) throw new OpenFailedException("Invalid format: header size incorrect"); m_numberOfVariableLengthRecords = reader.ReadUInt32(); m_pointDataRecordFormat = reader.ReadByte(); m_pointDataRecordLength = reader.ReadUInt16(); m_legacyNumberOfPointRecords = reader.ReadUInt32(); m_legacyNumberOfPointsByReturn = reader.ReadUInt32Array(5); m_quantization = reader.ReadSQuantization3D(); m_extent = reader.ReadExtent3D(); if (m_version.Version >= LASVersion.LAS_1_3) { m_startOfWaveformDataPacketRecord = reader.ReadUInt64(); } if (m_version.Version >= LASVersion.LAS_1_4) { m_startOfFirstExtendedVariableLengthRecord = reader.ReadUInt64(); m_numberOfExtendedVariableLengthRecords = reader.ReadUInt32(); m_numberOfPointRecords = reader.ReadUInt64(); m_numberOfPointsByReturn = reader.ReadUInt64Array(15); } else { m_numberOfPointRecords = m_legacyNumberOfPointRecords; m_numberOfPointsByReturn = new ulong[15]; for (int i = 0; i < m_legacyNumberOfPointsByReturn.Length; i++) m_numberOfPointsByReturn[i] = m_legacyNumberOfPointsByReturn[i]; } // This doesn't apply to LAZ files //ulong pointDataRegionLength = (ulong)length - m_offsetToPointData; //if (pointDataRegionLength < m_pointDataRecordLength * PointCount) // throw new Exception("Invalid format: point data region is not the expected size"); }
/// <summary> /// This will only work if point format, point length, offset, and scale are identical. /// </summary> public LASHeader(LASHeader[] headers, LASVLR[] vlrs, LASEVLR[] evlrs) { var header = headers[0]; var extent = headers.Select(h => h.m_extent).Union3D(); var points = (ulong)headers.Sum(h => (long)h.m_numberOfPointRecords); var pointsByReturn = new ulong[15]; for (var i = 0; i < pointsByReturn.Length; i++) { pointsByReturn[i] = (ulong)headers.Sum(h => (long)h.m_numberOfPointsByReturn[i]); } uint legacyPoints = 0; uint[] legacyPointsByReturn; if (points > uint.MaxValue) { legacyPoints = 0; legacyPointsByReturn = new uint[5]; } else { legacyPoints = (uint)points; legacyPointsByReturn = pointsByReturn.Take(5).Select(c => (uint)c).ToArray(); } m_fileSourceID = header.m_fileSourceID; m_globalEncoding = header.m_globalEncoding; m_projectID = header.m_projectID; m_version = LASVersionInfo.Create(LASVersion.LAS_1_4); m_systemIdentifier = header.m_systemIdentifier; m_generatingSoftware = header.m_generatingSoftware; m_fileCreationDayOfYear = header.m_fileCreationDayOfYear; m_fileCreationYear = header.m_fileCreationYear; m_headerSize = c_minHeaderSize[LASVersion.LAS_1_4]; m_offsetToPointData = m_headerSize + (uint)vlrs.Sum(vlr => vlr.Length); m_numberOfVariableLengthRecords = (uint)vlrs.Length; m_pointDataRecordFormat = header.m_pointDataRecordFormat; m_pointDataRecordLength = header.m_pointDataRecordLength; if (points > uint.MaxValue) { m_legacyNumberOfPointRecords = 0; m_legacyNumberOfPointsByReturn = new uint[5]; } else { m_legacyNumberOfPointRecords = legacyPoints; m_legacyNumberOfPointsByReturn = legacyPointsByReturn; } m_quantization = header.m_quantization; m_extent = extent; m_startOfWaveformDataPacketRecord = 0; m_startOfFirstExtendedVariableLengthRecord = m_offsetToPointData + (points * m_pointDataRecordLength); m_numberOfExtendedVariableLengthRecords = (uint)evlrs.Length; m_numberOfPointRecords = points; m_numberOfPointsByReturn = pointsByReturn; }
public LAZBinarySource(FileHandlerBase file, long count, Extent3D extent, SQuantization3D quantization, long dataOffset, short pointSizeBytes) : base(file, count, extent, quantization, dataOffset, pointSizeBytes) { m_handler = (LAZFile)file; }
public QuantizedStatistics ConvertToQuantized(SQuantization3D quantization) { var mean = (int)((m_mean - quantization.OffsetZ) / quantization.ScaleFactorZ); var stdDev = (uint)(m_stdDev / quantization.ScaleFactorZ); var mode = (int)((m_modeApproximate - quantization.OffsetZ) / quantization.ScaleFactorZ); return new QuantizedStatistics(mean, stdDev, mode); }