Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add default opacity to 1 and blend to additive (CC-165) #27

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions cryoet_data_portal_neuroglancer/models/json_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,16 @@ class ImageJSONGenerator(RenderingJSONGenerator):
volume_rendering_is_visible: bool = False
volume_rendering_gain: float = 0.0
can_hide_high_values_in_neuroglancer: bool = False
blend: str = "additive"
opacity: float = 1.0

def __post_init__(self):
self._type = RenderingTypes.IMAGE

def _compute_contrast_limits(self) -> tuple[float, float]:
if self.mean is None or self.rms is None:
return self.contrast_limits
# return self.contrast_limits
return (0.0, 1.0)
width = 3 * self.rms
return (self.mean - width, self.mean + width)

Expand All @@ -140,7 +143,7 @@ def _create_shader_and_controls(self) -> dict[str, Any]:
else:
shader_builder = ImageShaderBuilder(
contrast_limits=self.contrast_limits,
can_hide_high_values_in_neuroglancer=self.can_hide_high_values_in_neuroglancer,
# can_hide_high_values_in_neuroglancer=self.can_hide_high_values_in_neuroglancer,
)
return shader_builder.build()

Expand All @@ -159,7 +162,8 @@ def generate_json(self) -> dict:
"type": self.layer_type,
"name": self.name,
"source": create_source(f"zarr://{self.source}", self.scale, self.scale),
"opacity": 0.51,
"opacity": self.opacity,
"blend": self.blend,
"tab": "rendering",
"visible": self.is_visible,
"volumeRendering": "on" if self.volume_rendering_is_visible else "off",
Expand Down Expand Up @@ -268,6 +272,8 @@ class ImageVolumeJSONGenerator(RenderingJSONGenerator):

color: str
rendering_depth: int
blend: str = "additive"
opacity: float = 1.0

def __post_init__(self):
self._type = RenderingTypes.IMAGE
Expand All @@ -291,7 +297,8 @@ def generate_json(self) -> dict:
"name": f"{self.name}",
"source": create_source(f"zarr://{self.source}", self.scale, self.scale),
"tab": "rendering",
"blend": "additive",
"blend": self.blend,
"opacity": self.opacity,
"volumeRendering": "on",
"volumeRenderingDepthSamples": self.rendering_depth,
"visible": self.is_visible,
Expand Down
8 changes: 8 additions & 0 deletions cryoet_data_portal_neuroglancer/state_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ def generate_image_layer(
volume_rendering_is_visible: bool = False,
volume_rendering_gain: float = -7.8,
can_hide_high_values_in_neuroglancer: bool | None = None,
blend: str = "additive",
opacity: float = 1.0,
) -> dict[str, Any]:
"""Generates JSON for an image layer with optional contrast limits.

Expand All @@ -211,6 +213,8 @@ def generate_image_layer(
volume_rendering_is_visible=volume_rendering_is_visible,
volume_rendering_gain=volume_rendering_gain,
can_hide_high_values_in_neuroglancer=can_hide_high_values_in_neuroglancer,
blend=blend,
opacity=opacity,
).to_json()


Expand All @@ -222,6 +226,8 @@ def generate_image_volume_layer(
scale: tuple[float, float, float] | list[float] | float = (1.0, 1.0, 1.0),
is_visible: bool = True,
rendering_depth: int = 1024,
blend: str = "additive",
opacity: float = 1.0,
) -> dict[str, Any]:
source, name, url, _, scale = _setup_creation(source, name, url, scale=scale)
_validate_color(color)
Expand All @@ -232,6 +238,8 @@ def generate_image_volume_layer(
scale=scale,
is_visible=is_visible,
rendering_depth=rendering_depth,
blend=blend,
opacity=opacity,
).to_json()


Expand Down
9 changes: 9 additions & 0 deletions tests/test_state_generators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from cryoet_data_portal_neuroglancer.state_generator import generate_image_layer


def test__generate_image_layer_default_values():
state = generate_image_layer(source="mysource", scale=1.5, size={"a": 2.0})

assert "blend" in state
assert state["blend"] == "additive"
assert state["opacity"] == 1.0
Loading