Пример #1
0
        public void InitializeWithRegionAndData()
        {
            List <CubeBounds> testBounds = new List <CubeBounds>();

            testBounds.Add(new CubeBounds {
                BoundingBox = this.oneBoundingBox
            });
            testBounds.Add(new CubeBounds {
                BoundingBox = new BoundingBox(new Vector3(3, 3, 3), new Vector3(3, 1, 0))
            });

            OcTree <CubeBounds> testOcTree = new OcTree <CubeBounds>(this.zeroBoundingBox, testBounds);

            Assert.IsFalse(testOcTree.HasChildren);
            Assert.IsTrue(testOcTree.IsRoot);
            Assert.IsNotNull(testOcTree.Region);
            Assert.AreEqual(Vector3.Zero, testOcTree.Region.Max);

            testOcTree.UpdateTree();

            Assert.IsTrue(testOcTree.HasChildren);
            Assert.IsTrue(testOcTree.IsRoot);
            Assert.IsNotNull(testOcTree.Region);
            Assert.AreEqual(Vector3.Zero, testOcTree.Region.Min);
            Assert.AreEqual(new Vector3(4, 4, 4), testOcTree.Region.Max);

            OcTreeUtilities.Dump(testOcTree);
        }
Пример #2
0
        public void Initialize()
        {
            OcTree <CubeBounds> testOcTree = new OcTree <CubeBounds>();

            Assert.IsFalse(testOcTree.HasChildren);
            Assert.IsTrue(testOcTree.IsRoot);
            Assert.AreEqual(this.zeroBoundingBox, testOcTree.Region);
            OcTreeUtilities.Dump(testOcTree);
        }
Пример #3
0
        public void InitializeWithRegion()
        {
            OcTree <CubeBounds> testOcTree = new OcTree <CubeBounds>(this.oneBoundingBox);

            Assert.IsFalse(testOcTree.HasChildren);
            Assert.IsTrue(testOcTree.IsRoot);
            Assert.IsNotNull(testOcTree.Region);
            Assert.AreEqual(Vector3.One, testOcTree.Region.Max);
            OcTreeUtilities.Dump(testOcTree);
        }
Пример #4
0
        public void LoadDefaultMinSize()
        {
            OcTree <CubeBounds> ocTree;

            using (Stream metadataStream = new FileStream(".\\data\\validdataset1\\v1\\metadata.json", FileMode.Open, FileAccess.Read))
            {
                ocTree = MetadataLoader.Load(metadataStream, "L1", new Vector3(1, 1, 1));
            }

            ocTree.UpdateTree();
            Assert.IsNotNull(ocTree);
            Assert.IsTrue(ocTree.HasChildren);

            OcTreeUtilities.Dump(ocTree);
        }
Пример #5
0
        public void LoadLargeSet()
        {
            OcTree <CubeBounds> ocTree = new OcTree <CubeBounds>(new BoundingBox(Vector3.Zero, Vector3.Zero), new CubeBounds[] { }, 2);

            using (Stream metadataStream = new FileStream(".\\data\\validdataset2\\v1\\metadata.json", FileMode.Open, FileAccess.Read))
            {
                ocTree = MetadataLoader.Load(metadataStream, ocTree, "L1", new Vector3(1, 1, 1));
            }

            ocTree.UpdateTree();
            Assert.AreEqual(2, ocTree.MinimumSize);
            Assert.IsNotNull(ocTree);
            Assert.IsTrue(ocTree.HasChildren);

            OcTreeUtilities.Dump(ocTree);
        }
Пример #6
0
        public void RayIntersectionTest()
        {
            List <CubeBounds> testBounds = new List <CubeBounds>();

            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(Vector3.Zero, 1)
            });
            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(new Vector3(1, 1, 1), 1)
            });
            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(new Vector3(2, 2, 2), 1)
            });
            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(new Vector3(3, 3, 3), 1)
            });

            OcTree <CubeBounds> testOcTree = new OcTree <CubeBounds>(this.zeroBoundingBox, testBounds);

            testOcTree.UpdateTree();
            OcTreeUtilities.Dump(testOcTree);

            Assert.IsTrue(testOcTree.HasChildren);
            Assert.IsTrue(testOcTree.IsRoot);
            Assert.IsNotNull(testOcTree.Region);
            Assert.AreEqual(Vector3.Zero, testOcTree.Region.Min);
            Assert.AreEqual(new Vector3(4, 4, 4), testOcTree.Region.Max);

            Assert.AreEqual(0, testOcTree.Items.Count);

            // Ray Intersects
            Ray ray1 = new Ray(new Vector3(0, 0, 0), new Vector3(1, 1, 1));

            Assert.AreEqual(4, testOcTree.AllIntersections(ray1).Count());

            Ray ray2 = new Ray(new Vector3(0, 0, 0), new Vector3(0, 0, 1));

            Assert.AreEqual(1, testOcTree.AllIntersections(ray2).Count());

            // No Intersects
            Ray ray3 = new Ray(new Vector3(3, 0, 0), new Vector3(1, 1, 1));

            Assert.AreEqual(0, testOcTree.AllIntersections(ray3).Count());
        }
Пример #7
0
        public void SphereIntersectionTest()
        {
            List <CubeBounds> testBounds = new List <CubeBounds>();

            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(Vector3.Zero, 1)
            });
            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(new Vector3(1, 1, 1), 1)
            });
            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(new Vector3(2, 2, 2), 1)
            });
            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(new Vector3(3, 3, 3), 1)
            });

            OcTree <CubeBounds> testOcTree = new OcTree <CubeBounds>(this.zeroBoundingBox, testBounds);

            testOcTree.UpdateTree();
            OcTreeUtilities.Dump(testOcTree);

            Assert.IsTrue(testOcTree.HasChildren);
            Assert.IsTrue(testOcTree.IsRoot);
            Assert.IsNotNull(testOcTree.Region);
            Assert.AreEqual(Vector3.Zero, testOcTree.Region.Min);
            Assert.AreEqual(new Vector3(4, 4, 4), testOcTree.Region.Max);

            Assert.AreEqual(0, testOcTree.Items.Count);

            // Sphere Intersects - unlike bounding box, surface intersections are ignored
            BoundingSphere sphere1 = new BoundingSphere(new Vector3(2, 2, 2), 0.5f);

            Assert.AreEqual(2, testOcTree.AllIntersections(sphere1).Count());

            BoundingSphere sphere2 = new BoundingSphere(new Vector3(2, 2, 2), 1f);

            Assert.AreEqual(2, testOcTree.AllIntersections(sphere2).Count());
        }
Пример #8
0
        public void  ItemsTest()
        {
            List <CubeBounds> testBounds = new List <CubeBounds>();

            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(Vector3.Zero, 1)
            });
            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(new Vector3(1, 1, 1), 1)
            });
            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(new Vector3(2, 2, 2), 1)
            });
            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(new Vector3(3, 3, 3), 1)
            });

            OcTree <CubeBounds> testOcTree = new OcTree <CubeBounds>(this.zeroBoundingBox, testBounds);

            testOcTree.UpdateTree();
            OcTreeUtilities.Dump(testOcTree);

            Assert.IsTrue(testOcTree.HasChildren);
            Assert.IsTrue(testOcTree.IsRoot);
            Assert.IsNotNull(testOcTree.Region);

            var allItems = testOcTree.AllItems();

            Assert.AreEqual(4, allItems.Count());

            var octants = testOcTree.Octants.Where(o => o != null);

            foreach (var octant in octants)
            {
                var childItems = octant.AllItems();
                Assert.AreEqual(2, childItems.Count());
            }
        }
Пример #9
0
        public void BoundingBoxIntersectionTest()
        {
            List <CubeBounds> testBounds = new List <CubeBounds>();

            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(Vector3.Zero, 1)
            });
            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(new Vector3(1, 1, 1), 1)
            });
            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(new Vector3(2, 2, 2), 1)
            });
            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(new Vector3(3, 3, 3), 1)
            });

            OcTree <CubeBounds> testOcTree = new OcTree <CubeBounds>(this.zeroBoundingBox, testBounds);

            testOcTree.UpdateTree();
            OcTreeUtilities.Dump(testOcTree);

            Assert.IsTrue(testOcTree.HasChildren);
            Assert.IsTrue(testOcTree.IsRoot);
            Assert.IsNotNull(testOcTree.Region);
            Assert.AreEqual(Vector3.Zero, testOcTree.Region.Min);
            Assert.AreEqual(new Vector3(4, 4, 4), testOcTree.Region.Max);

            Assert.AreEqual(0, testOcTree.Items.Count);

            // Box Intersects
            BoundingBox box1 = this.MakeCube(new Vector3(-0.5f, -0.5f, -0.5f), 1);

            Assert.AreEqual(1, testOcTree.AllIntersections(box1).Count());

            BoundingBox box2 = this.MakeCube(new Vector3(0.5f, 0.5f, 0.5f), 1);

            Assert.AreEqual(2, testOcTree.AllIntersections(box2).Count());

            BoundingBox box3 = this.MakeCube(new Vector3(1.5f, 1.5f, 1.5f), 1);

            Assert.AreEqual(2, testOcTree.AllIntersections(box3).Count());

            BoundingBox box4 = this.MakeCube(new Vector3(2.5f, 2.5f, 2.5f), 1);

            Assert.AreEqual(2, testOcTree.AllIntersections(box4).Count());

            BoundingBox box5 = this.MakeCube(new Vector3(3.5f, 3.5f, 3.5f), 1);

            Assert.AreEqual(1, testOcTree.AllIntersections(box5).Count());

            // Box Contains & Intersects
            BoundingBox box6 = this.MakeCube(new Vector3(-0.5f, -0.5f, -0.5f), 2);

            Assert.AreEqual(2, testOcTree.AllIntersections(box6).Count());

            BoundingBox box7 = this.MakeCube(new Vector3(0.5f, 0.5f, 0.5f), 2);

            Assert.AreEqual(3, testOcTree.AllIntersections(box7).Count());

            // Box Contains
            BoundingBox box8 = this.MakeCube(new Vector3(3, 3, 3), 2);

            Assert.AreEqual(2, testOcTree.AllIntersections(box8).Count());

            // Box No Intersection
            BoundingBox box9 = this.MakeCube(new Vector3(0, 0, 3), 1);

            Assert.AreEqual(0, testOcTree.AllIntersections(box9).Count());
        }