/// <summary> /// inserts the shape into the tree /// </summary> /// <param name="shape"></param> public void insert(Origen shape) { //insert the shape if there is no shape in this branch of the tree if (null == null) { // data = shape; } else { //theres data in this branch so decide which branch the shape will need to go to byte x, y, z; short ix, iy, iz; //check to see which side its on on the x axis if (shape.OrigenX > OrigenX) { x = 1; ix = 1; } else { x = 0; ix = -1; } if (shape.OrigenY > OrigenY) { y = 1; iy = 1; } else { y = 0; iy = -1; } if (shape.OrigenZ > OrigenZ) { z = 1; iz = 1; } else { z = 0; iz = -1; } //check to see if the branch in x,y,z is null and if it is construct it if (nodes[x][y][z] == null) { nodes[x][y][z] = new Octree(OrigenX + ix, OrigenY + iy, OrigenZ + iz); } //insert in the new tree nodes[x][y][z].insert(shape); } }
/// <summary> /// defualt constructor--constructs an empty octree /// </summary> public Octree(float origenX, float origenY, float origenZ) : base(origenX, origenY, origenZ) { //construct the tree and its nodes nodes = new Octree[2][][]; for (int i = 0; i < 2; i++) { nodes[i] = new Octree[2][]; for (int j = 0; j < 2; j++) { nodes[i][j] = new Octree[2]; } } bucket = null; }