diff --git a/glue_ar/__init__.py b/glue_ar/__init__.py index 8b361d1..40e1aa0 100644 --- a/glue_ar/__init__.py +++ b/glue_ar/__init__.py @@ -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"] diff --git a/glue_ar/scatter.py b/glue_ar/scatter.py index eae57a5..57110e8 100644 --- a/glue_ar/scatter.py +++ b/glue_ar/scatter.py @@ -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(), diff --git a/glue_ar/tools.py b/glue_ar/tools.py index ea859f3..0507c5d 100644 --- a/glue_ar/tools.py +++ b/glue_ar/tools.py @@ -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")) @@ -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") diff --git a/glue_ar/volume.py b/glue_ar/volume.py index bd01d6a..ba7fa1f 100644 --- a/glue_ar/volume.py +++ b/glue_ar/volume.py @@ -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 = {} @@ -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