Beispiel #1
0
		public PointCloudTile(PointCloudTileSet tileSet, ushort col, ushort row, int validIndex, long offset, int count, int lowResOffset, int lowResCount)
		{
			if (count == 0)
				throw new ArgumentException("count");

			TileSet = tileSet;

			m_row = row;
			m_col = col;
			PointCount = count;
			LowResOffset = lowResOffset;
			LowResCount = lowResCount;

			PointOffset = offset;
			ValidIndex = validIndex;
		}
Beispiel #2
0
        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 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;
        }