예제 #1
0
        //return copy of child node array - not sure if copy function is correct

        public PointOctree[] getChildren()
        {
            if (children != null)
            {
                PointOctree[] clones = new PointOctree[8];
                Array.Copy(children, 0, clones, 0, 8);
                return(clones);
            }
            return(null);
        }
예제 #2
0
        //private bool isAutoReducing = false;



        //constructor // :base is the same as super to pass down to AABB constructor

        public PointOctree(PointOctree p, Vector3d o, double halfSize) :

            base(Vector3d.Add(o, new Vector3d(halfSize, halfSize, halfSize)), new Vector3d(halfSize, halfSize, halfSize))
        {
            this.parent      = p;
            this.halfSize    = halfSize;
            this.size        = halfSize + halfSize;
            this.offset      = o;
            this.numChildren = 0;

            if (parent != null)
            {
                depth       = parent.depth + 1;
                minNodeSize = parent.minNodeSize;
            }
        }
예제 #3
0
        public bool addPoint(Vector3d p)
        {
            //check if pt is inside cube - write code for contains point

            if (containsPoint(p))
            {
                if (halfSize <= minNodeSize)
                {
                    if (points == null)
                    {
                        points = new List <Vector3d>();
                    }

                    points.Add(p);

                    return(true);
                }
                else
                {
                    Vector3d plocal = Vector3d.Subtract(p, offset);

                    if (children == null)
                    {
                        children = new PointOctree[8];
                    }


                    int octant = getOctantID(plocal);
                    if (children[octant] == null)
                    {
                        Vector3d off = Vector3d.Add(offset, new Vector3d(
                                                        (octant & 1) != 0 ? halfSize : 0,
                                                        (octant & 2) != 0 ? halfSize : 0,
                                                        (octant & 4) != 0 ? halfSize : 0));

                        children[octant] = new PointOctree(this, off, halfSize * 0.5);

                        numChildren++;
                    }
                    return(children[octant].addPoint(p));
                }
            }
            return(false);
        }