Beispiel #1
0
    /// <summary>
    /// Split this leaf node by creating left and right children, then moving all the children of
    /// this node into the respective buckets.
    /// </summary>
    private void SplitLeafNode()
    {
        // Create the new children.
        pRight = new KDNode <T>(iDimensions, iBucketCapacity);
        pLeft  = new KDNode <T>(iDimensions, iBucketCapacity);

        // Move each item in this leaf into the children.
        for (int i = 0; i < Size; ++i)
        {
            // Store.
            double[] tOldPoint = tPoints[i];
            T        kOldData  = tData[i];

            // If larger, put it in the right.
            if (tOldPoint[iSplitDimension] > fSplitValue)
            {
                pRight.AddLeafPoint(tOldPoint, kOldData);
            }

            // If smaller, put it in the left.
            else
            {
                pLeft.AddLeafPoint(tOldPoint, kOldData);
            }
        }

        // Wipe the data from this KDNode.
        tPoints = null;
        tData   = null;
    }
Beispiel #2
0
    /// <summary>
    /// Insert a new point into this leaf node.
    /// </summary>
    /// <param name="tPoint">The position which represents the data.</param>
    /// <param name="kValue">The value of the data.</param>
    public void AddPoint(double[] tPoint, T kValue)
    {
        // Find the correct leaf node.
        KDNode <T> pCursor = this;

        while (!pCursor.IsLeaf)
        {
            // Extend the size of the leaf.
            pCursor.ExtendBounds(tPoint);
            pCursor.Size++;

            // If it is larger select the right, or lower,  select the left.
            pCursor = tPoint[pCursor.iSplitDimension] > pCursor.fSplitValue ? pCursor.pRight : pCursor.pLeft;
        }

        // Insert it into the leaf.
        pCursor.AddLeafPoint(tPoint, kValue);
    }