Beispiel #1
0
 /// <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;
 }
Beispiel #2
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);
 }
Beispiel #3
0
 /// <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;
     }
 }
Beispiel #4
0
 /// <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));
 }
Beispiel #5
0
 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;
 }