X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Fedu%2Fberkeley%2Fqfat%2Fgeom%2FRTree.java;h=5a29093ec98bcf1a48b5b9abc3db7ecc77f8fa0b;hb=5239d59bb876c25b263a24dbff11dc7a9082a431;hp=2fab5f5c84d0596f8f7b9bdbcc14fa9c9f2113ed;hpb=07751f52bde12760217a83f044608eaf779e8ed2;p=anneal.git diff --git a/src/edu/berkeley/qfat/geom/RTree.java b/src/edu/berkeley/qfat/geom/RTree.java index 2fab5f5..5a29093 100644 --- a/src/edu/berkeley/qfat/geom/RTree.java +++ b/src/edu/berkeley/qfat/geom/RTree.java @@ -4,6 +4,7 @@ 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 = @@ -15,10 +16,10 @@ public class RTree implements Iterable { public Iterator iterator() { return vToId.keySet().iterator(); } - private final MyIntProcedure myIntProcedure = new MyIntProcedure(); + 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 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(); @@ -54,31 +55,39 @@ public class RTree implements Iterable { rtree.delete(rect, 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) { + public V nearest(Point p) { return nearest(p, null); } + public V nearest(Point p, Visitor ip) { point.set(p.x, p.y, p.z); + this.visitor = ip; rtree.nearest(point, myIntProcedure, Float.POSITIVE_INFINITY); + this.visitor = null; V ret = found; found = null; return ret; } - public void range(HasBoundingBox v, Visitor vis) { + public void range(HasBoundingBox v, Visitor vis) { visitor = vis; + rect.set(v.getMinX(), v.getMinY(), v.getMinZ(), v.getMaxX(), v.getMaxY(), v.getMaxZ()); rtree.intersects(rect, myIntProcedure); visitor = null; } + public void range(Point p1, Point p2, Visitor vis) { + visitor = vis; + rect.set(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z); + rtree.intersects(rect, myIntProcedure); + visitor = null; + } + + private class MyIntProcedure implements IntProcedure { + public boolean execute(int id) { + found = idToV.get(id); + if (visitor != null) { + return visitor.visit(found); + } else { + return false; + } + } + } }