示例#1
0
 //------------------------------------------------------------------------------
 public override void findAdjacent(OctreeBranch _Tree)
 {
     for (int i = 0; i < 3; i++)
     {
         for (int j = 0; j < 3; j++)
         {
             for (int k = 0; k < 3; k++)
             {
                 if (_adjacent[i][j][k] == null)
                 {
                     // find the adj at my depth
                     // so global pos of adj would be
                     int        l = (i - 1); // i=0,1,2 => l=-1,0,1
                     int        m = (j - 1);
                     int        n = (k - 1);
                     OctreeNode f = _Tree.findIJK(Ipos + l, Jpos + m, Kpos + n);
                     if (f != null)
                     {
                         if (f.IsBranch == false)
                         {
                             _adjacent[i][j][k] = f;
                             if (_adjacent[l + 1][m + 1][n + 1].getAdjacentNOde(l, m, n) == null)
                             {
                                 _adjacent[l + 1][m + 1][n + 1].setAdjacentNOde(l * -1, m * -1, n * -1, this);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
示例#2
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--;
                 }
             }
         }
     }
 }
示例#3
0
        protected OctreeNode[][][] _adjacent;      // connected nodes on same level


        //------------------------------------------------------------------------------
        //constructor
        public OctreeNode(int mID, int mDepth, Vectors min, Vectors max, double r, OctreeBranch parent, eOctPos p)
        {
            _id        = mID;
            _depth     = mDepth;
            _bbMax     = new Vectors(max);
            _bbMin     = new Vectors(min);
            _vnorm     = new Vectors();
            _eigenvec2 = new Vectors();
            _eigenvec3 = new Vectors();
            _sigma     = new Vectors();
            _Ipos      = -1;
            _Jpos      = -1;
            _Kpos      = -1;
            _rg        = new Vectors();
            _adjacent  = new OctreeNode[3][][];
            for (int i = 0; i < 3; i++)
            {
                _adjacent[i] = new OctreeNode[3][];
                for (int j = 0; j < 3; j++)
                {
                    _adjacent[i][j] = new OctreeNode[3];
                    for (int k = 0; k < 3; k++)
                    {
                        _adjacent[i][j][k] = null;
                    }
                }
            }
            _radius = r;
            _parent = parent;
            _ePos   = p;
        }
示例#4
0
        //------------------------------------------------------------------------------
        public override void findAdjacent(OctreeBranch _Tree)
        {
            /*   if(ID!=0)
             * {
             * // TODO
             * }*/

            foreach (OctreeNode o in _chld)
            {
                if (o != null)
                {
                    o.findAdjacent(_Tree);
                }
            }
        }
示例#5
0
        //
        public OctreeBranch(double r, OctreeLeaf l, OctreeBranch parent, eOctPos p)
            : base(l.ID, l.Depth, l.vMin, l.vMax, r, parent, p)
        {
            _pts = new List <int>(l.PtsIdx);

            _chld = new List <OctreeNode>(OctreeNode._OCT);// the oct part
            _DispLstCentreNorm = -1;

            // we dont need to do PCA for Branches they come from leaves
            // which Are already calculated
            _vnorm     = l.Norm;
            _eigenvec2 = l.EigenVec2;
            _eigenvec3 = l.EigenVec3;
            _rg        = l.RadiiGyration;
            _sigma     = l.Sigma;
        }
示例#6
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--;
        }
示例#7
0
        //------------------------------------------------------------------------------
        // Init
        public void Init()
        {
            Trace.WriteLine("_Octree-Init-Start");
            Vectors    bbmin, bbmax;
            int        c   = PtData.ptCloud_Xcount();
            List <int> pts = new List <int>(c);

            PtData.ptCloud_min(out bbmin);
            PtData.ptCloud_max(out bbmax);
            int i = 0;

            for (; i < c; i++)
            {
                pts.Add(i);
            }
            double xr = Math.Abs(bbmax._X - bbmin._X);
            double yr = Math.Abs(bbmax._Y - bbmin._Y);
            double zr = Math.Abs(bbmax._Z - bbmin._Z);
            double r  = xr;

            if (r < yr)
            {
                r = yr;
            }
            if (r < zr)
            {
                r = zr;
            }
            //make our bounding box bigger than the data
            r += C.CONST.EPSILON;
            bbmin.addXYZ(-C.CONST.EPSILON, -C.CONST.EPSILON, -C.CONST.EPSILON);
            bbmax.addXYZ(C.CONST.EPSILON, C.CONST.EPSILON, C.CONST.EPSILON);

            Vectors newbbmax = new Vectors(bbmin._X + r, bbmin._Y + r, bbmin._Z + r);

            _Tree = new OctreeBranch(0, 0, bbmin, newbbmax, pts, r);

            DateTime startTime = DateTime.Now;

            Trace.WriteLine("_Octree-Split-Start" + startTime.ToString());
            Split();
            DateTime stopTime = DateTime.Now;
            TimeSpan duration = stopTime - startTime;

            Trace.WriteLine("_Octree-Split-End:" + duration.ToString());
            Vectors idx  = new Vectors(_Tree.vMin);
            double  minr = (r / (Math.Pow(2.0d, (double)(OctreeNode._CUROCTDEPTH))));//((double)(OctreeNode._CUROCTDEPTH) * (OctreeNode._CUROCTDEPTH) * (OctreeNode._CUROCTDEPTH)));

            //idx._X+= minr;
            //idx._Y+= minr;
            //idx._Z+= minr;
            // calculate its gobal position
            _Tree.GlobalPosition(minr, idx);
            // Find the Adjcent cells
            startTime = DateTime.Now;
            Trace.WriteLine("_Octree-Adjacent-Start" + startTime.ToString());
            AdjacentLeaf();

            //AdjacentTree();
            stopTime = DateTime.Now;
            duration = stopTime - startTime;
            Trace.WriteLine("_Octree-Adjacent-End:" + duration.ToString());
            Trace.WriteLine("_Octree-Init-End");
        }
示例#8
0
        //------------------------------------------------------------------------------
        // Constructors
        public OctreeLeaf(int ID, int depth, Vectors min, Vectors max, ref List <bool> used, double R, OctreeBranch parent, eOctPos p)
            : base(ID, depth, min, max, R, parent, p)
        {
            PtData.findptsCube(_bbMin, _bbMax, R, p, ref used, parent.PtsIdx, out _pts);

            if (_pts.Count > 0)
            {
                _DisplayListPT  = -1;
                _DisplayListLN  = -1;
                _DisplayListCTN = -1;
                _PCA_result     = false;
                _SurfaceNum     = -1;

                CalculateSigma();

                if (OctreeNode._MINPTSPCA <= NumPts)
                {
                    _PCA_result = DoPCATest();
                }
            }
            else
            {
                throw new Exception("Invalid Leaf pts: " + _pts.Count);
            }
        }
示例#9
0
 //------------------------------------------------------------------------------
 public abstract void findAdjacent(OctreeBranch _TreeRoot);