Example #1
0
        /// <summary> This method splits the node into four branch, and disperses
        /// the items into the branch. The split only happens if the
        /// boundary size of the node is larger than the minimum size (if
        /// we care). The items in this node are cleared after they are put
        /// into the branch.
        /// </summary>
        protected internal void split()
        {
            // Make sure we're bigger than the minimum, if we care,
            if (minSize != NO_MIN_SIZE)
                if (Math.Abs(bounds.Top - bounds.Bottom) < minSize &&
                    Math.Abs(bounds.Right - bounds.Left) < minSize &&
                    Math.Abs(bounds.Front - bounds.Back) < minSize)
                    return;

            float nsHalf = (float)(bounds.Top - (bounds.Top - bounds.Bottom) * 0.5);
            float ewHalf = (float)(bounds.Right - (bounds.Right - bounds.Left) * 0.5);
            float fbHalf = (float)(bounds.Front - (bounds.Front - bounds.Back) * 0.5);

            branch = new OctreeNode[8];

            branch[0] = new OctreeNode(ewHalf, bounds.Left, bounds.Front, fbHalf, bounds.Top, nsHalf, maxItems); //left-front-top
            branch[1] = new OctreeNode(bounds.Right, ewHalf, bounds.Front, fbHalf, bounds.Top, nsHalf, maxItems);
            branch[2] = new OctreeNode(ewHalf, bounds.Left, bounds.Front, fbHalf, nsHalf, bounds.Bottom, maxItems);
            branch[3] = new OctreeNode(bounds.Right, ewHalf, bounds.Front, fbHalf, nsHalf, bounds.Bottom, maxItems);

            branch[4] = new OctreeNode(ewHalf, bounds.Left, fbHalf, bounds.Back, bounds.Top, nsHalf, maxItems); //left-back-top
            branch[5] = new OctreeNode(bounds.Right, ewHalf, fbHalf, bounds.Back, bounds.Top, nsHalf, maxItems);
            branch[6] = new OctreeNode(ewHalf, bounds.Left, fbHalf, bounds.Back, nsHalf, bounds.Bottom, maxItems);
            branch[7] = new OctreeNode(bounds.Right, ewHalf, fbHalf, bounds.Back, nsHalf, bounds.Bottom, maxItems);

            ArrayList temp = (ArrayList)items.Clone();
            items.Clear();
            IEnumerator things = temp.GetEnumerator();
            while (things.MoveNext())
            {
                AddNode((OctreeLeaf)things.Current);
            }
        }
Example #2
0
 public Octree(float xMax, float xMin, float yMax, float yMin, float zMax, float zMin, int maxItems, float minSize)
 {
     top = new OctreeNode(xMax, xMin, yMax, yMin, zMax, zMin, maxItems, minSize);
 }