Created
August 3, 2017 21:23
-
-
Save matthewturk/3f9edcc6dbd61748ef953208a4e502bf to your computer and use it in GitHub Desktop.
Example IDV experimentation script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import OpenGL | |
#OpenGL.ERROR_LOGGING = True | |
#OpenGL.FULL_LOGGING = True | |
import yt | |
import time | |
import yt.visualization.volume_rendering.interactive_vr as ivr | |
from yt.visualization.volume_rendering.interactive_loop import \ | |
RenderingContext | |
import h5py | |
import numpy as np | |
from yt.visualization.volume_rendering import glfw_inputhook | |
@yt.derived_field("inv_radius", units="1.0/code_length**2") | |
def inv_radius(field, data): | |
d2 = sum((data[ax] - data.ds.domain_center[i])**2.0 for | |
i, ax in enumerate('xyz')) | |
inv_r2 = 1.0/d2 | |
np.clip(inv_r2, 0.0, 100.0, inv_r2) | |
return inv_r2 | |
ds = yt.testing.fake_amr_ds(["density"]) | |
rc = RenderingContext(960, 960, always_on_top = True) | |
# Create a 3d Texture from all_data() | |
dd = ds.all_data() | |
dd.set_field_parameter("center", ds.domain_center) | |
#dd.max_level = 3 | |
collection = ivr.BlockCollection(data_source = dd) | |
collection.add_data("inv_radius") | |
br = ivr.BlockRendering(data = collection, | |
vertex_shader = "default", | |
fragment_shader = "max_intensity", | |
colormap_vertex = "passthrough", | |
colormap_fragment = "apply_colormap") | |
bo = ivr.BlockRendering(data = collection, | |
vertex_shader = "default", | |
fragment_shader = "drawlines", | |
colormap_vertex = "passthrough", | |
colormap_fragment = "passthrough") | |
scene = ivr.SceneGraph() | |
scene.data_objects.append(collection) | |
#scene.components.append(bo) | |
scene.components.append(br) | |
characters = ivr.TextCharacters() | |
characters.build_textures() | |
scene.data_objects.append(characters) | |
tr = ivr.TextAnnotation(text = "Hi there", data = characters, | |
vertex_shader = "text_overlay", | |
fragment_shader = "text_overlay", | |
colormap_vertex = "passthrough", | |
colormap_fragment = "passthrough") | |
scene.annotations.append(tr) | |
#scene.annotations.append(bo) | |
# Create default camera | |
position = (0.0, 0.0, 0.0) | |
c = ivr.TrackballCamera(position=position, | |
focus=ds.domain_center, near_plane=0.1) | |
scene.camera = c | |
# Start rendering loop | |
shell = rc.start_shell(scene, c) | |
shell() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment