public PointCloudAnalysisResult(PointCloudTileDensity density, Statistics statistics, SQuantization3D quantization, List <PointCloudBinarySourceEnumeratorSparseGridRegion> gridIndex)
 {
     Density      = density;
     Statistics   = statistics;
     Quantization = quantization;
     GridIndex    = gridIndex;
 }
Example #2
0
        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;
        }
Example #3
0
        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));
        }
 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 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);
        }
Example #6
0
        public PointCloudTileSet(IPointCloudBinarySource source, PointCloudTileDensity density, SQuantizedExtentGrid <int> tileCounts, Grid <int> lowResCounts)
        {
            Extent          = source.Extent;
            Quantization    = source.Quantization;
            QuantizedExtent = source.QuantizedExtent;
            Density         = density;

            Cols      = tileCounts.SizeX;
            Rows      = tileCounts.SizeY;
            TileSizeX = tileCounts.CellSizeX;
            TileSizeY = tileCounts.CellSizeY;
            //TileSize = tileCounts.CellSize;

            PointCount     = density.PointCount;
            TileCount      = density.TileCount;
            ValidTileCount = density.ValidTileCount;

            LowResCount = 0;

            m_tileIndex = CreateTileIndex(ValidTileCount);
            m_tiles     = new PointCloudTile[density.ValidTileCount];

            // create valid tiles (in order)
            long offset         = 0;
            int  validTileIndex = 0;

            foreach (var tile in GetTileOrdering(Rows, Cols))
            {
                int pointCount = tileCounts.Data[tile.Row, tile.Col];
                if (pointCount > 0)
                {
                    var lowResCount = lowResCounts.Data[tile.Row, tile.Col];
                    m_tiles[validTileIndex] = new PointCloudTile(this, tile.Col, tile.Row, validTileIndex, offset, pointCount, LowResCount, lowResCount);
                    m_tileIndex.Add(tile.Index, validTileIndex);
                    ++validTileIndex;
                    offset      += (pointCount - lowResCount);
                    LowResCount += lowResCount;
                }
            }
        }
Example #7
0
        public PointCloudTileSet(BinaryReader reader)
        {
            Rows      = reader.ReadUInt16();
            Cols      = reader.ReadUInt16();
            TileSizeY = reader.ReadInt32();
            TileSizeX = reader.ReadInt32();

            TileCount = Rows * Cols;

            Extent          = reader.ReadExtent3D();
            Quantization    = reader.ReadSQuantization3D();
            QuantizedExtent = Quantization.Convert(Extent);
            Density         = reader.ReadTileDensity();
            PointCount      = Density.PointCount;
            ValidTileCount  = Density.ValidTileCount;

            LowResCount = 0;

            m_tileIndex = CreateTileIndex(ValidTileCount);
            m_tiles     = new PointCloudTile[ValidTileCount];

            // fill in valid tiles (dense)
            long pointOffset = 0;
            var  i           = 0;

            foreach (var tile in GetTileOrdering(Rows, Cols))
            {
                var pointCount  = reader.ReadInt32();
                var lowResCount = reader.ReadInt32();
                if (pointCount > 0)
                {
                    m_tiles[i] = new PointCloudTile(this, tile.Col, tile.Row, i, pointOffset, pointCount, LowResCount, lowResCount);
                    m_tileIndex.Add(tile.Index, i);

                    pointOffset += (pointCount - lowResCount);
                    LowResCount += lowResCount;
                    ++i;
                }
            }
        }
 public PointCloudAnalysisResult(PointCloudTileDensity density, Statistics statistics, SQuantization3D quantization)
     : this(density, statistics, quantization, null)
 {
 }
Example #9
0
 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;
 }
Example #10
0
        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");
        }
Example #11
0
        /// <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;
        }