HOME

TheInfoList



OR:

In
computer science Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to Applied science, practical discipli ...
, binary space partitioning (BSP) is a method for
space partitioning In geometry, space partitioning is the process of dividing a space (usually a Euclidean space) into two or more disjoint subsets (see also partition of a set). In other words, space partitioning divides a space into non-overlapping regions. Any ...
which
recursively Recursion (adjective: ''recursive'') occurs when a thing is defined in terms of itself or of its type. Recursion is used in a variety of disciplines ranging from linguistics to logic. The most common application of recursion is in mathematics ...
subdivides a
Euclidean space Euclidean space is the fundamental space of geometry, intended to represent physical space. Originally, that is, in Euclid's Elements, Euclid's ''Elements'', it was the three-dimensional space of Euclidean geometry, but in modern mathematics ther ...
into two
convex set In geometry, a subset of a Euclidean space, or more generally an affine space over the reals, is convex if, given any two points in the subset, the subset contains the whole line segment that joins them. Equivalently, a convex set or a convex r ...
s by using
hyperplane In geometry, a hyperplane is a subspace whose dimension is one less than that of its ''ambient space''. For example, if a space is 3-dimensional then its hyperplanes are the 2-dimensional planes, while if the space is 2-dimensional, its hyper ...
s as partitions. This process of subdividing gives rise to a representation of objects within the space in the form of a
tree data structure In computer science, a tree is a widely used abstract data type that represents a hierarchical tree structure with a set of connected nodes. Each node in the tree can be connected to many children (depending on the type of tree), but must be conn ...
known as a BSP tree. Binary space partitioning was developed in the context of
3D computer graphics 3D computer graphics, or “3D graphics,” sometimes called CGI, 3D-CGI or three-dimensional computer graphics are graphics that use a three-dimensional representation of geometric data (often Cartesian) that is stored in the computer for th ...
in 1969. The structure of a BSP tree is useful in rendering because it can efficiently give spatial information about the objects in a scene, such as objects being ordered from front-to-back with respect to a viewer at a given location. Other applications of BSP include: performing
geometrical Geometry (; ) is, with arithmetic, one of the oldest branches of mathematics. It is concerned with properties of space such as the distance, shape, size, and relative position of figures. A mathematician who works in the field of geometry is ca ...
operations with
shape A shape or figure is a graphics, graphical representation of an object or its external boundary, outline, or external Surface (mathematics), surface, as opposed to other properties such as color, Surface texture, texture, or material type. A pl ...
s (
constructive solid geometry Constructive solid geometry (CSG; formerly called computational binary solid geometry) is a technique used in solid modeling. Constructive solid geometry allows a modeler to create a complex surface or object by using Boolean operators to combi ...
) in
CAD Computer-aided design (CAD) is the use of computers (or ) to aid in the creation, modification, analysis, or optimization of a design. This software is used to increase the productivity of the designer, improve the quality of design, improve co ...
,
collision detection Collision detection is the computational problem of detecting the intersection (Euclidean geometry), intersection of two or more objects. Collision detection is a classic issue of computational geometry and has applications in various computing ...
in
robotics Robotics is an interdisciplinary branch of computer science and engineering. Robotics involves design, construction, operation, and use of robots. The goal of robotics is to design machines that can help and assist humans. Robotics integrat ...
and 3D video games, ray tracing, and other applications that involve the handling of complex spatial scenes.


Overview

Binary space partitioning is a generic process of
recursively Recursion (adjective: ''recursive'') occurs when a thing is defined in terms of itself or of its type. Recursion is used in a variety of disciplines ranging from linguistics to logic. The most common application of recursion is in mathematics ...
dividing a scene into two until the partitioning satisfies one or more requirements. It can be seen as a generalization of other spatial tree structures such as ''k''-d trees and
quadtree A quadtree is a tree data structure in which each internal node has exactly four children. Quadtrees are the two-dimensional analog of octrees and are most often used to partition a two-dimensional space by recursively subdividing it into four ...
s, one where hyperplanes that partition the space may have any orientation, rather than being aligned with the coordinate axes as they are in ''k''-d trees or quadtrees. When used in computer graphics to render scenes composed of planar
polygons In geometry, a polygon () is a plane figure that is described by a finite number of straight line segments connected to form a closed ''polygonal chain'' (or ''polygonal circuit''). The bounded plane region, the bounding circuit, or the two toge ...
, the partitioning planes are frequently chosen to coincide with the planes defined by polygons in the scene. The specific choice of partitioning plane and criterion for terminating the partitioning process varies depending on the purpose of the BSP tree. For example, in computer graphics rendering, the scene is divided until each node of the BSP tree contains only polygons that can be rendered in arbitrary order. When
back-face culling In computer graphics, back-face culling determines whether a polygon of a graphical object is drawn. It is a step in the graphical pipeline that tests whether the points in the polygon appear in clockwise or counter-clockwise order when projected ...
is used, each node, therefore, contains a convex set of polygons, whereas when rendering double-sided polygons, each node of the BSP tree contains only polygons in a single plane. In collision detection or ray tracing, a scene may be divided up into primitives on which collision or ray intersection tests are straightforward. Binary space partitioning arose from the computer graphics need to rapidly draw three-dimensional scenes composed of polygons. A simple way to draw such scenes is the
painter's algorithm The painter’s algorithm (also depth-sort algorithm and priority fill) is an algorithm for visible surface determination in 3D computer graphics that works on a polygon-by-polygon basis rather than a pixel-by-pixel, row by row, or area by are ...
, which produces polygons in order of distance from the viewer, back to front, painting over the background and previous polygons with each closer object. This approach has two disadvantages: the time required to sort polygons in back-to-front order, and the possibility of errors in overlapping polygons. Fuchs and co-authors showed that constructing a BSP tree solved both of these problems by providing a rapid method of sorting polygons with respect to a given viewpoint (linear in the number of polygons in the scene) and by subdividing overlapping polygons to avoid errors that can occur with the painter's algorithm. A disadvantage of binary space partitioning is that generating a BSP tree can be time-consuming. Typically, it is therefore performed once on static geometry, as a pre-calculation step, prior to rendering or other real-time operations on a scene. The expense of constructing a BSP tree makes it difficult and inefficient to directly implement moving objects into a tree. BSP trees are often used by 3D
video game Video games, also known as computer games, are electronic games that involves interaction with a user interface or input device such as a joystick, controller, keyboard, or motion sensing device to generate visual feedback. This fee ...
s, particularly
first-person shooter First-person shooter (FPS) is a sub-genre of shooter video games centered on gun and other weapon-based combat in a first-person perspective, with the player experiencing the action through the eyes of the protagonist and controlling the pl ...
s and those with indoor environments.
Game engine A game engine is a software framework primarily designed for the development of video games and generally includes relevant libraries and support programs. The "engine" terminology is similar to the term "software engine" used in the software i ...
s using BSP trees include the Doom (id Tech 1), Quake (id Tech 2 variant),
GoldSrc GoldSrc ( ) is a proprietary game engine developed by Valve. At its core, GoldSrc is a heavily modified version of id Software's ''Quake'' engine. It originally made its debut in 1998 with ''Half-Life'', and would power future games developed b ...
and
Source Source may refer to: Research * Historical document * Historical source * Source (intelligence) or sub source, typically a confidential provider of non open-source intelligence * Source (journalism), a person, publication, publishing institute o ...
engines. In them, BSP trees containing the static geometry of a scene are often used together with a
Z-buffer A depth buffer, also known as a z-buffer, is a type of data buffer used in computer graphics to represent depth information of objects in Three-dimensional space, 3D space from a particular Perspective (graphical), perspective. Depth buffers are ...
, to correctly merge movable objects such as doors and characters onto the background scene. While binary space partitioning provides a convenient way to store and retrieve spatial information about polygons in a scene, it does not solve the problem of visible surface determination.


Generation

The canonical use of a BSP tree is for rendering polygons (that are double-sided, that is, without
back-face culling In computer graphics, back-face culling determines whether a polygon of a graphical object is drawn. It is a step in the graphical pipeline that tests whether the points in the polygon appear in clockwise or counter-clockwise order when projected ...
) 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. 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: # 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. The final number of polygons or lines in a tree is often larger (sometimes much larger) 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
balance Balance or balancing may refer to: Common meanings * Balance (ability) in biomechanics * Balance (accounting) * Balance or weighing scale * Balance as in equality or equilibrium Arts and entertainment Film * ''Balance'' (1983 film), a Bulgaria ...
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.


Traversal

A BSP tree is traversed in a linear time, in an order determined by the particular function of the tree. Again using the example of rendering double-sided polygons using the painter's algorithm, to draw a polygon ''P'' correctly requires that all polygons behind the plane ''P'' lies in must be drawn first, then polygon ''P'', then finally the polygons in front of ''P''. If this drawing order is satisfied for all polygons in a scene, then the entire scene renders in the correct order. This procedure can be implemented by recursively traversing a BSP tree using the following algorithm. From a given viewing location ''V'', to render a BSP tree, # If the current node is a leaf node, render the polygons at the current node. # Otherwise, if the viewing location ''V'' is in front of the current node: ## Render the child BSP tree containing polygons behind the current node ## Render the polygons at the current node ## Render the child BSP tree containing polygons in front of the current node # Otherwise, if the viewing location ''V'' is behind the current node: ## Render the child BSP tree containing polygons in front of the current node ## Render the polygons at the current node ## Render the child BSP tree containing polygons behind the current node # Otherwise, the viewing location ''V'' must be exactly on the plane associated with the current node. Then: ## Render the child BSP tree containing polygons in front of the current node ## Render the child BSP tree containing polygons behind the current node Applying this algorithm recursively to the BSP tree generated above results in the following steps: * The algorithm is first applied to the root node of the tree, node ''A''. ''V'' is in front of node ''A'', so we apply the algorithm first to the child BSP tree containing polygons behind ''A'' ** This tree has root node ''B1''. ''V'' is behind ''B1'' so first, we apply the algorithm to the child BSP tree containing polygons in front of ''B1'': *** This tree is just the leaf node ''D1'', so the polygon ''D1'' is rendered. ** We then render the polygon ''B1''. ** We then apply the algorithm to the child BSP tree containing polygons behind ''B1'': *** This tree is just the leaf node ''C1'', so the polygon ''C1'' is rendered. * We then draw the polygons of ''A'' * We then apply the algorithm to the child BSP tree containing polygons in front of ''A'' ** This tree has root node ''B2''. ''V'' is behind ''B2'' so first, we apply the algorithm to the child BSP tree containing polygons in front of ''B2'': *** This tree is just the leaf node ''D2'', so the polygon ''D2'' is rendered. ** We then render the polygon ''B2''. ** We then apply the algorithm to the child BSP tree containing polygons behind ''B2'': *** This tree has root node ''C2''. ''V'' is in front of ''C2'' so first, we would apply the algorithm to the child BSP tree containing polygons behind ''C2''. There is no such tree, however, so we continue. *** We render the polygon ''C2''. *** We apply the algorithm to the child BSP tree containing polygons in front of ''C2'' **** This tree is just the leaf node ''D3'', so the polygon ''D3'' is rendered. The tree is traversed in linear time and renders the polygons in a far-to-near ordering (''D1'', ''B1'', ''C1'', ''A'', ''D2'', ''B2'', ''C2'', ''D3'') suitable for the painter's algorithm.


Timeline

*1969 Schumacker et al. published a report that described how carefully positioned planes in a virtual environment could be used to accelerate polygon ordering. The technique made use of depth coherence, which states that a polygon on the far side of the plane cannot, in any way, obstruct a closer polygon. This was used in flight simulators made by GE as well as Evans and Sutherland. However, the creation of the polygonal data organization was performed manually by the scene designer. *1980 Fuchs et al. extended Schumacker's idea to the representation of 3D objects in a virtual environment by using planes that lie coincident with polygons to recursively partition the 3D space. This provided a fully automated and algorithmic generation of a hierarchical polygonal data structure known as a Binary Space Partitioning Tree (BSP Tree). The process took place as an off-line preprocessing step that was performed once per environment/object. At run-time, the view-dependent visibility ordering was generated by traversing the tree. *1981 Naylor's Ph.D. thesis provided a full development of both BSP trees and a graph-theoretic approach using strongly connected components for pre-computing visibility, as well as the connection between the two methods. BSP trees as a dimension-independent spatial search structure were emphasized, with applications to visible surface determination. The thesis also included the first empirical data demonstrating that the size of the tree and the number of new polygons were reasonable (using a model of the Space Shuttle). *1983 Fuchs et al. described a micro-code implementation of the BSP tree algorithm on an Ikonas frame buffer system. This was the first demonstration of real-time visible surface determination using BSP trees. *1987 Thibault and Naylor described how arbitrary polyhedra may be represented using a BSP tree as opposed to the traditional b-rep (boundary representation). This provided a solid representation vs. a surface based-representation. Set operations on polyhedra were described using a tool, enabling
constructive solid geometry Constructive solid geometry (CSG; formerly called computational binary solid geometry) is a technique used in solid modeling. Constructive solid geometry allows a modeler to create a complex surface or object by using Boolean operators to combi ...
(CSG) in real-time. This was the forerunner of BSP level design using "
brushes A brush is a common tool with bristles, wire or other filaments. It generally consists of a handle or block to which filaments are affixed in either a parallel or perpendicular orientation, depending on the way the brush is to be gripped durin ...
", introduced in the Quake editor and picked up in the Unreal Editor. *1990 Naylor, Amanatides, and Thibault provided an algorithm for merging two BSP trees to form a new BSP tree from the two original trees. This provides many benefits including combining moving objects represented by BSP trees with a static environment (also represented by a BSP tree), very efficient CSG operations on polyhedra, exact collisions detection in O(log n * log n), and proper ordering of transparent surfaces contained in two interpenetrating objects (has been used for an x-ray vision effect). *1990 Teller and Séquin proposed the offline generation of potentially visible sets to accelerate visible surface determination in orthogonal 2D environments. *1991 Gordon and Chen HEN91described an efficient method of performing front-to-back rendering from a BSP tree, rather than the traditional back-to-front approach. They utilized a special data structure to record, efficiently, parts of the screen that have been drawn, and those yet to be rendered. This algorithm, together with the description of BSP Trees in the standard computer graphics textbook of the day ('' Computer Graphics: Principles and Practice'') was used by
John Carmack John D. Carmack II (born August 20, 1970) is an American computer programmer and video game developer. He co-founded the video game company id Software and was the lead programmer of its 1990s games ''Commander Keen'', ''Wolfenstein 3D'', ''Doo ...
in the making of ''Doom'' (video game). *1992 Teller's Ph.D. thesis described the efficient generation of potentially visible sets as a pre-processing step to accelerate real-time visible surface determination in arbitrary 3D polygonal environments. This was used in '' Quake'' and contributed significantly to that game's performance. *1993 Naylor answered the question of what characterizes a good BSP tree. He used expected case models (rather than worst-case analysis) to mathematically measure the expected cost of searching a tree and used this measure to build good BSP trees. Intuitively, the tree represents an object in a multi-resolution fashion (more exactly, as a tree of approximations). Parallels with Huffman codes and probabilistic binary search trees are drawn. *1993 Hayder Radha's Ph.D. thesis described (natural) image representation methods using BSP trees. This includes the development of an optimal BSP-tree construction framework for any arbitrary input image. This framework is based on a new image transform, known as the Least-Square-Error (LSE) Partitioning Line (LPE) transform. H. Radha's thesis also developed an optimal rate-distortion (RD) image compression framework and image manipulation approaches using BSP trees.


See also

* k-d tree *
Octree An octree is a tree data structure in which each internal node has exactly eight children. Octrees are most often used to partition a three-dimensional space by recursively subdividing it into eight octants. Octrees are the three-dimensional ana ...
*
Quadtree A quadtree is a tree data structure in which each internal node has exactly four children. Quadtrees are the two-dimensional analog of octrees and are most often used to partition a two-dimensional space by recursively subdividing it into four ...
*
Hierarchical clustering In data mining and statistics, hierarchical clustering (also called hierarchical cluster analysis or HCA) is a method of cluster analysis that seeks to build a hierarchy of clusters. Strategies for hierarchical clustering generally fall into ...
, an alternative way to divide
3D model In 3D computer graphics, 3D modeling is the process of developing a mathematical coordinate-based representation of any surface of an object (inanimate or living) in three dimensions via specialized software by manipulating edges, vertices, an ...
data for efficient rendering. * Guillotine cutting


References


Additional references

* * * * * * *https://ui.adsabs.harvard.edu/abs/1996ITIP....5.1610R/abstract * * Describes a randomized Painter's Algorithm.. *


External links

*
BSP trees presentationAnother BSP trees presentationA Java applet that demonstrates the process of tree generationA Master Thesis about BSP generatingBSP Trees: Theory and Implementation
{{Authority control Binary trees Geometric data structures 3D computer graphics Articles with example C code