Top Description Interfaces Classes Enums
[default module]

Package org.apache.commons.math3.geometry.partitioning


This package provides classes to implement Binary Space Partition trees.

BSP trees are an efficient way to represent parts of space and in particular polytopes (line segments in 1D, polygons in 2D and polyhedrons in 3D) and to operate on them. The main principle is to recursively subdivide the space using simple hyperplanes (points in 1D, lines in 2D, planes in 3D).

We start with a tree composed of a single node without any cut hyperplane: it represents the complete space, which is a convex part. If we add a cut hyperplane to this node, this represents a partition with the hyperplane at the node level and two half spaces at each side of the cut hyperplane. These half-spaces are represented by two child nodes without any cut hyperplanes associated, the plus child which represents the half space on the plus side of the cut hyperplane and the minus child on the other side. Continuing the subdivisions, we end up with a tree having internal nodes that are associated with a cut hyperplane and leaf nodes without any hyperplane which correspond to convex parts.

When BSP trees are used to represent polytopes, the convex parts are known to be completely inside or outside the polytope as long as there is no facet in the part (which is obviously the case if the cut hyperplanes have been chosen as the underlying hyperplanes of the facets (this is called an autopartition) and if the subdivision process has been continued until all facets have been processed. It is important to note that the polytope is not defined by a single part, but by several convex ones. This is the property that allows BSP-trees to represent non-convex polytopes despites all parts are convex. The Region class is devoted to this representation, it is build on top of the BSPTree class using boolean objects as the leaf nodes attributes to represent the inside/outside property of each leaf part, and also adds various methods dealing with boundaries (i.e. the separation between the inside and the outside parts).

Rather than simply associating the internal nodes with an hyperplane, we consider sub-hyperplanes which correspond to the part of the hyperplane that is inside the convex part defined by all the parent nodes (this implies that the sub-hyperplane at root node is in fact a complete hyperplane, because there is no parent to bound it). Since the parts are convex, the sub-hyperplanes are convex, in 3D the convex parts are convex polyhedrons, and the sub-hyperplanes are convex polygons that cut these polyhedrons in two sub-polyhedrons. Using this definition, a BSP tree completely partitions the space. Each point either belongs to one of the sub-hyperplanes in an internal node or belongs to one of the leaf convex parts.

In order to determine where a point is, it is sufficient to check its position with respect to the root cut hyperplane, to select the corresponding child tree and to repeat the procedure recursively, until either the point appears to be exactly on one of the hyperplanes in the middle of the tree or to be in one of the leaf parts. For this operation, it is sufficient to consider the complete hyperplanes, there is no need to check the points with the boundary of the sub-hyperplanes, because this check has in fact already been realized by the recursive descent in the tree. This is very easy to do and very efficient, especially if the tree is well balanced (the cost is O(log(n)) where n is the number of facets) or if the first tree levels close to the root discriminate large parts of the total space.

One of the main sources for the development of this package was Bruce Naylor, John Amanatides and William Thibault paper Merging BSP Trees Yields Polyhedral Set Operations Proc. Siggraph '90, Computer Graphics 24(4), August 1990, pp 115-124, published by the Association for Computing Machinery (ACM). The same paper can also be found here.

Note that the interfaces defined in this package are not intended to be implemented by Apache Commons Math users, they are only intended to be implemented within the library itself. New methods may be added even for minor versions, which breaks compatibility for external implementations.

Interface Summary

Modifier and TypeInterface and Description
public interface
BSPTreeVisitor<
Type of the space.
S extends Space
>

This interface is used to visit BSP tree nodes.

public interface
Embedding<
Type of the embedding space.
S extends Space
,
Type of the embedded sub-space.
T extends Space
>

This interface defines mappers between a space and one of its sub-spaces.

public interface
Hyperplane<
Type of the space.
S extends Space
>

This interface represents an hyperplane of a space.

public interface
Region<
Type of the space.
S extends Space
>

This interface represents a region of a space as a partition.

public interface
SubHyperplane<
Type of the embedding space.
S extends Space
>

This interface represents the remaining parts of an hyperplane after other parts have been chopped off.

public interface
Transform<
Type of the embedding space.
S extends Space
,
Type of the embedded sub-space.
T extends Space
>

This interface represents an inversible affine transform in a space.

Class Summary

Modifier and TypeClass and Description
public abstract class
AbstractRegion<
Type of the space.
S extends Space
,
Type of the sub-space.
T extends Space
>

Abstract class for all regions, independently of geometry type or dimension.

public abstract class
AbstractSubHyperplane<
Type of the embedding space.
S extends Space
,
Type of the embedded sub-space.
T extends Space
>

This class implements the dimension-independent parts of SubHyperplane.

public class
BoundaryAttribute<
Type of the space.
S extends Space
>

Class holding boundary attributes.

pack-priv class
BoundaryBuilder<
Type of the space.
S extends Space
>

Visitor building boundary shell tree.

public class
BoundaryProjection<
Type of the space.
S extends Space
>

Class holding the result of point projection on region boundary.

pack-priv class
BoundaryProjector<
Type of the space.
S extends Space
,
Type of the sub-space.
T extends Space
>

Local tree visitor to compute projection on boundary.

pack-priv class
BoundarySizeVisitor<
Type of the space.
S extends Space
>

Visitor computing the boundary size.

public class
BSPTree<
Type of the space.
S extends Space
>

This class represent a Binary Space Partition tree.

pack-priv class
Characterization<
Type of the space.
S extends Space
>

Cut sub-hyperplanes characterization with respect to inside/outside cells.

pack-priv class
InsideFinder<
Type of the space.
S extends Space
>

Utility class checking if inside nodes can be found on the plus and minus sides of an hyperplane.

public class
NodesSet<
Type of the space.
S extends Space
>

Set of BSP tree nodes.

public class
RegionFactory<
Type of the space.
S extends Space
>

This class is a factory for Region.

Enum Summary

Modifier and TypeEnum and Description
public enum
Side

Enumerate representing the location of an element with respect to an hyperplane of a space.