Last active
December 22, 2017 05:55
-
-
Save fxborg/ec41f33d881d30341286744e3a321363 to your computer and use it in GitHub Desktop.
main.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fstream> | |
#include <string> | |
#include <vector> | |
#include <ctime> | |
#include <cstdlib> | |
#include <iostream> | |
#include "kdtree.h" | |
using namespace std; | |
int main() | |
{ | |
// KDTree | |
KDTree tree; | |
// 座標データの読み込み | |
string src_path = "data.txt"; | |
ifstream fin(src_path); | |
if (fin.bad()) { | |
cout << "File Open Error:" << src_path << std::endl; | |
return 1; | |
} | |
std::string str; | |
size_t i=0; | |
while (std::getline(fin, str)) | |
{ | |
double x,y; | |
int res = sscanf_s(str.c_str(), "%lf\t%lf", &x, &y); | |
if (res != 2)continue; | |
// データをツリーに格納 | |
tree.add_point(++i, x, y); | |
} | |
fin.close(); | |
// 半径 座標の検索 | |
double dist = 20.0; | |
PointCloud_Point pt{ ++i,60.0,120 }; | |
vector<PointCloud_Point> rad_result = tree.radius_search(pt,dist*dist); | |
// 結果出力 | |
cout << " x y" << endl; | |
cout << "---------" << endl; | |
for (const PointCloud_Point& it : rad_result) | |
{ | |
cout <<" "<< it.x << " " << it.y << endl; | |
} | |
cout << endl; | |
system("pause"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment