Esempio n. 1
0
        public void Serialization_FromPts()
        {
            var filename = Config.TEST_FILE_NAME_PTS;

            if (!File.Exists(filename))
            {
                Assert.Ignore($"File not found: {filename}");
            }

            var config = ImportConfig.Default
                         .WithStorage(PointSetTests.CreateStorage())
                         .WithKey("test")
                         .WithOctreeSplitLimit(5000)
            ;
            var pointset = PointCloud.Import(filename, config);

            var json         = pointset.ToJson();
            var jsonReloaded = PointSet.Parse(json, config.Storage);

            var xs = new Queue <long>();

            pointset.Root.Value.ForEachNode(true, cell =>
            {
                xs.Enqueue(cell.PointCount);
                xs.Enqueue(cell.PointCountTree);
            });
            jsonReloaded.Root.Value.ForEachNode(true, cell =>
            {
                Assert.IsTrue(xs.Dequeue() == cell.PointCount);
                Assert.IsTrue(xs.Dequeue() == cell.PointCountTree);
            });
        }
Esempio n. 2
0
        public void HasCentroid()
        {
            var storage = PointSetTests.CreateStorage();

            var ps = new[]
            {
                new V3d(0.1, 0.1, 0.1),
                new V3d(0.9, 0.1, 0.1),
                new V3d(0.9, 0.9, 0.1),
                new V3d(0.1, 0.9, 0.1),
                new V3d(0.1, 0.1, 0.9),
                new V3d(0.9, 0.1, 0.9),
                new V3d(0.9, 0.9, 0.9),
                new V3d(0.1, 0.9, 0.9),
            };

            var config = ImportConfig.Default.WithStorage(storage).WithRandomKey();
            var n      = PointCloud.Chunks(new Chunk(ps, null), config).Root.Value;

            Assert.IsTrue(n.HasCentroidLocal);
            Assert.IsTrue(n.HasCentroidLocalStdDev);

            Assert.IsTrue(n.CentroidLocal.ApproxEqual(V3f.Zero, 1e-5f));
            Assert.IsTrue(n.CentroidLocalStdDev.ApproximateEquals(0.0f, 1e-5f));
        }
Esempio n. 3
0
        public void LodCreationSetsLodPointCountCell()
        {
            var r       = new Random();
            var storage = PointSetTests.CreateStorage();

            var ps = new V3d[42000].SetByIndex(_ => new V3d(r.NextDouble(), r.NextDouble(), r.NextDouble()));
            var cs = ps.Map(_ => C4b.White);

            var pointset = PointSet.Create(
                storage, "test", ps.ToList(), cs.ToList(), null, null, null, 5000,
                generateLod: false, isTemporaryImportNode: true, ct: default
                );

            pointset.Root.Value.ForEachNode(true, cell =>
            {
                Assert.IsTrue(cell.IsNotLeaf() || cell.Positions != null);
            });

            var config = ImportConfig.Default
                         .WithKey("Test")
                         .WithOctreeSplitLimit(1)
            ;
            var lodded = pointset.GenerateLod(config);

            lodded.Root.Value.ForEachNode(true, cell =>
            {
                Assert.IsTrue(cell.Positions.Value.Length > 0);
            });
        }
Esempio n. 4
0
        public void DisablingLodCreationWorks()
        {
            var r       = new Random();
            var storage = PointSetTests.CreateStorage();

            var ps = new V3d[42000].SetByIndex(_ => new V3d(r.NextDouble(), r.NextDouble(), r.NextDouble()));
            var cs = ps.Map(_ => C4b.White);

            var pointset = PointSet.Create(storage, "test", ps.ToList(), cs.ToList(), null, null, 5000, false, CancellationToken.None);

            pointset.Root.Value.ForEachNode(true, cell =>
            {
                Assert.IsTrue(cell.LodPointCount == 0);
            });

            var config = ImportConfig.Default
                         .WithKey("Test")
                         .WithOctreeSplitLimit(1)
                         .WithCreateOctreeLod(false)
            ;
            var lodded = pointset.GenerateLod(config);

            lodded.Root.Value.ForEachNode(true, cell =>
            {
                Assert.IsTrue(cell.LodPointCount == 0);
                Assert.IsTrue(cell.HasLodPositions == false);
            });
        }
Esempio n. 5
0
        public void HasPointDistance()
        {
            var storage = PointSetTests.CreateStorage();

            var ps = new[]
            {
                new V3d(0.1, 0.1, 0.1),
                new V3d(0.9, 0.1, 0.1),
                new V3d(0.9, 0.9, 0.1),
                new V3d(0.1, 0.9, 0.1),
                new V3d(0.1, 0.1, 0.9),
                new V3d(0.9, 0.1, 0.9),
                new V3d(0.9, 0.9, 0.9),
                new V3d(0.1, 0.9, 0.9),
            };

            var config = ImportConfig.Default.WithStorage(storage).WithRandomKey();
            var n      = PointCloud.Chunks(new Chunk(ps, null), config).Root.Value;

            Assert.IsTrue(n.HasPointDistanceAverage);
            Assert.IsTrue(n.HasPointDistanceStandardDeviation);

            Assert.IsTrue(n.PointDistanceAverage.ApproximateEquals(0.8f, 1e-5f));
            Assert.IsTrue(n.PointDistanceStandardDeviation.ApproximateEquals(0.0f, 1e-5f));
        }
Esempio n. 6
0
        public void HasBoundingBoxExact()
        {
            var storage = PointSetTests.CreateStorage();

            var ps = new[]
            {
                new V3d(0.1, 0.1, 0.1),
                new V3d(0.9, 0.1, 0.1),
                new V3d(0.9, 0.9, 0.1),
                new V3d(0.1, 0.9, 0.1),
                new V3d(0.1, 0.1, 0.9),
                new V3d(0.9, 0.1, 0.9),
                new V3d(0.9, 0.9, 0.9),
                new V3d(0.1, 0.9, 0.9),
            };

            var config = ImportConfig.Default.WithStorage(storage).WithRandomKey();
            var n      = PointCloud.Chunks(new Chunk(ps, null), config).Root.Value;

            Assert.IsTrue(n.HasBoundingBoxExactLocal);
            Assert.IsTrue(n.BoundingBoxExactLocal == new Box3f(new V3f(-0.4f), new V3f(0.4f)));

            Assert.IsTrue(n.HasBoundingBoxExactGlobal);
            Assert.IsTrue(n.BoundingBoxExactGlobal.Min.ApproxEqual(new V3d(0.1), 1e-6));
            Assert.IsTrue(n.BoundingBoxExactGlobal.Max.ApproxEqual(new V3d(0.9), 1e-6));
        }
Esempio n. 7
0
        public void Serialization()
        {
            var r       = new Random();
            var storage = PointSetTests.CreateStorage();

            var ps = new V3d[42000].SetByIndex(_ => new V3d(r.NextDouble(), r.NextDouble(), r.NextDouble()));
            var cs = ps.Map(_ => C4b.White);

            var pointset = PointSet.Create(storage, "test", ps.ToList(), cs.ToList(), null, null, 5000, false, CancellationToken.None);

            var config = ImportConfig.Default
                         .WithKey("lod")
                         .WithOctreeSplitLimit(1)
            ;
            var lodded = pointset.GenerateLod(config);

            var json     = lodded.ToJson();
            var relodded = PointSet.Parse(json, storage);

            var xs = new Queue <long>();

            lodded.Root.Value.ForEachNode(true, cell =>
            {
                xs.Enqueue(cell.PointCount);
                xs.Enqueue(cell.PointCountTree);
            });
            relodded.Root.Value.ForEachNode(true, cell =>
            {
                Assert.IsTrue(xs.Dequeue() == cell.PointCount);
                Assert.IsTrue(xs.Dequeue() == cell.PointCountTree);
            });
        }
Esempio n. 8
0
        public void CanRegenerateNormals()
        {
            // create original pointset
            var r         = new Random();
            var storage   = PointSetTests.CreateStorage();
            var ps        = new V3d[42000].SetByIndex(_ => new V3d(r.NextDouble(), r.NextDouble(), r.NextDouble()));
            var pointset0 = PointSet.Create(storage, "test", ps.ToList(), null, null, null, 5000, true, CancellationToken.None);

            Assert.IsTrue(!(pointset0.HasNormals || pointset0.HasLodNormals));

            // create new pointset with regenerated normals
            var pointset1 = pointset0.RegenerateNormals(xs => xs.Map(_ => V3f.XAxis), default, default);
Esempio n. 9
0
        public void LodPositions()
        {
            var r       = new Random();
            var storage = PointSetTests.CreateStorage();

            var ps = new V3d[42000].SetByIndex(_ => new V3d(r.NextDouble(), r.NextDouble(), r.NextDouble()));
            var cs = ps.Map(_ => C4b.White);

            var pointset = PointSet.Create(storage, "test", ps.ToList(), cs.ToList(), null, null, 5000, false, CancellationToken.None);

            pointset.Root.Value.ForEachNode(true, cell =>
            {
                if (cell.IsLeaf)
                {
                    Assert.IsTrue(cell.PointCount > 0);
                    Assert.IsTrue(cell.Positions.Value.Length == cell.PointCount);
                    Assert.IsTrue(cell.LodPositions == null);
                    Assert.IsTrue(cell.LodPointCount == 0);
                }
                else
                {
                    Assert.IsTrue(cell.PointCount == 0);
                    Assert.IsTrue(cell.Positions == null);
                    Assert.IsTrue(cell.LodPositions == null);
                    Assert.IsTrue(cell.LodPointCount == 0);
                }
            });

            var config = ImportConfig.Default
                         .WithKey("lod")
                         .WithOctreeSplitLimit(1)
            ;
            var lodded = pointset.GenerateLod(config);

            lodded.Root.Value.ForEachNode(true, cell =>
            {
                if (cell.IsLeaf)
                {
                    Assert.IsTrue(cell.PointCount > 0);
                    Assert.IsTrue(cell.Positions.Value.Length == cell.PointCount);
                    Assert.IsTrue(cell.LodPositions.Value.Length == cell.PointCount);
                    Assert.IsTrue(cell.LodPointCount > 0);
                }
                else
                {
                    Assert.IsTrue(cell.PointCount == 0);
                    Assert.IsTrue(cell.Positions == null);
                    Assert.IsTrue(cell.LodPositions.Value.Length > 0);
                    Assert.IsTrue(cell.LodPointCount > 0);
                }
            });
        }
Esempio n. 10
0
        public void CanMergePointSets_0()
        {
            const int n          = 25;
            const int splitLimit = 5;

            var r       = new Random();
            var storage = PointSetTests.CreateStorage();
            var config  = ImportConfig.Default
                          .WithStorage(storage)
                          .WithOctreeSplitLimit(splitLimit)
                          .WithMinDist(0)
                          .WithNormalizePointDensityGlobal(false)
                          .WithVerbose(true)
            ;

            var ps1       = new V3d[n].SetByIndex(_ => new V3d(r.NextDouble(), r.NextDouble(), r.NextDouble()));
            var cs1       = ps1.Map(_ => C4b.White);
            var ns1       = ps1.Map(_ => V3f.XAxis);
            var is1       = ps1.Map(_ => 123);
            var ks1       = ps1.Map(_ => (byte)0);
            var pointset1 = PointSet.Create(
                storage, "test1", ps1, cs1, ns1, is1, ks1, splitLimit,
                generateLod: false, isTemporaryImportNode: true, default
                );
            var pointset1Count = pointset1.Root.Value.CountPoints();

            Assert.IsTrue(pointset1Count == n);

            var ps2       = new V3d[n].SetByIndex(_ => new V3d(r.NextDouble(), r.NextDouble(), r.NextDouble()));
            var cs2       = ps2.Map(_ => C4b.White);
            var ns2       = ps2.Map(_ => V3f.XAxis);
            var is2       = ps2.Map(_ => 456);
            var ks2       = ps2.Map(_ => (byte)1);
            var pointset2 = PointSet.Create(
                storage, "test2", ps2, cs2, ns2, is2, ks2, splitLimit,
                generateLod: false, isTemporaryImportNode: true, default
                );
            var pointset2Count = pointset2.Root.Value.CountPoints();

            Assert.IsTrue(pointset2Count == n);

            var merged = pointset1.Merge(pointset2, null, config);

            Assert.IsTrue(merged.PointCount == n + n);
            Assert.IsTrue(merged.Root.Value.PointCountTree == n + n);
            var mergedCount = merged.Root.Value.CountPoints();

            Assert.IsTrue(mergedCount == n + n);
        }
Esempio n. 11
0
        private static PointSet _CreateRandomPointSetForOctreeLevelTests()
        {
            var r       = new Random();
            var storage = PointSetTests.CreateStorage();

            var ps = new V3d[51200].SetByIndex(_ => new V3d(r.NextDouble(), r.NextDouble(), r.NextDouble()));
            var cs = ps.Map(_ => C4b.White);

            var config = ImportConfig.Default.WithKey("Test").WithOctreeSplitLimit(1);

            return(PointSet
                   .Create(storage, "test", ps.ToList(), cs.ToList(), null, null, 100, true, CancellationToken.None)
                   .GenerateLod(config)
                   );
        }
Esempio n. 12
0
        public void HasTreeDepth2()
        {
            var r       = new Random();
            var storage = PointSetTests.CreateStorage();

            var ps = new V3d[20000].SetByIndex(_ => new V3d(r.NextDouble(), r.NextDouble(), r.NextDouble()));

            var config = ImportConfig.Default.WithStorage(storage).WithRandomKey();
            var n      = PointCloud.Chunks(new Chunk(ps, null), config).Root.Value;

            Assert.IsTrue(n.HasMinTreeDepth);
            Assert.IsTrue(n.HasMaxTreeDepth);

            Assert.IsTrue(n.MinTreeDepth == 1);
            Assert.IsTrue(n.MaxTreeDepth == 1);
        }
Esempio n. 13
0
        public void LodPositions()
        {
            var r       = new Random();
            var storage = PointSetTests.CreateStorage();

            var ps = new V3d[42000].SetByIndex(_ => new V3d(r.NextDouble(), r.NextDouble(), r.NextDouble()));
            var cs = ps.Map(_ => C4b.White);

            var pointset = PointSet.Create(
                storage, "test", ps.ToList(), cs.ToList(), null, null, null, 5000,
                generateLod: true, isTemporaryImportNode: true, default
                );

            pointset.Root.Value.ForEachNode(true, cell =>
            {
                var pointcount = cell.Positions.Value.Length;
                Assert.IsTrue(pointcount > 0);
            });
        }
Esempio n. 14
0
        public void CanMergePointSets_WithoutNormals()
        {
            var r       = new Random();
            var storage = PointSetTests.CreateStorage();

            var ps1       = new V3d[42000].SetByIndex(_ => new V3d(r.NextDouble(), r.NextDouble(), r.NextDouble()));
            var cs1       = ps1.Map(_ => C4b.White);
            var is1       = ps1.Map(_ => 123);
            var pointset1 = PointSet.Create(storage, "test1", ps1, cs1, null, is1, 1000, true, CancellationToken.None);

            var ps2       = new V3d[42000].SetByIndex(_ => new V3d(r.NextDouble() + 0.3, r.NextDouble() + 0.3, r.NextDouble() + 0.3));
            var cs2       = ps2.Map(_ => C4b.White);
            var is2       = ps2.Map(_ => 456);
            var pointset2 = PointSet.Create(storage, "test2", ps2, cs2, null, is2, 1000, true, CancellationToken.None);

            var merged = pointset1.Merge(pointset2, CancellationToken.None);

            Assert.IsTrue(merged.PointCount == 84000);
            Assert.IsTrue(merged.Root.Value.PointCountTree == 84000);
            Assert.IsTrue(merged.Root.Value.CountPoints() == 84000);
        }
Esempio n. 15
0
        public void LodCreationSetsPointCountCell_FromPts()
        {
            var filename = Config.TEST_FILE_NAME_PTS;

            if (!File.Exists(filename))
            {
                Assert.Ignore($"File not found: {filename}");
            }

            var config = ImportConfig.Default
                         .WithStorage(PointSetTests.CreateStorage())
                         .WithKey("test")
                         .WithOctreeSplitLimit(5000)
            ;
            var pointset = PointCloud.Import(filename, config);

            pointset.Root.Value.ForEachNode(true, cell =>
            {
                Assert.IsTrue(cell.LodPointCount > 0);
            });
        }
Esempio n. 16
0
        public void CanMergePointSets_WithoutNormals()
        {
            const int splitLimit = 1000;

            var r       = new Random();
            var storage = PointSetTests.CreateStorage();
            var config  = ImportConfig.Default
                          .WithStorage(storage)
                          .WithOctreeSplitLimit(splitLimit)
                          .WithMinDist(0)
                          .WithNormalizePointDensityGlobal(false)
                          .WithVerbose(true)
            ;

            var ps1       = new V3d[42000].SetByIndex(_ => new V3d(r.NextDouble(), r.NextDouble(), r.NextDouble()));
            var cs1       = ps1.Map(_ => C4b.White);
            var is1       = ps1.Map(_ => 123);
            var ks1       = ps1.Map(_ => (byte)42);
            var pointset1 = PointSet.Create(
                storage, "test1", ps1, cs1, null, is1, ks1, 1000,
                generateLod: false, isTemporaryImportNode: true, default
                );

            var ps2       = new V3d[42000].SetByIndex(_ => new V3d(r.NextDouble() + 0.3, r.NextDouble() + 0.3, r.NextDouble() + 0.3));
            var cs2       = ps2.Map(_ => C4b.White);
            var is2       = ps2.Map(_ => 456);
            var ks2       = ps2.Map(_ => (byte)7);
            var pointset2 = PointSet.Create(
                storage, "test2", ps2, cs2, null, is2, ks2, 1000,
                generateLod: false, isTemporaryImportNode: true, default
                );

            var merged = pointset1.Merge(pointset2, null, config);

            Assert.IsTrue(merged.PointCount == 84000);
            Assert.IsTrue(merged.Root.Value.PointCountTree == 84000);
            Assert.IsTrue(merged.Root.Value.CountPoints() == 84000);
        }
Esempio n. 17
0
        public void CanAddNormals()
        {
            var r       = new Random();
            var storage = PointSetTests.CreateStorage();

            var ps = new V3d[10000].SetByIndex(_ => new V3d(r.NextDouble(), r.NextDouble(), r.NextDouble()));

            var pointset = PointSet
                           .Create(storage, "test", ps.ToList(), null, null, null, 5000, false, CancellationToken.None)
                           .GenerateLod(ImportConfig.Default.WithKey("lod").WithOctreeSplitLimit(5000))
            ;

            storage.Add("pss", pointset, CancellationToken.None);

            var withNormals = WithRandomNormals(pointset.Root.Value);

            storage.Add("psWithNormals", withNormals, CancellationToken.None);

            withNormals.ForEachNode(true, node =>
            {
                if (node.IsLeaf)
                {
                    Assert.IsTrue(node.HasNormals);
                    Assert.IsTrue(!node.HasLodNormals);
                    Assert.IsTrue(node.Normals.Value.Length == node.PointCount);
                }
                else
                {
                    Assert.IsTrue(!node.HasNormals);
                    Assert.IsTrue(node.HasLodNormals);
                    Assert.IsTrue(node.LodNormals.Value.Length == node.LodPointCount);
                }

                //
                var binary = node.ToBinary();
                var node2  = PointSetNode.ParseBinary(binary, storage);
                Assert.IsTrue(node.HasNormals == node2.HasNormals);
                Assert.IsTrue(node.HasLodNormals == node2.HasLodNormals);
                Assert.IsTrue(node.Normals?.Value?.Length == node2.Normals?.Value?.Length);
                Assert.IsTrue(node.LodNormals?.Value?.Length == node2.LodNormals?.Value?.Length);
            });

            PointSetNode WithRandomNormals(PointSetNode n)
            {
                var id = Guid.NewGuid();
                var ns = new V3f[n.IsLeaf ? n.PointCount : n.LodPointCount].Set(V3f.OOI);

                storage.Add(id, ns, CancellationToken.None);

                if (n.IsLeaf)
                {
                    var m = n.WithNormals(id);
                    return(m);
                }
                else
                {
                    var subnodes = n.Subnodes.Map(x => x != null ? WithRandomNormals(x.Value) : null);
                    var m        = n.WithLodNormals(id, subnodes);
                    return(m);
                }
            }
        }