Example #1
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);
            });
        }
Example #2
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);
            });
        }
        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));
        }
        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);
            });
        }
        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));
        }
        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));
        }
Example #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);
            });
        }
Example #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);
Example #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);
                }
            });
        }
        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);
        }
Example #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)
                   );
        }
Example #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);
        }
Example #13
0
        public void Serialization_FromPts_Really()
        {
            Assert.IsTrue(Data.Points.Import.Pts.PtsFormat != null);
            var filename = Config.TEST_FILE_NAME_PTS;

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

            string id = null;

            var dbDiskLocation = Path.Combine(Path.GetTempPath(), "teststore_" + Guid.NewGuid());

            using (var storageA = PointSetTests.CreateDiskStorage(dbDiskLocation))
            {
                var config = ImportConfig.Default
                             .WithStorage(storageA)
                             .WithKey("test")
                             .WithOctreeSplitLimit(5000)
                ;
                var pointset = PointCloud.Import(filename, config);
                pointset.Root.Value.ForEachNode(true, cell =>
                {
                    var pointcount = cell.Positions?.Value.Length ?? 0;
                    Assert.IsTrue(pointcount > 0);
                    Assert.IsTrue(cell.Positions.Value.Length == pointcount);
                });

                id = pointset.Id;
            }

            using (var storageB = PointSetTests.CreateDiskStorage(dbDiskLocation))
            {
                var pointset = storageB.GetPointSet(id);
                pointset.Root.Value.ForEachNode(true, cell =>
                {
                    var pointcount = cell.Positions?.Value.Length ?? 0;
                    Assert.IsTrue(pointcount > 0);
                    Assert.IsTrue(cell.Positions.Value.Length == pointcount);
                });
            }

            Directory.Delete(dbDiskLocation, true);
        }
Example #14
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);
            });
        }
Example #15
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);
        }
Example #16
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);
            });
        }
        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);
        }
Example #18
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);
                }
            }
        }