Exemplo n.º 1
0
        /// <summary>
        /// Construct a new nearest neighbour iterator.
        /// </summary>
        /// <param name="pRoot">The root of the tree to begin searching from.</param>
        /// <param name="tSearchPoint">The point in n-dimensional space to search.</param>
        /// <param name="kDistance">The distance function used to evaluate the points.</param>
        /// <param name="iMaxPoints">The max number of points which can be returned by this iterator.  Capped to max in tree.</param>
        /// <param name="fThreshold">Threshold to apply to the search space.  Negative numbers indicate that no threshold is applied.</param>
        public NearestNeighbour(KDNode <T> pRoot, double[] tSearchPoint, DistanceFunctions kDistance, int iMaxPoints, double fThreshold)
        {
            // Check the dimensionality of the search point.
            if (tSearchPoint.Length != pRoot.iDimensions)
            {
                throw new Exception("Dimensionality of search point and kd-tree are not the same.");
            }

            // Store the search point.
            this.tSearchPoint = new double[tSearchPoint.Length];
            Array.Copy(tSearchPoint, this.tSearchPoint, tSearchPoint.Length);

            // Store the point count, distance function and tree root.
            this.iPointsRemaining   = Math.Min(iMaxPoints, pRoot.Size);
            this.fThreshold         = fThreshold;
            this.kDistanceFunction  = kDistance;
            this.pRoot              = pRoot;
            this.iMaxPointsReturned = iMaxPoints;
            _CurrentDistance        = -1;

            // Create an interval heap for the points we check.
            this.pEvaluated = new IntervalHeap <T>();

            // Create a min heap for the things we need to check.
            this.pPending = new MinHeap <KDNode <T> >();
            this.pPending.Insert(0, pRoot);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reset the iterator.
        /// </summary>
        public void Reset()
        {
            // Store the point count and the distance function.
            this.iPointsRemaining = Math.Min(iMaxPointsReturned, pRoot.Size);
            _CurrentDistance      = -1;

            // Create an interval heap for the points we check.
            this.pEvaluated = new IntervalHeap <T>();

            // Create a min heap for the things we need to check.
            this.pPending = new MinHeap <KDNode <T> >();
            this.pPending.Insert(0, pRoot);
        }