Filter
Filter wrapper.
This module provides a minimal wrapper around OIDN filters.
Filters are created from a :class:pyoidn.device.Device, then configured by
setting images and parameters, and finally committed/executed.
Typical usage:
.. code-block:: python
import numpy as np
import pyoidn
result = np.zeros_like(color, dtype=np.float32)
with pyoidn.Device() as device:
device.commit()
with pyoidn.Filter(device, pyoidn.OIDN_FILTER_TYPE_RT) as flt:
flt.set_image(pyoidn.OIDN_IMAGE_COLOR, color, pyoidn.OIDN_FORMAT_FLOAT3)
flt.set_image(pyoidn.OIDN_IMAGE_OUTPUT, result, pyoidn.OIDN_FORMAT_FLOAT3)
flt.commit()
flt.execute()
assert device.get_error() is None
Notes
- Image inputs can be passed either as NumPy arrays (shared host memory) or as
:class:
pyoidn.buffer.Bufferinstances (OIDN buffers). - Error handling: check :meth:
pyoidn.device.Device.get_errorafter operations. - Refer to https://github.com/RenderKit/oidn?tab=readme-ov-file#filters for the OIDN property settings.
Filter
Filter(device: Device, filter_type: str = OIDN_FILTER_TYPE_RT)
OIDN filter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
Device
|
The owning :class: |
required |
filter_type
|
str
|
Filter type string (e.g. |
OIDN_FILTER_TYPE_RT
|
Create a filter.
__enter__
__enter__() -> Filter
__exit__
__exit__(exc_type, exc, tb)
Exit a context manager and release the filter.
commit
commit()
Commit filter parameters and images.
execute
execute()
Execute the filter synchronously.
execute_async
execute_async()
Execute the filter asynchronously.
Synchronize via :meth:pyoidn.device.Device.wait.
get_bool
get_bool(name: str) -> bool
Get a boolean filter parameter.
get_float
get_float(name: str) -> float
Get a float filter parameter.
get_int
get_int(name: str) -> int
Get an integer filter parameter.
release
release()
Release the underlying OIDN filter handle.
set_bool
set_bool(name: str, value: bool)
Set a boolean filter parameter.
set_float
set_float(name: str, value: float)
Set a float filter parameter.
set_image
set_image(name: str, data: Any, data_format: int, width: int = -1, height: int = -1, byte_offset: int = 0, pixel_byte_stride: int = 0, row_byte_stride: int = 0) -> None
Set an input/output image.
When data is a NumPy array, this calls OIDN's shared-image API
(oidnSetSharedFilterImage). When data is a :class:pyoidn.buffer.Buffer,
it uses the buffer-based API (oidnSetFilterImage).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Image slot name. Common values are: |
required |
data
|
Any
|
NumPy array (host memory), :class: |
required |
data_format
|
int
|
One of |
required |
width
|
int
|
Image width. If |
-1
|
height
|
int
|
Image height. If |
-1
|
byte_offset
|
int
|
Byte offset into the buffer/pointer. |
0
|
pixel_byte_stride
|
int
|
Bytes between consecutive pixels. Use 0 to let OIDN assume tightly packed pixels. |
0
|
row_byte_stride
|
int
|
Bytes between consecutive rows. Use 0 to let OIDN assume tightly packed rows. |
0
|
set_int
set_int(name: str, value: int)
Set an integer filter parameter.
set_quality
set_quality(quality: int)
Set the filter quality level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quality
|
int
|
One of |
required |
set_value
set_value(k: str, value)
Convenience setter that dispatches based on Python type.
unset_image
unset_image(name: str)
Unset an input/output image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Image slot name. |
required |