Skip to content

Commit 420355e

Browse files
authored
Merge pull request #755 from PaulHax/tf-points
feat: add set_image_piecewise_function_points
2 parents 9dce163 + 0ca6672 commit 420355e

6 files changed

+71
-54
lines changed

examples/GettersAndSetters.ipynb

+50-28
Large diffs are not rendered by default.

itkwidgets/_initialization_params.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def init_params_dict(itk_viewer):
2222
'gradient_opacity': itk_viewer.setImageGradientOpacity,
2323
'gradient_opacity_scale': itk_viewer.setImageGradientOpacityScale,
2424
'interpolation': itk_viewer.setImageInterpolationEnabled,
25-
'gaussians': itk_viewer.setImagePiecewiseFunctionGaussians,
25+
'transfer_function': itk_viewer.setImagePiecewiseFunctionPoints,
2626
'shadow_enabled': itk_viewer.setImageShadowEnabled,
2727
'sample_distance': itk_viewer.setImageVolumeSampleDistance,
2828
'label_blend': itk_viewer.setLabelImageBlend,

itkwidgets/_method_types.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def deferred_methods():
88
'setImageGradientOpacity',
99
'setImageGradientOpacityScale',
1010
'setImageInterpolationEnabled',
11-
'setImagePiecewiseFunctionGaussians',
11+
'setImagePiecewiseFunctionPoints',
1212
'setImageVolumeSampleDistance',
1313
'setImageVolumeScatteringBlend',
1414
'setLabelImageBlend',
@@ -30,7 +30,7 @@ def deferred_methods():
3030
'getImageGradientOpacity',
3131
'getImageGradientOpacityScale',
3232
'getImageInterpolationEnabled',
33-
'getImagePiecewiseFunctionGaussians',
33+
'getImagePiecewiseFunctionPoints',
3434
'getImageVolumeSampleDistance',
3535
'getImageVolumeScatteringBlend',
3636
'getLabelImageBlend',

itkwidgets/_type_aliases.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
from .integrations.pytorch import HAVE_TORCH
88
from .integrations.vtk import HAVE_VTK
99
from .integrations.xarray import HAVE_XARRAY
10-
from typing import Dict, List, Literal, Union
10+
from typing import Dict, List, Literal, Union, Sequence
1111

12-
Gaussian_Curve = Dict[str, float]
13-
Gaussians = Dict[str, List[Gaussian_Curve]]
12+
Points2d = Sequence[Sequence[float]]
1413

1514
Style = Dict[str, str]
1615

itkwidgets/viewer.py

+15-19
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import uuid
1515

1616
from ._method_types import deferred_methods
17-
from ._type_aliases import Gaussians, Style, Image, PointSet, CroppingPlanes
17+
from ._type_aliases import Style, Image, PointSet, CroppingPlanes, Points2d
1818
from ._initialization_params import (
1919
init_params_dict,
2020
build_config,
@@ -784,30 +784,26 @@ async def get_image_interpolation_enabled(self) -> asyncio.Future | bool:
784784
return await self.viewer_rpc.itk_viewer.getImageInterpolationEnabled()
785785

786786
@fetch_value
787-
def set_image_piecewise_function_gaussians(self, gaussians: Gaussians) -> None:
788-
"""Set the volume rendering opacity transfer function Gaussian
789-
parameters. For each image component, multiple Gaussians can be
790-
specified. Queue the function to be run in the background thread once
787+
def set_image_piecewise_function_points(self, points: Points2d) -> None:
788+
"""Set the volume rendering opacity transfer function points.
789+
Queue the function to be run in the background thread once
791790
the plugin API is available.
792791
793-
:param gaussians: Opacity transfer function Gaussian
794-
parameters. Default Gaussian parameters:
795-
{'position': 0.5, 'height': 1, 'width': 0.5, 'xBias': 0.51, 'yBias': 0.4}
796-
:type gaussians: Gaussians
792+
:param points: Opacity piecewise transfer function points. Example args: [[.2, .1], [.8, .9]]
793+
:type points2d: Points2d
797794
"""
798-
self.queue_request('setImagePiecewiseFunctionGaussians', gaussians)
795+
self.queue_request('setImagePiecewiseFunctionPoints', points)
799796
@fetch_value
800-
async def get_image_piecewise_function_gaussians(
797+
async def get_image_piecewise_function_points(
801798
self,
802-
) -> asyncio.Future | Gaussians:
803-
"""Get the volume rendering opacity transfer function Gaussian
804-
parameters.
799+
) -> asyncio.Future | Points2d:
800+
"""Get the volume rendering opacity transfer function points.
805801
806802
:return: The future for the coroutine, to be updated with the opacity
807-
transfer function Gaussian parameters.
808-
:rtype: asyncio.Future | Gaussians
803+
transfer function points.
804+
:rtype: asyncio.Future | Points2d
809805
"""
810-
return await self.viewer_rpc.itk_viewer.getImagePiecewiseFunctionGaussians()
806+
return await self.viewer_rpc.itk_viewer.getImagePiecewiseFunctionPoints()
811807

812808
@fetch_value
813809
def set_image_shadow_enabled(self, enabled: bool) -> None:
@@ -1500,8 +1496,8 @@ def view(data=None, **kwargs):
15001496
:param gradient_opacity_scale: Gradient opacity scale for composite volume rendering, in the range (0.0, 1.0]. default: 0.5
15011497
:type gradient_opacity_scale: float
15021498
1503-
:param gaussians: Volume rendering opacity transfer function Gaussian parameters. For each image component, multiple Gaussians can be specified. Default Gaussian parameters: {'position': 0.5, 'height': 1, 'width': 0.5, 'xBias': 0.51, 'yBias': 0.4}
1504-
:type gaussians: dict
1499+
:param piecewise_function_points: Volume rendering opacity transfer function parameters. Example points arg: [[.2, .1], [.8, .9]]
1500+
:type piecewise_function_points: list
15051501
15061502
:param blend_mode: Volume rendering blend mode. Supported modes: 'Composite', 'Maximum', 'Minimum', 'Average'. default: 'Composite'
15071503
:type blend_mode: string

itkwidgets/viewer_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ITK_VIEWER_SRC = (
2-
"https://bafybeifqmoui4r4jpdo6sqpxvnjujh4hgygp4vr34qinuwi4uqayflq6xm.on.fleek.co/"
2+
"https://bafybeieiqiiwvdq66e2bndws5nwojbe4wwerbxyua6u37axxivi2rwf7wy.on.fleek.co/"
33
)
44
PYDATA_SPHINX_HREF = "https://cdn.jsdelivr.net/npm/[email protected]/dist/bootstrapUIMachineOptions.js.es.js"
55
MUI_HREF = "https://cdn.jsdelivr.net/npm/[email protected]/dist/materialUIMachineOptions.js.es.js"

0 commit comments

Comments
 (0)