Esempio n. 1
0
        /// <summary>
        /// Imports sequence of chunks.
        /// </summary>
        public static PointSet Chunks(IEnumerable <Chunk> chunks, ImportConfig config)
        {
            // optionally filter minDist
            if (config.MinDist > 0.0)
            {
                chunks = chunks.Select(x => x.ImmutableFilterSequentialMinDistL1(config.MinDist));
            }

            // optionally deduplicate points
            if (config.DeduplicateChunks)
            {
                chunks = chunks.Select(x => x.ImmutableDeduplicate());
            }

            // optionally reproject positions and/or estimate normals
            if (config.Reproject != null || config.EstimateNormals != null)
            {
                Chunk map(Chunk x, CancellationToken ct)
                {
                    if (config.Reproject != null)
                    {
                        var ps = config.Reproject(x.Positions);
                        x = x.WithPositions(ps);
                    }

                    if (config.EstimateNormals != null)
                    {
                        var ns = config.EstimateNormals(x.Positions);
                        x = x.WithNormals(ns);
                    }

                    return(x);
                }

                chunks = chunks.MapParallel(map, config.MaxDegreeOfParallelism, null, config.CancellationToken);
            }

            // reduce all chunks to single PointSet
            var final = chunks
                        .MapReduce(config.WithRandomKey().WithProgressCallback(x => config.ProgressCallback(x * 0.66)))
            ;

            // optionally create LOD data
            if (config.CreateOctreeLod)
            {
                final = final.GenerateLod(config.WithRandomKey().WithProgressCallback(x => config.ProgressCallback(0.66 + x * 0.34)));
            }

            // create final point set with specified key (or random key when no key is specified)
            var key = config.Key ?? Guid.NewGuid().ToString();

            final = new PointSet(config.Storage, key, final?.Root?.Value?.Id, config.OctreeSplitLimit);
            config.Storage.Add(key, final, config.CancellationToken);

            return(final);
        }
        /// <summary>
        /// Imports sequence of chunks.
        /// </summary>
        public static PointSet Chunks(IEnumerable <Chunk> chunks, ImportConfig config)
        {
            config?.ProgressCallback(0.0);

            // deduplicate points
            chunks = chunks.Select(x => x.ImmutableDeduplicate(config.Verbose));

            // merge small chunks
            chunks = MergeSmall(config.MaxChunkPointCount, chunks);

            // filter minDist
            if (config.MinDist > 0.0)
            {
                if (config.NormalizePointDensityGlobal)
                {
                    chunks = chunks.Select(x => x.ImmutableFilterMinDistByCell(new Cell(x.BoundingBox), config.ParseConfig));
                }
                else
                {
                    chunks = chunks.Select(x => x.ImmutableFilterSequentialMinDistL1(config.MinDist));
                }
            }

            // merge small chunks
            chunks = MergeSmall(config.MaxChunkPointCount, chunks);

            // EXPERIMENTAL
            //Report.BeginTimed("unmix");
            //chunks = chunks.ImmutableUnmixOutOfCore(@"T:\tmp", 1, config);
            //Report.End();

            // reproject positions and/or estimate normals
            if (config.Reproject != null)
            {
                Chunk map(Chunk x, CancellationToken ct)
                {
                    if (config.Reproject != null)
                    {
                        var ps = config.Reproject(x.Positions);
                        x = x.WithPositions(ps);
                    }

                    return(x);
                }

                chunks = chunks.MapParallel(map, config.MaxDegreeOfParallelism, null, config.CancellationToken);
            }

            // reduce all chunks to single PointSet
            Report.BeginTimed("map/reduce");
            var final = chunks
                        .MapReduce(config.WithRandomKey().WithProgressCallback(x => config.ProgressCallback(0.01 + x * 0.65)))
            ;

            Report.EndTimed();

            // create LOD data
            Report.BeginTimed("generate lod");
            final = final.GenerateLod(config.WithRandomKey().WithProgressCallback(x => config.ProgressCallback(0.66 + x * 0.34)));
            if (final.Root != null && config.Storage.GetPointCloudNode(final.Root.Value.Id) == null)
            {
                throw new InvalidOperationException("Invariant 4d633e55-bf84-45d7-b9c3-c534a799242e.");
            }
            Report.End();

            // create final point set with specified key (or random key when no key is specified)
            var key = config.Key ?? Guid.NewGuid().ToString();

#pragma warning disable CS0618 // Type or member is obsolete
            final = new PointSet(config.Storage, key, final?.Root?.Value?.Id, config.OctreeSplitLimit);
#pragma warning restore CS0618 // Type or member is obsolete
            config.Storage.Add(key, final);

            return(final);
        }