示例#1
0
 def setImageData(self, data):
     """
     setImageData(self, data)
     data is a numpy array
     """
     self._qt = False
     maxTextureSize = GL.glGetIntegerv(GL.GL_MAX_TEXTURE_SIZE)
     shape = data.shape
     self._dataMin = data.min()
     self._dataMax = data.max()
     if (shape[0] > maxTextureSize) or\
        (shape[1] > maxTextureSize):
         #very slow
         self._imageData = data.astype(numpy.float32)
         self._meshImage = True
         #self._imageData = data.astype(numpy.float32)
         self.__width  = self._imageData.shape[1]
         self.__height = self._imageData.shape[0]
         self.zPosition = 0.0
         self._xValues = numpy.arange(self.__width).astype(numpy.float32)
         self._yValues = numpy.arange(self.__height).astype(numpy.float32)
         self._zValues  = numpy.zeros(self._imageData.shape, numpy.float32)
         self.setLimits(0.0, 0.0, self.zPosition,
                    self.__width-1, self.__height-1, self.zPosition)
         (image,size,minmax)= spslut.transform(self._imageData.T, (1,0),
                                   (spslut.LINEAR,3.0),
                                   "RGBX", spslut.TEMP,
                                    0,
                                   (self._dataMin, self._dataMax),
                                   (0, 255), 1)
         self.pixmap = image
         self.pixmap.shape = -1, 4
         self.pixmap[:,3]  = 255
     else:
         self._meshImage = False
         (image,size,minmax)= spslut.transform(data, (1,0),
                                   (spslut.LINEAR,3.0),
                                   "RGBX", spslut.TEMP,
                                    0,
                                   (self._dataMin, self._dataMax),
                                   (0, 255), 1)
         self.setPixmap(image,
                        size[0],
                        size[1],
                        xmirror = False,
                        ymirror = False)
         self._imageData = data
     self._configuration['common']['colormap'][2]=self._dataMin
     self._configuration['common']['colormap'][3]=self._dataMax
     self._configuration['common']['colormap'][4]=self._dataMin
     self._configuration['common']['colormap'][5]=self._dataMax
示例#2
0
    def setConfiguration(self, ddict):
        Object3DBase.Object3D.setConfiguration(self, ddict)
        if self._qt:
            return
        if self._imageData is None:
            return
        if 'event' in ddict['common']:
            if ddict['common']['event'] == 'ColormapChanged':
                self._forceTextureCalculation = True
        if not self._forceTextureCalculation:
            return
        colormap = self._configuration['common']['colormap']

        #avoid recalculating min and max values
        if colormap[1]:
            vMin = colormap[4]
            vMax = colormap[5]
        else:
            vMin = colormap[2]
            vMax = colormap[3]
        if not self._meshImage:
            (pixmap,size,minmax)= spslut.transform(self._imageData,
                                              (1,0),
                                              (colormap[6],3.0),
                                              "RGBX",
                                              COLORMAPLIST[int(str(colormap[0]))],
                                              0,
                                              (vMin, vMax),
                                              (0, 255),1)
            width = size[0]
            height = size[1]
            pixmap.shape = -1, 4
            tjump = self.__tWidth
            pjump = self.__width
            for i in range(height):
                self.pixmap[i*tjump:(i*tjump+pjump), :] = pixmap[(i*pjump):(i+1)*pjump,:]
        else:
            (pixmap,size,minmax)= spslut.transform(self._imageData.T,
                                              (1,0),
                                              (colormap[6],3.0),
                                              "RGBX",
                                              COLORMAPLIST[int(str(colormap[0]))],
                                              0,
                                              (vMin, vMax),
                                              (0, 255),1)
            pixmap.shape = -1, 4
            self.pixmap[:,0:3] = pixmap[:,0:3]
        self.pixmap[:,3] = 255
        return
示例#3
0
 def getColors(self):
     if DEBUG:
         t0 = time.time()
     self._configuration['common']['colormap'][4] = self.values.min()
     self._configuration['common']['colormap'][5] = self.values.max()
     colormap = self._configuration['common']['colormap']
     (self.vertexColors, size, minmax) = spslut.transform(
         self.values, (1, 0), (colormap[6], 3.0), "RGBX",
         COLORMAPLIST[int(str(colormap[0]))], colormap[1],
         (colormap[2], colormap[3]), (0, 255), 1)
     self.vertexColors.shape = self.nVertices, 4
     self.vertexColors[:, 3] = self._alpha
     if DEBUG:
         print("colors elapsed = ", time.time() - t0)
     #selection colors
     # if I have more than pow(2, 24) vertices
     # the vertex with number pow(2, 24) will never be selected
     if 0:
         i = numpy.arange(self.nVertices)
         self.vertexSelectionColors = numpy.zeros((self.nVertices, 4),
                                                  numpy.uint8)
         self.vertexSelectionColors[:, 0] = (i & 255)
         self.vertexSelectionColors[:, 1] = ((i >> 8) & 255)
         self.vertexSelectionColors[:, 2] = ((i >> 16) & 255)
         self.vertexSelectionColors[:, 3] = 255 - (i >> 24)
     return
示例#4
0
 def buildPointList0(self):
     """
     This is just to test memory and speed
     """
     n1, n2, n3 = 256, 256, 256
     zdata = numpy.arange(n1*n2*n3).astype(numpy.float32)
     zdata.shape= -1, 1
     (image,size,minmax)= spslut.transform(zdata,
                                       (1,0),
                                       (spslut.LINEAR,3.0),
                                       "RGBX",
                                       spslut.TEMP,
                                       1,
                                       (0, 1),
                                       (0, 255),1)
     image.shape = -1, 4
     image[:,3] = 255
     #self.vertexColors = image.astype(numpy.float32)
     x = numpy.arange(n1).astype(numpy.float32)
     y = numpy.arange(n2).astype(numpy.float32)
     z = numpy.arange(n3).astype(numpy.float32)
     #Object3DCTools.draw3DGridQuads(x, y, y)
     #Object3DCTools.draw3DGridLines(x, y, z, image)
     Object3DCTools.draw3DGridPoints(x, y, z, image)
     self.zdata = zdata
示例#5
0
 def getColors(self):
     if DEBUG:
         t0 = time.time()
     self._configuration['common']['colormap'][4]=self.values.min()
     self._configuration['common']['colormap'][5]=self.values.max()
     colormap = self._configuration['common']['colormap']
     (self.vertexColors,size,minmax)= spslut.transform(self.values,
                                           (1,0),
                                           (colormap[6],3.0),
                                           "RGBX",
                                           COLORMAPLIST[int(str(colormap[0]))],
                                           colormap[1],
                                           (colormap[2], colormap[3]),
                                           (0, 255),1)
     self.vertexColors.shape = self.nVertices, 4
     self.vertexColors[:, 3] = self._alpha
     if DEBUG:
         print("colors elapsed = ", time.time() - t0)
     #selection colors
     # if I have more than pow(2, 24) vertices
     # the vertex with number pow(2, 24) will never be selected
     if 0:
         i = numpy.arange(self.nVertices)
         self.vertexSelectionColors = numpy.zeros((self.nVertices,4),
                                                  numpy.uint8)
         self.vertexSelectionColors[:,0] = (i & 255)
         self.vertexSelectionColors[:,1] = ((i >> 8) & 255)
         self.vertexSelectionColors[:,2] = ((i >> 16) & 255)
         self.vertexSelectionColors[:,3] = 255 - (i >> 24)
     return
示例#6
0
    def buildSPSLUTRedPixmap(data, start=None, end=None, isLog10=False):
        """Generate a pixmap with SPS LUT.
        Only supports red colormap with 256 colors.
        """
        colormap = spslut.RED
        mapping = spslut.LOG if isLog10 else spslut.LINEAR

        if start is None and end is None:
            autoScale = 1
            start, end = 0, 1
        else:
            autoScale = 0
            if start is None:
                start = data.min()
            if end is None:
                end = data.max()

        pixmap, size, minMax = spslut.transform(data,
                                                (1, 0),
                                                (mapping, 3.0),
                                                'RGBX',
                                                colormap,
                                                autoScale,
                                                (start, end),
                                                (0, 255),
                                                1)
        pixmap.shape = data.shape[0], data.shape[1], 4

        return pixmap
示例#7
0
 def buildPointList0(self):
     """
     This is just to test memory and speed
     """
     n1, n2, n3 = 256, 256, 256
     zdata = numpy.arange(n1*n2*n3).astype(numpy.float32)
     zdata.shape= -1, 1
     (image,size,minmax)= spslut.transform(zdata,
                                       (1,0),
                                       (spslut.LINEAR,3.0),
                                       "RGBX",
                                       spslut.TEMP,
                                       1,
                                       (0, 1),
                                       (0, 255),1)
     image.shape = -1, 4
     image[:,3] = 255
     #self.vertexColors = image.astype(numpy.float32)
     x = numpy.arange(n1).astype(numpy.float32)
     y = numpy.arange(n2).astype(numpy.float32)
     z = numpy.arange(n3).astype(numpy.float32)
     #Object3DCTools.draw3DGridQuads(x, y, y)
     #Object3DCTools.draw3DGridLines(x, y, z, image)
     Object3DCTools.draw3DGridPoints(x, y, z, image)
     self.zdata = zdata
示例#8
0
 def setImageData(self, data):
     """
     setImageData(self, data)
     data is a numpy array
     """
     self._qt = False
     maxTextureSize = GL.glGetIntegerv(GL.GL_MAX_TEXTURE_SIZE)
     shape = data.shape
     self._dataMin = data.min()
     self._dataMax = data.max()
     if (shape[0] > maxTextureSize) or\
        (shape[1] > maxTextureSize):
         #very slow
         self._imageData = data.astype(numpy.float32)
         self._meshImage = True
         #self._imageData = data.astype(numpy.float32)
         self.__width = self._imageData.shape[1]
         self.__height = self._imageData.shape[0]
         self.zPosition = 0.0
         self._xValues = numpy.arange(self.__width).astype(numpy.float32)
         self._yValues = numpy.arange(self.__height).astype(numpy.float32)
         self._zValues = numpy.zeros(self._imageData.shape, numpy.float32)
         self.setLimits(0.0, 0.0, self.zPosition, self.__width - 1,
                        self.__height - 1, self.zPosition)
         (image, size, minmax) = spslut.transform(
             self._imageData.T, (1, 0), (spslut.LINEAR, 3.0), "RGBX",
             spslut.TEMP, 0, (self._dataMin, self._dataMax), (0, 255), 1)
         self.pixmap = image
         self.pixmap.shape = -1, 4
         self.pixmap[:, 3] = 255
     else:
         self._meshImage = False
         (image, size,
          minmax) = spslut.transform(data, (1, 0), (spslut.LINEAR, 3.0),
                                     "RGBX", spslut.TEMP, 0,
                                     (self._dataMin, self._dataMax),
                                     (0, 255), 1)
         self.setPixmap(image,
                        size[0],
                        size[1],
                        xmirror=False,
                        ymirror=False)
         self._imageData = data
     self._configuration['common']['colormap'][2] = self._dataMin
     self._configuration['common']['colormap'][3] = self._dataMax
     self._configuration['common']['colormap'][4] = self._dataMin
     self._configuration['common']['colormap'][5] = self._dataMax
示例#9
0
    def setConfiguration(self, ddict):
        Object3DBase.Object3D.setConfiguration(self, ddict)
        if self._qt:
            return
        if self._imageData is None:
            return
        if 'event' in ddict['common']:
            if ddict['common']['event'] == 'ColormapChanged':
                self._forceTextureCalculation = True
        if not self._forceTextureCalculation:
            return
        colormap = self._configuration['common']['colormap']

        #avoid recalculating min and max values
        if colormap[1]:
            vMin = colormap[4]
            vMax = colormap[5]
        else:
            vMin = colormap[2]
            vMax = colormap[3]
        if not self._meshImage:
            (pixmap, size,
             minmax) = spslut.transform(self._imageData, (1, 0),
                                        (colormap[6], 3.0), "RGBX",
                                        COLORMAPLIST[int(str(colormap[0]))], 0,
                                        (vMin, vMax), (0, 255), 1)
            width = size[0]
            height = size[1]
            pixmap.shape = -1, 4
            tjump = self.__tWidth
            pjump = self.__width
            for i in range(height):
                self.pixmap[i * tjump:(i * tjump +
                                       pjump), :] = pixmap[(i *
                                                            pjump):(i + 1) *
                                                           pjump, :]
        else:
            (pixmap, size,
             minmax) = spslut.transform(self._imageData.T, (1, 0),
                                        (colormap[6], 3.0), "RGBX",
                                        COLORMAPLIST[int(str(colormap[0]))], 0,
                                        (vMin, vMax), (0, 255), 1)
            pixmap.shape = -1, 4
            self.pixmap[:, 0:3] = pixmap[:, 0:3]
        self.pixmap[:, 3] = 255
        return
示例#10
0
def getObject3DInstance(config=None):
    fileTypeList = [
        'Picture Files (*jpg *jpeg *tif *tiff *png)', 'EDF Files (*edf)',
        'EDF Files (*ccd)', 'ADSC Files (*img)', 'EDF Files (*)'
    ]
    fileList, filterUsed = Object3DFileDialogs.getFileList(
        None,
        filetypelist=fileTypeList,
        message="Please select one object data file",
        mode="OPEN",
        getfilter=True)
    if not len(fileList):
        return
    fname = fileList[0]
    if filterUsed.split()[0] == "Picture":
        qimage = qt.QImage(fname)
        if qimage.isNull():
            msg = qt.QMessageBox(self)
            msg.setIcon(qt.QMessageBox.Critical)
            msg.setText("Cannot read file %s as an image" % fname)
            msg.exec_()
            return
        object3D = Object3DPixmap(os.path.basename(fname))
        object3D.setQImage(qimage)
        return object3D
    if filterUsed.split()[0] in ["EDF", "ADSC"]:
        edf = EdfFile.EdfFile(fname)
        data = edf.GetData(0)
        if True:
            object3D = Object3DPixmap(os.path.basename(fname))
            object3D.setImageData(data)
        else:
            (image, size, minmax) = spslut.transform(data, (1, 0),
                                                     (spslut.LINEAR, 3.0),
                                                     "RGBX", spslut.TEMP, 1,
                                                     (0, 1), (0, 255), 1)
            object3D = Object3DPixmap(os.path.basename(fname))
            object3D.setPixmap(image,
                               size[0],
                               size[1],
                               xmirror=False,
                               ymirror=False)
        return object3D
    return None
示例#11
0
def getObject3DInstance(config=None):
    fileTypeList = ['Picture Files (*jpg *jpeg *tif *tiff *png)',
                    'EDF Files (*edf)',
                    'EDF Files (*ccd)',
                    'ADSC Files (*img)',
                    'EDF Files (*)']
    fileList, filterUsed = PyMcaFileDialogs.getFileList(
        parent=None,
        filetypelist=fileTypeList,
        message="Please select one object data file",
        mode="OPEN",
        getfilter=True)
    if not len(fileList):
        return
    fname = fileList[0]
    if filterUsed.split()[0] == "Picture":
        qimage = qt.QImage(fname)
        if qimage.isNull():
            msg = qt.QMessageBox(self)
            msg.setIcon(qt.QMessageBox.Critical)
            msg.setText("Cannot read file %s as an image" % fname)
            msg.exec_()
            return
        object3D = Object3DPixmap(os.path.basename(fname))
        object3D.setQImage(qimage)
        return object3D
    if filterUsed.split()[0] in ["EDF", "ADSC"]:
        edf = EdfFile.EdfFile(fname)
        data = edf.GetData(0)
        if True:
            object3D = Object3DPixmap(os.path.basename(fname))
            object3D.setImageData(data)
        else:
            (image,size,minmax)= spslut.transform(data, (1,0),
                                      (spslut.LINEAR,3.0),
                                      "RGBX", spslut.TEMP,
                                      1,
                                      (0, 1),
                                      (0, 255), 1)
            object3D = Object3DPixmap(os.path.basename(fname))
            object3D.setPixmap(image, size[0], size[1], xmirror = False, ymirror = False)
        return object3D
    return None
示例#12
0
if __name__ == "__main__":
    import sys
    import os
    from PyMca5.Object3D import SceneGLWindow
    from PyMca5.Object3D import Object3DFileDialogs
    app = qt.QApplication(sys.argv)
    window = SceneGLWindow.SceneGLWindow()
    window.show()
    object3D = getObject3DInstance()
    if object3D is None:
        name = "125 rows x 80 columns array"
        data = numpy.arange(10000.).astype(numpy.float32)
        data.shape = [125, 80]
        data[120:125, 70:80] = 0
        (image, size,
         minmax) = spslut.transform(data, (1, 0), (spslut.LINEAR, 3.0), "RGBX",
                                    spslut.TEMP, 1, (0, 1), (0, 255), 1)
        object3D = Object3DPixmap(os.path.basename(name))
        object3D.setPixmap(image,
                           size[0],
                           size[1],
                           xmirror=False,
                           ymirror=False)
        object3D.setImageData(data)
    window.addObject(object3D)
    window.glWidget.setZoomFactor(1.0)
    window.show()
    while (0):
        time.sleep(0.01)
        data = numpy.random.random((2048, 2048)) * 1000
        #data = data.astype(numpy.float32)
        data = data.astype(numpy.int16)
示例#13
0
def getPixmapFromData(ndarray, colormap=None, mask=None, colors=None):
    """
    Calculate a colormap and apply a mask (given as a set of unsigned ints) to
    it.

    :param ndarray:  Data values
    :type ndarray: Numpy array
    :param colormap: None or a list of seven parameters:

                0. Colormap index. Positive integer
                1. Autoscale flag
                2. Minimum value to be mapped
                3. Maximum value to be mapped
                4. Minimum data value
                5. Maximum data value
                6. Flag to indicate mode (0 - linear, 1 - logarithmic)

    :type colormap: list or None (default)
    :param mask: Numpy array of indices to indicating mask levels
    :type mask: Numpy nd array of indices or None (default)
    :param colors: List containing the colors associated to the mask levels
    :type colors: Numpy array of dimensions (N mask levels, 4) or None (default)
    :returns: Numpy uint8 array of shape equal data.shape + [4]
    """
    oldShape = list(ndarray.shape)

    # deal with numpy masked arrays
    if hasattr(ndarray, 'mask'):
        data = ndarray.data[:]
    else:
        data = ndarray[:]

    if len(oldShape) == 1:
        data.shape = -1, 1
    elif len(oldShape) != 2:
        raise TypeError("Input array must be of dimension 2 got %d" % \
                                len(oldShape))

    # deal with non finite data
    finiteData = numpy.isfinite(data)
    goodData = finiteData.min()

    if goodData:
        minData = data.min()
        maxData = data.max()
    else:
        tmpData = data[finiteData]
        if tmpData.size > 0:
            minData = tmpData.min()
            maxData = tmpData.max()
        else:
            minData = None
            maxData = None
        tmpData = None

    # apply colormap
    if colormap is None:
        colormapName = COLORMAP_LIST[min(DEFAULT_COLORMAP_INDEX,
                                    len(COLORMAP_LIST) - 1)]
        if DEFAULT_COLORMAP_LOG_FLAG:
            colormapScaling = spslut.log
        else:
            colormapScaling = spslut.LINEAR
        if minData is None:
            (pixmap, size, minmax)= spslut.transform(\
                            data,
                            (1,0),
                            (colormapScaling, 3.0),
                            "RGBX",
                            colormapName,
                            1,
                            (0, 1),
                            (0, 255), 1)
        else:
            (pixmap, size, minmax)= spslut.transform(\
                            data,
                            (1,0),
                            (colormapScaling,3.0),
                            "RGBX",
                            colormapName,
                            0,
                            (minData,maxData),
                            (0, 255), 1)
    else:
        if len(colormap) < 7:
            print("Missing colormap log flag assuming linear")
            colormap.append(spslut.LINEAR)
        if goodData:
            (pixmap, size, minmax)= spslut.transform(\
                            data,
                            (1,0),
                            (colormap[6],3.0),
                            "RGBX",
                            COLORMAP_LIST[int(str(colormap[0]))],
                            colormap[1],
                            (colormap[2],colormap[3]),
                            (0, 255), 1)
        elif colormap[1]:
            #autoscale
            if minData is None:
                colormapName = COLORMAP_LIST[min(DEFAULT_COLORMAP_INDEX,
                                            len(COLORMAP_LIST) - 1)]
                colormapScaling = DEFAULT_COLORMAP_LOG_FLAG
                (pixmap, size, minmax)= spslut.transform(\
                            data,
                            (1,0),
                            (colormapScaling, 3.0),
                            "RGBX",
                            colormapName,
                            1,
                            (0, 1),
                            (0, 255), 1)
            else:
                (pixmap, size, minmax)= spslut.transform(\
                            data,
                            (1,0),
                            (colormap[6],3.0),
                            "RGBX",
                            COLORMAP_LIST[int(str(colormap[0]))],
                            0,
                            (minData, maxData),
                            (0,255), 1)
        else:
            (pixmap, size, minmax)= spslut.transform(\
                            data,
                            (1,0),
                            (colormap[6],3.0),
                            "RGBX",
                            COLORMAP_LIST[int(str(colormap[0]))],
                            colormap[1],
                            (colormap[2],colormap[3]),
                            (0,255), 1)

    # make sure alpha is set
    pixmap.shape = -1, 4
    pixmap[:, 3] = 255
    pixmap.shape = list(data.shape) + [4]
    if not goodData:
        pixmap[finiteData < 1] = 255
    if mask is not None:
        return applyMaskToImage(pixmap, mask, colors=colors, copy=False)
    return pixmap
示例#14
0
 import sys
 import os
 from PyMca5.Object3D import SceneGLWindow
 from PyMca5.Object3D import Object3DFileDialogs
 app = qt.QApplication(sys.argv)
 window = SceneGLWindow.SceneGLWindow()
 window.show()
 object3D=getObject3DInstance()
 if object3D is None:
     name = "125 rows x 80 columns array"
     data = numpy.arange(10000.).astype(numpy.float32)
     data.shape = [125, 80]
     data[120:125, 70:80]  = 0
     (image,size,minmax)= spslut.transform(data, (1,0),
                                   (spslut.LINEAR,3.0),
                                   "RGBX", spslut.TEMP,
                                   1,
                                   (0, 1),
                                   (0, 255), 1)
     object3D = Object3DPixmap(os.path.basename(name))
     object3D.setPixmap(image, size[0], size[1],
                        xmirror = False,
                        ymirror = False)
     object3D.setImageData(data)
 window.addObject(object3D)
 window.glWidget.setZoomFactor(1.0)
 window.show()
 while(0):
     time.sleep(0.01)
     data = numpy.random.random((2048, 2048))*1000
     #data = data.astype(numpy.float32)
     data = data.astype(numpy.int16)