1 package edu.berkeley.qfat.geom;
2 import javax.media.opengl.*;
4 import com.infomatiq.jsi.*;
5 import com.infomatiq.jsi.rtree.*;
7 /** wrapper around the <tt>com.infomatiq.jsi.rtree.RTree</tt> class */
8 public class RTree<V extends HasBoundingBox> implements Iterable<V> {
10 private com.infomatiq.jsi.rtree.RTree rtree =
11 new com.infomatiq.jsi.rtree.RTree();
13 private int lowid = 0;
14 private HashMap<Integer, V> idToV = new HashMap<Integer, V>();
15 private HashMap<V, Integer> vToId = new HashMap<V, Integer>();
17 public Iterator<V> iterator() { return vToId.keySet().iterator(); }
19 private final MyIntProcedure myIntProcedure = new MyIntProcedure();
20 private final com.infomatiq.jsi.Rectangle rect = new com.infomatiq.jsi.Rectangle(0,0,0,0,0,0);
21 private final com.infomatiq.jsi.Point point = new com.infomatiq.jsi.Point(0,0,0);
22 private V found = null;
23 private Visitor<V> visitor = null;
25 private static final Properties props = new Properties();
27 props.put("MinNodeEntries", "1");
28 props.put("MaxNodeEntries", "5");
31 public RTree() { clear(); }
39 public void add(V v) { insert(v); }
40 public void insert(V v) {
44 rect.set(v.getMinX(), v.getMinY(), v.getMinZ(), v.getMaxX(), v.getMaxY(), v.getMaxZ());
48 public void remove(V v) {
49 Integer idi = vToId.get(v);
50 if (idi==null) return;
54 rect.set(v.getMinX(), v.getMinY(), v.getMinZ(), v.getMaxX(), v.getMaxY(), v.getMaxZ());
55 rtree.delete(rect, id);
58 public V nearest(Point p) {
59 point.set(p.x, p.y, p.z);
60 rtree.nearest(point, myIntProcedure, Float.POSITIVE_INFINITY);
66 public void range(HasBoundingBox v, Visitor vis) {
68 rtree.intersects(rect, myIntProcedure);
72 private class MyIntProcedure implements IntProcedure {
73 public boolean execute(int id) {
74 if (visitor != null) {
79 found = idToV.get(id);