public class SpatialHashTable<T>
extends java.lang.Object
List<T> myElements; ... SpatialHashTable<T> table = new SpatialHashTable<>(spacing); List<Point3d> positions = new ArrayList<Point3d>(); for (T el : myElements) { positions.add(el.getPos()); } table.setup(positions,elements); // construct map Point3d mySearchPoint = new Point3d(0., 1., 2.); Iterator<List<T>> it = table.getCellsNear (searchPoint); while (it.hasNext()) { List<T> cell = it.next(); for (T el : cell) { el.doSomething(); } }
Constructor and Description |
---|
SpatialHashTable(double gridSpacing) |
Modifier and Type | Method and Description |
---|---|
java.util.Map<java.util.List<T>,java.util.ArrayList<BVNode>> |
getCellsIntersecting(BVTree bvtree)
Returns a List of cells (List<T>'s) that might intersect a
bv tree.
|
java.util.Iterator<java.util.List<T>> |
getCellsNear(Point3d pos)
Return an iterator which iterates through 27 cells.
|
java.util.Iterator<java.util.List<T>> |
getCellsNearOld(Point3d pos)
This is the old method that for sure works, but might be slower.
|
void |
setup(java.util.List<? extends Point3d> positions,
java.util.List<? extends T> elements)
Replace the current map with a
new one generated from positions and elements.
|
void |
testIter(int a,
int b,
int c) |
public void setup(java.util.List<? extends Point3d> positions, java.util.List<? extends T> elements)
positions
- List of positions that determine the
position of each element in elementselements
- List of elements which will populate this
SpatialHashTablepublic java.util.Map<java.util.List<T>,java.util.ArrayList<BVNode>> getCellsIntersecting(BVTree bvtree)
bvtree
- public java.util.Iterator<java.util.List<T>> getCellsNear(Point3d pos)
pos
- A position in the centre bin.public java.util.Iterator<java.util.List<T>> getCellsNearOld(Point3d pos)
pos
- public void testIter(int a, int b, int c)