本文整理汇总了C++中QuadTree::findRegion方法的典型用法代码示例。如果您正苦于以下问题:C++ QuadTree::findRegion方法的具体用法?C++ QuadTree::findRegion怎么用?C++ QuadTree::findRegion使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QuadTree
的用法示例。
在下文中一共展示了QuadTree::findRegion方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main (int argc, const char * argv[])
{
if (false) {
double t0, t1, t2, t3;
t0 = gettimeofday_sec();
int width = 200;
int height = 200;
int n = 2000000;
// n= 2 millionで12secほどaddにかかる( nlogn )
QuadTree<Location> *tree = new QuadTree<Location>(Region(0,0,width,height));
for ( int i = 0; i < n; i++ ) {
double x = width * ((double)(rand() % n) - (n/2.0)) / n;
double y = height * ((double)(rand() % n) - (n/2.0)) / n;
Location *l = new Location(x,y);
tree->add(l);
}
t1 = gettimeofday_sec();
int count = 0;
std::vector<QuadTree<Location> *> foundTree = tree->findRegion(Region(70,-30,1,1));
for ( int i = 0 ; i < foundTree.size(); i++ ) {
count += foundTree[i]->getObjects().size();
}
t2 = gettimeofday_sec();
Location *l = tree->findFirstObjectInRegion(Region(700, 45.23, 1, 0.4));
t3 = gettimeofday_sec();
printf("get all objects -> %d\n", (int)tree->getObjects().size());
printf("find region objects - > %d\n", count);
if ( l != NULL ) {
printf("find first (%f, %f)\n", l->x, l->y);
}
printf("%d add time: %g\n", n, t1-t0);
printf("findRegion time: %g\n", t2-t1);
printf("findFirst time: %g\n", t3-t2);
}
// findFirst() test
if (true) {
int m = 20;
int n = 20;
QuadTree<Location> *tree = new QuadTree<Location>(Region(140,40, m, n));
LadyBug *ladybug = new LadyBug("", "/Users/asai/Desktop/gps.txt");
std::vector<Location *> *locs = ladybug->getLocations();
for ( unsigned int i = 0; i < locs->size(); i++ ) {
if ( !locs->at(i)->isError ) {
tree->add(locs->at(i));
}
}
tree->dump();
for ( int i = 0; i < m; i++ ) {
for ( int j = 0; j < n; j++ ) {
Region r = Region(140 - m/2 + i, 40 - n/2 + j, 2, 2);
Location *l = tree->findFirstObjectInRegion(r);
if ( l != NULL ) {
printf("found!");
r.dump();
} else {
int count = 0;
std::vector<QuadTree<Location> *> foundTree = tree->findRegion(r);
for ( int k = 0 ; k < foundTree.size(); k++ ) {
count += foundTree[k]->getObjects().size();
}
printf("not found but %d found by getObjects()\n", count);
}
}
}
}
return 0;
}