Ejemplo n.º 1
0
    def __init__(self):
        super(MainWindow, self).__init__()

        self.resize(500, 40)
        self.setWindowTitle("Key Frame View")

        self.keyPanel = KeyFramePanel(None)

        dataModel = DataModel(dataContainer=DemoData(50), prefetchSize=0)
        transModel = TransformModel()
        transModel.setModel(dataModel)

        transModel.setValueScale(0, 200)
        dataModel.setPos(2)
        self.keyPanel.connect_to_transform(transModel)

        k = KeyFrameList()
        k.addItem(KeyFrame(0.))
        k.addItem(KeyFrame(1.))

        self.keyPanel.setModel(k)

        self.setCentralWidget(self.keyPanel)

        self.setStyleSheet("background-color:black;color:white")
Ejemplo n.º 2
0
    def __init__(self):
        super(MainWindow,self).__init__()

        self.resize(500, 40)
        self.setWindowTitle("Key Frame View")



        self.keyPanel = KeyFramePanel(None)

        dataModel = DataModel(dataContainer = DemoData(50),prefetchSize = 0)
        transModel = TransformModel()
        transModel.setModel(dataModel)

        transModel.setValueScale(0,200)
        dataModel.setPos(2)
        self.keyPanel.connect_to_transform(transModel)


        k = KeyFrameList()
        k.addItem(KeyFrame(0.))
        k.addItem(KeyFrame(1.))

        self.keyPanel.setModel(k)


        self.setCentralWidget(self.keyPanel)

        self.setStyleSheet("background-color:black;color:white")
Ejemplo n.º 3
0
    def openFile(self,e):
        # path = QtWidgets.QFileDialog.getOpenFileName(self, 'Open Path (File or Folder)',
        #                                              '.', selectedFilter='*.tif')


        f = QtWidgets.QFileDialog()
        f.setWindowTitle('Open Path (File or Folder)')
        f.setFileMode(QtWidgets.QFileDialog.ExistingFile & QtWidgets.QFileDialog.Directory)
        f.exec_()
        path = f.selectedFiles()

        if len(path)==0:
            return

        path = str(path[0])
        if path:
            try:
                if self.glWidget.dataModel:
                    self.glWidget.dataModel.loadFromPath(path,
                        prefetchSize = self.glWidget.N_PREFETCH)
                else:
                    self.glWidget.setModel(DataModel.fromPath(path,
                        prefetchSize = self.glWidget.N_PREFETCH))
            except Exception as e:
                mbox = QtWidgets.QMessageBox()
                mbox.setText(str(e))
                mbox.setIcon(QtWidgets.QMessageBox.Warning)
                mbox.exec_()
Ejemplo n.º 4
0
    def dropEvent(self, event):
        def _url_to_path(url):
            path = url.toLocalFile()
            if spimagine.config.__SYSTEM_DARWIN__:
                path = spimagine.config._parseFileNameFix(path)
            return path

        self.setCursor(QtCore.Qt.BusyCursor)
        urls = event.mimeData().urls()

        if len(urls) == 0:
            return
        elif len(urls) == 1:
            path = _url_to_path(urls[0])
        elif len(urls) > 1:
            path = tuple(_url_to_path(url) for url in urls)

        try:
            if self.dataModel:
                self.dataModel.loadFromPath(path, prefetchSize=self.N_PREFETCH)
            else:
                self.setModel(
                    DataModel.fromPath(path, prefetchSize=self.N_PREFETCH))

            self.setCursor(QtCore.Qt.ArrowCursor)
        except Exception as e:
            QtWidgets.QMessageBox.warning(self, "",
                                          "Error loading Data:\n %s" % str(e))
Ejemplo n.º 5
0
def test_surface():
    from spimagine import DataModel, NumpyData, DemoData
    from spimagine.gui.mesh import SphericalMesh

    app = QtWidgets.QApplication(sys.argv)

    win = MainWidget()

    x = np.linspace(-1, 1, 128)
    Z, Y, X = np.meshgrid(x, x, x)
    d = np.exp(-10 * X**2)

    win.setModel(DataModel(DemoData()))

    # win.glWidget.add_surface_ellipsoid((1.,0,0),
    #                                    (.2,.2,.2),
    #                                    facecolor = (1.,.3,.1,.5),
    #                                    edgecolor = (1.,1.,1.,.2),
    #                                    Nphi =20, Ntheta=10)

    # win.glWidget.add_mesh(SphericalMesh(facecolor = (1.,1.,1.),
    #                            edgecolor = None))

    win.show()

    win.raise_()

    sys.exit(app.exec_())
Ejemplo n.º 6
0
    def dropEvent(self, event):
        def _url_to_path(url):
            path = url.toLocalFile()
            if spimagine.config.__SYSTEM_DARWIN__:
                path = spimagine.config._parseFileNameFix(path)
            return path

        self.setCursor(QtCore.Qt.BusyCursor)
        urls = event.mimeData().urls()

        if len(urls) == 0:
            return
        elif len(urls) == 1:
            path = _url_to_path(urls[0])
        elif len(urls) > 1:
            path = tuple(_url_to_path(url) for url in urls)

        try:
            if self.dataModel:
                self.dataModel.loadFromPath(path, prefetchSize=self.N_PREFETCH)
            else:
                self.setModel(DataModel.fromPath(path, prefetchSize=self.N_PREFETCH))

            self.setCursor(QtCore.Qt.ArrowCursor)
        except Exception as e:
            QtWidgets.QMessageBox.warning(self, "", "Error loading Data:\n %s" % str(e))
Ejemplo n.º 7
0
def test_surface():
    from spimagine import DataModel, DemoData

    app = QtWidgets.QApplication(sys.argv)

    win = GLWidget(size=QtCore.QSize(800, 600))

    win.setModel(DataModel(DemoData()))

    # win.add_surface_sphere((0,0,0), 1., facecolor = (.0,.3,1.,.5),
    #                                 Nphi = 30, Ntheta=20)

    # win.add_mesh(SphericalMesh(r = .8,
    #                            facecolor = (1.,0.,0.),
    #                            #edgecolor = (1.,1.,1.),
    #                            edgecolor = None,
    #                            alpha = .3))

    # win.add_mesh(EllipsoidMesh(rs = (.3,.6,.6),
    #                             pos = (0,0,-.5),
    #
    #                            facecolor = (0.,1.,1.),
    #                            #edgecolor = (1.,1.,1.),
    #                            edgecolor = None,
    #                            alpha = .4))
    #

    win.show()

    win.raise_()

    sys.exit(app.exec_())
Ejemplo n.º 8
0
def test_sphere():
    from spimagine import DataModel, NumpyData, SpimData, TiffData

    app = QtWidgets.QApplication(sys.argv)

    win = GLWidget(size=QtCore.QSize(500, 500), interpolation="nearest")

    x = np.linspace(-1, 1, 64)
    Z, Y, X = np.meshgrid(x, x, x)
    # R = sqrt(Z**2+Y**2+(X-.35)**2)
    # R2 = sqrt(Z**2+Y**2+(X+.35)**2)

    # d = 100.*exp(-10*R**2)+.0*np.random.normal(0,1.,X.shape)

    # d += 100.*exp(-10*R2**2)+.0*np.random.normal(0,1.,X.shape)

    Ns = 5
    r = .6
    phi = np.linspace(0, 2 * np.pi, Ns + 1)[:-1]
    d = np.zeros_like(X)
    for p in phi:
        d += 100. * np.exp(-10 * (Z**2 + (Y - r * np.sin(p))**2 +
                                  (X - r * np.cos(p))**2))

    win.setModel(DataModel(NumpyData(d)))

    win.transform.setValueScale(0, 40)

    win.show()

    win.raise_()

    sys.exit(app.exec_())
Ejemplo n.º 9
0
 def dropEvent(self, event):
     for url in event.mimeData().urls():
         path = url.toLocalFile().toLocal8Bit().data()
         if self.dataModel:
             self.dataModel.loadFromPath(path, prefetchSize=self.N_PREFETCH)
         else:
             self.setModel(DataModel.fromPath(path, prefetchSize=self.N_PREFETCH))
Ejemplo n.º 10
0
def test_sphere():
    from spimagine import DataModel, NumpyData

    x = np.linspace(-1, 1, 32)
    Z, Y, X = np.meshgrid(x, x, x)
    # R = sqrt(Z**2+Y**2+(X-.35)**2)
    # R2 = sqrt(Z**2+Y**2+(X+.35)**2)

    # d = 100.*exp(-10*R**2)+.0*np.random.normal(0,1.,X.shape)

    # d += 100.*exp(-10*R2**2)+.0*np.random.normal(0,1.,X.shape)

    Ns = 5
    r = .6
    phi = np.linspace(0, 2 * np.pi, Ns + 1)[:-1]
    d = np.zeros_like(X)
    for p in phi:
        d += 200. * np.exp(-10 * (Z**2 + (Y - r * np.sin(p))**2 +
                                  (X - r * np.cos(p))**2))

    app = QtWidgets.QApplication(sys.argv)

    win = MainWidget()

    win.setModel(DataModel(NumpyData(d)))

    # win.glWidget.transform.setIso(True)
    # win.glWidget.transform.setValueScale(0,40)

    # win.saveFile(None)
    win.show()

    win.raise_()

    sys.exit(app.exec_())
Ejemplo n.º 11
0
 def dropEvent(self, event):
     for url in event.mimeData().urls():
         path = url.toLocalFile().toLocal8Bit().data()
         if self.dataModel:
             self.dataModel.loadFromPath(path, prefetchSize=self.N_PREFETCH)
         else:
             self.setModel(DataModel.fromPath(path, prefetchSize=self.N_PREFETCH))
Ejemplo n.º 12
0
    def openFile(self, e):
        # path = QtWidgets.QFileDialog.getOpenFileName(self, 'Open Path (File or Folder)',
        #                                              '.', selectedFilter='*.tif')

        f = QtWidgets.QFileDialog()
        f.setWindowTitle('Open Path (File or Folder)')
        f.setFileMode(QtWidgets.QFileDialog.ExistingFile
                      & QtWidgets.QFileDialog.Directory)
        f.exec_()
        path = f.selectedFiles()

        if len(path) == 0:
            return

        path = str(path[0])
        if path:
            try:
                if self.glWidget.dataModel:
                    self.glWidget.dataModel.loadFromPath(
                        path, prefetchSize=self.glWidget.N_PREFETCH)
                else:
                    self.glWidget.setModel(
                        DataModel.fromPath(
                            path, prefetchSize=self.glWidget.N_PREFETCH))
            except Exception as e:
                mbox = QtWidgets.QMessageBox()
                mbox.setText(str(e))
                mbox.setIcon(QtWidgets.QMessageBox.Warning)
                mbox.exec_()
Ejemplo n.º 13
0
def test_demo_simple():
    from spimagine import DataModel, DemoData

    app = QtWidgets.QApplication(sys.argv)

    win = GLWidget(size=QtCore.QSize(800, 800))

    win.setModel(DataModel(DemoData()))
    win.show()

    win.raise_()

    sys.exit(app.exec_())
Ejemplo n.º 14
0
def test_demo():
    from data_model import DataModel, DemoData, SpimData, TiffData, NumpyData

    app = QtWidgets.QApplication(sys.argv)

    win = GLWidget(size=QtCore.QSize(800, 800))

    win.setModel(DataModel(DemoData()))

    win.show()

    win.raise_()

    sys.exit(app.exec_())
Ejemplo n.º 15
0
def test_empty():
    from spimagine import DataModel, NumpyData, SpimData, TiffData

    app = QtWidgets.QApplication(sys.argv)

    win = MainWidget()

    d = np.zeros((600, ) * 3, np.float32)

    d[0, 0, 0] = 1.

    win.setModel(DataModel(NumpyData(d)))

    win.show()

    win.raise_()

    sys.exit(app.exec_())
Ejemplo n.º 16
0
    def dropEvent(self, event):

        for url in event.mimeData().urls():

            # path = url.toLocalFile().toLocal8Bit().data()

            path = url.toLocalFile()

            if spimagine.config.__SYSTEM_DARWIN__:
                path = spimagine.config._parseFileNameFix(path)

            self.setCursor(QtCore.Qt.BusyCursor)

            if self.dataModel:
                self.dataModel.loadFromPath(path, prefetchSize=self.N_PREFETCH)
            else:
                self.setModel(DataModel.fromPath(path, prefetchSize=self.N_PREFETCH))

            self.setCursor(QtCore.Qt.ArrowCursor)
Ejemplo n.º 17
0
def test_empty():
    from spimagine import DataModel, NumpyData, SpimData, TiffData

    app = QtWidgets.QApplication(sys.argv)

    win = GLWidget(size=QtCore.QSize(1000, 1000))

    d = np.zeros((800, ) * 3, np.float32)

    d[0, 0, 0] = 1.

    win.show()

    win.raise_()

    QtCore.QThread.msleep(1000)

    win.setModel(DataModel(NumpyData(d)))

    sys.exit(app.exec_())
Ejemplo n.º 18
0
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.models.data_model 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.data_model 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
Ejemplo n.º 19
0
    def setModel(self, dataModel):
        self.glSliceWidget.setModel(dataModel)

    # def wheelEvent(self, event):
    #     self.sliderSlice.wheelEvent(event)


if __name__ == '__main__':
    from spimagine import DemoData, NumpyData

    app = QtWidgets.QApplication(sys.argv)

    # win = GLSliceWidget(size=QtCore.QSize(500,500))

    win = SliceWidget(size=QtCore.QSize(500, 500), interp=False)

    d = random.uniform(0, 1, (10, 20, 30))

    win.setModel(DataModel(NumpyData(d)))
    # win.setModel(DataModel(DemoData()))

    win.transform.setMax(1.)
    # win.transform.setPerspective(True)

    win.show()

    win.raise_()

    sys.exit(app.exec_())
Ejemplo n.º 20
0
def main():

    parser = argparse.ArgumentParser(description='spimagine rendering application ')
    parser.add_argument('fname',
                        type=str,
                        nargs='*',
                        help='the files/folder to open (e.g. tif, folder of tif) ',
                        default = None)

    parser.add_argument('-p',
                        dest='prefetch',
                        type = int,
                        default=0,
                        help='prefetch size (should not be negative, e.g. -p 2)')

    parser.add_argument('-u',
                        dest='units',
                        nargs = 3,
                        type=float,
                        default=[1.,1.,1.],
                        help='voxel units')

    parser.add_argument('-D',
                        action='store_true',
                        help="output DEBUG messages")

    parser.add_argument('-v',"--verbose",
                        action='store_true',
                        help="output DEBUG messages")


    try:
        args = parser.parse_args()
    except Exception as e:
        print(e)
        parser.print_help()
        sys.exit(0)

    logger = logging.getLogger("spimagine")


    if args.D or args.verbose:
        logger.setLevel(logging.DEBUG)

    # if sys.platform.startswith("win"):
    # 	QtWidgets.QApplication.setStyle(QtWidgets.QStyleFactory.create("CleanLooks"))
    # print(QtWidgets.QStyleFactory.create("Fusion"))
    # QtWidgets.QApplication.setStyle(QtWidgets.QStyleFactory.create("Fusion"))

    # QtWidgets.QApplication.setStyle(QtWidgets.QStyleFactory.create(QtWidgets.QStyleFactory.keys()[1]))


    app = QtWidgets.QApplication(sys.argv)

    logger.debug("available qt styles: %s " % str(QtWidgets.QStyleFactory.keys()))
    logger.debug("used qt styles: %s " % app.style().metaObject().className())



    #splash screen
    pixmap = QtGui.QPixmap(absPath('../gui/images/splash.png'))
    splash = QtWidgets.QSplashScreen(pixmap, QtCore.Qt.WindowStaysOnTopHint)
    splash.setMask(pixmap.mask())
    splash.show()
    app.processEvents()

    import spimagine
    from spimagine.gui.mainwidget import MainWidget
    from spimagine.models.data_model import DemoData, DataModel



    app.setWindowIcon(QtGui.QIcon(absPath('../gui/images/spimagine.png')))


    win = MainWidget()
    win.resize(spimagine.config.__DEFAULT_WIDTH__, spimagine.config.__DEFAULT_HEIGHT__)
    splash.hide()
    if args.fname:
        if len(args.fname)==1:
            win.setModel(DataModel.fromPath(args.fname[0]))
        else:
            win.setModel(DataModel.fromPath(args.fname))
    else:
        win.setModel(DataModel(DemoData()))

    win.transform.setStackUnits(*args.units)

    win.show()
    win.raise_window()


    splash.finish(win)

    sys.exit(app.exec_())
Ejemplo n.º 21
0
def main():

    parser = argparse.ArgumentParser(
        description='spimagine rendering application ')
    parser.add_argument(
        'fname',
        type=str,
        nargs='*',
        help='the files/folder to open (e.g. tif, folder of tif) ',
        default=None)

    parser.add_argument(
        '-p',
        dest='prefetch',
        type=int,
        default=0,
        help='prefetch size (should not be negative, e.g. -p 2)')

    parser.add_argument('-u',
                        dest='units',
                        nargs=3,
                        type=float,
                        default=[1., 1., 1.],
                        help='voxel units')

    parser.add_argument('-D',
                        action='store_true',
                        help="output DEBUG messages")

    parser.add_argument('-v',
                        "--verbose",
                        action='store_true',
                        help="output DEBUG messages")

    try:
        args = parser.parse_args()
    except Exception as e:
        print(e)
        parser.print_help()
        sys.exit(0)

    logger = logging.getLogger("spimagine")

    if args.D or args.verbose:
        logger.setLevel(logging.DEBUG)

    # if sys.platform.startswith("win"):
    # 	QtWidgets.QApplication.setStyle(QtWidgets.QStyleFactory.create("CleanLooks"))
    # print(QtWidgets.QStyleFactory.create("Fusion"))
    # QtWidgets.QApplication.setStyle(QtWidgets.QStyleFactory.create("Fusion"))

    # QtWidgets.QApplication.setStyle(QtWidgets.QStyleFactory.create(QtWidgets.QStyleFactory.keys()[1]))

    app = QtWidgets.QApplication(sys.argv)

    logger.debug("available qt styles: %s " %
                 str(QtWidgets.QStyleFactory.keys()))
    logger.debug("used qt styles: %s " % app.style().metaObject().className())

    #splash screen
    pixmap = QtGui.QPixmap(absPath('../gui/images/splash.png'))
    splash = QtWidgets.QSplashScreen(pixmap, QtCore.Qt.WindowStaysOnTopHint)
    splash.setMask(pixmap.mask())
    splash.show()
    app.processEvents()

    import spimagine
    from spimagine.gui.mainwidget import MainWidget
    from spimagine.models.data_model import DemoData, DataModel

    app.setWindowIcon(QtGui.QIcon(absPath('../gui/images/spimagine.png')))

    win = MainWidget()
    win.resize(spimagine.config.__DEFAULT_WIDTH__,
               spimagine.config.__DEFAULT_HEIGHT__)
    splash.hide()
    if args.fname:
        if len(args.fname) == 1:
            win.setModel(DataModel.fromPath(args.fname[0]))
        else:
            win.setModel(DataModel.fromPath(args.fname))
    else:
        win.setModel(DataModel(DemoData()))

    win.transform.setStackUnits(*args.units)

    win.show()
    win.raise_window()

    splash.finish(win)

    sys.exit(app.exec_())