libs/yocto/yocto_scene.cpp
// Splits a BVH node using the middle heuristic. Returns split position and
// axis.
Splits a BVH node using the middle heuristic. Returns split position and
axis.
Splits a BVH node using the middle heuristic . Returns split position and axis .
static pair<int, int> split_middle(
    vector<scene_bvh_primitive>& primitives, int start, int end) {
  auto axis = 0;
  auto mid  = (start + end) / 2;
  auto cbbox = invalidb3f;
  for (auto i = start; i < end; i++) cbbox = merge(cbbox, primitives[i].center);
  auto csize = cbbox.max - cbbox.min;
  if (csize == zero3f) return {mid, axis};
  if (csize.x >= csize.y && csize.x >= csize.z) axis = 0;
  if (csize.y >= csize.x && csize.y >= csize.z) axis = 1;
  if (csize.z >= csize.x && csize.z >= csize.y) axis = 2;
  mid = (int)(std::partition(primitives.data() + start, primitives.data() + end,
                  [axis, middle = center(cbbox)[axis]](auto& primitive) {
                    return primitive.center[axis] < middle;
                  }) -
              primitives.data());
  if (mid == start || mid == end) {
    mid = (start + end) / 2;
  }
  return {mid, axis};
}
static pair < int , int > split_middle ( vector < scene_bvh_primitive > & primitives , int start , int end ) { auto axis = 0 ; auto mid = ( start + end ) / 2 ; auto cbbox = invalidb3f ; for ( auto i = start ; i < end ; i ++ ) cbbox = merge ( cbbox , primitives [ i ] . center ) ; auto csize = cbbox . max - cbbox . min ; if ( csize == zero3f ) return { mid , axis } ; if ( csize . x >= csize . y && csize . x >= csize . z ) axis = 0 ; if ( csize . y >= csize . x && csize . y >= csize . z ) axis = 1 ; if ( csize . z >= csize . x && csize . z >= csize . y ) axis = 2 ; mid = ( int ) ( std :: partition ( primitives . data ( ) + start , primitives . data ( ) + end , [ axis , middle = center ( cbbox ) [ axis ] ] ( auto & primitive ) { return primitive . center [ axis ] < middle ; } ) - primitives . data ( ) ) ; if ( mid == start || mid == end ) { mid = ( start + end ) / 2 ; } return { mid , axis } ; }
Splits a BVH node using the middle heuristic.
Splits a BVH node using the middle heuristic .
// initialize split axis and position // compute primintive bounds and size // split along largest // split the space in the middle along the largest axis // if we were not able to split, just break the primitives in half // throw std::runtime_error("bad bvh split");