/// <summary> /// Create empty kd-tree /// </summary> /// <param name="dimensions"></param> /// <param name="policy"></param> public KdTree(int dimensions, Subdivision.ISubdivisionPolicy policy) { _subdiv_policy = policy; _root = new KdNode <T>(); this.InitializeNode(_root, dimensions); _cls = new Searches.ClosestLeafSearch <T>(_root); _count = 0; }
/// <summary> /// Instance a new kd-tree with the given collection of points and a subdivision policy. /// </summary> public KdTree(IEnumerable <T> vecs, Subdivision.ISubdivisionPolicy policy) { _subdiv_policy = policy; _root = new KdNode <T>(); this.InitializeNode(_root, vecs); _cls = new Searches.ClosestLeafSearch <T>(_root); _count = _root.Vectors.Count; this.TrySplit(_root); }
/// <summary> /// Optimize tree using the given subdivision policy. /// </summary> public void Optimize(Subdivision.ISubdivisionPolicy policy) { _subdiv_policy = policy; if (this.Count > 0) { // Save all elements T[] elements = new T[this.Count]; this.CopyTo(elements, 0); // Clean-Up this.Clear(); // note: this sets number of elements to be zero. // Reconstruct this.InitializeNode(_root, elements); this.TrySplit(_root); // Update missing info _count = elements.Length; } }
/// <summary> /// Instance a new kd-tree with the given collection of points and a subdivision policy. /// </summary> /// <remarks> /// Helps scripting languages that do not support constructor overloading. /// </remarks> public static KdTree <T> FromEnumerable(IEnumerable <T> vecs, Subdivision.ISubdivisionPolicy policy) { return(new KdTree <T>(vecs, policy)); }
public KdMap(int dimensions, Subdivision.ISubdivisionPolicy policy) { _kdtree = new KdTree <LocatablePair <TKey, TValue> >(dimensions, policy); _es = new Searches.ExactSearch <LocatablePair <TKey, TValue> >(_kdtree.Root); _es.CountLimit = 1; }