# Path: biobeam/beam_gui/volbeam.py
# def volbeam(dn=None, size=None,
#             simul_xy=None,
#             simul_z=None,
#             blocking=False,
#             raise_window=True):
#     if dn is None and size is None:
#         dn = np.zeros((256,)*3, np.float32)
#         dn[0, 0, 0] = 0.0000001
#         size = (200,)*3
#         simul_xy = (512,)*2
#         simul_z = 2
# 
#     app = getCurrentApp()
# 
#     window = BeamGui(dn=dn.astype(np.float32),
#                      size=size,
#                      simul_xy=simul_xy,
#                      simul_z=simul_z)
# 
#     window.show()
# 
#     window.propagate()
#     if raise_window:
#         window.raise_()
# 
#     if blocking:
#         getCurrentApp().exec_()
#     else:
#         return window


import numpy as np
import os
from biobeam.beam_gui.volbeam import volbeam
    from gputools import perlin3
    from tifffile import imread, imsave

from __future__ import print_function, unicode_literals, absolute_import, division



def get_volume(N=256):

    fname = "data/dn_%s.tif"%N
    if os.path.exists(fname):
        return imread(fname)



    print("creating volume...")

    _x = np.linspace(-1,1,N)
    R = np.sqrt(np.sum([_X**2 for _X in np.meshgrid(_x,_x,_x,indexing = "ij")],axis =0))

    dn = .05*(R<.2)
    dn += .01*perlin3((N,)*3, scale = 4)

    print("... done")
    imsave(fname, dn)

    return dn


if __name__=='__main__':
    dn = get_volume(512)


# Path: biobeam/beam_gui/volbeam.py
# def volbeam(dn=None, size=None,
#             simul_xy=None,
#             simul_z=None,
#             blocking=False,
#             raise_window=True):
#     if dn is None and size is None:
#         dn = np.zeros((256,)*3, np.float32)
#         dn[0, 0, 0] = 0.0000001
#         size = (200,)*3
#         simul_xy = (512,)*2
#         simul_z = 2
# 
#     app = getCurrentApp()
# 
#     window = BeamGui(dn=dn.astype(np.float32),
#                      size=size,
#                      simul_xy=simul_xy,
#                      simul_z=simul_z)
# 
#     window.show()
# 
#     window.propagate()
#     if raise_window:
#         window.raise_()
# 
#     if blocking:
#         getCurrentApp().exec_()
#     else:
#         return window


# Path: tests/volbeam/test_volbeam.py
import numpy as np
import os
from biobeam.beam_gui.volbeam import volbeam
    from gputools import perlin3
    from tifffile import imread, imsave


from __future__ import print_function, unicode_literals, absolute_import, division



def get_volume(N=256):

    fname = "data/dn_%s.tif"%N
    if os.path.exists(fname):
        return imread(fname)



    print("creating volume...")

    _x = np.linspace(-1,1,N)
    R = np.sqrt(np.sum([_X**2 for _X in np.meshgrid(_x,_x,_x,indexing = "ij")],axis =0))

    dn = .05*(R<.2)
    dn += .01*perlin3((N,)*3, scale = 4)

    print("... done")
    imsave(fname, dn)

    return dn


if __name__=='__main__':
    dn = get_volume(512)


    volbeam(dn, size=(100,)*3, blocking = True)