public Octree() { root = null; }
public Octree(List <Point3D> d) { root = new OctreeNode(d); }
public OctreeNode(List <Point3D> d) { foreach (var v in d) { sumx += v.X; sumy += v.Y; sumz += v.Z; if (minc.X > v.X) { minc.X = v.X; } if (minc.Y > v.Y) { minc.Y = v.Y; } if (minc.Z > v.Z) { minc.Z = v.Z; } if (maxc.X < v.X) { maxc.X = v.X; } if (maxc.Y < v.Y) { maxc.Y = v.Y; } if (maxc.Z < v.Z) { maxc.Z = v.Z; } } gCenter.X = sumx / d.Count; gCenter.Y = sumy / d.Count; gCenter.Z = sumz / d.Count; if (d.Count <= MAX_POINTS) //把数据放入该结点的数组里 { data = d; iShowListNum = GL.GenLists(1); GL.NewList(iShowListNum, ListMode.Compile); GL.Begin(PrimitiveType.Points); foreach (var v in data) { GL.Color3(v.PointColor); GL.Vertex3(v.X, v.Y, v.Z); } GL.End(); GL.EndList(); } else //把数据放到子结点里 { for (int i = 0; i < 8; i++) { l[i] = new List <Point3D>(); } for (int i = 0; i < d.Count; i++) { if (d[i].X < gCenter.X && d[i].Y < gCenter.Y && d[i].Z < gCenter.Z) { l[0].Add(d[i]); } else if (d[i].X <gCenter.X && d[i].Y> gCenter.Y && d[i].Z < gCenter.Z) { l[1].Add(d[i]); } else if (d[i].X > gCenter.X && d[i].Y < gCenter.Y && d[i].Z < gCenter.Z) { l[2].Add(d[i]); } else if (d[i].X > gCenter.X && d[i].Y > gCenter.Y && d[i].Z < gCenter.Z) { l[3].Add(d[i]); } else if (d[i].X < gCenter.X && d[i].Y <gCenter.Y && d[i].Z> gCenter.Z) { l[4].Add(d[i]); } else if (d[i].X <gCenter.X && d[i].Y> gCenter.Y && d[i].Z > gCenter.Z) { l[5].Add(d[i]); } else if (d[i].X > gCenter.X && d[i].Y <gCenter.Y && d[i].Z> gCenter.Z) { l[6].Add(d[i]); } else { l[7].Add(d[i]); } } child = new OctreeNode[8]; for (int i = 0; i < 8; i++) { child[i] = new OctreeNode(l[i]); } } }