1 package edu.berkeley.qfat.geom;
2 import javax.media.opengl.*;
4 import com.infomatiq.jsi.*;
5 import com.infomatiq.jsi.rtree.*;
7 public class RTree<V extends HasBoundingBox> implements Iterable<V> {
9 private com.infomatiq.jsi.rtree.RTree rtree =
10 new com.infomatiq.jsi.rtree.RTree();
12 private int lowid = 0;
13 private HashMap<Integer, V> idToV = new HashMap<Integer, V>();
14 private HashMap<V, Integer> vToId = new HashMap<V, Integer>();
16 public Iterator<V> iterator() { return vToId.keySet().iterator(); }
18 private static final Properties props = new Properties();
20 props.put("MinNodeEntries", "1");
21 props.put("MaxNodeEntries", "5");
24 public RTree() { clear(); }
32 public void add(V v) { insert(v); }
33 public void insert(V v) {
37 rect.set(v.getMinX(), v.getMinY(), v.getMinZ(), v.getMaxX(), v.getMaxY(), v.getMaxZ());
41 private com.infomatiq.jsi.Rectangle rect = new com.infomatiq.jsi.Rectangle(0,0,0,0,0,0);
42 public void remove(V v) {
43 Integer idi = vToId.get(v);
44 if (idi==null) return;
48 rect.set(v.getMinX(), v.getMinY(), v.getMinZ(), v.getMaxX(), v.getMaxY(), v.getMaxZ());
49 rtree.delete(rect, id);
54 private IntProcedure finder = new IntProcedure() {
55 public boolean execute(int id) {
56 found = idToV.get(id);
61 public V nearest(Point p) {
62 rtree.nearest(new com.infomatiq.jsi.Point(p.x, p.y, p.z), finder, Float.POSITIVE_INFINITY);
68 Visitor<V> visitor = null;
69 private IntProcedure searcher = new IntProcedure() {
70 public boolean execute(int id) {
76 public void range(HasBoundingBox v, Visitor vis) {
78 rtree.intersects(new com.infomatiq.jsi.Rectangle(v.getMinX(), v.getMinY(), v.getMinZ(),
79 v.getMaxX(), v.getMaxY(), v.getMaxZ()),