Skip to content

Commit

Permalink
fix: revert changs to ImageVolumeJSONGenerator and associated state
Browse files Browse the repository at this point in the history
  • Loading branch information
seankmartin committed Jun 26, 2024
1 parent 2152cdc commit e122031
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
20 changes: 12 additions & 8 deletions cryoet_data_portal_neuroglancer/models/json_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,20 +191,24 @@ def generate_json(self) -> dict:
class ImageVolumeJSONGenerator(RenderingJSONGenerator):
"""Generates JSON Neuroglancer config for volume rendering."""

rendering_depth: int # Ideally, this should be a power of 2
contrast_limits: tuple[float, float] = (-64, 64)
threedee_contrast_limits: tuple[float, float] = (-64, 64)
is_visible: bool = True
color: str
rendering_depth: int

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

def _get_shader(self) -> dict[str, Any]:
shader_builder = ImageShaderBuilder(
contrast_limits=self.contrast_limits,
threedee_contrast_limits=self.threedee_contrast_limits,
shader = (
f'#uicontrol vec3 color color(default="{self.color}")\n'
f"#uicontrol invlerp toRaw(range=[0, 1], window=[-1, 2])\n"
f"void main() {{\n"
f" emitRGBA(vec4(color * toRaw(getDataValue()), toRaw(getDataValue())));\n"
f"}}"
)
return shader_builder.build_shader()
return {
"shader": shader,
"shaderControls": {"color": self.color},
}

def generate_json(self) -> dict:
return {
Expand Down
3 changes: 3 additions & 0 deletions cryoet_data_portal_neuroglancer/state_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,17 @@ def generate_image_volume_layer(
source: str,
name: str = None,
url: str = None,
color: str = "#FFFFFF",
scale: tuple[float, float, float] = (1.0, 1.0, 1.0),
is_visible: bool = True,
rendering_depth: int = 1024,
) -> dict[str, Any]:
source, name, url, _, scale = _setup_creation(source, name, url, scale=scale)
_validate_color(color)
return ImageVolumeJSONGenerator(
source=source,
name=name,
color=color,
scale=scale,
is_visible=is_visible,
rendering_depth=rendering_depth,
Expand Down

0 comments on commit e122031

Please sign in to comment.