-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmainHierarchyCreator.cpp
163 lines (142 loc) · 3.61 KB
/
mainHierarchyCreator.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
* 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 [email protected]
*/
#include "loader.h"
#include "writer.h"
#include <vector>
#include <iostream>
#include "FlatGenerator.h"
#include "PointbasedKdTreeGenerator.h"
#include "AvgMerger.h"
#include "ClusterMerger.h"
#include "common.h"
#include <fstream>
#include <filesystem>
#include "appearance_filter.h"
#include "rotation_aligner.h"
void recTraverse(ExplicitTreeNode* node, int& zerocount)
{
if (node->depth == 0)
zerocount++;
if (node->children.size() > 0 && node->depth == 0)
throw std::runtime_error("Leaf nodes should never have children!");
for (auto c : node->children)
{
recTraverse(c, zerocount);
}
}
int main(int argc, char* argv[])
{
if (argc < 3)
throw std::runtime_error("Failed to pass args <plyfile> <source dir> [scaffold dir]");
int skyboxpoints = 0;
if (argc > 4)
{
const char* scaffoldpath = nullptr;
scaffoldpath = argv[4];
std::ifstream scaffoldfile(std::string(scaffoldpath) + "/pc_info.txt");
std::string line;
std::getline(scaffoldfile, line);
skyboxpoints = std::atoi(line.c_str());
}
std::vector<Gaussian> gaussians_unfiltered;
try
{
Loader::loadPly(argv[1], gaussians_unfiltered, skyboxpoints);
}
catch(const std::runtime_error& e)
{
std::cout << "Could not load .ply. Attempt loading .bin\n";
std::string filename(argv[1]);
filename.pop_back();
filename.pop_back();
filename.pop_back();
filename = filename + "bin";
std::cout << filename << std::endl;
Loader::loadBin(filename.c_str(), gaussians_unfiltered, skyboxpoints);
}
int valid = 0;
bool not_warned = true;
std::vector<Gaussian> gaussians(gaussians_unfiltered.size());
for (int i = 0; i < gaussians_unfiltered.size(); i++)
{
Gaussian& g = gaussians_unfiltered[i];
if (std::isinf(g.opacity))
{
if (not_warned)
std::cout << "Found Inf opacity";
not_warned = false;
continue;
}
if (std::isnan(g.opacity))
{
if (not_warned)
std::cout << "Found NaN opacity";
not_warned = false;
continue;
}
if (g.scale.hasNaN())
{
if (not_warned)
std::cout << "Found NaN scale";
not_warned = false;
continue;
}
if (g.rotation.hasNaN())
{
if (not_warned)
std::cout << "Found NaN rot";
not_warned = false;
continue;
}
if (g.position.hasNaN())
{
if (not_warned)
std::cout << "Found NaN pos";
not_warned = false;
continue;
}
if (g.shs.hasNaN())
{
if(not_warned)
std::cout << "Found NaN sh";
not_warned = false;
continue;
}
if (g.opacity == 0)
{
if (not_warned)
std::cout << "Found 0 opacity";
not_warned = false;
continue;
}
gaussians[valid] = g;
valid++;
}
gaussians.resize(valid);
std::cout << "Generating" << std::endl;
PointbasedKdTreeGenerator generator;
auto root = generator.generate(gaussians);
std::cout << "Merging" << std::endl;
ClusterMerger merger;
merger.merge(root, gaussians);
std::cout << "Fixing rotations" << std::endl;
RotationAligner::align(root, gaussians);
std::cout << "Filtering" << std::endl;
float limit = 0.0005f;
char* filterpath = "";
filterpath = argv[2];
AppearanceFilter filter;
filter.init(filterpath);
filter.filter(root, gaussians, limit, 2.0f);
filter.writeAnchors((std::string(argv[3]) + "/anchors.bin").c_str(), root, gaussians, limit);
std::cout << "Writing" << std::endl;
Writer::writeHierarchy((std::string(argv[3]) + "/hierarchy.hier").c_str(), gaussians, root, true);
}