# Path: spimagine/gui/volshow.py
# def volshow(data, autoscale=True,
#             stackUnits=[1., 1., 1.],
#             blocking=False,
#             cmap=None,
#             interpolation="linear",
#             show_window = True,
#             raise_window=True):
#     """
#     class to visualize 3d/4d data
# 
#     data can be
# 
#     - a 3d/4d numpy array of dimensions (z,y,x) or (t,z,y,x)
# 
#       e.g.
# 
#         volshow( randint(0,10,(10, 20,30,40) )
# 
# 
#     - an instance of a class derived from the abstract bass class GenericData
# 
#       e.g.
# 
#     from spimagine import GenericData
# 
#     class myData(GenericData):
#         def __getitem__(self,i):
#             return (100*i+3)*np.ones((100,100,100))
#         def size(self):
#             return (4,100,100,100)
# 
#     volshow(myData())
# 
#         or
# 
#     from spimagine import DataModel
# 
#     volshow(DataModel(dataContainer=myData(), prefetchSize= 5)
# 
# 
# 
# 
#     Parameters
#     ----------
#     data: ndarray
#         the volumetric data to render, 3d or 4d
# 
#     autoscale: boolean
#         autoscales the data
# 
#     stackUnits: tuple
#         the voxel dimensions (dx, dy, dz)
# 
#     blocking: boolean
#         if true, starts the qt event loop and waits till finished
#         (use this e.g. when running from outside ipython)
# 
#     cmap: str
#         the colormap to use
#         available colormaps: cmap = ["viridis", "coolwarm","jet","hot","grays"]
#         if None, then the default one is used
# 
#     interpolation: str
#         the interpolation used for rendering/slice views
#         "linear" or "nearest"
# 
#     raise_window: boolean
#         if true, raises the window
# 
#     Returns
#     -------
#         the widget w
# 
#     """
# 
#     logger.debug("volshow")
# 
#     logger.debug("volshow: getCurrentApp")
# 
#     app = getCurrentApp()
# 
#     from time import time
# 
#     t = time()
# 
#     # if isinstance(data,GenericData):
#     if isinstance(data, DataModel):
#         m = data
#     elif hasattr(data, "stackUnits"):
#         m = DataModel(data)
#     else:
#         if not isinstance(data, np.ndarray):
#             data = np.array(data)
#         if autoscale:
#             data = _rescale(data, 10000,0)
# 
#         if not data.dtype.type in VolumeRenderer.dtypes:
#             data = data.astype(np.float32, copy=False)
# 
#         m = DataModel(NumpyData(data))
# 
#     logger.debug("create model: %s s " % (time() - t))
#     t = time()
# 
#     # check whether there are already open windows, if not create one
#     try:
#         num, window = [(n, w) for n, w in six.iteritems(app.volfigs)][-1]
#     except:
#         num = 1
# 
#     window = volfig(num, interpolation=interpolation)
#     logger.debug("volfig: %s s " % (time() - t))
#     t = time()
# 
#     window.setModel(m)
# 
#     logger.debug("set model: %s s" % (time() - t));
# 
#     if cmap is None or cmap not in spimagine.config.__COLORMAPDICT__:
#         cmap = spimagine.config.__DEFAULTCOLORMAP__
# 
#     window.glWidget.set_colormap(cmap)
# 
#     window.glWidget.transform.setStackUnits(*stackUnits)
# 
#     if show_window:
#         window.show()
# 
#     if raise_window:
#         window.raise_window()
# 
#     if blocking:
#         getCurrentApp().exec_()
#     else:
#         return window


import numpy as np
import matplotlib
import OpenGL.GL as GL
from matplotlib.pyplot import cm
from spimagine import volshow
matplotlib.use("Qt5Agg")



if __name__ == '__main__':

    data = np.einsum("ij,k",np.ones((100,)*2), np.linspace(0,1,100))
    w = volshow(data)

# Path: spimagine/gui/volshow.py
# def volshow(data, autoscale=True,
#             stackUnits=[1., 1., 1.],
#             blocking=False,
#             cmap=None,
#             interpolation="linear",
#             show_window = True,
#             raise_window=True):
#     """
#     class to visualize 3d/4d data
# 
#     data can be
# 
#     - a 3d/4d numpy array of dimensions (z,y,x) or (t,z,y,x)
# 
#       e.g.
# 
#         volshow( randint(0,10,(10, 20,30,40) )
# 
# 
#     - an instance of a class derived from the abstract bass class GenericData
# 
#       e.g.
# 
#     from spimagine import GenericData
# 
#     class myData(GenericData):
#         def __getitem__(self,i):
#             return (100*i+3)*np.ones((100,100,100))
#         def size(self):
#             return (4,100,100,100)
# 
#     volshow(myData())
# 
#         or
# 
#     from spimagine import DataModel
# 
#     volshow(DataModel(dataContainer=myData(), prefetchSize= 5)
# 
# 
# 
# 
#     Parameters
#     ----------
#     data: ndarray
#         the volumetric data to render, 3d or 4d
# 
#     autoscale: boolean
#         autoscales the data
# 
#     stackUnits: tuple
#         the voxel dimensions (dx, dy, dz)
# 
#     blocking: boolean
#         if true, starts the qt event loop and waits till finished
#         (use this e.g. when running from outside ipython)
# 
#     cmap: str
#         the colormap to use
#         available colormaps: cmap = ["viridis", "coolwarm","jet","hot","grays"]
#         if None, then the default one is used
# 
#     interpolation: str
#         the interpolation used for rendering/slice views
#         "linear" or "nearest"
# 
#     raise_window: boolean
#         if true, raises the window
# 
#     Returns
#     -------
#         the widget w
# 
#     """
# 
#     logger.debug("volshow")
# 
#     logger.debug("volshow: getCurrentApp")
# 
#     app = getCurrentApp()
# 
#     from time import time
# 
#     t = time()
# 
#     # if isinstance(data,GenericData):
#     if isinstance(data, DataModel):
#         m = data
#     elif hasattr(data, "stackUnits"):
#         m = DataModel(data)
#     else:
#         if not isinstance(data, np.ndarray):
#             data = np.array(data)
#         if autoscale:
#             data = _rescale(data, 10000,0)
# 
#         if not data.dtype.type in VolumeRenderer.dtypes:
#             data = data.astype(np.float32, copy=False)
# 
#         m = DataModel(NumpyData(data))
# 
#     logger.debug("create model: %s s " % (time() - t))
#     t = time()
# 
#     # check whether there are already open windows, if not create one
#     try:
#         num, window = [(n, w) for n, w in six.iteritems(app.volfigs)][-1]
#     except:
#         num = 1
# 
#     window = volfig(num, interpolation=interpolation)
#     logger.debug("volfig: %s s " % (time() - t))
#     t = time()
# 
#     window.setModel(m)
# 
#     logger.debug("set model: %s s" % (time() - t));
# 
#     if cmap is None or cmap not in spimagine.config.__COLORMAPDICT__:
#         cmap = spimagine.config.__DEFAULTCOLORMAP__
# 
#     window.glWidget.set_colormap(cmap)
# 
#     window.glWidget.transform.setStackUnits(*stackUnits)
# 
#     if show_window:
#         window.show()
# 
#     if raise_window:
#         window.raise_window()
# 
#     if blocking:
#         getCurrentApp().exec_()
#     else:
#         return window


# Path: tests/test_gui/test_bitdepth.py
import numpy as np
import matplotlib
import OpenGL.GL as GL
from matplotlib.pyplot import cm
from spimagine import volshow

matplotlib.use("Qt5Agg")



if __name__ == '__main__':

    data = np.einsum("ij,k",np.ones((100,)*2), np.linspace(0,1,100))
    w = volshow(data)

    w.glWidget._set_colormap_array(cm.hot(np.linspace(0,1,2**12))[:,:3])