Commit a7715017 authored by Daniel Eggert's avatar Daniel Eggert
Browse files

Added RETree implementation option to IndexMediator

parent 798505e0
/**
*
*/
package de.potsdam.gfz.gms.database.indexes;
import java.util.List;
import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.index.ItemVisitor;
import com.vividsolutions.jts.index.SpatialIndex;
import de.potsdam.gfz.gms.utils.datastructures.trees.rtree.RETree;
/**
* @author Daniel Eggert (daniel.eggert@gfz-potsdam.de)
*
*/
public class SpatialRETree implements SpatialIndex {
private static final int MAX_ENTRIES = 128;
private static final int MIN_ENTRIES = 32;
private RETree<Integer> tree = new RETree<>(MIN_ENTRIES, MAX_ENTRIES, 2);
/*
* (non-Javadoc)
*
* @see com.vividsolutions.jts.index.SpatialIndex#insert(com.vividsolutions.jts.geom.Envelope, java.lang.Object)
*/
@Override
public void insert(Envelope e, Object item) {
tree.insert(toGmsEnvelope(e), (Integer) item);
}
/*
* (non-Javadoc)
*
* @see com.vividsolutions.jts.index.SpatialIndex#query(com.vividsolutions.jts.geom.Envelope)
*/
@Override
public List<Integer> query(Envelope searchEnv) {
throw new UnsupportedOperationException();
}
/*
* (non-Javadoc)
*
* @see com.vividsolutions.jts.index.SpatialIndex#query(com.vividsolutions.jts.geom.Envelope, com.vividsolutions.jts.index.ItemVisitor)
*/
@Override
public void query(Envelope searchEnv, ItemVisitor visitor) {
tree.parallelWorkerSearch(toGmsEnvelope(searchEnv), toGmsVisitor(visitor));
}
/*
* (non-Javadoc)
*
* @see com.vividsolutions.jts.index.SpatialIndex#remove(com.vividsolutions.jts.geom.Envelope, java.lang.Object)
*/
@Override
public boolean remove(Envelope itemEnv, Object item) {
throw new UnsupportedOperationException();
}
private static de.potsdam.gfz.gms.utils.datastructures.trees.rtree.aux.Envelope toGmsEnvelope(Envelope jtsEnv) {
return new de.potsdam.gfz.gms.utils.datastructures.trees.rtree.aux.Envelope(new double[] { jtsEnv.getMinX(), jtsEnv.getMinY() },
new double[] { jtsEnv.getMaxX(), jtsEnv.getMaxY() });
}
private static de.potsdam.gfz.gms.utils.datastructures.trees.rtree.aux.ItemVisitor<Integer> toGmsVisitor(final ItemVisitor jtsVisitor) {
return new de.potsdam.gfz.gms.utils.datastructures.trees.rtree.aux.ItemVisitor<Integer>() {
@Override
public void visitItem(Integer item) {
jtsVisitor.visitItem(item);
}
};
}
}
......@@ -20,6 +20,8 @@ import org.slf4j.LoggerFactory;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.index.ItemVisitor;
import com.vividsolutions.jts.index.SpatialIndex;
import com.vividsolutions.jts.index.strtree.AbstractSTRtree;
import com.vividsolutions.jts.index.strtree.STRtree;
import de.potsdam.gfz.gms.database.SceneDatabase;
......@@ -52,7 +54,7 @@ public class SpatialSceneIndex implements SceneIndex {
private static SceneIndex instance = null;
private final STRtree rTree;
private final SpatialIndex rTree;
private final int[] ids;
private final short[] datasetids;
......@@ -177,7 +179,9 @@ public class SpatialSceneIndex implements SceneIndex {
LOG.info(numScenes + " of " + totalScenes + " processed.");
LOG.info("building index");
rTree.build();
if (rTree instanceof AbstractSTRtree) {
((AbstractSTRtree) rTree).build();
}
LOG.info("finished building index");
}
......
......@@ -63,7 +63,10 @@ public class SceneIterator implements Iterator<Scene>, Closeable {
}
}
buffer.add(LAST_INDICATOR);
try {
buffer.put(LAST_INDICATOR);
} catch (InterruptedException e) {
}
}
};
......
......@@ -3,8 +3,6 @@ package de.potsdam.gfz.gms.utils.datastructures.trees.rtree;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.RecursiveAction;
import java.util.concurrent.Semaphore;
import java.util.concurrent.atomic.AtomicInteger;
......@@ -56,7 +54,7 @@ public abstract class AbstractRTree<T> implements Tree<T> {
/**
* Number of available cpus
*/
private static final int NUM_CPUS = Runtime.getRuntime().availableProcessors();
// private static final int NUM_CPUS = Runtime.getRuntime().availableProcessors();
/** the root node */
protected InnerNode root = null;
......@@ -64,12 +62,6 @@ public abstract class AbstractRTree<T> implements Tree<T> {
/** number of items */
protected int size = 0;
/** global pool */
private static ForkJoinPool pool = null; // new
// ForkJoinPool();
// //
// new
// ForkJoinPool();
/** count of visited nodes */
private final static AtomicInteger visitedNodeCount = new AtomicInteger(0);
......@@ -200,11 +192,6 @@ public abstract class AbstractRTree<T> implements Tree<T> {
root = null;
size = 0;
shutdownWorker();
if (pool != null) {
pool.shutdownNow();
pool = null;
}
}
@Override
......@@ -214,9 +201,6 @@ public abstract class AbstractRTree<T> implements Tree<T> {
// init parallel worker
initWorker();
// init fork join pool
pool = new ForkJoinPool();
}
protected void updateSubtreeSizes() {
......@@ -295,21 +279,6 @@ public abstract class AbstractRTree<T> implements Tree<T> {
return results;
}
@Override
public List<T> parallelForkJoinSearch(Envelope env) {
// use a thread safe list -> vector
final List<T> results = new CopyOnWriteArrayList<>();
parallelForkJoinSearch(env, new ItemVisitor<T>() {
@Override
public void visitItem(T item) {
results.add(item);
}
});
return results;
}
/**
* returns the relative overlapping volume of a tree level
*
......@@ -672,15 +641,6 @@ public abstract class AbstractRTree<T> implements Tree<T> {
}
}
@Override
public void parallelForkJoinSearch(Envelope env, ItemVisitor<T> visitor) {
visitedNodeCount.set(0);
if (pool == null) {
return;
}
pool.invoke(new ForkSearch<>(visitor, root, getSize() / NUM_CPUS, env));
}
/*
* (non-Javadoc)
*
......
......@@ -52,14 +52,6 @@ public interface Tree<T> {
*/
public List<T> search(Envelope env);
/**
* Search an envelope from the tree parallel with fork'n'join pattern and returns a list of all envelops which
* intersects the envelope
*
* @param env
*/
public List<T> parallelForkJoinSearch(Envelope env);
/**
* Determines all items intersecting the given envelope using parallel worker threads
*
......@@ -108,15 +100,6 @@ public interface Tree<T> {
*/
public void search(Envelope env, ItemVisitor<T> visitor);
/**
* Search an envelope from the tree with a specific visitor and returns a list of all envelops which intersects the
* envelope
*
* @param env
* @param visitor
*/
public void parallelForkJoinSearch(Envelope env, ItemVisitor<T> visitor);
public void parallelWorkerSearch(Envelope env, ItemVisitor<T> visitor);
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment