Test.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include <stdio.h>
00008 #include "RTree.h"
00009
00010 struct Rect
00011 {
00012 Rect() {}
00013
00014 Rect(int a_minX, int a_minY, int a_maxX, int a_maxY)
00015 {
00016 min[0] = a_minX;
00017 min[1] = a_minY;
00018
00019 max[0] = a_maxX;
00020 max[1] = a_maxY;
00021 }
00022
00023
00024 int min[2];
00025 int max[2];
00026 };
00027
00028 struct Rect rects[] =
00029 {
00030 Rect(0, 0, 2, 2),
00031 Rect(5, 5, 7, 7),
00032 Rect(8, 5, 9, 6),
00033 Rect(7, 1, 9, 2),
00034 };
00035
00036 int nrects = sizeof(rects) / sizeof(rects[0]);
00037
00038 Rect search_rect(6, 4, 10, 6);
00039
00040
00041 bool MySearchCallback(int id, void* arg)
00042 {
00043 printf("Hit data rect %d\n", id);
00044 return true;
00045 }
00046
00047
00048 void main()
00049 {
00050 RTree<int, int, 2, float> tree;
00051
00052 int i, nhits;
00053 printf("nrects = %d\n", nrects);
00054
00055 for(i=0; i<nrects; i++)
00056 {
00057 tree.Insert(rects[i].min, rects[i].max, i);
00058 }
00059
00060 nhits = tree.Search(search_rect.min, search_rect.max, MySearchCallback, NULL);
00061
00062 printf("Search resulted in %d hits\n", nhits);
00063
00064 getchar();
00065
00066
00067
00068
00069
00070
00071
00072 }