Class AbstractRegionBSPTree<P extends Point<P>,N extends AbstractRegionBSPTree.AbstractRegionNode<P,N>>
- Type Parameters:
P- Point implementation typeN- BSP tree node implementation type
- All Implemented Interfaces:
BSPSubtree<P,,N> BSPTree<P,,N> HyperplaneBoundedRegion<P>,Splittable<P,,HyperplaneBoundedRegion<P>> Region<P>,Sized
- Direct Known Subclasses:
RegionBSPTree1D,RegionBSPTree1S,RegionBSPTree2D,RegionBSPTree2S,RegionBSPTree3D
BSPTree specialized for representing regions of space. For example,
this class can be used to represent polygons in Euclidean 2D space and polyhedrons
in Euclidean 3D space.
This class is not thread safe.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAbstractRegionBSPTree.AbstractRegionNode<P extends Point<P>,N extends AbstractRegionBSPTree.AbstractRegionNode<P, N>> BSPTree.Nodeimplementation for use withAbstractRegionBSPTrees.protected static classAbstractRegionBSPTree.BoundaryProjector<P extends Point<P>,N extends AbstractRegionBSPTree.AbstractRegionNode<P, N>> Class used to compute the point on the region's boundary that is closest to a target point.private static final classAbstractRegionBSPTree.Condenser<P extends Point<P>,N extends AbstractRegionBSPTree.AbstractRegionNode<P, N>> Internal class used to perform tree condense operations.private static final classAbstractRegionBSPTree.DifferenceOperator<P extends Point<P>,N extends AbstractRegionBSPTree.AbstractRegionNode<P, N>> Class for performing boolean difference operations on region trees.private static final classAbstractRegionBSPTree.IntersectionOperator<P extends Point<P>,N extends AbstractRegionBSPTree.AbstractRegionNode<P, N>> Class for performing boolean intersection operations on region trees.private static final classAbstractRegionBSPTree.RegionBoundaryIterator<P extends Point<P>,C extends HyperplaneConvexSubset<P>, N extends AbstractRegionBSPTree.AbstractRegionNode<P, N>> Class that iterates over the boundary hyperplane convex subsets from a set of region nodes.private static classAbstractRegionBSPTree.RegionMergeOperator<P extends Point<P>,N extends AbstractRegionBSPTree.AbstractRegionNode<P, N>> Class containing the basic algorithm for merging region BSP trees.protected static classAbstractRegionBSPTree.RegionSizeProperties<P extends Point<P>>Class containing the primary size-related properties of a region.private static final classAbstractRegionBSPTree.UnionOperator<P extends Point<P>,N extends AbstractRegionBSPTree.AbstractRegionNode<P, N>> Class for performing boolean union operations on region trees.private static final classAbstractRegionBSPTree.XorOperator<P extends Point<P>,N extends AbstractRegionBSPTree.AbstractRegionNode<P, N>> Class for performing boolean symmetric difference (xor) operations on region trees.Nested classes/interfaces inherited from class org.apache.commons.geometry.core.partitioning.bsp.AbstractBSPTree
AbstractBSPTree.AbstractNode<P extends Point<P>,N extends AbstractBSPTree.AbstractNode<P, N>>, AbstractBSPTree.SubtreeInitializer<N extends AbstractBSPTree.AbstractNode<?, ?>> Nested classes/interfaces inherited from interface org.apache.commons.geometry.core.partitioning.bsp.BSPTree
BSPTree.FindNodeCutRule, BSPTree.Node<P extends Point<P>,N extends BSPTree.Node<P, N>> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate doubleThe region boundary size; this is computed when requested and then cached.private static final RegionCutRuleThe defaultRegionCutRule.The current size properties for the region.private static final doubleValue used to indicate an unknown size. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractRegionBSPTree(boolean full) Construct a new region will the given boolean determining whether or not the region will be full (including the entire space) or empty (excluding the entire space). -
Method Summary
Modifier and TypeMethodDescriptionIterable<? extends HyperplaneConvexSubset<P>> Return anIterablefor iterating over the boundaries of the region.Classify the given point with respect to the region.private RegionLocationclassifyRecursive(AbstractRegionBSPTree.AbstractRegionNode<P, N> node, P point) Recursively classify a point with respect to the region.voidChange this region into its complement.voidcomplement(AbstractRegionBSPTree<P, N> tree) Set this instance to be the complement of the given tree.private voidRecursively switch all inside nodes to outside nodes and vice versa.protected abstract AbstractRegionBSPTree.RegionSizeProperties<P> Compute the size-related properties of the region.booleancondense()Condense this tree by removing redundant subtrees, returning true if the tree structure was modified.protected voidcopyNodeProperties(N src, N dst) Copy non-structural node properties fromsrctodst.protected <C extends HyperplaneConvexSubset<P>>
Iterable<C> createBoundaryIterable(Function<HyperplaneConvexSubset<P>, C> typeConverter) Internal method for creating the iterable instances used to iterate the region boundaries.protected <C extends HyperplaneConvexSubset<P>>
List<C> createBoundaryList(Function<HyperplaneConvexSubset<P>, C> typeConverter) Internal method for creating a list of the region boundaries.voiddifference(AbstractRegionBSPTree<P, N> other) Compute the difference of this instance and the given region, storing the result back in this instance.voiddifference(AbstractRegionBSPTree<P, N> a, AbstractRegionBSPTree<P, N> b) Compute the difference of the two regions passed as arguments and store the result in this instance.List<? extends HyperplaneConvexSubset<P>> Return a list containing the boundaries of the region.doubleGet the size of the boundary of the region.Get the centroid, or geometric center, of the region or null if no centroid exists or one exists but is not unique.protected AbstractRegionBSPTree.RegionSizeProperties<P> Get the size-related properties for the region.doublegetSize()Get the size of the instance.protected AbstractBSPTree.SubtreeInitializer<N> getSubtreeInitializer(RegionCutRule cutRule) Get the subtree initializer to use for the given region cut rule.private booleanhasNodeWithLocationRecursive(AbstractRegionBSPTree.AbstractRegionNode<P, N> node, RegionLocation location) Return true if any node in the subtree rooted at the given node has a location with the given value.voidinsert(Iterable<? extends HyperplaneConvexSubset<P>> convexSubs) Insert a set of hyperplane convex subsets into the tree, using the defaultRegionCutRuleofMINUS_INSIDE.voidinsert(Iterable<? extends HyperplaneConvexSubset<P>> convexSubs, RegionCutRule cutRule) Insert a set of hyperplane convex subsets into the tree.voidinsert(BoundarySource<? extends HyperplaneConvexSubset<P>> boundarySrc) Insert all hyperplane convex subsets from the given source into the tree, using the defaultRegionCutRuleofMINUS_INSIDE.voidinsert(BoundarySource<? extends HyperplaneConvexSubset<P>> boundarySrc, RegionCutRule cutRule) Insert all hyperplane convex subsets from the given source into the tree.voidinsert(HyperplaneConvexSubset<P> convexSub) Insert a hyperplane convex subset into the tree, using the defaultRegionCutRuleofMINUS_INSIDE.voidinsert(HyperplaneConvexSubset<P> convexSub, RegionCutRule cutRule) Insert a hyperplane convex subset into the tree.voidinsert(HyperplaneSubset<P> sub) Insert a hyperplane subset into the tree, using the defaultRegionCutRuleofMINUS_INSIDE.voidinsert(HyperplaneSubset<P> sub, RegionCutRule cutRule) Insert a hyperplane subset into the tree.voidintersection(AbstractRegionBSPTree<P, N> other) Compute the intersection of this instance and the given region, storing the result back in this instance.voidCompute the intersection of the two regions passed as arguments and store the result in this instance.protected voidInvalidate any previously computed properties that rely on the internal structure of the tree.booleanisEmpty()Return true if the region is completely empty, ie all points in the space are classified asoutside.booleanisFull()Return true if the region spans the entire space.Project a point onto the boundary of the region.voidsetEmpty()Modify this instance so that is is completely empty.voidsetFull()Modify this instance so that it contains the entire space.protected <T extends AbstractRegionBSPTree<P,N>>
Split<T> split(Hyperplane<P> splitter, T minus, T plus) Helper method implementing the algorithm for splitting a tree by a hyperplane.voidunion(AbstractRegionBSPTree<P, N> other) Compute the union of this instance and the given region, storing the result back in this instance.voidunion(AbstractRegionBSPTree<P, N> a, AbstractRegionBSPTree<P, N> b) Compute the union of the two regions passed as arguments and store the result in this instance.voidxor(AbstractRegionBSPTree<P, N> other) Compute the symmetric difference (xor) of this instance and the given region, storing the result back in this instance.voidxor(AbstractRegionBSPTree<P, N> a, AbstractRegionBSPTree<P, N> b) Compute the symmetric difference (xor) of the two regions passed as arguments and store the result in this instance.Methods inherited from class org.apache.commons.geometry.core.partitioning.bsp.AbstractBSPTree
accept, accept, copy, copyNode, copySubtree, count, createNode, cutNode, extract, extractParentPath, findNode, findNode, getRoot, getVersion, height, importSubtree, insert, nodes, removeNodeCut, setNodeCut, setRoot, splitIntoTrees, splitSubtree, swapsInsideOutside, toString, transform, treeString, treeString, trimToNodeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.commons.geometry.core.Sized
isFinite, isInfiniteMethods inherited from interface org.apache.commons.geometry.core.partitioning.Splittable
split
-
Field Details
-
DEFAULT_REGION_CUT_RULE
The defaultRegionCutRule. -
UNKNOWN_SIZE
private static final double UNKNOWN_SIZEValue used to indicate an unknown size.- See Also:
-
boundarySize
private double boundarySizeThe region boundary size; this is computed when requested and then cached. -
regionSizeProperties
The current size properties for the region.
-
-
Constructor Details
-
AbstractRegionBSPTree
protected AbstractRegionBSPTree(boolean full) Construct a new region will the given boolean determining whether or not the region will be full (including the entire space) or empty (excluding the entire space).- Parameters:
full- if true, the region will cover the entire space, otherwise it will be empty
-
-
Method Details
-
isEmpty
public boolean isEmpty()Return true if the region is completely empty, ie all points in the space are classified asoutside. -
isFull
public boolean isFull()Return true if the region spans the entire space. In other words, a region is full if no points in the space are classified asoutside. -
hasNodeWithLocationRecursive
private boolean hasNodeWithLocationRecursive(AbstractRegionBSPTree.AbstractRegionNode<P, N> node, RegionLocation location) Return true if any node in the subtree rooted at the given node has a location with the given value.- Parameters:
node- the node at the root of the subtree to searchlocation- the location to find- Returns:
- true if any node in the subtree has the given location
-
setFull
public void setFull()Modify this instance so that it contains the entire space.- See Also:
-
setEmpty
public void setEmpty()Modify this instance so that is is completely empty.- See Also:
-
getSize
public double getSize()Get the size of the instance. -
getBoundarySize
public double getBoundarySize()Get the size of the boundary of the region. The size is a value in thed-1dimension space. For example, in Euclidean space, this will be a length in 2D and an area in 3D.- Specified by:
getBoundarySizein interfaceRegion<P extends Point<P>>- Returns:
- the size of the boundary of the region
-
insert
Insert a hyperplane subset into the tree, using the defaultRegionCutRuleofMINUS_INSIDE.- Parameters:
sub- the hyperplane subset to insert into the tree
-
insert
Insert a hyperplane subset into the tree.- Parameters:
sub- the hyperplane subset to insert into the treecutRule- rule used to determine the region locations of new child nodes
-
insert
Insert a hyperplane convex subset into the tree, using the defaultRegionCutRuleofMINUS_INSIDE.- Parameters:
convexSub- the hyperplane convex subset to insert into the tree
-
insert
Insert a hyperplane convex subset into the tree.- Parameters:
convexSub- the hyperplane convex subset to insert into the treecutRule- rule used to determine the region locations of new child nodes
-
insert
Insert a set of hyperplane convex subsets into the tree, using the defaultRegionCutRuleofMINUS_INSIDE.- Parameters:
convexSubs- iterable containing a collection of hyperplane convex subsets to insert into the tree
-
insert
Insert a set of hyperplane convex subsets into the tree.- Parameters:
convexSubs- iterable containing a collection of hyperplane convex subsets to insert into the treecutRule- rule used to determine the region locations of new child nodes
-
insert
Insert all hyperplane convex subsets from the given source into the tree, using the defaultRegionCutRuleofMINUS_INSIDE.- Parameters:
boundarySrc- source of boundary hyperplane subsets to insert into the tree
-
insert
public void insert(BoundarySource<? extends HyperplaneConvexSubset<P>> boundarySrc, RegionCutRule cutRule) Insert all hyperplane convex subsets from the given source into the tree.- Parameters:
boundarySrc- source of boundary hyperplane subsets to insert into the treecutRule- rule used to determine the region locations of new child nodes
-
getSubtreeInitializer
Get the subtree initializer to use for the given region cut rule.- Parameters:
cutRule- the cut rule to get an initializer for- Returns:
- the subtree initializer for the given region cut rule
-
boundaries
Return anIterablefor iterating over the boundaries of the region. Each boundary is oriented such that its plus side points to the outside of the region. The exact ordering of the boundaries is determined by the internal structure of the tree.- Returns:
- an
Iterablefor iterating over the boundaries of the region - See Also:
-
createBoundaryIterable
protected <C extends HyperplaneConvexSubset<P>> Iterable<C> createBoundaryIterable(Function<HyperplaneConvexSubset<P>, C> typeConverter) Internal method for creating the iterable instances used to iterate the region boundaries.- Type Parameters:
C- HyperplaneConvexSubset implementation type- Parameters:
typeConverter- function to convert the generic hyperplane subset type into the type specific for this tree- Returns:
- an iterable to iterating the region boundaries
-
getBoundaries
Return a list containing the boundaries of the region. Each boundary is oriented such that its plus side points to the outside of the region. The exact ordering of the boundaries is determined by the internal structure of the tree.- Returns:
- a list of the boundaries of the region
-
createBoundaryList
protected <C extends HyperplaneConvexSubset<P>> List<C> createBoundaryList(Function<HyperplaneConvexSubset<P>, C> typeConverter) Internal method for creating a list of the region boundaries.- Type Parameters:
C- HyperplaneConvexSubset implementation type- Parameters:
typeConverter- function to convert the generic convex subset type into the type specific for this tree- Returns:
- a list of the region boundaries
-
project
-
getCentroid
Get the centroid, or geometric center, of the region or null if no centroid exists or one exists but is not unique. A centroid will not exist for empty or infinite regions.The centroid of a geometric object is defined as the mean position of all points in the object, including interior points, vertices, and other points lying on the boundary. If a physical object has a uniform density, then its center of mass is the same as its geometric centroid.
- Specified by:
getCentroidin interfaceRegion<P extends Point<P>>- Returns:
- the centroid of the region or null if no unique centroid exists
- See Also:
-
split
protected <T extends AbstractRegionBSPTree<P,N>> Split<T> split(Hyperplane<P> splitter, T minus, T plus) Helper method implementing the algorithm for splitting a tree by a hyperplane. Subclasses should call this method with two instantiated trees of the correct type.- Type Parameters:
T- Tree implementation type- Parameters:
splitter- splitting hyperplaneminus- tree that will contain the minus side of the split resultplus- tree that will contain the plus side of the split result- Returns:
- result of splitting this tree with the given hyperplane
-
getRegionSizeProperties
Get the size-related properties for the region. The value is computed lazily and cached.- Returns:
- the size-related properties for the region
-
computeRegionSizeProperties
Compute the size-related properties of the region.- Returns:
- object containing size properties for the region
-
classify
Classify the given point with respect to the region.If the point is
NaN, thenRegionLocation.OUTSIDEis returned. -
classifyRecursive
private RegionLocation classifyRecursive(AbstractRegionBSPTree.AbstractRegionNode<P, N> node, P point) Recursively classify a point with respect to the region.- Parameters:
node- the node to classify againstpoint- the point to classify- Returns:
- the classification of the point with respect to the region rooted at the given node
-
complement
public void complement()Change this region into its complement. All inside nodes become outside nodes and vice versa. The orientations of the node cuts are not modified. -
complement
Set this instance to be the complement of the given tree. The argument is not modified.- Parameters:
tree- the tree to become the complement of
-
complementRecursive
Recursively switch all inside nodes to outside nodes and vice versa.- Parameters:
node- the node at the root of the subtree to switch
-
union
Compute the union of this instance and the given region, storing the result back in this instance. The argument is not modified.- Parameters:
other- the tree to compute the union with
-
union
Compute the union of the two regions passed as arguments and store the result in this instance. Any nodes currently existing in this instance are removed.- Parameters:
a- first argument to the union operationb- second argument to the union operation
-
intersection
Compute the intersection of this instance and the given region, storing the result back in this instance. The argument is not modified.- Parameters:
other- the tree to compute the intersection with
-
intersection
Compute the intersection of the two regions passed as arguments and store the result in this instance. Any nodes currently existing in this instance are removed.- Parameters:
a- first argument to the intersection operationb- second argument to the intersection operation
-
difference
Compute the difference of this instance and the given region, storing the result back in this instance. The argument is not modified.- Parameters:
other- the tree to compute the difference with
-
difference
Compute the difference of the two regions passed as arguments and store the result in this instance. Any nodes currently existing in this instance are removed.- Parameters:
a- first argument to the difference operationb- second argument to the difference operation
-
xor
Compute the symmetric difference (xor) of this instance and the given region, storing the result back in this instance. The argument is not modified.- Parameters:
other- the tree to compute the symmetric difference with
-
xor
Compute the symmetric difference (xor) of the two regions passed as arguments and store the result in this instance. Any nodes currently existing in this instance are removed.- Parameters:
a- first argument to the symmetric difference operationb- second argument to the symmetric difference operation
-
condense
public boolean condense()Condense this tree by removing redundant subtrees, returning true if the tree structure was modified.This operation can be used to reduce the total number of nodes in the tree after performing node manipulations. For example, if two sibling leaf nodes both represent the same
RegionLocation, then there is no reason from the perspective of the geometric region to retain both nodes. They are therefore both merged into their parent node. This method performs this simplification process.- Returns:
- true if the tree structure was modified, otherwise false
-
copyNodeProperties
Copy non-structural node properties fromsrctodst. Non-structural properties are those properties not directly related to the structure of the BSP tree, i.e. properties other than parent/child connections and cuts. Subclasses should override this method to copy additional properties stored on nodes.- Specified by:
copyNodePropertiesin classAbstractBSPTree<P extends Point<P>,N extends AbstractRegionBSPTree.AbstractRegionNode<P, N>> - Parameters:
src- source nodedst- destination node
-
invalidate
protected void invalidate()Invalidate any previously computed properties that rely on the internal structure of the tree. This method must be called any time the tree's internal structure changes in order to force cacheable tree and node properties to be recomputed the next time they are requested.This method increments the tree's
AbstractBSPTree.versionproperty.- Overrides:
invalidatein classAbstractBSPTree<P extends Point<P>,N extends AbstractRegionBSPTree.AbstractRegionNode<P, N>> - See Also:
-