Skip to content

Commit

Permalink
Clean up a few minor issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
Carifio24 committed Dec 18, 2023
1 parent 77cb93d commit 84cd81c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 22 deletions.
6 changes: 3 additions & 3 deletions glue_ar/export_volume.ui
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="valuetext_smoothing_terations"/>
<widget class="QLineEdit" name="valuetext_smoothing_iterations"/>
</item>
</layout>
</widget>
Expand All @@ -80,14 +80,14 @@
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<widget class="QPushButton" name="button_cancel">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_2">
<widget class="QPushButton" name="button_ok">
<property name="text">
<string>Export</string>
</property>
Expand Down
37 changes: 29 additions & 8 deletions glue_ar/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from glue.viewers.common.tool import Tool

from glue_ar.export_scatter import ExportScatterDialog
from glue_ar.export_volume import ExportVolumeDialog
from glue_ar.scatter import scatter_layer_as_multiblock
from glue_ar.export import export_gl, export_modelviewer
from glue_ar.volume import create_meshes
Expand All @@ -36,7 +37,7 @@ def activate(self):
if result == QDialog.Rejected:
return

export_path, _ = compat.getsavefilename(parent=self.viewer, basedir=f"scatter.{dialog.state.filetype}".lower())
export_path, _ = compat.getsavefilename(parent=self.viewer, basedir=f"scatter.{dialog.state.filetype.lower()}")
if not export_path:
return

Expand All @@ -49,11 +50,13 @@ def activate(self):
plotter.add_mesh(data, **mesh_info)

dir, base = split(export_path)
name, _ = splitext(base)
name, ext = splitext(base)
html_path = join(dir, f"{name}.html")
export_gl(plotter, export_path, with_alpha=True)

export_modelviewer(html_path, base, "Testing visualization")
if ext:
export_gl(plotter, export_path, with_alpha=True)
export_modelviewer(html_path, base, "Testing visualization")
else:
plotter.export_obj(export_path)


@viewer_tool
Expand All @@ -64,10 +67,28 @@ class GLVolumeExportTool(Tool):
tool_tip = "Export the current view to a glB file"

def activate(self):

dialog = ExportVolumeDialog(parent=self.viewer, viewer_state=self.viewer.state)
result = dialog.exec_()
if result == QDialog.Rejected:
return

export_path, _ = compat.getsavefilename(parent=self.viewer, basedir=f"volume.{dialog.state.filetype.lower()}")
if not export_path:
return

plotter = pv.Plotter()
meshes = create_meshes(self.viewer.state, use_gaussian_filter=True, smoothing_iteration_count=10)
layer_states = [state for state in self.viewer.state.layers if state.visible]
meshes = create_meshes(self.viewer.state, layer_states, dialog.info_dictionary)
for data in meshes.values():
mesh = data.pop("mesh")
plotter.add_mesh(mesh, color=data["color"], opacity=data["opacity"])
export_gl(plotter, "volume.gltf", with_alpha=True) # Do we want alpha for volume renderings?
export_modelviewer("volume.html", "volume.gltf", "Testing visualization")

dir, base = split(export_path)
name, ext = splitext(base)
html_path = join(dir, f"{name}.html")
if ext == 'glTF':
export_gl(plotter, export_path, with_alpha=True) # Do we want alpha for volume renderings?
export_modelviewer(html_path, base, "Testing visualization")
else:
plotter.export_obj(export_path)
23 changes: 12 additions & 11 deletions glue_ar/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# For the 3D volume viewer
# This is largely lifted from Luca's plugin
def create_meshes(viewer_state, layer_states=None, use_gaussian_filter=False, smoothing_iteration_count=0):
def create_meshes(viewer_state, layer_states, parameters):

meshes = {}

Expand All @@ -28,7 +28,7 @@ def create_meshes(viewer_state, layer_states=None, use_gaussian_filter=False, sm
target_cid=layer_state.attribute
)

meshes[layer_state.layer.uuid] = {
meshes[layer_state.layer.label] = {
"data": data,
"color": layer_color(layer_state),
"opacity": layer_state.alpha,
Expand All @@ -46,10 +46,10 @@ def create_meshes(viewer_state, layer_states=None, use_gaussian_filter=False, sm
subset_state=layer_state.layer.subset_state
)

datacube = meshes[parent.uuid]["data"]
datacube = meshes[parent.label]["data"]
data = subcube * datacube

meshes[layer_state.layer.uuid] = {
meshes[layer_state.layer.label] = {
"data": data,
"isomin": isomin_for_layer(viewer_state, layer_state),
"opacity": layer_state.alpha,
Expand All @@ -58,17 +58,17 @@ def create_meshes(viewer_state, layer_states=None, use_gaussian_filter=False, sm
}

# Delete sublayer data from parent data
if parent.uuid in meshes:
parent_data = meshes[parent.uuid]["data"]
if parent.label in meshes:
parent_data = meshes[parent.label]["data"]
parent_data = invert(subcube) * parent_data
meshes[parent.uuid]["data"] = parent_data
meshes[parent.label]["data"] = parent_data


for item in meshes.values():
for label, item in meshes.items():
data = item["data"]
isomin = item["isomin"]

if use_gaussian_filter:
if parameters[label]["gaussian_filter"]:
data = gaussian_filter(data, 1)

# Conventions between pyvista and glue data storage
Expand All @@ -82,8 +82,9 @@ def create_meshes(viewer_state, layer_states=None, use_gaussian_filter=False, sm
grid.point_data["values"] = data.flatten(order="F")
isodata = grid.contour([isomin])

if smoothing_iteration_count > 0:
isodata = isodata.smooth(n_iter=smoothing_iteration_count)
iterations = parameters[label]["smoothing_iterations"]
if iterations > 0:
isodata = isodata.smooth(n_iter=iterations)

item["mesh"] = isodata

Expand Down

0 comments on commit 84cd81c

Please sign in to comment.