本文整理汇总了C++中KDTree::balance方法的典型用法代码示例。如果您正苦于以下问题:C++ KDTree::balance方法的具体用法?C++ KDTree::balance怎么用?C++ KDTree::balance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KDTree
的用法示例。
在下文中一共展示了KDTree::balance方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testBoxIntersect
static void testBoxIntersect() {
KDTree<Vector3> tree;
// Make a tree containing a regular grid of points
for (int x = -5; x <= 5; ++x) {
for (int y = -5; y <= 5; ++y) {
for (int z = -5; z <= 5; ++z) {
tree.insert(Vector3(x, y, z));
}
}
}
tree.balance();
AABox box(Vector3(-1.5, -1.5, -1.5), Vector3(1.5, 1.5, 1.5));
KDTree<Vector3>::BoxIntersectionIterator it = tree.beginBoxIntersection(box);
const KDTree<Vector3>::BoxIntersectionIterator end = tree.endBoxIntersection();
int hits = 0;
while (it != end) {
const Vector3& v = *it;
debugAssert(box.contains(v));
++hits;
++it;
}
debugAssertM(hits == 3*3*3, "Wrong number of intersections found in testBoxIntersect for KDTree");
}
示例2: testSerialize
static void testSerialize() {
KDTree<Vector3> tree;
int N = 1000;
for (int i = 0; i < N; ++i) {
tree.insert(Vector3::random());
}
tree.balance();
// Save the struture
BinaryOutput b("test-bsp.dat", G3D_LITTLE_ENDIAN);
tree.serializeStructure(b);
b.commit();
}
示例3: 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) ");
}
示例4: perfKDTree
void perfKDTree() {
Array<AABox> array;
KDTree<AABox> tree;
const int NUM_POINTS = 1000000;
for (int i = 0; i < NUM_POINTS; ++i) {
Vector3 pt = Vector3(uniformRandom(-10, 10), uniformRandom(-10, 10), uniformRandom(-10, 10));
AABox box(pt, pt + Vector3(.1f, .1f, .1f));
array.append(box);
tree.insert(box);
}
RealTime t0 = System::time();
tree.balance();
RealTime t1 = System::time();
printf("KDTree<AABox>::balance() time for %d boxes: %gs\n\n", NUM_POINTS, t1 - t0);
uint64 bspcount = 0, arraycount = 0, boxcount = 0;
// Run twice to get cache issues out of the way
for (int it = 0; it < 2; ++it) {
Array<Plane> plane;
plane.append(Plane(Vector3(-1, 0, 0), Vector3(3, 1, 1)));
plane.append(Plane(Vector3(1, 0, 0), Vector3(1, 1, 1)));
plane.append(Plane(Vector3(0, 0, -1), Vector3(1, 1, 3)));
plane.append(Plane(Vector3(0, 0, 1), Vector3(1, 1, 1)));
plane.append(Plane(Vector3(0,-1, 0), Vector3(1, 3, 1)));
plane.append(Plane(Vector3(0, 1, 0), Vector3(1, -3, 1)));
AABox box(Vector3(1, 1, 1), Vector3(3,3,3));
Array<AABox> point;
System::beginCycleCount(bspcount);
tree.getIntersectingMembers(plane, point);
System::endCycleCount(bspcount);
point.clear();
System::beginCycleCount(boxcount);
tree.getIntersectingMembers(box, point);
System::endCycleCount(boxcount);
point.clear();
System::beginCycleCount(arraycount);
for (int i = 0; i < array.size(); ++i) {
if (! array[i].culledBy(plane)) {
point.append(array[i]);
}
}
System::endCycleCount(arraycount);
}
printf("KDTree<AABox>::getIntersectingMembers(plane) %g Mcycles\n"
"KDTree<AABox>::getIntersectingMembers(box) %g Mcycles\n"
"Culled by on Array<AABox> %g Mcycles\n\n",
bspcount / 1e6,
boxcount / 1e6,
arraycount / 1e6);
}