Пример #1
0
        public static KDNode BuildTree(List<IGeometry> geometry, BoundingBox area)
        {
            KDNode root = new KDNode(area, geometry.ToList());

            BuildTree(root, 1, Axis.X);

            return root;
        }
Пример #2
0
        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;
        }
Пример #3
0
 internal void RaiseNodeCreated(KDNode nodeSender, Pair<BoundingBox> splittedBox)
 {
     if (this.KDNodeCreated != null)
         this.KDNodeCreated(this, new KDTrees.KDNode.KDNodeCreatedEventArgs(splittedBox));
 }