Skip to content

Commit 76bc7b4

Browse files
committed
sample of adding gui widgets
1 parent bfbeab7 commit 76bc7b4

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
"""
2+
Custom widgets added to TkOptiX GUI.
3+
"""
4+
5+
import copy
6+
import numpy as np
7+
import tkinter as tk
8+
9+
from plotoptix import TkOptiX
10+
from plotoptix.materials import m_clear_glass
11+
12+
13+
def autoexposure():
14+
q = np.quantile(rt._raw_rgba[...,:3], 0.9)
15+
rt.set_float("tonemap_exposure", 1 / q)
16+
17+
def slide(event=None):
18+
att_len = 0.1 * int(slider.get())
19+
m_clear_glass["VarFloat3"]["base_color"] = [ att_len, att_len, 100 ]
20+
rt.setup_material("glass", m_clear_glass)
21+
22+
23+
24+
rt = TkOptiX(start_now=False)
25+
26+
rt.set_param(min_accumulation_step=8, max_accumulation_frames=500)
27+
28+
rt.set_uint("path_seg_range", 8, 16)
29+
30+
rt.set_background(0)
31+
rt.set_ambient(0.1)
32+
33+
rt.set_float("tonemap_exposure", 1.0)
34+
rt.set_float("tonemap_gamma", 2.2)
35+
rt.add_postproc("Gamma")
36+
37+
rt.setup_camera("cam", cam_type="Pinhole",
38+
#work_distribution="RelNoiseBalanced", # use that in 0.17.1
39+
eye=[-7, 8, 11], target=[0, 2, 0],
40+
fov=22, glock=True
41+
)
42+
rt.setup_light("light", pos=[4, 7, -1], color=20, radius=0.5)
43+
44+
rt.set_data("plane", geom="Parallelograms",
45+
pos=[-100, 0, -100], u=[200, 0, 0], v=[0, 0, 200],
46+
c=0.95
47+
)
48+
49+
m_clear_glass["VarFloat3"]["base_color"] = [ 0.3, 0.3, 100 ]
50+
rt.setup_material("glass", m_clear_glass)
51+
rt.set_data("cube", geom="Parallelepipeds",
52+
pos=[-1, 3, -1], u=[2, 0, 0], v=[0, 0, 2], w=[0, 2, 0],
53+
mat="glass"
54+
)
55+
56+
rt.start()
57+
58+
### Add a panel with custom widgets ###
59+
60+
# First, reconfigure the ray tracing output to leave a column for the new panel:
61+
rt._canvas.grid(column=0, row=0, columnspan=2, sticky="nsew")
62+
63+
# ...then insert the panel:
64+
p1 = tk.PanedWindow()
65+
p1.grid(column=2, row=0, sticky="ns")
66+
67+
# ...and add widgets, bind to handlers:
68+
btn = tk.Button(p1, text="Autoexposure", command=autoexposure)
69+
btn.grid(column=0, row=0, sticky="new", padx=8, pady=4)
70+
71+
slider = tk.Scale(p1, from_=0, to=100, orient="horizontal")
72+
slider.set(int(10 * m_clear_glass["VarFloat3"]["base_color"][0]))
73+
slider.bind("<B1-Motion>", slide)
74+
slider.grid(column=0, row=1, sticky="new")

0 commit comments

Comments
 (0)