Beispiel #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);
            });
        }
Beispiel #2
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);
            });
        }
        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);
            });
        }
Beispiel #4
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);
Beispiel #5
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);
                }
            });
        }
        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)
                   );
        }
        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);
            });
        }
Beispiel #8
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);
                }
            }
        }