-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
49 lines (45 loc) · 1.36 KB
/
main.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
import math
from util import *
from renderer import *
import matplotlib.pyplot as plt
if __name__ == "__main__":
# set guassian
pts = np.array([[2, 0, -2], [0, 2, -2], [-2, 0, -2]])
n = len(pts)
SpheHarmonics = np.random.random((n, 16, 3))
# print(SpheHarmonics)
opacities = np.ones((n, 1))
scales = np.ones((n, 3))
rotations = np.array([np.eye(3)] * n)
# set camera
cam_pos = np.array([0, 0, 5])
R = np.array([[1, 0, 0], [0, 1, 0], [0, 0, -1]])
proj_param = {"znear": 0.01, "zfar": 100, "fovX": 45, "fovY": 45}
viewmatrix = get_world2view_mat(R=R, t=cam_pos)
projmatrix = get_proj_mat_J(**proj_param)
projmatrix = np.dot(projmatrix, viewmatrix)
tanfovx = math.tan(proj_param["fovX"] * 0.5)
tanfovy = math.tan(proj_param["fovY"] * 0.5)
# render
rasterizer = Rasterizer()
out_color = rasterizer.splat(
guassian_num=len(pts),
basis_degree=3,
basis_num=16,
background=np.array([0, 0, 0]),
width=700,
height=700,
means3D=pts,
SpheHarmonics=SpheHarmonics,
opacities=opacities,
scales=scales,
scale_modifier=1,
rotations=rotations,
viewmatrix=viewmatrix,
projmatrix=projmatrix,
cam_pos=cam_pos,
tan_fovx=tanfovx,
tan_fovy=tanfovy,
)
plt.imshow(out_color)
plt.show()