Split position median instead of average
This commit is contained in:
parent
74ff7c8238
commit
2983d06bea
1 changed files with 8 additions and 5 deletions
|
@ -181,11 +181,14 @@ std::unique_ptr<Node> FastScene::build(Vector3d const &minimumBounds, Vector3d c
|
|||
|
||||
// Determine the split position
|
||||
// Note: Use the median of the minimum bounds of the primitives
|
||||
node->split = std::accumulate(primitives.begin(), primitives.end(), 0.0f,
|
||||
[&node](float &a, const auto &prim) {
|
||||
return a + prim->minimumBounds(node->dimension);
|
||||
}) /
|
||||
static_cast<float>(primitives.size());
|
||||
std::vector<std::shared_ptr<Primitive>> copy(primitives.size());
|
||||
std::partial_sort_copy(primitives.begin(), primitives.end(), copy.begin(), copy.end(),
|
||||
[&node](const auto &prim1, const auto &prim2) {
|
||||
return prim1->minimumBounds(node->dimension) <
|
||||
prim2->minimumBounds(node->dimension);
|
||||
});
|
||||
node->split = copy.at(copy.size() / 2)->minimumBounds(node->dimension);
|
||||
|
||||
|
||||
// Divide primitives into the left and right lists
|
||||
// Remember: A primitive can be in both lists!
|
||||
|
|
Loading…
Reference in a new issue