Skip to content

Commit

Permalink
Merge pull request #54 from rnd-team-dev/r0.17.1
Browse files Browse the repository at this point in the history
R0.17.1
  • Loading branch information
robertsulej authored Oct 6, 2023
2 parents 19a6dae + 6ed5825 commit dc38b7a
Show file tree
Hide file tree
Showing 11 changed files with 266 additions and 2,148 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Release history
===============

`v0.17.1` - 2023-10-06
----------------------

Added
~~~~~

- Noise-balanced work distribution: absolute and relative noise modes


`v0.17.0` - 2023-08-18
----------------------

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

.. _`v0.17.1`: https://github.com/rnd-team-dev/plotoptix/releases/tag/v0.17.1
.. _`v0.17.0`: https://github.com/rnd-team-dev/plotoptix/releases/tag/v0.17.0
.. _`v0.16.1`: https://github.com/rnd-team-dev/plotoptix/releases/tag/v0.16.1
.. _`v0.16.0`: https://github.com/rnd-team-dev/plotoptix/releases/tag/v0.16.0
.. _`v0.15.1`: https://github.com/rnd-team-dev/plotoptix/releases/tag/v0.15.1
Expand Down
2,265 changes: 155 additions & 2,110 deletions examples/1_basics/16_work_distribution.ipynb

Large diffs are not rendered by default.

74 changes: 74 additions & 0 deletions examples/2_animations_and_callbacks/7_add_gui_widgets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""
Custom widgets added to TkOptiX GUI.
"""

import copy
import numpy as np
import tkinter as tk

from plotoptix import TkOptiX
from plotoptix.materials import m_clear_glass


def autoexposure():
q = np.quantile(rt._raw_rgba[...,:3], 0.9)
rt.set_float("tonemap_exposure", 1 / q)

def slide(event=None):
att_len = 0.1 * int(slider.get())
m_clear_glass["VarFloat3"]["base_color"] = [ att_len, att_len, 100 ]
rt.setup_material("glass", m_clear_glass)



rt = TkOptiX(start_now=False)

rt.set_param(min_accumulation_step=8, max_accumulation_frames=500)

rt.set_uint("path_seg_range", 8, 16)

rt.set_background(0)
rt.set_ambient(0.1)

rt.set_float("tonemap_exposure", 1.0)
rt.set_float("tonemap_gamma", 2.2)
rt.add_postproc("Gamma")

rt.setup_camera("cam", cam_type="Pinhole",
#work_distribution="RelNoiseBalanced", # use that in 0.17.1
eye=[-7, 8, 11], target=[0, 2, 0],
fov=22, glock=True
)
rt.setup_light("light", pos=[4, 7, -1], color=20, radius=0.5)

rt.set_data("plane", geom="Parallelograms",
pos=[-100, 0, -100], u=[200, 0, 0], v=[0, 0, 200],
c=0.95
)

m_clear_glass["VarFloat3"]["base_color"] = [ 0.3, 0.3, 100 ]
rt.setup_material("glass", m_clear_glass)
rt.set_data("cube", geom="Parallelepipeds",
pos=[-1, 3, -1], u=[2, 0, 0], v=[0, 0, 2], w=[0, 2, 0],
mat="glass"
)

rt.start()

### Add a panel with custom widgets ###

# First, reconfigure the ray tracing output to leave a column for the new panel:
rt._canvas.grid(column=0, row=0, columnspan=2, sticky="nsew")

# ...then insert the panel:
p1 = tk.PanedWindow()
p1.grid(column=2, row=0, sticky="ns")

# ...and add widgets, bind to handlers:
btn = tk.Button(p1, text="Autoexposure", command=autoexposure)
btn.grid(column=0, row=0, sticky="new", padx=8, pady=4)

slider = tk.Scale(p1, from_=0, to=100, orient="horizontal")
slider.set(int(10 * m_clear_glass["VarFloat3"]["base_color"][0]))
slider.bind("<B1-Motion>", slide)
slider.grid(column=0, row=1, sticky="new")
4 changes: 2 additions & 2 deletions plotoptix/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

__author__ = "Robert Sulej, R&D Team <[email protected]>"
__status__ = "beta"
__version__ = "0.17.0"
__date__ = "18 August 2023"
__version__ = "0.17.1"
__date__ = "6 October 2023"

import logging

Expand Down
23 changes: 5 additions & 18 deletions plotoptix/_load_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,17 +287,12 @@ def _load_optix_win():
optix.set_coordinates_geom.argtypes = [c_int, c_float]
optix.set_coordinates_geom.restype = c_bool

optix.get_work_distribution.restype = c_int

optix.set_work_distribution.argtypes = [c_int]
optix.set_work_distribution.restype = c_bool

optix.get_noise_threshold.restype = c_float

optix.set_noise_threshold.argtypes = [c_float]
optix.set_noise_threshold.restype = c_bool

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]
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]
optix.setup_camera.restype = c_int

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]
Expand Down Expand Up @@ -941,16 +936,12 @@ def delete_geometry(self, name): return self._optix.delete_geometry(name)

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

def get_work_distribution(self): return self._optix.get_work_distribution()

def set_work_distribution(self, mode): return self._optix.set_work_distribution(mode)

def get_noise_threshold(self): return self._optix.get_noise_threshold()

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

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):
return self._optix.setup_camera_ptr(name, camera_type,
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):
return self._optix.setup_camera_ptr(name, camera_type, work_distribution,
IntPtr.__overloads__[Int64](eye),
IntPtr.__overloads__[Int64](target),
IntPtr.__overloads__[Int64](up),
Expand Down Expand Up @@ -1715,16 +1706,12 @@ def delete_geometry(self, name): return self._optix.delete_geometry(name)

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

def get_work_distribution(self): return self._optix.get_work_distribution()

def set_work_distribution(self, mode): return self._optix.set_work_distribution(mode)

def get_noise_threshold(self): return self._optix.get_noise_threshold()

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

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):
return self._optix.setup_camera_ptr(name, camera_type,
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):
return self._optix.setup_camera_ptr(name, camera_type, work_distribution,
IntPtr(eye),
IntPtr(target),
IntPtr(up),
Expand Down
Binary file modified plotoptix/bin/RnD.SharpOptiX.dll
Binary file not shown.
Binary file modified plotoptix/bin/librndSharpOptiX7.so
Binary file not shown.
Binary file modified plotoptix/bin/rndSharpOptiX7.dll
Binary file not shown.
10 changes: 9 additions & 1 deletion plotoptix/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,15 @@ class WorkDistribution(Enum):
"""

NoiseBalanced = 1
"""More rays towards noisy pixels.
"""More rays towards pixels with a higher relative noise, same as.
"""

RelNoiseBalanced = 1
"""More rays towards pixels a higher relative noise.
"""

AbsNoiseBalanced = 2
"""More rays towards pixels a higher absolute noise.
"""

class Camera(Enum):
Expand Down
25 changes: 9 additions & 16 deletions plotoptix/npoptix.py
Original file line number Diff line number Diff line change
Expand Up @@ -2144,15 +2144,6 @@ def set_param(self, **kwargs) -> None:
names ``"Hard"`` and ``"Soft"`` are accepted.
Set mode before adding lights.
- ``work_distribution``: how rays per pixel are distributed
Default value is :attr:`plotoptix.enums.WorkDistribution.Uniform`,
shooting constant number of rays per pixel (though no. of rays may
differ vor various materials of the primary hit).
Use :attr:`plotoptix.enums.WorkDistribution.NoiseBalanced` for dynamic
distribution of rays based on the estimated per pixel noise.
- ``max_accumulation_frames``
Expand Down Expand Up @@ -2205,12 +2196,6 @@ def set_param(self, **kwargs) -> None:
elif key == "max_accumulation_frames":
self._optix.set_max_accumulation_frames(int(value))

elif key == "work_distribution":
if isinstance(value, str): mode = WorkDistribution[value]
else: mode = value

self._optix.set_work_distribution(mode.value)

elif key == "noise_threshold":
self._optix.set_noise_threshold(float(value))

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

if not isinstance(name, str): name = str(name)
if isinstance(cam_type, str): cam_type = Camera[cam_type]
if isinstance(work_distribution, str): work_distribution = WorkDistribution[work_distribution]

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

h = self._optix.setup_camera(name, cam_type.value,
h = self._optix.setup_camera(name, cam_type.value, work_distribution.value,
eye_ptr, target_ptr, up.ctypes.data,
aperture_radius, aperture_fract,
focal_scale, chroma_l, chroma_t,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def get_tag(self):


setup(name='plotoptix',
version='0.17.0',
version='0.17.1',
url='https://rnd.team/plotoptix',
project_urls={
'Documentation': 'https://plotoptix.rnd.team',
Expand Down

0 comments on commit dc38b7a

Please sign in to comment.