def setupHistArr(self, i): self.hist_arr[i] = None img = self.data[tuple(self.zsec)][i] if img.dtype.type == N.uint8: self.hist_min[i], self.hist_max[i] = 0, (1 << 8) - 1 elif img.dtype.type == N.uint16: self.hist_min[i], self.hist_max[i] = 0, (1 << 16) - 1 elif img.dtype.type == N.int16: self.hist_min[i], self.hist_max[i] = 0 - (1 << 15), (1 << 15) - 1 from Priithon.all import U self.hist[i].hist_min, self.hist[i].hist_max = U.mm(img) #self.img) if img.dtype.type in (N.uint8, N.int16, N.uint16): self.hist_range[i] = self.hist_max[i] - self.hist_min[i] + 1 self.hist_arr[i] = N.zeros(shape=self.hist_range[i], dtype=N.int32)
def setupHistArr(self,i): self.hist_arr[i] = None img = self.data[ tuple(self.zsec) ][i] if img.dtype.type == N.uint8: self.hist_min[i], self.hist_max[i] = 0, (1<<8)-1 elif img.dtype.type == N.uint16: self.hist_min[i], self.hist_max[i] = 0, (1<<16)-1 elif img.dtype.type == N.int16: self.hist_min[i], self.hist_max[i] = 0-(1<<15), (1<<15)-1 from Priithon.all import U self.hist[i].hist_min,self.hist[i].hist_max = U.mm(img)#self.img) if img.dtype.type in (N.uint8, N.int16, N.uint16): self.hist_range[i] = self.hist_max[i] - self.hist_min[i] + 1 self.hist_arr[i] = N.zeros(shape=self.hist_range[i], dtype=N.int32)
def setupHistArr(self): self.hist_arr = None if self.img.dtype.type == N.uint8: self.hist_min, self.hist_max = 0, (1 << 8) - 1 elif self.img.dtype.type == N.uint16: self.hist_min, self.hist_max = 0, (1 << 16) - 1 elif self.img.dtype.type == N.int16: self.hist_min, self.hist_max = 0 - (1 << 15), (1 << 15) - 1 from Priithon.all import U self.hist.hist_min, self.hist.hist_max = U.mm(self.img) #self.hist_min #if self.hist.m_histPlotArray is not None: # self.hist.m_histPlotArray[0,0],self.hist.m_histPlotArray[-1,0] = U.mm(self.img) # print self.hist.m_histPlotArray[0,0],self.hist.m_histPlotArray[-1,0] if self.img.dtype.type in (N.uint8, N.int16, N.uint16): self.hist_range = self.hist_max - self.hist_min + 1 self.hist_arr = N.zeros(shape=self.hist_range, dtype=N.int32)
def setupHistArr(self): self.hist_arr = None if self.img.dtype.type == N.uint8: self.hist_min, self.hist_max = 0, (1<<8)-1 elif self.img.dtype.type == N.uint16: self.hist_min, self.hist_max = 0, (1<<16)-1 elif self.img.dtype.type == N.int16: self.hist_min, self.hist_max = 0-(1<<15), (1<<15)-1 from Priithon.all import U self.hist.hist_min,self.hist.hist_max = U.mm(self.img)#self.hist_min #if self.hist.m_histPlotArray is not None: # self.hist.m_histPlotArray[0,0],self.hist.m_histPlotArray[-1,0] = U.mm(self.img) # print self.hist.m_histPlotArray[0,0],self.hist.m_histPlotArray[-1,0] if self.img.dtype.type in (N.uint8, N.int16, N.uint16): self.hist_range = self.hist_max - self.hist_min + 1 self.hist_arr = N.zeros(shape=self.hist_range, dtype=N.int32)
def addImg(self, img, smin=0, smax=10000, alpha=1., interp=0, imgidx=None, alignParm=None, refreshNow=1): ''' append new image. Following lists get somthing appended: self.imgList self.loadImgsToGfxCard if imgidx is not None use 'insert(imgidx,...)' with self.imgList instead of append a new GL-texture is generated and an empty(!) texture with proper dtype is created. a new GL-Display-lists is generated and compiled according to self.originLeftBottom ''' pic_ny, pic_nx = img.shape # different shapes in multi wave images #self.pic_nys.append(pic_ny) #self.pic_nxs.append(pic_nx) if self.dims == (1, 2): # XY self.pic_nys = [self.mydoc.ny] * self.mydoc.nw self.pic_nxs = [self.mydoc.nx] * self.mydoc.nw elif self.dims == (0, 2): # XZ self.pic_nys = [self.mydoc.nz] * self.mydoc.nw self.pic_nxs = [self.mydoc.nx] * self.mydoc.nw elif self.dims == (1, 0): # ZY self.pic_nys = [self.mydoc.ny] * self.mydoc.nw self.pic_nxs = [self.mydoc.nz] * self.mydoc.nw self.pic_ny, self.pic_nx = max(self.pic_nys), max(self.pic_nxs) if smin == smax == 0: from Priithon.all import U smin, smax = U.mm(img) tex_nx = 2 while tex_nx < pic_nx: tex_nx *= 2 # // texture must be of size 2^n tex_ny = 2 while tex_ny < pic_ny: tex_ny *= 2 self.picTexRatio_x = float(pic_nx) / tex_nx self.picTexRatio_y = float(pic_ny) / tex_ny if sys.platform.startswith('linux'): wx.Yield() # added 20161209 for linux miniconda self.SetCurrent( self.context ) ## makes the implicit rendering context of this canvas current with this canvas textureID = glGenTextures(1) ## create one name for a texture object glBindTexture(GL_TEXTURE_2D, textureID) ## Define this new texture object based on img's geometry if interp: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) else: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) if img.dtype.type in (N.uint8, N.bool_): glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex_nx, tex_ny, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, None) elif img.dtype.type == N.int16: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex_nx, tex_ny, 0, GL_LUMINANCE, GL_SHORT, None) elif img.dtype.type == N.float32: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex_nx, tex_ny, 0, GL_LUMINANCE, GL_FLOAT, None) elif img.dtype.type == N.uint16: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex_nx, tex_ny, 0, GL_LUMINANCE, GL_UNSIGNED_SHORT, None) elif img.dtype.type in ( N.float64, N.int32, N.uint32, N.int64, N.uint64, ): #N.complex64, N.complex128): glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex_nx, tex_ny, 0, GL_LUMINANCE, GL_FLOAT, None) else: self.error = "unsupported data mode" raise ValueError, self.error curGLLIST = glGenLists(1) ## request one display-list index # 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 #[gllist, enabled, imgArr, textureID, smin, smax, r,g,b, tx, ty, rot, magX, magY, magZ] r, g, b = 1, 1, 1 ## default grey (if no self.setColor() is called) imgListItem = [ curGLLIST, 1, img, textureID, smin, smax, r, g, b, 0, 0, 0, 1, 1, 1 ] glNewList(curGLLIST, GL_COMPILE ) # Display list is created; Commands are merely compiled # Newsgroups: comp.graphics.api.opengl Date: 1998/05/05 # By the way, you don't have to explicitly delete a display list to reuse # its name. Simply call glNewList() again with the existing list name -- # this will implicitly delete the old contents and replace them with the # new ones; this will happen at glEndList() time. glBindTexture(GL_TEXTURE_2D, textureID) # CHECK: Is this redundant? glEnable(GL_TEXTURE_2D) glEnable( GL_BLEND) ## enable blending of colors (Chapter 6 of the Red Book) glBlendFunc(GL_ONE, GL_ONE) glBegin(GL_QUADS) ### draw black background under the image ###//(0,0) at left bottom glTexCoord2f(0, 0) glVertex2i(0, 0) glTexCoord2f(self.picTexRatio_x, 0) glVertex2i(pic_nx, 0) glTexCoord2f(self.picTexRatio_x, self.picTexRatio_y) glVertex2i(pic_nx, pic_ny) glTexCoord2f(0, self.picTexRatio_y) glVertex2i(0, pic_ny) glEnd() glDisable(GL_TEXTURE_2D) glDisable(GL_BLEND) glEndList() ## display list stops here if imgidx is None: imgidx = len(self.imgList) self.imgList.insert(imgidx, imgListItem) ## imgListItem contains the newly created display list, indexed by imgidx self.loadImgsToGfxCard.append(imgidx) self.imgsGlListChanged = True self.setLeftDown() if refreshNow: self.Refresh(0)
def addImg(self, img, smin=0, smax=10000, alpha=1., interp=0, imgidx=None, refreshNow=1): """ append new inage. Following lists get somthing appended: m_imgList m_loadImgsToGfxCard if imgidx is not None use 'insert(imgidx,...)' with m_imgList instead of append a new GL-texture is generated and an empty(!) texture with proper dtype is created. a new GL-Display-lists is generated an compiled according to m_originLeftBottom """ pic_ny, pic_nx = img.shape if len( self.m_imgList ) == 0: # some workaround code for functions originally written for viewer.py self.pic_ny, self.pic_nx = pic_ny, pic_nx if smin == smax == 0: from Priithon.all import U smin, smax = U.mm(img) tex_nx = 2 while tex_nx < pic_nx: tex_nx *= 2 # // texture must be of size 2^n tex_ny = 2 while tex_ny < pic_ny: tex_ny *= 2 self.picTexRatio_x = float(pic_nx) / tex_nx self.picTexRatio_y = float(pic_ny) / tex_ny wx.Yield() self.SetCurrent(self.context) # 20141127 textureID = glGenTextures(1) glBindTexture(GL_TEXTURE_2D, textureID) #glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glBlendFunc(GL_ONE, GL_ONE) # 20070827 #20070827 glBlendFunc(GL_SRC_ALPHA, GL_ONE) #20070827 # GL_LUMINANCE # Each element is a single luminance value. The GL converts it to fixed-point # or floating-point, then assembles it into an RGBA element by replicating # the luminance value three times for red, green, and blue and # attaching 1 for alpha. # GL_LUMINANCE_ALPHA # Each element is a luminance/alpha pair. The GL converts it to fixed-point # or floating point, then assembles it into an RGBA element by replicating # the luminance value three times for red, green, and blue. if interp: # FIXME put into gllist glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) else: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) if img.dtype.type in (N.uint8, N.bool_): glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex_nx, tex_ny, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, None) elif img.dtype.type == N.int16: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex_nx, tex_ny, 0, GL_LUMINANCE, GL_SHORT, None) elif img.dtype.type == N.float32: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex_nx, tex_ny, 0, GL_LUMINANCE, GL_FLOAT, None) elif img.dtype.type == N.uint16: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex_nx, tex_ny, 0, GL_LUMINANCE, GL_UNSIGNED_SHORT, None) elif img.dtype.type in ( N.float64, N.int32, N.uint32, N.int64, N.uint64, ): #N.complex64, N.complex128): glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex_nx, tex_ny, 0, GL_LUMINANCE, GL_FLOAT, None) else: self.error = "unsupported data mode" raise ValueError(self.error) #self.newGLListNow() curGLLIST = glGenLists(1) # 0 1 2 3 4 5 6 7 8 #[gllist, enabled, imgArr, textureID, smin, smax, r,g,b] r, g, b = 1, 1, 1 imgListItem = [ curGLLIST, 1, img, textureID, smin, smax, r, g, b, 0, 0, 0, 1 ] glNewList(curGLLIST, GL_COMPILE) # Newsgroups: comp.graphics.api.opengl Date: 1998/05/05 # By the way, you don't have to explicitly delete a display list to reuse # its name. Simply call glNewList() again with the existing list name -- # this will implicitly delete the old contents and replace them with the # new ones; this will happen at glEndList() time. glPushMatrix( ) # 20080701: in new coord system, integer pixel coord go through the center of pixel glTranslate(-.5, -.5, 0) glBindTexture(GL_TEXTURE_2D, textureID) glEnable(GL_TEXTURE_2D) #### glColor4f(1.0, 1.0, 1.0, alpha) ##################################glColor3f(1.0, 0.0, 0.0); # // Use a named texture. glBegin(GL_QUADS) ##BUG - HANGS glBindTexture(GL_TEXTURE_2D, self.m_texture_list) # # // glNormal3f( 0.0F, 0.0F, 1.0F) # # //seb TODO correct for pixel center vs pixel edge -> add .5 "somewhere" if self.m_originLeftBottom == 7 or \ self.m_originLeftBottom == 8: sx = pic_nx ox = sx / 2 sy = pic_ny oy = sy / 2 hx = self.picTexRatio_x / 2. # fft half nyquist hy = self.picTexRatio_y / 2. # fft half nyquist fx = self.picTexRatio_x # fft full nyquist fy = self.picTexRatio_y # fft full nyquist # quadrands(q): 2 | 1 # --+-- # 3 | 4 # d = 1 # display offset (how far left-down from center) ex = self.picTexRatio_x / sx ey = self.picTexRatio_y / sy # output from real_fft2d --- data nx is half-sized if self.m_originLeftBottom == 8: sx = (pic_nx - 1) * 2 ox = sx / 2 hx = self.picTexRatio_x # data: dc left bottom(q 1) display: dc left-down from center ! # q 3 q 1 glTexCoord2f(0, 0) glVertex2i(ox - d, oy - d) glTexCoord2f(hx, 0) glVertex2i(sx, oy - d) glTexCoord2f(hx, hy + ey) glVertex2i(sx, sy) glTexCoord2f(0, hy + ey) glVertex2i(ox - d, sy) # q 2 q 4 glTexCoord2f(0, fy) glVertex2i(ox - d, oy - d) glTexCoord2f(0, hy + ey) glVertex2i(ox - d, 0) glTexCoord2f(hx, hy + ey) glVertex2i(sx, 0) glTexCoord2f(hx, fy) glVertex2i(sx, oy - d) # q 2 (real_fft2d) (4) q 2 glTexCoord2f(hx - ex, fy) glVertex2i(0, oy) glTexCoord2f(hx - ex, hy) glVertex2i(0, sy) glTexCoord2f(ex, hy) glVertex2i(ox - d, sy) glTexCoord2f(ex, fy) glVertex2i(ox - d, oy) # (real_fft2d) just 1 pixel row: y-dc x-neg glTexCoord2f(hx - ex, 0) glVertex2i(0, oy) glTexCoord2f(hx - ex, ey) glVertex2i(0, oy - d) glTexCoord2f(ex, ey) glVertex2i(ox - d, oy - d) glTexCoord2f(ex, 0) glVertex2i(ox - d, oy) # q 3 (real_fft2d) (1) q 3 glTexCoord2f(ex, ey) glVertex2i(ox - d, oy - d) glTexCoord2f(hx - ex, ey) glVertex2i(0, oy - d) glTexCoord2f(hx - ex, hy) glVertex2i(0, 0) glTexCoord2f(ex, hy) glVertex2i(ox - d, 0) else: # self.m_originLeftBottom == 7: # data: dc left bottom(q 1) display: dc left-down from center ! # q 3 q 1 glTexCoord2f(0, 0) glVertex2i(ox - d, oy - d) glTexCoord2f(hx + ex, 0) glVertex2i(sx, oy - d) glTexCoord2f(hx + ex, hy + ey) glVertex2i(sx, sy) glTexCoord2f(0, hy + ey) glVertex2i(ox - d, sy) # q 2 q 4 glTexCoord2f(0, fy) glVertex2i(ox - d, oy - d) glTexCoord2f(0, hy + ey) glVertex2i(ox - d, 0) glTexCoord2f(hx + ex, hy + ey) glVertex2i(sx, 0) glTexCoord2f(hx + ex, fy) glVertex2i(sx, oy - d) # q 4 q 2 glTexCoord2f(fx, 0) glVertex2i(ox - d, oy - d) glTexCoord2f(fx, hy + ey) glVertex2i(ox - d, sy) glTexCoord2f(hx + ex, hy + ey) glVertex2i(0, sy) glTexCoord2f(hx + ex, 0) glVertex2i(0, oy - d) # q 1 q 3 glTexCoord2f(fx, fy) glVertex2i(ox - d, oy - d) glTexCoord2f(hx + ex, fy) glVertex2i(0, oy - d) glTexCoord2f(hx + ex, hy + ey) glVertex2i(0, 0) glTexCoord2f(fx, hy + ey) glVertex2i(ox - d, 0) elif self.m_originLeftBottom: ###//(0,0) at left top glTexCoord2f(0, 0) glVertex2i(0, 0) glTexCoord2f(self.picTexRatio_x, 0) glVertex2i(pic_nx, 0) glTexCoord2f(self.picTexRatio_x, self.picTexRatio_y) glVertex2i(pic_nx, pic_ny) glTexCoord2f(0, self.picTexRatio_y) glVertex2i(0, pic_ny) else: ###//(0,0) at left bottom glTexCoord2f(0, self.picTexRatio_y) glVertex2i(0, 0) glTexCoord2f(self.picTexRatio_x, self.picTexRatio_y) glVertex2i(pic_nx, 0) glTexCoord2f(self.picTexRatio_x, 0) glVertex2i(pic_nx, pic_ny) glTexCoord2f(0, 0) glVertex2i(0, pic_ny) glEnd() glDisable(GL_TEXTURE_2D) #20050520 glPopMatrix( ) # 20080701: in new coord system, integer pixel coord go through the center of pixel glEndList() # idx = self.newGLListDone(refreshNow=1, enable=1) # print idx # self.m_moreGlLists_texture[idx] = texture_list # self.m_moreGlLists_img[idx] = img if imgidx is None: imgidx = len(self.m_imgList) self.m_imgList.insert(imgidx, imgListItem) self.m_loadImgsToGfxCard.append(imgidx) self.m_imgsGlListChanged = True if len(self.m_imgList) == 1: self.m_zoomChanged = True if refreshNow: self.Refresh(0)
def addImg(self, img, smin=0, smax=10000, alpha=1., interp=0, imgidx=None, alignParm=None, refreshNow=1): ''' append new image. Following lists get somthing appended: self.imgList self.loadImgsToGfxCard if imgidx is not None use 'insert(imgidx,...)' with self.imgList instead of append a new GL-texture is generated and an empty(!) texture with proper dtype is created. a new GL-Display-lists is generated and compiled according to self.originLeftBottom ''' pic_ny, pic_nx = img.shape # different shapes in multi wave images #self.pic_nys.append(pic_ny) #self.pic_nxs.append(pic_nx) if self.dims == (1,2): # XY self.pic_nys = [self.mydoc.ny]*self.mydoc.nw self.pic_nxs = [self.mydoc.nx]*self.mydoc.nw elif self.dims == (0,2): # XZ self.pic_nys = [self.mydoc.nz]*self.mydoc.nw self.pic_nxs = [self.mydoc.nx]*self.mydoc.nw elif self.dims == (1,0): # ZY self.pic_nys = [self.mydoc.ny]*self.mydoc.nw self.pic_nxs = [self.mydoc.nz]*self.mydoc.nw self.pic_ny, self.pic_nx = max(self.pic_nys), max(self.pic_nxs) if smin == smax == 0: from Priithon.all import U smin, smax = U.mm(img) tex_nx = 2 while tex_nx<pic_nx: tex_nx*=2 # // texture must be of size 2^n tex_ny = 2 while tex_ny<pic_ny: tex_ny*=2 self.picTexRatio_x = float(pic_nx) / tex_nx self.picTexRatio_y = float(pic_ny) / tex_ny if sys.platform.startswith('linux') and wx.version().startswith('3'): wx.Yield() # added 20180312 self.SetCurrent(self.context) ## makes the implicit rendering context of this canvas current with this canvas textureID = glGenTextures(1) ## create one name for a texture object glBindTexture(GL_TEXTURE_2D, textureID) ## Define this new texture object based on img's geometry if interp: glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR) glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR) else: glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST) glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST) if img.dtype.type in (N.uint8, N.bool_): glTexImage2D(GL_TEXTURE_2D,0, GL_RGB, tex_nx,tex_ny, 0, GL_LUMINANCE,GL_UNSIGNED_BYTE, None) elif img.dtype.type == N.int16: glTexImage2D(GL_TEXTURE_2D,0, GL_RGB, tex_nx,tex_ny, 0, GL_LUMINANCE,GL_SHORT, None) elif img.dtype.type == N.float32: glTexImage2D(GL_TEXTURE_2D,0, GL_RGB, tex_nx,tex_ny, 0, GL_LUMINANCE,GL_FLOAT, None) elif img.dtype.type == N.uint16: glTexImage2D(GL_TEXTURE_2D,0, GL_RGB, tex_nx,tex_ny, 0, GL_LUMINANCE,GL_UNSIGNED_SHORT, None) elif img.dtype.type in (N.float64, N.int32, N.uint32, N.int64, N.uint64,): #N.complex64, N.complex128): glTexImage2D(GL_TEXTURE_2D,0, GL_RGB, tex_nx,tex_ny, 0, GL_LUMINANCE,GL_FLOAT, None) else: self.error = "unsupported data mode" raise ValueError(self.error) curGLLIST = glGenLists( 1 ) ## request one display-list index # 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 #[gllist, enabled, imgArr, textureID, smin, smax, r,g,b, tx, ty, rot, magX, magY, magZ] r,g,b=1,1,1 ## default grey (if no self.setColor() is called) imgListItem = [curGLLIST, 1, img, textureID, smin,smax, r,g,b, 0,0,0,1,1,1] glNewList(curGLLIST, GL_COMPILE) # Display list is created; Commands are merely compiled # Newsgroups: comp.graphics.api.opengl Date: 1998/05/05 # By the way, you don't have to explicitly delete a display list to reuse # its name. Simply call glNewList() again with the existing list name -- # this will implicitly delete the old contents and replace them with the # new ones; this will happen at glEndList() time. glBindTexture(GL_TEXTURE_2D, textureID) # CHECK: Is this redundant? glEnable(GL_TEXTURE_2D) glEnable(GL_BLEND) ## enable blending of colors (Chapter 6 of the Red Book) glBlendFunc(GL_ONE, GL_ONE) glBegin(GL_QUADS) ### draw black background under the image ###//(0,0) at left bottom glTexCoord2f( 0, 0) glVertex2i ( 0, 0) glTexCoord2f( self.picTexRatio_x, 0) glVertex2i ( pic_nx, 0) glTexCoord2f( self.picTexRatio_x, self.picTexRatio_y) glVertex2i ( pic_nx, pic_ny) glTexCoord2f( 0, self.picTexRatio_y) glVertex2i ( 0, pic_ny) glEnd() glDisable(GL_TEXTURE_2D) glDisable(GL_BLEND) glEndList() ## display list stops here if imgidx is None: imgidx = len(self.imgList) self.imgList.insert(imgidx, imgListItem) ## imgListItem contains the newly created display list, indexed by imgidx self.loadImgsToGfxCard.append( imgidx ) self.imgsGlListChanged = True self.setLeftDown() if refreshNow: self.Refresh(0)
def addImg(self, img, smin=0, smax=10000, alpha=1., interp=0, imgidx=None, refreshNow=1): """ append new inage. Following lists get somthing appended: m_imgList m_loadImgsToGfxCard if imgidx is not None use 'insert(imgidx,...)' with m_imgList instead of append a new GL-texture is generated and an empty(!) texture with proper dtype is created. a new GL-Display-lists is generated an compiled according to m_originLeftBottom """ pic_ny,pic_nx = img.shape if len(self.m_imgList) == 0: # some workaround code for functions originally written for viewer.py self.pic_ny, self.pic_nx = pic_ny,pic_nx if smin == smax == 0: from Priithon.all import U smin, smax = U.mm(img) tex_nx = 2 while tex_nx<pic_nx: tex_nx*=2 # // texture must be of size 2^n tex_ny = 2 while tex_ny<pic_ny: tex_ny*=2 self.picTexRatio_x = float(pic_nx) / tex_nx self.picTexRatio_y = float(pic_ny) / tex_ny wx.Yield() self.SetCurrent(self.context) # 20141127 textureID = glGenTextures(1) glBindTexture(GL_TEXTURE_2D, textureID) #glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glBlendFunc(GL_ONE, GL_ONE) # 20070827 #20070827 glBlendFunc(GL_SRC_ALPHA, GL_ONE) #20070827 # GL_LUMINANCE # Each element is a single luminance value. The GL converts it to fixed-point # or floating-point, then assembles it into an RGBA element by replicating # the luminance value three times for red, green, and blue and # attaching 1 for alpha. # GL_LUMINANCE_ALPHA # Each element is a luminance/alpha pair. The GL converts it to fixed-point # or floating point, then assembles it into an RGBA element by replicating # the luminance value three times for red, green, and blue. if interp: # FIXME put into gllist glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR) glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR) else: glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST) glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST) if img.dtype.type in (N.uint8,N.bool_): glTexImage2D(GL_TEXTURE_2D,0, GL_RGB, tex_nx,tex_ny, 0, GL_LUMINANCE,GL_UNSIGNED_BYTE, None) elif img.dtype.type == N.int16: glTexImage2D(GL_TEXTURE_2D,0, GL_RGB, tex_nx,tex_ny, 0, GL_LUMINANCE,GL_SHORT, None) elif img.dtype.type == N.float32: glTexImage2D(GL_TEXTURE_2D,0, GL_RGB, tex_nx,tex_ny, 0, GL_LUMINANCE,GL_FLOAT, None) elif img.dtype.type == N.uint16: glTexImage2D(GL_TEXTURE_2D,0, GL_RGB, tex_nx,tex_ny, 0, GL_LUMINANCE,GL_UNSIGNED_SHORT, None) elif img.dtype.type in (N.float64, N.int32, N.uint32, N.int64, N.uint64,): #N.complex64, N.complex128): glTexImage2D(GL_TEXTURE_2D,0, GL_RGB, tex_nx,tex_ny, 0, GL_LUMINANCE,GL_FLOAT, None) else: self.error = "unsupported data mode" raise ValueError(self.error) #self.newGLListNow() curGLLIST = glGenLists( 1 ) # 0 1 2 3 4 5 6 7 8 #[gllist, enabled, imgArr, textureID, smin, smax, r,g,b] r,g,b=1,1,1 imgListItem = [curGLLIST, 1, img, textureID, smin,smax, r,g,b, 0,0,0,1] glNewList( curGLLIST, GL_COMPILE ) # Newsgroups: comp.graphics.api.opengl Date: 1998/05/05 # By the way, you don't have to explicitly delete a display list to reuse # its name. Simply call glNewList() again with the existing list name -- # this will implicitly delete the old contents and replace them with the # new ones; this will happen at glEndList() time. glPushMatrix() # 20080701: in new coord system, integer pixel coord go through the center of pixel glTranslate(-.5,-.5 ,0) glBindTexture(GL_TEXTURE_2D, textureID) glEnable(GL_TEXTURE_2D) #### glColor4f(1.0, 1.0, 1.0, alpha) ##################################glColor3f(1.0, 0.0, 0.0); # // Use a named texture. glBegin(GL_QUADS) ##BUG - HANGS glBindTexture(GL_TEXTURE_2D, self.m_texture_list) # # // glNormal3f( 0.0F, 0.0F, 1.0F) # # //seb TODO correct for pixel center vs pixel edge -> add .5 "somewhere" if self.m_originLeftBottom == 7 or \ self.m_originLeftBottom == 8: sx = pic_nx ox = sx / 2 sy = pic_ny oy = sy / 2 hx = self.picTexRatio_x / 2. # fft half nyquist hy = self.picTexRatio_y / 2. # fft half nyquist fx = self.picTexRatio_x # fft full nyquist fy = self.picTexRatio_y # fft full nyquist # quadrands(q): 2 | 1 # --+-- # 3 | 4 # d = 1 # display offset (how far left-down from center) ex = self.picTexRatio_x / sx ey = self.picTexRatio_y / sy # output from real_fft2d --- data nx is half-sized if self.m_originLeftBottom == 8: sx = (pic_nx-1) * 2 ox = sx / 2 hx = self.picTexRatio_x # data: dc left bottom(q 1) display: dc left-down from center ! # q 3 q 1 glTexCoord2f( 0, 0); glVertex2i ( ox-d, oy-d) glTexCoord2f( hx, 0); glVertex2i ( sx, oy-d) glTexCoord2f( hx, hy+ey); glVertex2i ( sx, sy) glTexCoord2f( 0, hy+ey); glVertex2i ( ox-d, sy) # q 2 q 4 glTexCoord2f( 0, fy); glVertex2i ( ox-d, oy-d) glTexCoord2f( 0, hy+ey); glVertex2i ( ox-d, 0) glTexCoord2f( hx, hy+ey) ; glVertex2i ( sx, 0) glTexCoord2f( hx, fy); glVertex2i ( sx, oy-d) # q 2 (real_fft2d) (4) q 2 glTexCoord2f( hx-ex, fy); glVertex2i ( 0, oy) glTexCoord2f( hx-ex, hy); glVertex2i ( 0, sy) glTexCoord2f( ex, hy); glVertex2i ( ox-d, sy) glTexCoord2f( ex, fy); glVertex2i ( ox-d, oy) # (real_fft2d) just 1 pixel row: y-dc x-neg glTexCoord2f( hx-ex, 0); glVertex2i ( 0, oy) glTexCoord2f( hx-ex, ey); glVertex2i ( 0, oy-d) glTexCoord2f( ex, ey); glVertex2i ( ox-d, oy-d) glTexCoord2f( ex, 0); glVertex2i ( ox-d, oy) # q 3 (real_fft2d) (1) q 3 glTexCoord2f( ex, ey ); glVertex2i ( ox-d, oy-d) glTexCoord2f( hx-ex, ey ); glVertex2i ( 0 , oy-d) glTexCoord2f( hx-ex, hy) ; glVertex2i ( 0 , 0) glTexCoord2f( ex, hy); glVertex2i ( ox-d, 0) else: # self.m_originLeftBottom == 7: # data: dc left bottom(q 1) display: dc left-down from center ! # q 3 q 1 glTexCoord2f( 0, 0); glVertex2i ( ox-d, oy-d) glTexCoord2f( hx+ex, 0); glVertex2i ( sx, oy-d) glTexCoord2f( hx+ex, hy+ey); glVertex2i ( sx, sy) glTexCoord2f( 0, hy+ey); glVertex2i ( ox-d, sy) # q 2 q 4 glTexCoord2f( 0, fy); glVertex2i ( ox-d, oy-d) glTexCoord2f( 0, hy+ey); glVertex2i ( ox-d, 0) glTexCoord2f( hx+ex, hy+ey) ; glVertex2i ( sx, 0) glTexCoord2f( hx+ex, fy); glVertex2i ( sx, oy-d) # q 4 q 2 glTexCoord2f( fx, 0); glVertex2i ( ox-d, oy-d) glTexCoord2f( fx, hy+ey); glVertex2i ( ox-d, sy) glTexCoord2f( hx+ex, hy+ey); glVertex2i ( 0 , sy) glTexCoord2f( hx+ex, 0); glVertex2i ( 0 , oy-d) # q 1 q 3 glTexCoord2f( fx, fy); glVertex2i ( ox-d, oy-d) glTexCoord2f( hx+ex, fy); glVertex2i ( 0 , oy-d) glTexCoord2f( hx+ex, hy+ey) ; glVertex2i ( 0 , 0) glTexCoord2f( fx, hy+ey); glVertex2i ( ox-d, 0) elif self.m_originLeftBottom: ###//(0,0) at left top glTexCoord2f( 0, 0) glVertex2i ( 0, 0) glTexCoord2f( self.picTexRatio_x, 0) glVertex2i ( pic_nx, 0) glTexCoord2f( self.picTexRatio_x, self.picTexRatio_y) glVertex2i ( pic_nx, pic_ny) glTexCoord2f( 0, self.picTexRatio_y) glVertex2i ( 0, pic_ny) else: ###//(0,0) at left bottom glTexCoord2f( 0, self.picTexRatio_y) glVertex2i ( 0, 0) glTexCoord2f( self.picTexRatio_x, self.picTexRatio_y) glVertex2i ( pic_nx, 0) glTexCoord2f( self.picTexRatio_x, 0) glVertex2i ( pic_nx, pic_ny) glTexCoord2f( 0, 0) glVertex2i ( 0, pic_ny) glEnd() glDisable(GL_TEXTURE_2D) #20050520 glPopMatrix() # 20080701: in new coord system, integer pixel coord go through the center of pixel glEndList() # idx = self.newGLListDone(refreshNow=1, enable=1) # print idx # self.m_moreGlLists_texture[idx] = texture_list # self.m_moreGlLists_img[idx] = img if imgidx is None: imgidx = len(self.m_imgList) self.m_imgList.insert(imgidx, imgListItem) self.m_loadImgsToGfxCard.append( imgidx ) self.m_imgsGlListChanged = True if len(self.m_imgList) == 1: self.m_zoomChanged = True if refreshNow: self.Refresh(0)