Exemple #1
0
        public void AppendIntoList(FastLinkedList <T> list)
        {
            if (list == null)
            {
                return;
            }
            if (list._First == null)
            {
                return;
            }

            if (_First == null)
            {
                _First = list._First;
                _Last  = list._Last;
            }
            else
            {
                Node temp = _Last;
                _Last.Next          = list._First;
                _Last.Next.Previous = _Last;
                _Last = list._Last;
                if (_Last.Previous == null)
                {
                    _Last.Previous = temp;
                }
            }

            length = list.length + length;
        }
Exemple #2
0
        /**
         * Remove the triangles in @triangles that are completely inside the geometry contained
         * by this BSPTree instance. Triangles that are partially inside the geometry are clipped
         * against it.
         *
         * If @clipLessThan is false, the operation is reversed and triangles portions outside the geometry
         * of this BSPTree instance are removed.
         */
        public void ClipOutTriangles(FastLinkedList <Triangle> triangles, bool clipLessThan = true, IList <Triangle> discarded = null)
        {
            // ensure the root node exists
            if (root == null)
            {
                return;
            }

            // call the private, recursive version of ClipOutTriangles
            ClipOutTriangles(root, triangles, clipLessThan, discarded);
        }
Exemple #3
0
        public void CopyInto(IList <T> copy)
        {
            if (copy == null)
            {
                return;
            }

            FastLinkedList <T> .Node current = First;
            while (current != null)
            {
                copy.Add(current.Value);
                current = current.Next;
            }
        }
Exemple #4
0
        /**
         * Rescursive version of AddTriangles. This method partitions the triangles
         * in @triangles using @node's split plane, and then recursively calls itself
         * with the resulting greater-than and less-than lists.
         */
        private void AddTriangles(Node node, FastLinkedList <Triangle> triangles)
        {
            if (triangles == null)
            {
                return;
            }
            if (node == null)
            {
                return;
            }

            // get a reference to the list of triangles that are co-planar with
            // @node's split plane
            FastLinkedList <Triangle> nodeTriangles = node.GetTriangleList();

            FastLinkedList <Triangle> lessThan    = new FastLinkedList <Triangle>();
            FastLinkedList <Triangle> greaterThan = new FastLinkedList <Triangle>();

            // iterate through each triangle in @triangles and classify/partition each according
            // @node's split plane. co-planar triangles go into @nodeTriangles, triangles on the front
            // side go into @greaterThan, traingles on the back side go into @lessThan.
            triangles.Iterate((Triangle tri) => {
                Partitioner.Orientation orient = Partitioner.SliceTriangle(tri, node.SplitPlane, lessThan, greaterThan, nodeTriangles, nodeTriangles);
            });

            // release clear memory occupied by @triangles
            triangles.Clear();

            // recurse on the back side of @node's split plane
            if (lessThan.First != null)
            {
                if (node.LessThan == null)
                {
                    node.LessThan = Node.Create(lessThan.First.Value.OrientationPlane);
                }
                AddTriangles(node.LessThan, lessThan);
            }

            // recurse on the front side of @node's split plane
            if (greaterThan.First != null)
            {
                if (node.GreaterThan == null)
                {
                    node.GreaterThan = Node.Create(greaterThan.First.Value.OrientationPlane);
                }
                AddTriangles(node.GreaterThan, greaterThan);
            }
        }
Exemple #5
0
            /**
             * Invert this Node instances's split plane and triangles.
             */
            public void Invert()
            {
                FastLinkedList <Triangle> .Node current = triangles.First;
                while (current != null)
                {
                    current.Value.Invert();
                    current = current.Next;
                }

                SplitPlane.Invert();

                Node tempList = LessThan;

                LessThan    = GreaterThan;
                GreaterThan = tempList;
            }
Exemple #6
0
        /**
         * Add the triangles from @triangles into this BSPTree instance.
         */
        public void AddTriangles(List <Triangle> triangles)
        {
            if (triangles == null || triangles.Count <= 0)
            {
                return;
            }

            // ensure the root node exists
            if (root == null)
            {
                root = Node.Create(triangles[0].OrientationPlane);
            }

            // convert @triangles to a FastLinkedList structure.
            FastLinkedList <Triangle> linkedTriangles = new FastLinkedList <Triangle>();

            linkedTriangles.CopyFrom(triangles);

            // call the private, recursive version of AddTriangles
            AddTriangles(root, linkedTriangles);
        }
Exemple #7
0
 private Node()
 {
     LessThan    = null;
     GreaterThan = null;
     triangles   = new FastLinkedList <Triangle>();
 }
Exemple #8
0
        /**
         * Recursive version of ClipOutTriangles. This method partitions the triangles
         * in @triangles using @node's split plane, and then recursively calls itself
         * with the resulting greater-than and less-than lists. If the recursion reaches a
         * point where triangles in @triangles are on the back side of @node's split plane,
         * but this instance of BSPTree contains no geometry on that side (node.LessThan == null),
         * then the triangles placed in @lessThan are deleted from @triangles. This removes
         * the portions of triangles in @triangles that lie inside the geometry of this BSPTree
         * instance.
         *
         * If @clippLessThan is false, then we perform the reverse of the above oepration.
         * Triangles placed in @greaterThan than are removed when node.GreaterThan == null.
         * In that case the portions of triangles in @triangles that lie outside the geometry
         * of this BSPTree instance are removed.
         */
        private void ClipOutTriangles(Node node, FastLinkedList <Triangle> triangles, bool clipLessThan = true, IList <Triangle> discarded = null)
        {
            if (triangles == null || triangles.First == null)
            {
                return;
            }
            if (node == null)
            {
                return;
            }

            FastLinkedList <Triangle> lessThan    = new FastLinkedList <Triangle>();
            FastLinkedList <Triangle> greaterThan = new FastLinkedList <Triangle>();

            // iterate through each triangle in @triangles and classify/partition each according
            // @node's split plane. triangles on the front side go into @greaterThan, triangles
            // on the back side go into @lessThan. co-planar triangles whose normal matches that of
            // @node's split plane go into @greaterThan; the rest go into @lessThan.
            triangles.Iterate((Triangle tri) => {
                Partitioner.Orientation orient = Partitioner.SliceTriangle(tri, node.SplitPlane, lessThan, greaterThan, lessThan, greaterThan, true);
            });

            // release memory used by @triangles
            triangles.Clear();

            // recurse on the back side of @node's split plane if this BSPTree contains
            // geometry on that side. if it does not, and we want to clip out triangles
            // inside this BSPTree's geometry (@clipLessThan == true), then we clear out @lessThan.
            if (node.LessThan != null)
            {
                ClipOutTriangles(node.LessThan, lessThan, clipLessThan, discarded);
            }
            else if (clipLessThan)
            {
                if (discarded != null)
                {
                    lessThan.CopyInto(discarded);
                }
                lessThan.Clear();
            }

            // recurse on the front side of @node's split plane if this BSPTree contains
            // geometry on that side. if it does not, and we want to clip out triangles
            // outside this BSPTree's geometry (@clipLessThan == false), then we clear out @greaterThan.
            if (node.GreaterThan != null)
            {
                ClipOutTriangles(node.GreaterThan, greaterThan, clipLessThan, discarded);
            }
            else if (!clipLessThan)
            {
                if (discarded != null)
                {
                    greaterThan.CopyInto(discarded);
                }
                greaterThan.Clear();
            }

            // rebuild @triangles with the properly clipped triangles
            triangles.AppendIntoList(lessThan);
            triangles.AppendIntoList(greaterThan);
        }