import com.infomatiq.jsi.*;
import com.infomatiq.jsi.rtree.*;
+/** wrapper around the <tt>com.infomatiq.jsi.rtree.RTree</tt> class */
public class RTree<V extends HasBoundingBox> implements Iterable<V> {
private com.infomatiq.jsi.rtree.RTree rtree =
public Iterator<V> iterator() { return vToId.keySet().iterator(); }
+ private final MyIntProcedure myIntProcedure = new MyIntProcedure();
+ private final com.infomatiq.jsi.Rectangle rect = new com.infomatiq.jsi.Rectangle(0,0,0,0,0,0);
+ private final com.infomatiq.jsi.Point point = new com.infomatiq.jsi.Point(0,0,0);
+ private V found = null;
+ private Visitor<V> visitor = null;
+
private static final Properties props = new Properties();
static {
props.put("MinNodeEntries", "1");
rtree.add(rect, id);
}
- private com.infomatiq.jsi.Rectangle rect = new com.infomatiq.jsi.Rectangle(0,0,0,0,0,0);
public void remove(V v) {
Integer idi = vToId.get(v);
if (idi==null) return;
rtree.delete(rect, id);
}
- // gross...
- V found = null;
- private IntProcedure finder = new IntProcedure() {
- public boolean execute(int id) {
- found = idToV.get(id);
- return false;
- }
- };
-
public V nearest(Point p) {
- rtree.nearest(new com.infomatiq.jsi.Point(p.x, p.y, p.z), finder, Float.POSITIVE_INFINITY);
+ point.set(p.x, p.y, p.z);
+ rtree.nearest(point, myIntProcedure, Float.POSITIVE_INFINITY);
V ret = found;
found = null;
return ret;
}
- Visitor<V> visitor = null;
- private IntProcedure searcher = new IntProcedure() {
- public boolean execute(int id) {
- V v = idToV.get(id);
- visitor.visit(v);
- return true;
- }
- };
public void range(HasBoundingBox v, Visitor vis) {
visitor = vis;
- rtree.intersects(new com.infomatiq.jsi.Rectangle(v.getMinX(), v.getMinY(), v.getMinZ(),
- v.getMaxX(), v.getMaxY(), v.getMaxZ()),
- searcher);
+ rtree.intersects(rect, myIntProcedure);
visitor = null;
}
+ private class MyIntProcedure implements IntProcedure {
+ public boolean execute(int id) {
+ if (visitor != null) {
+ V v = idToV.get(id);
+ visitor.visit(v);
+ return true;
+ } else {
+ found = idToV.get(id);
+ return false;
+ }
+ }
+ }
}