Skip to content

Commit

Permalink
Add volume viewer tool.
Browse files Browse the repository at this point in the history
  • Loading branch information
Carifio24 committed Dec 6, 2023
1 parent 12b2a62 commit 35b6fa3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
5 changes: 4 additions & 1 deletion glue_ar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ def setup():
from glue_qt.config import qt_client

from glue_vispy_viewers.scatter.scatter_viewer import VispyScatterViewer
VispyScatterViewer.tools += ["ar:gltf"]
VispyScatterViewer.tools += ["ar:scatter-gl"]

from glue_vispy_viewers.volume.volume_viewer import VispyVolumeViewer
VispyVolumeViewer.tools += ["ar:volume-gl"]
2 changes: 1 addition & 1 deletion glue_ar/scatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def scatter_layer_as_glyphs(viewer_state, layer_state, glyph):

def scatter_layer_as_multiblock(viewer_state, layer_state):
data = xyz_for_layer(viewer_state, layer_state, scaled=True)
spheres = [pv.Sphere(center=p, radius=layer_state.size_scaling * layer_state.size / 600, phi_resolution=4, theta_resolution=4) for p in data]
spheres = [pv.Sphere(center=p, radius=layer_state.size_scaling * layer_state.size / 600, phi_resolution=10, theta_resolution=10) for p in data]
blocks = pv.MultiBlock(spheres)
return {
"data": blocks.extract_geometry(),
Expand Down
31 changes: 26 additions & 5 deletions glue_ar/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
from glue_ar.common import create_plotter
from glue_ar.scatter import scatter_layer_as_multiblock
from glue_ar.export import export_gl_with_alpha, export_modelviewer
from glue_ar.volume import create_meshes

__all__ = ["GLTFExportTool"]
__all__ = ["GLScatterExportTool", "GLVolumeExportTool"]

# This is just some placeholder image that I found online
AR_ICON = os.path.abspath(os.path.join(os.path.dirname(__file__), "ar"))
Expand All @@ -18,15 +19,35 @@
# No UI for now - that's easy to add once implementations are complete
# For now, this just exports to "test.gltf" and "test.html"
@viewer_tool
class GLTFExportTool(Tool):
class GLScatterExportTool(Tool):
icon = AR_ICON
tool_id = "ar:gltf"
action_text = "Export to glTF"
tool_tip = "Export the current view to a glTF fileb"
tool_id = "ar:scatter-gl"
action_text = "Export to gl"
tool_tip = "Export the current view to a glB file"

def activate(self):
plotter = create_plotter(pv.Plotter.add_mesh, scatter_layer_as_multiblock, self.viewer.state)

# output_filename = "test.obj"
# plotter.export_obj(output_filename)

output_filename = "test.glb"
export_gl_with_alpha(plotter, output_filename)

export_modelviewer("test.html", output_filename, "Testing visualization")


@viewer_tool
class GLVolumeExportTool(Tool):
icon = AR_ICON
tool_id = "ar:volume-gl"
action_text = "Export to gl"
tool_tip = "Export the current view to a glB file"

def activate(self):
plotter = pv.Plotter()
meshes = create_meshes(self.viewer.state, use_gaussian_filter=True, smoothing_iteration_count=0)
for data in meshes.values():
mesh = data.pop("mesh")
plotter.add_mesh(mesh, color=data["color"], opacity=data["opacity"])
plotter.export_obj("test.obj")
4 changes: 2 additions & 2 deletions glue_ar/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

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

meshes = {}

Expand Down Expand Up @@ -67,7 +67,7 @@ def create_meshes(viewer_state, layer_states=None, gaussian_filter=False, smooth
data = item["data"]
isomin = item["isomin"]

if gaussian_filter:
if use_gaussian_filter:
data = filters.gaussian_filters(data, 1)

# Conventions between pyvista and glue data storage
Expand Down

0 comments on commit 35b6fa3

Please sign in to comment.