Search in sources :

Example 46 with RectDouble2D

use of jcog.tree.rtree.rect.RectDouble2D in project narchy by automenta.

the class RTree2DTest method treeStructureStatsTest.

/**
 * Collect stats making the structure of trees of each split type
 * more visible.
 */
@Disabled
public // This test ignored because output needs to be manually evaluated.
void treeStructureStatsTest() {
    final int entryCount = 50_000;
    final RectDouble2D[] rects = generateRandomRects(entryCount);
    for (Spatialization.DefaultSplits type : Spatialization.DefaultSplits.values()) {
        RTree<RectDouble2D> rTree = createRect2DTree(2, 8, type);
        for (int i = 0; i < rects.length; i++) {
            rTree.add(rects[i]);
        }
        Stats stats = rTree.stats();
        stats.print(System.out);
    }
}
Also used : Stats(jcog.tree.rtree.util.Stats) RectDouble2D(jcog.tree.rtree.rect.RectDouble2D) Disabled(org.junit.jupiter.api.Disabled)

Example 47 with RectDouble2D

use of jcog.tree.rtree.rect.RectDouble2D in project narchy by automenta.

the class RTree2DTest method treeRemoveAndRebalanceTest.

@Disabled
public // This test ignored because output needs to be manually evaluated.
void treeRemoveAndRebalanceTest() {
    final RTree<RectDouble2D> rTree = createRect2DTree(Spatialization.DefaultSplits.QUADRATIC);
    RectDouble2D[] rect = new RectDouble2D[65];
    for (int i = 0; i < rect.length; i++) {
        if (i < 4) {
            rect[i] = new RectDouble2D(0, 0, 1, 1);
        } else if (i < 8) {
            rect[i] = new RectDouble2D(2, 2, 4, 4);
        } else if (i < 12) {
            rect[i] = new RectDouble2D(4, 4, 5, 5);
        } else if (i < 16) {
            rect[i] = new RectDouble2D(5, 5, 6, 6);
        } else if (i < 20) {
            rect[i] = new RectDouble2D(6, 6, 7, 7);
        } else if (i < 24) {
            rect[i] = new RectDouble2D(7, 7, 8, 8);
        } else if (i < 28) {
            rect[i] = new RectDouble2D(8, 8, 9, 9);
        } else if (i < 32) {
            rect[i] = new RectDouble2D(9, 9, 10, 10);
        } else if (i < 36) {
            rect[i] = new RectDouble2D(2, 2, 4, 4);
        } else if (i < 40) {
            rect[i] = new RectDouble2D(4, 4, 5, 5);
        } else if (i < 44) {
            rect[i] = new RectDouble2D(5, 5, 6, 6);
        } else if (i < 48) {
            rect[i] = new RectDouble2D(6, 6, 7, 7);
        } else if (i < 52) {
            rect[i] = new RectDouble2D(7, 7, 8, 8);
        } else if (i < 56) {
            rect[i] = new RectDouble2D(8, 8, 9, 9);
        } else if (i < 60) {
            rect[i] = new RectDouble2D(9, 9, 10, 10);
        } else if (i < 65) {
            rect[i] = new RectDouble2D(1, 1, 2, 2);
        }
    }
    for (int i = 0; i < rect.length; i++) {
        rTree.add(rect[i]);
    }
    Stats stat = rTree.stats();
    stat.print(System.out);
    for (int i = 0; i < 5; i++) {
        rTree.remove(rect[64]);
    }
    Stats stat2 = rTree.stats();
    stat2.print(System.out);
}
Also used : Stats(jcog.tree.rtree.util.Stats) RectDouble2D(jcog.tree.rtree.rect.RectDouble2D) Disabled(org.junit.jupiter.api.Disabled)

Example 48 with RectDouble2D

use of jcog.tree.rtree.rect.RectDouble2D in project narchy by automenta.

the class RTree2DTest method treeSearchStatsTest.

/**
 * Do a search and collect stats on how many nodes we hit and how many
 * bounding boxes we had to evaluate to get all the results.
 *
 * Preliminary findings:
 *  - Evals for QUADRATIC tree increases with size of the search bounding box.
 *  - QUADRATIC seems to be ideal for small search bounding boxes.
 */
@Disabled
public // This test ignored because output needs to be manually evaluated.
void treeSearchStatsTest() {
    final int entryCount = 5000;
    final RectDouble2D[] rects = generateRandomRects(entryCount);
    for (Spatialization.DefaultSplits type : Spatialization.DefaultSplits.values()) {
        RTree<RectDouble2D> rTree = createRect2DTree(2, 8, type);
        for (int i = 0; i < rects.length; i++) {
            rTree.add(rects[i]);
        }
        rTree.instrumentTree();
        final RectDouble2D searchRect = new RectDouble2D(100, 100, 120, 120);
        RectDouble2D[] results = new RectDouble2D[entryCount];
        int foundCount = rTree.containedToArray(searchRect, results);
        CounterNode<RectDouble2D> root = (CounterNode<RectDouble2D>) rTree.root();
        System.out.println("[" + type + "] searched " + CounterNode.searchCount + " nodes, returning " + foundCount + " entries");
        System.out.println("[" + type + "] evaluated " + CounterNode.bboxEvalCount + " b-boxes, returning " + foundCount + " entries");
    }
}
Also used : RectDouble2D(jcog.tree.rtree.rect.RectDouble2D) CounterNode(jcog.tree.rtree.util.CounterNode) Disabled(org.junit.jupiter.api.Disabled)

Aggregations

RectDouble2D (jcog.tree.rtree.rect.RectDouble2D)48 Test (org.junit.jupiter.api.Test)40 Stats (jcog.tree.rtree.util.Stats)17 Disabled (org.junit.jupiter.api.Disabled)6 Random (java.util.Random)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Double2D (jcog.tree.rtree.point.Double2D)2 CounterNode (jcog.tree.rtree.util.CounterNode)2