Пример #1
0
        public void CanImport_WithoutKey()
        {
            int n  = 10;
            var ps = new V3d[n];

            for (var i = 0; i < n; i++)
            {
                ps[i] = new V3d(i, 0, 0);
            }

            var chunk = new Chunk(ps);

            Assert.IsTrue(chunk.Count == 10);

            var config = ImportConfig.Default
                         .WithStorage(PointCloud.CreateInMemoryStore())
                         .WithKey(null)
                         .WithOctreeSplitLimit(10)
                         .WithCreateOctreeLod(false)
                         .WithDeduplicateChunks(false)
                         .WithMinDist(0.0)
                         .WithReproject(null)
                         .WithEstimateNormals(null)
            ;
            var pointcloud = PointCloud.Chunks(chunk, config);

            Assert.IsTrue(pointcloud.Id != null);
        }
Пример #2
0
        public void CanCreateInMemoryPointSet_Many()
        {
            var storage = PointCloud.CreateInMemoryStore();
            var ps      = new List <V3d>();
            var ns      = new List <V3f>();

            for (var x = 0.125; x < 1.0; x += 0.25)
            {
                for (var y = 0.125; y < 1.0; y += 0.25)
                {
                    for (var z = 0.125; z < 1.0; z += 0.25)
                    {
                        ps.Add(new V3d(x, y, z));
                        ns.Add(V3f.ZAxis);
                    }
                }
            }

            Assert.IsTrue(ps.Count == 4 * 4 * 4);

            var imps = InMemoryPointSet.Build(ps, null, ns, null, new Cell(0, 0, 0, 0), 1);
            var root = imps.ToPointSetCell(storage, ct: CancellationToken.None);

            Assert.IsTrue(root.PointCountTree == 4 * 4 * 4);
            var countNodes = root.CountLeafNodes(true);

            Assert.IsTrue(countNodes == 4 * 4 * 4);
        }
Пример #3
0
        public void CanImportChunk_Reproject()
        {
            int n  = 10;
            var ps = new V3d[n];

            for (var i = 0; i < n; i++)
            {
                ps[i] = new V3d(i, 0, 0);
            }
            var bb = new Box3d(ps);

            var chunk = new Chunk(ps);

            Assert.IsTrue(chunk.Count == 10);
            Assert.IsTrue(chunk.BoundingBox == bb);

            var config = ImportConfig.Default
                         .WithStorage(PointCloud.CreateInMemoryStore())
                         .WithKey("test")
                         .WithOctreeSplitLimit(10)
                         .WithReproject(xs => xs.Select(x => x += V3d.OIO).ToArray())
            ;
            var pointcloud = PointCloud.Chunks(chunk, config);

            Assert.IsTrue(pointcloud.BoundingBox == bb + V3d.OIO);
        }
Пример #4
0
        public void PointsetAttributes_NoLod()
        {
            var ps = new List <V3d> {
                new V3d(0.5, 0.5, 0.5)
            };
            var cs = new List <C4b> {
                C4b.White
            };
            var ns = new List <V3f> {
                V3f.ZAxis
            };
            var js = new List <int> {
                123
            };
            var storage  = PointCloud.CreateInMemoryStore();
            var pointset = PointSet.Create(storage, "test", ps, cs, ns, js, 1, false, default);

            Assert.IsTrue(pointset.HasColors == true);
            Assert.IsTrue(pointset.HasIntensities == true);
            Assert.IsTrue(pointset.HasKdTree == true);
            Assert.IsTrue(pointset.HasLodColors == false);
            Assert.IsTrue(pointset.HasLodIntensities == false);
            Assert.IsTrue(pointset.HasLodKdTree == false);
            Assert.IsTrue(pointset.HasLodNormals == false);
            Assert.IsTrue(pointset.HasLodPositions == false);
            Assert.IsTrue(pointset.HasNormals == true);
            Assert.IsTrue(pointset.HasPositions == true);
        }
Пример #5
0
        public void ForEachNodeIntersecting_Works()
        {
            var storage    = PointCloud.CreateInMemoryStore();
            var pointcloud = CreateClusteredPointsInUnitCube(1000, 10);
            var ns         = pointcloud.Root.Value.ForEachNodeIntersecting(Hull3d.Create(Box3d.Unit), true).ToArray();

            Assert.IsTrue(ns.Length > 0);
        }
Пример #6
0
        public void CanQueryPointsWithEverythingOutside_Single()
        {
            var storage = PointCloud.CreateInMemoryStore();
            var ps      = new List <V3d> {
                new V3d(0.5, 0.5, 0.5)
            };
            var root = InMemoryPointSet.Build(ps, null, null, null, Cell.Unit, 1).ToPointSetCell(storage, ct: CancellationToken.None);

            var rs = root.QueryPoints(cell => false, cell => true, p => false).SelectMany(x => x.Positions).ToArray();

            Assert.IsTrue(rs.Length == 0);
        }
Пример #7
0
        public void CanImportE57File_MinDist()
        {
            var filename = Path.Combine(Config.TestDataDir, "test.e57");
            var config   = ImportConfig.Default
                           .WithStorage(PointCloud.CreateInMemoryStore())
                           .WithKey("test")
                           .WithMinDist(10)
            ;
            var pointset = PointCloud.Import(filename, config);

            Assert.IsTrue(pointset.PointCount < 3);
        }
Пример #8
0
        public void CanImportE57FileAndLoadFromStore()
        {
            var filename = Path.Combine(Config.TestDataDir, "test.e57");
            var config   = ImportConfig.Default
                           .WithStorage(PointCloud.CreateInMemoryStore())
                           .WithKey("test")
            ;
            var pointset  = PointCloud.Import(filename, config);
            var pointset2 = config.Storage.GetPointSet("test", CancellationToken.None);

            Assert.IsTrue(pointset2 != null);
            Assert.IsTrue(pointset2.PointCount == 3);
        }
Пример #9
0
        private static PointSet CreateRandomPointsInUnitCube(int n, int splitLimit)
        {
            var r  = new Random();
            var ps = new V3d[n];

            for (var i = 0; i < n; i++)
            {
                ps[i] = new V3d(r.NextDouble(), r.NextDouble(), r.NextDouble());
            }
            var config = ImportConfig.Default
                         .WithStorage(PointCloud.CreateInMemoryStore())
                         .WithKey("test")
                         .WithOctreeSplitLimit(splitLimit)
            ;

            return(PointCloud.Chunks(new Chunk(ps, null), config));
        }
Пример #10
0
        public void CanImportPtsFile()
        {
            var filename = Path.Combine(Config.TestDataDir, "test.pts");

            if (!File.Exists(filename))
            {
                Assert.Ignore($"File not found: {filename}");
            }
            TestContext.WriteLine($"testfile is '{filename}'");
            var config = ImportConfig.Default
                         .WithStorage(PointCloud.CreateInMemoryStore())
                         .WithKey("test")
            ;
            var pointset = PointCloud.Import(filename, config);

            Assert.IsTrue(pointset != null);
            Assert.IsTrue(pointset.PointCount == 3);
        }
Пример #11
0
        internal static void TestKNearest()
        {
            var sw   = new Stopwatch();
            var rand = new Random();

            Report.BeginTimed("generating point clouds");
            var cloud0 = CreateRandomPointsInUnitCube(1000000, 8192);
            var cloud1 = CreateRandomPointsInUnitCube(1000000, 8192);

            Report.EndTimed();

            var ps0 = cloud0.QueryAllPoints().SelectMany(chunk => chunk.Positions).ToArray();

            sw.Restart();
            for (var i = 0; i < ps0.Length; i++)
            {
                var p = cloud1.QueryPointsNearPoint(ps0[i], 0.1, 1);
                if (i % 100000 == 0)
                {
                    Console.WriteLine($"{i,20:N0}     {sw.Elapsed}");
                }
            }
            sw.Stop();
            Console.WriteLine($"{ps0.Length,20:N0}     {sw.Elapsed}");

            PointSet CreateRandomPointsInUnitCube(int n, int splitLimit)
            {
                var r  = new Random();
                var ps = new V3d[n];

                for (var i = 0; i < n; i++)
                {
                    ps[i] = new V3d(r.NextDouble(), r.NextDouble(), r.NextDouble());
                }
                var config = ImportConfig.Default
                             .WithStorage(PointCloud.CreateInMemoryStore(new LruDictionary <string, object>(1024 * 1024 * 1024)))
                             .WithKey("test")
                             .WithOctreeSplitLimit(splitLimit)
                ;

                return(PointCloud.Chunks(new Chunk(ps, null), config));
            }
        }
Пример #12
0
        public void CanImport_DuplicateKey()
        {
            int n  = 10;
            var ps = new V3d[n];

            for (var i = 0; i < n; i++)
            {
                ps[i] = new V3d(i, 0, 0);
            }

            var chunk = new Chunk(ps);

            Assert.IsTrue(chunk.Count == 10);

            var config = ImportConfig.Default
                         .WithStorage(PointCloud.CreateInMemoryStore())
                         .WithKey("test")
                         .WithOctreeSplitLimit(10)
                         .WithCreateOctreeLod(false)
                         .WithDeduplicateChunks(false)
                         .WithMinDist(0.0)
                         .WithReproject(null)
                         .WithEstimateNormals(null)
            ;


            var pointcloud = PointCloud.Chunks(new Chunk[] { }, config);

            Assert.IsTrue(pointcloud.Id != null);
            Assert.IsTrue(pointcloud.PointCount == 0);


            var pointcloud2 = PointCloud.Chunks(chunk, config);

            Assert.IsTrue(pointcloud2.Id != null);
            Assert.IsTrue(pointcloud2.PointCount == 10);


            var reloaded = config.Storage.GetPointSet("test", CancellationToken.None);

            Assert.IsTrue(reloaded.PointCount == 10);
        }
Пример #13
0
        public void CanImportPtsFileAndLoadFromStore_CheckKey()
        {
            var filename = Path.Combine(Config.TestDataDir, "test.pts");

            if (!File.Exists(filename))
            {
                Assert.Ignore($"File not found: {filename}");
            }
            TestContext.WriteLine($"testfile is '{filename}'");
            var config = ImportConfig.Default
                         .WithStorage(PointCloud.CreateInMemoryStore())
                         .WithKey("test")
            ;
            var pointset = PointCloud.Import(filename, config);

            Assert.IsTrue(pointset.Id == "test");
            var pointset2 = config.Storage.GetPointSet("test", CancellationToken.None);

            Assert.IsTrue(pointset2 != null);
            Assert.IsTrue(pointset2.PointCount == 3);
        }
Пример #14
0
        public void CanImportChunk_EstimateNormals()
        {
            int n  = 10;
            var ps = new V3d[n];

            for (var i = 0; i < n; i++)
            {
                ps[i] = new V3d(i, 0, 0);
            }

            var chunk = new Chunk(ps);

            Assert.IsTrue(chunk.Count == 10);

            var config = ImportConfig.Default
                         .WithStorage(PointCloud.CreateInMemoryStore())
                         .WithKey("test")
                         .WithOctreeSplitLimit(10)
            ;
            var pointcloud = PointCloud.Chunks(chunk, config);
            var node       = pointcloud.Root.Value;

            Assert.IsTrue(node.IsLeaf);
            Assert.IsTrue(node.HasNormals == false);


            config = ImportConfig.Default
                     .WithStorage(PointCloud.CreateInMemoryStore())
                     .WithKey("test")
                     .WithOctreeSplitLimit(10)
                     .WithEstimateNormals(xs => xs.Select(x => V3f.OOI).ToArray())
            ;
            pointcloud = PointCloud.Chunks(chunk, config);
            node       = pointcloud.Root.Value;
            Assert.IsTrue(node.IsLeaf);
            Assert.IsTrue(node.HasNormals == true);
            Assert.IsTrue(node.Normals.Value.All(x => x == V3f.OOI));
        }
Пример #15
0
        private static PointSet CreateRegularPointsInUnitCube(int n, int splitLimit)
        {
            var ps    = new List <V3d>();
            var step  = 1.0 / n;
            var start = step * 0.5;

            for (var x = start; x < 1.0; x += step)
            {
                for (var y = start; y < 1.0; y += step)
                {
                    for (var z = start; z < 1.0; z += step)
                    {
                        ps.Add(new V3d(x, y, z));
                    }
                }
            }
            var config = ImportConfig.Default
                         .WithStorage(PointCloud.CreateInMemoryStore())
                         .WithKey("test")
                         .WithOctreeSplitLimit(splitLimit)
            ;

            return(PointCloud.Chunks(new Chunk(ps, null), config));
        }
Пример #16
0
        public void ProgressCallbackWorks()
        {
            var CHUNKSIZE  = 10000;
            var CHUNKCOUNT = 10;

            var countProgressCallbacks = 0L;

            var config = ImportConfig.Default
                         .WithStorage(PointCloud.CreateInMemoryStore())
                         .WithKey("test")
                         .WithProgressCallback(x => Interlocked.Increment(ref countProgressCallbacks));

            ;

            var pointcloud = PointCloud.Chunks(GenerateChunks(CHUNKSIZE).Take(CHUNKCOUNT), config);

            Assert.IsTrue(pointcloud.PointCount == CHUNKSIZE * CHUNKCOUNT);

            Assert.IsTrue(countProgressCallbacks > 10);


            IEnumerable <Chunk> GenerateChunks(int numberOfPointsPerChunk)
            {
                var r = new Random();

                while (true)
                {
                    var _ps = new V3d[numberOfPointsPerChunk];
                    for (var i = 0; i < numberOfPointsPerChunk; i++)
                    {
                        _ps[i] = new V3d(r.NextDouble(), r.NextDouble(), r.NextDouble());
                    }
                    yield return(new Chunk(_ps));
                }
            }
        }
Пример #17
0
        public void CanImportChunk_MinDist()
        {
            int n  = 100;
            var r  = new Random();
            var ps = new V3d[n];

            for (var i = 0; i < n; i++)
            {
                ps[i] = new V3d(r.NextDouble(), r.NextDouble(), r.NextDouble());
            }
            var chunk = new Chunk(ps);

            Assert.IsTrue(chunk.Count == 100);

            var config = ImportConfig.Default
                         .WithStorage(PointCloud.CreateInMemoryStore())
                         .WithKey("test")
                         .WithOctreeSplitLimit(10)
                         .WithMinDist(0.5)
            ;
            var pointcloud = PointCloud.Chunks(chunk, config);

            Assert.IsTrue(pointcloud.PointCount < 100);
        }
Пример #18
0
        public void CanImport_Empty()
        {
            var config = ImportConfig.Default
                         .WithStorage(PointCloud.CreateInMemoryStore())
                         .WithKey("test")
                         .WithOctreeSplitLimit(10)
                         .WithCreateOctreeLod(false)
                         .WithDeduplicateChunks(false)
                         .WithMinDist(0.0)
                         .WithReproject(null)
                         .WithEstimateNormals(null)
            ;


            var pointcloud = PointCloud.Chunks(new Chunk[] { }, config);

            Assert.IsTrue(pointcloud.Id == "test");
            Assert.IsTrue(pointcloud.PointCount == 0);

            var reloaded = config.Storage.GetPointSet("test", CancellationToken.None);

            Assert.IsTrue(reloaded.Id == "test");
            Assert.IsTrue(reloaded.PointCount == 0);
        }
Пример #19
0
        public void CanCreateInMemoryStore()
        {
            var store = PointCloud.CreateInMemoryStore();

            Assert.IsTrue(store != null);
        }