SUMO - Simulation of Urban MObility
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
Test.cpp
Go to the documentation of this file.
1
//
2
// Test.cpp
3
//
4
// This is a direct port of the C version of the RTree test program.
5
//
6
7
#include <stdio.h>
8
#include "
RTree.h
"
9
10
struct
Rect
11
{
12
Rect
() {}
13
14
Rect
(
int
a_minX,
int
a_minY,
int
a_maxX,
int
a_maxY)
15
{
16
min
[0] = a_minX;
17
min
[1] = a_minY;
18
19
max
[0] = a_maxX;
20
max
[1] = a_maxY;
21
}
22
23
24
int
min
[2];
25
int
max
[2];
26
};
27
28
struct
Rect
rects
[] =
29
{
30
Rect
(0, 0, 2, 2),
// xmin, ymin, xmax, ymax (for 2 dimensional RTree)
31
Rect
(5, 5, 7, 7),
32
Rect
(8, 5, 9, 6),
33
Rect
(7, 1, 9, 2),
34
};
35
36
int
nrects
=
sizeof
(
rects
) /
sizeof
(rects[0]);
37
38
Rect
search_rect
(6, 4, 10, 6);
// search will find above rects that this one overlaps
39
40
41
bool
MySearchCallback
(
int
id
,
void
* arg)
42
{
43
printf(
"Hit data rect %d\n"
,
id
);
44
return
true
;
// keep going
45
}
46
47
48
void
main
()
49
{
50
RTree<int, int, 2, float>
tree;
51
52
int
i, nhits;
53
printf(
"nrects = %d\n"
, nrects);
54
55
for
(i=0; i<
nrects
; i++)
56
{
57
tree.
Insert
(rects[i].
min
, rects[i].
max
, i);
// Note, all values including zero are fine in this version
58
}
59
60
nhits = tree.
Search
(
search_rect
.
min
,
search_rect
.
max
,
MySearchCallback
, NULL);
61
62
printf(
"Search resulted in %d hits\n"
, nhits);
63
64
getchar();
// Wait for keypress on exit so we can read console output
65
66
// Output:
67
//
68
// nrects = 4
69
// Hit data rect 1
70
// Hit data rect 2
71
// Search resulted in 2 hits
72
}
home
behr_mi
sumo
src
foreign
rtree
Test.cpp
Generated by
1.8.2