Exemple #1
0
        void AddIntoNodes(OctreeItem <T> item)
        {
            var added = false;
            var box   = item.Bound;

            for (int j = 0; j < octants.Length; j++)
            {
                var node = octants[j];

                var cross = node.Bounds.Contains(item.Bound);

                if (cross == AlignedBoxContainmentType.Contains)
                {
                    added = node.Add(ref box, item);
                    break;//if whole item inside octant, do not check the rest of octants
                }
                if (cross == AlignedBoxContainmentType.Intersects)
                {
                    //if item Intersects, ignore it
                }
            }
            if (!added)
            {
                //if can't add to any suboctants will add in parent octant
                AddItem(item);
            }
            //items.Add(item);
        }
Exemple #2
0
        public bool Add(AxisAlignedBox box, T item)
        {
            var oitem = new OctreeItem <T>(ref box, item);

            if (root.Add(ref box, oitem))
            {
                items.Add(item, oitem);
                return(true);
            }
            return(false);
        }
Exemple #3
0
        public bool Add(ref AxisAlignedBox box, OctreeItem <T> item)
        {
            if (this.Bounds.Contains(ref box) == AlignedBoxContainmentType.Disjoint)
            {
                return(false);
            }

            if (items.Count >= MaximumChildren && IsLeaf())
            {
                if (this.Bounds.Contains(item.Bound) == AlignedBoxContainmentType.Contains)
                {
                    //split nodes if can
                    var builded = RebuildTree();
                    if (builded)
                    {
                        //if octants were created
                        //try to add into suboctants
                        AddIntoNodes(item);
                    }
                    else
                    {
                        //if rebuild failed it means we can't add into suboctants
                        //so add item into current node because it Contains() == AlignedBoxContainmentType.Contains
                        AddItem(item);
                    }
                    return(true); //always true, item was added in current octant or suboctants for sure!
                }
                return(false);    //can't contain whole item so upper/bigger octant must contain it
            }
            if (!IsLeaf())        //try to add into some suboctants
            {
                AddIntoNodes(item);
            }
            else    //till saved items less than max count just put in the current node
            {
                AddItem(item);
            }

            return(true);
        }
Exemple #4
0
 void AddItem(OctreeItem <T> item)
 {
     item.SetOwner(this);
     items.Add(item);
 }
Exemple #5
0
 public void Remove(OctreeItem <T> item)
 {
     items.Remove(item);
 }