Esempio n. 1
0
        public TreeImportData(Bounds bounds, PointCloudVerticalHistogram histogram)
        {
            Bounds         = bounds;
            this.histogram = histogram;

            CalculateRoadBounds();
        }
Esempio n. 2
0
        public override PointCloudVerticalHistogram GenerateHistogram(PointCloudBounds bounds)
        {
            var fileName = Path.GetFileName(FilePath);
            var result   = new PointCloudVerticalHistogram(bounds);

            using (var laz = new Laszip(FilePath))
            {
                long count = laz.Count;

                try
                {
                    for (long i = 0; i < count; i++)
                    {
                        if (i % (1024 * 8) == 0)
                        {
                            var progress = (double)i / count;
                            EditorUtility.DisplayProgressBar(
                                $"Generating histogram ({fileName})",
                                $"{i:N0} points",
                                (float)progress);
                        }

                        var p = laz.GetNextPoint();
                        result.Add(p.Z);
                    }
                }
                finally
                {
                    EditorUtility.ClearProgressBar();
                }
            }

            return(result);
        }
Esempio n. 3
0
        public override PointCloudVerticalHistogram GenerateHistogram(PointCloudBounds bounds)
        {
            var fileName = Path.GetFileName(FilePath);

            long currentOffset = header.PointDataOffset;
            long processed     = 0;

            long count = header.PointDataCount;

            if (header.VersionMajor > 1 || header.VersionMajor == 1 && header.VersionMinor >= 4)
            {
                if (count == 0)
                {
                    count = (long)header.PointDataCountLong;
                }
            }

            var result = new PointCloudVerticalHistogram(bounds);

            using (var file = MemoryMappedFile.CreateFromFile(FilePath ?? throw new Exception("Input file not found."), FileMode.Open))
            {
                var batchIndex = 0;

                var maxArraySize    = TreeUtility.CalculateMaxArraySize(header.PointDataSize);
                var totalBatchCount = Mathf.CeilToInt((float)count / maxArraySize);

                while (processed < count)
                {
                    var batchCount = Math.Min(maxArraySize, count - processed);
                    var batchSize  = batchCount * header.PointDataSize;

                    using (var view = file.CreateViewAccessor(currentOffset, batchSize, MemoryMappedFileAccess.Read))
                    {
                        unsafe
                        {
                            batchIndex++;
                            var progressBarTitle =
                                $"Generating histogram ({fileName}, batch {batchIndex.ToString()}/{totalBatchCount.ToString()})";

                            var hst = PointImportJobs.GenerateHistogramLas(view, batchCount, header, bounds, progressBarTitle);
                            result.AddData(hst.regions);
                        }
                    }

                    processed     += batchCount;
                    currentOffset += batchSize;
                }
            }

            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// Calculates and returns merged bounds of points from all given processors.
        /// </summary>
        /// <param name="processors">Enumerable collection of point processors.</param>
        private static PointCloudVerticalHistogram GenerateHistogram(IEnumerable <PointProcessor> processors, PointCloudBounds bounds)
        {
            var result = new PointCloudVerticalHistogram(bounds);

            foreach (var processor in processors)
            {
                unsafe
                {
                    var processorHistogram = processor.GenerateHistogram(bounds);
                    result.AddData(processorHistogram.regions);
                }
            }

            return(result);
        }
Esempio n. 5
0
        protected PointCloudVerticalHistogram GenerateHistogramDefault(DefaultHeaderData headerData, PointCloudBounds bounds)
        {
            var fileName = Path.GetFileName(FilePath);

            long currentOffset = headerData.DataOffset;
            long processed     = 0;

            var result = new PointCloudVerticalHistogram(bounds);

            using (var file = MemoryMappedFile.CreateFromFile(FilePath ?? throw new Exception("Input file not found."), FileMode.Open))
            {
                var batchIndex = 0;

                var maxArraySize    = TreeUtility.CalculateMaxArraySize(headerData.DataStride);
                var totalBatchCount = Mathf.CeilToInt((float)headerData.DataCount / maxArraySize);

                while (processed < headerData.DataCount)
                {
                    var batchCount = Math.Min(maxArraySize, headerData.DataCount - processed);
                    var batchSize  = batchCount * headerData.DataStride;

                    using (var view = file.CreateViewAccessor(currentOffset, batchSize, MemoryMappedFileAccess.Read))
                    {
                        unsafe
                        {
                            batchIndex++;
                            var progressBarTitle =
                                $"Calculating bounds ({fileName}, batch {batchIndex.ToString()}/{totalBatchCount.ToString()})";

                            var batchHistogram = PointImportJobs.GenerateHistogram(view, batchCount,
                                                                                   headerData.DataStride, headerData.Elements, bounds, progressBarTitle);

                            result.AddData(batchHistogram.regions);
                        }
                    }

                    processed     += batchCount;
                    currentOffset += batchSize;
                }
            }

            return(result);
        }
Esempio n. 6
0
        public static PointCloudVerticalHistogram GenerateHistogramLas(MemoryMappedViewAccessor accessor, long count,
                                                                       LasPointProcessor.LasHeader header, PointCloudBounds bounds, string progressBarTitle = null)
        {
            var maxArraySize = TreeUtility.CalculateMaxArraySize(header.PointDataSize);

            if (count > maxArraySize)
            {
                Debug.LogWarning(
                    $"Too many points ({count:n0}), truncating to {maxArraySize:n0}");
                count = maxArraySize;
            }

            unsafe
            {
                byte *ptr = null;
                accessor.SafeMemoryMappedViewHandle.AcquirePointer(ref ptr);

                try
                {
                    var counts     = new NativeArray <int>(JobsUtility.MaxJobThreadCount, Allocator.TempJob);
                    var histograms = new NativeArray <PointCloudVerticalHistogram>(
                        JobsUtility.MaxJobThreadCount,
                        Allocator.TempJob,
                        NativeArrayOptions.UninitializedMemory);

                    for (var i = 0; i < histograms.Length; i++)
                    {
                        histograms[i] = new PointCloudVerticalHistogram(bounds);
                    }

                    try
                    {
                        var job = new PointCloudCreateHistogramLasJob()
                        {
                            Input  = ptr,
                            Stride = header.PointDataSize,

                            InputScaleX = header.ScaleX,
                            InputScaleY = header.ScaleY,
                            InputScaleZ = header.ScaleZ,

                            InputOffsetX = header.OffsetX,
                            InputOffsetY = header.OffsetY,
                            InputOffsetZ = header.OffsetZ,
                            Histogram    = (PointCloudVerticalHistogram *)histograms.GetUnsafePtr(),
                            Counts       = (int *)counts.GetUnsafePtr(),
                            ThreadIndex  = 0,
                        };

                        var h = job.Schedule((int)count, 65536);
                        while (!h.IsCompleted)
                        {
                            System.Threading.Thread.Sleep(100);

                            var processed = counts.Sum();
                            var progress  = (float)((double)processed / count);

                            EditorUtility.DisplayProgressBar(
                                string.IsNullOrEmpty(progressBarTitle) ? "Generating histogram" : progressBarTitle,
                                $"{processed:N0} points",
                                progress);
                        }

                        var result = new PointCloudVerticalHistogram(bounds);

                        foreach (var hst in histograms)
                        {
                            result.AddData(hst.regions);
                        }

                        return(result);
                    }
                    finally
                    {
                        EditorUtility.ClearProgressBar();
                        histograms.Dispose();
                        counts.Dispose();
                    }
                }
                finally
                {
                    accessor.SafeMemoryMappedViewHandle.ReleasePointer();
                }
            }
        }