-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgenerate_pseudomesh.py
155 lines (146 loc) · 5.13 KB
/
generate_pseudomesh.py
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
import argparse
from pathlib import Path
import numpy as np
import gs_utils
def main(ply_path: Path, algorithm: str, scale_muls: np.ndarray, no_of_points: int):
xyz, feat_dc, feat_res, opac, scales, rots_quaternion = gs_utils.load_ply(
ply_path, 0
)
if algorithm == "games":
games_ckpt_path = Path(ply_path.parent, "model_params.pt")
try:
games_data = gs_utils.load_games_pt(games_ckpt_path)
except FileNotFoundError:
games_data = None
if algorithm == "2dgs":
pseudomeshes = gs_utils.generate_pseudomesh_2dgs(
xyz=xyz,
features_dc=feat_dc,
opacities=opac,
scales=scales,
rots=rots_quaternion,
scale_muls=scale_muls,
no_of_points=no_of_points
)
elif algorithm == "surfels":
pseudomeshes = gs_utils.generate_pseudomesh_surfels(
xyz=xyz,
features_dc=feat_dc,
opacities=opac,
scales=scales,
rots=rots_quaternion,
scale_muls=scale_muls,
no_of_points=no_of_points
)
elif algorithm == "games":
pseudomeshes = gs_utils.generate_pseudomesh_games(
ckpt_data=games_data,
xyz=xyz,
features_dc=feat_dc,
opacities=opac,
scales=scales,
rots=rots_quaternion,
scale_muls=scale_muls,
no_of_points=no_of_points
)
elif algorithm == "sugar2d":
pseudomeshes = gs_utils.generate_pseudomesh_sugar_2d(
xyz=xyz,
features_dc=feat_dc,
opacities=opac,
scales=scales,
rots=rots_quaternion,
scale_muls=scale_muls,
no_of_points=no_of_points
)
elif algorithm == "sugar3d":
pseudomeshes = gs_utils.generate_pseudomesh_sugar_3d(
xyz=xyz,
features_dc=feat_dc,
opacities=opac,
scales=scales,
rots=rots_quaternion,
scale_muls=scale_muls,
no_of_points=no_of_points
)
elif algorithm == "3dgs":
pseudomeshes = gs_utils.generate_3dgs_pseudomesh(
xyz=xyz,
features_dc=feat_dc,
opacities=opac,
scales=scales,
rots=rots_quaternion,
scale_muls=scale_muls,
no_of_points=no_of_points
)
else:
raise NotImplementedError(f"Algorithm {algorithm} not yet implemented")
# save data
if "sugar" in algorithm:
main_out_dir = ply_path.parent
else:
main_out_dir = ply_path.parent.parent.parent
out_dir = Path(main_out_dir, "pseudomeshes")
out_dir.mkdir(exist_ok=True, parents=True)
for scale_val, pseudomesh_data in pseudomeshes.items():
scale_val_str = "{:.2f}".format(scale_val)
out_path = Path(out_dir, f"scale_{scale_val_str}_pts_{str(no_of_points)}.npz")
np.savez(
out_path,
**pseudomesh_data
)
print(f"Saved {out_path}")
def read_args():
parser = argparse.ArgumentParser(description="This script accepts ply file and outputs pseudomesh of it")
parser.add_argument(
"--ply",
# required=True,
# default="/home/grzegos/projects/phd/2dgs_nerf_output/hotdog/point_cloud/iteration_10000/point_cloud.ply",
# default="/home/grzegos/projects/phd/2dgs_read_output/garden1/point_cloud/iteration_30000/point_cloud.ply",
# default="/home/grzegos/projects/phd/games_nerf_output/hotdog_test_fff_sh0/point_cloud/iteration_30000/point_cloud.ply",
default="/home/grzegos/projects/phd/pseudomesh_paper/experiments/3dgs_hotdog_test_sh0/point_cloud/iteration_30000/point_cloud.ply",
# default="/home/grzegos/projects/phd/surfel_nerf_output/chair_test/point_cloud/iteration_50000/point_cloud.ply",
# default="/home/grzegos/projects/phd/games_nerf_output/hotdog_new_test/point_cloud/iteration_1000/point_cloud.ply",
# default="/home/grzegos/projects/phd/SuGaR/output/refined_ply/char_sh0/sugarfine_3Dgs7000_sdfestim02_sdfnorm02_level03_decim1000000_normalconsistency01_gaussperface1.ply",
type=str,
help="Path to the ply file"
)
parser.add_argument(
"--algorithm",
# default="games",
default="3dgs",
# default="surfels",
# default="games",
# default="sugar3d",
type=str,
choices=["2dgs", "games", "surfels", "sugar2d", "sugar3d", "3dgs"]
)
parser.add_argument(
"--scale_min",
default=2.3,
type=float
)
parser.add_argument(
"--scale_max",
default=2.4,
type=float
)
parser.add_argument(
"--scale_step",
default=0.2,
type=float
)
parser.add_argument(
"--no_points",
default=8,
type=int
)
args = parser.parse_args()
return {
"ply_path": Path(args.ply),
"algorithm": args.algorithm,
"scale_muls": np.arange(args.scale_min, args.scale_max, args.scale_step),
"no_of_points": args.no_points
}
if __name__ == "__main__":
main(**read_args())