示例#1
0
 //------------------------------------------------------------------------------
 public override void BalanceOctree(ref int NodeCount)
 {
     // test if this
     //create the first cells for this branch
     for (int i = 0; i < (OctreeNode._OCT); i++)
     {
         if (_chld[i] != null)
         {
             if (_chld[i].IsBranch)
             {
                 _chld[i].BalanceOctree(ref NodeCount);
             }
             else
             {
                 // we have a leaf
                 if (_chld[i].Depth != _CUROCTDEPTH)
                 {
                     double       r = _chld[i].R;
                     OctreeLeaf   l = (OctreeLeaf)_chld[i];
                     OctreeBranch b = new OctreeBranch(r, l, this, _chld[i].ePos);
                     int          j = _chld[i].Depth;
                     b.Create(ref j, ref NodeCount);
                     _chld[i] = b;
                     i--;
                 }
             }
         }
     }
 }
示例#2
0
        //------------------------------------------------------------------------------
        // create the octree and call the data
        public void Split()
        {
            int currDepth = 0;

            _Count = 1; // count =1 as we already Created _Tree
            // we have a node to split
            _Tree.Create(ref currDepth, ref _Count);
            //Debug.WriteLine("_Count={0}", _Count);
            //Debug.WriteLine("{0}", _Tree.ToString());
            _Tree.BalanceOctree(ref _Count);
        }
示例#3
0
        //------------------------------------------------------------------------------
        public void Create(ref int currDepth, ref int NodeCount)
        {
            currDepth++;
            if (currDepth > _CUROCTDEPTH)
            {
                _CUROCTDEPTH++;
            }

            int         i    = 0;
            double      r    = R / 2.0d;                    // Depth;
            List <bool> used = new List <bool>(_pts.Count); // avoid testing points

            for (int k = 0; k < used.Capacity; k++)
            {
                used.Add(false);
            }
            OctreeLeaf l = null;

            //create the first cells for this branch
            for (i = 0; i < (OctreeNode._OCT); i++)
            {
                Vectors lmin, lmax;
                CalculateNewBBCoord(i, out lmin, out lmax);
                OctreeNode n = null;
                try
                {
                    l = new OctreeLeaf(NodeCount, currDepth, lmin, lmax, ref used, r, this, (eOctPos)i);
                    n = l;
                    NodeCount++;
                    if (l.Split())
                    {
                        OctreeBranch b = new OctreeBranch(l.R, l, this, l.ePos);
                        b.Create(ref currDepth, ref NodeCount);
                        n = b;
                    }
                }

                catch (Exception s)
                {
                    n = null;
                    Debug.WriteLine(s.Message.ToString());
                }
                AddChild(n, i);
            }

            currDepth--;
        }