本文整理汇总了C++中KDTree::buildTree方法的典型用法代码示例。如果您正苦于以下问题:C++ KDTree::buildTree方法的具体用法?C++ KDTree::buildTree怎么用?C++ KDTree::buildTree使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KDTree
的用法示例。
在下文中一共展示了KDTree::buildTree方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char** argv){
KDTree<simplePoint3> tree;
std::vector<simplePoint3> pts{ {0,0,0},{1,1,1}, {-1, 3, 4}, {5, 6, 7}, {2, -6, 8}, {4, 5, -4},
{2, 3, 4},
{2, 5, 6}};
tree.buildTree(pts);
tree.dumpTreeInorder();
std::cout << "searching near 0,0,0.1" << std::endl;
auto closeNodes = tree.getPointsWithinCube({0, 0, 0.1}, 0.2);
std::cout << "found" << std::endl;
for(auto n : closeNodes){
tree.dumpNode(n);
}
std::cout << "searching near 0.5,0.5,0.5" << std::endl;
closeNodes = tree.getPointsWithinCube({0.5, 0.5, 0.5}, 0.7);
std::cout << "found" << std::endl;
for(auto n : closeNodes){
tree.dumpNode(n);
}
std::cout << "min, x: " << std::endl;
tree.dumpNode(tree.findMin(0));
std::cout << "min, y: " << std::endl;
tree.dumpNode(tree.findMin(1));
std::cout << "min, z: " << std::endl;
tree.dumpNode(tree.findMin(2));
for(auto i = 0; i < pts.size() -1; ++i){
std::cout << "deleting node " << i << std::endl;
tree.deletePoint(i);
tree.dumpTreeInorder();
}
std::cout << "inserting 2 points" << std::endl;
tree.insertPoint({1, 4, 5});
tree.dumpTreeInorder();
tree.insertPoint({3, 8, 6});
tree.dumpTreeInorder();
}
示例2: main
int main(int argc, const char * argv[])
{
int K = 3;
vector<vector<double> > dataset;
ReadData rd1("sample_data.txt");
dataset=rd1.allDataPointsVec;
int N=dataset.size();
//query_point
vector<double> query_point;
vector<vector<double> > query_point_dataset;
ReadData rd2("query_points.txt");
int N2 = rd2.get_num_of_elements();
int dim2 = rd2.get_num_of_dimensions();
query_point_dataset=rd2.allDataPointsVec;
query_point=query_point_dataset[1];
KDTree<128, size_t> kd;
vector<Point<128>> keyVec;
Point<128> key;
for(int i=0; i<query_point_dataset.size(); i++)
{
for(int j=0; j<128; j++)
{
key[j]=query_point_dataset[i][j];
}
keyVec.push_back(key);
}
vector<size_t> pointIndices;
for(int i=0; i<N; i++)
{
pointIndices.push_back(i);
}
kd.buildTree(dataset, pointIndices);
vector<size_t> indices;
for(int i=0; i<query_point_dataset.size(); i++)
{
indices = kd.kNNValues(keyVec[i], K);
for (int j = 0; j<K; j++)
{
cout<<"For the number row "<<i<<" query point, Using Exact kNN Search 3 Nearest Neigbour : The number "<<j+1<<" nearest neighbor index is "<<indices[j]<<endl;
}
}
/**Compare the KD-Tree with the Brute-Force Method*
for (int i = 0; i<indices.size(); i++)
{
if(indices[i]==brute_force_htable[brute_force_vec[i]])
{
cout<<"Comparing with the Brute-force method, the Exact K-Nearest Neighbour search by KD-Tree program is correct"<<endl;
}
}
*/
return 0;
}