本文整理汇总了C++中KDTree::DumpTree方法的典型用法代码示例。如果您正苦于以下问题:C++ KDTree::DumpTree方法的具体用法?C++ KDTree::DumpTree怎么用?C++ KDTree::DumpTree使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KDTree
的用法示例。
在下文中一共展示了KDTree::DumpTree方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char* argv[])
{
KDTree<Value, 2> kdtree = KDTree<Value, 2>::CreateKDTree(INSERT_NUM);
std::vector<KDTree<Value, 2>::DataType> vData;
for(uint32_t i=0; i<INSERT_NUM; ++i)
{
KDTree<Value, 2>::DataType item;
item.Vector[0] = random() % 99;
item.Vector[1] = random() % 99;
item.Value.Uin = i;
vData.push_back(item);
//printf("new vector (%u, %u)\n", item.Vector[0], item.Vector[1]);
}
timeval t1, t2;
gettimeofday(&t1, NULL);
kdtree.Build(vData);
gettimeofday(&t2, NULL);
printf("const: %.03fs\n", TIME_COST(t1, t2));
printf("Tree Dump:\n");
kdtree.DumpTree();
printf("\n");
KDTree<Value, 2>::VectorType key;
key[0] = (random() * time(NULL)) % 99;
key[1] = (random() * time(NULL)) % 99;
kdtree.Draw2DMap("map.jpg", key[0], key[1]);
#define SEARCH_COUNT 5
uint32_t range = 0;
KDTree<Value, 2>::DataType buffer[SEARCH_COUNT];
int foundCount = kdtree.Nearest(key, buffer, SEARCH_COUNT);
printf("nearest (%u, %u):\n", key[0], key[1]);
for(int i=0; i<foundCount; ++i)
{
uint32_t distance = EuclideanDistance<uint32_t, KDVector<uint32_t, 2>, 2>::Distance(key, buffer[i].Vector);
if(i == foundCount / 2)
range = distance;
printf(" %d:(%u, %u) distance:%u\n", i, buffer[i].Vector[0], buffer[i].Vector[1], distance);
}
printf("\n");
foundCount = kdtree.Range(key, range, buffer, SEARCH_COUNT);
printf("nearest (%u, %u) with range %u:\n", key[0], key[1], range);
for(int i=0; i<foundCount; ++i)
{
uint32_t distance = EuclideanDistance<uint32_t, KDVector<uint32_t, 2>, 2>::Distance(key, buffer[i].Vector);
printf(" %d:(%u, %u) distance:%u\n", i, buffer[i].Vector[0], buffer[i].Vector[1], distance);
}
printf("\n");
kdtree.Delete();
return 0;
}