Ejemplo n.º 1
0
        public static void ConvertLasData(MemoryMappedViewAccessor accessor, PointCloudPoint[] target, int count,
                                          ref LasPointProcessor.LasHeader header, TransformationData transformationData, string progressBarTitle = null)
        {
            unsafe
            {
                byte *sourcePtr = null;
                accessor.SafeMemoryMappedViewHandle.AcquirePointer(ref sourcePtr);

                try
                {
                    fixed(PointCloudPoint *targetPtr = target)
                    {
                        var counts = new NativeArray <int>(JobsUtility.MaxJobThreadCount, Allocator.TempJob);

                        try
                        {
                            var job = new LasConvertJob()
                            {
                                LasRGB8BitWorkaround = transformationData.LasRGB8BitWorkaround,
                                Input     = sourcePtr,
                                Stride    = header.PointDataSize,
                                Output    = targetPtr,
                                Transform = transformationData.TransformationMatrix,

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

                                InputOffsetX = header.OffsetX,
                                InputOffsetY = header.OffsetY,
                                InputOffsetZ = header.OffsetZ,

                                OutputCenterX = transformationData.OutputCenterX,
                                OutputCenterY = transformationData.OutputCenterY,
                                OutputCenterZ = transformationData.OutputCenterZ,

                                OutputScaleX = transformationData.OutputScaleX,
                                OutputScaleY = transformationData.OutputScaleY,
                                OutputScaleZ = transformationData.OutputScaleZ,

                                Counts      = (int *)counts.GetUnsafePtr(),
                                ThreadIndex = 0,
                            };

                            if (header.PointDataFormat == 2)
                            {
                                job.ColorInput = sourcePtr + 20;
                            }
                            else if (header.PointDataFormat == 3 || header.PointDataFormat == 5)
                            {
                                job.ColorInput = sourcePtr + 28;
                            }
                            else if (header.PointDataFormat == 7 || header.PointDataFormat == 8 ||
                                     header.PointDataFormat == 10)
                            {
                                job.ColorInput = sourcePtr + 30;
                            }

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

                                int   processed = counts.Sum();
                                float progress  = (float)((double)processed / count);
                                EditorUtility.DisplayProgressBar(
                                    string.IsNullOrEmpty(progressBarTitle) ? $"Applying transformation" : progressBarTitle,
                                    $"{processed:N0} points", progress);
                            }
                        }
                        finally
                        {
                            EditorUtility.ClearProgressBar();
                            counts.Dispose();
                        }
                    }
                }
                finally
                {
                    accessor.SafeMemoryMappedViewHandle.ReleasePointer();
                }
            }
        }
Ejemplo n.º 2
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();
                }
            }
        }