Skip to content

Commit

Permalink
Merge pull request #755 from PaulHax/tf-points
Browse files Browse the repository at this point in the history
feat: add set_image_piecewise_function_points
  • Loading branch information
thewtex authored Jun 24, 2024
2 parents 9dce163 + 0ca6672 commit 420355e
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 54 deletions.
78 changes: 50 additions & 28 deletions examples/GettersAndSetters.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion itkwidgets/_initialization_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def init_params_dict(itk_viewer):
'gradient_opacity': itk_viewer.setImageGradientOpacity,
'gradient_opacity_scale': itk_viewer.setImageGradientOpacityScale,
'interpolation': itk_viewer.setImageInterpolationEnabled,
'gaussians': itk_viewer.setImagePiecewiseFunctionGaussians,
'transfer_function': itk_viewer.setImagePiecewiseFunctionPoints,
'shadow_enabled': itk_viewer.setImageShadowEnabled,
'sample_distance': itk_viewer.setImageVolumeSampleDistance,
'label_blend': itk_viewer.setLabelImageBlend,
Expand Down
4 changes: 2 additions & 2 deletions itkwidgets/_method_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def deferred_methods():
'setImageGradientOpacity',
'setImageGradientOpacityScale',
'setImageInterpolationEnabled',
'setImagePiecewiseFunctionGaussians',
'setImagePiecewiseFunctionPoints',
'setImageVolumeSampleDistance',
'setImageVolumeScatteringBlend',
'setLabelImageBlend',
Expand All @@ -30,7 +30,7 @@ def deferred_methods():
'getImageGradientOpacity',
'getImageGradientOpacityScale',
'getImageInterpolationEnabled',
'getImagePiecewiseFunctionGaussians',
'getImagePiecewiseFunctionPoints',
'getImageVolumeSampleDistance',
'getImageVolumeScatteringBlend',
'getLabelImageBlend',
Expand Down
5 changes: 2 additions & 3 deletions itkwidgets/_type_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
from .integrations.pytorch import HAVE_TORCH
from .integrations.vtk import HAVE_VTK
from .integrations.xarray import HAVE_XARRAY
from typing import Dict, List, Literal, Union
from typing import Dict, List, Literal, Union, Sequence

Gaussian_Curve = Dict[str, float]
Gaussians = Dict[str, List[Gaussian_Curve]]
Points2d = Sequence[Sequence[float]]

Style = Dict[str, str]

Expand Down
34 changes: 15 additions & 19 deletions itkwidgets/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import uuid

from ._method_types import deferred_methods
from ._type_aliases import Gaussians, Style, Image, PointSet, CroppingPlanes
from ._type_aliases import Style, Image, PointSet, CroppingPlanes, Points2d
from ._initialization_params import (
init_params_dict,
build_config,
Expand Down Expand Up @@ -784,30 +784,26 @@ async def get_image_interpolation_enabled(self) -> asyncio.Future | bool:
return await self.viewer_rpc.itk_viewer.getImageInterpolationEnabled()

@fetch_value
def set_image_piecewise_function_gaussians(self, gaussians: Gaussians) -> None:
"""Set the volume rendering opacity transfer function Gaussian
parameters. For each image component, multiple Gaussians can be
specified. Queue the function to be run in the background thread once
def set_image_piecewise_function_points(self, points: Points2d) -> None:
"""Set the volume rendering opacity transfer function points.
Queue the function to be run in the background thread once
the plugin API is available.
:param gaussians: Opacity transfer function Gaussian
parameters. Default Gaussian parameters:
{'position': 0.5, 'height': 1, 'width': 0.5, 'xBias': 0.51, 'yBias': 0.4}
:type gaussians: Gaussians
:param points: Opacity piecewise transfer function points. Example args: [[.2, .1], [.8, .9]]
:type points2d: Points2d
"""
self.queue_request('setImagePiecewiseFunctionGaussians', gaussians)
self.queue_request('setImagePiecewiseFunctionPoints', points)
@fetch_value
async def get_image_piecewise_function_gaussians(
async def get_image_piecewise_function_points(
self,
) -> asyncio.Future | Gaussians:
"""Get the volume rendering opacity transfer function Gaussian
parameters.
) -> asyncio.Future | Points2d:
"""Get the volume rendering opacity transfer function points.
:return: The future for the coroutine, to be updated with the opacity
transfer function Gaussian parameters.
:rtype: asyncio.Future | Gaussians
transfer function points.
:rtype: asyncio.Future | Points2d
"""
return await self.viewer_rpc.itk_viewer.getImagePiecewiseFunctionGaussians()
return await self.viewer_rpc.itk_viewer.getImagePiecewiseFunctionPoints()

@fetch_value
def set_image_shadow_enabled(self, enabled: bool) -> None:
Expand Down Expand Up @@ -1500,8 +1496,8 @@ def view(data=None, **kwargs):
:param gradient_opacity_scale: Gradient opacity scale for composite volume rendering, in the range (0.0, 1.0]. default: 0.5
:type gradient_opacity_scale: float
: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}
:type gaussians: dict
:param piecewise_function_points: Volume rendering opacity transfer function parameters. Example points arg: [[.2, .1], [.8, .9]]
:type piecewise_function_points: list
:param blend_mode: Volume rendering blend mode. Supported modes: 'Composite', 'Maximum', 'Minimum', 'Average'. default: 'Composite'
:type blend_mode: string
Expand Down
2 changes: 1 addition & 1 deletion itkwidgets/viewer_config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ITK_VIEWER_SRC = (
"https://bafybeifqmoui4r4jpdo6sqpxvnjujh4hgygp4vr34qinuwi4uqayflq6xm.on.fleek.co/"
"https://bafybeieiqiiwvdq66e2bndws5nwojbe4wwerbxyua6u37axxivi2rwf7wy.on.fleek.co/"
)
PYDATA_SPHINX_HREF = "https://cdn.jsdelivr.net/npm/[email protected]/dist/bootstrapUIMachineOptions.js.es.js"
MUI_HREF = "https://cdn.jsdelivr.net/npm/[email protected]/dist/materialUIMachineOptions.js.es.js"

0 comments on commit 420355e

Please sign in to comment.