Skip to content

Commit dc38b7a

Browse files
authored
Merge pull request #54 from rnd-team-dev/r0.17.1
R0.17.1
2 parents 19a6dae + 6ed5825 commit dc38b7a

File tree

11 files changed

+266
-2148
lines changed

11 files changed

+266
-2148
lines changed

CHANGELOG.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
Release history
22
===============
33

4+
`v0.17.1` - 2023-10-06
5+
----------------------
6+
7+
Added
8+
~~~~~
9+
10+
- Noise-balanced work distribution: absolute and relative noise modes
11+
12+
413
`v0.17.0` - 2023-08-18
514
----------------------
615

@@ -608,6 +617,8 @@ Added
608617
- this changelog, markdown description content type tag for PyPI
609618
- use [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
610619

620+
.. _`v0.17.1`: https://github.com/rnd-team-dev/plotoptix/releases/tag/v0.17.1
621+
.. _`v0.17.0`: https://github.com/rnd-team-dev/plotoptix/releases/tag/v0.17.0
611622
.. _`v0.16.1`: https://github.com/rnd-team-dev/plotoptix/releases/tag/v0.16.1
612623
.. _`v0.16.0`: https://github.com/rnd-team-dev/plotoptix/releases/tag/v0.16.0
613624
.. _`v0.15.1`: https://github.com/rnd-team-dev/plotoptix/releases/tag/v0.15.1

examples/1_basics/16_work_distribution.ipynb

Lines changed: 155 additions & 2110 deletions
Large diffs are not rendered by default.
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")

plotoptix/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
__author__ = "Robert Sulej, R&D Team <dev@rnd.team>"
1414
__status__ = "beta"
15-
__version__ = "0.17.0"
16-
__date__ = "18 August 2023"
15+
__version__ = "0.17.1"
16+
__date__ = "6 October 2023"
1717

1818
import logging
1919

plotoptix/_load_lib.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -287,17 +287,12 @@ def _load_optix_win():
287287
optix.set_coordinates_geom.argtypes = [c_int, c_float]
288288
optix.set_coordinates_geom.restype = c_bool
289289

290-
optix.get_work_distribution.restype = c_int
291-
292-
optix.set_work_distribution.argtypes = [c_int]
293-
optix.set_work_distribution.restype = c_bool
294-
295290
optix.get_noise_threshold.restype = c_float
296291

297292
optix.set_noise_threshold.argtypes = [c_float]
298293
optix.set_noise_threshold.restype = c_bool
299294

300-
optix.setup_camera.argtypes = [c_wchar_p, c_int, c_void_p, c_void_p, c_void_p, c_float, c_float, c_float, c_float, c_float, c_float, c_float, c_float, c_float, c_float, c_float, c_bool, c_wchar_p, c_bool]
295+
optix.setup_camera.argtypes = [c_wchar_p, c_int, c_int, c_void_p, c_void_p, c_void_p, c_float, c_float, c_float, c_float, c_float, c_float, c_float, c_float, c_float, c_float, c_float, c_bool, c_wchar_p, c_bool]
301296
optix.setup_camera.restype = c_int
302297

303298
optix.update_camera.argtypes = [c_wchar_p, c_void_p, c_void_p, c_void_p, c_float, c_float, c_float, c_float, c_float, c_float, c_float]
@@ -941,16 +936,12 @@ def delete_geometry(self, name): return self._optix.delete_geometry(name)
941936

942937
def set_coordinates_geom(self, mode, thickness): return self._optix.set_coordinates_geom(mode, thickness)
943938

944-
def get_work_distribution(self): return self._optix.get_work_distribution()
945-
946-
def set_work_distribution(self, mode): return self._optix.set_work_distribution(mode)
947-
948939
def get_noise_threshold(self): return self._optix.get_noise_threshold()
949940

950941
def set_noise_threshold(self, thr): return self._optix.set_noise_threshold(thr)
951942

952-
def setup_camera(self, name, camera_type, eye, target, up, aperture_r, aperture_fract, focal_scale, chroma_l, chroma_t, fov, rxy, cx, cy, sensor_height, blur, glock, textures, make_current):
953-
return self._optix.setup_camera_ptr(name, camera_type,
943+
def setup_camera(self, name, camera_type, work_distribution, eye, target, up, aperture_r, aperture_fract, focal_scale, chroma_l, chroma_t, fov, rxy, cx, cy, sensor_height, blur, glock, textures, make_current):
944+
return self._optix.setup_camera_ptr(name, camera_type, work_distribution,
954945
IntPtr.__overloads__[Int64](eye),
955946
IntPtr.__overloads__[Int64](target),
956947
IntPtr.__overloads__[Int64](up),
@@ -1715,16 +1706,12 @@ def delete_geometry(self, name): return self._optix.delete_geometry(name)
17151706

17161707
def set_coordinates_geom(self, mode, thickness): return self._optix.set_coordinates_geom(mode, float(thickness))
17171708

1718-
def get_work_distribution(self): return self._optix.get_work_distribution()
1719-
1720-
def set_work_distribution(self, mode): return self._optix.set_work_distribution(mode)
1721-
17221709
def get_noise_threshold(self): return self._optix.get_noise_threshold()
17231710

17241711
def set_noise_threshold(self, thr): return self._optix.set_noise_threshold(thr)
17251712

1726-
def setup_camera(self, name, camera_type, eye, target, up, aperture_r, aperture_fract, focal_scale, chroma_l, chroma_t, fov, rxy, cx, cy, sensor_height, blur, glock, textures, make_current):
1727-
return self._optix.setup_camera_ptr(name, camera_type,
1713+
def setup_camera(self, name, camera_type, work_distribution, eye, target, up, aperture_r, aperture_fract, focal_scale, chroma_l, chroma_t, fov, rxy, cx, cy, sensor_height, blur, glock, textures, make_current):
1714+
return self._optix.setup_camera_ptr(name, camera_type, work_distribution,
17281715
IntPtr(eye),
17291716
IntPtr(target),
17301717
IntPtr(up),

plotoptix/bin/RnD.SharpOptiX.dll

-512 Bytes
Binary file not shown.

plotoptix/bin/librndSharpOptiX7.so

8.39 KB
Binary file not shown.

plotoptix/bin/rndSharpOptiX7.dll

8 KB
Binary file not shown.

plotoptix/enums.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,15 @@ class WorkDistribution(Enum):
458458
"""
459459

460460
NoiseBalanced = 1
461-
"""More rays towards noisy pixels.
461+
"""More rays towards pixels with a higher relative noise, same as.
462+
"""
463+
464+
RelNoiseBalanced = 1
465+
"""More rays towards pixels a higher relative noise.
466+
"""
467+
468+
AbsNoiseBalanced = 2
469+
"""More rays towards pixels a higher absolute noise.
462470
"""
463471

464472
class Camera(Enum):

plotoptix/npoptix.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,15 +2144,6 @@ def set_param(self, **kwargs) -> None:
21442144
names ``"Hard"`` and ``"Soft"`` are accepted.
21452145
21462146
Set mode before adding lights.
2147-
2148-
- ``work_distribution``: how rays per pixel are distributed
2149-
2150-
Default value is :attr:`plotoptix.enums.WorkDistribution.Uniform`,
2151-
shooting constant number of rays per pixel (though no. of rays may
2152-
differ vor various materials of the primary hit).
2153-
2154-
Use :attr:`plotoptix.enums.WorkDistribution.NoiseBalanced` for dynamic
2155-
distribution of rays based on the estimated per pixel noise.
21562147
21572148
- ``max_accumulation_frames``
21582149
@@ -2205,12 +2196,6 @@ def set_param(self, **kwargs) -> None:
22052196
elif key == "max_accumulation_frames":
22062197
self._optix.set_max_accumulation_frames(int(value))
22072198

2208-
elif key == "work_distribution":
2209-
if isinstance(value, str): mode = WorkDistribution[value]
2210-
else: mode = value
2211-
2212-
self._optix.set_work_distribution(mode.value)
2213-
22142199
elif key == "noise_threshold":
22152200
self._optix.set_noise_threshold(float(value))
22162201

@@ -2758,6 +2743,7 @@ def setup_camera(self, name: str,
27582743
target: Optional[Any] = None,
27592744
up: Optional[Any] = None,
27602745
cam_type: Union[Camera, str] = Camera.Pinhole,
2746+
work_distribution: Union[WorkDistribution, str] = WorkDistribution.Uniform,
27612747
aperture_radius: float = -1,
27622748
aperture_fract: float = 0.15,
27632749
focal_scale: float = -1,
@@ -2794,6 +2780,12 @@ def setup_camera(self, name: str,
27942780
cam_type : Camera enum or string, optional
27952781
Type (pinhole, depth of field, ...), see :class:`plotoptix.enums.Camera`.
27962782
Cannot be changed after construction.
2783+
work_distribution :
2784+
How rays per pixel are distributed. Default value is :attr:`plotoptix.enums.WorkDistribution.Uniform`,
2785+
shooting constant number of rays per pixel (though no. of rays may
2786+
differ vor various materials of the primary hit).
2787+
See :class:`plotoptix.enums.WorkDistribution` for dynamic
2788+
distribution of rays based on the estimated per pixel noise.
27972789
aperture_radius : float, optional
27982790
Aperture radius (increases focus blur for depth of field cameras). Default
27992791
`-1` is internally reset to `0.1`.
@@ -2837,6 +2829,7 @@ def setup_camera(self, name: str,
28372829

28382830
if not isinstance(name, str): name = str(name)
28392831
if isinstance(cam_type, str): cam_type = Camera[cam_type]
2832+
if isinstance(work_distribution, str): work_distribution = WorkDistribution[work_distribution]
28402833

28412834
if name in self.camera_handles:
28422835
self.update_camera(name=name, eye=eye, target=target, up=up,
@@ -2896,7 +2889,7 @@ def setup_camera(self, name: str,
28962889
tex_list = ""
28972890
if textures is not None: tex_list = ";".join(textures)
28982891

2899-
h = self._optix.setup_camera(name, cam_type.value,
2892+
h = self._optix.setup_camera(name, cam_type.value, work_distribution.value,
29002893
eye_ptr, target_ptr, up.ctypes.data,
29012894
aperture_radius, aperture_fract,
29022895
focal_scale, chroma_l, chroma_t,

0 commit comments

Comments
 (0)