public OctreeNode(float xMax, float xMin, float yMax, float yMin, float zMax, float zMin, int maximumItems, float minimumSize) { Bounds = new OctreeBox(xMax, xMin, yMax, yMin, zMax, zMin); MaxItems = maximumItems; MinSize = minimumSize; Items = ArrayList.Synchronized(new ArrayList(10)); }
public void Subdivide_Test() { Point[] pts = CreateRandomPointSet(100); OctreeBox testBox; // testBox = new OctreeBox(pts.ToList(), 0); Assert.AreEqual(100, testBox.Points.Count()); testBox.Subdivide(); int sum = 0; foreach (OctreeBox box in testBox.SubBoxes) { foreach (Point p in box.Points) { sum++; if (!box.PointWithin(p)) { Assert.Fail(String.Format("The Point {0} does not lie within box {1}!", p.ToString(), box.ToString())); } } } Assert.AreEqual(100, sum, 0, "Obviously not all points have been put to one box!"); // boundaries testBox = new OctreeBox(pts.ToList(), 5); OctreeBox current = testBox; while (!current.IsLeaf) { double widthX = current.Xmax - current.Xmin; double widthY = current.Ymax - current.Ymin; double widthZ = current.Zmax - current.Zmin; foreach (OctreeBox box in current.SubBoxes) { Assert.IsTrue(box.Xmax > box.Xmin, "Max should be greater than min!"); Assert.IsTrue(box.Ymax > box.Ymin, "Max should be greater than min!"); Assert.IsTrue(box.Zmax > box.Zmin, "Max should be greater than min!"); Assert.AreEqual((box.Xmax - box.Xmin) / 2 + box.Xmin, box.Xmean); Assert.AreEqual((box.Ymax - box.Ymin) / 2 + box.Ymin, box.Ymean); Assert.AreEqual((box.Zmax - box.Zmin) / 2 + box.Zmin, box.Zmean); Assert.AreEqual(widthX / 2, box.Xmax - box.Xmin, 0.0000000000001); Assert.AreEqual(widthY / 2, box.Ymax - box.Ymin, 0.0000000000001); Assert.AreEqual(widthZ / 2, box.Zmax - box.Zmin, 0.0000000000001); } current = current.SubBoxes[0]; } }
public void PointWithin_Test() { Point[] testPoints = CreateMinimalPointSet(); Point a = new Point(0.5, 0.5, 0.5); Point b = new Point(-2, 1, 0.5); OctreeBox box = new OctreeBox(testPoints.ToList(), 0); Assert.IsTrue(box.PointWithin(a)); Assert.IsFalse(box.PointWithin(b)); }
public void MinimumSquareDistanceTo_Test() { Point[] testPoints = CreateMinimalPointSet(); Point a = new Point(0.5, 0.5, 0.5); Point b = new Point(-2, 1, 0.5); Point c = new Point(3, 1, 0); Point d = new Point(1, 17, 0); OctreeBox box = new OctreeBox(testPoints.ToList(), 0); Assert.AreEqual(0, box.MinimumDistanceTo(a)); Assert.AreEqual(2, box.MinimumDistanceTo(b)); Assert.AreEqual(2, box.MinimumDistanceTo(c)); Assert.AreEqual(16, box.MinimumDistanceTo(d)); }
public void OctreeBox_Test() { Point[] pts = CreateRandomPointSet(100); OctreeBox testBox; testBox = new OctreeBox(pts.ToList(), 0); Assert.IsTrue(testBox.IsLeaf, "Box should be a leaf!"); testBox = new OctreeBox(pts.ToList(), 3); // Leafs Assert.IsFalse(testBox.IsLeaf, "Box should not be a leaf!"); Assert.IsFalse(testBox.SubBoxes[0].IsLeaf, "Subbox should not be a leaf!"); Assert.IsFalse(testBox.SubBoxes[0].SubBoxes[0].IsLeaf, "Sub-Subbox should not be a leaf!"); Assert.IsTrue(testBox.SubBoxes[0].SubBoxes[0]. SubBoxes[0].IsLeaf, "Sub-Sub-Subbox should be a leaf!"); Assert.AreEqual(8, testBox.SubBoxes.Length); }
public ArrayList GetNode(OctreeBox rect, ArrayList nodes) { if (Branch == null) { var things = Items.GetEnumerator(); while (things.MoveNext()) { var qtl = (OctreeLeaf)things.Current; if (qtl != null && rect.PointWithinBounds(qtl.X, qtl.Y, qtl.Z)) { nodes.Add(qtl.LeafObject); } } } else { foreach (var t in Branch.Where(t => t.Bounds.Within(rect))) { t.GetNode(rect, nodes); } } return(nodes); }
public ArrayList GetNode(OctreeBox rect, ArrayList nodes) { if (Branch == null) { var things = Items.GetEnumerator(); while (things.MoveNext()) { var qtl = (OctreeLeaf)things.Current; if (qtl != null && rect.PointWithinBounds(qtl.X, qtl.Y, qtl.Z)) nodes.Add(qtl.LeafObject); } } else { foreach (var t in Branch.Where(t => t.Bounds.Within(rect))) { t.GetNode(rect, nodes); } } return nodes; }
public bool Within(OctreeBox box) { return Within(box.Top, box.Left, box.Bottom, box.Right, box.Front, box.Back); }
public bool Within(OctreeBox box) { return(Within(box.Top, box.Left, box.Bottom, box.Right, box.Front, box.Back)); }