X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fqfat%2Fgeom%2FRTree.java;h=35b6f9b03d89e902c4695a33e5b7f2edf0b940ce;hb=f42953f58e189d611803dcb4661bb840d785c30a;hp=cd1d21764cb6251e508bb621915b5a3c45efe004;hpb=719b7ba4c0fe32a0c9e97aeb0156a999794dd0f7;p=anneal.git
diff --git a/src/edu/berkeley/qfat/geom/RTree.java b/src/edu/berkeley/qfat/geom/RTree.java
index cd1d217..35b6f9b 100644
--- a/src/edu/berkeley/qfat/geom/RTree.java
+++ b/src/edu/berkeley/qfat/geom/RTree.java
@@ -4,17 +4,24 @@ import java.util.*;
import com.infomatiq.jsi.*;
import com.infomatiq.jsi.rtree.*;
+/** wrapper around the com.infomatiq.jsi.rtree.RTree class */
public class RTree implements Iterable {
private com.infomatiq.jsi.rtree.RTree rtree =
new com.infomatiq.jsi.rtree.RTree();
- int lowid = 0;
- HashMap idToV = new HashMap();
- HashMap vToId = new HashMap();
+ private int lowid = 0;
+ private HashMap idToV = new HashMap();
+ private HashMap vToId = new HashMap();
public Iterator 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 visitor = null;
+
private static final Properties props = new Properties();
static {
props.put("MinNodeEntries", "1");
@@ -34,9 +41,8 @@ public class RTree implements Iterable {
int id = lowid++;
idToV.put(id, v);
vToId.put(v, id);
- rtree.add(new com.infomatiq.jsi.Rectangle(v.getMinX(), v.getMinY(), v.getMinZ(),
- v.getMaxX(), v.getMaxY(), v.getMaxZ()),
- id);
+ rect.set(v.getMinX(), v.getMinY(), v.getMinZ(), v.getMaxX(), v.getMaxY(), v.getMaxZ());
+ rtree.add(rect, id);
}
public void remove(V v) {
@@ -45,41 +51,34 @@ public class RTree implements Iterable {
int id = idi;
idToV.remove(id);
vToId.remove(v);
- rtree.delete(new com.infomatiq.jsi.Rectangle(v.getMinX(), v.getMinY(), v.getMinZ(),
- v.getMaxX(), v.getMaxY(), v.getMaxZ()),
- id);
+ rect.set(v.getMinX(), v.getMinY(), v.getMinZ(), v.getMaxX(), v.getMaxY(), v.getMaxZ());
+ 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 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;
+ }
+ }
+ }
}