def render_func(viewer, start_frame, end_frame):
        with lock:
            saver = neuroglancer.ScreenshotSaver(viewer, args.output_directory)
        for i in range(len(keypoints) - 1):
            a = keypoints[i]['state']
            b = keypoints[i + 1]['state']
            duration = keypoints[i]['transition_duration']
            num_frames = max(1, int(duration * fps))
            for frame_i in range(num_frames):
                t = frame_i / num_frames
                index, path = saver.get_next_path()
                if index >= end_frame:
                    return

                if index < start_frame:
                    saver.index += 1
                    continue

                if args.resume and os.path.exists(path):
                    saver.index += 1
                    with lock:
                        num_frames_written[0] += 1
                else:
                    cur_state = neuroglancer.ViewerState.interpolate(a, b, t)
                    viewer.set_state(cur_state)
                    index, path = saver.capture()
                    with lock:
                        num_frames_written[0] += 1
                        cur_num_frames_written = num_frames_written[0]
                        print('[%07d/%07d] keypoint %.3f/%5d: %s' %
                              (cur_num_frames_written, total_frames, i + t,
                               len(keypoints), path))
Exemple #2
0
def run_render(args):
    keypoints = load_script(args.script)
    viewer = neuroglancer.Viewer()
    print('Open the specified URL to begin rendering')
    print(viewer)
    if args.browser:
        webbrowser.open_new(viewer.get_viewer_url())
    fps = args.fps
    with viewer.config_state.txn() as s:
        s.show_ui_controls = False
        s.show_panel_borders = False
        s.viewer_size = [args.width, args.height]
    saver = neuroglancer.ScreenshotSaver(viewer, args.output_directory)
    total_frames = sum(max(1, k['transition_duration'] * fps) for k in keypoints[:-1])
    for i in range(len(keypoints) - 1):
        a = keypoints[i]['state']
        b = keypoints[i + 1]['state']
        duration = keypoints[i]['transition_duration']
        num_frames = max(1, int(duration * fps))
        for frame_i in range(num_frames):
            t = frame_i / num_frames
            cur_state = neuroglancer.ViewerState.interpolate(a, b, t)
            viewer.set_state(cur_state)
            index, path = saver.capture()
            print('[%07d/%07d] keypoint %.3f/%5d: %s' % (index, total_frames, i + t, len(keypoints), path))
Exemple #3
0
    def render_func(viewer, start_frame, end_frame):
        with lock:
            saver = neuroglancer.ScreenshotSaver(viewer, args.output_directory)
        states_to_capture = []
        frame_number = 0
        for i in range(len(keypoints) - 1):
            a = keypoints[i]['state']
            b = keypoints[i + 1]['state']
            duration = keypoints[i]['transition_duration']
            num_frames = max(1, int(duration * fps))
            for frame_i in range(num_frames):
                t = frame_i / num_frames
                if frame_number >= end_frame:
                    return

                if frame_number < start_frame:
                    frame_number += 1
                    continue

                path = saver.get_path(frame_number)

                if args.resume and os.path.exists(path):
                    frame_number += 1
                    with lock:
                        num_frames_written[0] += 1
                else:
                    cur_state = neuroglancer.ViewerState.interpolate(a, b, t)
                    states_to_capture.append((frame_number, i + t, cur_state))
                    frame_number += 1
        for frame_number, t, cur_state in states_to_capture:
            prefetch_states = [
                x[2] for x in states_to_capture[frame_number + 1:frame_number +
                                                1 + num_prefetch_frames]
            ]
            prev_state = viewer.state.to_json()
            cur_state = cur_state.to_json()
            cur_state['layers'] = prev_state['layers']
            cur_state = neuroglancer.ViewerState(cur_state)
            viewer.set_state(cur_state)
            if num_prefetch_frames > 0:
                with viewer.config_state.txn() as s:
                    del s.prefetch[:]
                    for i, state in enumerate(prefetch_states[1:]):
                        s.prefetch.append(
                            neuroglancer.PrefetchState(
                                state=state, priority=num_prefetch_frames - i))
            frame_number, path = saver.capture(frame_number)
            with lock:
                num_frames_written[0] += 1
                cur_num_frames_written = num_frames_written[0]
                print('[%07d/%07d] keypoint %.3f/%5d: %s' %
                      (cur_num_frames_written, total_frames, t, len(keypoints),
                       path))
    s.layers["%s_atlas" % brainname] = neuroglancer.SegmentationLayer(
        source="precomputed://http://localhost:%s" % int(port + 1))
print(viewer)
#this should add the atlas volume to the neuroglancer window

###WINDOW 3###
#take screenshots
#NOTE: THIS DOESN'T WORK IN A SPYDER, CONSOLE, ACTIVATE ENV AND RUN IN IPYTHON SHELL
import os

svdst = "/home/wanglab/Desktop/%s/cortex_wo_overlay_zoom " % brainname
#make sure these directories exist
if not os.path.exists(os.path.dirname(svdst)):
    os.mkdir(os.path.dirname(svdst))  #brain directory
if not os.path.exists(svdst): os.mkdir(svdst)  #structure directory
ss = neuroglancer.ScreenshotSaver(viewer, svdst)
with viewer.config_state.txn() as s:
    s.show_ui_controls = False
    s.show_panel_borders = False
for i in range(2700, 4000, 30):
    if i % 10 == 0: print(i)
    with viewer.txn() as s:
        s.voxel_coordinates = [
            1787, i, 442
        ]  #the xy coords here are from the neuroglancer window
        #(where the L center scale is located)
    #optionally limit window size
#    with viewer.config_state.txn() as s:
#        s.viewer_size = [1000,1000]
    ss.capture(index=i)