Classes | Macros | Typedefs | Functions
main.cpp File Reference
#include <string>
#include <ctime>
#include <stdio.h>
#include "larreco/ClusterFinder/RStarTree/RStarTree.h"

Go to the source code of this file.

Classes

struct  Visitor
 

Macros

#define RANDOM_DATASET
 
#define nodes   20000
 

Typedefs

typedef RStarTree< int, 2, 32, 64 > RTree
 
typedef RTree::BoundingBox BoundingBox
 

Functions

BoundingBox bounds (int x, int y, int w, int h)
 
int main (int argc, char **argv)
 

Macro Definition Documentation

#define nodes   20000
#define RANDOM_DATASET

Definition at line 25 of file main.cpp.

Typedef Documentation

Definition at line 34 of file main.cpp.

typedef RStarTree<int, 2, 32, 64> RTree

Definition at line 29 of file main.cpp.

Function Documentation

BoundingBox bounds ( int  x,
int  y,
int  w,
int  h 
)

Definition at line 37 of file main.cpp.

38 {
39  BoundingBox bb;
40 
41  bb.edges[0].first = x;
42  bb.edges[0].second = x + w;
43 
44  bb.edges[1].first = y;
45  bb.edges[1].second = y + h;
46 
47  return bb;
48 }
double y
std::pair< double, double > edges[dimensions]
list x
Definition: train.py:276
h
training ###############################
Definition: train_cnn.py:186
int main ( int  argc,
char **  argv 
)

Definition at line 72 of file main.cpp.

73 {
74  RTree tree;
75  Visitor x;
76 
77  // insert a bunch of items into the tree
78  // Note: this dataset is the one shown on Guttman's original paper
79 #ifdef GUTTMAN_DATASET
80  tree.Insert( "R8" , bounds( 1,5 , 3,2 ));
81  //tree.Print("I1");
82 
83  tree.Insert( "R9", bounds( 6,1 , 2,2 ));
84  //tree.Print("I2");
85 
86  tree.Insert( "R10", bounds( 6,4 , 2,2 ));
87  //tree.Print("I3");
88 
89  tree.Insert( "R11", bounds( 9,0 , 2,14 ));
90  //tree.Print("I4");
91 
92  tree.Insert( "R13", bounds( 13,1 , 1,9 ));
93  //tree.Print("I5");
94 
95  tree.Insert( "R14", bounds( 12,5 , 2,2 ));
96  //tree.Print("I6");
97 
98  tree.Insert( "R15", bounds( 0,16 , 2,2 ));
99  //tree.Print("I7");
100 
101  tree.Insert( "R16", bounds( 3,11 , 6,7 ));
102  //tree.Print("I8");
103 
104  tree.Insert( "R17", bounds( 14,10 , 7,4 ));
105  //tree.Print("I9");
106 
107  tree.Insert( "R18", bounds( 16,8 , 2,9 ));
108  //tree.Print("I10");
109 
110  tree.Insert( "R19", bounds( 17,12 , 3,3 ));
111  //tree.Print("I11");
112 
113  BoundingBox bound = bounds( 5,10, 5,5 );
114 
115  std::cout << "Searching in " << bound.ToString() << std::endl;
116  x = tree.Query(RTree::AcceptOverlapping(bound), Visitor());
117  std::cout << "Visited " << x.count << " nodes." << std::endl;
118 
119  tree.RemoveBoundedArea(bound);
120 
121  // stretch the bounds a bit
122 
123  std::cout << "Searching in " << bound.ToString() << std::endl;
124  x = tree.Query(RTree::AcceptOverlapping(bound), Visitor());
125  std::cout << "Visited " << x.count << " nodes." << std::endl;
126 
127  BoundingBox bound2 = bounds(0,10, 10,10);
128  std::cout << "Removing enclosed area " << bound2.ToString() << std::endl;
129  tree.RemoveBoundedArea(bound2);
130 
131  std::cout << "Searching in " << bound.ToString() << std::endl;
132  x = tree.Query(RTree::AcceptOverlapping(bound), Visitor());
133  std::cout << "Visited " << x.count << " nodes." << std::endl;
134 
135 
136  Visitor y = tree.Query(RTree::AcceptAny(), Visitor());
137  std::cout << "Visited " << y.count << " nodes." << std::endl;
138 
139 
140 #endif
141 
142 
143 #ifdef RANDOM_DATASET
144  srand(time(0));
145 
146  #define nodes 20000
147 
148  for (int i = 0; i < nodes/2; i++)
149  tree.Insert(i, bounds( rand() % 1000, rand() % 1000, rand() % 10, rand() % 10));
150 
151  for (int i = 0; i < nodes/2; i++)
152  tree.Insert(i, bounds( rand() % 1000, rand() % 1000, rand() % 20, rand() % 20));
153 
154  BoundingBox bound = bounds( 100,100, 300,400 );
155 
156  x = tree.Query(RTree::AcceptAny(), Visitor());
157  std::cout << "AcceptAny: " << x.count << " nodes visited (" << tree.GetSize() << " nodes in tree)" << std::endl;
158 
159 
160  std::cout << "Searching in " << bound.ToString() << std::endl;
161  x = tree.Query(RTree::AcceptEnclosing(bound), Visitor());
162  std::cout << "Visited " << x.count << " nodes (" << tree.GetSize() << " nodes in tree)" << std::endl;
163 
164  std::cout << "Removing enclosed area " << bound.ToString() << std::endl;
165  tree.RemoveBoundedArea(bound);
166 
167  std::cout << "Searching in " << bound.ToString() << std::endl;
168  x = tree.Query(RTree::AcceptEnclosing(bound), Visitor());
169  std::cout << "Visited " << x.count << " nodes. (" << tree.GetSize() << " nodes in tree)" << std::endl;
170 
171  //tree.Print();
172 
173 #endif
174 
175 
176 
177  return 0;
178 }
void Insert(LeafType leaf, const BoundingBox &bound)
Definition: RStarTree.h:123
#define nodes
double y
std::size_t GetSize() const
Definition: RStarTree.h:283
Definition: main.cpp:51
std::string ToString() const
int count
Definition: main.cpp:52
list x
Definition: train.py:276
Visitor Query(const Acceptor &accept, Visitor visitor)
Touches each node using the visitor pattern.
Definition: RStarTree.h:215
BoundingBox bounds(int x, int y, int w, int h)
Definition: main.cpp:37
void RemoveBoundedArea(const BoundingBox &bound)
Definition: RStarTree.h:270