Exemple #1
0
 public void Test(int i0, int iMid, PointLocalization owner, BoundingBoxCode b)
 {
     for (int i = 0; i < owner.Codes.Length; i++)
     {
         bool innen  = b.IsInside(owner.Codes[i]);
         bool innen2 = i >= i0 && i < iMid;
         if (innen != innen2)
         {
             throw new ApplicationException();
         }
     }
 }
Exemple #2
0
            /*
             * static int MyBinarySearch(GeomBinTreeBranchCode[] array, int i0, int Length, GeomBinTreeBranchCode searchValue) {
             *  if(Length <= 0)
             *      return -1;
             *
             *  if (array[i0] >= searchValue)
             *      return i0;
             *  if (array[i0 + Length - 1] < searchValue)
             *      return i0 + Length;
             *
             *  if (Length >= 2) {
             *      int ifnd = int.MinValue;
             *      MyBinarySearchRec(array, i0, Length, i0, Length, ref searchValue, out ifnd);
             *      return ifnd;
             *  } else {
             *      if (array[i0] >= searchValue)
             *          return i0;
             *      else
             *          return i0 + 1;
             *  }
             * }
             *
             * static void MyBinarySearchRec(GeomBinTreeBranchCode[] array, int i0, int Length, int _i0, int _Len, ref GeomBinTreeBranchCode searchValue, out int ifnd) {
             *  if( Length < 2)
             *      throw new ApplicationException();
             *  int iMid = i0 + Length / 2;
             *
             *  if (array[iMid] >= searchValue && array[iMid - 1] < searchValue) {
             *      ifnd = iMid;
             *  } else {
             *      if (array[iMid] >= searchValue) {
             *          MyBinarySearchRec(array, i0, Length, iMid, i0 + _Len - iMid, ref searchValue, out ifnd);
             *      } else {
             *          MyBinarySearchRec(array, i0, Length, i0, iMid - i0, ref searchValue, out ifnd);
             *      }
             *
             *  }
             *
             *  //if( iMid == i0 && array[iMid] >= searchValue && ) {
             *  //    return i0;
             *  //}
             *  //if(
             * }*/

            public void InitRecursive(GeomBinTreeBranchCode BoxCode, uint shifti, PointLocalization owner, int i0, int Len, uint RecDepth)
            {
                GeomBinTreeBranchCode BoxB = BoxCode; BoxB.Code |= shifti;


                int __iMid;

                for (__iMid = i0; __iMid < (i0 + Len); __iMid++)
                {
                    if (owner.Codes[__iMid].Code >= BoxB.Code)
                    {
                        break;
                    }
                    // if there is a performance problem, this linear search should be exchanged by a binary one
                }
                this.iMid = __iMid;

                //{
                //    GeomBinTreeBranchCode search = BoxB;
                //    search.Code -= 1;
                //    int iMid2 = MyBinarySearch(owner.Codes, 0, owner.Codes.Length, search);
                //    if (iMid2 != iMid)
                //        throw new ApplicationException();
                //}



                //if (iMid < 0) iMid = ~iMid;

                int LenLeft = iMid - i0;
                int LenRigt = Len + i0 - iMid;

                {
                    /*
                     * // test left
                     * {
                     *  BoundingBoxCode cdLeft;
                     *  cdLeft.Branch = BoxCode;
                     *  cdLeft.SignificantBits = RecDepth + 1;
                     *  Test(i0, iMid, owner, cdLeft);
                     * }
                     *
                     * // test right
                     * {
                     *  BoundingBoxCode cdRight;
                     *  cdRight.Branch = BoxB;
                     *  cdRight.SignificantBits = RecDepth + 1;
                     *  Test(iMid, i0 + Len, owner, cdRight);
                     * }
                     */
                }

                if (shifti == 1)
                {
                    return; // reached max. supported tree depth
                }
                shifti = shifti >> 1;


                if (LenLeft > 0)
                {
                    Left = new TreeNodeTmp();
                    Left.InitRecursive(BoxCode, shifti, owner, i0, LenLeft, RecDepth + 1);
                }
                if (LenRigt > 0)
                {
                    Right = new TreeNodeTmp();
                    Right.InitRecursive(BoxB, shifti, owner, iMid, LenRigt, RecDepth + 1);
                }
            }