我目前正在实现 Revelles、Urena 和 Lastra 的论文 "An Efficient Parametric Algorithm for Octree Traversal" .在 Ray - Octree intersection algorithms有人实现了它并粘贴了他的代码。我的实现应该是一样的,除了我使用了一些 vector 来计算。 但是,使用此八叉树仅渲染图像的右上部分,对于图像的其余部分,不遍历八叉树。检查是否遍历发生在以下方法中:
bool Octnode::intersect( Ray r, SurfaceData *sd )
{
unsigned int a = 0;
v3d o = r.origin();
v3d d = r.direction();
if ( r.direction()[0] < 0. ) {
o[0] = _size[0] - r.origin()[0];
d[0] = -r.direction()[0];
a |= 4;
}
if ( r.direction()[1] < 0. ) {
o[1] = _size[1] - r.origin()[1];
d[1] = -r.direction()[1];
a |= 2;
}
if ( r.direction()[2] < 0. ) {
o[2] = _size[2] - r.origin()[2];
d[2] = -r.direction()[2];
a |= 1;
}
v3d t0 = ( _min - o ) / d;
v3d t1 = ( _max - o ) / d;
scalar t = std::numeric_limits<double>::max();
// traversal -- if any -- starts here
if ( t0.max() < t1.min() ) {
return processSubtree( t0, t1, r, &t, sd, a );
} else {
return false;
}
}
[编辑]以上方法实现功能
void ray_parameter( octree *oct, ray r )
来自论文。正如 C. Urena 指出的那样,论文中存在导致遍历不正确的错误。不幸的是,在这个错误发生之前跳过了遍历。 在可以在 C. Urena 的链接之后找到的 Google 组中,八叉树节点的大小似乎计算不同。我做了:
_size = _max - _min;
对比
_size = ( _max - _min ) / 2.;
在 Google 组中。我会测试它并发布另一个更新。 [/编辑]
[编辑 2] 应用 Carlos 提到的修复并将大小减半让我走到了这一步:
应该完全渲染球体,但至少不会拒绝左上四分之一的所有光线。 [/Edit 2]
[编辑 3] 使用不同的数据集我得到了看似更好的结果,看起来我必须调查代码的其他部分。
[/Edit 3]
最佳答案
我没有时间详细审查您的代码,但也许您应该检查原始论文中的错误,该错误也可能出现在您的代码中:您可以在此处查看它的描述:http://lsi.ugr.es/curena/inves/wscg00/ -- 有一个指向带有讨论的 google 组的指针。
希望这有帮助, 卡洛斯。
关于c++ - 使用八叉树时仅渲染图像的右上部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20808334/