Пример #1
0
        public Node(Bspt bspt, int level, Leaf leafLeft)
        {
            this.bspt = bspt;
            if (level == bspt.treeDepth)
            {
                bspt.treeDepth = level + 1;
                if (bspt.treeDepth >= Bspt.MAX_TREE_DEPTH)
                    Console.WriteLine("BSPT tree depth too great:" + bspt.treeDepth.ToString());
            }
            if (leafLeft.count != Bspt.leafCountMax)
                throw new NullReferenceException();
            dim = level % bspt.dimMax;
            leafLeft.sort(dim);
            Leaf leafRight = new Leaf(bspt, leafLeft, Bspt.leafCountMax / 2);
            minLeft = leafLeft.tuples[0].getDimensionValue(dim);
            maxLeft = leafLeft.tuples[leafLeft.count - 1].getDimensionValue(dim);
            minRight = leafRight.tuples[0].getDimensionValue(dim);
            maxRight = leafRight.tuples[leafRight.count - 1].getDimensionValue(dim);

            eleLeft = leafLeft;
            eleRight = leafRight;
            count = Bspt.leafCountMax;
        }
Пример #2
0
          /*
            static float distance(int dim, Tuple t1, Tuple t2) {
            return Math.sqrt(distance2(dim, t1, t2));
            }

            static float distance2(int dim, Tuple t1, Tuple t2) {
            float distance2 = 0.0;
            while (--dim >= 0) {
            float distT = t1.getDimensionValue(dim) - t2.getDimensionValue(dim);
            distance2 += distT*distT;
            }
            return distance2;
            }
          */

          /**
           * Create a bspt with the specified number of dimensions. For a 3-dimensional
           * tree (x,y,z) call new Bspt(3).
           * @param dimMax
           */
        public Bspt(int dimMax)
        {
            this.dimMax = dimMax;
            this.eleRoot = new Leaf(this);
            treeDepth = 1;
        }
Пример #3
0
   /**
    * Iterate through all of your data points, calling addTuple
    * @param tuple
    */
 public void addTuple(Tuple tuple)
 {
     eleRoot = eleRoot.addTuple(0, tuple);
 }
Пример #4
0
 public override Element addTuple(int level, Tuple tuple)
 {
     float dimValue = tuple.getDimensionValue(dim);
     ++count;
     bool addLeft;
     if (dimValue < maxLeft)
     {
         addLeft = true;
     }
     else if (dimValue > minRight)
     {
         addLeft = false;
     }
     else if (dimValue == maxLeft)
     {
         if (dimValue == minRight)
         {
             if (eleLeft.count < eleRight.count)
                 addLeft = true;
             else
                 addLeft = false;
         }
         else
             addLeft = true;
     }
     else if (dimValue == minRight)
         addLeft = false;
     else
     {
         if (eleLeft.count < eleRight.count)
             addLeft = true;
         else
             addLeft = false;
     }
     if (addLeft)
     {
         if (dimValue < minLeft)
             minLeft = dimValue;
         else if (dimValue > maxLeft)
             maxLeft = dimValue;
         eleLeft = eleLeft.addTuple(level + 1, tuple);
     }
     else
     {
         if (dimValue < minRight)
             minRight = dimValue;
         else if (dimValue > maxRight)
             maxRight = dimValue;
         eleRight = eleRight.addTuple(level + 1, tuple);
     }
     return this;
 }