-
Notifications
You must be signed in to change notification settings - Fork 3
/
AvgMerger.cpp
50 lines (41 loc) · 1.23 KB
/
AvgMerger.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* Copyright (C) 2024, Inria
* GRAPHDECO research group, https://team.inria.fr/graphdeco
* All rights reserved.
*
* This software is free for non-commercial, research and evaluation use
* under the terms of the LICENSE.md file.
*
* For inquiries contact george.drettakis@inria.fr
*/
#include "AvgMerger.h"
void AvgMerger::mergeRec(ExplicitTreeNode* node, const std::vector<Gaussian>& leaf_gaussians)
{
Gaussian g;
g.position = Eigen::Vector3f::Zero();
g.rotation = Eigen::Vector4f::Zero();
g.opacity = 0;
g.scale = Eigen::Vector3f::Zero();
g.shs = SHs::Zero();
float div = node->children.size() + node->leaf_indices.size();
auto avgmerge = [&div](Gaussian& g, const Gaussian& x) {
g.position += x.position / div;
g.opacity += x.opacity / div;
g.scale += x.scale;
g.rotation += x.rotation / div;
g.shs += x.shs / div;
};
for (auto& child : node->children)
{
mergeRec(child, leaf_gaussians);
avgmerge(g, child->merged[0]);
for (auto& child_leaf : child->leaf_indices)
avgmerge(g, leaf_gaussians[child_leaf]);
}
g.rotation = g.rotation.normalized();
node->merged.push_back(g);
}
void AvgMerger::merge(ExplicitTreeNode* root, const std::vector<Gaussian>& leaf_gaussians)
{
mergeRec(root, leaf_gaussians);
}