P
- Point implementation typeN
- BSP tree node implementation typepublic abstract static class AbstractBSPTree.AbstractNode<P extends Point<P>,N extends AbstractBSPTree.AbstractNode<P,N>> extends Object implements BSPTree.Node<P,N>
BSPTree.Node
. This class is intended for use with
AbstractBSPTree
and delegates tree mutation methods back to the parent tree object.Modifier | Constructor and Description |
---|---|
protected |
AbstractNode(AbstractBSPTree<P,N> tree)
Simple constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
accept(BSPTreeVisitor<P,N> visitor)
Accept a visitor instance, calling it with each node from the subtree.
|
protected void |
checkValid()
Check if cached node properties are valid, meaning that no structural updates have
occurred in the tree since the last call to this method.
|
int |
count()
Return the total number of nodes in the subtree.
|
int |
depth()
Get the depth of the node in the tree.
|
HyperplaneConvexSubset<P> |
getCut()
Get the cut for the node.
|
Hyperplane<P> |
getCutHyperplane()
Get the hyperplane containing the node cut, if it exists.
|
N |
getMinus()
Get the node for the minus region of the cell.
|
N |
getParent()
Get the parent of the node.
|
N |
getPlus()
Get the node for the plus region of the cell.
|
protected abstract N |
getSelf()
Get a reference to the current instance, cast to type N.
|
AbstractBSPTree<P,N> |
getTree()
Get the
BSPTree that owns the node. |
int |
height()
The height of the subtree, ie the length of the longest downward path from
the subtree root to a leaf node.
|
boolean |
isInternal()
Return true if the node is an internal node, meaning that is
has a binary partitioner (aka "cut") and therefore two child nodes.
|
boolean |
isLeaf()
Return true if the node is a leaf node, meaning that it has no
binary partitioner (aka "cut") and therefore no child nodes.
|
boolean |
isMinus()
Return true if the node has a parent and is the parent's minus
child.
|
boolean |
isPlus()
Return true if the node has a parent and is the parent's plus
child.
|
protected void |
makeRoot()
Make this node a root node, detaching it from its parent and settings its depth to zero.
|
protected void |
nodeInvalidated()
Method called from
checkValid() when updates
are detected in the tree. |
Iterable<N> |
nodes()
Get an iterable for accessing the nodes in this subtree.
|
protected void |
setSubtree(HyperplaneConvexSubset<P> newCut,
N newMinus,
N newPlus)
Set the parameters for the subtree rooted at this node.
|
String |
toString() |
HyperplaneConvexSubset<P> |
trim(HyperplaneConvexSubset<P> sub)
Trim the given hyperplane subset to the region defined by this node by cutting
the argument with the cut hyperplanes (binary partitioners) of all parent nodes
up to the root.
|
protected AbstractNode(AbstractBSPTree<P,N> tree)
tree
- the tree instance that owns this nodepublic AbstractBSPTree<P,N> getTree()
BSPTree
that owns the node.getTree
in interface BSPTree.Node<P extends Point<P>,N extends AbstractBSPTree.AbstractNode<P,N>>
public int depth()
depth
in interface BSPTree.Node<P extends Point<P>,N extends AbstractBSPTree.AbstractNode<P,N>>
public int height()
height
in interface BSPSubtree<P extends Point<P>,N extends AbstractBSPTree.AbstractNode<P,N>>
public int count()
count
in interface BSPSubtree<P extends Point<P>,N extends AbstractBSPTree.AbstractNode<P,N>>
public Iterable<N> nodes()
BSPSubtree.accept(BSPTreeVisitor)
for accessing tree nodes but is not
as powerful or flexible since the node iteration order is fixed.nodes
in interface BSPSubtree<P extends Point<P>,N extends AbstractBSPTree.AbstractNode<P,N>>
public void accept(BSPTreeVisitor<P,N> visitor)
accept
in interface BSPSubtree<P extends Point<P>,N extends AbstractBSPTree.AbstractNode<P,N>>
visitor
- visitor called with each subtree nodepublic N getParent()
getParent
in interface BSPTree.Node<P extends Point<P>,N extends AbstractBSPTree.AbstractNode<P,N>>
public boolean isLeaf()
isLeaf
in interface BSPTree.Node<P extends Point<P>,N extends AbstractBSPTree.AbstractNode<P,N>>
public boolean isInternal()
isInternal
in interface BSPTree.Node<P extends Point<P>,N extends AbstractBSPTree.AbstractNode<P,N>>
public boolean isPlus()
isPlus
in interface BSPTree.Node<P extends Point<P>,N extends AbstractBSPTree.AbstractNode<P,N>>
public boolean isMinus()
isMinus
in interface BSPTree.Node<P extends Point<P>,N extends AbstractBSPTree.AbstractNode<P,N>>
public HyperplaneConvexSubset<P> getCut()
getCut
in interface BSPTree.Node<P extends Point<P>,N extends AbstractBSPTree.AbstractNode<P,N>>
BSPTree.Node.getPlus()
,
BSPTree.Node.getMinus()
,
BSPTree.Node.getCutHyperplane()
public Hyperplane<P> getCutHyperplane()
getCutHyperplane
in interface BSPTree.Node<P extends Point<P>,N extends AbstractBSPTree.AbstractNode<P,N>>
BSPTree.Node.getCut()
public N getPlus()
getPlus
in interface BSPTree.Node<P extends Point<P>,N extends AbstractBSPTree.AbstractNode<P,N>>
public N getMinus()
getMinus
in interface BSPTree.Node<P extends Point<P>,N extends AbstractBSPTree.AbstractNode<P,N>>
public HyperplaneConvexSubset<P> trim(HyperplaneConvexSubset<P> sub)
trim
in interface BSPTree.Node<P extends Point<P>,N extends AbstractBSPTree.AbstractNode<P,N>>
sub
- the hyperplane subset to trimprotected void setSubtree(HyperplaneConvexSubset<P> newCut, N newMinus, N newPlus)
Absolutely no validation is performed on the arguments. Callers are responsible for ensuring that any given hyperplane subset fits the region defined by the node and that any child nodes belong to this tree and are correctly initialized.
newCut
- the new cut hyperplane subset for the nodenewMinus
- the new minus child for the nodenewPlus
- the new plus child for the nodeprotected void makeRoot()
protected void checkValid()
nodeInvalidated()
method is called to clear the cached properties. This method
should be called at the beginning of any method that fetches cacheable properties
to ensure that no stale values are returned.protected void nodeInvalidated()
checkValid()
when updates
are detected in the tree. This method should clear out any
computed properties that rely on the structure of the tree
and prepare them for recalculation.Copyright © 2016–2021 The Apache Software Foundation. All rights reserved.