|
| 1 | +# @license |
| 2 | +# Copyright 2020 Google Inc. |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import neuroglancer |
| 16 | +import numpy as np |
| 17 | + |
| 18 | +from neuroglancer_utils.layer_utils import add_render_panel |
| 19 | +from neuroglancer_utils.viewer_utils import ( |
| 20 | + launch_nglancer, |
| 21 | + open_browser, |
| 22 | + remove_axis_lines, |
| 23 | + set_gpu_memory, |
| 24 | + threedee_view, |
| 25 | + update_projection, |
| 26 | + update_title, |
| 27 | +) |
| 28 | + |
| 29 | + |
| 30 | +def add_image_layer(state, **kwargs): |
| 31 | + dimensions = neuroglancer.CoordinateSpace( |
| 32 | + names=["x", "y", "z", "qudfa", "energy", "distance", "time", "mass"], |
| 33 | + units=("nm", "um", "", "s", "Hz", "m", "kHz", "us"), |
| 34 | + scales=(4, 8, 2.4, 0.5, 1000, 10.5, 19.2, 0.0002), |
| 35 | + ) |
| 36 | + generator = np.random.default_rng(0) |
| 37 | + data = generator.random((20, 55, 10, 100, 10, 5, 2, 10)) |
| 38 | + local_volume = neuroglancer.LocalVolume(data, dimensions) |
| 39 | + state.layers["image"] = neuroglancer.ImageLayer( |
| 40 | + source=local_volume, |
| 41 | + volume_rendering_mode="max", |
| 42 | + tool_bindings={ |
| 43 | + "A": neuroglancer.VolumeRenderingGainTool(), |
| 44 | + }, |
| 45 | + panels=[add_render_panel(side="right")], |
| 46 | + **kwargs, |
| 47 | + ) |
| 48 | + |
| 49 | + |
| 50 | +def get_shader(): |
| 51 | + return """#uicontrol invlerp normalized(range=[0,255], clamp=true) |
| 52 | +void main() { |
| 53 | + float val = normalized(); |
| 54 | + emitGrayscale(val); |
| 55 | +} |
| 56 | +""" |
| 57 | + |
| 58 | + |
| 59 | +if __name__ == "__main__": |
| 60 | + viewer = launch_nglancer() |
| 61 | + with viewer.txn() as s: |
| 62 | + add_image_layer(s, shader=get_shader()) |
| 63 | + threedee_view(viewer) |
| 64 | + remove_axis_lines(viewer) |
| 65 | + update_title(viewer, "Large example") |
| 66 | + set_gpu_memory(viewer, gpu_memory=2) |
| 67 | + update_projection(viewer, orientation=[0.25, 0.6, 0.65, 0.3]) |
| 68 | + open_browser(viewer, hang=True) |
0 commit comments