Initial QuadTree implementation
In an effort to find a faster bounding box hierarchy than the R-Tree, a QuadTree has been implemented here.
For now, the QuadTree construction is generally faster than the R-Tree and the queries are a bit slower, so overall, SKP local tests showed QuadTree performance similar to the R-Tree performance.
Tests and bench are included in this cl.
At this point, I'd like to be able to commit this in order to more easily use the bots to test multiple configurations and a larger number of SKPs. The R-Tree BBH is still used by default so this change shouldn't affect chromium.
BUG=skia:
R=junov@chromium.org, junov@google.com, senorblanco@google.com, senorblanco@chromium.org, reed@google.com, sugoi@google.com, fmalita@google.com
Author: sugoi@chromium.org
Review URL: https://codereview.chromium.org/131343011
git-svn-id: http://skia.googlecode.com/svn/trunk@13282 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-02-03 18:08:33 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Test.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkRTree.h"
|
|
|
|
#include "SkTSort.h"
|
|
|
|
|
|
|
|
static const size_t RTREE_MIN_CHILDREN = 6;
|
|
|
|
static const size_t RTREE_MAX_CHILDREN = 11;
|
|
|
|
|
|
|
|
static const int NUM_RECTS = 200;
|
|
|
|
static const size_t NUM_ITERATIONS = 100;
|
|
|
|
static const size_t NUM_QUERIES = 50;
|
|
|
|
|
2014-08-27 17:39:42 +00:00
|
|
|
static const SkScalar MAX_SIZE = 1000.0f;
|
Initial QuadTree implementation
In an effort to find a faster bounding box hierarchy than the R-Tree, a QuadTree has been implemented here.
For now, the QuadTree construction is generally faster than the R-Tree and the queries are a bit slower, so overall, SKP local tests showed QuadTree performance similar to the R-Tree performance.
Tests and bench are included in this cl.
At this point, I'd like to be able to commit this in order to more easily use the bots to test multiple configurations and a larger number of SKPs. The R-Tree BBH is still used by default so this change shouldn't affect chromium.
BUG=skia:
R=junov@chromium.org, junov@google.com, senorblanco@google.com, senorblanco@chromium.org, reed@google.com, sugoi@google.com, fmalita@google.com
Author: sugoi@chromium.org
Review URL: https://codereview.chromium.org/131343011
git-svn-id: http://skia.googlecode.com/svn/trunk@13282 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-02-03 18:08:33 +00:00
|
|
|
|
|
|
|
struct DataRect {
|
2014-08-27 17:39:42 +00:00
|
|
|
SkRect rect;
|
Initial QuadTree implementation
In an effort to find a faster bounding box hierarchy than the R-Tree, a QuadTree has been implemented here.
For now, the QuadTree construction is generally faster than the R-Tree and the queries are a bit slower, so overall, SKP local tests showed QuadTree performance similar to the R-Tree performance.
Tests and bench are included in this cl.
At this point, I'd like to be able to commit this in order to more easily use the bots to test multiple configurations and a larger number of SKPs. The R-Tree BBH is still used by default so this change shouldn't affect chromium.
BUG=skia:
R=junov@chromium.org, junov@google.com, senorblanco@google.com, senorblanco@chromium.org, reed@google.com, sugoi@google.com, fmalita@google.com
Author: sugoi@chromium.org
Review URL: https://codereview.chromium.org/131343011
git-svn-id: http://skia.googlecode.com/svn/trunk@13282 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-02-03 18:08:33 +00:00
|
|
|
void* data;
|
|
|
|
};
|
|
|
|
|
2014-08-27 17:39:42 +00:00
|
|
|
static SkRect random_rect(SkRandom& rand) {
|
|
|
|
SkRect rect = {0,0,0,0};
|
Initial QuadTree implementation
In an effort to find a faster bounding box hierarchy than the R-Tree, a QuadTree has been implemented here.
For now, the QuadTree construction is generally faster than the R-Tree and the queries are a bit slower, so overall, SKP local tests showed QuadTree performance similar to the R-Tree performance.
Tests and bench are included in this cl.
At this point, I'd like to be able to commit this in order to more easily use the bots to test multiple configurations and a larger number of SKPs. The R-Tree BBH is still used by default so this change shouldn't affect chromium.
BUG=skia:
R=junov@chromium.org, junov@google.com, senorblanco@google.com, senorblanco@chromium.org, reed@google.com, sugoi@google.com, fmalita@google.com
Author: sugoi@chromium.org
Review URL: https://codereview.chromium.org/131343011
git-svn-id: http://skia.googlecode.com/svn/trunk@13282 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-02-03 18:08:33 +00:00
|
|
|
while (rect.isEmpty()) {
|
2014-08-27 17:39:42 +00:00
|
|
|
rect.fLeft = rand.nextRangeF(0, MAX_SIZE);
|
|
|
|
rect.fRight = rand.nextRangeF(0, MAX_SIZE);
|
|
|
|
rect.fTop = rand.nextRangeF(0, MAX_SIZE);
|
|
|
|
rect.fBottom = rand.nextRangeF(0, MAX_SIZE);
|
Initial QuadTree implementation
In an effort to find a faster bounding box hierarchy than the R-Tree, a QuadTree has been implemented here.
For now, the QuadTree construction is generally faster than the R-Tree and the queries are a bit slower, so overall, SKP local tests showed QuadTree performance similar to the R-Tree performance.
Tests and bench are included in this cl.
At this point, I'd like to be able to commit this in order to more easily use the bots to test multiple configurations and a larger number of SKPs. The R-Tree BBH is still used by default so this change shouldn't affect chromium.
BUG=skia:
R=junov@chromium.org, junov@google.com, senorblanco@google.com, senorblanco@chromium.org, reed@google.com, sugoi@google.com, fmalita@google.com
Author: sugoi@chromium.org
Review URL: https://codereview.chromium.org/131343011
git-svn-id: http://skia.googlecode.com/svn/trunk@13282 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-02-03 18:08:33 +00:00
|
|
|
rect.sort();
|
|
|
|
}
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void random_data_rects(SkRandom& rand, DataRect out[], int n) {
|
|
|
|
for (int i = 0; i < n; ++i) {
|
|
|
|
out[i].rect = random_rect(rand);
|
|
|
|
out[i].data = reinterpret_cast<void*>(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-27 17:39:42 +00:00
|
|
|
static bool verify_query(SkRect query, DataRect rects[],
|
Initial QuadTree implementation
In an effort to find a faster bounding box hierarchy than the R-Tree, a QuadTree has been implemented here.
For now, the QuadTree construction is generally faster than the R-Tree and the queries are a bit slower, so overall, SKP local tests showed QuadTree performance similar to the R-Tree performance.
Tests and bench are included in this cl.
At this point, I'd like to be able to commit this in order to more easily use the bots to test multiple configurations and a larger number of SKPs. The R-Tree BBH is still used by default so this change shouldn't affect chromium.
BUG=skia:
R=junov@chromium.org, junov@google.com, senorblanco@google.com, senorblanco@chromium.org, reed@google.com, sugoi@google.com, fmalita@google.com
Author: sugoi@chromium.org
Review URL: https://codereview.chromium.org/131343011
git-svn-id: http://skia.googlecode.com/svn/trunk@13282 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-02-03 18:08:33 +00:00
|
|
|
SkTDArray<void*>& found) {
|
2014-08-27 17:39:42 +00:00
|
|
|
// TODO(mtklein): no need to do this after everything's SkRects
|
|
|
|
query.roundOut();
|
|
|
|
|
Initial QuadTree implementation
In an effort to find a faster bounding box hierarchy than the R-Tree, a QuadTree has been implemented here.
For now, the QuadTree construction is generally faster than the R-Tree and the queries are a bit slower, so overall, SKP local tests showed QuadTree performance similar to the R-Tree performance.
Tests and bench are included in this cl.
At this point, I'd like to be able to commit this in order to more easily use the bots to test multiple configurations and a larger number of SKPs. The R-Tree BBH is still used by default so this change shouldn't affect chromium.
BUG=skia:
R=junov@chromium.org, junov@google.com, senorblanco@google.com, senorblanco@chromium.org, reed@google.com, sugoi@google.com, fmalita@google.com
Author: sugoi@chromium.org
Review URL: https://codereview.chromium.org/131343011
git-svn-id: http://skia.googlecode.com/svn/trunk@13282 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-02-03 18:08:33 +00:00
|
|
|
SkTDArray<void*> expected;
|
|
|
|
// manually intersect with every rectangle
|
|
|
|
for (int i = 0; i < NUM_RECTS; ++i) {
|
2014-08-27 17:39:42 +00:00
|
|
|
if (SkRect::Intersects(query, rects[i].rect)) {
|
Initial QuadTree implementation
In an effort to find a faster bounding box hierarchy than the R-Tree, a QuadTree has been implemented here.
For now, the QuadTree construction is generally faster than the R-Tree and the queries are a bit slower, so overall, SKP local tests showed QuadTree performance similar to the R-Tree performance.
Tests and bench are included in this cl.
At this point, I'd like to be able to commit this in order to more easily use the bots to test multiple configurations and a larger number of SKPs. The R-Tree BBH is still used by default so this change shouldn't affect chromium.
BUG=skia:
R=junov@chromium.org, junov@google.com, senorblanco@google.com, senorblanco@chromium.org, reed@google.com, sugoi@google.com, fmalita@google.com
Author: sugoi@chromium.org
Review URL: https://codereview.chromium.org/131343011
git-svn-id: http://skia.googlecode.com/svn/trunk@13282 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-02-03 18:08:33 +00:00
|
|
|
expected.push(rects[i].data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (expected.count() != found.count()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 == expected.count()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Just cast to long since sorting by the value of the void*'s was being problematic...
|
|
|
|
SkTQSort(reinterpret_cast<long*>(expected.begin()),
|
|
|
|
reinterpret_cast<long*>(expected.end() - 1));
|
|
|
|
SkTQSort(reinterpret_cast<long*>(found.begin()),
|
|
|
|
reinterpret_cast<long*>(found.end() - 1));
|
|
|
|
return found == expected;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void run_queries(skiatest::Reporter* reporter, SkRandom& rand, DataRect rects[],
|
|
|
|
SkBBoxHierarchy& tree) {
|
|
|
|
for (size_t i = 0; i < NUM_QUERIES; ++i) {
|
|
|
|
SkTDArray<void*> hits;
|
2014-08-27 17:39:42 +00:00
|
|
|
SkRect query = random_rect(rand);
|
Initial QuadTree implementation
In an effort to find a faster bounding box hierarchy than the R-Tree, a QuadTree has been implemented here.
For now, the QuadTree construction is generally faster than the R-Tree and the queries are a bit slower, so overall, SKP local tests showed QuadTree performance similar to the R-Tree performance.
Tests and bench are included in this cl.
At this point, I'd like to be able to commit this in order to more easily use the bots to test multiple configurations and a larger number of SKPs. The R-Tree BBH is still used by default so this change shouldn't affect chromium.
BUG=skia:
R=junov@chromium.org, junov@google.com, senorblanco@google.com, senorblanco@chromium.org, reed@google.com, sugoi@google.com, fmalita@google.com
Author: sugoi@chromium.org
Review URL: https://codereview.chromium.org/131343011
git-svn-id: http://skia.googlecode.com/svn/trunk@13282 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-02-03 18:08:33 +00:00
|
|
|
tree.search(query, &hits);
|
|
|
|
REPORTER_ASSERT(reporter, verify_query(query, rects, hits));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tree_test_main(SkBBoxHierarchy* tree, int minChildren, int maxChildren,
|
|
|
|
skiatest::Reporter* reporter) {
|
|
|
|
DataRect rects[NUM_RECTS];
|
|
|
|
SkRandom rand;
|
|
|
|
REPORTER_ASSERT(reporter, NULL != tree);
|
|
|
|
|
|
|
|
int expectedDepthMin = -1;
|
|
|
|
int expectedDepthMax = -1;
|
|
|
|
|
|
|
|
int tmp = NUM_RECTS;
|
|
|
|
if (maxChildren > 0) {
|
|
|
|
while (tmp > 0) {
|
|
|
|
tmp -= static_cast<int>(pow(static_cast<double>(maxChildren),
|
|
|
|
static_cast<double>(expectedDepthMin + 1)));
|
|
|
|
++expectedDepthMin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = NUM_RECTS;
|
|
|
|
if (minChildren > 0) {
|
|
|
|
while (tmp > 0) {
|
|
|
|
tmp -= static_cast<int>(pow(static_cast<double>(minChildren),
|
|
|
|
static_cast<double>(expectedDepthMax + 1)));
|
|
|
|
++expectedDepthMax;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < NUM_ITERATIONS; ++i) {
|
|
|
|
random_data_rects(rand, rects, NUM_RECTS);
|
|
|
|
|
|
|
|
// First try bulk-loaded inserts
|
|
|
|
for (int i = 0; i < NUM_RECTS; ++i) {
|
|
|
|
tree->insert(rects[i].data, rects[i].rect, true);
|
|
|
|
}
|
|
|
|
tree->flushDeferredInserts();
|
|
|
|
run_queries(reporter, rand, rects, *tree);
|
|
|
|
REPORTER_ASSERT(reporter, NUM_RECTS == tree->getCount());
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
((expectedDepthMin <= 0) || (expectedDepthMin <= tree->getDepth())) &&
|
|
|
|
((expectedDepthMax <= 0) || (expectedDepthMax >= tree->getDepth())));
|
|
|
|
tree->clear();
|
|
|
|
REPORTER_ASSERT(reporter, 0 == tree->getCount());
|
|
|
|
|
|
|
|
// Then try immediate inserts
|
2014-03-17 10:38:34 +00:00
|
|
|
tree->insert(rects[0].data, rects[0].rect);
|
|
|
|
tree->flushDeferredInserts();
|
|
|
|
for (int i = 1; i < NUM_RECTS; ++i) {
|
Initial QuadTree implementation
In an effort to find a faster bounding box hierarchy than the R-Tree, a QuadTree has been implemented here.
For now, the QuadTree construction is generally faster than the R-Tree and the queries are a bit slower, so overall, SKP local tests showed QuadTree performance similar to the R-Tree performance.
Tests and bench are included in this cl.
At this point, I'd like to be able to commit this in order to more easily use the bots to test multiple configurations and a larger number of SKPs. The R-Tree BBH is still used by default so this change shouldn't affect chromium.
BUG=skia:
R=junov@chromium.org, junov@google.com, senorblanco@google.com, senorblanco@chromium.org, reed@google.com, sugoi@google.com, fmalita@google.com
Author: sugoi@chromium.org
Review URL: https://codereview.chromium.org/131343011
git-svn-id: http://skia.googlecode.com/svn/trunk@13282 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-02-03 18:08:33 +00:00
|
|
|
tree->insert(rects[i].data, rects[i].rect);
|
|
|
|
}
|
|
|
|
run_queries(reporter, rand, rects, *tree);
|
|
|
|
REPORTER_ASSERT(reporter, NUM_RECTS == tree->getCount());
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
((expectedDepthMin <= 0) || (expectedDepthMin <= tree->getDepth())) &&
|
|
|
|
((expectedDepthMax <= 0) || (expectedDepthMax >= tree->getDepth())));
|
|
|
|
tree->clear();
|
|
|
|
REPORTER_ASSERT(reporter, 0 == tree->getCount());
|
|
|
|
|
|
|
|
// And for good measure try immediate inserts, but in reversed order
|
2014-03-17 10:38:34 +00:00
|
|
|
tree->insert(rects[NUM_RECTS - 1].data, rects[NUM_RECTS - 1].rect);
|
|
|
|
tree->flushDeferredInserts();
|
|
|
|
for (int i = NUM_RECTS - 2; i >= 0; --i) {
|
Initial QuadTree implementation
In an effort to find a faster bounding box hierarchy than the R-Tree, a QuadTree has been implemented here.
For now, the QuadTree construction is generally faster than the R-Tree and the queries are a bit slower, so overall, SKP local tests showed QuadTree performance similar to the R-Tree performance.
Tests and bench are included in this cl.
At this point, I'd like to be able to commit this in order to more easily use the bots to test multiple configurations and a larger number of SKPs. The R-Tree BBH is still used by default so this change shouldn't affect chromium.
BUG=skia:
R=junov@chromium.org, junov@google.com, senorblanco@google.com, senorblanco@chromium.org, reed@google.com, sugoi@google.com, fmalita@google.com
Author: sugoi@chromium.org
Review URL: https://codereview.chromium.org/131343011
git-svn-id: http://skia.googlecode.com/svn/trunk@13282 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-02-03 18:08:33 +00:00
|
|
|
tree->insert(rects[i].data, rects[i].rect);
|
|
|
|
}
|
|
|
|
run_queries(reporter, rand, rects, *tree);
|
|
|
|
REPORTER_ASSERT(reporter, NUM_RECTS == tree->getCount());
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
((expectedDepthMin < 0) || (expectedDepthMin <= tree->getDepth())) &&
|
|
|
|
((expectedDepthMax < 0) || (expectedDepthMax >= tree->getDepth())));
|
|
|
|
tree->clear();
|
|
|
|
REPORTER_ASSERT(reporter, 0 == tree->getCount());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(BBoxHierarchy, reporter) {
|
|
|
|
// RTree
|
|
|
|
{
|
|
|
|
SkRTree* rtree = SkRTree::Create(RTREE_MIN_CHILDREN, RTREE_MAX_CHILDREN);
|
|
|
|
SkAutoUnref au(rtree);
|
|
|
|
tree_test_main(rtree, RTREE_MIN_CHILDREN, RTREE_MAX_CHILDREN, reporter);
|
|
|
|
|
|
|
|
// Rtree that orders input rectangles on deferred insert.
|
|
|
|
SkRTree* unsortedRtree = SkRTree::Create(RTREE_MIN_CHILDREN, RTREE_MAX_CHILDREN, 1, false);
|
|
|
|
SkAutoUnref auo(unsortedRtree);
|
|
|
|
tree_test_main(unsortedRtree, RTREE_MIN_CHILDREN, RTREE_MAX_CHILDREN, reporter);
|
|
|
|
}
|
|
|
|
}
|