├── Main.cpp ├── QuadTree.cpp ├── QuadTree.h └── README.md /Main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "stdlib.h" 3 | #include "QuadTree.h" 4 | #include 5 | #include 6 | using namespace std; 7 | int main() 8 | { 9 | ofstream myfile; 10 | myfile.open("F:\\QuadTree.txt", ios::out); 11 | if(!myfile) 12 | { 13 | std::cout<<"create file failed!"; 14 | system("pause"); 15 | exit(1); 16 | } 17 | 18 | QuadTree *p_tree = new QuadTree(TREE_DEPTH, MAX_OBJECT); 19 | p_tree->InitQuadTreeNode(QuadTree::Rect(LB_X, LB_Y, RT_X, RT_Y)); 20 | srand((unsigned)time(NULL)); 21 | for (int i = 0; i < RAND_NUM; ++i) 22 | { 23 | QuadTree::PosInfo pos; 24 | pos.latitude = rand() % (RT_X - LB_X) + LB_X + 1; 25 | pos.longitude = rand() % (RT_Y - LB_Y) + LB_Y + 1; 26 | p_tree->Insert(pos, p_tree->GetTreeRoot()); 27 | } 28 | p_tree->PrintAllQuadTreeLeafNode(p_tree->GetTreeRoot()); 29 | 30 | int pos_x, pos_y; 31 | cout<<"input a pos to search near point:"<>pos_x>>pos_y; 33 | QuadTree::PosInfo pos_source(pos_x, pos_y); 34 | std::vector pos_list; 35 | 36 | clock_t start_time = clock(); 37 | myfile<Search(SEARCH_NUM, pos_source, pos_list, p_tree->GetTreeRoot()); 39 | myfile<<"pos_list:"<::iterator it = pos_list.begin(); it != pos_list.end(); ++it) 41 | { 42 | myfile<<"["<<(*it).latitude<<", "<<(*it).longitude<<"]"<