-
Notifications
You must be signed in to change notification settings - Fork 0
/
reproject.py
41 lines (33 loc) · 1014 Bytes
/
reproject.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
from __future__ import (
annotations as __annotations__,
) # Delayed parsing of type annotations
import mitsuba as mi
import drjit as dr
def w2c(sensor: mi.ProjectiveCamera) -> mi.Transform4f:
params = mi.traverse(sensor)
C2S = mi.perspective_projection(
params["film.size"],
params["film.crop_size"],
params["film.crop_offset"],
params["x_fov"],
params["near_clip"],
params["far_clip"],
)
W2C = params["to_world"]
return C2S @ W2C
if __name__ == "__main__":
mi.set_variant("cuda_ad_rgb")
scene = mi.load_dict(mi.cornell_box()) # type: mi.Scene
params = mi.traverse(scene.sensors()[0])
C2S = mi.perspective_projection(
params["film.size"],
params["film.crop_size"],
params["film.crop_offset"],
params["x_fov"],
params["near_clip"],
params["far_clip"],
)
W2C = params["to_world"]
p = mi.Point3f(0.0, 0.0, -100.0)
s = C2S @ (W2C @ p)
print(f"{s=}")