TData - Data stored in each leaf nodeTBoundary - An object that splits the space into two distinct subsetspublic class BspTree<TData,TBoundary> extends Object implements IConstBspTree<TData,TBoundary>, Serializable
This is a generic implementation supporting both 2D and 3D spaces (or any other space, even non-euclidean). The TBoundary type parameter and the provided strategy define the space and how it is partitioned. BspTreeND, Point2D, StraightLine2D>( new BspLinePartitiongStrategy(6), ? ) would define a 2D BSP tree with up to 6 elements per leaf. BspTreeND, Point3D, Plane3D>( new BspPlanePartitiongStrategy(6), ? ) would define a 3D BSP tree with up to 6 elements per leaf.
| Modifier and Type | Field and Description |
|---|---|
protected IBspNode<TData,TBoundary> |
root |
protected IBspStrategy<TData,TBoundary> |
strategy |
| Constructor and Description |
|---|
BspTree(IBspStrategy<TData,TBoundary> strategy)
Constructor
Creates an empty leaf as root.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addData(IBspNode<TData,TBoundary> node,
TData data)
Add data to a particular node
Low-level API.
|
void |
addData(TData data)
Add data to the tree
May cause tree optimization - splitting of nodes.
|
IConstBspTree<TData,TBoundary> |
asConst()
Get constant interface
|
void |
clear()
Clear tree
Remove all data and nodes and create a new empty leaf root.
|
IBspNode<TData,TBoundary> |
getRoot()
Get root node
|
IBspStrategy<TData,TBoundary> |
getStrategy()
Get strategy
|
static <TData,TBoundary> |
make(IBspStrategy<TData,TBoundary> strategy)
Make empty tree
Shortcut to avoid having to specify type parameters.
|
static <TData,TBoundary> |
make(IBspStrategy<TData,TBoundary> strategy,
TData data)
Make tree with data
Shortcut to avoid having to specify type parameters.
|
BspInternalNode<TData,TBoundary> |
makeInternalNode()
Make internal node
Shortcut to avoid having to specify type parameters.
|
BspLeafNode<TData,TBoundary> |
makeLeafNode()
Make leaf node
Shortcut to avoid having to specify type parameters.
|
void |
optimize(BspLeafNode<TData,TBoundary> nodeToOptimize)
Optimize leaf node
Recursively splits data as determined by partitioning strategy to optimize tree performance.
|
void |
removeData(IBspNode<TData,TBoundary> node,
TData dataToRemove)
Remove data from a particular node
Low-level API.
|
void |
removeData(TData dataToRemove)
Remove data from the tree
|
void |
replace(IBspNode<TData,TBoundary> oldNode,
IBspNode<TData,TBoundary> newNode)
Replace old node in the tree by a new node
Low-level API.
|
protected void |
setDepthRecursively(IBspNode<TData,TBoundary> node,
int depth) |
void |
setRoot(IBspNode<TData,TBoundary> value)
Set the root node
Low-level API.
|
protected IBspStrategy<TData,TBoundary> strategy
public BspTree(IBspStrategy<TData,TBoundary> strategy)
Creates an empty leaf as root.
strategy - partitioning strategy to usepublic static <TData,TBoundary> BspTree<TData,TBoundary> make(IBspStrategy<TData,TBoundary> strategy, TData data)
Shortcut to avoid having to specify type parameters.
strategy - strategy to usedata - data to store in the tree,public static <TData,TBoundary> BspTree<TData,TBoundary> make(IBspStrategy<TData,TBoundary> strategy)
Shortcut to avoid having to specify type parameters.
strategy - splitting strategy to usepublic IConstBspTree<TData,TBoundary> asConst()
public IBspNode<TData,TBoundary> getRoot()
IConstBspTreegetRoot in interface IConstBspTree<TData,TBoundary>public IBspStrategy<TData,TBoundary> getStrategy()
IConstBspTreegetStrategy in interface IConstBspTree<TData,TBoundary>public void addData(TData data)
May cause tree optimization - splitting of nodes.
data - data to add, may be null, which would result in no oppublic void addData(IBspNode<TData,TBoundary> node, TData data)
Low-level API.
Caution: If the data spans multiple nodes, it must be added to all such nodes otherwise tree will become corrupted. May cause tree optimization - splitting of nodes.
node - node to which data should be addeddata - data to add, may be null, which would result in no oppublic void removeData(TData dataToRemove)
dataToRemove - data to removepublic void removeData(IBspNode<TData,TBoundary> node, TData dataToRemove)
Low-level API.
Caution: If the tree contains a portion of the data in multiple nodes, the data must be removed from all such nodes otherwise the tree will become corrupted.
node - node to remove data fromdataToRemove - data to removepublic void optimize(BspLeafNode<TData,TBoundary> nodeToOptimize)
Recursively splits data as determined by partitioning strategy to optimize tree performance.
nodeToOptimize - optimized nodepublic BspLeafNode<TData,TBoundary> makeLeafNode()
Shortcut to avoid having to specify type parameters.
public BspInternalNode<TData,TBoundary> makeInternalNode()
Shortcut to avoid having to specify type parameters.
public void replace(IBspNode<TData,TBoundary> oldNode, IBspNode<TData,TBoundary> newNode)
Low-level API.
oldNode - node to replace, supports both root and internal nodes and both parent and leaf nodesnewNode - new node to take place of the old nodepublic void clear()
Remove all data and nodes and create a new empty leaf root.
Copyright © 2019 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All rights reserved.