public static KDNode BuildTree(List<IGeometry> geometry, BoundingBox area) { KDNode root = new KDNode(area, geometry.ToList()); BuildTree(root, 1, Axis.X); return root; }
private static void BuildTree(KDNode node, uint depth, Axis axis) { if (depth > MaxDepth || node.Geometry.Count < MinTrianglesPerLeaf) return; node.SeparationPoint = 0.5; var boxes = node.Boundaries.SplitInHalf(axis); MessageDelegator.Instance.RaiseNodeCreated(node, boxes); Thread.Sleep(1000); var leftGeometry = node.Geometry.TakeIf(triangle => triangle.IsContainedIn(boxes.A)); var rightGeometry = node.Geometry.TakeAll(); node.ChildNodes = new KDNode[2]; node.Left = new KDNode(boxes.A, leftGeometry); node.Right = new KDNode(boxes.B, rightGeometry); BuildTree(node.Left, depth + 1, axis.Next2D()); BuildTree(node.Right, depth + 1, axis.Next2D()); return; }
internal void RaiseNodeCreated(KDNode nodeSender, Pair<BoundingBox> splittedBox) { if (this.KDNodeCreated != null) this.KDNodeCreated(this, new KDTrees.KDNode.KDNodeCreatedEventArgs(splittedBox)); }