/// <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> public NearestNeighbour(Node pRoot, double[] tSearchPoint) { // Check the dimensionality of the search point. if (tSearchPoint.Length != 4) { 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(10, pRoot.Size); this.pRoot = pRoot; _CurrentDistance = -1; // Create an interval heap for the points we check. this.pEvaluated = new IntervalHeap(); // Create a min heap for the things we need to check. this.pPending = new MinHeap(); this.pPending.Insert(0, pRoot); }
/// <summary> /// Reset the iterator. /// </summary> public void Reset() { // Store the point count and the distance function. this.iPointsRemaining = Math.Min(10, pRoot.Size); _CurrentDistance = -1; // Create an interval heap for the points we check. this.pEvaluated = new IntervalHeap(); // Create a min heap for the things we need to check. this.pPending = new MinHeap(); this.pPending.Insert(0, pRoot); }