本文整理汇总了C++中KDTree::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ KDTree::begin方法的具体用法?C++ KDTree::begin怎么用?C++ KDTree::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KDTree
的用法示例。
在下文中一共展示了KDTree::begin方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testRayIntersect
void testRayIntersect() {
KDTree<Triangle> tree;
Array<int> index;
Array<Point3> vertex;
printf(" (load model, ");
fflush(stdout);
ArticulatedModel::Ref model = ArticulatedModel::fromFile(System::findDataFile("cow.ifs"));
extractTriangles(model, vertex, index);
for (int i = 0; i < index.size(); i += 3) {
int i0 = index[i];
int i1 = index[i + 1];
int i2 = index[i + 2];
tree.insert(Triangle(vertex[i0], vertex[i1], vertex[i2]));
}
printf("balance tree, ");
fflush(stdout);
tree.balance();
Vector3 origin = Vector3(0, 5, 0);
IntersectCallback intersectCallback;
printf("raytrace, ");
fflush(stdout);
for (int i = 0; i < 4000; ++i) {
// Cast towards a random point near the cow surface
Vector3 target = vertex.randomElement() + Vector3::random() * 0.0001f;
Ray ray = Ray::fromOriginAndDirection(origin, (target - origin).direction());
// Exhaustively test against each triangle
float exhaustiveDistance = inf();
{
const KDTree<Triangle>::Iterator& end = tree.end();
KDTree<Triangle>::Iterator it = tree.begin();
while (it != end) {
const Triangle& tri = *it;
float d = ray.intersectionTime(tri);
if (d > 0 && d < exhaustiveDistance) {
exhaustiveDistance = d;
}
++it;
}
}
// Test using the ray iterator
float treeDistance = inf();
tree.intersectRay(ray, intersectCallback, treeDistance, true);
float treeDistance2 = inf();
tree.intersectRay(ray, intersectCallback, treeDistance2, false);
debugAssertM(fuzzyEq(treeDistance, exhaustiveDistance),
format("KDTree::intersectRay found a point at %f, "
"exhaustive ray intersection found %f.",
treeDistance, exhaustiveDistance));
debugAssertM(fuzzyEq(treeDistance2, exhaustiveDistance),
format("KDTree::intersectRay found a point at %f, "
"exhaustive ray intersection found %f.",
treeDistance2, exhaustiveDistance));
}
printf("done) ");
}