public class KdTree
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected static int |
DEFAULT_MAX_LEAF_NODE_SIZE
Default value for maximum number of objects in leaf nodes.
|
protected static int |
DEFAULT_MAX_MEDIAN_SAMPLES
Default value for maximum number of samples taken to estimate coordinate median.
|
protected int |
maxLeafNodeSize
Maximum number of objects in leaf nodes.
|
protected int |
maxMedianSamples
Maximum number of samples taken to estimate coordinate median.
|
protected java.util.Random |
random
Random for picking object samples for estimating median.
|
protected KdNode |
rootNode
The root node.
|
Constructor and Description |
---|
KdTree()
Generates an empty KdTree using default configuration.
|
KdTree(int maxLeafNodeSize,
int maxMedianSamples)
Generates an empty KdTree.
|
Modifier and Type | Method and Description |
---|---|
void |
addObject(ISpaceObject obj)
Adds an object to the tree.
|
ISpaceObject |
getNearestObject(IVector2 point)
Finds an object closest to the given point (exhaustive search!).
|
ISpaceObject |
getNearestObject(IVector2 point,
double searchRadius)
Finds an object closest to the given point with a given search radius.
|
ISpaceObject |
getNearestObject(IVector2 point,
double searchRadius,
IFilter filter)
Finds an object closest to the given point with a given search radius,
while filtering objects.
|
ISpaceObject |
getNearestObject(IVector2 point,
IFilter filter)
Finds an object closest to the given point while filtering objects (exhaustive search!).
|
java.util.List<ISpaceObject> |
getNearestObjects(IVector2 point,
double radius)
Finds all objects within a given search radius.
|
java.util.List<ISpaceObject> |
getNearestObjects(IVector2 point,
double radius,
IFilter filter)
Finds all objects within a given search radius.
|
void |
rebuild()
Rebuilds the tree, updating spatial information, adding objects and removing objects.
|
void |
removeObject(ISpaceObject obj)
Removes an object to the tree.
|
protected static final int DEFAULT_MAX_LEAF_NODE_SIZE
protected static final int DEFAULT_MAX_MEDIAN_SAMPLES
protected KdNode rootNode
protected java.util.Random random
protected int maxLeafNodeSize
protected int maxMedianSamples
public KdTree()
public KdTree(int maxLeafNodeSize, int maxMedianSamples)
maxLeafNodeSize
- Maximum number of objects in leaf nodes.maxMedianSamples
- Maximum number of samples taken to estimate coordinate median.public java.util.List<ISpaceObject> getNearestObjects(IVector2 point, double radius)
point
- Center of the search area.radius
- The search radius.public java.util.List<ISpaceObject> getNearestObjects(IVector2 point, double radius, IFilter filter)
point
- Center of the search area.radius
- The search radius.filter
- Object filter.public ISpaceObject getNearestObject(IVector2 point)
point
- The point.public ISpaceObject getNearestObject(IVector2 point, IFilter filter)
point
- The point.filter
- Object filter.public ISpaceObject getNearestObject(IVector2 point, double searchRadius)
point
- The point.searchRadius
- The search radius.public ISpaceObject getNearestObject(IVector2 point, double searchRadius, IFilter filter)
point
- The point.searchRadius
- The search radius.filter
- Object filter.public void addObject(ISpaceObject obj)
obj
- The object being added.public void removeObject(ISpaceObject obj)
obj
- The object being removed.public void rebuild()