Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Binary space partitioning
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Generation== The canonical use of a BSP tree is for rendering polygons (that are double-sided, that is, without [[back-face culling]]) with the painter's algorithm. Each polygon is designated with a front side and a backside which could be chosen arbitrarily and only affects the structure of the tree but not the required result.<ref name="fuchs80" /> Such a tree is constructed from an unsorted list of all the polygons in a scene. The recursive algorithm for construction of a BSP tree from that list of polygons is:<ref name="fuchs80"> {{cite conference | last1 = Fuchs | first1 = Henry | last2 = Kedem | first2 = Zvi. M | last3 = Naylor | first3 = Bruce F. |title=On Visible Surface Generation by A Priori Tree Structures |book-title=SIGGRAPH '80 Proceedings of the 7th annual conference on Computer graphics and interactive techniques | year=1980 |pages=124โ133 | publisher=ACM | doi=10.1145/965105.807481| url=http://www.cs.unc.edu/~fuchs/publications/VisSurfaceGeneration80.pdf}}</ref> # Choose a polygon ''P'' from the list. # Make a node ''N'' in the BSP tree, and add ''P'' to the list of polygons at that node. # For each other polygon in the list: ## If that polygon is wholly in front of the plane containing ''P'', move that polygon to the list of nodes in front of ''P''. ## If that polygon is wholly behind the plane containing ''P'', move that polygon to the list of nodes behind ''P''. ## If that polygon is intersected by the plane containing ''P'', split it into two polygons and move them to the respective lists of polygons behind and in front of ''P''. ## If that polygon lies in the plane containing ''P'', add it to the list of polygons at node ''N''. # Apply this algorithm to the list of polygons in front of ''P''. # Apply this algorithm to the list of polygons behind ''P''. The following diagram illustrates the use of this algorithm in converting a list of lines or polygons into a BSP tree. At each of the eight steps (i.-viii.), the algorithm above is applied to a list of lines, and one new node is added to the tree. {| |- valign="top" | | Start with a list of lines, (or in 3D, polygons) making up the scene. In the tree diagrams, lists are denoted by rounded rectangles and nodes in the BSP tree by circles. In the spatial diagram of the lines, the direction chosen to be the 'front' of a line is denoted by an arrow. | style="text-align:right;" | [[File:Example of BSP tree construction - step 1.svg|class=skin-invert]] |- valign="top" | style="text-align:right;" | '''i.''' |Following the steps of the algorithm above, # We choose a line, A, from the list and,... # ...add it to a node. # We split the remaining lines in the list into those in front of A (i.e. B2, C2, D2), and those behind (B1, C1, D1). # We first process the lines in front of A (in steps iiโv),... # ...followed by those behind (in steps viโvii). | style="text-align:right;" | [[File:Example of BSP tree construction - step 2.svg|class=skin-invert]] |- valign="top" | style="text-align:right;" | '''ii.''' || We now apply the algorithm to the list of lines in front of A (containing B2, C2, D2). We choose a line, B2, add it to a node and split the rest of the list into those lines that are in front of B2 (D2), and those that are behind it (C2, D3). || style="text-align:right;" | [[File:Example of BSP tree construction - step 3.svg|class=skin-invert]] |- valign="top" | style="text-align:right;" | '''iii.''' | Choose a line, D2, from the list of lines in front of B2 and A. It is the only line in the list, so after adding it to a node, nothing further needs to be done. | style="text-align:right;" | [[File:Example of BSP tree construction - step 4.svg|class=skin-invert]] |- valign="top" | style="text-align:right;" | '''iv.''' | We are done with the lines in front of B2, so consider the lines behind B2 (C2 and D3). Choose one of these (C2), add it to a node, and put the other line in the list (D3) into the list of lines in front of C2. | style="text-align:right;" | [[File:Example of BSP tree construction - step 5.svg|class=skin-invert]] |- valign="top" | style="text-align:right;" | '''v.''' | Now look at the list of lines in front of C2. There is only one line (D3), so add this to a node and continue. | style="text-align:right;" | [[File:Example of BSP tree construction - step 6.svg|class=skin-invert]] |- valign="top" | style="text-align:right;" | '''vi.''' || We have now added all of the lines in front of A to the BSP tree, so we now start on the list of lines behind A. Choosing a line (B1) from this list, we add B1 to a node and split the remainder of the list into lines in front of B1 (i.e. D1), and lines behind B1 (i.e. C1). || [[File:Example of BSP tree construction - step 7.svg|class=skin-invert]] |- valign="top" | style="text-align:right;" | '''vii.''' || Processing first the list of lines in front of B1, D1 is the only line in this list, so add this to a node and continue. || style="text-align:right;" | [[File:Example of BSP tree construction - step 8.svg|class=skin-invert]] |- valign="top" | style="text-align:right;" | '''viii.''' || Looking next at the list of lines behind B1, the only line in this list is C1, so add this to a node, and the BSP tree is complete. || style="text-align:right;" | [[File:Example of BSP tree construction - step 9.svg|class=skin-invert]] |} The final number of polygons or lines in a tree is often larger (sometimes much larger<ref name="fuchs80" />) than the original list, since lines or polygons that cross the partitioning plane must be split into two. It is desirable to minimize this increase, but also to maintain reasonable [[Binary tree#Types of binary trees|balance]] in the final tree. The choice of which polygon or line is used as a partitioning plane (in step 1 of the algorithm) is therefore important in creating an efficient BSP tree.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)