private bool DivideSelf() { var minPoint = _bounds.MinPoint; var maxPoint = _bounds.MaxPoint; var _size_x = (maxPoint.X - minPoint.X + 1) / 2; var _size_y = (maxPoint.Y - minPoint.Y + 1) / 2; var _size_z = (maxPoint.Z - minPoint.Z + 1) / 2; _children = new OctoTreeNode <T> [8]; _children[0] = new OctoTreeNode <T>( Cuboid.FromPoints( new Point3D(minPoint.X, minPoint.Y, minPoint.Z), new Point3D(maxPoint.X - _size_x, maxPoint.Y - _size_y, maxPoint.Z - _size_z) ), _capacity); _children[1] = new OctoTreeNode <T>( Cuboid.FromPoints( new Point3D(minPoint.X, minPoint.Y, minPoint.Z + _size_z), new Point3D(maxPoint.X - _size_x, maxPoint.Y - _size_y, maxPoint.Z) ), _capacity); _children[2] = new OctoTreeNode <T>( Cuboid.FromPoints( new Point3D(minPoint.X + _size_x, minPoint.Y, minPoint.Z + _size_z), new Point3D(maxPoint.X, maxPoint.Y - _size_y, maxPoint.Z) ), _capacity); _children[3] = new OctoTreeNode <T>( Cuboid.FromPoints( new Point3D(minPoint.X + _size_x, minPoint.Y, minPoint.Z), new Point3D(maxPoint.X, maxPoint.Y - _size_y, maxPoint.Z - _size_z) ), _capacity); _children[4] = new OctoTreeNode <T>( Cuboid.FromPoints( new Point3D(minPoint.X + _size_x, minPoint.Y + _size_y, minPoint.Z), new Point3D(maxPoint.X, maxPoint.Y, maxPoint.Z - _size_z) ), _capacity); _children[5] = new OctoTreeNode <T>( Cuboid.FromPoints( new Point3D(minPoint.X + _size_x, minPoint.Y + _size_y, minPoint.Z + _size_z), new Point3D(maxPoint.X, maxPoint.Y, maxPoint.Z) ), _capacity); _children[6] = new OctoTreeNode <T>( Cuboid.FromPoints( new Point3D(minPoint.X, minPoint.Y + _size_y, minPoint.Z + _size_z), new Point3D(maxPoint.X - _size_x, maxPoint.Y, maxPoint.Z) ), _capacity); _children[7] = new OctoTreeNode <T>( Cuboid.FromPoints( new Point3D(minPoint.X, minPoint.Y + _size_y, minPoint.Z), new Point3D(maxPoint.X - _size_x, maxPoint.Y, maxPoint.Z - _size_z) ), _capacity); foreach (var leaf in _leafs) { foreach (var child in _children) { if (child.AddNode(leaf.Point, leaf.Value)) { break; } } } _innerNode = true; _leafs = null; return(true); }
private OctoTree(Cuboid bound) { _root = new OctoTreeNode <T>(bound, 1); }