c++ - 使用八叉树时仅渲染图像的右上部分

标签 c++ algorithm raytracing octree

我目前正在实现 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 提到的修复并将大小减半让我走到了这一步:

enter image description here

应该完全渲染球体,但至少不会拒绝左上四分之一的所有光线。 [/Edit 2]

[编辑 3] 使用不同的数据集我得到了看似更好的结果,看起来我必须调查代码的其他部分。

enter image description here enter image description here

[/Edit 3]

最佳答案

我没有时间详细审查您的代码,但也许您应该检查原始论文中的错误,该错误也可能出现在您的代码中:您可以在此处查看它的描述:http://lsi.ugr.es/curena/inves/wscg00/ -- 有一个指向带有讨论的 google 组的指针。

希望这有帮助, 卡洛斯。

关于c++ - 使用八叉树时仅渲染图像的右上部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20808334/

相关文章:

c++ - sed 中用于替换 C++ 的正则表达式包括

game-physics - 在raytracer中实现景深的引用?

java - 这个光线转换算法正确吗?这是测试线/射线和立方体相交的正确方法吗?

c++ - 在新结构中声明的数组的地址

c++ - Visual Studio 如何将 boost::function 与/GR- 一起使用,而 GCC 不能与 -fno-rtti 一起使用?

algorithm - 哪种排序算法最适合对几乎完全排序的列表进行重新排序?

algorithm - 组合问题,房间配置

C圆形阵列

c# - 使用 C# 检测二维空间中的光投影和交叉点

c++ - 使用 googletest 测试 const 行为