/// <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="distance_function">The distance function used to evaluate the points.</param> /// <param name="max_result_count">The max number of points which can be returned by this iterator. Capped to max in tree.</param> /// <param name="threshold">Threshold to apply to the search space. Negative numbers indicate that no threshold is applied.</param> public NearestNeighbourEnumerator(DistanceType distance_zero, KDNode <DomainType, DistanceType, LabelType> pRoot, DomainType[] tSearchPoint, IFunctionDistance <DomainType[], DistanceType> distance_function, int max_result_count, DistanceType threshold, bool use_threshold) { // Check the dimensionality of the search point. if (tSearchPoint.Length != pRoot.d_dimension_count) { throw new Exception("Dimensionality of search point and kd-tree are not the same."); } //this.algebra_domain = algebra; // Store the search point. this.search_point = new DomainType[tSearchPoint.Length]; Array.Copy(tSearchPoint, this.search_point, tSearchPoint.Length); // Store the point count, distance function and tree root. this.iPointsRemaining = Math.Min(max_result_count, pRoot.Size); this.fThreshold = threshold; this.d_use_threshold = use_threshold; this.distance_function = distance_function; this.pRoot = pRoot; this.iMaxPointsReturned = max_result_count; this._CurrentDistance = distance_zero; this.d_current_distance_set = false; this.distance_zero = distance_zero; // Create an interval heap for the points we check. this.pEvaluated = new IntervalHeap <LabelType, DistanceType>(); // Create a min heap for the things we need to check. this.pPending = new MinHeap <KDNode <DomainType, DistanceType, LabelType>, DistanceType>(); this.pPending.Insert(distance_zero, pRoot); }
/// <summary> /// Reset the iterator. /// </summary> public void Reset() { // Store the point count and the distance function. this.iPointsRemaining = Math.Min(iMaxPointsReturned, pRoot.Size); _CurrentDistance = distance_zero; d_current_distance_set = false; // Create an interval heap for the points we check. this.pEvaluated = new IntervalHeap <LabelType, DistanceType>(); // Create a min heap for the things we need to check. this.pPending = new MinHeap <KDNode <DomainType, DistanceType, LabelType>, DistanceType>(); this.pPending.Insert(distance_zero, pRoot); }