From 07751f52bde12760217a83f044608eaf779e8ed2 Mon Sep 17 00:00:00 2001 From: adam Date: Sat, 15 Dec 2007 17:27:58 -0800 Subject: [PATCH] checkpoint darcs-hash:20071216012758-5007d-166fa72d432252c378f9ee5ec9df268dda1be75e.gz --- src/com/infomatiq/jsi/Point.java | 6 ++++++ src/edu/berkeley/qfat/geom/RTree.java | 36 ++++++++++++++++----------------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/com/infomatiq/jsi/Point.java b/src/com/infomatiq/jsi/Point.java index c608971..0134c73 100644 --- a/src/com/infomatiq/jsi/Point.java +++ b/src/com/infomatiq/jsi/Point.java @@ -48,4 +48,10 @@ public class Point { coordinates[1] = y; coordinates[2] = z; } + + public void set(float x, float y, float z) { + coordinates[0] = x; + coordinates[1] = y; + coordinates[2] = z; + } } diff --git a/src/edu/berkeley/qfat/geom/RTree.java b/src/edu/berkeley/qfat/geom/RTree.java index b9078e1..2fab5f5 100644 --- a/src/edu/berkeley/qfat/geom/RTree.java +++ b/src/edu/berkeley/qfat/geom/RTree.java @@ -15,6 +15,12 @@ public class RTree implements Iterable { 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"); @@ -38,7 +44,6 @@ public class RTree implements Iterable { 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; @@ -49,35 +54,30 @@ public class RTree implements Iterable { rtree.delete(rect, id); } - // gross... - V found = null; - private IntProcedure finder = new IntProcedure() { - public boolean execute(int id) { + 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; } - }; + } + } 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; } -- 1.7.10.4