Test.cpp

Go to the documentation of this file.
00001 //
00002 // Test.cpp
00003 //
00004 // This is a direct port of the C version of the RTree test program.
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), // xmin, ymin, xmax, ymax (for 2 dimensional RTree)
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); // search will find above rects that this one overlaps
00039 
00040 
00041 bool MySearchCallback(int id, void* arg) 
00042 {
00043   printf("Hit data rect %d\n", id);
00044   return true; // keep going
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); // Note, all values including zero are fine in this version
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(); // Wait for keypress on exit so we can read console output
00065 
00066   // Output:
00067   //
00068   // nrects = 4
00069   // Hit data rect 1
00070   // Hit data rect 2
00071   // Search resulted in 2 hits
00072 }

Generated on Wed May 5 00:06:37 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6