-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhierarchy_loader.cpp
128 lines (108 loc) · 3.38 KB
/
hierarchy_loader.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
/*
* 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 "hierarchy_loader.h"
#include <vector>
#include <Eigen/Dense>
#include "common.h"
#include <iostream>
#include <fstream>
#include "half.hpp"
struct HalfBox2
{
half_float::half minn[4];
half_float::half maxx[4];
};
void HierarchyLoader::load(const char* filename,
std::vector<Eigen::Vector3f>& pos,
std::vector<SHs>& shs,
std::vector<float>& alphas,
std::vector<Eigen::Vector3f>& scales,
std::vector<Eigen::Vector4f>& rot,
std::vector<Node>& nodes,
std::vector<Box>& boxes)
{
std::ifstream infile(filename, std::ios_base::binary);
if (!infile.good())
throw std::runtime_error("File not found!");
int P;
infile.read((char*)&P, sizeof(int));
if (P >= 0)
{
pos.resize(P);
shs.resize(P);
alphas.resize(P);
scales.resize(P);
rot.resize(P);
infile.read((char*)pos.data(), P * sizeof(Eigen::Vector3f));
infile.read((char*)rot.data(), P * sizeof(Eigen::Vector4f));
infile.read((char*)scales.data(), P * sizeof(Eigen::Vector3f));
infile.read((char*)alphas.data(), P * sizeof(float));
infile.read((char*)shs.data(), P * sizeof(SHs));
int N;
infile.read((char*)&N, sizeof(int));
nodes.resize(N);
boxes.resize(N);
infile.read((char*)nodes.data(), N * sizeof(Node));
infile.read((char*)boxes.data(), N * sizeof(Box));
}
else
{
size_t allP = -P;
pos.resize(allP);
shs.resize(allP);
alphas.resize(allP);
scales.resize(allP);
rot.resize(allP);
std::vector<half_float::half> half_rotations(allP * 4);
std::vector<half_float::half> half_scales(allP * 3);
std::vector<half_float::half> half_opacities(allP);
std::vector<half_float::half> half_shs(allP * 48);
infile.read((char*)pos.data(), allP * sizeof(Eigen::Vector3f));
infile.read((char*)half_rotations.data(), allP * 4 * sizeof(half_float::half));
infile.read((char*)half_scales.data(), allP * 3 * sizeof(half_float::half));
infile.read((char*)half_opacities.data(), allP * sizeof(half_float::half));
infile.read((char*)half_shs.data(), allP * 48 * sizeof(half_float::half));
for (size_t i = 0; i < allP; i++)
{
for (size_t j = 0; j < 4; j++)
rot[i][j] = half_rotations[i * 4 + j];
for (size_t j = 0; j < 3; j++)
scales[i][j] = half_scales[i * 3 + j];
alphas[i] = half_opacities[i];
for (size_t j = 0; j < 48; j++)
shs[i][j] = half_shs[i * 48 + j];
}
int N;
infile.read((char*)&N, sizeof(int));
size_t allN = N;
nodes.resize(allN);
boxes.resize(allN);
std::vector<HalfNode> half_nodes(allN);
std::vector<HalfBox2> half_boxes(allN);
infile.read((char*)half_nodes.data(), allN * sizeof(HalfNode));
infile.read((char*)half_boxes.data(), allN * sizeof(HalfBox2));
for (int i = 0; i < allN; i++)
{
nodes[i].parent = half_nodes[i].parent;
nodes[i].start = half_nodes[i].start;
nodes[i].start_children = half_nodes[i].start_children;
nodes[i].depth = half_nodes[i].dccc[0];
nodes[i].count_children = half_nodes[i].dccc[1];
nodes[i].count_leafs = half_nodes[i].dccc[2];
nodes[i].count_merged = half_nodes[i].dccc[3];
for (int j = 0; j < 4; j++)
{
boxes[i].minn[j] = half_boxes[i].minn[j];
boxes[i].maxx[j] = half_boxes[i].maxx[j];
}
}
}
}